book-index-ui 0.19.0 → 0.19.1
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 +1 -1
- package/dist/index.js +1103 -1097
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -728,7 +728,7 @@ ${uc}`;function Ot({children:e,style:n,wide:i,grid:r}){return t.jsxs("div",{clas
|
|
|
728
728
|
`)){const r=Ii(i);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=i.trim();!s||Ti.test(s)||n.push({kind:"body",text:i})}return n}function $s(e){if(!e)return[];const n=Sn(e);if(n==="unknown")return zo(e);const i=[];for(const{heading:r,body:s}of cd(e)){r&&i.push(r);const l=Ss(s);if(l.length!==0){if(_s(s)){i.push(...zo(s));continue}if(n==="record"){const d=l.join(" ");d&&i.push({kind:"body",text:d})}else for(const d of l){const p=ws(d);p.length&&i.push({kind:"body",text:p.join(" ")})}}}return i}const zs=e=>e;function Cs(e,n=zs){if(e.indexOf("《")<0)return n(e);const i=[],r=/《([^《》\n]+)》/g;let s=0,l=0,d;for(;d=r.exec(e);)d.index>s&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s,d.index))},l++)),i.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(d[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},l++)),s=d.index+d[0].length;return s===0?n(e):(s<e.length&&i.push(t.jsx(f.Fragment,{children:n(e.slice(s))},l++)),i)}function Ei(e,n={}){const i=n.renderText??zs,r=n.properNames?l=>Cs(l,i):i,s=n.gujiMarkdown?{gujiMarkdown:!0}:void 0;return Ge(e,r,s)}function Co(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,l)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${l}`):t.jsx(f.Fragment,{children:n(s)},`${i}-${l}`))}const Nn=/^(#{1,6})\s+(.*)$/,dd=/^\s*<!--.*-->\s*$/;function Is(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
|
|
729
729
|
`)?"":n)}function pd(e){return e<=1?2:e===2?3:4}function ud(){let e=1;return n=>{const i=pd(n),r=Math.min(i,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${i}`}}}function wn(e){return e?Sn(Is(e))!=="unknown":!1}function Io({text:e,mode:n,inline:i,dropTitle:r}){const s=Is(e),l=(c,u,g)=>!!r&&g<=1&&c<=2&&u.trim()===r.trim(),d=ud();if(n==="paragraph"&&Sn(s)!=="unknown"){const c=$s(s);return t.jsx(t.Fragment,{children:c.map((u,g)=>{if(u.kind==="heading"){if(l(u.level??1,u.text,g))return null;const{Tag:x,className:m}=d(u.level??1);return t.jsx(x,{className:m,children:i(u.text)},g)}return t.jsx("p",{children:Co(u.text,i,g)},g)})})}const p=s.split(`
|
|
730
730
|
`);let a=0;return t.jsx(t.Fragment,{children:p.map((c,u)=>{const g=c.match(Nn);if(g){const m=a++;if(l(g[1].length,g[2],m))return null;const{Tag:b,className:S}=d(g[1].length);return t.jsx(b,{className:S,children:i(g[2])},u)}if(!c.trim())return u>=2&&!!p[u-1].trim()&&!!p[u-2].trim()&&!Nn.test(p[u-1])&&!Nn.test(p[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(dd.test(c))return null;if(a++,/^\*\*[^*]+\*\*\s*$/.test(c.trim())){const{Tag:m,className:b}=d(3);return t.jsx(m,{className:b,children:i(c.trim().slice(2,-2))},u)}return t.jsx("p",{children:Co(c,i,u)},u)})})}function xd(e){const{convert:n}=Y();return f.useMemo(()=>e?n(e):"",[e,n])}function Ri({text:e,mode:n,tables:i=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:l,dropTitle:d}){const p=xd(e),{convert:a}=Y(),c=x=>Ei(x,{renderText:l,properNames:s,gujiMarkdown:r}),u=r?{gujiMarkdown:!0}:void 0,g=d?a(d):void 0;return!i||p.indexOf(":::")<0?t.jsx(Io,{text:p,mode:n,inline:c,dropTitle:g}):t.jsx(t.Fragment,{children:zi(p).map((x,m)=>x.type==="table"?t.jsx(Ci,{table:x.table,opts:u},m):t.jsx(Io,{text:x.text,mode:n,inline:c,dropTitle:m===0?g:void 0},m))})}function Ts(e,n){const[i,r]=f.useState(null),[s,l]=f.useState(!1),d=f.useRef(0);return f.useEffect(()=>{const p=++d.current;if(!e||!n){r(null),l(!1);return}let a;try{a=e(n)}catch{r(null),l(!1);return}if(!a||typeof a.then!="function"){r(a??null),l(!1);return}l(!0),a.then(c=>{p===d.current&&r(c??null)}).catch(()=>{p===d.current&&r(null)}).finally(()=>{p===d.current&&l(!1)})},[e,n]),{images:i,loading:s}}const To={A:"fine",B:"rough",C:"rough",D:"ocr"};function fd(e){return typeof e!="string"?null:e in Dn?e:e in To?To[e]:null}const gd={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},md={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function et(e){return typeof e!="string"?"":gd[e]??md[e]??e}const hd=["〇","一","二","三","四","五","六","七","八","九"],Eo=["","十","百","千"],bd=["","萬","億"];function Ni(e){if(e===0)return"〇";if(e<0)return`負${Ni(-e)}`;const n=[];let i=e,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(yd(s,r>0)+bd[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function yd(e,n){const i=[];let r=e;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let l=0;l<i.length;l++){const d=i[l],p=i.length-1-l;d===0?s&&!s.endsWith("〇")&&(s+="〇"):d===1&&p===1&&l===0&&!n?s+=Eo[p]:s+=hd[d]+Eo[p]}return s.replace(/〇$/,"")}let Gt=null,ln=null;const fn=new Set;function jd(){return Gt?Promise.resolve():ln||(ln=import("opencc-js/t2cn").then(e=>{Gt=e.Converter({from:"tw",to:"cn"}),fn.forEach(n=>n())}).catch(()=>{Gt=e=>e,fn.forEach(e=>e())}),ln)}const vd=e=>e;function jt(){const[,e]=f.useState(0);return f.useEffect(()=>{if(Gt)return;const n=()=>e(i=>i+1);return fn.add(n),jd(),()=>{fn.delete(n)}},[]),Gt??vd}function It(e,n){return n(e).toLowerCase()}const kd=o("highlight-bg");function Xt(e,n,i){if(!n)return e;const r=It(n,i);if(!r)return e;const s=It(e,i);if(s.length!==e.length)return e;const l=[];let d=0,p=0;for(;d<e.length;){const a=s.indexOf(r,d);if(a===-1){l.push(e.slice(d));break}a>d&&l.push(e.slice(d,a)),l.push(t.jsx("mark",{style:{background:kd,padding:0,color:"inherit"},children:e.slice(a,a+r.length)},p++)),d=a+r.length}return t.jsx(t.Fragment,{children:l})}function Li(e,n,i,r){if(!n)return!0;const s=It(n,r);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(d=>typeof d=="string"&&It(d,r).includes(s))}function Sd(e,n,i){return n?It(e,i).includes(It(n,i)):!0}const Bi={类:o("section-lei"),书:o("section-shu"),序:o("section-xu"),结语:o("section-jieyu"),注释:o("section-zhushi")},wd={考证:o("section-kaozhen")};function _d(e){const n=e.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Es(e){var r;const n=e.files.length,i=((r=e.children)==null?void 0:r.reduce((s,l)=>s+Es(l),0))||0;return n+i}function $d(e,n){const i=[],r=d=>{var p;i.push(...d.files),(p=d.children)==null||p.forEach(r)};if(r(e),i.length===0)return;const s=i.map(d=>n[d]);if(s.every(d=>d===void 0))return;if(s.some(d=>d==="loading"))return"loading";let l=0;for(const d of s)typeof d=="number"&&(l+=d);return l}const zd={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Ai({enabled:e,expanded:n,onClick:i,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...zd,...r},children:s}):t.jsx("span",{style:r,children:s})}function Cd({type:e}){const n=et(e),i=Bi[n]||o("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Id({section:e,onNavigate:n,highlightQuery:i=""}){const{convert:r}=Y(),s=Pe(),l=jt(),d=S=>S?Ge(r(S),h=>i?Xt(h,i,l):h):"",[p,a]=f.useState(!1),c=!!e.summary,u=!!e.comment,g=!!e.additional_comment,x=!!(e.content&&e.content.length>60),m=c||u||g||x;f.useEffect(()=>{i&&a(!0)},[i]);const b=!p&&x?ns(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[t.jsxs("div",{onClick:()=>m&&a(!p),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:m?"pointer":"default",userSelect:"none",background:o("input-bg")},children:[t.jsxs(Ai,{enabled:m,expanded:p,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",d(e.book_title),"》"]}):d(e.title),e.n_juan!=null&&t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"6px"},children:[Ni(e.n_juan),"卷"]}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg"),marginLeft:"8px"},children:d(e.author_info||e.author)})]}),!p&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:o("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:d(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:d(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:o("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:s(e.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),p&&m&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${o("widget-border")}`,background:o("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:o("desc-fg"),marginBottom:"8px"},children:d(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${o("primary")}`,background:`color-mix(in srgb, ${o("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:d(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${o("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:o("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:d(e.additional_comment)})]}),x&&!c&&!u&&!g&&t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:d(e.content)})]})]})}function Td({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=jt(),s=a=>a?Ge(i(a),c=>n?Xt(c,n,r):c):"",[l,d]=f.useState(!1),p=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Ai,{enabled:p,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[t.jsx(Cd,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:o("fg")},children:s(e.title)}),p&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&p&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Bi[et(e.type)]||o("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:o("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(e.content)})})]})}const Ed=100;function Wi(e){return et(e.type)!=="page_header"?!1:(e.content||"").length>=Ed}function Rd({section:e,highlightQuery:n=""}){const{convert:i}=Y(),r=jt();if(et(e.type)==="page_header"&&!Wi(e)||!e.content&&!e.title)return null;const s=i((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
731
|
-
`)),l=Ge(s,c=>n?Xt(c,n,r):c),d=et(e.type),p=Bi[d]||o("desc-fg"),a=d==="序"||d==="结语"||d==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:d}),l]})}function Nd(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var c;if(!n||e.length===0)return;let l=!1;const d=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(c=i==null?void 0:i.current)!=null&&c.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),d.length===0)return;const a=async u=>{var g;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,S=(g=b==null?void 0:b[0])==null?void 0:g.name;return{title:m,author:S}}catch{return null}};return Promise.all(d.map(async u=>{var x;const g=await a(u);return(x=i==null?void 0:i.current)==null||x.set(u,g),[u,g]})).then(u=>{l||s(g=>{const x={...g};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Ld({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Y(),d=Pe(),p=jt(),a=y=>y?Ge(l(y),j=>s?Xt(j,s,p):j):"",[c,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=et(e.type),x=wd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],S=b.length>1,h=Nd(S?b:[],i,r),v=m&&!c&&e.content.length>80?ns(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!c),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Ai,{enabled:m,expanded:c,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!c&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:d(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:g})]})]}),S&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const j=h[y],_=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:d(y),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),c&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function Bd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=jt(),d=n.trim(),p=f.useMemo(()=>d?e.sections.filter(a=>Li(a,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,c)=>t.jsx(Ld,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:d},c))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Ad(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Wd({sections:e,onNavigate:n,inline:i}){const r=Pe(),{convert:s}=Y(),l=Ad();return t.jsx(t.Fragment,{children:e.map((d,p)=>{const a=et(d.type);if(a==="page_header"&&!Wi(d))return null;if(a==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(d.title))),d.content&&t.jsx("p",{children:i(s(d.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const c=d.book_title?`《${d.book_title}》${d.n_juan!=null?Ni(d.n_juan)+"卷":""}`:d.title,u=i(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},d.work_id&&n?t.jsx("a",{href:r(d.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(d.work_id))},title:"查看作品",children:u}):u),d.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(d.author_info))}),d.content&&d.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),d.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(d.summary))]}),d.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(d.comment))]}),d.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(d.additional_comment))]})]},p)}return d.content?t.jsx("p",{children:i(s(d.content))},p):null})})}function Md(e){return e.some(n=>{const i=et(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Wi(n)})}function Fd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p,prefs:a}){var M;const{convert:c}=Y(),u=jt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",S=f.useCallback(W=>m?Xt(W,m,u):W,[m,u]),h=W=>Ei(W,{renderText:S,properNames:a.properNames}),v=f.useMemo(()=>m?e.sections.filter(W=>Li(W,m,b,u)):e.sections,[e.sections,m,b,u]),y=(W,P)=>P.filter(V=>et(V.type)===W).length,j=y("书",e.sections),_=y("诗",e.sections),k=y("考证",e.sections);let z="";b?z=m?`${y("考证",v)} / ${k} ${c("條")}`:`${k} ${c("條")}`:_>0?z=m?`${y("诗",v)} / ${_} 首`:`${_} 首`:j>0&&(z=m?`${y("书",v)} / ${j} ${c("部書")}`:`${j} ${c("部書")}`);const w=r!=null&&r.text_quality?fd(r.text_quality.grade):null,C=[];i&&C.push(i),z&&C.push(z),b&&(r!=null&&r.target_source)&&C.push(t.jsxs(t.Fragment,{children:[c("考證對象")," ",c(r.target_source)]})),w&&C.push(t.jsx("span",{title:Rl[w],children:(M=r==null?void 0:r.text_quality)!=null&&M.source_note?t.jsxs(t.Fragment,{children:["底本 ",c(r.text_quality.source_note),"(",c(Dn[w]),")"]}):t.jsxs(t.Fragment,{children:[c("文本質量")," ",c(Dn[w])]})})),e.source_url&&C.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:c("原文來源")}));const E=!b&&Md(e.sections),R=!!n&&(!E||a.readingMode==="paragraph"&&wn(n)),T=!b&&(E||!!n),O=b||!T?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:c(e.title)}),C.length>0&&t.jsx("p",{className:"bim-rd-meta",children:C.map((W,P)=>t.jsxs(f.Fragment,{children:[P>0&&t.jsx("span",{className:"bim-rd-dot"}),W]},P))}),T&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="entries",onClick:()=>x("entries"),children:c("條目")})]})]}),O==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx(Ri,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:S,dropTitle:e.title}):t.jsx(Wd,{sections:e.sections,onNavigate:l,inline:h})}),O==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Bd,{juan:e,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p}):t.jsxs(t.Fragment,{children:[v.map((W,P)=>{const V=et(W.type);return V==="书"||V==="诗"||V==="考证"?t.jsx(Id,{section:W,onNavigate:l,highlightQuery:m},P):V==="类"?t.jsx(Td,{section:W,highlightQuery:m},P):t.jsx(Rd,{section:W,highlightQuery:m},P)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Rs(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Pd(e){const n=Rs(e);return n.length>0?n[0]:null}function Od(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:d,query:p,isKaozhen:a}=e,c=jt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),S=f.useCallback((v,y)=>{const j=y==null?void 0:y.title;j&&b(_=>_[v]===j?_:{..._,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:d}),S(s,l))},[s,l,d,S]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((v,y)=>{let j=0;if(v.juan)for(const _ of v.juan.sections)Li(_,y,a,c)&&j++;return j===0&&v.rawText&&Sd(v.rawText,y,c)&&(j=1),j},[a,c]);return f.useEffect(()=>{const v=p.trim();if(!v){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const j={},_=[];for(const E of r){const R=u.current.get(E);R?j[E]=h(R,v):(j[E]="loading",_.push(E))}x(j);const k=8;let z=0;const w=async()=>{var E;for(;z<_.length;){if(y)return;const R=z++,T=_[R];try{const[O,M]=await Promise.all([i.getCollatedJuan(n,T),((E=i.getCollatedJuanText)==null?void 0:E.call(i,n,T))??Promise.resolve(null)]),W={juan:O,rawText:M};if(u.current.set(T,W),S(T,O),y)return;x(P=>({...P,[T]:h(W,v)}))}catch{if(y)return;x(O=>({...O,[T]:0}))}}},C=Array.from({length:Math.min(k,_.length)},()=>w());return Promise.all(C),()=>{y=!0}},[p,n,i,r.join(","),h,c,S]),{matchStates:g,titles:m}}const Mi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:d,style:p,title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,S]=f.useState(null),[h,v]=f.useState(!1),[y,j]=f.useState(null),[_,k]=f.useState(null),[z,w]=f.useState(null),[C,E]=f.useState(!1),[R,T]=f.useState(null),[O,M]=f.useState(""),W=f.useRef(new Map),P=f.useRef(0),V=s??_,K=f.useCallback(H=>{k(H),l==null||l(H)},[l]),N=e||b;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let H=!1;return v(!0),j(null),i.getCollatedEditionIndex(n).then(te=>{H||(te?S(te):j("未找到整理本数据"))}).catch(te=>{H||j(te instanceof Error?te.message:"加载失败")}).finally(()=>{H||v(!1)}),()=>{H=!0}},[e,n,i]),f.useEffect(()=>{if(N&&!V){const H=Pd(N);H&&K(H)}},[N,V,K]);const le=n||(N==null?void 0:N.work_id),G=f.useCallback(async H=>{var pe;if(!le||!(i!=null&&i.getCollatedJuan))return;const te=++P.current;E(!0),w(null),T(null);try{const[re,ee]=await Promise.all([i.getCollatedJuan(le,H),((pe=i.getCollatedJuanText)==null?void 0:pe.call(i,le,H))??Promise.resolve(null)]);if(te!==P.current)return;w(re),T(ee)}catch{if(te!==P.current)return;w(null),T(null)}finally{te===P.current&&E(!1)}},[le,i]);f.useEffect(()=>{V&&G(V)},[V,G]);const se=H=>{K(H)};if(h)return t.jsx("div",{className:d,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:d,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!N)return null;const ne=N.type==="kaozhen",Q=Rs(N);return t.jsx(Hd,{className:d,style:p,index:N,allFiles:Q,isKaozhen:ne,effectiveWorkId:le,transport:i,activeFile:V,handleSelectFile:se,juanData:z,juanRawText:R,juanLoading:C,searchQuery:O,setSearchQuery:M,onNavigate:r,workLabelCacheRef:W,reader:{title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function Ns(e,n,i,r){var c,u,g,x;const s=(u=(c=n.juan_metadata)==null?void 0:c[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:_d(e)),p=((x=(g=n.files)==null?void 0:g.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Dd(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,d=(a,c)=>({key:a,label:c??Ns(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,c)=>{var g;if(a.files.length===1&&!((g=a.children)!=null&&g.length))return d(a.files[0],s(a.label));const u=$d(a,i);return{key:`group:${c}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Es(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>d(x)),...(a.children??[]).map((x,m)=>p(x,`${c}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,c)=>p(a,`${c}`)):n.map(a=>d(a))}const Hd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:d,activeFile:p,handleSelectFile:a,juanData:c,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:S,reader:h})=>{const{convert:v}=Y(),[y,j]=_i(),{matchStates:_,titles:k}=Od({workId:l,transport:d,files:r,activeFile:p,activeJuan:c,activeRawText:u,query:x,isKaozhen:s}),z=Ts(h.resolveImages,p),w=f.useMemo(()=>Dd(i,r,_,k,v),[i,r,_,k,v]),C=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:T=>m(T.target.value)}),E=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(T=>T.vol_label)?"冊":"卷",R=p?Ns(p,i,k,v).position:void 0;return t.jsxs($i,{className:e,style:n,title:h.title??(i.title?v(i.title):void 0),subtitle:h.subtitle??v(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${v(E)}`,tocHeader:C,activeKey:p,onSelect:a,images:z.images,imagesLoading:z.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:j,paragraphToggle:!s&&wn(u),allowVertical:h.allowVertical,children:[g?t.jsx(yt,{}):c?t.jsx(Fd,{juan:c,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:b,transport:d,workLabelCache:S,prefs:y},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:v("參考文獻")}),t.jsx("ol",{children:i.references.map((T,O)=>t.jsxs("li",{children:[T.url?t.jsx("a",{className:"bim-rd-link",href:T.url,target:"_blank",rel:"noopener noreferrer",children:T.title}):t.jsx("span",{children:T.title}),T.author&&t.jsxs("span",{children:[",",T.author]}),T.note&&t.jsxs("span",{children:["。",T.note]})]},O))})]})]})},Gd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Ud={label:"其他",color:o("desc-fg")},Vd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},Yd={label:"待处理",color:o("warning")};function Kd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function qd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Fi=({items:e,loading:n})=>{const i=Pe();return n?t.jsx(yt,{}):e.length===0?t.jsx("div",{style:Jd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Gd[r.type]||Ud,l=Vd[r.status]||Yd,d=typeof window<"u"&&qd(r.pageUrl,window.location.href);return t.jsxs("div",{style:Zd,children:[t.jsxs("div",{style:Xd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ro,background:s.color},children:s.label}),t.jsx("span",{style:{...Ro,background:l.color},children:l.label})]}),t.jsx("span",{style:Qd,children:Kd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ep,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:Ln,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(d?t.jsx("a",{href:r.pageUrl,style:Ln,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Ln,children:r.pageUrl}))]}),t.jsx("div",{style:tp,children:r.content}),r.reply&&t.jsxs("div",{style:np,children:[t.jsx("div",{style:ip,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Jd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},Zd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},Xd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ro={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Qd={fontSize:"12px",color:o("desc-fg")},ep={fontSize:"12px",marginBottom:"6px"},Ln={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},tp={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},np={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},ip={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ei=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const d=de(),[p,a]=f.useState(null),[c,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[S,h]=f.useState(!1),v=r??g,y=P=>{x(P),s==null||s(P)},[j,_]=f.useState(!0),[k,z]=f.useState(null),[w,C]=f.useState(null),[E,R]=f.useState(null);f.useEffect(()=>{let P=!1;if(e.getCounts)return e.getCounts().then(V=>{P||a({works:V.works,books:V.books,collections:V.collections})}).catch(()=>{}),()=>{P=!0}},[e]),f.useEffect(()=>{let P=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const K=await e.getRecommended();if(K!=null&&K.groups)return K.groups.flatMap(N=>N.items.map(le=>({...le,group:N.name})))}catch{}return[]})().then(async K=>{if(P)return;const N=K.filter(G=>G.id);if(N.length===0){_(!1);return}const le=await Promise.all(N.map(async G=>{if(G.type)return{id:G.id,title:G.title,type:G.type,author:G.author,dynasty:G.dynasty,role:G.role,edition:G.edition,has_text:G.has_text,has_image:G.has_image,has_collated:G.has_collated,subtype:G.subtype,primary_name:G.primary_name,group:G.group,fallbackDescription:G.description};try{let se=null;if(e.getEntry)se=await e.getEntry(G.id);else{const ne=await e.getItem(G.id);ne&&(se={id:G.id,title:ne.title||G.id,type:ne.type||"work"})}if(se)return{...se,group:G.group,fallbackDescription:G.description}}catch{}return{id:G.id,title:G.title,type:be.extractType(G.id),group:G.group,fallbackDescription:G.description}}));P||(u(le.filter(G=>G!==null)),_(!1))}),()=>{P=!0}},[e,i]);const T=f.useRef(!1),O=f.useRef(!1),M=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||T.current)return;const P=e.getCatalogProgress??e.getResourceProgress;if(!P)return;T.current=!0;let V=!1;return P.call(e).then(K=>{V||z(K)}).catch(()=>{T.current=!1}),()=>{V=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||O.current||!e.getCollectionProgress)return;O.current=!0;let P=!1;return e.getCollectionProgress().then(V=>{P||C(V)}).catch(()=>{O.current=!1}),()=>{P=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||M.current||!e.getSiteProgress)return;M.current=!0;let P=!1;return e.getSiteProgress().then(V=>{P||R(V)}).catch(()=>{M.current=!1}),()=>{P=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let P=!1;return h(!0),fetch(l).then(V=>V.json()).then(V=>{!P&&V.success&&b(V.items||[])}).catch(()=>{}).finally(()=>{P||h(!1)}),()=>{P=!0}},[l,v]);const W=P=>{switch(P){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Mt,{label:d.home.recommendTab,active:v==="recommend",onClick:()=>y("recommend")}),t.jsx(Mt,{label:d.home.catalogTab,active:v==="catalog",onClick:()=>y("catalog")}),t.jsx(Mt,{label:d.home.collectionTab,active:v==="collection",onClick:()=>y("collection")}),t.jsx(Mt,{label:d.home.siteTab,active:v==="site",onClick:()=>y("site")}),l&&t.jsx(Mt,{label:d.home.feedbackTab,active:v==="feedback",onClick:()=>y("feedback")})]}),v==="recommend"&&t.jsx(op,{recommended:c,loading:j,onNavigate:n,getIcon:W,t:d}),v==="catalog"&&t.jsx(No,{progress:k,t:d,onNavigate:n}),v==="collection"&&t.jsx(No,{progress:w,t:d,onNavigate:n}),v==="site"&&t.jsx(sp,{progress:E,t:d,totalWorks:(p==null?void 0:p.works)??0}),v==="feedback"&&l&&t.jsx(Fi,{items:m,loading:S})]})})},Mt=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),op=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(yt,{});if(e.length===0)return null;const d=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;d.has(a)||d.set(a,[]),d.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(d.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(c=>{const u=c.dynasty||c.author?`${c.dynasty?`〔${c.dynasty}〕`:""}${c.author||""}`:c.fallbackDescription;return t.jsxs("a",{href:l(c.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(c.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(c.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c.title,c.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:c.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},c.id)})})]},p))})},No=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},d={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(c=>c.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:d[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(rp,{item:c,t:n,statusColor:d[p],onNavigate:i},c.id))})]},p)})})},rp=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,d=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:c=>c.currentTarget.style.borderBottomStyle="solid",onMouseLeave:c=>c.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:d})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Yt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},sp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((a,c)=>a.priority-c.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),d=s.reduce((a,c)=>Math.max(a,c.imported),0),p=i>0?Math.round(d/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:d.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(Lo,{item:a,t:n,totalWorks:i},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(Lo,{item:a,t:n,totalWorks:i},a.id))})]})]})},Lo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},Bo="(max-width: 768px)";function lp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Bo).matches);return f.useEffect(()=>{const i=window.matchMedia(Bo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const ap=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var V;const l=de(),{convert:d}=Y(),p=lp(),[a,c]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,S]=f.useState("detail"),[h,v]=f.useState([]),[y,j]=f.useState(!1),[_,k]=f.useState(null),[z,w]=f.useState(!1),C=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){k(null);return}w(!0);try{const N=await e.getCollatedEditionIndex(K);k(N)}catch{k(null)}finally{w(!1)}},[e]),E=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const N=await e.getCollectionCatalogs(K);v(N||[])}else if(e.getCollectionCatalog){const N=await e.getCollectionCatalog(K);v(N?[{resource_id:"",data:N}]:[])}}catch{v([])}finally{j(!1)}},[e]),R=f.useCallback(async K=>{if(i){i(K);return}c(K),g(null),v([]),k(null),S("detail"),m(!0);try{const N=await e.getItem(K.id);N&&(g(N),N.type==="collection"?E(K.id):N.type==="work"&&N.has_collated&&C(K.id))}catch(N){console.error("加载详情失败:",N)}finally{m(!1)}},[e,i,E,C]),T=f.useCallback(async K=>{g(null),v([]),k(null),S("detail"),m(!0);try{const N=await e.getItem(K);N&&(g(N),c({id:K,title:N.title||K,type:N.type||"book"}),N.type==="collection"?E(K):N.type==="work"&&N.has_collated&&C(K))}catch(N){console.error("导航失败:",N)}finally{m(!1)}},[e,E,C]),O=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(_||z),M=p&&(x||u),W=f.useCallback(()=>{c(null),g(null),v([]),k(null),S("detail")},[]),P=t.jsx(t.Fragment,{children:x?t.jsx(yt,{}):u?t.jsxs(t.Fragment,{children:[(O||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>S("detail"),style:an(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:an(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(K=>t.jsx("button",{onClick:()=>S(`catalog:${K.resource_id}`),style:an(b===`catalog:${K.resource_id}`),children:K.short_name?`${d(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&(_||z)&&t.jsxs("button",{onClick:()=>S("collated"),style:an(b==="collated"),children:[l.detailTab.collatedEdition,z&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(xi,{data:u,transport:e,onNavigate:T}):b.startsWith("catalog:")?t.jsx(fi,{data:(V=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:V.data,onNavigate:T}):b==="collated"?t.jsx(Mi,{index:_||void 0,workId:u.id,transport:e,onNavigate:T}):null})]}):t.jsx(ei,{transport:e,onNavigate:T,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:W,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:P})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Gn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(ei,{transport:e,onNavigate:T,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Gn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:P})]})};function an(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function dt(e){return e.replace(/\.md$/,"")}function Ao(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const Wo={padding:24,color:o("desc-fg")},ti=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:d,onVersionChange:p,title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:S})=>{const[h,v]=f.useState(e??null),[y,j]=f.useState(!1),[_,k]=f.useState(null),z=r!==void 0?r:_,w=f.useCallback(Q=>{s?s(Q):k(Q)},[s]),[C,E]=f.useState(null),[R,T]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const Q=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Q){j(!0);return}let H=!1;return Promise.resolve().then(Q).then(te=>{H||(te?v(te):j(!0))}).catch(()=>{H||j(!0)}),()=>{H=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const Q=dt(h.chapters[0].file);if(!z){w(Q);return}const H=dt(z);h.chapters.some(pe=>dt(pe.file)===H)||w(Q)},[h,z,w]);const O=f.useMemo(()=>{if(!h||!z)return null;const Q=dt(z);return h.chapters.find(H=>dt(H.file)===Q)??null},[h,z]);f.useEffect(()=>{if(!n||!O)return;const Q=l!==void 0?i.getWorkFullTextChapter?te=>i.getWorkFullTextChapter(n,l,te):null:i.getBookFullTextChapter?te=>i.getBookFullTextChapter(n,te):null;if(!Q)return;let H=!1;return T(!0),E(null),Promise.resolve(O.file).then(Q).then(te=>{H||E(te)}).catch(()=>{H||E(null)}).finally(()=>{H||T(!1)}),()=>{H=!0}},[n,O,i,l]);const M=Ts(u,O?dt(O.file):null),[W,P]=_i(),{convert:V}=Y(),K=!!(d&&d.length>1&&p),N=f.useMemo(()=>K?gs(d).map((Q,H)=>({...Q,label:Ao(d[H])})):void 0,[K,d]),le=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Q=>p(Q.target.value),children:d.map(Q=>t.jsx("option",{value:Q.key,children:Ao(Q)},Q.key))})]}):null;if(!h)return t.jsxs("div",{style:Wo,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Wo,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),"全文目录为空"]});const G=h.chapters.map(Q=>({key:dt(Q.file),label:V(Q.title)})),se=ys(h)||Yn(h),ne=C?C.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs($i,{title:a??V(h.version_label),subtitle:c??"全文",toc:G,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:z?dt(z):null,onSelect:w,images:M.images,imagesLoading:M.loading,renderImageOverlay:g,imagePanel:x,prefs:W,onPrefsChange:P,versions:N,currentVersionKey:N?l??null:void 0,onVersionChange:N?p:void 0,versionSource:!1,paragraphToggle:wn(ne),allowVertical:m,className:b,style:S,children:[O&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:V(O.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:V(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&ne!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ri,{text:ne,mode:W.readingMode,tables:se,gujiMarkdown:Yn(h),properNames:W.properNames})}),!R&&!C&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},cp=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=de(),{convert:l}=Y(),[d,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,c]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(g=>t.jsx(dp,{division:g,expanded:d===g.name,onToggle:()=>p(d===g.name?null:g.name),expandedCat:a,onCatToggle:x=>c(a===x?null:x),onNavigate:n},g.name))})]})},dp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:d}=Y(),p=e.categories.reduce((a,c)=>{const u=c.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.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, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const c=`${e.name}/${a.name}`;return t.jsx(pp,{category:a,expanded:r===c,onToggle:()=>s(c),onNavigate:l},a.name)})})]})},pp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,c,u,g;const{convert:s}=Y(),l=((a=e.books)==null?void 0:a.zhulu)||[],d=((c=e.books)==null?void 0:c.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Mo,{label:"著錄",books:l,onNavigate:r}),d.length>0&&t.jsx(Mo,{label:"存目",books:d,onNavigate:r})]})]})},Mo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=Y(),s=Pe(),[l,d]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,c)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},c))}),!l&&t.jsxs("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Ye=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=de();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:xp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:up,children:l.action.save})]})]}),s]})},up={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},xp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},He=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),ht=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},gn=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function fp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const dn=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),d=fp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&d?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Fo,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:d.name}),t.jsx(gn,{children:d.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Fo,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Fo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function gp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function mp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ls=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=de(),[s,l]=f.useState(null),d=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=g=>{n(e.filter((x,m)=>m!==g)),s===g&&l(null)},a=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},c=(g,x)=>{const m=[...e];m[g]={...m[g],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const S=[...e];S[g]={...S[g],id:b.id,name:b.title,type:"bookID"},n(S)})},u=g=>{i&&i(x=>{const m=[...e];m[g]={...m[g],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:g.name||`${r.editor.sourcePlaceholder} ${x+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:gp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:mp(g.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>c(x,"bookID"),style:{...Po,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>c(x,"url"),style:{...Po,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),g.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:nt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Oo,children:r.action.changeType})]}),g.id&&g.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:g.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),g.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:nt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Oo,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:vt})]})]}),g.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...nt,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:vt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:vt})]})]})]})]})})]},x)),t.jsxs("button",{onClick:d,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},nt={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},vt={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Po={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Oo={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Bs(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);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 As(e){return!e||e.length===0?"":JSON.stringify(e)}const Ws=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:d,childWorks:p,childCollections:a,containedBooks:c,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:S})=>{const h=de();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),S&&t.jsx("button",{onClick:S,style:hp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Ft,{direction:"up",title:h.relation.containedInCollection,entity:d,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(kt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(kt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),a&&a.length>0&&t.jsx(kt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(kt,{direction:"down",title:`${h.relation.allVersions} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Ft,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(kt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(kt,{direction:"down",title:`${h.relation.containedBooks} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Ft=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:d,linkLabel:p,createLabel:a,notLinkedLabel:c,viewLabel:u,unlinkLabel:g})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Ms(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Do,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Do,{onClick:s,title:g,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ni,{onClick:l,children:p}),t.jsx(ni,{onClick:d,primary:!0,children:a})]})]})},kt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:d,expandMoreLabel:p})=>{const[a,c]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Ms(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>c(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ni,{onClick:s,primary:!0,children:["+ ",l]})})]})},Do=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),ni=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Ms(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const hp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Fs=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:d,onSearch:p,isLoading:a,excludeId:c})=>{const[u,g]=f.useState(""),x=c?d.filter(h=>h.id!==c):d;f.useEffect(()=>{e&&(g(""),p(""))},[e]);const m=h=>{g(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:bp,children:t.jsxs("div",{style:yp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:jp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:vp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:Bn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:kp,children:[t.jsx("span",{style:{fontSize:"16px"},children:S}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Bn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Bn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:Sp,children:["创建新",b,"并关联"]})]})]})})},bp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},yp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},jp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},vp={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},kp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Bn={padding:"20px",textAlign:"center",color:o("desc-fg")},Sp={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Ho={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},wp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ps=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[d,p]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const c=x=>{x.key==="Enter"&&d.trim()?u():x.key==="Escape"&&l()},u=()=>{d.trim()&&s(d.trim(),{...r,title:d.trim()})};if(!e)return null;const g=()=>{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`创建新${Ho[n]}`}};return t.jsx("div",{style:_p,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:$p,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:wp[n]}),t.jsx("span",{children:g()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:d,onChange:x=>p(x.target.value),onKeyDown:c,placeholder:`请输入${Ho[n]}名称...`,style:zp})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Cp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!d.trim(),style:{...Ip,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},_p={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},$p={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},zp={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Cp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ip={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Tp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Os(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ep(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Ds=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:d,onSelect:p,onCancel:a,onCreate:c,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[S,h]=f.useState(!1),[v,y]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),y(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!g.trim()){b([]);return}const C=setTimeout(async()=>{h(!0);try{b(await u(g,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(C)},[g,i,u]);const j=f.useCallback(C=>{x(C.target.value),C.target.value.trim()&&y("search")},[]),_=f.useCallback(C=>s?C.filter(E=>E.id!==s):C,[s]);if(!e)return null;const k=n||(i==="all"?"选择实体":`选择${Os(i)}`),z=_(r),w=_(m);return t.jsx("div",{style:Np,children:t.jsxs("div",{style:Lp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:a,style:Bp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ap}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),z.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Go,{active:v==="recent",onClick:()=>y("recent"),children:["最近使用 (",z.length,")"]}),t.jsxs(Go,{active:v==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&z.length>0?t.jsx(Uo,{entities:z,onSelect:p}):g.trim()?S?t.jsx(An,{message:"搜索中..."}):w.length>0?t.jsx(Uo,{entities:w,onSelect:p}):t.jsx(An,{message:"未找到匹配的结果"}):t.jsx(An,{message:"输入关键词开始搜索"})}),l&&c&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:c,style:Wp,children:d||"创建新实体"})]})]})})},Go=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),Uo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Rp,{entity:i,onClick:()=>n(i)},i.id))}),Rp=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Tp(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Ep(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Os(e.type)})]})},An=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Np={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Bp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ap={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Wp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Mp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Fp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Hs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:d,onAskAI:p,renderSectionActions:a,onDownloadResource:c,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var q;const m=de(),[b,S]=f.useState(!1),[h,v]=f.useState("work"),[y,j]=f.useState(""),[_,k]=f.useState(""),[z,w]=f.useState([]),[C,E]=f.useState(!1),[R,T]=f.useState(!1),[O,M]=f.useState("work"),[W,P]=f.useState(""),[V,K]=f.useState(),[N,le]=f.useState(!1),[G,se]=f.useState(null),[ne,Q]=f.useState([]);f.useRef(null);const H=e.type,te=H==="work",pe=H==="collection",re=H==="book",ee=f.useCallback((L,I)=>{n({...e,[L]:I})},[e,n]),ye=f.useCallback((L,I)=>{j(L),v(I),k(m.editor.selectToLink+m.indexType[I]),w([]),S(!0)},[m]),ae=f.useCallback(L=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,L)},[r,e.id]),Te=f.useCallback(L=>{s==null||s(L.id,L.type)},[s]),je=f.useCallback((L,I,$)=>{const F={...$,author:($==null?void 0:$.author)||e.author,dynasty:$==null?void 0:$.dynasty};M(I),P(L),K(F),T(!0)},[e.author]),Ce=f.useCallback((L,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,W,{type:O,title:L,inheritData:I}),T(!1)},[r,e.id,W,O]),Re=f.useCallback(L=>{if(!L.trim()){w([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(L,h).then(I=>{w(I),E(!1)}).catch(()=>{w([]),E(!1)})},[r,h]),Ie=f.useCallback(L=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,L.id),S(!1)},[r,e.id,y]),D=f.useCallback(()=>{i()},[i]),oe=f.useCallback(L=>{se(()=>L),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),ie=f.useCallback((L,I)=>r!=null&&r.searchEntities?r.searchEntities(L,I==="all"?void 0:I):Promise.resolve([]),[r]),xe=f.useCallback(L=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(L),Q(I=>[L,...I.filter($=>$.id!==L.id)].slice(0,10)),G==null||G(L),le(!1),se(null)},[r,G]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Fp[H]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(gn,{children:e.id}),t.jsx(gn,{color:Mp[H],children:m.indexType[H]})]})}),t.jsx(Ye,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(dn,{label:te?m.editor.workTitle:pe?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:L=>ee("title",L)}),re&&t.jsx(dn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:L=>ee("workName",L)}),t.jsx(He,{label:m.editor.authorLabel,value:e.author||"",onChange:L=>ee("author",L)}),t.jsx(He,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:L=>ee("publicationYear",L)}),(re||pe)&&t.jsx(dn,{label:m.editor.containedIn,value:e.collection||"",onChange:L=>ee("collection",L)}),(re||pe)&&t.jsx(He,{label:m.editor.holderLabel,value:e.holder||"",onChange:L=>ee("holder",L)}),(re||pe)&&t.jsx(He,{label:re?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:L=>ee("pages",L)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(He,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:L=>ee("firstImage",L)})})]})}),t.jsx(Ye,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(ht,{value:e.description||"",onChange:L=>ee("description",L),placeholder:m.editor.descriptionPlaceholder})}),(((q=e.additional_works)==null?void 0:q.length)||0)>0&&t.jsx(Ye,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Pp,{items:e.additional_works||[],onChange:L=>ee("additional_works",L)})}),t.jsx(Ye,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Op,{items:e.indexed_by||[],onChange:L=>ee("indexed_by",L)})}),t.jsx(Ye,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Dp,{items:e.emendated_by||[],onChange:L=>ee("emendated_by",L)})}),t.jsx(Ye,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Hn,{items:e.resources||[],onChange:L=>ee("resources",L),onDownload:c,downloadStatuses:u,filterType:"text"})}),t.jsx(Ye,{title:m.section.imageResources,onSave:i,children:t.jsx(Hn,{items:e.resources||[],onChange:L=>ee("resources",L),onDownload:c,downloadStatuses:u,filterType:"image"})}),t.jsx(Ye,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ls,{items:Bs(e.sources||""),onChange:L=>ee("sources",As(L)),onOpenEntityPicker:oe})}),(re||pe)&&t.jsx(Ye,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(ht,{value:e.provenance||"",onChange:L=>ee("provenance",L),placeholder:m.editor.provenancePlaceholder})}),re&&t.jsx(Ye,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(ht,{value:e.otherEditions||"",onChange:L=>ee("otherEditions",L),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ws,{entityType:H,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:ye,onUnlinkEntity:ae,onViewEntity:Te,onCreateAndLink:je,onSaveRelations:D}),l&&d&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:d,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Fs,{isOpen:b,entityType:h,title:_,onSelect:Ie,onCancel:()=>S(!1),onCreate:()=>{S(!1),je(y,h)},searchResults:z,onSearch:Re,isLoading:C,excludeId:e.id}),t.jsx(Ps,{isOpen:R,entityType:O,relationField:W,inheritData:V,onConfirm:Ce,onCancel:()=>T(!1)}),t.jsx(Ds,{isOpen:N,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:e.id,onSelect:xe,onCancel:()=>{le(!1),se(null)},onSearch:ie})]})};function Pp({items:e,onChange:n}){const i=de(),r=(d,p,a)=>{const c=e.map((u,g)=>g===d?{...u,[p]:a}:u);n(c)},s=d=>n(e.filter((p,a)=>a!==d)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((d,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(He,{label:i.editor.bookNameLabel,value:d.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(He,{label:i.label.juanCount,value:d.n_juan!=null?String(d.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Gs({items:e,onChange:n,showMeta:i,addLabel:r}){const s=de(),[l,d]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,S)=>S===u?{...b,[g]:x||void 0}:b);n(m)},a=u=>{n(e.filter((g,x)=>x!==u)),l===u&&d(null)},c=()=>{n([...e,{source:""}]),d(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>{const x=l===g;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>d(x?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),a(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(He,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(He,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(g,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(He,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(He,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(He,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(ht,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(ht,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(ht,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:c,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Op({items:e,onChange:n}){const i=de();return t.jsx(Gs,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Dp({items:e,onChange:n}){const i=de();return t.jsx(Gs,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Us(e){var p,a,c,u,g,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((c=e.publication_info)==null?void 0:c.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",d={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const S=b.related_works.find(h=>h.relation==="part_of");S&&(d.parentWorkId=S.id,d.parentWorkName=S.title)}}if(e.type==="book"){const b=e;d.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(d.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return d}function Hp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Gp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:d,onSave:p,onDelete:a,onNavigate:c,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h,headerExtra:v,className:y,style:j}=e;de();const[_,k]=f.useState(s),z=l?s:_;f.useEffect(()=>{s!==_&&k(s)},[s]);const w=f.useCallback(()=>{const W=z==="view"?"edit":"view";l?l(W):k(W)},[z,l]),[C,E]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(W=>{W&&E(W)})},[i,r]);const R=n||C,T=f.useMemo(()=>R?Us(R):null,[R]),O=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:z==="edit"?o("accent-bg"):"transparent",color:o(z==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,M=t.jsxs(t.Fragment,{children:[O,v]});return!R&&!T?t.jsx(yt,{}):z==="view"?t.jsx(xi,{data:R,transport:r,onNavigate:c?W=>c(W):void 0,renderLink:u,headerExtra:M,className:y,style:j}):T?t.jsxs("div",{className:y,style:j,children:[M&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:M}),t.jsx(Hs,{data:T,onChange:d||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:c,showDelete:!!a,onDelete:a,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Vo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Vs=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[d,p]=f.useState(""),[a,c]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),c(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),f.useEffect(()=>{if(!e)return;const y=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const S=async()=>{if(!(!s||!d.trim())){g("submitting"),m("");try{await i({type:s,content:d.trim(),...a.trim()?{contact:a.trim()}:{}}),g("success")}catch(y){g("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&d.trim()&&u!=="submitting",v=Vo.find(y=>y.value===s);return t.jsx("div",{style:Up,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Vp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Yp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Kp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Qp,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Vo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...qp,...s===y.value?Jp:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:d,onChange:y=>p(y.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Zp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>c(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:tu}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:eu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!h,style:{...Xp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Up={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Vp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Yp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Kp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},qp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Jp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Zp={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Xp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Qp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},eu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},tu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ii="--bim-feedback-fab-offset",oi=48,nu=16,iu=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,d]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(ii,`calc(${p+oi+nu}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(ii)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ou,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.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"})})}),t.jsx(Vs,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},ou={position:"fixed",width:`${oi}px`,height:`${oi}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Yo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ys=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,d]=f.useState(""),[p,a]=f.useState("idle"),[c,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),d(""),i("bug")}catch(S){a("error"),u(S instanceof Error?S.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Yo.find(S=>S.value===n);return p==="success"?t.jsx("div",{style:Ko,children:t.jsxs("div",{style:cu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:du,children:"继续提交"})]})}):t.jsxs("div",{style:Ko,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Yo.map(S=>t.jsxs("button",{onClick:()=>i(S.value),style:{...ru,...n===S.value?su:{}},children:[t.jsx("span",{children:S.icon})," ",S.label]},S.value))}),t.jsx("textarea",{ref:g,value:r,onChange:S=>s(S.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...lu}}),t.jsx("input",{type:"text",value:l,onChange:S=>d(S.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:uu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...au,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:pu,children:c})]})},Ko={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},ru={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},su={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},lu={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},au={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},cu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},du={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},pu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},uu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function qo(e){return typeof e=="function"?e():e??"/api/feedback"}const Ks=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),d=f.useCallback(async()=>{const a=qo(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{d()},[d]);const p=async a=>{const c=qo(n),u=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||"提交失败")}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Fi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ys,{onSubmit:p})})]})},Jo={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Zo(e){return e?Jo[e]??e:Jo.related}const xu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function fu(e){return xu[e]??e}const gu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function mu(e){return gu[e]??""}function Pi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=Y(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,d)=>{const p=yi(l.role);return t.jsxs(f.Fragment,{children:[d>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Le,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},d)})}):null}function qs(e,n){var p,a;const i=hi(e,n),r=i.mirrors.map(c=>({key:c.key,label:c.label,description:c.description,rows:c.items.filter(u=>u.group_role!=="mirror"),mirrors:c.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(c=>c.key==="image"||c.key==="textImage").flatMap(c=>c.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(c=>c.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(c=>c.key==="text"))==null?void 0:a.items)??[],groups:r}}function Js(e,n){const i=(e.url?Et(e.url):void 0)||e.name,r=Ar(e,n);return r?`${i}(${r})`:i}function Oi({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=Y(),[s,l]=f.useState(!1),d=mn(e),p=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),a=r(Js(e,n)),c=Rt(e),u=jn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(ki,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(g=>!g),children:r(s?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function Zs({groups:e,listedVolumeCounts:n}){const{convert:i}=Y();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Oi,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const d=Rt(s),p=i(Js(s,r.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Ut=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function ri(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Ut.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const Xo=12,hu=60,Xs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:d,railLinks:p})=>{var Ce,Re,Ie;const a=de(),{convert:c}=Y(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[g,x]=f.useState(new Map),[m,b]=f.useState(!1),[S,h]=f.useState(""),[v,y]=f.useState(!1),j=u.length<=hu,_=j||m||!!S||v,k=f.useMemo(()=>_?u:u.slice(0,Xo),[u,_]);f.useEffect(()=>{if(!n||k.length===0)return;const D=k.filter(ie=>!g.has(ie));if(D.length===0)return;let oe=!1;return Promise.all(D.map(ie=>n.getItem(ie).then(xe=>{const q=xe??{};return[ie,{id:ie,title:q.title,edition:q.edition,resources:q.resources,publication_info:q.publication_info,current_location:q.current_location,lineage:q.lineage,measure_info:q.measure_info}]}).catch(()=>[ie,{id:ie}]))).then(ie=>{oe||x(xe=>{const q=new Map(xe);for(const[L,I]of ie)q.set(L,I);return q})}),()=>{oe=!0}},[n,k,g]);const z=f.useMemo(()=>u.map(D=>g.get(D)??{id:D}),[u,g]),w=u.length>0&&u.every(D=>g.has(D)),C=!!n&&k.some(D=>!g.has(D)),E=j||_,R=f.useMemo(()=>Mr(z,e.version_graph,{era:S,scanOnly:v,sort:E?"year":"default"}),[z,e.version_graph,S,v,E]),T=m?R.rows:R.rows.slice(0,Xo),O=R.allRows.filter(D=>D.hasImage).length,M=e.related_works||[],W=M.filter(D=>D.relation==="collected_in"),P=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],oe=ie=>{const xe=D.indexOf(ie??"");return xe<0?D.length:xe};return M.filter(ie=>ie.relation!=="collected_in").map((ie,xe)=>({r:ie,i:xe})).sort((ie,xe)=>oe(ie.r.relation)-oe(xe.r.relation)||ie.i-xe.i).map(ie=>ie.r)},[M]),V=f.useMemo(()=>{const D=hi(e.resources,e.resource_groups);return[...D.mirrors.flatMap(oe=>oe.items.map(ie=>({r:ie,kind:c(oe.label)}))),...D.buckets.flatMap(oe=>oe.items.map(ie=>({r:ie,kind:c(mu(oe.key))})))]},[e.resources,e.resource_groups,c]),K=e.indexed_by||[],N=e.emendated_by||[],le=f.useMemo(()=>{var F,A,Z;const D=[],oe=(A=(F=e.authors)==null?void 0:F[0])==null?void 0:A.dynasty;oe&&D.push({label:"成書",value:c(oe)});const ie=st(e,a.unit.juan);if(ie){const J=(Z=e.juan_count)==null?void 0:Z.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[c(ie),J&&J!==ie?t.jsxs("span",{className:"bim-d-meta",children:["(",c(J),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:c(fu(e.loss_status))});const xe=R.allRows.filter(J=>J.sortYear!=null),q=xe.length>0?xe.reduce((J,fe)=>J.sortYear<=fe.sortYear?J:fe):null;q!=null&&q.era.era?D.push({label:"最早存世",value:c([q.era.era,q.era.reign].filter(Boolean).join(" ")),title:q.era.source==="edition"?c("據版本題名推斷"):void 0}):C&&D.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":c("載入中"),children:"…"})}),N.length&&D.push({label:"考證",value:`${N.length} ${c("條")}`});const L=Qo(e.additional_titles);L.length&&D.push({label:"又名",value:L.map(c).join("、")});const I=Qo(e.attached_texts);I.length&&D.push({label:"附載",value:I.map(c).join("、")});const $=(e.additional_works||[]).map(J=>c(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${c(a.unit.juan)}`:""));return $.length&&D.push({label:"附錄",value:$.join("、")}),D},[e,c,a,C,R.allRows,N.length]),se=[{value:e._edition_count??u.length,label:"版本"},{value:w?O:0,label:"有影印"},{value:K.length,label:"家著錄"}],ne=e.classification,Q=ne?[ne.l1,ne.l2,ne.l3,ne.l4].filter(Boolean).map(D=>c(D)):[],H=e.subtype?c(a.workSubtype[e.subtype]??e.subtype):"",te=t.jsx(Jt,{title:c(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Be,{items:[...Q,ne!=null&&ne.source?c(`據《${ne.source.split("/")[0]}》`):"",H]}),description:(Ce=e.description)!=null&&Ce.text?t.jsxs(t.Fragment,{children:[t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Re=e.description.sources)!=null&&Re.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>c(nc(D))).filter(Boolean).join(" · ")}):null]}):void 0,stats:se,facts:le,readAction:s,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ie=e.appendix)==null?void 0:Ie.map((D,oe)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:c(D.title)}),t.jsx(rt,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},oe))}),pe=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(D=>({key:D,label:`${D} ${R.allRows.filter(oe=>oe.era.era===D).length}`}))]:[],re=[];u.length&&re.push({id:"versions",label:"版本",count:u.length}),K.length&&re.push({id:"catalogs",label:"著錄",count:K.length}),W.length&&re.push({id:"collected",label:"收入叢編",count:W.length}),P.length&&re.push({id:"related",label:"相關書目",count:P.length}),V.length&&re.push({id:"resources",label:"在線資源",count:V.length});const ee=u.length===0&&K.length===0,ye=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Be,{items:[c(`共 ${u.length} 種`),w&&O?c(`${O} 種有影印`):"",R.rows.length!==R.allRows.length?c(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":C&&pe.length===0&&u.length>1?"":void 0,children:[pe.length>0&&t.jsx(kn,{items:pe,value:S,onChange:D=>{h(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Jr,{label:"只看有影印",checked:v,onChange:D=>{y(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(E?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("版本")}),t.jsx("th",{children:c("年代")}),t.jsx("th",{children:c("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("影印")})})]})}),t.jsx("tbody",{children:T.map(D=>{var oe;return t.jsx(bu,{row:D,measure:(oe=g.get(D.id))==null?void 0:oe.measure_info,loaded:g.has(D.id),onNavigate:i,renderLink:r},`${D.id}:${g.has(D.id)?"r":"p"}`)})})]}),T.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(S||v?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>T.length&&t.jsx(Nt,{label:`展開其餘 ${R.rows.length-T.length} 種版本`,onClick:()=>b(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(yu,{items:K,transport:n,onNavigate:i,renderLink:r}),ee&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該作品的版本與書目收錄。")})})]}),ae=(D,oe)=>t.jsx(Le,{id:D,label:c(oe),onNavigate:i,renderLink:r,dense:!0}),Te=f.useMemo(()=>{const D=new Map;for(const oe of P){const ie=Zo(oe.relation);D.set(ie,(D.get(ie)??0)+1)}return D.size>1?[...D.entries()].sort((oe,ie)=>ie[1]-oe[1]).slice(0,4).map(([oe,ie])=>`${c(oe)} ${ie}`).join(" · "):void 0},[P,c]),je=t.jsxs(t.Fragment,{children:[t.jsx(mt,{id:"collected",title:"收入叢編",items:W.map(D=>ae(D.id,D.title))}),t.jsx(mt,{id:"related",title:"相關書目",meta:c(`${P.length} 部`),sub:Te,items:P.map(D=>t.jsxs(t.Fragment,{children:[ae(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?c(D.note):void 0,children:c(Zo(D.relation))})]}))}),t.jsx(mt,{id:"resources",title:"在線資源",cap:6,items:V.map(({r:D,kind:oe})=>{const ie=c((D.url?Et(D.url):void 0)||D.name),xe=Rt(D);return t.jsxs(t.Fragment,{children:[xe?t.jsxs("a",{href:xe,target:"_blank",rel:"noopener noreferrer",children:[ie," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ie}),oe&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:oe})]})})})]});return t.jsx(qt,{railTop:l,back:d,nav:re,railLinks:p,main:ye,card:te,side:je})};function Qo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function er(e,n){return n((e.url?Et(e.url):void 0)||e.name)}function bu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],c=a?er(a,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Rt(u):void 0,x=e.images.map(m=>er(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:d?l(d):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${c?"":" bim-d-zt-blank"}`,children:[c||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function yu({items:e,transport:n,onNavigate:i,renderLink:r}){const s=de(),{convert:l}=Y(),[d,p]=f.useState(0),a=Math.min(d,e.length-1),c=e[a],[u,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let m=!1;return Promise.all(x.map(b=>n.getItem(b).then(S=>{var h,v;return[b,((v=(h=S==null?void 0:S.authors)==null?void 0:h[0])==null?void 0:v.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{m||g(new Map(b.filter(([,S])=>S)))}),()=>{m=!0}},[n,e]),t.jsx(Fe,{id:"catalogs",title:"著錄",meta:t.jsx(Be,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===a,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,S)=>t.jsx("span",{children:b},S))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[c.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(c.title_info)}),t.jsx(Be,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[c.source_bid?t.jsx(Le,{id:c.source_bid,label:l(c.source),onNavigate:i,renderLink:r,dense:!0}):l(c.source),c.section?l(c.section):"",c.author_info?`${l(s.label.authorInfo)} ${l(c.author_info)}`:"",c.edition?`${l(s.label.edition)} ${l(c.edition)}`:"",c.page??""]}),c.summary&&t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.summary))}),c.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.comment))})]}),c.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.additional_comment))})]}),!c.summary&&!c.comment&&!c.additional_comment&&!c.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[t.jsx("button",{type:"button",disabled:a===0,onClick:()=>p(a-1),children:a>0?`← ${l(e[a-1].source)}`:""}),t.jsxs("span",{className:"bim-d-meta",children:[a+1," / ",e.length]}),t.jsx("button",{type:"button",disabled:a===e.length-1,onClick:()=>p(a+1),children:a<e.length-1?`${l(e[a+1].source)} →`:""})]})]})]})})}const tr=40,nr=2,ju=9,ir={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Wn(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Qs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:d,chapterLink:p,railTop:a,back:c,railLinks:u})=>{var q,L,I,$,F,A,Z,J,fe,we,_e,Ne,Ee,Lt;const g=de(),{convert:x}=Y(),[m,b]=f.useState(null),[S,h]=f.useState(new Map),[v,y]=f.useState([]),[j,_]=f.useState(new Map),[k,z]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let B=!1;return n.getItem(e.work_id).then(ce=>{!B&&ce&&ce.type==="work"&&b(ce)}).catch(()=>{}),()=>{B=!0}},[n,e.work_id]),f.useEffect(()=>{const B=e.contained_in||[];if(!n||B.length===0){h(new Map);return}let ce=!1;return Promise.all(B.map(ue=>{const ve=typeof ue=="string"?ue:ue.id;return n.getItem(ve).then(he=>[ve,he]).catch(()=>[ve,null])})).then(ue=>{if(ce)return;const ve=new Map;for(const[he,ge]of ue)ge&&ve.set(he,ge);h(ve)}),()=>{ce=!0}},[n,e.contained_in]);const w=f.useMemo(()=>{const B=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return B.add(e.id),[...B]},[m==null?void 0:m.books,e.related_books,e.id]),C=w.length-1;f.useEffect(()=>{if(!n||C<=0){y([]);return}const B=w.length<=tr,ce=B?w:w.slice(0,8);let ue=!1;return Promise.all(ce.map(ve=>ve===e.id?Promise.resolve({id:ve,title:e.title,edition:e.edition,year:xn(e)}):n.getItem(ve).then(he=>{const ge=he??{};return{id:ve,title:ge.title,edition:ge.edition,year:he?xn(ge):void 0}}).catch(()=>({id:ve})))).then(ve=>{if(ue)return;const he=ve.filter(ge=>ge.id===e.id||ge.title||ge.edition);B&&he.sort((ge,Ae)=>(ge.year??1/0)-(Ae.year??1/0)),y(he)}),()=>{ue=!0}},[n,w,C,e]);const E=e.lineage,R=f.useMemo(()=>[...((E==null?void 0:E.derived_from)||[]).filter(B=>B.ref_type==="book").map(B=>B.ref),...((E==null?void 0:E.related_to)||[]).map(B=>B.book_id)].filter(Boolean),[E]);f.useEffect(()=>{if(!n||R.length===0){_(new Map);return}let B=!1;return Promise.all(R.map(ce=>n.getItem(ce).then(ue=>[ce,{id:ce,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[ce,{id:ce}]))).then(ce=>{B||_(new Map(ce))}),()=>{B=!0}},[n,R]);const T=f.useMemo(()=>qs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),O=T.groups.reduce((B,ce)=>B+ce.rows.length+ce.mirrors.length,0),M=T.groups.length>0&&T.groups.every(B=>B.key==="_physical"),W=Kt(e),P=Hr(e),V=st(e,g.unit.juan),K=new Set((e.contained_in||[]).map(B=>typeof B=="string"?0:Ht(B.volume_index).length).filter(B=>B>0)),N=B=>{var ve;const ce=(ve=e.base_edition)==null?void 0:ve.find(he=>he.book_id===B&&he.name);if(ce!=null&&ce.name)return ce.name;const ue=j.get(B);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},le=f.useMemo(()=>{var ut,lt,en,at,tn;const B=[];P&&B.push({label:"版本類型",value:x(P),title:e.edition_type||(ut=e.lineage)!=null&&ut.category?void 0:x("據版本題名推斷")}),(lt=e.publication_info)!=null&<.details?B.push({label:"刊印",value:x(e.publication_info.details)}):(W.era||W.reign)&&B.push({label:"刊寫年代",value:x([W.era,W.reign].filter(Boolean).join(" ")),title:W.source==="edition"?x("據版本題名推斷"):void 0}),V&&B.push({label:"卷帙",value:x(V)});const ce=(e.contained_in||[]).flatMap(ke=>typeof ke=="string"?[]:Ht(ke.volume_index));ce.length&&B.push({label:"冊次",value:x(`第 ${vn(ce,g.unit.volume)} ${g.unit.volume}(${ce.length} ${g.unit.volume})`)});const ue=(((en=e.lineage)==null?void 0:en.derived_from)||[]).find(ke=>ke.relation==="底本"&&ke.ref_type==="book");ue&&N(ue.ref)&&B.push({label:"底本",value:t.jsx(Le,{id:ue.ref,label:x(N(ue.ref)),onNavigate:i,renderLink:r,dense:!0})});const ve=(e.base_edition||[]).filter(ke=>ke&&ke.name);for(const ke of["底本","配補","參校"]){if(ke==="底本"&&ue&&N(ue.ref))continue;const Ue=ve.filter(ze=>ze.role===ke);Ue.length&&B.push({label:ke,value:Ue.map((ze,nn)=>t.jsxs(f.Fragment,{children:[nn>0&&"、",ze.book_id?t.jsx(Le,{id:ze.book_id,label:x(ze.name),onNavigate:i,renderLink:r,dense:!0}):x(ze.name)]},nn))})}const he=(e.provenance||[]).filter(ke=>ke&&ke.institution),ge=(e.resources||[]).filter(ke=>(ke.types||(ke.type?[ke.type]:[])).includes("physical"));if(he.length){B.push({label:"存藏",value:he.slice(0,2).map(ze=>x(ze.institution)).join("、")+(he.length>2?x(` 等 ${he.length} 處`):"")});const ke=he.filter(ze=>ze.call_number).slice(0,2).map(ze=>`${x(ze.institution)} ${ze.call_number}`);ke.length&&B.push({label:"索書號",value:ke.join(";")+(he.filter(ze=>ze.call_number).length>2?"…":"")});const Ue=he.flatMap(ze=>ze.seals||[]).filter(Boolean);Ue.length&&B.push({label:"藏印",value:x(Ue.join("、"))})}else ge.length?B.push({label:"存藏",value:ge.slice(0,2).map(ke=>x(ke.name)).join("、")+(ge.length>2?x(` 等 ${ge.length} 處`):"")}):(at=e.current_location)!=null&&at.name&&B.push({label:"存藏",value:x(e.current_location.name)});const Ae=e.physical_description;if(Ae){const ke=[["行款",Ae.leaf_style],["裝幀",Ae.binding],["尺寸",Ae.dimensions],["品相",Ae.condition]];for(const[Ue,ze]of ke)ze&&ze.trim()&&B.push({label:Ue,value:x(ze)})}(tn=e.page_count)!=null&&tn.description&&B.push({label:g.label.pageCount,value:x(e.page_count.description)});const tt=[...Zn(e.additional_titles),...Zn(e.attached_texts)];return tt.length&&B.push({label:"又名",value:tt.map(x).join("、")}),B},[e,x,g,W,P,V,j,i,r]),G=x(e.title),se=e.edition?x(e.edition):void 0,ne=((q=e.lineage)==null?void 0:q.year_text)||"",Q=t.jsx(Jt,{kind:"版本",title:G,subtitle:se,byline:t.jsx(Pi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Be,{items:[P?x(P):"",W.era?x([W.era,W.reign].filter(Boolean).join("")):"",V?x(V):""]}),description:(L=e.description)!=null&&L.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((I=e.description)==null?void 0:I.text)?6:void 0,facts:le,readAction:s,secondaryAction:s&&O>0&&!M?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),H=e.contained_in||[],te=(l==null?void 0:l.chapters)||[],pe=te[0]&&Wn(te[0].title)[0].slice(-1)||"章",re=!!(($=E==null?void 0:E.derived_from)!=null&&$.length||(F=E==null?void 0:E.related_to)!=null&&F.length||(A=e.appendix)!=null&&A.length),ee=[];(te.length||T.text.length||d)&&ee.push({id:"fulltext",label:"全文",count:te.length?x(`${te.length} ${pe}`):void 0}),T.groups.length&&ee.push({id:"images",label:M?"館藏":"影印",count:O}),re&&ee.push({id:"lineage",label:"版本源流"}),H.length&&ee.push({id:"collections",label:"收入叢編",count:H.length}),(Z=e.location_history)!=null&&Z.length&&ee.push({id:"provenance",label:"流轉歷史"});const ye=B=>(p==null?void 0:p(B))??null,ae=te[0],Te=ae?ye(ae.file):null,je=k?te:te.slice(0,ju),Ce=(B,ce,ue)=>B?t.jsx("a",{className:ue,href:B.href??"#",onClick:B.onClick?ve=>{ve.metaKey||ve.ctrlKey||(ve.preventDefault(),B.onClick())}:void 0,children:ce}):t.jsx("span",{className:ue,children:ce}),Re=t.jsxs(t.Fragment,{children:[(te.length>0||T.text.length>0||d)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:te.length>0?t.jsx(Be,{items:[x(`${te.length} ${pe}`),(J=l==null?void 0:l.source)!=null&&J.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[d&&!ae&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ae&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Wn(ae.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((ae.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),Ce(Te,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),te.length>1&&t.jsx("ul",{className:"bim-d-chap",children:je.map(B=>{const[ce,ue]=Wn(B.title);return t.jsx("li",{children:Ce(ye(B.file),t.jsxs(t.Fragment,{children:[ce&&t.jsx("b",{children:x(ce)}),x(ue||B.file)]}))},B.file)})}),te.length>je.length&&t.jsx(Nt,{label:`展開其餘 ${te.length-je.length} ${pe}`,onClick:()=>z(!0)}),T.text.length>0&&t.jsxs(t.Fragment,{children:[(te.length>0||d)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:T.text.map((B,ce)=>t.jsx(Oi,{item:B,siblings:T.text,listedVolumeCounts:K},`${B.id||B.url||B.name}-${ce}`))})})]})]}),T.groups.length>0&&t.jsx(Fe,{id:"images",title:M?"館藏":"影印",meta:t.jsx(Be,{items:[T.groups.length>1?x(`${T.groups.length} 組`):"",x(`${O} 處`)]}),children:t.jsx(Zs,{groups:T.groups,listedVolumeCounts:K})}),re&&t.jsxs(Fe,{id:"lineage",title:"版本源流",meta:(fe=E==null?void 0:E.derived_from)!=null&&fe.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((E==null?void 0:E.derived_from)||[]).map((B,ce)=>{const ue=B.ref_type==="book"?N(B.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),B.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Le,{id:B.ref,label:x(ue||B.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(B.evidence||B.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[B.evidence?x(B.evidence):"",B.confidence&&ir[B.confidence]?x(`(${ir[B.confidence]})`):""]})]},`d-${ce}`)}),(we=E==null?void 0:E.derived_from)!=null&&we.length||(_e=E==null?void 0:E.related_to)!=null&&_e.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:se||G}),ne&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(ne)]})]}):null,((E==null?void 0:E.related_to)||[]).map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Le,{id:B.book_id,label:x(N(B.book_id)||B.book_id),onNavigate:i,renderLink:r,dense:!0})}),B.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(B.evidence)})]},`r-${ce}`)),(Ne=e.appendix)==null?void 0:Ne.map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(B.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(rt,{text:B.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${ce}`))]}),(E==null?void 0:E.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(E.note)})]}),H.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:H.map((B,ce)=>{var Ae,tt;const ue=typeof B=="string"?B:B.id,ve=typeof B=="string"?[]:Ht(B.volume_index),he=S.get(ue),ge=(he==null?void 0:he._member_count)||((Ae=he==null?void 0:he.books)==null?void 0:Ae.length)||((tt=he==null?void 0:he.contained_works)==null?void 0:tt.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:ue,label:he?x(he.title):ue,onNavigate:i,renderLink:r,dense:!0}),ve.length>0&&t.jsx(vu,{volumes:ve,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ge>0&&x(`全 ${ge} ${g.unit.bu}`)})]},`${ue}-${ce}`)})})})}),(Ee=e.location_history)!=null&&Ee.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(B.name)}),([B.start_date,B.end_date].filter(Boolean).join("—")||B.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Be,{items:[[B.start_date,B.end_date].filter(Boolean).join("—"),B.description?x(B.description):""]})})]},ce))})}):null,ee.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),Ie=v.findIndex(B=>B.id===e.id),D=w.length<=tr,oe=D&&Ie>=0?v.slice(Math.max(0,Ie-nr),Ie+nr+1):v.filter(B=>B.id!==e.id),ie=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Le,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Be,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(B=>`${B.dynasty?`〔${x(B.dynasty)}〕`:""}${x(B.name)}`),x(st(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Lt=m.description)==null?void 0:Lt.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),C>0&&oe.length>0&&t.jsxs("div",{children:[t.jsx(mt,{id:"siblings",title:D?"同作品版本":g.relation.siblingVersions,meta:x(D?"按年代":`${C} 種`),cap:oe.length,items:oe.map(B=>B.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(B.edition||B.title||B.id)}):t.jsx(Le,{id:B.id,label:x(B.edition||B.title||B.id),onNavigate:i,renderLink:r,dense:!0})),metas:oe.map(B=>[B.year!=null?B.year<0?`前${-B.year}`:String(B.year):"",B.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:oe.findIndex(B=>B.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Le,{id:m.id,label:x(`在作品頁看全部 ${w.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),xe=e.work_id?t.jsx(qr,{caption:g.section.belongsToWork,children:t.jsx(Le,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(qt,{railTop:a,back:c,up:xe,nav:ee,railLinks:u,main:Re,card:Q,side:ie})};function vu({volumes:e,unit:n}){const{convert:i}=Y();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${vn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Mn=16,ku=200,Su=16,el=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:d,back:p,railLinks:a})=>{var D,oe,ie,xe,q,L,I;const c=de(),{convert:u}=Y(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[S,h]=f.useState(null),[v,y]=f.useState(""),j=f.useMemo(()=>Or(e,n),[e,n]),[_,k]=f.useState(new Map),z=!!i&&j.rows.length>0&&j.rows.length<=ku,w=z&&j.rows.every($=>!$.id||_.has($.id)),C=$=>{var F;return ri($?(F=_.get($))==null?void 0:F.l1:void 0)},E=f.useMemo(()=>{const $=g.trim(),F=$?u($):"";return j.rows.filter(A=>{var J,fe;if(v&&ri(A.id?(J=_.get(A.id))==null?void 0:J.l1:void 0)!==v)return!1;if(!F)return!0;const Z=A.id&&((fe=_.get(A.id))==null?void 0:fe.title)||A.title;return u(Z).includes(F)||(A.subItems||[]).some(we=>u(we).includes(F))})},[j.rows,g,v,_,u]),R=m?E:E.slice(0,Mn),T=f.useMemo(()=>(z?j.rows:R).filter($=>$.id&&!_.has($.id)).map($=>$.id),[z,j.rows,R,_]);f.useEffect(()=>{if(!i||T.length===0)return;let $=!1;const F=T.slice(0,Su);return Promise.all(F.map(A=>i.getItem(A).then(Z=>{var we,_e;const J=Z??{},fe={title:J.title,edition:J.edition,authors:J.authors,measure:Z?st(Z,c.unit.juan):void 0,versionCount:J._edition_count??((we=J.books)==null?void 0:we.length),l1:((_e=J.classification)==null?void 0:_e.l1)||void 0};return[A,fe]}).catch(()=>[A,{}]))).then(A=>{$||k(Z=>{const J=new Map(Z);for(const[fe,we]of A)J.set(fe,we);return J})}),()=>{$=!0}},[i,T,c.unit.juan]);const O=(e.contained_in||[])[0];f.useEffect(()=>{if(!O){h(null);return}if(h({id:O}),!i)return;let $=!1;return i.getItem(O).then(F=>{$||h({id:O,title:F==null?void 0:F.title})}).catch(()=>{}),()=>{$=!0}},[i,O]);const M=f.useMemo(()=>qs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),W=M.text.length+M.groups.reduce(($,F)=>$+F.rows.length+F.mirrors.length,0),P=e.contained_works||[],V=new Set(j.rows.map($=>$.id).filter(Boolean)),K=P.length>0&&!P.every($=>V.has($.id)),N=(()=>{const $=j.rows.map(F=>F.edition).filter(Boolean);return $.length>1&&new Set($).size===1})(),le=j.rows.some($=>$.volumes.length>0||$.expected!=null),G=e._member_count||((D=e.books)==null?void 0:D.length)||P.length,se=st(e,c.unit.juan),ne=e.count,Q=$=>typeof $=="number"&&Number.isFinite($)?$:null,H=Q(ne==null?void 0:ne.juan)??Q((oe=e.juan_count)==null?void 0:oe.number),te=Q(ne==null?void 0:ne.ce)??(j.totalVolumes||null),pe=[{value:j.rows.length,label:"子目"},{value:H??0,label:c.unit.juan},{value:te??0,label:c.unit.volume}],re=f.useMemo(()=>{var A,Z;const $=[];if((A=e.publication_info)!=null&&A.details&&$.push({label:"刊印",value:u(e.publication_info.details)}),G&&G!==j.rows.length){const J=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";$.push({label:u(J),value:`${G} ${u(c.unit.bu)}`,title:u("子目與其各版本合計")})}const F=[Q(ne==null?void 0:ne.zhong)!=null?`${ne.zhong} 種`:"",Q(ne==null?void 0:ne.han)!=null?`${ne.han} 函`:""].filter(Boolean);return F.length&&$.push({label:"應收",value:u(F.join(" "))}),H==null&&se&&$.push({label:"卷帙",value:u(se),title:(Z=e.juan_count)!=null&&Z.description?u(e.juan_count.description):void 0}),$},[e,G,j.rows.length,H,se,ne,u,c]),ee=f.useMemo(()=>{if(!w)return[];const $=new Map;for(const A of j.rows){const Z=C(A.id);Z&&$.set(Z,($.get(Z)??0)+1)}const F=Ut.filter(A=>($.get(A.key)??0)>0);return F.length<2?[]:[{key:"",label:`${c.catalog.all} ${j.rows.length}`},...F.map(A=>({key:A.key,label:`${A.label} ${$.get(A.key)}`}))]},[w,j.rows,_,c]),ye=f.useMemo(()=>{if(!w||!j.rows.some(Z=>Z.volumes.length>0))return null;const $=[],F=j.rows.filter(Z=>Z.volumes.length>0).map(Z=>({k:C(Z.id)??"",from:Math.min(...Z.volumes),to:Math.max(...Z.volumes)})).sort((Z,J)=>Z.from-J.from);for(const Z of F){const J=Z.to-Z.from+1,fe=$[$.length-1];fe&&fe.key===Z.k?(fe.to=Math.max(fe.to,Z.to),fe.n+=J):$.push({key:Z.k,from:Z.from,to:Z.to,n:J})}const A=F.reduce((Z,J)=>Math.max(Z,J.to),0);return $.length>1&&$.some(Z=>Z.key)?{segs:$,last:A}:null},[w,j.rows,_]),ae=(ie=e.description)==null?void 0:ie.text,Te=t.jsx(Jt,{kind:"叢編",title:u(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Be,{items:[e.subtype==="work_collection"?u("作品集"):"",(xe=e.publication_info)!=null&&xe.year?u(e.publication_info.year):""]}),description:ae||(q=e.history)!=null&&q.length?t.jsxs(t.Fragment,{children:[ae&&t.jsx(rt,{text:ae,style:{fontSize:15,lineHeight:1.85}}),(L=e.history)!=null&&L.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map(($,F)=>t.jsx("li",{children:u($)},F))}):null]}):void 0,clampDescription:ji(ae)||(((I=e.history)==null?void 0:I.length)??0)>2?6:void 0,stats:pe,facts:re,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ye&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ye.segs.map(($,F)=>{const A=Ut.find(Z=>Z.key===$.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!A,title:A?u(`${A.label} 第 ${$.from}–${$.to} 冊`):void 0,"aria-label":u(A?`只看${A.label}`:"未分類"),"aria-pressed":!!A&&v===$.key,style:{flexGrow:$.n,background:o(A?A.token:"rule")},onClick:()=>{A&&(y(v===$.key?"":$.key),b(!1))}},F)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${c.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ye.last} ${c.unit.volume}`)})]})]})}),je=[];j.rows.length&&je.push({id:"titles",label:"子目",count:j.rows.length}),W&&je.push({id:"resources",label:"影印與全文",count:W}),K&&je.push({id:"works",label:c.section.containedWorks,count:P.length});const Ce=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Be,{items:[u(`${j.rows.length} ${c.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${c.unit.volume}`):"",E.length!==j.rows.length?u(`當前 ${E.length} ${c.unit.items}`):""]}),action:l,children:[(j.rows.length>Mn||ee.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ee.length>0&&t.jsx(kn,{items:ee,value:v,onChange:$=>{y($),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),j.rows.length>Mn&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:$=>{x($.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[le&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:R.map(($,F)=>{var Ne;const A=$.id?_.get($.id):void 0,Z=A!=null&&A.title&&$.title===$.id?A.title:$.title,J=((A==null?void 0:A.authors)||[]).find(Ee=>Ee&&Ee.name),fe=[J?`${J.dynasty?`〔${u(J.dynasty)}〕`:""}${u(J.name)}${J.role?` ${u(J.role)}`:""}`:"",A!=null&&A.measure?u(A.measure):"",(Ne=$.subItems)!=null&&Ne.length?$.subItems.map(Ee=>u(Ee)).join("、"):"",(A!=null&&A.edition||$.edition)&&!N?u((A==null?void 0:A.edition)||$.edition||""):""].filter(Boolean),we=Ut.find(Ee=>Ee.key===C($.id)),_e=$.volumes.length>0?u(`第 ${vn($.volumes,c.unit.volume)} ${c.unit.volume}`):$.expected!=null?u(`${$.found??0}/${$.expected} ${c.unit.volume}`):"";return t.jsxs("tr",{children:[le&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${_e?"":" bim-d-zt-blank"}`,children:[we&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(we.token)}}),_e||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[$.id?t.jsx(Le,{id:$.id,label:u(Z),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(Z)}),fe.length>0?t.jsx(Be,{items:fe}):$.id&&!A&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${A!=null&&A.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:A!=null&&A.versionCount?u(`${A.versionCount} 種`):""})]},`${$.id??$.title}-${F}`)})})]}),R.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(c.catalog.noMatch)}),E.length>R.length&&t.jsx(Nt,{label:`展開其餘 ${E.length-R.length} ${c.unit.items}`,onClick:()=>b(!0)})]}),W>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${W} 處`),children:[M.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[M.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:M.text.map(($,F)=>t.jsx(Oi,{item:$,siblings:M.text},`${$.id||$.url||$.name}-${F}`))})})]}),t.jsx(Zs,{groups:M.groups})]}),j.rows.length===0&&W===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),Re=K?t.jsx(mt,{id:"works",title:c.section.containedWorks,meta:u(`${P.length} 種`),cap:12,items:P.map($=>t.jsx(Le,{id:$.id,label:u($.title),onNavigate:r,renderLink:s,dense:!0}))}):null,Ie=S?t.jsx(qr,{caption:"上級叢編",children:t.jsx(Le,{id:S.id,label:u(S.title||S.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(qt,{railTop:d,back:p,up:Ie,nav:je,railLinks:a,main:Ce,card:Te,side:Re})},wu=16,Fn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function or(e){if(!e)return Fn.length;const n=Fn.indexOf(e);return n===-1?Fn.length:n}const _u={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function pt(e){return e==null?"":e<0?`前${-e}`:String(e)}const $u={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},tl=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:d})=>{var oe,ie,xe,q,L;const p=de(),{convert:a}=Y(),[c,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[S,h]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(I=>{const $=S.get(I.work_id);return{id:I.work_id,title:($==null?void 0:$.title)??I.title??I.work_id,role:I.role||"",cls:bi(I.role),versionCount:$==null?void 0:$.versionCount,section:$==null?void 0:$.cls,l1:$==null?void 0:$.l1,measure:$==null?void 0:$.measure,hasImage:$==null?void 0:$.hasImage,loaded:!!($!=null&&$.loaded)}}),[e.works,S]),y=f.useMemo(()=>Pr((e.works||[]).map(I=>I.role)),[e.works]),j=f.useMemo(()=>{const I=c==="全部"?v:v.filter($=>$.cls===c);return m==="versions"?[...I].sort(($,F)=>(F.versionCount??-1)-($.versionCount??-1)):I},[v,c,m]),_=g?j:j.slice(0,wu),k=f.useMemo(()=>_.filter(I=>!S.has(I.id)).map(I=>I.id),[_,S]);f.useEffect(()=>{if(!n||k.length===0)return;let I=!1;return Promise.all(k.map($=>n.getItem($).then(F=>{var fe,we,_e,Ne,Ee;const A=F??{},Z=A._edition_count??(((fe=A.books)==null?void 0:fe.length)??0)+(((we=A.collections)==null?void 0:we.length)??0),J=[(_e=A.classification)==null?void 0:_e.l1,(Ne=A.classification)==null?void 0:Ne.l2].filter(Boolean).join(" ");return[$,{id:$,title:A.title,versionCount:Z,loaded:!0,cls:J||void 0,l1:((Ee=A.classification)==null?void 0:Ee.l1)||void 0,measure:F&&st(F,p.unit.juan)||void 0,hasImage:!!(A.has_image??A._has_image)}]}).catch(()=>[$,{id:$,loaded:!0}]))).then($=>{I||h(F=>{const A=new Map(F);for(const[Z,J]of $)A.set(Z,J);return A})}),()=>{I=!0}},[n,k,p.unit.juan]);const z=f.useMemo(()=>{const I=new Map;for(const $ of e.alt_names||[]){const F=$.type||p.section.aliases;I.has(F)||I.set(F,[]),I.get(F).push($.name)}return[...I.entries()].sort(($,F)=>or($[0])-or(F[0])).map(([$,F])=>({label:$,names:F}))},[e.alt_names,p]),w=e.birth_year??((oe=e.dates)==null?void 0:oe.birth)??void 0,C=e.death_year??((ie=e.dates)==null?void 0:ie.death)??void 0,E=(xe=e.dates)==null?void 0:xe.floruit,R=w!=null||C!=null?`${pt(w)||"?"}—${pt(C)||"?"}`:Array.isArray(E)&&E.length===2&&E.every(I=>Number.isFinite(I))?`活躍於 ${pt(E[0])}—${pt(E[1])}`:"",T=new Set(["本名","字","號","号"]),O=z.filter(I=>T.has(I.label)),M=z.filter(I=>!T.has(I.label)),W=M.reduce((I,$)=>I+$.names.length,0),P=f.useMemo(()=>{const I=[];for(const F of O)I.push({label:F.label,value:F.names.map(A=>a(A)).join("、")});const $=(e.works||[]).length;return $&&I.push({label:"著作",value:`${$} ${a("種")}`}),I},[e.works,O,a]),V=I=>{var $;return($=z.find(F=>I.includes(F.label)))==null?void 0:$.names[0]},K=V(["字"]),N=V(["號","号"]),le=[K?`字${K}`:"",N?`號${N}`:""].filter(Boolean).join(","),G=e.native_place,se=e.dynasty?$u[e.dynasty]:void 0,ne=(()=>{if(!se||w==null||C==null||C<w)return null;const[I,$]=se,F=Math.max(w,I),A=Math.min(C,$);if(A<=F)return null;const Z=$-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":a(`${pt(w)}—${pt(C)},一生 ${C-w+1} 年`),children:t.jsx("i",{style:{left:`${(F-I)/Z*100}%`,width:`${(A-F)/Z*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:a(`${pt(I)} ${e.dynasty}`)}),t.jsx("span",{children:a(`一生 ${C-w+1} 年`)}),t.jsx("span",{children:pt($)})]})]})})(),Q=f.useMemo(()=>{if(!n||v.length===0||v.some(F=>!F.loaded))return null;const I=new Map;for(const F of v){const A=ri(F.l1);A&&I.set(A,(I.get(A)??0)+1)}const $=Ut.map(F=>({...F,n:I.get(F.key)??0})).filter(F=>F.n>0);return $.length?$:null},[v,n]),H=t.jsxs(Jt,{kind:_u[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:le?a(le):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Be,{items:[e.dynasty?a(e.dynasty):"",R?a(R):"",G?a(`${G}人`):""]}),ne]}),description:(q=e.description)!=null&&q.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((L=e.description)==null?void 0:L.text)?6:void 0,facts:P,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[W>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${W})`)}),t.jsx("dl",{children:M.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(I.label)}),t.jsx("dd",{children:I.names.map($=>a($)).join("、")})]},I.label))})]}),Q&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:a("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:Q.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:o(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:Q.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(I.token)}}),a(I.label)," ",I.n]},I.key))})]})]}),te=f.useMemo(()=>v.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,$)=>($.versionCount??0)-(I.versionCount??0)).slice(0,3),[v]),pe=!!n&&v.length>=3&&_.some(I=>!I.loaded),re=c==="全部"&&(pe||te.length>=2),ee=e.external_ids||{},ye=[];ee.cbdb_id!=null&&ye.push({label:"CBDB",id:String(ee.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ee.cbdb_id}`,note:ee.cbdb_match==="auto"?"自動匹配":void 0});const ae=ee.wikidata_id;ae&&ye.push({label:"Wikidata",id:ae,href:`https://www.wikidata.org/wiki/${ae}`});const Te=ee.viaf_id;Te&&ye.push({label:"VIAF",id:Te,href:`https://viaf.org/viaf/${Te}`});const je=y.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Ce=[...re&&!pe?[{id:"featured",label:"著作舉要",count:te.length}]:[],...v.length?[{id:"works",label:"全部著作",count:v.length}]:[],...ye.length?[{id:"external",label:"站外資料",count:ye.length}]:[]],Re=re?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:a("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":pe||void 0,children:[pe&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!pe&&te.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Le,{id:I.id,label:a(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Be,{items:[I.section?a(I.section):"",I.measure?a(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:a("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},I.id))]})]}):null,Ie=v.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Re,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Be,{items:[a(`共 ${v.length} 種`),j.length!==v.length?a(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[je.length>1&&t.jsx(kn,{items:je,value:c,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:a(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("部類")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:_.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:I.id,label:a(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(Be,{items:[a(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?a(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?a(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?a(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},I.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),j.length>_.length&&t.jsx(Nt,{label:`展開其餘 ${j.length-_.length} 種著作`,onClick:()=>x(!0)})]})]}),D=ye.length>0?t.jsx(mt,{id:"external",title:"站外資料",items:ye.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:ye.map(I=>I.id),foot:ee.cbdb_id!=null&&ee.cbdb_match==="auto"?a("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(qt,{railTop:s,back:l,nav:Ce,railLinks:d,main:Ie,card:H,side:D})},Di="(max-width: 719px)",zu=`${Di}, (pointer: coarse)`,nl=`
|
|
731
|
+
`)),l=Ge(s,c=>n?Xt(c,n,r):c),d=et(e.type),p=Bi[d]||o("desc-fg"),a=d==="序"||d==="结语"||d==="注释";return t.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:o("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${p}40`:void 0,background:a?o("bg"):void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:d}),l]})}function Nd(e,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var c;if(!n||e.length===0)return;let l=!1;const d=e.filter(u=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.has(u))}),p={};for(const u of e)(c=i==null?void 0:i.current)!=null&&c.has(u)&&(p[u]=i.current.get(u));if(Object.keys(p).length>0&&s(p),d.length===0)return;const a=async u=>{var g;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const x=await n.getItem(u);if(!x)return null;const m=x.title||u,b=x.authors,S=(g=b==null?void 0:b[0])==null?void 0:g.name;return{title:m,author:S}}catch{return null}};return Promise.all(d.map(async u=>{var x;const g=await a(u);return(x=i==null?void 0:i.current)==null||x.set(u,g),[u,g]})).then(u=>{l||s(g=>{const x={...g};for(const[m,b]of u)x[m]=b;return x})}),()=>{l=!0}},[e.join(","),n]),r}function Ld({section:e,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:l}=Y(),d=Pe(),p=jt(),a=y=>y?Ge(l(y),j=>s?Xt(j,s,p):j):"",[c,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const g=et(e.type),x=wd[g]||o("desc-fg"),m=!!e.content,b=e.work_ids||[],S=b.length>1,h=Nd(S?b:[],i,r),v=m&&!c&&e.content.length>80?ns(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${o("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>m&&u(!c),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:m?"pointer":"default",userSelect:"none"},children:[t.jsxs(Ai,{enabled:m,expanded:c,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[m&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:o("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:o("fg"),lineHeight:1.6},children:e.header_line?a(e.header_line):a(e.title)}),!c&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:o("desc-fg"),lineHeight:1.7},children:a(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:d(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&t.jsxs("span",{style:{fontSize:"11px",color:o("link-fg"),flexShrink:0},children:[b.length,"部作品"]}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:g})]})]}),S&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const j=h[y],_=j?`${l(j.title)}${j.author?`(${l(j.author)})`:""}`:y.slice(0,8)+"…";return t.jsxs("a",{href:d(y),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(y))},style:{fontSize:"12px",color:o("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),c&&m&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:o("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:o("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${o("widget-border")}`,fontSize:"12px",color:o("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:a(e.comment)})]})]})}function Bd({juan:e,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const l=jt(),d=n.trim(),p=f.useMemo(()=>d?e.sections.filter(a=>Li(a,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:p.map((a,c)=>t.jsx(Ld,{section:a,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:d},c))}),p.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:"无匹配结果"})]})}function Ad(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Wd({sections:e,onNavigate:n,inline:i}){const r=Pe(),{convert:s}=Y(),l=Ad();return t.jsx(t.Fragment,{children:e.map((d,p)=>{const a=et(d.type);if(a==="page_header"&&!Wi(d))return null;if(a==="类")return t.jsxs(f.Fragment,{children:[f.createElement(l("类"),null,i(s(d.title))),d.content&&t.jsx("p",{children:i(s(d.content))})]},p);if(a==="书"||a==="诗"||a==="考证"||a==="注释"){const c=d.book_title?`《${d.book_title}》${d.n_juan!=null?Ni(d.n_juan)+"卷":""}`:d.title,u=i(s(c));return t.jsxs("section",{className:"bim-rd-entry",children:[f.createElement(l("条目"),{className:"bim-rd-entry-h"},d.work_id&&n?t.jsx("a",{href:r(d.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),n(d.work_id))},title:"查看作品",children:u}):u),d.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(s(d.author_info))}),d.content&&d.content.split(/\n+/).map((g,x)=>t.jsx("p",{children:i(s(g))},x)),d.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"提要"}),i(s(d.summary))]}),d.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"按語"}),i(s(d.comment))]}),d.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:"附按"}),i(s(d.additional_comment))]})]},p)}return d.content?t.jsx("p",{children:i(s(d.content))},p):null})})}function Md(e){return e.some(n=>{const i=et(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Wi(n)})}function Fd({juan:e,rawText:n,positionLabel:i,index:r,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p,prefs:a}){var M;const{convert:c}=Y(),u=jt(),[g,x]=f.useState("text"),m=s.trim(),b=(r==null?void 0:r.type)==="kaozhen",S=f.useCallback(W=>m?Xt(W,m,u):W,[m,u]),h=W=>Ei(W,{renderText:S,properNames:a.properNames}),v=f.useMemo(()=>m?e.sections.filter(W=>Li(W,m,b,u)):e.sections,[e.sections,m,b,u]),y=(W,P)=>P.filter(V=>et(V.type)===W).length,j=y("书",e.sections),_=y("诗",e.sections),k=y("考证",e.sections);let z="";b?z=m?`${y("考证",v)} / ${k} ${c("條")}`:`${k} ${c("條")}`:_>0?z=m?`${y("诗",v)} / ${_} 首`:`${_} 首`:j>0&&(z=m?`${y("书",v)} / ${j} ${c("部書")}`:`${j} ${c("部書")}`);const w=r!=null&&r.text_quality?fd(r.text_quality.grade):null,C=[];i&&C.push(i),z&&C.push(z),b&&(r!=null&&r.target_source)&&C.push(t.jsxs(t.Fragment,{children:[c("考證對象")," ",c(r.target_source)]})),w&&C.push(t.jsx("span",{title:Rl[w],children:(M=r==null?void 0:r.text_quality)!=null&&M.source_note?t.jsxs(t.Fragment,{children:["底本 ",c(r.text_quality.source_note),"(",c(Dn[w]),")"]}):t.jsxs(t.Fragment,{children:[c("文本質量")," ",c(Dn[w])]})})),e.source_url&&C.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:c("原文來源")}));const E=!b&&Md(e.sections),R=!!n&&(!E||a.readingMode==="paragraph"&&wn(n)),T=!b&&(E||!!n),O=b||!T?"entries":g;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:c(e.title)}),C.length>0&&t.jsx("p",{className:"bim-rd-meta",children:C.map((W,P)=>t.jsxs(f.Fragment,{children:[P>0&&t.jsx("span",{className:"bim-rd-dot"}),W]},P))}),T&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":"看法",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="text",onClick:()=>x("text"),children:"正文"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":O==="entries",onClick:()=>x("entries"),children:c("條目")})]})]}),O==="text"&&t.jsx("article",{className:"bim-rd-prose",children:R?t.jsx(Ri,{text:n,mode:a.readingMode,properNames:a.properNames,renderText:S,dropTitle:e.title}):t.jsx(Wd,{sections:e.sections,onNavigate:l,inline:h})}),O==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:b?t.jsx(Bd,{juan:e,searchQuery:s,onNavigate:l,transport:d,workLabelCache:p}):t.jsxs(t.Fragment,{children:[v.map((W,P)=>{const V=et(W.type);return V==="书"||V==="诗"||V==="考证"?t.jsx(Id,{section:W,onNavigate:l,highlightQuery:m},P):V==="类"?t.jsx(Td,{section:W,highlightQuery:m},P):t.jsx(Rd,{section:W,highlightQuery:m},P)}),v.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:"无匹配结果"})]})})]})}function Rs(e){return e.juan_files&&e.juan_files.length>0?e.juan_files:e.files&&e.files.length>0?e.files.map(n=>n.filename):[]}function Pd(e){const n=Rs(e);return n.length>0?n[0]:null}function Od(e){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:l,activeRawText:d,query:p,isKaozhen:a}=e,c=jt(),u=f.useRef(new Map),[g,x]=f.useState({}),[m,b]=f.useState({}),S=f.useCallback((v,y)=>{const j=y==null?void 0:y.title;j&&b(_=>_[v]===j?_:{..._,[v]:j})},[]);f.useEffect(()=>{s&&l&&(u.current.set(s,{juan:l,rawText:d}),S(s,l))},[s,l,d,S]),f.useEffect(()=>{u.current.clear(),x({}),b({})},[n]);const h=f.useCallback((v,y)=>{let j=0;if(v.juan)for(const _ of v.juan.sections)Li(_,y,a,c)&&j++;return j===0&&v.rawText&&Sd(v.rawText,y,c)&&(j=1),j},[a,c]);return f.useEffect(()=>{const v=p.trim();if(!v){x({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const j={},_=[];for(const E of r){const R=u.current.get(E);R?j[E]=h(R,v):(j[E]="loading",_.push(E))}x(j);const k=8;let z=0;const w=async()=>{var E;for(;z<_.length;){if(y)return;const R=z++,T=_[R];try{const[O,M]=await Promise.all([i.getCollatedJuan(n,T),((E=i.getCollatedJuanText)==null?void 0:E.call(i,n,T))??Promise.resolve(null)]),W={juan:O,rawText:M};if(u.current.set(T,W),S(T,O),y)return;x(P=>({...P,[T]:h(W,v)}))}catch{if(y)return;x(O=>({...O,[T]:0}))}}},C=Array.from({length:Math.min(k,_.length)},()=>w());return Promise.all(C),()=>{y=!0}},[p,n,i,r.join(","),h,c,S]),{matchStates:g,titles:m}}const Mi=({index:e,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:l,className:d,style:p,title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m})=>{const[b,S]=f.useState(null),[h,v]=f.useState(!1),[y,j]=f.useState(null),[_,k]=f.useState(null),[z,w]=f.useState(null),[C,E]=f.useState(!1),[R,T]=f.useState(null),[O,M]=f.useState(""),W=f.useRef(new Map),P=f.useRef(0),V=s??_,K=f.useCallback(H=>{k(H),l==null||l(H)},[l]),N=e||b;f.useEffect(()=>{e&&(v(!1),j(null))},[e]),f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollatedEditionIndex))return;let H=!1;return v(!0),j(null),i.getCollatedEditionIndex(n).then(te=>{H||(te?S(te):j("未找到整理本数据"))}).catch(te=>{H||j(te instanceof Error?te.message:"加载失败")}).finally(()=>{H||v(!1)}),()=>{H=!0}},[e,n,i]),f.useEffect(()=>{if(N&&!V){const H=Pd(N);H&&K(H)}},[N,V,K]);const le=n||(N==null?void 0:N.work_id),G=f.useCallback(async H=>{var pe;if(!le||!(i!=null&&i.getCollatedJuan))return;const te=++P.current;E(!0),w(null),T(null);try{const[re,ee]=await Promise.all([i.getCollatedJuan(le,H),((pe=i.getCollatedJuanText)==null?void 0:pe.call(i,le,H))??Promise.resolve(null)]);if(te!==P.current)return;w(re),T(ee)}catch{if(te!==P.current)return;w(null),T(null)}finally{te===P.current&&E(!1)}},[le,i]);f.useEffect(()=>{V&&G(V)},[V,G]);const se=H=>{K(H)};if(h)return t.jsx("div",{className:d,style:{...p,padding:"24px"},children:t.jsx("div",{style:{color:o("desc-fg"),fontSize:"13px"},children:"加载整理本..."})});if(y)return t.jsx("div",{className:d,style:{...p,padding:"24px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:y});if(!N)return null;const ne=N.type==="kaozhen",Q=Rs(N);return t.jsx(Hd,{className:d,style:p,index:N,allFiles:Q,isKaozhen:ne,effectiveWorkId:le,transport:i,activeFile:V,handleSelectFile:se,juanData:z,juanRawText:R,juanLoading:C,searchQuery:O,setSearchQuery:M,onNavigate:r,workLabelCacheRef:W,reader:{title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m}})};function Ns(e,n,i,r){var c,u,g,x;const s=(u=(c=n.juan_metadata)==null?void 0:c[e])==null?void 0:u.vol_label,l=r(s?`${s}冊`:_d(e)),p=((x=(g=n.files)==null?void 0:g.find(m=>m.filename===e))==null?void 0:x.title)??i[e];if(!p)return{position:l,label:l};const a=r(p);return{position:l,label:l===p||l===a?a:`${l} ${a}`}}function Dd(e,n,i,r,s){const l=a=>a==="loading"?"…":typeof a=="number"&&a>0?a:void 0,d=(a,c)=>({key:a,label:c??Ns(a,e,r,s).label,hint:l(i[a]),disabled:i[a]===0}),p=(a,c)=>{var g;if(a.files.length===1&&!((g=a.children)!=null&&g.length))return d(a.files[0],s(a.label));const u=$d(a,i);return{key:`group:${c}`,label:s(a.label),hint:u==="loading"?"…":typeof u=="number"&&u>0?`${u}`:Es(a),defaultExpanded:typeof u=="number"&&u>0,children:[...a.files.map(x=>d(x)),...(a.children??[]).map((x,m)=>p(x,`${c}.${m}`))]}};return e.juan_groups&&e.juan_groups.length>0?e.juan_groups.map((a,c)=>p(a,`${c}`)):n.map(a=>d(a))}const Hd=({className:e,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:l,transport:d,activeFile:p,handleSelectFile:a,juanData:c,juanRawText:u,juanLoading:g,searchQuery:x,setSearchQuery:m,onNavigate:b,workLabelCacheRef:S,reader:h})=>{const{convert:v}=Y(),[y,j]=_i(),{matchStates:_,titles:k}=Od({workId:l,transport:d,files:r,activeFile:p,activeJuan:c,activeRawText:u,query:x,isKaozhen:s}),z=Ts(h.resolveImages,p),w=f.useMemo(()=>Dd(i,r,_,k,v),[i,r,_,k,v]),C=t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:s?"搜索全部章节…":"搜索全部卷…","aria-label":s?"搜索全部章节":"搜索全部卷",value:x,onChange:T=>m(T.target.value)}),E=s?"章":i.juan_metadata&&Object.values(i.juan_metadata).some(T=>T.vol_label)?"冊":"卷",R=p?Ns(p,i,k,v).position:void 0;return t.jsxs($i,{className:e,style:n,title:h.title??(i.title?v(i.title):void 0),subtitle:h.subtitle??v(s?"考證":"整理本"),toc:w,tocCaption:`目录 · ${r.length} ${v(E)}`,tocHeader:C,activeKey:p,onSelect:a,images:z.images,imagesLoading:z.loading,renderImageOverlay:h.renderImageOverlay,imagePanel:h.imagePanel,prefs:y,onPrefsChange:j,paragraphToggle:!s&&wn(u),allowVertical:h.allowVertical,children:[g?t.jsx(yt,{}):c?t.jsx(Fd,{juan:c,rawText:u,positionLabel:R,index:i,searchQuery:x,onNavigate:b,transport:d,workLabelCache:S,prefs:y},p??""):p?t.jsx("div",{className:"bim-rd-state",children:"无法加载这一卷"}):null,i.references&&i.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:v("參考文獻")}),t.jsx("ol",{children:i.references.map((T,O)=>t.jsxs("li",{children:[T.url?t.jsx("a",{className:"bim-rd-link",href:T.url,target:"_blank",rel:"noopener noreferrer",children:T.title}):t.jsx("span",{children:T.title}),T.author&&t.jsxs("span",{children:[",",T.author]}),T.note&&t.jsxs("span",{children:["。",T.note]})]},O))})]})]})},Gd={bug:{label:"错误反馈",color:o("danger")},resource:{label:"资源建议",color:o("primary")},suggestion:{label:"功能建议",color:o("primary")},other:{label:"其他",color:o("desc-fg")}},Ud={label:"其他",color:o("desc-fg")},Vd={pending:{label:"待处理",color:o("warning")},in_progress:{label:"处理中",color:o("primary")},resolved:{label:"已处理",color:o("success")},wontfix:{label:"不采纳",color:o("desc-fg")},duplicate:{label:"重复",color:o("desc-fg")}},Yd={label:"待处理",color:o("warning")};function Kd(e){try{const n=new Date(e),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function qd(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Fi=({items:e,loading:n})=>{const i=Pe();return n?t.jsx(yt,{}):e.length===0?t.jsx("div",{style:Jd,children:"暂无反馈"}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(r=>{const s=Gd[r.type]||Ud,l=Vd[r.status]||Yd,d=typeof window<"u"&&qd(r.pageUrl,window.location.href);return t.jsxs("div",{style:Zd,children:[t.jsxs("div",{style:Xd,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ro,background:s.color},children:s.label}),t.jsx("span",{style:{...Ro,background:l.color},children:l.label})]}),t.jsx("span",{style:Qd,children:Kd(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&t.jsxs("div",{style:ep,children:[r.resourceId&&t.jsx("a",{href:i(r.resourceId),style:Ln,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(d?t.jsx("a",{href:r.pageUrl,style:Ln,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Ln,children:r.pageUrl}))]}),t.jsx("div",{style:tp,children:r.content}),r.reply&&t.jsxs("div",{style:np,children:[t.jsx("div",{style:ip,children:"回复"}),t.jsx("div",{children:r.reply})]})]},r.id)})})},Jd={textAlign:"center",padding:"40px 0",color:o("desc-fg"),fontSize:"14px"},Zd={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"16px"},Xd={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ro={fontSize:"12px",color:o("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Qd={fontSize:"12px",color:o("desc-fg")},ep={fontSize:"12px",marginBottom:"6px"},Ln={color:o("primary"),textDecoration:"none",borderBottom:`1px dashed ${o("primary")}`},tp={fontSize:"14px",lineHeight:"1.6",color:o("fg"),whiteSpace:"pre-wrap"},np={marginTop:"12px",padding:"10px 12px",background:o("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:o("fg")},ip={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:o("primary")},ei=({transport:e,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:l})=>{const d=de(),[p,a]=f.useState(null),[c,u]=f.useState([]),[g,x]=f.useState("recommend"),[m,b]=f.useState([]),[S,h]=f.useState(!1),v=r??g,y=P=>{x(P),s==null||s(P)},[j,_]=f.useState(!0),[k,z]=f.useState(null),[w,C]=f.useState(null),[E,R]=f.useState(null);f.useEffect(()=>{let P=!1;if(e.getCounts)return e.getCounts().then(V=>{P||a({works:V.works,books:V.books,collections:V.collections})}).catch(()=>{}),()=>{P=!0}},[e]),f.useEffect(()=>{let P=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const K=await e.getRecommended();if(K!=null&&K.groups)return K.groups.flatMap(N=>N.items.map(le=>({...le,group:N.name})))}catch{}return[]})().then(async K=>{if(P)return;const N=K.filter(G=>G.id);if(N.length===0){_(!1);return}const le=await Promise.all(N.map(async G=>{if(G.type)return{id:G.id,title:G.title,type:G.type,author:G.author,dynasty:G.dynasty,role:G.role,edition:G.edition,has_text:G.has_text,has_image:G.has_image,has_collated:G.has_collated,subtype:G.subtype,primary_name:G.primary_name,group:G.group,fallbackDescription:G.description};try{let se=null;if(e.getEntry)se=await e.getEntry(G.id);else{const ne=await e.getItem(G.id);ne&&(se={id:G.id,title:ne.title||G.id,type:ne.type||"work"})}if(se)return{...se,group:G.group,fallbackDescription:G.description}}catch{}return{id:G.id,title:G.title,type:be.extractType(G.id),group:G.group,fallbackDescription:G.description}}));P||(u(le.filter(G=>G!==null)),_(!1))}),()=>{P=!0}},[e,i]);const T=f.useRef(!1),O=f.useRef(!1),M=f.useRef(!1);f.useEffect(()=>{if(v!=="catalog"||T.current)return;const P=e.getCatalogProgress??e.getResourceProgress;if(!P)return;T.current=!0;let V=!1;return P.call(e).then(K=>{V||z(K)}).catch(()=>{T.current=!1}),()=>{V=!0}},[e,v]),f.useEffect(()=>{if(v!=="collection"||O.current||!e.getCollectionProgress)return;O.current=!0;let P=!1;return e.getCollectionProgress().then(V=>{P||C(V)}).catch(()=>{O.current=!1}),()=>{P=!0}},[e,v]),f.useEffect(()=>{if(v!=="site"||M.current||!e.getSiteProgress)return;M.current=!0;let P=!1;return e.getSiteProgress().then(V=>{P||R(V)}).catch(()=>{M.current=!1}),()=>{P=!0}},[e,v]),f.useEffect(()=>{if(!l||v!=="feedback")return;let P=!1;return h(!0),fetch(l).then(V=>V.json()).then(V=>{!P&&V.success&&b(V.items||[])}).catch(()=>{}).finally(()=>{P||h(!1)}),()=>{P=!0}},[l,v]);const W=P=>{switch(P){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:o("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${o("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Mt,{label:d.home.recommendTab,active:v==="recommend",onClick:()=>y("recommend")}),t.jsx(Mt,{label:d.home.catalogTab,active:v==="catalog",onClick:()=>y("catalog")}),t.jsx(Mt,{label:d.home.collectionTab,active:v==="collection",onClick:()=>y("collection")}),t.jsx(Mt,{label:d.home.siteTab,active:v==="site",onClick:()=>y("site")}),l&&t.jsx(Mt,{label:d.home.feedbackTab,active:v==="feedback",onClick:()=>y("feedback")})]}),v==="recommend"&&t.jsx(op,{recommended:c,loading:j,onNavigate:n,getIcon:W,t:d}),v==="catalog"&&t.jsx(No,{progress:k,t:d,onNavigate:n}),v==="collection"&&t.jsx(No,{progress:w,t:d,onNavigate:n}),v==="site"&&t.jsx(sp,{progress:E,t:d,totalWorks:(p==null?void 0:p.works)??0}),v==="feedback"&&l&&t.jsx(Fi,{items:m,loading:S})]})})},Mt=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:o(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${o("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),op=({recommended:e,loading:n,onNavigate:i,getIcon:r,t:s})=>{const l=Pe();if(n)return t.jsx(yt,{});if(e.length===0)return null;const d=new Map;for(const p of e){const a=p.group||s.home.recommendedBrowse;d.has(a)||d.set(a,[]),d.get(a).push(p)}return t.jsx(t.Fragment,{children:Array.from(d.entries()).map(([p,a])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:p}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(c=>{const u=c.dynasty||c.author?`${c.dynasty?`〔${c.dynasty}〕`:""}${c.author||""}`:c.fallbackDescription;return t.jsxs("a",{href:l(c.id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(c.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,cursor:"pointer",background:o("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(c.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c.title,c.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:c.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},c.id)})})]},p))})},No=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((p,a)=>p.priority-a.priority),s=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},d={in_progress:o("progress-active"),done:o("progress-done"),todo:o("progress-todo")};return t.jsx("div",{children:s.map(p=>{const a=r.filter(c=>c.status===p);return a.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:d[p]}}),l[p]," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(rp,{item:c,t:n,statusColor:d[p],onNavigate:i},c.id))})]},p)})})},rp=({item:e,t:n,statusColor:i,onNavigate:r})=>{const s=Pe(),l=e.total>0?Math.round(e.imported/e.total*100):0,d=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const p=e.edition?`${e.name}·${e.edition}`:e.name,a=e.collection_id||e.work_id;return a&&r?t.jsx("a",{href:s(a),onClick:c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},onMouseEnter:c=>c.currentTarget.style.borderBottomStyle="solid",onMouseLeave:c=>c.currentTarget.style.borderBottomStyle="dashed",children:p}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:p}):p})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:o("widget-border"),color:o("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:d})]}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?Yt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},sp=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(yt,{});const r=[...e.resources].sort((a,c)=>a.priority-c.priority),s=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),d=s.reduce((a,c)=>Math.max(a,c.imported),0),p=i>0?Math.round(d/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${o("primary")} 6%, transparent)`,fontSize:"13px",color:o("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:d.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",p,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>t.jsx(Lo,{item:a,t:n,totalWorks:i},a.id))})]}),l.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:o("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:o("progress-todo")}}),n.home.statusTodo," (",l.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>t.jsx(Lo,{item:a,t:n,totalWorks:i},a.id))})]})]})},Lo=({item:e,t:n,totalWorks:i})=>{const r=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${o("widget-border")}`,background:o("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:o("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:o("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:o("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:o("desc-fg"),marginTop:"4px"},children:e.description})]})},Bo="(max-width: 768px)";function lp(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Bo).matches);return f.useEffect(()=>{const i=window.matchMedia(Bo),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),e}const ap=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var V;const l=de(),{convert:d}=Y(),p=lp(),[a,c]=f.useState(null),[u,g]=f.useState(null),[x,m]=f.useState(!1),[b,S]=f.useState("detail"),[h,v]=f.useState([]),[y,j]=f.useState(!1),[_,k]=f.useState(null),[z,w]=f.useState(!1),C=f.useCallback(async K=>{if(!e.getCollatedEditionIndex){k(null);return}w(!0);try{const N=await e.getCollatedEditionIndex(K);k(N)}catch{k(null)}finally{w(!1)}},[e]),E=f.useCallback(async K=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){v([]);return}j(!0);try{if(e.getCollectionCatalogs){const N=await e.getCollectionCatalogs(K);v(N||[])}else if(e.getCollectionCatalog){const N=await e.getCollectionCatalog(K);v(N?[{resource_id:"",data:N}]:[])}}catch{v([])}finally{j(!1)}},[e]),R=f.useCallback(async K=>{if(i){i(K);return}c(K),g(null),v([]),k(null),S("detail"),m(!0);try{const N=await e.getItem(K.id);N&&(g(N),N.type==="collection"?E(K.id):N.type==="work"&&N.has_collated&&C(K.id))}catch(N){console.error("加载详情失败:",N)}finally{m(!1)}},[e,i,E,C]),T=f.useCallback(async K=>{g(null),v([]),k(null),S("detail"),m(!0);try{const N=await e.getItem(K);N&&(g(N),c({id:K,title:N.title||K,type:N.type||"book"}),N.type==="collection"?E(K):N.type==="work"&&N.has_collated&&C(K))}catch(N){console.error("导航失败:",N)}finally{m(!1)}},[e,E,C]),O=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(_||z),M=p&&(x||u),W=f.useCallback(()=>{c(null),g(null),v([]),k(null),S("detail")},[]),P=t.jsx(t.Fragment,{children:x?t.jsx(yt,{}):u?t.jsxs(t.Fragment,{children:[(O||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${o("widget-border")}`,padding:p?"0 12px":"0 48px",background:o("input-bg"),flexShrink:0,overflowX:p?"auto":void 0},children:[O&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>S("detail"),style:an(b==="detail"),children:l.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&t.jsxs("button",{onClick:()=>{},style:an(!1),children:[l.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(K=>t.jsx("button",{onClick:()=>S(`catalog:${K.resource_id}`),style:an(b===`catalog:${K.resource_id}`),children:K.short_name?`${d(K.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},K.resource_id)),u.type==="work"&&(_||z)&&t.jsxs("button",{onClick:()=>S("collated"),style:an(b==="collated"),children:[l.detailTab.collatedEdition,z&&t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:p?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?t.jsx(xi,{data:u,transport:e,onNavigate:T}):b.startsWith("catalog:")?t.jsx(fi,{data:(V=h.find(K=>`catalog:${K.resource_id}`===b))==null?void 0:V.data,onNavigate:T}):b==="collated"?t.jsx(Mi,{index:_||void 0,workId:u.id,transport:e,onNavigate:T}):null})]}):t.jsx(ei,{transport:e,onNavigate:T,recommendedIds:r})});return p?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${o("widget-border")}`,background:o("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:W,style:{padding:"4px 12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:P})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Gn,{transport:e,onEntryClick:R,hideModeIndicator:n}),!u&&t.jsx(ei,{transport:e,onNavigate:T,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:o("bg"),color:o("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${o("widget-border")}`,display:"flex",flexDirection:"column",background:o("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(Gn,{transport:e,onEntryClick:R,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:o("bg"),display:"flex",flexDirection:"column"},children:P})]})};function an(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function dt(e){return e.replace(/\.md$/,"")}function Ao(e){let n="";if(e.source_url)try{const r=new URL(e.source_url).pathname.split("/").filter(Boolean).pop()??"";n=decodeURIComponent(r).replace(/_/g," ")}catch{}return[e.source_name,n||e.version_label].filter(Boolean).join(" · ")||e.key}const Wo={padding:24,color:o("desc-fg")},ti=({index:e,bookId:n,transport:i,activeChapter:r,onChapterChange:s,workKey:l,versions:d,onVersionChange:p,title:a,subtitle:c,resolveImages:u,renderImageOverlay:g,imagePanel:x,allowVertical:m,className:b,style:S})=>{const[h,v]=f.useState(e??null),[y,j]=f.useState(!1),[_,k]=f.useState(null),z=r!==void 0?r:_,w=f.useCallback(Q=>{s?s(Q):k(Q)},[s]),[C,E]=f.useState(null),[R,T]=f.useState(!1);f.useEffect(()=>{e&&v(e)},[e]),f.useEffect(()=>{if(e)return;v(null),j(!1);const Q=l!==void 0?i.getWorkFullTextIndex?()=>i.getWorkFullTextIndex(n,l):null:i.getBookFullTextIndex?()=>i.getBookFullTextIndex(n):null;if(!n||!Q){j(!0);return}let H=!1;return Promise.resolve().then(Q).then(te=>{H||(te?v(te):j(!0))}).catch(()=>{H||j(!0)}),()=>{H=!0}},[n,i,e,l]),f.useEffect(()=>{if(!h||h.chapters.length===0)return;const Q=dt(h.chapters[0].file);if(!z){w(Q);return}const H=dt(z);h.chapters.some(pe=>dt(pe.file)===H)||w(Q)},[h,z,w]);const O=f.useMemo(()=>{if(!h||!z)return null;const Q=dt(z);return h.chapters.find(H=>dt(H.file)===Q)??null},[h,z]);f.useEffect(()=>{if(!n||!O)return;const Q=l!==void 0?i.getWorkFullTextChapter?te=>i.getWorkFullTextChapter(n,l,te):null:i.getBookFullTextChapter?te=>i.getBookFullTextChapter(n,te):null;if(!Q)return;let H=!1;return T(!0),E(null),Promise.resolve(O.file).then(Q).then(te=>{H||E(te)}).catch(()=>{H||E(null)}).finally(()=>{H||T(!1)}),()=>{H=!0}},[n,O,i,l]);const M=Ts(u,O?dt(O.file):null),[W,P]=_i(),{convert:V}=Y(),K=!!(d&&d.length>1&&p),N=f.useMemo(()=>K?gs(d).map((Q,H)=>({...Q,label:Ao(d[H])})):void 0,[K,d]),le=K?t.jsxs("label",{children:["版本:",t.jsx("select",{value:l,onChange:Q=>p(Q.target.value),children:d.map(Q=>t.jsx("option",{value:Q.key,children:Ao(Q)},Q.key))})]}):null;if(!h)return t.jsxs("div",{style:Wo,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),y?"无法加载全文目录":"加载全文目录…"]});if(h.chapters.length===0)return t.jsxs("div",{style:Wo,children:[le&&t.jsx("div",{style:{marginBottom:12},children:le}),"全文目录为空"]});const G=h.chapters.map(Q=>({key:dt(Q.file),label:V(Q.title)})),se=ys(h)||Yn(h),ne=C?C.replace(/^##\s+[^\n]+\n+/,""):null;return t.jsxs($i,{title:a??V(h.version_label),subtitle:c??"全文",toc:G,tocCaption:`目录 · ${h.chapters.length} ${h.chapters.length>1?"卷":"篇"}`,activeKey:z?dt(z):null,onSelect:w,images:M.images,imagesLoading:M.loading,renderImageOverlay:g,imagePanel:x,prefs:W,onPrefsChange:P,versions:N,currentVersionKey:N?l??null:void 0,onVersionChange:N?p:void 0,versionSource:!1,paragraphToggle:wn(ne),allowVertical:m,className:b,style:S,children:[O&&t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:V(O.title)}),t.jsxs("p",{className:"bim-rd-meta",children:["来源 ",t.jsx("a",{className:"bim-rd-link",href:h.source.url,target:"_blank",rel:"noreferrer",children:V(h.source.name)}),h.source.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),h.source.license]})]})]}),R&&t.jsx("div",{className:"bim-rd-state",children:"加载中…"}),!R&&ne!=null&&t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Ri,{text:ne,mode:W.readingMode,tables:se,gujiMarkdown:Yn(h),properNames:W.properNames})}),!R&&!C&&t.jsx("div",{className:"bim-rd-state",children:"无法加载章节内容"})]})},cp=({data:e,onNavigate:n,className:i,style:r})=>{var u;const s=de(),{convert:l}=Y(),[d,p]=f.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[a,c]=f.useState(null);return t.jsxs("div",{className:i,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:o("fg"),margin:"0 0 8px"},children:l(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:o("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s.catalog.totalVolumes," ",t.jsx("strong",{children:e.total_volumes})," ",s.unit.juan]}),e.stats.zhulu!=null&&t.jsxs("span",{children:["著錄 ",t.jsx("strong",{children:e.stats.zhulu})," ",s.unit.bu]}),e.stats.cunmu!=null&&t.jsxs("span",{children:["存目 ",t.jsx("strong",{children:e.stats.cunmu})," ",s.unit.bu]}),e.stats.categories!=null&&t.jsxs("span",{children:[e.stats.categories," 類"]})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(g=>t.jsx(dp,{division:g,expanded:d===g.name,onToggle:()=>p(d===g.name?null:g.name),expandedCat:a,onCatToggle:x=>c(a===x?null:x),onNavigate:n},g.name))})]})},dp=({division:e,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:l})=>{const{convert:d}=Y(),p=e.categories.reduce((a,c)=>{const u=c.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.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, ${o("primary")} 6%, transparent)`:o("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:o("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:o("desc-fg")},children:[e.categories.length," 類 · ",p," 部",t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(a=>{const c=`${e.name}/${a.name}`;return t.jsx(pp,{category:a,expanded:r===c,onToggle:()=>s(c),onNavigate:l},a.name)})})]})},pp=({category:e,expanded:n,onToggle:i,onNavigate:r})=>{var a,c,u,g;const{convert:s}=Y(),l=((a=e.books)==null?void 0:a.zhulu)||[],d=((c=e.books)==null?void 0:c.cunmu)||[],p=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?o("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:o("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[s(e.name),e.volumes&&t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg"),marginLeft:"8px",fontWeight:400},children:["卷",e.volumes]})]}),t.jsxs("span",{style:{fontSize:"11px",color:o("desc-fg")},children:[p," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Mo,{label:"著錄",books:l,onNavigate:r}),d.length>0&&t.jsx(Mo,{label:"存目",books:d,onNavigate:r})]})]})},Mo=({label:e,books:n,onNavigate:i})=>{const{convert:r}=Y(),s=Pe(),[l,d]=f.useState(n.length<=20),p=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:p.map((a,c)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:o("fg")},children:a.work_id&&i?t.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${o("link-fg")}`},children:r(a.title)}):r(a.title)}),a.volumes&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.volumes)}),a.author&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:r(a.author).slice(0,20)})]},c))}),!l&&t.jsxs("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:o("primary"),background:"transparent",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Ye=({title:e,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const l=de();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:o("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&t.jsx("button",{onClick:i,style:xp,children:"AI"}),n&&t.jsx("button",{onClick:n,style:up,children:l.action.save})]})]}),s]})},up={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},xp={padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},He=({label:e,value:n,onChange:i,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:l=>i(l.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),ht=({value:e,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},gn=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||o("primary-soft"),color:o(n?"on-color-fg":"fg"),...i},children:e});function fp(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const dn=({value:e,onChange:n,label:i})=>{const[r,s]=f.useState(!1),l=f.useRef(null),d=fp(e||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&d?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Fo,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${o("input-border")}`,borderRadius:"2px",background:o("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:o("fg")},children:d.name}),t.jsx(gn,{children:d.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Fo,children:i}),t.jsx("input",{ref:l,type:"text",value:e||"",onChange:p=>n(p.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Fo={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500};function gp(e){switch(e){case"url":return o("source-url");case"bookID":return o("source-bookid");default:return o("desc-fg")}}function mp(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ls=({items:e,onChange:n,onOpenEntityPicker:i})=>{const r=de(),[s,l]=f.useState(null),d=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(e.length)},p=g=>{n(e.filter((x,m)=>m!==g)),s===g&&l(null)},a=(g,x,m)=>{const b=[...e];b[g]={...b[g],[x]:m},n(b)},c=(g,x)=>{const m=[...e];m[g]={...m[g],type:x,id:"",name:""},n(m),x==="bookID"&&i&&i(b=>{const S=[...e];S[g]={...S[g],id:b.id,name:b.title,type:"bookID"},n(S)})},u=g=>{i&&i(x=>{const m=[...e];m[g]={...m[g],id:x.id,name:x.title,type:"bookID"},n(m)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,x)=>t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:o("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(s===x?null:x),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===x?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:o("fg")},children:g.name||`${r.editor.sourcePlaceholder} ${x+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:gp(g.type),color:o("on-color-fg"),borderRadius:"3px",fontWeight:500},children:mp(g.type)}),t.jsx("button",{onClick:m=>{m.stopPropagation(),p(x)},style:{background:"transparent",border:"none",color:o("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===x&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${o("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>c(x,"bookID"),style:{...Po,borderColor:o("source-bookid"),color:o("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>c(x,"url"),style:{...Po,borderColor:o("source-url"),color:o("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),g.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:nt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Oo,children:r.action.changeType})]}),g.id&&g.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:o("bg"),border:`1px solid ${o("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:o("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:g.name}),t.jsx("code",{style:{fontSize:"11px",background:o("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>u(x),style:{background:"transparent",border:`1px solid ${o("widget-border")}`,color:o("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(x),style:{width:"100%",padding:"14px",border:`2px dashed ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),g.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:nt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const m=[...e];m[x]={...m[x],type:"",id:"",name:""},n(m)},style:Oo,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:m=>a(x,"name",m.target.value),placeholder:r.editor.sourceNamePlaceholder,style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:m=>a(x,"id",m.target.value),placeholder:"https://...",style:vt})]})]}),g.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${o("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...nt,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:m=>a(x,"details",m.target.value),placeholder:r.editor.detailsPlaceholder,style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:m=>a(x,"position",m.target.value),placeholder:"如: 卷三, p.52",style:vt})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:m=>a(x,"version",m.target.value),placeholder:"如: v1.0, 2024-01",style:vt})]}),t.jsxs("div",{children:[t.jsx("label",{style:nt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:m=>a(x,"processor_version",m.target.value),placeholder:"如: v0.1",style:vt})]})]})]})]})})]},x)),t.jsxs("button",{onClick:d,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},nt={display:"block",fontSize:"11px",color:o("desc-fg"),marginBottom:"4px",fontWeight:500},vt={width:"100%",padding:"6px 8px",background:o("input-bg"),color:o("input-fg"),border:`1px solid ${o("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Po={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:o("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Oo={background:"transparent",border:"none",color:o("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Bs(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);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 As(e){return!e||e.length===0?"":JSON.stringify(e)}const Ws=({entityType:e,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:l,belongsToCollection:d,childWorks:p,childCollections:a,containedBooks:c,siblingBooks:u,onLinkEntity:g,onUnlinkEntity:x,onViewEntity:m,onCreateAndLink:b,onSaveRelations:S})=>{const h=de();return t.jsxs("div",{style:{background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:h.section.relations})]}),S&&t.jsx("button",{onClick:S,style:hp,children:h.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Ft,{direction:"up",title:h.relation.containedInCollection,entity:d,onView:m,onUnlink:()=>x("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&u&&u.length>0&&t.jsx(kt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:m,onAdd:()=>b("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{direction:"up",title:h.relation.parentWork,entity:r,onView:m,onUnlink:()=>x("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),p&&p.length>0&&t.jsx(kt,{direction:"down",title:`${h.relation.childWorks} (${p.length})`,entities:p,onView:m,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),a&&a.length>0&&t.jsx(kt,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:m,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(kt,{direction:"down",title:`${h.relation.allVersions} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Ft,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:m,onUnlink:()=>x("workId"),onLink:()=>g("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(Ft,{direction:"up",title:h.relation.parentCollection,entity:s,onView:m,onUnlink:()=>x("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),t.jsx(kt,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:m,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),t.jsx(kt,{direction:"down",title:`${h.relation.containedBooks} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:m,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Ft=({direction:e,title:n,entity:i,onView:r,onUnlink:s,onLink:l,onCreate:d,linkLabel:p,createLabel:a,notLinkedLabel:c,viewLabel:u,unlinkLabel:g})=>{const x=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:o("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Ms(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Do,{onClick:()=>r(i),title:u,children:"👁️"}),t.jsx(Do,{onClick:s,title:g,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:c}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ni,{onClick:l,children:p}),t.jsx(ni,{onClick:d,primary:!0,children:a})]})]})},kt=({direction:e,title:n,entities:i,onView:r,onAdd:s,addLabel:l,noneLabel:d,expandMoreLabel:p})=>{const[a,c]=f.useState(!1),u=o(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",x=a?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"4px",padding:"10px",background:o("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[x.map(m=>t.jsxs("div",{onClick:()=>r(m),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:o("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Ms(m.type)}),t.jsx("span",{children:m.title})]},m.id)),i.length>5&&!a&&t.jsxs("div",{onClick:()=>c(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:o("link-fg"),cursor:"pointer"},children:[p," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:o("bg"),borderRadius:"4px",color:o("desc-fg"),fontSize:"12px",textAlign:"center"},children:d}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ni,{onClick:s,primary:!0,children:["+ ",l]})})]})},Do=({onClick:e,title:n,danger:i,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?o("danger"):"inherit",opacity:.7},children:r}),ni=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${o("widget-border")}`,borderRadius:"4px",background:n?o("primary"):"transparent",color:n?o("primary-fg"):"inherit",cursor:"pointer"},children:i});function Ms(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const hp={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Fs=({isOpen:e,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:l,searchResults:d,onSearch:p,isLoading:a,excludeId:c})=>{const[u,g]=f.useState(""),x=c?d.filter(h=>h.id!==c):d;f.useEffect(()=>{e&&(g(""),p(""))},[e]);const m=h=>{g(h),p(h)};if(!e)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:bp,children:t.jsxs("div",{style:yp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:jp,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:h=>m(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:vp})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?t.jsx("div",{style:Bn,children:"搜索中..."}):x.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:x.map(h=>t.jsxs("div",{onClick:()=>r(h),style:kp,children:[t.jsx("span",{style:{fontSize:"16px"},children:S}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?t.jsxs("div",{style:Bn,children:["未找到匹配的",b]}):t.jsxs("div",{style:Bn,children:["输入关键词搜索",b]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:l,style:Sp,children:["创建新",b,"并关联"]})]})]})})},bp={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},yp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},jp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},vp={width:"100%",padding:"10px 12px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},kp={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:o("primary-soft")},Bn={padding:"20px",textAlign:"center",color:o("desc-fg")},Sp={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Ho={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},wp={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ps=({isOpen:e,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:l})=>{const[d,p]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{e&&(p((r==null?void 0:r.title)||""),setTimeout(()=>{var x,m;(x=a.current)==null||x.focus(),(m=a.current)==null||m.select()},100))},[e,r==null?void 0:r.title]);const c=x=>{x.key==="Enter"&&d.trim()?u():x.key==="Escape"&&l()},u=()=>{d.trim()&&s(d.trim(),{...r,title:d.trim()})};if(!e)return null;const g=()=>{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`创建新${Ho[n]}`}};return t.jsx("div",{style:_p,onClick:x=>{x.target===x.currentTarget&&l()},children:t.jsxs("div",{style:$p,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:wp[n]}),t.jsx("span",{children:g()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:o("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:o("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:a,type:"text",value:d,onChange:x=>p(x.target.value),onKeyDown:c,placeholder:`请输入${Ho[n]}名称...`,style:zp})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),background:o("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:l,style:Cp,children:"取消"}),t.jsx("button",{onClick:u,disabled:!d.trim(),style:{...Ip,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},_p={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},$p={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:o("shadow-dialog")},zp={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${o("input-border")}`,borderRadius:"4px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box"},Cp={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",color:o("fg"),cursor:"pointer"},Ip={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg")};function Tp(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Os(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ep(e){switch(e){case"work":return o("editor-type-work");case"collection":return o("editor-type-collection");case"book":return o("editor-type-book");default:return o("desc-fg")}}const Ds=({isOpen:e,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:l=!1,createButtonText:d,onSelect:p,onCancel:a,onCreate:c,onSearch:u})=>{const[g,x]=f.useState(""),[m,b]=f.useState([]),[S,h]=f.useState(!1),[v,y]=f.useState("recent");f.useEffect(()=>{e&&(x(""),b([]),y(r.length>0?"recent":"search"))},[e,r.length]),f.useEffect(()=>{if(!g.trim()){b([]);return}const C=setTimeout(async()=>{h(!0);try{b(await u(g,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(C)},[g,i,u]);const j=f.useCallback(C=>{x(C.target.value),C.target.value.trim()&&y("search")},[]),_=f.useCallback(C=>s?C.filter(E=>E.id!==s):C,[s]);if(!e)return null;const k=n||(i==="all"?"选择实体":`选择${Os(i)}`),z=_(r),w=_(m);return t.jsx("div",{style:Np,children:t.jsxs("div",{style:Lp,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:a,style:Bp,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ap}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),z.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${o("widget-border")}`},children:[t.jsxs(Go,{active:v==="recent",onClick:()=>y("recent"),children:["最近使用 (",z.length,")"]}),t.jsxs(Go,{active:v==="search",onClick:()=>y("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&z.length>0?t.jsx(Uo,{entities:z,onSelect:p}):g.trim()?S?t.jsx(An,{message:"搜索中..."}):w.length>0?t.jsx(Uo,{entities:w,onSelect:p}):t.jsx(An,{message:"未找到匹配的结果"}):t.jsx(An,{message:"输入关键词开始搜索"})}),l&&c&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${o("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:c,style:Wp,children:d||"创建新实体"})]})]})})},Go=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${o("primary")}`:"2px solid transparent",background:"transparent",color:o(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),Uo=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Rp,{entity:i,onClick:()=>n(i)},i.id))}),Rp=({entity:e,onClick:n})=>{const[i,r]=f.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Tp(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:o("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:o("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Ep(e.type),color:o("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Os(e.type)})]})},An=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:o("desc-fg"),fontSize:"13px"},children:e}),Np={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:o("shadow-dialog")},Bp={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ap={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),fontSize:"13px",boxSizing:"border-box"},Wp={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:o("primary"),color:o("primary-fg"),cursor:"pointer"},Mp={work:o("editor-type-work"),collection:o("editor-type-collection"),book:o("editor-type-book"),entity:o("editor-type-entity")},Fp={work:"📜",collection:"📚",book:"📖",entity:"👤"},Hs=({data:e,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:l,onDelete:d,onAskAI:p,renderSectionActions:a,onDownloadResource:c,downloadStatuses:u,relations:g,onRelationsChange:x})=>{var q;const m=de(),[b,S]=f.useState(!1),[h,v]=f.useState("work"),[y,j]=f.useState(""),[_,k]=f.useState(""),[z,w]=f.useState([]),[C,E]=f.useState(!1),[R,T]=f.useState(!1),[O,M]=f.useState("work"),[W,P]=f.useState(""),[V,K]=f.useState(),[N,le]=f.useState(!1),[G,se]=f.useState(null),[ne,Q]=f.useState([]);f.useRef(null);const H=e.type,te=H==="work",pe=H==="collection",re=H==="book",ee=f.useCallback((L,I)=>{n({...e,[L]:I})},[e,n]),ye=f.useCallback((L,I)=>{j(L),v(I),k(m.editor.selectToLink+m.indexType[I]),w([]),S(!0)},[m]),ae=f.useCallback(L=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,L)},[r,e.id]),Te=f.useCallback(L=>{s==null||s(L.id,L.type)},[s]),je=f.useCallback((L,I,$)=>{const F={...$,author:($==null?void 0:$.author)||e.author,dynasty:$==null?void 0:$.dynasty};M(I),P(L),K(F),T(!0)},[e.author]),Ce=f.useCallback((L,I)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,W,{type:O,title:L,inheritData:I}),T(!1)},[r,e.id,W,O]),Re=f.useCallback(L=>{if(!L.trim()){w([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(L,h).then(I=>{w(I),E(!1)}).catch(()=>{w([]),E(!1)})},[r,h]),Ie=f.useCallback(L=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,y,L.id),S(!1)},[r,e.id,y]),D=f.useCallback(()=>{i()},[i]),oe=f.useCallback(L=>{se(()=>L),le(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),ie=f.useCallback((L,I)=>r!=null&&r.searchEntities?r.searchEntities(L,I==="all"?void 0:I):Promise.resolve([]),[r]),xe=f.useCallback(L=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(L),Q(I=>[L,...I.filter($=>$.id!==L.id)].slice(0,10)),G==null||G(L),le(!1),se(null)},[r,G]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${o("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Fp[H]}),t.jsx("span",{children:e.title||m.editor.untitled}),t.jsx(gn,{children:e.id}),t.jsx(gn,{color:Mp[H],children:m.indexType[H]})]})}),t.jsx(Ye,{title:m.section.basicInfo,onSave:i,onAskAI:p?()=>p("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(dn,{label:te?m.editor.workTitle:pe?m.editor.collectionTitle:m.editor.bookTitle,value:e.title,onChange:L=>ee("title",L)}),re&&t.jsx(dn,{label:m.editor.belongsToWork,value:e.workName||"",onChange:L=>ee("workName",L)}),t.jsx(He,{label:m.editor.authorLabel,value:e.author||"",onChange:L=>ee("author",L)}),t.jsx(He,{label:m.editor.publicationYearLabel,value:e.publicationYear||"",onChange:L=>ee("publicationYear",L)}),(re||pe)&&t.jsx(dn,{label:m.editor.containedIn,value:e.collection||"",onChange:L=>ee("collection",L)}),(re||pe)&&t.jsx(He,{label:m.editor.holderLabel,value:e.holder||"",onChange:L=>ee("holder",L)}),(re||pe)&&t.jsx(He,{label:re?m.editor.pageLabel:m.editor.volumeLabel,value:e.pages||"",onChange:L=>ee("pages",L)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(He,{label:m.editor.firstImageLabel,value:e.firstImage||"",onChange:L=>ee("firstImage",L)})})]})}),t.jsx(Ye,{title:m.section.description,onSave:i,onAskAI:p?()=>p("介绍"):void 0,children:t.jsx(ht,{value:e.description||"",onChange:L=>ee("description",L),placeholder:m.editor.descriptionPlaceholder})}),(((q=e.additional_works)==null?void 0:q.length)||0)>0&&t.jsx(Ye,{title:m.section.additionalWorks,onSave:i,children:t.jsx(Pp,{items:e.additional_works||[],onChange:L=>ee("additional_works",L)})}),t.jsx(Ye,{title:m.section.indexedBy,onSave:i,onAskAI:p?()=>p("收录于"):void 0,children:t.jsx(Op,{items:e.indexed_by||[],onChange:L=>ee("indexed_by",L)})}),t.jsx(Ye,{title:m.section.emendatedBy,onSave:i,onAskAI:p?()=>p("考证"):void 0,children:t.jsx(Dp,{items:e.emendated_by||[],onChange:L=>ee("emendated_by",L)})}),t.jsx(Ye,{title:m.section.textResources,onSave:i,onAskAI:p?()=>p("资源"):void 0,children:t.jsx(Hn,{items:e.resources||[],onChange:L=>ee("resources",L),onDownload:c,downloadStatuses:u,filterType:"text"})}),t.jsx(Ye,{title:m.section.imageResources,onSave:i,children:t.jsx(Hn,{items:e.resources||[],onChange:L=>ee("resources",L),onDownload:c,downloadStatuses:u,filterType:"image"})}),t.jsx(Ye,{title:m.section.sources,onSave:i,onAskAI:p?()=>p("资料来源"):void 0,children:t.jsx(Ls,{items:Bs(e.sources||""),onChange:L=>ee("sources",As(L)),onOpenEntityPicker:oe})}),(re||pe)&&t.jsx(Ye,{title:m.section.provenance,onSave:i,onAskAI:p?()=>p("收藏历史"):void 0,children:t.jsx(ht,{value:e.provenance||"",onChange:L=>ee("provenance",L),placeholder:m.editor.provenancePlaceholder})}),re&&t.jsx(Ye,{title:m.section.otherEditions,onSave:i,onAskAI:p?()=>p("其他版本"):void 0,children:t.jsx(ht,{value:e.otherEditions||"",onChange:L=>ee("otherEditions",L),placeholder:m.editor.otherEditionsPlaceholder})}),t.jsx(Ws,{entityType:H,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:ye,onUnlinkEntity:ae,onViewEntity:Te,onCreateAndLink:je,onSaveRelations:D}),l&&d&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${o("danger-soft-border")}`,background:o("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:o("danger"),fontWeight:600,marginBottom:"8px"},children:m.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:o("desc-fg"),marginBottom:"12px"},children:m.editor.dangerZoneDesc}),t.jsx("button",{onClick:d,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("danger")}`,borderRadius:"4px",background:"transparent",color:o("danger"),cursor:"pointer"},children:m.editor.deleteEntity})]}),t.jsx(Fs,{isOpen:b,entityType:h,title:_,onSelect:Ie,onCancel:()=>S(!1),onCreate:()=>{S(!1),je(y,h)},searchResults:z,onSearch:Re,isLoading:C,excludeId:e.id}),t.jsx(Ps,{isOpen:R,entityType:O,relationField:W,inheritData:V,onConfirm:Ce,onCancel:()=>T(!1)}),t.jsx(Ds,{isOpen:N,title:m.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:e.id,onSelect:xe,onCancel:()=>{le(!1),se(null)},onSearch:ie})]})};function Pp({items:e,onChange:n}){const i=de(),r=(d,p,a)=>{const c=e.map((u,g)=>g===d?{...u,[p]:a}:u);n(c)},s=d=>n(e.filter((p,a)=>a!==d)),l=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((d,p)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(He,{label:i.editor.bookNameLabel,value:d.book_title,onChange:a=>r(p,"book_title",a)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(He,{label:i.label.juanCount,value:d.n_juan!=null?String(d.n_juan):"",onChange:a=>r(p,"n_juan",a&&parseInt(a,10)||void 0)})}),t.jsx("button",{onClick:()=>s(p),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("muted"),marginTop:"18px"},children:"✕"})]},p)),t.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Gs({items:e,onChange:n,showMeta:i,addLabel:r}){const s=de(),[l,d]=f.useState(null),p=(u,g,x)=>{const m=e.map((b,S)=>S===u?{...b,[g]:x||void 0}:b);n(m)},a=u=>{n(e.filter((g,x)=>x!==u)),l===u&&d(null)},c=()=>{n([...e,{source:""}]),d(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>{const x=l===g;return t.jsxs("div",{style:{border:`1px solid ${o("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:x?`color-mix(in srgb, ${o("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>d(x?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:o("desc-fg"),transition:"transform 0.2s",transform:x?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:o("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:m=>{m.stopPropagation(),a(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${o("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:o("muted")},children:"✕"})]}),!x&&i&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:o("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),x&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(He,{label:s.label.sourceName,value:u.source,onChange:m=>p(g,"source",m)}),t.jsx(He,{label:s.label.sourceBid,value:u.source_bid||"",onChange:m=>p(g,"source_bid",m)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(He,{label:s.label.titleInfo,value:u.title_info||"",onChange:m=>p(g,"title_info",m)}),t.jsx(He,{label:s.label.authorInfo,value:u.author_info||"",onChange:m=>p(g,"author_info",m)})]}),t.jsx(He,{label:s.label.edition,value:u.edition||"",onChange:m=>p(g,"edition",m)})]}),t.jsx(ht,{value:u.summary||"",onChange:m=>p(g,"summary",m),placeholder:s.editor.summaryPlaceholder}),t.jsx(ht,{value:u.comment||"",onChange:m=>p(g,"comment",m),placeholder:s.editor.commentPlaceholder}),t.jsx(ht,{value:u.additional_comment||"",onChange:m=>p(g,"additional_comment",m),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),t.jsx("button",{onClick:c,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${o("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:o("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Op({items:e,onChange:n}){const i=de();return t.jsx(Gs,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Dp({items:e,onChange:n}){const i=de();return t.jsx(Gs,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Us(e){var p,a,c,u,g,x,m;const n=((a=(p=e.authors)==null?void 0:p[0])==null?void 0:a.name)||"",i=((c=e.publication_info)==null?void 0:c.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((x=e.page_count)==null?void 0:x.description)||"",l=typeof e.description=="object"&&e.description!==null&&e.description.text||"",d={id:e.id,title:e.title,type:e.type,author:n,publicationYear:i,holder:r,pages:s,description:l,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const b=e;if(Array.isArray(b.related_works)){const S=b.related_works.find(h=>h.relation==="part_of");S&&(d.parentWorkId=S.id,d.parentWorkName=S.title)}}if(e.type==="book"){const b=e;d.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(d.collectionId=(m=b.contained_in[0])==null?void 0:m.id)}return d}function Hp(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Gp=e=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:l,onChange:d,onSave:p,onDelete:a,onNavigate:c,renderLink:u,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h,headerExtra:v,className:y,style:j}=e;de();const[_,k]=f.useState(s),z=l?s:_;f.useEffect(()=>{s!==_&&k(s)},[s]);const w=f.useCallback(()=>{const W=z==="view"?"edit":"view";l?l(W):k(W)},[z,l]),[C,E]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(W=>{W&&E(W)})},[i,r]);const R=n||C,T=f.useMemo(()=>R?Us(R):null,[R]),O=l||!n?t.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${o("widget-border")}`,borderRadius:"4px",background:z==="edit"?o("accent-bg"):"transparent",color:o(z==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,M=t.jsxs(t.Fragment,{children:[O,v]});return!R&&!T?t.jsx(yt,{}):z==="view"?t.jsx(xi,{data:R,transport:r,onNavigate:c?W=>c(W):void 0,renderLink:u,headerExtra:M,className:y,style:j}):T?t.jsxs("div",{className:y,style:j,children:[M&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:M}),t.jsx(Hs,{data:T,onChange:d||(()=>{}),onSave:p||(()=>{}),transport:r,onNavigate:c,showDelete:!!a,onDelete:a,onAskAI:g,renderSectionActions:x,onDownloadResource:m,downloadStatuses:b,relations:S,onRelationsChange:h})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:o("muted")},children:"无数据"})},Vo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Vs=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,l]=f.useState(null),[d,p]=f.useState(""),[a,c]=f.useState(""),[u,g]=f.useState("idle"),[x,m]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{e&&(l(null),p(""),c(""),g("idle"),m(""))},[e]),f.useEffect(()=>{s&&setTimeout(()=>{var y;return(y=b.current)==null?void 0:y.focus()},100)},[s]),f.useEffect(()=>{if(u==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[u,n]),f.useEffect(()=>{if(!e)return;const y=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const S=async()=>{if(!(!s||!d.trim())){g("submitting"),m("");try{await i({type:s,content:d.trim(),...a.trim()?{contact:a.trim()}:{}}),g("success")}catch(y){g("error"),m(y instanceof Error?y.message:"提交失败,请稍后重试")}}};if(!e)return null;const h=s&&d.trim()&&u!=="submitting",v=Vo.find(y=>y.value===s);return t.jsx("div",{style:Up,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:Vp,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:Yp,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),t.jsx("button",{onClick:n,style:Kp,"aria-label":"关闭",children:"✕"})]}),u==="success"?t.jsxs("div",{style:Qp,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:o("primary"),marginTop:"8px"},children:"查看反馈列表 →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Vo.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...qp,...s===y.value?Jp:{}},children:[t.jsx("span",{children:y.icon})," ",y.label]},y.value))}),t.jsx("textarea",{ref:b,value:d,onChange:y=>p(y.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||u==="submitting",style:{...Zp,opacity:s?1:.6}}),t.jsx("input",{type:"text",value:a,onChange:y=>c(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||u==="submitting","aria-label":"联系方式(选填)",style:tu}),t.jsxs("div",{style:{fontSize:"12px",color:o("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:eu,children:x}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!h,style:{...Xp,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:u==="submitting"?"提交中...":"提交反馈"})})]})]})})},Up={position:"fixed",top:0,left:0,right:0,bottom:0,background:o("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Vp={background:o("bg"),border:`1px solid ${o("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:o("shadow-dialog")},Yp={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Kp={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:o("desc-fg"),padding:"4px 8px",borderRadius:"4px"},qp={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Jp={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},Zp={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("input-bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Xp={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},Qp={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:o("success")},eu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginBottom:"12px"},tu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ii="--bim-feedback-fab-offset",oi=48,nu=16,iu=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:r=!1,zIndex:s})=>{const[l,d]=f.useState(!1),p=n.bottom??24;return f.useEffect(()=>{if(r||typeof document>"u")return;const a=document.documentElement;return a.style.setProperty(ii,`calc(${p+oi+nu}px + env(safe-area-inset-bottom, 0px))`),()=>{a.style.removeProperty(ii)}},[r,p]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ou,zIndex:s??o("feedback-fab-z"),bottom:`calc(${p}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":"反馈",title:"反馈",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.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"})})}),t.jsx(Vs,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},ou={position:"fixed",width:`${oi}px`,height:`${oi}px`,borderRadius:"50%",border:"none",background:o("primary"),color:o("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:o("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Yo=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Ys=({onSubmit:e})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[l,d]=f.useState(""),[p,a]=f.useState("idle"),[c,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){a("submitting"),u("");try{await e({type:n,content:r.trim(),...l.trim()?{contact:l.trim()}:{}}),a("success"),s(""),d(""),i("bug")}catch(S){a("error"),u(S instanceof Error?S.message:"提交失败,请稍后重试")}}},m=n&&r.trim()&&p!=="submitting",b=Yo.find(S=>S.value===n);return p==="success"?t.jsx("div",{style:Ko,children:t.jsxs("div",{style:cu,children:[t.jsx("span",{children:"✓ 感谢您的反馈!"}),t.jsx("button",{onClick:()=>a("idle"),style:du,children:"继续提交"})]})}):t.jsxs("div",{style:Ko,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Yo.map(S=>t.jsxs("button",{onClick:()=>i(S.value),style:{...ru,...n===S.value?su:{}},children:[t.jsx("span",{children:S.icon})," ",S.label]},S.value))}),t.jsx("textarea",{ref:g,value:r,onChange:S=>s(S.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:p==="submitting",style:{...lu}}),t.jsx("input",{type:"text",value:l,onChange:S=>d(S.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:p==="submitting","aria-label":"联系方式(选填)",style:uu}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:o("desc-fg")},children:[r.length," / 2000"]}),t.jsx("button",{onClick:x,disabled:!m,style:{...au,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交"})]}),p==="error"&&t.jsx("div",{style:pu,children:c})]})},Ko={padding:"16px",border:`1px solid ${o("widget-border")}`,borderRadius:"8px",background:o("input-bg")},ru={padding:"8px 16px",fontSize:"13px",border:`1px solid ${o("widget-border")}`,borderRadius:"6px",background:"transparent",color:o("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},su={borderColor:o("primary"),background:o("list-active-bg"),color:o("primary"),fontWeight:500},lu={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},au={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:o("primary"),color:o("primary-fg"),fontWeight:500},cu={display:"flex",alignItems:"center",gap:"12px",color:o("success"),fontSize:"14px"},du={background:"none",border:"none",color:o("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},pu={fontSize:"13px",color:o("danger"),padding:"8px 12px",background:o("danger-bg"),borderRadius:"4px",marginTop:"8px"},uu={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${o("input-border")}`,borderRadius:"6px",background:o("bg"),color:o("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function qo(e){return typeof e=="function"?e():e??"/api/feedback"}const Ks=({resourceId:e,apiUrl:n})=>{const[i,r]=f.useState([]),[s,l]=f.useState(!0),d=f.useCallback(async()=>{const a=qo(n);l(!0);try{const u=await(await fetch(`${a}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&r(u.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{d()},[d]);const p=async a=>{const c=qo(n),u=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||"提交失败")}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Fi,{items:i,loading:s}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ys,{onSubmit:p})})]})},Jo={part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"};function Zo(e){return e?Jo[e]??e:Jo.related}const xu={extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"};function fu(e){return xu[e]??e}const gu={text:"全文",image:"影印",textImage:"圖文",physical:"館藏"};function mu(e){return gu[e]??""}function Pi({authors:e,onNavigate:n,renderLink:i}){const{convert:r}=Y(),s=(e||[]).filter(l=>l&&l.name);return s.length?t.jsx(t.Fragment,{children:s.map((l,d)=>{const p=yi(l.role);return t.jsxs(f.Fragment,{children:[d>0&&" ",l.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(l.dynasty),"〕"]}),l.entity_id?t.jsx(Le,{id:l.entity_id,label:r(l.name),onNavigate:n,renderLink:i,dense:!0}):r(l.name),p&&t.jsx("span",{style:{marginLeft:4},children:r(p)})]},d)})}):null}function qs(e,n){var p,a;const i=hi(e,n),r=i.mirrors.map(c=>({key:c.key,label:c.label,description:c.description,rows:c.items.filter(u=>u.group_role!=="mirror"),mirrors:c.items.filter(u=>u.group_role==="mirror")})),s=i.buckets.filter(c=>c.key==="image"||c.key==="textImage").flatMap(c=>c.items);s.length&&r.push({key:"_images",label:r.length?"其他影印":void 0,rows:s,mirrors:[]});const l=((p=i.buckets.find(c=>c.key==="physical"))==null?void 0:p.items)??[];return l.length&&r.push({key:"_physical",label:"館藏",rows:l,mirrors:[]}),{text:((a=i.buckets.find(c=>c.key==="text"))==null?void 0:a.items)??[],groups:r}}function Js(e,n){const i=(e.url?Et(e.url):void 0)||e.name,r=Ar(e,n);return r?`${i}(${r})`:i}function Oi({item:e,siblings:n,listedVolumeCounts:i}){const{convert:r}=Y(),[s,l]=f.useState(!1),d=mn(e),p=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),a=r(Js(e,n)),c=Rt(e),u=jn(e)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[c?t.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",children:[a," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:"bim-d-zt-name",children:a}),u&&t.jsx("span",{className:"bim-d-meta",children:r(u)}),p&&s&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(ki,{item:e})})]}),t.jsx("td",{className:p?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:p&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":s,onClick:()=>l(g=>!g),children:r(s?"收起分冊":`展開 ${d.expected} 冊`)})})]})}function Zs({groups:e,listedVolumeCounts:n}){const{convert:i}=Y();return t.jsx(t.Fragment,{children:e.map(r=>t.jsxs("div",{className:"bim-d-rg",children:[r.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:i(r.label)}),r.description&&t.jsx("p",{className:"bim-d-rg-d",children:i(r.description)}),r.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:r.rows.map((s,l)=>t.jsx(Oi,{item:s,siblings:r.rows,listedVolumeCounts:n},`${s.id||s.url||s.name}-${l}`))})}),r.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[r.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:i("鏡像")}),r.mirrors.map((s,l)=>{const d=Rt(s),p=i(Js(s,r.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:s.details?i(s.details):void 0,children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:p},l)})]})]},r.key))})}const Ut=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function ri(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Ut.find(r=>n.startsWith(r.key[0])))==null?void 0:i.key}const Xo=12,hu=60,Xs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,railTop:l,back:d,railLinks:p})=>{var Ce,Re,Ie;const a=de(),{convert:c}=Y(),u=f.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[g,x]=f.useState(new Map),[m,b]=f.useState(!1),[S,h]=f.useState(""),[v,y]=f.useState(!1),j=u.length<=hu,_=j||m||!!S||v,k=f.useMemo(()=>_?u:u.slice(0,Xo),[u,_]);f.useEffect(()=>{if(!n||k.length===0)return;const D=k.filter(ie=>!g.has(ie));if(D.length===0)return;let oe=!1;return Promise.all(D.map(ie=>n.getItem(ie).then(xe=>{const q=xe??{};return[ie,{id:ie,title:q.title,edition:q.edition,resources:q.resources,publication_info:q.publication_info,current_location:q.current_location,lineage:q.lineage,measure_info:q.measure_info}]}).catch(()=>[ie,{id:ie}]))).then(ie=>{oe||x(xe=>{const q=new Map(xe);for(const[L,I]of ie)q.set(L,I);return q})}),()=>{oe=!0}},[n,k,g]);const z=f.useMemo(()=>u.map(D=>g.get(D)??{id:D}),[u,g]),w=u.length>0&&u.every(D=>g.has(D)),C=!!n&&k.some(D=>!g.has(D)),E=j||_,R=f.useMemo(()=>Mr(z,e.version_graph,{era:S,scanOnly:v,sort:E?"year":"default"}),[z,e.version_graph,S,v,E]),T=m?R.rows:R.rows.slice(0,Xo),O=R.allRows.filter(D=>D.hasImage).length,M=e.related_works||[],W=M.filter(D=>D.relation==="collected_in"),P=f.useMemo(()=>{const D=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],oe=ie=>{const xe=D.indexOf(ie??"");return xe<0?D.length:xe};return M.filter(ie=>ie.relation!=="collected_in").map((ie,xe)=>({r:ie,i:xe})).sort((ie,xe)=>oe(ie.r.relation)-oe(xe.r.relation)||ie.i-xe.i).map(ie=>ie.r)},[M]),V=f.useMemo(()=>{const D=hi(e.resources,e.resource_groups);return[...D.mirrors.flatMap(oe=>oe.items.map(ie=>({r:ie,kind:c(oe.label)}))),...D.buckets.flatMap(oe=>oe.items.map(ie=>({r:ie,kind:c(mu(oe.key))})))]},[e.resources,e.resource_groups,c]),K=e.indexed_by||[],N=e.emendated_by||[],le=f.useMemo(()=>{var F,A,Z;const D=[],oe=(A=(F=e.authors)==null?void 0:F[0])==null?void 0:A.dynasty;oe&&D.push({label:"成書",value:c(oe)});const ie=st(e,a.unit.juan);if(ie){const J=(Z=e.juan_count)==null?void 0:Z.description;D.push({label:"卷帙",value:t.jsxs(t.Fragment,{children:[c(ie),J&&J!==ie?t.jsxs("span",{className:"bim-d-meta",children:["(",c(J),")"]}):null]})})}e.loss_status&&D.push({label:"存佚",value:c(fu(e.loss_status))});const xe=R.allRows.filter(J=>J.sortYear!=null),q=xe.length>0?xe.reduce((J,fe)=>J.sortYear<=fe.sortYear?J:fe):null;q!=null&&q.era.era?D.push({label:"最早存世",value:c([q.era.era,q.era.reign].filter(Boolean).join(" ")),title:q.era.source==="edition"?c("據版本題名推斷"):void 0}):C&&D.push({label:"最早存世",value:t.jsx("span",{className:"bim-d-meta","aria-label":c("載入中"),children:"…"})}),N.length&&D.push({label:"考證",value:`${N.length} ${c("條")}`});const L=Qo(e.additional_titles);L.length&&D.push({label:"又名",value:L.map(c).join("、")});const I=Qo(e.attached_texts);I.length&&D.push({label:"附載",value:I.map(c).join("、")});const $=(e.additional_works||[]).map(J=>c(J.book_title)+(J.n_juan!=null?` ${J.n_juan}${c(a.unit.juan)}`:""));return $.length&&D.push({label:"附錄",value:$.join("、")}),D},[e,c,a,C,R.allRows,N.length]),se=[{value:e._edition_count??u.length,label:"版本"},{value:w?O:0,label:"有影印"},{value:K.length,label:"家著錄"}],ne=e.classification,Q=ne?[ne.l1,ne.l2,ne.l3,ne.l4].filter(Boolean).map(D=>c(D)):[],H=e.subtype?c(a.workSubtype[e.subtype]??e.subtype):"",te=t.jsx(Jt,{title:c(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:i,renderLink:r}),meta:t.jsx(Be,{items:[...Q,ne!=null&&ne.source?c(`據《${ne.source.split("/")[0]}》`):"",H]}),description:(Ce=e.description)!=null&&Ce.text?t.jsxs(t.Fragment,{children:[t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Re=e.description.sources)!=null&&Re.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(D=>c(nc(D))).filter(Boolean).join(" · ")}):null]}):void 0,stats:se,facts:le,readAction:s,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Ie=e.appendix)==null?void 0:Ie.map((D,oe)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:c(D.title)}),t.jsx(rt,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},oe))}),pe=R.eras.length>=2?[{key:"",label:a.catalog.all},...R.eras.map(D=>({key:D,label:`${D} ${R.allRows.filter(oe=>oe.era.era===D).length}`}))]:[],re=[];u.length&&re.push({id:"versions",label:"版本",count:u.length}),K.length&&re.push({id:"catalogs",label:"著錄",count:K.length}),W.length&&re.push({id:"collected",label:"收入叢編",count:W.length}),P.length&&re.push({id:"related",label:"相關書目",count:P.length}),V.length&&re.push({id:"resources",label:"在線資源",count:V.length});const ee=u.length===0&&K.length===0,ye=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(Fe,{id:"versions",title:"版本",meta:t.jsx(Be,{items:[c(`共 ${u.length} 種`),w&&O?c(`${O} 種有影印`):"",R.rows.length!==R.allRows.length?c(`當前 ${R.rows.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":C&&pe.length===0&&u.length>1?"":void 0,children:[pe.length>0&&t.jsx(kn,{items:pe,value:S,onChange:D=>{h(D),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Jr,{label:"只看有影印",checked:v,onChange:D=>{y(D),b(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(E?"按年代排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("版本")}),t.jsx("th",{children:c("年代")}),t.jsx("th",{children:c("館藏")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("影印")})})]})}),t.jsx("tbody",{children:T.map(D=>{var oe;return t.jsx(bu,{row:D,measure:(oe=g.get(D.id))==null?void 0:oe.measure_info,loaded:g.has(D.id),onNavigate:i,renderLink:r},`${D.id}:${g.has(D.id)?"r":"p"}`)})})]}),T.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(S||v?"當前篩選下沒有版本":"暫無版本著錄")}),R.rows.length>T.length&&t.jsx(Nt,{label:`展開其餘 ${R.rows.length-T.length} 種版本`,onClick:()=>b(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("部分年代據版本題名推斷,非著錄原文")})]}),K.length>0&&t.jsx(yu,{items:K,transport:n,onNavigate:i,renderLink:r}),ee&&t.jsx(Fe,{title:"版本",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("尚未著錄該作品的版本與書目收錄。")})})]}),ae=(D,oe)=>t.jsx(Le,{id:D,label:c(oe),onNavigate:i,renderLink:r,dense:!0}),Te=f.useMemo(()=>{const D=new Map;for(const oe of P){const ie=Zo(oe.relation);D.set(ie,(D.get(ie)??0)+1)}return D.size>1?[...D.entries()].sort((oe,ie)=>ie[1]-oe[1]).slice(0,4).map(([oe,ie])=>`${c(oe)} ${ie}`).join(" · "):void 0},[P,c]),je=t.jsxs(t.Fragment,{children:[t.jsx(mt,{id:"collected",title:"收入叢編",items:W.map(D=>ae(D.id,D.title))}),t.jsx(mt,{id:"related",title:"相關書目",meta:c(`${P.length} 部`),sub:Te,items:P.map(D=>t.jsxs(t.Fragment,{children:[ae(D.id,D.title),t.jsx("span",{className:"bim-d-meta",title:D.note?c(D.note):void 0,children:c(Zo(D.relation))})]}))}),t.jsx(mt,{id:"resources",title:"在線資源",cap:6,items:V.map(({r:D,kind:oe})=>{const ie=c((D.url?Et(D.url):void 0)||D.name),xe=Rt(D);return t.jsxs(t.Fragment,{children:[xe?t.jsxs("a",{href:xe,target:"_blank",rel:"noopener noreferrer",children:[ie," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ie}),oe&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:oe})]})})})]});return t.jsx(qt,{railTop:l,back:d,nav:re,railLinks:p,main:ye,card:te,side:je})};function Qo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function er(e,n){return n((e.url?Et(e.url):void 0)||e.name)}function bu({row:e,measure:n,loaded:i,onNavigate:r,renderLink:s}){const{convert:l}=Y(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),p=e.era.source==="edition",a=e.holders[0],c=a?er(a,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?Rt(u):void 0,x=e.images.map(m=>er(m,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:p?l("據版本題名推斷"):void 0,children:d?l(d):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${c?"":" bim-d-zt-blank"}`,children:[c||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:x,children:l("有影印")}):t.jsx("span",{className:"bim-d-flag",title:x,children:l("有影印")}))})]})}function yu({items:e,transport:n,onNavigate:i,renderLink:r}){const s=de(),{convert:l}=Y(),[d,p]=f.useState(0),a=Math.min(d,e.length-1),c=e[a],[u,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const x=[...new Set(e.map(b=>b.source_bid).filter(b=>!!b))];if(x.length===0)return;let m=!1;return Promise.all(x.map(b=>n.getItem(b).then(S=>{var h,v;return[b,((v=(h=S==null?void 0:S.authors)==null?void 0:h[0])==null?void 0:v.dynasty)??""]}).catch(()=>[b,""]))).then(b=>{m||g(new Map(b.filter(([,S])=>S)))}),()=>{m=!0}},[n,e]),t.jsx(Fe,{id:"catalogs",title:"著錄",meta:t.jsx(Be,{items:[l(`歷代書目 ${e.length} 家`),l("按著錄順序")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":l("著錄書目"),children:e.map((x,m)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":m===a,"aria-label":l(x.source),onClick:()=>p(m),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(x.source_bid??"")?l(u.get(x.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...l(x.source)].slice(0,9).map((b,S)=>t.jsx("span",{children:b},S))})]})},m))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[c.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:l(c.title_info)}),t.jsx(Be,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[c.source_bid?t.jsx(Le,{id:c.source_bid,label:l(c.source),onNavigate:i,renderLink:r,dense:!0}):l(c.source),c.section?l(c.section):"",c.author_info?`${l(s.label.authorInfo)} ${l(c.author_info)}`:"",c.edition?`${l(s.label.edition)} ${l(c.edition)}`:"",c.page??""]}),c.summary&&t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.summary))}),c.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.comment)}),t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.comment))})]}),c.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:l(s.section.additionalComment)}),t.jsx("p",{className:"bim-d-quote",children:Ge(l(c.additional_comment))})]}),!c.summary&&!c.comment&&!c.additional_comment&&!c.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:l("僅著錄書名,無提要。")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[a>0?t.jsx("button",{type:"button","aria-label":l(`上一家:${e[a-1].source}`),onClick:()=>p(a-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",l(e[a-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[a+1," / ",e.length]}),a<e.length-1?t.jsx("button",{type:"button","aria-label":l(`下一家:${e[a+1].source}`),onClick:()=>p(a+1),children:t.jsxs("span",{"aria-hidden":"true",children:[l(e[a+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}const tr=40,nr=2,ju=9,ir={certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"};function Wn(e){if(!e)return["",""];const n=e.split(/[ ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Qs=({data:e,transport:n,onNavigate:i,renderLink:r,readAction:s,fullText:l,fullTextPending:d,chapterLink:p,railTop:a,back:c,railLinks:u})=>{var q,L,I,$,F,A,Z,J,fe,we,_e,Ne,Ee,Lt;const g=de(),{convert:x}=Y(),[m,b]=f.useState(null),[S,h]=f.useState(new Map),[v,y]=f.useState([]),[j,_]=f.useState(new Map),[k,z]=f.useState(!1);f.useEffect(()=>{if(!n||!e.work_id){b(null);return}let B=!1;return n.getItem(e.work_id).then(ce=>{!B&&ce&&ce.type==="work"&&b(ce)}).catch(()=>{}),()=>{B=!0}},[n,e.work_id]),f.useEffect(()=>{const B=e.contained_in||[];if(!n||B.length===0){h(new Map);return}let ce=!1;return Promise.all(B.map(ue=>{const ve=typeof ue=="string"?ue:ue.id;return n.getItem(ve).then(he=>[ve,he]).catch(()=>[ve,null])})).then(ue=>{if(ce)return;const ve=new Map;for(const[he,ge]of ue)ge&&ve.set(he,ge);h(ve)}),()=>{ce=!0}},[n,e.contained_in]);const w=f.useMemo(()=>{const B=new Set([...(m==null?void 0:m.books)||[],...e.related_books||[]]);return B.add(e.id),[...B]},[m==null?void 0:m.books,e.related_books,e.id]),C=w.length-1;f.useEffect(()=>{if(!n||C<=0){y([]);return}const B=w.length<=tr,ce=B?w:w.slice(0,8);let ue=!1;return Promise.all(ce.map(ve=>ve===e.id?Promise.resolve({id:ve,title:e.title,edition:e.edition,year:xn(e)}):n.getItem(ve).then(he=>{const ge=he??{};return{id:ve,title:ge.title,edition:ge.edition,year:he?xn(ge):void 0}}).catch(()=>({id:ve})))).then(ve=>{if(ue)return;const he=ve.filter(ge=>ge.id===e.id||ge.title||ge.edition);B&&he.sort((ge,Ae)=>(ge.year??1/0)-(Ae.year??1/0)),y(he)}),()=>{ue=!0}},[n,w,C,e]);const E=e.lineage,R=f.useMemo(()=>[...((E==null?void 0:E.derived_from)||[]).filter(B=>B.ref_type==="book").map(B=>B.ref),...((E==null?void 0:E.related_to)||[]).map(B=>B.book_id)].filter(Boolean),[E]);f.useEffect(()=>{if(!n||R.length===0){_(new Map);return}let B=!1;return Promise.all(R.map(ce=>n.getItem(ce).then(ue=>[ce,{id:ce,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[ce,{id:ce}]))).then(ce=>{B||_(new Map(ce))}),()=>{B=!0}},[n,R]);const T=f.useMemo(()=>qs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),O=T.groups.reduce((B,ce)=>B+ce.rows.length+ce.mirrors.length,0),M=T.groups.length>0&&T.groups.every(B=>B.key==="_physical"),W=Kt(e),P=Hr(e),V=st(e,g.unit.juan),K=new Set((e.contained_in||[]).map(B=>typeof B=="string"?0:Ht(B.volume_index).length).filter(B=>B>0)),N=B=>{var ve;const ce=(ve=e.base_edition)==null?void 0:ve.find(he=>he.book_id===B&&he.name);if(ce!=null&&ce.name)return ce.name;const ue=j.get(B);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},le=f.useMemo(()=>{var ut,lt,en,at,tn;const B=[];P&&B.push({label:"版本類型",value:x(P),title:e.edition_type||(ut=e.lineage)!=null&&ut.category?void 0:x("據版本題名推斷")}),(lt=e.publication_info)!=null&<.details?B.push({label:"刊印",value:x(e.publication_info.details)}):(W.era||W.reign)&&B.push({label:"刊寫年代",value:x([W.era,W.reign].filter(Boolean).join(" ")),title:W.source==="edition"?x("據版本題名推斷"):void 0}),V&&B.push({label:"卷帙",value:x(V)});const ce=(e.contained_in||[]).flatMap(ke=>typeof ke=="string"?[]:Ht(ke.volume_index));ce.length&&B.push({label:"冊次",value:x(`第 ${vn(ce,g.unit.volume)} ${g.unit.volume}(${ce.length} ${g.unit.volume})`)});const ue=(((en=e.lineage)==null?void 0:en.derived_from)||[]).find(ke=>ke.relation==="底本"&&ke.ref_type==="book");ue&&N(ue.ref)&&B.push({label:"底本",value:t.jsx(Le,{id:ue.ref,label:x(N(ue.ref)),onNavigate:i,renderLink:r,dense:!0})});const ve=(e.base_edition||[]).filter(ke=>ke&&ke.name);for(const ke of["底本","配補","參校"]){if(ke==="底本"&&ue&&N(ue.ref))continue;const Ue=ve.filter(ze=>ze.role===ke);Ue.length&&B.push({label:ke,value:Ue.map((ze,nn)=>t.jsxs(f.Fragment,{children:[nn>0&&"、",ze.book_id?t.jsx(Le,{id:ze.book_id,label:x(ze.name),onNavigate:i,renderLink:r,dense:!0}):x(ze.name)]},nn))})}const he=(e.provenance||[]).filter(ke=>ke&&ke.institution),ge=(e.resources||[]).filter(ke=>(ke.types||(ke.type?[ke.type]:[])).includes("physical"));if(he.length){B.push({label:"存藏",value:he.slice(0,2).map(ze=>x(ze.institution)).join("、")+(he.length>2?x(` 等 ${he.length} 處`):"")});const ke=he.filter(ze=>ze.call_number).slice(0,2).map(ze=>`${x(ze.institution)} ${ze.call_number}`);ke.length&&B.push({label:"索書號",value:ke.join(";")+(he.filter(ze=>ze.call_number).length>2?"…":"")});const Ue=he.flatMap(ze=>ze.seals||[]).filter(Boolean);Ue.length&&B.push({label:"藏印",value:x(Ue.join("、"))})}else ge.length?B.push({label:"存藏",value:ge.slice(0,2).map(ke=>x(ke.name)).join("、")+(ge.length>2?x(` 等 ${ge.length} 處`):"")}):(at=e.current_location)!=null&&at.name&&B.push({label:"存藏",value:x(e.current_location.name)});const Ae=e.physical_description;if(Ae){const ke=[["行款",Ae.leaf_style],["裝幀",Ae.binding],["尺寸",Ae.dimensions],["品相",Ae.condition]];for(const[Ue,ze]of ke)ze&&ze.trim()&&B.push({label:Ue,value:x(ze)})}(tn=e.page_count)!=null&&tn.description&&B.push({label:g.label.pageCount,value:x(e.page_count.description)});const tt=[...Zn(e.additional_titles),...Zn(e.attached_texts)];return tt.length&&B.push({label:"又名",value:tt.map(x).join("、")}),B},[e,x,g,W,P,V,j,i,r]),G=x(e.title),se=e.edition?x(e.edition):void 0,ne=((q=e.lineage)==null?void 0:q.year_text)||"",Q=t.jsx(Jt,{kind:"版本",title:G,subtitle:se,byline:t.jsx(Pi,{authors:e.authors??(m==null?void 0:m.authors),onNavigate:i,renderLink:r}),meta:t.jsx(Be,{items:[P?x(P):"",W.era?x([W.era,W.reign].filter(Boolean).join("")):"",V?x(V):""]}),description:(L=e.description)!=null&&L.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((I=e.description)==null?void 0:I.text)?6:void 0,facts:le,readAction:s,secondaryAction:s&&O>0&&!M?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:x("看原書影印")}):void 0,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),H=e.contained_in||[],te=(l==null?void 0:l.chapters)||[],pe=te[0]&&Wn(te[0].title)[0].slice(-1)||"章",re=!!(($=E==null?void 0:E.derived_from)!=null&&$.length||(F=E==null?void 0:E.related_to)!=null&&F.length||(A=e.appendix)!=null&&A.length),ee=[];(te.length||T.text.length||d)&&ee.push({id:"fulltext",label:"全文",count:te.length?x(`${te.length} ${pe}`):void 0}),T.groups.length&&ee.push({id:"images",label:M?"館藏":"影印",count:O}),re&&ee.push({id:"lineage",label:"版本源流"}),H.length&&ee.push({id:"collections",label:"收入叢編",count:H.length}),(Z=e.location_history)!=null&&Z.length&&ee.push({id:"provenance",label:"流轉歷史"});const ye=B=>(p==null?void 0:p(B))??null,ae=te[0],Te=ae?ye(ae.file):null,je=k?te:te.slice(0,ju),Ce=(B,ce,ue)=>B?t.jsx("a",{className:ue,href:B.href??"#",onClick:B.onClick?ve=>{ve.metaKey||ve.ctrlKey||(ve.preventDefault(),B.onClick())}:void 0,children:ce}):t.jsx("span",{className:ue,children:ce}),Re=t.jsxs(t.Fragment,{children:[(te.length>0||T.text.length>0||d)&&t.jsxs(Fe,{id:"fulltext",title:"全文",meta:te.length>0?t.jsx(Be,{items:[x(`${te.length} ${pe}`),(J=l==null?void 0:l.source)!=null&&J.name?x(`據${l.source.name}${l.source.license?` ${l.source.license}`:""}`):""]}):void 0,children:[d&&!ae&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ae&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:x(`從${Wn(ae.title)[0]||"第一章"}讀起`)}),t.jsx("span",{className:"bim-d-meta",children:x((ae.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),Ce(Te,t.jsxs(t.Fragment,{children:[x("進入閱讀頁")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),te.length>1&&t.jsx("ul",{className:"bim-d-chap",children:je.map(B=>{const[ce,ue]=Wn(B.title);return t.jsx("li",{children:Ce(ye(B.file),t.jsxs(t.Fragment,{children:[ce&&t.jsx("b",{children:x(ce)}),x(ue||B.file)]}))},B.file)})}),te.length>je.length&&t.jsx(Nt,{label:`展開其餘 ${te.length-je.length} ${pe}`,onClick:()=>z(!0)}),T.text.length>0&&t.jsxs(t.Fragment,{children:[(te.length>0||d)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:x("站外全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:T.text.map((B,ce)=>t.jsx(Oi,{item:B,siblings:T.text,listedVolumeCounts:K},`${B.id||B.url||B.name}-${ce}`))})})]})]}),T.groups.length>0&&t.jsx(Fe,{id:"images",title:M?"館藏":"影印",meta:t.jsx(Be,{items:[T.groups.length>1?x(`${T.groups.length} 組`):"",x(`${O} 處`)]}),children:t.jsx(Zs,{groups:T.groups,listedVolumeCounts:K})}),re&&t.jsxs(Fe,{id:"lineage",title:"版本源流",meta:(fe=E==null?void 0:E.derived_from)!=null&&fe.length?x("據版本傳承著錄"):void 0,children:[t.jsxs("ul",{className:"bim-d-tl",children:[((E==null?void 0:E.derived_from)||[]).map((B,ce)=>{const ue=B.ref_type==="book"?N(B.ref):"";return t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),B.ref_type==="book"?t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Le,{id:B.ref,label:x(ue||B.ref),onNavigate:i,renderLink:r,dense:!0})}):t.jsx("span",{className:"bim-d-tl-t",children:x("擬構祖本")}),(B.evidence||B.confidence)&&t.jsxs("span",{className:"bim-d-tl-ev",children:[B.evidence?x(B.evidence):"",B.confidence&&ir[B.confidence]?x(`(${ir[B.confidence]})`):""]})]},`d-${ce}`)}),(we=E==null?void 0:E.derived_from)!=null&&we.length||(_e=E==null?void 0:E.related_to)!=null&&_e.length?t.jsxs("li",{className:"bim-d-tl-cur",children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("本版")}),t.jsx("span",{className:"bim-d-tl-t",children:se||G}),ne&&t.jsxs("span",{className:"bim-d-meta",children:[t.jsx("span",{className:"bim-d-dot"}),x(ne)]})]}):null,((E==null?void 0:E.related_to)||[]).map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x(B.relation)}),t.jsx("span",{className:"bim-d-tl-t",children:t.jsx(Le,{id:B.book_id,label:x(N(B.book_id)||B.book_id),onNavigate:i,renderLink:r,dense:!0})}),B.evidence&&t.jsx("span",{className:"bim-d-tl-ev",children:x(B.evidence)})]},`r-${ce}`)),(Ne=e.appendix)==null?void 0:Ne.map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-rel bim-d-ui",children:x("附記")}),t.jsx("span",{className:"bim-d-tl-t",children:x(B.title)}),t.jsxs("details",{children:[t.jsx("summary",{className:"bim-d-ui",children:x("展開")}),t.jsx(rt,{text:B.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]})]},`a-${ce}`))]}),(E==null?void 0:E.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"10px 0 0",maxWidth:"46em"},children:x(E.note)})]}),H.length>0&&t.jsx(Fe,{id:"collections",title:"收入叢編",children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:H.map((B,ce)=>{var Ae,tt;const ue=typeof B=="string"?B:B.id,ve=typeof B=="string"?[]:Ht(B.volume_index),he=S.get(ue),ge=(he==null?void 0:he._member_count)||((Ae=he==null?void 0:he.books)==null?void 0:Ae.length)||((tt=he==null?void 0:he.contained_works)==null?void 0:tt.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:ue,label:he?x(he.title):ue,onNavigate:i,renderLink:r,dense:!0}),ve.length>0&&t.jsx(vu,{volumes:ve,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ge>0&&x(`全 ${ge} ${g.unit.bu}`)})]},`${ue}-${ce}`)})})})}),(Ee=e.location_history)!=null&&Ee.length?t.jsx(Fe,{id:"provenance",title:"流轉歷史",children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((B,ce)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:x(B.name)}),([B.start_date,B.end_date].filter(Boolean).join("—")||B.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Be,{items:[[B.start_date,B.end_date].filter(Boolean).join("—"),B.description?x(B.description):""]})})]},ce))})}):null,ee.length===0&&t.jsx(Fe,{title:"影印與全文",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:x("尚未著錄該版本的影印、全文與收藏信息。")})})]}),Ie=v.findIndex(B=>B.id===e.id),D=w.length<=tr,oe=D&&Ie>=0?v.slice(Math.max(0,Ie-nr),Ie+nr+1):v.filter(B=>B.id!==e.id),ie=t.jsxs(t.Fragment,{children:[m&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:x(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(Le,{id:m.id,label:x(m.title),onNavigate:i,renderLink:r})}),t.jsx(Be,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(m.authors||[]).slice(0,2).map(B=>`${B.dynasty?`〔${x(B.dynasty)}〕`:""}${x(B.name)}`),x(st(m,g.unit.juan)),m._edition_count?x(`${m._edition_count} 種版本`):""]}),((Lt=m.description)==null?void 0:Lt.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:x(m.description.text.replace(/[#*_>`[\]]/g,""))})]}),C>0&&oe.length>0&&t.jsxs("div",{children:[t.jsx(mt,{id:"siblings",title:D?"同作品版本":g.relation.siblingVersions,meta:x(D?"按年代":`${C} 種`),cap:oe.length,items:oe.map(B=>B.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:x(B.edition||B.title||B.id)}):t.jsx(Le,{id:B.id,label:x(B.edition||B.title||B.id),onNavigate:i,renderLink:r,dense:!0})),metas:oe.map(B=>[B.year!=null?B.year<0?`前${-B.year}`:String(B.year):"",B.id===e.id?x("本頁"):""].filter(Boolean).join(" ")),currentIndex:oe.findIndex(B=>B.id===e.id)}),m&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Le,{id:m.id,label:x(`在作品頁看全部 ${w.length} 種 →`),onNavigate:i,renderLink:r,dense:!0})})]})]}),xe=e.work_id?t.jsx(qr,{caption:g.section.belongsToWork,children:t.jsx(Le,{id:e.work_id,label:m?x(m.title):" ",onNavigate:i,renderLink:r,dense:!0})}):void 0;return t.jsx(qt,{railTop:a,back:c,up:xe,nav:ee,railLinks:u,main:Re,card:Q,side:ie})};function vu({volumes:e,unit:n}){const{convert:i}=Y();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i(`第 ${vn(e,n)} ${n}`),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i(`${e.length} ${n}`)]})]})}const Mn=16,ku=200,Su=16,el=({data:e,catalog:n,transport:i,onNavigate:r,renderLink:s,catalogAction:l,railTop:d,back:p,railLinks:a})=>{var D,oe,ie,xe,q,L,I;const c=de(),{convert:u}=Y(),[g,x]=f.useState(""),[m,b]=f.useState(!1),[S,h]=f.useState(null),[v,y]=f.useState(""),j=f.useMemo(()=>Or(e,n),[e,n]),[_,k]=f.useState(new Map),z=!!i&&j.rows.length>0&&j.rows.length<=ku,w=z&&j.rows.every($=>!$.id||_.has($.id)),C=$=>{var F;return ri($?(F=_.get($))==null?void 0:F.l1:void 0)},E=f.useMemo(()=>{const $=g.trim(),F=$?u($):"";return j.rows.filter(A=>{var J,fe;if(v&&ri(A.id?(J=_.get(A.id))==null?void 0:J.l1:void 0)!==v)return!1;if(!F)return!0;const Z=A.id&&((fe=_.get(A.id))==null?void 0:fe.title)||A.title;return u(Z).includes(F)||(A.subItems||[]).some(we=>u(we).includes(F))})},[j.rows,g,v,_,u]),R=m?E:E.slice(0,Mn),T=f.useMemo(()=>(z?j.rows:R).filter($=>$.id&&!_.has($.id)).map($=>$.id),[z,j.rows,R,_]);f.useEffect(()=>{if(!i||T.length===0)return;let $=!1;const F=T.slice(0,Su);return Promise.all(F.map(A=>i.getItem(A).then(Z=>{var we,_e;const J=Z??{},fe={title:J.title,edition:J.edition,authors:J.authors,measure:Z?st(Z,c.unit.juan):void 0,versionCount:J._edition_count??((we=J.books)==null?void 0:we.length),l1:((_e=J.classification)==null?void 0:_e.l1)||void 0};return[A,fe]}).catch(()=>[A,{}]))).then(A=>{$||k(Z=>{const J=new Map(Z);for(const[fe,we]of A)J.set(fe,we);return J})}),()=>{$=!0}},[i,T,c.unit.juan]);const O=(e.contained_in||[])[0];f.useEffect(()=>{if(!O){h(null);return}if(h({id:O}),!i)return;let $=!1;return i.getItem(O).then(F=>{$||h({id:O,title:F==null?void 0:F.title})}).catch(()=>{}),()=>{$=!0}},[i,O]);const M=f.useMemo(()=>qs(e.resources,e.resource_groups),[e.resources,e.resource_groups]),W=M.text.length+M.groups.reduce(($,F)=>$+F.rows.length+F.mirrors.length,0),P=e.contained_works||[],V=new Set(j.rows.map($=>$.id).filter(Boolean)),K=P.length>0&&!P.every($=>V.has($.id)),N=(()=>{const $=j.rows.map(F=>F.edition).filter(Boolean);return $.length>1&&new Set($).size===1})(),le=j.rows.some($=>$.volumes.length>0||$.expected!=null),G=e._member_count||((D=e.books)==null?void 0:D.length)||P.length,se=st(e,c.unit.juan),ne=e.count,Q=$=>typeof $=="number"&&Number.isFinite($)?$:null,H=Q(ne==null?void 0:ne.juan)??Q((oe=e.juan_count)==null?void 0:oe.number),te=Q(ne==null?void 0:ne.ce)??(j.totalVolumes||null),pe=[{value:j.rows.length,label:"子目"},{value:H??0,label:c.unit.juan},{value:te??0,label:c.unit.volume}],re=f.useMemo(()=>{var A,Z;const $=[];if((A=e.publication_info)!=null&&A.details&&$.push({label:"刊印",value:u(e.publication_info.details)}),G&&G!==j.rows.length){const J=e._member_type==="Book"?"所收版本":e._member_type==="Work"?"所收作品":"成員";$.push({label:u(J),value:`${G} ${u(c.unit.bu)}`,title:u("子目與其各版本合計")})}const F=[Q(ne==null?void 0:ne.zhong)!=null?`${ne.zhong} 種`:"",Q(ne==null?void 0:ne.han)!=null?`${ne.han} 函`:""].filter(Boolean);return F.length&&$.push({label:"應收",value:u(F.join(" "))}),H==null&&se&&$.push({label:"卷帙",value:u(se),title:(Z=e.juan_count)!=null&&Z.description?u(e.juan_count.description):void 0}),$},[e,G,j.rows.length,H,se,ne,u,c]),ee=f.useMemo(()=>{if(!w)return[];const $=new Map;for(const A of j.rows){const Z=C(A.id);Z&&$.set(Z,($.get(Z)??0)+1)}const F=Ut.filter(A=>($.get(A.key)??0)>0);return F.length<2?[]:[{key:"",label:`${c.catalog.all} ${j.rows.length}`},...F.map(A=>({key:A.key,label:`${A.label} ${$.get(A.key)}`}))]},[w,j.rows,_,c]),ye=f.useMemo(()=>{if(!w||!j.rows.some(Z=>Z.volumes.length>0))return null;const $=[],F=j.rows.filter(Z=>Z.volumes.length>0).map(Z=>({k:C(Z.id)??"",from:Math.min(...Z.volumes),to:Math.max(...Z.volumes)})).sort((Z,J)=>Z.from-J.from);for(const Z of F){const J=Z.to-Z.from+1,fe=$[$.length-1];fe&&fe.key===Z.k?(fe.to=Math.max(fe.to,Z.to),fe.n+=J):$.push({key:Z.k,from:Z.from,to:Z.to,n:J})}const A=F.reduce((Z,J)=>Math.max(Z,J.to),0);return $.length>1&&$.some(Z=>Z.key)?{segs:$,last:A}:null},[w,j.rows,_]),ae=(ie=e.description)==null?void 0:ie.text,Te=t.jsx(Jt,{kind:"叢編",title:u(e.title),byline:t.jsx(Pi,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Be,{items:[e.subtype==="work_collection"?u("作品集"):"",(xe=e.publication_info)!=null&&xe.year?u(e.publication_info.year):""]}),description:ae||(q=e.history)!=null&&q.length?t.jsxs(t.Fragment,{children:[ae&&t.jsx(rt,{text:ae,style:{fontSize:15,lineHeight:1.85}}),(L=e.history)!=null&&L.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map(($,F)=>t.jsx("li",{children:u($)},F))}):null]}):void 0,clampDescription:ji(ae)||(((I=e.history)==null?void 0:I.length)??0)>2?6:void 0,stats:pe,facts:re,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ye&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:u("全帙冊次分佈")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":u("全帙冊次分佈"),children:ye.segs.map(($,F)=>{const A=Ut.find(Z=>Z.key===$.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!A,title:A?u(`${A.label} 第 ${$.from}–${$.to} 冊`):void 0,"aria-label":u(A?`只看${A.label}`:"未分類"),"aria-pressed":!!A&&v===$.key,style:{flexGrow:$.n,background:o(A?A.token:"rule")},onClick:()=>{A&&(y(v===$.key?"":$.key),b(!1))}},F)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:u(`第 1 ${c.unit.volume}`)}),t.jsx("span",{children:u("點色段篩選部類")}),t.jsx("span",{children:u(`第 ${ye.last} ${c.unit.volume}`)})]})]})}),je=[];j.rows.length&&je.push({id:"titles",label:"子目",count:j.rows.length}),W&&je.push({id:"resources",label:"影印與全文",count:W}),K&&je.push({id:"works",label:c.section.containedWorks,count:P.length});const Ce=t.jsxs(t.Fragment,{children:[j.rows.length>0&&t.jsxs(Fe,{id:"titles",title:"子目",meta:t.jsx(Be,{items:[u(`${j.rows.length} ${c.unit.items}`),j.totalVolumes?u(`全帙 ${j.totalVolumes} ${c.unit.volume}`):"",E.length!==j.rows.length?u(`當前 ${E.length} ${c.unit.items}`):""]}),action:l,children:[(j.rows.length>Mn||ee.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ee.length>0&&t.jsx(kn,{items:ee,value:v,onChange:$=>{y($),b(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),j.rows.length>Mn&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:u("在本叢編中檢索"),"aria-label":u("在本叢編中檢索"),onChange:$=>{x($.target.value),b(!1)}})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[le&&t.jsx("th",{style:{width:"8.5em"},children:u("冊次")}),t.jsx("th",{children:u("書名")}),t.jsx("th",{style:{textAlign:"right"},children:u("版本")})]})}),t.jsx("tbody",{children:R.map(($,F)=>{var Ne;const A=$.id?_.get($.id):void 0,Z=A!=null&&A.title&&$.title===$.id?A.title:$.title,J=((A==null?void 0:A.authors)||[]).find(Ee=>Ee&&Ee.name),fe=[J?`${J.dynasty?`〔${u(J.dynasty)}〕`:""}${u(J.name)}${J.role?` ${u(J.role)}`:""}`:"",A!=null&&A.measure?u(A.measure):"",(Ne=$.subItems)!=null&&Ne.length?$.subItems.map(Ee=>u(Ee)).join("、"):"",(A!=null&&A.edition||$.edition)&&!N?u((A==null?void 0:A.edition)||$.edition||""):""].filter(Boolean),we=Ut.find(Ee=>Ee.key===C($.id)),_e=$.volumes.length>0?u(`第 ${vn($.volumes,c.unit.volume)} ${c.unit.volume}`):$.expected!=null?u(`${$.found??0}/${$.expected} ${c.unit.volume}`):"";return t.jsxs("tr",{children:[le&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${_e?"":" bim-d-zt-blank"}`,children:[we&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:o(we.token)}}),_e||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[$.id?t.jsx(Le,{id:$.id,label:u(Z),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(Z)}),fe.length>0?t.jsx(Be,{items:fe}):$.id&&!A&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${A!=null&&A.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:A!=null&&A.versionCount?u(`${A.versionCount} 種`):""})]},`${$.id??$.title}-${F}`)})})]}),R.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:u(c.catalog.noMatch)}),E.length>R.length&&t.jsx(Nt,{label:`展開其餘 ${E.length-R.length} ${c.unit.items}`,onClick:()=>b(!0)})]}),W>0&&t.jsxs(Fe,{id:"resources",title:"影印與全文",meta:u(`${W} 處`),children:[M.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[M.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:u("全文")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:M.text.map(($,F)=>t.jsx(Oi,{item:$,siblings:M.text},`${$.id||$.url||$.name}-${F}`))})})]}),t.jsx(Zs,{groups:M.groups})]}),j.rows.length===0&&W===0&&t.jsx(Fe,{title:"子目",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("尚未著錄該叢編的子目。")})})]}),Re=K?t.jsx(mt,{id:"works",title:c.section.containedWorks,meta:u(`${P.length} 種`),cap:12,items:P.map($=>t.jsx(Le,{id:$.id,label:u($.title),onNavigate:r,renderLink:s,dense:!0}))}):null,Ie=S?t.jsx(qr,{caption:"上級叢編",children:t.jsx(Le,{id:S.id,label:u(S.title||S.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(qt,{railTop:d,back:p,up:Ie,nav:je,railLinks:a,main:Ce,card:Te,side:Re})},wu=16,Fn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function or(e){if(!e)return Fn.length;const n=Fn.indexOf(e);return n===-1?Fn.length:n}const _u={people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"};function pt(e){return e==null?"":e<0?`前${-e}`:String(e)}const $u={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},tl=({data:e,transport:n,onNavigate:i,renderLink:r,railTop:s,back:l,railLinks:d})=>{var oe,ie,xe,q,L;const p=de(),{convert:a}=Y(),[c,u]=f.useState("全部"),[g,x]=f.useState(!1),[m,b]=f.useState("default"),[S,h]=f.useState(new Map),v=f.useMemo(()=>(e.works||[]).map(I=>{const $=S.get(I.work_id);return{id:I.work_id,title:($==null?void 0:$.title)??I.title??I.work_id,role:I.role||"",cls:bi(I.role),versionCount:$==null?void 0:$.versionCount,section:$==null?void 0:$.cls,l1:$==null?void 0:$.l1,measure:$==null?void 0:$.measure,hasImage:$==null?void 0:$.hasImage,loaded:!!($!=null&&$.loaded)}}),[e.works,S]),y=f.useMemo(()=>Pr((e.works||[]).map(I=>I.role)),[e.works]),j=f.useMemo(()=>{const I=c==="全部"?v:v.filter($=>$.cls===c);return m==="versions"?[...I].sort(($,F)=>(F.versionCount??-1)-($.versionCount??-1)):I},[v,c,m]),_=g?j:j.slice(0,wu),k=f.useMemo(()=>_.filter(I=>!S.has(I.id)).map(I=>I.id),[_,S]);f.useEffect(()=>{if(!n||k.length===0)return;let I=!1;return Promise.all(k.map($=>n.getItem($).then(F=>{var fe,we,_e,Ne,Ee;const A=F??{},Z=A._edition_count??(((fe=A.books)==null?void 0:fe.length)??0)+(((we=A.collections)==null?void 0:we.length)??0),J=[(_e=A.classification)==null?void 0:_e.l1,(Ne=A.classification)==null?void 0:Ne.l2].filter(Boolean).join(" ");return[$,{id:$,title:A.title,versionCount:Z,loaded:!0,cls:J||void 0,l1:((Ee=A.classification)==null?void 0:Ee.l1)||void 0,measure:F&&st(F,p.unit.juan)||void 0,hasImage:!!(A.has_image??A._has_image)}]}).catch(()=>[$,{id:$,loaded:!0}]))).then($=>{I||h(F=>{const A=new Map(F);for(const[Z,J]of $)A.set(Z,J);return A})}),()=>{I=!0}},[n,k,p.unit.juan]);const z=f.useMemo(()=>{const I=new Map;for(const $ of e.alt_names||[]){const F=$.type||p.section.aliases;I.has(F)||I.set(F,[]),I.get(F).push($.name)}return[...I.entries()].sort(($,F)=>or($[0])-or(F[0])).map(([$,F])=>({label:$,names:F}))},[e.alt_names,p]),w=e.birth_year??((oe=e.dates)==null?void 0:oe.birth)??void 0,C=e.death_year??((ie=e.dates)==null?void 0:ie.death)??void 0,E=(xe=e.dates)==null?void 0:xe.floruit,R=w!=null||C!=null?`${pt(w)||"?"}—${pt(C)||"?"}`:Array.isArray(E)&&E.length===2&&E.every(I=>Number.isFinite(I))?`活躍於 ${pt(E[0])}—${pt(E[1])}`:"",T=new Set(["本名","字","號","号"]),O=z.filter(I=>T.has(I.label)),M=z.filter(I=>!T.has(I.label)),W=M.reduce((I,$)=>I+$.names.length,0),P=f.useMemo(()=>{const I=[];for(const F of O)I.push({label:F.label,value:F.names.map(A=>a(A)).join("、")});const $=(e.works||[]).length;return $&&I.push({label:"著作",value:`${$} ${a("種")}`}),I},[e.works,O,a]),V=I=>{var $;return($=z.find(F=>I.includes(F.label)))==null?void 0:$.names[0]},K=V(["字"]),N=V(["號","号"]),le=[K?`字${K}`:"",N?`號${N}`:""].filter(Boolean).join(","),G=e.native_place,se=e.dynasty?$u[e.dynasty]:void 0,ne=(()=>{if(!se||w==null||C==null||C<w)return null;const[I,$]=se,F=Math.max(w,I),A=Math.min(C,$);if(A<=F)return null;const Z=$-I;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":a(`${pt(w)}—${pt(C)},一生 ${C-w+1} 年`),children:t.jsx("i",{style:{left:`${(F-I)/Z*100}%`,width:`${(A-F)/Z*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:a(`${pt(I)} ${e.dynasty}`)}),t.jsx("span",{children:a(`一生 ${C-w+1} 年`)}),t.jsx("span",{children:pt($)})]})]})})(),Q=f.useMemo(()=>{if(!n||v.length===0||v.some(F=>!F.loaded))return null;const I=new Map;for(const F of v){const A=ri(F.l1);A&&I.set(A,(I.get(A)??0)+1)}const $=Ut.map(F=>({...F,n:I.get(F.key)??0})).filter(F=>F.n>0);return $.length?$:null},[v,n]),H=t.jsxs(Jt,{kind:_u[e.subtype]??"人物",title:a(e.primary_name||e.title),subtitle:le?a(le):void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Be,{items:[e.dynasty?a(e.dynasty):"",R?a(R):"",G?a(`${G}人`):""]}),ne]}),description:(q=e.description)!=null&&q.text?t.jsx(rt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:ji((L=e.description)==null?void 0:L.text)?6:void 0,facts:P,foot:t.jsx(Zt,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[W>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:a(`更多別名(${W})`)}),t.jsx("dl",{children:M.map(I=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:a(I.label)}),t.jsx("dd",{children:I.names.map($=>a($)).join("、")})]},I.label))})]}),Q&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:a("著作分佈")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:Q.map(I=>t.jsx("i",{style:{flexGrow:I.n,background:o(I.token)}},I.key))}),t.jsx("div",{className:"bim-d-dist-key",children:Q.map(I=>t.jsxs("span",{children:[t.jsx("i",{style:{background:o(I.token)}}),a(I.label)," ",I.n]},I.key))})]})]}),te=f.useMemo(()=>v.filter(I=>I.loaded&&(I.versionCount??0)>0).sort((I,$)=>($.versionCount??0)-(I.versionCount??0)).slice(0,3),[v]),pe=!!n&&v.length>=3&&_.some(I=>!I.loaded),re=c==="全部"&&(pe||te.length>=2),ee=e.external_ids||{},ye=[];ee.cbdb_id!=null&&ye.push({label:"CBDB",id:String(ee.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ee.cbdb_id}`,note:ee.cbdb_match==="auto"?"自動匹配":void 0});const ae=ee.wikidata_id;ae&&ye.push({label:"Wikidata",id:ae,href:`https://www.wikidata.org/wiki/${ae}`});const Te=ee.viaf_id;Te&&ye.push({label:"VIAF",id:Te,href:`https://viaf.org/viaf/${Te}`});const je=y.map(I=>({key:I.cls,label:`${I.label} ${I.count}`})),Ce=[...re&&!pe?[{id:"featured",label:"著作舉要",count:te.length}]:[],...v.length?[{id:"works",label:"全部著作",count:v.length}]:[],...ye.length?[{id:"external",label:"站外資料",count:ye.length}]:[]],Re=re?t.jsxs(Fe,{id:"featured",title:"著作舉要",children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:a("存世版本最多的三部")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":pe||void 0,children:[pe&&[0,1,2].map(I=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},I)),!pe&&te.map(I=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Le,{id:I.id,label:a(I.title),onNavigate:i,renderLink:r,dense:!0})}),t.jsx(Be,{items:[I.section?a(I.section):"",I.measure?a(I.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:I.versionCount}),t.jsx("span",{children:a("種版本")}),I.hasImage&&t.jsx("span",{className:"bim-d-flag",children:a("有影印")})]})]},I.id))]})]}):null,Ie=v.length===0?t.jsx(Fe,{title:"著作",children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("尚未著錄該人物的關聯作品。")})}):t.jsxs(t.Fragment,{children:[Re,t.jsxs(Fe,{id:"works",title:"著作",meta:t.jsx(Be,{items:[a(`共 ${v.length} 種`),j.length!==v.length?a(`當前 ${j.length} 種`):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[je.length>1&&t.jsx(kn,{items:je,value:c,onChange:I=>{u(I),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":m==="versions",onClick:()=>{m==="default"&&x(!0),b(I=>I==="default"?"versions":"default")},children:a(m==="default"?"按版本數排列":"按著錄順序")})]}),t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("作品")}),t.jsx("th",{children:a("部類")}),t.jsx("th",{children:a("職任")}),t.jsx("th",{children:a("存世版本")}),t.jsx("th",{"aria-label":a("影印")})]})}),t.jsx("tbody",{children:_.map(I=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Le,{id:I.id,label:a(I.title),onNavigate:i,renderLink:r,dense:!0}),I.measure?t.jsx(Be,{items:[a(I.measure)]}):!I.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.section||I.loaded?"":" bim-d-zt-blank"}`,children:I.section?a(I.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.role?"":" bim-d-zt-blank"}`,children:I.role?a(I.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${I.loaded?"":" bim-d-zt-blank"}`,children:I.loaded?I.versionCount?a(`${I.versionCount} 種`):t.jsx("span",{className:"bim-d-zt-empty",children:a("未著錄")}):""}),t.jsx("td",{className:I.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:I.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:a("有影印")})})]},I.id))})]}),_.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:a("該職任下的著作尚未著錄。")}),j.length>_.length&&t.jsx(Nt,{label:`展開其餘 ${j.length-_.length} 種著作`,onClick:()=>x(!0)})]})]}),D=ye.length>0?t.jsx(mt,{id:"external",title:"站外資料",items:ye.map(I=>t.jsxs("a",{href:I.href,target:"_blank",rel:"noopener noreferrer",children:[I.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:ye.map(I=>I.id),foot:ee.cbdb_id!=null&&ee.cbdb_match==="auto"?a("CBDB 為自動匹配,未經人工核對"):void 0}):null;return t.jsx(qt,{railTop:s,back:l,nav:Ce,railLinks:d,main:Ie,card:H,side:D})},Di="(max-width: 719px)",zu=`${Di}, (pointer: coarse)`,nl=`
|
|
732
732
|
.bim-ct {
|
|
733
733
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
734
734
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|