1import{o as e}from"./rolldown-runtime-C_JJxWoe.js";import{a,o as t}from"./vendor-framer-motion-Bhdy4EQn.js";import{n as i}from"./vendor-react-CzjQKmBP.js";import{t as n}from"./useTranslation-5LTeYETn.js";import{S as s}from"./model-DpjQNbV9.js";import{t as r}from"./react-toastify.esm-GqbWfEFd.js";import{t as o}from"./DsIcon-Dym1BpSl.js";import{t as l}from"./Panel-mMQkzq7v.js";import{t as c}from"./Segmented-Dgdc_NJ8.js";import{t as d}from"./Spinner-DJHcTlRE.js";import{t as u}from"./Badge-Qls_pAJm.js";import{t as h}from"./Checkbox-Ca_9SD02.js";import{mn as g,pn as m,un as p}from"./index-CjqPNSQD.js";/* empty css */import{a as j}from"./components-B4jJNgro.js";import{a as x}from"./components-B1VUILlw.js";var v=e(t()),_="_page_1i0gh_17",f="_head_1i0gh_29",y="_title_1i0gh_34",M="_subtitle_1i0gh_56",b="_headMeta_1i0gh_70",N="_headMetaDot_1i0gh_79",w="_body_1i0gh_84",S="_nav_1i0gh_99",C="_navItem_1i0gh_110",k="_navItemOn_1i0gh_137",I="_navItemDrop_1i0gh_145",D="_navItemLabel_1i0gh_152",E="_navItemCount_1i0gh_160",z="_navItemKill_1i0gh_170",F="_navNew_1i0gh_180",T="_navNewForm_1i0gh_204",L="_field_1i0gh_213",$="_fieldInput_1i0gh_238",A="_search_1i0gh_267",O="_listBar_1i0gh_279",P="_listBarSpacer_1i0gh_288",R="_listBarCount_1i0gh_293",q="_rows_1i0gh_302",B="_row_1i0gh_302",U="_rowOn_1i0gh_330",W="_rowDragging_1i0gh_335",H="_rowGlyph_1i0gh_340",K="_rowBody_1i0gh_350",G="_rowTitle_1i0gh_356",Q="_rowMeta_1i0gh_370",V="_rowMetaNum_1i0gh_378",J="_rowActions_1i0gh_383",X="_mover_1i0gh_396",Y="_moverMenu_1i0gh_406",Z="_moverItem_1i0gh_423",ee="_moverItemOn_1i0gh_446",ae="_moverItemLabel_1i0gh_451",te="_state_1i0gh_459",ie="_stateBadge_1i0gh_471",ne="_stateTitle_1i0gh_483",se="_stateText_1i0gh_490",re="_unfile_1i0gh_504",oe="_unfileOn_1i0gh_518",le="_scrim_1i0gh_525",ce="_dialog_1i0gh_538",de="_dialogNarrow_1i0gh_562",ue="_dialogWide_1i0gh_566",he="_dialogHead_1i0gh_570",ge="_dialogTitle_1i0gh_578",me="_dialogBody_1i0gh_591",pe="_dialogFoot_1i0gh_599",je="_dialogFootSpacer_1i0gh_607",xe="_confirm_1i0gh_615",ve="_dialogText_1i0gh_622",_e="_bib_1i0gh_634",fe="_bibRow_1i0gh_645",ye="_bibText_1i0gh_657",Me="_form_1i0gh_671",be="_formRow_1i0gh_677",Ne="_group_1i0gh_683",we="_label_1i0gh_689",Se="_required_1i0gh_700",Ce="_select_1i0gh_704",ke="_lookup_1i0gh_724",Ie="_lookupField_1i0gh_731",De="_hint_1i0gh_736",Ee=u,ze=g,Fe=h,Te=o,Le=m,$e=l,Ae=c,Oe=d,Pe=p,Re=e(i()),qe=a(),Be=({title:e,headerExtra:a,children:t,footer:i,onClose:s,width:r="default"})=>{const{t:o}=n(),l=v.useRef(!1);v.useEffect(()=>{const e=e=>{"Escape"===e.key&&s()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[s]);const c=[ce];return"narrow"===r&&c.push(de),"wide"===r&&c.push(ue),(0,Re.createPortal)((0,qe.jsx)("div",{className:le,onMouseDown:e=>{l.current=e.target===e.currentTarget},onClick:e=>{l.current&&e.target===e.currentTarget&&s()},children:(0,qe.jsxs)("div",{className:c.join(" "),role:"dialog","aria-modal":"true",children:[(0,qe.jsxs)("div",{className:he,children:[(0,qe.jsx)("h2",{className:ge,children:e}),a,(0,qe.jsx)(Le,{icon:"x",label:o("citationManager.close"),size:"sm",onClick:s})]}),(0,qe.jsx)("div",{className:me,children:t}),i?(0,qe.jsx)("div",{className:pe,children:i}):(0,qe.jsx)("span",{})]})}),document.body)},Ue=(e,a)=>{r[e](a)},We=({isOpen:e,onClose:a,onSave:t,editingSource:i,folders:r=[]})=>{const{t:o}=n(),[l,c]=(0,v.useState)("auto"),[d,u]=(0,v.useState)(!1),[h,g]=(0,v.useState)(""),[m,p]=(0,v.useState)({type:"book",title:"",authors:[],year:void 0,publisher:"",url:"",doi:"",isbn:"",journal:"",volume:"",issue:"",pages:"",edition:"",city:"",abstract:"",notes:"",folderId:void 0}),[j,x]=(0,v.useState)("");(0,v.useEffect)(()=>{i?(p({type:i.type,title:i.title,authors:i.authors||[],year:i.year,publisher:i.publisher||"",url:i.url||"",doi:i.doi||"",isbn:i.isbn||"",journal:i.journal||"",volume:i.volume||"",issue:i.issue||"",pages:i.pages||"",edition:i.edition||"",city:i.city||"",abstract:i.abstract||"",notes:i.notes||"",folderId:i.folderId||void 0}),x((i.authors||[]).join(", ")),c("manual")):(_(),c("auto"))},[i,e]);const _=()=>{p({type:"book",title:"",authors:[],year:void 0,publisher:"",url:"",doi:"",isbn:"",journal:"",volume:"",issue:"",pages:"",edition:"",city:"",abstract:"",notes:"",folderId:void 0}),x(""),g("")},f=(e,a)=>{let t=e.title||a;if(t===e.url&&e.url)try{const a=new URL(e.url),i=a.pathname.split("/").filter(e=>e);if(i.length>0){const e=i[i.length-1];t=decodeURIComponent(e.replace(/\.[^/.]+$/,"")).replace(/[-_]/g," ")}else t=a.hostname.replace("www.","")}catch{t=e.title||a}return t},y=(e,a)=>({...m,type:e.type||m.type,title:a,authors:e.authors||[],year:void 0!==e.year?e.year:void 0,publisher:void 0!==e.publisher?e.publisher:"",url:void 0!==e.url?e.url:"",doi:void 0!==e.doi?e.doi:"",isbn:void 0!==e.isbn?e.isbn:"",journal:void 0!==e.journal?e.journal:"",volume:void 0!==e.volume?e.volume:"",issue:void 0!==e.issue?e.issue:"",pages:void 0!==e.pages?e.pages:"",edition:void 0!==e.edition?e.edition:"",city:void 0!==e.city?e.city:"",abstract:void 0!==e.abstract?e.abstract:""}),M=(e,a)=>!e.authors?.length&&!e.year&&!e.publisher&&!e.abstract&&e.url&&(a===e.url||a.length<20),b=async()=>
1{if(h.trim()){u(!0);try{const e=(await s.http.instance.post("/api/v2/citations/lookup",{query:h})).data,a=h.trim().replace(/^["'`]|["'`]$/g,""),t=f(e,a);p(y(e,t)),x((e.authors||[]).join(", ")),c("manual"),M(e,t)?Ue("info",o("citationManager.toast.lookupPartial")):Ue("success",o("citationManager.toast.lookupSuccess"))}catch(e){Ue("error",e.response?.data?.message||o("citationManager.toast.lookupError"))}finally{u(!1)}}else Ue("error",o("citationManager.toast.enterQuery"))},N=e=>{const a={type:e.type,title:(e.title||"").trim(),authors:Array.isArray(e.authors)&&e.authors.length>0?e.authors:void 0,year:e.year&&!isNaN(Number(e.year))?Number(e.year):void 0,publisher:e.publisher?.trim()||void 0,url:e.url?.trim()||void 0,doi:e.doi?.trim()||void 0,isbn:e.isbn?.trim()||void 0,journal:e.journal?.trim()||void 0,volume:e.volume?.trim()||void 0,issue:e.issue?.trim()||void 0,pages:e.pages?.trim()||void 0,edition:e.edition?.trim()||void 0,city:e.city?.trim()||void 0,abstract:e.abstract?.trim()||void 0,notes:e.notes?.trim()||void 0,folderId:e.folderId&&e.folderId.trim()?e.folderId.trim():void 0};return Object.keys(a).forEach(e=>{void 0===a[e]&&delete a[e]}),a},w=async()=>{if("auto"!==l||!h.trim()||m.title.trim())m.title.trim()?t(N(m)):Ue("error",o("citationManager.toast.titleRequired"));else{u(!0);try{const e=(await s.http.instance.post("/api/v2/citations/lookup",{query:h})).data,a=h.trim().replace(/^["'`]|["'`]$/g,""),i=f(e,a),n=y(e,i);if(!n.title.trim())return Ue("error",o("citationManager.toast.titleRequired")),void u(!1);M(e,i)&&Ue("info",o("citationManager.toast.lookupPartial")),t(N(n))}catch(e){Ue("error",e.response?.data?.message||o("citationManager.toast.lookupError"))}finally{u(!1)}}};if(!e)return null;const S=e=>p({...m,...e}),C=(e,a,t,i="text")=>(0,qe.jsxs)("span",{className:Ne,children:[(0,qe.jsx)("span",{className:we,children:a}),(0,qe.jsx)("span",{className:L,children:(0,qe.jsx)("input",{type:i,className:$,value:"number"===i?m[e]||"":m[e],onChange:a=>S({[e]:"number"===i?a.target.value?parseInt(a.target.value,10):void 0:a.target.value}),placeholder:t,"aria-label":a})})]}),k="article"===m.type||"journal"===m.type;return(0,qe.jsx)(Be,{width:"wide",onClose:a,title:o(i?"citationManager.editSource":"citationManager.addSource"),headerExtra:(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsx)("span",{className:je}),(0,qe.jsx)(Ae,{size:"sm",value:l,onChange:e=>c(e),options:[{value:"auto",label:o("citationManager.automatic")},{value:"manual",label:o("citationManager.manual")}]})]}),footer:"manual"===l?(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsx)(ze,{variant:"ghost",size:"md",onClick:a,children:o("citationManager.cancel")}),(0,qe.jsx)(ze,{variant:"primary",size:"md",icon:"check",onClick:w,children:o(i?"citationManager.update":"citationManager.save")})]}):void 0,children:"auto"===l?(0,qe.jsxs)("div",{className:Me,children:[(0,qe.jsxs)("span",{className:Ne,children:[(0,qe.jsx)("span",{className:we,children:o("citationManager.enterUrlDoiOrTitle")}),(0,qe.jsxs)("span",{className:ke,children:[(0,qe.jsxs)("span",{className:`${L} ${Ie}`,children:[(0,qe.jsx)(Te,{name:"link",size:14}),(0,qe.jsx)("input",{type:"text",className:$,value:h,onChange:e=>g(e.target.value),placeholder:o("citationManager.placeholder.urlDoiOrTitle"),"aria-label":o("citationManager.enterUrlDoiOrTitle"),onKeyDown:e=>{"Enter"===e.key&&b()}})]}),(0,qe.jsx)(ze,{variant:"primary",size:"md",icon:"search",loading:d,onClick:b,children:o(d?"citationManager.lookingUp":"citationManager.lookup")})]})]}),(0,qe.jsx)("p",{className:De,children:o("citationManager.emptyHint","Paste a DOI, URL or ISBN and we'll fill in the details.")})]}):(0,qe.jsxs)("div",{className:Me,children:[(0,qe.jsxs)("div",{className:be,children:[(0,qe.jsxs)("span",{className:Ne,children:[(0,qe.jsx)("span",{className:we,children:o("citationManager.sourceType")}),(0,qe.jsxs)("select",{className:Ce,value:m.type,onChange:e=>S({type:e.target.value}),"aria-label":o("citationManager.sourceType"),children:[(0,qe.jsx)("option",{value:"book",children:o("citationManager.type.book")}),(0,qe.jsx)("option",{value:"article",children:o("citationManager.type.article")}),(0,qe.jsx)("option",{value:"journal",children:o("citationManager.type.journal")}),(0,qe.jsx)("option",{value:"website",children:o("citationManager.type.website")}),(0,qe.jsx)("option",{value:"thesis",children:o("citationManager.type.thesis")}),(0,qe.jsx)("option",{value:"report",children:o("citationManager.type.report")}),(0,qe.jsx)("option",{value:"other",children:o("citationManager.type.other")})]})]}),(0,qe.jsxs)("span",{className:Ne,children:[(0,qe.jsx)("span",{className:we,children:o("citationManager.folder")}),(0,qe.jsxs)("select",{className:Ce,value:m.folderId||"",onChange:e=>S({folderId:e.target.value||void 0}),"aria-label":o("citationManager.folder"),children:[(0,qe.jsx)("option",{value:"",children:o("citationManager.noFolder")}),r.map(e=>(0,qe.jsx)("option",{value:e.id,children:e.name},e.id))]})]})]}),(0,qe.jsxs)("span",{className:Ne,children:[(0,qe.jsxs)("span",{className:we,children:[o("citationManager.fieldTitle")," ",(0,qe.jsx)("span",{className:Se,children:"*"})]}),(0,qe.jsx)("span",{className:L,children:(0,qe.jsx)("input",{type:"text",className:$,value:m.title,onChange:e=>S({title:e.target.value}),onKeyDown:e=>
1{"Enter"===e.key&&m.title.trim()&&w()},placeholder:o("citationManager.placeholder.title"),"aria-label":o("citationManager.fieldTitle")})})]}),(0,qe.jsxs)("span",{className:Ne,children:[(0,qe.jsx)("span",{className:we,children:o("citationManager.authors")}),(0,qe.jsx)("span",{className:L,children:(0,qe.jsx)("input",{type:"text",className:$,value:j,onChange:e=>(e=>{x(e);const a=e.split(",").map(e=>e.trim()).filter(e=>e.length>0);p({...m,authors:a})})(e.target.value),placeholder:o("citationManager.placeholder.authors"),"aria-label":o("citationManager.authors")})})]}),(0,qe.jsxs)("div",{className:be,children:[C("year",o("citationManager.year"),o("citationManager.placeholder.year"),"number"),C("publisher",o("citationManager.publisher"),o("citationManager.placeholder.publisher"))]}),k?(0,qe.jsxs)(qe.Fragment,{children:[C("journal",o("citationManager.journal"),o("citationManager.placeholder.journal")),(0,qe.jsxs)("div",{className:be,children:[C("volume",o("citationManager.volume"),o("citationManager.placeholder.volume")),C("issue",o("citationManager.issue"),o("citationManager.placeholder.issue")),C("pages",o("citationManager.pages"),o("citationManager.placeholder.pages"))]})]}):null,(0,qe.jsxs)("div",{className:be,children:[C("url",o("citationManager.url"),o("citationManager.placeholder.url"),"url"),C("doi",o("citationManager.doi"),o("citationManager.placeholder.doi"))]}),"book"===m.type?(0,qe.jsxs)("div",{className:be,children:[C("isbn",o("citationManager.isbn"),o("citationManager.placeholder.isbn")),C("edition",o("citationManager.edition"),o("citationManager.placeholder.edition"))]}):null]})})},He=(e,a)=>{r[e](a)},Ke=({isOpen:e,onClose:a,sourceIds:t})=>{const{t:i}=n(),[r,o]=(0,v.useState)("APA"),[l,c]=(0,v.useState)([]),[d,u]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1);(0,v.useEffect)(()=>{e&&t.length>0?m():e||c([])},[e,r,t.join(",")]);const m=async()=>{u(!0);try{if(1===t.length){const e=await s.http.instance.post("/api/v2/citations/format",{sourceId:t[0],style:r});c([e.data.citation])}else{const e=await s.http.instance.post("/api/v2/citations/format-multiple",{sourceIds:t,style:r});c(e.data.citations)}}catch(e){He("error",e.response?.data?.message||i("citationManager.toast.formatError"))}finally{u(!1)}};if(!e)return null;const p=1===t.length;return(0,qe.jsx)(Be,{onClose:a,title:p?i("citationManager.citation","Citation"):i("citationManager.bibliography"),headerExtra:(0,qe.jsxs)(qe.Fragment,{children:[p?null:(0,qe.jsx)(Ee,{mono:!0,children:i("citationManager.citationCount",{count:l.length||t.length,defaultValue:"{{count}} citations"})}),(0,qe.jsx)("span",{className:je}),(0,qe.jsx)(Ae,{size:"sm",value:r,onChange:e=>o(e),options:[{value:"APA",label:"APA 7"},{value:"MLA",label:"MLA 9"},{value:"Chicago",label:"Chicago"}]})]}),footer:(0,qe.jsx)(qe.Fragment,{children:(0,qe.jsx)(ze,{variant:"primary",size:"md",icon:h?"check":"copy",disabled:0===l.length,onClick:()=>{const e=l.join("\n");navigator.clipboard.writeText(e),He("success",i("citationManager.toast.copied")),g(!0),window.setTimeout(()=>g(!1),1400)},children:h?i("citationManager.copied","Copied"):p?i("citationManager.copy","Copy"):i("citationManager.copyAll")})}),children:d?(0,qe.jsxs)("div",{className:te,children:[(0,qe.jsx)(Oe,{size:20}),(0,qe.jsx)("p",{className:se,children:i("citationManager.loading","Loading sourcesâ¦")})]}):0===l.length?(0,qe.jsxs)("div",{className:te,children:[(0,qe.jsx)("span",{className:ie,children:(0,qe.jsx)(Te,{name:"quote",size:20,strokeWidth:1.5})}),(0,qe.jsx)("p",{className:se,children:i("citationManager.toast.formatError")})]}):(0,qe.jsx)("div",{className:_e,children:l.map((e,a)=>(0,qe.jsxs)("div",{className:fe,children:[(0,qe.jsx)("p",{className:ye,children:e}),(0,qe.jsx)(Pe,{content:i("citationManager.copy","Copy"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"copy",label:i("citationManager.copy","Copy"),size:"sm",onClick:()=>(e=>{navigator.clipboard.writeText(e),He("success",i("citationManager.toast.copied"))})(e)})})]},a))})})},Ge=({isOpen:e,onClose:a,onConfirm:t,count:i,isFolder:s})=>{const{t:r}=n();if(!e)return null;return(0,qe.jsx)(Be,{width:"narrow",onClose:a,title:r("citationManager.deleteSelected",{count:i}),footer:(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsx)(ze,{variant:"ghost",size:"md",onClick:a,children:r("citationManager.cancel")}),(0,qe.jsx)(ze,{variant:"danger",size:"md",icon:"trash-2",onClick:()=>{t(),a()},children:r("citationManager.delete")})]}),children:(0,qe.jsxs)("div",{className:xe,children:[(0,qe.jsx)("span",{className:ie,children:(0,qe.jsx)(Te,{name:s?"folder-x":"trash-2",size:20,strokeWidth:1.5})}),(0,qe.jsx)("p",{className:ve,children:r("citationManager.confirmDeleteSelected",{count:i})})]})})},Qe=({folders:e,selectedFolderId:a,countFor:t,onSelect:i,onCreate:s,onDelete:r,onDropSource:o,dragActive:l})=>{const{t:c}=n(),[d,u]=v.useState(!1),[h,g]=v.useState(""),[m,p]=v.useState(void 0),j=()=>{const e=h.trim();e&&(s(e),g(""),u(!1))},x=e=>{const t=[C];return a===e&&t.push(k),l&&m===e&&t.push(I),t.join(" ")},_=e=>({role:"button",tabIndex:0,"aria-current":a===e,className:x(e),onClick:()=>i(e),onKeyDown:a=>{"Enter"!==a.key&&" "!==a.key||(a.preventDefault(),i(e))},onDragOver:a=>{a.preventDefault(),a.dataTransfer.dropEffect="move",p(e)},onDragLeave:()=>p(a=>a===e?void 0:a),onDrop:a=>{a.preventDefault(),a.stopPropagation(),p(void 0),o(e)}});return(0,qe.jsxs)("nav",{className:S,"aria-label":c("citationManager.allFolders"),children:[(0,qe.jsxs)("div",{..._(null),children:[(0,qe.jsx)(Te,{name:"inbox",size:15}),(0,qe.jsx)("span",{className:D,children:c("citationManager.withoutFolder")}
1),(0,qe.jsx)("span",{className:E,children:t(null)})]}),e.map(e=>(0,qe.jsxs)("div",{..._(e.id),children:[(0,qe.jsx)(Te,{name:"folder",size:15}),(0,qe.jsx)("span",{className:D,children:e.name}),(0,qe.jsx)("span",{className:E,children:t(e.id)}),(0,qe.jsx)("span",{className:z,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,qe.jsx)(Le,{icon:"x",label:c("citationManager.deleteFolder"),size:"xs",onClick:()=>r(e.id)})})]},e.id)),d?(0,qe.jsxs)("div",{className:T,children:[(0,qe.jsxs)("span",{className:L,children:[(0,qe.jsx)(Te,{name:"folder-plus",size:14}),(0,qe.jsx)("input",{type:"text",className:$,value:h,autoFocus:!0,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&j(),"Escape"===e.key&&(u(!1),g(""))},placeholder:c("citationManager.folderNamePlaceholder"),"aria-label":c("citationManager.folderNamePlaceholder")})]}),(0,qe.jsx)(Pe,{content:c("citationManager.create"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"check",label:c("citationManager.create"),size:"sm",onClick:j})}),(0,qe.jsx)(Pe,{content:c("citationManager.cancel"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"x",label:c("citationManager.cancel"),size:"sm",onClick:()=>{u(!1),g("")}})})]}):(0,qe.jsxs)("button",{type:"button",className:F,onClick:()=>u(!0),children:[(0,qe.jsx)(Te,{name:"plus",size:15}),c("citationManager.newFolder","New folder")]})]})}
1,Ve={book:"book-open",article:"file-text",journal:"newspaper",website:"link",thesis:"graduation-cap",report:"clipboard-list",other:"file"};var Je=({folders:e,currentFolderId:a,onMove:t})=>{const{t:i}=n(),[s,r]=v.useState(!1),[o,l]=v.useState(null),c=v.useRef(null),d=v.useRef(null);v.useLayoutEffect(()=>{if(!s||!c.current)return void l(null);const a=c.current.getBoundingClientRect(),t=window.innerHeight-a.bottom,i=Math.min(240,10+32*(e.length+1)),n=t<i+12?a.top-i-4:a.bottom+4,r=Math.max(8,Math.min(a.right-200,window.innerWidth-200-8));l({top:Math.max(8,n),left:r})},[s,e.length]),v.useEffect(()=>{if(!s)return;const e=e=>{const a=e.target;c.current?.contains(a)||d.current?.contains(a)||r(!1)},a=()=>r(!1);return document.addEventListener("mousedown",e),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[s]);const u=(e,i,n)=>(0,qe.jsxs)("button",{type:"button",role:"menuitem",className:a===e?`${Z} ${ee}`:Z,onClick:()=>(e=>{r(!1),e!==a&&t(e)})(e),children:[(0,qe.jsx)(Te,{name:n,size:14}),(0,qe.jsx)("span",{className:ae,children:i})]},e??"__root");return(0,qe.jsxs)("span",{className:X,ref:c,children:[(0,qe.jsx)(Pe,{content:i("citationManager.moveToFolder","Move to folder"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"folder",label:i("citationManager.moveToFolder","Move to folder"),size:"sm",active:s,onClick:()=>r(e=>!e)})}),s&&o?(0,Re.createPortal)((0,qe.jsxs)("div",{ref:d,className:Y,role:"menu",style:{top:o.top,left:o.left},children:[u(null,i("citationManager.noFolder"),"inbox"),e.map(e=>u(e.id,e.name,"folder"))]}),document.body):null]})},Xe=({onDrop:e})=>{const{t:a}=n(),[t,i]=v.useState(!1);return(0,qe.jsxs)("div",{className:t?`${re} ${oe}`:re,onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move",i(!0)},onDragLeave:()=>i(!1),onDrop:a=>{a.preventDefault(),a.stopPropagation(),i(!1),e()},children:[(0,qe.jsx)(Te,{name:"inbox",size:18,strokeWidth:1.5}),a("citationManager.moveToRoot")]})},Ye=({sources:e,folders:a,selectedSourceIds:t,selectedFolderId:i,query:s,onQueryChange:r,onToggleSelection:o,onToggleShown:l,onCite:c,onEdit:d,onDelete:u,onMoveSourceToFolder:h,onGenerateBibliography:g,onDeleteSelected:m,onAddSource:p,draggedSourceId:j,onDragSource:x,isLoading:v})=>{const{t:_}=n(),f=e.map(e=>e.id),y=f.length>0&&f.every(e=>t.includes(e)),M=t.filter(e=>f.includes(e)).length,b=s.trim().length>0;return(0,qe.jsxs)($e,{padded:!1,style:{borderRadius:"var(--radius-card, 16px)"},children:[(0,qe.jsxs)("div",{className:O,children:[(0,qe.jsx)(Fe,{checked:y,disabled:0===f.length,onChange:()=>l(f,!y)}),(0,qe.jsxs)("label",{className:`${L} ${A}`,children:[(0,qe.jsx)(Te,{name:"search",size:14}),(0,qe.jsx)("input",{type:"search",className:$,value:s,onChange:e=>r(e.target.value),placeholder:_("citationManager.searchSources","Search sources"),"aria-label":_("citationManager.searchSources","Search sources")})]}),(0,qe.jsx)("span",{className:P}),M>0?(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsxs)("span",{className:R,children:[M," ",_(1===M?"citationManager.itemSelected":"citationManager.itemsSelected")]}),(0,qe.jsx)(ze,{variant:"primary",size:"sm",icon:"list",onClick:g,children:_("citationManager.generateBibliography")}),(0,qe.jsx)(Pe,{content:_("citationManager.deleteSelectedShort","Delete selected"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"trash-2",label:_("citationManager.deleteSelectedShort","Delete selected"),size:"sm",onClick:m})})]}):null]}),0===e.length?v?(0,qe.jsxs)("div",{className:te,children:[(0,qe.jsx)("span",{className:ie,children:(0,qe.jsx)(Te,{name:"loader",size:20,strokeWidth:1.5})}),(0,qe.jsx)("p",{className:se,children:_("citationManager.loading","Loading sourcesâ¦")})]}):b?(0,qe.jsxs)("div",{className:te,children:[(0,qe.jsx)("span",{className:ie,children:(0,qe.jsx)(Te,{name:"search-x",size:20,strokeWidth:1.5})}),(0,qe.jsx)("p",{className:se,children:_("citationManager.noMatch","No source matches â{{query}}â.",{query:s.trim()})})]}):(0,qe.jsxs)("div",{className:te,children:[(0,qe.jsx)("span",{className:ie,children:(0,qe.jsx)(Te,{name:"quote",size:20,strokeWidth:1.5})}),(0,qe.jsx)("strong",{className:ne,children:_("citationManager.emptyTitle","No sources here yet")}),(0,qe.jsx)("p",{className:se,children:_("citationManager.emptyHint","Paste a DOI, URL or ISBN and we'll fill in the details.")}),(0,qe.jsx)(ze,{variant:"secondary",size:"sm",icon:"plus",onClick:p,children:_("citationManager.addFirstSource")})]}):(0,qe.jsx)("div",{className:q,children:e.map(e=>{const i=t.includes(e.id),n=[B];i&&n.push(U),j===e.id&&n.push(W);const s=function(e){if(e.journal)return e.journal;if(e.publisher)return e.publisher;if(e.url)try{return new URL(e.url).hostname.replace(/^www\./,"")}catch{return e.url}return""}(e),r=function(e){return e&&0!==e.length?1===e.length?e[0]:2===e.length?`${e[0]} & ${e[1]}`:`${e[0]} et al.`:""}(e.authors);return(0,qe.jsxs)("div",{className:n.join(" "),draggable:!0,onDragStart:a=>{x(e.id),a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text/plain",e.id)},onDragEnd:()=>x(null),children:[(0,qe.jsx)(Fe,{checked:i,onChange:()=>o(e.id)}),(0,qe.jsx)("span",{className:H,children:(0,qe.jsx)(Te,{name:Ve[e.type]||"file-text",size:16})}),(0,qe.jsxs)("span",{className:K,children:[(0,qe.jsx)("strong",{className:G,t
1itle:e.title,children:e.title}),(0,qe.jsxs)("span",{className:Q,children:[r?`${r} · `:null,e.year?(0,qe.jsxs)(qe.Fragment,{children:[(0,qe.jsx)("span",{className:V,children:e.year}),s?" · ":null]}):null,s]})]}),(0,qe.jsxs)("span",{className:J,children:[(0,qe.jsx)(ze,{variant:"secondary",size:"sm",icon:"quote",onClick:()=>c(e.id),children:_("citationManager.cite")}),(0,qe.jsx)(Pe,{content:_("citationManager.edit"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"pencil",label:_("citationManager.edit"),size:"sm",onClick:()=>d(e)})}),(0,qe.jsx)(Je,{folders:a,currentFolderId:e.folderId||null,onMove:a=>h(e.id,a)}),(0,qe.jsx)(Pe,{content:_("citationManager.delete"),side:"bottom",children:(0,qe.jsx)(Le,{icon:"trash-2",label:_("citationManager.delete"),size:"sm",onClick:()=>u(e.id)})})]})]},e.id)})}),i&&j?(0,qe.jsx)(Xe,{onDrop:()=>h(j,null)}):null]})},Ze=(e,a)=>{r[e](a)},ea=()=>{const{t:e,i18n:a}=n(),[t,i]=(0,v.useState)([]),[r,o]=(0,v.useState)([]),[l,c]=(0,v.useState)(!1),[d,u]=(0,v.useState)(!1),[h,g]=(0,v.useState)(!1),[m,p]=(0,v.useState)(!1),[S,C]=(0,v.useState)([]),[k,I]=(0,v.useState)(null),[D,E]=(0,v.useState)(null),[z,F]=(0,v.useState)(null),[T,L]=(0,v.useState)(""),[$,A]=(0,v.useState)(null);v.useEffect(()=>{document.title=e("citationManager.pageTitle")},[a.language,e]),(0,v.useEffect)(()=>{(async()=>{try{await O(),await P()}catch(e){}})()},[a.language]),(0,v.useEffect)(()=>{0!==t.length?C(e=>{const a=new Set(t.map(e=>e.id)),i=e.filter(e=>a.has(e));return i.length!==e.length?i:e}):C([])},[t]);const O=async()=>{c(!0);try{const e=await s.http.instance.get("/api/v2/sources"),a=Array.isArray(e.data)?[...e.data]:e.data;i(a)}catch(a){Ze("error",e("citationManager.toast.loadError"))}finally{c(!1)}},P=async()=>{try{const e=await s.http.instance.get("/api/v2/folders"),a=Array.isArray(e.data)?[...e.data]:e.data;o(a)}catch(e){}},R=z?t.filter(e=>(e.folderId||null)===z):t.filter(e=>!e.folderId),q=(()=>{const e=R.map(e=>e.id);return S.filter(a=>e.includes(a))})(),B=T.trim().toLowerCase(),U=B?R.filter(e=>`${e.title} ${(e.authors||[]).join(" ")} ${e.publisher||""} ${e.journal||""}`.toLowerCase().includes(B)):R,W=async(a,i)=>{A(null);const n=t.find(e=>e.id===a);if(!n||(n.folderId?n.folderId:null)!==i)try{const t=null===i?{folderId:null}:{folderId:i};await s.http.instance.put(`/api/v2/sources/${a}`,t),await Promise.all([O(),P()]),Ze("success",e("citationManager.toast.moveSuccess"))}catch(r){Ze("error",r.response?.data?.message||e("citationManager.toast.moveError"))}};x((0,qe.jsx)(qe.Fragment,{children:(0,qe.jsx)(Pe,{content:e("citationManager.addSource"),side:"bottom",children:(0,qe.jsx)(ze,{variant:"primary",size:"sm",icon:"plus",onClick:()=>{E(null),u(!0)},children:e("citationManager.addSource")})})}),[e]);const H=t.length;return(0,qe.jsxs)("div",{className:_,children:[(0,qe.jsxs)("header",{className:f,children:[(0,qe.jsx)("h1",{className:y,children:e("citationManager.title")}),(0,qe.jsx)("p",{className:M,children:e("citationManager.description")}),(0,qe.jsxs)("div",{className:b,children:[(0,qe.jsx)("span",{children:e("citationManager.sourceCount",{count:H,defaultValue:"{{count}} sources"})}),(0,qe.jsx)("span",{className:N,children:"·"}),(0,qe.jsx)("span",{children:e("citationManager.folderCount",{count:r.length,defaultValue:"{{count}} folders"})})]})]}),(0,qe.jsxs)("div",{className:w,children:[(0,qe.jsx)(Qe,{folders:r,selectedFolderId:z,countFor:e=>null===e?t.filter(e=>!e.folderId).length:t.filter(a=>(a.folderId||null)===e).length,onSelect:F,onCreate:async a=>{try{await s.http.instance.post("/api/v2/folders",{name:a}),Ze("success",e("citationManager.toast.folderCreated")),P()}catch(t){Ze("error",t.response?.data?.message||e("citationManager.toast.folderCreateError"))}},onDelete:async a=>{if(window.confirm(e("citationManager.confirmDeleteFolder")))try{await s.http.instance.delete(`/api/v2/folders/${a}`),Ze("success",e("citationManager.toast.folderDeleted")),P(),O(),z===a&&F(null)}catch(t){Ze("error",t.response?.data?.message||e("citationManager.toast.folderDeleteError"))}},onDropSource:e=>{$&&W($,e)},dragActive:!!$}),(0,qe.jsx)(Ye,{sources:U,folders:r,selectedSourceIds:S,selectedFolderId:z,query:T,onQueryChange:L,onToggleSelection:e=>{C(a=>a.includes(e)?a.filter(a=>a!==e):[...a,e])},onToggleShown:(e,a)=>{C(t=>a?Array.from(new Set([...t,...e])):t.filter(a=>!e.includes(a)))},onCite:e=>{C([e]),g(!0)},onEdit:e=>{E(e),u(!0)},onDelete:e=>{I(e)},onMoveSourceToFolder:W,onGenerateBibliography:()=>{0!==q.length?(C(q),g(!0)):Ze("info",e("citationManager.toast.selectSources"))},onDeleteSelected:()=>{0!==S.length&&p(!0)},onAddSource:()=>{E(null),u(!0)},draggedSourceId:$,onDragSource:A,isLoading:l})]}),d&&(0,qe.jsx)(We,{isOpen:d,onClose:()=>{u(!1),E(null)},onSave:async a=>{try{D?(await s.http.instance.put(`/api/v2/sources/${D.id}`,a),Ze("success",e("citationManager.toast.updateSuccess"))):(await s.http.instance.post("/api/v2/sources",a),Ze("success",e("citationManager.toast.addSuccess"))),u(!1),E(null),await O(),await P(),a.folderId&&F(a.folderId)}catch(t){Ze("error",t.response?.data?.message||e("citationManager.toast.saveError"))}},editingSource:D,folders:r,onFoldersUpdate:P}),h&&(0,qe.jsx)(Ke,{isOpen:h,onClose:()=>{g(!1);const e=R.map(e=>e.id);C(S.filter(a=>!e.includes(a)))},sourceIds:q}),m&&(0,qe.jsx)(Ge,{isOpen:m,onClose:()=>p(!1),onConfirm:async()=>
1{if(0===q.length)return;const a=[...q];try{await Promise.all(a.map(e=>s.http.instance.delete(`/api/v2/sources/${e}`))),Ze("success",e("citationManager.toast.deleteSelectedSuccess",{count:a.length})),C(S.filter(e=>!a.includes(e))),await O()}catch(t){Ze("error",t.response?.data?.message||e("citationManager.toast.deleteSelectedError"))}},count:q.length,isFolder:!!z}),k&&(0,qe.jsx)(j,{close:()=>I(null),deleteHandler:async()=>{if(!k)return;const a=k;I(null);try{await s.http.instance.delete(`/api/v2/sources/${a}`),Ze("success",e("citationManager.toast.deleteSuccess")),C(e=>e.filter(e=>e!==a)),await O()}catch(t){Ze("error",e("citationManager.toast.deleteError"))}}})]})};export{ea as CitationManager,ea as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.