book-index-ui 0.2.8 → 0.2.10
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 +17 -3
- package/dist/index.js +2064 -2032
- package/dist/{storage-entry-BiThJ6BH.js → storage-entry-BozRmBBw.js} +332 -291
- package/dist/storage-entry-ByKvhJnH.cjs +1 -0
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +17 -3
- package/dist/storage.js +1 -1
- package/package.json +1 -1
- package/dist/storage-entry-2AJlDQPr.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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-2AJlDQPr.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?
|
|
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;
|
|
1
|
+
"use strict";var Sn=Object.create;var st=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var wn=Object.getOwnPropertyNames;var Cn=Object.getPrototypeOf,_n=Object.prototype.hasOwnProperty;var zn=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of wn(n))!_n.call(t,s)&&s!==r&&st(t,s,{get:()=>n[s],enumerable:!(o=kn(n,s))||o.enumerable});return t};var lt=(t,n,r)=>(r=t!=null?Sn(Cn(t)):{},zn(n||!t||!t.__esModule?st(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-ByKvhJnH.cjs"),e=require("react/jsx-runtime"),u=require("react"),In=require("react-dom"),Tn=t=>`/book-index?id=${t}`,Mt=u.createContext(Tn);function Rn({buildUrl:t,children:n}){const r=u.useMemo(()=>t,[t]);return e.jsx(Mt.Provider,{value:r,children:n})}function re(){return u.useContext(Mt)}function ge(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function En(t,n){return ge(t).includes(n)}const Dt={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Ln={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Bn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Le=u.createContext(null),Ht={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:"圖片資源"}},Wn={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:"图片资源"}},$n={"zh-Hant":Ht,"zh-Hans":Wn},Ot="bim-locale";function Pn(){try{const t=localStorage.getItem(Ot);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function An(t){try{localStorage.setItem(Ot,t)}catch{}}const Fn="zh-Hant",Mn=({locale:t,onLocaleChange:n,children:r})=>{const[o,s]=u.useState(t??Fn),i=t??o;u.useEffect(()=>{if(t)return;const f=Pn();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),An(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:i,setLocale:c,messages:$n[i],converter:l}),[i,c,l]);return e.jsx(Le.Provider,{value:p,children:r})};function P(){const t=u.useContext(Le);return(t==null?void 0:t.messages)??Ht}const Dn=2e3;function H(){const t=u.useContext(Le),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>=Dn){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 Be(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function Hn(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 On(){return{id:"",name:"",url:"",type:"text",details:""}}const Ze=({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=y=>{if(!s)return!0;const v=ge(y);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},x=t.map((y,v)=>({item:y,originalIndex:v})).filter(({item:y})=>f(y)),h=()=>{const y=On();s&&(y.type=s),n([...t,y]),a(t.length)},d=y=>{n(t.filter((v,j)=>j!==y)),a(null)},b=(y,v,j)=>{const _=[...t];if(_[y]={..._[y],[v]:j},v==="url"&&!_[y].id){const k=Hn(j);k&&(_[y].id=k)}n(_)},S=(y,v,j)=>{const k={...t[y].metadata||{}};j?k[v]=j:delete k[v],b(y,"metadata",Object.keys(k).length>0?k:void 0)},g=(y,v)=>{const j=v.trim()?v.split(/[,,、]/).map(_=>_.trim()).filter(Boolean):void 0;b(y,"structure",j)},w=(y,v,j)=>{const k=t[y].coverage||{level:1,ranges:""};v==="level"?k.level=parseInt(j)||1:k.ranges=j,b(y,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:y,originalIndex:v})=>{var j,_,k;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===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Un(y.type??"text"),color:"#fff"},children:(()=>{var R,L;const m=ge(y);return m.length===0?y.type??"text":m.length===1?((R=c.find(I=>I.value===m[0]))==null?void 0:R.label)??m[0]:m.includes("text")&&m.includes("image")?((L=c.find(I=>I.value==="text+image"))==null?void 0:L.label)??"text+image":m.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${i.editor.resourcePlaceholder} ${v+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:m=>m.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&y.url&&Vn(v,o==null?void 0:o[v],r,i),e.jsx("button",{onClick:m=>{m.stopPropagation(),d(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[En(y,"image")&&y.url&&Nn(y,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.type}),e.jsx("select",{value:y.type,onChange:m=>b(v,"type",m.target.value),style:{...ae,flex:1},children:c.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]}),e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:m=>b(v,"root_type",m.target.value),style:{...ae,flex:1},children:p.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:m=>b(v,"id",m.target.value),placeholder:i.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:m=>b(v,"name",m.target.value),placeholder:i.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:m=>b(v,"url",m.target.value),placeholder:i.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((j=y.structure)==null?void 0:j.join("、"))||"",onChange:m=>g(v,m.target.value),placeholder:i.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((_=y.coverage)==null?void 0:_.level)??"",onChange:m=>w(v,"level",m.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...Ce,flex:1},children:[e.jsx("span",{style:_e,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((k=y.coverage)==null?void 0:k.ranges)||"",onChange:m=>w(v,"ranges",m.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:m=>b(v,"details",m.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(([m,R])=>{var L;return e.jsxs("label",{style:{...Ce,gap:"4px"},children:[e.jsx("span",{style:{..._e,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((L=y.metadata)==null?void 0:L[m])||"",onChange:I=>S(v,m,I.target.value),placeholder:R,style:{...ae,flex:1}})]},m)})})]})]})]})]},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:i.action.addResource})]})]})};function Un(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Vn(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 Nn(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"},Ce={display:"flex",alignItems:"center",gap:"6px"},_e={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Kn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Yn(t){try{const n=new URL(t).hostname;return Kn[n]}catch{return}}const at={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function Gn(t){return t.includes("text")&&t.includes("image")?at["text+image"]:at[t[0]||"physical"]}const ct={text:0,image:1,physical:2};function Me(t){return t.length===0?"physical":[...t].sort((n,r)=>(ct[n]??99)-(ct[r]??99)).join("+")}function Jn(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}|${Me(ge(l))}`;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),c=a&&`${a[0]}|${Me(ge(t[l]))}`,p=`${i.base.name}|${Me(ge(i.base))}`;c===p&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||o.push(t[i]);return o}const tt=({items:t,groupByType:n=!0,onNavigate:r,renderLink:o})=>{const s=P(),i=u.useMemo(()=>Jn(t||[]),[t]),l={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},a=x=>l[x]?l[x]:x.split("+").map(h=>l[h]||h).join("+");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((x,h)=>e.jsx(pt,{item:x},x.id||h))});const c=new Map;for(const x of i){const h=Me(ge(x));c.has(h)||c.set(h,[]),c.get(h).push(x)}const p=["text","image","text+image","physical"],f=[...p.filter(x=>c.has(x)),...[...c.keys()].filter(x=>!p.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:f.map(x=>{const h=c.get(x),d=Gn(x.split("+"));return e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:d,display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:d}}),a(x),e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",h.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:h.map((b,S)=>e.jsx(pt,{item:b,onNavigate:r,renderLink:o},b.id||S))})]},x)})})},dt=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},Ut=({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})},qn=(t,n,r,o)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Ut,{value:n});if(t==="has_translation")return n?r.misc.hasTranslation:r.misc.noTranslation;const s=String(n);return o?o(s):s};function Zn(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 Xn(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 Qn(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 er={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},pt=({item:t,onNavigate:n,renderLink:r})=>{var S;const o=P(),{convert:s}=H(),i=re(),[l,a]=u.useState(!1),c=u.useMemo(()=>(t.url?Yn(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||Qn(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?{...er[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:dt(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}),((S=t.metadata)==null?void 0:S.check_type)&&e.jsx(Ut,{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=Xn(t.metadata);return g?Zn(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?"收起 ▲":"展开 ▼"})]}),dt(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,w])=>e.jsxs("span",{children:[o.metadata[g]||g,": ",qn(g,w,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(v=>v.group),w=[];if(g){let v=null;for(const j of p){const _=j.group||"";(!v||v.title!==_)&&(v={title:_,group_id:j.group_id,vols:[]},w.push(v)),v.vols.push(j)}}else w.push({vols:p});const y=v=>{const j=v.status==="missing";return v.url&&!j?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:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.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:w.map((v,j)=>{const _=v.title?s(v.title):"";let k=_;return v.title&&v.group_id&&(r?k=r(v.group_id,_):n&&(k=e.jsx("a",{href:i(v.group_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.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:m=>m.currentTarget.style.borderBottomStyle="solid",onMouseLeave:m=>m.currentTarget.style.borderBottomStyle="dashed",children:_}))),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(y)})]},j)})})})()]})},Vt=({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:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.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})]})]})},Ue="bim-search-history",xt=10,ut=8;function Ie(){try{const t=localStorage.getItem(Ue);return t?JSON.parse(t):[]}catch{return[]}}function tr(t){try{const n=Ie().filter(r=>r!==t);n.unshift(t),n.length>xt&&(n.length=xt),localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function nr(t){try{const n=Ie().filter(r=>r!==t);localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function rr(){try{localStorage.removeItem(Ue)}catch{}}const Nt=({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),[S,g]=u.useState(null),[w,y]=u.useState(Ie),v=u.useRef(null),j=u.useRef(null),_=u.useRef(null);u.useEffect(()=>{if(!t.getAllEntries)return;let z=!1;return t.getAllEntries().then(W=>{z||g(W)}).catch(()=>{}),()=>{z=!0}},[t]);const k=u.useCallback(z=>{if(!z.trim())return w.map(C=>({type:"history",text:C}));if(!S)return[];const W=z.toLowerCase(),$=[],U=[];for(const C of S){if($.length+U.length>=ut*2)break;const E=(C.title??"").toLowerCase();if(E.startsWith(W))$.push({type:"entry",text:C.title,entry:C});else if(E.includes(W))U.push({type:"entry",text:C.title,entry:C});else{const N=[...C.additional_titles||[],...C.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:`${C.title}`,entry:C});break}}}}return[...$,...U].slice(0,ut)},[S,w]);u.useEffect(()=>{h(k(n)),b(-1)},[n,k]),u.useEffect(()=>{const z=W=>{_.current&&!_.current.contains(W.target)&&f(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),u.useEffect(()=>{const z=W=>{var $,U;if(W.key==="/"&&document.activeElement!==v.current){const C=($=document.activeElement)==null?void 0:$.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT")return;W.preventDefault(),(U=v.current)==null||U.focus()}};return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[]);const m=u.useCallback(z=>{z.trim()&&(tr(z.trim()),y(Ie())),o(z),f(!1)},[o]),R=u.useCallback(z=>{z.type==="history"?(r(z.text),m(z.text)):z.entry&&(s?(s(z.entry),f(!1)):(r(z.text),m(z.text)))},[r,m,s]),L=u.useCallback(z=>{if(!p||x.length===0){z.key==="Enter"&&m(n);return}switch(z.key){case"ArrowDown":z.preventDefault(),b(W=>(W+1)%x.length);break;case"ArrowUp":z.preventDefault(),b(W=>(W-1+x.length)%x.length);break;case"Enter":z.preventDefault(),d>=0&&d<x.length?R(x[d]):m(n);break;case"Escape":z.preventDefault(),f(!1);break}},[p,x,d,n,m,R]),I=u.useCallback((z,W)=>{W.stopPropagation(),nr(z),y(Ie()),h($=>$.filter(U=>!(U.type==="history"&&U.text===z)))},[]),B=u.useCallback(z=>{z.stopPropagation(),rr(),y([]),h([])},[]);u.useEffect(()=>{if(d>=0&&j.current){const z=j.current.children;z[d]&&z[d].scrollIntoView({block:"nearest"})}},[d]);const M=!n.trim()&&w.length>0;return e.jsxs("div",{ref:_,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:a,value:n,onChange:z=>{r(z.target.value),f(!0)},onFocus:()=>f(!0),onKeyDown:L,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:j,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:B,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((z,W)=>e.jsxs("div",{onClick:()=>R(z),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:z.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.text}),z.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[z.entry.type],z.entry.edition&&` · ${z.entry.edition}`,z.entry.author&&` · ${z.entry.author}`]}),z.type==="history"&&e.jsx("button",{onClick:$=>I(z.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:"×"})]},`${z.type}-${z.text}-${W}`))]})]})},Ee="bim-recent-ids",ft="bim-recent-entries",gt=50,Ge=5,or=50,ir=200;function Te(){try{const t=localStorage.getItem(Ee);if(t)return JSON.parse(t);const n=localStorage.getItem(ft);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Ee,JSON.stringify(r)),localStorage.removeItem(ft),r}return[]}catch{return[]}}function sr(t){try{const n=Te().filter(r=>r!==t);n.unshift(t),n.length>gt&&(n.length=gt),localStorage.setItem(Ee,JSON.stringify(n))}catch{}}function lr(t){try{const n=Te().filter(r=>r!==t);localStorage.setItem(Ee,JSON.stringify(n))}catch{}}function ar(){try{localStorage.removeItem(Ee)}catch{}}const cr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xe=({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"}],[S,g]=u.useState(f??""),[w,y]=u.useState(null),[v,j]=u.useState(null),[_,k]=u.useState(!1),[m,R]=u.useState(null),[L,I]=u.useState(""),[B,M]=u.useState(!f),[z,W]=u.useState(Te),[$,U]=u.useState([]),[C,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,Y)=>{if(!A.trim()){M(!0),y(null),j(null);return}M(!1),k(!0),I("");try{if(t.searchAll){const Z=await t.searchAll(A,Y??Ge);y(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(A,te,{page:1,pageSize:Y??Ge})));y({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){I(Z instanceof Error?Z.message:String(Z)),y(null)}finally{k(!1)}},[t]);u.useEffect(()=>{var T,D;let A=!1;const Y=["work","book","collection","entity"],Z=Promise.all(Y.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=((D=t.getSubtypeStats)==null?void 0:D.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([J,le,me])=>{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}),me&&de(me))}),()=>{A=!0}},[t]),u.useEffect(()=>{ue.current||!(f!=null&&f.trim())||(ue.current=!0,q(f))},[f,q]);const K=u.useCallback(A=>{if(g(A),x==null||x(A),!A.trim()){M(!0),y(null),j(null);return}fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{j(null),q(A)},ir)},[q,x]),Ve=u.useCallback(A=>{fe.current&&clearTimeout(fe.current),x==null||x(A),q(A)},[q,x]),Ne=u.useCallback(A=>{j(A),q(S,or)},[S,q]);u.useEffect(()=>{if(!z.length){U([]);return}let A=!1;return E(!0),Promise.all(z.slice(0,10).map(async Y=>{var Z,G,te;try{if(t.getEntry){const D=await t.getEntry(Y);if(D)return D}const T=await t.getItem(Y);if(T){const D=T.authors;return{id:Y,title:T.title||Y,type:T.type||"work",author:(Z=D==null?void 0:D[0])==null?void 0:Z.name,dynasty:(G=D==null?void 0:D[0])==null?void 0:G.dynasty,role:(te=D==null?void 0:D[0])==null?void 0:te.role,edition:T.edition||void 0}}}catch{}return{id:Y,title:Y,type:"work",notFound:!0}})).then(Y=>{A||(U(Y),E(!1))}),()=>{A=!0}},[z,t]);const ke=A=>{R(A.id),sr(A.id),W(Te()),o==null||o(A)},we=A=>{lr(A),W(Te())},Ke=()=>{ar(),W([])},We=A=>b.find(Y=>Y.type===A),Ye=w&&(w.works.length>0||w.books.length>0||w.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(Vt,{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(Nt,{transport:t,value:S,onChange:K,onSearch:Ve,onEntrySelect:ke}),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&&B&&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:_?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):L?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:L})]}):B?e.jsx("div",{style:{flex:1},children:C?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:Ke,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(dr,{id:A.id,onRemove:we,t:d},A.id):e.jsx(ht,{entry:A,selected:m===A.id,onClick:ke,getConfig:We,onRemove:we},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})]})}):Ye?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:A,icon:Y,name:Z,key:G})=>{const te=w[G]??[],T=cr[G],D=w[T]??0;if(te.length===0)return null;const le=!(v===A)&&D>Ge;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:[D," ",d.unit.items]})]}),le&&e.jsx("button",{onClick:()=>Ne(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(me=>e.jsx(ht,{entry:me,selected:m===me.id,onClick:ke,getConfig:We,query:S},me.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:Be(d.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},ht=({entry:t,selected:n,onClick:r,getConfig:o,query:s,onRemove:i})=>{const l=P(),{convert:a}=H(),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:"→"})]})},dr=({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 pr(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 xr({data:t}){const{convert:n}=H(),{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 ur({alt_names:t}){const{convert:n}=H(),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 fr({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 gr({works:t,transport:n,onNavigate:r,renderLink:o}){const s=P(),{convert:i}=H(),l=re(),[a,c]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const d=t.map(S=>S.work_id);return(async()=>{const S=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(d);let j=!0;for(let _=0;_<d.length;_++){const k=v[_];k!=null&&k.title?S.set(d[_],k.title):k!=null&&k.primary_name?S.set(d[_],k.primary_name):j=!1}if(j)return S}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),j=new Map(v.map(k=>[k.id,k.title||k.primary_name||k.id]));let _=!0;for(const k of d){const m=j.get(k);m?S.set(k,m):_=!1}if(_)return S}catch{}const g=[...d],w=8,y=new Array(w).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!S.has(v))try{if(n.getEntry){const k=await n.getEntry(v);if(k!=null&&k.title){S.set(v,k.title);continue}}const j=await n.getItem(v),_=j&&(j.title||j.primary_name)||v;S.set(v,_)}catch{S.set(v,v)}}});return await Promise.all(y),S})().then(S=>{h||c(S)}),()=>{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),S=f.indexOf(d);return b===-1&&S===-1?h.localeCompare(d):b===-1?1:S===-1?-1:b-S});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,S)=>{const g=i(a.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,g)},S):r?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),r(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},S):e.jsx("li",{children:g},S)})})]},h)})]})}const Kt=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:s})=>{var f;const i=P(),{convert:l}=H();let a=!1;try{a=O.extractStatus(t.id)==="draft"}catch{}const c=pr(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(xr,{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(ur,{alt_names:t.alt_names}),e.jsx(fr,{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(gr,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},hr=["〇","一","二","三","四","五","六","七","八","九"],bt=["","十","百","千"];function Yt(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+=bt[a]:o+=hr[l]+bt[a])}return o}function Gt({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 br({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 mr({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 Jt({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:s}=H();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 yr({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(Gt,{type:o}),e.jsx(br,{isDraft:s}),e.jsx(mr,{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(Jt,{authors:i,type:o,onNavigate:p,renderLink:f}),a]})]})}function qt({items:t,label:n,showMeta:r,onNavigate:o,renderLink:s}){const i=P(),{convert:l}=H();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 vr({items:t,onNavigate:n,renderLink:r}){const o=P();return e.jsx(qt,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function Zt({items:t,onNavigate:n,renderLink:r}){const o=P();return e.jsx(qt,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function Xt({label:t,items:n}){const{convert:r}=H();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 jr({items:t}){const n=P();return e.jsx(Xt,{label:n.section.aliases,items:t})}function Sr({items:t}){const n=P();return e.jsx(Xt,{label:n.section.attachedTexts,items:t})}function kr({items:t}){const n=P(),{convert:r}=H();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 wr({items:t}){const n=P(),{convert:r}=H();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 Cr({items:t}){const n=P(),{convert:r}=H();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 mt({title:t,ids:n,transport:r,onNavigate:o,renderLink:s}){const{convert:i}=H(),[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 _r({book:t,onNavigate:n,renderLink:r}){const o=P(),{convert:s}=H(),[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(tt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:r})})]})}function zr({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(_r,{book:a,onNavigate:r,renderLink:o},a.id))})]}):null}function Ir({workData:t,onNavigate:n,renderLink:r}){var i,l,a;const o=P(),{convert:s}=H();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(Gt,{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:[Yt(t.juan_count.number),o.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(Jt,{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 Tr({items:t,onNavigate:n,renderLink:r}){const o=P(),{convert:s}=H();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:Be(o.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const nt=({data:t,id:n,transport:r,onNavigate:o,renderLink:s,headerExtra:i,className:l,style:a})=>{var B,M,z,W,$,U;const c=P(),{convert:p}=H(),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState(null),[g,w]=u.useState(null),[y,v]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!r)return;let C=!1;return d(!0),S(null),r.getItem(n).then(E=>{C||(E?x(E):S(c.misc.notFoundEntry))}).catch(E=>{C||S(E instanceof Error?E.message:c.misc.loadFailed)}).finally(()=>{C||d(!1)}),()=>{C=!0}},[t,n,r]),u.useEffect(()=>{if(!j||!r){w(null),v([]);return}let C=!1;const E=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(E?r.getItem(E).then(N=>{!C&&N&&N.type==="work"&&w(N)}).catch(()=>{}):w(null),j.type==="book"){const N=j;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=>{C||v(V)}):v([])}else v([]);return()=>{C=!0}},[j,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((C,E)=>e.jsx("div",{style:{height:E===1?"32px":"16px",width:`${C}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(!j)return null;if(j.type==="entity")return e.jsx("div",{className:l,style:a,children:e.jsx(Kt,{data:j,transport:r,onNavigate:o,renderLink:s,headerExtra:i})});const _=j.type==="book"?j:null,k=j.type==="collection"?j:null,m=j.type==="work"?j:null;let R=!1;try{R=O.extractStatus(j.id)==="draft"}catch{}let L="";j.measure_info?L=p(j.measure_info):(B=j.juan_count)!=null&&B.number?L=Yt(j.juan_count.number)+c.unit.juan:(M=j.juan_count)!=null&&M.description&&(L=p(j.juan_count.description));const I=[];return(z=j.publication_info)!=null&&z.year&&I.push(e.jsx(ce,{label:c.label.year,children:j.publication_info.year},"year")),(W=j.current_location)!=null&&W.name&&I.push(e.jsx(ce,{label:c.label.currentLocation,children:p(j.current_location.name)},"loc")),($=j.page_count)!=null&&$.description&&I.push(e.jsx(ce,{label:c.label.pageCount,children:j.page_count.description},"page")),_!=null&&_.edition&&I.push(e.jsx(ce,{label:c.label.edition,children:p(_.edition)},"ver")),m!=null&&m.parent_work&&I.push(e.jsx(ce,{label:c.label.parentWork,children:e.jsx(ie,{id:m.parent_work.id,label:p(m.parent_work.title),onNavigate:o,renderLink:s})},"pw")),m!=null&&m.parent_works&&m.parent_works.length>0&&!m.parent_work&&I.push(e.jsx(ce,{label:c.label.parentWork,children:m.parent_works.map((C,E)=>e.jsxs("span",{children:[E>0&&"、",e.jsx(ie,{id:C,onNavigate:o,renderLink:s})]},C))},"pws")),e.jsxs("div",{className:l,style:a,children:[e.jsx(yr,{id:j.id,title:p(j.title),edition:j.edition?p(j.edition):void 0,type:j.type,isDraft:R,authors:j.authors,volumeText:L,meta:I,headerExtra:i,onNavigate:o,renderLink:s}),((U=j.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(j.description.text)}),y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.containedIn}),e.jsx(Tr,{items:y,onNavigate:o,renderLink:s})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.belongsToWork}),e.jsx(Ir,{workData:g,onNavigate:o,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(kr,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(jr,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Sr,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(vr,{items:j.indexed_by,onNavigate:o,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Zt,{items:j.emendated_by,onNavigate:o,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.resources}),e.jsx(tt,{items:j.resources,groupByType:!0,onNavigate:o,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(wr,{items:_.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(Cr,{items:k.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(mt,{title:c.section.relatedVersions,ids:_.related_books,transport:r,onNavigate:o,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(mt,{title:c.section.containedBooks,ids:k.books,transport:r,onNavigate:o,renderLink:s}),(k==null?void 0:k.contained_works)&&k.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:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(C=>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:C.id,label:p(C.title),onNavigate:o,renderLink:s})},C.id))})]}),(m==null?void 0:m.books)&&m.books.length>0&&e.jsx(zr,{ids:m.books,transport:r,onNavigate:o,renderLink:s}),(m==null?void 0:m.related_works)&&m.related_works.length>0&&(()=>{const C=[],E=m.related_works.filter(F=>F.relation==="part_of"),N=m.related_works.filter(F=>F.relation==="has_part"),V=m.related_works.filter(F=>!F.relation);return E.length>0&&C.push({label:c.section.belongsToWork,items:E}),N.length>0&&C.push({label:c.section.containedWorks,items:N}),V.length>0&&C.push({label:c.section.relatedWorks,items:V}),C.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 Rr({data:t}){const n=P(),{convert:r}=H(),{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 Er({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:yt(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>r(s.name),style:yt(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 yt(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 Lr({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 Br(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 vt({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const s=P(),{convert:i}=H(),l=t.book_id||t.work_id,a=o&&t.volumes.length>0?Br(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(Lr,{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 Qt=({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,S]=u.useState(null),[g,w]=u.useState(""),y=t||c;u.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let m=!1;return x(!0),d(null),r.getCollectionCatalog(n).then(R=>{m||(R?p(R):d(a.catalog.notFound))}).catch(R=>{m||d(R instanceof Error?R.message:a.catalog.loadFailed)}).finally(()=>{m||x(!1)}),()=>{m=!0}},[t,n,r,a]);const v=(y==null?void 0:y.sections)&&y.sections.length>0,j=u.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const m=y.books.map(L=>L.volumes[0]).filter(L=>L!=null);return new Set(m).size<m.length},[y]),_=u.useMemo(()=>{if(!y)return[];let m=y.books;if(b&&(m=m.filter(R=>R.section===b)),g.trim()){const R=g.trim().toLowerCase();m=m.filter(L=>L.title.toLowerCase().includes(R)||L.sub_items&&L.sub_items.some(I=>I.toLowerCase().includes(R))||L.edition&&L.edition.toLowerCase().includes(R))}return m},[y,b,g]),k=u.useMemo(()=>{if(!j)return null;const m=[],R=new Map;for(const I of _){if(!I.volumes||I.volumes.length===0)continue;const B=I.volumes[0];R.has(B)||R.set(B,[]),R.get(B).push(I)}const L=[...R.keys()].sort((I,B)=>I-B);for(const I of L)m.push({volume:I,books:R.get(I)});return m},[_,j]);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}):y?e.jsxs("div",{className:i,style:l,children:[e.jsx(Rr,{data:y}),v&&e.jsx(Er,{sections:y.sections,activeSection:b,onSelect:S}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:g,onChange:m=>w(m.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:[_.length," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((m,R)=>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:Be(a.catalog.volume,{n:m.volume})}),m.books.map((L,I)=>e.jsx(vt,{book:L,onNavigate:o,renderLink:s,showVolumes:L.volumes.length>1},`${m.volume}-${I}`))]},`${m.volume}-${R}`)):_.map((m,R)=>e.jsx(vt,{book:m,onNavigate:o,renderLink:s,showVolumes:!0},R)),_.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},be=()=>{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,$e=7,Wr=({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,w=h.current;if(!g||!w)return;const y=g.getBoundingClientRect(),v=w.getBoundingClientRect(),j=window.innerHeight,_=document.documentElement.clientWidth;let k=r;r==="top"&&y.top-v.height-$e<8&&(k="bottom"),r==="bottom"&&y.bottom+v.height+$e>j-8&&(k="top");const m=k==="top"?y.top-v.height-$e:y.bottom+$e;let R=y.left+y.width/2-v.width/2;R=Math.max(8,Math.min(R,_-v.width-8)),p({left:R,top:m,placement:k})},[r]),b=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(!0),o)},[o]),S=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:S,onFocus:b,onBlur:S,style:{display:"inline-block",...i},children:n}),l&&In.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)]})},jt={A:"fine",B:"rough",C:"rough",D:"ocr"};function $r(t){return typeof t!="string"?null:t in Dt?t:t in jt?jt[t]:null}const Pr=["〇","一","二","三","四","五","六","七","八","九"],St=["","十","百","千"],Ar=["","萬","億"];function en(t){if(t===0)return"〇";if(t<0)return`負${en(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(Fr(s,o>0)+Ar[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Fr(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+=St[a]:s+=Pr[l]+St[a]}return s.replace(/〇$/,"")}let Re=null,Pe=null;const He=new Set;function Mr(){return Re?Promise.resolve():Pe||(Pe=import("opencc-js/t2cn").then(t=>{Re=t.Converter({from:"tw",to:"cn"}),He.forEach(n=>n())}).catch(()=>{Re=t=>t,He.forEach(t=>t())}),Pe)}function xe(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Re)return;const n=()=>t(r=>r+1);return He.add(n),Mr(),()=>{He.delete(n)}},[]),Re??(n=>n)}function je(t,n){return n(t).toLowerCase()}const rt="#fff59d";function Se(t,n,r){if(!n)return t;const o=je(n,r);if(!o)return t;const s=je(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:rt,padding:0,color:"inherit"},children:t.slice(c,c+o.length)},a++)),l=c+o.length}return e.jsx(e.Fragment,{children:i})}function ot(t,n,r,o){if(!n)return!0;const s=je(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"&&je(l,o).includes(s))}function Dr(t,n,r){return n?je(t,r).includes(je(n,r)):!0}const it={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Hr={考证:"#5d6d7e"};function Or(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 tn({file:t,isActive:n,onSelect:r,meta:o,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=Or(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?`${rt}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 nn(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(o=>nn(o,n)))}function rn(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((s,i)=>s+rn(i),0))||0;return n+r}function Ur(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 on({group:t,activeFile:n,onSelect:r,depth:o=0,juanMeta:s,matchStates:i}){var b;const l=nn(t,n||""),a=Ur(t,i),c=typeof a=="number"&&a>0,p=a===0,[f,x]=u.useState(l||c),h=rn(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 S=t.files[0],g=n===S,w=i[S],y=w===0,v=w==="loading",j=typeof w=="number"&&w>0;return e.jsxs("button",{onClick:()=>{y||r(S)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":y?"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)":j?`${rt}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,j&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:w}),v&&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(S=>e.jsx(tn,{file:S,isActive:n===S,onSelect:r,meta:s==null?void 0:s[S],matchState:i[S]},S))}),d&&t.children.map((S,g)=>e.jsx(on,{group:S,activeFile:n,onSelect:r,depth:o+1,juanMeta:s,matchStates:i},g))]})]})}function Vr({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(on,{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(tn,{file:a,isActive:r===a,onSelect:o,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function Nr({type:t}){const n=it[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 Kr({section:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=H(),s=re(),i=xe(),l=S=>{if(!S)return"";const g=o(S);return r?Se(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:[en(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:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.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 Yr({section:t,highlightQuery:n=""}){const{convert:r}=H(),o=xe(),s=c=>{if(!c)return"";const p=r(c);return n?Se(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(Nr,{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 ${it[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 Gr({section:t,highlightQuery:n=""}){const{convert:r}=H(),o=xe();if(!t.content&&!t.title)return null;const s=r((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`)),i=n?Se(s,n,o):s,l=it[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 Jr(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,S=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:d,author:S}}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 qr({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:s=""}){const{convert:i}=H(),l=re(),a=xe(),c=y=>{if(!y)return"";const v=i(y);return s?Se(v,s,a):v},[p,f]=u.useState(!1);u.useEffect(()=>{s&&f(!0)},[s]);const x=t.type,h=Hr[x]||"#717171",d=!!t.content,b=t.work_ids||[],S=b.length>1,g=Jr(S?b:[],r,o),w=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&&w&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(w)})]}),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:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&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})]})]}),S&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const v=g[y],j=v?`${i(v.title)}${v.author?`(${i(v.author)})`:""}`:y.slice(0,8)+"…";return e.jsxs("a",{href:l(y),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),_.stopPropagation(),n(y))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",j]},y)})}),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 Zr({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:s}){const{convert:i}=H(),l=xe(),a=n.trim(),c=u.useMemo(()=>a?t.sections.filter(x=>ot(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(qr,{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 Xr({text:t,highlightQuery:n=""}){const{convert:r}=H(),o=xe(),s=l=>{const a=r(l);return n?Se(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 Qr({sections:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=H(),s=re(),i=xe(),l=p=>{if(!p)return"";const f=o(p);return r?Se(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 eo({juan:t,rawText:n,searchQuery:r,onNavigate:o}){const{convert:s}=H(),i=xe(),[l,a]=u.useState("catalog"),c=r.trim(),p=u.useMemo(()=>c?t.sections.filter(d=>ot(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(Xr,{text:n,highlightQuery:c}):e.jsx(Qr,{sections:t.sections,onNavigate:o,highlightQuery:c})),l==="catalog"&&p.map((d,b)=>d.type==="书"||d.type==="詩"?e.jsx(Kr,{section:d,onNavigate:o,highlightQuery:c},b):d.type==="类"?e.jsx(Yr,{section:d,highlightQuery:c},b):e.jsx(Gr,{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 sn(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 kt(t){const n=sn(t);return n.length>0?n[0]:null}function to(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,S)=>{let g=0;if(b.juan)for(const w of b.juan.sections)ot(w,S,c,p)&&g++;return g===0&&b.rawText&&Dr(b.rawText,S,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 S=!1;const g={},w=[];for(const k of o){const m=f.current.get(k);m?g[k]=d(m,b):(g[k]="loading",w.push(k))}h(g);const y=8;let v=0;const j=async()=>{var k;for(;v<w.length;){if(S)return;const m=v++,R=w[m];try{const[L,I]=await Promise.all([r.getCollatedJuan(n,R),((k=r.getCollatedJuanText)==null?void 0:k.call(r,n,R))??Promise.resolve(null)]),B={juan:L,rawText:I};if(f.current.set(R,B),S)return;h(M=>({...M,[R]:d(B,b)}))}catch{if(S)return;h(L=>({...L,[R]:0}))}}},_=Array.from({length:Math.min(y,w.length)},()=>j());return Promise.all(_),()=>{S=!0}},[a,n,r,o.join(","),d,p]),{matchStates:x}}const ln=({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,S]=u.useState(null),[g,w]=u.useState(null),[y,v]=u.useState(!1),[j,_]=u.useState(null),[k,m]=u.useState(""),R=u.useRef(new Map),L=s??b,I=u.useCallback(C=>{S(C),i==null||i(C)},[i]),B=t||c;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let C=!1;return x(!0),d(null),r.getCollatedEditionIndex(n).then(E=>{if(!C)if(!E)d("未找到整理本数据");else{p(E);const N=kt(E);!s&&N&&I(N)}}).catch(E=>{C||d(E instanceof Error?E.message:"加载失败")}).finally(()=>{C||x(!1)}),()=>{C=!0}},[t,n,r,s,I]),u.useEffect(()=>{const C=t||c;if(C&&!L){const E=kt(C);E&&I(E)}},[t,c,L,I]);const M=n||(B==null?void 0:B.work_id),z=u.useCallback(async C=>{var E;if(!(!M||!(r!=null&&r.getCollatedJuan))){v(!0),w(null),_(null);try{const[N,V]=await Promise.all([r.getCollatedJuan(M,C),((E=r.getCollatedJuanText)==null?void 0:E.call(r,M,C))??Promise.resolve(null)]);w(N),_(V)}catch{w(null),_(null)}finally{v(!1)}}},[M,r]);u.useEffect(()=>{L&&z(L)},[L,z]);const W=C=>{I(C)};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(!B)return null;const $=B.type==="kaozhen",U=sn(B);return e.jsx(no,{className:l,style:a,index:B,allFiles:U,isKaozhen:$,effectiveWorkId:M,transport:r,activeFile:L,handleSelectFile:W,juanData:g,juanRawText:j,juanLoading:y,searchQuery:k,setSearchQuery:m,onNavigate:o,workLabelCacheRef:R})},no=({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:S})=>{const{matchStates:g}=to({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:w=>d(w.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 w=$r(r.text_quality.grade);return w?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Wr,{content:Ln[w],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Bn[w],cursor:"help"},children:Dt[w]})}),r.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",r.text_quality.source_note]})]}):null})()]}),e.jsx(Vr,{files:o,groups:r.juan_groups,activeFile:a,onSelect:c,juanMeta:r.juan_metadata,matchStates:g}),x?e.jsx(be,{}):p?s?e.jsx(Zr,{juan:p,searchQuery:h,onNavigate:b,transport:l,workLabelCache:S}):e.jsx(eo,{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((w,y)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[y+1,". "]}),w.url?e.jsx("a",{href:w.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:w.title}):e.jsx("span",{children:w.title}),w.author&&e.jsxs("span",{children:[",",w.author]}),w.note&&e.jsxs("span",{children:["。",w.note]})]},y))]})]})},ro={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},oo={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function io(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 an=({items:t,loading:n})=>{const r=re();return n?e.jsx(be,{}):t.length===0?e.jsx("div",{style:so,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=ro[o.type],i=oo[o.status];return e.jsxs("div",{style:lo,children:[e.jsxs("div",{style:ao,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...wt,background:s.color},children:s.label}),e.jsx("span",{style:{...wt,background:i.color},children:i.label})]}),e.jsx("span",{style:co,children:io(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:po,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:Ct,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:Ct,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:xo,children:o.content}),o.reply&&e.jsxs("div",{style:uo,children:[e.jsx("div",{style:fo,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},so={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},lo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},ao={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},wt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},co={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},po={fontSize:"12px",marginBottom:"6px"},Ct={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},xo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},uo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},fo={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Qe=({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([]),[S,g]=u.useState(!1),w=o??x,y=I=>{h(I),s==null||s(I)},[v,j]=u.useState(!0),[_,k]=u.useState(null),[m,R]=u.useState(null);u.useEffect(()=>{if(!t.getAllEntries)return;let I=!1;return t.getAllEntries().then(B=>{if(I)return;const M=B.filter($=>$.type==="work").length,z=B.filter($=>$.type==="book").length,W=B.filter($=>$.type==="collection").length;c({works:M,books:z,collections:W})}).catch(()=>{}),()=>{I=!0}},[t]),u.useEffect(()=>{let I=!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(z=>z.items.map(W=>({...W,group:z.name})))}catch{}return[]})().then(async M=>{if(I)return;const z=M.filter($=>$.id);if(z.length===0){j(!1);return}const W=await Promise.all(z.map(async $=>{try{let U=null;if(t.getEntry)U=await t.getEntry($.id);else{const C=await t.getItem($.id);C&&(U={id:$.id,title:C.title||$.id,type:C.type||"work"})}if(U)return{...U,group:$.group,fallbackDescription:$.description}}catch{}return{id:$.id,title:$.title,type:O.extractType($.id),group:$.group,fallbackDescription:$.description}}));I||(f(W.filter($=>$!==null)),j(!1))}),()=>{I=!0}},[t,r]),u.useEffect(()=>{if(!t.getResourceProgress)return;let I=!1;return t.getResourceProgress().then(B=>{I||k(B)}).catch(()=>{}),()=>{I=!0}},[t]),u.useEffect(()=>{if(!t.getSiteProgress)return;let I=!1;return t.getSiteProgress().then(B=>{I||R(B)}).catch(()=>{}),()=>{I=!0}},[t]),u.useEffect(()=>{if(!i||w!=="feedback")return;let I=!1;return g(!0),fetch(i).then(B=>B.json()).then(B=>{!I&&B.success&&b(B.items||[])}).catch(()=>{}).finally(()=>{I||g(!1)}),()=>{I=!0}},[i,w]);const L=I=>{switch(I){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(Ae,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>y("recommend")}),e.jsx(Ae,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>y("catalog")}),e.jsx(Ae,{label:l.home.siteTab,active:w==="site",onClick:()=>y("site")}),i&&e.jsx(Ae,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>y("feedback")})]}),w==="recommend"&&e.jsx(go,{recommended:p,loading:v,onNavigate:n,getIcon:L,t:l}),w==="catalog"&&e.jsx(ho,{progress:_,t:l,onNavigate:n}),w==="site"&&e.jsx(mo,{progress:m,t:l,totalWorks:(a==null?void 0:a.works)??0}),w==="feedback"&&i&&e.jsx(an,{items:d,loading:S})]})})},Ae=({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}),go=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:s})=>{const i=re();if(n)return e.jsx(be,{});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))})},ho=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(be,{});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(bo,{item:p,t:n,statusColor:l[a],onNavigate:r},p.id))})]},a)})})},bo=({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?Be(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})]})},mo=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(be,{});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(_t,{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(_t,{item:c,t:n,totalWorks:r},c.id))})]})]})},_t=({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})]})},zt="(max-width: 768px)";function yo(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(zt).matches);return u.useEffect(()=>{const r=window.matchMedia(zt),o=s=>n(s.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const vo=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:s})=>{var U;const i=P(),{convert:l}=H(),a=yo(),[c,p]=u.useState(null),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState("detail"),[g,w]=u.useState([]),[y,v]=u.useState(!1),[j,_]=u.useState(null),[k,m]=u.useState(!1),R=u.useCallback(async C=>{if(!t.getCollatedEditionIndex){_(null);return}m(!0);try{const E=await t.getCollatedEditionIndex(C);_(E)}catch{_(null)}finally{m(!1)}},[t]),L=u.useCallback(async C=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){w([]);return}v(!0);try{if(t.getCollectionCatalogs){const E=await t.getCollectionCatalogs(C);w(E||[])}else if(t.getCollectionCatalog){const E=await t.getCollectionCatalog(C);w(E?[{resource_id:"",data:E}]:[])}}catch{w([])}finally{v(!1)}},[t]),I=u.useCallback(async C=>{if(r){r(C);return}p(C),x(null),w([]),_(null),S("detail"),d(!0);try{const E=await t.getItem(C.id);E&&(x(E),E.type==="collection"?L(C.id):E.type==="work"&&E.has_collated&&R(C.id))}catch(E){console.error("加载详情失败:",E)}finally{d(!1)}},[t,r,L,R]),B=u.useCallback(async C=>{x(null),w([]),_(null),S("detail"),d(!0);try{const E=await t.getItem(C);E&&(x(E),p({id:C,title:E.title||C,type:E.type||"book"}),E.type==="collection"?L(C):E.type==="work"&&E.has_collated&&R(C))}catch(E){console.error("导航失败:",E)}finally{d(!1)}},[t,L,R]),M=(f==null?void 0:f.type)==="collection"&&(g.length>0||y)||(f==null?void 0:f.type)==="work"&&(j||k),z=a&&(h||f),W=u.useCallback(()=>{p(null),x(null),w([]),_(null),S("detail")},[]),$=e.jsx(e.Fragment,{children:h?e.jsx(be,{}):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:()=>S("detail"),style:Fe(b==="detail"),children:i.detailTab.basicInfo}),f.type==="collection"&&y&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Fe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),f.type==="collection"&&g.map(C=>e.jsx("button",{onClick:()=>S(`catalog:${C.resource_id}`),style:Fe(b===`catalog:${C.resource_id}`),children:C.short_name?`${l(C.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},C.resource_id)),f.type==="work"&&(j||k)&&e.jsxs("button",{onClick:()=>S("collated"),style:Fe(b==="collated"),children:[i.detailTab.collatedEdition,k&&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(nt,{data:f,transport:t,onNavigate:B}):b.startsWith("catalog:")?e.jsx(Qt,{data:(U=g.find(C=>`catalog:${C.resource_id}`===b))==null?void 0:U.data,onNavigate:B}):b==="collated"?e.jsx(ln,{index:j||void 0,workId:f.id,transport:t,onNavigate:B}):null})]}):e.jsx(Qe,{transport:t,onNavigate:B,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:z?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(Xe,{transport:t,onEntryClick:I,hideModeIndicator:n}),!f&&e.jsx(Qe,{transport:t,onNavigate:B,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(Xe,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Fe(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const jo=({data:t,onNavigate:n,className:r,style:o})=>{var f;const s=P(),{convert:i}=H(),[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(So,{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))})]})},So=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:s,onNavigate:i})=>{const{convert:l}=H(),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(ko,{category:c,expanded:o===p,onToggle:()=>s(p),onNavigate:i},c.name)})})]})},ko=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var c,p,f,x;const{convert:s}=H(),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(It,{label:"著錄",books:i,onNavigate:o}),l.length>0&&e.jsx(It,{label:"存目",books:l,onNavigate:o})]})]})},It=({label:t,books:n,onNavigate:r})=>{const{convert:o}=H(),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:Co,children:"AI"}),n&&e.jsx("button",{onClick:n,style:wo,children:i.action.save})]})]}),s]})},wo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Co={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"}})]}),he=({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"}})},Oe=({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 _o(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const De=({value:t,onChange:n,label:r})=>{const[o,s]=u.useState(!1),i=u.useRef(null),l=_o(t||"");return u.useEffect(()=>{o&&i.current&&i.current.focus()},[o]),!o&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Tt,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(Oe,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Tt,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"}})]})},Tt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function zo(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Io(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const cn=({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 S=[...t];S[x]={...S[x],id:b.id,name:b.title,type:"bookID"},n(S)})},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:zo(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Io(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:{...Rt,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:{...Rt,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:Et,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:Et,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:ye})]}),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:ye})]})]}),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:ye})]}),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:ye})]})]}),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:ye})]}),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:ye})]})]})]})]})})]},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},ye={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"},Rt={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"},Et={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function dn(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 pn(t){return!t||t.length===0?"":JSON.stringify(t)}const xn=({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:S})=>{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})]}),S&&e.jsx("button",{onClick:S,style:To,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ze,{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(ze,{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(ve,{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(ze,{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(ve,{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(ve,{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(ve,{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(ze,{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(ze,{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(ve,{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(ve,{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})]})]})]})},ze=({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:un(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(Lt,{onClick:()=>o(r),title:f,children:"👁️"}),e.jsx(Lt,{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(et,{onClick:i,children:a}),e.jsx(et,{onClick:l,primary:!0,children:c})]})]})},ve=({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:un(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(et,{onClick:s,primary:!0,children:["+ ",i]})})]})},Lt=({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}),et=({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 un(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const To={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"},fn=({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"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Ro,children:e.jsxs("div",{style:Eo,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:Lo,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:Bo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Je,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:Wo,children:[e.jsx("span",{style:{fontSize:"16px"},children:S}),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:Je,children:["未找到匹配的",b]}):e.jsxs("div",{style:Je,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:$o,children:["创建新",b,"并关联"]})]})]})})},Ro={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},Eo={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)"},Lo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Bo={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"},Wo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Je={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},$o={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Bt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Po={work:"📜",book:"📖",collection:"📚",entity:"👤"},gn=({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`创建新${Bt[n]}`}};return e.jsx("div",{style:Ao,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Fo,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:Po[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:`请输入${Bt[n]}名称...`,style:Mo})]}),((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:Do,children:"取消"}),e.jsx("button",{onClick:f,disabled:!l.trim(),style:{...Ho,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Ao={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",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Mo={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"},Do={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ho={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Oo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function hn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Uo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const bn=({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([]),[S,g]=u.useState(!1),[w,y]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),y(o.length>0?"recent":"search"))},[t,o.length]),u.useEffect(()=>{if(!x.trim()){b([]);return}const R=setTimeout(async()=>{g(!0);try{b(await f(x,r))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(R)},[x,r,f]);const v=u.useCallback(R=>{h(R.target.value),R.target.value.trim()&&y("search")},[]),j=u.useCallback(R=>s?R.filter(L=>L.id!==s):R,[s]);if(!t)return null;const _=n||(r==="all"?"选择实体":`选择${hn(r)}`),k=j(o),m=j(d);return e.jsx("div",{style:No,children:e.jsxs("div",{style:Ko,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:_}),e.jsx("button",{onClick:c,style:Yo,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:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Go}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&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(Wt,{active:w==="recent",onClick:()=>y("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(Wt,{active:w==="search",onClick:()=>y("search"),children:["搜索结果 ",m.length>0&&`(${m.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&k.length>0?e.jsx($t,{entities:k,onSelect:a}):x.trim()?S?e.jsx(qe,{message:"搜索中..."}):m.length>0?e.jsx($t,{entities:m,onSelect:a}):e.jsx(qe,{message:"未找到匹配的结果"}):e.jsx(qe,{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:Jo,children:l||"创建新实体"})]})]})})},Wt=({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}),$t=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(Vo,{entity:r,onClick:()=>n(r)},r.id))}),Vo=({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:Oo(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:Uo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:hn(t.type)})]})},qe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),No={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},Ko={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)"},Yo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Go={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"},Jo={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},qo={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Zo={work:"📜",collection:"📚",book:"📖",entity:"👤"},mn=({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,S]=u.useState(!1),[g,w]=u.useState("work"),[y,v]=u.useState(""),[j,_]=u.useState(""),[k,m]=u.useState([]),[R,L]=u.useState(!1),[I,B]=u.useState(!1),[M,z]=u.useState("work"),[W,$]=u.useState(""),[U,C]=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",K=u.useCallback((T,D)=>{n({...t,[T]:D})},[t,n]),Ve=u.useCallback((T,D)=>{v(T),w(D),_(d.editor.selectToLink+d.indexType[D]),m([]),S(!0)},[d]),Ne=u.useCallback(T=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,T)},[o,t.id]),ke=u.useCallback(T=>{s==null||s(T.id,T.type)},[s]),we=u.useCallback((T,D,J)=>{const le={...J,author:(J==null?void 0:J.author)||t.author,dynasty:(J==null?void 0:J.dynasty)||t.dynasty};z(D),$(T),C(le),B(!0)},[t.author,t.dynasty]),Ke=u.useCallback((T,D)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,W,{type:M,title:T,inheritData:D}),B(!1)},[o,t.id,W,M]),We=u.useCallback(T=>{if(!T.trim()){m([]);return}L(!0),o!=null&&o.searchEntities&&o.searchEntities(T,g).then(D=>{m(D),L(!1)}).catch(()=>{m([]),L(!1)})},[o,g]),Ye=u.useCallback(T=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,T.id),S(!1)},[o,t.id,y]),A=u.useCallback(()=>{r()},[r]),Y=u.useCallback(T=>{F(()=>T),N(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(Q).catch(()=>{})},[o]),Z=u.useCallback((T,D)=>o!=null&&o.searchEntities?o.searchEntities(T,D==="all"?void 0:D):Promise.resolve([]),[o]),G=u.useCallback(T=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(T),Q(D=>[T,...D.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:Zo[de]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Oe,{children:t.id}),e.jsx(Oe,{color:qo[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(De,{label:fe?d.editor.workTitle:ue?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:T=>K("title",T)}),q&&e.jsx(De,{label:d.editor.belongsToWork,value:t.workName||"",onChange:T=>K("workName",T)}),e.jsx(ee,{label:d.editor.authorLabel,value:t.author||"",onChange:T=>K("author",T)}),e.jsx(ee,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>K("dynasty",T)}),(q||ue)&&e.jsx(De,{label:d.editor.containedIn,value:t.collection||"",onChange:T=>K("collection",T)}),(q||ue)&&e.jsx(ee,{label:d.editor.holderLabel,value:t.holder||"",onChange:T=>K("holder",T)}),(q||ue)&&e.jsx(ee,{label:q?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:T=>K("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>K("firstImage",T)})})]})}),e.jsx(oe,{title:d.section.description,onSave:r,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(he,{value:t.description||"",onChange:T=>K("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(Xo,{items:t.additional_works||[],onChange:T=>K("additional_works",T)})}),e.jsx(oe,{title:d.section.indexedBy,onSave:r,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(Qo,{items:t.indexed_by||[],onChange:T=>K("indexed_by",T)})}),e.jsx(oe,{title:d.section.emendatedBy,onSave:r,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(ei,{items:t.emendated_by||[],onChange:T=>K("emendated_by",T)})}),e.jsx(oe,{title:d.section.textResources,onSave:r,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Ze,{items:t.resources||[],onChange:T=>K("resources",T),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(oe,{title:d.section.imageResources,onSave:r,children:e.jsx(Ze,{items:t.resources||[],onChange:T=>K("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(cn,{items:dn(t.sources||""),onChange:T=>K("sources",pn(T)),onOpenEntityPicker:Y})}),(q||ue)&&e.jsx(oe,{title:d.section.provenance,onSave:r,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(he,{value:t.provenance||"",onChange:T=>K("provenance",T),placeholder:d.editor.provenancePlaceholder})}),q&&e.jsx(oe,{title:d.section.otherEditions,onSave:r,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(he,{value:t.otherEditions||"",onChange:T=>K("otherEditions",T),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(xn,{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:Ve,onUnlinkEntity:Ne,onViewEntity:ke,onCreateAndLink:we,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(fn,{isOpen:b,entityType:g,title:j,onSelect:Ye,onCancel:()=>S(!1),onCreate:()=>{S(!1),we(y,g)},searchResults:k,onSearch:We,isLoading:R,excludeId:t.id}),e.jsx(gn,{isOpen:I,entityType:M,relationField:W,inheritData:U,onConfirm:Ke,onCancel:()=>B(!1)}),e.jsx(bn,{isOpen:E,title:d.action.selectBookOrWork,filterType:"all",recentEntities:se,excludeId:t.id,onSelect:G,onCancel:()=>{N(!1),F(null)},onSearch:Z})]})};function Xo({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 yn({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,S)=>S===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(he,{value:f.summary||"",onChange:d=>a(x,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(he,{value:f.comment||"",onChange:d=>a(x,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(he,{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 Qo({items:t,onChange:n}){const r=P();return e.jsx(yn,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function ei({items:t,onChange:n}){const r=P();return e.jsx(yn,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function vn(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 S=b.related_works.find(g=>g.relation==="part_of");S&&(l.parentWorkId=S.id,l.parentWorkName=S.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 ti(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 ni=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:S,onRelationsChange:g,headerExtra:w,className:y,style:v}=t;P();const[j,_]=u.useState(s),k=i?s:j;u.useEffect(()=>{s!==j&&_(s)},[s]);const m=u.useCallback(()=>{const W=k==="view"?"edit":"view";i?i(W):_(W)},[k,i]),[R,L]=u.useState(null);u.useEffect(()=>{r&&o&&o.getItem(r).then(W=>{W&&L(W)})},[r,o]);const I=n||R,B=u.useMemo(()=>I?vn(I):null,[I]),M=i||!n?e.jsx("button",{onClick:m,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,z=e.jsxs(e.Fragment,{children:[M,w]});return!I&&!B?e.jsx(be,{}):k==="view"?e.jsx(nt,{data:I,transport:o,onNavigate:p?W=>p(W):void 0,renderLink:f,headerExtra:z,className:y,style:v}):B?e.jsxs("div",{className:y,style:v,children:[z&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:z}),e.jsx(mn,{data:B,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:S,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Pt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],jn=({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=w=>{w.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",S=Pt.find(g=>g.value===s);return e.jsx("div",{style:ri,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:oi,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:ii,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:si,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:pi,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:Pt.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...li,...s===g.value?ai:{}},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:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||c==="submitting",style:{...ci,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:xi,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...di,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},ri={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},oi={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)"},ii={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},si={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},li={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"},ai={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ci={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"},di={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},pi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},xi={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ui=({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:{...fi,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(jn,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:r})]})},fi={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"},At=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],gi=({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=At.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Ft,children:e.jsxs("div",{style:vi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:ji,children:"继续提交"})]})}):e.jsxs("div",{style:Ft,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:At.map(d=>e.jsxs("button",{onClick:()=>r(d.value),style:{...hi,...n===d.value?bi:{}},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:{...mi}}),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:{...yi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Si,children:a})]})},Ft={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},hi={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"},bi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},mi={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"},yi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},vi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},ji={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Si={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},ki=({style:t})=>{const n=u.useContext(Le);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=Oe;exports.BidUrlProvider=Rn;exports.CollatedEdition=ln;exports.CollectionCatalog=Qt;exports.CreateEntityDialog=gn;exports.EmendatedBySection=Zt;exports.EntityDetail=Kt;exports.EntityPickerDialog=bn;exports.EntitySelector=fn;exports.FeedbackButton=ui;exports.FeedbackDialog=jn;exports.FeedbackForm=gi;exports.FeedbackList=an;exports.FormInput=ee;exports.FormTextArea=he;exports.HomePage=Qe;exports.IndexApp=vo;exports.IndexBrowser=Xe;exports.IndexDetail=nt;exports.IndexEditor=mn;exports.IndexView=ni;exports.LocaleContext=Le;exports.LocaleProvider=Mn;exports.LocaleToggle=ki;exports.ModeIndicator=Vt;exports.RelationPanel=xn;exports.ResourceEditor=Ze;exports.ResourceList=tt;exports.SearchInput=Nt;exports.Section=oe;exports.SmartBidInput=De;exports.SourceEditor=cn;exports.WorkCatalog=jo;exports.detailToEditor=vn;exports.editorToDetail=ti;exports.formatTemplate=Be;exports.parseSourceString=dn;exports.stringifySources=pn;exports.useBidUrl=re;exports.useConvert=H;exports.useT=P;
|