book-index-ui 0.4.0 → 0.4.2
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 +4 -4
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1417 -1389
- package/dist/storage.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var _o=Object.create;var Kt=Object.defineProperty;var Co=Object.getOwnPropertyDescriptor;var Io=Object.getOwnPropertyNames;var zo=Object.getPrototypeOf,To=Object.prototype.hasOwnProperty;var Ro=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Io(n))!To.call(t,s)&&s!==o&&Kt(t,s,{get:()=>n[s],enumerable:!(r=Co(n,s))||r.enumerable});return t};var Oe=(t,n,o)=>(o=t!=null?_o(zo(t)):{},Ro(n||!t||!t.__esModule?Kt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("./storage-entry-DpzAR0M4.cjs"),e=require("react/jsx-runtime"),u=require("react"),Eo=require("react-markdown"),Lo=require("remark-gfm"),Bo=require("react-dom"),Wo=t=>`/book-index?id=${t}`,An=u.createContext(Wo);function $o({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(An.Provider,{value:o,children:n})}function ve(){return u.useContext(An)}function Ee(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Ao(t,n){return Ee(t).includes(n)}const Fn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Fo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Mo={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Ze=u.createContext(null),Mn={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:"圖片資源"}},Po={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:"图片资源"}},Ho={"zh-Hant":Mn,"zh-Hans":Po},Pn="bim-locale";function Oo(){try{const t=localStorage.getItem(Pn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Do(t){try{localStorage.setItem(Pn,t)}catch{}}const No="zh-Hans",Vo=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??No),i=t??r;u.useEffect(()=>{if(t)return;const x=Oo();x&&x!==r&&s(x)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(x=>{const f=x.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>x=>x)}):c(null)},[i]);const a=u.useCallback(x=>{s(x),Do(x),n==null||n(x)},[n]),d=u.useMemo(()=>({locale:i,setLocale:a,messages:Ho[i],converter:l}),[i,a,l]);return e.jsx(Ze.Provider,{value:d,children:o})};function M(){const t=u.useContext(Ze);return(t==null?void 0:t.messages)??Mn}const Uo=2e3;function O(){const t=u.useContext(Ze),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 c=r.current.get(l);if(c!==void 0)return c;const a=o(l);if(r.current.size>=Uo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Qe(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Go(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 Yo(){return{id:"",name:"",url:"",type:"text",details:""}}const bt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=M(),[l,c]=u.useState(null),a=[{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}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],x=m=>{if(!s)return!0;const S=Ee(m);return s==="text"?S.includes("text"):s==="image"?S.includes("image")||S.includes("physical"):s==="physical"?S.includes("physical"):S.includes(s)},f=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>x(m)),h=()=>{const m=Yo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((S,w)=>w!==m)),c(null)},b=(m,S,w)=>{const j=[...t];if(j[m]={...j[m],[S]:w},S==="url"&&!j[m].id){const _=Go(w);_&&(j[m].id=_)}n(j)},v=(m,S,w)=>{const _={...t[m].metadata||{}};w?_[S]=w:delete _[S],b(m,"metadata",Object.keys(_).length>0?_:void 0)},g=(m,S)=>{const w=S.trim()?S.split(/[,,、]/).map(j=>j.trim()).filter(Boolean):void 0;b(m,"structure",w)},y=(m,S,w)=>{const _=t[m].coverage||{level:1,ranges:""};S==="level"?_.level=parseInt(w)||1:_.ranges=w,b(m,"coverage",_.ranges?_:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:m,originalIndex:S})=>{var w,j,_;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Ko(m.type??"text"),color:"#fff"},children:(()=>{var I,E;const k=Ee(m);return k.length===0?m.type??"text":k.length===1?((I=a.find(z=>z.value===k[0]))==null?void 0:I.label)??k[0]:k.includes("text")&&k.includes("image")?((E=a.find(z=>z.value==="text+image"))==null?void 0:E.label)??"text+image":k.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:k=>k.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Jo(S,r==null?void 0:r[S],o,i),e.jsx("button",{onClick:k=>{k.stopPropagation(),p(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Ao(m,"image")&&m.url&&qo(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:De,children:[e.jsx("span",{style:Ne,children:i.label.type}),e.jsx("select",{value:m.type,onChange:k=>b(S,"type",k.target.value),style:{...ke,flex:1},children:a.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]}),e.jsxs("label",{style:De,children:[e.jsx("span",{style:Ne,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:k=>b(S,"root_type",k.target.value),style:{...ke,flex:1},children:d.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:k=>b(S,"id",k.target.value),placeholder:i.editor.idAutoExtract,style:{...ke,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:k=>b(S,"name",k.target.value),placeholder:i.editor.resourceName,style:{...ke,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:k=>b(S,"url",k.target.value),placeholder:i.editor.resourceUrl,style:ke}),e.jsx("input",{type:"text",value:((w=m.structure)==null?void 0:w.join("、"))||"",onChange:k=>g(S,k.target.value),placeholder:i.editor.structurePlaceholder,style:ke}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:De,children:[e.jsx("span",{style:Ne,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((j=m.coverage)==null?void 0:j.level)??"",onChange:k=>y(S,"level",k.target.value),placeholder:"1",style:{...ke,width:"60px"}})]}),e.jsxs("label",{style:{...De,flex:1},children:[e.jsx("span",{style:Ne,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((_=m.coverage)==null?void 0:_.ranges)||"",onChange:k=>y(S,"ranges",k.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...ke,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:k=>b(S,"details",k.target.value),placeholder:i.editor.detailsPlaceholder,style:{...ke,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(([k,I])=>{var E;return e.jsxs("label",{style:{...De,gap:"4px"},children:[e.jsx("span",{style:{...Ne,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[k])||"",onChange:z=>v(S,k,z.target.value),placeholder:I,style:{...ke,flex:1}})]},k)})})]})]})]})]},S)}),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 Ko(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Jo(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 qo(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 ke={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"},De={display:"flex",alignItems:"center",gap:"6px"},Ne={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Xo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Zo(t){try{const n=new URL(t).hostname;return Xo[n]}catch{return}}const Jt={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function Qo(t){return t.includes("text")&&t.includes("image")?Jt["text+image"]:Jt[t[0]||"physical"]}const qt={text:0,image:1,physical:2};function rt(t){return t.length===0?"physical":[...t].sort((n,o)=>(qt[n]??99)-(qt[o]??99)).join("+")}function er(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[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 c=n(l.name);if(!c)continue;const[a,d]=c,x=`${a}|${rt(Ee(l))}`;o.has(x)||o.set(x,{base:{...l,name:a,url:"",volumes:[]},volumes:[]}),o.get(x).volumes.push({volume:d,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,c)=>l.volume-c.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 c=n(t[l].name),a=c&&`${c[0]}|${rt(Ee(t[l]))}`,d=`${i.base.name}|${rt(Ee(i.base))}`;a===d&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const St=({items:t,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const i=M(),{convert:l}=O(),c=u.useMemo(()=>er(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.useMemo(()=>{const g=new Map,y=[];for(const m of c){const S=m.group;S?(g.has(S)||g.set(S,[]),g.get(S).push(m)):y.push(m)}for(const m of g.values())m.sort((S,w)=>{const j=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return j(S)-j(w)});return{mirrorGroups:g,ungroupedItems:y}},[c]),x={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical},f=g=>x[g]?x[g]:g.split("+").map(y=>x[y]||y).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((g,y)=>e.jsx(pt,{item:g},g.id||y))});const h=(g,y)=>{const m=o==null?void 0:o[g],S=(m==null?void 0:m.label)||g,w=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(S)}),w&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(w)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((j,_)=>e.jsx(pt,{item:j,onNavigate:r,renderLink:s},j.id||_))})]},`group-${g}`)},p=new Map;for(const g of d){const y=rt(Ee(g));p.has(y)||p.set(y,[]),p.get(y).push(g)}const b=["text","image","text+image","physical"],v=[...b.filter(g=>p.has(g)),...[...p.keys()].filter(g=>!b.includes(g)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([g,y])=>h(g,y)),v.map(g=>{const y=p.get(g),m=Qo(g.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:f(g)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((S,w)=>e.jsx(pt,{item:S,onNavigate:r,renderLink:s},S.id||w))})]},g)})]})};function tr(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 nr(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 or(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 rr={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},pt=({item:t})=>{const n=M(),{convert:o}=O(),[r,s]=u.useState(!1),i=u.useMemo(()=>(t.url?Zo(t.url):void 0)||o(t.name),[t.url,t.name,o]),l=u.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||or(b)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,x=t.expected_volumes??(c?a+d:0),f=t.color_mode?{...rr[t.color_mode],label:n.colorMode[t.color_mode]}:null,h=t.details&&!c?o(t.details):null,p={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),h&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:h}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",x,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=nr(t.metadata);return b?tr(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const v=b.status==="missing";return b.url&&!v?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:v?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1},children:b.volume},b.volume)})})]})},Hn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const c=M(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,x=(n==null?void 0:n.repoPath)||"",f=x?x.split(/[/\\]/).pop()||x:"",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)"},p={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):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:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:f||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:x?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:x,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},ct="bim-search-history",Xt=10,Zt=8;function Ke(){try{const t=localStorage.getItem(ct);return t?JSON.parse(t):[]}catch{return[]}}function ir(t){try{const n=Ke().filter(o=>o!==t);n.unshift(t),n.length>Xt&&(n.length=Xt),localStorage.setItem(ct,JSON.stringify(n))}catch{}}function sr(t){try{const n=Ke().filter(o=>o!==t);localStorage.setItem(ct,JSON.stringify(n))}catch{}}function lr(){try{localStorage.removeItem(ct)}catch{}}const On=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=M(),c=i??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,x]=u.useState(!1),[f,h]=u.useState([]),[p,b]=u.useState(-1),[v,g]=u.useState(Ke),y=u.useRef(null),m=u.useRef(null),S=u.useRef(null),w=u.useRef(!1);u.useEffect(()=>{b(-1);const C=n.trim();if(!C){h(v.map(W=>({type:"history",text:W})));return}if(!t.searchAll){h([]);return}let B=!1;const P=setTimeout(()=>{t.searchAll(C,Zt).then(W=>{if(B)return;const F=[...W.works,...W.books,...W.collections,...W.entities??[]];h(F.slice(0,Zt).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{B||h([])})},80);return()=>{B=!0,clearTimeout(P)}},[n,v,t]),u.useEffect(()=>{const C=B=>{S.current&&!S.current.contains(B.target)&&x(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),u.useEffect(()=>{const C=B=>{var P,W;if(B.key==="/"&&document.activeElement!==y.current){const F=(P=document.activeElement)==null?void 0:P.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;B.preventDefault(),(W=y.current)==null||W.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const j=u.useCallback(C=>{C.trim()&&(ir(C.trim()),g(Ke())),r(C),x(!1)},[r]),_=u.useCallback(C=>{C.type==="history"?(o(C.text),j(C.text)):C.entry&&(s?(s(C.entry),x(!1)):(o(C.text),j(C.text)))},[o,j,s]),k=u.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&j(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(B=>(B+1)%f.length);break;case"ArrowUp":C.preventDefault(),b(B=>(B-1+f.length)%f.length);break;case"Enter":C.preventDefault(),p>=0&&p<f.length?_(f[p]):j(n);break;case"Escape":C.preventDefault(),x(!1);break}},[d,f,p,n,j,_]),I=u.useCallback((C,B)=>{B.stopPropagation(),sr(C),g(Ke()),h(P=>P.filter(W=>!(W.type==="history"&&W.text===C)))},[]),E=u.useCallback(C=>{C.stopPropagation(),lr(),g([]),h([])},[]);u.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const z=!n.trim()&&v.length>0;return e.jsxs("div",{ref:S,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:y,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),x(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{x(!0)},onKeyDown:k,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"}}),d&&f.length>0&&e.jsxs("div",{ref:m,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:[z&&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:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((C,B)=>e.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===p?"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:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:P=>I(C.text,P),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}-${B}`))]})]})},Xe="bim-recent-ids",Qt="bim-recent-entries",en=50,xt=5,ar=50,cr=200;function Je(){try{const t=localStorage.getItem(Xe);if(t)return JSON.parse(t);const n=localStorage.getItem(Qt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Xe,JSON.stringify(o)),localStorage.removeItem(Qt),o}return[]}catch{return[]}}function dr(t){try{const n=Je().filter(o=>o!==t);n.unshift(t),n.length>en&&(n.length=en),localStorage.setItem(Xe,JSON.stringify(n))}catch{}}function pr(t){try{const n=Je().filter(o=>o!==t);localStorage.setItem(Xe,JSON.stringify(n))}catch{}}function xr(){try{localStorage.removeItem(Xe)}catch{}}const ur={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},mt=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,initialQuery:x,onQueryChange:f,headerRight:h})=>{const p=M(),b=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:p.indexType.entity,key:"entities"}],[v,g]=u.useState(x??""),[y,m]=u.useState(null),[S,w]=u.useState(null),[j,_]=u.useState(!1),[k,I]=u.useState(null),[E,z]=u.useState(""),[C,B]=u.useState(!x),[P,W]=u.useState(Je),[F,D]=u.useState([]),[L,T]=u.useState(!1),[H,$]=u.useState(!1),[N,K]=u.useState(null),[te,se]=u.useState(null),fe=u.useRef(void 0),be=u.useRef(!1),ne=u.useCallback(async(A,ee)=>{if(!A.trim()){B(!0),m(null),w(null);return}B(!1),_(!0),z("");try{if(t.searchAll){const J=await t.searchAll(A,ee??xt);m(J)}else{const J=["work","book","collection","entity"],X=await Promise.all(J.map(re=>t.search(A,re,{page:1,pageSize:ee??xt})));m({works:X[0].entries,books:X[1].entries,collections:X[2].entries,entities:X[3].entries,totalWorks:X[0].total,totalBooks:X[1].total,totalCollections:X[2].total,totalEntities:X[3].total})}}catch(J){z(J instanceof Error?J.message:String(J)),m(null)}finally{_(!1)}},[t]);u.useEffect(()=>{let A=!1;const ee=()=>{var V,le;const J=["work","book","collection","entity"],X=Promise.all(J.map(xe=>t.loadEntries(xe,{page:1,pageSize:1}).catch(()=>({total:0})))),re=((V=t.getResourceCounts)==null?void 0:V.call(t).catch(()=>null))??Promise.resolve(null),R=((le=t.getSubtypeStats)==null?void 0:le.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([X,re,R]).then(([xe,Z,Se])=>{A||(K({works:xe[0].total,books:xe[1].total,collections:xe[2].total,entities:xe[3].total,hasText:Z==null?void 0:Z.hasText,hasImage:Z==null?void 0:Z.hasImage}),Se&&se(Se))})};return t.getCounts?t.getCounts().then(J=>{var X,re;A||(K({works:J.works,books:J.books,collections:J.collections,entities:J.entities,hasText:(X=J.resourceCounts)==null?void 0:X.hasText,hasImage:(re=J.resourceCounts)==null?void 0:re.hasImage}),J.subtypeStats&&se(J.subtypeStats))}).catch(()=>{A||ee()}):ee(),()=>{A=!0}},[t]),u.useEffect(()=>{be.current||!(x!=null&&x.trim())||(be.current=!0,ne(x))},[x,ne]);const Q=u.useCallback(A=>{if(g(A),!A.trim()){f==null||f(A),B(!0),m(null),w(null);return}fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{w(null),f==null||f(A),ne(A)},cr)},[ne,f]),Te=u.useCallback(A=>{fe.current&&clearTimeout(fe.current),f==null||f(A),ne(A)},[ne,f]),We=u.useCallback(A=>{w(A),ne(v,ar)},[v,ne]);u.useEffect(()=>{if(!P.length){D([]);return}let A=!1;return T(!0),Promise.all(P.slice(0,10).map(async ee=>{var J,X,re;try{if(t.getEntry){const V=await t.getEntry(ee);if(V)return V}const R=await t.getItem(ee);if(R){const V=R.authors;return{id:ee,title:R.title||ee,type:R.type||"work",author:(J=V==null?void 0:V[0])==null?void 0:J.name,dynasty:(X=V==null?void 0:V[0])==null?void 0:X.dynasty,role:(re=V==null?void 0:V[0])==null?void 0:re.role,edition:R.edition||void 0}}}catch{}return{id:ee,title:ee,type:"work",notFound:!0}})).then(ee=>{A||(D(ee),T(!1))}),()=>{A=!0}},[P,t]);const Ie=A=>{I(A.id),dr(A.id),W(Je()),r==null||r(A)},pe=A=>{pr(A),W(Je())},je=()=>{xr(),W([])},ze=A=>b.find(ee=>ee.type===A),$e=y&&(y.works.length>0||y.books.length>0||y.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:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&e.jsx(Hn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(On,{transport:t,value:v,onChange:Q,onSearch:Te,onEntrySelect:Ie}),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:p.action.newEntry})]}),N&&C&&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:te?e.jsxs(e.Fragment,{children:[(te.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:te.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.books.toLocaleString()})," 本"]}),te.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:te.article.toLocaleString()})," 篇"]}):null,te.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:te.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.collections.toLocaleString()}),N.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.entities.toLocaleString()})]})]})}),N.hasImage!=null&&N.hasText!=null&&e.jsxs("span",{children:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:N.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:j?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.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})]}):C?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.loading}):F.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:p.search.recentBrowse}),e.jsx("button",{onClick:je,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:p.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:F.slice(0,H?10:3).map(A=>A.notFound?e.jsx(fr,{id:A.id,onRemove:pe,t:p},A.id):e.jsx(tn,{entry:A,selected:k===A.id,onClick:Ie,getConfig:ze,onRemove:pe},A.id))}),!H&&F.length>3&&e.jsx("button",{onClick:()=>$(!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:p.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:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):$e?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:A,icon:ee,name:J,key:X})=>{const re=y[X]??[],R=ur[X],V=y[R]??0;if(re.length===0)return null;const xe=!(S===A)&&V>xt;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:[ee," ",J,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[V," ",p.unit.items]})]}),xe&&e.jsx("button",{onClick:()=>We(A),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:re.map(Z=>e.jsx(tn,{entry:Z,selected:k===Z.id,onClick:Ie,getConfig:ze,query:v},Z.id))})]},A)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Qe(p.search.noResultsFor,{query:v})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},tn=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=M(),{convert:c}=O(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(x=>{const f=typeof x=="string"?x:x==null?void 0:x.book_title;return f==null?void 0:f.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:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title: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:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,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:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:x=>{x.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:"→"})]})},fr=({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 gr(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 hr({data:t}){const{convert:n}=O(),{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 br({alt_names:t}){const{convert:n}=O(),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 c=r.indexOf(i),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children: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((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},i)})})}function mr({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 yr({works:t,transport:n,onNavigate:o,renderLink:r}){const s=M(),{convert:i}=O(),l=ve(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const p=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const S=await n.getEntriesByIds(p);let w=!0;for(let j=0;j<p.length;j++){const _=S[j];_!=null&&_.title?v.set(p[j],_.title):_!=null&&_.primary_name?v.set(p[j],_.primary_name):w=!1}if(w)return v}catch{}const g=[...p],y=8,m=new Array(y).fill(0).map(async()=>{for(;g.length;){const S=g.shift();if(!S)break;if(!v.has(S))try{if(n.getEntry){const _=await n.getEntry(S);if(_!=null&&_.title){v.set(S,_.title);continue}}const w=await n.getItem(S),j=w&&(w.title||w.primary_name)||S;v.set(S,j)}catch{v.set(S,S)}}});return await Promise.all(m),v})().then(v=>{h||a(v)}),()=>{h=!0}},[t,n]);const d=new Map;for(const h of t){const p=h.role||"";d.has(p)||d.set(p,[]),d.get(p).push(h)}const x=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((h,p)=>{const b=x.indexOf(h),v=x.indexOf(p);return b===-1&&v===-1?h.localeCompare(p):b===-1?1:v===-1?-1:b-v});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),f.map(h=>{const p=d.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:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((b,v)=>{const g=i(c.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,g)},v):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},v):e.jsx("li",{children:g},v)})})]},h)})]})}const Dn=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var x;const i=M(),{convert:l}=O();let c=!1;try{c=Y.extractStatus(t.id)==="draft"}catch{}const a=gr(t),d=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(hr,{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}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&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})]}),a&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(br,{alt_names:t.alt_names}),e.jsx(mr,{data:t}),((x=t.description)==null?void 0:x.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(yr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},Nn={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},vr={...Nn,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},yt=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=O(),i=n?vr:Nn;return e.jsx("div",{className:r,style:o,children:e.jsx(Eo,{remarkPlugins:[Lo],components:i,children:s(t)})})},jr=["〇","一","二","三","四","五","六","七","八","九"],nn=["","十","百","千"];function Vn(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]),c=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&i===0?r+=nn[c]:r+=jr[l]+nn[c])}return r}function Sr({type:t}){const n=M(),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 kr({isDraft:t}){const n=M();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 wr({id:t}){const n=M(),[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 he({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 we({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 Un({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=O();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const c=s(i.name),a=i.entity_id?e.jsx(ye,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});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),"〕"]}),a,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},l)})})}function ye({id:t,label:n,onNavigate:o,renderLink:r}){const s=ve();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 _r({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:x}){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})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Sr,{type:r}),e.jsx(kr,{isDraft:s}),e.jsx(wr,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(Un,{authors:i,type:r,onNavigate:d,renderLink:x}),c]})]})}function Gn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=M(),{convert:l}=O();if(!t.length)return null;const[c,a]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(he,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,x)=>{const f=c===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?null:x),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:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!f&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ye,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),f&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(we,{label:i.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(we,{label:i.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(we,{label:i.label.edition,children:l(d.edition)})]}),d.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(d.summary)})]}),d.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(d.comment)})]}),d.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(d.additional_comment)})]})]})]},x)})})]})}function Cr({items:t,onNavigate:n,renderLink:o}){const r=M();return e.jsx(Gn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function kt({items:t,onNavigate:n,renderLink:o}){const r=M();return e.jsx(Gn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Yn({label:t,items:n}){const{convert:o}=O();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(he,{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 Ir({items:t}){const n=M();return e.jsx(Yn,{label:n.section.aliases,items:t})}function zr({items:t}){const n=M();return e.jsx(Yn,{label:n.section.attachedTexts,items:t})}function Tr({items:t}){const n=M(),{convert:o}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(he,{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 Rr({items:t}){const n=M(),{convert:o}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(he,{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 Er({items:t}){const n=M(),{convert:o}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(he,{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 on({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=O(),[l,c]=u.useState([]);return u.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.getItem(d).then(x=>({id:d,title:x?x.title:void 0,edition:x?x.edition:void 0,type:x?x.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(he,{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(a=>({id:a}))).map(a=>{const d=a.edition?`${i(a.title)||a.id}(${i(a.edition)})`:i(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ye,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function ut({book:t,onNavigate:n,renderLink:o}){const r=M(),{convert:s}=O(),[i,l]=u.useState(!1),c=t.resources&&t.resources.length>0,a=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:"6px 12px",borderBottom:c&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(ye,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),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:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(St,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Lr({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const l=M(),{convert:c}=O(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(v=>({id:v})));return}let b=!1;return Promise.all(t.map(v=>o.getItem(v).then(g=>({id:v,title:g?g.title:void 0,edition:g?g.edition:void 0,resources:g?g.resources:void 0,resource_groups:g?g.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{b||d(v)}),()=>{b=!0}},[t,o]),!t.length)return null;const x=a.length?a:t.map(b=>({id:b})),f=new Map(x.map(b=>[b.id,b])),h=n==null?void 0:n.version_graph,p=Br(t,h);return e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(b=>{const v=f.get(b);return v?e.jsx(ut,{book:v,onNavigate:r,renderLink:s},b):null})}),p.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(v=>{const g=f.get(v);return g?e.jsx(ut,{book:g,onNavigate:r,renderLink:s},v):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.map(b=>e.jsx(ut,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Br(t,n){var g,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(g=n.collections)==null?void 0:g[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,l=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=m=>{if(a.has(m))return!0;const S=n.node_groups[m];return S!=null&&c.has(S)},x=[],f=new Map,h=[];for(const m of t)if(!((y=n.excluded_books)!=null&&y.includes(m)))if(d(m))x.push(m);else{const S=n.node_groups[m];S?(f.has(S)||f.set(S,[]),f.get(S).push(m)):h.push(m)}if(h.length+[...f.values()].reduce((m,S)=>m+S.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),v=[...f.entries()].map(([m,S])=>{const w=b.get(m);return{id:m,label:(w==null?void 0:w.label)??m,description:w==null?void 0:w.description,ids:S}});return h.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:x,groupedIds:v}}function Wr({workData:t,onNavigate:n,renderLink:o}){var l,c,a,d;const r=M(),{convert:s}=O(),i=!!((l=t.description)!=null&&l.text)||!!t.parent_work;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:"6px 14px",borderBottom:i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ye,{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)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Vn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Un,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(yt,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(we,{label:r.label.parentWork,children:e.jsx(ye,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function $r({items:t,onNavigate:n,renderLink:o}){const r=M(),{convert:s}=O();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(ye,{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:Qe(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const dt=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:l,className:c,style:a})=>{var B,P,W,F,D,L;const d=M(),{convert:x}=O(),[f,h]=u.useState(null),[p,b]=u.useState(!1),[v,g]=u.useState(null),[y,m]=u.useState(null),[S,w]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let T=!1;return b(!0),g(null),o.getItem(n).then(H=>{T||(H?h(H):g(d.misc.notFoundEntry))}).catch(H=>{T||g(H instanceof Error?H.message:d.misc.loadFailed)}).finally(()=>{T||b(!1)}),()=>{T=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){m(null),w([]);return}let T=!1;const H=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(H?o.getItem(H).then($=>{!T&&$&&$.type==="work"&&m($)}).catch(()=>{}):m(null),j.type==="book"){const $=j;$.contained_in&&$.contained_in.length>0?Promise.all($.contained_in.map(N=>{const K=typeof N=="string"?N:N.id,te=typeof N=="string"?void 0:N.volume_index;return o.getItem(K).then(se=>({id:K,title:se&&se.title||K,volume_index:te})).catch(()=>({id:K,title:K,volume_index:te}))})).then(N=>{T||w(N)}):w([])}else w([]);return()=>{T=!0}},[j,o]),p)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((T,H)=>e.jsx("div",{style:{height:H===1?"32px":"16px",width:`${T}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},H))})});if(v)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!j)return null;if(j.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Dn,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const _=j.type==="book"?j:null,k=j.type==="collection"?j:null,I=j.type==="work"?j:null;let E=!1;try{E=Y.extractStatus(j.id)==="draft"}catch{}let z="";j.measure_info?z=x(j.measure_info):(B=j.juan_count)!=null&&B.number?z=Vn(j.juan_count.number)+d.unit.juan:(P=j.juan_count)!=null&&P.description&&(z=x(j.juan_count.description));const C=[];return(W=j.publication_info)!=null&&W.year&&C.push(e.jsx(we,{label:d.label.year,children:j.publication_info.year},"year")),(F=j.current_location)!=null&&F.name&&C.push(e.jsx(we,{label:d.label.currentLocation,children:x(j.current_location.name)},"loc")),(D=j.page_count)!=null&&D.description&&C.push(e.jsx(we,{label:d.label.pageCount,children:j.page_count.description},"page")),_!=null&&_.edition&&C.push(e.jsx(we,{label:d.label.edition,children:x(_.edition)},"ver")),I!=null&&I.parent_work&&C.push(e.jsx(we,{label:d.label.parentWork,children:e.jsx(ye,{id:I.parent_work.id,label:x(I.parent_work.title),onNavigate:r,renderLink:s})},"pw")),I!=null&&I.parent_works&&I.parent_works.length>0&&!I.parent_work&&C.push(e.jsx(we,{label:d.label.parentWork,children:I.parent_works.map((T,H)=>e.jsxs("span",{children:[H>0&&"、",e.jsx(ye,{id:T,onNavigate:r,renderLink:s})]},T))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(_r,{id:j.id,title:x(j.title),edition:j.edition?x(j.edition):void 0,type:j.type,isDraft:E,authors:j.authors,volumeText:z,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=j.description)==null?void 0:L.text)&&e.jsx(yt,{text:j.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),j.appendix&&j.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:j.appendix.map((T,H)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:x(T.title)}),e.jsx(yt,{text:T.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},H))}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(he,{children:d.section.containedIn}),e.jsx($r,{items:S,onNavigate:r,renderLink:s})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx(he,{children:d.section.belongsToWork}),e.jsx(Wr,{workData:y,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(Tr,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(Ir,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(zr,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(Cr,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(kt,{items:j.emendated_by,onNavigate:r,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(he,{children:d.section.resources}),e.jsx(St,{items:j.resources,resourceGroups:j.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(Rr,{items:_.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(Er,{items:k.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(on,{title:d.section.relatedVersions,ids:_.related_books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(on,{title:d.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(he,{children:[d.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(T=>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(ye,{id:T.id,label:x(T.title),onNavigate:r,renderLink:s})},T.id))})]}),(I==null?void 0:I.books)&&I.books.length>0&&e.jsx(Lr,{ids:I.books,workData:I,transport:o,onNavigate:r,renderLink:s,footer:l}),(I==null?void 0:I.related_works)&&I.related_works.length>0&&(()=>{const T=[],H=I.related_works.filter(K=>K.relation==="part_of"),$=I.related_works.filter(K=>K.relation==="has_part"),N=I.related_works.filter(K=>!K.relation);return H.length>0&&T.push({label:d.section.belongsToWork,items:H}),$.length>0&&T.push({label:d.section.containedWorks,items:$}),N.length>0&&T.push({label:d.section.relatedWorks,items:N}),T.map(K=>e.jsxs("div",{children:[e.jsxs(he,{children:[K.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",K.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:K.items.map(te=>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(ye,{id:te.id,label:x(te.title),onNavigate:r,renderLink:s})},te.id))})]},K.label))})()]})};function Ar({data:t}){const n=M(),{convert:o}=O(),{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 Fr({sections:t,activeSection:n,onSelect:o}){const r=M();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:rn(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:rn(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 rn(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Mr({id:t,label:n,onNavigate:o,renderLink:r}){const s=ve();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 Pr(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 sn({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=M(),{convert:i}=O(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?Pr(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[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(d=>i(d)).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:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Mr,{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 wt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const c=M(),[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,v]=u.useState(null),[g,y]=u.useState(""),m=t||a;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let k=!1;return f(!0),p(null),o.getCollectionCatalog(n).then(I=>{k||(I?d(I):p(c.catalog.notFound))}).catch(I=>{k||p(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{k||f(!1)}),()=>{k=!0}},[t,n,o,c]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,w=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const k=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(k).size<k.length},[m]),j=u.useMemo(()=>{if(!m)return[];let k=m.books;if(b&&(k=k.filter(I=>I.section===b)),g.trim()){const I=g.trim().toLowerCase();k=k.filter(E=>E.title.toLowerCase().includes(I)||E.sub_items&&E.sub_items.some(z=>z.toLowerCase().includes(I))||E.edition&&E.edition.toLowerCase().includes(I))}return k},[m,b,g]),_=u.useMemo(()=>{if(!w)return null;const k=[],I=new Map;for(const z of j){if(!z.volumes||z.volumes.length===0)continue;const C=z.volumes[0];I.has(C)||I.set(C,[]),I.get(C).push(z)}const E=[...I.keys()].sort((z,C)=>z-C);for(const z of E)k.push({volume:z,books:I.get(z)});return k},[j,w]);return x?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.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(Ar,{data:m}),S&&e.jsx(Fr,{sections:m.sections,activeSection:b,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:k=>y(k.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:[j.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[_?_.map((k,I)=>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:Qe(c.catalog.volume,{n:k.volume})}),k.books.map((E,z)=>e.jsx(sn,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${k.volume}-${z}`))]},`${k.volume}-${I}`)):j.map((k,I)=>e.jsx(sn,{book:k,onNavigate:r,renderLink:s,showVolumes:!0},I)),j.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Be=()=>{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)})},ce=6,tt=7,Hr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),x=u.useRef(null),f=u.useRef(null),h=u.useRef(null),p=u.useCallback(()=>{const g=f.current,y=h.current;if(!g||!y)return;const m=g.getBoundingClientRect(),S=y.getBoundingClientRect(),w=window.innerHeight,j=document.documentElement.clientWidth;let _=o;o==="top"&&m.top-S.height-tt<8&&(_="bottom"),o==="bottom"&&m.bottom+S.height+tt>w-8&&(_="top");const k=_==="top"?m.top-S.height-tt:m.bottom+tt;let I=m.left+m.width/2-S.width/2;I=Math.max(8,Math.min(I,j-S.width-8)),d({left:I,top:k,placement:_})},[o]),b=u.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>c(!0),r)},[r]),v=u.useCallback(()=>{x.current&&clearTimeout(x.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const g=requestAnimationFrame(p);return()=>cancelAnimationFrame(g)},[l,p]),u.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:b,onMouseLeave:v,onFocus:b,onBlur:v,style:{display:"inline-block",...i},children:n}),l&&Bo.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth: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:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-ce,width:0,height:0,...a.placement==="top"?{bottom:-ce,borderTop:`${ce}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ce}px solid transparent`,borderRight:`${ce}px solid transparent`}:{top:-ce,borderBottom:`${ce}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ce}px solid transparent`,borderRight:`${ce}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${ce-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ce-1}px solid transparent`,borderRight:`${ce-1}px solid transparent`}:{top:-5,borderBottom:`${ce-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ce-1}px solid transparent`,borderRight:`${ce-1}px solid transparent`}}})]})]}),document.body)]})},ln={A:"fine",B:"rough",C:"rough",D:"ocr"};function Or(t){return typeof t!="string"?null:t in Fn?t:t in ln?ln[t]:null}const Dr={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function ie(t){return typeof t!="string"?"":Dr[t]??t}const Nr=["〇","一","二","三","四","五","六","七","八","九"],an=["","十","百","千"],Vr=["","萬","億"];function Kn(t){if(t===0)return"〇";if(t<0)return`負${Kn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Ur(s,r>0)+Vr[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ur(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],c=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&i===0&&!n?s+=an[c]:s+=Nr[l]+an[c]}return s.replace(/〇$/,"")}let qe=null,nt=null;const lt=new Set;function Gr(){return qe?Promise.resolve():nt||(nt=import("opencc-js/t2cn").then(t=>{qe=t.Converter({from:"tw",to:"cn"}),lt.forEach(n=>n())}).catch(()=>{qe=t=>t,lt.forEach(t=>t())}),nt)}function Ce(){const[,t]=u.useState(0);return u.useEffect(()=>{if(qe)return;const n=()=>t(o=>o+1);return lt.add(n),Gr(),()=>{lt.delete(n)}},[]),qe??(n=>n)}function Me(t,n){return n(t).toLowerCase()}const _t="#fff59d";function Pe(t,n,o){if(!n)return t;const r=Me(n,o);if(!r)return t;const s=Me(t,o);if(s.length!==t.length)return t;const i=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){i.push(t.slice(l));break}a>l&&i.push(t.slice(l,a)),i.push(e.jsx("mark",{style:{background:_t,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:i})}function Ct(t,n,o,r){if(!n)return!0;const s=Me(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"&&Me(l,r).includes(s))}function Yr(t,n,o){return n?Me(t,o).includes(Me(n,o)):!0}const It={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Kr={考证:"#5d6d7e"};function Jr(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 Jn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=Jr(t),d=!!(r!=null&&r.vol_label)&&!a.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)":c?`${_t}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:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&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 qn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>qn(r,n)))}function Xn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+Xn(i),0))||0;return n+o}function qr(t,n){const o=[],r=l=>{var c;o.push(...l.files),(c=l.children)==null||c.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 Zn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=qn(t,n||""),c=qr(t,i),a=typeof c=="number"&&c>0,d=c===0,[x,f]=u.useState(l||a),h=Xn(t),p=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!p){const v=t.files[0],g=n===v,y=i[v],m=y===0,S=y==="loading",w=typeof y=="number"&&y>0;return e.jsxs("button",{onClick:()=>{m||o(v)},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)":w?`${_t}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,w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:y}),S&&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:()=>f(!x),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)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"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,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&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(v=>e.jsx(Jn,{file:v,isActive:n===v,onSelect:o,meta:s==null?void 0:s[v],matchState:i[v]},v))}),p&&t.children.map((v,g)=>e.jsx(Zn,{group:v,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function Xr({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((c,a)=>e.jsx(Zn,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},a))}):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(c=>e.jsx(Jn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function Zr({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 Qr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=O(),s=ve(),i=Ce(),l=v=>{if(!v)return"";const g=r(v);return o?Pe(g,o,i):g},[c,a]=u.useState(!1),d=!!t.summary,x=!!t.comment,f=!!t.additional_comment,h=!!(t.content&&t.content.length>60),p=d||x||f||h;u.useEffect(()=>{o&&a(!0)},[o]);const b=!c&&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:()=>p&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"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:[Kn(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)})]}),!c&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&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&&!d&&!x&&!f&&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 ei({section:t,highlightQuery:n=""}){const{convert:o}=O(),r=Ce(),s=a=>{if(!a)return"";const d=o(a);return n?Pe(d,n,r):d},[i,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(Zr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&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&&c&&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 ti({section:t,highlightQuery:n=""}){const{convert:o}=O(),r=Ce();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),i=n?
|
|
3
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!i[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,x)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},x):e.jsx(u.Fragment,{children:s(d)},x))},c)})})}function si({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=O(),s=ve(),i=Ce(),l=d=>{if(!d)return"";const x=r(d);return o?Pe(x,o,i):x},c=[];let a=null;for(const d of t)ie(d.type)==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):ie(d.type)==="书"?(a||(a={category:"",items:[]}),a.items.push(d)):(ie(d.type)==="序"||ie(d.type)==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),ie(d.type)==="结语"&&(c.push(a),a=null));return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,x)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((f,h)=>ie(f.type)==="序"||ie(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),p.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},h))]},x))})}function li({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=O(),i=Ce(),[l,c]=u.useState("catalog"),a=o.trim(),d=u.useMemo(()=>a?t.sections.filter(p=>Ct(p,a,!1,i)):t.sections,[t.sections,a,i]),x=t.sections.filter(p=>ie(p.type)==="书").length,f=t.sections.filter(p=>ie(p.type)==="诗").length,h=a?d.filter(p=>ie(p.type)==="书"||ie(p.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(p=>e.jsx("button",{onClick:()=>c(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${f>0?`${f} 首`:`${x} 部書`}`:f>0?`${f} 首`:`${x} 部书`})]}),l==="raw"&&(n?e.jsx(ii,{text:n,highlightQuery:a}):e.jsx(si,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((p,b)=>ie(p.type)==="书"||ie(p.type)==="诗"?e.jsx(Qr,{section:p,onNavigate:r,highlightQuery:a},b):ie(p.type)==="类"?e.jsx(ei,{section:p,highlightQuery:a},b):e.jsx(ti,{section:p,highlightQuery:a},b)),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Qn(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 cn(t){const n=Qn(t);return n.length>0?n[0]:null}function ai(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:c,isKaozhen:a}=t,d=Ce(),x=u.useRef(new Map),[f,h]=u.useState({});u.useEffect(()=>{s&&i&&x.current.set(s,{juan:i,rawText:l})},[s,i,l]),u.useEffect(()=>{x.current.clear(),h({})},[n]);const p=u.useCallback((b,v)=>{let g=0;if(b.juan)for(const y of b.juan.sections)Ct(y,v,a,d)&&g++;return g===0&&b.rawText&&Yr(b.rawText,v,d)&&(g=1),g},[a,d]);return u.useEffect(()=>{const b=c.trim();if(!b){h({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let v=!1;const g={},y=[];for(const _ of r){const k=x.current.get(_);k?g[_]=p(k,b):(g[_]="loading",y.push(_))}h(g);const m=8;let S=0;const w=async()=>{var _;for(;S<y.length;){if(v)return;const k=S++,I=y[k];try{const[E,z]=await Promise.all([o.getCollatedJuan(n,I),((_=o.getCollatedJuanText)==null?void 0:_.call(o,n,I))??Promise.resolve(null)]),C={juan:E,rawText:z};if(x.current.set(I,C),v)return;h(B=>({...B,[I]:p(C,b)}))}catch{if(v)return;h(E=>({...E,[I]:0}))}}},j=Array.from({length:Math.min(m,y.length)},()=>w());return Promise.all(j),()=>{v=!0}},[c,n,o,r.join(","),p,d]),{matchStates:f}}const zt=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:l,style:c})=>{const[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,v]=u.useState(null),[g,y]=u.useState(null),[m,S]=u.useState(!1),[w,j]=u.useState(null),[_,k]=u.useState(""),I=u.useRef(new Map),E=s??b,z=u.useCallback(L=>{v(L),i==null||i(L)},[i]),C=t||a;u.useEffect(()=>{t&&(f(!1),p(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return f(!0),p(null),o.getCollatedEditionIndex(n).then(T=>{if(!L)if(!T)p("未找到整理本数据");else{d(T);const H=cn(T);!s&&H&&z(H)}}).catch(T=>{L||p(T instanceof Error?T.message:"加载失败")}).finally(()=>{L||f(!1)}),()=>{L=!0}},[t,n,o,s,z]),u.useEffect(()=>{const L=t||a;if(L&&!E){const T=cn(L);T&&z(T)}},[t,a,E,z]);const B=n||(C==null?void 0:C.work_id),P=u.useCallback(async L=>{var T;if(!(!B||!(o!=null&&o.getCollatedJuan))){S(!0),y(null),j(null);try{const[H,$]=await Promise.all([o.getCollatedJuan(B,L),((T=o.getCollatedJuanText)==null?void 0:T.call(o,B,L))??Promise.resolve(null)]);y(H),j($)}catch{y(null),j(null)}finally{S(!1)}}},[B,o]);u.useEffect(()=>{E&&P(E)},[E,P]);const W=L=>{z(L)};if(x)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!C)return null;const F=C.type==="kaozhen",D=Qn(C);return e.jsx(ci,{className:l,style:c,index:C,allFiles:D,isKaozhen:F,effectiveWorkId:B,transport:o,activeFile:E,handleSelectFile:W,juanData:g,juanRawText:w,juanLoading:m,searchQuery:_,setSearchQuery:k,onNavigate:r,workLabelCacheRef:I})},ci=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:x,juanLoading:f,searchQuery:h,setSearchQuery:p,onNavigate:b,workLabelCacheRef:v})=>{const{matchStates:g}=ai({workId:i,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:x,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:y=>p(y.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 y=Or(o.text_quality.grade);return y?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Hr,{content:Fo[y],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Mo[y],cursor:"help"},children:Fn[y]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(Xr,{files:r,groups:o.juan_groups,activeFile:c,onSelect:a,juanMeta:o.juan_metadata,matchStates:g}),f?e.jsx(Be,{}):d?s?e.jsx(ri,{juan:d,searchQuery:h,onNavigate:b,transport:l,workLabelCache:v}):e.jsx(li,{juan:d,rawText:x,searchQuery:h,onNavigate:b}):c?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((y,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,". "]}),y.url?e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:y.title}):e.jsx("span",{children:y.title}),y.author&&e.jsxs("span",{children:[",",y.author]}),y.note&&e.jsxs("span",{children:["。",y.note]})]},m))]})]})},di={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},pi={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function xi(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 Tt=({items:t,loading:n})=>{const o=ve();return n?e.jsx(Be,{}):t.length===0?e.jsx("div",{style:ui,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=di[r.type],i=pi[r.status];return e.jsxs("div",{style:fi,children:[e.jsxs("div",{style:gi,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...dn,background:s.color},children:s.label}),e.jsx("span",{style:{...dn,background:i.color},children:i.label})]}),e.jsx("span",{style:hi,children:xi(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:bi,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:pn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:pn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:mi,children:r.content}),r.reply&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},ui={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},fi={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},gi={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},dn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},hi={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},bi={fontSize:"12px",marginBottom:"6px"},pn={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},mi={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},yi={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},vi={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},vt=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=M(),[c,a]=u.useState(null),[d,x]=u.useState([]),[f,h]=u.useState("recommend"),[p,b]=u.useState([]),[v,g]=u.useState(!1),y=r??f,m=F=>{h(F),s==null||s(F)},[S,w]=u.useState(!0),[j,_]=u.useState(null),[k,I]=u.useState(null),[E,z]=u.useState(null);u.useEffect(()=>{let F=!1;if(t.getCounts)return t.getCounts().then(D=>{F||a({works:D.works,books:D.books,collections:D.collections})}).catch(()=>{}),()=>{F=!0}},[t]),u.useEffect(()=>{let F=!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(T=>T.items.map(H=>({...H,group:T.name})))}catch{}return[]})().then(async L=>{if(F)return;const T=L.filter($=>$.id);if(T.length===0){w(!1);return}const H=await Promise.all(T.map(async $=>{if($.type)return{id:$.id,title:$.title,type:$.type,author:$.author,dynasty:$.dynasty,role:$.role,edition:$.edition,has_text:$.has_text,has_image:$.has_image,has_collated:$.has_collated,subtype:$.subtype,primary_name:$.primary_name,group:$.group,fallbackDescription:$.description};try{let N=null;if(t.getEntry)N=await t.getEntry($.id);else{const K=await t.getItem($.id);K&&(N={id:$.id,title:K.title||$.id,type:K.type||"work"})}if(N)return{...N,group:$.group,fallbackDescription:$.description}}catch{}return{id:$.id,title:$.title,type:Y.extractType($.id),group:$.group,fallbackDescription:$.description}}));F||(x(H.filter($=>$!==null)),w(!1))}),()=>{F=!0}},[t,o]);const C=u.useRef(!1),B=u.useRef(!1),P=u.useRef(!1);u.useEffect(()=>{if(y!=="catalog"||C.current)return;const F=t.getCatalogProgress??t.getResourceProgress;if(!F)return;C.current=!0;let D=!1;return F.call(t).then(L=>{D||_(L)}).catch(()=>{C.current=!1}),()=>{D=!0}},[t,y]),u.useEffect(()=>{if(y!=="collection"||B.current||!t.getCollectionProgress)return;B.current=!0;let F=!1;return t.getCollectionProgress().then(D=>{F||I(D)}).catch(()=>{B.current=!1}),()=>{F=!0}},[t,y]),u.useEffect(()=>{if(y!=="site"||P.current||!t.getSiteProgress)return;P.current=!0;let F=!1;return t.getSiteProgress().then(D=>{F||z(D)}).catch(()=>{P.current=!1}),()=>{F=!0}},[t,y]),u.useEffect(()=>{if(!i||y!=="feedback")return;let F=!1;return g(!0),fetch(i).then(D=>D.json()).then(D=>{!F&&D.success&&b(D.items||[])}).catch(()=>{}).finally(()=>{F||g(!1)}),()=>{F=!0}},[i,y]);const W=F=>{switch(F){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(Ve,{label:l.home.recommendTab,active:y==="recommend",onClick:()=>m("recommend")}),e.jsx(Ve,{label:l.home.catalogTab,active:y==="catalog",onClick:()=>m("catalog")}),e.jsx(Ve,{label:l.home.collectionTab,active:y==="collection",onClick:()=>m("collection")}),e.jsx(Ve,{label:l.home.siteTab,active:y==="site",onClick:()=>m("site")}),i&&e.jsx(Ve,{label:l.home.feedbackTab,active:y==="feedback",onClick:()=>m("feedback")})]}),y==="recommend"&&e.jsx(ji,{recommended:d,loading:S,onNavigate:n,getIcon:W,t:l}),y==="catalog"&&e.jsx(xn,{progress:j,t:l,onNavigate:n}),y==="collection"&&e.jsx(xn,{progress:k,t:l,onNavigate:n}),y==="site"&&e.jsx(ki,{progress:E,t:l,totalWorks:(c==null?void 0:c.works)??0}),y==="feedback"&&i&&e.jsx(Tt,{items:p,loading:v})]})})},Ve=({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}),ji=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=ve();if(n)return e.jsx(Be,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const x=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o==null||o(d.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(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),x&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x})]})]},d.id)})})]},c))})},xn=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(Be,{});const r=[...t.resources].sort((c,a)=>c.priority-a.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(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),i[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Si,{item:d,t:n,statusColor:l[c],onNavigate:o},d.id))})]},c)})})},Si=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ve(),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 c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Qe(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})]})},ki=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(Be,{});const r=[...t.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),i=r.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=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," (",c,"%)"]}),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(a=>e.jsx(un,{item:a,t:n,totalWorks:o},a.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(a=>e.jsx(un,{item:a,t:n,totalWorks:o},a.id))})]})]})},un=({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})]})},fn="(max-width: 768px)";function wi(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(fn).matches);return u.useEffect(()=>{const o=window.matchMedia(fn),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const _i=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var D;const i=M(),{convert:l}=O(),c=wi(),[a,d]=u.useState(null),[x,f]=u.useState(null),[h,p]=u.useState(!1),[b,v]=u.useState("detail"),[g,y]=u.useState([]),[m,S]=u.useState(!1),[w,j]=u.useState(null),[_,k]=u.useState(!1),I=u.useCallback(async L=>{if(!t.getCollatedEditionIndex){j(null);return}k(!0);try{const T=await t.getCollatedEditionIndex(L);j(T)}catch{j(null)}finally{k(!1)}},[t]),E=u.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){y([]);return}S(!0);try{if(t.getCollectionCatalogs){const T=await t.getCollectionCatalogs(L);y(T||[])}else if(t.getCollectionCatalog){const T=await t.getCollectionCatalog(L);y(T?[{resource_id:"",data:T}]:[])}}catch{y([])}finally{S(!1)}},[t]),z=u.useCallback(async L=>{if(o){o(L);return}d(L),f(null),y([]),j(null),v("detail"),p(!0);try{const T=await t.getItem(L.id);T&&(f(T),T.type==="collection"?E(L.id):T.type==="work"&&T.has_collated&&I(L.id))}catch(T){console.error("加载详情失败:",T)}finally{p(!1)}},[t,o,E,I]),C=u.useCallback(async L=>{f(null),y([]),j(null),v("detail"),p(!0);try{const T=await t.getItem(L);T&&(f(T),d({id:L,title:T.title||L,type:T.type||"book"}),T.type==="collection"?E(L):T.type==="work"&&T.has_collated&&I(L))}catch(T){console.error("导航失败:",T)}finally{p(!1)}},[t,E,I]),B=(x==null?void 0:x.type)==="collection"&&(g.length>0||m)||(x==null?void 0:x.type)==="work"&&(w||_),P=c&&(h||x),W=u.useCallback(()=>{d(null),f(null),y([]),j(null),v("detail")},[]),F=e.jsx(e.Fragment,{children:h?e.jsx(Be,{}):x?e.jsxs(e.Fragment,{children:[(B||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:ot(b==="detail"),children:i.detailTab.basicInfo}),x.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:ot(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),x.type==="collection"&&g.map(L=>e.jsx("button",{onClick:()=>v(`catalog:${L.resource_id}`),style:ot(b===`catalog:${L.resource_id}`),children:L.short_name?`${l(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),x.type==="work"&&(w||_)&&e.jsxs("button",{onClick:()=>v("collated"),style:ot(b==="collated"),children:[i.detailTab.collatedEdition,_&&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:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(dt,{data:x,transport:t,onNavigate:C}):b.startsWith("catalog:")?e.jsx(wt,{data:(D=g.find(L=>`catalog:${L.resource_id}`===b))==null?void 0:D.data,onNavigate:C}):b==="collated"?e.jsx(zt,{index:w||void 0,workId:x.id,transport:t,onNavigate:C}):null})]}):e.jsx(vt,{transport:t,onNavigate:C,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:P?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:W,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(mt,{transport:t,onEntryClick:z,hideModeIndicator:n}),!x&&e.jsx(vt,{transport:t,onNavigate:C,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(mt,{transport:t,onEntryClick:z,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:F})]})};function ot(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 eo=({index:t,bookId:n,transport:o,activeChapter:r,onChapterChange:s})=>{const[i,l]=u.useState(t??null),[c,a]=u.useState(null),d=r!==void 0?r:c,x=u.useCallback(g=>{s?s(g):a(g)},[s]),[f,h]=u.useState(null),[p,b]=u.useState(!1);u.useEffect(()=>{t&&l(t)},[t]),u.useEffect(()=>{if(t||!n||!o.getBookFullTextIndex)return;let g=!1;return o.getBookFullTextIndex(n).then(y=>{g||l(y)}),()=>{g=!0}},[n,o,t]),u.useEffect(()=>{!i||i.chapters.length===0||d||x(i.chapters[0].file)},[i,d,x]),u.useEffect(()=>{if(!n||!d||!o.getBookFullTextChapter)return;let g=!1;return b(!0),h(null),o.getBookFullTextChapter(n,d).then(y=>{g||h(y)}).catch(()=>{g||h(null)}).finally(()=>{g||b(!1)}),()=>{g=!0}},[n,d,o]);const v=u.useMemo(()=>!i||!d?null:i.chapters.find(g=>g.file===d)??null,[i,d]);return i?i.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[i.version_label," · 共 ",i.total_chapters," ",(i.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:i.chapters.map(g=>{const y=g.file===d;return e.jsx("li",{children:e.jsx("button",{onClick:()=>x(g.file),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:y?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:y?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:y?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:g.title})},g.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},children:[v&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:v.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:i.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:i.source.name}),i.source.license&&e.jsxs(e.Fragment,{children:[" · ",i.source.license]})]})]}),p&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!p&&f&&e.jsx("article",{style:{fontSize:16,lineHeight:1.9,color:"var(--bim-fg, #2c2c2c)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:'"Songti SC", "Source Han Serif", "Noto Serif CJK SC", serif'},children:f.replace(/^##\s+[^\n]+\n+/,"")}),!p&&!f&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Ci=({data:t,onNavigate:n,className:o,style:r})=>{var x;const s=M(),{convert:i}=O(),[l,c]=u.useState(((x=t.divisions[0])==null?void 0:x.name)??null),[a,d]=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(f=>e.jsx(Ii,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:h=>d(a===h?null:h),onNavigate:n},f.name))})]})},Ii=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:l}=O(),c=t.categories.reduce((a,d)=>{const x=d.stats||{zhulu:0,cunmu:0};return a+(x.zhulu||0)+(x.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," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(zi,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:i},a.name)})})]})},zi=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,d,x,f;const{convert:s}=O(),i=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((x=t.stats)==null?void 0:x.zhulu)||i.length)+(((f=t.stats)==null?void 0:f.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:[c," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(gn,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(gn,{label:"存目",books:l,onNavigate:r})]})]})},gn=({label:t,books:n,onNavigate:o})=>{const{convert:r}=O(),s=ve(),[i,l]=u.useState(n.length<=20),c=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:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:s(a.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!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," 條"]})]})},me=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=M();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:Ri,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ti,children:i.action.save})]})]}),s]})},Ti={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ri={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ue=({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"}})]}),Le=({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"}})},at=({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 Ei(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const it=({value:t,onChange:n,label:o})=>{const[r,s]=u.useState(!1),i=u.useRef(null),l=Ei(t||"");return u.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:hn,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(at,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:hn,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:c=>n(c.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"}})]})},hn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Li(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Bi(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const to=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=M(),[s,i]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},c=f=>{n(t.filter((h,p)=>p!==f)),s===f&&i(null)},a=(f,h,p)=>{const b=[...t];b[f]={...b[f],[h]:p},n(b)},d=(f,h)=>{const p=[...t];p[f]={...p[f],type:h,id:"",name:""},n(p),h==="bookID"&&o&&o(b=>{const v=[...t];v[f]={...v[f],id:b.id,name:b.title,type:"bookID"},n(v)})},x=f=>{o&&o(h=>{const p=[...t];p[f]={...p[f],id:h.id,name:h.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,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:f.name||`${r.editor.sourcePlaceholder} ${h+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Li(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:Bi(f.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),c(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),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:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(h,"bookID"),style:{...bn,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:()=>d(h,"url"),style:{...bn,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})]})]})]}),f.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:_e,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:mn,children:r.action.changeType})]}),f.id&&f.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:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),e.jsx("button",{onClick:()=>x(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:()=>x(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})]})]})}),f.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:_e,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:mn,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:p=>a(h,"name",p.target.value),placeholder:r.editor.sourceNamePlaceholder,style:Ae})]}),e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:p=>a(h,"id",p.target.value),placeholder:"https://...",style:Ae})]})]}),f.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:{..._e,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:_e,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:p=>a(h,"details",p.target.value),placeholder:r.editor.detailsPlaceholder,style:Ae})]}),e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:p=>a(h,"position",p.target.value),placeholder:"如: 卷三, p.52",style:Ae})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:p=>a(h,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:Ae})]}),e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:p=>a(h,"processor_version",p.target.value),placeholder:"如: v0.1",style:Ae})]})]})]})]})})]},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})]})]})},_e={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Ae={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},bn={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"},mn={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function no(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 oo(t){return!t||t.length===0?"":JSON.stringify(t)}const ro=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:x,onLinkEntity:f,onUnlinkEntity:h,onViewEntity:p,onCreateAndLink:b,onSaveRelations:v})=>{const g=M();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),v&&e.jsx("button",{onClick:v,style:Wi,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ue,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:p,onUnlink:()=>h("workId"),onLink:()=>f("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(Ue,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:p,onUnlink:()=>h("collectionId"),onLink:()=>f("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&&x&&x.length>0&&e.jsx(Fe,{direction:"horizontal",title:`${g.relation.siblingVersions} (${x.length})`,entities:x,onView:p,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(Ue,{direction:"up",title:g.relation.parentWork,entity:r,onView:p,onUnlink:()=>h("parentWorkId"),onLink:()=>f("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}),c&&c.length>0&&e.jsx(Fe,{direction:"down",title:`${g.relation.childWorks} (${c.length})`,entities:c,onView:p,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(Fe,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:p,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(Fe,{direction:"down",title:`${g.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,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(Ue,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:p,onUnlink:()=>h("workId"),onLink:()=>f("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(Ue,{direction:"up",title:g.relation.parentCollection,entity:s,onView:p,onUnlink:()=>h("parentCollectionId"),onLink:()=>f("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(Fe,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:p,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(Fe,{direction:"down",title:`${g.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},Ue=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:x,unlinkLabel:f})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=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:p}),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:io(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(yn,{onClick:()=>r(o),title:x,children:"👁️"}),e.jsx(yn,{onClick:s,title:f,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:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(jt,{onClick:i,children:c}),e.jsx(jt,{onClick:l,primary:!0,children:a})]})]})},Fe=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=u.useState(!1),x=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(p=>e.jsxs("div",{onClick:()=>r(p),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:io(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(jt,{onClick:s,primary:!0,children:["+ ",i]})})]})},yn=({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}),jt=({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 io(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Wi={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"},so=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[x,f]=u.useState(""),h=d?l.filter(g=>g.id!==d):l;u.useEffect(()=>{t&&(f(""),c(""))},[t]);const p=g=>{f(g),c(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:$i,children:e.jsxs("div",{style:Ai,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:Fi,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:x,onChange:g=>p(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Mi})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:ft,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:Pi,children:[e.jsx("span",{style:{fontSize:"16px"},children:v}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):x?e.jsxs("div",{style:ft,children:["未找到匹配的",b]}):e.jsxs("div",{style:ft,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:Hi,children:["创建新",b,"并关联"]})]})]})})},$i={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},Ai={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)"},Fi={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Mi={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"},Pi={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},ft={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Hi={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},vn={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Oi={work:"📜",book:"📖",collection:"📚",entity:"👤"},lo=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var h,p;(h=a.current)==null||h.focus(),(p=a.current)==null||p.select()},100))},[t,r==null?void 0:r.title]);const d=h=>{h.key==="Enter"&&l.trim()?x():h.key==="Escape"&&i()},x=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const f=()=>{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`创建新${vn[n]}`}};return e.jsx("div",{style:Di,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Ni,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:Oi[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:h=>c(h.target.value),onKeyDown:d,placeholder:`请输入${vn[n]}名称...`,style:Vi})]}),((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:Ui,children:"取消"}),e.jsx("button",{onClick:x,disabled:!l.trim(),style:{...Gi,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Di={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},Ni={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)"},Vi={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"},Ui={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Gi={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Yi(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function ao(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ki(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const co=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:x})=>{const[f,h]=u.useState(""),[p,b]=u.useState([]),[v,g]=u.useState(!1),[y,m]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!f.trim()){b([]);return}const I=setTimeout(async()=>{g(!0);try{b(await x(f,o))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(I)},[f,o,x]);const S=u.useCallback(I=>{h(I.target.value),I.target.value.trim()&&m("search")},[]),w=u.useCallback(I=>s?I.filter(E=>E.id!==s):I,[s]);if(!t)return null;const j=n||(o==="all"?"选择实体":`选择${ao(o)}`),_=w(r),k=w(p);return e.jsx("div",{style:qi,children:e.jsxs("div",{style:Xi,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:j}),e.jsx("button",{onClick:a,style:Zi,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:f,onChange:S,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Qi}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(jn,{active:y==="recent",onClick:()=>m("recent"),children:["最近使用 (",_.length,")"]}),e.jsxs(jn,{active:y==="search",onClick:()=>m("search"),children:["搜索结果 ",k.length>0&&`(${k.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:y==="recent"&&_.length>0?e.jsx(Sn,{entities:_,onSelect:c}):f.trim()?v?e.jsx(gt,{message:"搜索中..."}):k.length>0?e.jsx(Sn,{entities:k,onSelect:c}):e.jsx(gt,{message:"未找到匹配的结果"}):e.jsx(gt,{message:"输入关键词开始搜索"})}),i&&d&&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:d,style:es,children:l||"创建新实体"})]})]})})},jn=({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}),Sn=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Ji,{entity:o,onClick:()=>n(o)},o.id))}),Ji=({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:Yi(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:Ki(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:ao(t.type)})]})},gt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),qi={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},Xi={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)"},Zi={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Qi={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"},es={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ts={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},ns={work:"📜",collection:"📚",book:"📖",entity:"👤"},po=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:x,relations:f,onRelationsChange:h})=>{var re;const p=M(),[b,v]=u.useState(!1),[g,y]=u.useState("work"),[m,S]=u.useState(""),[w,j]=u.useState(""),[_,k]=u.useState([]),[I,E]=u.useState(!1),[z,C]=u.useState(!1),[B,P]=u.useState("work"),[W,F]=u.useState(""),[D,L]=u.useState(),[T,H]=u.useState(!1),[$,N]=u.useState(null),[K,te]=u.useState([]);u.useRef(null);const se=t.type,fe=se==="work",be=se==="collection",ne=se==="book",Q=u.useCallback((R,V)=>{n({...t,[R]:V})},[t,n]),Te=u.useCallback((R,V)=>{S(R),y(V),j(p.editor.selectToLink+p.indexType[V]),k([]),v(!0)},[p]),We=u.useCallback(R=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,R)},[r,t.id]),Ie=u.useCallback(R=>{s==null||s(R.id,R.type)},[s]),pe=u.useCallback((R,V,le)=>{const xe={...le,author:(le==null?void 0:le.author)||t.author,dynasty:(le==null?void 0:le.dynasty)||t.dynasty};P(V),F(R),L(xe),C(!0)},[t.author,t.dynasty]),je=u.useCallback((R,V)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,W,{type:B,title:R,inheritData:V}),C(!1)},[r,t.id,W,B]),ze=u.useCallback(R=>{if(!R.trim()){k([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(R,g).then(V=>{k(V),E(!1)}).catch(()=>{k([]),E(!1)})},[r,g]),$e=u.useCallback(R=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,R.id),v(!1)},[r,t.id,m]),A=u.useCallback(()=>{o()},[o]),ee=u.useCallback(R=>{N(()=>R),H(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(te).catch(()=>{})},[r]),J=u.useCallback((R,V)=>r!=null&&r.searchEntities?r.searchEntities(R,V==="all"?void 0:V):Promise.resolve([]),[r]),X=u.useCallback(R=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(R),te(V=>[R,...V.filter(le=>le.id!==R.id)].slice(0,10)),$==null||$(R),H(!1),N(null)},[r,$]);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:ns[se]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(at,{children:t.id}),e.jsx(at,{color:ts[se],children:p.indexType[se]})]})}),e.jsx(me,{title:p.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(it,{label:fe?p.editor.workTitle:be?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:R=>Q("title",R)}),ne&&e.jsx(it,{label:p.editor.belongsToWork,value:t.workName||"",onChange:R=>Q("workName",R)}),e.jsx(ue,{label:p.editor.authorLabel,value:t.author||"",onChange:R=>Q("author",R)}),e.jsx(ue,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:R=>Q("dynasty",R)}),(ne||be)&&e.jsx(it,{label:p.editor.containedIn,value:t.collection||"",onChange:R=>Q("collection",R)}),(ne||be)&&e.jsx(ue,{label:p.editor.holderLabel,value:t.holder||"",onChange:R=>Q("holder",R)}),(ne||be)&&e.jsx(ue,{label:ne?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:R=>Q("pages",R)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ue,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:R=>Q("firstImage",R)})})]})}),e.jsx(me,{title:p.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Le,{value:t.description||"",onChange:R=>Q("description",R),placeholder:p.editor.descriptionPlaceholder})}),(((re=t.additional_works)==null?void 0:re.length)||0)>0&&e.jsx(me,{title:p.section.additionalWorks,onSave:o,children:e.jsx(os,{items:t.additional_works||[],onChange:R=>Q("additional_works",R)})}),e.jsx(me,{title:p.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(rs,{items:t.indexed_by||[],onChange:R=>Q("indexed_by",R)})}),e.jsx(me,{title:p.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(is,{items:t.emendated_by||[],onChange:R=>Q("emendated_by",R)})}),e.jsx(me,{title:p.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(bt,{items:t.resources||[],onChange:R=>Q("resources",R),onDownload:d,downloadStatuses:x,filterType:"text"})}),e.jsx(me,{title:p.section.imageResources,onSave:o,children:e.jsx(bt,{items:t.resources||[],onChange:R=>Q("resources",R),onDownload:d,downloadStatuses:x,filterType:"image"})}),e.jsx(me,{title:p.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(to,{items:no(t.sources||""),onChange:R=>Q("sources",oo(R)),onOpenEntityPicker:ee})}),(ne||be)&&e.jsx(me,{title:p.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Le,{value:t.provenance||"",onChange:R=>Q("provenance",R),placeholder:p.editor.provenancePlaceholder})}),ne&&e.jsx(me,{title:p.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Le,{value:t.otherEditions||"",onChange:R=>Q("otherEditions",R),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(ro,{entityType:se,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:Te,onUnlinkEntity:We,onViewEntity:Ie,onCreateAndLink:pe,onSaveRelations:A}),i&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.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:p.editor.deleteEntity})]}),e.jsx(so,{isOpen:b,entityType:g,title:w,onSelect:$e,onCancel:()=>v(!1),onCreate:()=>{v(!1),pe(m,g)},searchResults:_,onSearch:ze,isLoading:I,excludeId:t.id}),e.jsx(lo,{isOpen:z,entityType:B,relationField:W,inheritData:D,onConfirm:je,onCancel:()=>C(!1)}),e.jsx(co,{isOpen:T,title:p.action.selectBookOrWork,filterType:"all",recentEntities:K,excludeId:t.id,onSelect:X,onCancel:()=>{H(!1),N(null)},onSearch:J})]})};function os({items:t,onChange:n}){const o=M(),r=(l,c,a)=>{const d=t.map((x,f)=>f===l?{...x,[c]:a}:x);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ue,{label:o.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ue,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick: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 xo({items:t,onChange:n,showMeta:o,addLabel:r}){const s=M(),[i,l]=u.useState(null),c=(x,f,h)=>{const p=t.map((b,v)=>v===x?{...b,[f]:h||void 0}:b);n(p)},a=x=>{n(t.filter((f,h)=>h!==x)),i===x&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>{const h=i===f;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:f),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:x.source||s.editor.unnamedSource}),x.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:x.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&o&&(x.title_info||x.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[x.title_info,x.title_info&&x.author_info&&" — ",x.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(ue,{label:s.label.sourceName,value:x.source,onChange:p=>c(f,"source",p)}),e.jsx(ue,{label:s.label.sourceBid,value:x.source_bid||"",onChange:p=>c(f,"source_bid",p)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ue,{label:s.label.titleInfo,value:x.title_info||"",onChange:p=>c(f,"title_info",p)}),e.jsx(ue,{label:s.label.authorInfo,value:x.author_info||"",onChange:p=>c(f,"author_info",p)})]}),e.jsx(ue,{label:s.label.edition,value:x.edition||"",onChange:p=>c(f,"edition",p)})]}),e.jsx(Le,{value:x.summary||"",onChange:p=>c(f,"summary",p),placeholder:s.editor.summaryPlaceholder}),e.jsx(Le,{value:x.comment||"",onChange:p=>c(f,"comment",p),placeholder:s.editor.commentPlaceholder}),e.jsx(Le,{value:x.additional_comment||"",onChange:p=>c(f,"additional_comment",p),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function rs({items:t,onChange:n}){const o=M();return e.jsx(xo,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function is({items:t,onChange:n}){const o=M();return e.jsx(xo,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function uo(t){var c,a,d,x,f,h,p;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",o=((d=t.publication_info)==null?void 0:d.year)||"",r=((x=t.current_location)==null?void 0:x.name)||"",s=(f=t.page_count)!=null&&f.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 v=b.related_works.find(g=>g.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const b=t;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(p=b.contained_in[0])==null?void 0:p.id)}return l}function ss(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 ls=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:x,onAskAI:f,renderSectionActions:h,onDownloadResource:p,downloadStatuses:b,relations:v,onRelationsChange:g,headerExtra:y,className:m,style:S}=t;M();const[w,j]=u.useState(s),_=i?s:w;u.useEffect(()=>{s!==w&&j(s)},[s]);const k=u.useCallback(()=>{const W=_==="view"?"edit":"view";i?i(W):j(W)},[_,i]),[I,E]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(W=>{W&&E(W)})},[o,r]);const z=n||I,C=u.useMemo(()=>z?uo(z):null,[z]),B=i||!n?e.jsx("button",{onClick:k,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:_==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:_==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,P=e.jsxs(e.Fragment,{children:[B,y]});return!z&&!C?e.jsx(Be,{}):_==="view"?e.jsx(dt,{data:z,transport:r,onNavigate:d?W=>d(W):void 0,renderLink:x,headerExtra:P,className:m,style:S}):C?e.jsxs("div",{className:m,style:S,children:[P&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:P}),e.jsx(po,{data:C,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:h,onDownloadResource:p,downloadStatuses:b,relations:v,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},kn=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],fo=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=u.useState(null),[l,c]=u.useState(""),[a,d]=u.useState("idle"),[x,f]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(i(null),c(""),d("idle"),f(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[s]),u.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),u.useEffect(()=>{if(!t)return;const g=y=>{y.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const p=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await o({type:s,content:l.trim()}),d("success")}catch(g){d("error"),f(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&l.trim()&&a!=="submitting",v=kn.find(g=>g.value===s);return e.jsx("div",{style:as,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:cs,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:ds,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ps,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:hs,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:kn.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...xs,...s===g.value?us:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:l,onChange:g=>c(g.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...fs,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),a==="error"&&e.jsx("div",{style:bs,children:x}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!b,style:{...gs,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},as={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},cs={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)"},ds={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ps={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},xs={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"},us={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},fs={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"},gs={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},hs={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},bs={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ms=({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:{...ys,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(fo,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},ys={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"},wn=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],go=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,s]=u.useState(""),[i,l]=u.useState("idle"),[c,a]=u.useState(""),d=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var p;return(p=d.current)==null?void 0:p.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){l("submitting"),a("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(p){l("error"),a(p instanceof Error?p.message:"提交失败,请稍后重试")}}},f=n&&r.trim()&&i!=="submitting",h=wn.find(p=>p.value===n);return i==="success"?e.jsx("div",{style:_n,children:e.jsxs("div",{style:ws,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:_s,children:"继续提交"})]})}):e.jsxs("div",{style:_n,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:wn.map(p=>e.jsxs("button",{onClick:()=>o(p.value),style:{...vs,...n===p.value?js:{}},children:[e.jsx("span",{children:p.icon})," ",p.label]},p.value))}),e.jsx("textarea",{ref:d,value:r,onChange:p=>s(p.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Ss}}),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:x,disabled:!f,style:{...ks,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Cs,children:c})]})},_n={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},vs={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"},js={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ss={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"},ks={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ws={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},_s={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Cs={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Cn(t){return typeof t=="function"?t():t??"/api/feedback"}const ho=({resourceId:t,apiUrl:n})=>{const[o,r]=u.useState([]),[s,i]=u.useState(!0),l=u.useCallback(async()=>{const a=Cn(n);i(!0);try{const x=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();x.success&&r(x.items)}catch{}finally{i(!1)}},[t,n]);u.useEffect(()=>{l()},[l]);const c=async a=>{const d=Cn(n),x=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!x.ok){const f=await x.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(Tt,{items:o,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(go,{onSubmit:c})})]})};function Is(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function zs(t,n){if(!t.lineage)return null;const o=t.lineage;return{id:t.id,kind:"book",label:t.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[t.id],note:o.note}}function In(t,n,o){return{id:`derive:${n.ref}->${t}:${o}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Ts(t,n,o){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Rs(t,n){var d;if(n==="all")return null;const o=(d=t.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,i=r||s||!!(o!=null&&o.hypothetical_ids);if(!i&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!o||!i)return null;const l=r?new Set(o.groups):null,c=new Set(o.book_ids??[]);if(l&&t.node_groups)for(const[x,f]of Object.entries(t.node_groups))l.has(f)&&c.add(x);let a=null;if(o.hypothetical_ids&&(a=new Set(o.hypothetical_ids)),l){a||(a=new Set);for(const x of t.hypothetical_nodes??[])x.group&&l.has(x.group)&&a.add(x.id)}return{books:c,hypos:a}}function st(t,n,o){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const i=new Set(r.excluded_books??[]),l=r.node_groups??{},c=Rs(r,o??r.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,x=(c==null?void 0:c.hypos)??null,f=new Set,h=new Set;if(a){const w=new Map(n.map(z=>[z.id,z])),j=new Map((r.hypothetical_nodes??[]).map(z=>[z.id,z])),_=z=>{const C=w.get(z);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(P=>P.ref);const B=j.get(z);return B?(B.derived_from??[]).map(P=>P.ref):[]},k=z=>j.has(z)?!x||x.has(z):!d||d.has(z),I=new Set,E=z=>{if(!I.has(z)){I.add(z);for(const C of _(z))i.has(C)||(k(C)||(j.has(C)?h.add(C):w.has(C)&&f.add(C)),E(C))}};for(const z of n)d&&d.has(z.id)&&!i.has(z.id)&&E(z.id);for(const z of r.hypothetical_nodes??[])x&&x.has(z.id)&&E(z.id)}const p=n.filter(w=>!i.has(w.id)).filter(w=>!d||d.has(w.id)||f.has(w.id)).map(w=>{const j=zs(w,l);return j&&f.has(w.id)&&(j.bridge=!0),j}).filter(w=>w!==null),b=(r.hypothetical_nodes??[]).filter(w=>!x||x.has(w.id)||h.has(w.id)).map(w=>{const j=Is(w);return h.has(w.id)&&(j.bridge=!0),j}),v=[...p,...b],g=new Set(v.map(w=>w.id)),y=new Set,m=[],S=w=>{y.has(w.id)||!g.has(w.source)||!g.has(w.target)||(y.add(w.id),m.push(w))};for(const w of n)i.has(w.id)||!w.lineage||d&&!d.has(w.id)&&!f.has(w.id)||((w.lineage.derived_from??[]).forEach((j,_)=>{S(In(w.id,j,_))}),(w.lineage.related_to??[]).forEach((j,_)=>{S(Ts(w.id,j,_))}));for(const w of r.hypothetical_nodes??[])x&&!x.has(w.id)&&!h.has(w.id)||(w.derived_from??[]).forEach((j,_)=>{S(In(w.id,j,_))});return{nodes:v,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(i)}}function bo(t,n,o){const r=(t??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Es(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(a=>a.id)),i=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...i]),c=(a,d)=>{l.has(d.ref)||o.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(x=>c(d,x)),(a.lineage.related_to??[]).forEach(x=>{s.has(x.book_id)||o.push(`${d}: related_to.book_id "${x.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(x=>c(d,x))}return o}const mo=({graph:t,renderLink:n,className:o,style:r})=>{const{convert:s}=O();if(!t.nodes.length)return e.jsx("div",{style:{...Us,...r},className:o,children:"暂无版本图数据"});const i=new Map,l=new Map;for(const h of t.edges)if(h.kind==="derive"){const p=i.get(h.target)??[];p.push(h),i.set(h.target,p)}else for(const p of[h.source,h.target]){const b=l.get(p)??[];b.push(h),l.set(p,b)}const c=new Map(t.nodes.map(h=>[h.id,h])),a=new Map,d=[];for(const h of t.nodes)if(h.group){const p=a.get(h.group)??[];p.push(h),a.set(h.group,p)}else d.push(h);const x=(h,p)=>(h.year??9999)-(p.year??9999);a.forEach(h=>h.sort(x)),d.sort(x);const f=t.groups.filter(h=>a.has(h.id));return e.jsxs("div",{className:o,style:{...Bs,...r},children:[t.title&&e.jsx("div",{style:Ws,children:s(t.title)}),t.description&&e.jsx("div",{style:$s,children:s(t.description)}),f.map(h=>e.jsx(zn,{label:h.label,color:h.color,nodes:a.get(h.id),incomingMap:i,siblingMap:l,nodeMap:c,renderLink:n},h.id)),d.length>0&&e.jsx(zn,{label:"其他",nodes:d,incomingMap:i,siblingMap:l,nodeMap:c,renderLink:n})]})},zn=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:l})=>{const{convert:c}=O();return e.jsxs("div",{style:As,children:[e.jsx("div",{style:{...Fs,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),o.map(a=>e.jsx(Ls,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:i,renderLink:l},a.id))]})},Ls=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical",l=t.bridge,{convert:c}=O();return e.jsxs("div",{style:{...Ms,borderStyle:i||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Ps,children:[e.jsx("span",{style:Hs,children:i||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Os,children:bo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Ds,children:[t.category&&e.jsx(Ge,{children:c(t.category)}),t.status==="lost"&&e.jsx(Ge,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Ge,{tone:"warn",children:"残本"}),i&&e.jsx(Ge,{tone:"info",children:"假想祖本"}),l&&e.jsx(Ge,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Ns,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Vs,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Rn,children:[e.jsx("div",{style:En,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:Ln(a.confidence),children:[e.jsx("span",{style:Bn,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(Tn,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Wn,children:["· ",c(a.evidence)]})]},a.id)})]}),o.length>0&&e.jsxs("div",{style:Rn,children:[e.jsx("div",{style:En,children:"关联:"}),o.map(a=>{const d=a.source===t.id?a.target:a.source,x=r.get(d);return e.jsxs("div",{style:Ln(a.confidence),children:[e.jsx("span",{style:Bn,children:c(a.relation)}),e.jsx("span",{children:(x==null?void 0:x.kind)==="book"&&s?s(x.id,c(x.label)):c((x==null?void 0:x.label)??d)}),e.jsx(Tn,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Wn,children:["· ",c(a.evidence)]})]},a.id)})]})]})},Ge=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Tn=({level:t})=>{const o={certain:{label:"确定",color:"#2e7d32"},consensus:{label:"共识",color:"#1976d2"},probable:{label:"推测",color:"#ed6c02"},disputed:{label:"有争议",color:"#c62828"}}[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},Bs={fontSize:"14px",color:"var(--bim-fg, #333)"},Ws={fontSize:"16px",fontWeight:600,marginBottom:"8px"},$s={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},As={marginBottom:"16px"},Fs={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ms={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ps={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Hs={fontSize:"15px",fontWeight:600},Os={fontSize:"12px",color:"var(--bim-muted, #777)"},Ds={marginBottom:"6px"},Ns={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Vs={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Rn={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},En={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Ln=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Bn={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Wn={fontSize:"11px",color:"var(--bim-muted, #888)"},Us={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},yo=({selectedNodeId:t,...n})=>{const[o,r]=u.useState("loading"),[s,i]=u.useState(null);return u.useEffect(()=>{let l=!1;return Gs().then(c=>{l||(c?(i(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),o==="loading"?e.jsx("div",{style:$n,children:"加载图组件中…"}):o==="missing"||!s?e.jsxs("div",{style:$n,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Ys,{modules:s,selectedNodeId:t,...n})};async function Gs(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const Ys=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:x,Position:f,BaseEdge:h,EdgeLabelRenderer:p,getSmoothStepPath:b,dagre:v}=l,g=u.useMemo(()=>({lineage:_=>{var D,L,T,H;const k=((D=_.data)==null?void 0:D.stepPosition)??.85,[I,E,z]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:k,borderRadius:5}),C=!!((L=_.data)!=null&&L.isSibling),B=C?E:_.targetX-18,P=C?z:_.targetY-12,W=(T=_.data)==null?void 0:T.labelStyle,F=(H=_.data)==null?void 0:H.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(h,{id:_.id,path:I,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&e.jsx(p,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${B}px,${P}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...F,...W},children:_.label})})]})}}),[h,p,b]),y=u.useMemo(()=>({version:_=>{const k=_.data,I=k.kind==="hypothetical",E=k.status==="lost",z=k.isSelected,C=k.bridge,B=k.borderColor??"#888",P=C||I?"dashed":"solid",W=C?.5:E?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${P} ${z?"#0078d4":B}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:W,boxShadow:z?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":I||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(x,{type:"target",position:f.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:I||!k.renderLink?k.label:k.renderLink(k.bookId,k.label)}),k.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:k.description}),k.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:bo(k.yearText,void 0,k.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(x,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[x,f]),{convert:m}=O(),{rfNodes:S,rfEdges:w}=u.useMemo(()=>Ks(t,v,n,i,m),[t,v,n,i,m]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(c,{nodes:S,edges:w,nodeTypes:y,edgeTypes:g,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Ks(t,n,o,r,s=i=>i??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(y=>[y.id,y.color??"#888"]));for(const y of t.nodes)a.setNode(y.id,{width:160,height:90});const x=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const y of t.edges)y.kind==="derive"&&(x.has(y.relation)||a.setEdge(y.source,y.target));n.layout(a);const f=t.nodes.map(y=>{const m=a.node(y.id),S=r&&y.id===r,w={kind:y.kind,label:s(y.label),bookId:y.kind==="book"?y.id:void 0,yearText:s(y.year_text??qs(y)),uncertain:y.year_uncertain,category:y.category,status:y.status,borderColor:y.group?d.get(y.group):void 0,renderLink:o,isSelected:S,description:s(y.description),bridge:y.bridge};return{id:y.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:w,draggable:!1,selected:S}}),h=.78,p=.06,b=new Map;for(const y of t.edges)y.kind==="derive"&&(b.has(y.source)||b.set(y.source,[]),b.get(y.source).push(y));const v=new Map;for(const[y,m]of b){if(m.length<=1)continue;const S=[...m].sort((j,_)=>{var E,z;const k=((E=a.node(j.target))==null?void 0:E.y)??0,I=((z=a.node(_.target))==null?void 0:z.y)??0;return k-I}),w=S.length;S.forEach((j,_)=>{const k=(_-(w-1)/2)*p;v.set(j.id,h+k)})}const g=t.edges.map(y=>Js(y,v.get(y.id),s));return{rfNodes:f,rfEdges:g}}function Js(t,n,o=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",i=Xs(t.confidence),l={type:"arrowclosed",color:i,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:o(t.relation),data:{labelStyle:{color:"#444"},isSibling:s,stepPosition:n},style:{stroke:i,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function qs(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Xs(t){switch(t){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const $n={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},vo=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:x,style:f})=>{var m;const[h,p]=u.useState(n),b=S=>{p(S),i==null||i(S)},v=(()=>{if(!a)return[];const S=Object.entries(a);return S.length===0||a.all?S:[...S,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),g=!!(c&&v.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const y=l?(m=a==null?void 0:a[l])==null?void 0:m.description:void 0;return e.jsxs("div",{className:x,style:f,children:[e.jsxs("div",{style:Zs,children:[e.jsx("button",{onClick:()=>b("list"),style:ht(h==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:ht(h==="graph"),children:"关系图"}),g&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),v.map(([S,w])=>{const j=d==null?void 0:d[S];return e.jsxs("button",{onClick:()=>c==null?void 0:c(S),style:ht(l===S),title:w.description,children:[w.label,j!=null?` ${j}`:""]},S)})]})]}),g&&y&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:y}),h==="list"?e.jsx(mo,{graph:t,renderLink:o}):e.jsx(yo,{graph:t,renderLink:o,height:r,selectedNodeId:s})]})},Zs={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},ht=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),Rt=({style:t})=>{const n=u.useContext(Ze);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:"简"})]})},Et=({href:t,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:i=>{i.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:i=>{i.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:o,height:o,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})}),Qs=`
|
|
1
|
+
"use strict";var Co=Object.create;var Jt=Object.defineProperty;var Io=Object.getOwnPropertyDescriptor;var zo=Object.getOwnPropertyNames;var To=Object.getPrototypeOf,Ro=Object.prototype.hasOwnProperty;var Eo=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of zo(n))!Ro.call(t,s)&&s!==o&&Jt(t,s,{get:()=>n[s],enumerable:!(r=Io(n,s))||r.enumerable});return t};var De=(t,n,o)=>(o=t!=null?Co(To(t)):{},Eo(n||!t||!t.__esModule?Jt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("./storage-entry-DpzAR0M4.cjs"),e=require("react/jsx-runtime"),u=require("react"),Lo=require("react-markdown"),Bo=require("remark-gfm"),Wo=require("react-dom"),$o=t=>`/book-index?id=${t}`,Fn=u.createContext($o);function Ao({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(Fn.Provider,{value:o,children:n})}function ve(){return u.useContext(Fn)}function Le(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Fo(t,n){return Le(t).includes(n)}const Mn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Mo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Po={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Qe=u.createContext(null),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:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評論"},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:"圖片資源"}},Ho={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:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评论"},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:"图片资源"}},Oo={"zh-Hant":Pn,"zh-Hans":Ho},Hn="bim-locale";function Do(){try{const t=localStorage.getItem(Hn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function No(t){try{localStorage.setItem(Hn,t)}catch{}}const Vo="zh-Hans",Uo=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??Vo),i=t??r;u.useEffect(()=>{if(t)return;const x=Do();x&&x!==r&&s(x)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(x=>{const f=x.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>x=>x)}):c(null)},[i]);const a=u.useCallback(x=>{s(x),No(x),n==null||n(x)},[n]),d=u.useMemo(()=>({locale:i,setLocale:a,messages:Oo[i],converter:l}),[i,a,l]);return e.jsx(Qe.Provider,{value:d,children:o})};function P(){const t=u.useContext(Qe);return(t==null?void 0:t.messages)??Pn}const Go=2e3;function O(){const t=u.useContext(Qe),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 c=r.current.get(l);if(c!==void 0)return c;const a=o(l);if(r.current.size>=Go){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function et(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Yo(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 Ko(){return{id:"",name:"",url:"",type:"text",details:""}}const mt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=P(),[l,c]=u.useState(null),a=[{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}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],x=m=>{if(!s)return!0;const S=Le(m);return s==="text"?S.includes("text"):s==="image"?S.includes("image")||S.includes("physical"):s==="physical"?S.includes("physical"):S.includes(s)},f=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>x(m)),h=()=>{const m=Ko();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((S,w)=>w!==m)),c(null)},b=(m,S,w)=>{const j=[...t];if(j[m]={...j[m],[S]:w},S==="url"&&!j[m].id){const _=Yo(w);_&&(j[m].id=_)}n(j)},v=(m,S,w)=>{const _={...t[m].metadata||{}};w?_[S]=w:delete _[S],b(m,"metadata",Object.keys(_).length>0?_:void 0)},g=(m,S)=>{const w=S.trim()?S.split(/[,,、]/).map(j=>j.trim()).filter(Boolean):void 0;b(m,"structure",w)},y=(m,S,w)=>{const _=t[m].coverage||{level:1,ranges:""};S==="level"?_.level=parseInt(w)||1:_.ranges=w,b(m,"coverage",_.ranges?_:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:m,originalIndex:S})=>{var w,j,_;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Jo(m.type??"text"),color:"#fff"},children:(()=>{var I,E;const k=Le(m);return k.length===0?m.type??"text":k.length===1?((I=a.find(z=>z.value===k[0]))==null?void 0:I.label)??k[0]:k.includes("text")&&k.includes("image")?((E=a.find(z=>z.value==="text+image"))==null?void 0:E.label)??"text+image":k.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:k=>k.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&qo(S,r==null?void 0:r[S],o,i),e.jsx("button",{onClick:k=>{k.stopPropagation(),p(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Fo(m,"image")&&m.url&&Xo(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ne,children:[e.jsx("span",{style:Ve,children:i.label.type}),e.jsx("select",{value:m.type,onChange:k=>b(S,"type",k.target.value),style:{...ke,flex:1},children:a.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]}),e.jsxs("label",{style:Ne,children:[e.jsx("span",{style:Ve,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:k=>b(S,"root_type",k.target.value),style:{...ke,flex:1},children:d.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:k=>b(S,"id",k.target.value),placeholder:i.editor.idAutoExtract,style:{...ke,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:k=>b(S,"name",k.target.value),placeholder:i.editor.resourceName,style:{...ke,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:k=>b(S,"url",k.target.value),placeholder:i.editor.resourceUrl,style:ke}),e.jsx("input",{type:"text",value:((w=m.structure)==null?void 0:w.join("、"))||"",onChange:k=>g(S,k.target.value),placeholder:i.editor.structurePlaceholder,style:ke}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ne,children:[e.jsx("span",{style:Ve,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((j=m.coverage)==null?void 0:j.level)??"",onChange:k=>y(S,"level",k.target.value),placeholder:"1",style:{...ke,width:"60px"}})]}),e.jsxs("label",{style:{...Ne,flex:1},children:[e.jsx("span",{style:Ve,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((_=m.coverage)==null?void 0:_.ranges)||"",onChange:k=>y(S,"ranges",k.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...ke,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:k=>b(S,"details",k.target.value),placeholder:i.editor.detailsPlaceholder,style:{...ke,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(([k,I])=>{var E;return e.jsxs("label",{style:{...Ne,gap:"4px"},children:[e.jsx("span",{style:{...Ve,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[k])||"",onChange:z=>v(S,k,z.target.value),placeholder:I,style:{...ke,flex:1}})]},k)})})]})]})]})]},S)}),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 Jo(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function qo(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 Xo(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 ke={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ne={display:"flex",alignItems:"center",gap:"6px"},Ve={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Zo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Qo(t){try{const n=new URL(t).hostname;return Zo[n]}catch{return}}const qt={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function er(t){return t.includes("text")&&t.includes("image")?qt["text+image"]:qt[t[0]||"physical"]}const Xt={text:0,image:1,physical:2};function it(t){return t.length===0?"physical":[...t].sort((n,o)=>(Xt[n]??99)-(Xt[o]??99)).join("+")}function tr(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[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 c=n(l.name);if(!c)continue;const[a,d]=c,x=`${a}|${it(Le(l))}`;o.has(x)||o.set(x,{base:{...l,name:a,url:"",volumes:[]},volumes:[]}),o.get(x).volumes.push({volume:d,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,c)=>l.volume-c.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 c=n(t[l].name),a=c&&`${c[0]}|${it(Le(t[l]))}`,d=`${i.base.name}|${it(Le(i.base))}`;a===d&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const kt=({items:t,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const i=P(),{convert:l}=O(),c=u.useMemo(()=>tr(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.useMemo(()=>{const g=new Map,y=[];for(const m of c){const S=m.group;S?(g.has(S)||g.set(S,[]),g.get(S).push(m)):y.push(m)}for(const m of g.values())m.sort((S,w)=>{const j=_=>_.group_role==="origin"?0:_.group_role==="mirror"?1:2;return j(S)-j(w)});return{mirrorGroups:g,ungroupedItems:y}},[c]),x={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical},f=g=>x[g]?x[g]:g.split("+").map(y=>x[y]||y).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((g,y)=>e.jsx(xt,{item:g},g.id||y))});const h=(g,y)=>{const m=o==null?void 0:o[g],S=(m==null?void 0:m.label)||g,w=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(S)}),w&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(w)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((j,_)=>e.jsx(xt,{item:j,onNavigate:r,renderLink:s},j.id||_))})]},`group-${g}`)},p=new Map;for(const g of d){const y=it(Le(g));p.has(y)||p.set(y,[]),p.get(y).push(g)}const b=["text","image","text+image","physical"],v=[...b.filter(g=>p.has(g)),...[...p.keys()].filter(g=>!b.includes(g)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([g,y])=>h(g,y)),v.map(g=>{const y=p.get(g),m=er(g.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:f(g)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:y.map((S,w)=>e.jsx(xt,{item:S,onNavigate:r,renderLink:s},S.id||w))})]},g)})]})};function nr(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 or(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 rr(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 ir={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},xt=({item:t})=>{const n=P(),{convert:o}=O(),[r,s]=u.useState(!1),i=u.useMemo(()=>(t.url?Qo(t.url):void 0)||o(t.name),[t.url,t.name,o]),l=u.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||rr(b)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,x=t.expected_volumes??(c?a+d:0),f=t.color_mode?{...ir[t.color_mode],label:n.colorMode[t.color_mode]}:null,h=t.details&&!c?o(t.details):null,p={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),h&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:h}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",x,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=or(t.metadata);return b?nr(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const v=b.status==="missing";return b.url&&!v?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:v?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1},children:b.volume},b.volume)})})]})},On=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const c=P(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,x=(n==null?void 0:n.repoPath)||"",f=x?x.split(/[/\\]/).pop()||x:"",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)"},p={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):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:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:f||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:x?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:x,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},dt="bim-search-history",Zt=10,Qt=8;function Je(){try{const t=localStorage.getItem(dt);return t?JSON.parse(t):[]}catch{return[]}}function sr(t){try{const n=Je().filter(o=>o!==t);n.unshift(t),n.length>Zt&&(n.length=Zt),localStorage.setItem(dt,JSON.stringify(n))}catch{}}function lr(t){try{const n=Je().filter(o=>o!==t);localStorage.setItem(dt,JSON.stringify(n))}catch{}}function ar(){try{localStorage.removeItem(dt)}catch{}}const Dn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=P(),c=i??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,x]=u.useState(!1),[f,h]=u.useState([]),[p,b]=u.useState(-1),[v,g]=u.useState(Je),y=u.useRef(null),m=u.useRef(null),S=u.useRef(null),w=u.useRef(!1);u.useEffect(()=>{b(-1);const C=n.trim();if(!C){h(v.map(W=>({type:"history",text:W})));return}if(!t.searchAll){h([]);return}let B=!1;const H=setTimeout(()=>{t.searchAll(C,Qt).then(W=>{if(B)return;const F=[...W.works,...W.books,...W.collections,...W.entities??[]];h(F.slice(0,Qt).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{B||h([])})},80);return()=>{B=!0,clearTimeout(H)}},[n,v,t]),u.useEffect(()=>{const C=B=>{S.current&&!S.current.contains(B.target)&&x(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),u.useEffect(()=>{const C=B=>{var H,W;if(B.key==="/"&&document.activeElement!==y.current){const F=(H=document.activeElement)==null?void 0:H.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;B.preventDefault(),(W=y.current)==null||W.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const j=u.useCallback(C=>{C.trim()&&(sr(C.trim()),g(Je())),r(C),x(!1)},[r]),_=u.useCallback(C=>{C.type==="history"?(o(C.text),j(C.text)):C.entry&&(s?(s(C.entry),x(!1)):(o(C.text),j(C.text)))},[o,j,s]),k=u.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&j(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(B=>(B+1)%f.length);break;case"ArrowUp":C.preventDefault(),b(B=>(B-1+f.length)%f.length);break;case"Enter":C.preventDefault(),p>=0&&p<f.length?_(f[p]):j(n);break;case"Escape":C.preventDefault(),x(!1);break}},[d,f,p,n,j,_]),I=u.useCallback((C,B)=>{B.stopPropagation(),lr(C),g(Je()),h(H=>H.filter(W=>!(W.type==="history"&&W.text===C)))},[]),E=u.useCallback(C=>{C.stopPropagation(),ar(),g([]),h([])},[]);u.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const z=!n.trim()&&v.length>0;return e.jsxs("div",{ref:S,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:y,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),x(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{x(!0)},onKeyDown:k,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"}}),d&&f.length>0&&e.jsxs("div",{ref:m,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:[z&&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:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((C,B)=>e.jsxs("div",{onClick:()=>_(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===p?"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:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>I(C.text,H),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}-${B}`))]})]})},Ze="bim-recent-ids",en="bim-recent-entries",tn=50,ut=5,cr=50,dr=200;function qe(){try{const t=localStorage.getItem(Ze);if(t)return JSON.parse(t);const n=localStorage.getItem(en);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ze,JSON.stringify(o)),localStorage.removeItem(en),o}return[]}catch{return[]}}function pr(t){try{const n=qe().filter(o=>o!==t);n.unshift(t),n.length>tn&&(n.length=tn),localStorage.setItem(Ze,JSON.stringify(n))}catch{}}function xr(t){try{const n=qe().filter(o=>o!==t);localStorage.setItem(Ze,JSON.stringify(n))}catch{}}function ur(){try{localStorage.removeItem(Ze)}catch{}}const fr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},yt=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,initialQuery:x,onQueryChange:f,headerRight:h})=>{const p=P(),b=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:p.indexType.entity,key:"entities"}],[v,g]=u.useState(x??""),[y,m]=u.useState(null),[S,w]=u.useState(null),[j,_]=u.useState(!1),[k,I]=u.useState(null),[E,z]=u.useState(""),[C,B]=u.useState(!x),[H,W]=u.useState(qe),[F,D]=u.useState([]),[L,$]=u.useState(!1),[X,R]=u.useState(!1),[M,oe]=u.useState(null),[Q,ee]=u.useState(null),le=u.useRef(void 0),ae=u.useRef(!1),U=u.useCallback(async(A,ne)=>{if(!A.trim()){B(!0),m(null),w(null);return}B(!1),_(!0),z("");try{if(t.searchAll){const K=await t.searchAll(A,ne??ut);m(K)}else{const K=["work","book","collection","entity"],Z=await Promise.all(K.map(ie=>t.search(A,ie,{page:1,pageSize:ne??ut})));m({works:Z[0].entries,books:Z[1].entries,collections:Z[2].entries,entities:Z[3].entries,totalWorks:Z[0].total,totalBooks:Z[1].total,totalCollections:Z[2].total,totalEntities:Z[3].total})}}catch(K){z(K instanceof Error?K.message:String(K)),m(null)}finally{_(!1)}},[t]);u.useEffect(()=>{let A=!1;const ne=()=>{var N,ce;const K=["work","book","collection","entity"],Z=Promise.all(K.map(fe=>t.loadEntries(fe,{page:1,pageSize:1}).catch(()=>({total:0})))),ie=((N=t.getResourceCounts)==null?void 0:N.call(t).catch(()=>null))??Promise.resolve(null),T=((ce=t.getSubtypeStats)==null?void 0:ce.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([Z,ie,T]).then(([fe,te,Se])=>{A||(oe({works:fe[0].total,books:fe[1].total,collections:fe[2].total,entities:fe[3].total,hasText:te==null?void 0:te.hasText,hasImage:te==null?void 0:te.hasImage}),Se&&ee(Se))})};return t.getCounts?t.getCounts().then(K=>{var Z,ie;A||(oe({works:K.works,books:K.books,collections:K.collections,entities:K.entities,hasText:(Z=K.resourceCounts)==null?void 0:Z.hasText,hasImage:(ie=K.resourceCounts)==null?void 0:ie.hasImage}),K.subtypeStats&&ee(K.subtypeStats))}).catch(()=>{A||ne()}):ne(),()=>{A=!0}},[t]),u.useEffect(()=>{ae.current||!(x!=null&&x.trim())||(ae.current=!0,U(x))},[x,U]);const q=u.useCallback(A=>{if(g(A),!A.trim()){f==null||f(A),B(!0),m(null),w(null);return}le.current&&clearTimeout(le.current),le.current=setTimeout(()=>{w(null),f==null||f(A),U(A)},dr)},[U,f]),Te=u.useCallback(A=>{le.current&&clearTimeout(le.current),f==null||f(A),U(A)},[U,f]),$e=u.useCallback(A=>{w(A),U(v,cr)},[v,U]);u.useEffect(()=>{if(!H.length){D([]);return}let A=!1;return $(!0),Promise.all(H.slice(0,10).map(async ne=>{var K,Z,ie;try{if(t.getEntry){const N=await t.getEntry(ne);if(N)return N}const T=await t.getItem(ne);if(T){const N=T.authors;return{id:ne,title:T.title||ne,type:T.type||"work",author:(K=N==null?void 0:N[0])==null?void 0:K.name,dynasty:(Z=N==null?void 0:N[0])==null?void 0:Z.dynasty,role:(ie=N==null?void 0:N[0])==null?void 0:ie.role,edition:T.edition||void 0}}}catch{}return{id:ne,title:ne,type:"work",notFound:!0}})).then(ne=>{A||(D(ne),$(!1))}),()=>{A=!0}},[H,t]);const Ie=A=>{I(A.id),pr(A.id),W(qe()),r==null||r(A)},ue=A=>{xr(A),W(qe())},je=()=>{ur(),W([])},ze=A=>b.find(ne=>ne.type===A),Ae=y&&(y.works.length>0||y.books.length>0||y.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:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&e.jsx(On,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Dn,{transport:t,value:v,onChange:q,onSearch:Te,onEntrySelect:Ie}),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:p.action.newEntry})]}),M&&C&&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:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.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:"·"}),p.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:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.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:j?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.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})]}):C?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.loading}):F.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:p.search.recentBrowse}),e.jsx("button",{onClick:je,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:p.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:F.slice(0,X?10:3).map(A=>A.notFound?e.jsx(gr,{id:A.id,onRemove:ue,t:p},A.id):e.jsx(nn,{entry:A,selected:k===A.id,onClick:Ie,getConfig:ze,onRemove:ue},A.id))}),!X&&F.length>3&&e.jsx("button",{onClick:()=>R(!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:p.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:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):Ae?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:A,icon:ne,name:K,key:Z})=>{const ie=y[Z]??[],T=fr[Z],N=y[T]??0;if(ie.length===0)return null;const fe=!(S===A)&&N>ut;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:[ne," ",K,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[N," ",p.unit.items]})]}),fe&&e.jsx("button",{onClick:()=>$e(A),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ie.map(te=>e.jsx(nn,{entry:te,selected:k===te.id,onClick:Ie,getConfig:ze,query:v},te.id))})]},A)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:et(p.search.noResultsFor,{query:v})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},nn=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=P(),{convert:c}=O(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(x=>{const f=typeof x=="string"?x:x==null?void 0:x.book_title;return f==null?void 0:f.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:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title: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:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,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:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:x=>{x.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:"→"})]})},gr=({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 hr(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 br({data:t}){const{convert:n}=O(),{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 mr({alt_names:t}){const{convert:n}=O(),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 c=r.indexOf(i),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children: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((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},i)})})}function yr({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 vr({works:t,transport:n,onNavigate:o,renderLink:r}){const s=P(),{convert:i}=O(),l=ve(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const p=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const S=await n.getEntriesByIds(p);let w=!0;for(let j=0;j<p.length;j++){const _=S[j];_!=null&&_.title?v.set(p[j],_.title):_!=null&&_.primary_name?v.set(p[j],_.primary_name):w=!1}if(w)return v}catch{}const g=[...p],y=8,m=new Array(y).fill(0).map(async()=>{for(;g.length;){const S=g.shift();if(!S)break;if(!v.has(S))try{if(n.getEntry){const _=await n.getEntry(S);if(_!=null&&_.title){v.set(S,_.title);continue}}const w=await n.getItem(S),j=w&&(w.title||w.primary_name)||S;v.set(S,j)}catch{v.set(S,S)}}});return await Promise.all(m),v})().then(v=>{h||a(v)}),()=>{h=!0}},[t,n]);const d=new Map;for(const h of t){const p=h.role||"";d.has(p)||d.set(p,[]),d.get(p).push(h)}const x=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((h,p)=>{const b=x.indexOf(h),v=x.indexOf(p);return b===-1&&v===-1?h.localeCompare(p):b===-1?1:v===-1?-1:b-v});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),f.map(h=>{const p=d.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:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((b,v)=>{const g=i(c.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,g)},v):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},v):e.jsx("li",{children:g},v)})})]},h)})]})}const Nn=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var x;const i=P(),{convert:l}=O();let c=!1;try{c=Y.extractStatus(t.id)==="draft"}catch{}const a=hr(t),d=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(br,{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}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&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})]}),a&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(mr,{alt_names:t.alt_names}),e.jsx(yr,{data:t}),((x=t.description)==null?void 0:x.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(vr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},Vn={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},jr={...Vn,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},vt=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=O(),i=n?jr:Vn;return e.jsx("div",{className:r,style:o,children:e.jsx(Lo,{remarkPlugins:[Bo],components:i,children:s(t)})})},Sr=["〇","一","二","三","四","五","六","七","八","九"],on=["","十","百","千"];function Un(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]),c=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&i===0?r+=on[c]:r+=Sr[l]+on[c])}return r}function kr({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 wr({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 _r({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 be({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 we({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 Gn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=O();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const c=s(i.name),a=i.entity_id?e.jsx(ye,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});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),"〕"]}),a,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},l)})})}function ye({id:t,label:n,onNavigate:o,renderLink:r}){const s=ve();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 Cr({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:x}){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})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(kr,{type:r}),e.jsx(wr,{isDraft:s}),e.jsx(_r,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(Gn,{authors:i,type:r,onNavigate:d,renderLink:x}),c]})]})}function Yn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=P(),{convert:l}=O();if(!t.length)return null;const[c,a]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,x)=>{const f=c===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?null:x),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:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!f&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ye,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),f&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(we,{label:i.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(we,{label:i.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(we,{label:i.label.edition,children:l(d.edition)})]}),d.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(d.summary)})]}),d.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(d.comment)})]}),d.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(d.additional_comment)})]})]})]},x)})})]})}function Ir({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(Yn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function wt({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(Yn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Kn({label:t,items:n}){const{convert:o}=O();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{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 zr({items:t}){const n=P();return e.jsx(Kn,{label:n.section.aliases,items:t})}function Tr({items:t}){const n=P();return e.jsx(Kn,{label:n.section.attachedTexts,items:t})}function Rr({items:t}){const n=P(),{convert:o}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{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 Er({items:t}){const n=P(),{convert:o}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{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 Lr({items:t}){const n=P(),{convert:o}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{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 rn({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=O(),[l,c]=u.useState([]);return u.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.getItem(d).then(x=>({id:d,title:x?x.title:void 0,edition:x?x.edition:void 0,type:x?x.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(be,{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(a=>({id:a}))).map(a=>{const d=a.edition?`${i(a.title)||a.id}(${i(a.edition)})`:i(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ye,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function ft({book:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=O(),[i,l]=u.useState(!1),c=t.resources&&t.resources.length>0,a=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:"6px 12px",borderBottom:c&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(ye,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),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:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(kt,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Br({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const l=P(),{convert:c}=O(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(v=>({id:v})));return}let b=!1;return Promise.all(t.map(v=>o.getItem(v).then(g=>({id:v,title:g?g.title:void 0,edition:g?g.edition:void 0,resources:g?g.resources:void 0,resource_groups:g?g.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{b||d(v)}),()=>{b=!0}},[t,o]),!t.length)return null;const x=a.length?a:t.map(b=>({id:b})),f=new Map(x.map(b=>[b.id,b])),h=n==null?void 0:n.version_graph,p=Wr(t,h);return e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(b=>{const v=f.get(b);return v?e.jsx(ft,{book:v,onNavigate:r,renderLink:s},b):null})}),p.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(v=>{const g=f.get(v);return g?e.jsx(ft,{book:g,onNavigate:r,renderLink:s},v):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.map(b=>e.jsx(ft,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Wr(t,n){var g,y;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(g=n.collections)==null?void 0:g[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,l=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=m=>{if(a.has(m))return!0;const S=n.node_groups[m];return S!=null&&c.has(S)},x=[],f=new Map,h=[];for(const m of t)if(!((y=n.excluded_books)!=null&&y.includes(m)))if(d(m))x.push(m);else{const S=n.node_groups[m];S?(f.has(S)||f.set(S,[]),f.get(S).push(m)):h.push(m)}if(h.length+[...f.values()].reduce((m,S)=>m+S.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),v=[...f.entries()].map(([m,S])=>{const w=b.get(m);return{id:m,label:(w==null?void 0:w.label)??m,description:w==null?void 0:w.description,ids:S}});return h.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:x,groupedIds:v}}function $r({workData:t,onNavigate:n,renderLink:o}){var l,c,a,d;const r=P(),{convert:s}=O(),i=!!((l=t.description)!=null&&l.text)||!!t.parent_work;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:"6px 14px",borderBottom:i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ye,{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)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Un(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Gn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(vt,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(we,{label:r.label.parentWork,children:e.jsx(ye,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Ar({items:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=O();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(ye,{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:et(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const pt=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:l,className:c,style:a})=>{var B,H,W,F,D,L,$,X;const d=P(),{convert:x}=O(),[f,h]=u.useState(null),[p,b]=u.useState(!1),[v,g]=u.useState(null),[y,m]=u.useState(null),[S,w]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let R=!1;return b(!0),g(null),o.getItem(n).then(M=>{R||(M?h(M):g(d.misc.notFoundEntry))}).catch(M=>{R||g(M instanceof Error?M.message:d.misc.loadFailed)}).finally(()=>{R||b(!1)}),()=>{R=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){m(null),w([]);return}let R=!1;const M=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(M?o.getItem(M).then(oe=>{!R&&oe&&oe.type==="work"&&m(oe)}).catch(()=>{}):m(null),j.type==="book"){const oe=j;oe.contained_in&&oe.contained_in.length>0?Promise.all(oe.contained_in.map(Q=>{const ee=typeof Q=="string"?Q:Q.id,le=typeof Q=="string"?void 0:Q.volume_index;return o.getItem(ee).then(ae=>({id:ee,title:ae&&ae.title||ee,volume_index:le})).catch(()=>({id:ee,title:ee,volume_index:le}))})).then(Q=>{R||w(Q)}):w([])}else w([]);return()=>{R=!0}},[j,o]),p)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((R,M)=>e.jsx("div",{style:{height:M===1?"32px":"16px",width:`${R}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},M))})});if(v)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!j)return null;if(j.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Nn,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const _=j.type==="book"?j:null,k=j.type==="collection"?j:null,I=j.type==="work"?j:null;let E=!1;try{E=Y.extractStatus(j.id)==="draft"}catch{}let z="";j.measure_info?z=x(j.measure_info):(B=j.juan_count)!=null&&B.number?z=Un(j.juan_count.number)+d.unit.juan:(H=j.juan_count)!=null&&H.description&&(z=x(j.juan_count.description));const C=[];return(W=j.publication_info)!=null&&W.year&&C.push(e.jsx(we,{label:d.label.year,children:j.publication_info.year},"year")),(F=j.current_location)!=null&&F.name&&C.push(e.jsx(we,{label:d.label.currentLocation,children:x(j.current_location.name)},"loc")),(D=j.page_count)!=null&&D.description&&C.push(e.jsx(we,{label:d.label.pageCount,children:j.page_count.description},"page")),_!=null&&_.edition&&C.push(e.jsx(we,{label:d.label.edition,children:x(_.edition)},"ver")),I!=null&&I.parent_work&&C.push(e.jsx(we,{label:d.label.parentWork,children:e.jsx(ye,{id:I.parent_work.id,label:x(I.parent_work.title),onNavigate:r,renderLink:s})},"pw")),I!=null&&I.parent_works&&I.parent_works.length>0&&!I.parent_work&&C.push(e.jsx(we,{label:d.label.parentWork,children:I.parent_works.map((R,M)=>e.jsxs("span",{children:[M>0&&"、",e.jsx(ye,{id:R,onNavigate:r,renderLink:s})]},R))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Cr,{id:j.id,title:x(j.title),edition:j.edition?x(j.edition):void 0,type:j.type,isDraft:E,authors:j.authors,volumeText:z,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=j.description)==null?void 0:L.text)&&e.jsx(vt,{text:j.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),j.appendix&&j.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:j.appendix.map((R,M)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:x(R.title)}),e.jsx(vt,{text:R.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},M))}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.containedIn}),e.jsx(Ar,{items:S,onNavigate:r,renderLink:s})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.belongsToWork}),e.jsx($r,{workData:y,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(Rr,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(zr,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Tr,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(Ir,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(wt,{items:j.emendated_by,onNavigate:r,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.resources}),e.jsx(kt,{items:j.resources,resourceGroups:j.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(Er,{items:_.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(Lr,{items:k.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(rn,{title:d.section.relatedVersions,ids:_.related_books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(rn,{title:d.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(be,{children:[d.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(R=>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(ye,{id:R.id,label:x(R.title),onNavigate:r,renderLink:s})},R.id))})]}),((($=I==null?void 0:I.books)==null?void 0:$.length)||0)+(((X=I==null?void 0:I.collections)==null?void 0:X.length)||0)>0&&e.jsx(Br,{ids:[...(I==null?void 0:I.books)||[],...(I==null?void 0:I.collections)||[]],workData:I,transport:o,onNavigate:r,renderLink:s,footer:l}),(I==null?void 0:I.related_works)&&I.related_works.length>0&&(()=>{const R=[],M=I.related_works.filter(U=>U.relation==="part_of"),oe=I.related_works.filter(U=>U.relation==="has_part"),Q=I.related_works.filter(U=>U.relation==="has_adaptation"),ee=I.related_works.filter(U=>U.relation==="text_carried_by"),le=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ae=I.related_works.filter(U=>!U.relation||!le.has(U.relation));return M.length>0&&R.push({label:d.section.belongsToWork,items:M}),oe.length>0&&R.push({label:d.section.containedWorks,items:oe}),Q.length>0&&R.push({label:d.section.adaptations,items:Q}),ee.length>0&&R.push({label:d.section.derivativeWorks,items:ee}),ae.length>0&&R.push({label:d.section.relatedWorks,items:ae}),R.map(U=>e.jsxs("div",{children:[e.jsxs(be,{children:[U.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",U.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:U.items.map(q=>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(ye,{id:q.id,label:x(q.title),onNavigate:r,renderLink:s})},q.id))})]},U.label))})()]})};function Fr({data:t}){const n=P(),{convert:o}=O(),{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 Mr({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:sn(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:sn(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 sn(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 Pr({id:t,label:n,onNavigate:o,renderLink:r}){const s=ve();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 Hr(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 ln({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=P(),{convert:i}=O(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?Hr(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[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(d=>i(d)).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:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Pr,{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 _t=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const c=P(),[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,v]=u.useState(null),[g,y]=u.useState(""),m=t||a;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let k=!1;return f(!0),p(null),o.getCollectionCatalog(n).then(I=>{k||(I?d(I):p(c.catalog.notFound))}).catch(I=>{k||p(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{k||f(!1)}),()=>{k=!0}},[t,n,o,c]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,w=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const k=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(k).size<k.length},[m]),j=u.useMemo(()=>{if(!m)return[];let k=m.books;if(b&&(k=k.filter(I=>I.section===b)),g.trim()){const I=g.trim().toLowerCase();k=k.filter(E=>E.title.toLowerCase().includes(I)||E.sub_items&&E.sub_items.some(z=>z.toLowerCase().includes(I))||E.edition&&E.edition.toLowerCase().includes(I))}return k},[m,b,g]),_=u.useMemo(()=>{if(!w)return null;const k=[],I=new Map;for(const z of j){if(!z.volumes||z.volumes.length===0)continue;const C=z.volumes[0];I.has(C)||I.set(C,[]),I.get(C).push(z)}const E=[...I.keys()].sort((z,C)=>z-C);for(const z of E)k.push({volume:z,books:I.get(z)});return k},[j,w]);return x?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.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(Fr,{data:m}),S&&e.jsx(Mr,{sections:m.sections,activeSection:b,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:k=>y(k.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:[j.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[_?_.map((k,I)=>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:et(c.catalog.volume,{n:k.volume})}),k.books.map((E,z)=>e.jsx(ln,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${k.volume}-${z}`))]},`${k.volume}-${I}`)):j.map((k,I)=>e.jsx(ln,{book:k,onNavigate:r,renderLink:s,showVolumes:!0},I)),j.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},We=()=>{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)})},pe=6,nt=7,Or=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),x=u.useRef(null),f=u.useRef(null),h=u.useRef(null),p=u.useCallback(()=>{const g=f.current,y=h.current;if(!g||!y)return;const m=g.getBoundingClientRect(),S=y.getBoundingClientRect(),w=window.innerHeight,j=document.documentElement.clientWidth;let _=o;o==="top"&&m.top-S.height-nt<8&&(_="bottom"),o==="bottom"&&m.bottom+S.height+nt>w-8&&(_="top");const k=_==="top"?m.top-S.height-nt:m.bottom+nt;let I=m.left+m.width/2-S.width/2;I=Math.max(8,Math.min(I,j-S.width-8)),d({left:I,top:k,placement:_})},[o]),b=u.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>c(!0),r)},[r]),v=u.useCallback(()=>{x.current&&clearTimeout(x.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const g=requestAnimationFrame(p);return()=>cancelAnimationFrame(g)},[l,p]),u.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:b,onMouseLeave:v,onFocus:b,onBlur:v,style:{display:"inline-block",...i},children:n}),l&&Wo.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth: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:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-pe,width:0,height:0,...a.placement==="top"?{bottom:-pe,borderTop:`${pe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${pe}px solid transparent`,borderRight:`${pe}px solid transparent`}:{top:-pe,borderBottom:`${pe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${pe}px solid transparent`,borderRight:`${pe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${pe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${pe-1}px solid transparent`,borderRight:`${pe-1}px solid transparent`}:{top:-5,borderBottom:`${pe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${pe-1}px solid transparent`,borderRight:`${pe-1}px solid transparent`}}})]})]}),document.body)]})},an={A:"fine",B:"rough",C:"rough",D:"ocr"};function Dr(t){return typeof t!="string"?null:t in Mn?t:t in an?an[t]:null}const Nr={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function se(t){return typeof t!="string"?"":Nr[t]??t}const Vr=["〇","一","二","三","四","五","六","七","八","九"],cn=["","十","百","千"],Ur=["","萬","億"];function Jn(t){if(t===0)return"〇";if(t<0)return`負${Jn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Gr(s,r>0)+Ur[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Gr(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],c=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&i===0&&!n?s+=cn[c]:s+=Vr[l]+cn[c]}return s.replace(/〇$/,"")}let Xe=null,ot=null;const at=new Set;function Yr(){return Xe?Promise.resolve():ot||(ot=import("opencc-js/t2cn").then(t=>{Xe=t.Converter({from:"tw",to:"cn"}),at.forEach(n=>n())}).catch(()=>{Xe=t=>t,at.forEach(t=>t())}),ot)}function Ce(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Xe)return;const n=()=>t(o=>o+1);return at.add(n),Yr(),()=>{at.delete(n)}},[]),Xe??(n=>n)}function Pe(t,n){return n(t).toLowerCase()}const Ct="#fff59d";function He(t,n,o){if(!n)return t;const r=Pe(n,o);if(!r)return t;const s=Pe(t,o);if(s.length!==t.length)return t;const i=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){i.push(t.slice(l));break}a>l&&i.push(t.slice(l,a)),i.push(e.jsx("mark",{style:{background:Ct,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:i})}function It(t,n,o,r){if(!n)return!0;const s=Pe(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"&&Pe(l,r).includes(s))}function Kr(t,n,o){return n?Pe(t,o).includes(Pe(n,o)):!0}const zt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Jr={考证:"#5d6d7e"};function qr(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 qn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=qr(t),d=!!(r!=null&&r.vol_label)&&!a.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)":c?`${Ct}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:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&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 Xn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Xn(r,n)))}function Zn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+Zn(i),0))||0;return n+o}function Xr(t,n){const o=[],r=l=>{var c;o.push(...l.files),(c=l.children)==null||c.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 Qn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=Xn(t,n||""),c=Xr(t,i),a=typeof c=="number"&&c>0,d=c===0,[x,f]=u.useState(l||a),h=Zn(t),p=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!p){const v=t.files[0],g=n===v,y=i[v],m=y===0,S=y==="loading",w=typeof y=="number"&&y>0;return e.jsxs("button",{onClick:()=>{m||o(v)},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)":w?`${Ct}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,w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:y}),S&&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:()=>f(!x),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)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"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,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&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(v=>e.jsx(qn,{file:v,isActive:n===v,onSelect:o,meta:s==null?void 0:s[v],matchState:i[v]},v))}),p&&t.children.map((v,g)=>e.jsx(Qn,{group:v,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function Zr({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((c,a)=>e.jsx(Qn,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},a))}):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(c=>e.jsx(qn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function Qr({type:t}){const n=zt[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 ei({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=O(),s=ve(),i=Ce(),l=v=>{if(!v)return"";const g=r(v);return o?He(g,o,i):g},[c,a]=u.useState(!1),d=!!t.summary,x=!!t.comment,f=!!t.additional_comment,h=!!(t.content&&t.content.length>60),p=d||x||f||h;u.useEffect(()=>{o&&a(!0)},[o]);const b=!c&&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:()=>p&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"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:[Jn(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)})]}),!c&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&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&&!d&&!x&&!f&&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 ti({section:t,highlightQuery:n=""}){const{convert:o}=O(),r=Ce(),s=a=>{if(!a)return"";const d=o(a);return n?He(d,n,r):d},[i,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(Qr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&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&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${zt[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 ni({section:t,highlightQuery:n=""}){const{convert:o}=O(),r=Ce();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`)),i=n?He(s,n,r):s,l=zt[t.type]||"#717171",c=se(t.type)==="序"||se(t.type)==="结语";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${l}40`:void 0,background:c?"var(--bim-bg, #fafafa)":void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&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 oi(t,n,o){const[r,s]=u.useState({});return u.useEffect(()=>{var d;if(!n||t.length===0)return;let i=!1;const l=t.filter(x=>{var f;return!((f=o==null?void 0:o.current)!=null&&f.has(x))}),c={};for(const x of t)(d=o==null?void 0:o.current)!=null&&d.has(x)&&(c[x]=o.current.get(x));if(Object.keys(c).length>0&&s(c),l.length===0)return;const a=async x=>{var f;try{if(n.getEntry){const g=await n.getEntry(x);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(x);if(!h)return null;const p=h.title||x,b=h.authors,v=(f=b==null?void 0:b[0])==null?void 0:f.name;return{title:p,author:v}}catch{return null}};return Promise.all(l.map(async x=>{var h;const f=await a(x);return(h=o==null?void 0:o.current)==null||h.set(x,f),[x,f]})).then(x=>{i||s(f=>{const h={...f};for(const[p,b]of x)h[p]=b;return h})}),()=>{i=!0}},[t.join(","),n]),r}function ri({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=O(),l=ve(),c=Ce(),a=m=>{if(!m)return"";const S=i(m);return s?He(S,s,c):S},[d,x]=u.useState(!1);u.useEffect(()=>{s&&x(!0)},[s]);const f=t.type,h=Jr[f]||"#717171",p=!!t.content,b=t.work_ids||[],v=b.length>1,g=oi(v?b:[],o,r),y=p&&!d&&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:()=>p&&x(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"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?a(t.header_line):a(t.title)}),!d&&y&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(y)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:l(b[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),v&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:h,border:`1px solid ${h}40`,borderRadius:"2px",background:`${h}08`},children:f})]})]}),v&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(m=>{const S=g[m],w=S?`${i(S.title)}${S.author?`(${i(S.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:l(m),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",w]},m)})}),d&&p&&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:a(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:a(t.comment)})]})]})}function ii({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=O(),l=Ce(),c=n.trim(),a=u.useMemo(()=>c?t.sections.filter(f=>It(f,c,!0,l)):t.sections,[t.sections,c,l]),d=t.sections.filter(f=>se(f.type)==="考证").length,x=a.filter(f=>se(f.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:c?`${x} / ${d} 條`:`${d} 條`})]}),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:a.map((f,h)=>e.jsx(ri,{section:f,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},h))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function si({text:t,highlightQuery:n=""}){const{convert:o}=O(),r=Ce(),s=l=>{const c=o(l);return n?He(c,n,r):c},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,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!i[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,x)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},x):e.jsx(u.Fragment,{children:s(d)},x))},c)})})}function li({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=O(),s=ve(),i=Ce(),l=d=>{if(!d)return"";const x=r(d);return o?He(x,o,i):x},c=[];let a=null;for(const d of t)se(d.type)==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):se(d.type)==="书"?(a||(a={category:"",items:[]}),a.items.push(d)):(se(d.type)==="序"||se(d.type)==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),se(d.type)==="结语"&&(c.push(a),a=null));return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,x)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((f,h)=>se(f.type)==="序"||se(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),p.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},h))]},x))})}function ai({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=O(),i=Ce(),[l,c]=u.useState("catalog"),a=o.trim(),d=u.useMemo(()=>a?t.sections.filter(p=>It(p,a,!1,i)):t.sections,[t.sections,a,i]),x=t.sections.filter(p=>se(p.type)==="书").length,f=t.sections.filter(p=>se(p.type)==="诗").length,h=a?d.filter(p=>se(p.type)==="书"||se(p.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(p=>e.jsx("button",{onClick:()=>c(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${f>0?`${f} 首`:`${x} 部書`}`:f>0?`${f} 首`:`${x} 部书`})]}),l==="raw"&&(n?e.jsx(si,{text:n,highlightQuery:a}):e.jsx(li,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((p,b)=>se(p.type)==="书"||se(p.type)==="诗"?e.jsx(ei,{section:p,onNavigate:r,highlightQuery:a},b):se(p.type)==="类"?e.jsx(ti,{section:p,highlightQuery:a},b):e.jsx(ni,{section:p,highlightQuery:a},b)),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function eo(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 dn(t){const n=eo(t);return n.length>0?n[0]:null}function ci(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:c,isKaozhen:a}=t,d=Ce(),x=u.useRef(new Map),[f,h]=u.useState({});u.useEffect(()=>{s&&i&&x.current.set(s,{juan:i,rawText:l})},[s,i,l]),u.useEffect(()=>{x.current.clear(),h({})},[n]);const p=u.useCallback((b,v)=>{let g=0;if(b.juan)for(const y of b.juan.sections)It(y,v,a,d)&&g++;return g===0&&b.rawText&&Kr(b.rawText,v,d)&&(g=1),g},[a,d]);return u.useEffect(()=>{const b=c.trim();if(!b){h({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let v=!1;const g={},y=[];for(const _ of r){const k=x.current.get(_);k?g[_]=p(k,b):(g[_]="loading",y.push(_))}h(g);const m=8;let S=0;const w=async()=>{var _;for(;S<y.length;){if(v)return;const k=S++,I=y[k];try{const[E,z]=await Promise.all([o.getCollatedJuan(n,I),((_=o.getCollatedJuanText)==null?void 0:_.call(o,n,I))??Promise.resolve(null)]),C={juan:E,rawText:z};if(x.current.set(I,C),v)return;h(B=>({...B,[I]:p(C,b)}))}catch{if(v)return;h(E=>({...E,[I]:0}))}}},j=Array.from({length:Math.min(m,y.length)},()=>w());return Promise.all(j),()=>{v=!0}},[c,n,o,r.join(","),p,d]),{matchStates:f}}const Tt=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:l,style:c})=>{const[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,v]=u.useState(null),[g,y]=u.useState(null),[m,S]=u.useState(!1),[w,j]=u.useState(null),[_,k]=u.useState(""),I=u.useRef(new Map),E=s??b,z=u.useCallback(L=>{v(L),i==null||i(L)},[i]),C=t||a;u.useEffect(()=>{t&&(f(!1),p(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return f(!0),p(null),o.getCollatedEditionIndex(n).then($=>{if(!L)if(!$)p("未找到整理本数据");else{d($);const X=dn($);!s&&X&&z(X)}}).catch($=>{L||p($ instanceof Error?$.message:"加载失败")}).finally(()=>{L||f(!1)}),()=>{L=!0}},[t,n,o,s,z]),u.useEffect(()=>{const L=t||a;if(L&&!E){const $=dn(L);$&&z($)}},[t,a,E,z]);const B=n||(C==null?void 0:C.work_id),H=u.useCallback(async L=>{var $;if(!(!B||!(o!=null&&o.getCollatedJuan))){S(!0),y(null),j(null);try{const[X,R]=await Promise.all([o.getCollatedJuan(B,L),(($=o.getCollatedJuanText)==null?void 0:$.call(o,B,L))??Promise.resolve(null)]);y(X),j(R)}catch{y(null),j(null)}finally{S(!1)}}},[B,o]);u.useEffect(()=>{E&&H(E)},[E,H]);const W=L=>{z(L)};if(x)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!C)return null;const F=C.type==="kaozhen",D=eo(C);return e.jsx(di,{className:l,style:c,index:C,allFiles:D,isKaozhen:F,effectiveWorkId:B,transport:o,activeFile:E,handleSelectFile:W,juanData:g,juanRawText:w,juanLoading:m,searchQuery:_,setSearchQuery:k,onNavigate:r,workLabelCacheRef:I})},di=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:x,juanLoading:f,searchQuery:h,setSearchQuery:p,onNavigate:b,workLabelCacheRef:v})=>{const{matchStates:g}=ci({workId:i,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:x,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:y=>p(y.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 y=Dr(o.text_quality.grade);return y?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Or,{content:Mo[y],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Po[y],cursor:"help"},children:Mn[y]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(Zr,{files:r,groups:o.juan_groups,activeFile:c,onSelect:a,juanMeta:o.juan_metadata,matchStates:g}),f?e.jsx(We,{}):d?s?e.jsx(ii,{juan:d,searchQuery:h,onNavigate:b,transport:l,workLabelCache:v}):e.jsx(ai,{juan:d,rawText:x,searchQuery:h,onNavigate:b}):c?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((y,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,". "]}),y.url?e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:y.title}):e.jsx("span",{children:y.title}),y.author&&e.jsxs("span",{children:[",",y.author]}),y.note&&e.jsxs("span",{children:["。",y.note]})]},m))]})]})},pi={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},xi={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function ui(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 Rt=({items:t,loading:n})=>{const o=ve();return n?e.jsx(We,{}):t.length===0?e.jsx("div",{style:fi,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=pi[r.type],i=xi[r.status];return e.jsxs("div",{style:gi,children:[e.jsxs("div",{style:hi,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...pn,background:s.color},children:s.label}),e.jsx("span",{style:{...pn,background:i.color},children:i.label})]}),e.jsx("span",{style:bi,children:ui(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:mi,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:xn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:xn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:yi,children:r.content}),r.reply&&e.jsxs("div",{style:vi,children:[e.jsx("div",{style:ji,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},fi={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},gi={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},hi={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},pn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},bi={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},mi={fontSize:"12px",marginBottom:"6px"},xn={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},yi={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},vi={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},ji={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},jt=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=P(),[c,a]=u.useState(null),[d,x]=u.useState([]),[f,h]=u.useState("recommend"),[p,b]=u.useState([]),[v,g]=u.useState(!1),y=r??f,m=F=>{h(F),s==null||s(F)},[S,w]=u.useState(!0),[j,_]=u.useState(null),[k,I]=u.useState(null),[E,z]=u.useState(null);u.useEffect(()=>{let F=!1;if(t.getCounts)return t.getCounts().then(D=>{F||a({works:D.works,books:D.books,collections:D.collections})}).catch(()=>{}),()=>{F=!0}},[t]),u.useEffect(()=>{let F=!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($=>$.items.map(X=>({...X,group:$.name})))}catch{}return[]})().then(async L=>{if(F)return;const $=L.filter(R=>R.id);if($.length===0){w(!1);return}const X=await Promise.all($.map(async R=>{if(R.type)return{id:R.id,title:R.title,type:R.type,author:R.author,dynasty:R.dynasty,role:R.role,edition:R.edition,has_text:R.has_text,has_image:R.has_image,has_collated:R.has_collated,subtype:R.subtype,primary_name:R.primary_name,group:R.group,fallbackDescription:R.description};try{let M=null;if(t.getEntry)M=await t.getEntry(R.id);else{const oe=await t.getItem(R.id);oe&&(M={id:R.id,title:oe.title||R.id,type:oe.type||"work"})}if(M)return{...M,group:R.group,fallbackDescription:R.description}}catch{}return{id:R.id,title:R.title,type:Y.extractType(R.id),group:R.group,fallbackDescription:R.description}}));F||(x(X.filter(R=>R!==null)),w(!1))}),()=>{F=!0}},[t,o]);const C=u.useRef(!1),B=u.useRef(!1),H=u.useRef(!1);u.useEffect(()=>{if(y!=="catalog"||C.current)return;const F=t.getCatalogProgress??t.getResourceProgress;if(!F)return;C.current=!0;let D=!1;return F.call(t).then(L=>{D||_(L)}).catch(()=>{C.current=!1}),()=>{D=!0}},[t,y]),u.useEffect(()=>{if(y!=="collection"||B.current||!t.getCollectionProgress)return;B.current=!0;let F=!1;return t.getCollectionProgress().then(D=>{F||I(D)}).catch(()=>{B.current=!1}),()=>{F=!0}},[t,y]),u.useEffect(()=>{if(y!=="site"||H.current||!t.getSiteProgress)return;H.current=!0;let F=!1;return t.getSiteProgress().then(D=>{F||z(D)}).catch(()=>{H.current=!1}),()=>{F=!0}},[t,y]),u.useEffect(()=>{if(!i||y!=="feedback")return;let F=!1;return g(!0),fetch(i).then(D=>D.json()).then(D=>{!F&&D.success&&b(D.items||[])}).catch(()=>{}).finally(()=>{F||g(!1)}),()=>{F=!0}},[i,y]);const W=F=>{switch(F){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(Ue,{label:l.home.recommendTab,active:y==="recommend",onClick:()=>m("recommend")}),e.jsx(Ue,{label:l.home.catalogTab,active:y==="catalog",onClick:()=>m("catalog")}),e.jsx(Ue,{label:l.home.collectionTab,active:y==="collection",onClick:()=>m("collection")}),e.jsx(Ue,{label:l.home.siteTab,active:y==="site",onClick:()=>m("site")}),i&&e.jsx(Ue,{label:l.home.feedbackTab,active:y==="feedback",onClick:()=>m("feedback")})]}),y==="recommend"&&e.jsx(Si,{recommended:d,loading:S,onNavigate:n,getIcon:W,t:l}),y==="catalog"&&e.jsx(un,{progress:j,t:l,onNavigate:n}),y==="collection"&&e.jsx(un,{progress:k,t:l,onNavigate:n}),y==="site"&&e.jsx(wi,{progress:E,t:l,totalWorks:(c==null?void 0:c.works)??0}),y==="feedback"&&i&&e.jsx(Rt,{items:p,loading:v})]})})},Ue=({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}),Si=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=ve();if(n)return e.jsx(We,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const x=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o==null||o(d.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(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),x&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x})]})]},d.id)})})]},c))})},un=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(We,{});const r=[...t.resources].sort((c,a)=>c.priority-a.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(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),i[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(ki,{item:d,t:n,statusColor:l[c],onNavigate:o},d.id))})]},c)})})},ki=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ve(),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 c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?et(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})]})},wi=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(We,{});const r=[...t.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),i=r.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=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," (",c,"%)"]}),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(a=>e.jsx(fn,{item:a,t:n,totalWorks:o},a.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(a=>e.jsx(fn,{item:a,t:n,totalWorks:o},a.id))})]})]})},fn=({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})]})},gn="(max-width: 768px)";function _i(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(gn).matches);return u.useEffect(()=>{const o=window.matchMedia(gn),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Ci=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var D;const i=P(),{convert:l}=O(),c=_i(),[a,d]=u.useState(null),[x,f]=u.useState(null),[h,p]=u.useState(!1),[b,v]=u.useState("detail"),[g,y]=u.useState([]),[m,S]=u.useState(!1),[w,j]=u.useState(null),[_,k]=u.useState(!1),I=u.useCallback(async L=>{if(!t.getCollatedEditionIndex){j(null);return}k(!0);try{const $=await t.getCollatedEditionIndex(L);j($)}catch{j(null)}finally{k(!1)}},[t]),E=u.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){y([]);return}S(!0);try{if(t.getCollectionCatalogs){const $=await t.getCollectionCatalogs(L);y($||[])}else if(t.getCollectionCatalog){const $=await t.getCollectionCatalog(L);y($?[{resource_id:"",data:$}]:[])}}catch{y([])}finally{S(!1)}},[t]),z=u.useCallback(async L=>{if(o){o(L);return}d(L),f(null),y([]),j(null),v("detail"),p(!0);try{const $=await t.getItem(L.id);$&&(f($),$.type==="collection"?E(L.id):$.type==="work"&&$.has_collated&&I(L.id))}catch($){console.error("加载详情失败:",$)}finally{p(!1)}},[t,o,E,I]),C=u.useCallback(async L=>{f(null),y([]),j(null),v("detail"),p(!0);try{const $=await t.getItem(L);$&&(f($),d({id:L,title:$.title||L,type:$.type||"book"}),$.type==="collection"?E(L):$.type==="work"&&$.has_collated&&I(L))}catch($){console.error("导航失败:",$)}finally{p(!1)}},[t,E,I]),B=(x==null?void 0:x.type)==="collection"&&(g.length>0||m)||(x==null?void 0:x.type)==="work"&&(w||_),H=c&&(h||x),W=u.useCallback(()=>{d(null),f(null),y([]),j(null),v("detail")},[]),F=e.jsx(e.Fragment,{children:h?e.jsx(We,{}):x?e.jsxs(e.Fragment,{children:[(B||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:rt(b==="detail"),children:i.detailTab.basicInfo}),x.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:rt(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),x.type==="collection"&&g.map(L=>e.jsx("button",{onClick:()=>v(`catalog:${L.resource_id}`),style:rt(b===`catalog:${L.resource_id}`),children:L.short_name?`${l(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),x.type==="work"&&(w||_)&&e.jsxs("button",{onClick:()=>v("collated"),style:rt(b==="collated"),children:[i.detailTab.collatedEdition,_&&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:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(pt,{data:x,transport:t,onNavigate:C}):b.startsWith("catalog:")?e.jsx(_t,{data:(D=g.find(L=>`catalog:${L.resource_id}`===b))==null?void 0:D.data,onNavigate:C}):b==="collated"?e.jsx(Tt,{index:w||void 0,workId:x.id,transport:t,onNavigate:C}):null})]}):e.jsx(jt,{transport:t,onNavigate:C,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:H?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:W,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(yt,{transport:t,onEntryClick:z,hideModeIndicator:n}),!x&&e.jsx(jt,{transport:t,onNavigate:C,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(yt,{transport:t,onEntryClick:z,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:F})]})};function rt(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}}function Ee(t){return t.replace(/\.md$/,"")}const to=({index:t,bookId:n,transport:o,activeChapter:r,onChapterChange:s})=>{const[i,l]=u.useState(t??null),[c,a]=u.useState(null),d=r!==void 0?r:c,x=u.useCallback(g=>{s?s(g):a(g)},[s]),[f,h]=u.useState(null),[p,b]=u.useState(!1);u.useEffect(()=>{t&&l(t)},[t]),u.useEffect(()=>{if(t||!n||!o.getBookFullTextIndex)return;let g=!1;return o.getBookFullTextIndex(n).then(y=>{g||l(y)}),()=>{g=!0}},[n,o,t]),u.useEffect(()=>{if(!i||i.chapters.length===0)return;const g=Ee(i.chapters[0].file);if(!d){x(g);return}const y=Ee(d);i.chapters.some(S=>Ee(S.file)===y)||x(g)},[i,d,x]);const v=u.useMemo(()=>{if(!i||!d)return null;const g=Ee(d);return i.chapters.find(y=>Ee(y.file)===g)??null},[i,d]);return u.useEffect(()=>{if(!n||!v||!o.getBookFullTextChapter)return;let g=!1;return b(!0),h(null),o.getBookFullTextChapter(n,v.file).then(y=>{g||h(y)}).catch(()=>{g||h(null)}).finally(()=>{g||b(!1)}),()=>{g=!0}},[n,v,o]),i?i.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[i.version_label," · 共 ",i.total_chapters," ",(i.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:i.chapters.map(g=>{const y=Ee(g.file),m=y===Ee(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>x(y),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:m?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:m?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:m?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:g.title})},g.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},children:[v&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:v.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:i.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:i.source.name}),i.source.license&&e.jsxs(e.Fragment,{children:[" · ",i.source.license]})]})]}),p&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!p&&f&&e.jsx("article",{style:{fontSize:16,lineHeight:1.9,color:"var(--bim-fg, #2c2c2c)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:'"Songti SC", "Source Han Serif", "Noto Serif CJK SC", serif'},children:f.replace(/^##\s+[^\n]+\n+/,"")}),!p&&!f&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Ii=({data:t,onNavigate:n,className:o,style:r})=>{var x;const s=P(),{convert:i}=O(),[l,c]=u.useState(((x=t.divisions[0])==null?void 0:x.name)??null),[a,d]=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(f=>e.jsx(zi,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:h=>d(a===h?null:h),onNavigate:n},f.name))})]})},zi=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:l}=O(),c=t.categories.reduce((a,d)=>{const x=d.stats||{zhulu:0,cunmu:0};return a+(x.zhulu||0)+(x.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," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(Ti,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:i},a.name)})})]})},Ti=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,d,x,f;const{convert:s}=O(),i=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((x=t.stats)==null?void 0:x.zhulu)||i.length)+(((f=t.stats)==null?void 0:f.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:[c," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(hn,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(hn,{label:"存目",books:l,onNavigate:r})]})]})},hn=({label:t,books:n,onNavigate:o})=>{const{convert:r}=O(),s=ve(),[i,l]=u.useState(n.length<=20),c=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:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:s(a.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!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," 條"]})]})},me=({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:Ei,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ri,children:i.action.save})]})]}),s]})},Ri={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ei={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ge=({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"}})},ct=({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 Li(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const st=({value:t,onChange:n,label:o})=>{const[r,s]=u.useState(!1),i=u.useRef(null),l=Li(t||"");return u.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bn,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(ct,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bn,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:c=>n(c.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"}})]})},bn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Bi(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Wi(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const no=({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)},c=f=>{n(t.filter((h,p)=>p!==f)),s===f&&i(null)},a=(f,h,p)=>{const b=[...t];b[f]={...b[f],[h]:p},n(b)},d=(f,h)=>{const p=[...t];p[f]={...p[f],type:h,id:"",name:""},n(p),h==="bookID"&&o&&o(b=>{const v=[...t];v[f]={...v[f],id:b.id,name:b.title,type:"bookID"},n(v)})},x=f=>{o&&o(h=>{const p=[...t];p[f]={...p[f],id:h.id,name:h.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,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:f.name||`${r.editor.sourcePlaceholder} ${h+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Bi(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:Wi(f.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),c(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),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:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(h,"bookID"),style:{...mn,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:()=>d(h,"url"),style:{...mn,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})]})]})]}),f.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:_e,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:yn,children:r.action.changeType})]}),f.id&&f.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:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),e.jsx("button",{onClick:()=>x(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:()=>x(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})]})]})}),f.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:_e,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:yn,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:p=>a(h,"name",p.target.value),placeholder:r.editor.sourceNamePlaceholder,style:Fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:p=>a(h,"id",p.target.value),placeholder:"https://...",style:Fe})]})]}),f.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:{..._e,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:_e,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:p=>a(h,"details",p.target.value),placeholder:r.editor.detailsPlaceholder,style:Fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:p=>a(h,"position",p.target.value),placeholder:"如: 卷三, p.52",style:Fe})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:p=>a(h,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:Fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:_e,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:p=>a(h,"processor_version",p.target.value),placeholder:"如: v0.1",style:Fe})]})]})]})]})})]},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})]})]})},_e={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Fe={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"},mn={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"},yn={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function oo(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 ro(t){return!t||t.length===0?"":JSON.stringify(t)}const io=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:x,onLinkEntity:f,onUnlinkEntity:h,onViewEntity:p,onCreateAndLink:b,onSaveRelations:v})=>{const g=P();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),v&&e.jsx("button",{onClick:v,style:$i,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ge,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:p,onUnlink:()=>h("workId"),onLink:()=>f("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(Ge,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:p,onUnlink:()=>h("collectionId"),onLink:()=>f("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&&x&&x.length>0&&e.jsx(Me,{direction:"horizontal",title:`${g.relation.siblingVersions} (${x.length})`,entities:x,onView:p,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(Ge,{direction:"up",title:g.relation.parentWork,entity:r,onView:p,onUnlink:()=>h("parentWorkId"),onLink:()=>f("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}),c&&c.length>0&&e.jsx(Me,{direction:"down",title:`${g.relation.childWorks} (${c.length})`,entities:c,onView:p,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(Me,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:p,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(Me,{direction:"down",title:`${g.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,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(Ge,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:p,onUnlink:()=>h("workId"),onLink:()=>f("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(Ge,{direction:"up",title:g.relation.parentCollection,entity:s,onView:p,onUnlink:()=>h("parentCollectionId"),onLink:()=>f("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(Me,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:p,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(Me,{direction:"down",title:`${g.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},Ge=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:x,unlinkLabel:f})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=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:p}),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:so(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(vn,{onClick:()=>r(o),title:x,children:"👁️"}),e.jsx(vn,{onClick:s,title:f,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:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(St,{onClick:i,children:c}),e.jsx(St,{onClick:l,primary:!0,children:a})]})]})},Me=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=u.useState(!1),x=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(p=>e.jsxs("div",{onClick:()=>r(p),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:so(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(St,{onClick:s,primary:!0,children:["+ ",i]})})]})},vn=({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}),St=({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 so(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const $i={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"},lo=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[x,f]=u.useState(""),h=d?l.filter(g=>g.id!==d):l;u.useEffect(()=>{t&&(f(""),c(""))},[t]);const p=g=>{f(g),c(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Ai,children:e.jsxs("div",{style:Fi,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:Mi,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:x,onChange:g=>p(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Pi})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:gt,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:Hi,children:[e.jsx("span",{style:{fontSize:"16px"},children:v}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):x?e.jsxs("div",{style:gt,children:["未找到匹配的",b]}):e.jsxs("div",{style:gt,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:Oi,children:["创建新",b,"并关联"]})]})]})})},Ai={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},Fi={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)"},Mi={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Pi={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"},Hi={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},gt={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Oi={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},jn={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Di={work:"📜",book:"📖",collection:"📚",entity:"👤"},ao=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var h,p;(h=a.current)==null||h.focus(),(p=a.current)==null||p.select()},100))},[t,r==null?void 0:r.title]);const d=h=>{h.key==="Enter"&&l.trim()?x():h.key==="Escape"&&i()},x=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const f=()=>{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`创建新${jn[n]}`}};return e.jsx("div",{style:Ni,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Vi,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:Di[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:h=>c(h.target.value),onKeyDown:d,placeholder:`请输入${jn[n]}名称...`,style:Ui})]}),((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:Gi,children:"取消"}),e.jsx("button",{onClick:x,disabled:!l.trim(),style:{...Yi,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Ni={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},Vi={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)"},Ui={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"},Gi={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Yi={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Ki(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function co(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ji(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const po=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:x})=>{const[f,h]=u.useState(""),[p,b]=u.useState([]),[v,g]=u.useState(!1),[y,m]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!f.trim()){b([]);return}const I=setTimeout(async()=>{g(!0);try{b(await x(f,o))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(I)},[f,o,x]);const S=u.useCallback(I=>{h(I.target.value),I.target.value.trim()&&m("search")},[]),w=u.useCallback(I=>s?I.filter(E=>E.id!==s):I,[s]);if(!t)return null;const j=n||(o==="all"?"选择实体":`选择${co(o)}`),_=w(r),k=w(p);return e.jsx("div",{style:Xi,children:e.jsxs("div",{style:Zi,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:j}),e.jsx("button",{onClick:a,style:Qi,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:f,onChange:S,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:es}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),_.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Sn,{active:y==="recent",onClick:()=>m("recent"),children:["最近使用 (",_.length,")"]}),e.jsxs(Sn,{active:y==="search",onClick:()=>m("search"),children:["搜索结果 ",k.length>0&&`(${k.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:y==="recent"&&_.length>0?e.jsx(kn,{entities:_,onSelect:c}):f.trim()?v?e.jsx(ht,{message:"搜索中..."}):k.length>0?e.jsx(kn,{entities:k,onSelect:c}):e.jsx(ht,{message:"未找到匹配的结果"}):e.jsx(ht,{message:"输入关键词开始搜索"})}),i&&d&&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:d,style:ts,children:l||"创建新实体"})]})]})})},Sn=({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}),kn=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(qi,{entity:o,onClick:()=>n(o)},o.id))}),qi=({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:Ki(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:Ji(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:co(t.type)})]})},ht=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Xi={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},Zi={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)"},Qi={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},es={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"},ts={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ns={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},os={work:"📜",collection:"📚",book:"📖",entity:"👤"},xo=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:x,relations:f,onRelationsChange:h})=>{var ie;const p=P(),[b,v]=u.useState(!1),[g,y]=u.useState("work"),[m,S]=u.useState(""),[w,j]=u.useState(""),[_,k]=u.useState([]),[I,E]=u.useState(!1),[z,C]=u.useState(!1),[B,H]=u.useState("work"),[W,F]=u.useState(""),[D,L]=u.useState(),[$,X]=u.useState(!1),[R,M]=u.useState(null),[oe,Q]=u.useState([]);u.useRef(null);const ee=t.type,le=ee==="work",ae=ee==="collection",U=ee==="book",q=u.useCallback((T,N)=>{n({...t,[T]:N})},[t,n]),Te=u.useCallback((T,N)=>{S(T),y(N),j(p.editor.selectToLink+p.indexType[N]),k([]),v(!0)},[p]),$e=u.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),Ie=u.useCallback(T=>{s==null||s(T.id,T.type)},[s]),ue=u.useCallback((T,N,ce)=>{const fe={...ce,author:(ce==null?void 0:ce.author)||t.author,dynasty:(ce==null?void 0:ce.dynasty)||t.dynasty};H(N),F(T),L(fe),C(!0)},[t.author,t.dynasty]),je=u.useCallback((T,N)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,W,{type:B,title:T,inheritData:N}),C(!1)},[r,t.id,W,B]),ze=u.useCallback(T=>{if(!T.trim()){k([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(T,g).then(N=>{k(N),E(!1)}).catch(()=>{k([]),E(!1)})},[r,g]),Ae=u.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),v(!1)},[r,t.id,m]),A=u.useCallback(()=>{o()},[o]),ne=u.useCallback(T=>{M(()=>T),X(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),K=u.useCallback((T,N)=>r!=null&&r.searchEntities?r.searchEntities(T,N==="all"?void 0:N):Promise.resolve([]),[r]),Z=u.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Q(N=>[T,...N.filter(ce=>ce.id!==T.id)].slice(0,10)),R==null||R(T),X(!1),M(null)},[r,R]);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:os[ee]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(ct,{children:t.id}),e.jsx(ct,{color:ns[ee],children:p.indexType[ee]})]})}),e.jsx(me,{title:p.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(st,{label:le?p.editor.workTitle:ae?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:T=>q("title",T)}),U&&e.jsx(st,{label:p.editor.belongsToWork,value:t.workName||"",onChange:T=>q("workName",T)}),e.jsx(ge,{label:p.editor.authorLabel,value:t.author||"",onChange:T=>q("author",T)}),e.jsx(ge,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>q("dynasty",T)}),(U||ae)&&e.jsx(st,{label:p.editor.containedIn,value:t.collection||"",onChange:T=>q("collection",T)}),(U||ae)&&e.jsx(ge,{label:p.editor.holderLabel,value:t.holder||"",onChange:T=>q("holder",T)}),(U||ae)&&e.jsx(ge,{label:U?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:T=>q("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ge,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>q("firstImage",T)})})]})}),e.jsx(me,{title:p.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Be,{value:t.description||"",onChange:T=>q("description",T),placeholder:p.editor.descriptionPlaceholder})}),(((ie=t.additional_works)==null?void 0:ie.length)||0)>0&&e.jsx(me,{title:p.section.additionalWorks,onSave:o,children:e.jsx(rs,{items:t.additional_works||[],onChange:T=>q("additional_works",T)})}),e.jsx(me,{title:p.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(is,{items:t.indexed_by||[],onChange:T=>q("indexed_by",T)})}),e.jsx(me,{title:p.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(ss,{items:t.emendated_by||[],onChange:T=>q("emendated_by",T)})}),e.jsx(me,{title:p.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(mt,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:d,downloadStatuses:x,filterType:"text"})}),e.jsx(me,{title:p.section.imageResources,onSave:o,children:e.jsx(mt,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:d,downloadStatuses:x,filterType:"image"})}),e.jsx(me,{title:p.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(no,{items:oo(t.sources||""),onChange:T=>q("sources",ro(T)),onOpenEntityPicker:ne})}),(U||ae)&&e.jsx(me,{title:p.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Be,{value:t.provenance||"",onChange:T=>q("provenance",T),placeholder:p.editor.provenancePlaceholder})}),U&&e.jsx(me,{title:p.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Be,{value:t.otherEditions||"",onChange:T=>q("otherEditions",T),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(io,{entityType:ee,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:Te,onUnlinkEntity:$e,onViewEntity:Ie,onCreateAndLink:ue,onSaveRelations:A}),i&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.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:p.editor.deleteEntity})]}),e.jsx(lo,{isOpen:b,entityType:g,title:w,onSelect:Ae,onCancel:()=>v(!1),onCreate:()=>{v(!1),ue(m,g)},searchResults:_,onSearch:ze,isLoading:I,excludeId:t.id}),e.jsx(ao,{isOpen:z,entityType:B,relationField:W,inheritData:D,onConfirm:je,onCancel:()=>C(!1)}),e.jsx(po,{isOpen:$,title:p.action.selectBookOrWork,filterType:"all",recentEntities:oe,excludeId:t.id,onSelect:Z,onCancel:()=>{X(!1),M(null)},onSearch:K})]})};function rs({items:t,onChange:n}){const o=P(),r=(l,c,a)=>{const d=t.map((x,f)=>f===l?{...x,[c]:a}:x);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ge,{label:o.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ge,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick: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 uo({items:t,onChange:n,showMeta:o,addLabel:r}){const s=P(),[i,l]=u.useState(null),c=(x,f,h)=>{const p=t.map((b,v)=>v===x?{...b,[f]:h||void 0}:b);n(p)},a=x=>{n(t.filter((f,h)=>h!==x)),i===x&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>{const h=i===f;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:f),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:x.source||s.editor.unnamedSource}),x.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:x.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&o&&(x.title_info||x.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[x.title_info,x.title_info&&x.author_info&&" — ",x.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(ge,{label:s.label.sourceName,value:x.source,onChange:p=>c(f,"source",p)}),e.jsx(ge,{label:s.label.sourceBid,value:x.source_bid||"",onChange:p=>c(f,"source_bid",p)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ge,{label:s.label.titleInfo,value:x.title_info||"",onChange:p=>c(f,"title_info",p)}),e.jsx(ge,{label:s.label.authorInfo,value:x.author_info||"",onChange:p=>c(f,"author_info",p)})]}),e.jsx(ge,{label:s.label.edition,value:x.edition||"",onChange:p=>c(f,"edition",p)})]}),e.jsx(Be,{value:x.summary||"",onChange:p=>c(f,"summary",p),placeholder:s.editor.summaryPlaceholder}),e.jsx(Be,{value:x.comment||"",onChange:p=>c(f,"comment",p),placeholder:s.editor.commentPlaceholder}),e.jsx(Be,{value:x.additional_comment||"",onChange:p=>c(f,"additional_comment",p),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function is({items:t,onChange:n}){const o=P();return e.jsx(uo,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function ss({items:t,onChange:n}){const o=P();return e.jsx(uo,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function fo(t){var c,a,d,x,f,h,p;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",o=((d=t.publication_info)==null?void 0:d.year)||"",r=((x=t.current_location)==null?void 0:x.name)||"",s=(f=t.page_count)!=null&&f.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 v=b.related_works.find(g=>g.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const b=t;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(p=b.contained_in[0])==null?void 0:p.id)}return l}function ls(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 as=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:x,onAskAI:f,renderSectionActions:h,onDownloadResource:p,downloadStatuses:b,relations:v,onRelationsChange:g,headerExtra:y,className:m,style:S}=t;P();const[w,j]=u.useState(s),_=i?s:w;u.useEffect(()=>{s!==w&&j(s)},[s]);const k=u.useCallback(()=>{const W=_==="view"?"edit":"view";i?i(W):j(W)},[_,i]),[I,E]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(W=>{W&&E(W)})},[o,r]);const z=n||I,C=u.useMemo(()=>z?fo(z):null,[z]),B=i||!n?e.jsx("button",{onClick:k,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:_==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:_==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?"切换到编辑模式":"切换到查看模式",children:_==="view"?"✏️ 编辑":"👁 查看"}):null,H=e.jsxs(e.Fragment,{children:[B,y]});return!z&&!C?e.jsx(We,{}):_==="view"?e.jsx(pt,{data:z,transport:r,onNavigate:d?W=>d(W):void 0,renderLink:x,headerExtra:H,className:m,style:S}):C?e.jsxs("div",{className:m,style:S,children:[H&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:H}),e.jsx(xo,{data:C,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:h,onDownloadResource:p,downloadStatuses:b,relations:v,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},wn=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],go=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=u.useState(null),[l,c]=u.useState(""),[a,d]=u.useState("idle"),[x,f]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(i(null),c(""),d("idle"),f(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[s]),u.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),u.useEffect(()=>{if(!t)return;const g=y=>{y.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const p=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await o({type:s,content:l.trim()}),d("success")}catch(g){d("error"),f(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&l.trim()&&a!=="submitting",v=wn.find(g=>g.value===s);return e.jsx("div",{style:cs,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:ds,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:ps,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:xs,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:bs,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:wn.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...us,...s===g.value?fs:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:l,onChange:g=>c(g.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...gs,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),a==="error"&&e.jsx("div",{style:ms,children:x}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!b,style:{...hs,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},cs={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},ds={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)"},ps={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},xs={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},us={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"},fs={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},gs={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"},hs={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},bs={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ms={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ys=({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:{...vs,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(go,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},vs={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"},_n=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],ho=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,s]=u.useState(""),[i,l]=u.useState("idle"),[c,a]=u.useState(""),d=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var p;return(p=d.current)==null?void 0:p.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){l("submitting"),a("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(p){l("error"),a(p instanceof Error?p.message:"提交失败,请稍后重试")}}},f=n&&r.trim()&&i!=="submitting",h=_n.find(p=>p.value===n);return i==="success"?e.jsx("div",{style:Cn,children:e.jsxs("div",{style:_s,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Cs,children:"继续提交"})]})}):e.jsxs("div",{style:Cn,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:_n.map(p=>e.jsxs("button",{onClick:()=>o(p.value),style:{...js,...n===p.value?Ss:{}},children:[e.jsx("span",{children:p.icon})," ",p.label]},p.value))}),e.jsx("textarea",{ref:d,value:r,onChange:p=>s(p.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...ks}}),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:x,disabled:!f,style:{...ws,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Is,children:c})]})},Cn={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},js={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"},Ss={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ks={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"},ws={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},_s={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Cs={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Is={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function In(t){return typeof t=="function"?t():t??"/api/feedback"}const bo=({resourceId:t,apiUrl:n})=>{const[o,r]=u.useState([]),[s,i]=u.useState(!0),l=u.useCallback(async()=>{const a=In(n);i(!0);try{const x=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();x.success&&r(x.items)}catch{}finally{i(!1)}},[t,n]);u.useEffect(()=>{l()},[l]);const c=async a=>{const d=In(n),x=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!x.ok){const f=await x.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(Rt,{items:o,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(ho,{onSubmit:c})})]})};function zs(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function Ts(t,n){if(!t.lineage)return null;const o=t.lineage;return{id:t.id,kind:"book",label:t.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[t.id],note:o.note}}function zn(t,n,o){return{id:`derive:${n.ref}->${t}:${o}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Rs(t,n,o){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Es(t,n){var d;if(n==="all")return null;const o=(d=t.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,i=r||s||!!(o!=null&&o.hypothetical_ids);if(!i&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!o||!i)return null;const l=r?new Set(o.groups):null,c=new Set(o.book_ids??[]);if(l&&t.node_groups)for(const[x,f]of Object.entries(t.node_groups))l.has(f)&&c.add(x);let a=null;if(o.hypothetical_ids&&(a=new Set(o.hypothetical_ids)),l){a||(a=new Set);for(const x of t.hypothetical_nodes??[])x.group&&l.has(x.group)&&a.add(x.id)}return{books:c,hypos:a}}function lt(t,n,o){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const i=new Set(r.excluded_books??[]),l=r.node_groups??{},c=Es(r,o??r.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,x=(c==null?void 0:c.hypos)??null,f=new Set,h=new Set;if(a){const w=new Map(n.map(z=>[z.id,z])),j=new Map((r.hypothetical_nodes??[]).map(z=>[z.id,z])),_=z=>{const C=w.get(z);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(H=>H.ref);const B=j.get(z);return B?(B.derived_from??[]).map(H=>H.ref):[]},k=z=>j.has(z)?!x||x.has(z):!d||d.has(z),I=new Set,E=z=>{if(!I.has(z)){I.add(z);for(const C of _(z))i.has(C)||(k(C)||(j.has(C)?h.add(C):w.has(C)&&f.add(C)),E(C))}};for(const z of n)d&&d.has(z.id)&&!i.has(z.id)&&E(z.id);for(const z of r.hypothetical_nodes??[])x&&x.has(z.id)&&E(z.id)}const p=n.filter(w=>!i.has(w.id)).filter(w=>!d||d.has(w.id)||f.has(w.id)).map(w=>{const j=Ts(w,l);return j&&f.has(w.id)&&(j.bridge=!0),j}).filter(w=>w!==null),b=(r.hypothetical_nodes??[]).filter(w=>!x||x.has(w.id)||h.has(w.id)).map(w=>{const j=zs(w);return h.has(w.id)&&(j.bridge=!0),j}),v=[...p,...b],g=new Set(v.map(w=>w.id)),y=new Set,m=[],S=w=>{y.has(w.id)||!g.has(w.source)||!g.has(w.target)||(y.add(w.id),m.push(w))};for(const w of n)i.has(w.id)||!w.lineage||d&&!d.has(w.id)&&!f.has(w.id)||((w.lineage.derived_from??[]).forEach((j,_)=>{S(zn(w.id,j,_))}),(w.lineage.related_to??[]).forEach((j,_)=>{S(Rs(w.id,j,_))}));for(const w of r.hypothetical_nodes??[])x&&!x.has(w.id)&&!h.has(w.id)||(w.derived_from??[]).forEach((j,_)=>{S(zn(w.id,j,_))});return{nodes:v,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(i)}}function mo(t,n,o){const r=(t??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ls(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(a=>a.id)),i=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...i]),c=(a,d)=>{l.has(d.ref)||o.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(x=>c(d,x)),(a.lineage.related_to??[]).forEach(x=>{s.has(x.book_id)||o.push(`${d}: related_to.book_id "${x.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(x=>c(d,x))}return o}const yo=({graph:t,renderLink:n,className:o,style:r})=>{const{convert:s}=O();if(!t.nodes.length)return e.jsx("div",{style:{...Gs,...r},className:o,children:"暂无版本图数据"});const i=new Map,l=new Map;for(const h of t.edges)if(h.kind==="derive"){const p=i.get(h.target)??[];p.push(h),i.set(h.target,p)}else for(const p of[h.source,h.target]){const b=l.get(p)??[];b.push(h),l.set(p,b)}const c=new Map(t.nodes.map(h=>[h.id,h])),a=new Map,d=[];for(const h of t.nodes)if(h.group){const p=a.get(h.group)??[];p.push(h),a.set(h.group,p)}else d.push(h);const x=(h,p)=>(h.year??9999)-(p.year??9999);a.forEach(h=>h.sort(x)),d.sort(x);const f=t.groups.filter(h=>a.has(h.id));return e.jsxs("div",{className:o,style:{...Ws,...r},children:[t.title&&e.jsx("div",{style:$s,children:s(t.title)}),t.description&&e.jsx("div",{style:As,children:s(t.description)}),f.map(h=>e.jsx(Tn,{label:h.label,color:h.color,nodes:a.get(h.id),incomingMap:i,siblingMap:l,nodeMap:c,renderLink:n},h.id)),d.length>0&&e.jsx(Tn,{label:"其他",nodes:d,incomingMap:i,siblingMap:l,nodeMap:c,renderLink:n})]})},Tn=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:l})=>{const{convert:c}=O();return e.jsxs("div",{style:Fs,children:[e.jsx("div",{style:{...Ms,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),o.map(a=>e.jsx(Bs,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:i,renderLink:l},a.id))]})},Bs=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical",l=t.bridge,{convert:c}=O();return e.jsxs("div",{style:{...Ps,borderStyle:i||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Hs,children:[e.jsx("span",{style:Os,children:i||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Ds,children:mo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Ns,children:[t.category&&e.jsx(Ye,{children:c(t.category)}),t.status==="lost"&&e.jsx(Ye,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Ye,{tone:"warn",children:"残本"}),i&&e.jsx(Ye,{tone:"info",children:"假想祖本"}),l&&e.jsx(Ye,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Vs,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Us,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:En,children:[e.jsx("div",{style:Ln,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:Bn(a.confidence),children:[e.jsx("span",{style:Wn,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(Rn,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:$n,children:["· ",c(a.evidence)]})]},a.id)})]}),o.length>0&&e.jsxs("div",{style:En,children:[e.jsx("div",{style:Ln,children:"关联:"}),o.map(a=>{const d=a.source===t.id?a.target:a.source,x=r.get(d);return e.jsxs("div",{style:Bn(a.confidence),children:[e.jsx("span",{style:Wn,children:c(a.relation)}),e.jsx("span",{children:(x==null?void 0:x.kind)==="book"&&s?s(x.id,c(x.label)):c((x==null?void 0:x.label)??d)}),e.jsx(Rn,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:$n,children:["· ",c(a.evidence)]})]},a.id)})]})]})},Ye=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Rn=({level:t})=>{const o={certain:{label:"确定",color:"#2e7d32"},consensus:{label:"共识",color:"#1976d2"},probable:{label:"推测",color:"#ed6c02"},disputed:{label:"有争议",color:"#c62828"}}[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},Ws={fontSize:"14px",color:"var(--bim-fg, #333)"},$s={fontSize:"16px",fontWeight:600,marginBottom:"8px"},As={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Fs={marginBottom:"16px"},Ms={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ps={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Hs={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Os={fontSize:"15px",fontWeight:600},Ds={fontSize:"12px",color:"var(--bim-muted, #777)"},Ns={marginBottom:"6px"},Vs={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Us={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},En={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Ln={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Bn=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Wn={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},$n={fontSize:"11px",color:"var(--bim-muted, #888)"},Gs={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},vo=({selectedNodeId:t,...n})=>{const[o,r]=u.useState("loading"),[s,i]=u.useState(null);return u.useEffect(()=>{let l=!1;return Ys().then(c=>{l||(c?(i(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),o==="loading"?e.jsx("div",{style:An,children:"加载图组件中…"}):o==="missing"||!s?e.jsxs("div",{style:An,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Ks,{modules:s,selectedNodeId:t,...n})};async function Ys(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const Ks=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:x,Position:f,BaseEdge:h,EdgeLabelRenderer:p,getSmoothStepPath:b,dagre:v}=l,g=u.useMemo(()=>({lineage:_=>{var D,L,$,X;const k=((D=_.data)==null?void 0:D.stepPosition)??.85,[I,E,z]=b({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:k,borderRadius:5}),C=!!((L=_.data)!=null&&L.isSibling),B=C?E:_.targetX-18,H=C?z:_.targetY-12,W=($=_.data)==null?void 0:$.labelStyle,F=(X=_.data)==null?void 0:X.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(h,{id:_.id,path:I,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&e.jsx(p,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${B}px,${H}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...F,...W},children:_.label})})]})}}),[h,p,b]),y=u.useMemo(()=>({version:_=>{const k=_.data,I=k.kind==="hypothetical",E=k.status==="lost",z=k.isSelected,C=k.bridge,B=k.borderColor??"#888",H=C||I?"dashed":"solid",W=C?.5:E?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${H} ${z?"#0078d4":B}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:W,boxShadow:z?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":I||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(x,{type:"target",position:f.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:I||!k.renderLink?k.label:k.renderLink(k.bookId,k.label)}),k.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:k.description}),k.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:mo(k.yearText,void 0,k.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(x,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[x,f]),{convert:m}=O(),{rfNodes:S,rfEdges:w}=u.useMemo(()=>Js(t,v,n,i,m),[t,v,n,i,m]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(c,{nodes:S,edges:w,nodeTypes:y,edgeTypes:g,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Js(t,n,o,r,s=i=>i??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(y=>[y.id,y.color??"#888"]));for(const y of t.nodes)a.setNode(y.id,{width:160,height:90});const x=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const y of t.edges)y.kind==="derive"&&(x.has(y.relation)||a.setEdge(y.source,y.target));n.layout(a);const f=t.nodes.map(y=>{const m=a.node(y.id),S=r&&y.id===r,w={kind:y.kind,label:s(y.label),bookId:y.kind==="book"?y.id:void 0,yearText:s(y.year_text??Xs(y)),uncertain:y.year_uncertain,category:y.category,status:y.status,borderColor:y.group?d.get(y.group):void 0,renderLink:o,isSelected:S,description:s(y.description),bridge:y.bridge};return{id:y.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:w,draggable:!1,selected:S}}),h=.78,p=.06,b=new Map;for(const y of t.edges)y.kind==="derive"&&(b.has(y.source)||b.set(y.source,[]),b.get(y.source).push(y));const v=new Map;for(const[y,m]of b){if(m.length<=1)continue;const S=[...m].sort((j,_)=>{var E,z;const k=((E=a.node(j.target))==null?void 0:E.y)??0,I=((z=a.node(_.target))==null?void 0:z.y)??0;return k-I}),w=S.length;S.forEach((j,_)=>{const k=(_-(w-1)/2)*p;v.set(j.id,h+k)})}const g=t.edges.map(y=>qs(y,v.get(y.id),s));return{rfNodes:f,rfEdges:g}}function qs(t,n,o=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",i=Zs(t.confidence),l={type:"arrowclosed",color:i,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:o(t.relation),data:{labelStyle:{color:"#444"},isSibling:s,stepPosition:n},style:{stroke:i,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Xs(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Zs(t){switch(t){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const An={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},jo=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:x,style:f})=>{var m;const[h,p]=u.useState(n),b=S=>{p(S),i==null||i(S)},v=(()=>{if(!a)return[];const S=Object.entries(a);return S.length===0||a.all?S:[...S,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),g=!!(c&&v.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const y=l?(m=a==null?void 0:a[l])==null?void 0:m.description:void 0;return e.jsxs("div",{className:x,style:f,children:[e.jsxs("div",{style:Qs,children:[e.jsx("button",{onClick:()=>b("list"),style:bt(h==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:bt(h==="graph"),children:"关系图"}),g&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),v.map(([S,w])=>{const j=d==null?void 0:d[S];return e.jsxs("button",{onClick:()=>c==null?void 0:c(S),style:bt(l===S),title:w.description,children:[w.label,j!=null?` ${j}`:""]},S)})]})]}),g&&y&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:y}),h==="list"?e.jsx(yo,{graph:t,renderLink:o}):e.jsx(vo,{graph:t,renderLink:o,height:r,selectedNodeId:s})]})},Qs={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},bt=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),Et=({style:t})=>{const n=u.useContext(Qe);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:"简"})]})},Lt=({href:t,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:i=>{i.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:i=>{i.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:o,height:o,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})}),el=`
|
|
4
4
|
.bim-detail-root { flex-direction: row; }
|
|
5
5
|
.bim-detail-top-nav { display: none; }
|
|
6
6
|
.bim-detail-content { padding: 24px 32px 32px; }
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
.bim-detail-top-nav { display: block; }
|
|
11
11
|
.bim-detail-content { padding: 16px 16px 32px; }
|
|
12
12
|
}
|
|
13
|
-
`;function el({items:t,activeKey:n,onSelect:o,onBack:r,backLabel:s,width:i}){return e.jsxs("nav",{style:{display:"flex",flexDirection:"column",paddingTop:16,width:i,flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-bg, transparent)"},children:[r&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:r,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 20px",fontSize:14,color:"var(--bim-fg, #2c2c2c)",background:"transparent",border:"none",cursor:"pointer",textAlign:"left"},onMouseEnter:l=>{l.currentTarget.style.color="var(--bim-primary, #8B0000)"},onMouseLeave:l=>{l.currentTarget.style.color="var(--bim-fg, #2c2c2c)"},children:[e.jsx("svg",{width:"14",height:"14",fill:"none",strokeWidth:2,viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M15 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),s]}),e.jsx("div",{style:{margin:"8px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",opacity:.6}})]}),t.map(l=>{const c=l.key===n;return e.jsxs("button",{type:"button",onClick:()=>o(l.key),style:{position:"relative",textAlign:"left",padding:"8px 20px",fontSize:14,background:"transparent",border:"none",cursor:"pointer",color:c?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",fontWeight:c?500:400,transition:"color 120ms"},onMouseEnter:a=>{c||(a.currentTarget.style.color="var(--bim-primary, #8B0000)")},onMouseLeave:a=>{c||(a.currentTarget.style.color="var(--bim-fg, #2c2c2c)")},children:[c&&e.jsx("span",{style:{position:"absolute",left:0,top:"50%",transform:"translateY(-50%)",width:3,height:16,background:"var(--bim-primary, #8B0000)",borderRadius:"0 2px 2px 0"}}),l.label]},l.key)})]})}function tl({items:t,activeKey:n,onSelect:o,onBack:r,backLabel:s}){return e.jsx("div",{style:{flexShrink:0,borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-bg, transparent)"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",overflowX:"auto"},children:[r&&e.jsxs("button",{type:"button",onClick:r,style:{display:"flex",alignItems:"center",gap:4,padding:"10px 12px",fontSize:14,color:"var(--bim-fg, #2c2c2c)",background:"transparent",border:"none",borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",flexShrink:0,whiteSpace:"nowrap"},children:[e.jsx("svg",{width:"14",height:"14",fill:"none",strokeWidth:2,viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M15 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),s]}),t.map(i=>{const l=i.key===n;return e.jsx("button",{type:"button",onClick:()=>o(i.key),style:{padding:"10px 16px",fontSize:14,background:"transparent",border:"none",borderBottom:l?"2px solid var(--bim-primary, #8B0000)":"2px solid transparent",color:l?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",fontWeight:l?500:400,cursor:"pointer",flexShrink:0,whiteSpace:"nowrap"},children:i.label},i.key)})]})})}function Ye({sourceLink:t}){return e.jsxs("div",{style:{position:"absolute",top:24,right:32,zIndex:10,display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Rt,{}),t&&e.jsx(Et,{...t})]})}const nl=({id:t,transport:n,activeTab:o,onTabChange:r,activeJuan:s,onJuanChange:i,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:x=1,selectedLineageNodeId:f,onNavigate:h,onBack:p,backLabel:b,renderLink:v,enrichDetail:g,getSourceLink:y,extraTabs:m=[],showFeedbackTab:S=!0,feedbackApiUrl:w,height:j="100vh",sideNavWidth:_=144,contentMaxWidth:k=1024,className:I,style:E})=>{var Bt,Wt,$t,At,Ft,Mt;const z=M(),{convert:C}=O(),[B,P]=u.useState(null),[W,F]=u.useState(null),[D,L]=u.useState(!0),[T,H]=u.useState(!1),[$,N]=u.useState([]),[K,te]=u.useState(!1),[se,fe]=u.useState(null),[be,ne]=u.useState(!1),[Q,Te]=u.useState(null),[We,Ie]=u.useState(!1),[pe,je]=u.useState(null),[ze,$e]=u.useState(!1),A=u.useRef(null),[ee,J]=u.useState(null),X=s!==void 0?s:ee,re=u.useCallback(G=>{i?i(G):J(G)},[i]),R=u.useCallback(async G=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){N([]);return}te(!0);try{if(n.getCollectionCatalogs){const U=await n.getCollectionCatalogs(G);N(U||[])}else if(n.getCollectionCatalog){const U=await n.getCollectionCatalog(G);N(U?[{resource_id:"",data:U}]:[])}}catch{N([])}finally{te(!1)}},[n]),V=u.useCallback(async G=>{if(!n.getCollatedEditionIndex){fe(null);return}ne(!0);try{const U=await n.getCollatedEditionIndex(G);fe(U)}catch{fe(null)}finally{ne(!1)}},[n]),le=u.useCallback(async G=>{if(!n.getBookFullTextIndex){Te(null);return}Ie(!0);try{const U=await n.getBookFullTextIndex(G);Te(U)}catch{Te(null)}finally{Ie(!1)}},[n]),xe=u.useCallback(async(G,U)=>{$e(!0);try{if(n.getLineageGraph){const de=await n.getLineageGraph(G);de&&je(de)}const ae=U.version_graph;if(!ae||!ae.enabled){pe||je(null),A.current=null;return}const oe=U.books??[],ge=[];for(const de of oe)try{const Re=await n.getItem(de);Re&&ge.push(Re)}catch{}A.current={work:U,books:ge};const He=a??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),q=He==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":He??"all";je(st(U,ge,q))}catch{je(null),A.current=null}finally{$e(!1)}},[n]);u.useEffect(()=>{let G=!1;return(async()=>{L(!0),H(!1),P(null),F(null),N([]),fe(null),je(null),A.current=null;try{const ae=await n.getItem(t);if(G)return;if(!ae){H(!0);return}const oe=ae;let ge=null;if(n.getEntry&&(ge=await n.getEntry(t),G))return;ge||(ge={id:t,title:oe.title??oe.primary_name??t,type:oe.type??"book"}),g&&g(ge,oe),P(ge),F(oe),oe.type==="collection"?R(t):oe.type==="work"?((oe.has_collated||n.getCollatedEditionIndex)&&V(t),(oe.version_graph||n.getLineageGraph)&&xe(t,oe)):oe.type==="book"&&oe.has_full_text&&n.getBookFullTextIndex&&le(t)}catch{G||H(!0)}finally{G||L(!1)}})(),()=>{G=!0}},[t,n,g,R,V,xe,le]),u.useEffect(()=>{const G=A.current;G&&a&&je(st(G.work,G.books,a))},[a]);const Z=[];if(W){if(Z.push({key:"basic",label:((Bt=z.detailTab)==null?void 0:Bt.basicInfo)??"基本信息"}),W.type==="collection"){K&&$.length===0&&Z.push({key:"catalog:loading",label:`${((Wt=z.detailTab)==null?void 0:Wt.catalog)??"目录"}...`});for(const U of $){const ae=U.short_name?`${C(U.short_name)}`:(($t=z.detailTab)==null?void 0:$t.collectionCatalog)??"丛编目录",oe=((At=z.detailTab)==null?void 0:At.catalogSuffix)??"·目录";Z.push({key:`catalog:${U.resource_id}`,label:U.short_name?`${ae}${oe}`:ae})}}W.type==="work"&&(se||be)&&Z.push({key:"collated",label:be?`${((Ft=z.detailTab)==null?void 0:Ft.collatedEdition)??"整理本"}...`:((Mt=z.detailTab)==null?void 0:Mt.collatedEdition)??"整理本"}),W.type==="book"&&(Q||We)&&Z.push({key:"fulltext",label:We?"全文...":"全文"}),W.type==="work"&&(pe||ze)&&Z.push({key:"lineage",label:ze?"版本传承...":"版本传承"});const G=W.emendated_by;Array.isArray(G)&&G.length>0&&Z.push({key:"emendated",label:"考證"});for(const U of m)(U.position??"before-feedback")==="before-feedback"&&U.shouldShow(W)&&Z.push({key:U.key,label:U.label});S&&Z.push({key:"feedback",label:"反馈"});for(const U of m)U.position==="after-feedback"&&U.shouldShow(W)&&Z.push({key:U.key,label:U.label})}const Se=B&&W&&y?y({activeTab:o,activeJuan:X,entry:B,detail:W}):null,jo=()=>{var oe,ge,He;if(D)return e.jsx("div",{style:{padding:"48px 16px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},children:"加载中…"});if(T)return e.jsxs("div",{style:{padding:"48px 16px",textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",gap:12},children:[e.jsx("span",{style:{fontSize:32},children:"📭"}),e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})]});if(!B||!W)return null;const G={maxWidth:k,position:"relative"},U="bim-detail-content";if(o==="basic")return e.jsx("div",{className:U,style:G,children:e.jsx(dt,{data:W,transport:n,onNavigate:h,renderLink:v,headerExtra:e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Rt,{}),Se&&e.jsx(Et,{...Se})]}),relatedBooksFooter:pe&&pe.nodes.length>0?e.jsx(ol,{graph:pe,totalBookCount:(()=>{var Re;const q=A.current;if(!q)return;const de=new Set(((Re=q.work.version_graph)==null?void 0:Re.excluded_books)??[]);return(q.work.books??[]).filter(et=>!de.has(et)).length})(),onOpen:()=>r("lineage")}):null})});if(typeof o=="string"&&o.startsWith("catalog:")){const q=(oe=$.find(de=>`catalog:${de.resource_id}`===o))==null?void 0:oe.data;return e.jsxs("div",{className:U,style:G,children:[e.jsx(Ye,{sourceLink:Se}),e.jsx(wt,{data:q,onNavigate:h,renderLink:v})]})}if(o==="collated")return e.jsxs("div",{className:U,style:G,children:[e.jsx(Ye,{sourceLink:Se}),e.jsx(zt,{index:se||void 0,workId:t,transport:n,onNavigate:h,activeJuan:X,onJuanChange:re})]});if(o==="fulltext")return e.jsxs("div",{className:U,style:G,children:[e.jsx(Ye,{sourceLink:Se}),e.jsx(eo,{index:Q||void 0,bookId:t,transport:n,activeChapter:X,onChapterChange:re})]});if(o==="lineage"){if(!pe)return e.jsx("div",{style:{...G,color:"var(--bim-desc-fg, #999)"},children:ze?"加载中…":"暂无版本图数据"});const q=W.type==="work"?W:null;return e.jsxs("div",{className:U,style:G,children:[e.jsx(Ye,{sourceLink:Se}),e.jsx(vo,{graph:pe,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:f,collection:a??((ge=q==null?void 0:q.version_graph)==null?void 0:ge.default_collection),onCollectionChange:d,collectionsAvailable:(He=q==null?void 0:q.version_graph)==null?void 0:He.collections,collectionCounts:(()=>{var Pt,Ht,Ot,Dt,Nt,Vt,Ut;if(!q)return;const de={},Re=((Pt=A.current)==null?void 0:Pt.books)??[];de.all=(((Ht=q.books)==null?void 0:Ht.length)??0)-(((Dt=(Ot=q.version_graph)==null?void 0:Ot.excluded_books)==null?void 0:Dt.length)??0);const et=(Nt=q.version_graph)==null?void 0:Nt.collections;if(et)for(const Gt of Object.keys(et))de[Gt]=st(q,Re,Gt).nodes.filter(Yt=>Yt.kind==="book"&&!Yt.bridge).length;return de.core==null&&((Ut=(Vt=q.version_graph)==null?void 0:Vt.core_books)!=null&&Ut.length)&&(de.core=q.version_graph.core_books.length),de})()})]})}if(o==="emendated"){const q=W.emendated_by;return!Array.isArray(q)||q.length===0?null:e.jsxs("div",{className:U,style:G,children:[e.jsx(Ye,{sourceLink:Se}),e.jsx(kt,{items:q,onNavigate:h,renderLink:v})]})}if(o==="feedback"&&S)return e.jsx("div",{className:U,style:G,children:e.jsx(ho,{resourceId:t,apiUrl:w})});const ae=m.find(q=>q.key===o);return ae?ae.render({detail:W,entry:B,transport:n,onNavigate:h}):null},So={height:j,display:"flex",background:"var(--bim-bg, transparent)",color:"var(--bim-fg, #2c2c2c)",...E},ko=b??"返回索引",Lt=B||D,wo=["bim-detail-root",I].filter(Boolean).join(" ");return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:Qs}),e.jsxs("div",{className:wo,style:So,children:[Lt&&e.jsx("div",{className:"bim-detail-side-nav",children:e.jsx(el,{items:Z,activeKey:o,onSelect:r,onBack:p,backLabel:ko,width:_})}),Lt&&e.jsx("div",{className:"bim-detail-top-nav",children:e.jsx(tl,{items:Z,activeKey:o,onSelect:r,onBack:p,backLabel:"返回"})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:jo()})]})]})};function ol({graph:t,totalBookCount:n,onOpen:o}){const r=n??t.nodes.filter(s=>s.kind==="book").length;return e.jsxs("div",{onClick:o,role:"button",tabIndex:0,onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&o()},style:{display:"flex",alignItems:"center",gap:12,padding:"10px 14px",background:"var(--bim-info-bg, #e7f3ff)",color:"var(--bim-info-fg, #0c5380)",border:"1px solid var(--bim-info-border, #b3dbff)",borderRadius:6,cursor:"pointer",fontSize:13,lineHeight:1.5},children:[e.jsx("div",{style:{fontSize:18,lineHeight:1},children:"📜"}),e.jsxs("div",{style:{flex:1},children:["本作品共有 ",e.jsx("strong",{children:r})," 个版本,已整理出版本之间的传承关系。",t.description&&e.jsxs("span",{style:{opacity:.85},children:[" ",t.description.slice(0,40),"…"]})]}),e.jsx("span",{style:{padding:"2px 10px",background:"var(--bim-info-fg, #0c5380)",color:"var(--bim-info-bg, #fff)",borderRadius:4,fontSize:12,whiteSpace:"nowrap"},children:"查看版本源流 →"})]})}exports.BidLink=Y.BidLink;exports.BookIndexError=Y.BookIndexError;exports.BookIndexManager=Y.BookIndexManager;exports.BookIndexStorage=Y.BookIndexStorage;exports.BundleStorage=Y.BundleStorage;exports.ConfigError=Y.ConfigError;exports.GithubStorage=Y.GithubStorage;exports.IdGenerationError=Y.IdGenerationError;exports.IdGenerator=Y.IdGenerator;exports.LocalStorage=Y.LocalStorage;exports.MigrationError=Y.MigrationError;exports.StorageError=Y.StorageError;exports.base36Decode=Y.base36Decode;exports.base36Encode=Y.base36Encode;exports.base58Decode=Y.base58Decode;exports.buildId=Y.buildId;exports.buildPromotionMap=Y.buildPromotionMap;exports.cleanName=Y.cleanName;exports.decodeId=Y.decodeId;exports.decodeIdString=Y.decodeIdString;exports.encodeId=Y.encodeId;exports.extractIdFromUrl=Y.extractIdFromUrl;exports.extractStatus=Y.extractStatus;exports.extractType=Y.extractType;exports.normalizeCatalog=Y.normalizeCatalog;exports.parseId=Y.parseId;exports.shardOf=Y.shardOf;exports.smartDecode=Y.smartDecode;exports.validateResource=Y.validateResource;exports.Badge=at;exports.BidUrlProvider=$o;exports.BookDetailLayout=nl;exports.BookFullText=eo;exports.CollatedEdition=zt;exports.CollectionCatalog=wt;exports.CreateEntityDialog=lo;exports.EmendatedBySection=kt;exports.EntityDetail=Dn;exports.EntityPickerDialog=co;exports.EntitySelector=so;exports.FeedbackButton=ms;exports.FeedbackDialog=fo;exports.FeedbackForm=go;exports.FeedbackList=Tt;exports.FeedbackTab=ho;exports.FormInput=ue;exports.FormTextArea=Le;exports.HomePage=vt;exports.IndexApp=_i;exports.IndexBrowser=mt;exports.IndexDetail=dt;exports.IndexEditor=po;exports.IndexView=ls;exports.LocaleContext=Ze;exports.LocaleProvider=Vo;exports.LocaleToggle=Rt;exports.ModeIndicator=Hn;exports.RelationPanel=ro;exports.RepoSourceLink=Et;exports.ResourceEditor=bt;exports.ResourceList=St;exports.SearchInput=On;exports.Section=me;exports.SmartBidInput=it;exports.SourceEditor=to;exports.VersionLineageGraph=yo;exports.VersionLineageList=mo;exports.VersionLineageView=vo;exports.WorkCatalog=Ci;exports.buildLineageGraph=st;exports.detailToEditor=uo;exports.editorToDetail=ss;exports.formatTemplate=Qe;exports.parseSourceString=no;exports.stringifySources=oo;exports.useBidUrl=ve;exports.useConvert=O;exports.useT=M;exports.validateLineageGraph=Es;
|
|
13
|
+
`;function tl({items:t,activeKey:n,onSelect:o,onBack:r,backLabel:s,width:i}){return e.jsxs("nav",{style:{display:"flex",flexDirection:"column",paddingTop:16,width:i,flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-bg, transparent)"},children:[r&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:r,style:{display:"flex",alignItems:"center",gap:6,padding:"8px 20px",fontSize:14,color:"var(--bim-fg, #2c2c2c)",background:"transparent",border:"none",cursor:"pointer",textAlign:"left"},onMouseEnter:l=>{l.currentTarget.style.color="var(--bim-primary, #8B0000)"},onMouseLeave:l=>{l.currentTarget.style.color="var(--bim-fg, #2c2c2c)"},children:[e.jsx("svg",{width:"14",height:"14",fill:"none",strokeWidth:2,viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M15 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),s]}),e.jsx("div",{style:{margin:"8px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",opacity:.6}})]}),t.map(l=>{const c=l.key===n;return e.jsxs("button",{type:"button",onClick:()=>o(l.key),style:{position:"relative",textAlign:"left",padding:"8px 20px",fontSize:14,background:"transparent",border:"none",cursor:"pointer",color:c?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",fontWeight:c?500:400,transition:"color 120ms"},onMouseEnter:a=>{c||(a.currentTarget.style.color="var(--bim-primary, #8B0000)")},onMouseLeave:a=>{c||(a.currentTarget.style.color="var(--bim-fg, #2c2c2c)")},children:[c&&e.jsx("span",{style:{position:"absolute",left:0,top:"50%",transform:"translateY(-50%)",width:3,height:16,background:"var(--bim-primary, #8B0000)",borderRadius:"0 2px 2px 0"}}),l.label]},l.key)})]})}function nl({items:t,activeKey:n,onSelect:o,onBack:r,backLabel:s}){return e.jsx("div",{style:{flexShrink:0,borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-bg, transparent)"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",overflowX:"auto"},children:[r&&e.jsxs("button",{type:"button",onClick:r,style:{display:"flex",alignItems:"center",gap:4,padding:"10px 12px",fontSize:14,color:"var(--bim-fg, #2c2c2c)",background:"transparent",border:"none",borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",flexShrink:0,whiteSpace:"nowrap"},children:[e.jsx("svg",{width:"14",height:"14",fill:"none",strokeWidth:2,viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M15 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),s]}),t.map(i=>{const l=i.key===n;return e.jsx("button",{type:"button",onClick:()=>o(i.key),style:{padding:"10px 16px",fontSize:14,background:"transparent",border:"none",borderBottom:l?"2px solid var(--bim-primary, #8B0000)":"2px solid transparent",color:l?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",fontWeight:l?500:400,cursor:"pointer",flexShrink:0,whiteSpace:"nowrap"},children:i.label},i.key)})]})})}function Ke({sourceLink:t}){return e.jsxs("div",{style:{position:"absolute",top:24,right:32,zIndex:10,display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Et,{}),t&&e.jsx(Lt,{...t})]})}const ol=({id:t,transport:n,activeTab:o,onTabChange:r,activeJuan:s,onJuanChange:i,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:x=1,selectedLineageNodeId:f,onNavigate:h,onBack:p,backLabel:b,renderLink:v,enrichDetail:g,getSourceLink:y,extraTabs:m=[],showFeedbackTab:S=!0,feedbackApiUrl:w,height:j="100vh",sideNavWidth:_=144,contentMaxWidth:k=1024,className:I,style:E})=>{var Wt,$t,At,Ft,Mt,Pt;const z=P(),{convert:C}=O(),[B,H]=u.useState(null),[W,F]=u.useState(null),[D,L]=u.useState(!0),[$,X]=u.useState(!1),[R,M]=u.useState([]),[oe,Q]=u.useState(!1),[ee,le]=u.useState(null),[ae,U]=u.useState(!1),[q,Te]=u.useState(null),[$e,Ie]=u.useState(!1),[ue,je]=u.useState(null),[ze,Ae]=u.useState(!1),A=u.useRef(null),[ne,K]=u.useState(null),Z=s!==void 0?s:ne,ie=u.useCallback(G=>{i?i(G):K(G)},[i]),T=u.useCallback(async G=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){M([]);return}Q(!0);try{if(n.getCollectionCatalogs){const V=await n.getCollectionCatalogs(G);M(V||[])}else if(n.getCollectionCatalog){const V=await n.getCollectionCatalog(G);M(V?[{resource_id:"",data:V}]:[])}}catch{M([])}finally{Q(!1)}},[n]),N=u.useCallback(async G=>{if(!n.getCollatedEditionIndex){le(null);return}U(!0);try{const V=await n.getCollatedEditionIndex(G);le(V)}catch{le(null)}finally{U(!1)}},[n]),ce=u.useCallback(async G=>{if(!n.getBookFullTextIndex){Te(null);return}Ie(!0);try{const V=await n.getBookFullTextIndex(G);Te(V)}catch{Te(null)}finally{Ie(!1)}},[n]),fe=u.useCallback(async(G,V)=>{Ae(!0);try{if(n.getLineageGraph){const xe=await n.getLineageGraph(G);xe&&je(xe)}const de=V.version_graph;if(!de||!de.enabled){ue||je(null),A.current=null;return}const re=V.books??[],he=[];for(const xe of re)try{const Re=await n.getItem(xe);Re&&he.push(Re)}catch{}A.current={work:V,books:he};const Oe=a??de.default_collection??(de.core_books&&de.core_books.length>0?"core":"all"),J=Oe==="core"&&Array.isArray(de.core_books)&&de.core_books.length>0?"core":Oe??"all";je(lt(V,he,J))}catch{je(null),A.current=null}finally{Ae(!1)}},[n]);u.useEffect(()=>{let G=!1;return(async()=>{L(!0),X(!1),H(null),F(null),M([]),le(null),je(null),A.current=null;try{const de=await n.getItem(t);if(G)return;if(!de){X(!0);return}const re=de;let he=null;if(n.getEntry&&(he=await n.getEntry(t),G))return;he||(he={id:t,title:re.title??re.primary_name??t,type:re.type??"book"}),g&&g(he,re),H(he),F(re),re.type==="collection"?T(t):re.type==="work"?((re.has_collated||n.getCollatedEditionIndex)&&N(t),(re.version_graph||n.getLineageGraph)&&fe(t,re)):re.type==="book"&&re.has_full_text&&n.getBookFullTextIndex&&ce(t)}catch{G||X(!0)}finally{G||L(!1)}})(),()=>{G=!0}},[t,n,g,T,N,fe,ce]),u.useEffect(()=>{const G=A.current;G&&a&&je(lt(G.work,G.books,a))},[a]);const te=[];if(W){if(te.push({key:"basic",label:((Wt=z.detailTab)==null?void 0:Wt.basicInfo)??"基本信息"}),W.type==="collection"){oe&&R.length===0&&te.push({key:"catalog:loading",label:`${(($t=z.detailTab)==null?void 0:$t.catalog)??"目录"}...`});for(const V of R){const de=V.short_name?`${C(V.short_name)}`:((At=z.detailTab)==null?void 0:At.collectionCatalog)??"丛编目录",re=((Ft=z.detailTab)==null?void 0:Ft.catalogSuffix)??"·目录";te.push({key:`catalog:${V.resource_id}`,label:V.short_name?`${de}${re}`:de})}}W.type==="work"&&(ee||ae)&&te.push({key:"collated",label:ae?`${((Mt=z.detailTab)==null?void 0:Mt.collatedEdition)??"整理本"}...`:((Pt=z.detailTab)==null?void 0:Pt.collatedEdition)??"整理本"}),W.type==="book"&&(q||$e)&&te.push({key:"fulltext",label:$e?"全文...":"全文"}),W.type==="work"&&(ue||ze)&&te.push({key:"lineage",label:ze?"版本传承...":"版本传承"});const G=W.emendated_by;Array.isArray(G)&&G.length>0&&te.push({key:"emendated",label:"考證"});for(const V of m)(V.position??"before-feedback")==="before-feedback"&&V.shouldShow(W)&&te.push({key:V.key,label:V.label});S&&te.push({key:"feedback",label:"反馈"});for(const V of m)V.position==="after-feedback"&&V.shouldShow(W)&&te.push({key:V.key,label:V.label})}const Se=B&&W&&y?y({activeTab:o,activeJuan:Z,entry:B,detail:W}):null,So=()=>{var re,he,Oe;if(D)return e.jsx("div",{style:{padding:"48px 16px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},children:"加载中…"});if($)return e.jsxs("div",{style:{padding:"48px 16px",textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",gap:12},children:[e.jsx("span",{style:{fontSize:32},children:"📭"}),e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})]});if(!B||!W)return null;const G={maxWidth:k,position:"relative"},V="bim-detail-content";if(o==="basic")return e.jsx("div",{className:V,style:G,children:e.jsx(pt,{data:W,transport:n,onNavigate:h,renderLink:v,headerExtra:e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Et,{}),Se&&e.jsx(Lt,{...Se})]}),relatedBooksFooter:ue&&ue.nodes.length>0?e.jsx(rl,{graph:ue,totalBookCount:(()=>{var Re;const J=A.current;if(!J)return;const xe=new Set(((Re=J.work.version_graph)==null?void 0:Re.excluded_books)??[]);return(J.work.books??[]).filter(tt=>!xe.has(tt)).length})(),onOpen:()=>r("lineage")}):null})});if(typeof o=="string"&&o.startsWith("catalog:")){const J=(re=R.find(xe=>`catalog:${xe.resource_id}`===o))==null?void 0:re.data;return e.jsxs("div",{className:V,style:G,children:[e.jsx(Ke,{sourceLink:Se}),e.jsx(_t,{data:J,onNavigate:h,renderLink:v})]})}if(o==="collated")return e.jsxs("div",{className:V,style:G,children:[e.jsx(Ke,{sourceLink:Se}),e.jsx(Tt,{index:ee||void 0,workId:t,transport:n,onNavigate:h,activeJuan:Z,onJuanChange:ie})]});if(o==="fulltext")return e.jsxs("div",{className:V,style:G,children:[e.jsx(Ke,{sourceLink:Se}),e.jsx(to,{index:q||void 0,bookId:t,transport:n,activeChapter:Z,onChapterChange:ie})]});if(o==="lineage"){if(!ue)return e.jsx("div",{style:{...G,color:"var(--bim-desc-fg, #999)"},children:ze?"加载中…":"暂无版本图数据"});const J=W.type==="work"?W:null;return e.jsxs("div",{className:V,style:G,children:[e.jsx(Ke,{sourceLink:Se}),e.jsx(jo,{graph:ue,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:f,collection:a??((he=J==null?void 0:J.version_graph)==null?void 0:he.default_collection),onCollectionChange:d,collectionsAvailable:(Oe=J==null?void 0:J.version_graph)==null?void 0:Oe.collections,collectionCounts:(()=>{var Ht,Ot,Dt,Nt,Vt,Ut,Gt;if(!J)return;const xe={},Re=((Ht=A.current)==null?void 0:Ht.books)??[];xe.all=(((Ot=J.books)==null?void 0:Ot.length)??0)-(((Nt=(Dt=J.version_graph)==null?void 0:Dt.excluded_books)==null?void 0:Nt.length)??0);const tt=(Vt=J.version_graph)==null?void 0:Vt.collections;if(tt)for(const Yt of Object.keys(tt))xe[Yt]=lt(J,Re,Yt).nodes.filter(Kt=>Kt.kind==="book"&&!Kt.bridge).length;return xe.core==null&&((Gt=(Ut=J.version_graph)==null?void 0:Ut.core_books)!=null&&Gt.length)&&(xe.core=J.version_graph.core_books.length),xe})()})]})}if(o==="emendated"){const J=W.emendated_by;return!Array.isArray(J)||J.length===0?null:e.jsxs("div",{className:V,style:G,children:[e.jsx(Ke,{sourceLink:Se}),e.jsx(wt,{items:J,onNavigate:h,renderLink:v})]})}if(o==="feedback"&&S)return e.jsx("div",{className:V,style:G,children:e.jsx(bo,{resourceId:t,apiUrl:w})});const de=m.find(J=>J.key===o);return de?de.render({detail:W,entry:B,transport:n,onNavigate:h}):null},ko={height:j,display:"flex",background:"var(--bim-bg, transparent)",color:"var(--bim-fg, #2c2c2c)",...E},wo=b??"返回索引",Bt=B||D,_o=["bim-detail-root",I].filter(Boolean).join(" ");return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:el}),e.jsxs("div",{className:_o,style:ko,children:[Bt&&e.jsx("div",{className:"bim-detail-side-nav",children:e.jsx(tl,{items:te,activeKey:o,onSelect:r,onBack:p,backLabel:wo,width:_})}),Bt&&e.jsx("div",{className:"bim-detail-top-nav",children:e.jsx(nl,{items:te,activeKey:o,onSelect:r,onBack:p,backLabel:"返回"})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:So()})]})]})};function rl({graph:t,totalBookCount:n,onOpen:o}){const r=n??t.nodes.filter(s=>s.kind==="book").length;return e.jsxs("div",{onClick:o,role:"button",tabIndex:0,onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&o()},style:{display:"flex",alignItems:"center",gap:12,padding:"10px 14px",background:"var(--bim-info-bg, #e7f3ff)",color:"var(--bim-info-fg, #0c5380)",border:"1px solid var(--bim-info-border, #b3dbff)",borderRadius:6,cursor:"pointer",fontSize:13,lineHeight:1.5},children:[e.jsx("div",{style:{fontSize:18,lineHeight:1},children:"📜"}),e.jsxs("div",{style:{flex:1},children:["本作品共有 ",e.jsx("strong",{children:r})," 个版本,已整理出版本之间的传承关系。",t.description&&e.jsxs("span",{style:{opacity:.85},children:[" ",t.description.slice(0,40),"…"]})]}),e.jsx("span",{style:{padding:"2px 10px",background:"var(--bim-info-fg, #0c5380)",color:"var(--bim-info-bg, #fff)",borderRadius:4,fontSize:12,whiteSpace:"nowrap"},children:"查看版本源流 →"})]})}exports.BidLink=Y.BidLink;exports.BookIndexError=Y.BookIndexError;exports.BookIndexManager=Y.BookIndexManager;exports.BookIndexStorage=Y.BookIndexStorage;exports.BundleStorage=Y.BundleStorage;exports.ConfigError=Y.ConfigError;exports.GithubStorage=Y.GithubStorage;exports.IdGenerationError=Y.IdGenerationError;exports.IdGenerator=Y.IdGenerator;exports.LocalStorage=Y.LocalStorage;exports.MigrationError=Y.MigrationError;exports.StorageError=Y.StorageError;exports.base36Decode=Y.base36Decode;exports.base36Encode=Y.base36Encode;exports.base58Decode=Y.base58Decode;exports.buildId=Y.buildId;exports.buildPromotionMap=Y.buildPromotionMap;exports.cleanName=Y.cleanName;exports.decodeId=Y.decodeId;exports.decodeIdString=Y.decodeIdString;exports.encodeId=Y.encodeId;exports.extractIdFromUrl=Y.extractIdFromUrl;exports.extractStatus=Y.extractStatus;exports.extractType=Y.extractType;exports.normalizeCatalog=Y.normalizeCatalog;exports.parseId=Y.parseId;exports.shardOf=Y.shardOf;exports.smartDecode=Y.smartDecode;exports.validateResource=Y.validateResource;exports.Badge=ct;exports.BidUrlProvider=Ao;exports.BookDetailLayout=ol;exports.BookFullText=to;exports.CollatedEdition=Tt;exports.CollectionCatalog=_t;exports.CreateEntityDialog=ao;exports.EmendatedBySection=wt;exports.EntityDetail=Nn;exports.EntityPickerDialog=po;exports.EntitySelector=lo;exports.FeedbackButton=ys;exports.FeedbackDialog=go;exports.FeedbackForm=ho;exports.FeedbackList=Rt;exports.FeedbackTab=bo;exports.FormInput=ge;exports.FormTextArea=Be;exports.HomePage=jt;exports.IndexApp=Ci;exports.IndexBrowser=yt;exports.IndexDetail=pt;exports.IndexEditor=xo;exports.IndexView=as;exports.LocaleContext=Qe;exports.LocaleProvider=Uo;exports.LocaleToggle=Et;exports.ModeIndicator=On;exports.RelationPanel=io;exports.RepoSourceLink=Lt;exports.ResourceEditor=mt;exports.ResourceList=kt;exports.SearchInput=Dn;exports.Section=me;exports.SmartBidInput=st;exports.SourceEditor=no;exports.VersionLineageGraph=vo;exports.VersionLineageList=yo;exports.VersionLineageView=jo;exports.WorkCatalog=Ii;exports.buildLineageGraph=lt;exports.detailToEditor=fo;exports.editorToDetail=ls;exports.formatTemplate=et;exports.parseSourceString=oo;exports.stringifySources=ro;exports.useBidUrl=ve;exports.useConvert=O;exports.useT=P;exports.validateLineageGraph=Ls;
|