book-index-ui 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +575 -20
- package/dist/index.js +4066 -2271
- package/dist/storage-entry-0bL59zPV.js +1488 -0
- package/dist/storage-entry-C5i8mBl3.cjs +1 -0
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +138 -20
- package/dist/storage.js +1 -1
- package/package.json +4 -3
- package/dist/__vite-optional-peer-dep_opencc-js_book-index-ui-BcPniuRQ.cjs +0 -1
- package/dist/__vite-optional-peer-dep_opencc-js_book-index-ui-DYxpcVy9.js +0 -4
- package/dist/storage-entry-Cq3ff6VP.js +0 -1316
- package/dist/storage-entry-DC1qzCnq.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("./storage-entry-DC1qzCnq.cjs"),e=require("react/jsx-runtime"),d=require("react");function _t(t){if(!t)return"";try{const n=new URL(t).hostname,r={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(r[n])return r[n];const i=n.split(".");return i.length>=2?i[i.length-2]:n}catch{return""}}const Be=[{value:"text",label:"文字"},{value:"image",label:"图片"},{value:"text+image",label:"文字+图片"},{value:"physical",label:"实体"}],Rt=[{value:"catalog",label:"目录式"},{value:"search",label:"搜索式"}];function Et(){return{id:"",name:"",url:"",type:"text",details:""}}const we=({items:t,onChange:n,onDownload:r,downloadStatuses:i,filterType:s})=>{const[o,c]=d.useState(null),l=g=>s?s==="text"?g==="text"||g==="text+image":s==="image"?g==="image"||g==="text+image"||g==="physical":g===s:!0,x=t.map((g,y)=>({item:g,originalIndex:y})).filter(({item:g})=>l(g.type)),b=()=>{const g=Et();s&&(g.type=s),n([...t,g]),c(t.length)},p=g=>{n(t.filter((y,w)=>w!==g)),c(null)},a=(g,y,w)=>{const C=[...t];if(C[g]={...C[g],[y]:w},y==="url"&&!C[g].id){const m=_t(w);m&&(C[g].id=m)}n(C)},f=(g,y)=>{const w=y.trim()?y.split(/[,,、]/).map(C=>C.trim()).filter(Boolean):void 0;a(g,"structure",w)},v=(g,y,w)=>{const m=t[g].coverage||{level:1,ranges:""};y==="level"?m.level=parseInt(w)||1:m.ranges=w,a(g,"coverage",m.ranges?m:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:g,originalIndex:y})=>{var w,C,m,I;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(o===y?null:y),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:o===y?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Bt(g.type),color:"#fff"},children:((w=Be.find(h=>h.value===g.type))==null?void 0:w.label)||g.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:g.name||`资源 ${y+1}`}),g.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:g.id}),g.url&&e.jsx("a",{href:g.url,target:"_blank",rel:"noopener noreferrer",onClick:h=>h.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&g.url&&Tt(y,i==null?void 0:i[y],r),e.jsx("button",{onClick:h=>{h.stopPropagation(),p(y)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:"删除此资源",children:"✕"})]}),o===y&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(g.type==="image"||g.type==="text+image")&&g.url&&Wt(g),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pe,children:[e.jsx("span",{style:xe,children:"类型"}),e.jsx("select",{value:g.type,onChange:h=>a(y,"type",h.target.value),style:{...ee,flex:1},children:Be.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("label",{style:pe,children:[e.jsx("span",{style:xe,children:"根类型"}),e.jsx("select",{value:g.root_type||"catalog",onChange:h=>a(y,"root_type",h.target.value),style:{...ee,flex:1},children:Rt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:g.id,onChange:h=>a(y,"id",h.target.value),placeholder:"ID (自动从URL提取)",style:{...ee,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:g.name,onChange:h=>a(y,"name",h.target.value),placeholder:"资源名称",style:{...ee,flex:1}})]}),e.jsx("input",{type:"text",value:g.url,onChange:h=>a(y,"url",h.target.value),placeholder:"资源链接 (URL)",style:ee}),e.jsx("input",{type:"text",value:((C=g.structure)==null?void 0:C.join("、"))||"",onChange:h=>f(y,h.target.value),placeholder:"层级结构 (如: 册、卷)",style:ee}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pe,children:[e.jsx("span",{style:xe,children:"覆盖层级"}),e.jsx("input",{type:"number",min:1,value:((m=g.coverage)==null?void 0:m.level)??"",onChange:h=>v(y,"level",h.target.value),placeholder:"1",style:{...ee,width:"60px"}})]}),e.jsxs("label",{style:{...pe,flex:1},children:[e.jsx("span",{style:xe,children:"覆盖范围"}),e.jsx("input",{type:"text",value:((I=g.coverage)==null?void 0:I.ranges)||"",onChange:h=>v(y,"ranges",h.target.value),placeholder:"如: 2,3,5-8",style:{...ee,flex:1}})]})]}),e.jsx("textarea",{value:g.details||"",onChange:h=>a(y,"details",h.target.value),placeholder:"详细说明",style:{...ee,minHeight:"60px",resize:"vertical"}})]})]})]},y)}),e.jsxs("button",{onClick:b,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:"添加资源"})]})]})};function Bt(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Tt(t,n,r){const i=(n==null?void 0:n.status)==="downloading",s=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:o=>{o.stopPropagation(),i||r(t,"")},disabled:i,style:{background:"transparent",border:"none",color:s?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:s?"下载完成":i?`下载中 ${(n==null?void 0:n.progress)||0}%`:"下载此资源",children:s?"✓":i?"⏳":"⬇"})}function Wt(t){const n=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:n?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:"图片资源链接"})})}const ee={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},pe={display:"flex",alignItems:"center",gap:"6px"},xe={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Lt={text:"文字资源",image:"图片资源","text+image":"文字+图片资源",physical:"实体资源"},Te={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},$t=["text","image","text+image","physical"],_e=({items:t,groupByType:n=!0})=>{if(!t||t.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:"暂无资源信息"});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.map((i,s)=>e.jsx(We,{item:i},i.id||s))});const r=$t.map(i=>({type:i,items:t.filter(s=>s.type===i)})).filter(i=>i.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:r.map(({type:i,items:s})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Te[i],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Te[i]}}),Lt[i],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",s.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:s.map((o,c)=>e.jsx(We,{item:o},o.id||c))})]},i))})},We=({item:t})=>e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:t.details||t.structure?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:t.name}),t.url&&e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:"访问 →"})]}),(t.details||t.structure||t.coverage)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.details&&e.jsx("span",{children:t.details}),t.structure&&e.jsxs("span",{children:["层级: ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:["覆盖: L",t.coverage.level," ",t.coverage.ranges]})]})]}),qe=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:i,onToggleDraft:s,onConfigurePath:o,onSelectFolder:c})=>{const l=t==="local",x=(n==null?void 0:n.isDraft)??!0,b=(n==null?void 0:n.repoPath)||"",p=b?b.split(/[/\\]/).pop()||b:"",a={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},f={onMouseOver:g=>g.currentTarget.style.opacity="0.8",onMouseOut:g=>g.currentTarget.style.opacity="1"},v=e.jsxs("div",{onClick:s,title:`点击切换到 ${x?"official":"draft"} 仓库`,style:{...a,background:x?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...f,children:[e.jsx("span",{children:x?"📝":"📚"}),e.jsx("span",{children:x?"draft":"official"})]});return r==="index-browser"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[v,e.jsxs("div",{onClick:i,title:"点击切换到同步模式",style:a,...f,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:"本地模式"}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:c,title:b||"选择本地文件夹",style:{...a,paddingLeft:"8px",paddingRight:"8px"},...f,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[v,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:i,title:"点击切换到本地模式",style:a,...f,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:"同步模式:"}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:o,title:p||"配置同步路径",style:{...a,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:i,title:l?"点击切换到 GitHub 同步模式":"点击切换到本地模式",style:a,...f,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?"本地模式":"GitHub 同步"}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:c,title:b||"选择本地文件夹",style:{...a,paddingLeft:"8px",paddingRight:"8px",minWidth:b?"100px":"auto",justifyContent:"space-between"},...f,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!l&&p&&e.jsxs("div",{style:{...a,background:"#2196f3",color:"white",cursor:"default"},title:b,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:p})]})]})},he="bim-search-history",Le=10,$e=8;function ce(){try{const t=localStorage.getItem(he);return t?JSON.parse(t):[]}catch{return[]}}function At(t){try{const n=ce().filter(r=>r!==t);n.unshift(t),n.length>Le&&(n.length=Le),localStorage.setItem(he,JSON.stringify(n))}catch{}}function Ht(t){try{const n=ce().filter(r=>r!==t);localStorage.setItem(he,JSON.stringify(n))}catch{}}function Ft(){try{localStorage.removeItem(he)}catch{}}const Pt={work:"作品",book:"书籍",collection:"丛编"},Qe=({transport:t,value:n,onChange:r,onSearch:i,onEntrySelect:s,placeholder:o="搜索作品、书籍、丛编..."})=>{const[c,l]=d.useState(!1),[x,b]=d.useState([]),[p,a]=d.useState(-1),[f,v]=d.useState(null),[g,y]=d.useState(ce),w=d.useRef(null),C=d.useRef(null),m=d.useRef(null);d.useEffect(()=>{if(!t.getAllEntries)return;let u=!1;return t.getAllEntries().then(k=>{u||v(k)}).catch(()=>{}),()=>{u=!0}},[t]);const I=d.useCallback(u=>{if(!u.trim())return g.map(A=>({type:"history",text:A}));if(!f)return[];const k=u.toLowerCase(),B=[],W=[];for(const A of f){if(B.length+W.length>=$e*2)break;const $=A.title.toLowerCase();if($.startsWith(k))B.push({type:"entry",text:A.title,entry:A});else if($.includes(k))W.push({type:"entry",text:A.title,entry:A});else if(A.additional_titles){for(const L of A.additional_titles)if(L.toLowerCase().includes(k)){B.push({type:"entry",text:`${A.title}`,entry:A});break}}}return[...B,...W].slice(0,$e)},[f,g]);d.useEffect(()=>{b(I(n)),a(-1)},[n,I]),d.useEffect(()=>{const u=k=>{m.current&&!m.current.contains(k.target)&&l(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]),d.useEffect(()=>{const u=k=>{var B,W;if(k.key==="/"&&document.activeElement!==w.current){const A=(B=document.activeElement)==null?void 0:B.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return;k.preventDefault(),(W=w.current)==null||W.focus()}};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[]);const h=d.useCallback(u=>{u.trim()&&(At(u.trim()),y(ce())),i(u),l(!1)},[i]),j=d.useCallback(u=>{u.type==="history"?(r(u.text),h(u.text)):u.entry&&(s?(s(u.entry),l(!1)):(r(u.text),h(u.text)))},[r,h,s]),z=d.useCallback(u=>{if(!c||x.length===0){u.key==="Enter"&&h(n);return}switch(u.key){case"ArrowDown":u.preventDefault(),a(k=>(k+1)%x.length);break;case"ArrowUp":u.preventDefault(),a(k=>(k-1+x.length)%x.length);break;case"Enter":u.preventDefault(),p>=0&&p<x.length?j(x[p]):h(n);break;case"Escape":u.preventDefault(),l(!1);break}},[c,x,p,n,h,j]),_=d.useCallback((u,k)=>{k.stopPropagation(),Ht(u),y(ce()),b(B=>B.filter(W=>!(W.type==="history"&&W.text===u)))},[]),R=d.useCallback(u=>{u.stopPropagation(),Ft(),y([]),b([])},[]);d.useEffect(()=>{if(p>=0&&C.current){const u=C.current.children;u[p]&&u[p].scrollIntoView({block:"nearest"})}},[p]);const M=!n.trim()&&g.length>0;return e.jsxs("div",{ref:m,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:w,type:"text",placeholder:o,value:n,onChange:u=>{r(u.target.value),l(!0)},onFocus:()=>l(!0),onKeyDown:z,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),c&&x.length>0&&e.jsxs("div",{ref:C,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[M&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:"搜索历史"}),e.jsx("button",{onClick:R,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:"清除全部"})]}),x.map((u,k)=>e.jsxs("div",{onClick:()=>j(u),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:k===p?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:u.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.text}),u.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[Pt[u.entry.type],u.entry.author&&` · ${u.entry.author}`]}),u.type==="history"&&e.jsx("button",{onClick:B=>_(u.text,B),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:"删除",children:"×"})]},`${u.type}-${u.text}-${k}`))]})]})},Ce="bim-recent-ids",Ae="bim-recent-entries",He=50,ve=5,Ot=50,Mt=200;function ze(){try{const t=localStorage.getItem(Ce);if(t)return JSON.parse(t);const n=localStorage.getItem(Ae);if(n){const r=JSON.parse(n).map(i=>i.id);return localStorage.setItem(Ce,JSON.stringify(r)),localStorage.removeItem(Ae),r}return[]}catch{return[]}}function Ut(t){try{const n=ze().filter(r=>r!==t);n.unshift(t),n.length>He&&(n.length=He),localStorage.setItem(Ce,JSON.stringify(n))}catch{}}const Fe=[{type:"work",icon:"✍️",name:"作品",key:"works"},{type:"book",icon:"📖",name:"书籍",key:"books"},{type:"collection",icon:"📚",name:"丛编",key:"collections"}],Yt={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},et=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:i,onNewEntry:s,onSwitchMode:o,onToggleDraft:c,onConfigurePath:l,onSelectFolder:x,hideModeIndicator:b,initialQuery:p,onQueryChange:a})=>{const[f,v]=d.useState(p??""),[g,y]=d.useState(null),[w,C]=d.useState(null),[m,I]=d.useState(!1),[h,j]=d.useState(null),[z,_]=d.useState(""),[R,M]=d.useState(!p),[u,k]=d.useState(ze),[B,W]=d.useState([]),[A,$]=d.useState(!1),L=d.useRef(void 0),U=d.useRef(!1),H=d.useCallback(async(E,P)=>{if(!E.trim()){M(!0),y(null),C(null);return}M(!1),I(!0),_("");try{if(t.searchAll){const T=await t.searchAll(E,P??ve);y(T)}else{const T=["work","book","collection"],N=await Promise.all(T.map(Q=>t.search(E,Q,{page:1,pageSize:P??ve})));y({works:N[0].entries,books:N[1].entries,collections:N[2].entries,totalWorks:N[0].total,totalBooks:N[1].total,totalCollections:N[2].total})}}catch(T){_(T instanceof Error?T.message:String(T)),y(null)}finally{I(!1)}},[t]);d.useEffect(()=>{U.current||!(p!=null&&p.trim())||(U.current=!0,H(p))},[p,H]);const O=d.useCallback(E=>{if(v(E),a==null||a(E),!E.trim()){M(!0),y(null),C(null);return}L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{C(null),H(E)},Mt)},[H,a]),J=d.useCallback(E=>{L.current&&clearTimeout(L.current),a==null||a(E),H(E)},[H,a]),be=d.useCallback(E=>{C(E),H(f,Ot)},[f,H]);d.useEffect(()=>{if(!u.length){W([]);return}let E=!1;return $(!0),Promise.all(u.slice(0,8).map(async P=>{var T,N,Q;try{if(t.getEntry){const Y=await t.getEntry(P);if(Y)return Y}const ie=await t.getItem(P);if(ie){const Y=ie.authors;return{id:P,title:ie.title||P,type:ie.type||"work",author:(T=Y==null?void 0:Y[0])==null?void 0:T.name,dynasty:(N=Y==null?void 0:Y[0])==null?void 0:N.dynasty,role:(Q=Y==null?void 0:Y[0])==null?void 0:Q.role}}}catch{}return null})).then(P=>{E||(W(P.filter(T=>T!==null)),$(!1))}),()=>{E=!0}},[u,t]);const le=E=>{j(E.id),Ut(E.id),k(ze()),i==null||i(E)},X=E=>Fe.find(P=>P.type===E),me=g&&(g.works.length>0||g.books.length>0||g.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:"索引浏览器"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:"浏览和管理古籍元数据"})]}),!b&&e.jsx(qe,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:o,onToggleDraft:c,onConfigurePath:l,onSelectFolder:x})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Qe,{transport:t,value:f,onChange:O,onSearch:J,onEntrySelect:le}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:"+ 新建"})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:m?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:"搜索中..."}):z?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:z})]}):R?e.jsx("div",{style:{flex:1},children:A?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:"加载中..."}):B.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:"最近浏览"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:B.map(E=>e.jsx(Pe,{entry:E,selected:h===E.id,onClick:le,getConfig:X},E.id))})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:"搜索古籍索引"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"输入关键词搜索作品、书籍或丛编"})]})}):me?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:Fe.map(({type:E,icon:P,name:T,key:N})=>{const Q=g[N],ie=Yt[N],Y=g[ie];if(Q.length===0)return null;const ye=!(w===E)&&Y>ve;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[P," ",T,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[Y," 条"]})]}),ye&&e.jsx("button",{onClick:()=>be(E),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:"查看全部 →"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(ae=>e.jsx(Pe,{entry:ae,selected:h===ae.id,onClick:le,getConfig:X,query:f},ae.id))})]},E)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsxs("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:["未找到与「",f,"」相关的结果"]}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"试试其他关键词、别名或作者名"})]})})]})},Pe=({entry:t,selected:n,onClick:r,getConfig:i,query:s})=>{const o=s&&t.additional_titles?t.additional_titles.find(c=>c.toLowerCase().includes(s.toLowerCase())):void 0;return e.jsxs("div",{onClick:()=>r(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsx("span",{style:{fontSize:"16px",marginTop:"2px"},children:i(t.type).icon}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:t.title}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:"文字资源",children:"📝"}),t.has_image&&e.jsx("span",{title:"图片资源",children:"🖼️"})]}),t.juan_count!=null&&t.juan_count>0&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,"卷"]})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",t.dynasty,"〕"]}),t.author&&e.jsx("span",{children:t.author}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",t.role]})]}),o&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:["别名:",o]})]}),e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},Dt={book:"书籍",work:"作品",collection:"丛编"},Nt=["〇","一","二","三","四","五","六","七","八","九"],Oe=["","十","百","千"];function tt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let i="",s=!1;for(let o=0;o<r;o++){const c=parseInt(n[o]),l=r-1-o;c===0?s=!0:(s&&i&&(i+="〇"),s=!1,c===1&&l===1&&o===0?i+=Oe[l]:i+=Nt[c]+Oe[l])}return i}function nt({type:t}){const n={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:n[t],border:`1px solid ${n[t]}40`,borderRadius:"2px",background:`${n[t]}08`},children:Dt[t]})}function Gt({isDraft:t}){return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?"草稿":"正式"})}function Jt({id:t}){const[n,r]=d.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px 3px 10px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px"},children:[e.jsx("span",{children:"ID:"}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"12px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:n?"已复制":"复制 ID",style:{cursor:"pointer",fontSize:"13px",opacity:n?1:.5,transition:"opacity 0.15s"},onMouseEnter:s=>s.currentTarget.style.opacity="1",onMouseLeave:s=>s.currentTarget.style.opacity=n?"1":"0.5",children:n?"✓":"⧉"})]})}function K({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function q({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function it({authors:t,type:n}){return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,i)=>e.jsxs("span",{children:[i>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",r.dynasty,"〕"]}),e.jsx("span",{style:{fontWeight:500},children:r.name}),r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",r.role]})]},i))})}function ne({id:t,label:n,onNavigate:r,renderLink:i}){return i?e.jsx(e.Fragment,{children:i(t,n)}):r?e.jsx("span",{onClick:()=>r(t),style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Vt({id:t,title:n,type:r,isDraft:i,authors:s,volumeText:o,meta:c,headerExtra:l}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[e.jsxs("h1",{style:{fontSize:"24px",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:o})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0,paddingTop:"4px"},children:[e.jsx(nt,{type:r}),e.jsx(Gt,{isDraft:i}),e.jsx(Jt,{id:t}),l]})]}),((s==null?void 0:s.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[s&&s.length>0&&e.jsx(it,{authors:s,type:r}),c]})]})}function Kt({items:t,onNavigate:n,renderLink:r}){if(!t.length)return null;const[i,s]=d.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"收录"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((o,c)=>{const l=i===c;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...l?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>s(l?null:c),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:o.source}),!l&&o.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o.title_info}),o.source_bid&&e.jsx("span",{onClick:x=>x.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ne,{id:o.source_bid,label:"查看 →",onNavigate:n,renderLink:r})})]}),l&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(o.title_info||o.author_info||o.version)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[o.title_info&&e.jsx(q,{label:"题名",children:o.title_info}),o.author_info&&e.jsx(q,{label:"著者",children:o.author_info}),o.version&&e.jsx(q,{label:"版本",children:o.version})]}),o.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:o.summary})]}),o.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o.comment})]}),o.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o.additional_comment})]})]})]},c)})})]})}function Xt({items:t}){return t.length?e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"别名"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((n,r)=>e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:n},r))})]}):null}function Zt({items:t}){return t.length?e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"附录"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((n,r)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",n.book_title,"》",n.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[n.n_juan,"卷"]})]},r))})]}):null}function qt({items:t}){return t.length?e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"流转历史"}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((n,r)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:n.name}),n.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:n.description})]},r))]})]}):null}function Qt({items:t}){return t.length?e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"历史沿革"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((n,r)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),n]},r))})]}):null}function Me({title:t,ids:n,transport:r,onNavigate:i,renderLink:s}){const[o,c]=d.useState([]);return d.useEffect(()=>{if(!n.length){c([]);return}if(!r){c(n.map(x=>({id:x})));return}let l=!1;return Promise.all(n.map(x=>r.getItem(x).then(b=>({id:x,title:b?b.title:void 0,version:b?b.version:void 0,type:b?b.type:void 0})).catch(()=>({id:x})))).then(x=>{l||c(x)}),()=>{l=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(K,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(o.length?o:n.map(l=>({id:l}))).map(l=>{const x=l.version?`${l.title||l.id}(${l.version})`:l.title||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ne,{id:l.id,label:x,onNavigate:i,renderLink:s})},l.id)})})]}):null}function en({ids:t,transport:n,onNavigate:r,renderLink:i}){const[s,o]=d.useState([]);return d.useEffect(()=>{if(!t.length){o([]);return}if(!n){o(t.map(l=>({id:l})));return}let c=!1;return Promise.all(t.map(l=>n.getItem(l).then(x=>({id:l,title:x?x.title:void 0,version:x?x.version:void 0,resources:x?x.resources:void 0})).catch(()=>({id:l})))).then(l=>{c||o(l)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(K,{children:["相关版本",e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(s.length?s:t.map(c=>({id:c}))).map(c=>{var x;const l=c.version?`${c.title||c.id}(${c.version})`:c.title||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsx("div",{style:{padding:"10px 14px",borderBottom:(x=c.resources)!=null&&x.length?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:e.jsx(ne,{id:c.id,label:l,onNavigate:r,renderLink:i})}),c.resources&&c.resources.length>0&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(_e,{items:c.resources,groupByType:!0})})]},c.id)})})]}):null}function tn({workData:t,onNavigate:n,renderLink:r}){var i,s,o;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(nt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ne,{id:t.id,label:t.title,onNavigate:n,renderLink:r})}),((i=t.juan_count)==null?void 0:i.number)&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[tt(t.juan_count.number),"卷"]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(it,{authors:t.authors,type:"work"}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(o=t.authors)!=null&&o.length?"8px 0 0":"0",textAlign:"justify"},children:t.description.text}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(q,{label:"上级作品",children:e.jsx(ne,{id:t.parent_work.id,label:t.parent_work.title,onNavigate:n,renderLink:r})})})]})]})}function nn({items:t,onNavigate:n,renderLink:r}){return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:"丛编"}),e.jsx(ne,{id:i.id,label:i.title||i.id,onNavigate:n,renderLink:r}),i.volume_index!=null&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:["第",i.volume_index,"册"]})]},i.id))}):null}const rt=({data:t,id:n,transport:r,onNavigate:i,renderLink:s,headerExtra:o,className:c,style:l})=>{var M,u,k,B,W,A;const[x,b]=d.useState(null),[p,a]=d.useState(!1),[f,v]=d.useState(null),[g,y]=d.useState(null),[w,C]=d.useState([]),m=t||x;if(d.useEffect(()=>{if(t||!n||!r)return;let $=!1;return a(!0),v(null),r.getItem(n).then(L=>{$||(L?b(L):v("未找到该条目"))}).catch(L=>{$||v(L instanceof Error?L.message:"加载失败")}).finally(()=>{$||a(!1)}),()=>{$=!0}},[t,n,r]),d.useEffect(()=>{if(!m||!r){y(null),C([]);return}let $=!1;if(m.type==="book"){const L=m;L.work_id?r.getItem(L.work_id).then(U=>{!$&&U&&U.type==="work"&&y(U)}).catch(()=>{}):y(null),L.contained_in&&L.contained_in.length>0?Promise.all(L.contained_in.map(U=>{const H=typeof U=="string"?U:U.id,O=typeof U=="string"?void 0:U.volume_index;return r.getItem(H).then(J=>({id:H,title:J&&J.title||H,volume_index:O})).catch(()=>({id:H,title:H,volume_index:O}))})).then(U=>{$||C(U)}):C([])}else y(null),C([]);return()=>{$=!0}},[m,r]),p)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map(($,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${$}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(f)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f});if(!m)return null;const I=m.type==="book"?m:null,h=m.type==="collection"?m:null,j=m.type==="work"?m:null;let z=!1;try{z=F.extractStatus(m.id)==="draft"}catch{}let _="";(M=m.juan_count)!=null&&M.number?_=tt(m.juan_count.number)+"卷":(u=m.juan_count)!=null&&u.description&&(_=m.juan_count.description);const R=[];return(k=m.publication_info)!=null&&k.year&&R.push(e.jsx(q,{label:"年代",children:m.publication_info.year},"year")),(B=m.current_location)!=null&&B.name&&R.push(e.jsx(q,{label:"现藏",children:m.current_location.name},"loc")),(W=m.page_count)!=null&&W.description&&R.push(e.jsx(q,{label:"页",children:m.page_count.description},"page")),I!=null&&I.version&&R.push(e.jsx(q,{label:"版本",children:I.version},"ver")),j!=null&&j.parent_work&&R.push(e.jsx(q,{label:"上级作品",children:e.jsx(ne,{id:j.parent_work.id,label:j.parent_work.title,onNavigate:i,renderLink:s})},"pw")),j!=null&&j.parent_works&&j.parent_works.length>0&&!j.parent_work&&R.push(e.jsx(q,{label:"上级作品",children:j.parent_works.map(($,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(ne,{id:$,onNavigate:i,renderLink:s})]},$))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(Vt,{id:m.id,title:m.title,type:m.type,isDraft:z,authors:m.authors,volumeText:_,meta:R,headerExtra:o}),((A=m.description)==null?void 0:A.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:m.description.text}),w.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"收录于"}),e.jsx(nn,{items:w,onNavigate:i,renderLink:s})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"所属作品"}),e.jsx(tn,{workData:g,onNavigate:i,renderLink:s})]}),m.additional_works&&m.additional_works.length>0&&e.jsx(Zt,{items:m.additional_works}),m.additional_titles&&m.additional_titles.length>0&&e.jsx(Xt,{items:m.additional_titles}),m.indexed_by&&m.indexed_by.length>0&&e.jsx(Kt,{items:m.indexed_by,onNavigate:i,renderLink:s}),m.resources&&m.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(K,{children:"资源"}),e.jsx(_e,{items:m.resources,groupByType:!0})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(qt,{items:I.location_history}),(h==null?void 0:h.history)&&h.history.length>0&&e.jsx(Qt,{items:h.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx(Me,{title:"相关版本",ids:I.related_books,transport:r,onNavigate:i,renderLink:s}),(h==null?void 0:h.books)&&h.books.length>0&&e.jsx(Me,{title:"收录书籍",ids:h.books,transport:r,onNavigate:i,renderLink:s}),(j==null?void 0:j.books)&&j.books.length>0&&e.jsx(en,{ids:j.books,transport:r,onNavigate:i,renderLink:s}),(j==null?void 0:j.related_works)&&j.related_works.length>0&&(()=>{const $=[],L=j.related_works.filter(O=>O.relation==="part_of"),U=j.related_works.filter(O=>O.relation==="has_part"),H=j.related_works.filter(O=>!O.relation);return L.length>0&&$.push({label:"所属作品",items:L}),U.length>0&&$.push({label:"包含作品",items:U}),H.length>0&&$.push({label:"相关作品",items:H}),$.map(O=>e.jsxs("div",{children:[e.jsxs(K,{children:[O.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",O.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:O.items.map(J=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ne,{id:J.id,label:J.title,onNavigate:i,renderLink:s})},J.id))})]},O.label))})()]})};function rn({data:t}){const{stats:n}=t,r=t.total_volumes>0?Math.round(n.processed_volumes/t.total_volumes*100):0;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:t.title}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," 册"]}),e.jsxs("span",{children:["已处理 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:n.processed_volumes})," 册 (",r,"%)"]}),e.jsxs("span",{children:["收录 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:n.total_books})," 部"]}),e.jsxs("span",{children:["已匹配 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:n.matched_works})," 部"]}),n.unmatched_works>0&&e.jsxs("span",{children:["待匹配 ",e.jsx("strong",{style:{color:"#e67e22"},children:n.unmatched_works})," 部"]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:["来源: ",t.source]})]})}function ln({sections:t,activeSection:n,onSelect:r}){return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:Ue(n===null),children:"全部"}),t.map(i=>e.jsxs("button",{onClick:()=>r(i.name),style:Ue(n===i.name),children:[i.name,e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function Ue(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function sn({id:t,label:n,onNavigate:r,renderLink:i}){return i?e.jsx(e.Fragment,{children:i(t,n)}):r?e.jsx("span",{onClick:()=>r(t),style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function on({book:t,onNavigate:n,renderLink:r}){const i=t.book_id||t.work_id;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[e.jsx("span",{style:{flexShrink:0,width:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:t.volumes.length===1?`第${t.volumes[0]}册`:`${t.volumes[0]}–${t.volumes[t.volumes.length-1]}册`}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.title,t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.join("、"),")"]})]}),i&&e.jsx(sn,{id:i,label:t.book_id?"书籍":"作品",onNavigate:n,renderLink:r}),!i&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:"未匹配"})]})}const lt=({data:t,collectionId:n,transport:r,onNavigate:i,renderLink:s,className:o,style:c})=>{const[l,x]=d.useState(null),[b,p]=d.useState(!1),[a,f]=d.useState(null),[v,g]=d.useState(null),[y,w]=d.useState(""),C=t||l;d.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let h=!1;return p(!0),f(null),r.getCollectionCatalog(n).then(j=>{h||(j?x(j):f("未找到丛编目录数据"))}).catch(j=>{h||f(j instanceof Error?j.message:"加载失败")}).finally(()=>{h||p(!1)}),()=>{h=!0}},[t,n,r]);const m=d.useMemo(()=>{if(!C)return[];let h=C.books;if(v&&(h=h.filter(j=>j.section===v)),y.trim()){const j=y.trim().toLowerCase();h=h.filter(z=>z.title.toLowerCase().includes(j)||z.sub_items&&z.sub_items.some(_=>_.toLowerCase().includes(j)))}return h},[C,v,y]),I=d.useMemo(()=>{const h=[];let j=-1,z=[];for(const _ of m){if(!_.volumes||_.volumes.length===0)continue;const R=_.volumes[0];R!==j?(z.length>0&&h.push({volume:j,books:z}),j=R,z=[_]):z.push(_)}return z.length>0&&h.push({volume:j,books:z}),h},[m]);return b?e.jsx("div",{className:o,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载丛编目录..."})}):a?e.jsx("div",{className:o,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a}):C?e.jsxs("div",{className:o,style:c,children:[e.jsx(rn,{data:C}),e.jsx(ln,{sections:C.sections,activeSection:v,onSelect:g}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:"搜索书名...",value:y,onChange:h=>w(h.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[m.length," 部"]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[I.map((h,j)=>e.jsxs("div",{children:[e.jsxs("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:["第 ",h.volume," 册"]}),h.books.map((z,_)=>e.jsx(on,{book:z,onNavigate:i,renderLink:s},`${h.volume}-${_}`))]},`${h.volume}-${j}`)),I.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})]}):null},an=["〇","一","二","三","四","五","六","七","八","九"],Ye=["","十","百","千"],dn=["","萬","億"];function st(t){if(t===0)return"〇";if(t<0)return`負${st(-t)}`;const n=[];let r=t,i=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(cn(s,i>0)+dn[i]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),i++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function cn(t,n){const r=[];let i=t;for(;i>0;)r.unshift(i%10),i=Math.floor(i/10);let s="";for(let o=0;o<r.length;o++){const c=r[o],l=r.length-1-o;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&l===1&&o===0&&!n?s+=Ye[l]:s+=an[c]+Ye[l]}return s.replace(/〇$/,"")}const ot={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function pn(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function at({file:t,isActive:n,onSelect:r}){return e.jsx("button",{onClick:()=>r(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:pn(t)})}function dt(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(i=>dt(i,n)))}function ct(t){var i;const n=t.files.length,r=((i=t.children)==null?void 0:i.reduce((s,o)=>s+ct(o),0))||0;return n+r}function pt({group:t,activeFile:n,onSelect:r,depth:i=0}){var b;const s=dt(t,n||""),[o,c]=d.useState(s),l=ct(t),x=!!((b=t.children)!=null&&b.length);return d.useEffect(()=>{s&&c(!0)},[s]),e.jsxs("div",{style:{marginBottom:i===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!o),style:{display:"flex",alignItems:"center",gap:"6px",padding:i===0?"4px 8px":"2px 8px",paddingLeft:`${8+i*16}px`,cursor:"pointer",userSelect:"none",fontSize:i===0?"13px":"12px",fontWeight:i===0?600:500,color:s?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",l,")"]})]}),o&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+i*16}px`},children:t.files.map(p=>e.jsx(at,{file:p,isActive:n===p,onSelect:r},p))}),x&&t.children.map((p,a)=>e.jsx(pt,{group:p,activeFile:n,onSelect:r,depth:i+1},a))]})]})}function xn({files:t,groups:n,activeFile:r,onSelect:i}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((s,o)=>e.jsx(pt,{group:s,activeFile:r,onSelect:i},o))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(s=>e.jsx(at,{file:s,isActive:r===s,onSelect:i},s))})}function fn({type:t}){const n=ot[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function gn({section:t,onNavigate:n}){const[r,i]=d.useState(!1),s=!!t.summary,o=!!t.comment,c=!!t.additional_comment,l=s||o||c;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>l&&i(!r),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:l?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[l&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:r?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},children:[t.book_title?`《${t.book_title}》`:t.title,t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[st(t.n_juan),"卷"]})]}),t.version&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:t.version}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("span",{onClick:x=>{x.stopPropagation(),n(t.work_id)},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",flexShrink:0},title:"查看作品",children:"→作品"})]}),r&&l&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:t.author_info}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:t.summary})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:t.comment})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:t.additional_comment})]})]})]})}function un({section:t}){const[n,r]=d.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!n),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(fn,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:t.title}),i&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:n?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),n&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${ot[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:t.content})})]})}function hn({section:t}){if(!t.content&&!t.title)return null;const n=(t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`);return e.jsx("div",{style:{padding:"6px 0",fontSize:"13px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.7,whiteSpace:"pre-line"},children:n})}function bn({juan:t,searchQuery:n,onNavigate:r}){const i=d.useMemo(()=>{if(!n.trim())return t.sections;const o=n.trim().toLowerCase();return t.sections.filter(c=>{var l,x,b,p,a;return((l=c.title)==null?void 0:l.toLowerCase().includes(o))||((x=c.book_title)==null?void 0:x.toLowerCase().includes(o))||((b=c.author)==null?void 0:b.toLowerCase().includes(o))||((p=c.author_info)==null?void 0:p.toLowerCase().includes(o))||((a=c.summary)==null?void 0:a.toLowerCase().includes(o))})},[t.sections,n]),s=i.filter(o=>o.type==="书").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:t.title}),t.source_url&&e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:"原文 ↗"}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[s," 部书"]})]}),i.map((o,c)=>o.type==="书"?e.jsx(gn,{section:o,onNavigate:r},c):o.type==="部"||o.type==="类"?e.jsx(un,{section:o},c):e.jsx(hn,{section:o},c)),i.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const xt=({index:t,workId:n,transport:r,onNavigate:i,activeJuan:s,onJuanChange:o,className:c,style:l})=>{const[x,b]=d.useState(null),[p,a]=d.useState(!1),[f,v]=d.useState(null),[g,y]=d.useState(null),[w,C]=d.useState(null),[m,I]=d.useState(!1),[h,j]=d.useState(""),z=s??g,_=d.useCallback(B=>{y(B),o==null||o(B)},[o]),R=t||x;d.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let B=!1;return a(!0),v(null),r.getCollatedEditionIndex(n).then(W=>{B||(W?(b(W),!s&&W.juan_files.length>0&&_(W.juan_files[0])):v("未找到整理本数据"))}).catch(W=>{B||v(W instanceof Error?W.message:"加载失败")}).finally(()=>{B||a(!1)}),()=>{B=!0}},[t,n,r,s,_]),d.useEffect(()=>{t&&t.juan_files.length>0&&!z&&_(t.juan_files[0])},[t,z,_]);const M=n||(R==null?void 0:R.work_id),u=d.useCallback(async B=>{if(!(!M||!(r!=null&&r.getCollatedJuan))){I(!0),C(null);try{const W=await r.getCollatedJuan(M,B);C(W)}catch{C(null)}finally{I(!1)}}},[M,r]);d.useEffect(()=>{z&&u(z)},[z,u]);const k=B=>{_(B),j("")};return p?e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):f?e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):R?e.jsxs("div",{className:c,style:l,children:[e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:R.total_juan})," 卷"]})}),e.jsx(xn,{files:R.juan_files,groups:R.juan_groups,activeFile:z,onSelect:k}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:h,onChange:B=>j(B.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),m?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载中..."}):w?e.jsx(bn,{juan:w,searchQuery:h,onNavigate:i}):z?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null]}):null},mn=[{id:"",title:"四库全书总目",description:"清·纪昀等纂修,200卷"},{id:"",title:"四库全书(文渊阁本)",description:"清·乾隆敕编,1500册"}],ft=({transport:t,onNavigate:n,recommendedIds:r})=>{const[i,s]=d.useState(null),[o,c]=d.useState([]);d.useEffect(()=>{if(!t.getAllEntries)return;let x=!1;return t.getAllEntries().then(b=>{if(x)return;const p=b.filter(v=>v.type==="work").length,a=b.filter(v=>v.type==="book").length,f=b.filter(v=>v.type==="collection").length;s({works:p,books:a,collections:f})}).catch(()=>{}),()=>{x=!0}},[t]),d.useEffect(()=>{const b=(r??mn).filter(a=>a.id);if(b.length===0)return;let p=!1;return Promise.all(b.map(async a=>{try{if(t.getEntry)return await t.getEntry(a.id);const f=await t.getItem(a.id);if(f)return{id:a.id,title:f.title||a.id,type:f.type||"work"}}catch{}return null})).then(a=>{p||c(a.filter(f=>f!==null))}),()=>{p=!0}},[t,r]);const l=x=>{switch(x){case"work":return"✍️";case"book":return"📖";case"collection":return"📚"}};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",padding:"40px 20px",color:"var(--bim-fg, #333)"},children:[e.jsxs("div",{style:{textAlign:"center",marginBottom:"40px"},children:[e.jsx("div",{style:{fontSize:"48px",marginBottom:"12px"},children:"📚"}),e.jsx("h1",{style:{margin:"0 0 8px",fontSize:"24px",fontWeight:500,color:"var(--bim-fg, #333)"},children:"古籍索引"}),e.jsx("p",{style:{margin:0,fontSize:"14px",color:"var(--bim-desc-fg, #717171)"},children:"从左侧搜索框输入关键词,查找作品、书籍或丛编"})]}),o.length>0&&e.jsxs("div",{style:{width:"100%",maxWidth:"500px",marginBottom:"32px"},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:"推荐浏览"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(x=>e.jsxs("div",{onClick:()=>n==null?void 0:n(x.id),style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsx("span",{style:{fontSize:"20px"},children:l(x.type)}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:500},children:x.title}),(x.dynasty||x.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[x.dynasty&&e.jsxs("span",{children:["〔",x.dynasty,"〕"]}),x.author&&e.jsx("span",{children:x.author})]})]})]},x.id))})]}),i&&e.jsxs("div",{style:{display:"flex",gap:"32px",padding:"16px 0",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx(je,{icon:"✍️",label:"作品",count:i.works}),e.jsx(je,{icon:"📖",label:"书籍",count:i.books}),e.jsx(je,{icon:"📚",label:"丛编",count:i.collections})]})]})},je=({icon:t,label:n,count:r})=>e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"20px",marginBottom:"4px"},children:t}),e.jsx("div",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #333)"},children:r.toLocaleString()}),e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n})]}),yn=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:i})=>{var M;const[s,o]=d.useState(null),[c,l]=d.useState(null),[x,b]=d.useState(!1),[p,a]=d.useState("detail"),[f,v]=d.useState([]),[g,y]=d.useState(!1),[w,C]=d.useState(null),[m,I]=d.useState(!1),h=d.useCallback(async u=>{if(!t.getCollatedEditionIndex){C(null);return}I(!0);try{const k=await t.getCollatedEditionIndex(u);C(k)}catch{C(null)}finally{I(!1)}},[t]),j=d.useCallback(async u=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){v([]);return}y(!0);try{if(t.getCollectionCatalogs){const k=await t.getCollectionCatalogs(u);v(k||[])}else if(t.getCollectionCatalog){const k=await t.getCollectionCatalog(u);v(k?[{resource_id:"",data:k}]:[])}}catch{v([])}finally{y(!1)}},[t]),z=d.useCallback(async u=>{if(r){r(u);return}o(u),l(null),v([]),C(null),a("detail"),b(!0);try{const k=await t.getItem(u.id);k&&(l(k),k.type==="collection"?j(u.id):k.type==="work"&&h(u.id))}catch(k){console.error("加载详情失败:",k)}finally{b(!1)}},[t,r,j,h]),_=d.useCallback(async u=>{l(null),v([]),C(null),a("detail"),b(!0);try{const k=await t.getItem(u);k&&(l(k),o({id:u,title:k.title||u,type:k.type||"book"}),k.type==="collection"?j(u):k.type==="work"&&h(u))}catch(k){console.error("导航失败:",k)}finally{b(!1)}},[t,j,h]),R=(c==null?void 0:c.type)==="collection"&&(f.length>0||g)||(c==null?void 0:c.type)==="work"&&(w||m);return e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(et,{transport:t,onEntryClick:z,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:x?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中..."})}):c?e.jsxs(e.Fragment,{children:[R&&e.jsxs("div",{style:{display:"flex",gap:"0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:[e.jsx("button",{onClick:()=>a("detail"),style:fe(p==="detail"),children:"基本信息"}),c.type==="collection"&&g&&f.length===0&&e.jsxs("button",{onClick:()=>{},style:fe(!1),children:["目錄",e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),c.type==="collection"&&f.map(u=>e.jsx("button",{onClick:()=>a(`catalog:${u.resource_id}`),style:fe(p===`catalog:${u.resource_id}`),children:u.short_name?`${u.short_name}·目錄`:"叢編目錄"},u.resource_id)),c.type==="work"&&(w||m)&&e.jsxs("button",{onClick:()=>a("collated"),style:fe(p==="collated"),children:["整理本",m&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),e.jsx("div",{style:{padding:"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:p==="detail"?e.jsx(rt,{data:c,transport:t,onNavigate:_}):p.startsWith("catalog:")?e.jsx(lt,{data:(M=f.find(u=>`catalog:${u.resource_id}`===p))==null?void 0:M.data,onNavigate:_}):p==="collated"?e.jsx(xt,{index:w||void 0,workId:c.id,transport:t,onNavigate:_}):null})]}):e.jsx(ft,{transport:t,onNavigate:_,recommendedIds:i})})]})};function fe(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const Z=({title:t,onSave:n,onAskAI:r,extraButtons:i,children:s})=>e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[i,r&&e.jsx("button",{onClick:r,style:jn,children:"AI"}),n&&e.jsx("button",{onClick:n,style:vn,children:"保存"})]})]}),s]}),vn={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},jn={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},G=({label:t,value:n,onChange:r,placeholder:i,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:o=>r(o.target.value),placeholder:i,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),re=({value:t,onChange:n,placeholder:r})=>{const i=d.useRef(null);return d.useEffect(()=>{i.current&&(i.current.style.height="auto",i.current.style.height=`${i.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:i,value:t||"",onChange:s=>n(s.target.value),placeholder:r,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},ue=({children:t,color:n,style:r})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...r},children:t});function Sn(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ge=({value:t,onChange:n,label:r})=>{const[i,s]=d.useState(!1),o=d.useRef(null),c=Sn(t||"");return d.useEffect(()=>{i&&o.current&&o.current.focus()},[i]),!i&&c?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:De,children:r}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:c.name}),e.jsx(ue,{children:c.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:De,children:r}),e.jsx("input",{ref:o,type:"text",value:t||"",onChange:l=>n(l.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},De={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function kn(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function wn(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const gt=({items:t,onChange:n,onOpenEntityPicker:r})=>{const[i,s]=d.useState(null),o=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),s(t.length)},c=p=>{n(t.filter((a,f)=>f!==p)),i===p&&s(null)},l=(p,a,f)=>{const v=[...t];v[p]={...v[p],[a]:f},n(v)},x=(p,a)=>{const f=[...t];f[p]={...f[p],type:a,id:"",name:""},n(f),a==="bookID"&&r&&r(v=>{const g=[...t];g[p]={...g[p],id:v.id,name:v.title,type:"bookID"},n(g)})},b=p=>{r&&r(a=>{const f=[...t];f[p]={...f[p],id:a.id,name:a.title,type:"bookID"},n(f)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,a)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>s(i===a?null:a),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===a?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:p.name||`来源 ${a+1}`}),p.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:kn(p.type),color:"white",borderRadius:"3px",fontWeight:500},children:wn(p.type)}),e.jsx("button",{onClick:f=>{f.stopPropagation(),c(a)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:"删除此来源",children:"✕"})]}),i===a&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!p.type&&e.jsxs("div",{children:[e.jsx("label",{style:te,children:"选择来源类型"}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>x(a,"bookID"),style:{...Ne,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:"从现有书籍选择"})]}),e.jsxs("button",{onClick:()=>x(a,"url"),style:{...Ne,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:"输入网址链接"})]})]})]}),p.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:te,children:"选择书籍/作品"}),e.jsx("button",{onClick:()=>{const f=[...t];f[a]={...f[a],type:"",id:"",name:""},n(f)},style:Ge,children:"更换类型"})]}),p.id&&p.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:p.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:p.id})]}),e.jsx("button",{onClick:()=>b(a),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:"重选"})]}):e.jsxs("button",{onClick:()=>b(a),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:"点击选择书籍/作品"})]})]})}),p.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:te,children:"来源名称"}),e.jsx("button",{onClick:()=>{const f=[...t];f[a]={...f[a],type:"",id:"",name:""},n(f)},style:Ge,children:"更换类型"})]}),e.jsx("input",{type:"text",value:p.name,onChange:f=>l(a,"name",f.target.value),placeholder:"如: 维基文库、中国基本古籍库",style:se})]}),e.jsxs("div",{children:[e.jsx("label",{style:te,children:"URL 地址"}),e.jsx("input",{type:"text",value:p.id,onChange:f=>l(a,"id",f.target.value),placeholder:"https://...",style:se})]})]}),p.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...te,opacity:.7},children:"可选信息"})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsxs("label",{style:te,children:["详细说明 ",e.jsx("span",{style:{opacity:.5},children:"(可选)"})]}),e.jsx("input",{type:"text",value:p.details,onChange:f=>l(a,"details",f.target.value),placeholder:"补充说明",style:se})]}),e.jsxs("div",{children:[e.jsxs("label",{style:te,children:["位置/页码 ",e.jsx("span",{style:{opacity:.5},children:"(可选)"})]}),e.jsx("input",{type:"text",value:p.position,onChange:f=>l(a,"position",f.target.value),placeholder:"如: 卷三, p.52",style:se})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsxs("label",{style:te,children:["数据版本 ",e.jsx("span",{style:{opacity:.5},children:"(可选)"})]}),e.jsx("input",{type:"text",value:p.version,onChange:f=>l(a,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:se})]}),e.jsxs("div",{children:[e.jsxs("label",{style:te,children:["处理器版本 ",e.jsx("span",{style:{opacity:.5},children:"(可选)"})]}),e.jsx("input",{type:"text",value:p.processor_version,onChange:f=>l(a,"processor_version",f.target.value),placeholder:"如: v0.1",style:se})]})]})]})]})})]},a)),e.jsxs("button",{onClick:o,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:"添加来源"})]})]})},te={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},se={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ne={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Ge={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function ut(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function ht(t){return!t||t.length===0?"":JSON.stringify(t)}const bt=({entityType:t,entityId:n,entityTitle:r,parentWork:i,parentCollection:s,belongsToWork:o,belongsToCollection:c,childWorks:l,childCollections:x,containedBooks:b,siblingBooks:p,onLinkEntity:a,onUnlinkEntity:f,onViewEntity:v,onCreateAndLink:g,onSaveRelations:y})=>e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:"关联关系"})]}),y&&e.jsx("button",{onClick:y,style:Cn,children:"保存"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(de,{direction:"up",title:"所属作品 (Work)",entity:o,onView:v,onUnlink:()=>f("workId"),onLink:()=>a("workId","work"),onCreate:()=>g("workId","work",{title:r})}),e.jsx(de,{direction:"up",title:"收录于丛编 (Collection)",entity:c,onView:v,onUnlink:()=>f("collectionId"),onLink:()=>a("collectionId","collection"),onCreate:()=>g("collectionId","collection",{title:r})}),o&&p&&p.length>0&&e.jsx(oe,{direction:"horizontal",title:`同作品其他版本 (${p.length})`,entities:p,onView:v,onAdd:()=>g("siblingBook","book",{workId:o.id}),addLabel:"为此作品添加新版本"})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(de,{direction:"up",title:"父作品 (Parent Work)",entity:i,onView:v,onUnlink:()=>f("parentWorkId"),onLink:()=>a("parentWorkId","work"),onCreate:()=>g("parentWorkId","work")}),l&&l.length>0&&e.jsx(oe,{direction:"down",title:`子作品 (${l.length})`,entities:l,onView:v,onAdd:()=>g("childWork","work",{parentWorkId:n}),addLabel:"添加子作品"}),x&&x.length>0&&e.jsx(oe,{direction:"down",title:`丛编实现 (${x.length})`,entities:x,onView:v,onAdd:()=>g("childCollection","collection",{workId:n}),addLabel:"添加丛编实现"}),e.jsx(oe,{direction:"down",title:`所有版本 (${(b==null?void 0:b.length)??0})`,entities:b||[],onView:v,onAdd:()=>g("childBook","book",{workId:n}),addLabel:"添加新版本"})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(de,{direction:"up",title:"对应作品 (Work)",entity:o,onView:v,onUnlink:()=>f("workId"),onLink:()=>a("workId","work"),onCreate:()=>g("workId","work",{title:r})}),e.jsx(de,{direction:"up",title:"父丛编 (Parent Collection)",entity:s,onView:v,onUnlink:()=>f("parentCollectionId"),onLink:()=>a("parentCollectionId","collection"),onCreate:()=>g("parentCollectionId","collection")}),e.jsx(oe,{direction:"down",title:`子丛编 (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:v,onAdd:()=>g("childCollection","collection",{parentCollectionId:n}),addLabel:"添加子丛编"}),e.jsx(oe,{direction:"down",title:`包含书籍 (${(b==null?void 0:b.length)??0})`,entities:b||[],onView:v,onAdd:()=>g("childBook","book",{collectionId:n}),addLabel:"添加书籍"})]})]})]}),de=({direction:t,title:n,entity:r,onView:i,onUnlink:s,onLink:o,onCreate:c})=>{const l=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:l,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:mt(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Je,{onClick:()=>i(r),title:"查看",children:"👁️"}),e.jsx(Je,{onClick:s,title:"解除关联",danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:"(未关联)"}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Ie,{onClick:o,children:"+ 关联现有"}),e.jsx(Ie,{onClick:c,primary:!0,children:"+ 创建并关联"})]})]})},oe=({direction:t,title:n,entities:r,onView:i,onAdd:s,addLabel:o})=>{const[c,l]=d.useState(!1),x=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",b=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",p=c?r:r.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:b}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[p.map(a=>e.jsxs("div",{onClick:()=>i(a),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:mt(a.type)}),e.jsx("span",{children:a.title})]},a.id)),r.length>5&&!c&&e.jsxs("div",{onClick:()=>l(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:["展开更多 (",r.length-5," 项)"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:"(暂无)"}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ie,{onClick:s,primary:!0,children:["+ ",o]})})]})},Je=({onClick:t,title:n,danger:r,children:i})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:i}),Ie=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:r});function mt(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Cn={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},yt=({isOpen:t,entityType:n,title:r,onSelect:i,onCancel:s,onCreate:o,searchResults:c,onSearch:l,isLoading:x,excludeId:b})=>{const[p,a]=d.useState(""),f=b?c.filter(w=>w.id!==b):c;d.useEffect(()=>{t&&(a(""),l(""))},[t]);const v=w=>{a(w),l(w)};if(!t)return null;const g=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:zn,children:e.jsxs("div",{style:In,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:s,style:_n,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:w=>v(w.target.value),placeholder:`搜索${g}名称或 ID...`,autoFocus:!0,style:Rn})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:x?e.jsx("div",{style:Se,children:"搜索中..."}):f.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:f.map(w=>e.jsxs("div",{onClick:()=>i(w),style:En,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:w.title}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[w.id,w.author&&` · ${w.author}`,w.dynasty&&` · ${w.dynasty}`]})]})]},w.id))}):p?e.jsxs("div",{style:Se,children:["未找到匹配的",g]}):e.jsxs("div",{style:Se,children:["输入关键词搜索",g]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:o,style:Bn,children:["创建新",g,"并关联"]})]})]})})},zn={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},In={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},_n={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Rn={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},En={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Se={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Bn={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ve={work:"作品",book:"书籍",collection:"丛编"},Tn={work:"📜",book:"📖",collection:"📚"},vt=({isOpen:t,entityType:n,relationField:r,inheritData:i,onConfirm:s,onCancel:o})=>{const[c,l]=d.useState(""),x=d.useRef(null);d.useEffect(()=>{t&&(l((i==null?void 0:i.title)||""),setTimeout(()=>{var f,v;(f=x.current)==null||f.focus(),(v=x.current)==null||v.select()},100))},[t,i==null?void 0:i.title]);const b=f=>{f.key==="Enter"&&c.trim()?p():f.key==="Escape"&&o()},p=()=>{c.trim()&&s(c.trim(),{...i,title:c.trim()})};if(!t)return null;const a=()=>{switch(r){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Ve[n]}`}};return e.jsx("div",{style:Wn,onClick:f=>{f.target===f.currentTarget&&o()},children:e.jsxs("div",{style:Ln,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Tn[n]}),e.jsx("span",{children:a()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:x,type:"text",value:c,onChange:f=>l(f.target.value),onKeyDown:b,placeholder:`请输入${Ve[n]}名称...`,style:$n})]}),((i==null?void 0:i.author)||(i==null?void 0:i.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(i==null?void 0:i.author)&&e.jsxs("div",{children:["作者: ",i.author]}),(i==null?void 0:i.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",i.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:o,style:An,children:"取消"}),e.jsx("button",{onClick:p,disabled:!c.trim(),style:{...Hn,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Wn={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ln={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",minWidth:"400px",maxWidth:"500px",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},$n={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},An={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Hn={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Fn(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function jt(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Pn(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const St=({isOpen:t,title:n,filterType:r="all",recentEntities:i=[],excludeId:s,showCreateButton:o=!1,createButtonText:c,onSelect:l,onCancel:x,onCreate:b,onSearch:p})=>{const[a,f]=d.useState(""),[v,g]=d.useState([]),[y,w]=d.useState(!1),[C,m]=d.useState("recent");d.useEffect(()=>{t&&(f(""),g([]),m(i.length>0?"recent":"search"))},[t,i.length]),d.useEffect(()=>{if(!a.trim()){g([]);return}const R=setTimeout(async()=>{w(!0);try{g(await p(a,r))}catch{g([])}finally{w(!1)}},300);return()=>clearTimeout(R)},[a,r,p]);const I=d.useCallback(R=>{f(R.target.value),R.target.value.trim()&&m("search")},[]),h=d.useCallback(R=>s?R.filter(M=>M.id!==s):R,[s]);if(!t)return null;const j=n||(r==="all"?"选择实体":`选择${jt(r)}`),z=h(i),_=h(v);return e.jsx("div",{style:Mn,children:e.jsxs("div",{style:Un,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:j}),e.jsx("button",{onClick:x,style:Yn,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:a,onChange:I,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Dn}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),z.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Ke,{active:C==="recent",onClick:()=>m("recent"),children:["最近使用 (",z.length,")"]}),e.jsxs(Ke,{active:C==="search",onClick:()=>m("search"),children:["搜索结果 ",_.length>0&&`(${_.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:C==="recent"&&z.length>0?e.jsx(Xe,{entities:z,onSelect:l}):a.trim()?y?e.jsx(ke,{message:"搜索中..."}):_.length>0?e.jsx(Xe,{entities:_,onSelect:l}):e.jsx(ke,{message:"未找到匹配的结果"}):e.jsx(ke,{message:"输入关键词开始搜索"})}),o&&b&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:b,style:Nn,children:c||"创建新实体"})]})]})})},Ke=({active:t,onClick:n,children:r})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:r}),Xe=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(On,{entity:r,onClick:()=>n(r)},r.id))}),On=({entity:t,onClick:n})=>{const[r,i]=d.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Fn(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.title}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Pn(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:jt(t.type)})]})},ke=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Mn={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Un={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Yn={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Dn={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Nn={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Gn={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},Ze={work:"作品",collection:"丛书",book:"书籍"},Jn={work:"📜",collection:"📚",book:"📖"},Vn=({data:t,onChange:n,onSave:r,transport:i,onNavigate:s,showDelete:o,onDelete:c,onAskAI:l,renderSectionActions:x,onDownloadResource:b,downloadStatuses:p,relations:a,onRelationsChange:f})=>{var Ee;const[v,g]=d.useState(!1),[y,w]=d.useState("work"),[C,m]=d.useState(""),[I,h]=d.useState(""),[j,z]=d.useState([]),[_,R]=d.useState(!1),[M,u]=d.useState(!1),[k,B]=d.useState("work"),[W,A]=d.useState(""),[$,L]=d.useState(),[U,H]=d.useState(!1),[O,J]=d.useState(null),[be,le]=d.useState([]);d.useRef(null);const X=t.type,me=X==="work",E=X==="collection",P=X==="book",T=d.useCallback((S,D)=>{n({...t,[S]:D})},[t,n]),N=d.useCallback((S,D)=>{m(S),w(D);const V=Ze[D];h(`选择要关联的${V}`),z([]),g(!0)},[]),Q=d.useCallback(S=>{i!=null&&i.unlinkEntity&&i.unlinkEntity(t.id,S)},[i,t.id]),ie=d.useCallback(S=>{s==null||s(S.id,S.type)},[s]),Y=d.useCallback((S,D,V)=>{const It={...V,author:(V==null?void 0:V.author)||t.author,dynasty:(V==null?void 0:V.dynasty)||t.dynasty};B(D),A(S),L(It),u(!0)},[t.author,t.dynasty]),Re=d.useCallback((S,D)=>{i!=null&&i.createAndLink&&i.createAndLink(t.id,W,{type:k,title:S,inheritData:D}),u(!1)},[i,t.id,W,k]),ye=d.useCallback(S=>{if(!S.trim()){z([]);return}R(!0),i!=null&&i.searchEntities&&i.searchEntities(S,y).then(D=>{z(D),R(!1)}).catch(()=>{z([]),R(!1)})},[i,y]),ae=d.useCallback(S=>{i!=null&&i.linkEntity&&i.linkEntity(t.id,C,S.id),g(!1)},[i,t.id,C]),kt=d.useCallback(()=>{r()},[r]),wt=d.useCallback(S=>{J(()=>S),H(!0),i!=null&&i.getRecentEntities&&i.getRecentEntities().then(le).catch(()=>{})},[i]),Ct=d.useCallback((S,D)=>i!=null&&i.searchEntities?i.searchEntities(S,D==="all"?void 0:D):Promise.resolve([]),[i]),zt=d.useCallback(S=>{i!=null&&i.addRecentEntity&&i.addRecentEntity(S),le(D=>[S,...D.filter(V=>V.id!==S.id)].slice(0,10)),O==null||O(S),H(!1),J(null)},[i,O]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Jn[X]}),e.jsx("span",{children:t.title||"未命名"}),e.jsx(ue,{children:t.id}),e.jsx(ue,{color:Gn[X],children:Ze[X]})]})}),e.jsx(Z,{title:"📊 基本信息",onSave:r,onAskAI:l?()=>l("基本信息"):void 0,extraButtons:x==null?void 0:x("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(ge,{label:me?"作品名 (Work Title)":E?"丛书名 (Collection Title)":"书名 (Book Title)",value:t.title,onChange:S=>T("title",S)}),P&&e.jsx(ge,{label:"所属作品 (Work)",value:t.workName||"",onChange:S=>T("workName",S)}),e.jsx(G,{label:"作者 (Author)",value:t.author||"",onChange:S=>T("author",S)}),e.jsx(G,{label:"朝代/年份 (Dynasty/Year)",value:t.dynasty||"",onChange:S=>T("dynasty",S)}),(P||E)&&e.jsx(ge,{label:"收录于 (Collection)",value:t.collection||"",onChange:S=>T("collection",S)}),(P||E)&&e.jsx(G,{label:"现藏于 (Holder)",value:t.holder||"",onChange:S=>T("holder",S)}),(P||E)&&e.jsx(G,{label:P?"页数 (Pages)":"册数 (Volumes)",value:t.pages||"",onChange:S=>T("pages",S)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(G,{label:"首页图片 (First Image URL)",value:t.firstImage||"",onChange:S=>T("firstImage",S)})})]})}),e.jsx(Z,{title:"📝 介绍 (Description)",onSave:r,onAskAI:l?()=>l("介绍"):void 0,children:e.jsx(re,{value:t.description||"",onChange:S=>T("description",S),placeholder:"简要介绍..."})}),(((Ee=t.additional_works)==null?void 0:Ee.length)||0)>0&&e.jsx(Z,{title:"📑 附属作品 (Additional Works)",onSave:r,children:e.jsx(Kn,{items:t.additional_works||[],onChange:S=>T("additional_works",S)})}),e.jsx(Z,{title:"📖 收录于 (Indexed By)",onSave:r,onAskAI:l?()=>l("收录于"):void 0,children:e.jsx(Xn,{items:t.indexed_by||[],onChange:S=>T("indexed_by",S)})}),e.jsx(Z,{title:"📝 文字资源 (Text Resources)",onSave:r,onAskAI:l?()=>l("资源"):void 0,children:e.jsx(we,{items:t.resources||[],onChange:S=>T("resources",S),onDownload:b,downloadStatuses:p,filterType:"text"})}),e.jsx(Z,{title:"🖼️ 图片资源 (Image Resources)",onSave:r,children:e.jsx(we,{items:t.resources||[],onChange:S=>T("resources",S),onDownload:b,downloadStatuses:p,filterType:"image"})}),e.jsx(Z,{title:"📚 资料来源 (Sources)",onSave:r,onAskAI:l?()=>l("资料来源"):void 0,children:e.jsx(gt,{items:ut(t.sources||""),onChange:S=>T("sources",ht(S)),onOpenEntityPicker:wt})}),(P||E)&&e.jsx(Z,{title:"📜 收藏历史 (Provenance)",onSave:r,onAskAI:l?()=>l("收藏历史"):void 0,children:e.jsx(re,{value:t.provenance||"",onChange:S=>T("provenance",S),placeholder:"该资源的流传与收藏记录..."})}),P&&e.jsx(Z,{title:"📚 其他版本 (Other Editions)",onSave:r,onAskAI:l?()=>l("其他版本"):void 0,children:e.jsx(re,{value:t.otherEditions||"",onChange:S=>T("otherEditions",S),placeholder:"相关版本的 ID..."})}),e.jsx(bt,{entityType:X,entityId:t.id,entityTitle:t.title,parentWork:a==null?void 0:a.parentWork,parentCollection:a==null?void 0:a.parentCollection,belongsToWork:a==null?void 0:a.belongsToWork,belongsToCollection:a==null?void 0:a.belongsToCollection,childWorks:a==null?void 0:a.childWorks,childCollections:a==null?void 0:a.childCollections,containedBooks:a==null?void 0:a.containedBooks,siblingBooks:a==null?void 0:a.siblingBooks,onLinkEntity:N,onUnlinkEntity:Q,onViewEntity:ie,onCreateAndLink:Y,onSaveRelations:kt}),o&&c&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:"危险区域 (Danger Zone)"}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:"从索引库中永久删除该实体的所有元数据文件。"}),e.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:"删除该实体 (Delete Entity)"})]}),e.jsx(yt,{isOpen:v,entityType:y,title:I,onSelect:ae,onCancel:()=>g(!1),onCreate:()=>{g(!1),Y(C,y)},searchResults:j,onSearch:ye,isLoading:_,excludeId:t.id}),e.jsx(vt,{isOpen:M,entityType:k,relationField:W,inheritData:$,onConfirm:Re,onCancel:()=>u(!1)}),e.jsx(St,{isOpen:U,title:"选择书籍/作品",filterType:"all",recentEntities:be,excludeId:t.id,onSelect:zt,onCancel:()=>{H(!1),J(null)},onSearch:Ct})]})};function Kn({items:t,onChange:n}){const r=(o,c,l)=>{const x=t.map((b,p)=>p===o?{...b,[c]:l}:b);n(x)},i=o=>n(t.filter((c,l)=>l!==o)),s=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((o,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(G,{label:"书名",value:o.book_title,onChange:l=>r(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(G,{label:"卷数",value:o.n_juan!=null?String(o.n_juan):"",onChange:l=>r(c,"n_juan",l&&parseInt(l,10)||void 0)})}),e.jsx("button",{onClick:()=>i(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:s,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:"+ 添加附属作品"})]})}function Xn({items:t,onChange:n}){const[r,i]=d.useState(null),s=(l,x,b)=>{const p=t.map((a,f)=>f===l?{...a,[x]:b||void 0}:a);n(p)},o=l=>{n(t.filter((x,b)=>b!==l)),r===l&&i(null)},c=()=>{n([...t,{source:""}]),i(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,x)=>{const b=r===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:b?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>i(b?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:b?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:l.source||"(未命名来源)"}),l.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:l.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),o(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!b&&(l.title_info||l.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[l.title_info,l.title_info&&l.author_info&&" — ",l.author_info]}),b&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(G,{label:"来源名称",value:l.source,onChange:p=>s(x,"source",p)}),e.jsx(G,{label:"来源 BID",value:l.source_bid||"",onChange:p=>s(x,"source_bid",p)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(G,{label:"题名",value:l.title_info||"",onChange:p=>s(x,"title_info",p)}),e.jsx(G,{label:"著者",value:l.author_info||"",onChange:p=>s(x,"author_info",p)})]}),e.jsx(G,{label:"版本",value:l.version||"",onChange:p=>s(x,"version",p)}),e.jsx(re,{value:l.summary||"",onChange:p=>s(x,"summary",p),placeholder:"提要..."}),e.jsx(re,{value:l.comment||"",onChange:p=>s(x,"comment",p),placeholder:"按語..."}),e.jsx(re,{value:l.additional_comment||"",onChange:p=>s(x,"additional_comment",p),placeholder:"附按..."})]})]},x)}),e.jsx("button",{onClick:c,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:"+ 添加收录来源"})]})}exports.BidLink=F.BidLink;exports.BookIndexError=F.BookIndexError;exports.BookIndexManager=F.BookIndexManager;exports.BookIndexStorage=F.BookIndexStorage;exports.BundleStorage=F.BundleStorage;exports.ConfigError=F.ConfigError;exports.GithubStorage=F.GithubStorage;exports.IdGenerationError=F.IdGenerationError;exports.IdGenerator=F.IdGenerator;exports.LocalStorage=F.LocalStorage;exports.MigrationError=F.MigrationError;exports.StorageError=F.StorageError;exports.base58Decode=F.base58Decode;exports.base58Encode=F.base58Encode;exports.buildId=F.buildId;exports.decodeIdString=F.decodeIdString;exports.extractIdFromUrl=F.extractIdFromUrl;exports.extractStatus=F.extractStatus;exports.extractType=F.extractType;exports.parseId=F.parseId;exports.validateResource=F.validateResource;exports.Badge=ue;exports.CollatedEdition=xt;exports.CollectionCatalog=lt;exports.CreateEntityDialog=vt;exports.EntityPickerDialog=St;exports.EntitySelector=yt;exports.FormInput=G;exports.FormTextArea=re;exports.HomePage=ft;exports.IndexApp=yn;exports.IndexBrowser=et;exports.IndexDetail=rt;exports.IndexEditor=Vn;exports.ModeIndicator=qe;exports.RelationPanel=bt;exports.ResourceEditor=we;exports.ResourceList=_e;exports.SearchInput=Qe;exports.Section=Z;exports.SmartBidInput=ge;exports.SourceEditor=gt;exports.parseSourceString=ut;exports.stringifySources=ht;
|
|
1
|
+
"use strict";var Dt=Object.create;var Oe=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var Ut=Object.getPrototypeOf,Yt=Object.prototype.hasOwnProperty;var Gt=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Nt(n))!Yt.call(t,r)&&r!==i&&Oe(t,r,{get:()=>n[r],enumerable:!(o=Vt(n,r))||o.enumerable});return t};var Jt=(t,n,i)=>(i=t!=null?Dt(Ut(t)):{},Gt(n||!t||!t.__esModule?Oe(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./storage-entry-C5i8mBl3.cjs"),e=require("react/jsx-runtime"),p=require("react"),je=p.createContext(null),ut={indexType:{work:"作品",book:"書籍",collection:"叢編"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Kt={indexType:{work:"作品",book:"书籍",collection:"丛编"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"实体资源"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"实体"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Zt={"zh-Hant":ut,"zh-Hans":Kt},Xt=({locale:t,onLocaleChange:n,children:i})=>{const[o,r]=p.useState(t??"zh-Hant"),s=t??o,[a,l]=p.useState(null);p.useEffect(()=>{s==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});l(()=>x)}).catch(()=>{l(()=>g=>g)}):l(null)},[s]);const d=p.useCallback(g=>{r(g),n==null||n(g)},[n]),u=p.useMemo(()=>({locale:s,setLocale:d,messages:Zt[s],converter:a}),[s,d,a]);return e.jsx(je.Provider,{value:u,children:i})};function W(){const t=p.useContext(je);return(t==null?void 0:t.messages)??ut}const qt=2e3;function F(){const t=p.useContext(je),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=p.useRef(new Map),r=p.useRef(n);r.current!==n&&(o.current.clear(),r.current=n);const s=p.useCallback(a=>{if(!a)return"";if(!i)return a;const l=o.current.get(a);if(l!==void 0)return l;const d=i(a);if(o.current.size>=qt){const u=o.current.keys().next().value;u!==void 0&&o.current.delete(u)}return o.current.set(a,d),d},[i]);return p.useMemo(()=>({convert:s,locale:n,isSimplified:n==="zh-Hans"}),[s,n])}function Se(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function Qt(t){if(!t)return"";try{const n=new URL(t).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function en(){return{id:"",name:"",url:"",type:"text",details:""}}const Pe=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:r})=>{const s=W(),[a,l]=p.useState(null),d=[{value:"text",label:s.resourceTypeShort.text},{value:"image",label:s.resourceTypeShort.image},{value:"text+image",label:s.resourceTypeShort.textImage},{value:"physical",label:s.resourceTypeShort.physical}],u=[{value:"catalog",label:s.rootType.catalog},{value:"search",label:s.rootType.search}],g=m=>r?r==="text"?m==="text"||m==="text+image":r==="image"?m==="image"||m==="text+image"||m==="physical":m===r:!0,x=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>g(m.type)),f=()=>{const m=en();r&&(m.type=r),n([...t,m]),l(t.length)},c=m=>{n(t.filter((S,y)=>y!==m)),l(null)},j=(m,S,y)=>{const I=[...t];if(I[m]={...I[m],[S]:y},S==="url"&&!I[m].id){const T=Qt(y);T&&(I[m].id=T)}n(I)},w=(m,S,y)=>{const T={...t[m].metadata||{}};y?T[S]=y:delete T[S],j(m,"metadata",Object.keys(T).length>0?T:void 0)},b=(m,S)=>{const y=S.trim()?S.split(/[,,、]/).map(I=>I.trim()).filter(Boolean):void 0;j(m,"structure",y)},E=(m,S,y)=>{const T=t[m].coverage||{level:1,ranges:""};S==="level"?T.level=parseInt(y)||1:T.ranges=y,j(m,"coverage",T.ranges?T:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:S})=>{var y,I,T,v;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(a===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:tn(m.type),color:"#fff"},children:((y=d.find(h=>h.value===m.type))==null?void 0:y.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${s.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:h=>h.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&m.url&&nn(S,o==null?void 0:o[S],i,s),e.jsx("button",{onClick:h=>{h.stopPropagation(),c(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:s.editor.deleteThisResource,children:"✕"})]}),a===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&on(m,s),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.type}),e.jsx("select",{value:m.type,onChange:h=>j(S,"type",h.target.value),style:{...oe,flex:1},children:d.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:h=>j(S,"root_type",h.target.value),style:{...oe,flex:1},children:u.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:h=>j(S,"id",h.target.value),placeholder:s.editor.idAutoExtract,style:{...oe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:h=>j(S,"name",h.target.value),placeholder:s.editor.resourceName,style:{...oe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:h=>j(S,"url",h.target.value),placeholder:s.editor.resourceUrl,style:oe}),e.jsx("input",{type:"text",value:((I=m.structure)==null?void 0:I.join("、"))||"",onChange:h=>b(S,h.target.value),placeholder:s.editor.structurePlaceholder,style:oe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:s.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((T=m.coverage)==null?void 0:T.level)??"",onChange:h=>E(S,"level",h.target.value),placeholder:"1",style:{...oe,width:"60px"}})]}),e.jsxs("label",{style:{...be,flex:1},children:[e.jsx("span",{style:me,children:s.label.coverageRange}),e.jsx("input",{type:"text",value:((v=m.coverage)==null?void 0:v.ranges)||"",onChange:h=>E(S,"ranges",h.target.value),placeholder:s.editor.coverageRangePlaceholder,style:{...oe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:h=>j(S,"details",h.target.value),placeholder:s.editor.detailsPlaceholder,style:{...oe,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:s.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(s.metadata).map(([h,R])=>{var C;return e.jsxs("label",{style:{...be,gap:"4px"},children:[e.jsx("span",{style:{...me,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((C=m.metadata)==null?void 0:C[h])||"",onChange:_=>w(S,h,_.target.value),placeholder:R,style:{...oe,flex:1}})]},h)})})]})]})]})]},S)}),e.jsxs("button",{onClick:f,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:s.action.addResource})]})]})};function tn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function nn(t,n,i,o){const r=(n==null?void 0:n.status)==="downloading",s=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),r||i(t,"")},disabled:r,style:{background:"transparent",border:"none",color:s?"var(--bim-success, #4caf50)":r?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:r?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:r?.6:.9},title:s?o.download.completed:r?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:s?"✓":r?"⏳":"⬇"})}function on(t,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:i?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const oe={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},be={display:"flex",alignItems:"center",gap:"6px"},me={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},rn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function ln(t){try{const n=new URL(t).hostname;return rn[n]}catch{return}}const De={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},sn=["text","image","text+image","physical"];function an(t){const n=s=>{const a=s.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const l=s.match(/^(.+?)[·(](\d+)[)]?$/);return l?[l[1],parseInt(l[2])]:null},i=new Map,o=[],r=new Set;for(let s=0;s<t.length;s++){const a=t[s];if(a.volumes&&a.volumes.length>0)continue;const l=n(a.name);if(!l)continue;const[d,u]=l,g=`${d}|${a.type}`;i.has(g)||i.set(g,{base:{...a,name:d,url:"",volumes:[]},volumes:[]}),i.get(g).volumes.push({volume:u,url:a.url||void 0,status:"found"}),r.add(s)}for(const[,s]of i)if(s.volumes.length>=2)s.volumes.sort((a,l)=>a.volume-l.volume),s.base.volumes=s.volumes,s.base.expected_volumes=s.volumes.length,o.push(s.base);else for(let a=0;a<t.length;a++)if(r.has(a)){const l=n(t[a].name);l&&`${l[0]}|${t[a].type}`==`${s.base.name}|${s.base.type}`&&r.delete(a)}for(let s=0;s<t.length;s++)r.has(s)||o.push(t[s]);return o}const Fe=({items:t,groupByType:n=!0})=>{const i=W(),o=p.useMemo(()=>an(t||[]),[t]),r={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical};if(!o||o.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:o.map((a,l)=>e.jsx(Ne,{item:a},a.id||l))});const s=sn.map(a=>({type:a,items:o.filter(l=>l.type===a)})).filter(a=>a.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:s.map(({type:a,items:l})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:De[a],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:De[a]}}),r[a],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",l.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:l.map((d,u)=>e.jsx(Ne,{item:d},d.id||u))})]},a))})},Ve=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},gt=({value:t})=>{const i=W().checkType[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:i.bg,color:i.fg},children:i.label}):e.jsx("span",{children:t})},dn=(t,n,i)=>t==="check_type"&&typeof n=="string"?e.jsx(gt,{value:n}):t==="has_translation"?n?i.misc.hasTranslation:i.misc.noTranslation:String(n);function cn(t){if(t.url)return t.url;for(const[n,i]of Object.entries(t))if(n.endsWith("_url")&&typeof i=="string")return i}const pn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ne=({item:t})=>{var f;const n=W(),{convert:i}=F(),[o,r]=p.useState(!1),s=p.useMemo(()=>(t.url?ln(t.url):void 0)||i(t.name),[t.url,t.name,i]),a=p.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(c=>({...c,url:c.url||cn(c)})),[t.volumes]),l=a&&a.length>0,d=l?a.filter(c=>c.status!=="missing").length:0,u=l?a.length-d:0,g=t.expected_volumes??(l?a.length:0),x=t.color_mode?{...pn[t.color_mode],label:n.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:Ve(t)||l?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:s}),x&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((f=t.metadata)==null?void 0:f.check_type)&&e.jsx(gt,{value:t.metadata.check_type}),l&&e.jsxs("button",{onClick:()=>r(!o),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[d,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:o?"▲":"▼"})]}),t.url&&e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),Ve(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([c])=>c!=="check_type").map(([c,j])=>e.jsxs("span",{children:[n.metadata[c]||c,": ",dn(c,j,n)]},c)),t.details&&!l&&e.jsx("span",{children:t.details}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),l&&o&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:a.map(c=>{const j=c.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:c.url&&!j?e.jsx("a",{href:c.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:c.label||`${c.volume}`,children:c.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.6:1,lineHeight:1.4},children:c.volume})},c.volume)})})]})},ft=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:r,onConfigurePath:s,onSelectFolder:a})=>{const l=W(),d=t==="local",u=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",x=g?g.split(/[/\\]/).pop()||g:"",f={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},c={onMouseOver:w=>w.currentTarget.style.opacity="0.8",onMouseOut:w=>w.currentTarget.style.opacity="1"},j=e.jsxs("div",{onClick:r,title:u?l.mode.switchToOfficial:l.mode.switchToDraft,style:{...f,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...c,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return i==="index-browser"?d?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[j,e.jsxs("div",{onClick:o,title:l.mode.switchToSync,style:f,...c,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:l.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:g||l.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[j,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:l.mode.switchToLocal,style:f,...c,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:l.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:s,title:x||l.mode.configurePath,style:{...f,background:"transparent",padding:"6px",fontSize:"12px"},...c,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:d?l.mode.switchToGithub:l.mode.switchToLocal,style:f,...c,children:[e.jsx("span",{children:d?"📁":"🌐"}),e.jsx("span",{children:d?l.mode.localMode:l.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),d&&e.jsxs("div",{onClick:a,title:g||l.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!d&&x&&e.jsxs("div",{style:{...f,background:"#2196f3",color:"white",cursor:"default"},title:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Te="bim-search-history",Ue=10,Ye=8;function ve(){try{const t=localStorage.getItem(Te);return t?JSON.parse(t):[]}catch{return[]}}function xn(t){try{const n=ve().filter(i=>i!==t);n.unshift(t),n.length>Ue&&(n.length=Ue),localStorage.setItem(Te,JSON.stringify(n))}catch{}}function un(t){try{const n=ve().filter(i=>i!==t);localStorage.setItem(Te,JSON.stringify(n))}catch{}}function gn(){try{localStorage.removeItem(Te)}catch{}}const ht=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:r,placeholder:s})=>{const a=W(),l=s??a.search.placeholder,d={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection},[u,g]=p.useState(!1),[x,f]=p.useState([]),[c,j]=p.useState(-1),[w,b]=p.useState(null),[E,m]=p.useState(ve),S=p.useRef(null),y=p.useRef(null),I=p.useRef(null);p.useEffect(()=>{if(!t.getAllEntries)return;let k=!1;return t.getAllEntries().then(P=>{k||b(P)}).catch(()=>{}),()=>{k=!0}},[t]);const T=p.useCallback(k=>{if(!k.trim())return E.map(L=>({type:"history",text:L}));if(!w)return[];const P=k.toLowerCase(),D=[],U=[];for(const L of w){if(D.length+U.length>=Ye*2)break;const M=L.title.toLowerCase();if(M.startsWith(P))D.push({type:"entry",text:L.title,entry:L});else if(M.includes(P))U.push({type:"entry",text:L.title,entry:L});else if(L.additional_titles){for(const V of L.additional_titles)if(V.toLowerCase().includes(P)){D.push({type:"entry",text:`${L.title}`,entry:L});break}}}return[...D,...U].slice(0,Ye)},[w,E]);p.useEffect(()=>{f(T(n)),j(-1)},[n,T]),p.useEffect(()=>{const k=P=>{I.current&&!I.current.contains(P.target)&&g(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]),p.useEffect(()=>{const k=P=>{var D,U;if(P.key==="/"&&document.activeElement!==S.current){const L=(D=document.activeElement)==null?void 0:D.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;P.preventDefault(),(U=S.current)==null||U.focus()}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[]);const v=p.useCallback(k=>{k.trim()&&(xn(k.trim()),m(ve())),o(k),g(!1)},[o]),h=p.useCallback(k=>{k.type==="history"?(i(k.text),v(k.text)):k.entry&&(r?(r(k.entry),g(!1)):(i(k.text),v(k.text)))},[i,v,r]),R=p.useCallback(k=>{if(!u||x.length===0){k.key==="Enter"&&v(n);return}switch(k.key){case"ArrowDown":k.preventDefault(),j(P=>(P+1)%x.length);break;case"ArrowUp":k.preventDefault(),j(P=>(P-1+x.length)%x.length);break;case"Enter":k.preventDefault(),c>=0&&c<x.length?h(x[c]):v(n);break;case"Escape":k.preventDefault(),g(!1);break}},[u,x,c,n,v,h]),C=p.useCallback((k,P)=>{P.stopPropagation(),un(k),m(ve()),f(D=>D.filter(U=>!(U.type==="history"&&U.text===k)))},[]),_=p.useCallback(k=>{k.stopPropagation(),gn(),m([]),f([])},[]);p.useEffect(()=>{if(c>=0&&y.current){const k=y.current.children;k[c]&&k[c].scrollIntoView({block:"nearest"})}},[c]);const $=!n.trim()&&E.length>0;return e.jsxs("div",{ref:I,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:l,value:n,onChange:k=>{i(k.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:R,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),u&&x.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[$&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:_,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((k,P)=>e.jsxs("div",{onClick:()=>h(k),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:P===c?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:k.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.text}),k.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[d[k.entry.type],k.entry.edition&&` · ${k.entry.edition}`,k.entry.author&&` · ${k.entry.author}`]}),k.type==="history"&&e.jsx("button",{onClick:D=>C(k.text,D),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${k.type}-${k.text}-${P}`))]})]})},$e="bim-recent-ids",Ge="bim-recent-entries",Je=50,Re=5,fn=50,hn=200;function Ae(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(Ge);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem($e,JSON.stringify(i)),localStorage.removeItem(Ge),i}return[]}catch{return[]}}function bn(t){try{const n=Ae().filter(i=>i!==t);n.unshift(t),n.length>Je&&(n.length=Je),localStorage.setItem($e,JSON.stringify(n))}catch{}}const mn={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},bt=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:r,onSwitchMode:s,onToggleDraft:a,onConfigurePath:l,onSelectFolder:d,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:f})=>{const c=W(),j=[{type:"work",icon:"✍️",name:c.indexType.work,key:"works"},{type:"book",icon:"📖",name:c.indexType.book,key:"books"},{type:"collection",icon:"📚",name:c.indexType.collection,key:"collections"}],[w,b]=p.useState(g??""),[E,m]=p.useState(null),[S,y]=p.useState(null),[I,T]=p.useState(!1),[v,h]=p.useState(null),[R,C]=p.useState(""),[_,$]=p.useState(!g),[k,P]=p.useState(Ae),[D,U]=p.useState([]),[L,M]=p.useState(!1),[V,Y]=p.useState(!1),[A,ee]=p.useState(null),q=p.useRef(void 0),te=p.useRef(!1),ne=p.useCallback(async(B,G)=>{if(!B.trim()){$(!0),m(null),y(null);return}$(!1),T(!0),C("");try{if(t.searchAll){const O=await t.searchAll(B,G??Re);m(O)}else{const O=["work","book","collection"],Z=await Promise.all(O.map(se=>t.search(B,se,{page:1,pageSize:G??Re})));m({works:Z[0].entries,books:Z[1].entries,collections:Z[2].entries,totalWorks:Z[0].total,totalBooks:Z[1].total,totalCollections:Z[2].total})}}catch(O){C(O instanceof Error?O.message:String(O)),m(null)}finally{T(!1)}},[t]);p.useEffect(()=>{let B=!1;const G=["work","book","collection"];return Promise.all(G.map(O=>t.loadEntries(O,{page:1,pageSize:1}).catch(()=>({total:0})))).then(O=>{B||ee({works:O[0].total,books:O[1].total,collections:O[2].total})}),()=>{B=!0}},[t]),p.useEffect(()=>{te.current||!(g!=null&&g.trim())||(te.current=!0,ne(g))},[g,ne]);const xe=p.useCallback(B=>{if(b(B),x==null||x(B),!B.trim()){$(!0),m(null),y(null);return}q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{y(null),ne(B)},hn)},[ne,x]),le=p.useCallback(B=>{q.current&&clearTimeout(q.current),x==null||x(B),ne(B)},[ne,x]),N=p.useCallback(B=>{y(B),ne(w,fn)},[w,ne]);p.useEffect(()=>{if(!k.length){U([]);return}let B=!1;return M(!0),Promise.all(k.slice(0,10).map(async G=>{var O,Z,se;try{if(t.getEntry){const J=await t.getEntry(G);if(J)return J}const ae=await t.getItem(G);if(ae){const J=ae.authors;return{id:G,title:ae.title||G,type:ae.type||"work",author:(O=J==null?void 0:J[0])==null?void 0:O.name,dynasty:(Z=J==null?void 0:J[0])==null?void 0:Z.dynasty,role:(se=J==null?void 0:J[0])==null?void 0:se.role,edition:ae.edition||void 0}}}catch{}return null})).then(G=>{B||(U(G.filter(O=>O!==null)),M(!1))}),()=>{B=!0}},[k,t]);const he=B=>{h(B.id),bn(B.id),P(Ae()),o==null||o(B)},ke=B=>j.find(G=>G.type===B),_e=E&&(E.works.length>0||E.books.length>0||E.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:c.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[f,!u&&e.jsx(ft,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:s,onToggleDraft:a,onConfigurePath:l,onSelectFolder:d})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(ht,{transport:t,value:w,onChange:xe,onSearch:le,onEntrySelect:he}),r&&e.jsx("button",{onClick:()=>r("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:c.action.newEntry})]}),A&&_&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[c.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:A.collections.toLocaleString()})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:I?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.searching}):R?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:R})]}):_?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.loading}):D.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:c.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:D.slice(0,V?10:3).map(B=>e.jsx(Ke,{entry:B,selected:v===B.id,onClick:he,getConfig:ke},B.id))}),!V&&D.length>3&&e.jsx("button",{onClick:()=>Y(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:c.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:c.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.searchSubtitle})]})}):_e?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:j.map(({type:B,icon:G,name:O,key:Z})=>{const se=E[Z],ae=mn[Z],J=E[ae];if(se.length===0)return null;const we=!(S===B)&&J>Re;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[G," ",O,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",c.unit.items]})]}),we&&e.jsx("button",{onClick:()=>N(B),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:c.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:se.map(z=>e.jsx(Ke,{entry:z,selected:v===z.id,onClick:he,getConfig:ke,query:w},z.id))})]},B)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Se(c.search.noResultsFor,{query:w})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.tryOther})]})})]})},Ke=({entry:t,selected:n,onClick:i,getConfig:o,query:r})=>{const s=W(),{convert:a}=F(),l=r&&t.additional_titles?t.additional_titles.find(d=>d.toLowerCase().includes(r.toLowerCase())):void 0;return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(t.title)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:s.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:s.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),t.juan_count!=null&&t.juan_count>0&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,s.unit.juan]})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),l&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",a(l)]})]}),e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},yn=["〇","一","二","三","四","五","六","七","八","九"],Ze=["","十","百","千"];function mt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",r=!1;for(let s=0;s<i;s++){const a=parseInt(n[s]),l=i-1-s;a===0?r=!0:(r&&o&&(o+="〇"),r=!1,a===1&&l===1&&s===0?o+=Ze[l]:o+=yn[a]+Ze[l])}return o}function yt({type:t}){const n=W(),i={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i[t],border:`1px solid ${i[t]}40`,borderRadius:"2px",background:`${i[t]}08`},children:n.indexType[t]})}function vn({isDraft:t}){const n=W();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function jn({id:t}){const n=W(),[i,o]=p.useState(!1),r=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px 3px 10px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"12px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:r,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"13px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:s=>s.currentTarget.style.opacity="1",onMouseLeave:s=>s.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function Q({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function re({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function vt({authors:t,type:n}){const{convert:i}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,r)=>e.jsxs("span",{children:[r>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",i(o.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:i(o.name)}),o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",i(o.role)]})]},r))})}function pe({id:t,label:n,onNavigate:i,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:`/${t}`,onClick:r=>{r.preventDefault(),i(t)},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Sn({id:t,title:n,edition:i,type:o,isDraft:r,authors:s,volumeText:a,meta:l,headerExtra:d}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[e.jsxs("h1",{style:{fontSize:"24px",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0,paddingTop:"4px"},children:[e.jsx(yt,{type:o}),e.jsx(vn,{isDraft:r}),e.jsx(jn,{id:t}),d]})]}),((s==null?void 0:s.length)||l.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[s&&s.length>0&&e.jsx(vt,{authors:s,type:o}),l]})]})}function kn({items:t,onNavigate:n,renderLink:i}){const o=W(),{convert:r}=F();if(!t.length)return null;const[s,a]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:o.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((l,d)=>{const u=s===d;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(u?null:d),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:r(l.source)}),!u&&l.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r(l.title_info)}),l.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(pe,{id:l.source_bid,label:o.action.view,onNavigate:n,renderLink:i})})]}),u&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(l.title_info||l.author_info||l.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[l.title_info&&e.jsx(re,{label:o.label.titleInfo,children:r(l.title_info)}),l.author_info&&e.jsx(re,{label:o.label.authorInfo,children:r(l.author_info)}),l.edition&&e.jsx(re,{label:o.label.edition,children:r(l.edition)})]}),l.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:r(l.summary)})]}),l.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:r(l.comment)})]}),l.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:r(l.additional_comment)})]})]})]},d)})})]})}function wn({items:t}){const n=W(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.aliases}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,r)=>e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(o)},r))})]}):null}function Cn({items:t}){const n=W(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,r)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},r))})]}):null}function zn({items:t}){const n=W(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,r)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(o.description)})]},r))]})]}):null}function In({items:t}){const n=W(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,r)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(o)]},r))})]}):null}function Xe({title:t,ids:n,transport:i,onNavigate:o,renderLink:r}){const{convert:s}=F(),[a,l]=p.useState([]);return p.useEffect(()=>{if(!n.length){l([]);return}if(!i){l(n.map(u=>({id:u})));return}let d=!1;return Promise.all(n.map(u=>i.getItem(u).then(g=>({id:u,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:u})))).then(u=>{d||l(u)}),()=>{d=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(d=>({id:d}))).map(d=>{const u=d.edition?`${s(d.title)||d.id}(${s(d.edition)})`:s(d.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(pe,{id:d.id,label:u,onNavigate:o,renderLink:r})},d.id)})})]}):null}function Tn({book:t,onNavigate:n,renderLink:i}){const o=W(),{convert:r}=F(),[s,a]=p.useState(!1),l=t.resources&&t.resources.length>0,d=t.edition?`${r(t.title)||t.id}(${r(t.edition)})`:r(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:l&&!s?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(pe,{id:t.id,label:d,onNavigate:n,renderLink:i})}),l&&e.jsx("span",{onClick:()=>a(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:s?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:s?o.action.expand:o.action.collapse,children:"▼"})]}),l&&!s&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Fe,{items:t.resources,groupByType:!0})})]})}function _n({ids:t,transport:n,onNavigate:i,renderLink:o}){const r=W(),[s,a]=p.useState([]);return p.useEffect(()=>{if(!t.length){a([]);return}if(!n){a(t.map(d=>({id:d})));return}let l=!1;return Promise.all(t.map(d=>n.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:d})))).then(d=>{l||a(d)}),()=>{l=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(Q,{children:[r.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(s.length?s:t.map(l=>({id:l}))).map(l=>e.jsx(Tn,{book:l,onNavigate:i,renderLink:o},l.id))})]}):null}function Rn({workData:t,onNavigate:n,renderLink:i}){var s,a,l;const o=W(),{convert:r}=F();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(yt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(pe,{id:t.id,label:r(t.title),onNavigate:n,renderLink:i})}),((s=t.juan_count)==null?void 0:s.number)&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[mt(t.juan_count.number),o.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(vt,{authors:t.authors,type:"work"}),((a=t.description)==null?void 0:a.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(l=t.authors)!=null&&l.length?"8px 0 0":"0",textAlign:"justify"},children:r(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(re,{label:o.label.parentWork,children:e.jsx(pe,{id:t.parent_work.id,label:r(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Ln({items:t,onNavigate:n,renderLink:i}){const o=W(),{convert:r}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(s=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:o.indexType.collection}),e.jsx(pe,{id:s.id,label:r(s.title)||s.id,onNavigate:n,renderLink:i}),s.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Se(o.catalog.volume,{n:s.volume_index})})]},s.id))}):null}const jt=({data:t,id:n,transport:i,onNavigate:o,renderLink:r,headerExtra:s,className:a,style:l})=>{var _,$,k,P,D,U;const d=W(),{convert:u}=F(),[g,x]=p.useState(null),[f,c]=p.useState(!1),[j,w]=p.useState(null),[b,E]=p.useState(null),[m,S]=p.useState([]),y=t||g;if(p.useEffect(()=>{if(t||!n||!i)return;let L=!1;return c(!0),w(null),i.getItem(n).then(M=>{L||(M?x(M):w(d.misc.notFoundEntry))}).catch(M=>{L||w(M instanceof Error?M.message:d.misc.loadFailed)}).finally(()=>{L||c(!1)}),()=>{L=!0}},[t,n,i]),p.useEffect(()=>{if(!y||!i){E(null),S([]);return}let L=!1;const M=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(M?i.getItem(M).then(V=>{!L&&V&&V.type==="work"&&E(V)}).catch(()=>{}):E(null),y.type==="book"){const V=y;V.contained_in&&V.contained_in.length>0?Promise.all(V.contained_in.map(Y=>{const A=typeof Y=="string"?Y:Y.id,ee=typeof Y=="string"?void 0:Y.volume_index;return i.getItem(A).then(q=>({id:A,title:q&&q.title||A,volume_index:ee})).catch(()=>({id:A,title:A,volume_index:ee}))})).then(Y=>{L||S(Y)}):S([])}else S([]);return()=>{L=!0}},[y,i]),f)return e.jsx("div",{className:a,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((L,M)=>e.jsx("div",{style:{height:M===1?"32px":"16px",width:`${L}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},M))})});if(j)return e.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:j});if(!y)return null;const I=y.type==="book"?y:null,T=y.type==="collection"?y:null,v=y.type==="work"?y:null;let h=!1;try{h=H.extractStatus(y.id)==="draft"}catch{}let R="";(_=y.juan_count)!=null&&_.number?R=mt(y.juan_count.number)+d.unit.juan:($=y.juan_count)!=null&&$.description&&(R=u(y.juan_count.description));const C=[];return(k=y.publication_info)!=null&&k.year&&C.push(e.jsx(re,{label:d.label.year,children:y.publication_info.year},"year")),(P=y.current_location)!=null&&P.name&&C.push(e.jsx(re,{label:d.label.currentLocation,children:u(y.current_location.name)},"loc")),(D=y.page_count)!=null&&D.description&&C.push(e.jsx(re,{label:d.label.pageCount,children:y.page_count.description},"page")),I!=null&&I.edition&&C.push(e.jsx(re,{label:d.label.edition,children:u(I.edition)},"ver")),v!=null&&v.parent_work&&C.push(e.jsx(re,{label:d.label.parentWork,children:e.jsx(pe,{id:v.parent_work.id,label:u(v.parent_work.title),onNavigate:o,renderLink:r})},"pw")),v!=null&&v.parent_works&&v.parent_works.length>0&&!v.parent_work&&C.push(e.jsx(re,{label:d.label.parentWork,children:v.parent_works.map((L,M)=>e.jsxs("span",{children:[M>0&&"、",e.jsx(pe,{id:L,onNavigate:o,renderLink:r})]},L))},"pws")),e.jsxs("div",{className:a,style:l,children:[e.jsx(Sn,{id:y.id,title:u(y.title),edition:y.edition?u(y.edition):void 0,type:y.type,isDraft:h,authors:y.authors,volumeText:R,meta:C,headerExtra:s}),((U=y.description)==null?void 0:U.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(y.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.containedIn}),e.jsx(Ln,{items:m,onNavigate:o,renderLink:r})]}),b&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.belongsToWork}),e.jsx(Rn,{workData:b,onNavigate:o,renderLink:r})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(Cn,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(wn,{items:y.additional_titles}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(kn,{items:y.indexed_by,onNavigate:o,renderLink:r}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{children:d.section.resources}),e.jsx(Fe,{items:y.resources,groupByType:!0})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(zn,{items:I.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(In,{items:T.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx(Xe,{title:d.section.relatedVersions,ids:I.related_books,transport:i,onNavigate:o,renderLink:r}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(Xe,{title:d.section.containedBooks,ids:T.books,transport:i,onNavigate:o,renderLink:r}),(v==null?void 0:v.books)&&v.books.length>0&&e.jsx(_n,{ids:v.books,transport:i,onNavigate:o,renderLink:r}),(v==null?void 0:v.related_works)&&v.related_works.length>0&&(()=>{const L=[],M=v.related_works.filter(A=>A.relation==="part_of"),V=v.related_works.filter(A=>A.relation==="has_part"),Y=v.related_works.filter(A=>!A.relation);return M.length>0&&L.push({label:d.section.belongsToWork,items:M}),V.length>0&&L.push({label:d.section.containedWorks,items:V}),Y.length>0&&L.push({label:d.section.relatedWorks,items:Y}),L.map(A=>e.jsxs("div",{children:[e.jsxs(Q,{children:[A.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",A.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:A.items.map(ee=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(pe,{id:ee.id,label:u(ee.title),onNavigate:o,renderLink:r})},ee.id))})]},A.label))})()]})};function En({data:t}){const n=W(),{convert:i}=F(),{stats:o}=t,r=o.processed_volumes??o.total_found_volumes,s=r!=null&&t.total_volumes>0?Math.round(r/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),s!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r})," ",n.unit.volume," (",s,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Bn({sections:t,activeSection:n,onSelect:i}){const o=W();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:qe(n===null),children:o.catalog.all}),t.map(r=>e.jsxs("button",{onClick:()=>i(r.name),style:qe(n===r.name),children:[r.name,r.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[r.volume_range[0],"–",r.volume_range[1]]})]},r.name))]})}function qe(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Wn({id:t,label:n,onNavigate:i,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:`/${t}`,onClick:r=>{r.preventDefault(),i(t)},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Pn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],o=t[t.length-1];return o-i+1===t.length?`${i}–${o}`:t.length<=3?t.join(", "):`${i}–${o} (${t.length}${n})`}function Qe({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const r=W(),{convert:s}=F(),a=t.book_id||t.work_id,l=o&&t.volumes.length>0?Pn(t.volumes,r.unit.volume):null,d=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:l}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[s(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(u=>s(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:s(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:d?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,r.unit.volume]}),a&&e.jsx(Wn,{id:a,label:t.book_id?r.indexType.book:r.indexType.work,onNavigate:n,renderLink:i}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:r.catalog.unmatched_label})]})}const St=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:r,className:s,style:a})=>{const l=W(),[d,u]=p.useState(null),[g,x]=p.useState(!1),[f,c]=p.useState(null),[j,w]=p.useState(null),[b,E]=p.useState(""),m=t||d;p.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let v=!1;return x(!0),c(null),i.getCollectionCatalog(n).then(h=>{v||(h?u(h):c(l.catalog.notFound))}).catch(h=>{v||c(h instanceof Error?h.message:l.catalog.loadFailed)}).finally(()=>{v||x(!1)}),()=>{v=!0}},[t,n,i,l]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,y=p.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const v=m.books.map(R=>R.volumes[0]).filter(R=>R!=null);return new Set(v).size<v.length},[m]),I=p.useMemo(()=>{if(!m)return[];let v=m.books;if(j&&(v=v.filter(h=>h.section===j)),b.trim()){const h=b.trim().toLowerCase();v=v.filter(R=>R.title.toLowerCase().includes(h)||R.sub_items&&R.sub_items.some(C=>C.toLowerCase().includes(h))||R.edition&&R.edition.toLowerCase().includes(h))}return v},[m,j,b]),T=p.useMemo(()=>{if(!y)return null;const v=[],h=new Map;for(const C of I){if(!C.volumes||C.volumes.length===0)continue;const _=C.volumes[0];h.has(_)||h.set(_,[]),h.get(_).push(C)}const R=[...h.keys()].sort((C,_)=>C-_);for(const C of R)v.push({volume:C,books:h.get(C)});return v},[I,y]);return g?e.jsx("div",{className:s,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:l.catalog.loading})}):f?e.jsx("div",{className:s,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):m?e.jsxs("div",{className:s,style:a,children:[e.jsx(En,{data:m}),S&&e.jsx(Bn,{sections:m.sections,activeSection:j,onSelect:w}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:l.search.searchBookName,value:b,onChange:v=>E(v.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[I.length," ",l.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[T?T.map((v,h)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Se(l.catalog.volume,{n:v.volume})}),v.books.map((R,C)=>e.jsx(Qe,{book:R,onNavigate:o,renderLink:r,showVolumes:R.volumes.length>1},`${v.volume}-${C}`))]},`${v.volume}-${h}`)):I.map((v,h)=>e.jsx(Qe,{book:v,onNavigate:o,renderLink:r,showVolumes:!0},h)),I.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:l.catalog.noMatch})]})]}):null},$n=["〇","一","二","三","四","五","六","七","八","九"],et=["","十","百","千"],An=["","萬","億"];function kt(t){if(t===0)return"〇";if(t<0)return`負${kt(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const r=i%1e4;r>0?n.unshift(Mn(r,o>0)+An[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Mn(t,n){const i=[];let o=t;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let r="";for(let s=0;s<i.length;s++){const a=i[s],l=i.length-1-s;a===0?r&&!r.endsWith("〇")&&(r+="〇"):a===1&&l===1&&s===0&&!n?r+=et[l]:r+=$n[a]+et[l]}return r.replace(/〇$/,"")}const wt={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Fn(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ct({file:t,isActive:n,onSelect:i}){return e.jsx("button",{onClick:()=>i(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:Fn(t)})}function zt(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>zt(o,n)))}function It(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((r,s)=>r+It(s),0))||0;return n+i}function Tt({group:t,activeFile:n,onSelect:i,depth:o=0}){var u;const r=zt(t,n||""),[s,a]=p.useState(r),l=It(t),d=!!((u=t.children)!=null&&u.length);return p.useEffect(()=>{r&&a(!0)},[r]),e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>a(!s),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:r?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:s?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",l,")"]})]}),s&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(g=>e.jsx(Ct,{file:g,isActive:n===g,onSelect:i},g))}),d&&t.children.map((g,x)=>e.jsx(Tt,{group:g,activeFile:n,onSelect:i,depth:o+1},x))]})]})}function Hn({files:t,groups:n,activeFile:i,onSelect:o}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((r,s)=>e.jsx(Tt,{group:r,activeFile:i,onSelect:o},s))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(r=>e.jsx(Ct,{file:r,isActive:i===r,onSelect:o},r))})}function On({type:t}){const n=wt[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Dn({section:t,onNavigate:n}){const{convert:i}=F(),[o,r]=p.useState(!1),s=!!t.summary,a=!!t.comment,l=!!t.additional_comment,d=s||a||l;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&r(!o),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},children:[t.book_title?`《${i(t.book_title)}》`:i(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[kt(t.n_juan),"卷"]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:i(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:`/${t.work_id}`,onClick:u=>{u.preventDefault(),u.stopPropagation(),n(t.work_id)},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),o&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:i(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:i(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(t.additional_comment)})]})]})]})}function Vn({section:t}){const{convert:n}=F(),[i,o]=p.useState(!1),r=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>r&&o(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:r?"pointer":"default",userSelect:"none"},children:[e.jsx(On,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),r&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${wt[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:n(t.content)})})]})}function Nn({section:t}){const{convert:n}=F();if(!t.content&&!t.title)return null;const i=n((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`));return e.jsx("div",{style:{padding:"6px 0",fontSize:"13px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.7,whiteSpace:"pre-line"},children:i})}function Un({juan:t,searchQuery:n,onNavigate:i}){const{convert:o}=F(),r=p.useMemo(()=>{if(!n.trim())return t.sections;const a=n.trim().toLowerCase();return t.sections.filter(l=>{var d,u,g,x,f;return((d=l.title)==null?void 0:d.toLowerCase().includes(a))||((u=l.book_title)==null?void 0:u.toLowerCase().includes(a))||((g=l.author)==null?void 0:g.toLowerCase().includes(a))||((x=l.author_info)==null?void 0:x.toLowerCase().includes(a))||((f=l.summary)==null?void 0:f.toLowerCase().includes(a))})},[t.sections,n]),s=r.filter(a=>a.type==="书").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:o(t.title)}),t.source_url&&e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:"原文 ↗"}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[s," 部书"]})]}),r.map((a,l)=>a.type==="书"?e.jsx(Dn,{section:a,onNavigate:i},l):a.type==="部"||a.type==="类"?e.jsx(Vn,{section:a},l):e.jsx(Nn,{section:a},l)),r.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const _t=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:r,onJuanChange:s,className:a,style:l})=>{const[d,u]=p.useState(null),[g,x]=p.useState(!1),[f,c]=p.useState(null),[j,w]=p.useState(null),[b,E]=p.useState(null),[m,S]=p.useState(!1),[y,I]=p.useState(""),T=r??j,v=p.useCallback($=>{w($),s==null||s($)},[s]),h=t||d;p.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return x(!0),c(null),i.getCollatedEditionIndex(n).then(k=>{$||(k?(u(k),!r&&k.juan_files.length>0&&v(k.juan_files[0])):c("未找到整理本数据"))}).catch(k=>{$||c(k instanceof Error?k.message:"加载失败")}).finally(()=>{$||x(!1)}),()=>{$=!0}},[t,n,i,r,v]),p.useEffect(()=>{t&&t.juan_files.length>0&&!T&&v(t.juan_files[0])},[t,T,v]);const R=n||(h==null?void 0:h.work_id),C=p.useCallback(async $=>{if(!(!R||!(i!=null&&i.getCollatedJuan))){S(!0),E(null);try{const k=await i.getCollatedJuan(R,$);E(k)}catch{E(null)}finally{S(!1)}}},[R,i]);p.useEffect(()=>{T&&C(T)},[T,C]);const _=$=>{v($),I("")};return g?e.jsx("div",{className:a,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):f?e.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):h?e.jsxs("div",{className:a,style:l,children:[e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:h.total_juan})," 卷"]})}),e.jsx(Hn,{files:h.juan_files,groups:h.juan_groups,activeFile:T,onSelect:_}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:y,onChange:$=>I($.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),m?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载中..."}):b?e.jsx(Un,{juan:b,searchQuery:y,onNavigate:o}):T?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null]}):null},Yn=[{id:"FCNcSJbF77V",title:"欽定四庫全書·文淵閣本",description:"清·紀昀等編,藏於臺灣國立故宮博物院",group:"重要叢編"},{id:"FCPFLm7Uie3",title:"欽定四庫全書·文源閣本",description:"清·紀昀等編,已毀於英法聯軍",group:"重要叢編"},{id:"FCPFLywwwNP",title:"欽定四庫全書·文溯閣本",description:"清·紀昀等編,藏於甘肅省圖書館",group:"重要叢編"},{id:"FCPFMeX1suq",title:"欽定四庫全書·文津閣本",description:"清·紀昀等編,藏於中國國家圖書館",group:"重要叢編"},{id:"GY4HvsY3w3u",title:"欽定四庫全書總目",description:"清·紀昀等編,200卷",group:"經典作品"},{id:"GY4JLP3nDUB",title:"欽定四庫全書",description:"清乾隆38-52年,紀昀等編纂",group:"經典作品"},{id:"GY3ty2LN9ro",title:"易經",description:"西周·周文王",group:"經典作品"},{id:"GY4JM7j7yi7",title:"史記",description:"西漢·司馬遷",group:"經典作品"}],Rt=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:r})=>{const s=W(),[a,l]=p.useState(null),[d,u]=p.useState([]),[g,x]=p.useState("recommend"),f=o??g,c=S=>{x(S),r==null||r(S)},[j,w]=p.useState(null),[b,E]=p.useState(null);p.useEffect(()=>{if(!t.getAllEntries)return;let S=!1;return t.getAllEntries().then(y=>{if(S)return;const I=y.filter(h=>h.type==="work").length,T=y.filter(h=>h.type==="book").length,v=y.filter(h=>h.type==="collection").length;l({works:I,books:T,collections:v})}).catch(()=>{}),()=>{S=!0}},[t]),p.useEffect(()=>{let S=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const I=await t.getRecommended();if(I!=null&&I.groups)return I.groups.flatMap(T=>T.items.map(v=>({...v,group:T.name})))}catch{}return Yn})().then(async I=>{if(S)return;const T=I.filter(h=>h.id);if(T.length===0)return;const v=await Promise.all(T.map(async h=>{try{let R=null;if(t.getEntry)R=await t.getEntry(h.id);else{const C=await t.getItem(h.id);C&&(R={id:h.id,title:C.title||h.id,type:C.type||"work"})}if(R)return{...R,group:h.group,fallbackDescription:h.description}}catch{}return{id:h.id,title:h.title,type:h.id.startsWith("FC")?"collection":"work",group:h.group,fallbackDescription:h.description}}));S||u(v.filter(h=>h!==null))}),()=>{S=!0}},[t,i]),p.useEffect(()=>{if(!t.getResourceProgress)return;let S=!1;return t.getResourceProgress().then(y=>{S||w(y)}).catch(()=>{}),()=>{S=!0}},[t]),p.useEffect(()=>{if(!t.getSiteProgress)return;let S=!1;return t.getSiteProgress().then(y=>{S||E(y)}).catch(()=>{}),()=>{S=!0}},[t]);const m=S=>{switch(S){case"work":return"✍️";case"book":return"📖";case"collection":return"📚"}};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:[e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Le,{label:s.home.recommendTab,active:f==="recommend",onClick:()=>c("recommend")}),e.jsx(Le,{label:s.home.catalogTab,active:f==="catalog",onClick:()=>c("catalog")}),e.jsx(Le,{label:s.home.siteTab,active:f==="site",onClick:()=>c("site")})]}),f==="recommend"&&e.jsx(Gn,{recommended:d,onNavigate:n,getIcon:m,t:s}),f==="catalog"&&e.jsx(Jn,{progress:j,t:s,onNavigate:n}),f==="site"&&e.jsx(Zn,{progress:b,t:s,totalWorks:(a==null?void 0:a.works)??0})]}),a&&e.jsxs("div",{style:{display:"flex",gap:"32px",padding:"16px 0",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx(Ee,{icon:"✍️",label:s.indexType.work,count:a.works}),e.jsx(Ee,{icon:"📖",label:s.indexType.book,count:a.books}),e.jsx(Ee,{icon:"📚",label:s.indexType.collection,count:a.collections})]})]})},Le=({label:t,active:n,onClick:i})=>e.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Gn=({recommended:t,onNavigate:n,getIcon:i,t:o})=>{if(t.length===0)return null;const r=new Map;for(const s of t){const a=s.group||o.home.recommendedBrowse;r.has(a)||r.set(a,[]),r.get(a).push(s)}return e.jsx(e.Fragment,{children:Array.from(r.entries()).map(([s,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:s}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(l=>{const d=l.dynasty||l.author?`${l.dynasty?`〔${l.dynasty}〕`:""}${l.author||""}`:l.fallbackDescription;return e.jsxs("a",{href:`/${l.id}`,onClick:u=>{u.preventDefault(),n==null||n(l.id)},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:i(l.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[l.title,l.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:l.edition})]}),d&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d})]})]},l.id)})})]},s))})},Jn=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const o=[...t.resources].sort((l,d)=>l.priority-d.priority),r=["in_progress","done","todo"],s={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:r.map(l=>{const d=o.filter(u=>u.status===l);return d.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[l]}}),s[l]," (",d.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:d.map(u=>e.jsx(Kn,{item:u,t:n,statusColor:a[l],onNavigate:i},u.id))})]},l)})})},Kn=({item:t,t:n,statusColor:i,onNavigate:o})=>{const r=t.total>0?Math.round(t.imported/t.total*100):0,s=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=t.edition?`${t.name}·${t.edition}`:t.name,l=t.collection_id||t.work_id;return l&&o?e.jsx("a",{href:`/${l}`,onClick:d=>{d.preventDefault(),o(l)},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:s})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Se(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Zn=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const o=[...t.resources].sort((d,u)=>d.priority-u.priority),r=o.filter(d=>d.imported>0),s=o.filter(d=>d.imported===0),a=r.reduce((d,u)=>Math.max(d,u.imported),0),l=i>0?Math.round(a/i*100):0;return e.jsxs("div",{children:[i>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",l,"%)"]}),r.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",r.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map(d=>e.jsx(tt,{item:d,t:n,totalWorks:i},d.id))})]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(d=>e.jsx(tt,{item:d,t:n,totalWorks:i},d.id))})]})]})},tt=({item:t,t:n,totalWorks:i})=>{const o=i>0?Math.round(t.imported/i*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&i>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Ee=({icon:t,label:n,count:i})=>e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"20px",marginBottom:"4px"},children:t}),e.jsx("div",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #333)"},children:i.toLocaleString()}),e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n})]}),Xn=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o})=>{var R;const[r,s]=p.useState(null),[a,l]=p.useState(null),[d,u]=p.useState(!1),[g,x]=p.useState("detail"),[f,c]=p.useState([]),[j,w]=p.useState(!1),[b,E]=p.useState(null),[m,S]=p.useState(!1),y=p.useCallback(async C=>{if(!t.getCollatedEditionIndex){E(null);return}S(!0);try{const _=await t.getCollatedEditionIndex(C);E(_)}catch{E(null)}finally{S(!1)}},[t]),I=p.useCallback(async C=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){c([]);return}w(!0);try{if(t.getCollectionCatalogs){const _=await t.getCollectionCatalogs(C);c(_||[])}else if(t.getCollectionCatalog){const _=await t.getCollectionCatalog(C);c(_?[{resource_id:"",data:_}]:[])}}catch{c([])}finally{w(!1)}},[t]),T=p.useCallback(async C=>{if(i){i(C);return}s(C),l(null),c([]),E(null),x("detail"),u(!0);try{const _=await t.getItem(C.id);_&&(l(_),_.type==="collection"?I(C.id):_.type==="work"&&_.has_collated&&y(C.id))}catch(_){console.error("加载详情失败:",_)}finally{u(!1)}},[t,i,I,y]),v=p.useCallback(async C=>{l(null),c([]),E(null),x("detail"),u(!0);try{const _=await t.getItem(C);_&&(l(_),s({id:C,title:_.title||C,type:_.type||"book"}),_.type==="collection"?I(C):_.type==="work"&&_.has_collated&&y(C))}catch(_){console.error("导航失败:",_)}finally{u(!1)}},[t,I,y]),h=(a==null?void 0:a.type)==="collection"&&(f.length>0||j)||(a==null?void 0:a.type)==="work"&&(b||m);return e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(bt,{transport:t,onEntryClick:T,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:d?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中..."})}):a?e.jsxs(e.Fragment,{children:[h&&e.jsxs("div",{style:{display:"flex",gap:"0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:[e.jsx("button",{onClick:()=>x("detail"),style:Ce(g==="detail"),children:"基本信息"}),a.type==="collection"&&j&&f.length===0&&e.jsxs("button",{onClick:()=>{},style:Ce(!1),children:["目錄",e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),a.type==="collection"&&f.map(C=>e.jsx("button",{onClick:()=>x(`catalog:${C.resource_id}`),style:Ce(g===`catalog:${C.resource_id}`),children:C.short_name?`${C.short_name}·目錄`:"叢編目錄"},C.resource_id)),a.type==="work"&&(b||m)&&e.jsxs("button",{onClick:()=>x("collated"),style:Ce(g==="collated"),children:["整理本",m&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),e.jsx("div",{style:{padding:"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:g==="detail"?e.jsx(jt,{data:a,transport:t,onNavigate:v}):g.startsWith("catalog:")?e.jsx(St,{data:(R=f.find(C=>`catalog:${C.resource_id}`===g))==null?void 0:R.data,onNavigate:v}):g==="collated"?e.jsx(_t,{index:b||void 0,workId:a.id,transport:t,onNavigate:v}):null})]}):e.jsx(Rt,{transport:t,onNavigate:v,recommendedIds:o})})]})};function Ce(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const qn=({data:t,onNavigate:n,className:i,style:o})=>{var g;const r=W(),{convert:s}=F(),[a,l]=p.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[d,u]=p.useState(null);return e.jsxs("div",{className:i,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:s(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[r.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",r.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",r.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",r.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Qn,{division:x,expanded:a===x.name,onToggle:()=>l(a===x.name?null:x.name),expandedCat:d,onCatToggle:f=>u(d===f?null:f),onNavigate:n},x.name))})]})},Qn=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:r,onNavigate:s})=>{const{convert:a}=F(),l=t.categories.reduce((d,u)=>{const g=u.stats||{zhulu:0,cunmu:0};return d+(g.zhulu||0)+(g.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",l," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(d=>{const u=`${t.name}/${d.name}`;return e.jsx(eo,{category:d,expanded:o===u,onToggle:()=>r(u),onNavigate:s},d.name)})})]})},eo=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var d,u,g,x;const{convert:r}=F(),s=((d=t.books)==null?void 0:d.zhulu)||[],a=((u=t.books)==null?void 0:u.cunmu)||[],l=(((g=t.stats)==null?void 0:g.zhulu)||s.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[r(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l," 部 ",n?"▲":"▼"]})]}),n&&(s.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[s.length>0&&e.jsx(nt,{label:"著錄",books:s,onNavigate:o}),a.length>0&&e.jsx(nt,{label:"存目",books:a,onNavigate:o})]})]})},nt=({label:t,books:n,onNavigate:i})=>{const{convert:o}=F(),[r,s]=p.useState(n.length<=20),a=r?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map((l,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:l.work_id&&i?e.jsx("a",{href:`/${l.work_id}`,onClick:u=>{u.preventDefault(),i(l.work_id)},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(l.title)}):o(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(l.author).slice(0,20)})]},d))}),!r&&e.jsxs("button",{onClick:()=>s(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ie=({title:t,onSave:n,onAskAI:i,extraButtons:o,children:r})=>{const s=W();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,i&&e.jsx("button",{onClick:i,style:no,children:"AI"}),n&&e.jsx("button",{onClick:n,style:to,children:s.action.save})]})]}),r]})},to={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},no={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},X=({label:t,value:n,onChange:i,placeholder:o,disabled:r})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:s=>i(s.target.value),placeholder:o,disabled:r,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),ue=({value:t,onChange:n,placeholder:i})=>{const o=p.useRef(null);return p.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:r=>n(r.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Ie=({children:t,color:n,style:i})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...i},children:t});function oo(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ze=({value:t,onChange:n,label:i})=>{const[o,r]=p.useState(!1),s=p.useRef(null),a=oo(t||"");return p.useEffect(()=>{o&&s.current&&s.current.focus()},[o]),!o&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ot,children:i}),e.jsxs("div",{onClick:()=>r(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:a.name}),e.jsx(Ie,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ot,children:i}),e.jsx("input",{ref:s,type:"text",value:t||"",onChange:l=>n(l.target.value),onBlur:()=>r(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},ot={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function io(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function ro(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Lt=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=W(),[r,s]=p.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),s(t.length)},l=x=>{n(t.filter((f,c)=>c!==x)),r===x&&s(null)},d=(x,f,c)=>{const j=[...t];j[x]={...j[x],[f]:c},n(j)},u=(x,f)=>{const c=[...t];c[x]={...c[x],type:f,id:"",name:""},n(c),f==="bookID"&&i&&i(j=>{const w=[...t];w[x]={...w[x],id:j.id,name:j.title,type:"bookID"},n(w)})},g=x=>{i&&i(f=>{const c=[...t];c[x]={...c[x],id:f.id,name:f.title,type:"bookID"},n(c)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>s(r===f?null:f),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:r===f?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${o.editor.sourcePlaceholder} ${f+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:io(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:ro(x.type)}),e.jsx("button",{onClick:c=>{c.stopPropagation(),l(f)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),r===f&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>u(f,"bookID"),style:{...it,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>u(f,"url"),style:{...it,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ce,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const c=[...t];c[f]={...c[f],type:"",id:"",name:""},n(c)},style:rt,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>g(f),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>g(f),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ce,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const c=[...t];c[f]={...c[f],type:"",id:"",name:""},n(c)},style:rt,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:c=>d(f,"name",c.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:c=>d(f,"id",c.target.value),placeholder:"https://...",style:ge})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...ce,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:c=>d(f,"details",c.target.value),placeholder:o.editor.detailsPlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:c=>d(f,"position",c.target.value),placeholder:"如: 卷三, p.52",style:ge})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:c=>d(f,"version",c.target.value),placeholder:"如: v1.0, 2024-01",style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:c=>d(f,"processor_version",c.target.value),placeholder:"如: v0.1",style:ge})]})]})]})]})})]},f)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},ce={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ge={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},it={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},rt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Et(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Bt(t){return!t||t.length===0?"":JSON.stringify(t)}const Wt=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:r,belongsToWork:s,belongsToCollection:a,childWorks:l,childCollections:d,containedBooks:u,siblingBooks:g,onLinkEntity:x,onUnlinkEntity:f,onViewEntity:c,onCreateAndLink:j,onSaveRelations:w})=>{const b=W();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:b.section.relations})]}),w&&e.jsx("button",{onClick:w,style:lo,children:b.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:b.relation.belongsToWork,entity:s,onView:c,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>j("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(ye,{direction:"up",title:b.relation.containedInCollection,entity:a,onView:c,onUnlink:()=>f("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>j("collectionId","collection",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),s&&g&&g.length>0&&e.jsx(fe,{direction:"horizontal",title:`${b.relation.siblingVersions} (${g.length})`,entities:g,onView:c,onAdd:()=>j("siblingBook","book",{workId:s.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:b.relation.parentWork,entity:o,onView:c,onUnlink:()=>f("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>j("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),l&&l.length>0&&e.jsx(fe,{direction:"down",title:`${b.relation.childWorks} (${l.length})`,entities:l,onView:c,onAdd:()=>j("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),d&&d.length>0&&e.jsx(fe,{direction:"down",title:`${b.relation.collectionImpl} (${d.length})`,entities:d,onView:c,onAdd:()=>j("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(fe,{direction:"down",title:`${b.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:c,onAdd:()=>j("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:b.relation.correspondingWork,entity:s,onView:c,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>j("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(ye,{direction:"up",title:b.relation.parentCollection,entity:r,onView:c,onUnlink:()=>f("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>j("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(fe,{direction:"down",title:`${b.relation.childCollections} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:c,onAdd:()=>j("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(fe,{direction:"down",title:`${b.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:c,onAdd:()=>j("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},ye=({direction:t,title:n,entity:i,onView:o,onUnlink:r,onLink:s,onCreate:a,linkLabel:l,createLabel:d,notLinkedLabel:u,viewLabel:g,unlinkLabel:x})=>{const f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",c=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:c}),e.jsx("span",{children:n})]}),i?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Pt(i.type)}),e.jsx("span",{style:{fontWeight:500},children:i.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(lt,{onClick:()=>o(i),title:g,children:"👁️"}),e.jsx(lt,{onClick:r,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:u}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Me,{onClick:s,children:l}),e.jsx(Me,{onClick:a,primary:!0,children:d})]})]})},fe=({direction:t,title:n,entities:i,onView:o,onAdd:r,addLabel:s,noneLabel:a,expandMoreLabel:l})=>{const[d,u]=p.useState(!1),g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",f=d?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[f.map(c=>e.jsxs("div",{onClick:()=>o(c),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Pt(c.type)}),e.jsx("span",{children:c.title})]},c.id)),i.length>5&&!d&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[l," (",i.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Me,{onClick:r,primary:!0,children:["+ ",s]})})]})},lt=({onClick:t,title:n,danger:i,children:o})=>e.jsx("button",{onClick:r=>{r.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),Me=({onClick:t,primary:n,children:i})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:i});function Pt(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const lo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},$t=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:r,onCreate:s,searchResults:a,onSearch:l,isLoading:d,excludeId:u})=>{const[g,x]=p.useState(""),f=u?a.filter(b=>b.id!==u):a;p.useEffect(()=>{t&&(x(""),l(""))},[t]);const c=b=>{x(b),l(b)};if(!t)return null;const j=n==="work"?"作品":n==="book"?"书籍":"丛编",w=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:so,children:e.jsxs("div",{style:ao,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),e.jsx("button",{onClick:r,style:co,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:b=>c(b.target.value),placeholder:`搜索${j}名称或 ID...`,autoFocus:!0,style:po})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:d?e.jsx("div",{style:Be,children:"搜索中..."}):f.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:f.map(b=>e.jsxs("div",{onClick:()=>o(b),style:xo,children:[e.jsx("span",{style:{fontSize:"16px"},children:w}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):g?e.jsxs("div",{style:Be,children:["未找到匹配的",j]}):e.jsxs("div",{style:Be,children:["输入关键词搜索",j]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:s,style:uo,children:["创建新",j,"并关联"]})]})]})})},so={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ao={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},co={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},po={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},xo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Be={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},uo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},st={work:"作品",book:"书籍",collection:"丛编"},go={work:"📜",book:"📖",collection:"📚"},At=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:r,onCancel:s})=>{const[a,l]=p.useState(""),d=p.useRef(null);p.useEffect(()=>{t&&(l((o==null?void 0:o.title)||""),setTimeout(()=>{var f,c;(f=d.current)==null||f.focus(),(c=d.current)==null||c.select()},100))},[t,o==null?void 0:o.title]);const u=f=>{f.key==="Enter"&&a.trim()?g():f.key==="Escape"&&s()},g=()=>{a.trim()&&r(a.trim(),{...o,title:a.trim()})};if(!t)return null;const x=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${st[n]}`}};return e.jsx("div",{style:fo,onClick:f=>{f.target===f.currentTarget&&s()},children:e.jsxs("div",{style:ho,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:go[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:d,type:"text",value:a,onChange:f=>l(f.target.value),onKeyDown:u,placeholder:`请输入${st[n]}名称...`,style:bo})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:s,style:mo,children:"取消"}),e.jsx("button",{onClick:g,disabled:!a.trim(),style:{...yo,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},fo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ho={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",minWidth:"400px",maxWidth:"500px",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},bo={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},mo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},yo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function vo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Mt(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function jo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Ft=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:r,showCreateButton:s=!1,createButtonText:a,onSelect:l,onCancel:d,onCreate:u,onSearch:g})=>{const[x,f]=p.useState(""),[c,j]=p.useState([]),[w,b]=p.useState(!1),[E,m]=p.useState("recent");p.useEffect(()=>{t&&(f(""),j([]),m(o.length>0?"recent":"search"))},[t,o.length]),p.useEffect(()=>{if(!x.trim()){j([]);return}const h=setTimeout(async()=>{b(!0);try{j(await g(x,i))}catch{j([])}finally{b(!1)}},300);return()=>clearTimeout(h)},[x,i,g]);const S=p.useCallback(h=>{f(h.target.value),h.target.value.trim()&&m("search")},[]),y=p.useCallback(h=>r?h.filter(R=>R.id!==r):h,[r]);if(!t)return null;const I=n||(i==="all"?"选择实体":`选择${Mt(i)}`),T=y(o),v=y(c);return e.jsx("div",{style:ko,children:e.jsxs("div",{style:wo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:I}),e.jsx("button",{onClick:d,style:Co,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:S,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:zo}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),w&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),T.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(at,{active:E==="recent",onClick:()=>m("recent"),children:["最近使用 (",T.length,")"]}),e.jsxs(at,{active:E==="search",onClick:()=>m("search"),children:["搜索结果 ",v.length>0&&`(${v.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:E==="recent"&&T.length>0?e.jsx(dt,{entities:T,onSelect:l}):x.trim()?w?e.jsx(We,{message:"搜索中..."}):v.length>0?e.jsx(dt,{entities:v,onSelect:l}):e.jsx(We,{message:"未找到匹配的结果"}):e.jsx(We,{message:"输入关键词开始搜索"})}),s&&u&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:u,style:Io,children:a||"创建新实体"})]})]})})},at=({active:t,onClick:n,children:i})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:i}),dt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(So,{entity:i,onClick:()=>n(i)},i.id))}),So=({entity:t,onClick:n})=>{const[i,o]=p.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:vo(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:jo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Mt(t.type)})]})},We=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),ko={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},wo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Co={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},zo={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Io={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},To={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},_o={work:"📜",collection:"📚",book:"📖"},Ro=({data:t,onChange:n,onSave:i,transport:o,onNavigate:r,showDelete:s,onDelete:a,onAskAI:l,renderSectionActions:d,onDownloadResource:u,downloadStatuses:g,relations:x,onRelationsChange:f})=>{var we;const c=W(),[j,w]=p.useState(!1),[b,E]=p.useState("work"),[m,S]=p.useState(""),[y,I]=p.useState(""),[T,v]=p.useState([]),[h,R]=p.useState(!1),[C,_]=p.useState(!1),[$,k]=p.useState("work"),[P,D]=p.useState(""),[U,L]=p.useState(),[M,V]=p.useState(!1),[Y,A]=p.useState(null),[ee,q]=p.useState([]);p.useRef(null);const te=t.type,ne=te==="work",xe=te==="collection",le=te==="book",N=p.useCallback((z,K)=>{n({...t,[z]:K})},[t,n]),he=p.useCallback((z,K)=>{S(z),E(K),I(c.editor.selectToLink+c.indexType[K]),v([]),w(!0)},[c]),ke=p.useCallback(z=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,z)},[o,t.id]),_e=p.useCallback(z=>{r==null||r(z.id,z.type)},[r]),B=p.useCallback((z,K,de)=>{const Ot={...de,author:(de==null?void 0:de.author)||t.author,dynasty:(de==null?void 0:de.dynasty)||t.dynasty};k(K),D(z),L(Ot),_(!0)},[t.author,t.dynasty]),G=p.useCallback((z,K)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,P,{type:$,title:z,inheritData:K}),_(!1)},[o,t.id,P,$]),O=p.useCallback(z=>{if(!z.trim()){v([]);return}R(!0),o!=null&&o.searchEntities&&o.searchEntities(z,b).then(K=>{v(K),R(!1)}).catch(()=>{v([]),R(!1)})},[o,b]),Z=p.useCallback(z=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,m,z.id),w(!1)},[o,t.id,m]),se=p.useCallback(()=>{i()},[i]),ae=p.useCallback(z=>{A(()=>z),V(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(q).catch(()=>{})},[o]),J=p.useCallback((z,K)=>o!=null&&o.searchEntities?o.searchEntities(z,K==="all"?void 0:K):Promise.resolve([]),[o]),He=p.useCallback(z=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(z),q(K=>[z,...K.filter(de=>de.id!==z.id)].slice(0,10)),Y==null||Y(z),V(!1),A(null)},[o,Y]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:_o[te]}),e.jsx("span",{children:t.title||c.editor.untitled}),e.jsx(Ie,{children:t.id}),e.jsx(Ie,{color:To[te],children:c.indexType[te]})]})}),e.jsx(ie,{title:c.section.basicInfo,onSave:i,onAskAI:l?()=>l("基本信息"):void 0,extraButtons:d==null?void 0:d("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(ze,{label:ne?c.editor.workTitle:xe?c.editor.collectionTitle:c.editor.bookTitle,value:t.title,onChange:z=>N("title",z)}),le&&e.jsx(ze,{label:c.editor.belongsToWork,value:t.workName||"",onChange:z=>N("workName",z)}),e.jsx(X,{label:c.editor.authorLabel,value:t.author||"",onChange:z=>N("author",z)}),e.jsx(X,{label:c.editor.dynastyLabel,value:t.dynasty||"",onChange:z=>N("dynasty",z)}),(le||xe)&&e.jsx(ze,{label:c.editor.containedIn,value:t.collection||"",onChange:z=>N("collection",z)}),(le||xe)&&e.jsx(X,{label:c.editor.holderLabel,value:t.holder||"",onChange:z=>N("holder",z)}),(le||xe)&&e.jsx(X,{label:le?c.editor.pageLabel:c.editor.volumeLabel,value:t.pages||"",onChange:z=>N("pages",z)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(X,{label:c.editor.firstImageLabel,value:t.firstImage||"",onChange:z=>N("firstImage",z)})})]})}),e.jsx(ie,{title:c.section.description,onSave:i,onAskAI:l?()=>l("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:z=>N("description",z),placeholder:c.editor.descriptionPlaceholder})}),(((we=t.additional_works)==null?void 0:we.length)||0)>0&&e.jsx(ie,{title:c.section.additionalWorks,onSave:i,children:e.jsx(Lo,{items:t.additional_works||[],onChange:z=>N("additional_works",z)})}),e.jsx(ie,{title:c.section.indexedBy,onSave:i,onAskAI:l?()=>l("收录于"):void 0,children:e.jsx(Eo,{items:t.indexed_by||[],onChange:z=>N("indexed_by",z)})}),e.jsx(ie,{title:c.section.textResources,onSave:i,onAskAI:l?()=>l("资源"):void 0,children:e.jsx(Pe,{items:t.resources||[],onChange:z=>N("resources",z),onDownload:u,downloadStatuses:g,filterType:"text"})}),e.jsx(ie,{title:c.section.imageResources,onSave:i,children:e.jsx(Pe,{items:t.resources||[],onChange:z=>N("resources",z),onDownload:u,downloadStatuses:g,filterType:"image"})}),e.jsx(ie,{title:c.section.sources,onSave:i,onAskAI:l?()=>l("资料来源"):void 0,children:e.jsx(Lt,{items:Et(t.sources||""),onChange:z=>N("sources",Bt(z)),onOpenEntityPicker:ae})}),(le||xe)&&e.jsx(ie,{title:c.section.provenance,onSave:i,onAskAI:l?()=>l("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:z=>N("provenance",z),placeholder:c.editor.provenancePlaceholder})}),le&&e.jsx(ie,{title:c.section.otherEditions,onSave:i,onAskAI:l?()=>l("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:z=>N("otherEditions",z),placeholder:c.editor.otherEditionsPlaceholder})}),e.jsx(Wt,{entityType:te,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:he,onUnlinkEntity:ke,onViewEntity:_e,onCreateAndLink:B,onSaveRelations:se}),s&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:c.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:c.editor.dangerZoneDesc}),e.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:c.editor.deleteEntity})]}),e.jsx($t,{isOpen:j,entityType:b,title:y,onSelect:Z,onCancel:()=>w(!1),onCreate:()=>{w(!1),B(m,b)},searchResults:T,onSearch:O,isLoading:h,excludeId:t.id}),e.jsx(At,{isOpen:C,entityType:$,relationField:P,inheritData:U,onConfirm:G,onCancel:()=>_(!1)}),e.jsx(Ft,{isOpen:M,title:c.action.selectBookOrWork,filterType:"all",recentEntities:ee,excludeId:t.id,onSelect:He,onCancel:()=>{V(!1),A(null)},onSearch:J})]})};function Lo({items:t,onChange:n}){const i=W(),o=(a,l,d)=>{const u=t.map((g,x)=>x===a?{...g,[l]:d}:g);n(u)},r=a=>n(t.filter((l,d)=>d!==a)),s=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,l)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(X,{label:i.editor.bookNameLabel,value:a.book_title,onChange:d=>o(l,"book_title",d)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(X,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:d=>o(l,"n_juan",d&&parseInt(d,10)||void 0)})}),e.jsx("button",{onClick:()=>r(l),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},l)),e.jsx("button",{onClick:s,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Eo({items:t,onChange:n}){const i=W(),[o,r]=p.useState(null),s=(d,u,g)=>{const x=t.map((f,c)=>c===d?{...f,[u]:g||void 0}:f);n(x)},a=d=>{n(t.filter((u,g)=>g!==d)),o===d&&r(null)},l=()=>{n([...t,{source:""}]),r(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((d,u)=>{const g=o===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>r(g?null:u),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:d.source||i.editor.unnamedSource}),d.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:d.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(u)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&(d.title_info||d.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[d.title_info,d.title_info&&d.author_info&&" — ",d.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(X,{label:i.label.sourceName,value:d.source,onChange:x=>s(u,"source",x)}),e.jsx(X,{label:i.label.sourceBid,value:d.source_bid||"",onChange:x=>s(u,"source_bid",x)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(X,{label:i.label.titleInfo,value:d.title_info||"",onChange:x=>s(u,"title_info",x)}),e.jsx(X,{label:i.label.authorInfo,value:d.author_info||"",onChange:x=>s(u,"author_info",x)})]}),e.jsx(X,{label:i.label.edition,value:d.edition||"",onChange:x=>s(u,"edition",x)}),e.jsx(ue,{value:d.summary||"",onChange:x=>s(u,"summary",x),placeholder:i.editor.summaryPlaceholder}),e.jsx(ue,{value:d.comment||"",onChange:x=>s(u,"comment",x),placeholder:i.editor.commentPlaceholder}),e.jsx(ue,{value:d.additional_comment||"",onChange:x=>s(u,"additional_comment",x),placeholder:i.editor.additionalCommentPlaceholder})]})]},u)}),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:i.action.addIndexedBy})]})}const ct=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ht=({isOpen:t,onClose:n,onSubmit:i})=>{const[o,r]=p.useState(null),[s,a]=p.useState(""),[l,d]=p.useState("idle"),[u,g]=p.useState(""),x=p.useRef(null);p.useEffect(()=>{t&&(r(null),a(""),d("idle"),g(""))},[t]),p.useEffect(()=>{o&&setTimeout(()=>{var w;return(w=x.current)==null?void 0:w.focus()},100)},[o]),p.useEffect(()=>{if(l==="success"){const w=setTimeout(n,2e3);return()=>clearTimeout(w)}},[l,n]),p.useEffect(()=>{if(!t)return;const w=b=>{b.key==="Escape"&&n()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[t,n]);const f=async()=>{if(!(!o||!s.trim())){d("submitting"),g("");try{await i({type:o,content:s.trim()}),d("success")}catch(w){d("error"),g(w instanceof Error?w.message:"提交失败,请稍后重试")}}};if(!t)return null;const c=o&&s.trim()&&l!=="submitting",j=ct.find(w=>w.value===o);return e.jsx("div",{style:Bo,onClick:w=>{w.target===w.currentTarget&&n()},children:e.jsxs("div",{style:Wo,onClick:w=>w.stopPropagation(),children:[e.jsxs("div",{style:Po,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:$o,"aria-label":"关闭",children:"✕"})]}),l==="success"?e.jsxs("div",{style:Oo,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:ct.map(w=>e.jsxs("button",{onClick:()=>r(w.value),style:{...Ao,...o===w.value?Mo:{}},children:[e.jsx("span",{children:w.icon})," ",w.label]},w.value))}),e.jsx("textarea",{ref:x,value:s,onChange:w=>a(w.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!o||l==="submitting",style:{...Fo,opacity:o?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),l==="error"&&e.jsx("div",{style:Do,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:f,disabled:!c,style:{...Ho,opacity:c?1:.6,cursor:c?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交反馈"})})]})]})})},Bo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Wo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Po={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},$o={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Ao={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Mo={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Fo={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Ho={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Oo={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Do={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Vo=({onSubmit:t,position:n={bottom:24,right:24}})=>{const[i,o]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>o(!0),style:{...No,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(Ht,{isOpen:i,onClose:()=>o(!1),onSubmit:t})]})},No={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Uo={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Yo={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Go(t){try{const n=new Date(t),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const Jo=({items:t,loading:n})=>n?e.jsx("div",{style:pt,children:"加载中..."}):t.length===0?e.jsx("div",{style:pt,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(i=>{const o=Uo[i.type],r=Yo[i.status];return e.jsxs("div",{style:Ko,children:[e.jsxs("div",{style:Zo,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...xt,background:o.color},children:o.label}),e.jsx("span",{style:{...xt,background:r.color},children:r.label})]}),e.jsx("span",{style:Xo,children:Go(i.createdAt)})]}),e.jsx("div",{style:qo,children:i.content}),i.reply&&e.jsxs("div",{style:Qo,children:[e.jsx("div",{style:ei,children:"回复"}),e.jsx("div",{children:i.reply})]})]},i.id)})}),pt={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Ko={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Zo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Xo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},qo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Qo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},ei={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},ti=({style:t})=>{const n=p.useContext(je);if(!n)return null;const{locale:i,setLocale:o}=n,r=i==="zh-Hant",s=()=>o(r?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:s,title:r?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:r?"var(--bim-primary, #0078d4)":void 0,fontWeight:r?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:r?void 0:"var(--bim-primary, #0078d4)",fontWeight:r?400:700},children:"简"})]})};exports.BidLink=H.BidLink;exports.BookIndexError=H.BookIndexError;exports.BookIndexManager=H.BookIndexManager;exports.BookIndexStorage=H.BookIndexStorage;exports.BundleStorage=H.BundleStorage;exports.ConfigError=H.ConfigError;exports.GithubStorage=H.GithubStorage;exports.IdGenerationError=H.IdGenerationError;exports.IdGenerator=H.IdGenerator;exports.LocalStorage=H.LocalStorage;exports.MigrationError=H.MigrationError;exports.StorageError=H.StorageError;exports.base58Decode=H.base58Decode;exports.base58Encode=H.base58Encode;exports.buildId=H.buildId;exports.decodeIdString=H.decodeIdString;exports.extractIdFromUrl=H.extractIdFromUrl;exports.extractStatus=H.extractStatus;exports.extractType=H.extractType;exports.normalizeCatalog=H.normalizeCatalog;exports.parseId=H.parseId;exports.validateResource=H.validateResource;exports.Badge=Ie;exports.CollatedEdition=_t;exports.CollectionCatalog=St;exports.CreateEntityDialog=At;exports.EntityPickerDialog=Ft;exports.EntitySelector=$t;exports.FeedbackButton=Vo;exports.FeedbackDialog=Ht;exports.FeedbackList=Jo;exports.FormInput=X;exports.FormTextArea=ue;exports.HomePage=Rt;exports.IndexApp=Xn;exports.IndexBrowser=bt;exports.IndexDetail=jt;exports.IndexEditor=Ro;exports.LocaleContext=je;exports.LocaleProvider=Xt;exports.LocaleToggle=ti;exports.ModeIndicator=ft;exports.RelationPanel=Wt;exports.ResourceEditor=Pe;exports.ResourceList=Fe;exports.SearchInput=ht;exports.Section=ie;exports.SmartBidInput=ze;exports.SourceEditor=Lt;exports.WorkCatalog=qn;exports.formatTemplate=Se;exports.parseSourceString=Et;exports.stringifySources=Bt;exports.useConvert=F;exports.useT=W;
|