book-index-ui 0.2.23 → 0.2.25

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 CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var Pn=Object.create;var pt=Object.defineProperty;var Fn=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var Hn=Object.getPrototypeOf,Dn=Object.prototype.hasOwnProperty;var On=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Mn(n))!Dn.call(t,s)&&s!==r&&pt(t,s,{get:()=>n[s],enumerable:!(o=Fn(n,s))||o.enumerable});return t};var Ce=(t,n,r)=>(r=t!=null?Pn(Hn(t)):{},On(n||!t||!t.__esModule?pt(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-C7sHSk4U.cjs"),e=require("react/jsx-runtime"),f=require("react"),An=require("react-dom"),Vn=t=>`/book-index?id=${t}`,Zt=f.createContext(Vn);function Un({buildUrl:t,children:n}){const r=f.useMemo(()=>t,[t]);return e.jsx(Zt.Provider,{value:r,children:n})}function ae(){return f.useContext(Zt)}function be(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Nn(t,n){return be(t).includes(n)}const Qt={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Yn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Gn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Pe=f.createContext(null),en={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:"圖片資源"}},Kn={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:"图片资源"}},Jn={"zh-Hant":en,"zh-Hans":Kn},tn="bim-locale";function qn(){try{const t=localStorage.getItem(tn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Xn(t){try{localStorage.setItem(tn,t)}catch{}}const Zn="zh-Hant",Qn=({locale:t,onLocaleChange:n,children:r})=>{const[o,s]=f.useState(t??Zn),i=t??o;f.useEffect(()=>{if(t)return;const u=qn();u&&u!==o&&s(u)},[]);const[c,l]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const p=u.Converter({from:"tw",to:"cn"});l(()=>p)}).catch(()=>{l(()=>u=>u)}):l(null)},[i]);const a=f.useCallback(u=>{s(u),Xn(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:i,setLocale:a,messages:Jn[i],converter:c}),[i,a,c]);return e.jsx(Pe.Provider,{value:d,children:r})};function F(){const t=f.useContext(Pe);return(t==null?void 0:t.messages)??en}const er=2e3;function A(){const t=f.useContext(Pe),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const i=f.useCallback(c=>{if(!c)return"";if(!r)return c;const l=o.current.get(c);if(l!==void 0)return l;const a=r(c);if(o.current.size>=er){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(c,a),a},[r]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Fe(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function tr(t){if(!t)return"";try{const n=new URL(t).hostname,r={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(r[n])return r[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function nr(){return{id:"",name:"",url:"",type:"text",details:""}}const tt=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:s})=>{const i=F(),[c,l]=f.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}],u=y=>{if(!s)return!0;const v=be(y);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},p=t.map((y,v)=>({item:y,originalIndex:v})).filter(({item:y})=>u(y)),h=()=>{const y=nr();s&&(y.type=s),n([...t,y]),l(t.length)},x=y=>{n(t.filter((v,z)=>z!==y)),l(null)},b=(y,v,z)=>{const m=[...t];if(m[y]={...m[y],[v]:z},v==="url"&&!m[y].id){const k=tr(z);k&&(m[y].id=k)}n(m)},j=(y,v,z)=>{const k={...t[y].metadata||{}};z?k[v]=z:delete k[v],b(y,"metadata",Object.keys(k).length>0?k:void 0)},g=(y,v)=>{const z=v.trim()?v.split(/[,,、]/).map(m=>m.trim()).filter(Boolean):void 0;b(y,"structure",z)},w=(y,v,z)=>{const k=t[y].coverage||{level:1,ranges:""};v==="level"?k.level=parseInt(z)||1:k.ranges=z,b(y,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.map(({item:y,originalIndex:v})=>{var z,m,k;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(c===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:rr(y.type??"text"),color:"#fff"},children:(()=>{var C,I;const S=be(y);return S.length===0?y.type??"text":S.length===1?((C=a.find(T=>T.value===S[0]))==null?void 0:C.label)??S[0]:S.includes("text")&&S.includes("image")?((I=a.find(T=>T.value==="text+image"))==null?void 0:I.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${i.editor.resourcePlaceholder} ${v+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&y.url&&or(v,o==null?void 0:o[v],r,i),e.jsx("button",{onClick:S=>{S.stopPropagation(),x(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),c===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Nn(y,"image")&&y.url&&ir(y,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.type}),e.jsx("select",{value:y.type,onChange:S=>b(v,"type",S.target.value),style:{...pe,flex:1},children:a.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:S=>b(v,"root_type",S.target.value),style:{...pe,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:S=>b(v,"id",S.target.value),placeholder:i.editor.idAutoExtract,style:{...pe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:S=>b(v,"name",S.target.value),placeholder:i.editor.resourceName,style:{...pe,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:S=>b(v,"url",S.target.value),placeholder:i.editor.resourceUrl,style:pe}),e.jsx("input",{type:"text",value:((z=y.structure)==null?void 0:z.join("、"))||"",onChange:S=>g(v,S.target.value),placeholder:i.editor.structurePlaceholder,style:pe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((m=y.coverage)==null?void 0:m.level)??"",onChange:S=>w(v,"level",S.target.value),placeholder:"1",style:{...pe,width:"60px"}})]}),e.jsxs("label",{style:{...ze,flex:1},children:[e.jsx("span",{style:Ie,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((k=y.coverage)==null?void 0:k.ranges)||"",onChange:S=>w(v,"ranges",S.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...pe,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:S=>b(v,"details",S.target.value),placeholder:i.editor.detailsPlaceholder,style:{...pe,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(([S,C])=>{var I;return e.jsxs("label",{style:{...ze,gap:"4px"},children:[e.jsx("span",{style:{...Ie,minWidth:"56px"},children:C}),e.jsx("input",{type:"text",value:((I=y.metadata)==null?void 0:I[S])||"",onChange:T=>j(v,S,T.target.value),placeholder:C,style:{...pe,flex:1}})]},S)})})]})]})]})]},v)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addResource})]})]})};function rr(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function or(t,n,r,o){const s=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:c=>{c.stopPropagation(),s||r(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:i?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function ir(t,n){const r=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:r?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const pe={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"},ze={display:"flex",alignItems:"center",gap:"6px"},Ie={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},sr={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function lr(t){try{const n=new URL(t).hostname;return sr[n]}catch{return}}const xt={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function ar(t){return t.includes("text")&&t.includes("image")?xt["text+image"]:xt[t[0]||"physical"]}const ut={text:0,image:1,physical:2};function Ve(t){return t.length===0?"physical":[...t].sort((n,r)=>(ut[n]??99)-(ut[r]??99)).join("+")}function cr(t){const n=i=>{const c=i.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const l=i.match(/^(.+?)[·(](\d+)[)]?$/);return l?[l[1],parseInt(l[2])]:null},r=new Map,o=[],s=new Set;for(let i=0;i<t.length;i++){const c=t[i];if(c.volumes&&c.volumes.length>0)continue;const l=n(c.name);if(!l)continue;const[a,d]=l,u=`${a}|${Ve(be(c))}`;r.has(u)||r.set(u,{base:{...c,name:a,url:"",volumes:[]},volumes:[]}),r.get(u).volumes.push({volume:d,url:c.url||void 0,status:"found"}),s.add(i)}for(const[,i]of r)if(i.volumes.length>=2)i.volumes.sort((c,l)=>c.volume-l.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,o.push(i.base);else for(let c=0;c<t.length;c++)if(s.has(c)){const l=n(t[c].name),a=l&&`${l[0]}|${Ve(be(t[c]))}`,d=`${i.base.name}|${Ve(be(i.base))}`;a===d&&s.delete(c)}for(let i=0;i<t.length;i++)s.has(i)||o.push(t[i]);return o}const it=({items:t,groupByType:n=!0,onNavigate:r,renderLink:o})=>{const s=F(),i=f.useMemo(()=>cr(t||[]),[t]),c={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},l=p=>c[p]?c[p]:p.split("+").map(h=>c[h]||h).join("+");if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((p,h)=>e.jsx(ft,{item:p},p.id||h))});const a=new Map;for(const p of i){const h=Ve(be(p));a.has(h)||a.set(h,[]),a.get(h).push(p)}const d=["text","image","text+image","physical"],u=[...d.filter(p=>a.has(p)),...[...a.keys()].filter(p=>!d.includes(p)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(p=>{const h=a.get(p),x=ar(p.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:x,whiteSpace:"nowrap",flexShrink:0},children:l(p)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:h.map((b,j)=>e.jsx(ft,{item:b,onNavigate:r,renderLink:o},b.id||j))})]},p)})})};function dr(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 pr(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const r=n.match(/^(\d+)/);return r?parseInt(r[1],10):void 0}function xr(t){if(t.url)return t.url;for(const[n,r]of Object.entries(t))if(n.endsWith("_url")&&typeof r=="string")return r}const ur={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},ft=({item:t})=>{const n=F(),{convert:r}=A(),[o,s]=f.useState(!1),i=f.useMemo(()=>(t.url?lr(t.url):void 0)||r(t.name),[t.url,t.name,r]),c=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||xr(b)})),[t.volumes]),l=c&&c.length>0,a=l?new Set(c.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=l?new Set(c.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=t.expected_volumes??(l?a+d:0),p=t.color_mode?{...ur[t.color_mode],label:n.colorMode[t.color_mode]}:null,h=t.details&&!l?r(t.details):null,x={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:x,children:[e.jsx("span",{style:{fontWeight:500},children:i}),p&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:p.bg,color:p.fg},children:p.label}),h&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:h}),l&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=pr(t.metadata);return b?dr(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}),l&&e.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),l&&o&&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:c.map(b=>{const j=b.status==="missing";return b.url&&!j?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:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.6:1},children:b.volume},b.volume)})})]})},nn=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:i,onSelectFolder:c})=>{const l=F(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",p=u?u.split(/[/\\]/).pop()||u:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},x={onMouseOver:j=>j.currentTarget.style.opacity="0.8",onMouseOut:j=>j.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?l.mode.switchToOfficial:l.mode.switchToDraft,style:{...h,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...x,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return r==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:o,title:l.mode.switchToSync,style:h,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:l.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:c,title:u||l.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:l.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:l.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:p||l.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:a?l.mode.switchToGithub:l.mode.switchToLocal,style:h,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?l.mode.localMode:l.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:c,title:u||l.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!a&&p&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:p})]})]})},Ge="bim-search-history",gt=10,ht=8;function Le(){try{const t=localStorage.getItem(Ge);return t?JSON.parse(t):[]}catch{return[]}}function fr(t){try{const n=Le().filter(r=>r!==t);n.unshift(t),n.length>gt&&(n.length=gt),localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function gr(t){try{const n=Le().filter(r=>r!==t);localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function hr(){try{localStorage.removeItem(Ge)}catch{}}const rn=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:s,placeholder:i})=>{const c=F(),l=i??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection,entity:c.indexType.entity},[d,u]=f.useState(!1),[p,h]=f.useState([]),[x,b]=f.useState(-1),[j,g]=f.useState(Le),w=f.useRef(null),y=f.useRef(null),v=f.useRef(null),z=f.useRef(!1);f.useEffect(()=>{b(-1);const _=n.trim();if(!_){h(j.map(M=>({type:"history",text:M})));return}if(!t.searchAll){h([]);return}let B=!1;const D=setTimeout(()=>{t.searchAll(_,ht).then(M=>{if(B)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];h($.slice(0,ht).map(H=>({type:"entry",text:H.title||H.id,entry:H})))}).catch(()=>{B||h([])})},80);return()=>{B=!0,clearTimeout(D)}},[n,j,t]),f.useEffect(()=>{const _=B=>{v.current&&!v.current.contains(B.target)&&u(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]),f.useEffect(()=>{const _=B=>{var D,M;if(B.key==="/"&&document.activeElement!==w.current){const $=(D=document.activeElement)==null?void 0:D.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;B.preventDefault(),(M=w.current)==null||M.focus()}};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[]);const m=f.useCallback(_=>{_.trim()&&(fr(_.trim()),g(Le())),o(_),u(!1)},[o]),k=f.useCallback(_=>{_.type==="history"?(r(_.text),m(_.text)):_.entry&&(s?(s(_.entry),u(!1)):(r(_.text),m(_.text)))},[r,m,s]),S=f.useCallback(_=>{if(!d||p.length===0){_.key==="Enter"&&m(n);return}switch(_.key){case"ArrowDown":_.preventDefault(),b(B=>(B+1)%p.length);break;case"ArrowUp":_.preventDefault(),b(B=>(B-1+p.length)%p.length);break;case"Enter":_.preventDefault(),x>=0&&x<p.length?k(p[x]):m(n);break;case"Escape":_.preventDefault(),u(!1);break}},[d,p,x,n,m,k]),C=f.useCallback((_,B)=>{B.stopPropagation(),gr(_),g(Le()),h(D=>D.filter(M=>!(M.type==="history"&&M.text===_)))},[]),I=f.useCallback(_=>{_.stopPropagation(),hr(),g([]),h([])},[]);f.useEffect(()=>{if(x>=0&&y.current){const _=y.current.children;_[x]&&_[x].scrollIntoView({block:"nearest"})}},[x]);const T=!n.trim()&&j.length>0;return e.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:w,type:"text",placeholder:l,value:n,onChange:_=>{r(_.target.value),u(!0)},onCompositionStart:()=>{z.current=!0},onCompositionEnd:()=>{z.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,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&&p.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&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:c.search.history}),e.jsx("button",{onClick:I,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),p.map((_,B)=>e.jsxs("div",{onClick:()=>k(_),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===x?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:_.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.text}),_.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[_.entry.type],_.entry.edition&&` · ${_.entry.edition}`,_.entry.author&&` · ${_.entry.author}`]}),_.type==="history"&&e.jsx("button",{onClick:D=>C(_.text,D),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${_.type}-${_.text}-${B}`))]})]})},$e="bim-recent-ids",bt="bim-recent-entries",mt=50,Ze=5,br=50,mr=200;function Be(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(bt);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem($e,JSON.stringify(r)),localStorage.removeItem(bt),r}return[]}catch{return[]}}function yr(t){try{const n=Be().filter(r=>r!==t);n.unshift(t),n.length>mt&&(n.length=mt),localStorage.setItem($e,JSON.stringify(n))}catch{}}function vr(t){try{const n=Be().filter(r=>r!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function jr(){try{localStorage.removeItem($e)}catch{}}const Sr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},nt=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:s,onSwitchMode:i,onToggleDraft:c,onConfigurePath:l,onSelectFolder:a,hideModeIndicator:d,initialQuery:u,onQueryChange:p,headerRight:h})=>{const x=F(),b=[{type:"work",icon:"✍️",name:x.indexType.work,key:"works"},{type:"book",icon:"📖",name:x.indexType.book,key:"books"},{type:"collection",icon:"📚",name:x.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:x.indexType.entity,key:"entities"}],[j,g]=f.useState(u??""),[w,y]=f.useState(null),[v,z]=f.useState(null),[m,k]=f.useState(!1),[S,C]=f.useState(null),[I,T]=f.useState(""),[_,B]=f.useState(!u),[D,M]=f.useState(Be),[$,H]=f.useState([]),[L,R]=f.useState(!1),[V,W]=f.useState(!1),[U,Y]=f.useState(null),[Z,ne]=f.useState(null),he=f.useRef(void 0),ge=f.useRef(!1),Q=f.useCallback(async(P,J)=>{if(!P.trim()){B(!0),y(null),z(null);return}B(!1),k(!0),T("");try{if(t.searchAll){const G=await t.searchAll(P,J??Ze);y(G)}else{const G=["work","book","collection","entity"],K=await Promise.all(G.map(ee=>t.search(P,ee,{page:1,pageSize:J??Ze})));y({works:K[0].entries,books:K[1].entries,collections:K[2].entries,entities:K[3].entries,totalWorks:K[0].total,totalBooks:K[1].total,totalCollections:K[2].total,totalEntities:K[3].total})}}catch(G){T(G instanceof Error?G.message:String(G)),y(null)}finally{k(!1)}},[t]);f.useEffect(()=>{let P=!1;const J=()=>{var O,re;const G=["work","book","collection","entity"],K=Promise.all(G.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((O=t.getResourceCounts)==null?void 0:O.call(t).catch(()=>null))??Promise.resolve(null),E=((re=t.getSubtypeStats)==null?void 0:re.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([K,ee,E]).then(([ce,de,dt])=>{P||(Y({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:de==null?void 0:de.hasText,hasImage:de==null?void 0:de.hasImage}),dt&&ne(dt))})};return t.getCounts?t.getCounts().then(G=>{var K,ee;P||(Y({works:G.works,books:G.books,collections:G.collections,entities:G.entities,hasText:(K=G.resourceCounts)==null?void 0:K.hasText,hasImage:(ee=G.resourceCounts)==null?void 0:ee.hasImage}),G.subtypeStats&&ne(G.subtypeStats))}).catch(()=>{P||J()}):J(),()=>{P=!0}},[t]),f.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Q(u))},[u,Q]);const q=f.useCallback(P=>{if(g(P),!P.trim()){p==null||p(P),B(!0),y(null),z(null);return}he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{z(null),p==null||p(P),Q(P)},mr)},[Q,p]),Ke=f.useCallback(P=>{he.current&&clearTimeout(he.current),p==null||p(P),Q(P)},[Q,p]),Je=f.useCallback(P=>{z(P),Q(j,br)},[j,Q]);f.useEffect(()=>{if(!D.length){H([]);return}let P=!1;return R(!0),Promise.all(D.slice(0,10).map(async J=>{var G,K,ee;try{if(t.getEntry){const O=await t.getEntry(J);if(O)return O}const E=await t.getItem(J);if(E){const O=E.authors;return{id:J,title:E.title||J,type:E.type||"work",author:(G=O==null?void 0:O[0])==null?void 0:G.name,dynasty:(K=O==null?void 0:O[0])==null?void 0:K.dynasty,role:(ee=O==null?void 0:O[0])==null?void 0:ee.role,edition:E.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{P||(H(J),R(!1))}),()=>{P=!0}},[D,t]);const we=P=>{C(P.id),yr(P.id),M(Be()),o==null||o(P)},_e=P=>{vr(P),M(Be())},qe=()=>{jr(),M([])},Me=P=>b.find(J=>J.type===P),Xe=w&&(w.works.length>0||w.books.length>0||w.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:x.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&e.jsx(nn,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:i,onToggleDraft:c,onConfigurePath:l,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(rn,{transport:t,value:j,onChange:q,onSearch:Ke,onEntrySelect:we}),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:x.action.newEntry})]}),U&&_&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()})," 本"]}),Z.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.article.toLocaleString()})," 篇"]}):null,Z.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[x.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()}),U.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.entities.toLocaleString()})]})]})}),U.hasImage!=null&&U.hasText!=null&&e.jsxs("span",{children:[x.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),x.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:m?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.searching}):I?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:I})]}):_?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:x.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:x.search.recentBrowse}),e.jsx("button",{onClick:qe,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:x.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,V?10:3).map(P=>P.notFound?e.jsx(kr,{id:P.id,onRemove:_e,t:x},P.id):e.jsx(yt,{entry:P,selected:S===P.id,onClick:we,getConfig:Me,onRemove:_e},P.id))}),!V&&$.length>3&&e.jsx("button",{onClick:()=>W(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:x.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:x.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.searchSubtitle})]})}):Xe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:P,icon:J,name:G,key:K})=>{const ee=w[K]??[],E=Sr[K],O=w[E]??0;if(ee.length===0)return null;const ce=!(v===P)&&O>Ze;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[J," ",G,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[O," ",x.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>Je(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:x.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ee.map(de=>e.jsx(yt,{entry:de,selected:S===de.id,onClick:we,getConfig:Me,query:j},de.id))})]},P)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Fe(x.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:x.search.tryOther})]})})]})},yt=({entry:t,selected:n,onClick:r,getConfig:o,query:s,onRemove:i})=>{const c=F(),{convert:l}=A(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(u=>{const p=typeof u=="string"?u:u==null?void 0:u.book_title;return p==null?void 0:p.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>r(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:l(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:c.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:c.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:l(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,c.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:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(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:[c.search.alias,":",l(d)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:c.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:"→"})]})},kr=({id:t,onRemove:n,t:r})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:r.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:r.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function wr(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 _r({data:t}){const{convert:n}=A(),{dynasty:r,birth_year:o,death_year:s}=t,i=[];return r&&i.push(`〔${n(r)}〕`),o!==void 0&&s!==void 0?i.push(`${o}—${s}`):o!==void 0?i.push(`${o}—?`):s!==void 0&&i.push(`?—${s}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function Cr({alt_names:t}){const{convert:n}=A(),r=new Map;for(const i of t){const c=i.type||"別名";r.has(c)||r.set(c,[]),r.get(c).push(i.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...r.keys()].sort((i,c)=>{const l=o.indexOf(i),a=o.indexOf(c);return l===-1&&a===-1?0:l===-1?1:a===-1?-1:l-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 c=r.get(i);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:i}),e.jsx("span",{children:c.map((l,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(l)]},a))})]},i)})})}function zr({data:t}){const n=t.external_ids;if(!n)return null;const r=[];return n.cbdb_id&&r.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),r.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function Ir({works:t,transport:n,onNavigate:r,renderLink:o}){const s=F(),{convert:i}=A(),c=ae(),[l,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let h=!1;const x=t.map(j=>j.work_id);return(async()=>{const j=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(x);let z=!0;for(let m=0;m<x.length;m++){const k=v[m];k!=null&&k.title?j.set(x[m],k.title):k!=null&&k.primary_name?j.set(x[m],k.primary_name):z=!1}if(z)return j}catch{}const g=[...x],w=8,y=new Array(w).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!j.has(v))try{if(n.getEntry){const k=await n.getEntry(v);if(k!=null&&k.title){j.set(v,k.title);continue}}const z=await n.getItem(v),m=z&&(z.title||z.primary_name)||v;j.set(v,m)}catch{j.set(v,v)}}});return await Promise.all(y),j})().then(j=>{h||a(j)}),()=>{h=!0}},[t,n]);const d=new Map;for(const h of t){const x=h.role||"";d.has(x)||d.set(x,[]),d.get(x).push(h)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],p=[...d.keys()].sort((h,x)=>{const b=u.indexOf(h),j=u.indexOf(x);return b===-1&&j===-1?h.localeCompare(x):b===-1?1:j===-1?-1:b-j});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),p.map(h=>{const x=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:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.map((b,j)=>{const g=i(l.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,g)},j):r?e.jsx("li",{children:e.jsx("a",{href:c(b.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),r(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},j):e.jsx("li",{children:g},j)})})]},h)})]})}const on=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:s})=>{var u;const i=F(),{convert:c}=A();let l=!1;try{l=N.extractStatus(t.id)==="draft"}catch{}const a=wr(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:[c(t.primary_name),e.jsx(_r,{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}),l&&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(Cr,{alt_names:t.alt_names}),e.jsx(zr,{data:t}),((u=t.description)==null?void 0:u.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Ir,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},Tr=["〇","一","二","三","四","五","六","七","八","九"],vt=["","十","百","千"];function sn(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",s=!1;for(let i=0;i<r;i++){const c=parseInt(n[i]),l=r-1-i;c===0?s=!0:(s&&o&&(o+="〇"),s=!1,c===1&&l===1&&i===0?o+=vt[l]:o+=Tr[c]+vt[l])}return o}function ln({type:t}){const n=F(),r={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:r[t],border:`1px solid ${r[t]}40`,borderRadius:"2px",background:`${r[t]}08`},children:n.indexType[t]})}function Rr({isDraft:t}){const n=F();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 Er({id:t}){const n=F(),[r,o]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function ie({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 xe({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 an({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:s}=A();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,c)=>{const l=s(i.name),a=i.entity_id?e.jsx(le,{id:i.entity_id,label:l,onNavigate:r,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:l});return e.jsxs("span",{children:[c>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)]})]},c)})})}function le({id:t,label:n,onNavigate:r,renderLink:o}){const s=ae();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),r(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Lr({id:t,title:n,edition:r,type:o,isDraft:s,authors:i,volumeText:c,meta:l,headerExtra:a,onNavigate:d,renderLink:u}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:r}),c&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:c})]}),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(ln,{type:o}),e.jsx(Rr,{isDraft:s}),e.jsx(Er,{id:t})]}),((i==null?void 0:i.length)||l.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(an,{authors:i,type:o,onNavigate:d,renderLink:u}),l]})]})}function cn({items:t,label:n,showMeta:r,onNavigate:o,renderLink:s}){const i=F(),{convert:c}=A();if(!t.length)return null;const[l,a]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const p=l===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...p?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(p?null:u),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c(d.source)}),!p&&r&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(le,{id:d.source_bid,label:i.action.view,onNavigate:o,renderLink:s})})]}),p&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r&&(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(xe,{label:i.label.titleInfo,children:c(d.title_info)}),d.author_info&&e.jsx(xe,{label:i.label.authorInfo,children:c(d.author_info)}),d.edition&&e.jsx(xe,{label:i.label.edition,children:c(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:c(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:c(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:c(d.additional_comment)})]})]})]},u)})})]})}function Br({items:t,onNavigate:n,renderLink:r}){const o=F();return e.jsx(cn,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function dn({items:t,onNavigate:n,renderLink:r}){const o=F();return e.jsx(cn,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function pn({label:t,items:n}){const{convert:r}=A();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const i=typeof o=="string"?o:o.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:r(i)},s)})})]}):null}function Wr({items:t}){const n=F();return e.jsx(pn,{label:n.section.aliases,items:t})}function $r({items:t}){const n=F();return e.jsx(pn,{label:n.section.attachedTexts,items:t})}function Pr({items:t}){const n=F(),{convert:r}=A();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",r(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function Fr({items:t}){const n=F(),{convert:r}=A();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:r(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:r(o.description)})]},s))]})]}):null}function Mr({items:t}){const n=F(),{convert:r}=A();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),r(o)]},s))})]}):null}function jt({title:t,ids:n,transport:r,onNavigate:o,renderLink:s}){const{convert:i}=A(),[c,l]=f.useState([]);return f.useEffect(()=>{if(!n.length){l([]);return}if(!r){l(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>r.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{a||l(d)}),()=>{a=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{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:(c.length?c: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(le,{id:a.id,label:d,onNavigate:o,renderLink:s})},a.id)})})]}):null}function Hr({book:t,onNavigate:n,renderLink:r}){const o=F(),{convert:s}=A(),[i,c]=f.useState(!1),l=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:"10px 14px",borderBottom:l&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(le,{id:t.id,label:a,onNavigate:n,renderLink:r})}),l&&e.jsx("span",{onClick:()=>c(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?o.action.expand:o.action.collapse,children:"▼"})]}),l&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(it,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:r})})]})}function Dr({ids:t,transport:n,onNavigate:r,renderLink:o,footer:s}){const i=F(),[c,l]=f.useState([]);return f.useEffect(()=>{if(!t.length){l([]);return}if(!n){l(t.map(d=>({id:d})));return}let a=!1;return Promise.all(t.map(d=>n.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:d})))).then(d=>{a||l(d)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),s,e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:(c.length?c:t.map(a=>({id:a}))).map(a=>e.jsx(Hr,{book:a,onNavigate:r,renderLink:o},a.id))})]}):null}function Or({workData:t,onNavigate:n,renderLink:r}){var i,c,l;const o=F(),{convert:s}=A();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(ln,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(le,{id:t.id,label:s(t.title),onNavigate:n,renderLink:r})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((i=t.juan_count)==null?void 0:i.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[sn(t.juan_count.number),o.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(an,{authors:t.authors,type:"work",onNavigate:n,renderLink:r}),((c=t.description)==null?void 0:c.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(l=t.authors)!=null&&l.length?"8px 0 0":"0",textAlign:"justify"},children:s(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(xe,{label:o.label.parentWork,children:e.jsx(le,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function Ar({items:t,onNavigate:n,renderLink:r}){const o=F(),{convert:s}=A();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:o.indexType.collection}),e.jsx(le,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:r}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Fe(o.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const st=({data:t,id:n,transport:r,onNavigate:o,renderLink:s,headerExtra:i,relatedBooksFooter:c,className:l,style:a})=>{var B,D,M,$,H,L;const d=F(),{convert:u}=A(),[p,h]=f.useState(null),[x,b]=f.useState(!1),[j,g]=f.useState(null),[w,y]=f.useState(null),[v,z]=f.useState([]),m=t||p;if(f.useEffect(()=>{if(t||!n||!r)return;let R=!1;return b(!0),g(null),r.getItem(n).then(V=>{R||(V?h(V):g(d.misc.notFoundEntry))}).catch(V=>{R||g(V instanceof Error?V.message:d.misc.loadFailed)}).finally(()=>{R||b(!1)}),()=>{R=!0}},[t,n,r]),f.useEffect(()=>{if(!m||!r){y(null),z([]);return}let R=!1;const V=m.type==="book"||m.type==="collection"?m.work_id:void 0;if(V?r.getItem(V).then(W=>{!R&&W&&W.type==="work"&&y(W)}).catch(()=>{}):y(null),m.type==="book"){const W=m;W.contained_in&&W.contained_in.length>0?Promise.all(W.contained_in.map(U=>{const Y=typeof U=="string"?U:U.id,Z=typeof U=="string"?void 0:U.volume_index;return r.getItem(Y).then(ne=>({id:Y,title:ne&&ne.title||Y,volume_index:Z})).catch(()=>({id:Y,title:Y,volume_index:Z}))})).then(U=>{R||z(U)}):z([])}else z([]);return()=>{R=!0}},[m,r]),x)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((R,V)=>e.jsx("div",{style:{height:V===1?"32px":"16px",width:`${R}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},V))})});if(j)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:j});if(!m)return null;if(m.type==="entity")return e.jsx("div",{className:l,style:a,children:e.jsx(on,{data:m,transport:r,onNavigate:o,renderLink:s,headerExtra:i})});const k=m.type==="book"?m:null,S=m.type==="collection"?m:null,C=m.type==="work"?m:null;let I=!1;try{I=N.extractStatus(m.id)==="draft"}catch{}let T="";m.measure_info?T=u(m.measure_info):(B=m.juan_count)!=null&&B.number?T=sn(m.juan_count.number)+d.unit.juan:(D=m.juan_count)!=null&&D.description&&(T=u(m.juan_count.description));const _=[];return(M=m.publication_info)!=null&&M.year&&_.push(e.jsx(xe,{label:d.label.year,children:m.publication_info.year},"year")),($=m.current_location)!=null&&$.name&&_.push(e.jsx(xe,{label:d.label.currentLocation,children:u(m.current_location.name)},"loc")),(H=m.page_count)!=null&&H.description&&_.push(e.jsx(xe,{label:d.label.pageCount,children:m.page_count.description},"page")),k!=null&&k.edition&&_.push(e.jsx(xe,{label:d.label.edition,children:u(k.edition)},"ver")),C!=null&&C.parent_work&&_.push(e.jsx(xe,{label:d.label.parentWork,children:e.jsx(le,{id:C.parent_work.id,label:u(C.parent_work.title),onNavigate:o,renderLink:s})},"pw")),C!=null&&C.parent_works&&C.parent_works.length>0&&!C.parent_work&&_.push(e.jsx(xe,{label:d.label.parentWork,children:C.parent_works.map((R,V)=>e.jsxs("span",{children:[V>0&&"、",e.jsx(le,{id:R,onNavigate:o,renderLink:s})]},R))},"pws")),e.jsxs("div",{className:l,style:a,children:[e.jsx(Lr,{id:m.id,title:u(m.title),edition:m.edition?u(m.edition):void 0,type:m.type,isDraft:I,authors:m.authors,volumeText:T,meta:_,headerExtra:i,onNavigate:o,renderLink:s}),((L=m.description)==null?void 0:L.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(m.description.text)}),v.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.containedIn}),e.jsx(Ar,{items:v,onNavigate:o,renderLink:s})]}),w&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.belongsToWork}),e.jsx(Or,{workData:w,onNavigate:o,renderLink:s})]}),m.additional_works&&m.additional_works.length>0&&e.jsx(Pr,{items:m.additional_works}),m.additional_titles&&m.additional_titles.length>0&&e.jsx(Wr,{items:m.additional_titles}),m.attached_texts&&m.attached_texts.length>0&&e.jsx($r,{items:m.attached_texts}),m.indexed_by&&m.indexed_by.length>0&&e.jsx(Br,{items:m.indexed_by,onNavigate:o,renderLink:s}),m.emendated_by&&m.emendated_by.length>0&&e.jsx(dn,{items:m.emendated_by,onNavigate:o,renderLink:s}),m.resources&&m.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.resources}),e.jsx(it,{items:m.resources,groupByType:!0,onNavigate:o,renderLink:s})]}),(k==null?void 0:k.location_history)&&k.location_history.length>0&&e.jsx(Fr,{items:k.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Mr,{items:S.history}),(k==null?void 0:k.related_books)&&k.related_books.length>0&&e.jsx(jt,{title:d.section.relatedVersions,ids:k.related_books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(jt,{title:d.section.containedBooks,ids:S.books,transport:r,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ie,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(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(le,{id:R.id,label:u(R.title),onNavigate:o,renderLink:s})},R.id))})]}),(C==null?void 0:C.books)&&C.books.length>0&&e.jsx(Dr,{ids:C.books,transport:r,onNavigate:o,renderLink:s,footer:c}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const R=[],V=C.related_works.filter(Y=>Y.relation==="part_of"),W=C.related_works.filter(Y=>Y.relation==="has_part"),U=C.related_works.filter(Y=>!Y.relation);return V.length>0&&R.push({label:d.section.belongsToWork,items:V}),W.length>0&&R.push({label:d.section.containedWorks,items:W}),U.length>0&&R.push({label:d.section.relatedWorks,items:U}),R.map(Y=>e.jsxs("div",{children:[e.jsxs(ie,{children:[Y.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",Y.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Y.items.map(Z=>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(le,{id:Z.id,label:u(Z.title),onNavigate:o,renderLink:s})},Z.id))})]},Y.label))})()]})};function Vr({data:t}){const n=F(),{convert:r}=A(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,i=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:r(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:r(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),i!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",i,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Ur({sections:t,activeSection:n,onSelect:r}){const o=F();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:St(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>r(s.name),style:St(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 St(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Nr({id:t,label:n,onNavigate:r,renderLink:o}){const s=ae();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),r(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Yr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function kt({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const s=F(),{convert:i}=A(),c=t.book_id||t.work_id,l=o&&t.volumes.length>0?Yr(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:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:l}),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]}),c&&e.jsx(Nr,{id:c,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:r}),!c&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const xn=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:s,className:i,style:c})=>{const l=F(),[a,d]=f.useState(null),[u,p]=f.useState(!1),[h,x]=f.useState(null),[b,j]=f.useState(null),[g,w]=f.useState(""),y=t||a;f.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let S=!1;return p(!0),x(null),r.getCollectionCatalog(n).then(C=>{S||(C?d(C):x(l.catalog.notFound))}).catch(C=>{S||x(C instanceof Error?C.message:l.catalog.loadFailed)}).finally(()=>{S||p(!1)}),()=>{S=!0}},[t,n,r,l]);const v=(y==null?void 0:y.sections)&&y.sections.length>0,z=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const S=y.books.map(I=>I.volumes[0]).filter(I=>I!=null);return new Set(S).size<S.length},[y]),m=f.useMemo(()=>{if(!y)return[];let S=y.books;if(b&&(S=S.filter(C=>C.section===b)),g.trim()){const C=g.trim().toLowerCase();S=S.filter(I=>I.title.toLowerCase().includes(C)||I.sub_items&&I.sub_items.some(T=>T.toLowerCase().includes(C))||I.edition&&I.edition.toLowerCase().includes(C))}return S},[y,b,g]),k=f.useMemo(()=>{if(!z)return null;const S=[],C=new Map;for(const T of m){if(!T.volumes||T.volumes.length===0)continue;const _=T.volumes[0];C.has(_)||C.set(_,[]),C.get(_).push(T)}const I=[...C.keys()].sort((T,_)=>T-_);for(const T of I)S.push({volume:T,books:C.get(T)});return S},[m,z]);return u?e.jsx("div",{className:i,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:l.catalog.loading})}):h?e.jsx("div",{className:i,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):y?e.jsxs("div",{className:i,style:c,children:[e.jsx(Vr,{data:y}),v&&e.jsx(Ur,{sections:y.sections,activeSection:b,onSelect:j}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:l.search.searchBookName,value:g,onChange:S=>w(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[m.length," ",l.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((S,C)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Fe(l.catalog.volume,{n:S.volume})}),S.books.map((I,T)=>e.jsx(kt,{book:I,onNavigate:o,renderLink:s,showVolumes:I.volumes.length>1},`${S.volume}-${T}`))]},`${S.volume}-${C}`)):m.map((S,C)=>e.jsx(kt,{book:S,onNavigate:o,renderLink:s,showVolumes:!0},C)),m.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:l.catalog.noMatch})]})]}):null},ye=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},te=6,He=7,Gr=({content:t,children:n,placement:r="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:i})=>{const[c,l]=f.useState(!1),[a,d]=f.useState(null),u=f.useRef(null),p=f.useRef(null),h=f.useRef(null),x=f.useCallback(()=>{const g=p.current,w=h.current;if(!g||!w)return;const y=g.getBoundingClientRect(),v=w.getBoundingClientRect(),z=window.innerHeight,m=document.documentElement.clientWidth;let k=r;r==="top"&&y.top-v.height-He<8&&(k="bottom"),r==="bottom"&&y.bottom+v.height+He>z-8&&(k="top");const S=k==="top"?y.top-v.height-He:y.bottom+He;let C=y.left+y.width/2-v.width/2;C=Math.max(8,Math.min(C,m-v.width-8)),d({left:C,top:S,placement:k})},[r]),b=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>l(!0),o)},[o]),j=f.useCallback(()=>{u.current&&clearTimeout(u.current),l(!1),d(null)},[]);return f.useEffect(()=>{if(!c)return;const g=requestAnimationFrame(x);return()=>cancelAnimationFrame(g)},[c,x]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:p,onMouseEnter:b,onMouseLeave:j,onFocus:b,onBlur:j,style:{display:"inline-block",...i},children:n}),c&&An.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:-te,width:0,height:0,...a.placement==="top"?{bottom:-te,borderTop:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}:{top:-te,borderBottom:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}:{top:-5,borderBottom:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}}})]})]}),document.body)]})},wt={A:"fine",B:"rough",C:"rough",D:"ocr"};function Kr(t){return typeof t!="string"?null:t in Qt?t:t in wt?wt[t]:null}const Jr={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function X(t){return typeof t!="string"?"":Jr[t]??t}const qr=["〇","一","二","三","四","五","六","七","八","九"],_t=["","十","百","千"],Xr=["","萬","億"];function un(t){if(t===0)return"〇";if(t<0)return`負${un(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const s=r%1e4;s>0?n.unshift(Zr(s,o>0)+Xr[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Zr(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let s="";for(let i=0;i<r.length;i++){const c=r[i],l=r.length-1-i;c===0?s&&!s.endsWith("〇")&&(s+="〇"):c===1&&l===1&&i===0&&!n?s+=_t[l]:s+=qr[c]+_t[l]}return s.replace(/〇$/,"")}let We=null,De=null;const Ne=new Set;function Qr(){return We?Promise.resolve():De||(De=import("opencc-js/t2cn").then(t=>{We=t.Converter({from:"tw",to:"cn"}),Ne.forEach(n=>n())}).catch(()=>{We=t=>t,Ne.forEach(t=>t())}),De)}function fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(We)return;const n=()=>t(r=>r+1);return Ne.add(n),Qr(),()=>{Ne.delete(n)}},[]),We??(n=>n)}function Se(t,n){return n(t).toLowerCase()}const lt="#fff59d";function ke(t,n,r){if(!n)return t;const o=Se(n,r);if(!o)return t;const s=Se(t,r);if(s.length!==t.length)return t;const i=[];let c=0,l=0;for(;c<t.length;){const a=s.indexOf(o,c);if(a===-1){i.push(t.slice(c));break}a>c&&i.push(t.slice(c,a)),i.push(e.jsx("mark",{style:{background:lt,padding:0,color:"inherit"},children:t.slice(a,a+o.length)},l++)),c=a+o.length}return e.jsx(e.Fragment,{children:i})}function at(t,n,r,o){if(!n)return!0;const s=Se(n,o);return(r?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(c=>typeof c=="string"&&Se(c,o).includes(s))}function eo(t,n,r){return n?Se(t,r).includes(Se(n,r)):!0}const ct={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},to={考证:"#5d6d7e"};function no(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function fn({file:t,isActive:n,onSelect:r,meta:o,matchState:s}){const i=s===0,c=s==="loading",l=typeof s=="number"&&s>0,a=no(t),d=!!(o!=null&&o.vol_label)&&!a.includes(o.vol_label);return e.jsxs("button",{onClick:()=>{i||r(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":l?`${lt}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:["(",o.vol_label,"冊)"]}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function gn(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(o=>gn(o,n)))}function hn(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((s,i)=>s+hn(i),0))||0;return n+r}function ro(t,n){const r=[],o=c=>{var l;r.push(...c.files),(l=c.children)==null||l.forEach(o)};if(o(t),r.length===0)return;const s=r.map(c=>n[c]);if(s.every(c=>c===void 0))return;if(s.some(c=>c==="loading"))return"loading";let i=0;for(const c of s)typeof c=="number"&&(i+=c);return i}function bn({group:t,activeFile:n,onSelect:r,depth:o=0,juanMeta:s,matchStates:i}){var b;const c=gn(t,n||""),l=ro(t,i),a=typeof l=="number"&&l>0,d=l===0,[u,p]=f.useState(c||a),h=hn(t),x=!!((b=t.children)!=null&&b.length);if(f.useEffect(()=>{c&&p(!0)},[c]),f.useEffect(()=>{a&&p(!0)},[a]),t.files.length===1&&!x){const j=t.files[0],g=n===j,w=i[j],y=w===0,v=w==="loading",z=typeof w=="number"&&w>0;return e.jsxs("button",{onClick:()=>{y||r(j)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":y?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:g?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":z?`${lt}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,z&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:w}),v&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>p(!u),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:c?"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:u?"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:["匹配 ",l]}),l==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),u&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(j=>e.jsx(fn,{file:j,isActive:n===j,onSelect:r,meta:s==null?void 0:s[j],matchState:i[j]},j))}),x&&t.children.map((j,g)=>e.jsx(bn,{group:j,activeFile:n,onSelect:r,depth:o+1,juanMeta:s,matchStates:i},g))]})]})}function oo({files:t,groups:n,activeFile:r,onSelect:o,juanMeta:s,matchStates:i}){const c=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((l,a)=>e.jsx(bn,{group:l,activeFile:r,onSelect:o,juanMeta:s,matchStates:i},a))}):c.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(l=>e.jsx(fn,{file:l,isActive:r===l,onSelect:o,meta:s==null?void 0:s[l],matchState:i[l]},l))})}function io({type:t}){const n=ct[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 so({section:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=A(),s=ae(),i=fe(),c=j=>{if(!j)return"";const g=o(j);return r?ke(g,r,i):g},[l,a]=f.useState(!1),d=!!t.summary,u=!!t.comment,p=!!t.additional_comment,h=!!(t.content&&t.content.length>60),x=d||u||p||h;f.useEffect(()=>{r&&a(!0)},[r]);const b=!l&&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:()=>x&&a(!l),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:x?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[x&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:l?"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:["《",c(t.book_title),"》"]}):c(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[un(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:c(t.author_info||t.author)})]}),!l&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:c(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:c(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:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),l&&x&&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:c(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:c(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:c(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:c(t.additional_comment)})]}),h&&!d&&!u&&!p&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)})]})]})}function lo({section:t,highlightQuery:n=""}){const{convert:r}=A(),o=fe(),s=a=>{if(!a)return"";const d=r(a);return n?ke(d,n,o):d},[i,c]=f.useState(!1),l=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>l&&c(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:l?"pointer":"default",userSelect:"none"},children:[e.jsx(io,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),l&&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&&l&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${ct[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 ao({section:t,highlightQuery:n=""}){const{convert:r}=A(),o=fe();if(!t.content&&!t.title)return null;const s=r((t.content||t.title||"").replace(/\n{2,}/g,`
2
- `)),i=n?ke(s,n,o):s,c=ct[t.type]||"#717171",l=X(t.type)==="序"||X(t.type)==="结语";return e.jsxs("div",{style:{padding:l?"10px 12px":"6px 0",margin:l?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:l?`3px solid ${c}40`:void 0,background:l?"var(--bim-bg, #fafafa)":void 0,borderRadius:l?"0 4px 4px 0":void 0,position:"relative"},children:[l&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:c,marginRight:"8px",padding:"1px 5px",border:`1px solid ${c}40`,borderRadius:"2px",background:`${c}08`,verticalAlign:"middle"},children:t.type}),i]})}function co(t,n,r){const[o,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let i=!1;const c=t.filter(u=>{var p;return!((p=r==null?void 0:r.current)!=null&&p.has(u))}),l={};for(const u of t)(d=r==null?void 0:r.current)!=null&&d.has(u)&&(l[u]=r.current.get(u));if(Object.keys(l).length>0&&s(l),c.length===0)return;const a=async u=>{var p;try{if(n.getEntry){const g=await n.getEntry(u);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(u);if(!h)return null;const x=h.title||u,b=h.authors,j=(p=b==null?void 0:b[0])==null?void 0:p.name;return{title:x,author:j}}catch{return null}};return Promise.all(c.map(async u=>{var h;const p=await a(u);return(h=r==null?void 0:r.current)==null||h.set(u,p),[u,p]})).then(u=>{i||s(p=>{const h={...p};for(const[x,b]of u)h[x]=b;return h})}),()=>{i=!0}},[t.join(","),n]),o}function po({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:s=""}){const{convert:i}=A(),c=ae(),l=fe(),a=y=>{if(!y)return"";const v=i(y);return s?ke(v,s,l):v},[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const p=t.type,h=to[p]||"#717171",x=!!t.content,b=t.work_ids||[],j=b.length>1,g=co(j?b:[],r,o),w=x&&!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:()=>x&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:x?"pointer":"default",userSelect:"none"},children:[x&&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&&w&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(w)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:c(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),j&&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:p})]})]}),j&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const v=g[y],z=v?`${i(v.title)}${v.author?`(${i(v.author)})`:""}`:y.slice(0,8)+"…";return e.jsxs("a",{href:c(y),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(y))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",z]},y)})}),d&&x&&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 xo({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:s}){const{convert:i}=A(),c=fe(),l=n.trim(),a=f.useMemo(()=>l?t.sections.filter(p=>at(p,l,!0,c)):t.sections,[t.sections,l,c]),d=t.sections.filter(p=>X(p.type)==="考证").length,u=a.filter(p=>X(p.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:l?`${u} / ${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((p,h)=>e.jsx(po,{section:p,onNavigate:r,transport:o,workLabelCache:s,highlightQuery:l},h))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function uo({text:t,highlightQuery:n=""}){const{convert:r}=A(),o=fe(),s=c=>{const l=r(c);return n?ke(l,n,o):l},i=t.split(`
3
- `);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((c,l)=>{if(c.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(c.slice(2))},l);if(c.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(c.slice(3))},l);if(c.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(c.slice(4))},l);if(!c.trim())return l>0&&!i[l-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},l);const a=c.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,u)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},u):e.jsx(f.Fragment,{children:s(d)},u))},l)})})}function fo({sections:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=A(),s=ae(),i=fe(),c=d=>{if(!d)return"";const u=o(d);return r?ke(u,r,i):u},l=[];let a=null;for(const d of t)X(d.type)==="类"?(a&&l.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):X(d.type)==="书"?(a||(a={category:"",items:[]}),a.items.push(d)):(X(d.type)==="序"||X(d.type)==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),X(d.type)==="结语"&&(l.push(a),a=null));return a&&l.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:l.map((d,u)=>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:[c(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:c(d.categoryContent)})]}),d.items.map((p,h)=>X(p.type)==="序"||X(p.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:c(p.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&p.work_id?e.jsx("a",{href:s(p.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),x.stopPropagation(),n(p.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(p.title),children:e.jsx("strong",{children:c(p.title)})}):e.jsx("strong",{children:c(p.title)}),p.content&&c(p.content)]},h))]},u))})}function go({juan:t,rawText:n,searchQuery:r,onNavigate:o}){const{convert:s}=A(),i=fe(),[c,l]=f.useState("catalog"),a=r.trim(),d=f.useMemo(()=>a?t.sections.filter(x=>at(x,a,!1,i)):t.sections,[t.sections,a,i]),u=t.sections.filter(x=>X(x.type)==="书").length,p=t.sections.filter(x=>X(x.type)==="诗").length,h=a?d.filter(x=>X(x.type)==="书"||X(x.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(x=>e.jsx("button",{onClick:()=>l(x),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:x==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:c===x?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:c===x?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:x==="catalog"?"目錄":"原文"},x))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${p>0?`${p} 首`:`${u} 部書`}`:p>0?`${p} 首`:`${u} 部书`})]}),c==="raw"&&(n?e.jsx(uo,{text:n,highlightQuery:a}):e.jsx(fo,{sections:t.sections,onNavigate:o,highlightQuery:a})),c==="catalog"&&d.map((x,b)=>X(x.type)==="书"||X(x.type)==="诗"?e.jsx(so,{section:x,onNavigate:o,highlightQuery:a},b):X(x.type)==="类"?e.jsx(lo,{section:x,highlightQuery:a},b):e.jsx(ao,{section:x,highlightQuery:a},b)),c==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function mn(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 Ct(t){const n=mn(t);return n.length>0?n[0]:null}function ho(t){const{workId:n,transport:r,files:o,activeFile:s,activeJuan:i,activeRawText:c,query:l,isKaozhen:a}=t,d=fe(),u=f.useRef(new Map),[p,h]=f.useState({});f.useEffect(()=>{s&&i&&u.current.set(s,{juan:i,rawText:c})},[s,i,c]),f.useEffect(()=>{u.current.clear(),h({})},[n]);const x=f.useCallback((b,j)=>{let g=0;if(b.juan)for(const w of b.juan.sections)at(w,j,a,d)&&g++;return g===0&&b.rawText&&eo(b.rawText,j,d)&&(g=1),g},[a,d]);return f.useEffect(()=>{const b=l.trim();if(!b){h({});return}if(!n||!(r!=null&&r.getCollatedJuan)||o.length===0)return;let j=!1;const g={},w=[];for(const k of o){const S=u.current.get(k);S?g[k]=x(S,b):(g[k]="loading",w.push(k))}h(g);const y=8;let v=0;const z=async()=>{var k;for(;v<w.length;){if(j)return;const S=v++,C=w[S];try{const[I,T]=await Promise.all([r.getCollatedJuan(n,C),((k=r.getCollatedJuanText)==null?void 0:k.call(r,n,C))??Promise.resolve(null)]),_={juan:I,rawText:T};if(u.current.set(C,_),j)return;h(B=>({...B,[C]:x(_,b)}))}catch{if(j)return;h(I=>({...I,[C]:0}))}}},m=Array.from({length:Math.min(y,w.length)},()=>z());return Promise.all(m),()=>{j=!0}},[l,n,r,o.join(","),x,d]),{matchStates:p}}const yn=({index:t,workId:n,transport:r,onNavigate:o,activeJuan:s,onJuanChange:i,className:c,style:l})=>{const[a,d]=f.useState(null),[u,p]=f.useState(!1),[h,x]=f.useState(null),[b,j]=f.useState(null),[g,w]=f.useState(null),[y,v]=f.useState(!1),[z,m]=f.useState(null),[k,S]=f.useState(""),C=f.useRef(new Map),I=s??b,T=f.useCallback(L=>{j(L),i==null||i(L)},[i]),_=t||a;f.useEffect(()=>{t&&(p(!1),x(null))},[t]),f.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let L=!1;return p(!0),x(null),r.getCollatedEditionIndex(n).then(R=>{if(!L)if(!R)x("未找到整理本数据");else{d(R);const V=Ct(R);!s&&V&&T(V)}}).catch(R=>{L||x(R instanceof Error?R.message:"加载失败")}).finally(()=>{L||p(!1)}),()=>{L=!0}},[t,n,r,s,T]),f.useEffect(()=>{const L=t||a;if(L&&!I){const R=Ct(L);R&&T(R)}},[t,a,I,T]);const B=n||(_==null?void 0:_.work_id),D=f.useCallback(async L=>{var R;if(!(!B||!(r!=null&&r.getCollatedJuan))){v(!0),w(null),m(null);try{const[V,W]=await Promise.all([r.getCollatedJuan(B,L),((R=r.getCollatedJuanText)==null?void 0:R.call(r,B,L))??Promise.resolve(null)]);w(V),m(W)}catch{w(null),m(null)}finally{v(!1)}}},[B,r]);f.useEffect(()=>{I&&D(I)},[I,D]);const M=L=>{T(L)};if(u)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!_)return null;const $=_.type==="kaozhen",H=mn(_);return e.jsx(bo,{className:c,style:l,index:_,allFiles:H,isKaozhen:$,effectiveWorkId:B,transport:r,activeFile:I,handleSelectFile:M,juanData:g,juanRawText:z,juanLoading:y,searchQuery:k,setSearchQuery:S,onNavigate:o,workLabelCacheRef:C})},bo=({className:t,style:n,index:r,allFiles:o,isKaozhen:s,effectiveWorkId:i,transport:c,activeFile:l,handleSelectFile:a,juanData:d,juanRawText:u,juanLoading:p,searchQuery:h,setSearchQuery:x,onNavigate:b,workLabelCacheRef:j})=>{const{matchStates:g}=ho({workId:i,transport:c,files:o,activeFile:l,activeJuan:d,activeRawText:u,query:h,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:h,onChange:w=>x(w.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s?e.jsxs(e.Fragment,{children:[r.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_juan})," 卷"]})}),r.text_quality&&(()=>{const w=Kr(r.text_quality.grade);return w?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Gr,{content:Yn[w],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Gn[w],cursor:"help"},children:Qt[w]})}),r.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",r.text_quality.source_note]})]}):null})()]}),e.jsx(oo,{files:o,groups:r.juan_groups,activeFile:l,onSelect:a,juanMeta:r.juan_metadata,matchStates:g}),p?e.jsx(ye,{}):d?s?e.jsx(xo,{juan:d,searchQuery:h,onNavigate:b,transport:c,workLabelCache:j}):e.jsx(go,{juan:d,rawText:u,searchQuery:h,onNavigate:b}):l?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,r.references&&r.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),r.references.map((w,y)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[y+1,". "]}),w.url?e.jsx("a",{href:w.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:w.title}):e.jsx("span",{children:w.title}),w.author&&e.jsxs("span",{children:[",",w.author]}),w.note&&e.jsxs("span",{children:["。",w.note]})]},y))]})]})},mo={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},yo={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function vo(t){try{const n=new Date(t),r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}`}catch{return t}}const vn=({items:t,loading:n})=>{const r=ae();return n?e.jsx(ye,{}):t.length===0?e.jsx("div",{style:jo,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=mo[o.type],i=yo[o.status];return e.jsxs("div",{style:So,children:[e.jsxs("div",{style:ko,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...zt,background:s.color},children:s.label}),e.jsx("span",{style:{...zt,background:i.color},children:i.label})]}),e.jsx("span",{style:wo,children:vo(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:_o,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:It,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:It,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Co,children:o.content}),o.reply&&e.jsxs("div",{style:zo,children:[e.jsx("div",{style:Io,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},jo={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},So={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},ko={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},zt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},wo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},_o={fontSize:"12px",marginBottom:"6px"},It={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Co={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},zo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Io={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},rt=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:s,feedbackApiUrl:i})=>{const c=F(),[l,a]=f.useState(null),[d,u]=f.useState([]),[p,h]=f.useState("recommend"),[x,b]=f.useState([]),[j,g]=f.useState(!1),w=o??p,y=$=>{h($),s==null||s($)},[v,z]=f.useState(!0),[m,k]=f.useState(null),[S,C]=f.useState(null),[I,T]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(H=>{$||a({works:H.works,books:H.books,collections:H.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const L=await t.getRecommended();if(L!=null&&L.groups)return L.groups.flatMap(R=>R.items.map(V=>({...V,group:R.name})))}catch{}return[]})().then(async L=>{if($)return;const R=L.filter(W=>W.id);if(R.length===0){z(!1);return}const V=await Promise.all(R.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const Y=await t.getItem(W.id);Y&&(U={id:W.id,title:Y.title||W.id,type:Y.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:N.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(u(V.filter(W=>W!==null)),z(!1))}),()=>{$=!0}},[t,r]);const _=f.useRef(!1),B=f.useRef(!1),D=f.useRef(!1);f.useEffect(()=>{if(w!=="catalog"||_.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;_.current=!0;let H=!1;return $.call(t).then(L=>{H||k(L)}).catch(()=>{_.current=!1}),()=>{H=!0}},[t,w]),f.useEffect(()=>{if(w!=="collection"||B.current||!t.getCollectionProgress)return;B.current=!0;let $=!1;return t.getCollectionProgress().then(H=>{$||C(H)}).catch(()=>{B.current=!1}),()=>{$=!0}},[t,w]),f.useEffect(()=>{if(w!=="site"||D.current||!t.getSiteProgress)return;D.current=!0;let $=!1;return t.getSiteProgress().then(H=>{$||T(H)}).catch(()=>{D.current=!1}),()=>{$=!0}},[t,w]),f.useEffect(()=>{if(!i||w!=="feedback")return;let $=!1;return g(!0),fetch(i).then(H=>H.json()).then(H=>{!$&&H.success&&b(H.items||[])}).catch(()=>{}).finally(()=>{$||g(!1)}),()=>{$=!0}},[i,w]);const M=$=>{switch($){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(Te,{label:c.home.recommendTab,active:w==="recommend",onClick:()=>y("recommend")}),e.jsx(Te,{label:c.home.catalogTab,active:w==="catalog",onClick:()=>y("catalog")}),e.jsx(Te,{label:c.home.collectionTab,active:w==="collection",onClick:()=>y("collection")}),e.jsx(Te,{label:c.home.siteTab,active:w==="site",onClick:()=>y("site")}),i&&e.jsx(Te,{label:c.home.feedbackTab,active:w==="feedback",onClick:()=>y("feedback")})]}),w==="recommend"&&e.jsx(To,{recommended:d,loading:v,onNavigate:n,getIcon:M,t:c}),w==="catalog"&&e.jsx(Tt,{progress:m,t:c,onNavigate:n}),w==="collection"&&e.jsx(Tt,{progress:S,t:c,onNavigate:n}),w==="site"&&e.jsx(Eo,{progress:I,t:c,totalWorks:(l==null?void 0:l.works)??0}),w==="feedback"&&i&&e.jsx(vn,{items:x,loading:j})]})})},Te=({label:t,active:n,onClick:r})=>e.jsx("button",{onClick:r,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),To=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:s})=>{const i=ae();if(n)return e.jsx(ye,{});if(t.length===0)return null;const c=new Map;for(const l of t){const a=l.group||s.home.recommendedBrowse;c.has(a)||c.set(a,[]),c.get(a).push(l)}return e.jsx(e.Fragment,{children:Array.from(c.entries()).map(([l,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:l}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r==null||r(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:o(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})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},l))})},Tt=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(ye,{});const o=[...t.resources].sort((l,a)=>l.priority-a.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(l=>{const a=o.filter(d=>d.status===l);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:c[l]}}),i[l]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Ro,{item:d,t:n,statusColor:c[l],onNavigate:r},d.id))})]},l)})})},Ro=({item:t,t:n,statusColor:r,onNavigate:o})=>{const s=ae(),i=t.total>0?Math.round(t.imported/t.total*100):0,c=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 l=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&o?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(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:l}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:l}):l})()}),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:c})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Fe(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${i}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Eo=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(ye,{});const o=[...t.resources].sort((a,d)=>a.priority-d.priority),s=o.filter(a=>a.imported>0),i=o.filter(a=>a.imported===0),c=s.reduce((a,d)=>Math.max(a,d.imported),0),l=r>0?Math.round(c/r*100):0;return e.jsxs("div",{children:[r>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:c.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",l,"%)"]}),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(Rt,{item:a,t:n,totalWorks:r},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(Rt,{item:a,t:n,totalWorks:r},a.id))})]})]})},Rt=({item:t,t:n,totalWorks:r})=>{const o=r>0?Math.round(t.imported/r*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&r>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Et="(max-width: 768px)";function Lo(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Et).matches);return f.useEffect(()=>{const r=window.matchMedia(Et),o=s=>n(s.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const Bo=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:s})=>{var H;const i=F(),{convert:c}=A(),l=Lo(),[a,d]=f.useState(null),[u,p]=f.useState(null),[h,x]=f.useState(!1),[b,j]=f.useState("detail"),[g,w]=f.useState([]),[y,v]=f.useState(!1),[z,m]=f.useState(null),[k,S]=f.useState(!1),C=f.useCallback(async L=>{if(!t.getCollatedEditionIndex){m(null);return}S(!0);try{const R=await t.getCollatedEditionIndex(L);m(R)}catch{m(null)}finally{S(!1)}},[t]),I=f.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){w([]);return}v(!0);try{if(t.getCollectionCatalogs){const R=await t.getCollectionCatalogs(L);w(R||[])}else if(t.getCollectionCatalog){const R=await t.getCollectionCatalog(L);w(R?[{resource_id:"",data:R}]:[])}}catch{w([])}finally{v(!1)}},[t]),T=f.useCallback(async L=>{if(r){r(L);return}d(L),p(null),w([]),m(null),j("detail"),x(!0);try{const R=await t.getItem(L.id);R&&(p(R),R.type==="collection"?I(L.id):R.type==="work"&&R.has_collated&&C(L.id))}catch(R){console.error("加载详情失败:",R)}finally{x(!1)}},[t,r,I,C]),_=f.useCallback(async L=>{p(null),w([]),m(null),j("detail"),x(!0);try{const R=await t.getItem(L);R&&(p(R),d({id:L,title:R.title||L,type:R.type||"book"}),R.type==="collection"?I(L):R.type==="work"&&R.has_collated&&C(L))}catch(R){console.error("导航失败:",R)}finally{x(!1)}},[t,I,C]),B=(u==null?void 0:u.type)==="collection"&&(g.length>0||y)||(u==null?void 0:u.type)==="work"&&(z||k),D=l&&(h||u),M=f.useCallback(()=>{d(null),p(null),w([]),m(null),j("detail")},[]),$=e.jsx(e.Fragment,{children:h?e.jsx(ye,{}):u?e.jsxs(e.Fragment,{children:[(B||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:l?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:l?"auto":void 0},children:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>j("detail"),style:Oe(b==="detail"),children:i.detailTab.basicInfo}),u.type==="collection"&&y&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Oe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&g.map(L=>e.jsx("button",{onClick:()=>j(`catalog:${L.resource_id}`),style:Oe(b===`catalog:${L.resource_id}`),children:L.short_name?`${c(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),u.type==="work"&&(z||k)&&e.jsxs("button",{onClick:()=>j("collated"),style:Oe(b==="collated"),children:[i.detailTab.collatedEdition,k&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:l?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(st,{data:u,transport:t,onNavigate:_}):b.startsWith("catalog:")?e.jsx(xn,{data:(H=g.find(L=>`catalog:${L.resource_id}`===b))==null?void 0:H.data,onNavigate:_}):b==="collated"?e.jsx(yn,{index:z||void 0,workId:u.id,transport:t,onNavigate:_}):null})]}):e.jsx(rt,{transport:t,onNavigate:_,recommendedIds:o})});return l?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:D?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:M,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(nt,{transport:t,onEntryClick:T,hideModeIndicator:n}),!u&&e.jsx(rt,{transport:t,onNavigate:_,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(nt,{transport:t,onEntryClick:T,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Oe(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 Wo=({data:t,onNavigate:n,className:r,style:o})=>{var u;const s=F(),{convert:i}=A(),[c,l]=f.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[a,d]=f.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(p=>e.jsx($o,{division:p,expanded:c===p.name,onToggle:()=>l(c===p.name?null:p.name),expandedCat:a,onCatToggle:h=>d(a===h?null:h),onNavigate:n},p.name))})]})},$o=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:s,onNavigate:i})=>{const{convert:c}=A(),l=t.categories.reduce((a,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return a+(u.zhulu||0)+(u.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:c(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",l," 部",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(Po,{category:a,expanded:o===d,onToggle:()=>s(d),onNavigate:i},a.name)})})]})},Po=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var a,d,u,p;const{convert:s}=A(),i=((a=t.books)==null?void 0:a.zhulu)||[],c=((d=t.books)==null?void 0:d.cunmu)||[],l=(((u=t.stats)==null?void 0:u.zhulu)||i.length)+(((p=t.stats)==null?void 0:p.cunmu)||c.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||c.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Lt,{label:"著錄",books:i,onNavigate:o}),c.length>0&&e.jsx(Lt,{label:"存目",books:c,onNavigate:o})]})]})},Lt=({label:t,books:n,onNavigate:r})=>{const{convert:o}=A(),s=ae(),[i,c]=f.useState(n.length<=20),l=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:l.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&&r?e.jsx("a",{href:s(a.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),r(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(a.title)}):o(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(a.author).slice(0,20)})]},d))}),!i&&e.jsxs("button",{onClick:()=>c(!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," 條"]})]})},se=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:s})=>{const i=F();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:Mo,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Fo,children:i.action.save})]})]}),s]})},Fo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Mo={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},oe=({label:t,value:n,onChange:r,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:i=>r(i.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),me=({value:t,onChange:n,placeholder:r})=>{const o=f.useRef(null);return f.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:r,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Ye=({children:t,color:n,style:r})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...r},children:t});function Ho(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ue=({value:t,onChange:n,label:r})=>{const[o,s]=f.useState(!1),i=f.useRef(null),c=Ho(t||"");return f.useEffect(()=>{o&&i.current&&i.current.focus()},[o]),!o&&c?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Bt,children:r}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:c.name}),e.jsx(Ye,{children:c.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Bt,children:r}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:l=>n(l.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"}})]})},Bt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Do(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Oo(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const jn=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=F(),[s,i]=f.useState(null),c=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},l=p=>{n(t.filter((h,x)=>x!==p)),s===p&&i(null)},a=(p,h,x)=>{const b=[...t];b[p]={...b[p],[h]:x},n(b)},d=(p,h)=>{const x=[...t];x[p]={...x[p],type:h,id:"",name:""},n(x),h==="bookID"&&r&&r(b=>{const j=[...t];j[p]={...j[p],id:b.id,name:b.title,type:"bookID"},n(j)})},u=p=>{r&&r(h=>{const x=[...t];x[p]={...x[p],id:h.id,name:h.title,type:"bookID"},n(x)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>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:p.name||`${o.editor.sourcePlaceholder} ${h+1}`}),p.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Do(p.type),color:"white",borderRadius:"3px",fontWeight:500},children:Oo(p.type)}),e.jsx("button",{onClick:x=>{x.stopPropagation(),l(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!p.type&&e.jsxs("div",{children:[e.jsx("label",{style:ue,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(h,"bookID"),style:{...Wt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(h,"url"),style:{...Wt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),p.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const x=[...t];x[h]={...x[h],type:"",id:"",name:""},n(x)},style:$t,children:o.action.changeType})]}),p.id&&p.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:p.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:p.id})]}),e.jsx("button",{onClick:()=>u(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>u(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),p.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const x=[...t];x[h]={...x[h],type:"",id:"",name:""},n(x)},style:$t,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:p.name,onChange:x=>a(h,"name",x.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:p.id,onChange:x=>a(h,"id",x.target.value),placeholder:"https://...",style:ve})]})]}),p.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...ue,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:p.details,onChange:x=>a(h,"details",x.target.value),placeholder:o.editor.detailsPlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:p.position,onChange:x=>a(h,"position",x.target.value),placeholder:"如: 卷三, p.52",style:ve})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:p.version,onChange:x=>a(h,"version",x.target.value),placeholder:"如: v1.0, 2024-01",style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:p.processor_version,onChange:x=>a(h,"processor_version",x.target.value),placeholder:"如: v0.1",style:ve})]})]})]})]})})]},h)),e.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},ue={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ve={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"},Wt={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"},$t={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Sn(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(r=>({id:r.id||"",name:r.name||"",type:r.type||"",details:r.details||"",position:r.position||"",version:r.version||"",processor_version:r.processor_version||""}))}catch{}return[]}function kn(t){return!t||t.length===0?"":JSON.stringify(t)}const wn=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:s,belongsToWork:i,belongsToCollection:c,childWorks:l,childCollections:a,containedBooks:d,siblingBooks:u,onLinkEntity:p,onUnlinkEntity:h,onViewEntity:x,onCreateAndLink:b,onSaveRelations:j})=>{const g=F();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),j&&e.jsx("button",{onClick:j,style:Ao,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:x,onUnlink:()=>h("workId"),onLink:()=>p("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Re,{direction:"up",title:g.relation.containedInCollection,entity:c,onView:x,onUnlink:()=>h("collectionId"),onLink:()=>p("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),i&&u&&u.length>0&&e.jsx(je,{direction:"horizontal",title:`${g.relation.siblingVersions} (${u.length})`,entities:u,onView:x,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(Re,{direction:"up",title:g.relation.parentWork,entity:o,onView:x,onUnlink:()=>h("parentWorkId"),onLink:()=>p("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}),l&&l.length>0&&e.jsx(je,{direction:"down",title:`${g.relation.childWorks} (${l.length})`,entities:l,onView:x,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(je,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:x,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(je,{direction:"down",title:`${g.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,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(Re,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:x,onUnlink:()=>h("workId"),onLink:()=>p("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Re,{direction:"up",title:g.relation.parentCollection,entity:s,onView:x,onUnlink:()=>h("parentCollectionId"),onLink:()=>p("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(je,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:x,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(je,{direction:"down",title:`${g.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},Re=({direction:t,title:n,entity:r,onView:o,onUnlink:s,onLink:i,onCreate:c,linkLabel:l,createLabel:a,notLinkedLabel:d,viewLabel:u,unlinkLabel:p})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:_n(r.type)}),e.jsx("span",{style:{fontWeight:500},children:r.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:r.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Pt,{onClick:()=>o(r),title:u,children:"👁️"}),e.jsx(Pt,{onClick:s,title:p,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(ot,{onClick:i,children:l}),e.jsx(ot,{onClick:c,primary:!0,children:a})]})]})},je=({direction:t,title:n,entities:r,onView:o,onAdd:s,addLabel:i,noneLabel:c,expandMoreLabel:l})=>{const[a,d]=f.useState(!1),u=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?r:r.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(x=>e.jsxs("div",{onClick:()=>o(x),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:_n(x.type)}),e.jsx("span",{children:x.title})]},x.id)),r.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:[l," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:c}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(ot,{onClick:s,primary:!0,children:["+ ",i]})})]})},Pt=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),ot=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:r});function _n(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Ao={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"},Cn=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:s,onCreate:i,searchResults:c,onSearch:l,isLoading:a,excludeId:d})=>{const[u,p]=f.useState(""),h=d?c.filter(g=>g.id!==d):c;f.useEffect(()=>{t&&(p(""),l(""))},[t]);const x=g=>{p(g),l(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",j=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Vo,children:e.jsxs("div",{style:Uo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:s,style:No,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:g=>x(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Yo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Qe,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>o(g),style:Go,children:[e.jsx("span",{style:{fontSize:"16px"},children:j}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):u?e.jsxs("div",{style:Qe,children:["未找到匹配的",b]}):e.jsxs("div",{style:Qe,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:Ko,children:["创建新",b,"并关联"]})]})]})})},Vo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Uo={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)"},No={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Yo={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"},Go={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Qe={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Ko={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ft={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Jo={work:"📜",book:"📖",collection:"📚",entity:"👤"},zn=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:s,onCancel:i})=>{const[c,l]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{t&&(l((o==null?void 0:o.title)||""),setTimeout(()=>{var h,x;(h=a.current)==null||h.focus(),(x=a.current)==null||x.select()},100))},[t,o==null?void 0:o.title]);const d=h=>{h.key==="Enter"&&c.trim()?u():h.key==="Escape"&&i()},u=()=>{c.trim()&&s(c.trim(),{...o,title:c.trim()})};if(!t)return null;const p=()=>{switch(r){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Ft[n]}`}};return e.jsx("div",{style:qo,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Xo,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:Jo[n]}),e.jsx("span",{children:p()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:c,onChange:h=>l(h.target.value),onKeyDown:d,placeholder:`请输入${Ft[n]}名称...`,style:Zo})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:Qo,children:"取消"}),e.jsx("button",{onClick:u,disabled:!c.trim(),style:{...ei,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},qo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Xo={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)"},Zo={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"},Qo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ei={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function ti(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function In(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ni(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Tn=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:s,showCreateButton:i=!1,createButtonText:c,onSelect:l,onCancel:a,onCreate:d,onSearch:u})=>{const[p,h]=f.useState(""),[x,b]=f.useState([]),[j,g]=f.useState(!1),[w,y]=f.useState("recent");f.useEffect(()=>{t&&(h(""),b([]),y(o.length>0?"recent":"search"))},[t,o.length]),f.useEffect(()=>{if(!p.trim()){b([]);return}const C=setTimeout(async()=>{g(!0);try{b(await u(p,r))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(C)},[p,r,u]);const v=f.useCallback(C=>{h(C.target.value),C.target.value.trim()&&y("search")},[]),z=f.useCallback(C=>s?C.filter(I=>I.id!==s):C,[s]);if(!t)return null;const m=n||(r==="all"?"选择实体":`选择${In(r)}`),k=z(o),S=z(x);return e.jsx("div",{style:oi,children:e.jsxs("div",{style:ii,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:m}),e.jsx("button",{onClick:a,style:si,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:p,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:li}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),j&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),k.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Mt,{active:w==="recent",onClick:()=>y("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(Mt,{active:w==="search",onClick:()=>y("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&k.length>0?e.jsx(Ht,{entities:k,onSelect:l}):p.trim()?j?e.jsx(et,{message:"搜索中..."}):S.length>0?e.jsx(Ht,{entities:S,onSelect:l}):e.jsx(et,{message:"未找到匹配的结果"}):e.jsx(et,{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:ai,children:c||"创建新实体"})]})]})})},Mt=({active:t,onClick:n,children:r})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:r}),Ht=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(ri,{entity:r,onClick:()=>n(r)},r.id))}),ri=({entity:t,onClick:n})=>{const[r,o]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:ti(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:ni(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:In(t.type)})]})},et=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),oi={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ii={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},si={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},li={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"},ai={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ci={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},di={work:"📜",collection:"📚",book:"📖",entity:"👤"},Rn=({data:t,onChange:n,onSave:r,transport:o,onNavigate:s,showDelete:i,onDelete:c,onAskAI:l,renderSectionActions:a,onDownloadResource:d,downloadStatuses:u,relations:p,onRelationsChange:h})=>{var ee;const x=F(),[b,j]=f.useState(!1),[g,w]=f.useState("work"),[y,v]=f.useState(""),[z,m]=f.useState(""),[k,S]=f.useState([]),[C,I]=f.useState(!1),[T,_]=f.useState(!1),[B,D]=f.useState("work"),[M,$]=f.useState(""),[H,L]=f.useState(),[R,V]=f.useState(!1),[W,U]=f.useState(null),[Y,Z]=f.useState([]);f.useRef(null);const ne=t.type,he=ne==="work",ge=ne==="collection",Q=ne==="book",q=f.useCallback((E,O)=>{n({...t,[E]:O})},[t,n]),Ke=f.useCallback((E,O)=>{v(E),w(O),m(x.editor.selectToLink+x.indexType[O]),S([]),j(!0)},[x]),Je=f.useCallback(E=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,E)},[o,t.id]),we=f.useCallback(E=>{s==null||s(E.id,E.type)},[s]),_e=f.useCallback((E,O,re)=>{const ce={...re,author:(re==null?void 0:re.author)||t.author,dynasty:(re==null?void 0:re.dynasty)||t.dynasty};D(O),$(E),L(ce),_(!0)},[t.author,t.dynasty]),qe=f.useCallback((E,O)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,M,{type:B,title:E,inheritData:O}),_(!1)},[o,t.id,M,B]),Me=f.useCallback(E=>{if(!E.trim()){S([]);return}I(!0),o!=null&&o.searchEntities&&o.searchEntities(E,g).then(O=>{S(O),I(!1)}).catch(()=>{S([]),I(!1)})},[o,g]),Xe=f.useCallback(E=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,E.id),j(!1)},[o,t.id,y]),P=f.useCallback(()=>{r()},[r]),J=f.useCallback(E=>{U(()=>E),V(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(Z).catch(()=>{})},[o]),G=f.useCallback((E,O)=>o!=null&&o.searchEntities?o.searchEntities(E,O==="all"?void 0:O):Promise.resolve([]),[o]),K=f.useCallback(E=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(E),Z(O=>[E,...O.filter(re=>re.id!==E.id)].slice(0,10)),W==null||W(E),V(!1),U(null)},[o,W]);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:di[ne]}),e.jsx("span",{children:t.title||x.editor.untitled}),e.jsx(Ye,{children:t.id}),e.jsx(Ye,{color:ci[ne],children:x.indexType[ne]})]})}),e.jsx(se,{title:x.section.basicInfo,onSave:r,onAskAI:l?()=>l("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ue,{label:he?x.editor.workTitle:ge?x.editor.collectionTitle:x.editor.bookTitle,value:t.title,onChange:E=>q("title",E)}),Q&&e.jsx(Ue,{label:x.editor.belongsToWork,value:t.workName||"",onChange:E=>q("workName",E)}),e.jsx(oe,{label:x.editor.authorLabel,value:t.author||"",onChange:E=>q("author",E)}),e.jsx(oe,{label:x.editor.dynastyLabel,value:t.dynasty||"",onChange:E=>q("dynasty",E)}),(Q||ge)&&e.jsx(Ue,{label:x.editor.containedIn,value:t.collection||"",onChange:E=>q("collection",E)}),(Q||ge)&&e.jsx(oe,{label:x.editor.holderLabel,value:t.holder||"",onChange:E=>q("holder",E)}),(Q||ge)&&e.jsx(oe,{label:Q?x.editor.pageLabel:x.editor.volumeLabel,value:t.pages||"",onChange:E=>q("pages",E)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(oe,{label:x.editor.firstImageLabel,value:t.firstImage||"",onChange:E=>q("firstImage",E)})})]})}),e.jsx(se,{title:x.section.description,onSave:r,onAskAI:l?()=>l("介绍"):void 0,children:e.jsx(me,{value:t.description||"",onChange:E=>q("description",E),placeholder:x.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(se,{title:x.section.additionalWorks,onSave:r,children:e.jsx(pi,{items:t.additional_works||[],onChange:E=>q("additional_works",E)})}),e.jsx(se,{title:x.section.indexedBy,onSave:r,onAskAI:l?()=>l("收录于"):void 0,children:e.jsx(xi,{items:t.indexed_by||[],onChange:E=>q("indexed_by",E)})}),e.jsx(se,{title:x.section.emendatedBy,onSave:r,onAskAI:l?()=>l("考证"):void 0,children:e.jsx(ui,{items:t.emendated_by||[],onChange:E=>q("emendated_by",E)})}),e.jsx(se,{title:x.section.textResources,onSave:r,onAskAI:l?()=>l("资源"):void 0,children:e.jsx(tt,{items:t.resources||[],onChange:E=>q("resources",E),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(se,{title:x.section.imageResources,onSave:r,children:e.jsx(tt,{items:t.resources||[],onChange:E=>q("resources",E),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(se,{title:x.section.sources,onSave:r,onAskAI:l?()=>l("资料来源"):void 0,children:e.jsx(jn,{items:Sn(t.sources||""),onChange:E=>q("sources",kn(E)),onOpenEntityPicker:J})}),(Q||ge)&&e.jsx(se,{title:x.section.provenance,onSave:r,onAskAI:l?()=>l("收藏历史"):void 0,children:e.jsx(me,{value:t.provenance||"",onChange:E=>q("provenance",E),placeholder:x.editor.provenancePlaceholder})}),Q&&e.jsx(se,{title:x.section.otherEditions,onSave:r,onAskAI:l?()=>l("其他版本"):void 0,children:e.jsx(me,{value:t.otherEditions||"",onChange:E=>q("otherEditions",E),placeholder:x.editor.otherEditionsPlaceholder})}),e.jsx(wn,{entityType:ne,entityId:t.id,entityTitle:t.title,parentWork:p==null?void 0:p.parentWork,parentCollection:p==null?void 0:p.parentCollection,belongsToWork:p==null?void 0:p.belongsToWork,belongsToCollection:p==null?void 0:p.belongsToCollection,childWorks:p==null?void 0:p.childWorks,childCollections:p==null?void 0:p.childCollections,containedBooks:p==null?void 0:p.containedBooks,siblingBooks:p==null?void 0:p.siblingBooks,onLinkEntity:Ke,onUnlinkEntity:Je,onViewEntity:we,onCreateAndLink:_e,onSaveRelations:P}),i&&c&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:x.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:x.editor.dangerZoneDesc}),e.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:x.editor.deleteEntity})]}),e.jsx(Cn,{isOpen:b,entityType:g,title:z,onSelect:Xe,onCancel:()=>j(!1),onCreate:()=>{j(!1),_e(y,g)},searchResults:k,onSearch:Me,isLoading:C,excludeId:t.id}),e.jsx(zn,{isOpen:T,entityType:B,relationField:M,inheritData:H,onConfirm:qe,onCancel:()=>_(!1)}),e.jsx(Tn,{isOpen:R,title:x.action.selectBookOrWork,filterType:"all",recentEntities:Y,excludeId:t.id,onSelect:K,onCancel:()=>{V(!1),U(null)},onSearch:G})]})};function pi({items:t,onChange:n}){const r=F(),o=(c,l,a)=>{const d=t.map((u,p)=>p===c?{...u,[l]:a}:u);n(d)},s=c=>n(t.filter((l,a)=>a!==c)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((c,l)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(oe,{label:r.editor.bookNameLabel,value:c.book_title,onChange:a=>o(l,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(oe,{label:r.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>o(l,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(l),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},l)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r.action.addAdditionalWork})]})}function En({items:t,onChange:n,showMeta:r,addLabel:o}){const s=F(),[i,c]=f.useState(null),l=(u,p,h)=>{const x=t.map((b,j)=>j===u?{...b,[p]:h||void 0}:b);n(x)},a=u=>{n(t.filter((p,h)=>h!==u)),i===u&&c(null)},d=()=>{n([...t,{source:""}]),c(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,p)=>{const h=i===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>c(h?null:p),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:u.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(p)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&r&&(u.title_info||u.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.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(oe,{label:s.label.sourceName,value:u.source,onChange:x=>l(p,"source",x)}),e.jsx(oe,{label:s.label.sourceBid,value:u.source_bid||"",onChange:x=>l(p,"source_bid",x)})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(oe,{label:s.label.titleInfo,value:u.title_info||"",onChange:x=>l(p,"title_info",x)}),e.jsx(oe,{label:s.label.authorInfo,value:u.author_info||"",onChange:x=>l(p,"author_info",x)})]}),e.jsx(oe,{label:s.label.edition,value:u.edition||"",onChange:x=>l(p,"edition",x)})]}),e.jsx(me,{value:u.summary||"",onChange:x=>l(p,"summary",x),placeholder:s.editor.summaryPlaceholder}),e.jsx(me,{value:u.comment||"",onChange:x=>l(p,"comment",x),placeholder:s.editor.commentPlaceholder}),e.jsx(me,{value:u.additional_comment||"",onChange:x=>l(p,"additional_comment",x),placeholder:s.editor.additionalCommentPlaceholder})]})]},p)}),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:o})]})}function xi({items:t,onChange:n}){const r=F();return e.jsx(En,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function ui({items:t,onChange:n}){const r=F();return e.jsx(En,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function Ln(t){var l,a,d,u,p,h,x;const n=((a=(l=t.authors)==null?void 0:l[0])==null?void 0:a.name)||"",r=((d=t.publication_info)==null?void 0:d.year)||"",o=((u=t.current_location)==null?void 0:u.name)||"",s=(p=t.page_count)!=null&&p.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||"",c={id:t.id,title:t.title,type:t.type,author:n,dynasty:r,holder:o,pages:s,description:i,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const j=b.related_works.find(g=>g.relation==="part_of");j&&(c.parentWorkId=j.id,c.parentWorkName=j.title)}}if(t.type==="book"){const b=t;c.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(c.collectionId=(x=b.contained_in[0])==null?void 0:x.id)}return c}function fi(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 gi=t=>{const{data:n,id:r,transport:o,mode:s="view",onModeChange:i,onChange:c,onSave:l,onDelete:a,onNavigate:d,renderLink:u,onAskAI:p,renderSectionActions:h,onDownloadResource:x,downloadStatuses:b,relations:j,onRelationsChange:g,headerExtra:w,className:y,style:v}=t;F();const[z,m]=f.useState(s),k=i?s:z;f.useEffect(()=>{s!==z&&m(s)},[s]);const S=f.useCallback(()=>{const M=k==="view"?"edit":"view";i?i(M):m(M)},[k,i]),[C,I]=f.useState(null);f.useEffect(()=>{r&&o&&o.getItem(r).then(M=>{M&&I(M)})},[r,o]);const T=n||C,_=f.useMemo(()=>T?Ln(T):null,[T]),B=i||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:k==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:k==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:k==="view"?"切换到编辑模式":"切换到查看模式",children:k==="view"?"✏️ 编辑":"👁 查看"}):null,D=e.jsxs(e.Fragment,{children:[B,w]});return!T&&!_?e.jsx(ye,{}):k==="view"?e.jsx(st,{data:T,transport:o,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:D,className:y,style:v}):_?e.jsxs("div",{className:y,style:v,children:[D&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:D}),e.jsx(Rn,{data:_,onChange:c||(()=>{}),onSave:l||(()=>{}),transport:o,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:p,renderSectionActions:h,onDownloadResource:x,downloadStatuses:b,relations:j,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Dt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Bn=({isOpen:t,onClose:n,onSubmit:r,feedbackListUrl:o})=>{const[s,i]=f.useState(null),[c,l]=f.useState(""),[a,d]=f.useState("idle"),[u,p]=f.useState(""),h=f.useRef(null);f.useEffect(()=>{t&&(i(null),l(""),d("idle"),p(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[s]),f.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),f.useEffect(()=>{if(!t)return;const g=w=>{w.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const x=async()=>{if(!(!s||!c.trim())){d("submitting"),p("");try{await r({type:s,content:c.trim()}),d("success")}catch(g){d("error"),p(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&c.trim()&&a!=="submitting",j=Dt.find(g=>g.value===s);return e.jsx("div",{style:hi,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:bi,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:mi,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:yi,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:wi,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Dt.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...vi,...s===g.value?ji:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:c,onChange:g=>l(g.target.value),placeholder:(j==null?void 0:j.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...Si,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),a==="error"&&e.jsx("div",{style:_i,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:x,disabled:!b,style:{...ki,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},hi={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},bi={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)"},mi={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},yi={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},vi={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"},ji={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Si={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"},ki={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},wi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},_i={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Ci=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:r})=>{const[o,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...zi,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(Bn,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:r})]})},zi={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"},Ot=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ii=({onSubmit:t})=>{const[n,r]=f.useState("bug"),[o,s]=f.useState(""),[i,c]=f.useState("idle"),[l,a]=f.useState(""),d=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var x;return(x=d.current)==null?void 0:x.focus()},100)},[n]);const u=async()=>{if(!(!n||!o.trim())){c("submitting"),a("");try{await t({type:n,content:o.trim()}),c("success"),s(""),r("bug")}catch(x){c("error"),a(x instanceof Error?x.message:"提交失败,请稍后重试")}}},p=n&&o.trim()&&i!=="submitting",h=Ot.find(x=>x.value===n);return i==="success"?e.jsx("div",{style:At,children:e.jsxs("div",{style:Bi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>c("idle"),style:Wi,children:"继续提交"})]})}):e.jsxs("div",{style:At,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ot.map(x=>e.jsxs("button",{onClick:()=>r(x.value),style:{...Ti,...n===x.value?Ri:{}},children:[e.jsx("span",{children:x.icon})," ",x.label]},x.value))}),e.jsx("textarea",{ref:d,value:o,onChange:x=>s(x.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Ei}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[o.length," / 2000"]}),e.jsx("button",{onClick:u,disabled:!p,style:{...Li,opacity:p?1:.6,cursor:p?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:$i,children:l})]})},At={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Ti={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"},Ri={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ei={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"},Li={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Bi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Wi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},$i={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Pi(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 Fi(t,n){if(!t.lineage)return null;const r=t.lineage;return{id:t.id,kind:"book",label:t.title,year:r.year,year_text:r.year_text,year_uncertain:r.year_uncertain,category:r.category,status:r.status,extant_juan:r.extant_juan,group:n[t.id],note:r.note}}function Vt(t,n,r){return{id:`derive:${n.ref}->${t}:${r}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Mi(t,n,r){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${r}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Hi(t,n,r){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const i=new Set(o.excluded_books??[]),c=o.node_groups??{},l=(r??o.default_collection??"all")==="core"&&Array.isArray(o.core_books)&&o.core_books.length>0,a=l?new Set(o.core_books):null,d=l&&o.core_hypotheticals?new Set(o.core_hypotheticals):null,u=new Set,p=new Set;if(l){const v=new Map(n.map(I=>[I.id,I])),z=new Map((o.hypothetical_nodes??[]).map(I=>[I.id,I])),m=I=>{const T=v.get(I);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(B=>B.ref);const _=z.get(I);return _?(_.derived_from??[]).map(B=>B.ref):[]},k=I=>z.has(I)?!d||d.has(I):!a||a.has(I),S=new Set,C=I=>{if(!S.has(I)){S.add(I);for(const T of m(I))i.has(T)||(k(T)||(z.has(T)?p.add(T):v.has(T)&&u.add(T)),C(T))}};for(const I of n)a&&a.has(I.id)&&!i.has(I.id)&&C(I.id);for(const I of o.hypothetical_nodes??[])d&&d.has(I.id)&&C(I.id)}const h=n.filter(v=>!i.has(v.id)).filter(v=>!a||a.has(v.id)||u.has(v.id)).map(v=>{const z=Fi(v,c);return z&&u.has(v.id)&&(z.bridge=!0),z}).filter(v=>v!==null),x=(o.hypothetical_nodes??[]).filter(v=>!d||d.has(v.id)||p.has(v.id)).map(v=>{const z=Pi(v);return p.has(v.id)&&(z.bridge=!0),z}),b=[...h,...x],j=new Set(b.map(v=>v.id)),g=new Set,w=[],y=v=>{g.has(v.id)||!j.has(v.source)||!j.has(v.target)||(g.add(v.id),w.push(v))};for(const v of n)i.has(v.id)||!v.lineage||a&&!a.has(v.id)&&!u.has(v.id)||((v.lineage.derived_from??[]).forEach((z,m)=>{y(Vt(v.id,z,m))}),(v.lineage.related_to??[]).forEach((z,m)=>{y(Mi(v.id,z,m))}));for(const v of o.hypothetical_nodes??[])d&&!d.has(v.id)&&!p.has(v.id)||(v.derived_from??[]).forEach((z,m)=>{y(Vt(v.id,z,m))});return{nodes:b,edges:w,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(i)}}function Di(t,n){const r=[],o=t.version_graph;if(!o)return r;const s=new Set(n.map(a=>a.id)),i=new Set((o.hypothetical_nodes??[]).map(a=>a.id)),c=new Set([...s,...i]),l=(a,d)=>{c.has(d.ref)||r.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&r.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&r.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(u=>l(d,u)),(a.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||r.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const a of o.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(u=>l(d,u))}return r}const Wn=({graph:t,renderLink:n,className:r,style:o})=>{if(!t.nodes.length)return e.jsx("div",{style:{...es,...o},className:r,children:"暂无版本图数据"});const s=new Map,i=new Map;for(const p of t.edges)if(p.kind==="derive"){const h=s.get(p.target)??[];h.push(p),s.set(p.target,h)}else for(const h of[p.source,p.target]){const x=i.get(h)??[];x.push(p),i.set(h,x)}const c=new Map(t.nodes.map(p=>[p.id,p])),l=new Map,a=[];for(const p of t.nodes)if(p.group){const h=l.get(p.group)??[];h.push(p),l.set(p.group,h)}else a.push(p);const d=(p,h)=>(p.year??9999)-(h.year??9999);l.forEach(p=>p.sort(d)),a.sort(d);const u=t.groups.filter(p=>l.has(p.id));return e.jsxs("div",{className:r,style:{...Ai,...o},children:[t.title&&e.jsx("div",{style:Vi,children:t.title}),t.description&&e.jsx("div",{style:Ui,children:t.description}),u.map(p=>e.jsx(Ut,{label:p.label,color:p.color,nodes:l.get(p.id),incomingMap:s,siblingMap:i,nodeMap:c,renderLink:n},p.id)),a.length>0&&e.jsx(Ut,{label:"其他",nodes:a,incomingMap:s,siblingMap:i,nodeMap:c,renderLink:n})]})},Ut=({label:t,color:n,nodes:r,incomingMap:o,siblingMap:s,nodeMap:i,renderLink:c})=>e.jsxs("div",{style:Ni,children:[e.jsx("div",{style:{...Yi,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:t}),r.map(l=>e.jsx(Oi,{node:l,incoming:o.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:i,renderLink:c},l.id))]}),Oi=({node:t,incoming:n,siblings:r,nodeMap:o,renderLink:s})=>{const i=t.kind==="hypothetical",c=t.bridge;return e.jsxs("div",{style:{...Gi,borderStyle:i||c?"dashed":"solid",opacity:c?.55:t.status==="lost"?.7:1,background:c?"var(--bim-bg-subtle, #fafafa)":void 0},title:c?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Ki,children:[e.jsx("span",{style:Ji,children:i||!s?t.label:s(t.id,t.label)}),t.year&&e.jsxs("span",{style:qi,children:[t.year_text??t.year,t.year_uncertain?"?":""]})]}),e.jsxs("div",{style:Xi,children:[t.category&&e.jsx(Ee,{children:t.category}),t.status==="lost"&&e.jsx(Ee,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Ee,{tone:"warn",children:"残本"}),i&&e.jsx(Ee,{tone:"info",children:"假想祖本"}),c&&e.jsx(Ee,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Zi,children:["现存:",t.extant_juan]}),t.note&&e.jsx("div",{style:Qi,children:t.note}),n.length>0&&e.jsxs("div",{style:Yt,children:[e.jsx("div",{style:Gt,children:"来源:"}),n.map(l=>{const a=o.get(l.source);return e.jsxs("div",{style:Kt(l.confidence),children:[e.jsx("span",{style:Jt,children:l.relation}),e.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,a.label):(a==null?void 0:a.label)??l.source}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Nt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:qt,children:["· ",l.evidence]})]},l.id)})]}),r.length>0&&e.jsxs("div",{style:Yt,children:[e.jsx("div",{style:Gt,children:"关联:"}),r.map(l=>{const a=l.source===t.id?l.target:l.source,d=o.get(a);return e.jsxs("div",{style:Kt(l.confidence),children:[e.jsx("span",{style:Jt,children:l.relation}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,d.label):(d==null?void 0:d.label)??a}),e.jsx(Nt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:qt,children:["· ",l.evidence]})]},l.id)})]})]})},Ee=({children:t,tone:n="default"})=>{const o={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:o.bg,color:o.fg,marginRight:"4px"},children:t})},Nt=({level:t})=>{const r={certain:{label:"确定",color:"#2e7d32"},consensus:{label:"共识",color:"#1976d2"},probable:{label:"推测",color:"#ed6c02"},disputed:{label:"有争议",color:"#c62828"}}[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:r.label}):null},Ai={fontSize:"14px",color:"var(--bim-fg, #333)"},Vi={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ui={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Ni={marginBottom:"16px"},Yi={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Gi={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ki={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ji={fontSize:"15px",fontWeight:600},qi={fontSize:"12px",color:"var(--bim-muted, #777)"},Xi={marginBottom:"6px"},Zi={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Qi={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Yt={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Gt={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Kt=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Jt={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},qt={fontSize:"11px",color:"var(--bim-muted, #888)"},es={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},$n=({selectedNodeId:t,...n})=>{const[r,o]=f.useState("loading"),[s,i]=f.useState(null);return f.useEffect(()=>{let c=!1;return ts().then(l=>{c||(l?(i(l),o("ready")):o("missing"))}),()=>{c=!0}},[]),r==="loading"?e.jsx("div",{style:Xt,children:"加载图组件中…"}):r==="missing"||!s?e.jsxs("div",{style:Xt,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(ns,{modules:s,selectedNodeId:t,...n})};async function ts(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let r=!1;try{await import("@xyflow/react/dist/style.css"),r=!0}catch{r=!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:r}}catch{return null}}const ns=({graph:t,renderLink:n,height:r=600,className:o,style:s,selectedNodeId:i,modules:c})=>{const{ReactFlow:l,Background:a,Controls:d,Handle:u,Position:p,BaseEdge:h,EdgeLabelRenderer:x,getSmoothStepPath:b,dagre:j}=c,g=f.useMemo(()=>({lineage:m=>{var $,H,L,R;const k=(($=m.data)==null?void 0:$.stepPosition)??.85,[S,C,I]=b({sourceX:m.sourceX,sourceY:m.sourceY,sourcePosition:m.sourcePosition,targetX:m.targetX,targetY:m.targetY,targetPosition:m.targetPosition,stepPosition:k,borderRadius:5}),T=!!((H=m.data)!=null&&H.isSibling),_=T?C:m.targetX-18,B=T?I:m.targetY-12,D=(L=m.data)==null?void 0:L.labelStyle,M=(R=m.data)==null?void 0:R.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(h,{id:m.id,path:S,style:m.style,markerStart:m.markerStart,markerEnd:m.markerEnd}),m.label&&e.jsx(x,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${_}px,${B}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)",...M,...D},children:m.label})})]})}}),[h,x,b]),w=f.useMemo(()=>({version:m=>{const k=m.data,S=k.kind==="hypothetical",C=k.status==="lost",I=k.isSelected,T=k.bridge,_=k.borderColor??"#888",B=T||S?"dashed":"solid",D=T?.5:C?.6:1;return e.jsxs("div",{style:{background:T?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${B} ${I?"#0078d4":_}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:D,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":S||T?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:T?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:p.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:S||!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.jsxs("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:[k.yearText,k.uncertain?"?":"",k.category?` · ${k.category}`:""]}),C&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:p.Right,style:{visibility:"hidden"}})]})}}),[u,p]),{rfNodes:y,rfEdges:v}=f.useMemo(()=>rs(t,j,n,i),[t,j,n,i]);return e.jsx("div",{style:{width:"100%",height:r,...s},className:o,children:e.jsxs(l,{nodes:y,edges:v,nodeTypes:w,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 rs(t,n,r,o){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const a=new Map(t.groups.map(g=>[g.id,g.color??"#888"]));for(const g of t.nodes)l.setNode(g.id,{width:160,height:90});const d=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const g of t.edges)g.kind==="derive"&&(d.has(g.relation)||l.setEdge(g.source,g.target));n.layout(l);const u=t.nodes.map(g=>{const w=l.node(g.id),y=o&&g.id===o,v={kind:g.kind,label:g.label,bookId:g.kind==="book"?g.id:void 0,yearText:g.year_text??is(g),uncertain:g.year_uncertain,category:g.category,status:g.status,borderColor:g.group?a.get(g.group):void 0,renderLink:r,isSelected:y,description:g.description,bridge:g.bridge};return{id:g.id,type:"version",position:{x:w.x-160/2,y:w.y-90/2},data:v,draggable:!1,selected:y}}),p=.78,h=.06,x=new Map;for(const g of t.edges)g.kind==="derive"&&(x.has(g.source)||x.set(g.source,[]),x.get(g.source).push(g));const b=new Map;for(const[g,w]of x){if(w.length<=1)continue;const y=[...w].sort((z,m)=>{var C,I;const k=((C=l.node(z.target))==null?void 0:C.y)??0,S=((I=l.node(m.target))==null?void 0:I.y)??0;return k-S}),v=y.length;y.forEach((z,m)=>{const k=(m-(v-1)/2)*h;b.set(z.id,p+k)})}const j=t.edges.map(g=>os(g,b.get(g.id)));return{rfNodes:u,rfEdges:j}}function os(t,n){const r=t.confidence==="probable"||t.confidence==="disputed",o=t.kind==="sibling",s=ss(t.confidence),i={type:"arrowclosed",color:s,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:t.relation,data:{labelStyle:{color:"#444"},isSibling:o,stepPosition:n},style:{stroke:s,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:i,markerStart:o?i:void 0,zIndex:1e3}}function is(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function ss(t){switch(t){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const Xt={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)"},ls=({graph:t,defaultMode:n="list",renderLink:r,graphHeight:o=600,selectedNodeId:s,onModeChange:i,collection:c,onCollectionChange:l,collectionsAvailable:a,collectionCounts:d,className:u,style:p})=>{var m,k,S,C,I,T;const[h,x]=f.useState(n),b=_=>{x(_),i==null||i(_)},j=!!(a&&(a.core||a.all)&&l);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const g=((m=a==null?void 0:a.core)==null?void 0:m.label)??"核心",w=((k=a==null?void 0:a.all)==null?void 0:k.label)??"完整",y=d==null?void 0:d.core,v=d==null?void 0:d.all,z=c==="core"?(S=a==null?void 0:a.core)==null?void 0:S.description:(C=a==null?void 0:a.all)==null?void 0:C.description;return e.jsxs("div",{className:u,style:p,children:[e.jsxs("div",{style:as,children:[e.jsx("button",{onClick:()=>b("list"),style:Ae(h==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:Ae(h==="graph"),children:"关系图"}),j&&e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:4,alignItems:"center"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),e.jsxs("button",{onClick:()=>l==null?void 0:l("core"),style:Ae(c==="core"),title:(I=a==null?void 0:a.core)==null?void 0:I.description,children:[g,y!=null?` ${y}`:""]}),e.jsxs("button",{onClick:()=>l==null?void 0:l("all"),style:Ae(c==="all"),title:(T=a==null?void 0:a.all)==null?void 0:T.description,children:[w,v!=null?` ${v}`:""]})]})]}),j&&z&&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:z}),h==="list"?e.jsx(Wn,{graph:t,renderLink:r}):e.jsx($n,{graph:t,renderLink:r,height:o,selectedNodeId:s})]})},as={display:"flex",gap:4,marginBottom:12},Ae=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"}),cs=({style:t})=>{const n=f.useContext(Pe);if(!n)return null;const{locale:r,setLocale:o}=n,s=r==="zh-Hant",i=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})};exports.BidLink=N.BidLink;exports.BookIndexError=N.BookIndexError;exports.BookIndexManager=N.BookIndexManager;exports.BookIndexStorage=N.BookIndexStorage;exports.BundleStorage=N.BundleStorage;exports.ConfigError=N.ConfigError;exports.GithubStorage=N.GithubStorage;exports.IdGenerationError=N.IdGenerationError;exports.IdGenerator=N.IdGenerator;exports.LocalStorage=N.LocalStorage;exports.MigrationError=N.MigrationError;exports.StorageError=N.StorageError;exports.base36Decode=N.base36Decode;exports.base36Encode=N.base36Encode;exports.base58Decode=N.base58Decode;exports.buildId=N.buildId;exports.cleanName=N.cleanName;exports.decodeId=N.decodeId;exports.decodeIdString=N.decodeIdString;exports.encodeId=N.encodeId;exports.extractIdFromUrl=N.extractIdFromUrl;exports.extractStatus=N.extractStatus;exports.extractType=N.extractType;exports.normalizeCatalog=N.normalizeCatalog;exports.parseId=N.parseId;exports.shardOf=N.shardOf;exports.smartDecode=N.smartDecode;exports.validateResource=N.validateResource;exports.Badge=Ye;exports.BidUrlProvider=Un;exports.CollatedEdition=yn;exports.CollectionCatalog=xn;exports.CreateEntityDialog=zn;exports.EmendatedBySection=dn;exports.EntityDetail=on;exports.EntityPickerDialog=Tn;exports.EntitySelector=Cn;exports.FeedbackButton=Ci;exports.FeedbackDialog=Bn;exports.FeedbackForm=Ii;exports.FeedbackList=vn;exports.FormInput=oe;exports.FormTextArea=me;exports.HomePage=rt;exports.IndexApp=Bo;exports.IndexBrowser=nt;exports.IndexDetail=st;exports.IndexEditor=Rn;exports.IndexView=gi;exports.LocaleContext=Pe;exports.LocaleProvider=Qn;exports.LocaleToggle=cs;exports.ModeIndicator=nn;exports.RelationPanel=wn;exports.ResourceEditor=tt;exports.ResourceList=it;exports.SearchInput=rn;exports.Section=se;exports.SmartBidInput=Ue;exports.SourceEditor=jn;exports.VersionLineageGraph=$n;exports.VersionLineageList=Wn;exports.VersionLineageView=ls;exports.WorkCatalog=Wo;exports.buildLineageGraph=Hi;exports.detailToEditor=Ln;exports.editorToDetail=fi;exports.formatTemplate=Fe;exports.parseSourceString=Sn;exports.stringifySources=kn;exports.useBidUrl=ae;exports.useConvert=A;exports.useT=F;exports.validateLineageGraph=Di;
1
+ "use strict";var Fn=Object.create;var ut=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Vn=Object.prototype.hasOwnProperty;var Un=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of On(n))!Vn.call(t,s)&&s!==o&&ut(t,s,{get:()=>n[s],enumerable:!(r=Hn(n,s))||r.enumerable});return t};var Ce=(t,n,o)=>(o=t!=null?Fn(Dn(t)):{},Un(n||!t||!t.__esModule?ut(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-C7sHSk4U.cjs"),e=require("react/jsx-runtime"),f=require("react"),Nn=require("react-markdown"),Gn=require("remark-gfm"),Yn=require("react-dom"),Kn=t=>`/book-index?id=${t}`,en=f.createContext(Kn);function Jn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(en.Provider,{value:o,children:n})}function ae(){return f.useContext(en)}function be(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function qn(t,n){return be(t).includes(n)}const tn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Xn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Zn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Pe=f.createContext(null),nn={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:"圖片資源"}},Qn={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:"图片资源"}},eo={"zh-Hant":nn,"zh-Hans":Qn},on="bim-locale";function to(){try{const t=localStorage.getItem(on);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function no(t){try{localStorage.setItem(on,t)}catch{}}const oo="zh-Hans",ro=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(t??oo),i=t??r;f.useEffect(()=>{if(t)return;const u=to();u&&u!==r&&s(u)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>u=>u)}):c(null)},[i]);const l=f.useCallback(u=>{s(u),no(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:i,setLocale:l,messages:eo[i],converter:a}),[i,l,a]);return e.jsx(Pe.Provider,{value:d,children:o})};function A(){const t=f.useContext(Pe);return(t==null?void 0:t.messages)??nn}const io=2e3;function F(){const t=f.useContext(Pe),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=f.useCallback(a=>{if(!a)return"";if(!o)return a;const c=r.current.get(a);if(c!==void 0)return c;const l=o(a);if(r.current.size>=io){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,l),l},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Ae(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function so(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 lo(){return{id:"",name:"",url:"",type:"text",details:""}}const nt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=A(),[a,c]=f.useState(null),l=[{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}],u=m=>{if(!s)return!0;const k=be(m);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},x=t.map((m,k)=>({item:m,originalIndex:k})).filter(({item:m})=>u(m)),g=()=>{const m=lo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((k,_)=>_!==m)),c(null)},h=(m,k,_)=>{const v=[...t];if(v[m]={...v[m],[k]:_},k==="url"&&!v[m].id){const w=so(_);w&&(v[m].id=w)}n(v)},y=(m,k,_)=>{const w={...t[m].metadata||{}};_?w[k]=_:delete w[k],h(m,"metadata",Object.keys(w).length>0?w:void 0)},b=(m,k)=>{const _=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;h(m,"structure",_)},j=(m,k,_)=>{const w=t[m].coverage||{level:1,ranges:""};k==="level"?w.level=parseInt(_)||1:w.ranges=_,h(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:k})=>{var _,v,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(a===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ao(m.type??"text"),color:"#fff"},children:(()=>{var z,E;const S=be(m);return S.length===0?m.type??"text":S.length===1?((z=l.find(I=>I.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((E=l.find(I=>I.value==="text+image"))==null?void 0:E.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${k+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:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&co(k,r==null?void 0:r[k],o,i),e.jsx("button",{onClick:S=>{S.stopPropagation(),p(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),a===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[qn(m,"image")&&m.url&&po(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.type}),e.jsx("select",{value:m.type,onChange:S=>h(k,"type",S.target.value),style:{...pe,flex:1},children:l.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{...pe,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:S=>h(k,"id",S.target.value),placeholder:i.editor.idAutoExtract,style:{...pe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:S=>h(k,"name",S.target.value),placeholder:i.editor.resourceName,style:{...pe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:S=>h(k,"url",S.target.value),placeholder:i.editor.resourceUrl,style:pe}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:S=>b(k,S.target.value),placeholder:i.editor.structurePlaceholder,style:pe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((v=m.coverage)==null?void 0:v.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...pe,width:"60px"}})]}),e.jsxs("label",{style:{...ze,flex:1},children:[e.jsx("span",{style:Ie,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...pe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:i.editor.detailsPlaceholder,style:{...pe,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(([S,z])=>{var E;return e.jsxs("label",{style:{...ze,gap:"4px"},children:[e.jsx("span",{style:{...Ie,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[S])||"",onChange:I=>y(k,S,I.target.value),placeholder:z,style:{...pe,flex:1}})]},S)})})]})]})]})]},k)}),e.jsxs("button",{onClick:g,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 ao(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function co(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:a=>{a.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 po(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 pe={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"},ze={display:"flex",alignItems:"center",gap:"6px"},Ie={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},xo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function uo(t){try{const n=new URL(t).hostname;return xo[n]}catch{return}}const ft={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function fo(t){return t.includes("text")&&t.includes("image")?ft["text+image"]:ft[t[0]||"physical"]}const gt={text:0,image:1,physical:2};function De(t){return t.length===0?"physical":[...t].sort((n,o)=>(gt[n]??99)-(gt[o]??99)).join("+")}function go(t){const n=i=>{const a=i.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[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 a=t[i];if(a.volumes&&a.volumes.length>0)continue;const c=n(a.name);if(!c)continue;const[l,d]=c,u=`${l}|${De(be(a))}`;o.has(u)||o.set(u,{base:{...a,name:l,url:"",volumes:[]},volumes:[]}),o.get(u).volumes.push({volume:d,url:a.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((a,c)=>a.volume-c.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let a=0;a<t.length;a++)if(s.has(a)){const c=n(t[a].name),l=c&&`${c[0]}|${De(be(t[a]))}`,d=`${i.base.name}|${De(be(i.base))}`;l===d&&s.delete(a)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const lt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=A(),i=f.useMemo(()=>go(t||[]),[t]),a={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},c=x=>a[x]?a[x]:x.split("+").map(g=>a[g]||g).join("+");if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((x,g)=>e.jsx(ht,{item:x},x.id||g))});const l=new Map;for(const x of i){const g=De(be(x));l.has(g)||l.set(g,[]),l.get(g).push(x)}const d=["text","image","text+image","physical"],u=[...d.filter(x=>l.has(x)),...[...l.keys()].filter(x=>!d.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(x=>{const g=l.get(x),p=fo(x.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:p,whiteSpace:"nowrap",flexShrink:0},children:c(x)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((h,y)=>e.jsx(ht,{item:h,onNavigate:o,renderLink:r},h.id||y))})]},x)})})};function ho(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 bo(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 mo(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 yo={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},ht=({item:t})=>{const n=A(),{convert:o}=F(),[r,s]=f.useState(!1),i=f.useMemo(()=>(t.url?uo(t.url):void 0)||o(t.name),[t.url,t.name,o]),a=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||mo(h)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(a.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,u=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...yo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=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}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=bo(t.metadata);return h?ho(t.url,h):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:a.map(h=>{const y=h.status==="missing";return h.url&&!y?e.jsx("a",{href:h.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:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:h.volume},h.volume)})})]})},rn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:a})=>{const c=A(),l=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",g={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:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,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"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:g,...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:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:g,...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:x||c.mode.configurePath,style:{...g,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:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...p,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!l&&x&&e.jsxs("div",{style:{...g,background:"#2196f3",color:"white",cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Ge="bim-search-history",bt=10,mt=8;function Le(){try{const t=localStorage.getItem(Ge);return t?JSON.parse(t):[]}catch{return[]}}function vo(t){try{const n=Le().filter(o=>o!==t);n.unshift(t),n.length>bt&&(n.length=bt),localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function jo(t){try{const n=Le().filter(o=>o!==t);localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function So(){try{localStorage.removeItem(Ge)}catch{}}const sn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const a=A(),c=i??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[x,g]=f.useState([]),[p,h]=f.useState(-1),[y,b]=f.useState(Le),j=f.useRef(null),m=f.useRef(null),k=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{h(-1);const C=n.trim();if(!C){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let B=!1;const H=setTimeout(()=>{t.searchAll(C,mt).then(M=>{if(B)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,mt).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{B||g([])})},80);return()=>{B=!0,clearTimeout(H)}},[n,y,t]),f.useEffect(()=>{const C=B=>{k.current&&!k.current.contains(B.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=B=>{var H,M;if(B.key==="/"&&document.activeElement!==j.current){const $=(H=document.activeElement)==null?void 0:H.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;B.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(vo(C.trim()),b(Le())),r(C),u(!1)},[r]),w=f.useCallback(C=>{C.type==="history"?(o(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),v(C.text)))},[o,v,s]),S=f.useCallback(C=>{if(!d||x.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(B=>(B+1)%x.length);break;case"ArrowUp":C.preventDefault(),h(B=>(B-1+x.length)%x.length);break;case"Enter":C.preventDefault(),p>=0&&p<x.length?w(x[p]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,x,p,n,v,w]),z=f.useCallback((C,B)=>{B.stopPropagation(),jo(C),b(Le()),g(H=>H.filter(M=>!(M.type==="history"&&M.text===C)))},[]),E=f.useCallback(C=>{C.stopPropagation(),So(),b([]),g([])},[]);f.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,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&&x.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:[I&&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:a.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:a.search.clearAll})]}),x.map((C,B)=>e.jsxs("div",{onClick:()=>w(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:[l[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>z(C.text,H),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${C.type}-${C.text}-${B}`))]})]})},$e="bim-recent-ids",yt="bim-recent-entries",vt=50,Xe=5,ko=50,wo=200;function Be(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(yt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem($e,JSON.stringify(o)),localStorage.removeItem(yt),o}return[]}catch{return[]}}function _o(t){try{const n=Be().filter(o=>o!==t);n.unshift(t),n.length>vt&&(n.length=vt),localStorage.setItem($e,JSON.stringify(n))}catch{}}function Co(t){try{const n=Be().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function zo(){try{localStorage.removeItem($e)}catch{}}const Io={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ot=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,hideModeIndicator:d,initialQuery:u,onQueryChange:x,headerRight:g})=>{const p=A(),h=[{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"}],[y,b]=f.useState(u??""),[j,m]=f.useState(null),[k,_]=f.useState(null),[v,w]=f.useState(!1),[S,z]=f.useState(null),[E,I]=f.useState(""),[C,B]=f.useState(!u),[H,M]=f.useState(Be),[$,D]=f.useState([]),[L,T]=f.useState(!1),[O,W]=f.useState(!1),[U,G]=f.useState(null),[Z,ne]=f.useState(null),he=f.useRef(void 0),ge=f.useRef(!1),Q=f.useCallback(async(P,J)=>{if(!P.trim()){B(!0),m(null),_(null);return}B(!1),w(!0),I("");try{if(t.searchAll){const Y=await t.searchAll(P,J??Xe);m(Y)}else{const Y=["work","book","collection","entity"],K=await Promise.all(Y.map(ee=>t.search(P,ee,{page:1,pageSize:J??Xe})));m({works:K[0].entries,books:K[1].entries,collections:K[2].entries,entities:K[3].entries,totalWorks:K[0].total,totalBooks:K[1].total,totalCollections:K[2].total,totalEntities:K[3].total})}}catch(Y){I(Y instanceof Error?Y.message:String(Y)),m(null)}finally{w(!1)}},[t]);f.useEffect(()=>{let P=!1;const J=()=>{var V,oe;const Y=["work","book","collection","entity"],K=Promise.all(Y.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((V=t.getResourceCounts)==null?void 0:V.call(t).catch(()=>null))??Promise.resolve(null),R=((oe=t.getSubtypeStats)==null?void 0:oe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([K,ee,R]).then(([ce,de,xt])=>{P||(G({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:de==null?void 0:de.hasText,hasImage:de==null?void 0:de.hasImage}),xt&&ne(xt))})};return t.getCounts?t.getCounts().then(Y=>{var K,ee;P||(G({works:Y.works,books:Y.books,collections:Y.collections,entities:Y.entities,hasText:(K=Y.resourceCounts)==null?void 0:K.hasText,hasImage:(ee=Y.resourceCounts)==null?void 0:ee.hasImage}),Y.subtypeStats&&ne(Y.subtypeStats))}).catch(()=>{P||J()}):J(),()=>{P=!0}},[t]),f.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Q(u))},[u,Q]);const q=f.useCallback(P=>{if(b(P),!P.trim()){x==null||x(P),B(!0),m(null),_(null);return}he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{_(null),x==null||x(P),Q(P)},wo)},[Q,x]),Ye=f.useCallback(P=>{he.current&&clearTimeout(he.current),x==null||x(P),Q(P)},[Q,x]),Ke=f.useCallback(P=>{_(P),Q(y,ko)},[y,Q]);f.useEffect(()=>{if(!H.length){D([]);return}let P=!1;return T(!0),Promise.all(H.slice(0,10).map(async J=>{var Y,K,ee;try{if(t.getEntry){const V=await t.getEntry(J);if(V)return V}const R=await t.getItem(J);if(R){const V=R.authors;return{id:J,title:R.title||J,type:R.type||"work",author:(Y=V==null?void 0:V[0])==null?void 0:Y.name,dynasty:(K=V==null?void 0:V[0])==null?void 0:K.dynasty,role:(ee=V==null?void 0:V[0])==null?void 0:ee.role,edition:R.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{P||(D(J),T(!1))}),()=>{P=!0}},[H,t]);const we=P=>{z(P.id),_o(P.id),M(Be()),r==null||r(P)},_e=P=>{Co(P),M(Be())},Je=()=>{zo(),M([])},Me=P=>h.find(J=>J.type===P),qe=j&&(j.works.length>0||j.books.length>0||j.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:[g,!d&&e.jsx(rn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(sn,{transport:t,value:y,onChange:q,onSearch:Ye,onEntrySelect:we}),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})]}),U&&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:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()})," 本"]}),Z.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.article.toLocaleString()})," 篇"]}):null,Z.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()}),U.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:U.entities.toLocaleString()})]})]})}),U.hasImage!=null&&U.hasText!=null&&e.jsxs("span",{children:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:v?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}):$.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:$.slice(0,O?10:3).map(P=>P.notFound?e.jsx(To,{id:P.id,onRemove:_e,t:p},P.id):e.jsx(jt,{entry:P,selected:S===P.id,onClick:we,getConfig:Me,onRemove:_e},P.id))}),!O&&$.length>3&&e.jsx("button",{onClick:()=>W(!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})]})}):qe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:P,icon:J,name:Y,key:K})=>{const ee=j[K]??[],R=Io[K],V=j[R]??0;if(ee.length===0)return null;const ce=!(k===P)&&V>Xe;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[J," ",Y,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[V," ",p.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>Ke(P),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:ee.map(de=>e.jsx(jt,{entry:de,selected:S===de.id,onClick:we,getConfig:Me,query:y},de.id))})]},P)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Ae(p.search.noResultsFor,{query:y})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},jt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const a=A(),{convert:c}=F(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.find(u=>{const x=typeof u=="string"?u:u==null?void 0:u.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children: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:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.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,a.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:[a.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:a.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:"→"})]})},To=({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 Ro(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 Eo({data:t}){const{convert:n}=F(),{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 Lo({alt_names:t}){const{convert:n}=F(),o=new Map;for(const i of t){const a=i.type||"別名";o.has(a)||o.set(a,[]),o.get(a).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,a)=>{const c=r.indexOf(i),l=r.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const a=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:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},i)})})}function Bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function Wo({works:t,transport:n,onNavigate:o,renderLink:r}){const s=A(),{convert:i}=F(),a=ae(),[c,l]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const p=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(p);let _=!0;for(let v=0;v<p.length;v++){const w=k[v];w!=null&&w.title?y.set(p[v],w.title):w!=null&&w.primary_name?y.set(p[v],w.primary_name):_=!1}if(_)return y}catch{}const b=[...p],j=8,m=new Array(j).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!y.has(k))try{if(n.getEntry){const w=await n.getEntry(k);if(w!=null&&w.title){y.set(k,w.title);continue}}const _=await n.getItem(k),v=_&&(_.title||_.primary_name)||k;y.set(k,v)}catch{y.set(k,k)}}});return await Promise.all(m),y})().then(y=>{g||l(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const p=g.role||"";d.has(p)||d.set(p,[]),d.get(p).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,p)=>{const h=u.indexOf(g),y=u.indexOf(p);return h===-1&&y===-1?g.localeCompare(p):h===-1?1:y===-1?-1:h-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(g=>{const p=d.get(g);return e.jsxs("div",{style:{marginBottom:"8px"},children:[g&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((h,y)=>{const b=i(c.get(h.work_id)||h.work_id);return r?e.jsx("li",{children:r(h.work_id,b)},y):o?e.jsx("li",{children:e.jsx("a",{href:a(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:b})},y):e.jsx("li",{children:b},y)})})]},g)})]})}const ln=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var u;const i=A(),{convert:a}=F();let c=!1;try{c=N.extractStatus(t.id)==="draft"}catch{}const l=Ro(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:[a(t.primary_name),e.jsx(Eo,{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})]}),l&&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(Lo,{alt_names:t.alt_names}),e.jsx(Bo,{data:t}),((u=t.description)==null?void 0:u.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:a(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Wo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},an={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})},$o={...an,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},rt=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=F(),i=n?$o:an;return e.jsx("div",{className:r,style:o,children:e.jsx(Nn,{remarkPlugins:[Gn],components:i,children:s(t)})})},Po=["〇","一","二","三","四","五","六","七","八","九"],St=["","十","百","千"];function cn(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 a=parseInt(n[i]),c=o-1-i;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&i===0?r+=St[c]:r+=Po[a]+St[c])}return r}function Ao({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function Mo({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function Fo({id:t}){const n=A(),[o,r]=f.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 ie({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 xe({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 dn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,a)=>{const c=s(i.name),l=i.entity_id?e.jsx(le,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>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),"〕"]}),l,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},a)})})}function le({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();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 Ho({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:a,meta:c,headerExtra:l,onNavigate:d,renderLink:u}){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}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Ao,{type:r}),e.jsx(Mo,{isDraft:s}),e.jsx(Fo,{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(dn,{authors:i,type:r,onNavigate:d,renderLink:u}),c]})]})}function pn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=A(),{convert:a}=F();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const x=c===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>l(x?null:u),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(d.source)}),!x&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(le,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(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(xe,{label:i.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(xe,{label:i.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(xe,{label:i.label.edition,children:a(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:a(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:a(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:a(d.additional_comment)})]})]})]},u)})})]})}function Oo({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function xn({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function un({label:t,items:n}){const{convert:o}=F();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{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 Do({items:t}){const n=A();return e.jsx(un,{label:n.section.aliases,items:t})}function Vo({items:t}){const n=A();return e.jsx(un,{label:n.section.attachedTexts,items:t})}function Uo({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{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 No({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{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 Go({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{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 kt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=F(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let l=!1;return Promise.all(n.map(d=>o.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{l||c(d)}),()=>{l=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{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:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${i(l.title)||l.id}(${i(l.edition)})`:i(l.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(le,{id:l.id,label:d,onNavigate:r,renderLink:s})},l.id)})})]}):null}function Ze({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F(),[i,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=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(le,{id:t.id,label:l,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>a(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(lt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Yo({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const a=A(),{convert:c}=F(),[l,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(y=>({id:y})));return}let h=!1;return Promise.all(t.map(y=>o.getItem(y).then(b=>({id:y,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0})).catch(()=>({id:y})))).then(y=>{h||d(y)}),()=>{h=!0}},[t,o]),!t.length)return null;const u=l.length?l:t.map(h=>({id:h})),x=new Map(u.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,p=Ko(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[a.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(h=>{const y=x.get(h);return y?e.jsx(Ze,{book:y,onNavigate:r,renderLink:s},h):null})}),p.groupedIds.map(h=>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(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(y=>{const b=x.get(y);return b?e.jsx(Ze,{book:b,onNavigate:r,renderLink:s},y):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(h=>e.jsx(Ze,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function Ko(t,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(b=n.collections)==null?void 0:b[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,a=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const k=n.node_groups[m];return k!=null&&c.has(k)},u=[],x=new Map,g=[];for(const m of t)if(!((j=n.excluded_books)!=null&&j.includes(m)))if(d(m))u.push(m);else{const k=n.node_groups[m];k?(x.has(k)||x.set(k,[]),x.get(k).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,k)=>m+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,k])=>{const _=h.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:k}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:y}}function Jo({workData:t,onNavigate:n,renderLink:o}){var a,c,l,d;const r=A(),{convert:s}=F(),i=!!((a=t.description)!=null&&a.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(le,{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:[cn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(dn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(rt,{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(xe,{label:r.label.parentWork,children:e.jsx(le,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function qo({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F();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(le,{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:Ae(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const at=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:a,className:c,style:l})=>{var B,H,M,$,D,L;const d=A(),{convert:u}=F(),[x,g]=f.useState(null),[p,h]=f.useState(!1),[y,b]=f.useState(null),[j,m]=f.useState(null),[k,_]=f.useState([]),v=t||x;if(f.useEffect(()=>{if(t||!n||!o)return;let T=!1;return h(!0),b(null),o.getItem(n).then(O=>{T||(O?g(O):b(d.misc.notFoundEntry))}).catch(O=>{T||b(O instanceof Error?O.message:d.misc.loadFailed)}).finally(()=>{T||h(!1)}),()=>{T=!0}},[t,n,o]),f.useEffect(()=>{if(!v||!o){m(null),_([]);return}let T=!1;const O=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(O?o.getItem(O).then(W=>{!T&&W&&W.type==="work"&&m(W)}).catch(()=>{}):m(null),v.type==="book"){const W=v;W.contained_in&&W.contained_in.length>0?Promise.all(W.contained_in.map(U=>{const G=typeof U=="string"?U:U.id,Z=typeof U=="string"?void 0:U.volume_index;return o.getItem(G).then(ne=>({id:G,title:ne&&ne.title||G,volume_index:Z})).catch(()=>({id:G,title:G,volume_index:Z}))})).then(U=>{T||_(U)}):_([])}else _([]);return()=>{T=!0}},[v,o]),p)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((T,O)=>e.jsx("div",{style:{height:O===1?"32px":"16px",width:`${T}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},O))})});if(y)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!v)return null;if(v.type==="entity")return e.jsx("div",{className:c,style:l,children:e.jsx(ln,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let E=!1;try{E=N.extractStatus(v.id)==="draft"}catch{}let I="";v.measure_info?I=u(v.measure_info):(B=v.juan_count)!=null&&B.number?I=cn(v.juan_count.number)+d.unit.juan:(H=v.juan_count)!=null&&H.description&&(I=u(v.juan_count.description));const C=[];return(M=v.publication_info)!=null&&M.year&&C.push(e.jsx(xe,{label:d.label.year,children:v.publication_info.year},"year")),($=v.current_location)!=null&&$.name&&C.push(e.jsx(xe,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(D=v.page_count)!=null&&D.description&&C.push(e.jsx(xe,{label:d.label.pageCount,children:v.page_count.description},"page")),w!=null&&w.edition&&C.push(e.jsx(xe,{label:d.label.edition,children:u(w.edition)},"ver")),z!=null&&z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:e.jsx(le,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:z.parent_works.map((T,O)=>e.jsxs("span",{children:[O>0&&"、",e.jsx(le,{id:T,onNavigate:r,renderLink:s})]},T))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(Ho,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:E,authors:v.authors,volumeText:I,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=v.description)==null?void 0:L.text)&&e.jsx(rt,{text:v.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((T,O)=>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:u(T.title)}),e.jsx(rt,{text:T.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},O))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.containedIn}),e.jsx(qo,{items:k,onNavigate:r,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.belongsToWork}),e.jsx(Jo,{workData:j,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&e.jsx(Uo,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&e.jsx(Do,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&e.jsx(Vo,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&e.jsx(Oo,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&e.jsx(xn,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.resources}),e.jsx(lt,{items:v.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(No,{items:w.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Go,{items:S.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(kt,{title:d.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(kt,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ie,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(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(le,{id:T.id,label:u(T.title),onNavigate:r,renderLink:s})},T.id))})]}),(z==null?void 0:z.books)&&z.books.length>0&&e.jsx(Yo,{ids:z.books,workData:z,transport:o,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const T=[],O=z.related_works.filter(G=>G.relation==="part_of"),W=z.related_works.filter(G=>G.relation==="has_part"),U=z.related_works.filter(G=>!G.relation);return O.length>0&&T.push({label:d.section.belongsToWork,items:O}),W.length>0&&T.push({label:d.section.containedWorks,items:W}),U.length>0&&T.push({label:d.section.relatedWorks,items:U}),T.map(G=>e.jsxs("div",{children:[e.jsxs(ie,{children:[G.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(Z=>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(le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},G.label))})()]})};function Xo({data:t}){const n=A(),{convert:o}=F(),{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 Zo({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:wt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:wt(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 wt(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 Qo({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();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 er(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 _t({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=A(),{convert:i}=F(),a=t.book_id||t.work_id,c=r&&t.volumes.length>0?er(t.volumes,s.unit.volume):null,l=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:l?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(Qo,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const fn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:a})=>{const c=A(),[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(""),m=t||l;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),p(null),o.getCollectionCatalog(n).then(z=>{S||(z?d(z):p(c.catalog.notFound))}).catch(z=>{S||p(z instanceof Error?z.message:c.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,c]);const k=(m==null?void 0:m.sections)&&m.sections.length>0,_=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const S=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[m]),v=f.useMemo(()=>{if(!m)return[];let S=m.books;if(h&&(S=S.filter(z=>z.section===h)),b.trim()){const z=b.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(I=>I.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return S},[m,h,b]),w=f.useMemo(()=>{if(!_)return null;const S=[],z=new Map;for(const I of v){if(!I.volumes||I.volumes.length===0)continue;const C=I.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(I)}const E=[...z.keys()].sort((I,C)=>I-C);for(const I of E)S.push({volume:I,books:z.get(I)});return S},[v,_]);return u?e.jsx("div",{className:i,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:i,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:i,style:a,children:[e.jsx(Xo,{data:m}),k&&e.jsx(Zo,{sections:m.sections,activeSection:h,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:b,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[v.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((S,z)=>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:Ae(c.catalog.volume,{n:S.volume})}),S.books.map((E,I)=>e.jsx(_t,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${S.volume}-${I}`))]},`${S.volume}-${z}`)):v.map((S,z)=>e.jsx(_t,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},ye=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},te=6,Fe=7,tr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),u=f.useRef(null),x=f.useRef(null),g=f.useRef(null),p=f.useCallback(()=>{const b=x.current,j=g.current;if(!b||!j)return;const m=b.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,v=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-k.height-Fe<8&&(w="bottom"),o==="bottom"&&m.bottom+k.height+Fe>_-8&&(w="top");const S=w==="top"?m.top-k.height-Fe:m.bottom+Fe;let z=m.left+m.width/2-k.width/2;z=Math.max(8,Math.min(z,v-k.width-8)),d({left:z,top:S,placement:w})},[o]),h=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!0),r)},[r]),y=f.useCallback(()=>{u.current&&clearTimeout(u.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const b=requestAnimationFrame(p);return()=>cancelAnimationFrame(b)},[a,p]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:h,onMouseLeave:y,onFocus:h,onBlur:y,style:{display:"inline-block",...i},children:n}),a&&Yn.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.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:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-te,width:0,height:0,...l.placement==="top"?{bottom:-te,borderTop:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}:{top:-te,borderBottom:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}:{top:-5,borderBottom:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}}})]})]}),document.body)]})},Ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function nr(t){return typeof t!="string"?null:t in tn?t:t in Ct?Ct[t]:null}const or={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function X(t){return typeof t!="string"?"":or[t]??t}const rr=["〇","一","二","三","四","五","六","七","八","九"],zt=["","十","百","千"],ir=["","萬","億"];function gn(t){if(t===0)return"〇";if(t<0)return`負${gn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(sr(s,r>0)+ir[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function sr(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 a=o[i],c=o.length-1-i;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&i===0&&!n?s+=zt[c]:s+=rr[a]+zt[c]}return s.replace(/〇$/,"")}let We=null,He=null;const Ue=new Set;function lr(){return We?Promise.resolve():He||(He=import("opencc-js/t2cn").then(t=>{We=t.Converter({from:"tw",to:"cn"}),Ue.forEach(n=>n())}).catch(()=>{We=t=>t,Ue.forEach(t=>t())}),He)}function fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(We)return;const n=()=>t(o=>o+1);return Ue.add(n),lr(),()=>{Ue.delete(n)}},[]),We??(n=>n)}function Se(t,n){return n(t).toLowerCase()}const ct="#fff59d";function ke(t,n,o){if(!n)return t;const r=Se(n,o);if(!r)return t;const s=Se(t,o);if(s.length!==t.length)return t;const i=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(r,a);if(l===-1){i.push(t.slice(a));break}l>a&&i.push(t.slice(a,l)),i.push(e.jsx("mark",{style:{background:ct,padding:0,color:"inherit"},children:t.slice(l,l+r.length)},c++)),a=l+r.length}return e.jsx(e.Fragment,{children:i})}function dt(t,n,o,r){if(!n)return!0;const s=Se(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(a=>typeof a=="string"&&Se(a,r).includes(s))}function ar(t,n,o){return n?Se(t,o).includes(Se(n,o)):!0}const pt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},cr={考证:"#5d6d7e"};function dr(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 hn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,a=s==="loading",c=typeof s=="number"&&s>0,l=dr(t),d=!!(r!=null&&r.vol_label)&&!l.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:[l,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}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function bn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>bn(r,n)))}function mn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+mn(i),0))||0;return n+o}function pr(t,n){const o=[],r=a=>{var c;o.push(...a.files),(c=a.children)==null||c.forEach(r)};if(r(t),o.length===0)return;const s=o.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let i=0;for(const a of s)typeof a=="number"&&(i+=a);return i}function yn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var h;const a=bn(t,n||""),c=pr(t,i),l=typeof c=="number"&&c>0,d=c===0,[u,x]=f.useState(a||l),g=mn(t),p=!!((h=t.children)!=null&&h.length);if(f.useEffect(()=>{a&&x(!0)},[a]),f.useEffect(()=>{l&&x(!0)},[l]),t.files.length===1&&!p){const y=t.files[0],b=n===y,j=i[y],m=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{m||o(y)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:b?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:b?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${ct}40`:"transparent",color:b?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:b?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:j}),k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!u),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:a?"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:u?"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:["(",g,")"]}),l&&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:"…"})]}),u&&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(y=>e.jsx(hn,{file:y,isActive:n===y,onSelect:o,meta:s==null?void 0:s[y],matchState:i[y]},y))}),p&&t.children.map((y,b)=>e.jsx(yn,{group:y,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},b))]})]})}function xr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const a=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,l)=>e.jsx(yn,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},l))}):a.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:a.map(c=>e.jsx(hn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function ur({type:t}){const n=pt[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 fr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=y=>{if(!y)return"";const b=r(y);return o?ke(b,o,i):b},[c,l]=f.useState(!1),d=!!t.summary,u=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),p=d||u||x||g;f.useEffect(()=>{o&&l(!0)},[o]);const h=!c&&g?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&&l(!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:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[gn(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:a(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(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:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.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:a(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:a(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:a(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:a(t.additional_comment)})]}),g&&!d&&!u&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)})]})]})}function gr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=l=>{if(!l)return"";const d=o(l);return n?ke(d,n,r):d},[i,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ur,{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 ${pt[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 hr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
2
+ `)),i=n?ke(s,n,r):s,a=pt[t.type]||"#717171",c=X(t.type)==="序"||X(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 ${a}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:a,marginRight:"8px",padding:"1px 5px",border:`1px solid ${a}40`,borderRadius:"2px",background:`${a}08`,verticalAlign:"middle"},children:t.type}),i]})}function br(t,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let i=!1;const a=t.filter(u=>{var x;return!((x=o==null?void 0:o.current)!=null&&x.has(u))}),c={};for(const u of t)(d=o==null?void 0:o.current)!=null&&d.has(u)&&(c[u]=o.current.get(u));if(Object.keys(c).length>0&&s(c),a.length===0)return;const l=async u=>{var x;try{if(n.getEntry){const b=await n.getEntry(u);if(b)return{title:b.title,author:b.author}}const g=await n.getItem(u);if(!g)return null;const p=g.title||u,h=g.authors,y=(x=h==null?void 0:h[0])==null?void 0:x.name;return{title:p,author:y}}catch{return null}};return Promise.all(a.map(async u=>{var g;const x=await l(u);return(g=o==null?void 0:o.current)==null||g.set(u,x),[u,x]})).then(u=>{i||s(x=>{const g={...x};for(const[p,h]of u)g[p]=h;return g})}),()=>{i=!0}},[t.join(","),n]),r}function mr({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=F(),a=ae(),c=fe(),l=m=>{if(!m)return"";const k=i(m);return s?ke(k,s,c):k},[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=t.type,g=cr[x]||"#717171",p=!!t.content,h=t.work_ids||[],y=h.length>1,b=br(y?h:[],o,r),j=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&&u(!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?l(t.header_line):l(t.title)}),!d&&j&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:l(j)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&e.jsx("a",{href:a(h[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(h[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),y&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[h.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),y&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(m=>{const k=b[m],_=k?`${i(k.title)}${k.author?`(${i(k.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:a(m),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",_]},m)})}),d&&p&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}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:l(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:l(t.comment)})]})]})}function yr({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=F(),a=fe(),c=n.trim(),l=f.useMemo(()=>c?t.sections.filter(x=>dt(x,c,!0,a)):t.sections,[t.sections,c,a]),d=t.sections.filter(x=>X(x.type)==="考证").length,u=l.filter(x=>X(x.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${u} / ${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:l.map((x,g)=>e.jsx(mr,{section:x,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},g))}),l.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function vr({text:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=a=>{const c=o(a);return n?ke(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((a,c)=>{if(a.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(a.slice(2))},c);if(a.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(a.slice(3))},c);if(a.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(a.slice(4))},c);if(!a.trim())return c>0&&!i[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const l=a.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((d,u)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},u):e.jsx(f.Fragment,{children:s(d)},u))},c)})})}function jr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=d=>{if(!d)return"";const u=r(d);return o?ke(u,o,i):u},c=[];let l=null;for(const d of t)X(d.type)==="类"?(l&&c.push(l),l={category:d.title,categoryContent:d.content||void 0,items:[]}):X(d.type)==="书"?(l||(l={category:"",items:[]}),l.items.push(d)):(X(d.type)==="序"||X(d.type)==="结语")&&(l||(l={category:"",items:[]}),l.items.push(d),X(d.type)==="结语"&&(c.push(l),l=null));return l&&c.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,u)=>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:[a(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:a(d.categoryContent)})]}),d.items.map((x,g)=>X(x.type)==="序"||X(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:a(x.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),p.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:a(x.title)})}):e.jsx("strong",{children:a(x.title)}),x.content&&a(x.content)]},g))]},u))})}function Sr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=F(),i=fe(),[a,c]=f.useState("catalog"),l=o.trim(),d=f.useMemo(()=>l?t.sections.filter(p=>dt(p,l,!1,i)):t.sections,[t.sections,l,i]),u=t.sections.filter(p=>X(p.type)==="书").length,x=t.sections.filter(p=>X(p.type)==="诗").length,g=l?d.filter(p=>X(p.type)==="书"||X(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:a===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:a===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:g!=null?`${g} / ${x>0?`${x} 首`:`${u} 部書`}`:x>0?`${x} 首`:`${u} 部书`})]}),a==="raw"&&(n?e.jsx(vr,{text:n,highlightQuery:l}):e.jsx(jr,{sections:t.sections,onNavigate:r,highlightQuery:l})),a==="catalog"&&d.map((p,h)=>X(p.type)==="书"||X(p.type)==="诗"?e.jsx(fr,{section:p,onNavigate:r,highlightQuery:l},h):X(p.type)==="类"?e.jsx(gr,{section:p,highlightQuery:l},h):e.jsx(hr,{section:p,highlightQuery:l},h)),a==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function vn(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 It(t){const n=vn(t);return n.length>0?n[0]:null}function kr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:a,query:c,isKaozhen:l}=t,d=fe(),u=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&i&&u.current.set(s,{juan:i,rawText:a})},[s,i,a]),f.useEffect(()=>{u.current.clear(),g({})},[n]);const p=f.useCallback((h,y)=>{let b=0;if(h.juan)for(const j of h.juan.sections)dt(j,y,l,d)&&b++;return b===0&&h.rawText&&ar(h.rawText,y,d)&&(b=1),b},[l,d]);return f.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let y=!1;const b={},j=[];for(const w of r){const S=u.current.get(w);S?b[w]=p(S,h):(b[w]="loading",j.push(w))}g(b);const m=8;let k=0;const _=async()=>{var w;for(;k<j.length;){if(y)return;const S=k++,z=j[S];try{const[E,I]=await Promise.all([o.getCollatedJuan(n,z),((w=o.getCollatedJuanText)==null?void 0:w.call(o,n,z))??Promise.resolve(null)]),C={juan:E,rawText:I};if(u.current.set(z,C),y)return;g(B=>({...B,[z]:p(C,h)}))}catch{if(y)return;g(E=>({...E,[z]:0}))}}},v=Array.from({length:Math.min(m,j.length)},()=>_());return Promise.all(v),()=>{y=!0}},[c,n,o,r.join(","),p,d]),{matchStates:x}}const jn=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:a,style:c})=>{const[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(null),[m,k]=f.useState(!1),[_,v]=f.useState(null),[w,S]=f.useState(""),z=f.useRef(new Map),E=s??h,I=f.useCallback(L=>{y(L),i==null||i(L)},[i]),C=t||l;f.useEffect(()=>{t&&(x(!1),p(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return x(!0),p(null),o.getCollatedEditionIndex(n).then(T=>{if(!L)if(!T)p("未找到整理本数据");else{d(T);const O=It(T);!s&&O&&I(O)}}).catch(T=>{L||p(T instanceof Error?T.message:"加载失败")}).finally(()=>{L||x(!1)}),()=>{L=!0}},[t,n,o,s,I]),f.useEffect(()=>{const L=t||l;if(L&&!E){const T=It(L);T&&I(T)}},[t,l,E,I]);const B=n||(C==null?void 0:C.work_id),H=f.useCallback(async L=>{var T;if(!(!B||!(o!=null&&o.getCollatedJuan))){k(!0),j(null),v(null);try{const[O,W]=await Promise.all([o.getCollatedJuan(B,L),((T=o.getCollatedJuanText)==null?void 0:T.call(o,B,L))??Promise.resolve(null)]);j(O),v(W)}catch{j(null),v(null)}finally{k(!1)}}},[B,o]);f.useEffect(()=>{E&&H(E)},[E,H]);const M=L=>{I(L)};if(u)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!C)return null;const $=C.type==="kaozhen",D=vn(C);return e.jsx(wr,{className:a,style:c,index:C,allFiles:D,isKaozhen:$,effectiveWorkId:B,transport:o,activeFile:E,handleSelectFile:M,juanData:b,juanRawText:_,juanLoading:m,searchQuery:w,setSearchQuery:S,onNavigate:r,workLabelCacheRef:z})},wr=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:a,activeFile:c,handleSelectFile:l,juanData:d,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:p,onNavigate:h,workLabelCacheRef:y})=>{const{matchStates:b}=kr({workId:i,transport:a,files:r,activeFile:c,activeJuan:d,activeRawText:u,query:g,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:g,onChange:j=>p(j.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 j=nr(o.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(tr,{content:Xn[j],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Zn[j],cursor:"help"},children:tn[j]})}),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:l,juanMeta:o.juan_metadata,matchStates:b}),x?e.jsx(ye,{}):d?s?e.jsx(yr,{juan:d,searchQuery:g,onNavigate:h,transport:a,workLabelCache:y}):e.jsx(Sr,{juan:d,rawText:u,searchQuery:g,onNavigate:h}):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((j,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,". "]}),j.url?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:j.title}):e.jsx("span",{children:j.title}),j.author&&e.jsxs("span",{children:[",",j.author]}),j.note&&e.jsxs("span",{children:["。",j.note]})]},m))]})]})},_r={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Cr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function zr(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 Sn=({items:t,loading:n})=>{const o=ae();return n?e.jsx(ye,{}):t.length===0?e.jsx("div",{style:Ir,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=_r[r.type],i=Cr[r.status];return e.jsxs("div",{style:Tr,children:[e.jsxs("div",{style:Rr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Tt,background:s.color},children:s.label}),e.jsx("span",{style:{...Tt,background:i.color},children:i.label})]}),e.jsx("span",{style:Er,children:zr(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Lr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:Rt,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:Rt,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Br,children:r.content}),r.reply&&e.jsxs("div",{style:Wr,children:[e.jsx("div",{style:$r,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ir={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Tr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Rr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Tt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Er={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Lr={fontSize:"12px",marginBottom:"6px"},Rt={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Br={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Wr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},$r={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},it=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const a=A(),[c,l]=f.useState(null),[d,u]=f.useState([]),[x,g]=f.useState("recommend"),[p,h]=f.useState([]),[y,b]=f.useState(!1),j=r??x,m=$=>{g($),s==null||s($)},[k,_]=f.useState(!0),[v,w]=f.useState(null),[S,z]=f.useState(null),[E,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(D=>{$||l({works:D.works,books:D.books,collections:D.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!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(O=>({...O,group:T.name})))}catch{}return[]})().then(async L=>{if($)return;const T=L.filter(W=>W.id);if(T.length===0){_(!1);return}const O=await Promise.all(T.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const G=await t.getItem(W.id);G&&(U={id:W.id,title:G.title||W.id,type:G.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:N.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(u(O.filter(W=>W!==null)),_(!1))}),()=>{$=!0}},[t,o]);const C=f.useRef(!1),B=f.useRef(!1),H=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||C.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;C.current=!0;let D=!1;return $.call(t).then(L=>{D||w(L)}).catch(()=>{C.current=!1}),()=>{D=!0}},[t,j]),f.useEffect(()=>{if(j!=="collection"||B.current||!t.getCollectionProgress)return;B.current=!0;let $=!1;return t.getCollectionProgress().then(D=>{$||z(D)}).catch(()=>{B.current=!1}),()=>{$=!0}},[t,j]),f.useEffect(()=>{if(j!=="site"||H.current||!t.getSiteProgress)return;H.current=!0;let $=!1;return t.getSiteProgress().then(D=>{$||I(D)}).catch(()=>{H.current=!1}),()=>{$=!0}},[t,j]),f.useEffect(()=>{if(!i||j!=="feedback")return;let $=!1;return b(!0),fetch(i).then(D=>D.json()).then(D=>{!$&&D.success&&h(D.items||[])}).catch(()=>{}).finally(()=>{$||b(!1)}),()=>{$=!0}},[i,j]);const M=$=>{switch($){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(Te,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>m("recommend")}),e.jsx(Te,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>m("catalog")}),e.jsx(Te,{label:a.home.collectionTab,active:j==="collection",onClick:()=>m("collection")}),e.jsx(Te,{label:a.home.siteTab,active:j==="site",onClick:()=>m("site")}),i&&e.jsx(Te,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>m("feedback")})]}),j==="recommend"&&e.jsx(Pr,{recommended:d,loading:k,onNavigate:n,getIcon:M,t:a}),j==="catalog"&&e.jsx(Et,{progress:v,t:a,onNavigate:n}),j==="collection"&&e.jsx(Et,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(Mr,{progress:E,t:a,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&i&&e.jsx(Sn,{items:p,loading:y})]})})},Te=({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}),Pr=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=ae();if(n)return e.jsx(ye,{});if(t.length===0)return null;const a=new Map;for(const c of t){const l=c.group||s.home.recommendedBrowse;a.has(l)||a.set(l,[]),a.get(l).push(c)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([c,l])=>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:l.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.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})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},c))})},Et=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((c,l)=>c.priority-l.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(c=>{const l=r.filter(d=>d.status===c);return l.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:a[c]}}),i[c]," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(d=>e.jsx(Ar,{item:d,t:n,statusColor:a[c],onNavigate:o},d.id))})]},c)})})},Ar=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ae(),i=t.total>0?Math.round(t.imported/t.total*100):0,a=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,l=t.collection_id||t.work_id;return l&&r?e.jsx("a",{href:s(l),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(l))},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:a})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ae(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})]})},Mr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((l,d)=>l.priority-d.priority),s=r.filter(l=>l.imported>0),i=r.filter(l=>l.imported===0),a=s.reduce((l,d)=>Math.max(l,d.imported),0),c=o>0?Math.round(a/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:a.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(l=>e.jsx(Lt,{item:l,t:n,totalWorks:o},l.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(l=>e.jsx(Lt,{item:l,t:n,totalWorks:o},l.id))})]})]})},Lt=({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})]})},Bt="(max-width: 768px)";function Fr(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Bt).matches);return f.useEffect(()=>{const o=window.matchMedia(Bt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Hr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var D;const i=A(),{convert:a}=F(),c=Fr(),[l,d]=f.useState(null),[u,x]=f.useState(null),[g,p]=f.useState(!1),[h,y]=f.useState("detail"),[b,j]=f.useState([]),[m,k]=f.useState(!1),[_,v]=f.useState(null),[w,S]=f.useState(!1),z=f.useCallback(async L=>{if(!t.getCollatedEditionIndex){v(null);return}S(!0);try{const T=await t.getCollatedEditionIndex(L);v(T)}catch{v(null)}finally{S(!1)}},[t]),E=f.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}k(!0);try{if(t.getCollectionCatalogs){const T=await t.getCollectionCatalogs(L);j(T||[])}else if(t.getCollectionCatalog){const T=await t.getCollectionCatalog(L);j(T?[{resource_id:"",data:T}]:[])}}catch{j([])}finally{k(!1)}},[t]),I=f.useCallback(async L=>{if(o){o(L);return}d(L),x(null),j([]),v(null),y("detail"),p(!0);try{const T=await t.getItem(L.id);T&&(x(T),T.type==="collection"?E(L.id):T.type==="work"&&T.has_collated&&z(L.id))}catch(T){console.error("加载详情失败:",T)}finally{p(!1)}},[t,o,E,z]),C=f.useCallback(async L=>{x(null),j([]),v(null),y("detail"),p(!0);try{const T=await t.getItem(L);T&&(x(T),d({id:L,title:T.title||L,type:T.type||"book"}),T.type==="collection"?E(L):T.type==="work"&&T.has_collated&&z(L))}catch(T){console.error("导航失败:",T)}finally{p(!1)}},[t,E,z]),B=(u==null?void 0:u.type)==="collection"&&(b.length>0||m)||(u==null?void 0:u.type)==="work"&&(_||w),H=c&&(g||u),M=f.useCallback(()=>{d(null),x(null),j([]),v(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(ye,{}):u?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:()=>y("detail"),style:Oe(h==="detail"),children:i.detailTab.basicInfo}),u.type==="collection"&&m&&b.length===0&&e.jsxs("button",{onClick:()=>{},style:Oe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&b.map(L=>e.jsx("button",{onClick:()=>y(`catalog:${L.resource_id}`),style:Oe(h===`catalog:${L.resource_id}`),children:L.short_name?`${a(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),u.type==="work"&&(_||w)&&e.jsxs("button",{onClick:()=>y("collated"),style:Oe(h==="collated"),children:[i.detailTab.collatedEdition,w&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?e.jsx(at,{data:u,transport:t,onNavigate:C}):h.startsWith("catalog:")?e.jsx(fn,{data:(D=b.find(L=>`catalog:${L.resource_id}`===h))==null?void 0:D.data,onNavigate:C}):h==="collated"?e.jsx(jn,{index:_||void 0,workId:u.id,transport:t,onNavigate:C}):null})]}):e.jsx(it,{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:M,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(ot,{transport:t,onEntryClick:I,hideModeIndicator:n}),!u&&e.jsx(it,{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(ot,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Oe(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 Or=({data:t,onNavigate:n,className:o,style:r})=>{var u;const s=A(),{convert:i}=F(),[a,c]=f.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[l,d]=f.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Dr,{division:x,expanded:a===x.name,onToggle:()=>c(a===x.name?null:x.name),expandedCat:l,onCatToggle:g=>d(l===g?null:g),onNavigate:n},x.name))})]})},Dr=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:a}=F(),c=t.categories.reduce((l,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return l+(u.zhulu||0)+(u.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:a(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(l=>{const d=`${t.name}/${l.name}`;return e.jsx(Vr,{category:l,expanded:r===d,onToggle:()=>s(d),onNavigate:i},l.name)})})]})},Vr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var l,d,u,x;const{convert:s}=F(),i=((l=t.books)==null?void 0:l.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],c=(((u=t.stats)==null?void 0:u.zhulu)||i.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.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||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Wt,{label:"著錄",books:i,onNavigate:r}),a.length>0&&e.jsx(Wt,{label:"存目",books:a,onNavigate:r})]})]})},Wt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=F(),s=ae(),[i,a]=f.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((l,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:l.work_id&&o?e.jsx("a",{href:s(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(l.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(l.title)}):r(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(l.author).slice(0,20)})]},d))}),!i&&e.jsxs("button",{onClick:()=>a(!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," 條"]})]})},se=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:Nr,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ur,children:i.action.save})]})]}),s]})},Ur={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Nr={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},re=({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"}})]}),me=({value:t,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange: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"}})},Ne=({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 Gr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ve=({value:t,onChange:n,label:o})=>{const[r,s]=f.useState(!1),i=f.useRef(null),a=Gr(t||"");return f.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:$t,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:a.name}),e.jsx(Ne,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:$t,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"}})]})},$t={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Yr(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Kr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const kn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[s,i]=f.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},c=x=>{n(t.filter((g,p)=>p!==x)),s===x&&i(null)},l=(x,g,p)=>{const h=[...t];h[x]={...h[x],[g]:p},n(h)},d=(x,g)=>{const p=[...t];p[x]={...p[x],type:g,id:"",name:""},n(p),g==="bookID"&&o&&o(h=>{const y=[...t];y[x]={...y[x],id:h.id,name:h.title,type:"bookID"},n(y)})},u=x=>{o&&o(g=>{const p=[...t];p[x]={...p[x],id:g.id,name:g.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,g)=>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===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Yr(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Kr(x.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),c(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Pt,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(g,"url"),style:{...Pt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[g]={...p[g],type:"",id:"",name:""},n(p)},style:At,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>u(g),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:()=>u(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[g]={...p[g],type:"",id:"",name:""},n(p)},style:At,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:p=>l(g,"name",p.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:p=>l(g,"id",p.target.value),placeholder:"https://...",style:ve})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...ue,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:ue,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:p=>l(g,"details",p.target.value),placeholder:r.editor.detailsPlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:p=>l(g,"position",p.target.value),placeholder:"如: 卷三, p.52",style:ve})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:p=>l(g,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:p=>l(g,"processor_version",p.target.value),placeholder:"如: v0.1",style:ve})]})]})]})]})})]},g)),e.jsxs("button",{onClick:a,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})]})]})},ue={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ve={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"},Pt={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"},At={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function wn(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 _n(t){return!t||t.length===0?"":JSON.stringify(t)}const Cn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:a,childWorks:c,childCollections:l,containedBooks:d,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:p,onCreateAndLink:h,onSaveRelations:y})=>{const b=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:b.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Jr,children:b.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.belongsToWork,entity:i,onView:p,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(Re,{direction:"up",title:b.relation.containedInCollection,entity:a,onView:p,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),i&&u&&u.length>0&&e.jsx(je,{direction:"horizontal",title:`${b.relation.siblingVersions} (${u.length})`,entities:u,onView:p,onAdd:()=>h("siblingBook","book",{workId:i.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.parentWork,entity:r,onView:p,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),c&&c.length>0&&e.jsx(je,{direction:"down",title:`${b.relation.childWorks} (${c.length})`,entities:c,onView:p,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),l&&l.length>0&&e.jsx(je,{direction:"down",title:`${b.relation.collectionImpl} (${l.length})`,entities:l,onView:p,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(je,{direction:"down",title:`${b.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>h("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.correspondingWork,entity:i,onView:p,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(Re,{direction:"up",title:b.relation.parentCollection,entity:s,onView:p,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(je,{direction:"down",title:`${b.relation.childCollections} (${(l==null?void 0:l.length)??0})`,entities:l||[],onView:p,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(je,{direction:"down",title:`${b.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},Re=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:a,linkLabel:c,createLabel:l,notLinkedLabel:d,viewLabel:u,unlinkLabel:x})=>{const g=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:g,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:zn(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(Mt,{onClick:()=>r(o),title:u,children:"👁️"}),e.jsx(Mt,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(st,{onClick:i,children:c}),e.jsx(st,{onClick:a,primary:!0,children:l})]})]})},je=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:a,expandMoreLabel:c})=>{const[l,d]=f.useState(!1),u=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=l?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:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.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:zn(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!l&&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:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(st,{onClick:s,primary:!0,children:["+ ",i]})})]})},Mt=({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 zn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Jr={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"},In=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:a,onSearch:c,isLoading:l,excludeId:d})=>{const[u,x]=f.useState(""),g=d?a.filter(b=>b.id!==d):a;f.useEffect(()=>{t&&(x(""),c(""))},[t]);const p=b=>{x(b),c(b)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:qr,children:e.jsxs("div",{style:Xr,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:Zr,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:b=>p(b.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Qr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:l?e.jsx("div",{style:Qe,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(b=>e.jsxs("div",{onClick:()=>r(b),style:ei,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):u?e.jsxs("div",{style:Qe,children:["未找到匹配的",h]}):e.jsxs("div",{style:Qe,children:["输入关键词搜索",h]})}),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:ti,children:["创建新",h,"并关联"]})]})]})})},qr={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},Xr={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)"},Zr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Qr={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"},ei={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Qe={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},ti={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ft={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},ni={work:"📜",book:"📖",collection:"📚",entity:"👤"},Tn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[a,c]=f.useState(""),l=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,p;(g=l.current)==null||g.focus(),(p=l.current)==null||p.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&a.trim()?u():g.key==="Escape"&&i()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!t)return null;const x=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Ft[n]}`}};return e.jsx("div",{style:oi,onClick:g=>{g.target===g.currentTarget&&i()},children:e.jsxs("div",{style:ri,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ni[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:l,type:"text",value:a,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Ft[n]}名称...`,style:ii})]}),((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:si,children:"取消"}),e.jsx("button",{onClick:u,disabled:!a.trim(),style:{...li,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},oi={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},ri={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)"},ii={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"},si={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},li={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function ai(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Rn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ci(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const En=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:a,onSelect:c,onCancel:l,onCreate:d,onSearch:u})=>{const[x,g]=f.useState(""),[p,h]=f.useState([]),[y,b]=f.useState(!1),[j,m]=f.useState("recent");f.useEffect(()=>{t&&(g(""),h([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!x.trim()){h([]);return}const z=setTimeout(async()=>{b(!0);try{h(await u(x,o))}catch{h([])}finally{b(!1)}},300);return()=>clearTimeout(z)},[x,o,u]);const k=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&m("search")},[]),_=f.useCallback(z=>s?z.filter(E=>E.id!==s):z,[s]);if(!t)return null;const v=n||(o==="all"?"选择实体":`选择${Rn(o)}`),w=_(r),S=_(p);return e.jsx("div",{style:pi,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:v}),e.jsx("button",{onClick:l,style:ui,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:fi}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Ht,{active:j==="recent",onClick:()=>m("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(Ht,{active:j==="search",onClick:()=>m("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&w.length>0?e.jsx(Ot,{entities:w,onSelect:c}):x.trim()?y?e.jsx(et,{message:"搜索中..."}):S.length>0?e.jsx(Ot,{entities:S,onSelect:c}):e.jsx(et,{message:"未找到匹配的结果"}):e.jsx(et,{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:gi,children:a||"创建新实体"})]})]})})},Ht=({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}),Ot=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(di,{entity:o,onClick:()=>n(o)},o.id))}),di=({entity:t,onClick:n})=>{const[o,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:ai(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:ci(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Rn(t.type)})]})},et=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),pi={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)"},ui={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},fi={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"},gi={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},hi={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},bi={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ln=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:a,onAskAI:c,renderSectionActions:l,onDownloadResource:d,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var ee;const p=A(),[h,y]=f.useState(!1),[b,j]=f.useState("work"),[m,k]=f.useState(""),[_,v]=f.useState(""),[w,S]=f.useState([]),[z,E]=f.useState(!1),[I,C]=f.useState(!1),[B,H]=f.useState("work"),[M,$]=f.useState(""),[D,L]=f.useState(),[T,O]=f.useState(!1),[W,U]=f.useState(null),[G,Z]=f.useState([]);f.useRef(null);const ne=t.type,he=ne==="work",ge=ne==="collection",Q=ne==="book",q=f.useCallback((R,V)=>{n({...t,[R]:V})},[t,n]),Ye=f.useCallback((R,V)=>{k(R),j(V),v(p.editor.selectToLink+p.indexType[V]),S([]),y(!0)},[p]),Ke=f.useCallback(R=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,R)},[r,t.id]),we=f.useCallback(R=>{s==null||s(R.id,R.type)},[s]),_e=f.useCallback((R,V,oe)=>{const ce={...oe,author:(oe==null?void 0:oe.author)||t.author,dynasty:(oe==null?void 0:oe.dynasty)||t.dynasty};H(V),$(R),L(ce),C(!0)},[t.author,t.dynasty]),Je=f.useCallback((R,V)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,M,{type:B,title:R,inheritData:V}),C(!1)},[r,t.id,M,B]),Me=f.useCallback(R=>{if(!R.trim()){S([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(R,b).then(V=>{S(V),E(!1)}).catch(()=>{S([]),E(!1)})},[r,b]),qe=f.useCallback(R=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,R.id),y(!1)},[r,t.id,m]),P=f.useCallback(()=>{o()},[o]),J=f.useCallback(R=>{U(()=>R),O(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),Y=f.useCallback((R,V)=>r!=null&&r.searchEntities?r.searchEntities(R,V==="all"?void 0:V):Promise.resolve([]),[r]),K=f.useCallback(R=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(R),Z(V=>[R,...V.filter(oe=>oe.id!==R.id)].slice(0,10)),W==null||W(R),O(!1),U(null)},[r,W]);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:bi[ne]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(Ne,{children:t.id}),e.jsx(Ne,{color:hi[ne],children:p.indexType[ne]})]})}),e.jsx(se,{title:p.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:l==null?void 0:l("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ve,{label:he?p.editor.workTitle:ge?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:R=>q("title",R)}),Q&&e.jsx(Ve,{label:p.editor.belongsToWork,value:t.workName||"",onChange:R=>q("workName",R)}),e.jsx(re,{label:p.editor.authorLabel,value:t.author||"",onChange:R=>q("author",R)}),e.jsx(re,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:R=>q("dynasty",R)}),(Q||ge)&&e.jsx(Ve,{label:p.editor.containedIn,value:t.collection||"",onChange:R=>q("collection",R)}),(Q||ge)&&e.jsx(re,{label:p.editor.holderLabel,value:t.holder||"",onChange:R=>q("holder",R)}),(Q||ge)&&e.jsx(re,{label:Q?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:R=>q("pages",R)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(re,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:R=>q("firstImage",R)})})]})}),e.jsx(se,{title:p.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(me,{value:t.description||"",onChange:R=>q("description",R),placeholder:p.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(se,{title:p.section.additionalWorks,onSave:o,children:e.jsx(mi,{items:t.additional_works||[],onChange:R=>q("additional_works",R)})}),e.jsx(se,{title:p.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(yi,{items:t.indexed_by||[],onChange:R=>q("indexed_by",R)})}),e.jsx(se,{title:p.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(vi,{items:t.emendated_by||[],onChange:R=>q("emendated_by",R)})}),e.jsx(se,{title:p.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(nt,{items:t.resources||[],onChange:R=>q("resources",R),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(se,{title:p.section.imageResources,onSave:o,children:e.jsx(nt,{items:t.resources||[],onChange:R=>q("resources",R),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(se,{title:p.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(kn,{items:wn(t.sources||""),onChange:R=>q("sources",_n(R)),onOpenEntityPicker:J})}),(Q||ge)&&e.jsx(se,{title:p.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(me,{value:t.provenance||"",onChange:R=>q("provenance",R),placeholder:p.editor.provenancePlaceholder})}),Q&&e.jsx(se,{title:p.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(me,{value:t.otherEditions||"",onChange:R=>q("otherEditions",R),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(Cn,{entityType:ne,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:Ye,onUnlinkEntity:Ke,onViewEntity:we,onCreateAndLink:_e,onSaveRelations:P}),i&&a&&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:a,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(In,{isOpen:h,entityType:b,title:_,onSelect:qe,onCancel:()=>y(!1),onCreate:()=>{y(!1),_e(m,b)},searchResults:w,onSearch:Me,isLoading:z,excludeId:t.id}),e.jsx(Tn,{isOpen:I,entityType:B,relationField:M,inheritData:D,onConfirm:Je,onCancel:()=>C(!1)}),e.jsx(En,{isOpen:T,title:p.action.selectBookOrWork,filterType:"all",recentEntities:G,excludeId:t.id,onSelect:K,onCancel:()=>{O(!1),U(null)},onSearch:Y})]})};function mi({items:t,onChange:n}){const o=A(),r=(a,c,l)=>{const d=t.map((u,x)=>x===a?{...u,[c]:l}:u);n(d)},s=a=>n(t.filter((c,l)=>l!==a)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(re,{label:o.editor.bookNameLabel,value:a.book_title,onChange:l=>r(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(re,{label:o.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:l=>r(c,"n_juan",l&&parseInt(l,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 Bn({items:t,onChange:n,showMeta:o,addLabel:r}){const s=A(),[i,a]=f.useState(null),c=(u,x,g)=>{const p=t.map((h,y)=>y===u?{...h,[x]:g||void 0}:h);n(p)},l=u=>{n(t.filter((x,g)=>g!==u)),i===u&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,x)=>{const g=i===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>a(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:u.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),l(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&o&&(u.title_info||u.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),g&&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(re,{label:s.label.sourceName,value:u.source,onChange:p=>c(x,"source",p)}),e.jsx(re,{label:s.label.sourceBid,value:u.source_bid||"",onChange:p=>c(x,"source_bid",p)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(re,{label:s.label.titleInfo,value:u.title_info||"",onChange:p=>c(x,"title_info",p)}),e.jsx(re,{label:s.label.authorInfo,value:u.author_info||"",onChange:p=>c(x,"author_info",p)})]}),e.jsx(re,{label:s.label.edition,value:u.edition||"",onChange:p=>c(x,"edition",p)})]}),e.jsx(me,{value:u.summary||"",onChange:p=>c(x,"summary",p),placeholder:s.editor.summaryPlaceholder}),e.jsx(me,{value:u.comment||"",onChange:p=>c(x,"comment",p),placeholder:s.editor.commentPlaceholder}),e.jsx(me,{value:u.additional_comment||"",onChange:p=>c(x,"additional_comment",p),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),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 yi({items:t,onChange:n}){const o=A();return e.jsx(Bn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function vi({items:t,onChange:n}){const o=A();return e.jsx(Bn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Wn(t){var c,l,d,u,x,g,p;const n=((l=(c=t.authors)==null?void 0:c[0])==null?void 0:l.name)||"",o=((d=t.publication_info)==null?void 0:d.year)||"",r=((u=t.current_location)==null?void 0:u.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={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 h=t;if(Array.isArray(h.related_works)){const y=h.related_works.find(b=>b.relation==="part_of");y&&(a.parentWorkId=y.id,a.parentWorkName=y.title)}}if(t.type==="book"){const h=t;a.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(a.collectionId=(p=h.contained_in[0])==null?void 0:p.id)}return a}function ji(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 Si=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:a,onSave:c,onDelete:l,onNavigate:d,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:p,downloadStatuses:h,relations:y,onRelationsChange:b,headerExtra:j,className:m,style:k}=t;A();const[_,v]=f.useState(s),w=i?s:_;f.useEffect(()=>{s!==_&&v(s)},[s]);const S=f.useCallback(()=>{const M=w==="view"?"edit":"view";i?i(M):v(M)},[w,i]),[z,E]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(M=>{M&&E(M)})},[o,r]);const I=n||z,C=f.useMemo(()=>I?Wn(I):null,[I]),B=i||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,H=e.jsxs(e.Fragment,{children:[B,j]});return!I&&!C?e.jsx(ye,{}):w==="view"?e.jsx(at,{data:I,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:H,className:m,style:k}):C?e.jsxs("div",{className:m,style:k,children:[H&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:H}),e.jsx(Ln,{data:C,onChange:a||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!l,onDelete:l,onAskAI:x,renderSectionActions:g,onDownloadResource:p,downloadStatuses:h,relations:y,onRelationsChange:b})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Dt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],$n=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=f.useState(null),[a,c]=f.useState(""),[l,d]=f.useState("idle"),[u,x]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(i(null),c(""),d("idle"),x(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=g.current)==null?void 0:b.focus()},100)},[s]),f.useEffect(()=>{if(l==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[l,n]),f.useEffect(()=>{if(!t)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[t,n]);const p=async()=>{if(!(!s||!a.trim())){d("submitting"),x("");try{await o({type:s,content:a.trim()}),d("success")}catch(b){d("error"),x(b instanceof Error?b.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&a.trim()&&l!=="submitting",y=Dt.find(b=>b.value===s);return e.jsx("div",{style:ki,onClick:b=>{b.target===b.currentTarget&&n()},children:e.jsxs("div",{style:wi,onClick:b=>b.stopPropagation(),children:[e.jsxs("div",{style:_i,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Ci,"aria-label":"关闭",children:"✕"})]}),l==="success"?e.jsxs("div",{style:Ei,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:Dt.map(b=>e.jsxs("button",{onClick:()=>i(b.value),style:{...zi,...s===b.value?Ii:{}},children:[e.jsx("span",{children:b.icon})," ",b.label]},b.value))}),e.jsx("textarea",{ref:g,value:a,onChange:b=>c(b.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||l==="submitting",style:{...Ti,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),l==="error"&&e.jsx("div",{style:Li,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!h,style:{...Ri,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交反馈"})})]})]})})},ki={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},wi={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)"},_i={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ci={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},zi={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"},Ii={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ti={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"},Ri={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ei={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Li={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Bi=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Wi,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($n,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},Wi={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"},Vt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],$i=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[i,a]=f.useState("idle"),[c,l]=f.useState(""),d=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var p;return(p=d.current)==null?void 0:p.focus()},100)},[n]);const u=async()=>{if(!(!n||!r.trim())){a("submitting"),l("");try{await t({type:n,content:r.trim()}),a("success"),s(""),o("bug")}catch(p){a("error"),l(p instanceof Error?p.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&i!=="submitting",g=Vt.find(p=>p.value===n);return i==="success"?e.jsx("div",{style:Ut,children:e.jsxs("div",{style:Hi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>a("idle"),style:Oi,children:"继续提交"})]})}):e.jsxs("div",{style:Ut,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Vt.map(p=>e.jsxs("button",{onClick:()=>o(p.value),style:{...Pi,...n===p.value?Ai:{}},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:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Mi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:u,disabled:!x,style:{...Fi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Di,children:c})]})},Ut={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Pi={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"},Ai={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Mi={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Fi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Hi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Oi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Di={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Vi(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 Ui(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 Nt(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 Ni(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 Gi(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 a=r?new Set(o.groups):null,c=new Set(o.book_ids??[]);if(a&&t.node_groups)for(const[u,x]of Object.entries(t.node_groups))a.has(x)&&c.add(u);let l=null;if(o.hypothetical_ids&&(l=new Set(o.hypothetical_ids)),a){l||(l=new Set);for(const u of t.hypothetical_nodes??[])u.group&&a.has(u.group)&&l.add(u.id)}return{books:c,hypos:l}}function Yi(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??[]),a=r.node_groups??{},c=Gi(r,o??r.default_collection??"all"),l=c!==null,d=(c==null?void 0:c.books)??null,u=(c==null?void 0:c.hypos)??null,x=new Set,g=new Set;if(l){const _=new Map(n.map(I=>[I.id,I])),v=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),w=I=>{const C=_.get(I);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(H=>H.ref);const B=v.get(I);return B?(B.derived_from??[]).map(H=>H.ref):[]},S=I=>v.has(I)?!u||u.has(I):!d||d.has(I),z=new Set,E=I=>{if(!z.has(I)){z.add(I);for(const C of w(I))i.has(C)||(S(C)||(v.has(C)?g.add(C):_.has(C)&&x.add(C)),E(C))}};for(const I of n)d&&d.has(I.id)&&!i.has(I.id)&&E(I.id);for(const I of r.hypothetical_nodes??[])u&&u.has(I.id)&&E(I.id)}const p=n.filter(_=>!i.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const v=Ui(_,a);return v&&x.has(_.id)&&(v.bridge=!0),v}).filter(_=>_!==null),h=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||g.has(_.id)).map(_=>{const v=Vi(_);return g.has(_.id)&&(v.bridge=!0),v}),y=[...p,...h],b=new Set(y.map(_=>_.id)),j=new Set,m=[],k=_=>{j.has(_.id)||!b.has(_.source)||!b.has(_.target)||(j.add(_.id),m.push(_))};for(const _ of n)i.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((v,w)=>{k(Nt(_.id,v,w))}),(_.lineage.related_to??[]).forEach((v,w)=>{k(Ni(_.id,v,w))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((v,w)=>{k(Nt(_.id,v,w))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(i)}}function Pn(t,n,o){const r=(t??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ki(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(l=>l.id)),i=new Set((r.hypothetical_nodes??[]).map(l=>l.id)),a=new Set([...s,...i]),c=(l,d)=>{a.has(d.ref)||o.push(`${l}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${l}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&o.push(`${l}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const l of n){if(!l.lineage)continue;const d=`Book ${l.id} (${l.title})`;(l.lineage.derived_from??[]).forEach(u=>c(d,u)),(l.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const l of r.hypothetical_nodes??[]){const d=`Hypothetical ${l.id} (${l.label})`;(l.derived_from??[]).forEach(u=>c(d,u))}return o}const An=({graph:t,renderLink:n,className:o,style:r})=>{const{convert:s}=F();if(!t.nodes.length)return e.jsx("div",{style:{...as,...r},className:o,children:"暂无版本图数据"});const i=new Map,a=new Map;for(const g of t.edges)if(g.kind==="derive"){const p=i.get(g.target)??[];p.push(g),i.set(g.target,p)}else for(const p of[g.source,g.target]){const h=a.get(p)??[];h.push(g),a.set(p,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),l=new Map,d=[];for(const g of t.nodes)if(g.group){const p=l.get(g.group)??[];p.push(g),l.set(g.group,p)}else d.push(g);const u=(g,p)=>(g.year??9999)-(p.year??9999);l.forEach(g=>g.sort(u)),d.sort(u);const x=t.groups.filter(g=>l.has(g.id));return e.jsxs("div",{className:o,style:{...qi,...r},children:[t.title&&e.jsx("div",{style:Xi,children:s(t.title)}),t.description&&e.jsx("div",{style:Zi,children:s(t.description)}),x.map(g=>e.jsx(Gt,{label:g.label,color:g.color,nodes:l.get(g.id),incomingMap:i,siblingMap:a,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(Gt,{label:"其他",nodes:d,incomingMap:i,siblingMap:a,nodeMap:c,renderLink:n})]})},Gt=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:a})=>{const{convert:c}=F();return e.jsxs("div",{style:Qi,children:[e.jsx("div",{style:{...es,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),o.map(l=>e.jsx(Ji,{node:l,incoming:r.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:i,renderLink:a},l.id))]})},Ji=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical",a=t.bridge,{convert:c}=F();return e.jsxs("div",{style:{...ts,borderStyle:i||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?"var(--bim-bg-subtle, #fafafa)":void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:ns,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:rs,children:Pn(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:is,children:[t.category&&e.jsx(Ee,{children:c(t.category)}),t.status==="lost"&&e.jsx(Ee,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Ee,{tone:"warn",children:"残本"}),i&&e.jsx(Ee,{tone:"info",children:"假想祖本"}),a&&e.jsx(Ee,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:ss,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ls,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Kt,children:[e.jsx("div",{style:Jt,children:"来源:"}),n.map(l=>{const d=r.get(l.source);return e.jsxs("div",{style:qt(l.confidence),children:[e.jsx("span",{style:Xt,children:c(l.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)??l.source)}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Yt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Zt,children:["· ",c(l.evidence)]})]},l.id)})]}),o.length>0&&e.jsxs("div",{style:Kt,children:[e.jsx("div",{style:Jt,children:"关联:"}),o.map(l=>{const d=l.source===t.id?l.target:l.source,u=r.get(d);return e.jsxs("div",{style:qt(l.confidence),children:[e.jsx("span",{style:Xt,children:c(l.relation)}),e.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??d)}),e.jsx(Yt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Zt,children:["· ",c(l.evidence)]})]},l.id)})]})]})},Ee=({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})},Yt=({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},qi={fontSize:"14px",color:"var(--bim-fg, #333)"},Xi={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Zi={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Qi={marginBottom:"16px"},es={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},ts={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},ns={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},os={fontSize:"15px",fontWeight:600},rs={fontSize:"12px",color:"var(--bim-muted, #777)"},is={marginBottom:"6px"},ss={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ls={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Kt={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Jt={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},qt=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Xt={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Zt={fontSize:"11px",color:"var(--bim-muted, #888)"},as={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Mn=({selectedNodeId:t,...n})=>{const[o,r]=f.useState("loading"),[s,i]=f.useState(null);return f.useEffect(()=>{let a=!1;return cs().then(c=>{a||(c?(i(c),r("ready")):r("missing"))}),()=>{a=!0}},[]),o==="loading"?e.jsx("div",{style:Qt,children:"加载图组件中…"}):o==="missing"||!s?e.jsxs("div",{style:Qt,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(ds,{modules:s,selectedNodeId:t,...n})};async function cs(){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 ds=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:a})=>{const{ReactFlow:c,Background:l,Controls:d,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:p,getSmoothStepPath:h,dagre:y}=a,b=f.useMemo(()=>({lineage:w=>{var D,L,T,O;const S=((D=w.data)==null?void 0:D.stepPosition)??.85,[z,E,I]=h({sourceX:w.sourceX,sourceY:w.sourceY,sourcePosition:w.sourcePosition,targetX:w.targetX,targetY:w.targetY,targetPosition:w.targetPosition,stepPosition:S,borderRadius:5}),C=!!((L=w.data)!=null&&L.isSibling),B=C?E:w.targetX-18,H=C?I:w.targetY-12,M=(T=w.data)==null?void 0:T.labelStyle,$=(O=w.data)==null?void 0:O.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:w.id,path:z,style:w.style,markerStart:w.markerStart,markerEnd:w.markerEnd}),w.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)",...$,...M},children:w.label})})]})}}),[g,p,h]),j=f.useMemo(()=>({version:w=>{const S=w.data,z=S.kind==="hypothetical",E=S.status==="lost",I=S.isSelected,C=S.bridge,B=S.borderColor??"#888",H=C||z?"dashed":"solid",M=C?.5:E?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${H} ${I?"#0078d4":B}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":z||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Pn(S.yearText,void 0,S.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:m}=F(),{rfNodes:k,rfEdges:_}=f.useMemo(()=>ps(t,y,n,i,m),[t,y,n,i,m]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(c,{nodes:k,edges:_,nodeTypes:j,edgeTypes:b,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(l,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function ps(t,n,o,r,s=i=>i??""){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??"#888"]));for(const j of t.nodes)l.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(u.has(j.relation)||l.setEdge(j.source,j.target));n.layout(l);const x=t.nodes.map(j=>{const m=l.node(j.id),k=r&&j.id===r,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??us(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:o,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:_,draggable:!1,selected:k}}),g=.78,p=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const y=new Map;for(const[j,m]of h){if(m.length<=1)continue;const k=[...m].sort((v,w)=>{var E,I;const S=((E=l.node(v.target))==null?void 0:E.y)??0,z=((I=l.node(w.target))==null?void 0:I.y)??0;return S-z}),_=k.length;k.forEach((v,w)=>{const S=(w-(_-1)/2)*p;y.set(v.id,g+S)})}const b=t.edges.map(j=>xs(j,y.get(j.id),s));return{rfNodes:x,rfEdges:b}}function xs(t,n,o=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",i=fs(t.confidence),a={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:a,markerStart:s?a:void 0,zIndex:1e3}}function us(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function fs(t){switch(t){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const Qt={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)"},gs=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,collection:a,onCollectionChange:c,collectionsAvailable:l,collectionCounts:d,className:u,style:x})=>{var m;const[g,p]=f.useState(n),h=k=>{p(k),i==null||i(k)},y=(()=>{if(!l)return[];const k=Object.entries(l);return k.length===0||l.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),b=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const j=a?(m=l==null?void 0:l[a])==null?void 0:m.description:void 0;return e.jsxs("div",{className:u,style:x,children:[e.jsxs("div",{style:hs,children:[e.jsx("button",{onClick:()=>h("list"),style:tt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:tt(g==="graph"),children:"关系图"}),b&&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:"集合:"}),y.map(([k,_])=>{const v=d==null?void 0:d[k];return e.jsxs("button",{onClick:()=>c==null?void 0:c(k),style:tt(a===k),title:_.description,children:[_.label,v!=null?` ${v}`:""]},k)})]})]}),b&&j&&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:j}),g==="list"?e.jsx(An,{graph:t,renderLink:o}):e.jsx(Mn,{graph:t,renderLink:o,height:r,selectedNodeId:s})]})},hs={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},tt=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"}),bs=({style:t})=>{const n=f.useContext(Pe);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",i=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})};exports.BidLink=N.BidLink;exports.BookIndexError=N.BookIndexError;exports.BookIndexManager=N.BookIndexManager;exports.BookIndexStorage=N.BookIndexStorage;exports.BundleStorage=N.BundleStorage;exports.ConfigError=N.ConfigError;exports.GithubStorage=N.GithubStorage;exports.IdGenerationError=N.IdGenerationError;exports.IdGenerator=N.IdGenerator;exports.LocalStorage=N.LocalStorage;exports.MigrationError=N.MigrationError;exports.StorageError=N.StorageError;exports.base36Decode=N.base36Decode;exports.base36Encode=N.base36Encode;exports.base58Decode=N.base58Decode;exports.buildId=N.buildId;exports.cleanName=N.cleanName;exports.decodeId=N.decodeId;exports.decodeIdString=N.decodeIdString;exports.encodeId=N.encodeId;exports.extractIdFromUrl=N.extractIdFromUrl;exports.extractStatus=N.extractStatus;exports.extractType=N.extractType;exports.normalizeCatalog=N.normalizeCatalog;exports.parseId=N.parseId;exports.shardOf=N.shardOf;exports.smartDecode=N.smartDecode;exports.validateResource=N.validateResource;exports.Badge=Ne;exports.BidUrlProvider=Jn;exports.CollatedEdition=jn;exports.CollectionCatalog=fn;exports.CreateEntityDialog=Tn;exports.EmendatedBySection=xn;exports.EntityDetail=ln;exports.EntityPickerDialog=En;exports.EntitySelector=In;exports.FeedbackButton=Bi;exports.FeedbackDialog=$n;exports.FeedbackForm=$i;exports.FeedbackList=Sn;exports.FormInput=re;exports.FormTextArea=me;exports.HomePage=it;exports.IndexApp=Hr;exports.IndexBrowser=ot;exports.IndexDetail=at;exports.IndexEditor=Ln;exports.IndexView=Si;exports.LocaleContext=Pe;exports.LocaleProvider=ro;exports.LocaleToggle=bs;exports.ModeIndicator=rn;exports.RelationPanel=Cn;exports.ResourceEditor=nt;exports.ResourceList=lt;exports.SearchInput=sn;exports.Section=se;exports.SmartBidInput=Ve;exports.SourceEditor=kn;exports.VersionLineageGraph=Mn;exports.VersionLineageList=An;exports.VersionLineageView=gs;exports.WorkCatalog=Or;exports.buildLineageGraph=Yi;exports.detailToEditor=Wn;exports.editorToDetail=ji;exports.formatTemplate=Ae;exports.parseSourceString=wn;exports.stringifySources=_n;exports.useBidUrl=ae;exports.useConvert=F;exports.useT=A;exports.validateLineageGraph=Ki;