book-index-ui 0.2.12 → 0.2.14
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 +26 -1
- package/dist/index.js +980 -957
- package/dist/{storage-entry-sPrgfaS5.cjs → storage-entry-QB1IoDUU.cjs} +1 -1
- package/dist/{storage-entry-CWocbrbM.js → storage-entry-UQLfmeLb.js} +250 -221
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +15 -1
- package/dist/storage.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var wn=Object.create;var lt=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var _n=Object.getOwnPropertyNames;var zn=Object.getPrototypeOf,In=Object.prototype.hasOwnProperty;var Tn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of _n(n))!In.call(t,s)&&s!==o&<(t,s,{get:()=>n[s],enumerable:!(r=Cn(n,s))||r.enumerable});return t};var at=(t,n,o)=>(o=t!=null?wn(zn(t)):{},Tn(n||!t||!t.__esModule?lt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("./storage-entry-sPrgfaS5.cjs"),e=require("react/jsx-runtime"),u=require("react"),Rn=require("react-dom"),En=t=>`/book-index?id=${t}`,Ht=u.createContext(En);function Ln({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(Ht.Provider,{value:o,children:n})}function oe(){return u.useContext(Ht)}function he(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Bn(t,n){return he(t).includes(n)}const Ot={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Wn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},$n={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Be=u.createContext(null),Ut={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:"目錄",collectionTab:"叢編",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:"圖片資源"}},Pn={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:"目录",collectionTab:"丛编",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:"图片资源"}},An={"zh-Hant":Ut,"zh-Hans":Pn},Vt="bim-locale";function Fn(){try{const t=localStorage.getItem(Vt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Mn(t){try{localStorage.setItem(Vt,t)}catch{}}const Dn="zh-Hant",Hn=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??Dn),i=t??r;u.useEffect(()=>{if(t)return;const f=Fn();f&&f!==r&&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),Mn(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:i,setLocale:c,messages:An[i],converter:l}),[i,c,l]);return e.jsx(Be.Provider,{value:p,children:o})};function $(){const t=u.useContext(Be);return(t==null?void 0:t.messages)??Ut}const On=2e3;function H(){const t=u.useContext(Be),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=u.useCallback(l=>{if(!l)return"";if(!o)return l;const a=r.current.get(l);if(a!==void 0)return a;const c=o(l);if(r.current.size>=On){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(l,c),c},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function We(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Un(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Vn(){return{id:"",name:"",url:"",type:"text",details:""}}const Ze=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=$(),[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=he(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=Vn();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 z=[...t];if(z[y]={...z[y],[v]:j},v==="url"&&!z[y].id){const k=Un(j);k&&(z[y].id=k)}n(z)},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(z=>z.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,z,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:Nn(y.type??"text"),color:"#fff"},children:(()=>{var T,E;const m=he(y);return m.length===0?y.type??"text":m.length===1?((T=c.find(B=>B.value===m[0]))==null?void 0:T.label)??m[0]:m.includes("text")&&m.includes("image")?((E=c.find(B=>B.value==="text+image"))==null?void 0:E.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:"🔗"}),o&&y.url&&Kn(v,r==null?void 0:r[v],o,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:[Bn(y,"image")&&y.url&&Yn(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:{...de,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:{...de,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:{...de,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:{...de,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:m=>b(v,"url",m.target.value),placeholder:i.editor.resourceUrl,style:de}),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:de}),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:((z=y.coverage)==null?void 0:z.level)??"",onChange:m=>w(v,"level",m.target.value),placeholder:"1",style:{...de,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:{...de,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:m=>b(v,"details",m.target.value),placeholder:i.editor.detailsPlaceholder,style:{...de,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,T])=>{var E;return e.jsxs("label",{style:{...Ce,gap:"4px"},children:[e.jsx("span",{style:{..._e,minWidth:"56px"},children:T}),e.jsx("input",{type:"text",value:((E=y.metadata)==null?void 0:E[m])||"",onChange:B=>S(v,m,B.target.value),placeholder:T,style:{...de,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 Nn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Kn(t,n,o,r){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||o(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?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function Yn(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const de={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"},Gn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Jn(t){try{const n=new URL(t).hostname;return Gn[n]}catch{return}}const ct={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function qn(t){return t.includes("text")&&t.includes("image")?ct["text+image"]:ct[t[0]||"physical"]}const dt={text:0,image:1,physical:2};function Me(t){return t.length===0?"physical":[...t].sort((n,o)=>(dt[n]??99)-(dt[o]??99)).join("+")}function Zn(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},o=new Map,r=[],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(he(l))}`;o.has(f)||o.set(f,{base:{...l,name:c,url:"",volumes:[]},volumes:[]}),o.get(f).volumes.push({volume:p,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)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,r.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(he(t[l]))}`,p=`${i.base.name}|${Me(he(i.base))}`;c===p&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const tt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=$(),i=u.useMemo(()=>Zn(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(xt,{item:x},x.id||h))});const c=new Map;for(const x of i){const h=Me(he(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=qn(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(xt,{item:b,onNavigate:o,renderLink:r},b.id||S))})]},x)})})},pt=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},Nt=({value:t})=>{const o=$().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},Xn=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Nt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const s=String(n);return r?r(s):s};function Qn(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 eo(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function to(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const no={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},xt=({item:t,onNavigate:n,renderLink:o})=>{var S;const r=$(),{convert:s}=H(),i=oe(),[l,a]=u.useState(!1),c=u.useMemo(()=>(t.url?Jn(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||to(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?{...no[t.color_mode],label:r.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:pt(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(Nt,{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,r.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=eo(t.metadata);return g?Qn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:r.action.visit}),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?"收起 ▲":"展开 ▼"})]}),pt(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:[r.metadata[g]||g,": ",Xn(g,w,r,s)]},g)),t.details&&!f&&e.jsx("span",{children:s(t.details)}),t.structure&&e.jsxs("span",{children:[r.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[r.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),f&&l&&(()=>{const g=p.some(v=>v.group),w=[];if(g){let v=null;for(const j of p){const z=j.group||"";(!v||v.title!==z)&&(v={title:z,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 z=v.title?s(v.title):"";let k=z;return v.title&&v.group_id&&(o?k=o(v.group_id,z):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:z}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[k,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(y)})]},j)})})})()]})},Kt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const a=$(),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 o==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,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:r,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:r,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",ut=10,ft=8;function Te(){try{const t=localStorage.getItem(Ue);return t?JSON.parse(t):[]}catch{return[]}}function oo(t){try{const n=Te().filter(o=>o!==t);n.unshift(t),n.length>ut&&(n.length=ut),localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function ro(t){try{const n=Te().filter(o=>o!==t);localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function io(){try{localStorage.removeItem(Ue)}catch{}}const Yt=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=$(),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(Te),v=u.useRef(null),j=u.useRef(null),z=u.useRef(null);u.useEffect(()=>{if(!t.getAllEntries)return;let _=!1;return t.getAllEntries().then(L=>{_||g(L)}).catch(()=>{}),()=>{_=!0}},[t]);const k=u.useCallback(_=>{if(!_.trim())return w.map(C=>({type:"history",text:C}));if(!S)return[];const L=_.toLowerCase(),A=[],O=[];for(const C of S){if(A.length+O.length>=ft*2)break;const R=(C.title??"").toLowerCase();if(R.startsWith(L))A.push({type:"entry",text:C.title,entry:C});else if(R.includes(L))O.push({type:"entry",text:C.title,entry:C});else{const V=[...C.additional_titles||[],...C.attached_texts||[]];for(const N of V){const M=typeof N=="string"?N:N==null?void 0:N.book_title;if(M!=null&&M.toLowerCase().includes(L)){A.push({type:"entry",text:`${C.title}`,entry:C});break}}}}return[...A,...O].slice(0,ft)},[S,w]);u.useEffect(()=>{h(k(n)),b(-1)},[n,k]),u.useEffect(()=>{const _=L=>{z.current&&!z.current.contains(L.target)&&f(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]),u.useEffect(()=>{const _=L=>{var A,O;if(L.key==="/"&&document.activeElement!==v.current){const C=(A=document.activeElement)==null?void 0:A.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT")return;L.preventDefault(),(O=v.current)==null||O.focus()}};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[]);const m=u.useCallback(_=>{_.trim()&&(oo(_.trim()),y(Te())),r(_),f(!1)},[r]),T=u.useCallback(_=>{_.type==="history"?(o(_.text),m(_.text)):_.entry&&(s?(s(_.entry),f(!1)):(o(_.text),m(_.text)))},[o,m,s]),E=u.useCallback(_=>{if(!p||x.length===0){_.key==="Enter"&&m(n);return}switch(_.key){case"ArrowDown":_.preventDefault(),b(L=>(L+1)%x.length);break;case"ArrowUp":_.preventDefault(),b(L=>(L-1+x.length)%x.length);break;case"Enter":_.preventDefault(),d>=0&&d<x.length?T(x[d]):m(n);break;case"Escape":_.preventDefault(),f(!1);break}},[p,x,d,n,m,T]),B=u.useCallback((_,L)=>{L.stopPropagation(),ro(_),y(Te()),h(A=>A.filter(O=>!(O.type==="history"&&O.text===_)))},[]),F=u.useCallback(_=>{_.stopPropagation(),io(),y([]),h([])},[]);u.useEffect(()=>{if(d>=0&&j.current){const _=j.current.children;_[d]&&_[d].scrollIntoView({block:"nearest"})}},[d]);const W=!n.trim()&&w.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:a,value:n,onChange:_=>{o(_.target.value),f(!0)},onFocus:()=>f(!0),onKeyDown:E,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:[W&&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:F,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((_,L)=>e.jsxs("div",{onClick:()=>T(_),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:L===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:_.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.text}),_.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[_.entry.type],_.entry.edition&&` · ${_.entry.edition}`,_.entry.author&&` · ${_.entry.author}`]}),_.type==="history"&&e.jsx("button",{onClick:A=>B(_.text,A),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:"×"})]},`${_.type}-${_.text}-${L}`))]})]})},Le="bim-recent-ids",gt="bim-recent-entries",ht=50,Ge=5,so=50,lo=200;function Re(){try{const t=localStorage.getItem(Le);if(t)return JSON.parse(t);const n=localStorage.getItem(gt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Le,JSON.stringify(o)),localStorage.removeItem(gt),o}return[]}catch{return[]}}function ao(t){try{const n=Re().filter(o=>o!==t);n.unshift(t),n.length>ht&&(n.length=ht),localStorage.setItem(Le,JSON.stringify(n))}catch{}}function co(t){try{const n=Re().filter(o=>o!==t);localStorage.setItem(Le,JSON.stringify(n))}catch{}}function po(){try{localStorage.removeItem(Le)}catch{}}const xo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xe=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:p,initialQuery:f,onQueryChange:x,headerRight:h})=>{const d=$(),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),[z,k]=u.useState(!1),[m,T]=u.useState(null),[E,B]=u.useState(""),[F,W]=u.useState(!f),[_,L]=u.useState(Re),[A,O]=u.useState([]),[C,R]=u.useState(!1),[V,N]=u.useState(!1),[M,re]=u.useState(null),[Q,le]=u.useState(null),ge=u.useRef(void 0),fe=u.useRef(!1),q=u.useCallback(async(P,G)=>{if(!P.trim()){W(!0),y(null),j(null);return}W(!1),k(!0),B("");try{if(t.searchAll){const K=await t.searchAll(P,G??Ge);y(K)}else{const K=["work","book","collection","entity"],Y=await Promise.all(K.map(Z=>t.search(P,Z,{page:1,pageSize:G??Ge})));y({works:Y[0].entries,books:Y[1].entries,collections:Y[2].entries,entities:Y[3].entries,totalWorks:Y[0].total,totalBooks:Y[1].total,totalCollections:Y[2].total,totalEntities:Y[3].total})}}catch(K){B(K instanceof Error?K.message:String(K)),y(null)}finally{k(!1)}},[t]);u.useEffect(()=>{let P=!1;const G=()=>{var D,ee;const K=["work","book","collection","entity"],Y=Promise.all(K.map(ae=>t.loadEntries(ae,{page:1,pageSize:1}).catch(()=>({total:0})))),Z=((D=t.getResourceCounts)==null?void 0:D.call(t).catch(()=>null))??Promise.resolve(null),I=((ee=t.getSubtypeStats)==null?void 0:ee.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([Y,Z,I]).then(([ae,ce,st])=>{P||(re({works:ae[0].total,books:ae[1].total,collections:ae[2].total,entities:ae[3].total,hasText:ce==null?void 0:ce.hasText,hasImage:ce==null?void 0:ce.hasImage}),st&&le(st))})};return t.getCounts?t.getCounts().then(K=>{var Y,Z;P||(re({works:K.works,books:K.books,collections:K.collections,entities:K.entities,hasText:(Y=K.resourceCounts)==null?void 0:Y.hasText,hasImage:(Z=K.resourceCounts)==null?void 0:Z.hasImage}),K.subtypeStats&&le(K.subtypeStats))}).catch(()=>{P||G()}):G(),()=>{P=!0}},[t]),u.useEffect(()=>{fe.current||!(f!=null&&f.trim())||(fe.current=!0,q(f))},[f,q]);const J=u.useCallback(P=>{if(g(P),x==null||x(P),!P.trim()){W(!0),y(null),j(null);return}ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>{j(null),q(P)},lo)},[q,x]),Ve=u.useCallback(P=>{ge.current&&clearTimeout(ge.current),x==null||x(P),q(P)},[q,x]),Ne=u.useCallback(P=>{j(P),q(S,so)},[S,q]);u.useEffect(()=>{if(!_.length){O([]);return}let P=!1;return R(!0),Promise.all(_.slice(0,10).map(async G=>{var K,Y,Z;try{if(t.getEntry){const D=await t.getEntry(G);if(D)return D}const I=await t.getItem(G);if(I){const D=I.authors;return{id:G,title:I.title||G,type:I.type||"work",author:(K=D==null?void 0:D[0])==null?void 0:K.name,dynasty:(Y=D==null?void 0:D[0])==null?void 0:Y.dynasty,role:(Z=D==null?void 0:D[0])==null?void 0:Z.role,edition:I.edition||void 0}}}catch{}return{id:G,title:G,type:"work",notFound:!0}})).then(G=>{P||(O(G),R(!1))}),()=>{P=!0}},[_,t]);const ke=P=>{T(P.id),ao(P.id),L(Re()),r==null||r(P)},we=P=>{co(P),L(Re())},Ke=()=>{po(),L([])},$e=P=>b.find(G=>G.type===P),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(Kt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Yt,{transport:t,value:S,onChange:J,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})]}),M&&F&&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:M.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:M.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()}),M.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:M.entities.toLocaleString()})]})]})}),M.hasImage!=null&&M.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.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}):E?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:E})]}):F?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}):A.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:A.slice(0,V?10:3).map(P=>P.notFound?e.jsx(uo,{id:P.id,onRemove:we,t:d},P.id):e.jsx(bt,{entry:P,selected:m===P.id,onClick:ke,getConfig:$e,onRemove:we},P.id))}),!V&&A.length>3&&e.jsx("button",{onClick:()=>N(!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:P,icon:G,name:K,key:Y})=>{const Z=w[Y]??[],I=xo[Y],D=w[I]??0;if(Z.length===0)return null;const ae=!(v===P)&&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:[G," ",K,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[D," ",d.unit.items]})]}),ae&&e.jsx("button",{onClick:()=>Ne(P),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:Z.map(ce=>e.jsx(bt,{entry:ce,selected:m===ce.id,onClick:ke,getConfig:$e,query:S},ce.id))})]},P)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:We(d.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},bt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=$(),{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:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children: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:"→"})]})},uo=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function fo(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 go({data:t}){const{convert:n}=H(),{dynasty:o,birth_year:r,death_year:s}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?i.push(`${r}—${s}`):r!==void 0?i.push(`${r}—?`):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 ho({alt_names:t}){const{convert:n}=H(),o=new Map;for(const i of t){const l=i.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,l)=>{const a=r.indexOf(i),c=r.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=o.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 bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function mo({works:t,transport:n,onNavigate:o,renderLink:r}){const s=$(),{convert:i}=H(),l=oe(),[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 z=0;z<d.length;z++){const k=v[z];k!=null&&k.title?S.set(d[z],k.title):k!=null&&k.primary_name?S.set(d[z],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 z=!0;for(const k of d){const m=j.get(k);m?S.set(k,m):z=!1}if(z)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),z=j&&(j.title||j.primary_name)||v;S.set(v,z)}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 r?e.jsx("li",{children:r(b.work_id,g)},S):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),o(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 Gt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var f;const i=$(),{convert:l}=H();let a=!1;try{a=U.extractStatus(t.id)==="draft"}catch{}const c=fo(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(go,{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(ho,{alt_names:t.alt_names}),e.jsx(bo,{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(mo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},yo=["〇","一","二","三","四","五","六","七","八","九"],mt=["","十","百","千"];function Jt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",s=!1;for(let i=0;i<o;i++){const l=parseInt(n[i]),a=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&a===1&&i===0?r+=mt[a]:r+=yo[l]+mt[a])}return r}function qt({type:t}){const n=$(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function vo({isDraft:t}){const n=$();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 jo({id:t}){const n=$(),[o,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ne({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function pe({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 Zt({authors:t,type:n,onNavigate:o,renderLink:r}){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(se,{id:i.entity_id,label:a,onNavigate:o,renderLink:r}):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 se({id:t,label:n,onNavigate:o,renderLink:r}){const s=oe();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function So({id:t,title:n,edition:o,type:r,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,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),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(qt,{type:r}),e.jsx(vo,{isDraft:s}),e.jsx(jo,{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(Zt,{authors:i,type:r,onNavigate:p,renderLink:f}),a]})]})}function Xt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=$(),{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&&o&&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(se,{id:p.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(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(pe,{label:i.label.titleInfo,children:l(p.title_info)}),p.author_info&&e.jsx(pe,{label:i.label.authorInfo,children:l(p.author_info)}),p.edition&&e.jsx(pe,{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 ko({items:t,onNavigate:n,renderLink:o}){const r=$();return e.jsx(Xt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Qt({items:t,onNavigate:n,renderLink:o}){const r=$();return e.jsx(Xt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function en({label:t,items:n}){const{convert:o}=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((r,s)=>{const i=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},s)})})]}):null}function wo({items:t}){const n=$();return e.jsx(en,{label:n.section.aliases,items:t})}function Co({items:t}){const n=$();return e.jsx(en,{label:n.section.attachedTexts,items:t})}function _o({items:t}){const n=$(),{convert:o}=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((r,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:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function zo({items:t}){const n=$(),{convert:o}=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((r,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:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Io({items:t}){const n=$(),{convert:o}=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((r,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:"·"}),o(r)]},s))})]}):null}function yt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=H(),[l,a]=u.useState([]);return u.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>o.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,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(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(se,{id:c.id,label:p,onNavigate:r,renderLink:s})},c.id)})})]}):null}function To({book:t,onNavigate:n,renderLink:o}){const r=$(),{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(se,{id:t.id,label:c,onNavigate:n,renderLink:o})}),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?r.action.expand:r.action.collapse,children:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(tt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ro({ids:t,transport:n,onNavigate:o,renderLink:r}){const s=$(),[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(To,{book:a,onNavigate:o,renderLink:r},a.id))})]}):null}function Eo({workData:t,onNavigate:n,renderLink:o}){var i,l,a;const r=$(),{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(qt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(se,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),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:[Jt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(Zt,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((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(pe,{label:r.label.parentWork,children:e.jsx(se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Lo({items:t,onNavigate:n,renderLink:o}){const r=$(),{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:r.indexType.collection}),e.jsx(se,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:o}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:We(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const nt=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,className:l,style:a})=>{var F,W,_,L,A,O;const c=$(),{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||!o)return;let C=!1;return d(!0),S(null),o.getItem(n).then(R=>{C||(R?x(R):S(c.misc.notFoundEntry))}).catch(R=>{C||S(R instanceof Error?R.message:c.misc.loadFailed)}).finally(()=>{C||d(!1)}),()=>{C=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){w(null),v([]);return}let C=!1;const R=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(R?o.getItem(R).then(V=>{!C&&V&&V.type==="work"&&w(V)}).catch(()=>{}):w(null),j.type==="book"){const V=j;V.contained_in&&V.contained_in.length>0?Promise.all(V.contained_in.map(N=>{const M=typeof N=="string"?N:N.id,re=typeof N=="string"?void 0:N.volume_index;return o.getItem(M).then(Q=>({id:M,title:Q&&Q.title||M,volume_index:re})).catch(()=>({id:M,title:M,volume_index:re}))})).then(N=>{C||v(N)}):v([])}else v([]);return()=>{C=!0}},[j,o]),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,R)=>e.jsx("div",{style:{height:R===1?"32px":"16px",width:`${C}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},R))})});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(Gt,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const z=j.type==="book"?j:null,k=j.type==="collection"?j:null,m=j.type==="work"?j:null;let T=!1;try{T=U.extractStatus(j.id)==="draft"}catch{}let E="";j.measure_info?E=p(j.measure_info):(F=j.juan_count)!=null&&F.number?E=Jt(j.juan_count.number)+c.unit.juan:(W=j.juan_count)!=null&&W.description&&(E=p(j.juan_count.description));const B=[];return(_=j.publication_info)!=null&&_.year&&B.push(e.jsx(pe,{label:c.label.year,children:j.publication_info.year},"year")),(L=j.current_location)!=null&&L.name&&B.push(e.jsx(pe,{label:c.label.currentLocation,children:p(j.current_location.name)},"loc")),(A=j.page_count)!=null&&A.description&&B.push(e.jsx(pe,{label:c.label.pageCount,children:j.page_count.description},"page")),z!=null&&z.edition&&B.push(e.jsx(pe,{label:c.label.edition,children:p(z.edition)},"ver")),m!=null&&m.parent_work&&B.push(e.jsx(pe,{label:c.label.parentWork,children:e.jsx(se,{id:m.parent_work.id,label:p(m.parent_work.title),onNavigate:r,renderLink:s})},"pw")),m!=null&&m.parent_works&&m.parent_works.length>0&&!m.parent_work&&B.push(e.jsx(pe,{label:c.label.parentWork,children:m.parent_works.map((C,R)=>e.jsxs("span",{children:[R>0&&"、",e.jsx(se,{id:C,onNavigate:r,renderLink:s})]},C))},"pws")),e.jsxs("div",{className:l,style:a,children:[e.jsx(So,{id:j.id,title:p(j.title),edition:j.edition?p(j.edition):void 0,type:j.type,isDraft:T,authors:j.authors,volumeText:E,meta:B,headerExtra:i,onNavigate:r,renderLink:s}),((O=j.description)==null?void 0:O.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(Lo,{items:y,onNavigate:r,renderLink:s})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.belongsToWork}),e.jsx(Eo,{workData:g,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(_o,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(wo,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Co,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(ko,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Qt,{items:j.emendated_by,onNavigate:r,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:r,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(zo,{items:z.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(Io,{items:k.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(yt,{title:c.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(yt,{title:c.section.containedBooks,ids:k.books,transport:o,onNavigate:r,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(se,{id:C.id,label:p(C.title),onNavigate:r,renderLink:s})},C.id))})]}),(m==null?void 0:m.books)&&m.books.length>0&&e.jsx(Ro,{ids:m.books,transport:o,onNavigate:r,renderLink:s}),(m==null?void 0:m.related_works)&&m.related_works.length>0&&(()=>{const C=[],R=m.related_works.filter(M=>M.relation==="part_of"),V=m.related_works.filter(M=>M.relation==="has_part"),N=m.related_works.filter(M=>!M.relation);return R.length>0&&C.push({label:c.section.belongsToWork,items:R}),V.length>0&&C.push({label:c.section.containedWorks,items:V}),N.length>0&&C.push({label:c.section.relatedWorks,items:N}),C.map(M=>e.jsxs("div",{children:[e.jsxs(ne,{children:[M.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",M.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:M.items.map(re=>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(se,{id:re.id,label:p(re.title),onNavigate:r,renderLink:s})},re.id))})]},M.label))})()]})};function Bo({data:t}){const n=$(),{convert:o}=H(),{stats:r}=t,s=r.processed_volumes??r.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:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),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:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Wo({sections:t,activeSection:n,onSelect:o}){const r=$();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:vt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:vt(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 vt(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 $o({id:t,label:n,onNavigate:o,renderLink:r}){const s=oe();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter: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 Po(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function jt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=$(),{convert:i}=H(),l=t.book_id||t.work_id,a=r&&t.volumes.length>0?Po(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:[r&&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($o,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const tn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const a=$(),[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||!(o!=null&&o.getCollectionCatalog))return;let m=!1;return x(!0),d(null),o.getCollectionCatalog(n).then(T=>{m||(T?p(T):d(a.catalog.notFound))}).catch(T=>{m||d(T instanceof Error?T.message:a.catalog.loadFailed)}).finally(()=>{m||x(!1)}),()=>{m=!0}},[t,n,o,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(E=>E.volumes[0]).filter(E=>E!=null);return new Set(m).size<m.length},[y]),z=u.useMemo(()=>{if(!y)return[];let m=y.books;if(b&&(m=m.filter(T=>T.section===b)),g.trim()){const T=g.trim().toLowerCase();m=m.filter(E=>E.title.toLowerCase().includes(T)||E.sub_items&&E.sub_items.some(B=>B.toLowerCase().includes(T))||E.edition&&E.edition.toLowerCase().includes(T))}return m},[y,b,g]),k=u.useMemo(()=>{if(!j)return null;const m=[],T=new Map;for(const B of z){if(!B.volumes||B.volumes.length===0)continue;const F=B.volumes[0];T.has(F)||T.set(F,[]),T.get(F).push(B)}const E=[...T.keys()].sort((B,F)=>B-F);for(const B of E)m.push({volume:B,books:T.get(B)});return m},[z,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(Bo,{data:y}),v&&e.jsx(Wo,{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:[z.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,T)=>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:We(a.catalog.volume,{n:m.volume})}),m.books.map((E,B)=>e.jsx(jt,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${m.volume}-${B}`))]},`${m.volume}-${T}`)):z.map((m,T)=>e.jsx(jt,{book:m,onNavigate:r,renderLink:s,showVolumes:!0},T)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},me=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Pe=7,Ao=({content:t,children:n,placement:o="top",delayMs:r=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,z=document.documentElement.clientWidth;let k=o;o==="top"&&y.top-v.height-Pe<8&&(k="bottom"),o==="bottom"&&y.bottom+v.height+Pe>j-8&&(k="top");const m=k==="top"?y.top-v.height-Pe:y.bottom+Pe;let T=y.left+y.width/2-v.width/2;T=Math.max(8,Math.min(T,z-v.width-8)),p({left:T,top:m,placement:k})},[o]),b=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(!0),r)},[r]),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&&Rn.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)]})},St={A:"fine",B:"rough",C:"rough",D:"ocr"};function Fo(t){return typeof t!="string"?null:t in Ot?t:t in St?St[t]:null}const Mo=["〇","一","二","三","四","五","六","七","八","九"],kt=["","十","百","千"],Do=["","萬","億"];function nn(t){if(t===0)return"〇";if(t<0)return`負${nn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Ho(s,r>0)+Do[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ho(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let i=0;i<o.length;i++){const l=o[i],a=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&a===1&&i===0&&!n?s+=kt[a]:s+=Mo[l]+kt[a]}return s.replace(/〇$/,"")}let Ee=null,Ae=null;const He=new Set;function Oo(){return Ee?Promise.resolve():Ae||(Ae=import("opencc-js/t2cn").then(t=>{Ee=t.Converter({from:"tw",to:"cn"}),He.forEach(n=>n())}).catch(()=>{Ee=t=>t,He.forEach(t=>t())}),Ae)}function ue(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Ee)return;const n=()=>t(o=>o+1);return He.add(n),Oo(),()=>{He.delete(n)}},[]),Ee??(n=>n)}function je(t,n){return n(t).toLowerCase()}const ot="#fff59d";function Se(t,n,o){if(!n)return t;const r=je(n,o);if(!r)return t;const s=je(t,o);if(s.length!==t.length)return t;const i=[];let l=0,a=0;for(;l<t.length;){const c=s.indexOf(r,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:ot,padding:0,color:"inherit"},children:t.slice(c,c+r.length)},a++)),l=c+r.length}return e.jsx(e.Fragment,{children:i})}function rt(t,n,o,r){if(!n)return!0;const s=je(n,r);return(o?[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,r).includes(s))}function Uo(t,n,o){return n?je(t,o).includes(je(n,o)):!0}const it={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Vo={考证:"#5d6d7e"};function No(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 on({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=No(t),p=!!(r!=null&&r.vol_label)&&!c.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(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?`${ot}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:["(",r.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 rn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>rn(r,n)))}function sn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+sn(i),0))||0;return n+o}function Ko(t,n){const o=[],r=l=>{var a;o.push(...l.files),(a=l.children)==null||a.forEach(r)};if(r(t),o.length===0)return;const s=o.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 ln({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=rn(t,n||""),a=Ko(t,i),c=typeof a=="number"&&a>0,p=a===0,[f,x]=u.useState(l||c),h=sn(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||o(S)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*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?`${ot}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:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!f),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":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+r*16}px`},children:t.files.map(S=>e.jsx(on,{file:S,isActive:n===S,onSelect:o,meta:s==null?void 0:s[S],matchState:i[S]},S))}),d&&t.children.map((S,g)=>e.jsx(ln,{group:S,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function Yo({files:t,groups:n,activeFile:o,onSelect:r,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(ln,{group:a,activeFile:o,onSelect:r,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(on,{file:a,isActive:o===a,onSelect:r,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function Go({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 Jo({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=H(),s=oe(),i=ue(),l=S=>{if(!S)return"";const g=r(S);return o?Se(g,o,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(()=>{o&&c(!0)},[o]);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:[nn(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 qo({section:t,highlightQuery:n=""}){const{convert:o}=H(),r=ue(),s=c=>{if(!c)return"";const p=o(c);return n?Se(p,n,r):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(Go,{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 Zo({section:t,highlightQuery:n=""}){const{convert:o}=H(),r=ue();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),i=n?Se(s,n,r):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 Xo(t,n,o){const[r,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=o==null?void 0:o.current)!=null&&x.has(f))}),a={};for(const f of t)(p=o==null?void 0:o.current)!=null&&p.has(f)&&(a[f]=o.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=o==null?void 0:o.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]),r}function Qo({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=H(),l=
|
|
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 nr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=H(),s=oe(),i=ue(),l=p=>{if(!p)return"";const f=r(p);return o?Se(f,o,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:r(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 or({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=H(),i=ue(),[l,a]=u.useState("catalog"),c=o.trim(),p=u.useMemo(()=>c?t.sections.filter(d=>rt(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(tr,{text:n,highlightQuery:c}):e.jsx(nr,{sections:t.sections,onNavigate:r,highlightQuery:c})),l==="catalog"&&p.map((d,b)=>d.type==="书"||d.type==="詩"?e.jsx(Jo,{section:d,onNavigate:r,highlightQuery:c},b):d.type==="类"?e.jsx(qo,{section:d,highlightQuery:c},b):e.jsx(Zo,{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 an(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 wt(t){const n=an(t);return n.length>0?n[0]:null}function rr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:a,isKaozhen:c}=t,p=ue(),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)rt(w,S,c,p)&&g++;return g===0&&b.rawText&&Uo(b.rawText,S,p)&&(g=1),g},[c,p]);return u.useEffect(()=>{const b=a.trim();if(!b){h({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let S=!1;const g={},w=[];for(const k of r){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++,T=w[m];try{const[E,B]=await Promise.all([o.getCollatedJuan(n,T),((k=o.getCollatedJuanText)==null?void 0:k.call(o,n,T))??Promise.resolve(null)]),F={juan:E,rawText:B};if(f.current.set(T,F),S)return;h(W=>({...W,[T]:d(F,b)}))}catch{if(S)return;h(E=>({...E,[T]:0}))}}},z=Array.from({length:Math.min(y,w.length)},()=>j());return Promise.all(z),()=>{S=!0}},[a,n,o,r.join(","),d,p]),{matchStates:x}}const cn=({index:t,workId:n,transport:o,onNavigate:r,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,z]=u.useState(null),[k,m]=u.useState(""),T=u.useRef(new Map),E=s??b,B=u.useCallback(C=>{S(C),i==null||i(C)},[i]),F=t||c;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let C=!1;return x(!0),d(null),o.getCollatedEditionIndex(n).then(R=>{if(!C)if(!R)d("未找到整理本数据");else{p(R);const V=wt(R);!s&&V&&B(V)}}).catch(R=>{C||d(R instanceof Error?R.message:"加载失败")}).finally(()=>{C||x(!1)}),()=>{C=!0}},[t,n,o,s,B]),u.useEffect(()=>{const C=t||c;if(C&&!E){const R=wt(C);R&&B(R)}},[t,c,E,B]);const W=n||(F==null?void 0:F.work_id),_=u.useCallback(async C=>{var R;if(!(!W||!(o!=null&&o.getCollatedJuan))){v(!0),w(null),z(null);try{const[V,N]=await Promise.all([o.getCollatedJuan(W,C),((R=o.getCollatedJuanText)==null?void 0:R.call(o,W,C))??Promise.resolve(null)]);w(V),z(N)}catch{w(null),z(null)}finally{v(!1)}}},[W,o]);u.useEffect(()=>{E&&_(E)},[E,_]);const L=C=>{B(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(!F)return null;const A=F.type==="kaozhen",O=an(F);return e.jsx(ir,{className:l,style:a,index:F,allFiles:O,isKaozhen:A,effectiveWorkId:W,transport:o,activeFile:E,handleSelectFile:L,juanData:g,juanRawText:j,juanLoading:y,searchQuery:k,setSearchQuery:m,onNavigate:r,workLabelCacheRef:T})},ir=({className:t,style:n,index:o,allFiles:r,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}=rr({workId:i,transport:l,files:r,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:[o.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_juan})," 卷"]})}),o.text_quality&&(()=>{const w=Fo(o.text_quality.grade);return w?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Ao,{content:Wn[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:$n[w],cursor:"help"},children:Ot[w]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(Yo,{files:r,groups:o.juan_groups,activeFile:a,onSelect:c,juanMeta:o.juan_metadata,matchStates:g}),x?e.jsx(me,{}):p?s?e.jsx(er,{juan:p,searchQuery:h,onNavigate:b,transport:l,workLabelCache:S}):e.jsx(or,{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,o.references&&o.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:"參考文獻"}),o.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))]})]})},sr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},lr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function ar(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const dn=({items:t,loading:n})=>{const o=oe();return n?e.jsx(me,{}):t.length===0?e.jsx("div",{style:cr,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=sr[r.type],i=lr[r.status];return e.jsxs("div",{style:dr,children:[e.jsxs("div",{style:pr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Ct,background:s.color},children:s.label}),e.jsx("span",{style:{...Ct,background:i.color},children:i.label})]}),e.jsx("span",{style:xr,children:ar(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:ur,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:_t,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:_t,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:fr,children:r.content}),r.reply&&e.jsxs("div",{style:gr,children:[e.jsx("div",{style:hr,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},cr={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},dr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},pr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ct={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},xr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ur={fontSize:"12px",marginBottom:"6px"},_t={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},fr={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},gr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},hr={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Qe=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=$(),[a,c]=u.useState(null),[p,f]=u.useState([]),[x,h]=u.useState("recommend"),[d,b]=u.useState([]),[S,g]=u.useState(!1),w=r??x,y=W=>{h(W),s==null||s(W)},[v,j]=u.useState(!0),[z,k]=u.useState(null),[m,T]=u.useState(null),[E,B]=u.useState(null);u.useEffect(()=>{let W=!1;const _=A=>{W||c(A)},L=()=>{t.getAllEntries&&t.getAllEntries().then(A=>{_({works:A.filter(O=>O.type==="work").length,books:A.filter(O=>O.type==="book").length,collections:A.filter(O=>O.type==="collection").length})}).catch(()=>{})};return t.getCounts?t.getCounts().then(A=>_({works:A.works,books:A.books,collections:A.collections})).catch(L):L(),()=>{W=!0}},[t]),u.useEffect(()=>{let W=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const L=await t.getRecommended();if(L!=null&&L.groups)return L.groups.flatMap(A=>A.items.map(O=>({...O,group:A.name})))}catch{}return[]})().then(async L=>{if(W)return;const A=L.filter(C=>C.id);if(A.length===0){j(!1);return}const O=await Promise.all(A.map(async C=>{try{let R=null;if(t.getEntry)R=await t.getEntry(C.id);else{const V=await t.getItem(C.id);V&&(R={id:C.id,title:V.title||C.id,type:V.type||"work"})}if(R)return{...R,group:C.group,fallbackDescription:C.description}}catch{}return{id:C.id,title:C.title,type:U.extractType(C.id),group:C.group,fallbackDescription:C.description}}));W||(f(O.filter(C=>C!==null)),j(!1))}),()=>{W=!0}},[t,o]),u.useEffect(()=>{let W=!1;const _=t.getCatalogProgress??t.getResourceProgress;if(_)return _.call(t).then(L=>{W||k(L)}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{if(!t.getCollectionProgress)return;let W=!1;return t.getCollectionProgress().then(_=>{W||T(_)}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{if(!t.getSiteProgress)return;let W=!1;return t.getSiteProgress().then(_=>{W||B(_)}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{if(!i||w!=="feedback")return;let W=!1;return g(!0),fetch(i).then(_=>_.json()).then(_=>{!W&&_.success&&b(_.items||[])}).catch(()=>{}).finally(()=>{W||g(!1)}),()=>{W=!0}},[i,w]);const F=W=>{switch(W){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(ze,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>y("recommend")}),e.jsx(ze,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>y("catalog")}),e.jsx(ze,{label:l.home.collectionTab,active:w==="collection",onClick:()=>y("collection")}),e.jsx(ze,{label:l.home.siteTab,active:w==="site",onClick:()=>y("site")}),i&&e.jsx(ze,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>y("feedback")})]}),w==="recommend"&&e.jsx(br,{recommended:p,loading:v,onNavigate:n,getIcon:F,t:l}),w==="catalog"&&e.jsx(zt,{progress:z,t:l,onNavigate:n}),w==="collection"&&e.jsx(zt,{progress:m,t:l,onNavigate:n}),w==="site"&&e.jsx(yr,{progress:E,t:l,totalWorks:(a==null?void 0:a.works)??0}),w==="feedback"&&i&&e.jsx(dn,{items:d,loading:S})]})})},ze=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),br=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=oe();if(n)return e.jsx(me,{});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(),o==null||o(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:r(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))})},zt=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(me,{});const r=[...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=r.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(mr,{item:p,t:n,statusColor:l[a],onNavigate:o},p.id))})]},a)})})},mr=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=oe(),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&&r?e.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(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?We(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:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},yr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(me,{});const r=[...t.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),i=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),a=o>0?Math.round(l/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",o.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(It,{item:c,t:n,totalWorks:o},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(It,{item:c,t:n,totalWorks:o},c.id))})]})]})},It=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Tt="(max-width: 768px)";function vr(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(Tt).matches);return u.useEffect(()=>{const o=window.matchMedia(Tt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const jr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var O;const i=$(),{convert:l}=H(),a=vr(),[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,z]=u.useState(null),[k,m]=u.useState(!1),T=u.useCallback(async C=>{if(!t.getCollatedEditionIndex){z(null);return}m(!0);try{const R=await t.getCollatedEditionIndex(C);z(R)}catch{z(null)}finally{m(!1)}},[t]),E=u.useCallback(async C=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){w([]);return}v(!0);try{if(t.getCollectionCatalogs){const R=await t.getCollectionCatalogs(C);w(R||[])}else if(t.getCollectionCatalog){const R=await t.getCollectionCatalog(C);w(R?[{resource_id:"",data:R}]:[])}}catch{w([])}finally{v(!1)}},[t]),B=u.useCallback(async C=>{if(o){o(C);return}p(C),x(null),w([]),z(null),S("detail"),d(!0);try{const R=await t.getItem(C.id);R&&(x(R),R.type==="collection"?E(C.id):R.type==="work"&&R.has_collated&&T(C.id))}catch(R){console.error("加载详情失败:",R)}finally{d(!1)}},[t,o,E,T]),F=u.useCallback(async C=>{x(null),w([]),z(null),S("detail"),d(!0);try{const R=await t.getItem(C);R&&(x(R),p({id:C,title:R.title||C,type:R.type||"book"}),R.type==="collection"?E(C):R.type==="work"&&R.has_collated&&T(C))}catch(R){console.error("导航失败:",R)}finally{d(!1)}},[t,E,T]),W=(f==null?void 0:f.type)==="collection"&&(g.length>0||y)||(f==null?void 0:f.type)==="work"&&(j||k),_=a&&(h||f),L=u.useCallback(()=>{p(null),x(null),w([]),z(null),S("detail")},[]),A=e.jsx(e.Fragment,{children:h?e.jsx(me,{}):f?e.jsxs(e.Fragment,{children:[(W||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:[W&&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:F}):b.startsWith("catalog:")?e.jsx(tn,{data:(O=g.find(C=>`catalog:${C.resource_id}`===b))==null?void 0:O.data,onNavigate:F}):b==="collated"?e.jsx(cn,{index:j||void 0,workId:f.id,transport:t,onNavigate:F}):null})]}):e.jsx(Qe,{transport:t,onNavigate:F,recommendedIds:r})});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:_?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:L,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:A})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Xe,{transport:t,onEntryClick:B,hideModeIndicator:n}),!f&&e.jsx(Qe,{transport:t,onNavigate:F,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Xe,{transport:t,onEntryClick:B,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:A})]})};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 Sr=({data:t,onNavigate:n,className:o,style:r})=>{var f;const s=$(),{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:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children: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(kr,{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))})]})},kr=({division:t,expanded:n,onToggle:o,expandedCat:r,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:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children: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(wr,{category:c,expanded:r===p,onToggle:()=>s(p),onNavigate:i},c.name)})})]})},wr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{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:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[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(Rt,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(Rt,{label:"存目",books:l,onNavigate:r})]})]})},Rt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=H(),s=oe(),[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&&o?e.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(c.title)}):r(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(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," 條"]})]})},ie=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=$();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:_r,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Cr,children:i.action.save})]})]}),s]})},Cr={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},_r={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},te=({label:t,value:n,onChange:o,placeholder:r,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=>o(i.target.value),placeholder:r,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"}})]}),be=({value:t,onChange:n,placeholder:o})=>{const r=u.useRef(null);return u.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Oe=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function zr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const De=({value:t,onChange:n,label:o})=>{const[r,s]=u.useState(!1),i=u.useRef(null),l=zr(t||"");return u.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Et,children:o}),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:Et,children:o}),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"}})]})},Et={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Ir(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Tr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const pn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=$(),[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"&&o&&o(b=>{const S=[...t];S[x]={...S[x],id:b.id,name:b.title,type:"bookID"},n(S)})},f=x=>{o&&o(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||`${r.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ir(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Tr(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:r.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:xe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Lt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>p(h,"url"),style:{...Lt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),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:xe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Bt,children:r.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:r.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:r.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:xe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Bt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>c(h,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.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:{...xe,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>c(h,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.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:xe,children:r.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:xe,children:r.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:r.action.addSource})]})]})},xe={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"},Lt={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"},Bt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function xn(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function un(t){return!t||t.length===0?"":JSON.stringify(t)}const fn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,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=$();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:Rr,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),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(Ie,{direction:"up",title:g.relation.parentWork,entity:r,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(Ie,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{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})]})]})]})},Ie=({direction:t,title:n,entity:o,onView:r,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})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:gn(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Wt,{onClick:()=>r(o),title:f,children:"👁️"}),e.jsx(Wt,{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:o,onView:r,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?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>r(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:gn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.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," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(et,{onClick:s,primary:!0,children:["+ ",i]})})]})},Wt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),et=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function gn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Rr={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"},hn=({isOpen:t,entityType:n,title:o,onSelect:r,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:Er,children:e.jsxs("div",{style:Lr,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:s,style:Br,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:Wr})}),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:()=>r(g),style:$r,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:Pr,children:["创建新",b,"并关联"]})]})]})})},Er={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},Lr={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)"},Br={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Wr={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"},$r={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)"},Pr={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},$t={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ar={work:"📜",book:"📖",collection:"📚",entity:"👤"},bn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,a]=u.useState(""),c=u.useRef(null);u.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,d;(h=c.current)==null||h.focus(),(d=c.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?f():h.key==="Escape"&&i()},f=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const x=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${$t[n]}`}};return e.jsx("div",{style:Fr,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Mr,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:Ar[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:`请输入${$t[n]}名称...`,style:Dr})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:Hr,children:"取消"}),e.jsx("button",{onClick:f,disabled:!l.trim(),style:{...Or,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Fr={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},Mr={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)"},Dr={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"},Hr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Or={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Ur(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function mn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Vr(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const yn=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],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(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!x.trim()){b([]);return}const T=setTimeout(async()=>{g(!0);try{b(await f(x,o))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(T)},[x,o,f]);const v=u.useCallback(T=>{h(T.target.value),T.target.value.trim()&&y("search")},[]),j=u.useCallback(T=>s?T.filter(E=>E.id!==s):T,[s]);if(!t)return null;const z=n||(o==="all"?"选择实体":`选择${mn(o)}`),k=j(r),m=j(d);return e.jsx("div",{style:Kr,children:e.jsxs("div",{style:Yr,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:Gr,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:Jr}),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(Pt,{active:w==="recent",onClick:()=>y("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(Pt,{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(At,{entities:k,onSelect:a}):x.trim()?S?e.jsx(qe,{message:"搜索中..."}):m.length>0?e.jsx(At,{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:qr,children:l||"创建新实体"})]})]})})},Pt=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),At=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Nr,{entity:o,onClick:()=>n(o)},o.id))}),Nr=({entity:t,onClick:n})=>{const[o,r]=u.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Ur(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:Vr(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:mn(t.type)})]})},qe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Kr={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},Yr={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)"},Gr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Jr={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"},qr={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Zr={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Xr={work:"📜",collection:"📚",book:"📖",entity:"👤"},vn=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:a,renderSectionActions:c,onDownloadResource:p,downloadStatuses:f,relations:x,onRelationsChange:h})=>{var Z;const d=$(),[b,S]=u.useState(!1),[g,w]=u.useState("work"),[y,v]=u.useState(""),[j,z]=u.useState(""),[k,m]=u.useState([]),[T,E]=u.useState(!1),[B,F]=u.useState(!1),[W,_]=u.useState("work"),[L,A]=u.useState(""),[O,C]=u.useState(),[R,V]=u.useState(!1),[N,M]=u.useState(null),[re,Q]=u.useState([]);u.useRef(null);const le=t.type,ge=le==="work",fe=le==="collection",q=le==="book",J=u.useCallback((I,D)=>{n({...t,[I]:D})},[t,n]),Ve=u.useCallback((I,D)=>{v(I),w(D),z(d.editor.selectToLink+d.indexType[D]),m([]),S(!0)},[d]),Ne=u.useCallback(I=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,I)},[r,t.id]),ke=u.useCallback(I=>{s==null||s(I.id,I.type)},[s]),we=u.useCallback((I,D,ee)=>{const ae={...ee,author:(ee==null?void 0:ee.author)||t.author,dynasty:(ee==null?void 0:ee.dynasty)||t.dynasty};_(D),A(I),C(ae),F(!0)},[t.author,t.dynasty]),Ke=u.useCallback((I,D)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,L,{type:W,title:I,inheritData:D}),F(!1)},[r,t.id,L,W]),$e=u.useCallback(I=>{if(!I.trim()){m([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(I,g).then(D=>{m(D),E(!1)}).catch(()=>{m([]),E(!1)})},[r,g]),Ye=u.useCallback(I=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,y,I.id),S(!1)},[r,t.id,y]),P=u.useCallback(()=>{o()},[o]),G=u.useCallback(I=>{M(()=>I),V(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),K=u.useCallback((I,D)=>r!=null&&r.searchEntities?r.searchEntities(I,D==="all"?void 0:D):Promise.resolve([]),[r]),Y=u.useCallback(I=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(I),Q(D=>[I,...D.filter(ee=>ee.id!==I.id)].slice(0,10)),N==null||N(I),V(!1),M(null)},[r,N]);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:Xr[le]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Oe,{children:t.id}),e.jsx(Oe,{color:Zr[le],children:d.indexType[le]})]})}),e.jsx(ie,{title:d.section.basicInfo,onSave:o,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:ge?d.editor.workTitle:fe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:I=>J("title",I)}),q&&e.jsx(De,{label:d.editor.belongsToWork,value:t.workName||"",onChange:I=>J("workName",I)}),e.jsx(te,{label:d.editor.authorLabel,value:t.author||"",onChange:I=>J("author",I)}),e.jsx(te,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:I=>J("dynasty",I)}),(q||fe)&&e.jsx(De,{label:d.editor.containedIn,value:t.collection||"",onChange:I=>J("collection",I)}),(q||fe)&&e.jsx(te,{label:d.editor.holderLabel,value:t.holder||"",onChange:I=>J("holder",I)}),(q||fe)&&e.jsx(te,{label:q?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:I=>J("pages",I)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(te,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:I=>J("firstImage",I)})})]})}),e.jsx(ie,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(be,{value:t.description||"",onChange:I=>J("description",I),placeholder:d.editor.descriptionPlaceholder})}),(((Z=t.additional_works)==null?void 0:Z.length)||0)>0&&e.jsx(ie,{title:d.section.additionalWorks,onSave:o,children:e.jsx(Qr,{items:t.additional_works||[],onChange:I=>J("additional_works",I)})}),e.jsx(ie,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(ei,{items:t.indexed_by||[],onChange:I=>J("indexed_by",I)})}),e.jsx(ie,{title:d.section.emendatedBy,onSave:o,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(ti,{items:t.emendated_by||[],onChange:I=>J("emendated_by",I)})}),e.jsx(ie,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Ze,{items:t.resources||[],onChange:I=>J("resources",I),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(ie,{title:d.section.imageResources,onSave:o,children:e.jsx(Ze,{items:t.resources||[],onChange:I=>J("resources",I),onDownload:p,downloadStatuses:f,filterType:"image"})}),e.jsx(ie,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(pn,{items:xn(t.sources||""),onChange:I=>J("sources",un(I)),onOpenEntityPicker:G})}),(q||fe)&&e.jsx(ie,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(be,{value:t.provenance||"",onChange:I=>J("provenance",I),placeholder:d.editor.provenancePlaceholder})}),q&&e.jsx(ie,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(be,{value:t.otherEditions||"",onChange:I=>J("otherEditions",I),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(fn,{entityType:le,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:P}),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(hn,{isOpen:b,entityType:g,title:j,onSelect:Ye,onCancel:()=>S(!1),onCreate:()=>{S(!1),we(y,g)},searchResults:k,onSearch:$e,isLoading:T,excludeId:t.id}),e.jsx(bn,{isOpen:B,entityType:W,relationField:L,inheritData:O,onConfirm:Ke,onCancel:()=>F(!1)}),e.jsx(yn,{isOpen:R,title:d.action.selectBookOrWork,filterType:"all",recentEntities:re,excludeId:t.id,onSelect:Y,onCancel:()=>{V(!1),M(null)},onSearch:K})]})};function Qr({items:t,onChange:n}){const o=$(),r=(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(te,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(te,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(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:o.action.addAdditionalWork})]})}function jn({items:t,onChange:n,showMeta:o,addLabel:r}){const s=$(),[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&&o&&(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(te,{label:s.label.sourceName,value:f.source,onChange:d=>a(x,"source",d)}),e.jsx(te,{label:s.label.sourceBid,value:f.source_bid||"",onChange:d=>a(x,"source_bid",d)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(te,{label:s.label.titleInfo,value:f.title_info||"",onChange:d=>a(x,"title_info",d)}),e.jsx(te,{label:s.label.authorInfo,value:f.author_info||"",onChange:d=>a(x,"author_info",d)})]}),e.jsx(te,{label:s.label.edition,value:f.edition||"",onChange:d=>a(x,"edition",d)})]}),e.jsx(be,{value:f.summary||"",onChange:d=>a(x,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(be,{value:f.comment||"",onChange:d=>a(x,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(be,{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:r})]})}function ei({items:t,onChange:n}){const o=$();return e.jsx(jn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function ti({items:t,onChange:n}){const o=$();return e.jsx(jn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Sn(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)||"",o=((p=t.publication_info)==null?void 0:p.year)||"",r=((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:o,holder:r,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 ni(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 oi=t=>{const{data:n,id:o,transport:r,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;$();const[j,z]=u.useState(s),k=i?s:j;u.useEffect(()=>{s!==j&&z(s)},[s]);const m=u.useCallback(()=>{const L=k==="view"?"edit":"view";i?i(L):z(L)},[k,i]),[T,E]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(L=>{L&&E(L)})},[o,r]);const B=n||T,F=u.useMemo(()=>B?Sn(B):null,[B]),W=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,_=e.jsxs(e.Fragment,{children:[W,w]});return!B&&!F?e.jsx(me,{}):k==="view"?e.jsx(nt,{data:B,transport:r,onNavigate:p?L=>p(L):void 0,renderLink:f,headerExtra:_,className:y,style:v}):F?e.jsxs("div",{className:y,style:v,children:[_&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:_}),e.jsx(vn,{data:F,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:r,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:"无数据"})},Ft=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],kn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{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 o({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=Ft.find(g=>g.value===s);return e.jsx("div",{style:ri,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:ii,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:si,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:li,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:xi,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Ft.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...ai,...s===g.value?ci:{}},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:{...di,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:ui,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...pi,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},ii={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)"},si={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},li={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ai={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"},ci={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},di={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"},pi={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},xi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ui={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},fi=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...gi,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(kn,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},gi={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"},Mt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],hi=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,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||!r.trim())){l("submitting"),c("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(d){l("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&i!=="submitting",h=Mt.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Dt,children:e.jsxs("div",{style:ji,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Si,children:"继续提交"})]})}):e.jsxs("div",{style:Dt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Mt.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...bi,...n===d.value?mi:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:p,value:r,onChange:d=>s(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...yi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:f,disabled:!x,style:{...vi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:ki,children:a})]})},Dt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},bi={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"},mi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},yi={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"},vi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ji={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Si={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ki={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},wi=({style:t})=>{const n=u.useContext(Be);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",i=()=>r(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=U.BidLink;exports.BookIndexError=U.BookIndexError;exports.BookIndexManager=U.BookIndexManager;exports.BookIndexStorage=U.BookIndexStorage;exports.BundleStorage=U.BundleStorage;exports.ConfigError=U.ConfigError;exports.GithubStorage=U.GithubStorage;exports.IdGenerationError=U.IdGenerationError;exports.IdGenerator=U.IdGenerator;exports.LocalStorage=U.LocalStorage;exports.MigrationError=U.MigrationError;exports.StorageError=U.StorageError;exports.base36Decode=U.base36Decode;exports.base36Encode=U.base36Encode;exports.base58Decode=U.base58Decode;exports.buildId=U.buildId;exports.decodeId=U.decodeId;exports.decodeIdString=U.decodeIdString;exports.encodeId=U.encodeId;exports.extractIdFromUrl=U.extractIdFromUrl;exports.extractStatus=U.extractStatus;exports.extractType=U.extractType;exports.normalizeCatalog=U.normalizeCatalog;exports.parseId=U.parseId;exports.smartDecode=U.smartDecode;exports.validateResource=U.validateResource;exports.Badge=Oe;exports.BidUrlProvider=Ln;exports.CollatedEdition=cn;exports.CollectionCatalog=tn;exports.CreateEntityDialog=bn;exports.EmendatedBySection=Qt;exports.EntityDetail=Gt;exports.EntityPickerDialog=yn;exports.EntitySelector=hn;exports.FeedbackButton=fi;exports.FeedbackDialog=kn;exports.FeedbackForm=hi;exports.FeedbackList=dn;exports.FormInput=te;exports.FormTextArea=be;exports.HomePage=Qe;exports.IndexApp=jr;exports.IndexBrowser=Xe;exports.IndexDetail=nt;exports.IndexEditor=vn;exports.IndexView=oi;exports.LocaleContext=Be;exports.LocaleProvider=Hn;exports.LocaleToggle=wi;exports.ModeIndicator=Kt;exports.RelationPanel=fn;exports.ResourceEditor=Ze;exports.ResourceList=tt;exports.SearchInput=Yt;exports.Section=ie;exports.SmartBidInput=De;exports.SourceEditor=pn;exports.WorkCatalog=Sr;exports.detailToEditor=Sn;exports.editorToDetail=ni;exports.formatTemplate=We;exports.parseSourceString=xn;exports.stringifySources=un;exports.useBidUrl=oe;exports.useConvert=H;exports.useT=$;
|
|
1
|
+
"use strict";var wn=Object.create;var lt=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var _n=Object.getOwnPropertyNames;var zn=Object.getPrototypeOf,In=Object.prototype.hasOwnProperty;var Tn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of _n(n))!In.call(t,s)&&s!==o&<(t,s,{get:()=>n[s],enumerable:!(r=Cn(n,s))||r.enumerable});return t};var at=(t,n,o)=>(o=t!=null?wn(zn(t)):{},Tn(n||!t||!t.__esModule?lt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("./storage-entry-QB1IoDUU.cjs"),e=require("react/jsx-runtime"),u=require("react"),Rn=require("react-dom"),En=t=>`/book-index?id=${t}`,Ht=u.createContext(En);function Ln({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(Ht.Provider,{value:o,children:n})}function re(){return u.useContext(Ht)}function he(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Bn(t,n){return he(t).includes(n)}const Ot={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Wn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},$n={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Be=u.createContext(null),Ut={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:"目錄",collectionTab:"叢編",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:"圖片資源"}},Pn={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:"目录",collectionTab:"丛编",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:"图片资源"}},An={"zh-Hant":Ut,"zh-Hans":Pn},Vt="bim-locale";function Fn(){try{const t=localStorage.getItem(Vt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Mn(t){try{localStorage.setItem(Vt,t)}catch{}}const Dn="zh-Hant",Hn=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??Dn),i=t??r;u.useEffect(()=>{if(t)return;const f=Fn();f&&f!==r&&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),Mn(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:i,setLocale:c,messages:An[i],converter:l}),[i,c,l]);return e.jsx(Be.Provider,{value:p,children:o})};function P(){const t=u.useContext(Be);return(t==null?void 0:t.messages)??Ut}const On=2e3;function H(){const t=u.useContext(Be),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=u.useCallback(l=>{if(!l)return"";if(!o)return l;const a=r.current.get(l);if(a!==void 0)return a;const c=o(l);if(r.current.size>=On){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(l,c),c},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function We(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Un(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Vn(){return{id:"",name:"",url:"",type:"text",details:""}}const Ze=({items:t,onChange:n,onDownload:o,downloadStatuses:r,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=>{if(!s)return!0;const v=he(m);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((m,v)=>({item:m,originalIndex:v})).filter(({item:m})=>f(m)),h=()=>{const m=Vn();s&&(m.type=s),n([...t,m]),a(t.length)},d=m=>{n(t.filter((v,j)=>j!==m)),a(null)},b=(m,v,j)=>{const z=[...t];if(z[m]={...z[m],[v]:j},v==="url"&&!z[m].id){const w=Un(j);w&&(z[m].id=w)}n(z)},S=(m,v,j)=>{const w={...t[m].metadata||{}};j?w[v]=j:delete w[v],b(m,"metadata",Object.keys(w).length>0?w:void 0)},g=(m,v)=>{const j=v.trim()?v.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;b(m,"structure",j)},k=(m,v,j)=>{const w=t[m].coverage||{level:1,ranges:""};v==="level"?w.level=parseInt(j)||1:w.ranges=j,b(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:v})=>{var j,z,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===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:Nn(m.type??"text"),color:"#fff"},children:(()=>{var R,E;const y=he(m);return y.length===0?m.type??"text":y.length===1?((R=c.find(L=>L.value===y[0]))==null?void 0:R.label)??y[0]:y.includes("text")&&y.includes("image")?((E=c.find(L=>L.value==="text+image"))==null?void 0:E.label)??"text+image":y.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${v+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:y=>y.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Kn(v,r==null?void 0:r[v],o,i),e.jsx("button",{onClick:y=>{y.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:[Bn(m,"image")&&m.url&&Yn(m,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:m.type,onChange:y=>b(v,"type",y.target.value),style:{...de,flex:1},children:c.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value))})]}),e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:y=>b(v,"root_type",y.target.value),style:{...de,flex:1},children:p.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:y=>b(v,"id",y.target.value),placeholder:i.editor.idAutoExtract,style:{...de,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:y=>b(v,"name",y.target.value),placeholder:i.editor.resourceName,style:{...de,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:y=>b(v,"url",y.target.value),placeholder:i.editor.resourceUrl,style:de}),e.jsx("input",{type:"text",value:((j=m.structure)==null?void 0:j.join("、"))||"",onChange:y=>g(v,y.target.value),placeholder:i.editor.structurePlaceholder,style:de}),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:((z=m.coverage)==null?void 0:z.level)??"",onChange:y=>k(v,"level",y.target.value),placeholder:"1",style:{...de,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:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:y=>k(v,"ranges",y.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...de,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:y=>b(v,"details",y.target.value),placeholder:i.editor.detailsPlaceholder,style:{...de,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(([y,R])=>{var E;return e.jsxs("label",{style:{...Ce,gap:"4px"},children:[e.jsx("span",{style:{..._e,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[y])||"",onChange:L=>S(v,y,L.target.value),placeholder:R,style:{...de,flex:1}})]},y)})})]})]})]})]},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 Nn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Kn(t,n,o,r){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||o(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?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function Yn(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const de={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"},Gn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Jn(t){try{const n=new URL(t).hostname;return Gn[n]}catch{return}}const ct={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function qn(t){return t.includes("text")&&t.includes("image")?ct["text+image"]:ct[t[0]||"physical"]}const dt={text:0,image:1,physical:2};function Me(t){return t.length===0?"physical":[...t].sort((n,o)=>(dt[n]??99)-(dt[o]??99)).join("+")}function Zn(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},o=new Map,r=[],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(he(l))}`;o.has(f)||o.set(f,{base:{...l,name:c,url:"",volumes:[]},volumes:[]}),o.get(f).volumes.push({volume:p,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)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,r.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(he(t[l]))}`,p=`${i.base.name}|${Me(he(i.base))}`;c===p&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const tt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=P(),i=u.useMemo(()=>Zn(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(xt,{item:x},x.id||h))});const c=new Map;for(const x of i){const h=Me(he(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=qn(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(xt,{item:b,onNavigate:o,renderLink:r},b.id||S))})]},x)})})},pt=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},Nt=({value:t})=>{const o=P().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},Xn=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Nt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const s=String(n);return r?r(s):s};function Qn(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 eo(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function to(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const no={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},xt=({item:t,onNavigate:n,renderLink:o})=>{var S;const r=P(),{convert:s}=H(),i=re(),[l,a]=u.useState(!1),c=u.useMemo(()=>(t.url?Jn(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||to(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?{...no[t.color_mode],label:r.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:pt(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(Nt,{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,r.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=eo(t.metadata);return g?Qn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:r.action.visit}),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?"收起 ▲":"展开 ▼"})]}),pt(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:[r.metadata[g]||g,": ",Xn(g,k,r,s)]},g)),t.details&&!f&&e.jsx("span",{children:s(t.details)}),t.structure&&e.jsxs("span",{children:[r.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[r.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),f&&l&&(()=>{const g=p.some(v=>v.group),k=[];if(g){let v=null;for(const j of p){const z=j.group||"";(!v||v.title!==z)&&(v={title:z,group_id:j.group_id,vols:[]},k.push(v)),v.vols.push(j)}}else k.push({vols:p});const m=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:k.map((v,j)=>{const z=v.title?s(v.title):"";let w=z;return v.title&&v.group_id&&(o?w=o(v.group_id,z):n&&(w=e.jsx("a",{href:i(v.group_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.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:y=>y.currentTarget.style.borderBottomStyle="solid",onMouseLeave:y=>y.currentTarget.style.borderBottomStyle="dashed",children:z}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[w,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(m)})]},j)})})})()]})},Kt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,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 o==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,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:r,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:r,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",ut=10,ft=8;function Te(){try{const t=localStorage.getItem(Ue);return t?JSON.parse(t):[]}catch{return[]}}function oo(t){try{const n=Te().filter(o=>o!==t);n.unshift(t),n.length>ut&&(n.length=ut),localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function ro(t){try{const n=Te().filter(o=>o!==t);localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function io(){try{localStorage.removeItem(Ue)}catch{}}const Yt=({transport:t,value:n,onChange:o,onSearch:r,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),[k,m]=u.useState(Te),v=u.useRef(null),j=u.useRef(null),z=u.useRef(null),w=u.useRef(!1),y=u.useCallback(()=>{w.current||!t.getAllEntries||(w.current=!0,t.getAllEntries().then(C=>{g(C)}).catch(()=>{w.current=!1}))},[t]),R=u.useCallback(C=>{if(!C.trim())return k.map(W=>({type:"history",text:W}));if(!S)return[];const $=C.toLowerCase(),_=[],I=[];for(const W of S){if(_.length+I.length>=ft*2)break;const B=(W.title??"").toLowerCase();if(B.startsWith($))_.push({type:"entry",text:W.title,entry:W});else if(B.includes($))I.push({type:"entry",text:W.title,entry:W});else{const M=[...W.additional_titles||[],...W.attached_texts||[]];for(const Y of M){const Z=typeof Y=="string"?Y:Y==null?void 0:Y.book_title;if(Z!=null&&Z.toLowerCase().includes($)){_.push({type:"entry",text:`${W.title}`,entry:W});break}}}}return[..._,...I].slice(0,ft)},[S,k]);u.useEffect(()=>{h(R(n)),b(-1)},[n,R]),u.useEffect(()=>{const C=$=>{z.current&&!z.current.contains($.target)&&f(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),u.useEffect(()=>{const C=$=>{var _,I;if($.key==="/"&&document.activeElement!==v.current){const W=(_=document.activeElement)==null?void 0:_.tagName;if(W==="INPUT"||W==="TEXTAREA"||W==="SELECT")return;$.preventDefault(),(I=v.current)==null||I.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const E=u.useCallback(C=>{C.trim()&&(oo(C.trim()),m(Te())),r(C),f(!1)},[r]),L=u.useCallback(C=>{C.type==="history"?(o(C.text),E(C.text)):C.entry&&(s?(s(C.entry),f(!1)):(o(C.text),E(C.text)))},[o,E,s]),A=u.useCallback(C=>{if(!p||x.length===0){C.key==="Enter"&&E(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b($=>($+1)%x.length);break;case"ArrowUp":C.preventDefault(),b($=>($-1+x.length)%x.length);break;case"Enter":C.preventDefault(),d>=0&&d<x.length?L(x[d]):E(n);break;case"Escape":C.preventDefault(),f(!1);break}},[p,x,d,n,E,L]),O=u.useCallback((C,$)=>{$.stopPropagation(),ro(C),m(Te()),h(_=>_.filter(I=>!(I.type==="history"&&I.text===C)))},[]),K=u.useCallback(C=>{C.stopPropagation(),io(),m([]),h([])},[]);u.useEffect(()=>{if(d>=0&&j.current){const C=j.current.children;C[d]&&C[d].scrollIntoView({block:"nearest"})}},[d]);const V=!n.trim()&&k.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:a,value:n,onChange:C=>{o(C.target.value),f(!0),y()},onFocus:()=>{f(!0),y()},onKeyDown:A,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:[V&&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:K,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((C,$)=>e.jsxs("div",{onClick:()=>L(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:_=>O(C.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:"×"})]},`${C.type}-${C.text}-${$}`))]})]})},Le="bim-recent-ids",gt="bim-recent-entries",ht=50,Ge=5,so=50,lo=200;function Re(){try{const t=localStorage.getItem(Le);if(t)return JSON.parse(t);const n=localStorage.getItem(gt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Le,JSON.stringify(o)),localStorage.removeItem(gt),o}return[]}catch{return[]}}function ao(t){try{const n=Re().filter(o=>o!==t);n.unshift(t),n.length>ht&&(n.length=ht),localStorage.setItem(Le,JSON.stringify(n))}catch{}}function co(t){try{const n=Re().filter(o=>o!==t);localStorage.setItem(Le,JSON.stringify(n))}catch{}}function po(){try{localStorage.removeItem(Le)}catch{}}const xo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xe=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,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??""),[k,m]=u.useState(null),[v,j]=u.useState(null),[z,w]=u.useState(!1),[y,R]=u.useState(null),[E,L]=u.useState(""),[A,O]=u.useState(!f),[K,V]=u.useState(Re),[C,$]=u.useState([]),[_,I]=u.useState(!1),[W,B]=u.useState(!1),[M,Y]=u.useState(null),[Z,le]=u.useState(null),ge=u.useRef(void 0),fe=u.useRef(!1),X=u.useCallback(async(F,J)=>{if(!F.trim()){O(!0),m(null),j(null);return}O(!1),w(!0),L("");try{if(t.searchAll){const N=await t.searchAll(F,J??Ge);m(N)}else{const N=["work","book","collection","entity"],G=await Promise.all(N.map(Q=>t.search(F,Q,{page:1,pageSize:J??Ge})));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(N){L(N instanceof Error?N.message:String(N)),m(null)}finally{w(!1)}},[t]);u.useEffect(()=>{let F=!1;const J=()=>{var D,te;const N=["work","book","collection","entity"],G=Promise.all(N.map(ae=>t.loadEntries(ae,{page:1,pageSize:1}).catch(()=>({total:0})))),Q=((D=t.getResourceCounts)==null?void 0:D.call(t).catch(()=>null))??Promise.resolve(null),T=((te=t.getSubtypeStats)==null?void 0:te.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([G,Q,T]).then(([ae,ce,st])=>{F||(Y({works:ae[0].total,books:ae[1].total,collections:ae[2].total,entities:ae[3].total,hasText:ce==null?void 0:ce.hasText,hasImage:ce==null?void 0:ce.hasImage}),st&&le(st))})};return t.getCounts?t.getCounts().then(N=>{var G,Q;F||(Y({works:N.works,books:N.books,collections:N.collections,entities:N.entities,hasText:(G=N.resourceCounts)==null?void 0:G.hasText,hasImage:(Q=N.resourceCounts)==null?void 0:Q.hasImage}),N.subtypeStats&&le(N.subtypeStats))}).catch(()=>{F||J()}):J(),()=>{F=!0}},[t]),u.useEffect(()=>{fe.current||!(f!=null&&f.trim())||(fe.current=!0,X(f))},[f,X]);const q=u.useCallback(F=>{if(g(F),x==null||x(F),!F.trim()){O(!0),m(null),j(null);return}ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>{j(null),X(F)},lo)},[X,x]),Ve=u.useCallback(F=>{ge.current&&clearTimeout(ge.current),x==null||x(F),X(F)},[X,x]),Ne=u.useCallback(F=>{j(F),X(S,so)},[S,X]);u.useEffect(()=>{if(!K.length){$([]);return}let F=!1;return I(!0),Promise.all(K.slice(0,10).map(async J=>{var N,G,Q;try{if(t.getEntry){const D=await t.getEntry(J);if(D)return D}const T=await t.getItem(J);if(T){const D=T.authors;return{id:J,title:T.title||J,type:T.type||"work",author:(N=D==null?void 0:D[0])==null?void 0:N.name,dynasty:(G=D==null?void 0:D[0])==null?void 0:G.dynasty,role:(Q=D==null?void 0:D[0])==null?void 0:Q.role,edition:T.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{F||($(J),I(!1))}),()=>{F=!0}},[K,t]);const ke=F=>{R(F.id),ao(F.id),V(Re()),r==null||r(F)},we=F=>{co(F),V(Re())},Ke=()=>{po(),V([])},$e=F=>b.find(J=>J.type===F),Ye=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(Kt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Yt,{transport:t,value:S,onChange:q,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})]}),M&&A&&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:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()})," 本"]}),Z.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.article.toLocaleString()})," 篇"]}):null,Z.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()}),M.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:M.entities.toLocaleString()})]})]})}),M.hasImage!=null&&M.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.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}):E?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:E})]}):A?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}):C.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:C.slice(0,W?10:3).map(F=>F.notFound?e.jsx(uo,{id:F.id,onRemove:we,t:d},F.id):e.jsx(bt,{entry:F,selected:y===F.id,onClick:ke,getConfig:$e,onRemove:we},F.id))}),!W&&C.length>3&&e.jsx("button",{onClick:()=>B(!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:F,icon:J,name:N,key:G})=>{const Q=k[G]??[],T=xo[G],D=k[T]??0;if(Q.length===0)return null;const ae=!(v===F)&&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:[J," ",N,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[D," ",d.unit.items]})]}),ae&&e.jsx("button",{onClick:()=>Ne(F),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:Q.map(ce=>e.jsx(bt,{entry:ce,selected:y===ce.id,onClick:ke,getConfig:$e,query:S},ce.id))})]},F)})}):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:We(d.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},bt=({entry:t,selected:n,onClick:o,getConfig:r,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:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children: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:"→"})]})},uo=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function fo(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 go({data:t}){const{convert:n}=H(),{dynasty:o,birth_year:r,death_year:s}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?i.push(`${r}—${s}`):r!==void 0?i.push(`${r}—?`):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 ho({alt_names:t}){const{convert:n}=H(),o=new Map;for(const i of t){const l=i.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,l)=>{const a=r.indexOf(i),c=r.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=o.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 bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function mo({works:t,transport:n,onNavigate:o,renderLink:r}){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 z=0;z<d.length;z++){const w=v[z];w!=null&&w.title?S.set(d[z],w.title):w!=null&&w.primary_name?S.set(d[z],w.primary_name):j=!1}if(j)return S}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),j=new Map(v.map(w=>[w.id,w.title||w.primary_name||w.id]));let z=!0;for(const w of d){const y=j.get(w);y?S.set(w,y):z=!1}if(z)return S}catch{}const g=[...d],k=8,m=new Array(k).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!S.has(v))try{if(n.getEntry){const w=await n.getEntry(v);if(w!=null&&w.title){S.set(v,w.title);continue}}const j=await n.getItem(v),z=j&&(j.title||j.primary_name)||v;S.set(v,z)}catch{S.set(v,v)}}});return await Promise.all(m),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 r?e.jsx("li",{children:r(b.work_id,g)},S):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),o(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 Gt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var f;const i=P(),{convert:l}=H();let a=!1;try{a=U.extractStatus(t.id)==="draft"}catch{}const c=fo(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(go,{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(ho,{alt_names:t.alt_names}),e.jsx(bo,{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(mo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},yo=["〇","一","二","三","四","五","六","七","八","九"],mt=["","十","百","千"];function Jt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",s=!1;for(let i=0;i<o;i++){const l=parseInt(n[i]),a=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&a===1&&i===0?r+=mt[a]:r+=yo[l]+mt[a])}return r}function qt({type:t}){const n=P(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function vo({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 jo({id:t}){const n=P(),[o,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function oe({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 pe({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 Zt({authors:t,type:n,onNavigate:o,renderLink:r}){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(se,{id:i.entity_id,label:a,onNavigate:o,renderLink:r}):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 se({id:t,label:n,onNavigate:o,renderLink:r}){const s=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function So({id:t,title:n,edition:o,type:r,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,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),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(qt,{type:r}),e.jsx(vo,{isDraft:s}),e.jsx(jo,{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(Zt,{authors:i,type:r,onNavigate:p,renderLink:f}),a]})]})}function Xt({items:t,label:n,showMeta:o,onNavigate:r,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(oe,{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&&o&&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(se,{id:p.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(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(pe,{label:i.label.titleInfo,children:l(p.title_info)}),p.author_info&&e.jsx(pe,{label:i.label.authorInfo,children:l(p.author_info)}),p.edition&&e.jsx(pe,{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 ko({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(Xt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Qt({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(Xt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function en({label:t,items:n}){const{convert:o}=H();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const i=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},s)})})]}):null}function wo({items:t}){const n=P();return e.jsx(en,{label:n.section.aliases,items:t})}function Co({items:t}){const n=P();return e.jsx(en,{label:n.section.attachedTexts,items:t})}function _o({items:t}){const n=P(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,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:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function zo({items:t}){const n=P(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,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:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Io({items:t}){const n=P(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,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:"·"}),o(r)]},s))})]}):null}function yt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=H(),[l,a]=u.useState([]);return u.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>o.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,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(oe,{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(se,{id:c.id,label:p,onNavigate:r,renderLink:s})},c.id)})})]}):null}function To({book:t,onNavigate:n,renderLink:o}){const r=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(se,{id:t.id,label:c,onNavigate:n,renderLink:o})}),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?r.action.expand:r.action.collapse,children:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(tt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ro({ids:t,transport:n,onNavigate:o,renderLink:r}){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(oe,{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(To,{book:a,onNavigate:o,renderLink:r},a.id))})]}):null}function Eo({workData:t,onNavigate:n,renderLink:o}){var i,l,a;const r=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(qt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(se,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),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:[Jt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(Zt,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((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(pe,{label:r.label.parentWork,children:e.jsx(se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Lo({items:t,onNavigate:n,renderLink:o}){const r=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:r.indexType.collection}),e.jsx(se,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:o}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:We(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const nt=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,className:l,style:a})=>{var A,O,K,V,C,$;const c=P(),{convert:p}=H(),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState(null),[g,k]=u.useState(null),[m,v]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let _=!1;return d(!0),S(null),o.getItem(n).then(I=>{_||(I?x(I):S(c.misc.notFoundEntry))}).catch(I=>{_||S(I instanceof Error?I.message:c.misc.loadFailed)}).finally(()=>{_||d(!1)}),()=>{_=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){k(null),v([]);return}let _=!1;const I=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(I?o.getItem(I).then(W=>{!_&&W&&W.type==="work"&&k(W)}).catch(()=>{}):k(null),j.type==="book"){const W=j;W.contained_in&&W.contained_in.length>0?Promise.all(W.contained_in.map(B=>{const M=typeof B=="string"?B:B.id,Y=typeof B=="string"?void 0:B.volume_index;return o.getItem(M).then(Z=>({id:M,title:Z&&Z.title||M,volume_index:Y})).catch(()=>({id:M,title:M,volume_index:Y}))})).then(B=>{_||v(B)}):v([])}else v([]);return()=>{_=!0}},[j,o]),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((_,I)=>e.jsx("div",{style:{height:I===1?"32px":"16px",width:`${_}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},I))})});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(Gt,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const z=j.type==="book"?j:null,w=j.type==="collection"?j:null,y=j.type==="work"?j:null;let R=!1;try{R=U.extractStatus(j.id)==="draft"}catch{}let E="";j.measure_info?E=p(j.measure_info):(A=j.juan_count)!=null&&A.number?E=Jt(j.juan_count.number)+c.unit.juan:(O=j.juan_count)!=null&&O.description&&(E=p(j.juan_count.description));const L=[];return(K=j.publication_info)!=null&&K.year&&L.push(e.jsx(pe,{label:c.label.year,children:j.publication_info.year},"year")),(V=j.current_location)!=null&&V.name&&L.push(e.jsx(pe,{label:c.label.currentLocation,children:p(j.current_location.name)},"loc")),(C=j.page_count)!=null&&C.description&&L.push(e.jsx(pe,{label:c.label.pageCount,children:j.page_count.description},"page")),z!=null&&z.edition&&L.push(e.jsx(pe,{label:c.label.edition,children:p(z.edition)},"ver")),y!=null&&y.parent_work&&L.push(e.jsx(pe,{label:c.label.parentWork,children:e.jsx(se,{id:y.parent_work.id,label:p(y.parent_work.title),onNavigate:r,renderLink:s})},"pw")),y!=null&&y.parent_works&&y.parent_works.length>0&&!y.parent_work&&L.push(e.jsx(pe,{label:c.label.parentWork,children:y.parent_works.map((_,I)=>e.jsxs("span",{children:[I>0&&"、",e.jsx(se,{id:_,onNavigate:r,renderLink:s})]},_))},"pws")),e.jsxs("div",{className:l,style:a,children:[e.jsx(So,{id:j.id,title:p(j.title),edition:j.edition?p(j.edition):void 0,type:j.type,isDraft:R,authors:j.authors,volumeText:E,meta:L,headerExtra:i,onNavigate:r,renderLink:s}),(($=j.description)==null?void 0:$.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)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:c.section.containedIn}),e.jsx(Lo,{items:m,onNavigate:r,renderLink:s})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:c.section.belongsToWork}),e.jsx(Eo,{workData:g,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(_o,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(wo,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Co,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(ko,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Qt,{items:j.emendated_by,onNavigate:r,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:c.section.resources}),e.jsx(tt,{items:j.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(zo,{items:z.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&e.jsx(Io,{items:w.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(yt,{title:c.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:s}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(yt,{title:c.section.containedBooks,ids:w.books,transport:o,onNavigate:r,renderLink:s}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(oe,{children:[c.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",w.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.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(se,{id:_.id,label:p(_.title),onNavigate:r,renderLink:s})},_.id))})]}),(y==null?void 0:y.books)&&y.books.length>0&&e.jsx(Ro,{ids:y.books,transport:o,onNavigate:r,renderLink:s}),(y==null?void 0:y.related_works)&&y.related_works.length>0&&(()=>{const _=[],I=y.related_works.filter(M=>M.relation==="part_of"),W=y.related_works.filter(M=>M.relation==="has_part"),B=y.related_works.filter(M=>!M.relation);return I.length>0&&_.push({label:c.section.belongsToWork,items:I}),W.length>0&&_.push({label:c.section.containedWorks,items:W}),B.length>0&&_.push({label:c.section.relatedWorks,items:B}),_.map(M=>e.jsxs("div",{children:[e.jsxs(oe,{children:[M.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",M.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:M.items.map(Y=>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(se,{id:Y.id,label:p(Y.title),onNavigate:r,renderLink:s})},Y.id))})]},M.label))})()]})};function Bo({data:t}){const n=P(),{convert:o}=H(),{stats:r}=t,s=r.processed_volumes??r.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:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),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:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Wo({sections:t,activeSection:n,onSelect:o}){const r=P();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:vt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:vt(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 vt(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 $o({id:t,label:n,onNavigate:o,renderLink:r}){const s=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter: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 Po(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function jt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=P(),{convert:i}=H(),l=t.book_id||t.work_id,a=r&&t.volumes.length>0?Po(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:[r&&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($o,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const tn=({data:t,collectionId:n,transport:o,onNavigate:r,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,k]=u.useState(""),m=t||c;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let y=!1;return x(!0),d(null),o.getCollectionCatalog(n).then(R=>{y||(R?p(R):d(a.catalog.notFound))}).catch(R=>{y||d(R instanceof Error?R.message:a.catalog.loadFailed)}).finally(()=>{y||x(!1)}),()=>{y=!0}},[t,n,o,a]);const v=(m==null?void 0:m.sections)&&m.sections.length>0,j=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const y=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(y).size<y.length},[m]),z=u.useMemo(()=>{if(!m)return[];let y=m.books;if(b&&(y=y.filter(R=>R.section===b)),g.trim()){const R=g.trim().toLowerCase();y=y.filter(E=>E.title.toLowerCase().includes(R)||E.sub_items&&E.sub_items.some(L=>L.toLowerCase().includes(R))||E.edition&&E.edition.toLowerCase().includes(R))}return y},[m,b,g]),w=u.useMemo(()=>{if(!j)return null;const y=[],R=new Map;for(const L of z){if(!L.volumes||L.volumes.length===0)continue;const A=L.volumes[0];R.has(A)||R.set(A,[]),R.get(A).push(L)}const E=[...R.keys()].sort((L,A)=>L-A);for(const L of E)y.push({volume:L,books:R.get(L)});return y},[z,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}):m?e.jsxs("div",{className:i,style:l,children:[e.jsx(Bo,{data:m}),v&&e.jsx(Wo,{sections:m.sections,activeSection:b,onSelect:S}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:g,onChange:y=>k(y.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:[w?w.map((y,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:We(a.catalog.volume,{n:y.volume})}),y.books.map((E,L)=>e.jsx(jt,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${y.volume}-${L}`))]},`${y.volume}-${R}`)):z.map((y,R)=>e.jsx(jt,{book:y,onNavigate:r,renderLink:s,showVolumes:!0},R)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},me=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},ee=6,Pe=7,Ao=({content:t,children:n,placement:o="top",delayMs:r=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(),v=k.getBoundingClientRect(),j=window.innerHeight,z=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-v.height-Pe<8&&(w="bottom"),o==="bottom"&&m.bottom+v.height+Pe>j-8&&(w="top");const y=w==="top"?m.top-v.height-Pe:m.bottom+Pe;let R=m.left+m.width/2-v.width/2;R=Math.max(8,Math.min(R,z-v.width-8)),p({left:R,top:y,placement:w})},[o]),b=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(!0),r)},[r]),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&&Rn.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:-ee,width:0,height:0,...c.placement==="top"?{bottom:-ee,borderTop:`${ee}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ee}px solid transparent`,borderRight:`${ee}px solid transparent`}:{top:-ee,borderBottom:`${ee}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ee}px solid transparent`,borderRight:`${ee}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...c.placement==="top"?{bottom:-5,borderTop:`${ee-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ee-1}px solid transparent`,borderRight:`${ee-1}px solid transparent`}:{top:-5,borderBottom:`${ee-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ee-1}px solid transparent`,borderRight:`${ee-1}px solid transparent`}}})]})]}),document.body)]})},St={A:"fine",B:"rough",C:"rough",D:"ocr"};function Fo(t){return typeof t!="string"?null:t in Ot?t:t in St?St[t]:null}const Mo=["〇","一","二","三","四","五","六","七","八","九"],kt=["","十","百","千"],Do=["","萬","億"];function nn(t){if(t===0)return"〇";if(t<0)return`負${nn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Ho(s,r>0)+Do[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ho(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let i=0;i<o.length;i++){const l=o[i],a=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&a===1&&i===0&&!n?s+=kt[a]:s+=Mo[l]+kt[a]}return s.replace(/〇$/,"")}let Ee=null,Ae=null;const He=new Set;function Oo(){return Ee?Promise.resolve():Ae||(Ae=import("opencc-js/t2cn").then(t=>{Ee=t.Converter({from:"tw",to:"cn"}),He.forEach(n=>n())}).catch(()=>{Ee=t=>t,He.forEach(t=>t())}),Ae)}function ue(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Ee)return;const n=()=>t(o=>o+1);return He.add(n),Oo(),()=>{He.delete(n)}},[]),Ee??(n=>n)}function je(t,n){return n(t).toLowerCase()}const ot="#fff59d";function Se(t,n,o){if(!n)return t;const r=je(n,o);if(!r)return t;const s=je(t,o);if(s.length!==t.length)return t;const i=[];let l=0,a=0;for(;l<t.length;){const c=s.indexOf(r,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:ot,padding:0,color:"inherit"},children:t.slice(c,c+r.length)},a++)),l=c+r.length}return e.jsx(e.Fragment,{children:i})}function rt(t,n,o,r){if(!n)return!0;const s=je(n,r);return(o?[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,r).includes(s))}function Uo(t,n,o){return n?je(t,o).includes(je(n,o)):!0}const it={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Vo={考证:"#5d6d7e"};function No(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 on({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=No(t),p=!!(r!=null&&r.vol_label)&&!c.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(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?`${ot}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:["(",r.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 rn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>rn(r,n)))}function sn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+sn(i),0))||0;return n+o}function Ko(t,n){const o=[],r=l=>{var a;o.push(...l.files),(a=l.children)==null||a.forEach(r)};if(r(t),o.length===0)return;const s=o.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 ln({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=rn(t,n||""),a=Ko(t,i),c=typeof a=="number"&&a>0,p=a===0,[f,x]=u.useState(l||c),h=sn(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,k=i[S],m=k===0,v=k==="loading",j=typeof k=="number"&&k>0;return e.jsxs("button",{onClick:()=>{m||o(S)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*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)":j?`${ot}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,j&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:k}),v&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!f),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":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+r*16}px`},children:t.files.map(S=>e.jsx(on,{file:S,isActive:n===S,onSelect:o,meta:s==null?void 0:s[S],matchState:i[S]},S))}),d&&t.children.map((S,g)=>e.jsx(ln,{group:S,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function Yo({files:t,groups:n,activeFile:o,onSelect:r,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(ln,{group:a,activeFile:o,onSelect:r,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(on,{file:a,isActive:o===a,onSelect:r,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function Go({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 Jo({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=H(),s=re(),i=ue(),l=S=>{if(!S)return"";const g=r(S);return o?Se(g,o,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(()=>{o&&c(!0)},[o]);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:[nn(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 qo({section:t,highlightQuery:n=""}){const{convert:o}=H(),r=ue(),s=c=>{if(!c)return"";const p=o(c);return n?Se(p,n,r):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(Go,{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 Zo({section:t,highlightQuery:n=""}){const{convert:o}=H(),r=ue();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`)),i=n?Se(s,n,r):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 Xo(t,n,o){const[r,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=o==null?void 0:o.current)!=null&&x.has(f))}),a={};for(const f of t)(p=o==null?void 0:o.current)!=null&&p.has(f)&&(a[f]=o.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=o==null?void 0:o.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]),r}function Qo({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=H(),l=re(),a=ue(),c=m=>{if(!m)return"";const v=i(m);return s?Se(v,s,a):v},[p,f]=u.useState(!1);u.useEffect(()=>{s&&f(!0)},[s]);const x=t.type,h=Vo[x]||"#717171",d=!!t.content,b=t.work_ids||[],S=b.length>1,g=Xo(S?b:[],o,r),k=d&&!p&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>d&&f(!p),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!p&&k&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(k)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:l(b[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),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(m=>{const v=g[m],j=v?`${i(v.title)}${v.author?`(${i(v.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:l(m),onClick:z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),z.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",j]},m)})}),p&&d&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${h}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function er({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=H(),l=ue(),a=n.trim(),c=u.useMemo(()=>a?t.sections.filter(x=>rt(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(Qo,{section:x,onNavigate:o,transport:r,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 tr({text:t,highlightQuery:n=""}){const{convert:o}=H(),r=ue(),s=l=>{const a=o(l);return n?Se(a,n,r):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 nr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=H(),s=re(),i=ue(),l=p=>{if(!p)return"";const f=r(p);return o?Se(f,o,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:r(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 or({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=H(),i=ue(),[l,a]=u.useState("catalog"),c=o.trim(),p=u.useMemo(()=>c?t.sections.filter(d=>rt(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(tr,{text:n,highlightQuery:c}):e.jsx(nr,{sections:t.sections,onNavigate:r,highlightQuery:c})),l==="catalog"&&p.map((d,b)=>d.type==="书"||d.type==="詩"?e.jsx(Jo,{section:d,onNavigate:r,highlightQuery:c},b):d.type==="类"?e.jsx(qo,{section:d,highlightQuery:c},b):e.jsx(Zo,{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 an(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 wt(t){const n=an(t);return n.length>0?n[0]:null}function rr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:a,isKaozhen:c}=t,p=ue(),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 k of b.juan.sections)rt(k,S,c,p)&&g++;return g===0&&b.rawText&&Uo(b.rawText,S,p)&&(g=1),g},[c,p]);return u.useEffect(()=>{const b=a.trim();if(!b){h({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let S=!1;const g={},k=[];for(const w of r){const y=f.current.get(w);y?g[w]=d(y,b):(g[w]="loading",k.push(w))}h(g);const m=8;let v=0;const j=async()=>{var w;for(;v<k.length;){if(S)return;const y=v++,R=k[y];try{const[E,L]=await Promise.all([o.getCollatedJuan(n,R),((w=o.getCollatedJuanText)==null?void 0:w.call(o,n,R))??Promise.resolve(null)]),A={juan:E,rawText:L};if(f.current.set(R,A),S)return;h(O=>({...O,[R]:d(A,b)}))}catch{if(S)return;h(E=>({...E,[R]:0}))}}},z=Array.from({length:Math.min(m,k.length)},()=>j());return Promise.all(z),()=>{S=!0}},[a,n,o,r.join(","),d,p]),{matchStates:x}}const cn=({index:t,workId:n,transport:o,onNavigate:r,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,k]=u.useState(null),[m,v]=u.useState(!1),[j,z]=u.useState(null),[w,y]=u.useState(""),R=u.useRef(new Map),E=s??b,L=u.useCallback(_=>{S(_),i==null||i(_)},[i]),A=t||c;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let _=!1;return x(!0),d(null),o.getCollatedEditionIndex(n).then(I=>{if(!_)if(!I)d("未找到整理本数据");else{p(I);const W=wt(I);!s&&W&&L(W)}}).catch(I=>{_||d(I instanceof Error?I.message:"加载失败")}).finally(()=>{_||x(!1)}),()=>{_=!0}},[t,n,o,s,L]),u.useEffect(()=>{const _=t||c;if(_&&!E){const I=wt(_);I&&L(I)}},[t,c,E,L]);const O=n||(A==null?void 0:A.work_id),K=u.useCallback(async _=>{var I;if(!(!O||!(o!=null&&o.getCollatedJuan))){v(!0),k(null),z(null);try{const[W,B]=await Promise.all([o.getCollatedJuan(O,_),((I=o.getCollatedJuanText)==null?void 0:I.call(o,O,_))??Promise.resolve(null)]);k(W),z(B)}catch{k(null),z(null)}finally{v(!1)}}},[O,o]);u.useEffect(()=>{E&&K(E)},[E,K]);const V=_=>{L(_)};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(!A)return null;const C=A.type==="kaozhen",$=an(A);return e.jsx(ir,{className:l,style:a,index:A,allFiles:$,isKaozhen:C,effectiveWorkId:O,transport:o,activeFile:E,handleSelectFile:V,juanData:g,juanRawText:j,juanLoading:m,searchQuery:w,setSearchQuery:y,onNavigate:r,workLabelCacheRef:R})},ir=({className:t,style:n,index:o,allFiles:r,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}=rr({workId:i,transport:l,files:r,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:[o.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_juan})," 卷"]})}),o.text_quality&&(()=>{const k=Fo(o.text_quality.grade);return k?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Ao,{content:Wn[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:$n[k],cursor:"help"},children:Ot[k]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(Yo,{files:r,groups:o.juan_groups,activeFile:a,onSelect:c,juanMeta:o.juan_metadata,matchStates:g}),x?e.jsx(me,{}):p?s?e.jsx(er,{juan:p,searchQuery:h,onNavigate:b,transport:l,workLabelCache:S}):e.jsx(or,{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,o.references&&o.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:"參考文獻"}),o.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))]})]})},sr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},lr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function ar(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const dn=({items:t,loading:n})=>{const o=re();return n?e.jsx(me,{}):t.length===0?e.jsx("div",{style:cr,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=sr[r.type],i=lr[r.status];return e.jsxs("div",{style:dr,children:[e.jsxs("div",{style:pr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Ct,background:s.color},children:s.label}),e.jsx("span",{style:{...Ct,background:i.color},children:i.label})]}),e.jsx("span",{style:xr,children:ar(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:ur,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:_t,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:_t,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:fr,children:r.content}),r.reply&&e.jsxs("div",{style:gr,children:[e.jsx("div",{style:hr,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},cr={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},dr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},pr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ct={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},xr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ur={fontSize:"12px",marginBottom:"6px"},_t={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},fr={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},gr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},hr={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Qe=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,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),k=r??x,m=C=>{h(C),s==null||s(C)},[v,j]=u.useState(!0),[z,w]=u.useState(null),[y,R]=u.useState(null),[E,L]=u.useState(null);u.useEffect(()=>{let C=!1;const $=I=>{C||c(I)},_=()=>{t.getAllEntries&&t.getAllEntries().then(I=>{$({works:I.filter(W=>W.type==="work").length,books:I.filter(W=>W.type==="book").length,collections:I.filter(W=>W.type==="collection").length})}).catch(()=>{})};return t.getCounts?t.getCounts().then(I=>$({works:I.works,books:I.books,collections:I.collections})).catch(_):_(),()=>{C=!0}},[t]),u.useEffect(()=>{let C=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const _=await t.getRecommended();if(_!=null&&_.groups)return _.groups.flatMap(I=>I.items.map(W=>({...W,group:I.name})))}catch{}return[]})().then(async _=>{if(C)return;const I=_.filter(B=>B.id);if(I.length===0){j(!1);return}const W=await Promise.all(I.map(async B=>{if(B.type)return{id:B.id,title:B.title,type:B.type,author:B.author,dynasty:B.dynasty,role:B.role,edition:B.edition,has_text:B.has_text,has_image:B.has_image,has_collated:B.has_collated,subtype:B.subtype,primary_name:B.primary_name,group:B.group,fallbackDescription:B.description};try{let M=null;if(t.getEntry)M=await t.getEntry(B.id);else{const Y=await t.getItem(B.id);Y&&(M={id:B.id,title:Y.title||B.id,type:Y.type||"work"})}if(M)return{...M,group:B.group,fallbackDescription:B.description}}catch{}return{id:B.id,title:B.title,type:U.extractType(B.id),group:B.group,fallbackDescription:B.description}}));C||(f(W.filter(B=>B!==null)),j(!1))}),()=>{C=!0}},[t,o]);const A=u.useRef(!1),O=u.useRef(!1),K=u.useRef(!1);u.useEffect(()=>{if(k!=="catalog"||A.current)return;const C=t.getCatalogProgress??t.getResourceProgress;if(!C)return;A.current=!0;let $=!1;return C.call(t).then(_=>{$||w(_)}).catch(()=>{A.current=!1}),()=>{$=!0}},[t,k]),u.useEffect(()=>{if(k!=="collection"||O.current||!t.getCollectionProgress)return;O.current=!0;let C=!1;return t.getCollectionProgress().then($=>{C||R($)}).catch(()=>{O.current=!1}),()=>{C=!0}},[t,k]),u.useEffect(()=>{if(k!=="site"||K.current||!t.getSiteProgress)return;K.current=!0;let C=!1;return t.getSiteProgress().then($=>{C||L($)}).catch(()=>{K.current=!1}),()=>{C=!0}},[t,k]),u.useEffect(()=>{if(!i||k!=="feedback")return;let C=!1;return g(!0),fetch(i).then($=>$.json()).then($=>{!C&&$.success&&b($.items||[])}).catch(()=>{}).finally(()=>{C||g(!1)}),()=>{C=!0}},[i,k]);const V=C=>{switch(C){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(ze,{label:l.home.recommendTab,active:k==="recommend",onClick:()=>m("recommend")}),e.jsx(ze,{label:l.home.catalogTab,active:k==="catalog",onClick:()=>m("catalog")}),e.jsx(ze,{label:l.home.collectionTab,active:k==="collection",onClick:()=>m("collection")}),e.jsx(ze,{label:l.home.siteTab,active:k==="site",onClick:()=>m("site")}),i&&e.jsx(ze,{label:l.home.feedbackTab,active:k==="feedback",onClick:()=>m("feedback")})]}),k==="recommend"&&e.jsx(br,{recommended:p,loading:v,onNavigate:n,getIcon:V,t:l}),k==="catalog"&&e.jsx(zt,{progress:z,t:l,onNavigate:n}),k==="collection"&&e.jsx(zt,{progress:y,t:l,onNavigate:n}),k==="site"&&e.jsx(yr,{progress:E,t:l,totalWorks:(a==null?void 0:a.works)??0}),k==="feedback"&&i&&e.jsx(dn,{items:d,loading:S})]})})},ze=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),br=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=re();if(n)return e.jsx(me,{});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(),o==null||o(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:r(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))})},zt=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(me,{});const r=[...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=r.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(mr,{item:p,t:n,statusColor:l[a],onNavigate:o},p.id))})]},a)})})},mr=({item:t,t:n,statusColor:o,onNavigate:r})=>{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&&r?e.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(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?We(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:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},yr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(me,{});const r=[...t.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),i=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),a=o>0?Math.round(l/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",o.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(It,{item:c,t:n,totalWorks:o},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(It,{item:c,t:n,totalWorks:o},c.id))})]})]})},It=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Tt="(max-width: 768px)";function vr(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(Tt).matches);return u.useEffect(()=>{const o=window.matchMedia(Tt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const jr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var $;const i=P(),{convert:l}=H(),a=vr(),[c,p]=u.useState(null),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState("detail"),[g,k]=u.useState([]),[m,v]=u.useState(!1),[j,z]=u.useState(null),[w,y]=u.useState(!1),R=u.useCallback(async _=>{if(!t.getCollatedEditionIndex){z(null);return}y(!0);try{const I=await t.getCollatedEditionIndex(_);z(I)}catch{z(null)}finally{y(!1)}},[t]),E=u.useCallback(async _=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){k([]);return}v(!0);try{if(t.getCollectionCatalogs){const I=await t.getCollectionCatalogs(_);k(I||[])}else if(t.getCollectionCatalog){const I=await t.getCollectionCatalog(_);k(I?[{resource_id:"",data:I}]:[])}}catch{k([])}finally{v(!1)}},[t]),L=u.useCallback(async _=>{if(o){o(_);return}p(_),x(null),k([]),z(null),S("detail"),d(!0);try{const I=await t.getItem(_.id);I&&(x(I),I.type==="collection"?E(_.id):I.type==="work"&&I.has_collated&&R(_.id))}catch(I){console.error("加载详情失败:",I)}finally{d(!1)}},[t,o,E,R]),A=u.useCallback(async _=>{x(null),k([]),z(null),S("detail"),d(!0);try{const I=await t.getItem(_);I&&(x(I),p({id:_,title:I.title||_,type:I.type||"book"}),I.type==="collection"?E(_):I.type==="work"&&I.has_collated&&R(_))}catch(I){console.error("导航失败:",I)}finally{d(!1)}},[t,E,R]),O=(f==null?void 0:f.type)==="collection"&&(g.length>0||m)||(f==null?void 0:f.type)==="work"&&(j||w),K=a&&(h||f),V=u.useCallback(()=>{p(null),x(null),k([]),z(null),S("detail")},[]),C=e.jsx(e.Fragment,{children:h?e.jsx(me,{}):f?e.jsxs(e.Fragment,{children:[(O||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:[O&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>S("detail"),style:Fe(b==="detail"),children:i.detailTab.basicInfo}),f.type==="collection"&&m&&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(_=>e.jsx("button",{onClick:()=>S(`catalog:${_.resource_id}`),style:Fe(b===`catalog:${_.resource_id}`),children:_.short_name?`${l(_.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},_.resource_id)),f.type==="work"&&(j||w)&&e.jsxs("button",{onClick:()=>S("collated"),style:Fe(b==="collated"),children:[i.detailTab.collatedEdition,w&&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:A}):b.startsWith("catalog:")?e.jsx(tn,{data:($=g.find(_=>`catalog:${_.resource_id}`===b))==null?void 0:$.data,onNavigate:A}):b==="collated"?e.jsx(cn,{index:j||void 0,workId:f.id,transport:t,onNavigate:A}):null})]}):e.jsx(Qe,{transport:t,onNavigate:A,recommendedIds:r})});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:K?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:V,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:C})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Xe,{transport:t,onEntryClick:L,hideModeIndicator:n}),!f&&e.jsx(Qe,{transport:t,onNavigate:A,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Xe,{transport:t,onEntryClick:L,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:C})]})};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 Sr=({data:t,onNavigate:n,className:o,style:r})=>{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:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children: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(kr,{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))})]})},kr=({division:t,expanded:n,onToggle:o,expandedCat:r,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:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children: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(wr,{category:c,expanded:r===p,onToggle:()=>s(p),onNavigate:i},c.name)})})]})},wr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{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:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[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(Rt,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(Rt,{label:"存目",books:l,onNavigate:r})]})]})},Rt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=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&&o?e.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(c.title)}):r(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(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," 條"]})]})},ie=({title:t,onSave:n,onAskAI:o,extraButtons:r,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:[r,o&&e.jsx("button",{onClick:o,style:_r,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Cr,children:i.action.save})]})]}),s]})},Cr={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},_r={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ne=({label:t,value:n,onChange:o,placeholder:r,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=>o(i.target.value),placeholder:r,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"}})]}),be=({value:t,onChange:n,placeholder:o})=>{const r=u.useRef(null);return u.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Oe=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function zr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const De=({value:t,onChange:n,label:o})=>{const[r,s]=u.useState(!1),i=u.useRef(null),l=zr(t||"");return u.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Et,children:o}),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:Et,children:o}),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"}})]})},Et={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Ir(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Tr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const pn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=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"&&o&&o(b=>{const S=[...t];S[x]={...S[x],id:b.id,name:b.title,type:"bookID"},n(S)})},f=x=>{o&&o(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||`${r.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ir(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Tr(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:r.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:xe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Lt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>p(h,"url"),style:{...Lt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),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:xe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Bt,children:r.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:r.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:r.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:xe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Bt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>c(h,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.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:{...xe,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>c(h,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.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:xe,children:r.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:xe,children:r.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:r.action.addSource})]})]})},xe={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"},Lt={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"},Bt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function xn(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function un(t){return!t||t.length===0?"":JSON.stringify(t)}const fn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,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:Rr,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),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(Ie,{direction:"up",title:g.relation.parentWork,entity:r,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(Ie,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{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})]})]})]})},Ie=({direction:t,title:n,entity:o,onView:r,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})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:gn(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Wt,{onClick:()=>r(o),title:f,children:"👁️"}),e.jsx(Wt,{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:o,onView:r,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?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>r(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:gn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.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," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(et,{onClick:s,primary:!0,children:["+ ",i]})})]})},Wt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),et=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function gn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Rr={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"},hn=({isOpen:t,entityType:n,title:o,onSelect:r,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:Er,children:e.jsxs("div",{style:Lr,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:s,style:Br,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:Wr})}),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:()=>r(g),style:$r,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:Pr,children:["创建新",b,"并关联"]})]})]})})},Er={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},Lr={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)"},Br={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Wr={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"},$r={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)"},Pr={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},$t={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ar={work:"📜",book:"📖",collection:"📚",entity:"👤"},bn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,a]=u.useState(""),c=u.useRef(null);u.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,d;(h=c.current)==null||h.focus(),(d=c.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?f():h.key==="Escape"&&i()},f=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const x=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${$t[n]}`}};return e.jsx("div",{style:Fr,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Mr,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:Ar[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:`请输入${$t[n]}名称...`,style:Dr})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:Hr,children:"取消"}),e.jsx("button",{onClick:f,disabled:!l.trim(),style:{...Or,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Fr={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},Mr={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)"},Dr={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"},Hr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Or={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Ur(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function mn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Vr(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const yn=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],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),[k,m]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!x.trim()){b([]);return}const R=setTimeout(async()=>{g(!0);try{b(await f(x,o))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(R)},[x,o,f]);const v=u.useCallback(R=>{h(R.target.value),R.target.value.trim()&&m("search")},[]),j=u.useCallback(R=>s?R.filter(E=>E.id!==s):R,[s]);if(!t)return null;const z=n||(o==="all"?"选择实体":`选择${mn(o)}`),w=j(r),y=j(d);return e.jsx("div",{style:Kr,children:e.jsxs("div",{style:Yr,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:Gr,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:Jr}),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:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Pt,{active:k==="recent",onClick:()=>m("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(Pt,{active:k==="search",onClick:()=>m("search"),children:["搜索结果 ",y.length>0&&`(${y.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:k==="recent"&&w.length>0?e.jsx(At,{entities:w,onSelect:a}):x.trim()?S?e.jsx(qe,{message:"搜索中..."}):y.length>0?e.jsx(At,{entities:y,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:qr,children:l||"创建新实体"})]})]})})},Pt=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),At=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Nr,{entity:o,onClick:()=>n(o)},o.id))}),Nr=({entity:t,onClick:n})=>{const[o,r]=u.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Ur(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:Vr(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:mn(t.type)})]})},qe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Kr={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},Yr={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)"},Gr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Jr={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"},qr={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Zr={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Xr={work:"📜",collection:"📚",book:"📖",entity:"👤"},vn=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:a,renderSectionActions:c,onDownloadResource:p,downloadStatuses:f,relations:x,onRelationsChange:h})=>{var Q;const d=P(),[b,S]=u.useState(!1),[g,k]=u.useState("work"),[m,v]=u.useState(""),[j,z]=u.useState(""),[w,y]=u.useState([]),[R,E]=u.useState(!1),[L,A]=u.useState(!1),[O,K]=u.useState("work"),[V,C]=u.useState(""),[$,_]=u.useState(),[I,W]=u.useState(!1),[B,M]=u.useState(null),[Y,Z]=u.useState([]);u.useRef(null);const le=t.type,ge=le==="work",fe=le==="collection",X=le==="book",q=u.useCallback((T,D)=>{n({...t,[T]:D})},[t,n]),Ve=u.useCallback((T,D)=>{v(T),k(D),z(d.editor.selectToLink+d.indexType[D]),y([]),S(!0)},[d]),Ne=u.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),ke=u.useCallback(T=>{s==null||s(T.id,T.type)},[s]),we=u.useCallback((T,D,te)=>{const ae={...te,author:(te==null?void 0:te.author)||t.author,dynasty:(te==null?void 0:te.dynasty)||t.dynasty};K(D),C(T),_(ae),A(!0)},[t.author,t.dynasty]),Ke=u.useCallback((T,D)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,V,{type:O,title:T,inheritData:D}),A(!1)},[r,t.id,V,O]),$e=u.useCallback(T=>{if(!T.trim()){y([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(T,g).then(D=>{y(D),E(!1)}).catch(()=>{y([]),E(!1)})},[r,g]),Ye=u.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),S(!1)},[r,t.id,m]),F=u.useCallback(()=>{o()},[o]),J=u.useCallback(T=>{M(()=>T),W(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),N=u.useCallback((T,D)=>r!=null&&r.searchEntities?r.searchEntities(T,D==="all"?void 0:D):Promise.resolve([]),[r]),G=u.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Z(D=>[T,...D.filter(te=>te.id!==T.id)].slice(0,10)),B==null||B(T),W(!1),M(null)},[r,B]);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:Xr[le]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Oe,{children:t.id}),e.jsx(Oe,{color:Zr[le],children:d.indexType[le]})]})}),e.jsx(ie,{title:d.section.basicInfo,onSave:o,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:ge?d.editor.workTitle:fe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:T=>q("title",T)}),X&&e.jsx(De,{label:d.editor.belongsToWork,value:t.workName||"",onChange:T=>q("workName",T)}),e.jsx(ne,{label:d.editor.authorLabel,value:t.author||"",onChange:T=>q("author",T)}),e.jsx(ne,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>q("dynasty",T)}),(X||fe)&&e.jsx(De,{label:d.editor.containedIn,value:t.collection||"",onChange:T=>q("collection",T)}),(X||fe)&&e.jsx(ne,{label:d.editor.holderLabel,value:t.holder||"",onChange:T=>q("holder",T)}),(X||fe)&&e.jsx(ne,{label:X?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:T=>q("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ne,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>q("firstImage",T)})})]})}),e.jsx(ie,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(be,{value:t.description||"",onChange:T=>q("description",T),placeholder:d.editor.descriptionPlaceholder})}),(((Q=t.additional_works)==null?void 0:Q.length)||0)>0&&e.jsx(ie,{title:d.section.additionalWorks,onSave:o,children:e.jsx(Qr,{items:t.additional_works||[],onChange:T=>q("additional_works",T)})}),e.jsx(ie,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(ei,{items:t.indexed_by||[],onChange:T=>q("indexed_by",T)})}),e.jsx(ie,{title:d.section.emendatedBy,onSave:o,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(ti,{items:t.emendated_by||[],onChange:T=>q("emendated_by",T)})}),e.jsx(ie,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Ze,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(ie,{title:d.section.imageResources,onSave:o,children:e.jsx(Ze,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:p,downloadStatuses:f,filterType:"image"})}),e.jsx(ie,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(pn,{items:xn(t.sources||""),onChange:T=>q("sources",un(T)),onOpenEntityPicker:J})}),(X||fe)&&e.jsx(ie,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(be,{value:t.provenance||"",onChange:T=>q("provenance",T),placeholder:d.editor.provenancePlaceholder})}),X&&e.jsx(ie,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(be,{value:t.otherEditions||"",onChange:T=>q("otherEditions",T),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(fn,{entityType:le,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:F}),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(hn,{isOpen:b,entityType:g,title:j,onSelect:Ye,onCancel:()=>S(!1),onCreate:()=>{S(!1),we(m,g)},searchResults:w,onSearch:$e,isLoading:R,excludeId:t.id}),e.jsx(bn,{isOpen:L,entityType:O,relationField:V,inheritData:$,onConfirm:Ke,onCancel:()=>A(!1)}),e.jsx(yn,{isOpen:I,title:d.action.selectBookOrWork,filterType:"all",recentEntities:Y,excludeId:t.id,onSelect:G,onCancel:()=>{W(!1),M(null)},onSearch:N})]})};function Qr({items:t,onChange:n}){const o=P(),r=(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(ne,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ne,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(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:o.action.addAdditionalWork})]})}function jn({items:t,onChange:n,showMeta:o,addLabel:r}){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&&o&&(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(ne,{label:s.label.sourceName,value:f.source,onChange:d=>a(x,"source",d)}),e.jsx(ne,{label:s.label.sourceBid,value:f.source_bid||"",onChange:d=>a(x,"source_bid",d)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ne,{label:s.label.titleInfo,value:f.title_info||"",onChange:d=>a(x,"title_info",d)}),e.jsx(ne,{label:s.label.authorInfo,value:f.author_info||"",onChange:d=>a(x,"author_info",d)})]}),e.jsx(ne,{label:s.label.edition,value:f.edition||"",onChange:d=>a(x,"edition",d)})]}),e.jsx(be,{value:f.summary||"",onChange:d=>a(x,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(be,{value:f.comment||"",onChange:d=>a(x,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(be,{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:r})]})}function ei({items:t,onChange:n}){const o=P();return e.jsx(jn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function ti({items:t,onChange:n}){const o=P();return e.jsx(jn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Sn(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)||"",o=((p=t.publication_info)==null?void 0:p.year)||"",r=((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:o,holder:r,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 ni(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 oi=t=>{const{data:n,id:o,transport:r,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:k,className:m,style:v}=t;P();const[j,z]=u.useState(s),w=i?s:j;u.useEffect(()=>{s!==j&&z(s)},[s]);const y=u.useCallback(()=>{const V=w==="view"?"edit":"view";i?i(V):z(V)},[w,i]),[R,E]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(V=>{V&&E(V)})},[o,r]);const L=n||R,A=u.useMemo(()=>L?Sn(L):null,[L]),O=i||!n?e.jsx("button",{onClick:y,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,K=e.jsxs(e.Fragment,{children:[O,k]});return!L&&!A?e.jsx(me,{}):w==="view"?e.jsx(nt,{data:L,transport:r,onNavigate:p?V=>p(V):void 0,renderLink:f,headerExtra:K,className:m,style:v}):A?e.jsxs("div",{className:m,style:v,children:[K&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:K}),e.jsx(vn,{data:A,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:r,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:"无数据"})},Ft=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],kn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{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 o({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=Ft.find(g=>g.value===s);return e.jsx("div",{style:ri,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:ii,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:si,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:li,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:xi,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Ft.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...ai,...s===g.value?ci:{}},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:{...di,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:ui,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...pi,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},ii={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)"},si={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},li={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ai={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"},ci={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},di={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"},pi={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},xi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ui={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},fi=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...gi,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(kn,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},gi={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"},Mt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],hi=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,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||!r.trim())){l("submitting"),c("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(d){l("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&i!=="submitting",h=Mt.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Dt,children:e.jsxs("div",{style:ji,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Si,children:"继续提交"})]})}):e.jsxs("div",{style:Dt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Mt.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...bi,...n===d.value?mi:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:p,value:r,onChange:d=>s(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...yi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:f,disabled:!x,style:{...vi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:ki,children:a})]})},Dt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},bi={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"},mi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},yi={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"},vi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ji={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Si={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ki={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},wi=({style:t})=>{const n=u.useContext(Be);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",i=()=>r(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=U.BidLink;exports.BookIndexError=U.BookIndexError;exports.BookIndexManager=U.BookIndexManager;exports.BookIndexStorage=U.BookIndexStorage;exports.BundleStorage=U.BundleStorage;exports.ConfigError=U.ConfigError;exports.GithubStorage=U.GithubStorage;exports.IdGenerationError=U.IdGenerationError;exports.IdGenerator=U.IdGenerator;exports.LocalStorage=U.LocalStorage;exports.MigrationError=U.MigrationError;exports.StorageError=U.StorageError;exports.base36Decode=U.base36Decode;exports.base36Encode=U.base36Encode;exports.base58Decode=U.base58Decode;exports.buildId=U.buildId;exports.decodeId=U.decodeId;exports.decodeIdString=U.decodeIdString;exports.encodeId=U.encodeId;exports.extractIdFromUrl=U.extractIdFromUrl;exports.extractStatus=U.extractStatus;exports.extractType=U.extractType;exports.normalizeCatalog=U.normalizeCatalog;exports.parseId=U.parseId;exports.smartDecode=U.smartDecode;exports.validateResource=U.validateResource;exports.Badge=Oe;exports.BidUrlProvider=Ln;exports.CollatedEdition=cn;exports.CollectionCatalog=tn;exports.CreateEntityDialog=bn;exports.EmendatedBySection=Qt;exports.EntityDetail=Gt;exports.EntityPickerDialog=yn;exports.EntitySelector=hn;exports.FeedbackButton=fi;exports.FeedbackDialog=kn;exports.FeedbackForm=hi;exports.FeedbackList=dn;exports.FormInput=ne;exports.FormTextArea=be;exports.HomePage=Qe;exports.IndexApp=jr;exports.IndexBrowser=Xe;exports.IndexDetail=nt;exports.IndexEditor=vn;exports.IndexView=oi;exports.LocaleContext=Be;exports.LocaleProvider=Hn;exports.LocaleToggle=wi;exports.ModeIndicator=Kt;exports.RelationPanel=fn;exports.ResourceEditor=Ze;exports.ResourceList=tt;exports.SearchInput=Yt;exports.Section=ie;exports.SmartBidInput=De;exports.SourceEditor=pn;exports.WorkCatalog=Sr;exports.detailToEditor=Sn;exports.editorToDetail=ni;exports.formatTemplate=We;exports.parseSourceString=xn;exports.stringifySources=un;exports.useBidUrl=re;exports.useConvert=H;exports.useT=P;
|