book-index-ui 0.2.7 → 0.2.9
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 +3 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2753 -2543
- package/dist/{storage-entry-2AJlDQPr.cjs → storage-entry-D_ldU5TV.cjs} +1 -1
- package/dist/{storage-entry-BiThJ6BH.js → storage-entry-DwmBQz5U.js} +81 -63
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +8 -0
- package/dist/storage.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var dn=Object.create;var Je=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var xn=Object.getOwnPropertyNames;var un=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var gn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of xn(n))!fn.call(t,i)&&i!==o&&Je(t,i,{get:()=>n[i],enumerable:!(r=pn(n,i))||r.enumerable});return t};var hn=(t,n,o)=>(o=t!=null?dn(un(t)):{},gn(n||!t||!t.__esModule?Je(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-2AJlDQPr.cjs"),e=require("react/jsx-runtime"),f=require("react"),bn=require("react-dom"),mn=t=>`/book-index?id=${t}`,zt=f.createContext(mn);function yn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(zt.Provider,{value:o,children:n})}function re(){return f.useContext(zt)}const ze=f.createContext(null),It={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},vn={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"实体资源"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"实体"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},jn={"zh-Hant":It,"zh-Hans":vn},Tt="bim-locale";function Sn(){try{const t=localStorage.getItem(Tt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function kn(t){try{localStorage.setItem(Tt,t)}catch{}}const wn="zh-Hant",Cn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=f.useState(t??wn),l=t??r;f.useEffect(()=>{if(t)return;const d=Sn();d&&d!==r&&i(d)},[]);const[s,c]=f.useState(null);f.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(d=>{const p=d.Converter({from:"tw",to:"cn"});c(()=>p)}).catch(()=>{c(()=>d=>d)}):c(null)},[l]);const a=f.useCallback(d=>{i(d),kn(d),n==null||n(d)},[n]),u=f.useMemo(()=>({locale:l,setLocale:a,messages:jn[l],converter:s}),[l,a,s]);return e.jsx(ze.Provider,{value:u,children:o})};function A(){const t=f.useContext(ze);return(t==null?void 0:t.messages)??It}const _n=2e3;function D(){const t=f.useContext(ze),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),i=f.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=f.useCallback(s=>{if(!s)return"";if(!o)return s;const c=r.current.get(s);if(c!==void 0)return c;const a=o(s);if(r.current.size>=_n){const u=r.current.keys().next().value;u!==void 0&&r.current.delete(u)}return r.current.set(s,a),a},[o]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Ie(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function zn(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function In(){return{id:"",name:"",url:"",type:"text",details:""}}const Ue=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=A(),[s,c]=f.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],d=m=>i?i==="text"?m==="text"||m==="text+image":i==="image"?m==="image"||m==="text+image"||m==="physical":m===i:!0,p=t.map((m,v)=>({item:m,originalIndex:v})).filter(({item:m})=>d(m.type)),h=()=>{const m=In();i&&(m.type=i),n([...t,m]),c(t.length)},x=m=>{n(t.filter((v,b)=>b!==m)),c(null)},y=(m,v,b)=>{const z=[...t];if(z[m]={...z[m],[v]:b},v==="url"&&!z[m].id){const k=zn(b);k&&(z[m].id=k)}n(z)},j=(m,v,b)=>{const k={...t[m].metadata||{}};b?k[v]=b:delete k[v],y(m,"metadata",Object.keys(k).length>0?k:void 0)},g=(m,v)=>{const b=v.trim()?v.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;y(m,"structure",b)},I=(m,v,b)=>{const k=t[m].coverage||{level:1,ranges:""};v==="level"?k.level=parseInt(b)||1:k.ranges=b,y(m,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.map(({item:m,originalIndex:v})=>{var b,z,k,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(s===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Tn(m.type),color:"#fff"},children:((b=a.find(C=>C.value===m.type))==null?void 0:b.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${l.editor.resourcePlaceholder} ${v+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:C=>C.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Rn(v,r==null?void 0:r[v],o,l),e.jsx("button",{onClick:C=>{C.stopPropagation(),x(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),s===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&Ln(m,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.type}),e.jsx("select",{value:m.type,onChange:C=>y(v,"type",C.target.value),style:{...ae,flex:1},children:a.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:C=>y(v,"root_type",C.target.value),style:{...ae,flex:1},children:u.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:C=>y(v,"id",C.target.value),placeholder:l.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:C=>y(v,"name",C.target.value),placeholder:l.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:C=>y(v,"url",C.target.value),placeholder:l.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((z=m.structure)==null?void 0:z.join("、"))||"",onChange:C=>g(v,C.target.value),placeholder:l.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=m.coverage)==null?void 0:k.level)??"",onChange:C=>I(v,"level",C.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...je,flex:1},children:[e.jsx("span",{style:Se,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:C=>I(v,"ranges",C.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:C=>y(v,"details",C.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ae,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([C,B])=>{var R;return e.jsxs("label",{style:{...je,gap:"4px"},children:[e.jsx("span",{style:{...Se,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((R=m.metadata)==null?void 0:R[C])||"",onChange:E=>j(v,C,E.target.value),placeholder:B,style:{...ae,flex:1}})]},C)})})]})]})]})]},v)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:l.action.addResource})]})]})};function Tn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Rn(t,n,o,r){const i=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:s=>{s.stopPropagation(),i||o(t,"")},disabled:i,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:l?r.download.completed:i?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":i?"⏳":"⬇"})}function Ln(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ae={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},je={display:"flex",alignItems:"center",gap:"6px"},Se={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},En={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Bn(t){try{const n=new URL(t).hostname;return En[n]}catch{return}}const Ze={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},Wn=["text","image","text+image","physical"];function $n(t){const n=l=>{const s=l.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const c=l.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const s=t[l];if(s.volumes&&s.volumes.length>0)continue;const c=n(s.name);if(!c)continue;const[a,u]=c,d=`${a}|${s.type}`;o.has(d)||o.set(d,{base:{...s,name:a,url:"",volumes:[]},volumes:[]}),o.get(d).volumes.push({volume:u,url:s.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((s,c)=>s.volume-c.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let s=0;s<t.length;s++)if(i.has(s)){const c=n(t[s].name);c&&`${c[0]}|${t[s].type}`==`${l.base.name}|${l.base.type}`&&i.delete(s)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const Ye=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const i=A(),l=f.useMemo(()=>$n(t||[]),[t]),s={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical};if(!l||l.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:l.map((a,u)=>e.jsx(Qe,{item:a},a.id||u))});const c=Wn.map(a=>({type:a,items:l.filter(u=>u.type===a)})).filter(a=>a.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:c.map(({type:a,items:u})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ze[a],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ze[a]}}),s[a],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",u.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:u.map((d,p)=>e.jsx(Qe,{item:d,onNavigate:o,renderLink:r},d.id||p))})]},a))})},Xe=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},Rt=({value:t})=>{const o=A().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},An=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Rt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function Pn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const i=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(i)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(i[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function Fn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function Mn(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const Dn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Qe=({item:t,onNavigate:n,renderLink:o})=>{var j;const r=A(),{convert:i}=D(),l=re(),[s,c]=f.useState(!1),a=f.useMemo(()=>(t.url?Bn(t.url):void 0)||i(t.name),[t.url,t.name,i]),u=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(g=>({...g,url:g.url||Mn(g)})),[t.volumes]),d=u&&u.length>0,p=d?new Set(u.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,h=d?new Set(u.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,x=t.expected_volumes??(d?p+h:0),y=t.color_mode?{...Dn[t.color_mode],label:r.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:Xe(t)||d?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a}),y&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:y.bg,color:y.fg},children:y.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((j=t.metadata)==null?void 0:j.check_type)&&e.jsx(Rt,{value:t.metadata.check_type}),d&&e.jsxs("span",{style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)"},children:[p,"/",x,r.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=Fn(t.metadata);return g?Pn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:r.action.visit}),d&&e.jsx("button",{onClick:()=>c(!s),title:s?"收起分册":"展开分册",style:{marginLeft:"auto",padding:"1px 10px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:s?"var(--bim-widget-border, #e0e0e0)":"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",lineHeight:1.4},children:s?"收起 ▲":"展开 ▼"})]}),Xe(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([g])=>g!=="check_type").map(([g,I])=>e.jsxs("span",{children:[r.metadata[g]||g,": ",An(g,I,r,i)]},g)),t.details&&!d&&e.jsx("span",{children:i(t.details)}),t.structure&&e.jsxs("span",{children:[r.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[r.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),d&&s&&(()=>{const g=u.some(v=>v.group),I=[];if(g){let v=null;for(const b of u){const z=b.group||"";(!v||v.title!==z)&&(v={title:z,group_id:b.group_id,vols:[]},I.push(v)),v.vols.push(b)}}else I.push({vols:u});const m=v=>{const b=v.status==="missing";return v.url&&!b?e.jsx("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:v.label||`${v.volume}`,children:v.volume},v.volume):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:b?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:b?"line-through":"none",opacity:b?.6:1,lineHeight:1.4},children:v.volume},v.volume)};return e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexDirection:"column",gap:"8px"},children:I.map((v,b)=>{const z=v.title?i(v.title):"";let k=z;return v.title&&v.group_id&&(o?k=o(v.group_id,z):n&&(k=e.jsx("a",{href:l(v.group_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),n(v.group_id))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:w=>w.currentTarget.style.borderBottomStyle="solid",onMouseLeave:w=>w.currentTarget.style.borderBottomStyle="dashed",children:z}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[k,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(m)})]},b)})})})()]})},Lt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:s})=>{const c=A(),a=t==="local",u=(n==null?void 0:n.isDraft)??!0,d=(n==null?void 0:n.repoPath)||"",p=d?d.split(/[/\\]/).pop()||d:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},x={onMouseOver:j=>j.currentTarget.style.opacity="0.8",onMouseOut:j=>j.currentTarget.style.opacity="1"},y=e.jsxs("div",{onClick:i,title:u?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...x,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[y,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:s,title:d||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[y,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:p||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:s,title:d||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:d?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!a&&p&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:d,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:p})]})]})},$e="bim-search-history",et=10,tt=8;function we(){try{const t=localStorage.getItem($e);return t?JSON.parse(t):[]}catch{return[]}}function Hn(t){try{const n=we().filter(o=>o!==t);n.unshift(t),n.length>et&&(n.length=et),localStorage.setItem($e,JSON.stringify(n))}catch{}}function On(t){try{const n=we().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function Un(){try{localStorage.removeItem($e)}catch{}}const Et=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const s=A(),c=l??s.search.placeholder,a={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection,entity:s.indexType.entity},[u,d]=f.useState(!1),[p,h]=f.useState([]),[x,y]=f.useState(-1),[j,g]=f.useState(null),[I,m]=f.useState(we),v=f.useRef(null),b=f.useRef(null),z=f.useRef(null);f.useEffect(()=>{if(!t.getAllEntries)return;let _=!1;return t.getAllEntries().then($=>{_||g($)}).catch(()=>{}),()=>{_=!0}},[t]);const k=f.useCallback(_=>{if(!_.trim())return I.map(S=>({type:"history",text:S}));if(!j)return[];const $=_.toLowerCase(),W=[],U=[];for(const S of j){if(W.length+U.length>=tt*2)break;const L=(S.title??"").toLowerCase();if(L.startsWith($))W.push({type:"entry",text:S.title,entry:S});else if(L.includes($))U.push({type:"entry",text:S.title,entry:S});else{const K=[...S.additional_titles||[],...S.attached_texts||[]];for(const V of K){const F=typeof V=="string"?V:V==null?void 0:V.book_title;if(F!=null&&F.toLowerCase().includes($)){W.push({type:"entry",text:`${S.title}`,entry:S});break}}}}return[...W,...U].slice(0,tt)},[j,I]);f.useEffect(()=>{h(k(n)),y(-1)},[n,k]),f.useEffect(()=>{const _=$=>{z.current&&!z.current.contains($.target)&&d(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]),f.useEffect(()=>{const _=$=>{var W,U;if($.key==="/"&&document.activeElement!==v.current){const S=(W=document.activeElement)==null?void 0:W.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;$.preventDefault(),(U=v.current)==null||U.focus()}};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[]);const w=f.useCallback(_=>{_.trim()&&(Hn(_.trim()),m(we())),r(_),d(!1)},[r]),C=f.useCallback(_=>{_.type==="history"?(o(_.text),w(_.text)):_.entry&&(i?(i(_.entry),d(!1)):(o(_.text),w(_.text)))},[o,w,i]),B=f.useCallback(_=>{if(!u||p.length===0){_.key==="Enter"&&w(n);return}switch(_.key){case"ArrowDown":_.preventDefault(),y($=>($+1)%p.length);break;case"ArrowUp":_.preventDefault(),y($=>($-1+p.length)%p.length);break;case"Enter":_.preventDefault(),x>=0&&x<p.length?C(p[x]):w(n);break;case"Escape":_.preventDefault(),d(!1);break}},[u,p,x,n,w,C]),R=f.useCallback((_,$)=>{$.stopPropagation(),On(_),m(we()),h(W=>W.filter(U=>!(U.type==="history"&&U.text===_)))},[]),E=f.useCallback(_=>{_.stopPropagation(),Un(),m([]),h([])},[]);f.useEffect(()=>{if(x>=0&&b.current){const _=b.current.children;_[x]&&_[x].scrollIntoView({block:"nearest"})}},[x]);const H=!n.trim()&&I.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:c,value:n,onChange:_=>{o(_.target.value),d(!0)},onFocus:()=>d(!0),onKeyDown:B,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),u&&p.length>0&&e.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[H&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:s.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),p.map((_,$)=>e.jsxs("div",{onClick:()=>C(_),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===x?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:_.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.text}),_.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[_.entry.type],_.entry.edition&&` · ${_.entry.edition}`,_.entry.author&&` · ${_.entry.author}`]}),_.type==="history"&&e.jsx("button",{onClick:W=>R(_.text,W),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:s.action.remove,children:"×"})]},`${_.type}-${_.text}-${$}`))]})]})},_e="bim-recent-ids",nt="bim-recent-entries",rt=50,De=5,Vn=50,Kn=200;function Ce(){try{const t=localStorage.getItem(_e);if(t)return JSON.parse(t);const n=localStorage.getItem(nt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(_e,JSON.stringify(o)),localStorage.removeItem(nt),o}return[]}catch{return[]}}function Nn(t){try{const n=Ce().filter(o=>o!==t);n.unshift(t),n.length>rt&&(n.length=rt),localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Yn(t){try{const n=Ce().filter(o=>o!==t);localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Gn(){try{localStorage.removeItem(_e)}catch{}}const qn={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Ve=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:u,initialQuery:d,onQueryChange:p,headerRight:h})=>{const x=A(),y=[{type:"work",icon:"✍️",name:x.indexType.work,key:"works"},{type:"book",icon:"📖",name:x.indexType.book,key:"books"},{type:"collection",icon:"📚",name:x.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:x.indexType.entity,key:"entities"}],[j,g]=f.useState(d??""),[I,m]=f.useState(null),[v,b]=f.useState(null),[z,k]=f.useState(!1),[w,C]=f.useState(null),[B,R]=f.useState(""),[E,H]=f.useState(!d),[_,$]=f.useState(Ce),[W,U]=f.useState([]),[S,L]=f.useState(!1),[K,V]=f.useState(!1),[F,le]=f.useState(null),[Q,de]=f.useState(null),ue=f.useRef(void 0),xe=f.useRef(!1),J=f.useCallback(async(P,Y)=>{if(!P.trim()){H(!0),m(null),b(null);return}H(!1),k(!0),R("");try{if(t.searchAll){const Z=await t.searchAll(P,Y??De);m(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(P,te,{page:1,pageSize:Y??De})));m({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(Z){R(Z instanceof Error?Z.message:String(Z)),m(null)}finally{k(!1)}},[t]);f.useEffect(()=>{var T,M;let P=!1;const Y=["work","book","collection","entity"],Z=Promise.all(Y.map(q=>t.loadEntries(q,{page:1,pageSize:1}).catch(()=>({total:0})))),G=((T=t.getResourceCounts)==null?void 0:T.call(t).catch(()=>null))??Promise.resolve(null),te=((M=t.getSubtypeStats)==null?void 0:M.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([q,se,he])=>{P||(le({works:q[0].total,books:q[1].total,collections:q[2].total,entities:q[3].total,hasText:se==null?void 0:se.hasText,hasImage:se==null?void 0:se.hasImage}),he&&de(he))}),()=>{P=!0}},[t]),f.useEffect(()=>{xe.current||!(d!=null&&d.trim())||(xe.current=!0,J(d))},[d,J]);const N=f.useCallback(P=>{if(g(P),p==null||p(P),!P.trim()){H(!0),m(null),b(null);return}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>{b(null),J(P)},Kn)},[J,p]),Ae=f.useCallback(P=>{ue.current&&clearTimeout(ue.current),p==null||p(P),J(P)},[J,p]),Pe=f.useCallback(P=>{b(P),J(j,Vn)},[j,J]);f.useEffect(()=>{if(!_.length){U([]);return}let P=!1;return L(!0),Promise.all(_.slice(0,10).map(async Y=>{var Z,G,te;try{if(t.getEntry){const M=await t.getEntry(Y);if(M)return M}const T=await t.getItem(Y);if(T){const M=T.authors;return{id:Y,title:T.title||Y,type:T.type||"work",author:(Z=M==null?void 0:M[0])==null?void 0:Z.name,dynasty:(G=M==null?void 0:M[0])==null?void 0:G.dynasty,role:(te=M==null?void 0:M[0])==null?void 0:te.role,edition:T.edition||void 0}}}catch{}return{id:Y,title:Y,type:"work",notFound:!0}})).then(Y=>{P||(U(Y),L(!1))}),()=>{P=!0}},[_,t]);const ye=P=>{C(P.id),Nn(P.id),$(Ce()),r==null||r(P)},ve=P=>{Yn(P),$(Ce())},Fe=()=>{Gn(),$([])},Te=P=>y.find(Y=>Y.type===P),Me=I&&(I.works.length>0||I.books.length>0||I.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:x.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&e.jsx(Lt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Et,{transport:t,value:j,onChange:N,onSearch:Ae,onEntrySelect:ye}),i&&e.jsx("button",{onClick:()=>i("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:x.action.newEntry})]}),F&&E&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[x.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()}),F.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.entities.toLocaleString()})]})]})}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[x.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.searching}):B?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):E?e.jsx("div",{style:{flex:1},children:S?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.loading}):W.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:x.search.recentBrowse}),e.jsx("button",{onClick:Fe,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:x.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:W.slice(0,K?10:3).map(P=>P.notFound?e.jsx(Jn,{id:P.id,onRemove:ve,t:x},P.id):e.jsx(ot,{entry:P,selected:w===P.id,onClick:ye,getConfig:Te,onRemove:ve},P.id))}),!K&&W.length>3&&e.jsx("button",{onClick:()=>V(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:x.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:x.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.searchSubtitle})]})}):Me?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:y.map(({type:P,icon:Y,name:Z,key:G})=>{const te=I[G]??[],T=qn[G],M=I[T]??0;if(te.length===0)return null;const se=!(v===P)&&M>De;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[Y," ",Z,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[M," ",x.unit.items]})]}),se&&e.jsx("button",{onClick:()=>Pe(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:x.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(he=>e.jsx(ot,{entry:he,selected:w===he.id,onClick:ye,getConfig:Te,query:j},he.id))})]},P)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Ie(x.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.tryOther})]})})]})},ot=({entry:t,selected:n,onClick:o,getConfig:r,query:i,onRemove:l})=>{const s=A(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],u=i&&a.length?a.find(d=>{const p=typeof d=="string"?d:d==null?void 0:d.book_title;return p==null?void 0:p.toLowerCase().includes(i.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:s.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:s.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,s.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),u&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",c(u)]})]}),l?e.jsx("button",{onClick:d=>{d.stopPropagation(),l(t.id)},title:s.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},Jn=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Zn(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function Xn({data:t}){const{convert:n}=D(),{dynasty:o,birth_year:r,death_year:i}=t,l=[];return o&&l.push(`〔${n(o)}〕`),r!==void 0&&i!==void 0?l.push(`${r}—${i}`):r!==void 0?l.push(`${r}—?`):i!==void 0&&l.push(`?—${i}`),l.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:l.join(" ")})}function Qn({alt_names:t}){const{convert:n}=D(),o=new Map;for(const l of t){const s=l.type||"別名";o.has(s)||o.set(s,[]),o.get(s).push(l.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],i=[...o.keys()].sort((l,s)=>{const c=r.indexOf(l),a=r.indexOf(s);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:i.map(l=>{const s=o.get(l);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:l}),e.jsx("span",{children:s.map((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},l)})})}function er({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function tr({works:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),{convert:l}=D(),s=re(),[c,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let h=!1;const x=t.map(j=>j.work_id);return(async()=>{const j=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(x);let b=!0;for(let z=0;z<x.length;z++){const k=v[z];k!=null&&k.title?j.set(x[z],k.title):k!=null&&k.primary_name?j.set(x[z],k.primary_name):b=!1}if(b)return j}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),b=new Map(v.map(k=>[k.id,k.title||k.primary_name||k.id]));let z=!0;for(const k of x){const w=b.get(k);w?j.set(k,w):z=!1}if(z)return j}catch{}const g=[...x],I=8,m=new Array(I).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!j.has(v))try{if(n.getEntry){const k=await n.getEntry(v);if(k!=null&&k.title){j.set(v,k.title);continue}}const b=await n.getItem(v),z=b&&(b.title||b.primary_name)||v;j.set(v,z)}catch{j.set(v,v)}}});return await Promise.all(m),j})().then(j=>{h||a(j)}),()=>{h=!0}},[t,n]);const u=new Map;for(const h of t){const x=h.role||"";u.has(x)||u.set(x,[]),u.get(x).push(h)}const d=["撰","編","注","輯","集","校","評","譯","述","作",""],p=[...u.keys()].sort((h,x)=>{const y=d.indexOf(h),j=d.indexOf(x);return y===-1&&j===-1?h.localeCompare(x):y===-1?1:j===-1?-1:y-j});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),p.map(h=>{const x=u.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[l(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.map((y,j)=>{const g=l(c.get(y.work_id)||y.work_id);return r?e.jsx("li",{children:r(y.work_id,g)},j):o?e.jsx("li",{children:e.jsx("a",{href:s(y.work_id),onClick:I=>{I.metaKey||I.ctrlKey||(I.preventDefault(),o(y.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},j):e.jsx("li",{children:g},j)})})]},h)})]})}const Bt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:i})=>{var d;const l=A(),{convert:s}=D();let c=!1;try{c=O.extractStatus(t.id)==="draft"}catch{}const a=Zn(t),u=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[s(t.primary_name),e.jsx(Xn,{data:t})]}),i]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:l.indexType.entity}),u&&t.subtype!=="people"&&e.jsx("span",{children:u}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),a&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Qn,{alt_names:t.alt_names}),e.jsx(er,{data:t}),((d=t.description)==null?void 0:d.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:s(t.description.text)}),t.works&&t.works.length>0&&e.jsx(tr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},nr=["〇","一","二","三","四","五","六","七","八","九"],it=["","十","百","千"];function Wt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",i=!1;for(let l=0;l<o;l++){const s=parseInt(n[l]),c=o-1-l;s===0?i=!0:(i&&r&&(r+="〇"),i=!1,s===1&&c===1&&l===0?r+=it[c]:r+=nr[s]+it[c])}return r}function $t({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function rr({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function or({id:t}){const n=A(),[o,r]=f.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ne({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function ce({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function At({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:i}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((l,s)=>{const c=i(l.name),a=l.entity_id?e.jsx(ie,{id:l.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[s>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),l.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",i(l.dynasty),"〕"]}),a,l.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",i(l.role)]})]},s)})})}function ie({id:t,label:n,onNavigate:o,renderLink:r}){const i=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ir({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:s,meta:c,headerExtra:a,onNavigate:u,renderLink:d}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),s&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx($t,{type:r}),e.jsx(rr,{isDraft:i}),e.jsx(or,{id:t})]}),((l==null?void 0:l.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(At,{authors:l,type:r,onNavigate:u,renderLink:d}),c]})]})}function Pt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:i}){const l=A(),{convert:s}=D();if(!t.length)return null;const[c,a]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((u,d)=>{const p=c===d;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...p?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(p?null:d),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:s(u.source)}),!p&&o&&u.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s(u.title_info)}),u.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ie,{id:u.source_bid,label:l.action.view,onNavigate:r,renderLink:i})})]}),p&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(u.title_info||u.author_info||u.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[u.title_info&&e.jsx(ce,{label:l.label.titleInfo,children:s(u.title_info)}),u.author_info&&e.jsx(ce,{label:l.label.authorInfo,children:s(u.author_info)}),u.edition&&e.jsx(ce,{label:l.label.edition,children:s(u.edition)})]}),u.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:l.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:s(u.summary)})]}),u.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:l.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.comment)})]}),u.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:l.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(u.additional_comment)})]})]})]},d)})})]})}function lr({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ft({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Mt({label:t,items:n}){const{convert:o}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,i)=>{const l=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(l)},i)})})]}):null}function sr({items:t}){const n=A();return e.jsx(Mt,{label:n.section.aliases,items:t})}function ar({items:t}){const n=A();return e.jsx(Mt,{label:n.section.attachedTexts,items:t})}function cr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,i)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},i))})]}):null}function dr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,i)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},i))]})]}):null}function pr({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,i)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},i))})]}):null}function lt({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=D(),[s,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(u=>({id:u})));return}let a=!1;return Promise.all(n.map(u=>o.getItem(u).then(d=>({id:u,title:d?d.title:void 0,edition:d?d.edition:void 0,type:d?d.type:void 0})).catch(()=>({id:u})))).then(u=>{a||c(u)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(s.length?s:n.map(a=>({id:a}))).map(a=>{const u=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ie,{id:a.id,label:u,onNavigate:r,renderLink:i})},a.id)})})]}):null}function xr({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D(),[l,s]=f.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?i(t.edition):i(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:c&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ie,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>s(u=>!u),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Ye,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function ur({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),[l,s]=f.useState([]);return f.useEffect(()=>{if(!t.length){s([]);return}if(!n){s(t.map(a=>({id:a})));return}let c=!1;return Promise.all(t.map(a=>n.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:a})))).then(a=>{c||s(a)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(l.length?l:t.map(c=>({id:c}))).map(c=>e.jsx(xr,{book:c,onNavigate:o,renderLink:r},c.id))})]}):null}function fr({workData:t,onNavigate:n,renderLink:o}){var l,s,c;const r=A(),{convert:i}=D();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx($t,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ie,{id:t.id,label:i(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:i(t.measure_info)}):((l=t.juan_count)==null?void 0:l.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Wt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(At,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(c=t.authors)!=null&&c.length?"8px 0 0":"0",textAlign:"justify"},children:i(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(ce,{label:r.label.parentWork,children:e.jsx(ie,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function gr({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(ie,{id:l.id,label:i(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ie(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Ge=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:s,style:c})=>{var E,H,_,$,W,U;const a=A(),{convert:u}=D(),[d,p]=f.useState(null),[h,x]=f.useState(!1),[y,j]=f.useState(null),[g,I]=f.useState(null),[m,v]=f.useState([]),b=t||d;if(f.useEffect(()=>{if(t||!n||!o)return;let S=!1;return x(!0),j(null),o.getItem(n).then(L=>{S||(L?p(L):j(a.misc.notFoundEntry))}).catch(L=>{S||j(L instanceof Error?L.message:a.misc.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o]),f.useEffect(()=>{if(!b||!o){I(null),v([]);return}let S=!1;const L=b.type==="book"||b.type==="collection"?b.work_id:void 0;if(L?o.getItem(L).then(K=>{!S&&K&&K.type==="work"&&I(K)}).catch(()=>{}):I(null),b.type==="book"){const K=b;K.contained_in&&K.contained_in.length>0?Promise.all(K.contained_in.map(V=>{const F=typeof V=="string"?V:V.id,le=typeof V=="string"?void 0:V.volume_index;return o.getItem(F).then(Q=>({id:F,title:Q&&Q.title||F,volume_index:le})).catch(()=>({id:F,title:F,volume_index:le}))})).then(V=>{S||v(V)}):v([])}else v([]);return()=>{S=!0}},[b,o]),h)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((S,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${S}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(y)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!b)return null;if(b.type==="entity")return e.jsx("div",{className:s,style:c,children:e.jsx(Bt,{data:b,transport:o,onNavigate:r,renderLink:i,headerExtra:l})});const z=b.type==="book"?b:null,k=b.type==="collection"?b:null,w=b.type==="work"?b:null;let C=!1;try{C=O.extractStatus(b.id)==="draft"}catch{}let B="";b.measure_info?B=u(b.measure_info):(E=b.juan_count)!=null&&E.number?B=Wt(b.juan_count.number)+a.unit.juan:(H=b.juan_count)!=null&&H.description&&(B=u(b.juan_count.description));const R=[];return(_=b.publication_info)!=null&&_.year&&R.push(e.jsx(ce,{label:a.label.year,children:b.publication_info.year},"year")),($=b.current_location)!=null&&$.name&&R.push(e.jsx(ce,{label:a.label.currentLocation,children:u(b.current_location.name)},"loc")),(W=b.page_count)!=null&&W.description&&R.push(e.jsx(ce,{label:a.label.pageCount,children:b.page_count.description},"page")),z!=null&&z.edition&&R.push(e.jsx(ce,{label:a.label.edition,children:u(z.edition)},"ver")),w!=null&&w.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:e.jsx(ie,{id:w.parent_work.id,label:u(w.parent_work.title),onNavigate:r,renderLink:i})},"pw")),w!=null&&w.parent_works&&w.parent_works.length>0&&!w.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:w.parent_works.map((S,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(ie,{id:S,onNavigate:r,renderLink:i})]},S))},"pws")),e.jsxs("div",{className:s,style:c,children:[e.jsx(ir,{id:b.id,title:u(b.title),edition:b.edition?u(b.edition):void 0,type:b.type,isDraft:C,authors:b.authors,volumeText:B,meta:R,headerExtra:l,onNavigate:r,renderLink:i}),((U=b.description)==null?void 0:U.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(b.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.containedIn}),e.jsx(gr,{items:m,onNavigate:r,renderLink:i})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.belongsToWork}),e.jsx(fr,{workData:g,onNavigate:r,renderLink:i})]}),b.additional_works&&b.additional_works.length>0&&e.jsx(cr,{items:b.additional_works}),b.additional_titles&&b.additional_titles.length>0&&e.jsx(sr,{items:b.additional_titles}),b.attached_texts&&b.attached_texts.length>0&&e.jsx(ar,{items:b.attached_texts}),b.indexed_by&&b.indexed_by.length>0&&e.jsx(lr,{items:b.indexed_by,onNavigate:r,renderLink:i}),b.emendated_by&&b.emendated_by.length>0&&e.jsx(Ft,{items:b.emendated_by,onNavigate:r,renderLink:i}),b.resources&&b.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.resources}),e.jsx(Ye,{items:b.resources,groupByType:!0,onNavigate:r,renderLink:i})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(dr,{items:z.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(pr,{items:k.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(lt,{title:a.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:i}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(lt,{title:a.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:i}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[a.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(S=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ie,{id:S.id,label:u(S.title),onNavigate:r,renderLink:i})},S.id))})]}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(ur,{ids:w.books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.related_works)&&w.related_works.length>0&&(()=>{const S=[],L=w.related_works.filter(F=>F.relation==="part_of"),K=w.related_works.filter(F=>F.relation==="has_part"),V=w.related_works.filter(F=>!F.relation);return L.length>0&&S.push({label:a.section.belongsToWork,items:L}),K.length>0&&S.push({label:a.section.containedWorks,items:K}),V.length>0&&S.push({label:a.section.relatedWorks,items:V}),S.map(F=>e.jsxs("div",{children:[e.jsxs(ne,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(le=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ie,{id:le.id,label:u(le.title),onNavigate:r,renderLink:i})},le.id))})]},F.label))})()]})};function hr({data:t}){const n=A(),{convert:o}=D(),{stats:r}=t,i=r.processed_volumes??r.total_found_volumes,l=i!=null&&t.total_volumes>0?Math.round(i/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function br({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:st(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:st(n===i.name),children:[i.name,i.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function st(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function mr({id:t,label:n,onNavigate:o,renderLink:r}){const i=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function yr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function at({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=A(),{convert:l}=D(),s=t.book_id||t.work_id,c=r&&t.volumes.length>0?yr(t.volumes,i.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[l(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(u=>l(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),s&&e.jsx(mr,{id:s,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!s&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const Dt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:s})=>{const c=A(),[a,u]=f.useState(null),[d,p]=f.useState(!1),[h,x]=f.useState(null),[y,j]=f.useState(null),[g,I]=f.useState(""),m=t||a;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let w=!1;return p(!0),x(null),o.getCollectionCatalog(n).then(C=>{w||(C?u(C):x(c.catalog.notFound))}).catch(C=>{w||x(C instanceof Error?C.message:c.catalog.loadFailed)}).finally(()=>{w||p(!1)}),()=>{w=!0}},[t,n,o,c]);const v=(m==null?void 0:m.sections)&&m.sections.length>0,b=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const w=m.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[m]),z=f.useMemo(()=>{if(!m)return[];let w=m.books;if(y&&(w=w.filter(C=>C.section===y)),g.trim()){const C=g.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(C)||B.sub_items&&B.sub_items.some(R=>R.toLowerCase().includes(C))||B.edition&&B.edition.toLowerCase().includes(C))}return w},[m,y,g]),k=f.useMemo(()=>{if(!b)return null;const w=[],C=new Map;for(const R of z){if(!R.volumes||R.volumes.length===0)continue;const E=R.volumes[0];C.has(E)||C.set(E,[]),C.get(E).push(R)}const B=[...C.keys()].sort((R,E)=>R-E);for(const R of B)w.push({volume:R,books:C.get(R)});return w},[z,b]);return d?e.jsx("div",{className:l,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):h?e.jsx("div",{className:l,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:l,style:s,children:[e.jsx(hr,{data:m}),v&&e.jsx(br,{sections:m.sections,activeSection:y,onSelect:j}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:w=>I(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[z.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((w,C)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Ie(c.catalog.volume,{n:w.volume})}),w.books.map((B,R)=>e.jsx(at,{book:B,onNavigate:r,renderLink:i,showVolumes:B.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${C}`)):z.map((w,C)=>e.jsx(at,{book:w,onNavigate:r,renderLink:i,showVolumes:!0},C)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Ht={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},vr={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},jr={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},ge=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Re=7,Sr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:i=280,wrapperStyle:l})=>{const[s,c]=f.useState(!1),[a,u]=f.useState(null),d=f.useRef(null),p=f.useRef(null),h=f.useRef(null),x=f.useCallback(()=>{const g=p.current,I=h.current;if(!g||!I)return;const m=g.getBoundingClientRect(),v=I.getBoundingClientRect(),b=window.innerHeight,z=document.documentElement.clientWidth;let k=o;o==="top"&&m.top-v.height-Re<8&&(k="bottom"),o==="bottom"&&m.bottom+v.height+Re>b-8&&(k="top");const w=k==="top"?m.top-v.height-Re:m.bottom+Re;let C=m.left+m.width/2-v.width/2;C=Math.max(8,Math.min(C,z-v.width-8)),u({left:C,top:w,placement:k})},[o]),y=f.useCallback(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>c(!0),r)},[r]),j=f.useCallback(()=>{d.current&&clearTimeout(d.current),c(!1),u(null)},[]);return f.useEffect(()=>{if(!s)return;const g=requestAnimationFrame(x);return()=>cancelAnimationFrame(g)},[s,x]),f.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:p,onMouseEnter:y,onMouseLeave:j,onFocus:y,onBlur:j,style:{display:"inline-block",...l},children:n}),s&&bn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:i,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-X,width:0,height:0,...a.placement==="top"?{bottom:-X,borderTop:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}:{top:-X,borderBottom:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}:{top:-5,borderBottom:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}}})]})]}),document.body)]})},ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function kr(t){return typeof t!="string"?null:t in Ht?t:t in ct?ct[t]:null}const wr=["〇","一","二","三","四","五","六","七","八","九"],dt=["","十","百","千"],Cr=["","萬","億"];function Ot(t){if(t===0)return"〇";if(t<0)return`負${Ot(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(_r(i,r>0)+Cr[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function _r(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let i="";for(let l=0;l<o.length;l++){const s=o[l],c=o.length-1-l;s===0?i&&!i.endsWith("〇")&&(i+="〇"):s===1&&c===1&&l===0&&!n?i+=dt[c]:i+=wr[s]+dt[c]}return i.replace(/〇$/,"")}const qe={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},zr={考证:"#5d6d7e"};function Ir(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Ut({file:t,isActive:n,onSelect:o,meta:r}){return e.jsxs("button",{onClick:()=>o(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:[Ir(t),(r==null?void 0:r.vol_label)&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]})]})}function Vt(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Vt(r,n)))}function Kt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+Kt(l),0))||0;return n+o}function Nt({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:i}){var d;const l=Vt(t,n||""),[s,c]=f.useState(l),a=Kt(t),u=!!((d=t.children)!=null&&d.length);if(f.useEffect(()=>{l&&c(!0)},[l]),t.files.length===1&&!u){const p=t.files[0],h=n===p;return e.jsx("button",{onClick:()=>o(p),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:h?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:h?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:h?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:h?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!s),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:s?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",a,")"]})]}),s&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(p=>e.jsx(Ut,{file:p,isActive:n===p,onSelect:o,meta:i==null?void 0:i[p]},p))}),u&&t.children.map((p,h)=>e.jsx(Nt,{group:p,activeFile:n,onSelect:o,depth:r+1,juanMeta:i},h))]})]})}function Tr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((s,c)=>e.jsx(Nt,{group:s,activeFile:o,onSelect:r,juanMeta:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(s=>e.jsx(Ut,{file:s,isActive:o===s,onSelect:r,meta:i==null?void 0:i[s]},s))})}function Rr({type:t}){const n=qe[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Lr({section:t,onNavigate:n}){const{convert:o}=D(),r=re(),[i,l]=f.useState(!1),s=!!t.summary,c=!!t.comment,a=!!t.additional_comment,u=!!(t.content&&t.content.length>60),d=s||c||a||u,p=!i&&u?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&l(!i),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ot(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(t.author_info||t.author)})]}),!i&&p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:o(p)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:r(t.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),i&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:o(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:o(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o(t.additional_comment)})]}),u&&!s&&!c&&!a&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(t.content)})]})]})}function Er({section:t}){const{convert:n}=D(),[o,r]=f.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(Rr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),i&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${qe[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:n(t.content)})})]})}function Br({section:t}){const{convert:n}=D();if(!t.content&&!t.title)return null;const o=n((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),
|
|
3
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((r,i)=>{if(r.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:n(r.slice(2))},i);if(r.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:n(r.slice(3))},i);if(r.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:n(r.slice(4))},i);if(!r.trim())return i>0&&!o[i-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},i);const l=r.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((s,c)=>s.startsWith("**")&&s.endsWith("**")?e.jsx("strong",{children:n(s.slice(2,-2))},c):n(s))},i)})})}function Fr({sections:t,onNavigate:n}){const{convert:o}=D(),r=re(),i=[];let l=null;for(const s of t)s.type==="类"?(l&&i.push(l),l={category:s.title,categoryContent:s.content||void 0,items:[]}):s.type==="书"?(l||(l={category:"",items:[]}),l.items.push(s)):(s.type==="序"||s.type==="结语")&&(l||(l={category:"",items:[]}),l.items.push(s),s.type==="结语"&&(i.push(l),l=null));return l&&i.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((s,c)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[s.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[o(s.category),s.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:o(s.categoryContent)})]}),s.items.map((a,u)=>a.type==="序"||a.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},u):(a.content?a.title+a.content:a.title,e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&a.work_id?e.jsx("a",{href:r(a.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(a.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(a.title),children:e.jsx("strong",{children:o(a.title)})}):e.jsx("strong",{children:o(a.title)}),a.content&&o(a.content)]},u)))]},c))})}function Mr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:i}=D(),[l,s]=f.useState("catalog"),c=f.useMemo(()=>{if(!o.trim())return t.sections;const d=o.trim().toLowerCase();return t.sections.filter(p=>{var h,x,y,j,g,I;return((h=p.title)==null?void 0:h.toLowerCase().includes(d))||((x=p.book_title)==null?void 0:x.toLowerCase().includes(d))||((y=p.author)==null?void 0:y.toLowerCase().includes(d))||((j=p.author_info)==null?void 0:j.toLowerCase().includes(d))||((g=p.summary)==null?void 0:g.toLowerCase().includes(d))||((I=p.content)==null?void 0:I.toLowerCase().includes(d))})},[t.sections,o]),a=c.filter(d=>d.type==="书").length,u=c.filter(d=>d.type==="詩").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(d=>e.jsx("button",{onClick:()=>s(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:u>0?`${u} 首`:`${a} 部书`})]}),l==="raw"&&(n?e.jsx(Pr,{text:n}):e.jsx(Fr,{sections:c,onNavigate:r})),l==="catalog"&&c.map((d,p)=>d.type==="书"||d.type==="詩"?e.jsx(Lr,{section:d,onNavigate:r},p):d.type==="类"?e.jsx(Er,{section:d},p):e.jsx(Br,{section:d},p)),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Yt(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function pt(t){const n=Yt(t);return n.length>0?n[0]:null}const Gt=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:i,onJuanChange:l,className:s,style:c})=>{const[a,u]=f.useState(null),[d,p]=f.useState(!1),[h,x]=f.useState(null),[y,j]=f.useState(null),[g,I]=f.useState(null),[m,v]=f.useState(!1),[b,z]=f.useState(null),[k,w]=f.useState(""),C=f.useRef(new Map),B=i??y,R=f.useCallback(S=>{j(S),l==null||l(S)},[l]),E=t||a;f.useEffect(()=>{t&&(p(!1),x(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let S=!1;return p(!0),x(null),o.getCollatedEditionIndex(n).then(L=>{if(!S)if(!L)x("未找到整理本数据");else{u(L);const K=pt(L);!i&&K&&R(K)}}).catch(L=>{S||x(L instanceof Error?L.message:"加载失败")}).finally(()=>{S||p(!1)}),()=>{S=!0}},[t,n,o,i,R]),f.useEffect(()=>{const S=t||a;if(S&&!B){const L=pt(S);L&&R(L)}},[t,a,B,R]);const H=n||(E==null?void 0:E.work_id),_=f.useCallback(async S=>{var L;if(!(!H||!(o!=null&&o.getCollatedJuan))){v(!0),I(null),z(null);try{const[K,V]=await Promise.all([o.getCollatedJuan(H,S),((L=o.getCollatedJuanText)==null?void 0:L.call(o,H,S))??Promise.resolve(null)]);I(K),z(V)}catch{I(null),z(null)}finally{v(!1)}}},[H,o]);f.useEffect(()=>{B&&_(B)},[B,_]);const $=S=>{R(S),w("")};if(d)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!E)return null;const W=E.type==="kaozhen",U=Yt(E);return e.jsxs("div",{className:s,style:c,children:[e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:W?e.jsxs(e.Fragment,{children:[E.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:E.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:U.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:E.total_juan})," 卷"]})}),E.text_quality&&(()=>{const S=kr(E.text_quality.grade);return S?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Sr,{content:vr[S],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:jr[S],cursor:"help"},children:Ht[S]})}),E.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",E.text_quality.source_note]})]}):null})()]}),e.jsx(Tr,{files:U,groups:E.juan_groups,activeFile:B,onSelect:$,juanMeta:E.juan_metadata}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:W?"搜索条目、考证内容...":"搜索书名、作者...",value:k,onChange:S=>w(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),m?e.jsx(ge,{}):g?W?e.jsx(Ar,{juan:g,searchQuery:k,onNavigate:r,transport:o,workLabelCache:C}):e.jsx(Mr,{juan:g,rawText:b,searchQuery:k,onNavigate:r}):B?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,E.references&&E.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),E.references.map((S,L)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[L+1,". "]}),S.url?e.jsx("a",{href:S.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:S.title}):e.jsx("span",{children:S.title}),S.author&&e.jsxs("span",{children:[",",S.author]}),S.note&&e.jsxs("span",{children:["。",S.note]})]},L))]})]})},Dr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Hr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Or(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const qt=({items:t,loading:n})=>{const o=re();return n?e.jsx(ge,{}):t.length===0?e.jsx("div",{style:Ur,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const i=Dr[r.type],l=Hr[r.status];return e.jsxs("div",{style:Vr,children:[e.jsxs("div",{style:Kr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...xt,background:i.color},children:i.label}),e.jsx("span",{style:{...xt,background:l.color},children:l.label})]}),e.jsx("span",{style:Nr,children:Or(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Yr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:ut,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:ut,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Gr,children:r.content}),r.reply&&e.jsxs("div",{style:qr,children:[e.jsx("div",{style:Jr,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ur={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Vr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Kr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Nr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Yr={fontSize:"12px",marginBottom:"6px"},ut={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Gr={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},qr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Jr={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Ke=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:i,feedbackApiUrl:l})=>{const s=A(),[c,a]=f.useState(null),[u,d]=f.useState([]),[p,h]=f.useState("recommend"),[x,y]=f.useState([]),[j,g]=f.useState(!1),I=r??p,m=R=>{h(R),i==null||i(R)},[v,b]=f.useState(!0),[z,k]=f.useState(null),[w,C]=f.useState(null);f.useEffect(()=>{if(!t.getAllEntries)return;let R=!1;return t.getAllEntries().then(E=>{if(R)return;const H=E.filter(W=>W.type==="work").length,_=E.filter(W=>W.type==="book").length,$=E.filter(W=>W.type==="collection").length;a({works:H,books:_,collections:$})}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{let R=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const H=await t.getRecommended();if(H!=null&&H.groups)return H.groups.flatMap(_=>_.items.map($=>({...$,group:_.name})))}catch{}return[]})().then(async H=>{if(R)return;const _=H.filter(W=>W.id);if(_.length===0){b(!1);return}const $=await Promise.all(_.map(async W=>{try{let U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const S=await t.getItem(W.id);S&&(U={id:W.id,title:S.title||W.id,type:S.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:O.extractType(W.id),group:W.group,fallbackDescription:W.description}}));R||(d($.filter(W=>W!==null)),b(!1))}),()=>{R=!0}},[t,o]),f.useEffect(()=>{if(!t.getResourceProgress)return;let R=!1;return t.getResourceProgress().then(E=>{R||k(E)}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{if(!t.getSiteProgress)return;let R=!1;return t.getSiteProgress().then(E=>{R||C(E)}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{if(!l||I!=="feedback")return;let R=!1;return g(!0),fetch(l).then(E=>E.json()).then(E=>{!R&&E.success&&y(E.items||[])}).catch(()=>{}).finally(()=>{R||g(!1)}),()=>{R=!0}},[l,I]);const B=R=>{switch(R){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Le,{label:s.home.recommendTab,active:I==="recommend",onClick:()=>m("recommend")}),e.jsx(Le,{label:s.home.catalogTab,active:I==="catalog",onClick:()=>m("catalog")}),e.jsx(Le,{label:s.home.siteTab,active:I==="site",onClick:()=>m("site")}),l&&e.jsx(Le,{label:s.home.feedbackTab,active:I==="feedback",onClick:()=>m("feedback")})]}),I==="recommend"&&e.jsx(Zr,{recommended:u,loading:v,onNavigate:n,getIcon:B,t:s}),I==="catalog"&&e.jsx(Xr,{progress:z,t:s,onNavigate:n}),I==="site"&&e.jsx(eo,{progress:w,t:s,totalWorks:(c==null?void 0:c.works)??0}),I==="feedback"&&l&&e.jsx(qt,{items:x,loading:j})]})})},Le=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Zr=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:i})=>{const l=re();if(n)return e.jsx(ge,{});if(t.length===0)return null;const s=new Map;for(const c of t){const a=c.group||i.home.recommendedBrowse;s.has(a)||s.set(a,[]),s.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(s.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(u=>{const d=u.dynasty||u.author?`${u.dynasty?`〔${u.dynasty}〕`:""}${u.author||""}`:u.fallbackDescription;return e.jsxs("a",{href:l(u.id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o==null||o(u.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(u.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[u.title,u.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:u.edition})]}),d&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d})]})]},u.id)})})]},c))})},Xr=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),i=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},s={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:i.map(c=>{const a=r.filter(u=>u.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:s[c]}}),l[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(u=>e.jsx(Qr,{item:u,t:n,statusColor:s[c],onNavigate:o},u.id))})]},c)})})},Qr=({item:t,t:n,statusColor:o,onNavigate:r})=>{const i=re(),l=t.total>0?Math.round(t.imported/t.total*100):0,s=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:i(a),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:u=>u.currentTarget.style.borderBottomStyle="solid",onMouseLeave:u=>u.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:s})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ie(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${l}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},eo=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((a,u)=>a.priority-u.priority),i=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),s=i.reduce((a,u)=>Math.max(a,u.imported),0),c=o>0?Math.round(s/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:s.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]})]})},ft=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},gt="(max-width: 768px)";function to(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(gt).matches);return f.useEffect(()=>{const o=window.matchMedia(gt),r=i=>n(i.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const no=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:i})=>{var U;const l=A(),{convert:s}=D(),c=to(),[a,u]=f.useState(null),[d,p]=f.useState(null),[h,x]=f.useState(!1),[y,j]=f.useState("detail"),[g,I]=f.useState([]),[m,v]=f.useState(!1),[b,z]=f.useState(null),[k,w]=f.useState(!1),C=f.useCallback(async S=>{if(!t.getCollatedEditionIndex){z(null);return}w(!0);try{const L=await t.getCollatedEditionIndex(S);z(L)}catch{z(null)}finally{w(!1)}},[t]),B=f.useCallback(async S=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){I([]);return}v(!0);try{if(t.getCollectionCatalogs){const L=await t.getCollectionCatalogs(S);I(L||[])}else if(t.getCollectionCatalog){const L=await t.getCollectionCatalog(S);I(L?[{resource_id:"",data:L}]:[])}}catch{I([])}finally{v(!1)}},[t]),R=f.useCallback(async S=>{if(o){o(S);return}u(S),p(null),I([]),z(null),j("detail"),x(!0);try{const L=await t.getItem(S.id);L&&(p(L),L.type==="collection"?B(S.id):L.type==="work"&&L.has_collated&&C(S.id))}catch(L){console.error("加载详情失败:",L)}finally{x(!1)}},[t,o,B,C]),E=f.useCallback(async S=>{p(null),I([]),z(null),j("detail"),x(!0);try{const L=await t.getItem(S);L&&(p(L),u({id:S,title:L.title||S,type:L.type||"book"}),L.type==="collection"?B(S):L.type==="work"&&L.has_collated&&C(S))}catch(L){console.error("导航失败:",L)}finally{x(!1)}},[t,B,C]),H=(d==null?void 0:d.type)==="collection"&&(g.length>0||m)||(d==null?void 0:d.type)==="work"&&(b||k),_=c&&(h||d),$=f.useCallback(()=>{u(null),p(null),I([]),z(null),j("detail")},[]),W=e.jsx(e.Fragment,{children:h?e.jsx(ge,{}):d?e.jsxs(e.Fragment,{children:[(H||i)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[H&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>j("detail"),style:Ee(y==="detail"),children:l.detailTab.basicInfo}),d.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Ee(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),d.type==="collection"&&g.map(S=>e.jsx("button",{onClick:()=>j(`catalog:${S.resource_id}`),style:Ee(y===`catalog:${S.resource_id}`),children:S.short_name?`${s(S.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},S.resource_id)),d.type==="work"&&(b||k)&&e.jsxs("button",{onClick:()=>j("collated"),style:Ee(y==="collated"),children:[l.detailTab.collatedEdition,k&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),i&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:i})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:y==="detail"?e.jsx(Ge,{data:d,transport:t,onNavigate:E}):y.startsWith("catalog:")?e.jsx(Dt,{data:(U=g.find(S=>`catalog:${S.resource_id}`===y))==null?void 0:U.data,onNavigate:E}):y==="collated"?e.jsx(Gt,{index:b||void 0,workId:d.id,transport:t,onNavigate:E}):null})]}):e.jsx(Ke,{transport:t,onNavigate:E,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:_?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:$,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:W})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ve,{transport:t,onEntryClick:R,hideModeIndicator:n}),!d&&e.jsx(Ke,{transport:t,onNavigate:E,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Ve,{transport:t,onEntryClick:R,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:W})]})};function Ee(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const ro=({data:t,onNavigate:n,className:o,style:r})=>{var d;const i=A(),{convert:l}=D(),[s,c]=f.useState(((d=t.divisions[0])==null?void 0:d.name)??null),[a,u]=f.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:l(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[i.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",i.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",i.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",i.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(p=>e.jsx(oo,{division:p,expanded:s===p.name,onToggle:()=>c(s===p.name?null:p.name),expandedCat:a,onCatToggle:h=>u(a===h?null:h),onNavigate:n},p.name))})]})},oo=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:i,onNavigate:l})=>{const{convert:s}=D(),c=t.categories.reduce((a,u)=>{const d=u.stats||{zhulu:0,cunmu:0};return a+(d.zhulu||0)+(d.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:s(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const u=`${t.name}/${a.name}`;return e.jsx(io,{category:a,expanded:r===u,onToggle:()=>i(u),onNavigate:l},a.name)})})]})},io=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,u,d,p;const{convert:i}=D(),l=((a=t.books)==null?void 0:a.zhulu)||[],s=((u=t.books)==null?void 0:u.cunmu)||[],c=(((d=t.stats)==null?void 0:d.zhulu)||l.length)+(((p=t.stats)==null?void 0:p.cunmu)||s.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[i(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||s.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(ht,{label:"著錄",books:l,onNavigate:r}),s.length>0&&e.jsx(ht,{label:"存目",books:s,onNavigate:r})]})]})},ht=({label:t,books:n,onNavigate:o})=>{const{convert:r}=D(),i=re(),[l,s]=f.useState(n.length<=20),c=l?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,u)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:i(a.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},u))}),!l&&e.jsxs("button",{onClick:()=>s(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},oe=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:i})=>{const l=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:so,children:"AI"}),n&&e.jsx("button",{onClick:n,style:lo,children:l.action.save})]})]}),i]})},lo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},so={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ee=({label:t,value:n,onChange:o,placeholder:r,disabled:i})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:i,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),fe=({value:t,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:i=>n(i.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},We=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function ao(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Be=({value:t,onChange:n,label:o})=>{const[r,i]=f.useState(!1),l=f.useRef(null),s=ao(t||"");return f.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&s?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsxs("div",{onClick:()=>i(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:s.name}),e.jsx(We,{children:s.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>i(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},bt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function co(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function po(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Jt=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[i,l]=f.useState(null),s=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},c=p=>{n(t.filter((h,x)=>x!==p)),i===p&&l(null)},a=(p,h,x)=>{const y=[...t];y[p]={...y[p],[h]:x},n(y)},u=(p,h)=>{const x=[...t];x[p]={...x[p],type:h,id:"",name:""},n(x),h==="bookID"&&o&&o(y=>{const j=[...t];j[p]={...j[p],id:y.id,name:y.title,type:"bookID"},n(j)})},d=p=>{o&&o(h=>{const x=[...t];x[p]={...x[p],id:h.id,name:h.title,type:"bookID"},n(x)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(i===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:p.name||`${r.editor.sourcePlaceholder} ${h+1}`}),p.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:co(p.type),color:"white",borderRadius:"3px",fontWeight:500},children:po(p.type)}),e.jsx("button",{onClick:x=>{x.stopPropagation(),c(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),i===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!p.type&&e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>u(h,"bookID"),style:{...mt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>u(h,"url"),style:{...mt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),p.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const x=[...t];x[h]={...x[h],type:"",id:"",name:""},n(x)},style:yt,children:r.action.changeType})]}),p.id&&p.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:p.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:p.id})]}),e.jsx("button",{onClick:()=>d(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>d(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),p.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const x=[...t];x[h]={...x[h],type:"",id:"",name:""},n(x)},style:yt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:p.name,onChange:x=>a(h,"name",x.target.value),placeholder:r.editor.sourceNamePlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:p.id,onChange:x=>a(h,"id",x.target.value),placeholder:"https://...",style:be})]})]}),p.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...pe,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:p.details,onChange:x=>a(h,"details",x.target.value),placeholder:r.editor.detailsPlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:p.position,onChange:x=>a(h,"position",x.target.value),placeholder:"如: 卷三, p.52",style:be})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:p.version,onChange:x=>a(h,"version",x.target.value),placeholder:"如: v1.0, 2024-01",style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:p.processor_version,onChange:x=>a(h,"processor_version",x.target.value),placeholder:"如: v0.1",style:be})]})]})]})]})})]},h)),e.jsxs("button",{onClick:s,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},be={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},mt={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},yt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Zt(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function Xt(t){return!t||t.length===0?"":JSON.stringify(t)}const Qt=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:i,belongsToWork:l,belongsToCollection:s,childWorks:c,childCollections:a,containedBooks:u,siblingBooks:d,onLinkEntity:p,onUnlinkEntity:h,onViewEntity:x,onCreateAndLink:y,onSaveRelations:j})=>{const g=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),j&&e.jsx("button",{onClick:j,style:xo,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.belongsToWork,entity:l,onView:x,onUnlink:()=>h("workId"),onLink:()=>p("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ke,{direction:"up",title:g.relation.containedInCollection,entity:s,onView:x,onUnlink:()=>h("collectionId"),onLink:()=>p("collectionId","collection"),onCreate:()=>y("collectionId","collection",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),l&&d&&d.length>0&&e.jsx(me,{direction:"horizontal",title:`${g.relation.siblingVersions} (${d.length})`,entities:d,onView:x,onAdd:()=>y("siblingBook","book",{workId:l.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.parentWork,entity:r,onView:x,onUnlink:()=>h("parentWorkId"),onLink:()=>p("parentWorkId","work"),onCreate:()=>y("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),c&&c.length>0&&e.jsx(me,{direction:"down",title:`${g.relation.childWorks} (${c.length})`,entities:c,onView:x,onAdd:()=>y("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(me,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:x,onAdd:()=>y("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(me,{direction:"down",title:`${g.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:x,onAdd:()=>y("childBook","book",{workId:n}),addLabel:g.action.addVersion,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.correspondingWork,entity:l,onView:x,onUnlink:()=>h("workId"),onLink:()=>p("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ke,{direction:"up",title:g.relation.parentCollection,entity:i,onView:x,onUnlink:()=>h("parentCollectionId"),onLink:()=>p("parentCollectionId","collection"),onCreate:()=>y("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(me,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:x,onAdd:()=>y("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(me,{direction:"down",title:`${g.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:x,onAdd:()=>y("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},ke=({direction:t,title:n,entity:o,onView:r,onUnlink:i,onLink:l,onCreate:s,linkLabel:c,createLabel:a,notLinkedLabel:u,viewLabel:d,unlinkLabel:p})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:en(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(vt,{onClick:()=>r(o),title:d,children:"👁️"}),e.jsx(vt,{onClick:i,title:p,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:u}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Ne,{onClick:l,children:c}),e.jsx(Ne,{onClick:s,primary:!0,children:a})]})]})},me=({direction:t,title:n,entities:o,onView:r,onAdd:i,addLabel:l,noneLabel:s,expandMoreLabel:c})=>{const[a,u]=f.useState(!1),d=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:d,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(x=>e.jsxs("div",{onClick:()=>r(x),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:en(x.type)}),e.jsx("span",{children:x.title})]},x.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:s}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ne,{onClick:i,primary:!0,children:["+ ",l]})})]})},vt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:i=>{i.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),Ne=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function en(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const xo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},tn=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:i,onCreate:l,searchResults:s,onSearch:c,isLoading:a,excludeId:u})=>{const[d,p]=f.useState(""),h=u?s.filter(g=>g.id!==u):s;f.useEffect(()=>{t&&(p(""),c(""))},[t]);const x=g=>{p(g),c(g)};if(!t)return null;const y=n==="work"?"作品":n==="book"?"书籍":"丛编",j=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:uo,children:e.jsxs("div",{style:fo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:i,style:go,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:d,onChange:g=>x(g.target.value),placeholder:`搜索${y}名称或 ID...`,autoFocus:!0,style:ho})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:He,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>r(g),style:bo,children:[e.jsx("span",{style:{fontSize:"16px"},children:j}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):d?e.jsxs("div",{style:He,children:["未找到匹配的",y]}):e.jsxs("div",{style:He,children:["输入关键词搜索",y]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:l,style:mo,children:["创建新",y,"并关联"]})]})]})})},uo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},fo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},go={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},ho={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},bo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},He={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},mo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},jt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},yo={work:"📜",book:"📖",collection:"📚",entity:"👤"},nn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:i,onCancel:l})=>{const[s,c]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var h,x;(h=a.current)==null||h.focus(),(x=a.current)==null||x.select()},100))},[t,r==null?void 0:r.title]);const u=h=>{h.key==="Enter"&&s.trim()?d():h.key==="Escape"&&l()},d=()=>{s.trim()&&i(s.trim(),{...r,title:s.trim()})};if(!t)return null;const p=()=>{switch(o){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`创建新${jt[n]}`}};return e.jsx("div",{style:vo,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:jo,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:yo[n]}),e.jsx("span",{children:p()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:s,onChange:h=>c(h.target.value),onKeyDown:u,placeholder:`请输入${jt[n]}名称...`,style:So})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:ko,children:"取消"}),e.jsx("button",{onClick:d,disabled:!s.trim(),style:{...wo,opacity:s.trim()?1:.6,cursor:s.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},vo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},jo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},So={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},ko={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},wo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Co(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function rn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function _o(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const on=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:i,showCreateButton:l=!1,createButtonText:s,onSelect:c,onCancel:a,onCreate:u,onSearch:d})=>{const[p,h]=f.useState(""),[x,y]=f.useState([]),[j,g]=f.useState(!1),[I,m]=f.useState("recent");f.useEffect(()=>{t&&(h(""),y([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!p.trim()){y([]);return}const C=setTimeout(async()=>{g(!0);try{y(await d(p,o))}catch{y([])}finally{g(!1)}},300);return()=>clearTimeout(C)},[p,o,d]);const v=f.useCallback(C=>{h(C.target.value),C.target.value.trim()&&m("search")},[]),b=f.useCallback(C=>i?C.filter(B=>B.id!==i):C,[i]);if(!t)return null;const z=n||(o==="all"?"选择实体":`选择${rn(o)}`),k=b(r),w=b(x);return e.jsx("div",{style:Io,children:e.jsxs("div",{style:To,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:z}),e.jsx("button",{onClick:a,style:Ro,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:p,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Lo}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),j&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),k.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(St,{active:I==="recent",onClick:()=>m("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(St,{active:I==="search",onClick:()=>m("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:I==="recent"&&k.length>0?e.jsx(kt,{entities:k,onSelect:c}):p.trim()?j?e.jsx(Oe,{message:"搜索中..."}):w.length>0?e.jsx(kt,{entities:w,onSelect:c}):e.jsx(Oe,{message:"未找到匹配的结果"}):e.jsx(Oe,{message:"输入关键词开始搜索"})}),l&&u&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:u,style:Eo,children:s||"创建新实体"})]})]})})},St=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),kt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(zo,{entity:o,onClick:()=>n(o)},o.id))}),zo=({entity:t,onClick:n})=>{const[o,r]=f.useState(!1);return e.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?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Co(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:_o(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:rn(t.type)})]})},Oe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Io={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},To={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Ro={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Lo={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Eo={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Bo={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Wo={work:"📜",collection:"📚",book:"📖",entity:"👤"},ln=({data:t,onChange:n,onSave:o,transport:r,onNavigate:i,showDelete:l,onDelete:s,onAskAI:c,renderSectionActions:a,onDownloadResource:u,downloadStatuses:d,relations:p,onRelationsChange:h})=>{var te;const x=A(),[y,j]=f.useState(!1),[g,I]=f.useState("work"),[m,v]=f.useState(""),[b,z]=f.useState(""),[k,w]=f.useState([]),[C,B]=f.useState(!1),[R,E]=f.useState(!1),[H,_]=f.useState("work"),[$,W]=f.useState(""),[U,S]=f.useState(),[L,K]=f.useState(!1),[V,F]=f.useState(null),[le,Q]=f.useState([]);f.useRef(null);const de=t.type,ue=de==="work",xe=de==="collection",J=de==="book",N=f.useCallback((T,M)=>{n({...t,[T]:M})},[t,n]),Ae=f.useCallback((T,M)=>{v(T),I(M),z(x.editor.selectToLink+x.indexType[M]),w([]),j(!0)},[x]),Pe=f.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),ye=f.useCallback(T=>{i==null||i(T.id,T.type)},[i]),ve=f.useCallback((T,M,q)=>{const se={...q,author:(q==null?void 0:q.author)||t.author,dynasty:(q==null?void 0:q.dynasty)||t.dynasty};_(M),W(T),S(se),E(!0)},[t.author,t.dynasty]),Fe=f.useCallback((T,M)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,$,{type:H,title:T,inheritData:M}),E(!1)},[r,t.id,$,H]),Te=f.useCallback(T=>{if(!T.trim()){w([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(T,g).then(M=>{w(M),B(!1)}).catch(()=>{w([]),B(!1)})},[r,g]),Me=f.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),j(!1)},[r,t.id,m]),P=f.useCallback(()=>{o()},[o]),Y=f.useCallback(T=>{F(()=>T),K(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),Z=f.useCallback((T,M)=>r!=null&&r.searchEntities?r.searchEntities(T,M==="all"?void 0:M):Promise.resolve([]),[r]),G=f.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Q(M=>[T,...M.filter(q=>q.id!==T.id)].slice(0,10)),V==null||V(T),K(!1),F(null)},[r,V]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Wo[de]}),e.jsx("span",{children:t.title||x.editor.untitled}),e.jsx(We,{children:t.id}),e.jsx(We,{color:Bo[de],children:x.indexType[de]})]})}),e.jsx(oe,{title:x.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Be,{label:ue?x.editor.workTitle:xe?x.editor.collectionTitle:x.editor.bookTitle,value:t.title,onChange:T=>N("title",T)}),J&&e.jsx(Be,{label:x.editor.belongsToWork,value:t.workName||"",onChange:T=>N("workName",T)}),e.jsx(ee,{label:x.editor.authorLabel,value:t.author||"",onChange:T=>N("author",T)}),e.jsx(ee,{label:x.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>N("dynasty",T)}),(J||xe)&&e.jsx(Be,{label:x.editor.containedIn,value:t.collection||"",onChange:T=>N("collection",T)}),(J||xe)&&e.jsx(ee,{label:x.editor.holderLabel,value:t.holder||"",onChange:T=>N("holder",T)}),(J||xe)&&e.jsx(ee,{label:J?x.editor.pageLabel:x.editor.volumeLabel,value:t.pages||"",onChange:T=>N("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:x.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>N("firstImage",T)})})]})}),e.jsx(oe,{title:x.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(fe,{value:t.description||"",onChange:T=>N("description",T),placeholder:x.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(oe,{title:x.section.additionalWorks,onSave:o,children:e.jsx($o,{items:t.additional_works||[],onChange:T=>N("additional_works",T)})}),e.jsx(oe,{title:x.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Ao,{items:t.indexed_by||[],onChange:T=>N("indexed_by",T)})}),e.jsx(oe,{title:x.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(Po,{items:t.emendated_by||[],onChange:T=>N("emendated_by",T)})}),e.jsx(oe,{title:x.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(Ue,{items:t.resources||[],onChange:T=>N("resources",T),onDownload:u,downloadStatuses:d,filterType:"text"})}),e.jsx(oe,{title:x.section.imageResources,onSave:o,children:e.jsx(Ue,{items:t.resources||[],onChange:T=>N("resources",T),onDownload:u,downloadStatuses:d,filterType:"image"})}),e.jsx(oe,{title:x.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Jt,{items:Zt(t.sources||""),onChange:T=>N("sources",Xt(T)),onOpenEntityPicker:Y})}),(J||xe)&&e.jsx(oe,{title:x.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(fe,{value:t.provenance||"",onChange:T=>N("provenance",T),placeholder:x.editor.provenancePlaceholder})}),J&&e.jsx(oe,{title:x.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(fe,{value:t.otherEditions||"",onChange:T=>N("otherEditions",T),placeholder:x.editor.otherEditionsPlaceholder})}),e.jsx(Qt,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:p==null?void 0:p.parentWork,parentCollection:p==null?void 0:p.parentCollection,belongsToWork:p==null?void 0:p.belongsToWork,belongsToCollection:p==null?void 0:p.belongsToCollection,childWorks:p==null?void 0:p.childWorks,childCollections:p==null?void 0:p.childCollections,containedBooks:p==null?void 0:p.containedBooks,siblingBooks:p==null?void 0:p.siblingBooks,onLinkEntity:Ae,onUnlinkEntity:Pe,onViewEntity:ye,onCreateAndLink:ve,onSaveRelations:P}),l&&s&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:x.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:x.editor.dangerZoneDesc}),e.jsx("button",{onClick:s,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:x.editor.deleteEntity})]}),e.jsx(tn,{isOpen:y,entityType:g,title:b,onSelect:Me,onCancel:()=>j(!1),onCreate:()=>{j(!1),ve(m,g)},searchResults:k,onSearch:Te,isLoading:C,excludeId:t.id}),e.jsx(nn,{isOpen:R,entityType:H,relationField:$,inheritData:U,onConfirm:Fe,onCancel:()=>E(!1)}),e.jsx(on,{isOpen:L,title:x.action.selectBookOrWork,filterType:"all",recentEntities:le,excludeId:t.id,onSelect:G,onCancel:()=>{K(!1),F(null)},onSearch:Z})]})};function $o({items:t,onChange:n}){const o=A(),r=(s,c,a)=>{const u=t.map((d,p)=>p===s?{...d,[c]:a}:d);n(u)},i=s=>n(t.filter((c,a)=>a!==s)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ee,{label:o.editor.bookNameLabel,value:s.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ee,{label:o.label.juanCount,value:s.n_juan!=null?String(s.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>i(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function sn({items:t,onChange:n,showMeta:o,addLabel:r}){const i=A(),[l,s]=f.useState(null),c=(d,p,h)=>{const x=t.map((y,j)=>j===d?{...y,[p]:h||void 0}:y);n(x)},a=d=>{n(t.filter((p,h)=>h!==d)),l===d&&s(null)},u=()=>{n([...t,{source:""}]),s(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((d,p)=>{const h=l===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>s(h?null:p),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:d.source||i.editor.unnamedSource}),d.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:d.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(p)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&o&&(d.title_info||d.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[d.title_info,d.title_info&&d.author_info&&" — ",d.author_info]}),h&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:i.label.sourceName,value:d.source,onChange:x=>c(p,"source",x)}),e.jsx(ee,{label:i.label.sourceBid,value:d.source_bid||"",onChange:x=>c(p,"source_bid",x)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:i.label.titleInfo,value:d.title_info||"",onChange:x=>c(p,"title_info",x)}),e.jsx(ee,{label:i.label.authorInfo,value:d.author_info||"",onChange:x=>c(p,"author_info",x)})]}),e.jsx(ee,{label:i.label.edition,value:d.edition||"",onChange:x=>c(p,"edition",x)})]}),e.jsx(fe,{value:d.summary||"",onChange:x=>c(p,"summary",x),placeholder:i.editor.summaryPlaceholder}),e.jsx(fe,{value:d.comment||"",onChange:x=>c(p,"comment",x),placeholder:i.editor.commentPlaceholder}),e.jsx(fe,{value:d.additional_comment||"",onChange:x=>c(p,"additional_comment",x),placeholder:i.editor.additionalCommentPlaceholder})]})]},p)}),e.jsx("button",{onClick:u,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function Ao({items:t,onChange:n}){const o=A();return e.jsx(sn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Po({items:t,onChange:n}){const o=A();return e.jsx(sn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function an(t){var c,a,u,d,p,h,x;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",o=((u=t.publication_info)==null?void 0:u.year)||"",r=((d=t.current_location)==null?void 0:d.name)||"",i=(p=t.page_count)!=null&&p.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",s={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:i,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const y=t;if(Array.isArray(y.related_works)){const j=y.related_works.find(g=>g.relation==="part_of");j&&(s.parentWorkId=j.id,s.parentWorkName=j.title)}}if(t.type==="book"){const y=t;s.workId=y.work_id,Array.isArray(y.contained_in)&&y.contained_in.length>0&&(s.collectionId=(x=y.contained_in[0])==null?void 0:x.id)}return s}function Fo(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Mo=t=>{const{data:n,id:o,transport:r,mode:i="view",onModeChange:l,onChange:s,onSave:c,onDelete:a,onNavigate:u,renderLink:d,onAskAI:p,renderSectionActions:h,onDownloadResource:x,downloadStatuses:y,relations:j,onRelationsChange:g,headerExtra:I,className:m,style:v}=t;A();const[b,z]=f.useState(i),k=l?i:b;f.useEffect(()=>{i!==b&&z(i)},[i]);const w=f.useCallback(()=>{const $=k==="view"?"edit":"view";l?l($):z($)},[k,l]),[C,B]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then($=>{$&&B($)})},[o,r]);const R=n||C,E=f.useMemo(()=>R?an(R):null,[R]),H=l||!n?e.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:k==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:k==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:k==="view"?"切换到编辑模式":"切换到查看模式",children:k==="view"?"✏️ 编辑":"👁 查看"}):null,_=e.jsxs(e.Fragment,{children:[H,I]});return!R&&!E?e.jsx(ge,{}):k==="view"?e.jsx(Ge,{data:R,transport:r,onNavigate:u?$=>u($):void 0,renderLink:d,headerExtra:_,className:m,style:v}):E?e.jsxs("div",{className:m,style:v,children:[_&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:_}),e.jsx(ln,{data:E,onChange:s||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:u,showDelete:!!a,onDelete:a,onAskAI:p,renderSectionActions:h,onDownloadResource:x,downloadStatuses:y,relations:j,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},wt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],cn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[i,l]=f.useState(null),[s,c]=f.useState(""),[a,u]=f.useState("idle"),[d,p]=f.useState(""),h=f.useRef(null);f.useEffect(()=>{t&&(l(null),c(""),u("idle"),p(""))},[t]),f.useEffect(()=>{i&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[i]),f.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),f.useEffect(()=>{if(!t)return;const g=I=>{I.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const x=async()=>{if(!(!i||!s.trim())){u("submitting"),p("");try{await o({type:i,content:s.trim()}),u("success")}catch(g){u("error"),p(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const y=i&&s.trim()&&a!=="submitting",j=wt.find(g=>g.value===i);return e.jsx("div",{style:Do,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:Ho,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:Oo,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Uo,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Go,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:wt.map(g=>e.jsxs("button",{onClick:()=>l(g.value),style:{...Vo,...i===g.value?Ko:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:s,onChange:g=>c(g.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!i||a==="submitting",style:{...No,opacity:i?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),a==="error"&&e.jsx("div",{style:qo,children:d}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:x,disabled:!y,style:{...Yo,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Do={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ho={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Oo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Uo={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Vo={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Ko={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},No={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Yo={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Go={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},qo={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Jo=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,i]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>i(!0),style:{...Zo,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(cn,{isOpen:r,onClose:()=>i(!1),onSubmit:t,feedbackListUrl:o})]})},Zo={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Ct=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Xo=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,i]=f.useState(""),[l,s]=f.useState("idle"),[c,a]=f.useState(""),u=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var x;return(x=u.current)==null?void 0:x.focus()},100)},[n]);const d=async()=>{if(!(!n||!r.trim())){s("submitting"),a("");try{await t({type:n,content:r.trim()}),s("success"),i(""),o("bug")}catch(x){s("error"),a(x instanceof Error?x.message:"提交失败,请稍后重试")}}},p=n&&r.trim()&&l!=="submitting",h=Ct.find(x=>x.value===n);return l==="success"?e.jsx("div",{style:_t,children:e.jsxs("div",{style:ri,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>s("idle"),style:oi,children:"继续提交"})]})}):e.jsxs("div",{style:_t,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ct.map(x=>e.jsxs("button",{onClick:()=>o(x.value),style:{...Qo,...n===x.value?ei:{}},children:[e.jsx("span",{children:x.icon})," ",x.label]},x.value))}),e.jsx("textarea",{ref:u,value:r,onChange:x=>i(x.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...ti}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:d,disabled:!p,style:{...ni,opacity:p?1:.6,cursor:p?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&e.jsx("div",{style:ii,children:c})]})},_t={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Qo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ei={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ti={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ni={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ri={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},oi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ii={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},li=({style:t})=>{const n=f.useContext(ze);if(!n)return null;const{locale:o,setLocale:r}=n,i=o==="zh-Hant",l=()=>r(i?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:i?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:i?"var(--bim-primary, #0078d4)":void 0,fontWeight:i?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:i?void 0:"var(--bim-primary, #0078d4)",fontWeight:i?400:700},children:"简"})]})};exports.BidLink=O.BidLink;exports.BookIndexError=O.BookIndexError;exports.BookIndexManager=O.BookIndexManager;exports.BookIndexStorage=O.BookIndexStorage;exports.BundleStorage=O.BundleStorage;exports.ConfigError=O.ConfigError;exports.GithubStorage=O.GithubStorage;exports.IdGenerationError=O.IdGenerationError;exports.IdGenerator=O.IdGenerator;exports.LocalStorage=O.LocalStorage;exports.MigrationError=O.MigrationError;exports.StorageError=O.StorageError;exports.base36Decode=O.base36Decode;exports.base36Encode=O.base36Encode;exports.base58Decode=O.base58Decode;exports.buildId=O.buildId;exports.decodeId=O.decodeId;exports.decodeIdString=O.decodeIdString;exports.encodeId=O.encodeId;exports.extractIdFromUrl=O.extractIdFromUrl;exports.extractStatus=O.extractStatus;exports.extractType=O.extractType;exports.normalizeCatalog=O.normalizeCatalog;exports.parseId=O.parseId;exports.smartDecode=O.smartDecode;exports.validateResource=O.validateResource;exports.Badge=We;exports.BidUrlProvider=yn;exports.CollatedEdition=Gt;exports.CollectionCatalog=Dt;exports.CreateEntityDialog=nn;exports.EmendatedBySection=Ft;exports.EntityDetail=Bt;exports.EntityPickerDialog=on;exports.EntitySelector=tn;exports.FeedbackButton=Jo;exports.FeedbackDialog=cn;exports.FeedbackForm=Xo;exports.FeedbackList=qt;exports.FormInput=ee;exports.FormTextArea=fe;exports.HomePage=Ke;exports.IndexApp=no;exports.IndexBrowser=Ve;exports.IndexDetail=Ge;exports.IndexEditor=ln;exports.IndexView=Mo;exports.LocaleContext=ze;exports.LocaleProvider=Cn;exports.LocaleToggle=li;exports.ModeIndicator=Lt;exports.RelationPanel=Qt;exports.ResourceEditor=Ue;exports.ResourceList=Ye;exports.SearchInput=Et;exports.Section=oe;exports.SmartBidInput=Be;exports.SourceEditor=Jt;exports.WorkCatalog=ro;exports.detailToEditor=an;exports.editorToDetail=Fo;exports.formatTemplate=Ie;exports.parseSourceString=Zt;exports.stringifySources=Xt;exports.useBidUrl=re;exports.useConvert=D;exports.useT=A;
|
|
1
|
+
"use strict";var yn=Object.create;var ot=Object.defineProperty;var vn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Sn=Object.getPrototypeOf,kn=Object.prototype.hasOwnProperty;var wn=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of jn(n))!kn.call(t,s)&&s!==r&&ot(t,s,{get:()=>n[s],enumerable:!(o=vn(n,s))||o.enumerable});return t};var it=(t,n,r)=>(r=t!=null?yn(Sn(t)):{},wn(n||!t||!t.__esModule?ot(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-D_ldU5TV.cjs"),e=require("react/jsx-runtime"),u=require("react"),Cn=require("react-dom"),_n=t=>`/book-index?id=${t}`,Pt=u.createContext(_n);function zn({buildUrl:t,children:n}){const r=u.useMemo(()=>t,[t]);return e.jsx(Pt.Provider,{value:r,children:n})}function re(){return u.useContext(Pt)}const Ee=u.createContext(null),At={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},In={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"实体资源"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"实体"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Tn={"zh-Hant":At,"zh-Hans":In},Ft="bim-locale";function Rn(){try{const t=localStorage.getItem(Ft);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function En(t){try{localStorage.setItem(Ft,t)}catch{}}const Ln="zh-Hant",Bn=({locale:t,onLocaleChange:n,children:r})=>{const[o,s]=u.useState(t??Ln),i=t??o;u.useEffect(()=>{if(t)return;const f=Rn();f&&f!==o&&s(f)},[]);const[l,a]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(f=>{const x=f.Converter({from:"tw",to:"cn"});a(()=>x)}).catch(()=>{a(()=>f=>f)}):a(null)},[i]);const c=u.useCallback(f=>{s(f),En(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:i,setLocale:c,messages:Tn[i],converter:l}),[i,c,l]);return e.jsx(Ee.Provider,{value:p,children:r})};function P(){const t=u.useContext(Ee);return(t==null?void 0:t.messages)??At}const Wn=2e3;function D(){const t=u.useContext(Ee),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const i=u.useCallback(l=>{if(!l)return"";if(!r)return l;const a=o.current.get(l);if(a!==void 0)return a;const c=r(l);if(o.current.size>=Wn){const p=o.current.keys().next().value;p!==void 0&&o.current.delete(p)}return o.current.set(l,c),c},[r]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Le(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function $n(t){if(!t)return"";try{const n=new URL(t).hostname,r={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function Pn(){return{id:"",name:"",url:"",type:"text",details:""}}const Je=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:s})=>{const i=P(),[l,a]=u.useState(null),c=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],p=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],f=m=>s?s==="text"?m==="text"||m==="text+image":s==="image"?m==="image"||m==="text+image"||m==="physical":m===s:!0,x=t.map((m,j)=>({item:m,originalIndex:j})).filter(({item:m})=>f(m.type)),h=()=>{const m=Pn();s&&(m.type=s),n([...t,m]),a(t.length)},d=m=>{n(t.filter((j,y)=>y!==m)),a(null)},b=(m,j,y)=>{const z=[...t];if(z[m]={...z[m],[j]:y},j==="url"&&!z[m].id){const S=$n(y);S&&(z[m].id=S)}n(z)},v=(m,j,y)=>{const S={...t[m].metadata||{}};y?S[j]=y:delete S[j],b(m,"metadata",Object.keys(S).length>0?S:void 0)},g=(m,j)=>{const y=j.trim()?j.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;b(m,"structure",y)},k=(m,j,y)=>{const S=t[m].coverage||{level:1,ranges:""};j==="level"?S.level=parseInt(y)||1:S.ranges=y,b(m,"coverage",S.ranges?S:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:j})=>{var y,z,S,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(l===j?null:j),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:An(m.type),color:"#fff"},children:((y=c.find(C=>C.value===m.type))==null?void 0:y.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${j+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:C=>C.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&m.url&&Fn(j,o==null?void 0:o[j],r,i),e.jsx("button",{onClick:C=>{C.stopPropagation(),d(j)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===j&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&Mn(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:we,children:[e.jsx("span",{style:Ce,children:i.label.type}),e.jsx("select",{value:m.type,onChange:C=>b(j,"type",C.target.value),style:{...ae,flex:1},children:c.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsxs("label",{style:we,children:[e.jsx("span",{style:Ce,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:C=>b(j,"root_type",C.target.value),style:{...ae,flex:1},children:p.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:C=>b(j,"id",C.target.value),placeholder:i.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:C=>b(j,"name",C.target.value),placeholder:i.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:C=>b(j,"url",C.target.value),placeholder:i.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((z=m.structure)==null?void 0:z.join("、"))||"",onChange:C=>g(j,C.target.value),placeholder:i.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:we,children:[e.jsx("span",{style:Ce,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((S=m.coverage)==null?void 0:S.level)??"",onChange:C=>k(j,"level",C.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...we,flex:1},children:[e.jsx("span",{style:Ce,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:C=>k(j,"ranges",C.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:C=>b(j,"details",C.target.value),placeholder:i.editor.detailsPlaceholder,style:{...ae,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(i.metadata).map(([C,B])=>{var R;return e.jsxs("label",{style:{...we,gap:"4px"},children:[e.jsx("span",{style:{...Ce,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((R=m.metadata)==null?void 0:R[C])||"",onChange:L=>v(j,C,L.target.value),placeholder:B,style:{...ae,flex:1}})]},C)})})]})]})]})]},j)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addResource})]})]})};function An(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Fn(t,n,r,o){const s=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:l=>{l.stopPropagation(),s||r(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:i?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function Mn(t,n){const r=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:r?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ae={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},we={display:"flex",alignItems:"center",gap:"6px"},Ce={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Hn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Dn(t){try{const n=new URL(t).hostname;return Hn[n]}catch{return}}const st={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},On=["text","image","text+image","physical"];function Un(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const a=i.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},r=new Map,o=[],s=new Set;for(let i=0;i<t.length;i++){const l=t[i];if(l.volumes&&l.volumes.length>0)continue;const a=n(l.name);if(!a)continue;const[c,p]=a,f=`${c}|${l.type}`;r.has(f)||r.set(f,{base:{...l,name:c,url:"",volumes:[]},volumes:[]}),r.get(f).volumes.push({volume:p,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of r)if(i.volumes.length>=2)i.volumes.sort((l,a)=>l.volume-a.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,o.push(i.base);else for(let l=0;l<t.length;l++)if(s.has(l)){const a=n(t[l].name);a&&`${a[0]}|${t[l].type}`==`${i.base.name}|${i.base.type}`&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||o.push(t[i]);return o}const Qe=({items:t,groupByType:n=!0,onNavigate:r,renderLink:o})=>{const s=P(),i=u.useMemo(()=>Un(t||[]),[t]),l={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical};if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:i.map((c,p)=>e.jsx(at,{item:c},c.id||p))});const a=On.map(c=>({type:c,items:i.filter(p=>p.type===c)})).filter(c=>c.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:a.map(({type:c,items:p})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:st[c],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:st[c]}}),l[c],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",p.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:p.map((f,x)=>e.jsx(at,{item:f,onNavigate:r,renderLink:o},f.id||x))})]},c))})},lt=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},Mt=({value:t})=>{const r=P().checkType[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:r.bg,color:r.fg},children:r.label}):e.jsx("span",{children:t})},Vn=(t,n,r,o)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Mt,{value:n});if(t==="has_translation")return n?r.misc.hasTranslation:r.misc.noTranslation;const s=String(n);return o?o(s):s};function Nn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const s=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(s)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(s[1]))}&page=${n}`;const i=new URL(t);return i.searchParams.set("page",String(n)),i.toString()}return t}catch{return t}}function Yn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const r=n.match(/^(\d+)/);return r?parseInt(r[1],10):void 0}function Kn(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}const Gn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},at=({item:t,onNavigate:n,renderLink:r})=>{var v;const o=P(),{convert:s}=D(),i=re(),[l,a]=u.useState(!1),c=u.useMemo(()=>(t.url?Dn(t.url):void 0)||s(t.name),[t.url,t.name,s]),p=u.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(g=>({...g,url:g.url||Kn(g)})),[t.volumes]),f=p&&p.length>0,x=f?new Set(p.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,h=f?new Set(p.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,d=t.expected_volumes??(f?x+h:0),b=t.color_mode?{...Gn[t.color_mode],label:o.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:lt(t)||f?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c}),b&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:b.bg,color:b.fg},children:b.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((v=t.metadata)==null?void 0:v.check_type)&&e.jsx(Mt,{value:t.metadata.check_type}),f&&e.jsxs("span",{style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)"},children:[x,"/",d,o.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=Yn(t.metadata);return g?Nn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:o.action.visit}),f&&e.jsx("button",{onClick:()=>a(!l),title:l?"收起分册":"展开分册",style:{marginLeft:"auto",padding:"1px 10px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:l?"var(--bim-widget-border, #e0e0e0)":"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",lineHeight:1.4},children:l?"收起 ▲":"展开 ▼"})]}),lt(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([g])=>g!=="check_type").map(([g,k])=>e.jsxs("span",{children:[o.metadata[g]||g,": ",Vn(g,k,o,s)]},g)),t.details&&!f&&e.jsx("span",{children:s(t.details)}),t.structure&&e.jsxs("span",{children:[o.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[o.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),f&&l&&(()=>{const g=p.some(j=>j.group),k=[];if(g){let j=null;for(const y of p){const z=y.group||"";(!j||j.title!==z)&&(j={title:z,group_id:y.group_id,vols:[]},k.push(j)),j.vols.push(y)}}else k.push({vols:p});const m=j=>{const y=j.status==="missing";return j.url&&!y?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:j.label||`${j.volume}`,children:j.volume},j.volume):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:y?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1,lineHeight:1.4},children:j.volume},j.volume)};return e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexDirection:"column",gap:"8px"},children:k.map((j,y)=>{const z=j.title?s(j.title):"";let S=z;return j.title&&j.group_id&&(r?S=r(j.group_id,z):n&&(S=e.jsx("a",{href:i(j.group_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),n(j.group_id))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:w=>w.currentTarget.style.borderBottomStyle="solid",onMouseLeave:w=>w.currentTarget.style.borderBottomStyle="dashed",children:z}))),e.jsxs("div",{children:[j.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[S,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",j.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:j.vols.map(m)})]},y)})})})()]})},Ht=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const a=P(),c=t==="local",p=(n==null?void 0:n.isDraft)??!0,f=(n==null?void 0:n.repoPath)||"",x=f?f.split(/[/\\]/).pop()||f:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},d={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:p?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:p?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:p?"📝":"📚"}),e.jsx("span",{children:p?"draft":"official"})]});return r==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:o,title:a.mode.switchToSync,style:h,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:f||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:x||a.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:c?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:l,title:f||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:f?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:f,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},De="bim-search-history",ct=10,dt=8;function ze(){try{const t=localStorage.getItem(De);return t?JSON.parse(t):[]}catch{return[]}}function Jn(t){try{const n=ze().filter(r=>r!==t);n.unshift(t),n.length>ct&&(n.length=ct),localStorage.setItem(De,JSON.stringify(n))}catch{}}function qn(t){try{const n=ze().filter(r=>r!==t);localStorage.setItem(De,JSON.stringify(n))}catch{}}function Zn(){try{localStorage.removeItem(De)}catch{}}const Dt=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:s,placeholder:i})=>{const l=P(),a=i??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,f]=u.useState(!1),[x,h]=u.useState([]),[d,b]=u.useState(-1),[v,g]=u.useState(null),[k,m]=u.useState(ze),j=u.useRef(null),y=u.useRef(null),z=u.useRef(null);u.useEffect(()=>{if(!t.getAllEntries)return;let I=!1;return t.getAllEntries().then(W=>{I||g(W)}).catch(()=>{}),()=>{I=!0}},[t]);const S=u.useCallback(I=>{if(!I.trim())return k.map(_=>({type:"history",text:_}));if(!v)return[];const W=I.toLowerCase(),$=[],U=[];for(const _ of v){if($.length+U.length>=dt*2)break;const E=(_.title??"").toLowerCase();if(E.startsWith(W))$.push({type:"entry",text:_.title,entry:_});else if(E.includes(W))U.push({type:"entry",text:_.title,entry:_});else{const N=[..._.additional_titles||[],..._.attached_texts||[]];for(const V of N){const F=typeof V=="string"?V:V==null?void 0:V.book_title;if(F!=null&&F.toLowerCase().includes(W)){$.push({type:"entry",text:`${_.title}`,entry:_});break}}}}return[...$,...U].slice(0,dt)},[v,k]);u.useEffect(()=>{h(S(n)),b(-1)},[n,S]),u.useEffect(()=>{const I=W=>{z.current&&!z.current.contains(W.target)&&f(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[]),u.useEffect(()=>{const I=W=>{var $,U;if(W.key==="/"&&document.activeElement!==j.current){const _=($=document.activeElement)==null?void 0:$.tagName;if(_==="INPUT"||_==="TEXTAREA"||_==="SELECT")return;W.preventDefault(),(U=j.current)==null||U.focus()}};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]);const w=u.useCallback(I=>{I.trim()&&(Jn(I.trim()),m(ze())),o(I),f(!1)},[o]),C=u.useCallback(I=>{I.type==="history"?(r(I.text),w(I.text)):I.entry&&(s?(s(I.entry),f(!1)):(r(I.text),w(I.text)))},[r,w,s]),B=u.useCallback(I=>{if(!p||x.length===0){I.key==="Enter"&&w(n);return}switch(I.key){case"ArrowDown":I.preventDefault(),b(W=>(W+1)%x.length);break;case"ArrowUp":I.preventDefault(),b(W=>(W-1+x.length)%x.length);break;case"Enter":I.preventDefault(),d>=0&&d<x.length?C(x[d]):w(n);break;case"Escape":I.preventDefault(),f(!1);break}},[p,x,d,n,w,C]),R=u.useCallback((I,W)=>{W.stopPropagation(),qn(I),m(ze()),h($=>$.filter(U=>!(U.type==="history"&&U.text===I)))},[]),L=u.useCallback(I=>{I.stopPropagation(),Zn(),m([]),h([])},[]);u.useEffect(()=>{if(d>=0&&y.current){const I=y.current.children;I[d]&&I[d].scrollIntoView({block:"nearest"})}},[d]);const M=!n.trim()&&k.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:a,value:n,onChange:I=>{r(I.target.value),f(!0)},onFocus:()=>f(!0),onKeyDown:B,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),p&&x.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[M&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:L,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((I,W)=>e.jsxs("div",{onClick:()=>C(I),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:W===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:I.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.text}),I.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[I.entry.type],I.entry.edition&&` · ${I.entry.edition}`,I.entry.author&&` · ${I.entry.author}`]}),I.type==="history"&&e.jsx("button",{onClick:$=>R(I.text,$),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${I.type}-${I.text}-${W}`))]})]})},Re="bim-recent-ids",pt="bim-recent-entries",xt=50,Ye=5,Xn=50,Qn=200;function Ie(){try{const t=localStorage.getItem(Re);if(t)return JSON.parse(t);const n=localStorage.getItem(pt);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Re,JSON.stringify(r)),localStorage.removeItem(pt),r}return[]}catch{return[]}}function er(t){try{const n=Ie().filter(r=>r!==t);n.unshift(t),n.length>xt&&(n.length=xt),localStorage.setItem(Re,JSON.stringify(n))}catch{}}function tr(t){try{const n=Ie().filter(r=>r!==t);localStorage.setItem(Re,JSON.stringify(n))}catch{}}function nr(){try{localStorage.removeItem(Re)}catch{}}const rr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},qe=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:p,initialQuery:f,onQueryChange:x,headerRight:h})=>{const d=P(),b=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:d.indexType.entity,key:"entities"}],[v,g]=u.useState(f??""),[k,m]=u.useState(null),[j,y]=u.useState(null),[z,S]=u.useState(!1),[w,C]=u.useState(null),[B,R]=u.useState(""),[L,M]=u.useState(!f),[I,W]=u.useState(Ie),[$,U]=u.useState([]),[_,E]=u.useState(!1),[N,V]=u.useState(!1),[F,se]=u.useState(null),[Q,de]=u.useState(null),fe=u.useRef(void 0),ue=u.useRef(!1),q=u.useCallback(async(A,K)=>{if(!A.trim()){M(!0),m(null),y(null);return}M(!1),S(!0),R("");try{if(t.searchAll){const Z=await t.searchAll(A,K??Ye);m(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(A,te,{page:1,pageSize:K??Ye})));m({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(Z){R(Z instanceof Error?Z.message:String(Z)),m(null)}finally{S(!1)}},[t]);u.useEffect(()=>{var T,H;let A=!1;const K=["work","book","collection","entity"],Z=Promise.all(K.map(J=>t.loadEntries(J,{page:1,pageSize:1}).catch(()=>({total:0})))),G=((T=t.getResourceCounts)==null?void 0:T.call(t).catch(()=>null))??Promise.resolve(null),te=((H=t.getSubtypeStats)==null?void 0:H.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([J,le,be])=>{A||(se({works:J[0].total,books:J[1].total,collections:J[2].total,entities:J[3].total,hasText:le==null?void 0:le.hasText,hasImage:le==null?void 0:le.hasImage}),be&&de(be))}),()=>{A=!0}},[t]),u.useEffect(()=>{ue.current||!(f!=null&&f.trim())||(ue.current=!0,q(f))},[f,q]);const Y=u.useCallback(A=>{if(g(A),x==null||x(A),!A.trim()){M(!0),m(null),y(null);return}fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{y(null),q(A)},Qn)},[q,x]),Oe=u.useCallback(A=>{fe.current&&clearTimeout(fe.current),x==null||x(A),q(A)},[q,x]),Ue=u.useCallback(A=>{y(A),q(v,Xn)},[v,q]);u.useEffect(()=>{if(!I.length){U([]);return}let A=!1;return E(!0),Promise.all(I.slice(0,10).map(async K=>{var Z,G,te;try{if(t.getEntry){const H=await t.getEntry(K);if(H)return H}const T=await t.getItem(K);if(T){const H=T.authors;return{id:K,title:T.title||K,type:T.type||"work",author:(Z=H==null?void 0:H[0])==null?void 0:Z.name,dynasty:(G=H==null?void 0:H[0])==null?void 0:G.dynasty,role:(te=H==null?void 0:H[0])==null?void 0:te.role,edition:T.edition||void 0}}}catch{}return{id:K,title:K,type:"work",notFound:!0}})).then(K=>{A||(U(K),E(!1))}),()=>{A=!0}},[I,t]);const Se=A=>{C(A.id),er(A.id),W(Ie()),o==null||o(A)},ke=A=>{tr(A),W(Ie())},Ve=()=>{nr(),W([])},Be=A=>b.find(K=>K.type===A),Ne=k&&(k.works.length>0||k.books.length>0||k.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!p&&e.jsx(Ht,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Dt,{transport:t,value:v,onChange:Y,onSearch:Oe,onEntrySelect:Se}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:d.action.newEntry})]}),F&&L&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()}),F.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.entities.toLocaleString()})]})]})}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):B?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):L?e.jsx("div",{style:{flex:1},children:_?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:d.search.recentBrowse}),e.jsx("button",{onClick:Ve,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:d.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,N?10:3).map(A=>A.notFound?e.jsx(or,{id:A.id,onRemove:ke,t:d},A.id):e.jsx(ut,{entry:A,selected:w===A.id,onClick:Se,getConfig:Be,onRemove:ke},A.id))}),!N&&$.length>3&&e.jsx("button",{onClick:()=>V(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:d.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Ne?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:A,icon:K,name:Z,key:G})=>{const te=k[G]??[],T=rr[G],H=k[T]??0;if(te.length===0)return null;const le=!(j===A)&&H>Ye;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[K," ",Z,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[H," ",d.unit.items]})]}),le&&e.jsx("button",{onClick:()=>Ue(A),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(be=>e.jsx(ut,{entry:be,selected:w===be.id,onClick:Se,getConfig:Be,query:v},be.id))})]},A)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Le(d.search.noResultsFor,{query:v})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},ut=({entry:t,selected:n,onClick:r,getConfig:o,query:s,onRemove:i})=>{const l=P(),{convert:a}=D(),c=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&c.length?c.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>r(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),p&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",a(p)]})]}),i?e.jsx("button",{onClick:f=>{f.stopPropagation(),i(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},or=({id:t,onRemove:n,t:r})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:r.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:r.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function ir(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function sr({data:t}){const{convert:n}=D(),{dynasty:r,birth_year:o,death_year:s}=t,i=[];return r&&i.push(`〔${n(r)}〕`),o!==void 0&&s!==void 0?i.push(`${o}—${s}`):o!==void 0?i.push(`${o}—?`):s!==void 0&&i.push(`?—${s}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function lr({alt_names:t}){const{convert:n}=D(),r=new Map;for(const i of t){const l=i.type||"別名";r.has(l)||r.set(l,[]),r.get(l).push(i.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...r.keys()].sort((i,l)=>{const a=o.indexOf(i),c=o.indexOf(l);return a===-1&&c===-1?0:a===-1?1:c===-1?-1:a-c});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const l=r.get(i);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:i}),e.jsx("span",{children:l.map((a,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(a)]},c))})]},i)})})}function ar({data:t}){const n=t.external_ids;if(!n)return null;const r=[];return n.cbdb_id&&r.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),r.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function cr({works:t,transport:n,onNavigate:r,renderLink:o}){const s=P(),{convert:i}=D(),l=re(),[a,c]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const d=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(d);let y=!0;for(let z=0;z<d.length;z++){const S=j[z];S!=null&&S.title?v.set(d[z],S.title):S!=null&&S.primary_name?v.set(d[z],S.primary_name):y=!1}if(y)return v}catch{}if(n.getAllEntries)try{const j=await n.getAllEntries(),y=new Map(j.map(S=>[S.id,S.title||S.primary_name||S.id]));let z=!0;for(const S of d){const w=y.get(S);w?v.set(S,w):z=!1}if(z)return v}catch{}const g=[...d],k=8,m=new Array(k).fill(0).map(async()=>{for(;g.length;){const j=g.shift();if(!j)break;if(!v.has(j))try{if(n.getEntry){const S=await n.getEntry(j);if(S!=null&&S.title){v.set(j,S.title);continue}}const y=await n.getItem(j),z=y&&(y.title||y.primary_name)||j;v.set(j,z)}catch{v.set(j,j)}}});return await Promise.all(m),v})().then(v=>{h||c(v)}),()=>{h=!0}},[t,n]);const p=new Map;for(const h of t){const d=h.role||"";p.has(d)||p.set(d,[]),p.get(d).push(h)}const f=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...p.keys()].sort((h,d)=>{const b=f.indexOf(h),v=f.indexOf(d);return b===-1&&v===-1?h.localeCompare(d):b===-1?1:v===-1?-1:b-v});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(h=>{const d=p.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",d.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:d.map((b,v)=>{const g=i(a.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,g)},v):r?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),r(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},v):e.jsx("li",{children:g},v)})})]},h)})]})}const Ot=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:s})=>{var f;const i=P(),{convert:l}=D();let a=!1;try{a=O.extractStatus(t.id)==="draft"}catch{}const c=ir(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[l(t.primary_name),e.jsx(sr,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:i.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),c&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(lr,{alt_names:t.alt_names}),e.jsx(ar,{data:t}),((f=t.description)==null?void 0:f.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:l(t.description.text)}),t.works&&t.works.length>0&&e.jsx(cr,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},dr=["〇","一","二","三","四","五","六","七","八","九"],ft=["","十","百","千"];function Ut(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let i=0;i<r;i++){const l=parseInt(n[i]),a=r-1-i;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&a===1&&i===0?o+=ft[a]:o+=dr[l]+ft[a])}return o}function Vt({type:t}){const n=P(),r={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:r[t],border:`1px solid ${r[t]}40`,borderRadius:"2px",background:`${r[t]}08`},children:n.indexType[t]})}function pr({isDraft:t}){const n=P();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function xr({id:t}){const n=P(),[r,o]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function ne({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function ce({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function Nt({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:s}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const a=s(i.name),c=i.entity_id?e.jsx(ie,{id:i.entity_id,label:a,onNavigate:r,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:a});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),c,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},l)})})}function ie({id:t,label:n,onNavigate:r,renderLink:o}){const s=re();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),r(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ur({id:t,title:n,edition:r,type:o,isDraft:s,authors:i,volumeText:l,meta:a,headerExtra:c,onNavigate:p,renderLink:f}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:r}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Vt,{type:o}),e.jsx(pr,{isDraft:s}),e.jsx(xr,{id:t})]}),((i==null?void 0:i.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(Nt,{authors:i,type:o,onNavigate:p,renderLink:f}),a]})]})}function Yt({items:t,label:n,showMeta:r,onNavigate:o,renderLink:s}){const i=P(),{convert:l}=D();if(!t.length)return null;const[a,c]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((p,f)=>{const x=a===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(x?null:f),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(p.source)}),!x&&r&&p.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(p.title_info)}),p.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ie,{id:p.source_bid,label:i.action.view,onNavigate:o,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r&&(p.title_info||p.author_info||p.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[p.title_info&&e.jsx(ce,{label:i.label.titleInfo,children:l(p.title_info)}),p.author_info&&e.jsx(ce,{label:i.label.authorInfo,children:l(p.author_info)}),p.edition&&e.jsx(ce,{label:i.label.edition,children:l(p.edition)})]}),p.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(p.summary)})]}),p.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.comment)})]}),p.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.additional_comment)})]})]})]},f)})})]})}function fr({items:t,onNavigate:n,renderLink:r}){const o=P();return e.jsx(Yt,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function Kt({items:t,onNavigate:n,renderLink:r}){const o=P();return e.jsx(Yt,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function Gt({label:t,items:n}){const{convert:r}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const i=typeof o=="string"?o:o.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:r(i)},s)})})]}):null}function gr({items:t}){const n=P();return e.jsx(Gt,{label:n.section.aliases,items:t})}function hr({items:t}){const n=P();return e.jsx(Gt,{label:n.section.attachedTexts,items:t})}function br({items:t}){const n=P(),{convert:r}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function mr({items:t}){const n=P(),{convert:r}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:r(o.description)})]},s))]})]}):null}function yr({items:t}){const n=P(),{convert:r}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),r(o)]},s))})]}):null}function gt({title:t,ids:n,transport:r,onNavigate:o,renderLink:s}){const{convert:i}=D(),[l,a]=u.useState([]);return u.useEffect(()=>{if(!n.length){a([]);return}if(!r){a(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>r.getItem(p).then(f=>({id:p,title:f?f.title:void 0,edition:f?f.edition:void 0,type:f?f.type:void 0})).catch(()=>({id:p})))).then(p=>{c||a(p)}),()=>{c=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(c=>({id:c}))).map(c=>{const p=c.edition?`${i(c.title)||c.id}(${i(c.edition)})`:i(c.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ie,{id:c.id,label:p,onNavigate:o,renderLink:s})},c.id)})})]}):null}function vr({book:t,onNavigate:n,renderLink:r}){const o=P(),{convert:s}=D(),[i,l]=u.useState(!1),a=t.resources&&t.resources.length>0,c=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:a&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ie,{id:t.id,label:c,onNavigate:n,renderLink:r})}),a&&e.jsx("span",{onClick:()=>l(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?o.action.expand:o.action.collapse,children:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Qe,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:r})})]})}function jr({ids:t,transport:n,onNavigate:r,renderLink:o}){const s=P(),[i,l]=u.useState([]);return u.useEffect(()=>{if(!t.length){l([]);return}if(!n){l(t.map(c=>({id:c})));return}let a=!1;return Promise.all(t.map(c=>n.getItem(c).then(p=>({id:c,title:p?p.title:void 0,edition:p?p.edition:void 0,resources:p?p.resources:void 0})).catch(()=>({id:c})))).then(c=>{a||l(c)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[s.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(i.length?i:t.map(a=>({id:a}))).map(a=>e.jsx(vr,{book:a,onNavigate:r,renderLink:o},a.id))})]}):null}function Sr({workData:t,onNavigate:n,renderLink:r}){var i,l,a;const o=P(),{convert:s}=D();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(Vt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ie,{id:t.id,label:s(t.title),onNavigate:n,renderLink:r})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((i=t.juan_count)==null?void 0:i.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Ut(t.juan_count.number),o.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(Nt,{authors:t.authors,type:"work",onNavigate:n,renderLink:r}),((l=t.description)==null?void 0:l.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:s(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(ce,{label:o.label.parentWork,children:e.jsx(ie,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function kr({items:t,onNavigate:n,renderLink:r}){const o=P(),{convert:s}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:o.indexType.collection}),e.jsx(ie,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:r}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Le(o.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const et=({data:t,id:n,transport:r,onNavigate:o,renderLink:s,headerExtra:i,className:l,style:a})=>{var L,M,I,W,$,U;const c=P(),{convert:p}=D(),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,v]=u.useState(null),[g,k]=u.useState(null),[m,j]=u.useState([]),y=t||f;if(u.useEffect(()=>{if(t||!n||!r)return;let _=!1;return d(!0),v(null),r.getItem(n).then(E=>{_||(E?x(E):v(c.misc.notFoundEntry))}).catch(E=>{_||v(E instanceof Error?E.message:c.misc.loadFailed)}).finally(()=>{_||d(!1)}),()=>{_=!0}},[t,n,r]),u.useEffect(()=>{if(!y||!r){k(null),j([]);return}let _=!1;const E=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(E?r.getItem(E).then(N=>{!_&&N&&N.type==="work"&&k(N)}).catch(()=>{}):k(null),y.type==="book"){const N=y;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(V=>{const F=typeof V=="string"?V:V.id,se=typeof V=="string"?void 0:V.volume_index;return r.getItem(F).then(Q=>({id:F,title:Q&&Q.title||F,volume_index:se})).catch(()=>({id:F,title:F,volume_index:se}))})).then(V=>{_||j(V)}):j([])}else j([]);return()=>{_=!0}},[y,r]),h)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((_,E)=>e.jsx("div",{style:{height:E===1?"32px":"16px",width:`${_}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},E))})});if(b)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:b});if(!y)return null;if(y.type==="entity")return e.jsx("div",{className:l,style:a,children:e.jsx(Ot,{data:y,transport:r,onNavigate:o,renderLink:s,headerExtra:i})});const z=y.type==="book"?y:null,S=y.type==="collection"?y:null,w=y.type==="work"?y:null;let C=!1;try{C=O.extractStatus(y.id)==="draft"}catch{}let B="";y.measure_info?B=p(y.measure_info):(L=y.juan_count)!=null&&L.number?B=Ut(y.juan_count.number)+c.unit.juan:(M=y.juan_count)!=null&&M.description&&(B=p(y.juan_count.description));const R=[];return(I=y.publication_info)!=null&&I.year&&R.push(e.jsx(ce,{label:c.label.year,children:y.publication_info.year},"year")),(W=y.current_location)!=null&&W.name&&R.push(e.jsx(ce,{label:c.label.currentLocation,children:p(y.current_location.name)},"loc")),($=y.page_count)!=null&&$.description&&R.push(e.jsx(ce,{label:c.label.pageCount,children:y.page_count.description},"page")),z!=null&&z.edition&&R.push(e.jsx(ce,{label:c.label.edition,children:p(z.edition)},"ver")),w!=null&&w.parent_work&&R.push(e.jsx(ce,{label:c.label.parentWork,children:e.jsx(ie,{id:w.parent_work.id,label:p(w.parent_work.title),onNavigate:o,renderLink:s})},"pw")),w!=null&&w.parent_works&&w.parent_works.length>0&&!w.parent_work&&R.push(e.jsx(ce,{label:c.label.parentWork,children:w.parent_works.map((_,E)=>e.jsxs("span",{children:[E>0&&"、",e.jsx(ie,{id:_,onNavigate:o,renderLink:s})]},_))},"pws")),e.jsxs("div",{className:l,style:a,children:[e.jsx(ur,{id:y.id,title:p(y.title),edition:y.edition?p(y.edition):void 0,type:y.type,isDraft:C,authors:y.authors,volumeText:B,meta:R,headerExtra:i,onNavigate:o,renderLink:s}),((U=y.description)==null?void 0:U.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:p(y.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.containedIn}),e.jsx(kr,{items:m,onNavigate:o,renderLink:s})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.belongsToWork}),e.jsx(Sr,{workData:g,onNavigate:o,renderLink:s})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(br,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(gr,{items:y.additional_titles}),y.attached_texts&&y.attached_texts.length>0&&e.jsx(hr,{items:y.attached_texts}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(fr,{items:y.indexed_by,onNavigate:o,renderLink:s}),y.emendated_by&&y.emendated_by.length>0&&e.jsx(Kt,{items:y.emendated_by,onNavigate:o,renderLink:s}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.resources}),e.jsx(Qe,{items:y.resources,groupByType:!0,onNavigate:o,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(mr,{items:z.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(yr,{items:S.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(gt,{title:c.section.relatedVersions,ids:z.related_books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(gt,{title:c.section.containedBooks,ids:S.books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[c.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(_=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ie,{id:_.id,label:p(_.title),onNavigate:o,renderLink:s})},_.id))})]}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(jr,{ids:w.books,transport:r,onNavigate:o,renderLink:s}),(w==null?void 0:w.related_works)&&w.related_works.length>0&&(()=>{const _=[],E=w.related_works.filter(F=>F.relation==="part_of"),N=w.related_works.filter(F=>F.relation==="has_part"),V=w.related_works.filter(F=>!F.relation);return E.length>0&&_.push({label:c.section.belongsToWork,items:E}),N.length>0&&_.push({label:c.section.containedWorks,items:N}),V.length>0&&_.push({label:c.section.relatedWorks,items:V}),_.map(F=>e.jsxs("div",{children:[e.jsxs(ne,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(se=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ie,{id:se.id,label:p(se.title),onNavigate:o,renderLink:s})},se.id))})]},F.label))})()]})};function wr({data:t}){const n=P(),{convert:r}=D(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,i=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:r(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),i!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",i,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Cr({sections:t,activeSection:n,onSelect:r}){const o=P();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:ht(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>r(s.name),style:ht(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function ht(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function _r({id:t,label:n,onNavigate:r,renderLink:o}){const s=re();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),r(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function zr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function bt({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const s=P(),{convert:i}=D(),l=t.book_id||t.work_id,a=o&&t.volumes.length>0?zr(t.volumes,s.unit.volume):null,c=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(p=>i(p)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:c?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(_r,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:r}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const Jt=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:s,className:i,style:l})=>{const a=P(),[c,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[b,v]=u.useState(null),[g,k]=u.useState(""),m=t||c;u.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let w=!1;return x(!0),d(null),r.getCollectionCatalog(n).then(C=>{w||(C?p(C):d(a.catalog.notFound))}).catch(C=>{w||d(C instanceof Error?C.message:a.catalog.loadFailed)}).finally(()=>{w||x(!1)}),()=>{w=!0}},[t,n,r,a]);const j=(m==null?void 0:m.sections)&&m.sections.length>0,y=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const w=m.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(w).size<w.length},[m]),z=u.useMemo(()=>{if(!m)return[];let w=m.books;if(b&&(w=w.filter(C=>C.section===b)),g.trim()){const C=g.trim().toLowerCase();w=w.filter(B=>B.title.toLowerCase().includes(C)||B.sub_items&&B.sub_items.some(R=>R.toLowerCase().includes(C))||B.edition&&B.edition.toLowerCase().includes(C))}return w},[m,b,g]),S=u.useMemo(()=>{if(!y)return null;const w=[],C=new Map;for(const R of z){if(!R.volumes||R.volumes.length===0)continue;const L=R.volumes[0];C.has(L)||C.set(L,[]),C.get(L).push(R)}const B=[...C.keys()].sort((R,L)=>R-L);for(const R of B)w.push({volume:R,books:C.get(R)});return w},[z,y]);return f?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):h?e.jsx("div",{className:i,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:i,style:l,children:[e.jsx(wr,{data:m}),j&&e.jsx(Cr,{sections:m.sections,activeSection:b,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:g,onChange:w=>k(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[z.length," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[S?S.map((w,C)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Le(a.catalog.volume,{n:w.volume})}),w.books.map((B,R)=>e.jsx(bt,{book:B,onNavigate:o,renderLink:s,showVolumes:B.volumes.length>1},`${w.volume}-${R}`))]},`${w.volume}-${C}`)):z.map((w,C)=>e.jsx(bt,{book:w,onNavigate:o,renderLink:s,showVolumes:!0},C)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},qt={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Ir={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Tr={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},he=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,We=7,Rr=({content:t,children:n,placement:r="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,a]=u.useState(!1),[c,p]=u.useState(null),f=u.useRef(null),x=u.useRef(null),h=u.useRef(null),d=u.useCallback(()=>{const g=x.current,k=h.current;if(!g||!k)return;const m=g.getBoundingClientRect(),j=k.getBoundingClientRect(),y=window.innerHeight,z=document.documentElement.clientWidth;let S=r;r==="top"&&m.top-j.height-We<8&&(S="bottom"),r==="bottom"&&m.bottom+j.height+We>y-8&&(S="top");const w=S==="top"?m.top-j.height-We:m.bottom+We;let C=m.left+m.width/2-j.width/2;C=Math.max(8,Math.min(C,z-j.width-8)),p({left:C,top:w,placement:S})},[r]),b=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(!0),o)},[o]),v=u.useCallback(()=>{f.current&&clearTimeout(f.current),a(!1),p(null)},[]);return u.useEffect(()=>{if(!l)return;const g=requestAnimationFrame(d);return()=>cancelAnimationFrame(g)},[l,d]),u.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:b,onMouseLeave:v,onFocus:b,onBlur:v,style:{display:"inline-block",...i},children:n}),l&&Cn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(c==null?void 0:c.left)??-9999,top:(c==null?void 0:c.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:c?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-X,width:0,height:0,...c.placement==="top"?{bottom:-X,borderTop:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}:{top:-X,borderBottom:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...c.placement==="top"?{bottom:-5,borderTop:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}:{top:-5,borderBottom:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}}})]})]}),document.body)]})},mt={A:"fine",B:"rough",C:"rough",D:"ocr"};function Er(t){return typeof t!="string"?null:t in qt?t:t in mt?mt[t]:null}const Lr=["〇","一","二","三","四","五","六","七","八","九"],yt=["","十","百","千"],Br=["","萬","億"];function Zt(t){if(t===0)return"〇";if(t<0)return`負${Zt(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(Wr(s,o>0)+Br[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Wr(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let s="";for(let i=0;i<r.length;i++){const l=r[i],a=r.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&a===1&&i===0&&!n?s+=yt[a]:s+=Lr[l]+yt[a]}return s.replace(/〇$/,"")}let Te=null,$e=null;const Me=new Set;function $r(){return Te?Promise.resolve():$e||($e=import("opencc-js/t2cn").then(t=>{Te=t.Converter({from:"tw",to:"cn"}),Me.forEach(n=>n())}).catch(()=>{Te=t=>t,Me.forEach(t=>t())}),$e)}function xe(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Te)return;const n=()=>t(r=>r+1);return Me.add(n),$r(),()=>{Me.delete(n)}},[]),Te??(n=>n)}function ve(t,n){return n(t).toLowerCase()}const tt="#fff59d";function je(t,n,r){if(!n)return t;const o=ve(n,r);if(!o)return t;const s=ve(t,r);if(s.length!==t.length)return t;const i=[];let l=0,a=0;for(;l<t.length;){const c=s.indexOf(o,l);if(c===-1){i.push(t.slice(l));break}c>l&&i.push(t.slice(l,c)),i.push(e.jsx("mark",{style:{background:tt,padding:0,color:"inherit"},children:t.slice(c,c+o.length)},a++)),l=c+o.length}return e.jsx(e.Fragment,{children:i})}function nt(t,n,r,o){if(!n)return!0;const s=ve(n,o);return(r?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(l=>typeof l=="string"&&ve(l,o).includes(s))}function Pr(t,n,r){return n?ve(t,r).includes(ve(n,r)):!0}const rt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Ar={考证:"#5d6d7e"};function Fr(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Xt({file:t,isActive:n,onSelect:r,meta:o,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=Fr(t),p=!!(o!=null&&o.vol_label)&&!c.includes(o.vol_label);return e.jsxs("button",{onClick:()=>{i||r(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${tt}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":i?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:i?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:i?.5:1},children:[c,p&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",o.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Qt(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(o=>Qt(o,n)))}function en(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((s,i)=>s+en(i),0))||0;return n+r}function Mr(t,n){const r=[],o=l=>{var a;r.push(...l.files),(a=l.children)==null||a.forEach(o)};if(o(t),r.length===0)return;const s=r.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let i=0;for(const l of s)typeof l=="number"&&(i+=l);return i}function tn({group:t,activeFile:n,onSelect:r,depth:o=0,juanMeta:s,matchStates:i}){var b;const l=Qt(t,n||""),a=Mr(t,i),c=typeof a=="number"&&a>0,p=a===0,[f,x]=u.useState(l||c),h=en(t),d=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{l&&x(!0)},[l]),u.useEffect(()=>{c&&x(!0)},[c]),t.files.length===1&&!d){const v=t.files[0],g=n===v,k=i[v],m=k===0,j=k==="loading",y=typeof k=="number"&&k>0;return e.jsxs("button",{onClick:()=>{m||r(v)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:g?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":y?`${tt}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,y&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:k}),j&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!f),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",h,")"]}),c&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",a]}),a==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),f&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(v=>e.jsx(Xt,{file:v,isActive:n===v,onSelect:r,meta:s==null?void 0:s[v],matchState:i[v]},v))}),d&&t.children.map((v,g)=>e.jsx(tn,{group:v,activeFile:n,onSelect:r,depth:o+1,juanMeta:s,matchStates:i},g))]})]})}function Hr({files:t,groups:n,activeFile:r,onSelect:o,juanMeta:s,matchStates:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((a,c)=>e.jsx(tn,{group:a,activeFile:r,onSelect:o,juanMeta:s,matchStates:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(a=>e.jsx(Xt,{file:a,isActive:r===a,onSelect:o,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function Dr({type:t}){const n=rt[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Or({section:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=D(),s=re(),i=xe(),l=v=>{if(!v)return"";const g=o(v);return r?je(g,r,i):g},[a,c]=u.useState(!1),p=!!t.summary,f=!!t.comment,x=!!t.additional_comment,h=!!(t.content&&t.content.length>60),d=p||f||x||h;u.useEffect(()=>{r&&c(!0)},[r]);const b=!a&&h?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&c(!a),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Zt(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!a&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),a&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),h&&!p&&!f&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function Ur({section:t,highlightQuery:n=""}){const{convert:r}=D(),o=xe(),s=c=>{if(!c)return"";const p=r(c);return n?je(p,n,o):p},[i,l]=u.useState(!1),a=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>a&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:a?"pointer":"default",userSelect:"none"},children:[e.jsx(Dr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),a&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&a&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${rt[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}function Vr({section:t,highlightQuery:n=""}){const{convert:r}=D(),o=xe();if(!t.content&&!t.title)return null;const s=r((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`)),i=n?je(s,n,o):s,l=rt[t.type]||"#717171",a=t.type==="序"||t.type==="结语";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${l}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:l,marginRight:"8px",padding:"1px 5px",border:`1px solid ${l}40`,borderRadius:"2px",background:`${l}08`,verticalAlign:"middle"},children:t.type}),i]})}function Nr(t,n,r){const[o,s]=u.useState({});return u.useEffect(()=>{var p;if(!n||t.length===0)return;let i=!1;const l=t.filter(f=>{var x;return!((x=r==null?void 0:r.current)!=null&&x.has(f))}),a={};for(const f of t)(p=r==null?void 0:r.current)!=null&&p.has(f)&&(a[f]=r.current.get(f));if(Object.keys(a).length>0&&s(a),l.length===0)return;const c=async f=>{var x;try{if(n.getEntry){const g=await n.getEntry(f);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(f);if(!h)return null;const d=h.title||f,b=h.authors,v=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:d,author:v}}catch{return null}};return Promise.all(l.map(async f=>{var h;const x=await c(f);return(h=r==null?void 0:r.current)==null||h.set(f,x),[f,x]})).then(f=>{i||s(x=>{const h={...x};for(const[d,b]of f)h[d]=b;return h})}),()=>{i=!0}},[t.join(","),n]),o}function Yr({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:s=""}){const{convert:i}=D(),l=re(),a=xe(),c=m=>{if(!m)return"";const j=i(m);return s?je(j,s,a):j},[p,f]=u.useState(!1);u.useEffect(()=>{s&&f(!0)},[s]);const x=t.type,h=Ar[x]||"#717171",d=!!t.content,b=t.work_ids||[],v=b.length>1,g=Nr(v?b:[],r,o),k=d&&!p&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>d&&f(!p),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!p&&k&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(k)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:l(b[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),v&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:h,border:`1px solid ${h}40`,borderRadius:"2px",background:`${h}08`},children:x})]})]}),v&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(m=>{const j=g[m],y=j?`${i(j.title)}${j.author?`(${i(j.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:l(m),onClick:z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),z.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",y]},m)})}),p&&d&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${h}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function Kr({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:s}){const{convert:i}=D(),l=xe(),a=n.trim(),c=u.useMemo(()=>a?t.sections.filter(x=>nt(x,a,!0,l)):t.sections,[t.sections,a,l]),p=t.sections.filter(x=>x.type==="考证").length,f=c.filter(x=>x.type==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:a?`${f} / ${p} 條`:`${p} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:c.map((x,h)=>e.jsx(Yr,{section:x,onNavigate:r,transport:o,workLabelCache:s,highlightQuery:a},h))}),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Gr({text:t,highlightQuery:n=""}){const{convert:r}=D(),o=xe(),s=l=>{const a=r(l);return n?je(a,n,o):a},i=t.split(`
|
|
3
|
+
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((l,a)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},a);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},a);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},a);if(!l.trim())return a>0&&!i[a-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},a);const c=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:c.map((p,f)=>p.startsWith("**")&&p.endsWith("**")?e.jsx("strong",{children:s(p.slice(2,-2))},f):e.jsx(u.Fragment,{children:s(p)},f))},a)})})}function Jr({sections:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=D(),s=re(),i=xe(),l=p=>{if(!p)return"";const f=o(p);return r?je(f,r,i):f},a=[];let c=null;for(const p of t)p.type==="类"?(c&&a.push(c),c={category:p.title,categoryContent:p.content||void 0,items:[]}):p.type==="书"?(c||(c={category:"",items:[]}),c.items.push(p)):(p.type==="序"||p.type==="结语")&&(c||(c={category:"",items:[]}),c.items.push(p),p.type==="结语"&&(a.push(c),c=null));return c&&a.push(c),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:a.map((p,f)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[p.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(p.category),p.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(p.categoryContent)})]}),p.items.map((x,h)=>x.type==="序"||x.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(x.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(x.title),children:e.jsx("strong",{children:l(x.title)})}):e.jsx("strong",{children:l(x.title)}),x.content&&l(x.content)]},h))]},f))})}function qr({juan:t,rawText:n,searchQuery:r,onNavigate:o}){const{convert:s}=D(),i=xe(),[l,a]=u.useState("catalog"),c=r.trim(),p=u.useMemo(()=>c?t.sections.filter(d=>nt(d,c,!1,i)):t.sections,[t.sections,c,i]),f=t.sections.filter(d=>d.type==="书").length,x=t.sections.filter(d=>d.type==="詩").length,h=c?p.filter(d=>d.type==="书"||d.type==="詩").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(d=>e.jsx("button",{onClick:()=>a(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${x>0?`${x} 首`:`${f} 部書`}`:x>0?`${x} 首`:`${f} 部书`})]}),l==="raw"&&(n?e.jsx(Gr,{text:n,highlightQuery:c}):e.jsx(Jr,{sections:t.sections,onNavigate:o,highlightQuery:c})),l==="catalog"&&p.map((d,b)=>d.type==="书"||d.type==="詩"?e.jsx(Or,{section:d,onNavigate:o,highlightQuery:c},b):d.type==="类"?e.jsx(Ur,{section:d,highlightQuery:c},b):e.jsx(Vr,{section:d,highlightQuery:c},b)),l==="catalog"&&p.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function nn(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function vt(t){const n=nn(t);return n.length>0?n[0]:null}function Zr(t){const{workId:n,transport:r,files:o,activeFile:s,activeJuan:i,activeRawText:l,query:a,isKaozhen:c}=t,p=xe(),f=u.useRef(new Map),[x,h]=u.useState({});u.useEffect(()=>{s&&i&&f.current.set(s,{juan:i,rawText:l})},[s,i,l]),u.useEffect(()=>{f.current.clear(),h({})},[n]);const d=u.useCallback((b,v)=>{let g=0;if(b.juan)for(const k of b.juan.sections)nt(k,v,c,p)&&g++;return g===0&&b.rawText&&Pr(b.rawText,v,p)&&(g=1),g},[c,p]);return u.useEffect(()=>{const b=a.trim();if(!b){h({});return}if(!n||!(r!=null&&r.getCollatedJuan)||o.length===0)return;let v=!1;const g={},k=[];for(const S of o){const w=f.current.get(S);w?g[S]=d(w,b):(g[S]="loading",k.push(S))}h(g);const m=8;let j=0;const y=async()=>{var S;for(;j<k.length;){if(v)return;const w=j++,C=k[w];try{const[B,R]=await Promise.all([r.getCollatedJuan(n,C),((S=r.getCollatedJuanText)==null?void 0:S.call(r,n,C))??Promise.resolve(null)]),L={juan:B,rawText:R};if(f.current.set(C,L),v)return;h(M=>({...M,[C]:d(L,b)}))}catch{if(v)return;h(B=>({...B,[C]:0}))}}},z=Array.from({length:Math.min(m,k.length)},()=>y());return Promise.all(z),()=>{v=!0}},[a,n,r,o.join(","),d,p]),{matchStates:x}}const rn=({index:t,workId:n,transport:r,onNavigate:o,activeJuan:s,onJuanChange:i,className:l,style:a})=>{const[c,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[b,v]=u.useState(null),[g,k]=u.useState(null),[m,j]=u.useState(!1),[y,z]=u.useState(null),[S,w]=u.useState(""),C=u.useRef(new Map),B=s??b,R=u.useCallback(_=>{v(_),i==null||i(_)},[i]),L=t||c;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let _=!1;return x(!0),d(null),r.getCollatedEditionIndex(n).then(E=>{if(!_)if(!E)d("未找到整理本数据");else{p(E);const N=vt(E);!s&&N&&R(N)}}).catch(E=>{_||d(E instanceof Error?E.message:"加载失败")}).finally(()=>{_||x(!1)}),()=>{_=!0}},[t,n,r,s,R]),u.useEffect(()=>{const _=t||c;if(_&&!B){const E=vt(_);E&&R(E)}},[t,c,B,R]);const M=n||(L==null?void 0:L.work_id),I=u.useCallback(async _=>{var E;if(!(!M||!(r!=null&&r.getCollatedJuan))){j(!0),k(null),z(null);try{const[N,V]=await Promise.all([r.getCollatedJuan(M,_),((E=r.getCollatedJuanText)==null?void 0:E.call(r,M,_))??Promise.resolve(null)]);k(N),z(V)}catch{k(null),z(null)}finally{j(!1)}}},[M,r]);u.useEffect(()=>{B&&I(B)},[B,I]);const W=_=>{R(_)};if(f)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!L)return null;const $=L.type==="kaozhen",U=nn(L);return e.jsx(Xr,{className:l,style:a,index:L,allFiles:U,isKaozhen:$,effectiveWorkId:M,transport:r,activeFile:B,handleSelectFile:W,juanData:g,juanRawText:y,juanLoading:m,searchQuery:S,setSearchQuery:w,onNavigate:o,workLabelCacheRef:C})},Xr=({className:t,style:n,index:r,allFiles:o,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:a,handleSelectFile:c,juanData:p,juanRawText:f,juanLoading:x,searchQuery:h,setSearchQuery:d,onNavigate:b,workLabelCacheRef:v})=>{const{matchStates:g}=Zr({workId:i,transport:l,files:o,activeFile:a,activeJuan:p,activeRawText:f,query:h,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:h,onChange:k=>d(k.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s?e.jsxs(e.Fragment,{children:[r.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_juan})," 卷"]})}),r.text_quality&&(()=>{const k=Er(r.text_quality.grade);return k?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Rr,{content:Ir[k],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Tr[k],cursor:"help"},children:qt[k]})}),r.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",r.text_quality.source_note]})]}):null})()]}),e.jsx(Hr,{files:o,groups:r.juan_groups,activeFile:a,onSelect:c,juanMeta:r.juan_metadata,matchStates:g}),x?e.jsx(he,{}):p?s?e.jsx(Kr,{juan:p,searchQuery:h,onNavigate:b,transport:l,workLabelCache:v}):e.jsx(qr,{juan:p,rawText:f,searchQuery:h,onNavigate:b}):a?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,r.references&&r.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),r.references.map((k,m)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[m+1,". "]}),k.url?e.jsx("a",{href:k.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:k.title}):e.jsx("span",{children:k.title}),k.author&&e.jsxs("span",{children:[",",k.author]}),k.note&&e.jsxs("span",{children:["。",k.note]})]},m))]})]})},Qr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},eo={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function to(t){try{const n=new Date(t),r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}`}catch{return t}}const on=({items:t,loading:n})=>{const r=re();return n?e.jsx(he,{}):t.length===0?e.jsx("div",{style:no,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=Qr[o.type],i=eo[o.status];return e.jsxs("div",{style:ro,children:[e.jsxs("div",{style:oo,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...jt,background:s.color},children:s.label}),e.jsx("span",{style:{...jt,background:i.color},children:i.label})]}),e.jsx("span",{style:io,children:to(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:so,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:St,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:St,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:lo,children:o.content}),o.reply&&e.jsxs("div",{style:ao,children:[e.jsx("div",{style:co,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},no={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ro={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},oo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},jt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},io={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},so={fontSize:"12px",marginBottom:"6px"},St={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},lo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},ao={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},co={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Ze=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:s,feedbackApiUrl:i})=>{const l=P(),[a,c]=u.useState(null),[p,f]=u.useState([]),[x,h]=u.useState("recommend"),[d,b]=u.useState([]),[v,g]=u.useState(!1),k=o??x,m=R=>{h(R),s==null||s(R)},[j,y]=u.useState(!0),[z,S]=u.useState(null),[w,C]=u.useState(null);u.useEffect(()=>{if(!t.getAllEntries)return;let R=!1;return t.getAllEntries().then(L=>{if(R)return;const M=L.filter($=>$.type==="work").length,I=L.filter($=>$.type==="book").length,W=L.filter($=>$.type==="collection").length;c({works:M,books:I,collections:W})}).catch(()=>{}),()=>{R=!0}},[t]),u.useEffect(()=>{let R=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const M=await t.getRecommended();if(M!=null&&M.groups)return M.groups.flatMap(I=>I.items.map(W=>({...W,group:I.name})))}catch{}return[]})().then(async M=>{if(R)return;const I=M.filter($=>$.id);if(I.length===0){y(!1);return}const W=await Promise.all(I.map(async $=>{try{let U=null;if(t.getEntry)U=await t.getEntry($.id);else{const _=await t.getItem($.id);_&&(U={id:$.id,title:_.title||$.id,type:_.type||"work"})}if(U)return{...U,group:$.group,fallbackDescription:$.description}}catch{}return{id:$.id,title:$.title,type:O.extractType($.id),group:$.group,fallbackDescription:$.description}}));R||(f(W.filter($=>$!==null)),y(!1))}),()=>{R=!0}},[t,r]),u.useEffect(()=>{if(!t.getResourceProgress)return;let R=!1;return t.getResourceProgress().then(L=>{R||S(L)}).catch(()=>{}),()=>{R=!0}},[t]),u.useEffect(()=>{if(!t.getSiteProgress)return;let R=!1;return t.getSiteProgress().then(L=>{R||C(L)}).catch(()=>{}),()=>{R=!0}},[t]),u.useEffect(()=>{if(!i||k!=="feedback")return;let R=!1;return g(!0),fetch(i).then(L=>L.json()).then(L=>{!R&&L.success&&b(L.items||[])}).catch(()=>{}).finally(()=>{R||g(!1)}),()=>{R=!0}},[i,k]);const B=R=>{switch(R){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Pe,{label:l.home.recommendTab,active:k==="recommend",onClick:()=>m("recommend")}),e.jsx(Pe,{label:l.home.catalogTab,active:k==="catalog",onClick:()=>m("catalog")}),e.jsx(Pe,{label:l.home.siteTab,active:k==="site",onClick:()=>m("site")}),i&&e.jsx(Pe,{label:l.home.feedbackTab,active:k==="feedback",onClick:()=>m("feedback")})]}),k==="recommend"&&e.jsx(po,{recommended:p,loading:j,onNavigate:n,getIcon:B,t:l}),k==="catalog"&&e.jsx(xo,{progress:z,t:l,onNavigate:n}),k==="site"&&e.jsx(fo,{progress:w,t:l,totalWorks:(a==null?void 0:a.works)??0}),k==="feedback"&&i&&e.jsx(on,{items:d,loading:v})]})})},Pe=({label:t,active:n,onClick:r})=>e.jsx("button",{onClick:r,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),po=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:s})=>{const i=re();if(n)return e.jsx(he,{});if(t.length===0)return null;const l=new Map;for(const a of t){const c=a.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(a)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([a,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const f=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return e.jsxs("a",{href:i(p.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),r==null||r(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(p.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:p.edition})]}),f&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f})]})]},p.id)})})]},a))})},xo=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(he,{});const o=[...t.resources].sort((a,c)=>a.priority-c.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(a=>{const c=o.filter(p=>p.status===a);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[a]}}),i[a]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>e.jsx(uo,{item:p,t:n,statusColor:l[a],onNavigate:r},p.id))})]},a)})})},uo=({item:t,t:n,statusColor:r,onNavigate:o})=>{const s=re(),i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&o?e.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(c))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Le(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${i}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},fo=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(he,{});const o=[...t.resources].sort((c,p)=>c.priority-p.priority),s=o.filter(c=>c.imported>0),i=o.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),a=r>0?Math.round(l/r*100):0;return e.jsxs("div",{children:[r>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",a,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>e.jsx(kt,{item:c,t:n,totalWorks:r},c.id))})]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(c=>e.jsx(kt,{item:c,t:n,totalWorks:r},c.id))})]})]})},kt=({item:t,t:n,totalWorks:r})=>{const o=r>0?Math.round(t.imported/r*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&r>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},wt="(max-width: 768px)";function go(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(wt).matches);return u.useEffect(()=>{const r=window.matchMedia(wt),o=s=>n(s.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const ho=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:s})=>{var U;const i=P(),{convert:l}=D(),a=go(),[c,p]=u.useState(null),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,v]=u.useState("detail"),[g,k]=u.useState([]),[m,j]=u.useState(!1),[y,z]=u.useState(null),[S,w]=u.useState(!1),C=u.useCallback(async _=>{if(!t.getCollatedEditionIndex){z(null);return}w(!0);try{const E=await t.getCollatedEditionIndex(_);z(E)}catch{z(null)}finally{w(!1)}},[t]),B=u.useCallback(async _=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){k([]);return}j(!0);try{if(t.getCollectionCatalogs){const E=await t.getCollectionCatalogs(_);k(E||[])}else if(t.getCollectionCatalog){const E=await t.getCollectionCatalog(_);k(E?[{resource_id:"",data:E}]:[])}}catch{k([])}finally{j(!1)}},[t]),R=u.useCallback(async _=>{if(r){r(_);return}p(_),x(null),k([]),z(null),v("detail"),d(!0);try{const E=await t.getItem(_.id);E&&(x(E),E.type==="collection"?B(_.id):E.type==="work"&&E.has_collated&&C(_.id))}catch(E){console.error("加载详情失败:",E)}finally{d(!1)}},[t,r,B,C]),L=u.useCallback(async _=>{x(null),k([]),z(null),v("detail"),d(!0);try{const E=await t.getItem(_);E&&(x(E),p({id:_,title:E.title||_,type:E.type||"book"}),E.type==="collection"?B(_):E.type==="work"&&E.has_collated&&C(_))}catch(E){console.error("导航失败:",E)}finally{d(!1)}},[t,B,C]),M=(f==null?void 0:f.type)==="collection"&&(g.length>0||m)||(f==null?void 0:f.type)==="work"&&(y||S),I=a&&(h||f),W=u.useCallback(()=>{p(null),x(null),k([]),z(null),v("detail")},[]),$=e.jsx(e.Fragment,{children:h?e.jsx(he,{}):f?e.jsxs(e.Fragment,{children:[(M||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[M&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:Ae(b==="detail"),children:i.detailTab.basicInfo}),f.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Ae(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),f.type==="collection"&&g.map(_=>e.jsx("button",{onClick:()=>v(`catalog:${_.resource_id}`),style:Ae(b===`catalog:${_.resource_id}`),children:_.short_name?`${l(_.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},_.resource_id)),f.type==="work"&&(y||S)&&e.jsxs("button",{onClick:()=>v("collated"),style:Ae(b==="collated"),children:[i.detailTab.collatedEdition,S&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(et,{data:f,transport:t,onNavigate:L}):b.startsWith("catalog:")?e.jsx(Jt,{data:(U=g.find(_=>`catalog:${_.resource_id}`===b))==null?void 0:U.data,onNavigate:L}):b==="collated"?e.jsx(rn,{index:y||void 0,workId:f.id,transport:t,onNavigate:L}):null})]}):e.jsx(Ze,{transport:t,onNavigate:L,recommendedIds:o})});return a?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:I?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:W,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(qe,{transport:t,onEntryClick:R,hideModeIndicator:n}),!f&&e.jsx(Ze,{transport:t,onNavigate:L,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(qe,{transport:t,onEntryClick:R,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Ae(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const bo=({data:t,onNavigate:n,className:r,style:o})=>{var f;const s=P(),{convert:i}=D(),[l,a]=u.useState(((f=t.divisions[0])==null?void 0:f.name)??null),[c,p]=u.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(mo,{division:x,expanded:l===x.name,onToggle:()=>a(l===x.name?null:x.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},x.name))})]})},mo=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:s,onNavigate:i})=>{const{convert:l}=D(),a=t.categories.reduce((c,p)=>{const f=p.stats||{zhulu:0,cunmu:0};return c+(f.zhulu||0)+(f.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const p=`${t.name}/${c.name}`;return e.jsx(yo,{category:c,expanded:o===p,onToggle:()=>s(p),onNavigate:i},c.name)})})]})},yo=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var c,p,f,x;const{convert:s}=D(),i=((c=t.books)==null?void 0:c.zhulu)||[],l=((p=t.books)==null?void 0:p.cunmu)||[],a=(((f=t.stats)==null?void 0:f.zhulu)||i.length)+(((x=t.stats)==null?void 0:x.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Ct,{label:"著錄",books:i,onNavigate:o}),l.length>0&&e.jsx(Ct,{label:"存目",books:l,onNavigate:o})]})]})},Ct=({label:t,books:n,onNavigate:r})=>{const{convert:o}=D(),s=re(),[i,l]=u.useState(n.length<=20),a=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map((c,p)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:c.work_id&&r?e.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),r(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(c.title)}):o(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(c.author).slice(0,20)})]},p))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},oe=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:s})=>{const i=P();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:jo,children:"AI"}),n&&e.jsx("button",{onClick:n,style:vo,children:i.action.save})]})]}),s]})},vo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},jo={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ee=({label:t,value:n,onChange:r,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:i=>r(i.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),ge=({value:t,onChange:n,placeholder:r})=>{const o=u.useRef(null);return u.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:r,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},He=({children:t,color:n,style:r})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...r},children:t});function So(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Fe=({value:t,onChange:n,label:r})=>{const[o,s]=u.useState(!1),i=u.useRef(null),l=So(t||"");return u.useEffect(()=>{o&&i.current&&i.current.focus()},[o]),!o&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:_t,children:r}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(He,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:_t,children:r}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:a=>n(a.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},_t={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function ko(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function wo(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const sn=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=P(),[s,i]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},a=x=>{n(t.filter((h,d)=>d!==x)),s===x&&i(null)},c=(x,h,d)=>{const b=[...t];b[x]={...b[x],[h]:d},n(b)},p=(x,h)=>{const d=[...t];d[x]={...d[x],type:h,id:"",name:""},n(d),h==="bookID"&&r&&r(b=>{const v=[...t];v[x]={...v[x],id:b.id,name:b.title,type:"bookID"},n(v)})},f=x=>{r&&r(h=>{const d=[...t];d[x]={...d[x],id:h.id,name:h.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>i(s===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${o.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:ko(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:wo(x.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...zt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>p(h,"url"),style:{...zt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:It,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>f(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>f(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:It,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>c(h,"name",d.target.value),placeholder:o.editor.sourceNamePlaceholder,style:me})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:d=>c(h,"id",d.target.value),placeholder:"https://...",style:me})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...pe,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>c(h,"details",d.target.value),placeholder:o.editor.detailsPlaceholder,style:me})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:d=>c(h,"position",d.target.value),placeholder:"如: 卷三, p.52",style:me})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:d=>c(h,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:me})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:d=>c(h,"processor_version",d.target.value),placeholder:"如: v0.1",style:me})]})]})]})]})})]},h)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},me={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},zt={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},It={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function ln(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function an(t){return!t||t.length===0?"":JSON.stringify(t)}const cn=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:a,childCollections:c,containedBooks:p,siblingBooks:f,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:d,onCreateAndLink:b,onSaveRelations:v})=>{const g=P();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),v&&e.jsx("button",{onClick:v,style:Co,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(_e,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(_e,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),i&&f&&f.length>0&&e.jsx(ye,{direction:"horizontal",title:`${g.relation.siblingVersions} (${f.length})`,entities:f,onView:d,onAdd:()=>b("siblingBook","book",{workId:i.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(_e,{direction:"up",title:g.relation.parentWork,entity:o,onView:d,onUnlink:()=>h("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),a&&a.length>0&&e.jsx(ye,{direction:"down",title:`${g.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),c&&c.length>0&&e.jsx(ye,{direction:"down",title:`${g.relation.collectionImpl} (${c.length})`,entities:c,onView:d,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(ye,{direction:"down",title:`${g.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>b("childBook","book",{workId:n}),addLabel:g.action.addVersion,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(_e,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(_e,{direction:"up",title:g.relation.parentCollection,entity:s,onView:d,onUnlink:()=>h("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ye,{direction:"down",title:`${g.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:d,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(ye,{direction:"down",title:`${g.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},_e=({direction:t,title:n,entity:r,onView:o,onUnlink:s,onLink:i,onCreate:l,linkLabel:a,createLabel:c,notLinkedLabel:p,viewLabel:f,unlinkLabel:x})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:d}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:dn(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Tt,{onClick:()=>o(r),title:f,children:"👁️"}),e.jsx(Tt,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:p}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Xe,{onClick:i,children:a}),e.jsx(Xe,{onClick:l,primary:!0,children:c})]})]})},ye=({direction:t,title:n,entities:r,onView:o,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:a})=>{const[c,p]=u.useState(!1),f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=c?r:r.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>o(d),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:dn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),r.length>5&&!c&&e.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Xe,{onClick:s,primary:!0,children:["+ ",i]})})]})},Tt=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),Xe=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:r});function dn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Co={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},pn=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:s,onCreate:i,searchResults:l,onSearch:a,isLoading:c,excludeId:p})=>{const[f,x]=u.useState(""),h=p?l.filter(g=>g.id!==p):l;u.useEffect(()=>{t&&(x(""),a(""))},[t]);const d=g=>{x(g),a(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:_o,children:e.jsxs("div",{style:zo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:s,style:Io,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:f,onChange:g=>d(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:To})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Ke,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>o(g),style:Ro,children:[e.jsx("span",{style:{fontSize:"16px"},children:v}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):f?e.jsxs("div",{style:Ke,children:["未找到匹配的",b]}):e.jsxs("div",{style:Ke,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:i,style:Eo,children:["创建新",b,"并关联"]})]})]})})},_o={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},zo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Io={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},To={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Ro={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ke={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Eo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Rt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Lo={work:"📜",book:"📖",collection:"📚",entity:"👤"},xn=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:s,onCancel:i})=>{const[l,a]=u.useState(""),c=u.useRef(null);u.useEffect(()=>{t&&(a((o==null?void 0:o.title)||""),setTimeout(()=>{var h,d;(h=c.current)==null||h.focus(),(d=c.current)==null||d.select()},100))},[t,o==null?void 0:o.title]);const p=h=>{h.key==="Enter"&&l.trim()?f():h.key==="Escape"&&i()},f=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!t)return null;const x=()=>{switch(r){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Rt[n]}`}};return e.jsx("div",{style:Bo,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Wo,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Lo[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:c,type:"text",value:l,onChange:h=>a(h.target.value),onKeyDown:p,placeholder:`请输入${Rt[n]}名称...`,style:$o})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:Po,children:"取消"}),e.jsx("button",{onClick:f,disabled:!l.trim(),style:{...Ao,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Bo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Wo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},$o={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},Po={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ao={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Fo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function un(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Mo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const fn=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:a,onCancel:c,onCreate:p,onSearch:f})=>{const[x,h]=u.useState(""),[d,b]=u.useState([]),[v,g]=u.useState(!1),[k,m]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),m(o.length>0?"recent":"search"))},[t,o.length]),u.useEffect(()=>{if(!x.trim()){b([]);return}const C=setTimeout(async()=>{g(!0);try{b(await f(x,r))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(C)},[x,r,f]);const j=u.useCallback(C=>{h(C.target.value),C.target.value.trim()&&m("search")},[]),y=u.useCallback(C=>s?C.filter(B=>B.id!==s):C,[s]);if(!t)return null;const z=n||(r==="all"?"选择实体":`选择${un(r)}`),S=y(o),w=y(d);return e.jsx("div",{style:Do,children:e.jsxs("div",{style:Oo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:z}),e.jsx("button",{onClick:c,style:Uo,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Vo}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),S.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Et,{active:k==="recent",onClick:()=>m("recent"),children:["最近使用 (",S.length,")"]}),e.jsxs(Et,{active:k==="search",onClick:()=>m("search"),children:["搜索结果 ",w.length>0&&`(${w.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:k==="recent"&&S.length>0?e.jsx(Lt,{entities:S,onSelect:a}):x.trim()?v?e.jsx(Ge,{message:"搜索中..."}):w.length>0?e.jsx(Lt,{entities:w,onSelect:a}):e.jsx(Ge,{message:"未找到匹配的结果"}):e.jsx(Ge,{message:"输入关键词开始搜索"})}),i&&p&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:p,style:No,children:l||"创建新实体"})]})]})})},Et=({active:t,onClick:n,children:r})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:r}),Lt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(Ho,{entity:r,onClick:()=>n(r)},r.id))}),Ho=({entity:t,onClick:n})=>{const[r,o]=u.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Fo(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Mo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:un(t.type)})]})},Ge=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Do={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Oo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Uo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Vo={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},No={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Yo={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Ko={work:"📜",collection:"📚",book:"📖",entity:"👤"},gn=({data:t,onChange:n,onSave:r,transport:o,onNavigate:s,showDelete:i,onDelete:l,onAskAI:a,renderSectionActions:c,onDownloadResource:p,downloadStatuses:f,relations:x,onRelationsChange:h})=>{var te;const d=P(),[b,v]=u.useState(!1),[g,k]=u.useState("work"),[m,j]=u.useState(""),[y,z]=u.useState(""),[S,w]=u.useState([]),[C,B]=u.useState(!1),[R,L]=u.useState(!1),[M,I]=u.useState("work"),[W,$]=u.useState(""),[U,_]=u.useState(),[E,N]=u.useState(!1),[V,F]=u.useState(null),[se,Q]=u.useState([]);u.useRef(null);const de=t.type,fe=de==="work",ue=de==="collection",q=de==="book",Y=u.useCallback((T,H)=>{n({...t,[T]:H})},[t,n]),Oe=u.useCallback((T,H)=>{j(T),k(H),z(d.editor.selectToLink+d.indexType[H]),w([]),v(!0)},[d]),Ue=u.useCallback(T=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,T)},[o,t.id]),Se=u.useCallback(T=>{s==null||s(T.id,T.type)},[s]),ke=u.useCallback((T,H,J)=>{const le={...J,author:(J==null?void 0:J.author)||t.author,dynasty:(J==null?void 0:J.dynasty)||t.dynasty};I(H),$(T),_(le),L(!0)},[t.author,t.dynasty]),Ve=u.useCallback((T,H)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,W,{type:M,title:T,inheritData:H}),L(!1)},[o,t.id,W,M]),Be=u.useCallback(T=>{if(!T.trim()){w([]);return}B(!0),o!=null&&o.searchEntities&&o.searchEntities(T,g).then(H=>{w(H),B(!1)}).catch(()=>{w([]),B(!1)})},[o,g]),Ne=u.useCallback(T=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,m,T.id),v(!1)},[o,t.id,m]),A=u.useCallback(()=>{r()},[r]),K=u.useCallback(T=>{F(()=>T),N(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(Q).catch(()=>{})},[o]),Z=u.useCallback((T,H)=>o!=null&&o.searchEntities?o.searchEntities(T,H==="all"?void 0:H):Promise.resolve([]),[o]),G=u.useCallback(T=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(T),Q(H=>[T,...H.filter(J=>J.id!==T.id)].slice(0,10)),V==null||V(T),N(!1),F(null)},[o,V]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ko[de]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(He,{children:t.id}),e.jsx(He,{color:Yo[de],children:d.indexType[de]})]})}),e.jsx(oe,{title:d.section.basicInfo,onSave:r,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Fe,{label:fe?d.editor.workTitle:ue?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:T=>Y("title",T)}),q&&e.jsx(Fe,{label:d.editor.belongsToWork,value:t.workName||"",onChange:T=>Y("workName",T)}),e.jsx(ee,{label:d.editor.authorLabel,value:t.author||"",onChange:T=>Y("author",T)}),e.jsx(ee,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>Y("dynasty",T)}),(q||ue)&&e.jsx(Fe,{label:d.editor.containedIn,value:t.collection||"",onChange:T=>Y("collection",T)}),(q||ue)&&e.jsx(ee,{label:d.editor.holderLabel,value:t.holder||"",onChange:T=>Y("holder",T)}),(q||ue)&&e.jsx(ee,{label:q?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:T=>Y("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>Y("firstImage",T)})})]})}),e.jsx(oe,{title:d.section.description,onSave:r,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(ge,{value:t.description||"",onChange:T=>Y("description",T),placeholder:d.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(oe,{title:d.section.additionalWorks,onSave:r,children:e.jsx(Go,{items:t.additional_works||[],onChange:T=>Y("additional_works",T)})}),e.jsx(oe,{title:d.section.indexedBy,onSave:r,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(Jo,{items:t.indexed_by||[],onChange:T=>Y("indexed_by",T)})}),e.jsx(oe,{title:d.section.emendatedBy,onSave:r,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(qo,{items:t.emendated_by||[],onChange:T=>Y("emendated_by",T)})}),e.jsx(oe,{title:d.section.textResources,onSave:r,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Je,{items:t.resources||[],onChange:T=>Y("resources",T),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(oe,{title:d.section.imageResources,onSave:r,children:e.jsx(Je,{items:t.resources||[],onChange:T=>Y("resources",T),onDownload:p,downloadStatuses:f,filterType:"image"})}),e.jsx(oe,{title:d.section.sources,onSave:r,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(sn,{items:ln(t.sources||""),onChange:T=>Y("sources",an(T)),onOpenEntityPicker:K})}),(q||ue)&&e.jsx(oe,{title:d.section.provenance,onSave:r,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(ge,{value:t.provenance||"",onChange:T=>Y("provenance",T),placeholder:d.editor.provenancePlaceholder})}),q&&e.jsx(oe,{title:d.section.otherEditions,onSave:r,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(ge,{value:t.otherEditions||"",onChange:T=>Y("otherEditions",T),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(cn,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:Oe,onUnlinkEntity:Ue,onViewEntity:Se,onCreateAndLink:ke,onSaveRelations:A}),i&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:d.editor.deleteEntity})]}),e.jsx(pn,{isOpen:b,entityType:g,title:y,onSelect:Ne,onCancel:()=>v(!1),onCreate:()=>{v(!1),ke(m,g)},searchResults:S,onSearch:Be,isLoading:C,excludeId:t.id}),e.jsx(xn,{isOpen:R,entityType:M,relationField:W,inheritData:U,onConfirm:Ve,onCancel:()=>L(!1)}),e.jsx(fn,{isOpen:E,title:d.action.selectBookOrWork,filterType:"all",recentEntities:se,excludeId:t.id,onSelect:G,onCancel:()=>{N(!1),F(null)},onSearch:Z})]})};function Go({items:t,onChange:n}){const r=P(),o=(l,a,c)=>{const p=t.map((f,x)=>x===l?{...f,[a]:c}:f);n(p)},s=l=>n(t.filter((a,c)=>c!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ee,{label:r.editor.bookNameLabel,value:l.book_title,onChange:c=>o(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ee,{label:r.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>o(a,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>s(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r.action.addAdditionalWork})]})}function hn({items:t,onChange:n,showMeta:r,addLabel:o}){const s=P(),[i,l]=u.useState(null),a=(f,x,h)=>{const d=t.map((b,v)=>v===f?{...b,[x]:h||void 0}:b);n(d)},c=f=>{n(t.filter((x,h)=>h!==f)),i===f&&l(null)},p=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,x)=>{const h=i===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(h?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:f.source||s.editor.unnamedSource}),f.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:f.source_bid}),e.jsx("button",{onClick:d=>{d.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&r&&(f.title_info||f.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[f.title_info,f.title_info&&f.author_info&&" — ",f.author_info]}),h&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:s.label.sourceName,value:f.source,onChange:d=>a(x,"source",d)}),e.jsx(ee,{label:s.label.sourceBid,value:f.source_bid||"",onChange:d=>a(x,"source_bid",d)})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:s.label.titleInfo,value:f.title_info||"",onChange:d=>a(x,"title_info",d)}),e.jsx(ee,{label:s.label.authorInfo,value:f.author_info||"",onChange:d=>a(x,"author_info",d)})]}),e.jsx(ee,{label:s.label.edition,value:f.edition||"",onChange:d=>a(x,"edition",d)})]}),e.jsx(ge,{value:f.summary||"",onChange:d=>a(x,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(ge,{value:f.comment||"",onChange:d=>a(x,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(ge,{value:f.additional_comment||"",onChange:d=>a(x,"additional_comment",d),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o})]})}function Jo({items:t,onChange:n}){const r=P();return e.jsx(hn,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function qo({items:t,onChange:n}){const r=P();return e.jsx(hn,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function bn(t){var a,c,p,f,x,h,d;const n=((c=(a=t.authors)==null?void 0:a[0])==null?void 0:c.name)||"",r=((p=t.publication_info)==null?void 0:p.year)||"",o=((f=t.current_location)==null?void 0:f.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",l={id:t.id,title:t.title,type:t.type,author:n,dynasty:r,holder:o,pages:s,description:i,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const v=b.related_works.find(g=>g.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const b=t;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(d=b.contained_in[0])==null?void 0:d.id)}return l}function Zo(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const Xo=t=>{const{data:n,id:r,transport:o,mode:s="view",onModeChange:i,onChange:l,onSave:a,onDelete:c,onNavigate:p,renderLink:f,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:v,onRelationsChange:g,headerExtra:k,className:m,style:j}=t;P();const[y,z]=u.useState(s),S=i?s:y;u.useEffect(()=>{s!==y&&z(s)},[s]);const w=u.useCallback(()=>{const W=S==="view"?"edit":"view";i?i(W):z(W)},[S,i]),[C,B]=u.useState(null);u.useEffect(()=>{r&&o&&o.getItem(r).then(W=>{W&&B(W)})},[r,o]);const R=n||C,L=u.useMemo(()=>R?bn(R):null,[R]),M=i||!n?e.jsx("button",{onClick:w,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:S==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:S==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:S==="view"?"切换到编辑模式":"切换到查看模式",children:S==="view"?"✏️ 编辑":"👁 查看"}):null,I=e.jsxs(e.Fragment,{children:[M,k]});return!R&&!L?e.jsx(he,{}):S==="view"?e.jsx(et,{data:R,transport:o,onNavigate:p?W=>p(W):void 0,renderLink:f,headerExtra:I,className:m,style:j}):L?e.jsxs("div",{className:m,style:j,children:[I&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:I}),e.jsx(gn,{data:L,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:v,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Bt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],mn=({isOpen:t,onClose:n,onSubmit:r,feedbackListUrl:o})=>{const[s,i]=u.useState(null),[l,a]=u.useState(""),[c,p]=u.useState("idle"),[f,x]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(i(null),a(""),p("idle"),x(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[s]),u.useEffect(()=>{if(c==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[c,n]),u.useEffect(()=>{if(!t)return;const g=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const d=async()=>{if(!(!s||!l.trim())){p("submitting"),x("");try{await r({type:s,content:l.trim()}),p("success")}catch(g){p("error"),x(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&l.trim()&&c!=="submitting",v=Bt.find(g=>g.value===s);return e.jsx("div",{style:Qo,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:ei,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:ti,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ni,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:li,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Bt.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...ri,...s===g.value?oi:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:l,onChange:g=>a(g.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||c==="submitting",style:{...ii,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),c==="error"&&e.jsx("div",{style:ai,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...si,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},Qo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ei={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ti={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ni={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ri={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},oi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ii={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},si={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},li={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ai={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ci=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:r})=>{const[o,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...di,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(mn,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:r})]})},di={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Wt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],pi=({onSubmit:t})=>{const[n,r]=u.useState("bug"),[o,s]=u.useState(""),[i,l]=u.useState("idle"),[a,c]=u.useState(""),p=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=p.current)==null?void 0:d.focus()},100)},[n]);const f=async()=>{if(!(!n||!o.trim())){l("submitting"),c("");try{await t({type:n,content:o.trim()}),l("success"),s(""),r("bug")}catch(d){l("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&o.trim()&&i!=="submitting",h=Wt.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:$t,children:e.jsxs("div",{style:hi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:bi,children:"继续提交"})]})}):e.jsxs("div",{style:$t,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Wt.map(d=>e.jsxs("button",{onClick:()=>r(d.value),style:{...xi,...n===d.value?ui:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:p,value:o,onChange:d=>s(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...fi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[o.length," / 2000"]}),e.jsx("button",{onClick:f,disabled:!x,style:{...gi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:mi,children:a})]})},$t={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},xi={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ui={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},fi={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},gi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},hi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},bi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},mi={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},yi=({style:t})=>{const n=u.useContext(Ee);if(!n)return null;const{locale:r,setLocale:o}=n,s=r==="zh-Hant",i=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})};exports.BidLink=O.BidLink;exports.BookIndexError=O.BookIndexError;exports.BookIndexManager=O.BookIndexManager;exports.BookIndexStorage=O.BookIndexStorage;exports.BundleStorage=O.BundleStorage;exports.ConfigError=O.ConfigError;exports.GithubStorage=O.GithubStorage;exports.IdGenerationError=O.IdGenerationError;exports.IdGenerator=O.IdGenerator;exports.LocalStorage=O.LocalStorage;exports.MigrationError=O.MigrationError;exports.StorageError=O.StorageError;exports.base36Decode=O.base36Decode;exports.base36Encode=O.base36Encode;exports.base58Decode=O.base58Decode;exports.buildId=O.buildId;exports.decodeId=O.decodeId;exports.decodeIdString=O.decodeIdString;exports.encodeId=O.encodeId;exports.extractIdFromUrl=O.extractIdFromUrl;exports.extractStatus=O.extractStatus;exports.extractType=O.extractType;exports.normalizeCatalog=O.normalizeCatalog;exports.parseId=O.parseId;exports.smartDecode=O.smartDecode;exports.validateResource=O.validateResource;exports.Badge=He;exports.BidUrlProvider=zn;exports.CollatedEdition=rn;exports.CollectionCatalog=Jt;exports.CreateEntityDialog=xn;exports.EmendatedBySection=Kt;exports.EntityDetail=Ot;exports.EntityPickerDialog=fn;exports.EntitySelector=pn;exports.FeedbackButton=ci;exports.FeedbackDialog=mn;exports.FeedbackForm=pi;exports.FeedbackList=on;exports.FormInput=ee;exports.FormTextArea=ge;exports.HomePage=Ze;exports.IndexApp=ho;exports.IndexBrowser=qe;exports.IndexDetail=et;exports.IndexEditor=gn;exports.IndexView=Xo;exports.LocaleContext=Ee;exports.LocaleProvider=Bn;exports.LocaleToggle=yi;exports.ModeIndicator=Ht;exports.RelationPanel=cn;exports.ResourceEditor=Je;exports.ResourceList=Qe;exports.SearchInput=Dt;exports.Section=oe;exports.SmartBidInput=Fe;exports.SourceEditor=sn;exports.WorkCatalog=bo;exports.detailToEditor=bn;exports.editorToDetail=Zo;exports.formatTemplate=Le;exports.parseSourceString=ln;exports.stringifySources=an;exports.useBidUrl=re;exports.useConvert=D;exports.useT=P;
|