book-index-ui 0.2.11 → 0.2.13

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 kn=Object.create;var lt=Object.defineProperty;var wn=Object.getOwnPropertyDescriptor;var Cn=Object.getOwnPropertyNames;var _n=Object.getPrototypeOf,zn=Object.prototype.hasOwnProperty;var In=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of Cn(n))!zn.call(t,l)&&l!==r&&lt(t,l,{get:()=>n[l],enumerable:!(o=wn(n,l))||o.enumerable});return t};var st=(t,n,r)=>(r=t!=null?kn(_n(t)):{},In(n||!t||!t.__esModule?lt(r,"default",{value:t,enumerable:!0}):r,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-DEouFxE1.cjs"),e=require("react/jsx-runtime"),u=require("react"),Tn=require("react-dom"),Rn=t=>`/book-index?id=${t}`,Dt=u.createContext(Rn);function En({buildUrl:t,children:n}){const r=u.useMemo(()=>t,[t]);return e.jsx(Dt.Provider,{value:r,children:n})}function re(){return u.useContext(Dt)}function ge(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Ln(t,n){return ge(t).includes(n)}const Ht={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Bn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Wn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Be=u.createContext(null),Ot={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:"圖片資源"}},$n={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Pn={"zh-Hant":Ot,"zh-Hans":$n},Ut="bim-locale";function An(){try{const t=localStorage.getItem(Ut);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Fn(t){try{localStorage.setItem(Ut,t)}catch{}}const Mn="zh-Hant",Dn=({locale:t,onLocaleChange:n,children:r})=>{const[o,l]=u.useState(t??Mn),i=t??o;u.useEffect(()=>{if(t)return;const f=An();f&&f!==o&&l(f)},[]);const[s,a]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(f=>{const x=f.Converter({from:"tw",to:"cn"});a(()=>x)}).catch(()=>{a(()=>f=>f)}):a(null)},[i]);const c=u.useCallback(f=>{l(f),Fn(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:i,setLocale:c,messages:Pn[i],converter:s}),[i,c,s]);return e.jsx(Be.Provider,{value:p,children:r})};function $(){const t=u.useContext(Be);return(t==null?void 0:t.messages)??Ot}const Hn=2e3;function H(){const t=u.useContext(Be),n=(t==null?void 0:t.locale)??"zh-Hant",r=(t==null?void 0:t.converter)??null,o=u.useRef(new Map),l=u.useRef(n);l.current!==n&&(o.current.clear(),l.current=n);const i=u.useCallback(s=>{if(!s)return"";if(!r)return s;const a=o.current.get(s);if(a!==void 0)return a;const c=r(s);if(o.current.size>=Hn){const p=o.current.keys().next().value;p!==void 0&&o.current.delete(p)}return o.current.set(s,c),c},[r]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function We(t,n){return t.replace(/\{(\w+)\}/g,(r,o)=>String(n[o]??""))}function On(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 Un(){return{id:"",name:"",url:"",type:"text",details:""}}const Ze=({items:t,onChange:n,onDownload:r,downloadStatuses:o,filterType:l})=>{const i=$(),[s,a]=u.useState(null),c=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],p=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],f=y=>{if(!l)return!0;const v=ge(y);return l==="text"?v.includes("text"):l==="image"?v.includes("image")||v.includes("physical"):l==="physical"?v.includes("physical"):v.includes(l)},x=t.map((y,v)=>({item:y,originalIndex:v})).filter(({item:y})=>f(y)),h=()=>{const y=Un();l&&(y.type=l),n([...t,y]),a(t.length)},d=y=>{n(t.filter((v,j)=>j!==y)),a(null)},b=(y,v,j)=>{const z=[...t];if(z[y]={...z[y],[v]:j},v==="url"&&!z[y].id){const w=On(j);w&&(z[y].id=w)}n(z)},S=(y,v,j)=>{const w={...t[y].metadata||{}};j?w[v]=j:delete w[v],b(y,"metadata",Object.keys(w).length>0?w:void 0)},g=(y,v)=>{const j=v.trim()?v.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;b(y,"structure",j)},C=(y,v,j)=>{const w=t[y].coverage||{level:1,ranges:""};v==="level"?w.level=parseInt(j)||1:w.ranges=j,b(y,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:y,originalIndex:v})=>{var j,z,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(s===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Vn(y.type??"text"),color:"#fff"},children:(()=>{var T,E;const m=ge(y);return m.length===0?y.type??"text":m.length===1?((T=c.find(L=>L.value===m[0]))==null?void 0:T.label)??m[0]:m.includes("text")&&m.includes("image")?((E=c.find(L=>L.value==="text+image"))==null?void 0:E.label)??"text+image":m.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${i.editor.resourcePlaceholder} ${v+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:m=>m.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),r&&y.url&&Nn(v,o==null?void 0:o[v],r,i),e.jsx("button",{onClick:m=>{m.stopPropagation(),d(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),s===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Ln(y,"image")&&y.url&&Kn(y,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.type}),e.jsx("select",{value:y.type,onChange:m=>b(v,"type",m.target.value),style:{...ae,flex:1},children:c.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]}),e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:m=>b(v,"root_type",m.target.value),style:{...ae,flex:1},children:p.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:m=>b(v,"id",m.target.value),placeholder:i.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:m=>b(v,"name",m.target.value),placeholder:i.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:m=>b(v,"url",m.target.value),placeholder:i.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((j=y.structure)==null?void 0:j.join("、"))||"",onChange:m=>g(v,m.target.value),placeholder:i.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((z=y.coverage)==null?void 0:z.level)??"",onChange:m=>C(v,"level",m.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...Ce,flex:1},children:[e.jsx("span",{style:_e,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=y.coverage)==null?void 0:w.ranges)||"",onChange:m=>C(v,"ranges",m.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:m=>b(v,"details",m.target.value),placeholder:i.editor.detailsPlaceholder,style:{...ae,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(i.metadata).map(([m,T])=>{var E;return e.jsxs("label",{style:{...Ce,gap:"4px"},children:[e.jsx("span",{style:{..._e,minWidth:"56px"},children:T}),e.jsx("input",{type:"text",value:((E=y.metadata)==null?void 0:E[m])||"",onChange:L=>S(v,m,L.target.value),placeholder:T,style:{...ae,flex:1}})]},m)})})]})]})]})]},v)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addResource})]})]})};function Vn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Nn(t,n,r,o){const l=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:s=>{s.stopPropagation(),l||r(t,"")},disabled:l,style:{background:"transparent",border:"none",color:i?"var(--bim-success, #4caf50)":l?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:l?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:l?.6:.9},title:i?o.download.completed:l?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:i?"✓":l?"⏳":"⬇"})}function Kn(t,n){const r=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:r?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ae={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ce={display:"flex",alignItems:"center",gap:"6px"},_e={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Yn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Gn(t){try{const n=new URL(t).hostname;return Yn[n]}catch{return}}const at={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function Jn(t){return t.includes("text")&&t.includes("image")?at["text+image"]:at[t[0]||"physical"]}const ct={text:0,image:1,physical:2};function Me(t){return t.length===0?"physical":[...t].sort((n,r)=>(ct[n]??99)-(ct[r]??99)).join("+")}function qn(t){const n=i=>{const s=i.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const a=i.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},r=new Map,o=[],l=new Set;for(let i=0;i<t.length;i++){const s=t[i];if(s.volumes&&s.volumes.length>0)continue;const a=n(s.name);if(!a)continue;const[c,p]=a,f=`${c}|${Me(ge(s))}`;r.has(f)||r.set(f,{base:{...s,name:c,url:"",volumes:[]},volumes:[]}),r.get(f).volumes.push({volume:p,url:s.url||void 0,status:"found"}),l.add(i)}for(const[,i]of r)if(i.volumes.length>=2)i.volumes.sort((s,a)=>s.volume-a.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,o.push(i.base);else for(let s=0;s<t.length;s++)if(l.has(s)){const a=n(t[s].name),c=a&&`${a[0]}|${Me(ge(t[s]))}`,p=`${i.base.name}|${Me(ge(i.base))}`;c===p&&l.delete(s)}for(let i=0;i<t.length;i++)l.has(i)||o.push(t[i]);return o}const tt=({items:t,groupByType:n=!0,onNavigate:r,renderLink:o})=>{const l=$(),i=u.useMemo(()=>qn(t||[]),[t]),s={text:l.resourceType.text,image:l.resourceType.image,"text+image":l.resourceType.textImage,physical:l.resourceType.physical},a=x=>s[x]?s[x]:x.split("+").map(h=>s[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:l.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:i.map((x,h)=>e.jsx(pt,{item:x},x.id||h))});const c=new Map;for(const x of i){const h=Me(ge(x));c.has(h)||c.set(h,[]),c.get(h).push(x)}const p=["text","image","text+image","physical"],f=[...p.filter(x=>c.has(x)),...[...c.keys()].filter(x=>!p.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:f.map(x=>{const h=c.get(x),d=Jn(x.split("+"));return e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:d,display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:d}}),a(x),e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",h.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:h.map((b,S)=>e.jsx(pt,{item:b,onNavigate:r,renderLink:o},b.id||S))})]},x)})})},dt=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},Vt=({value:t})=>{const r=$().checkType[t];return r?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:r.bg,color:r.fg},children:r.label}):e.jsx("span",{children:t})},Zn=(t,n,r,o)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Vt,{value:n});if(t==="has_translation")return n?r.misc.hasTranslation:r.misc.noTranslation;const l=String(n);return o?o(l):l};function Xn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const l=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(l)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(l[1]))}&page=${n}`;const i=new URL(t);return i.searchParams.set("page",String(n)),i.toString()}return t}catch{return t}}function Qn(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 er(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 tr={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},pt=({item:t,onNavigate:n,renderLink:r})=>{var S;const o=$(),{convert:l}=H(),i=re(),[s,a]=u.useState(!1),c=u.useMemo(()=>(t.url?Gn(t.url):void 0)||l(t.name),[t.url,t.name,l]),p=u.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(g=>({...g,url:g.url||er(g)})),[t.volumes]),f=p&&p.length>0,x=f?new Set(p.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,h=f?new Set(p.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,d=t.expected_volumes??(f?x+h:0),b=t.color_mode?{...tr[t.color_mode],label:o.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:dt(t)||f?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c}),b&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:b.bg,color:b.fg},children:b.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((S=t.metadata)==null?void 0:S.check_type)&&e.jsx(Vt,{value:t.metadata.check_type}),f&&e.jsxs("span",{style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)"},children:[x,"/",d,o.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=Qn(t.metadata);return g?Xn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:o.action.visit}),f&&e.jsx("button",{onClick:()=>a(!s),title:s?"收起分册":"展开分册",style:{marginLeft:"auto",padding:"1px 10px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:s?"var(--bim-widget-border, #e0e0e0)":"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",lineHeight:1.4},children:s?"收起 ▲":"展开 ▼"})]}),dt(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([g])=>g!=="check_type").map(([g,C])=>e.jsxs("span",{children:[o.metadata[g]||g,": ",Zn(g,C,o,l)]},g)),t.details&&!f&&e.jsx("span",{children:l(t.details)}),t.structure&&e.jsxs("span",{children:[o.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[o.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),f&&s&&(()=>{const g=p.some(v=>v.group),C=[];if(g){let v=null;for(const j of p){const z=j.group||"";(!v||v.title!==z)&&(v={title:z,group_id:j.group_id,vols:[]},C.push(v)),v.vols.push(j)}}else C.push({vols:p});const y=v=>{const j=v.status==="missing";return v.url&&!j?e.jsx("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:v.label||`${v.volume}`,children:v.volume},v.volume):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.6:1,lineHeight:1.4},children:v.volume},v.volume)};return e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexDirection:"column",gap:"8px"},children:C.map((v,j)=>{const z=v.title?l(v.title):"";let w=z;return v.title&&v.group_id&&(r?w=r(v.group_id,z):n&&(w=e.jsx("a",{href:i(v.group_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),n(v.group_id))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:m=>m.currentTarget.style.borderBottomStyle="solid",onMouseLeave:m=>m.currentTarget.style.borderBottomStyle="dashed",children:z}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[w,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(y)})]},j)})})})()]})},Nt=({indexSource:t,syncConfig:n,variant:r="index-browser",onSwitchMode:o,onToggleDraft:l,onConfigurePath:i,onSelectFolder:s})=>{const a=$(),c=t==="local",p=(n==null?void 0:n.isDraft)??!0,f=(n==null?void 0:n.repoPath)||"",x=f?f.split(/[/\\]/).pop()||f:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},d={onMouseOver:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:l,title:p?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:p?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:p?"📝":"📚"}),e.jsx("span",{children:p?"draft":"official"})]});return r==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:o,title:a.mode.switchToSync,style:h,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:s,title:f||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:x||a.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:c?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:s,title:f||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:f?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:f,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Ue="bim-search-history",xt=10,ut=8;function Te(){try{const t=localStorage.getItem(Ue);return t?JSON.parse(t):[]}catch{return[]}}function nr(t){try{const n=Te().filter(r=>r!==t);n.unshift(t),n.length>xt&&(n.length=xt),localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function rr(t){try{const n=Te().filter(r=>r!==t);localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function or(){try{localStorage.removeItem(Ue)}catch{}}const Kt=({transport:t,value:n,onChange:r,onSearch:o,onEntrySelect:l,placeholder:i})=>{const s=$(),a=i??s.search.placeholder,c={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection,entity:s.indexType.entity},[p,f]=u.useState(!1),[x,h]=u.useState([]),[d,b]=u.useState(-1),[S,g]=u.useState(null),[C,y]=u.useState(Te),v=u.useRef(null),j=u.useRef(null),z=u.useRef(null);u.useEffect(()=>{if(!t.getAllEntries)return;let _=!1;return t.getAllEntries().then(B=>{_||g(B)}).catch(()=>{}),()=>{_=!0}},[t]);const w=u.useCallback(_=>{if(!_.trim())return C.map(k=>({type:"history",text:k}));if(!S)return[];const B=_.toLowerCase(),D=[],U=[];for(const k of S){if(D.length+U.length>=ut*2)break;const R=(k.title??"").toLowerCase();if(R.startsWith(B))D.push({type:"entry",text:k.title,entry:k});else if(R.includes(B))U.push({type:"entry",text:k.title,entry:k});else{const V=[...k.additional_titles||[],...k.attached_texts||[]];for(const N of V){const F=typeof N=="string"?N:N==null?void 0:N.book_title;if(F!=null&&F.toLowerCase().includes(B)){D.push({type:"entry",text:`${k.title}`,entry:k});break}}}}return[...D,...U].slice(0,ut)},[S,C]);u.useEffect(()=>{h(w(n)),b(-1)},[n,w]),u.useEffect(()=>{const _=B=>{z.current&&!z.current.contains(B.target)&&f(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]),u.useEffect(()=>{const _=B=>{var D,U;if(B.key==="/"&&document.activeElement!==v.current){const k=(D=document.activeElement)==null?void 0:D.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT")return;B.preventDefault(),(U=v.current)==null||U.focus()}};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[]);const m=u.useCallback(_=>{_.trim()&&(nr(_.trim()),y(Te())),o(_),f(!1)},[o]),T=u.useCallback(_=>{_.type==="history"?(r(_.text),m(_.text)):_.entry&&(l?(l(_.entry),f(!1)):(r(_.text),m(_.text)))},[r,m,l]),E=u.useCallback(_=>{if(!p||x.length===0){_.key==="Enter"&&m(n);return}switch(_.key){case"ArrowDown":_.preventDefault(),b(B=>(B+1)%x.length);break;case"ArrowUp":_.preventDefault(),b(B=>(B-1+x.length)%x.length);break;case"Enter":_.preventDefault(),d>=0&&d<x.length?T(x[d]):m(n);break;case"Escape":_.preventDefault(),f(!1);break}},[p,x,d,n,m,T]),L=u.useCallback((_,B)=>{B.stopPropagation(),rr(_),y(Te()),h(D=>D.filter(U=>!(U.type==="history"&&U.text===_)))},[]),P=u.useCallback(_=>{_.stopPropagation(),or(),y([]),h([])},[]);u.useEffect(()=>{if(d>=0&&j.current){const _=j.current.children;_[d]&&_[d].scrollIntoView({block:"nearest"})}},[d]);const W=!n.trim()&&C.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:a,value:n,onChange:_=>{r(_.target.value),f(!0)},onFocus:()=>f(!0),onKeyDown:E,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),p&&x.length>0&&e.jsxs("div",{ref:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[W&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:s.search.history}),e.jsx("button",{onClick:P,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),x.map((_,B)=>e.jsxs("div",{onClick:()=>T(_),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:_.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:_.text}),_.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[_.entry.type],_.entry.edition&&` · ${_.entry.edition}`,_.entry.author&&` · ${_.entry.author}`]}),_.type==="history"&&e.jsx("button",{onClick:D=>L(_.text,D),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:s.action.remove,children:"×"})]},`${_.type}-${_.text}-${B}`))]})]})},Le="bim-recent-ids",ft="bim-recent-entries",gt=50,Ge=5,ir=50,lr=200;function Re(){try{const t=localStorage.getItem(Le);if(t)return JSON.parse(t);const n=localStorage.getItem(ft);if(n){const r=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Le,JSON.stringify(r)),localStorage.removeItem(ft),r}return[]}catch{return[]}}function sr(t){try{const n=Re().filter(r=>r!==t);n.unshift(t),n.length>gt&&(n.length=gt),localStorage.setItem(Le,JSON.stringify(n))}catch{}}function ar(t){try{const n=Re().filter(r=>r!==t);localStorage.setItem(Le,JSON.stringify(n))}catch{}}function cr(){try{localStorage.removeItem(Le)}catch{}}const dr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xe=({transport:t,indexSource:n="local",syncConfig:r,onEntryClick:o,onNewEntry:l,onSwitchMode:i,onToggleDraft:s,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:p,initialQuery:f,onQueryChange:x,headerRight:h})=>{const d=$(),b=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:d.indexType.entity,key:"entities"}],[S,g]=u.useState(f??""),[C,y]=u.useState(null),[v,j]=u.useState(null),[z,w]=u.useState(!1),[m,T]=u.useState(null),[E,L]=u.useState(""),[P,W]=u.useState(!f),[_,B]=u.useState(Re),[D,U]=u.useState([]),[k,R]=u.useState(!1),[V,N]=u.useState(!1),[F,le]=u.useState(null),[Q,de]=u.useState(null),fe=u.useRef(void 0),ue=u.useRef(!1),q=u.useCallback(async(A,Y)=>{if(!A.trim()){W(!0),y(null),j(null);return}W(!1),w(!0),L("");try{if(t.searchAll){const Z=await t.searchAll(A,Y??Ge);y(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(A,te,{page:1,pageSize:Y??Ge})));y({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(Z){L(Z instanceof Error?Z.message:String(Z)),y(null)}finally{w(!1)}},[t]);u.useEffect(()=>{var I,M;let A=!1;const Y=["work","book","collection","entity"],Z=Promise.all(Y.map(J=>t.loadEntries(J,{page:1,pageSize:1}).catch(()=>({total:0})))),G=((I=t.getResourceCounts)==null?void 0:I.call(t).catch(()=>null))??Promise.resolve(null),te=((M=t.getSubtypeStats)==null?void 0:M.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([J,se,me])=>{A||(le({works:J[0].total,books:J[1].total,collections:J[2].total,entities:J[3].total,hasText:se==null?void 0:se.hasText,hasImage:se==null?void 0:se.hasImage}),me&&de(me))}),()=>{A=!0}},[t]),u.useEffect(()=>{ue.current||!(f!=null&&f.trim())||(ue.current=!0,q(f))},[f,q]);const K=u.useCallback(A=>{if(g(A),x==null||x(A),!A.trim()){W(!0),y(null),j(null);return}fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{j(null),q(A)},lr)},[q,x]),Ve=u.useCallback(A=>{fe.current&&clearTimeout(fe.current),x==null||x(A),q(A)},[q,x]),Ne=u.useCallback(A=>{j(A),q(S,ir)},[S,q]);u.useEffect(()=>{if(!_.length){U([]);return}let A=!1;return R(!0),Promise.all(_.slice(0,10).map(async Y=>{var Z,G,te;try{if(t.getEntry){const M=await t.getEntry(Y);if(M)return M}const I=await t.getItem(Y);if(I){const M=I.authors;return{id:Y,title:I.title||Y,type:I.type||"work",author:(Z=M==null?void 0:M[0])==null?void 0:Z.name,dynasty:(G=M==null?void 0:M[0])==null?void 0:G.dynasty,role:(te=M==null?void 0:M[0])==null?void 0:te.role,edition:I.edition||void 0}}}catch{}return{id:Y,title:Y,type:"work",notFound:!0}})).then(Y=>{A||(U(Y),R(!1))}),()=>{A=!0}},[_,t]);const ke=A=>{T(A.id),sr(A.id),B(Re()),o==null||o(A)},we=A=>{ar(A),B(Re())},Ke=()=>{cr(),B([])},$e=A=>b.find(Y=>Y.type===A),Ye=C&&(C.works.length>0||C.books.length>0||C.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!p&&e.jsx(Nt,{variant:"index-browser",indexSource:n,syncConfig:r,onSwitchMode:i,onToggleDraft:s,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Kt,{transport:t,value:S,onChange:K,onSearch:Ve,onEntrySelect:ke}),l&&e.jsx("button",{onClick:()=>l("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:d.action.newEntry})]}),F&&P&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()}),F.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.entities.toLocaleString()})]})]})}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):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})]}):P?e.jsx("div",{style:{flex:1},children:k?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):D.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:d.search.recentBrowse}),e.jsx("button",{onClick:Ke,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:d.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:D.slice(0,V?10:3).map(A=>A.notFound?e.jsx(pr,{id:A.id,onRemove:we,t:d},A.id):e.jsx(ht,{entry:A,selected:m===A.id,onClick:ke,getConfig:$e,onRemove:we},A.id))}),!V&&D.length>3&&e.jsx("button",{onClick:()=>N(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:d.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Ye?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:A,icon:Y,name:Z,key:G})=>{const te=C[G]??[],I=dr[G],M=C[I]??0;if(te.length===0)return null;const se=!(v===A)&&M>Ge;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[Y," ",Z,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[M," ",d.unit.items]})]}),se&&e.jsx("button",{onClick:()=>Ne(A),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(me=>e.jsx(ht,{entry:me,selected:m===me.id,onClick:ke,getConfig:$e,query:S},me.id))})]},A)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:We(d.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},ht=({entry:t,selected:n,onClick:r,getConfig:o,query:l,onRemove:i})=>{const s=$(),{convert:a}=H(),c=[...t.additional_titles||[],...t.attached_texts||[]],p=l&&c.length?c.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(l.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>r(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:s.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:s.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,s.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),p&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",a(p)]})]}),i?e.jsx("button",{onClick:f=>{f.stopPropagation(),i(t.id)},title:s.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},pr=({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 xr(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 ur({data:t}){const{convert:n}=H(),{dynasty:r,birth_year:o,death_year:l}=t,i=[];return r&&i.push(`〔${n(r)}〕`),o!==void 0&&l!==void 0?i.push(`${o}—${l}`):o!==void 0?i.push(`${o}—?`):l!==void 0&&i.push(`?—${l}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function fr({alt_names:t}){const{convert:n}=H(),r=new Map;for(const i of t){const s=i.type||"別名";r.has(s)||r.set(s,[]),r.get(s).push(i.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],l=[...r.keys()].sort((i,s)=>{const a=o.indexOf(i),c=o.indexOf(s);return a===-1&&c===-1?0:a===-1?1:c===-1?-1:a-c});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:l.map(i=>{const s=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:s.map((a,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(a)]},c))})]},i)})})}function gr({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 hr({works:t,transport:n,onNavigate:r,renderLink:o}){const l=$(),{convert:i}=H(),s=re(),[a,c]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const d=t.map(S=>S.work_id);return(async()=>{const S=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(d);let j=!0;for(let z=0;z<d.length;z++){const w=v[z];w!=null&&w.title?S.set(d[z],w.title):w!=null&&w.primary_name?S.set(d[z],w.primary_name):j=!1}if(j)return S}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),j=new Map(v.map(w=>[w.id,w.title||w.primary_name||w.id]));let z=!0;for(const w of d){const m=j.get(w);m?S.set(w,m):z=!1}if(z)return S}catch{}const g=[...d],C=8,y=new Array(C).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!S.has(v))try{if(n.getEntry){const w=await n.getEntry(v);if(w!=null&&w.title){S.set(v,w.title);continue}}const j=await n.getItem(v),z=j&&(j.title||j.primary_name)||v;S.set(v,z)}catch{S.set(v,v)}}});return await Promise.all(y),S})().then(S=>{h||c(S)}),()=>{h=!0}},[t,n]);const p=new Map;for(const h of t){const d=h.role||"";p.has(d)||p.set(d,[]),p.get(d).push(h)}const f=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...p.keys()].sort((h,d)=>{const b=f.indexOf(h),S=f.indexOf(d);return b===-1&&S===-1?h.localeCompare(d):b===-1?1:S===-1?-1:b-S});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[l.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(h=>{const d=p.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",d.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:d.map((b,S)=>{const g=i(a.get(b.work_id)||b.work_id);return o?e.jsx("li",{children:o(b.work_id,g)},S):r?e.jsx("li",{children:e.jsx("a",{href:s(b.work_id),onClick:C=>{C.metaKey||C.ctrlKey||(C.preventDefault(),r(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},S):e.jsx("li",{children:g},S)})})]},h)})]})}const Yt=({data:t,transport:n,onNavigate:r,renderLink:o,headerExtra:l})=>{var f;const i=$(),{convert:s}=H();let a=!1;try{a=O.extractStatus(t.id)==="draft"}catch{}const c=xr(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[s(t.primary_name),e.jsx(ur,{data:t})]}),l]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:i.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),c&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(fr,{alt_names:t.alt_names}),e.jsx(gr,{data:t}),((f=t.description)==null?void 0:f.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:s(t.description.text)}),t.works&&t.works.length>0&&e.jsx(hr,{works:t.works,transport:n,onNavigate:r,renderLink:o})]})},br=["〇","一","二","三","四","五","六","七","八","九"],bt=["","十","百","千"];function Gt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),r=n.length;let o="",l=!1;for(let i=0;i<r;i++){const s=parseInt(n[i]),a=r-1-i;s===0?l=!0:(l&&o&&(o+="〇"),l=!1,s===1&&a===1&&i===0?o+=bt[a]:o+=br[s]+bt[a])}return o}function Jt({type:t}){const n=$(),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 mr({isDraft:t}){const n=$();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function yr({id:t}){const n=$(),[r,o]=u.useState(!1),l=()=>{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:l,title:r?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:r?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=r?"1":"0.5",children:r?"✓":"⧉"})]})}function ne({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function ce({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function qt({authors:t,type:n,onNavigate:r,renderLink:o}){const{convert:l}=H();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,s)=>{const a=l(i.name),c=i.entity_id?e.jsx(ie,{id:i.entity_id,label:a,onNavigate:r,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:a});return e.jsxs("span",{children:[s>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:["〔",l(i.dynasty),"〕"]}),c,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",l(i.role)]})]},s)})})}function ie({id:t,label:n,onNavigate:r,renderLink:o}){const l=re();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:l(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 vr({id:t,title:n,edition:r,type:o,isDraft:l,authors:i,volumeText:s,meta:a,headerExtra:c,onNavigate:p,renderLink:f}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,r&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:r}),s&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Jt,{type:o}),e.jsx(mr,{isDraft:l}),e.jsx(yr,{id:t})]}),((i==null?void 0:i.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(qt,{authors:i,type:o,onNavigate:p,renderLink:f}),a]})]})}function Zt({items:t,label:n,showMeta:r,onNavigate:o,renderLink:l}){const i=$(),{convert:s}=H();if(!t.length)return null;const[a,c]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((p,f)=>{const x=a===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(x?null:f),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:s(p.source)}),!x&&r&&p.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s(p.title_info)}),p.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ie,{id:p.source_bid,label:i.action.view,onNavigate:o,renderLink:l})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r&&(p.title_info||p.author_info||p.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[p.title_info&&e.jsx(ce,{label:i.label.titleInfo,children:s(p.title_info)}),p.author_info&&e.jsx(ce,{label:i.label.authorInfo,children:s(p.author_info)}),p.edition&&e.jsx(ce,{label:i.label.edition,children:s(p.edition)})]}),p.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:s(p.summary)})]}),p.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(p.comment)})]}),p.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:s(p.additional_comment)})]})]})]},f)})})]})}function jr({items:t,onNavigate:n,renderLink:r}){const o=$();return e.jsx(Zt,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:r})}function Xt({items:t,onNavigate:n,renderLink:r}){const o=$();return e.jsx(Zt,{items:t,label:o.section.emendated,onNavigate:n,renderLink:r})}function Qt({label:t,items:n}){const{convert:r}=H();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,l)=>{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)},l)})})]}):null}function Sr({items:t}){const n=$();return e.jsx(Qt,{label:n.section.aliases,items:t})}function kr({items:t}){const n=$();return e.jsx(Qt,{label:n.section.attachedTexts,items:t})}function wr({items:t}){const n=$(),{convert:r}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,l)=>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]})]},l))})]}):null}function Cr({items:t}){const n=$(),{convert:r}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,l)=>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)})]},l))]})]}):null}function _r({items:t}){const n=$(),{convert:r}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,l)=>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)]},l))})]}):null}function mt({title:t,ids:n,transport:r,onNavigate:o,renderLink:l}){const{convert:i}=H(),[s,a]=u.useState([]);return u.useEffect(()=>{if(!n.length){a([]);return}if(!r){a(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>r.getItem(p).then(f=>({id:p,title:f?f.title:void 0,edition:f?f.edition:void 0,type:f?f.type:void 0})).catch(()=>({id:p})))).then(p=>{c||a(p)}),()=>{c=!0}},[n,r]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(s.length?s:n.map(c=>({id:c}))).map(c=>{const p=c.edition?`${i(c.title)||c.id}(${i(c.edition)})`:i(c.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ie,{id:c.id,label:p,onNavigate:o,renderLink:l})},c.id)})})]}):null}function zr({book:t,onNavigate:n,renderLink:r}){const o=$(),{convert:l}=H(),[i,s]=u.useState(!1),a=t.resources&&t.resources.length>0,c=t.edition?l(t.edition):l(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:a&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ie,{id:t.id,label:c,onNavigate:n,renderLink:r})}),a&&e.jsx("span",{onClick:()=>s(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?o.action.expand:o.action.collapse,children:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(tt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:r})})]})}function Ir({ids:t,transport:n,onNavigate:r,renderLink:o}){const l=$(),[i,s]=u.useState([]);return u.useEffect(()=>{if(!t.length){s([]);return}if(!n){s(t.map(c=>({id:c})));return}let a=!1;return Promise.all(t.map(c=>n.getItem(c).then(p=>({id:c,title:p?p.title:void 0,edition:p?p.edition:void 0,resources:p?p.resources:void 0})).catch(()=>({id:c})))).then(c=>{a||s(c)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(i.length?i:t.map(a=>({id:a}))).map(a=>e.jsx(zr,{book:a,onNavigate:r,renderLink:o},a.id))})]}):null}function Tr({workData:t,onNavigate:n,renderLink:r}){var i,s,a;const o=$(),{convert:l}=H();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(Jt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ie,{id:t.id,label:l(t.title),onNavigate:n,renderLink:r})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(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:[Gt(t.juan_count.number),o.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(qt,{authors:t.authors,type:"work",onNavigate:n,renderLink:r}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:l(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(ce,{label:o.label.parentWork,children:e.jsx(ie,{id:t.parent_work.id,label:l(t.parent_work.title),onNavigate:n,renderLink:r})})})]})]})}function Rr({items:t,onNavigate:n,renderLink:r}){const o=$(),{convert:l}=H();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:o.indexType.collection}),e.jsx(ie,{id:i.id,label:l(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:We(o.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const nt=({data:t,id:n,transport:r,onNavigate:o,renderLink:l,headerExtra:i,className:s,style:a})=>{var P,W,_,B,D,U;const c=$(),{convert:p}=H(),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState(null),[g,C]=u.useState(null),[y,v]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!r)return;let k=!1;return d(!0),S(null),r.getItem(n).then(R=>{k||(R?x(R):S(c.misc.notFoundEntry))}).catch(R=>{k||S(R instanceof Error?R.message:c.misc.loadFailed)}).finally(()=>{k||d(!1)}),()=>{k=!0}},[t,n,r]),u.useEffect(()=>{if(!j||!r){C(null),v([]);return}let k=!1;const R=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(R?r.getItem(R).then(V=>{!k&&V&&V.type==="work"&&C(V)}).catch(()=>{}):C(null),j.type==="book"){const V=j;V.contained_in&&V.contained_in.length>0?Promise.all(V.contained_in.map(N=>{const F=typeof N=="string"?N:N.id,le=typeof N=="string"?void 0:N.volume_index;return r.getItem(F).then(Q=>({id:F,title:Q&&Q.title||F,volume_index:le})).catch(()=>({id:F,title:F,volume_index:le}))})).then(N=>{k||v(N)}):v([])}else v([]);return()=>{k=!0}},[j,r]),h)return e.jsx("div",{className:s,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((k,R)=>e.jsx("div",{style:{height:R===1?"32px":"16px",width:`${k}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},R))})});if(b)return e.jsx("div",{className:s,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:b});if(!j)return null;if(j.type==="entity")return e.jsx("div",{className:s,style:a,children:e.jsx(Yt,{data:j,transport:r,onNavigate:o,renderLink:l,headerExtra:i})});const z=j.type==="book"?j:null,w=j.type==="collection"?j:null,m=j.type==="work"?j:null;let T=!1;try{T=O.extractStatus(j.id)==="draft"}catch{}let E="";j.measure_info?E=p(j.measure_info):(P=j.juan_count)!=null&&P.number?E=Gt(j.juan_count.number)+c.unit.juan:(W=j.juan_count)!=null&&W.description&&(E=p(j.juan_count.description));const L=[];return(_=j.publication_info)!=null&&_.year&&L.push(e.jsx(ce,{label:c.label.year,children:j.publication_info.year},"year")),(B=j.current_location)!=null&&B.name&&L.push(e.jsx(ce,{label:c.label.currentLocation,children:p(j.current_location.name)},"loc")),(D=j.page_count)!=null&&D.description&&L.push(e.jsx(ce,{label:c.label.pageCount,children:j.page_count.description},"page")),z!=null&&z.edition&&L.push(e.jsx(ce,{label:c.label.edition,children:p(z.edition)},"ver")),m!=null&&m.parent_work&&L.push(e.jsx(ce,{label:c.label.parentWork,children:e.jsx(ie,{id:m.parent_work.id,label:p(m.parent_work.title),onNavigate:o,renderLink:l})},"pw")),m!=null&&m.parent_works&&m.parent_works.length>0&&!m.parent_work&&L.push(e.jsx(ce,{label:c.label.parentWork,children:m.parent_works.map((k,R)=>e.jsxs("span",{children:[R>0&&"、",e.jsx(ie,{id:k,onNavigate:o,renderLink:l})]},k))},"pws")),e.jsxs("div",{className:s,style:a,children:[e.jsx(vr,{id:j.id,title:p(j.title),edition:j.edition?p(j.edition):void 0,type:j.type,isDraft:T,authors:j.authors,volumeText:E,meta:L,headerExtra:i,onNavigate:o,renderLink:l}),((U=j.description)==null?void 0:U.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:p(j.description.text)}),y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.containedIn}),e.jsx(Rr,{items:y,onNavigate:o,renderLink:l})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.belongsToWork}),e.jsx(Tr,{workData:g,onNavigate:o,renderLink:l})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(wr,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(Sr,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(kr,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(jr,{items:j.indexed_by,onNavigate:o,renderLink:l}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Xt,{items:j.emendated_by,onNavigate:o,renderLink:l}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:c.section.resources}),e.jsx(tt,{items:j.resources,groupByType:!0,onNavigate:o,renderLink:l})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(Cr,{items:z.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&e.jsx(_r,{items:w.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(mt,{title:c.section.relatedVersions,ids:z.related_books,transport:r,onNavigate:o,renderLink:l}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(mt,{title:c.section.containedBooks,ids:w.books,transport:r,onNavigate:o,renderLink:l}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[c.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",w.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(k=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ie,{id:k.id,label:p(k.title),onNavigate:o,renderLink:l})},k.id))})]}),(m==null?void 0:m.books)&&m.books.length>0&&e.jsx(Ir,{ids:m.books,transport:r,onNavigate:o,renderLink:l}),(m==null?void 0:m.related_works)&&m.related_works.length>0&&(()=>{const k=[],R=m.related_works.filter(F=>F.relation==="part_of"),V=m.related_works.filter(F=>F.relation==="has_part"),N=m.related_works.filter(F=>!F.relation);return R.length>0&&k.push({label:c.section.belongsToWork,items:R}),V.length>0&&k.push({label:c.section.containedWorks,items:V}),N.length>0&&k.push({label:c.section.relatedWorks,items:N}),k.map(F=>e.jsxs("div",{children:[e.jsxs(ne,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(le=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ie,{id:le.id,label:p(le.title),onNavigate:o,renderLink:l})},le.id))})]},F.label))})()]})};function Er({data:t}){const n=$(),{convert:r}=H(),{stats:o}=t,l=o.processed_volumes??o.total_found_volumes,i=l!=null&&t.total_volumes>0?Math.round(l/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:l})," ",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 Lr({sections:t,activeSection:n,onSelect:r}){const o=$();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>r(null),style:yt(n===null),children:o.catalog.all}),t.map(l=>e.jsxs("button",{onClick:()=>r(l.name),style:yt(n===l.name),children:[l.name,l.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[l.volume_range[0],"–",l.volume_range[1]]})]},l.name))]})}function yt(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Br({id:t,label:n,onNavigate:r,renderLink:o}){const l=re();return o?e.jsx(e.Fragment,{children:o(t,n)}):r?e.jsx("a",{href:l(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 Wr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const r=t[0],o=t[t.length-1];return o-r+1===t.length?`${r}–${o}`:t.length<=3?t.join(", "):`${r}–${o} (${t.length}${n})`}function vt({book:t,onNavigate:n,renderLink:r,showVolumes:o}){const l=$(),{convert:i}=H(),s=t.book_id||t.work_id,a=o&&t.volumes.length>0?Wr(t.volumes,l.unit.volume):null,c=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(p=>i(p)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:c?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,l.unit.volume]}),s&&e.jsx(Br,{id:s,label:t.book_id?l.indexType.book:l.indexType.work,onNavigate:n,renderLink:r}),!s&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:l.catalog.unmatched_label})]})}const en=({data:t,collectionId:n,transport:r,onNavigate:o,renderLink:l,className:i,style:s})=>{const a=$(),[c,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[b,S]=u.useState(null),[g,C]=u.useState(""),y=t||c;u.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollectionCatalog))return;let m=!1;return x(!0),d(null),r.getCollectionCatalog(n).then(T=>{m||(T?p(T):d(a.catalog.notFound))}).catch(T=>{m||d(T instanceof Error?T.message:a.catalog.loadFailed)}).finally(()=>{m||x(!1)}),()=>{m=!0}},[t,n,r,a]);const v=(y==null?void 0:y.sections)&&y.sections.length>0,j=u.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const m=y.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(m).size<m.length},[y]),z=u.useMemo(()=>{if(!y)return[];let m=y.books;if(b&&(m=m.filter(T=>T.section===b)),g.trim()){const T=g.trim().toLowerCase();m=m.filter(E=>E.title.toLowerCase().includes(T)||E.sub_items&&E.sub_items.some(L=>L.toLowerCase().includes(T))||E.edition&&E.edition.toLowerCase().includes(T))}return m},[y,b,g]),w=u.useMemo(()=>{if(!j)return null;const m=[],T=new Map;for(const L of z){if(!L.volumes||L.volumes.length===0)continue;const P=L.volumes[0];T.has(P)||T.set(P,[]),T.get(P).push(L)}const E=[...T.keys()].sort((L,P)=>L-P);for(const L of E)m.push({volume:L,books:T.get(L)});return m},[z,j]);return f?e.jsx("div",{className:i,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):h?e.jsx("div",{className:i,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):y?e.jsxs("div",{className:i,style:s,children:[e.jsx(Er,{data:y}),v&&e.jsx(Lr,{sections:y.sections,activeSection:b,onSelect:S}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:g,onChange:m=>C(m.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[z.length," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((m,T)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:We(a.catalog.volume,{n:m.volume})}),m.books.map((E,L)=>e.jsx(vt,{book:E,onNavigate:o,renderLink:l,showVolumes:E.volumes.length>1},`${m.volume}-${L}`))]},`${m.volume}-${T}`)):z.map((m,T)=>e.jsx(vt,{book:m,onNavigate:o,renderLink:l,showVolumes:!0},T)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},be=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Pe=7,$r=({content:t,children:n,placement:r="top",delayMs:o=100,maxWidth:l=280,wrapperStyle:i})=>{const[s,a]=u.useState(!1),[c,p]=u.useState(null),f=u.useRef(null),x=u.useRef(null),h=u.useRef(null),d=u.useCallback(()=>{const g=x.current,C=h.current;if(!g||!C)return;const y=g.getBoundingClientRect(),v=C.getBoundingClientRect(),j=window.innerHeight,z=document.documentElement.clientWidth;let w=r;r==="top"&&y.top-v.height-Pe<8&&(w="bottom"),r==="bottom"&&y.bottom+v.height+Pe>j-8&&(w="top");const m=w==="top"?y.top-v.height-Pe:y.bottom+Pe;let T=y.left+y.width/2-v.width/2;T=Math.max(8,Math.min(T,z-v.width-8)),p({left:T,top:m,placement:w})},[r]),b=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(!0),o)},[o]),S=u.useCallback(()=>{f.current&&clearTimeout(f.current),a(!1),p(null)},[]);return u.useEffect(()=>{if(!s)return;const g=requestAnimationFrame(d);return()=>cancelAnimationFrame(g)},[s,d]),u.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:b,onMouseLeave:S,onFocus:b,onBlur:S,style:{display:"inline-block",...i},children:n}),s&&Tn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(c==null?void 0:c.left)??-9999,top:(c==null?void 0:c.top)??-9999,maxWidth:l,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:c?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-X,width:0,height:0,...c.placement==="top"?{bottom:-X,borderTop:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}:{top:-X,borderBottom:`${X}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${X}px solid transparent`,borderRight:`${X}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...c.placement==="top"?{bottom:-5,borderTop:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}:{top:-5,borderBottom:`${X-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${X-1}px solid transparent`,borderRight:`${X-1}px solid transparent`}}})]})]}),document.body)]})},jt={A:"fine",B:"rough",C:"rough",D:"ocr"};function Pr(t){return typeof t!="string"?null:t in Ht?t:t in jt?jt[t]:null}const Ar=["〇","一","二","三","四","五","六","七","八","九"],St=["","十","百","千"],Fr=["","萬","億"];function tn(t){if(t===0)return"〇";if(t<0)return`負${tn(-t)}`;const n=[];let r=t,o=0;for(;r>0;){const l=r%1e4;l>0?n.unshift(Mr(l,o>0)+Fr[o]):n.length>0&&n.unshift("〇"),r=Math.floor(r/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Mr(t,n){const r=[];let o=t;for(;o>0;)r.unshift(o%10),o=Math.floor(o/10);let l="";for(let i=0;i<r.length;i++){const s=r[i],a=r.length-1-i;s===0?l&&!l.endsWith("〇")&&(l+="〇"):s===1&&a===1&&i===0&&!n?l+=St[a]:l+=Ar[s]+St[a]}return l.replace(/〇$/,"")}let Ee=null,Ae=null;const He=new Set;function Dr(){return Ee?Promise.resolve():Ae||(Ae=import("opencc-js/t2cn").then(t=>{Ee=t.Converter({from:"tw",to:"cn"}),He.forEach(n=>n())}).catch(()=>{Ee=t=>t,He.forEach(t=>t())}),Ae)}function xe(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Ee)return;const n=()=>t(r=>r+1);return He.add(n),Dr(),()=>{He.delete(n)}},[]),Ee??(n=>n)}function je(t,n){return n(t).toLowerCase()}const rt="#fff59d";function Se(t,n,r){if(!n)return t;const o=je(n,r);if(!o)return t;const l=je(t,r);if(l.length!==t.length)return t;const i=[];let s=0,a=0;for(;s<t.length;){const c=l.indexOf(o,s);if(c===-1){i.push(t.slice(s));break}c>s&&i.push(t.slice(s,c)),i.push(e.jsx("mark",{style:{background:rt,padding:0,color:"inherit"},children:t.slice(c,c+o.length)},a++)),s=c+o.length}return e.jsx(e.Fragment,{children:i})}function ot(t,n,r,o){if(!n)return!0;const l=je(n,o);return(r?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(s=>typeof s=="string"&&je(s,o).includes(l))}function Hr(t,n,r){return n?je(t,r).includes(je(n,r)):!0}const it={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Or={考证:"#5d6d7e"};function Ur(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 nn({file:t,isActive:n,onSelect:r,meta:o,matchState:l}){const i=l===0,s=l==="loading",a=typeof l=="number"&&l>0,c=Ur(t),p=!!(o!=null&&o.vol_label)&&!c.includes(o.vol_label);return e.jsxs("button",{onClick:()=>{i||r(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${rt}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":i?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:i?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:i?.5:1},children:[c,p&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",o.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:l}),s&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function rn(t,n){var r;return t.files.includes(n)?!0:!!((r=t.children)!=null&&r.some(o=>rn(o,n)))}function on(t){var o;const n=t.files.length,r=((o=t.children)==null?void 0:o.reduce((l,i)=>l+on(i),0))||0;return n+r}function Vr(t,n){const r=[],o=s=>{var a;r.push(...s.files),(a=s.children)==null||a.forEach(o)};if(o(t),r.length===0)return;const l=r.map(s=>n[s]);if(l.every(s=>s===void 0))return;if(l.some(s=>s==="loading"))return"loading";let i=0;for(const s of l)typeof s=="number"&&(i+=s);return i}function ln({group:t,activeFile:n,onSelect:r,depth:o=0,juanMeta:l,matchStates:i}){var b;const s=rn(t,n||""),a=Vr(t,i),c=typeof a=="number"&&a>0,p=a===0,[f,x]=u.useState(s||c),h=on(t),d=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{s&&x(!0)},[s]),u.useEffect(()=>{c&&x(!0)},[c]),t.files.length===1&&!d){const S=t.files[0],g=n===S,C=i[S],y=C===0,v=C==="loading",j=typeof C=="number"&&C>0;return e.jsxs("button",{onClick:()=>{y||r(S)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":y?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:g?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":j?`${rt}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,j&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:C}),v&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!f),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:s?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",h,")"]}),c&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",a]}),a==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),f&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(S=>e.jsx(nn,{file:S,isActive:n===S,onSelect:r,meta:l==null?void 0:l[S],matchState:i[S]},S))}),d&&t.children.map((S,g)=>e.jsx(ln,{group:S,activeFile:n,onSelect:r,depth:o+1,juanMeta:l,matchStates:i},g))]})]})}function Nr({files:t,groups:n,activeFile:r,onSelect:o,juanMeta:l,matchStates:i}){const s=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((a,c)=>e.jsx(ln,{group:a,activeFile:r,onSelect:o,juanMeta:l,matchStates:i},c))}):s.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:s.map(a=>e.jsx(nn,{file:a,isActive:r===a,onSelect:o,meta:l==null?void 0:l[a],matchState:i[a]},a))})}function Kr({type:t}){const n=it[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Yr({section:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=H(),l=re(),i=xe(),s=S=>{if(!S)return"";const g=o(S);return r?Se(g,r,i):g},[a,c]=u.useState(!1),p=!!t.summary,f=!!t.comment,x=!!t.additional_comment,h=!!(t.content&&t.content.length>60),d=p||f||x||h;u.useEffect(()=>{r&&c(!0)},[r]);const b=!a&&h?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&c(!a),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",s(t.book_title),"》"]}):s(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[tn(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:s(t.author_info||t.author)})]}),!a&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:s(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:s(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:l(t.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),a&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:s(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:s(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:s(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:s(t.additional_comment)})]}),h&&!p&&!f&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})]})]})}function Gr({section:t,highlightQuery:n=""}){const{convert:r}=H(),o=xe(),l=c=>{if(!c)return"";const p=r(c);return n?Se(p,n,o):p},[i,s]=u.useState(!1),a=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>a&&s(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:a?"pointer":"default",userSelect:"none"},children:[e.jsx(Kr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:l(t.title)}),a&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&a&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${it[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})})]})}function Jr({section:t,highlightQuery:n=""}){const{convert:r}=H(),o=xe();if(!t.content&&!t.title)return null;const l=r((t.content||t.title||"").replace(/\n{2,}/g,`
2
- `)),i=n?Se(l,n,o):l,s=it[t.type]||"#717171",a=t.type==="序"||t.type==="结语";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${s}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:s,marginRight:"8px",padding:"1px 5px",border:`1px solid ${s}40`,borderRadius:"2px",background:`${s}08`,verticalAlign:"middle"},children:t.type}),i]})}function qr(t,n,r){const[o,l]=u.useState({});return u.useEffect(()=>{var p;if(!n||t.length===0)return;let i=!1;const s=t.filter(f=>{var x;return!((x=r==null?void 0:r.current)!=null&&x.has(f))}),a={};for(const f of t)(p=r==null?void 0:r.current)!=null&&p.has(f)&&(a[f]=r.current.get(f));if(Object.keys(a).length>0&&l(a),s.length===0)return;const c=async f=>{var x;try{if(n.getEntry){const g=await n.getEntry(f);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(f);if(!h)return null;const d=h.title||f,b=h.authors,S=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:d,author:S}}catch{return null}};return Promise.all(s.map(async f=>{var h;const x=await c(f);return(h=r==null?void 0:r.current)==null||h.set(f,x),[f,x]})).then(f=>{i||l(x=>{const h={...x};for(const[d,b]of f)h[d]=b;return h})}),()=>{i=!0}},[t.join(","),n]),o}function Zr({section:t,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:l=""}){const{convert:i}=H(),s=re(),a=xe(),c=y=>{if(!y)return"";const v=i(y);return l?Se(v,l,a):v},[p,f]=u.useState(!1);u.useEffect(()=>{l&&f(!0)},[l]);const x=t.type,h=Or[x]||"#717171",d=!!t.content,b=t.work_ids||[],S=b.length>1,g=qr(S?b:[],r,o),C=d&&!p&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>d&&f(!p),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!p&&C&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(C)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:s(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:h,border:`1px solid ${h}40`,borderRadius:"2px",background:`${h}08`},children:x})]})]}),S&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const v=g[y],j=v?`${i(v.title)}${v.author?`(${i(v.author)})`:""}`:y.slice(0,8)+"…";return e.jsxs("a",{href:s(y),onClick:z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),z.stopPropagation(),n(y))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",j]},y)})}),p&&d&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${h}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function Xr({juan:t,searchQuery:n,onNavigate:r,transport:o,workLabelCache:l}){const{convert:i}=H(),s=xe(),a=n.trim(),c=u.useMemo(()=>a?t.sections.filter(x=>ot(x,a,!0,s)):t.sections,[t.sections,a,s]),p=t.sections.filter(x=>x.type==="考证").length,f=c.filter(x=>x.type==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:a?`${f} / ${p} 條`:`${p} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:c.map((x,h)=>e.jsx(Zr,{section:x,onNavigate:r,transport:o,workLabelCache:l,highlightQuery:a},h))}),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Qr({text:t,highlightQuery:n=""}){const{convert:r}=H(),o=xe(),l=s=>{const a=r(s);return n?Se(a,n,o):a},i=t.split(`
3
- `);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((s,a)=>{if(s.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:l(s.slice(2))},a);if(s.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:l(s.slice(3))},a);if(s.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:l(s.slice(4))},a);if(!s.trim())return a>0&&!i[a-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},a);const c=s.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:c.map((p,f)=>p.startsWith("**")&&p.endsWith("**")?e.jsx("strong",{children:l(p.slice(2,-2))},f):e.jsx(u.Fragment,{children:l(p)},f))},a)})})}function eo({sections:t,onNavigate:n,highlightQuery:r=""}){const{convert:o}=H(),l=re(),i=xe(),s=p=>{if(!p)return"";const f=o(p);return r?Se(f,r,i):f},a=[];let c=null;for(const p of t)p.type==="类"?(c&&a.push(c),c={category:p.title,categoryContent:p.content||void 0,items:[]}):p.type==="书"?(c||(c={category:"",items:[]}),c.items.push(p)):(p.type==="序"||p.type==="结语")&&(c||(c={category:"",items:[]}),c.items.push(p),p.type==="结语"&&(a.push(c),c=null));return c&&a.push(c),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:a.map((p,f)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[p.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[s(p.category),p.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:s(p.categoryContent)})]}),p.items.map((x,h)=>x.type==="序"||x.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:s(x.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:l(x.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(x.title),children:e.jsx("strong",{children:s(x.title)})}):e.jsx("strong",{children:s(x.title)}),x.content&&s(x.content)]},h))]},f))})}function to({juan:t,rawText:n,searchQuery:r,onNavigate:o}){const{convert:l}=H(),i=xe(),[s,a]=u.useState("catalog"),c=r.trim(),p=u.useMemo(()=>c?t.sections.filter(d=>ot(d,c,!1,i)):t.sections,[t.sections,c,i]),f=t.sections.filter(d=>d.type==="书").length,x=t.sections.filter(d=>d.type==="詩").length,h=c?p.filter(d=>d.type==="书"||d.type==="詩").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:l(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(d=>e.jsx("button",{onClick:()=>a(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:s===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:s===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${x>0?`${x} 首`:`${f} 部書`}`:x>0?`${x} 首`:`${f} 部书`})]}),s==="raw"&&(n?e.jsx(Qr,{text:n,highlightQuery:c}):e.jsx(eo,{sections:t.sections,onNavigate:o,highlightQuery:c})),s==="catalog"&&p.map((d,b)=>d.type==="书"||d.type==="詩"?e.jsx(Yr,{section:d,onNavigate:o,highlightQuery:c},b):d.type==="类"?e.jsx(Gr,{section:d,highlightQuery:c},b):e.jsx(Jr,{section:d,highlightQuery:c},b)),s==="catalog"&&p.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function sn(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function kt(t){const n=sn(t);return n.length>0?n[0]:null}function no(t){const{workId:n,transport:r,files:o,activeFile:l,activeJuan:i,activeRawText:s,query:a,isKaozhen:c}=t,p=xe(),f=u.useRef(new Map),[x,h]=u.useState({});u.useEffect(()=>{l&&i&&f.current.set(l,{juan:i,rawText:s})},[l,i,s]),u.useEffect(()=>{f.current.clear(),h({})},[n]);const d=u.useCallback((b,S)=>{let g=0;if(b.juan)for(const C of b.juan.sections)ot(C,S,c,p)&&g++;return g===0&&b.rawText&&Hr(b.rawText,S,p)&&(g=1),g},[c,p]);return u.useEffect(()=>{const b=a.trim();if(!b){h({});return}if(!n||!(r!=null&&r.getCollatedJuan)||o.length===0)return;let S=!1;const g={},C=[];for(const w of o){const m=f.current.get(w);m?g[w]=d(m,b):(g[w]="loading",C.push(w))}h(g);const y=8;let v=0;const j=async()=>{var w;for(;v<C.length;){if(S)return;const m=v++,T=C[m];try{const[E,L]=await Promise.all([r.getCollatedJuan(n,T),((w=r.getCollatedJuanText)==null?void 0:w.call(r,n,T))??Promise.resolve(null)]),P={juan:E,rawText:L};if(f.current.set(T,P),S)return;h(W=>({...W,[T]:d(P,b)}))}catch{if(S)return;h(E=>({...E,[T]:0}))}}},z=Array.from({length:Math.min(y,C.length)},()=>j());return Promise.all(z),()=>{S=!0}},[a,n,r,o.join(","),d,p]),{matchStates:x}}const an=({index:t,workId:n,transport:r,onNavigate:o,activeJuan:l,onJuanChange:i,className:s,style:a})=>{const[c,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[b,S]=u.useState(null),[g,C]=u.useState(null),[y,v]=u.useState(!1),[j,z]=u.useState(null),[w,m]=u.useState(""),T=u.useRef(new Map),E=l??b,L=u.useCallback(k=>{S(k),i==null||i(k)},[i]),P=t||c;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(r!=null&&r.getCollatedEditionIndex))return;let k=!1;return x(!0),d(null),r.getCollatedEditionIndex(n).then(R=>{if(!k)if(!R)d("未找到整理本数据");else{p(R);const V=kt(R);!l&&V&&L(V)}}).catch(R=>{k||d(R instanceof Error?R.message:"加载失败")}).finally(()=>{k||x(!1)}),()=>{k=!0}},[t,n,r,l,L]),u.useEffect(()=>{const k=t||c;if(k&&!E){const R=kt(k);R&&L(R)}},[t,c,E,L]);const W=n||(P==null?void 0:P.work_id),_=u.useCallback(async k=>{var R;if(!(!W||!(r!=null&&r.getCollatedJuan))){v(!0),C(null),z(null);try{const[V,N]=await Promise.all([r.getCollatedJuan(W,k),((R=r.getCollatedJuanText)==null?void 0:R.call(r,W,k))??Promise.resolve(null)]);C(V),z(N)}catch{C(null),z(null)}finally{v(!1)}}},[W,r]);u.useEffect(()=>{E&&_(E)},[E,_]);const B=k=>{L(k)};if(f)return e.jsx("div",{className:s,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:s,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!P)return null;const D=P.type==="kaozhen",U=sn(P);return e.jsx(ro,{className:s,style:a,index:P,allFiles:U,isKaozhen:D,effectiveWorkId:W,transport:r,activeFile:E,handleSelectFile:B,juanData:g,juanRawText:j,juanLoading:y,searchQuery:w,setSearchQuery:m,onNavigate:o,workLabelCacheRef:T})},ro=({className:t,style:n,index:r,allFiles:o,isKaozhen:l,effectiveWorkId:i,transport:s,activeFile:a,handleSelectFile:c,juanData:p,juanRawText:f,juanLoading:x,searchQuery:h,setSearchQuery:d,onNavigate:b,workLabelCacheRef:S})=>{const{matchStates:g}=no({workId:i,transport:s,files:o,activeFile:a,activeJuan:p,activeRawText:f,query:h,isKaozhen:l});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:l?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:h,onChange:C=>d(C.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:l?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 C=Pr(r.text_quality.grade);return C?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx($r,{content:Bn[C],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Wn[C],cursor:"help"},children:Ht[C]})}),r.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",r.text_quality.source_note]})]}):null})()]}),e.jsx(Nr,{files:o,groups:r.juan_groups,activeFile:a,onSelect:c,juanMeta:r.juan_metadata,matchStates:g}),x?e.jsx(be,{}):p?l?e.jsx(Xr,{juan:p,searchQuery:h,onNavigate:b,transport:s,workLabelCache:S}):e.jsx(to,{juan:p,rawText:f,searchQuery:h,onNavigate:b}):a?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,r.references&&r.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),r.references.map((C,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,". "]}),C.url?e.jsx("a",{href:C.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:C.title}):e.jsx("span",{children:C.title}),C.author&&e.jsxs("span",{children:[",",C.author]}),C.note&&e.jsxs("span",{children:["。",C.note]})]},y))]})]})},oo={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},io={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function lo(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 cn=({items:t,loading:n})=>{const r=re();return n?e.jsx(be,{}):t.length===0?e.jsx("div",{style:so,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const l=oo[o.type],i=io[o.status];return e.jsxs("div",{style:ao,children:[e.jsxs("div",{style:co,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...wt,background:l.color},children:l.label}),e.jsx("span",{style:{...wt,background:i.color},children:i.label})]}),e.jsx("span",{style:po,children:lo(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:xo,children:[o.resourceId&&e.jsx("a",{href:r(o.resourceId),style:Ct,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:Ct,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:uo,children:o.content}),o.reply&&e.jsxs("div",{style:fo,children:[e.jsx("div",{style:go,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},so={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ao={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},co={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},wt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},po={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},xo={fontSize:"12px",marginBottom:"6px"},Ct={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},uo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},fo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},go={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Qe=({transport:t,onNavigate:n,recommendedIds:r,activeTab:o,onTabChange:l,feedbackApiUrl:i})=>{const s=$(),[a,c]=u.useState(null),[p,f]=u.useState([]),[x,h]=u.useState("recommend"),[d,b]=u.useState([]),[S,g]=u.useState(!1),C=o??x,y=W=>{h(W),l==null||l(W)},[v,j]=u.useState(!0),[z,w]=u.useState(null),[m,T]=u.useState(null),[E,L]=u.useState(null);u.useEffect(()=>{if(!t.getAllEntries)return;let W=!1;return t.getAllEntries().then(_=>{if(W)return;const B=_.filter(k=>k.type==="work").length,D=_.filter(k=>k.type==="book").length,U=_.filter(k=>k.type==="collection").length;c({works:B,books:D,collections:U})}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{let W=!1;return(async()=>{if(r)return r;if(t.getRecommended)try{const B=await t.getRecommended();if(B!=null&&B.groups)return B.groups.flatMap(D=>D.items.map(U=>({...U,group:D.name})))}catch{}return[]})().then(async B=>{if(W)return;const D=B.filter(k=>k.id);if(D.length===0){j(!1);return}const U=await Promise.all(D.map(async k=>{try{let R=null;if(t.getEntry)R=await t.getEntry(k.id);else{const V=await t.getItem(k.id);V&&(R={id:k.id,title:V.title||k.id,type:V.type||"work"})}if(R)return{...R,group:k.group,fallbackDescription:k.description}}catch{}return{id:k.id,title:k.title,type:O.extractType(k.id),group:k.group,fallbackDescription:k.description}}));W||(f(U.filter(k=>k!==null)),j(!1))}),()=>{W=!0}},[t,r]),u.useEffect(()=>{let W=!1;const _=t.getCatalogProgress??t.getResourceProgress;if(_)return _.call(t).then(B=>{W||w(B)}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{if(!t.getCollectionProgress)return;let W=!1;return t.getCollectionProgress().then(_=>{W||T(_)}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{if(!t.getSiteProgress)return;let W=!1;return t.getSiteProgress().then(_=>{W||L(_)}).catch(()=>{}),()=>{W=!0}},[t]),u.useEffect(()=>{if(!i||C!=="feedback")return;let W=!1;return g(!0),fetch(i).then(_=>_.json()).then(_=>{!W&&_.success&&b(_.items||[])}).catch(()=>{}).finally(()=>{W||g(!1)}),()=>{W=!0}},[i,C]);const P=W=>{switch(W){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(ze,{label:s.home.recommendTab,active:C==="recommend",onClick:()=>y("recommend")}),e.jsx(ze,{label:s.home.catalogTab,active:C==="catalog",onClick:()=>y("catalog")}),e.jsx(ze,{label:s.home.collectionTab,active:C==="collection",onClick:()=>y("collection")}),e.jsx(ze,{label:s.home.siteTab,active:C==="site",onClick:()=>y("site")}),i&&e.jsx(ze,{label:s.home.feedbackTab,active:C==="feedback",onClick:()=>y("feedback")})]}),C==="recommend"&&e.jsx(ho,{recommended:p,loading:v,onNavigate:n,getIcon:P,t:s}),C==="catalog"&&e.jsx(_t,{progress:z,t:s,onNavigate:n}),C==="collection"&&e.jsx(_t,{progress:m,t:s,onNavigate:n}),C==="site"&&e.jsx(mo,{progress:E,t:s,totalWorks:(a==null?void 0:a.works)??0}),C==="feedback"&&i&&e.jsx(cn,{items:d,loading:S})]})})},ze=({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}),ho=({recommended:t,loading:n,onNavigate:r,getIcon:o,t:l})=>{const i=re();if(n)return e.jsx(be,{});if(t.length===0)return null;const s=new Map;for(const a of t){const c=a.group||l.home.recommendedBrowse;s.has(c)||s.set(c,[]),s.get(c).push(a)}return e.jsx(e.Fragment,{children:Array.from(s.entries()).map(([a,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const f=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return e.jsxs("a",{href:i(p.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),r==null||r(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(p.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:p.edition})]}),f&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f})]})]},p.id)})})]},a))})},_t=({progress:t,t:n,onNavigate:r})=>{if(!t)return e.jsx(be,{});const o=[...t.resources].sort((a,c)=>a.priority-c.priority),l=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},s={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:l.map(a=>{const c=o.filter(p=>p.status===a);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:s[a]}}),i[a]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>e.jsx(bo,{item:p,t:n,statusColor:s[a],onNavigate:r},p.id))})]},a)})})},bo=({item:t,t:n,statusColor:r,onNavigate:o})=>{const l=re(),i=t.total>0?Math.round(t.imported/t.total*100):0,s=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&o?e.jsx("a",{href:l(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(c))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:s})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?We(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${i}%`,borderRadius:"2px",background:r,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},mo=({progress:t,t:n,totalWorks:r})=>{if(!t)return e.jsx(be,{});const o=[...t.resources].sort((c,p)=>c.priority-p.priority),l=o.filter(c=>c.imported>0),i=o.filter(c=>c.imported===0),s=l.reduce((c,p)=>Math.max(c,p.imported),0),a=r>0?Math.round(s/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:s.toLocaleString()})," / ",r.toLocaleString()," ",n.indexType.work," (",a,"%)"]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(c=>e.jsx(zt,{item:c,t:n,totalWorks:r},c.id))})]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(c=>e.jsx(zt,{item:c,t:n,totalWorks:r},c.id))})]})]})},zt=({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})]})},It="(max-width: 768px)";function yo(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(It).matches);return u.useEffect(()=>{const r=window.matchMedia(It),o=l=>n(l.matches);return r.addEventListener("change",o),()=>r.removeEventListener("change",o)},[]),t}const vo=({transport:t,hideModeIndicator:n=!0,onEntryClick:r,recommendedIds:o,headerRight:l})=>{var U;const i=$(),{convert:s}=H(),a=yo(),[c,p]=u.useState(null),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState("detail"),[g,C]=u.useState([]),[y,v]=u.useState(!1),[j,z]=u.useState(null),[w,m]=u.useState(!1),T=u.useCallback(async k=>{if(!t.getCollatedEditionIndex){z(null);return}m(!0);try{const R=await t.getCollatedEditionIndex(k);z(R)}catch{z(null)}finally{m(!1)}},[t]),E=u.useCallback(async k=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){C([]);return}v(!0);try{if(t.getCollectionCatalogs){const R=await t.getCollectionCatalogs(k);C(R||[])}else if(t.getCollectionCatalog){const R=await t.getCollectionCatalog(k);C(R?[{resource_id:"",data:R}]:[])}}catch{C([])}finally{v(!1)}},[t]),L=u.useCallback(async k=>{if(r){r(k);return}p(k),x(null),C([]),z(null),S("detail"),d(!0);try{const R=await t.getItem(k.id);R&&(x(R),R.type==="collection"?E(k.id):R.type==="work"&&R.has_collated&&T(k.id))}catch(R){console.error("加载详情失败:",R)}finally{d(!1)}},[t,r,E,T]),P=u.useCallback(async k=>{x(null),C([]),z(null),S("detail"),d(!0);try{const R=await t.getItem(k);R&&(x(R),p({id:k,title:R.title||k,type:R.type||"book"}),R.type==="collection"?E(k):R.type==="work"&&R.has_collated&&T(k))}catch(R){console.error("导航失败:",R)}finally{d(!1)}},[t,E,T]),W=(f==null?void 0:f.type)==="collection"&&(g.length>0||y)||(f==null?void 0:f.type)==="work"&&(j||w),_=a&&(h||f),B=u.useCallback(()=>{p(null),x(null),C([]),z(null),S("detail")},[]),D=e.jsx(e.Fragment,{children:h?e.jsx(be,{}):f?e.jsxs(e.Fragment,{children:[(W||l)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[W&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>S("detail"),style:Fe(b==="detail"),children:i.detailTab.basicInfo}),f.type==="collection"&&y&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Fe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),f.type==="collection"&&g.map(k=>e.jsx("button",{onClick:()=>S(`catalog:${k.resource_id}`),style:Fe(b===`catalog:${k.resource_id}`),children:k.short_name?`${s(k.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},k.resource_id)),f.type==="work"&&(j||w)&&e.jsxs("button",{onClick:()=>S("collated"),style:Fe(b==="collated"),children:[i.detailTab.collatedEdition,w&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),l&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:l})]}),e.jsx("div",{style:{padding:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(nt,{data:f,transport:t,onNavigate:P}):b.startsWith("catalog:")?e.jsx(en,{data:(U=g.find(k=>`catalog:${k.resource_id}`===b))==null?void 0:U.data,onNavigate:P}):b==="collated"?e.jsx(an,{index:j||void 0,workId:f.id,transport:t,onNavigate:P}):null})]}):e.jsx(Qe,{transport:t,onNavigate:P,recommendedIds:o})});return a?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:_?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:B,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:D})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Xe,{transport:t,onEntryClick:L,hideModeIndicator:n}),!f&&e.jsx(Qe,{transport:t,onNavigate:P,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Xe,{transport:t,onEntryClick:L,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:D})]})};function Fe(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const jo=({data:t,onNavigate:n,className:r,style:o})=>{var f;const l=$(),{convert:i}=H(),[s,a]=u.useState(((f=t.divisions[0])==null?void 0:f.name)??null),[c,p]=u.useState(null);return e.jsxs("div",{className:r,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[l.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",l.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",l.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",l.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(So,{division:x,expanded:s===x.name,onToggle:()=>a(s===x.name?null:x.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},x.name))})]})},So=({division:t,expanded:n,onToggle:r,expandedCat:o,onCatToggle:l,onNavigate:i})=>{const{convert:s}=H(),a=t.categories.reduce((c,p)=>{const f=p.stats||{zhulu:0,cunmu:0};return c+(f.zhulu||0)+(f.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:r,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:s(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const p=`${t.name}/${c.name}`;return e.jsx(ko,{category:c,expanded:o===p,onToggle:()=>l(p),onNavigate:i},c.name)})})]})},ko=({category:t,expanded:n,onToggle:r,onNavigate:o})=>{var c,p,f,x;const{convert:l}=H(),i=((c=t.books)==null?void 0:c.zhulu)||[],s=((p=t.books)==null?void 0:p.cunmu)||[],a=(((f=t.stats)==null?void 0:f.zhulu)||i.length)+(((x=t.stats)==null?void 0:x.cunmu)||s.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:[l(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||s.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Tt,{label:"著錄",books:i,onNavigate:o}),s.length>0&&e.jsx(Tt,{label:"存目",books:s,onNavigate:o})]})]})},Tt=({label:t,books:n,onNavigate:r})=>{const{convert:o}=H(),l=re(),[i,s]=u.useState(n.length<=20),a=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map((c,p)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:c.work_id&&r?e.jsx("a",{href:l(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),r(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(c.title)}):o(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(c.author).slice(0,20)})]},p))}),!i&&e.jsxs("button",{onClick:()=>s(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},oe=({title:t,onSave:n,onAskAI:r,extraButtons:o,children:l})=>{const i=$();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,r&&e.jsx("button",{onClick:r,style:Co,children:"AI"}),n&&e.jsx("button",{onClick:n,style:wo,children:i.action.save})]})]}),l]})},wo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Co={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ee=({label:t,value:n,onChange:r,placeholder:o,disabled:l})=>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:l,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),he=({value:t,onChange:n,placeholder:r})=>{const o=u.useRef(null);return u.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:l=>n(l.target.value),placeholder:r,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Oe=({children:t,color:n,style:r})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...r},children:t});function _o(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const De=({value:t,onChange:n,label:r})=>{const[o,l]=u.useState(!1),i=u.useRef(null),s=_o(t||"");return u.useEffect(()=>{o&&i.current&&i.current.focus()},[o]),!o&&s?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Rt,children:r}),e.jsxs("div",{onClick:()=>l(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:s.name}),e.jsx(Oe,{children:s.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Rt,children:r}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:a=>n(a.target.value),onBlur:()=>l(!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"}})]})},Rt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function zo(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Io(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const dn=({items:t,onChange:n,onOpenEntityPicker:r})=>{const o=$(),[l,i]=u.useState(null),s=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},a=x=>{n(t.filter((h,d)=>d!==x)),l===x&&i(null)},c=(x,h,d)=>{const b=[...t];b[x]={...b[x],[h]:d},n(b)},p=(x,h)=>{const d=[...t];d[x]={...d[x],type:h,id:"",name:""},n(d),h==="bookID"&&r&&r(b=>{const S=[...t];S[x]={...S[x],id:b.id,name:b.title,type:"bookID"},n(S)})},f=x=>{r&&r(h=>{const d=[...t];d[x]={...d[x],id:h.id,name:h.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>i(l===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${o.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:zo(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Io(x.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),l===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Et,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>p(h,"url"),style:{...Et,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Lt,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>f(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>f(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Lt,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>c(h,"name",d.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:d=>c(h,"id",d.target.value),placeholder:"https://...",style:ye})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...pe,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>c(h,"details",d.target.value),placeholder:o.editor.detailsPlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:d=>c(h,"position",d.target.value),placeholder:"如: 卷三, p.52",style:ye})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:d=>c(h,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:d=>c(h,"processor_version",d.target.value),placeholder:"如: v0.1",style:ye})]})]})]})]})})]},h)),e.jsxs("button",{onClick:s,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ye={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Et={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"},Lt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function pn(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 xn(t){return!t||t.length===0?"":JSON.stringify(t)}const un=({entityType:t,entityId:n,entityTitle:r,parentWork:o,parentCollection:l,belongsToWork:i,belongsToCollection:s,childWorks:a,childCollections:c,containedBooks:p,siblingBooks:f,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:d,onCreateAndLink:b,onSaveRelations:S})=>{const g=$();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),S&&e.jsx("button",{onClick:S,style:To,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{direction:"up",title:g.relation.containedInCollection,entity:s,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),i&&f&&f.length>0&&e.jsx(ve,{direction:"horizontal",title:`${g.relation.siblingVersions} (${f.length})`,entities:f,onView:d,onAdd:()=>b("siblingBook","book",{workId:i.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.parentWork,entity:o,onView:d,onUnlink:()=>h("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),a&&a.length>0&&e.jsx(ve,{direction:"down",title:`${g.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),c&&c.length>0&&e.jsx(ve,{direction:"down",title:`${g.relation.collectionImpl} (${c.length})`,entities:c,onView:d,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(ve,{direction:"down",title:`${g.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>b("childBook","book",{workId:n}),addLabel:g.action.addVersion,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:r}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{direction:"up",title:g.relation.parentCollection,entity:l,onView:d,onUnlink:()=>h("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ve,{direction:"down",title:`${g.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:d,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(ve,{direction:"down",title:`${g.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},Ie=({direction:t,title:n,entity:r,onView:o,onUnlink:l,onLink:i,onCreate:s,linkLabel:a,createLabel:c,notLinkedLabel:p,viewLabel:f,unlinkLabel:x})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:d}),e.jsx("span",{children:n})]}),r?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:fn(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(Bt,{onClick:()=>o(r),title:f,children:"👁️"}),e.jsx(Bt,{onClick:l,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:p}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(et,{onClick:i,children:a}),e.jsx(et,{onClick:s,primary:!0,children:c})]})]})},ve=({direction:t,title:n,entities:r,onView:o,onAdd:l,addLabel:i,noneLabel:s,expandMoreLabel:a})=>{const[c,p]=u.useState(!1),f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=c?r:r.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),r.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>o(d),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:fn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),r.length>5&&!c&&e.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",r.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:s}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(et,{onClick:l,primary:!0,children:["+ ",i]})})]})},Bt=({onClick:t,title:n,danger:r,children:o})=>e.jsx("button",{onClick:l=>{l.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:r?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),et=({onClick:t,primary:n,children:r})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:r});function fn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const To={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},gn=({isOpen:t,entityType:n,title:r,onSelect:o,onCancel:l,onCreate:i,searchResults:s,onSearch:a,isLoading:c,excludeId:p})=>{const[f,x]=u.useState(""),h=p?s.filter(g=>g.id!==p):s;u.useEffect(()=>{t&&(x(""),a(""))},[t]);const d=g=>{x(g),a(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Ro,children:e.jsxs("div",{style:Eo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:r}),e.jsx("button",{onClick:l,style:Lo,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:f,onChange:g=>d(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Bo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Je,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>o(g),style:Wo,children:[e.jsx("span",{style:{fontSize:"16px"},children:S}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):f?e.jsxs("div",{style:Je,children:["未找到匹配的",b]}):e.jsxs("div",{style:Je,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:i,style:$o,children:["创建新",b,"并关联"]})]})]})})},Ro={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Eo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Lo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Bo={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Wo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Je={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},$o={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Wt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Po={work:"📜",book:"📖",collection:"📚",entity:"👤"},hn=({isOpen:t,entityType:n,relationField:r,inheritData:o,onConfirm:l,onCancel:i})=>{const[s,a]=u.useState(""),c=u.useRef(null);u.useEffect(()=>{t&&(a((o==null?void 0:o.title)||""),setTimeout(()=>{var h,d;(h=c.current)==null||h.focus(),(d=c.current)==null||d.select()},100))},[t,o==null?void 0:o.title]);const p=h=>{h.key==="Enter"&&s.trim()?f():h.key==="Escape"&&i()},f=()=>{s.trim()&&l(s.trim(),{...o,title:s.trim()})};if(!t)return null;const x=()=>{switch(r){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Wt[n]}`}};return e.jsx("div",{style:Ao,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Fo,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Po[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:c,type:"text",value:s,onChange:h=>a(h.target.value),onKeyDown:p,placeholder:`请输入${Wt[n]}名称...`,style:Mo})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:Do,children:"取消"}),e.jsx("button",{onClick:f,disabled:!s.trim(),style:{...Ho,opacity:s.trim()?1:.6,cursor:s.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Ao={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Fo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Mo={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},Do={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ho={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Oo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function bn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Uo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const mn=({isOpen:t,title:n,filterType:r="all",recentEntities:o=[],excludeId:l,showCreateButton:i=!1,createButtonText:s,onSelect:a,onCancel:c,onCreate:p,onSearch:f})=>{const[x,h]=u.useState(""),[d,b]=u.useState([]),[S,g]=u.useState(!1),[C,y]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),y(o.length>0?"recent":"search"))},[t,o.length]),u.useEffect(()=>{if(!x.trim()){b([]);return}const T=setTimeout(async()=>{g(!0);try{b(await f(x,r))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(T)},[x,r,f]);const v=u.useCallback(T=>{h(T.target.value),T.target.value.trim()&&y("search")},[]),j=u.useCallback(T=>l?T.filter(E=>E.id!==l):T,[l]);if(!t)return null;const z=n||(r==="all"?"选择实体":`选择${bn(r)}`),w=j(o),m=j(d);return e.jsx("div",{style:No,children:e.jsxs("div",{style:Ko,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:z}),e.jsx("button",{onClick:c,style:Yo,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Go}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),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($t,{active:C==="recent",onClick:()=>y("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs($t,{active:C==="search",onClick:()=>y("search"),children:["搜索结果 ",m.length>0&&`(${m.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:C==="recent"&&w.length>0?e.jsx(Pt,{entities:w,onSelect:a}):x.trim()?S?e.jsx(qe,{message:"搜索中..."}):m.length>0?e.jsx(Pt,{entities:m,onSelect:a}):e.jsx(qe,{message:"未找到匹配的结果"}):e.jsx(qe,{message:"输入关键词开始搜索"})}),i&&p&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:p,style:Jo,children:s||"创建新实体"})]})]})})},$t=({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}),Pt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(r=>e.jsx(Vo,{entity:r,onClick:()=>n(r)},r.id))}),Vo=({entity:t,onClick:n})=>{const[r,o]=u.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Oo(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Uo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:bn(t.type)})]})},qe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),No={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ko={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Yo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Go={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Jo={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},qo={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Zo={work:"📜",collection:"📚",book:"📖",entity:"👤"},yn=({data:t,onChange:n,onSave:r,transport:o,onNavigate:l,showDelete:i,onDelete:s,onAskAI:a,renderSectionActions:c,onDownloadResource:p,downloadStatuses:f,relations:x,onRelationsChange:h})=>{var te;const d=$(),[b,S]=u.useState(!1),[g,C]=u.useState("work"),[y,v]=u.useState(""),[j,z]=u.useState(""),[w,m]=u.useState([]),[T,E]=u.useState(!1),[L,P]=u.useState(!1),[W,_]=u.useState("work"),[B,D]=u.useState(""),[U,k]=u.useState(),[R,V]=u.useState(!1),[N,F]=u.useState(null),[le,Q]=u.useState([]);u.useRef(null);const de=t.type,fe=de==="work",ue=de==="collection",q=de==="book",K=u.useCallback((I,M)=>{n({...t,[I]:M})},[t,n]),Ve=u.useCallback((I,M)=>{v(I),C(M),z(d.editor.selectToLink+d.indexType[M]),m([]),S(!0)},[d]),Ne=u.useCallback(I=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,I)},[o,t.id]),ke=u.useCallback(I=>{l==null||l(I.id,I.type)},[l]),we=u.useCallback((I,M,J)=>{const se={...J,author:(J==null?void 0:J.author)||t.author,dynasty:(J==null?void 0:J.dynasty)||t.dynasty};_(M),D(I),k(se),P(!0)},[t.author,t.dynasty]),Ke=u.useCallback((I,M)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,B,{type:W,title:I,inheritData:M}),P(!1)},[o,t.id,B,W]),$e=u.useCallback(I=>{if(!I.trim()){m([]);return}E(!0),o!=null&&o.searchEntities&&o.searchEntities(I,g).then(M=>{m(M),E(!1)}).catch(()=>{m([]),E(!1)})},[o,g]),Ye=u.useCallback(I=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,I.id),S(!1)},[o,t.id,y]),A=u.useCallback(()=>{r()},[r]),Y=u.useCallback(I=>{F(()=>I),V(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(Q).catch(()=>{})},[o]),Z=u.useCallback((I,M)=>o!=null&&o.searchEntities?o.searchEntities(I,M==="all"?void 0:M):Promise.resolve([]),[o]),G=u.useCallback(I=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(I),Q(M=>[I,...M.filter(J=>J.id!==I.id)].slice(0,10)),N==null||N(I),V(!1),F(null)},[o,N]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Zo[de]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Oe,{children:t.id}),e.jsx(Oe,{color:qo[de],children:d.indexType[de]})]})}),e.jsx(oe,{title:d.section.basicInfo,onSave:r,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(De,{label:fe?d.editor.workTitle:ue?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:I=>K("title",I)}),q&&e.jsx(De,{label:d.editor.belongsToWork,value:t.workName||"",onChange:I=>K("workName",I)}),e.jsx(ee,{label:d.editor.authorLabel,value:t.author||"",onChange:I=>K("author",I)}),e.jsx(ee,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:I=>K("dynasty",I)}),(q||ue)&&e.jsx(De,{label:d.editor.containedIn,value:t.collection||"",onChange:I=>K("collection",I)}),(q||ue)&&e.jsx(ee,{label:d.editor.holderLabel,value:t.holder||"",onChange:I=>K("holder",I)}),(q||ue)&&e.jsx(ee,{label:q?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:I=>K("pages",I)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:I=>K("firstImage",I)})})]})}),e.jsx(oe,{title:d.section.description,onSave:r,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(he,{value:t.description||"",onChange:I=>K("description",I),placeholder:d.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(oe,{title:d.section.additionalWorks,onSave:r,children:e.jsx(Xo,{items:t.additional_works||[],onChange:I=>K("additional_works",I)})}),e.jsx(oe,{title:d.section.indexedBy,onSave:r,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(Qo,{items:t.indexed_by||[],onChange:I=>K("indexed_by",I)})}),e.jsx(oe,{title:d.section.emendatedBy,onSave:r,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(ei,{items:t.emendated_by||[],onChange:I=>K("emendated_by",I)})}),e.jsx(oe,{title:d.section.textResources,onSave:r,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Ze,{items:t.resources||[],onChange:I=>K("resources",I),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(oe,{title:d.section.imageResources,onSave:r,children:e.jsx(Ze,{items:t.resources||[],onChange:I=>K("resources",I),onDownload:p,downloadStatuses:f,filterType:"image"})}),e.jsx(oe,{title:d.section.sources,onSave:r,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(dn,{items:pn(t.sources||""),onChange:I=>K("sources",xn(I)),onOpenEntityPicker:Y})}),(q||ue)&&e.jsx(oe,{title:d.section.provenance,onSave:r,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(he,{value:t.provenance||"",onChange:I=>K("provenance",I),placeholder:d.editor.provenancePlaceholder})}),q&&e.jsx(oe,{title:d.section.otherEditions,onSave:r,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(he,{value:t.otherEditions||"",onChange:I=>K("otherEditions",I),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(un,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:Ve,onUnlinkEntity:Ne,onViewEntity:ke,onCreateAndLink:we,onSaveRelations:A}),i&&s&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick:s,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:d.editor.deleteEntity})]}),e.jsx(gn,{isOpen:b,entityType:g,title:j,onSelect:Ye,onCancel:()=>S(!1),onCreate:()=>{S(!1),we(y,g)},searchResults:w,onSearch:$e,isLoading:T,excludeId:t.id}),e.jsx(hn,{isOpen:L,entityType:W,relationField:B,inheritData:U,onConfirm:Ke,onCancel:()=>P(!1)}),e.jsx(mn,{isOpen:R,title:d.action.selectBookOrWork,filterType:"all",recentEntities:le,excludeId:t.id,onSelect:G,onCancel:()=>{V(!1),F(null)},onSearch:Z})]})};function Xo({items:t,onChange:n}){const r=$(),o=(s,a,c)=>{const p=t.map((f,x)=>x===s?{...f,[a]:c}:f);n(p)},l=s=>n(t.filter((a,c)=>c!==s)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ee,{label:r.editor.bookNameLabel,value:s.book_title,onChange:c=>o(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ee,{label:r.label.juanCount,value:s.n_juan!=null?String(s.n_juan):"",onChange:c=>o(a,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>l(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r.action.addAdditionalWork})]})}function vn({items:t,onChange:n,showMeta:r,addLabel:o}){const l=$(),[i,s]=u.useState(null),a=(f,x,h)=>{const d=t.map((b,S)=>S===f?{...b,[x]:h||void 0}:b);n(d)},c=f=>{n(t.filter((x,h)=>h!==f)),i===f&&s(null)},p=()=>{n([...t,{source:""}]),s(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,x)=>{const h=i===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>s(h?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:f.source||l.editor.unnamedSource}),f.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:f.source_bid}),e.jsx("button",{onClick:d=>{d.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&r&&(f.title_info||f.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[f.title_info,f.title_info&&f.author_info&&" — ",f.author_info]}),h&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:l.label.sourceName,value:f.source,onChange:d=>a(x,"source",d)}),e.jsx(ee,{label:l.label.sourceBid,value:f.source_bid||"",onChange:d=>a(x,"source_bid",d)})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:l.label.titleInfo,value:f.title_info||"",onChange:d=>a(x,"title_info",d)}),e.jsx(ee,{label:l.label.authorInfo,value:f.author_info||"",onChange:d=>a(x,"author_info",d)})]}),e.jsx(ee,{label:l.label.edition,value:f.edition||"",onChange:d=>a(x,"edition",d)})]}),e.jsx(he,{value:f.summary||"",onChange:d=>a(x,"summary",d),placeholder:l.editor.summaryPlaceholder}),e.jsx(he,{value:f.comment||"",onChange:d=>a(x,"comment",d),placeholder:l.editor.commentPlaceholder}),e.jsx(he,{value:f.additional_comment||"",onChange:d=>a(x,"additional_comment",d),placeholder:l.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o})]})}function Qo({items:t,onChange:n}){const r=$();return e.jsx(vn,{items:t,onChange:n,showMeta:!0,addLabel:r.action.addIndexedBy})}function ei({items:t,onChange:n}){const r=$();return e.jsx(vn,{items:t,onChange:n,addLabel:r.action.addEmendatedBy})}function jn(t){var a,c,p,f,x,h,d;const n=((c=(a=t.authors)==null?void 0:a[0])==null?void 0:c.name)||"",r=((p=t.publication_info)==null?void 0:p.year)||"",o=((f=t.current_location)==null?void 0:f.name)||"",l=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",s={id:t.id,title:t.title,type:t.type,author:n,dynasty:r,holder:o,pages:l,description:i,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const S=b.related_works.find(g=>g.relation==="part_of");S&&(s.parentWorkId=S.id,s.parentWorkName=S.title)}}if(t.type==="book"){const b=t;s.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(s.collectionId=(d=b.contained_in[0])==null?void 0:d.id)}return s}function ti(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const ni=t=>{const{data:n,id:r,transport:o,mode:l="view",onModeChange:i,onChange:s,onSave:a,onDelete:c,onNavigate:p,renderLink:f,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:S,onRelationsChange:g,headerExtra:C,className:y,style:v}=t;$();const[j,z]=u.useState(l),w=i?l:j;u.useEffect(()=>{l!==j&&z(l)},[l]);const m=u.useCallback(()=>{const B=w==="view"?"edit":"view";i?i(B):z(B)},[w,i]),[T,E]=u.useState(null);u.useEffect(()=>{r&&o&&o.getItem(r).then(B=>{B&&E(B)})},[r,o]);const L=n||T,P=u.useMemo(()=>L?jn(L):null,[L]),W=i||!n?e.jsx("button",{onClick:m,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background: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,_=e.jsxs(e.Fragment,{children:[W,C]});return!L&&!P?e.jsx(be,{}):w==="view"?e.jsx(nt,{data:L,transport:o,onNavigate:p?B=>p(B):void 0,renderLink:f,headerExtra:_,className:y,style:v}):P?e.jsxs("div",{className:y,style:v,children:[_&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:_}),e.jsx(yn,{data:P,onChange:s||(()=>{}),onSave:a||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:S,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},At=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Sn=({isOpen:t,onClose:n,onSubmit:r,feedbackListUrl:o})=>{const[l,i]=u.useState(null),[s,a]=u.useState(""),[c,p]=u.useState("idle"),[f,x]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(i(null),a(""),p("idle"),x(""))},[t]),u.useEffect(()=>{l&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[l]),u.useEffect(()=>{if(c==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[c,n]),u.useEffect(()=>{if(!t)return;const g=C=>{C.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const d=async()=>{if(!(!l||!s.trim())){p("submitting"),x("");try{await r({type:l,content:s.trim()}),p("success")}catch(g){p("error"),x(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=l&&s.trim()&&c!=="submitting",S=At.find(g=>g.value===l);return e.jsx("div",{style:ri,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:oi,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:ii,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:li,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:pi,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:At.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...si,...l===g.value?ai:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:s,onChange:g=>a(g.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!l||c==="submitting",style:{...ci,opacity:l?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),c==="error"&&e.jsx("div",{style:xi,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...di,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},ri={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},oi={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ii={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},li={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},si={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ai={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ci={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},di={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},pi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},xi={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ui=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:r})=>{const[o,l]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>l(!0),style:{...fi,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(Sn,{isOpen:o,onClose:()=>l(!1),onSubmit:t,feedbackListUrl:r})]})},fi={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Ft=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],gi=({onSubmit:t})=>{const[n,r]=u.useState("bug"),[o,l]=u.useState(""),[i,s]=u.useState("idle"),[a,c]=u.useState(""),p=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=p.current)==null?void 0:d.focus()},100)},[n]);const f=async()=>{if(!(!n||!o.trim())){s("submitting"),c("");try{await t({type:n,content:o.trim()}),s("success"),l(""),r("bug")}catch(d){s("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&o.trim()&&i!=="submitting",h=Ft.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Mt,children:e.jsxs("div",{style:vi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>s("idle"),style:ji,children:"继续提交"})]})}):e.jsxs("div",{style:Mt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ft.map(d=>e.jsxs("button",{onClick:()=>r(d.value),style:{...hi,...n===d.value?bi:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:p,value:o,onChange:d=>l(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...mi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[o.length," / 2000"]}),e.jsx("button",{onClick:f,disabled:!x,style:{...yi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Si,children:a})]})},Mt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},hi={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},bi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},mi={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},yi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},vi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},ji={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Si={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},ki=({style:t})=>{const n=u.useContext(Be);if(!n)return null;const{locale:r,setLocale:o}=n,l=r==="zh-Hant",i=()=>o(l?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,title:l?"切换为简体":"切換為繁體",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:l?"var(--bim-primary, #0078d4)":void 0,fontWeight:l?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:l?void 0:"var(--bim-primary, #0078d4)",fontWeight:l?400:700},children:"简"})]})};exports.BidLink=O.BidLink;exports.BookIndexError=O.BookIndexError;exports.BookIndexManager=O.BookIndexManager;exports.BookIndexStorage=O.BookIndexStorage;exports.BundleStorage=O.BundleStorage;exports.ConfigError=O.ConfigError;exports.GithubStorage=O.GithubStorage;exports.IdGenerationError=O.IdGenerationError;exports.IdGenerator=O.IdGenerator;exports.LocalStorage=O.LocalStorage;exports.MigrationError=O.MigrationError;exports.StorageError=O.StorageError;exports.base36Decode=O.base36Decode;exports.base36Encode=O.base36Encode;exports.base58Decode=O.base58Decode;exports.buildId=O.buildId;exports.decodeId=O.decodeId;exports.decodeIdString=O.decodeIdString;exports.encodeId=O.encodeId;exports.extractIdFromUrl=O.extractIdFromUrl;exports.extractStatus=O.extractStatus;exports.extractType=O.extractType;exports.normalizeCatalog=O.normalizeCatalog;exports.parseId=O.parseId;exports.smartDecode=O.smartDecode;exports.validateResource=O.validateResource;exports.Badge=Oe;exports.BidUrlProvider=En;exports.CollatedEdition=an;exports.CollectionCatalog=en;exports.CreateEntityDialog=hn;exports.EmendatedBySection=Xt;exports.EntityDetail=Yt;exports.EntityPickerDialog=mn;exports.EntitySelector=gn;exports.FeedbackButton=ui;exports.FeedbackDialog=Sn;exports.FeedbackForm=gi;exports.FeedbackList=cn;exports.FormInput=ee;exports.FormTextArea=he;exports.HomePage=Qe;exports.IndexApp=vo;exports.IndexBrowser=Xe;exports.IndexDetail=nt;exports.IndexEditor=yn;exports.IndexView=ni;exports.LocaleContext=Be;exports.LocaleProvider=Dn;exports.LocaleToggle=ki;exports.ModeIndicator=Nt;exports.RelationPanel=un;exports.ResourceEditor=Ze;exports.ResourceList=tt;exports.SearchInput=Kt;exports.Section=oe;exports.SmartBidInput=De;exports.SourceEditor=dn;exports.WorkCatalog=jo;exports.detailToEditor=jn;exports.editorToDetail=ti;exports.formatTemplate=We;exports.parseSourceString=pn;exports.stringifySources=xn;exports.useBidUrl=re;exports.useConvert=H;exports.useT=$;
1
+ "use strict";var wn=Object.create;var lt=Object.defineProperty;var Cn=Object.getOwnPropertyDescriptor;var _n=Object.getOwnPropertyNames;var zn=Object.getPrototypeOf,In=Object.prototype.hasOwnProperty;var Tn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of _n(n))!In.call(t,s)&&s!==o&&lt(t,s,{get:()=>n[s],enumerable:!(r=Cn(n,s))||r.enumerable});return t};var at=(t,n,o)=>(o=t!=null?wn(zn(t)):{},Tn(n||!t||!t.__esModule?lt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("./storage-entry-QB1IoDUU.cjs"),e=require("react/jsx-runtime"),u=require("react"),Rn=require("react-dom"),En=t=>`/book-index?id=${t}`,Ht=u.createContext(En);function Ln({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(Ht.Provider,{value:o,children:n})}function re(){return u.useContext(Ht)}function he(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Bn(t,n){return he(t).includes(n)}const Ot={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Wn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},$n={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Be=u.createContext(null),Ut={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Pn={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},An={"zh-Hant":Ut,"zh-Hans":Pn},Vt="bim-locale";function Fn(){try{const t=localStorage.getItem(Vt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Mn(t){try{localStorage.setItem(Vt,t)}catch{}}const Dn="zh-Hant",Hn=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??Dn),i=t??r;u.useEffect(()=>{if(t)return;const f=Fn();f&&f!==r&&s(f)},[]);const[l,a]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(f=>{const x=f.Converter({from:"tw",to:"cn"});a(()=>x)}).catch(()=>{a(()=>f=>f)}):a(null)},[i]);const c=u.useCallback(f=>{s(f),Mn(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:i,setLocale:c,messages:An[i],converter:l}),[i,c,l]);return e.jsx(Be.Provider,{value:p,children:o})};function W(){const t=u.useContext(Be);return(t==null?void 0:t.messages)??Ut}const On=2e3;function U(){const t=u.useContext(Be),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=u.useCallback(l=>{if(!l)return"";if(!o)return l;const a=r.current.get(l);if(a!==void 0)return a;const c=o(l);if(r.current.size>=On){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(l,c),c},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function We(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Un(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Vn(){return{id:"",name:"",url:"",type:"text",details:""}}const Ze=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=W(),[l,a]=u.useState(null),c=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],p=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],f=m=>{if(!s)return!0;const v=he(m);return s==="text"?v.includes("text"):s==="image"?v.includes("image")||v.includes("physical"):s==="physical"?v.includes("physical"):v.includes(s)},x=t.map((m,v)=>({item:m,originalIndex:v})).filter(({item:m})=>f(m)),h=()=>{const m=Vn();s&&(m.type=s),n([...t,m]),a(t.length)},d=m=>{n(t.filter((v,j)=>j!==m)),a(null)},b=(m,v,j)=>{const _=[...t];if(_[m]={..._[m],[v]:j},v==="url"&&!_[m].id){const k=Un(j);k&&(_[m].id=k)}n(_)},S=(m,v,j)=>{const k={...t[m].metadata||{}};j?k[v]=j:delete k[v],b(m,"metadata",Object.keys(k).length>0?k:void 0)},g=(m,v)=>{const j=v.trim()?v.split(/[,,、]/).map(_=>_.trim()).filter(Boolean):void 0;b(m,"structure",j)},w=(m,v,j)=>{const k=t[m].coverage||{level:1,ranges:""};v==="level"?k.level=parseInt(j)||1:k.ranges=j,b(m,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:v})=>{var j,_,k;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(l===v?null:v),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===v?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Nn(m.type??"text"),color:"#fff"},children:(()=>{var R,E;const y=he(m);return y.length===0?m.type??"text":y.length===1?((R=c.find(L=>L.value===y[0]))==null?void 0:R.label)??y[0]:y.includes("text")&&y.includes("image")?((E=c.find(L=>L.value==="text+image"))==null?void 0:E.label)??"text+image":y.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${v+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:y=>y.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Kn(v,r==null?void 0:r[v],o,i),e.jsx("button",{onClick:y=>{y.stopPropagation(),d(v)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===v&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Bn(m,"image")&&m.url&&Yn(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.type}),e.jsx("select",{value:m.type,onChange:y=>b(v,"type",y.target.value),style:{...de,flex:1},children:c.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value))})]}),e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:y=>b(v,"root_type",y.target.value),style:{...de,flex:1},children:p.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:y=>b(v,"id",y.target.value),placeholder:i.editor.idAutoExtract,style:{...de,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:y=>b(v,"name",y.target.value),placeholder:i.editor.resourceName,style:{...de,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:y=>b(v,"url",y.target.value),placeholder:i.editor.resourceUrl,style:de}),e.jsx("input",{type:"text",value:((j=m.structure)==null?void 0:j.join("、"))||"",onChange:y=>g(v,y.target.value),placeholder:i.editor.structurePlaceholder,style:de}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ce,children:[e.jsx("span",{style:_e,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((_=m.coverage)==null?void 0:_.level)??"",onChange:y=>w(v,"level",y.target.value),placeholder:"1",style:{...de,width:"60px"}})]}),e.jsxs("label",{style:{...Ce,flex:1},children:[e.jsx("span",{style:_e,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((k=m.coverage)==null?void 0:k.ranges)||"",onChange:y=>w(v,"ranges",y.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...de,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:y=>b(v,"details",y.target.value),placeholder:i.editor.detailsPlaceholder,style:{...de,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(i.metadata).map(([y,R])=>{var E;return e.jsxs("label",{style:{...Ce,gap:"4px"},children:[e.jsx("span",{style:{..._e,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[y])||"",onChange:L=>S(v,y,L.target.value),placeholder:R,style:{...de,flex:1}})]},y)})})]})]})]})]},v)}),e.jsxs("button",{onClick:h,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addResource})]})]})};function Nn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Kn(t,n,o,r){const s=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:l=>{l.stopPropagation(),s||o(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:i?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function Yn(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const de={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Ce={display:"flex",alignItems:"center",gap:"6px"},_e={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Gn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Jn(t){try{const n=new URL(t).hostname;return Gn[n]}catch{return}}const ct={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function qn(t){return t.includes("text")&&t.includes("image")?ct["text+image"]:ct[t[0]||"physical"]}const dt={text:0,image:1,physical:2};function Me(t){return t.length===0?"physical":[...t].sort((n,o)=>(dt[n]??99)-(dt[o]??99)).join("+")}function Zn(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const a=i.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const l=t[i];if(l.volumes&&l.volumes.length>0)continue;const a=n(l.name);if(!a)continue;const[c,p]=a,f=`${c}|${Me(he(l))}`;o.has(f)||o.set(f,{base:{...l,name:c,url:"",volumes:[]},volumes:[]}),o.get(f).volumes.push({volume:p,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,a)=>l.volume-a.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let l=0;l<t.length;l++)if(s.has(l)){const a=n(t[l].name),c=a&&`${a[0]}|${Me(he(t[l]))}`,p=`${i.base.name}|${Me(he(i.base))}`;c===p&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const tt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=W(),i=u.useMemo(()=>Zn(t||[]),[t]),l={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},a=x=>l[x]?l[x]:x.split("+").map(h=>l[h]||h).join("+");if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:i.map((x,h)=>e.jsx(xt,{item:x},x.id||h))});const c=new Map;for(const x of i){const h=Me(he(x));c.has(h)||c.set(h,[]),c.get(h).push(x)}const p=["text","image","text+image","physical"],f=[...p.filter(x=>c.has(x)),...[...c.keys()].filter(x=>!p.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:f.map(x=>{const h=c.get(x),d=qn(x.split("+"));return e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:d,display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:d}}),a(x),e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",h.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:h.map((b,S)=>e.jsx(xt,{item:b,onNavigate:o,renderLink:r},b.id||S))})]},x)})})},pt=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},Nt=({value:t})=>{const o=W().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},Xn=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Nt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const s=String(n);return r?r(s):s};function Qn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const s=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(s)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(s[1]))}&page=${n}`;const i=new URL(t);return i.searchParams.set("page",String(n)),i.toString()}return t}catch{return t}}function eo(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function to(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const no={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},xt=({item:t,onNavigate:n,renderLink:o})=>{var S;const r=W(),{convert:s}=U(),i=re(),[l,a]=u.useState(!1),c=u.useMemo(()=>(t.url?Jn(t.url):void 0)||s(t.name),[t.url,t.name,s]),p=u.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(g=>({...g,url:g.url||to(g)})),[t.volumes]),f=p&&p.length>0,x=f?new Set(p.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,h=f?new Set(p.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,d=t.expected_volumes??(f?x+h:0),b=t.color_mode?{...no[t.color_mode],label:r.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:pt(t)||f?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c}),b&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:b.bg,color:b.fg},children:b.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((S=t.metadata)==null?void 0:S.check_type)&&e.jsx(Nt,{value:t.metadata.check_type}),f&&e.jsxs("span",{style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)"},children:[x,"/",d,r.unit.volume,h>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",h]})]}),t.url&&e.jsx("a",{href:(()=>{const g=eo(t.metadata);return g?Qn(t.url,g):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:r.action.visit}),f&&e.jsx("button",{onClick:()=>a(!l),title:l?"收起分册":"展开分册",style:{marginLeft:"auto",padding:"1px 10px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:l?"var(--bim-widget-border, #e0e0e0)":"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",lineHeight:1.4},children:l?"收起 ▲":"展开 ▼"})]}),pt(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([g])=>g!=="check_type").map(([g,w])=>e.jsxs("span",{children:[r.metadata[g]||g,": ",Xn(g,w,r,s)]},g)),t.details&&!f&&e.jsx("span",{children:s(t.details)}),t.structure&&e.jsxs("span",{children:[r.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[r.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),f&&l&&(()=>{const g=p.some(v=>v.group),w=[];if(g){let v=null;for(const j of p){const _=j.group||"";(!v||v.title!==_)&&(v={title:_,group_id:j.group_id,vols:[]},w.push(v)),v.vols.push(j)}}else w.push({vols:p});const m=v=>{const j=v.status==="missing";return v.url&&!j?e.jsx("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:v.label||`${v.volume}`,children:v.volume},v.volume):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:j?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:j?"line-through":"none",opacity:j?.6:1,lineHeight:1.4},children:v.volume},v.volume)};return e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexDirection:"column",gap:"8px"},children:w.map((v,j)=>{const _=v.title?s(v.title):"";let k=_;return v.title&&v.group_id&&(o?k=o(v.group_id,_):n&&(k=e.jsx("a",{href:i(v.group_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),n(v.group_id))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:y=>y.currentTarget.style.borderBottomStyle="solid",onMouseLeave:y=>y.currentTarget.style.borderBottomStyle="dashed",children:_}))),e.jsxs("div",{children:[v.title&&e.jsxs("div",{style:{fontSize:"12px",fontWeight:500,color:"var(--bim-fg, #333)",marginBottom:"4px"},children:[k,e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",v.vols.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px"},children:v.vols.map(m)})]},j)})})})()]})},Kt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const a=W(),c=t==="local",p=(n==null?void 0:n.isDraft)??!0,f=(n==null?void 0:n.repoPath)||"",x=f?f.split(/[/\\]/).pop()||f:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},d={onMouseOver:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:p?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:p?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:p?"📝":"📚"}),e.jsx("span",{children:p?"draft":"official"})]});return o==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:h,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:f||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:x||a.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:c?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:l,title:f||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:f?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!c&&x&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:f,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Ue="bim-search-history",ut=10,ft=8;function Te(){try{const t=localStorage.getItem(Ue);return t?JSON.parse(t):[]}catch{return[]}}function oo(t){try{const n=Te().filter(o=>o!==t);n.unshift(t),n.length>ut&&(n.length=ut),localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function ro(t){try{const n=Te().filter(o=>o!==t);localStorage.setItem(Ue,JSON.stringify(n))}catch{}}function io(){try{localStorage.removeItem(Ue)}catch{}}const Yt=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=W(),a=i??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,f]=u.useState(!1),[x,h]=u.useState([]),[d,b]=u.useState(-1),[S,g]=u.useState(null),[w,m]=u.useState(Te),v=u.useRef(null),j=u.useRef(null),_=u.useRef(null),k=u.useRef(!1),y=u.useCallback(()=>{k.current||!t.getAllEntries||(k.current=!0,t.getAllEntries().then(z=>{g(z)}).catch(()=>{k.current=!1}))},[t]),R=u.useCallback(z=>{if(!z.trim())return w.map($=>({type:"history",text:$}));if(!S)return[];const F=z.toLowerCase(),C=[],I=[];for(const $ of S){if(C.length+I.length>=ft*2)break;const K=($.title??"").toLowerCase();if(K.startsWith(F))C.push({type:"entry",text:$.title,entry:$});else if(K.includes(F))I.push({type:"entry",text:$.title,entry:$});else{const D=[...$.additional_titles||[],...$.attached_texts||[]];for(const q of D){const Z=typeof q=="string"?q:q==null?void 0:q.book_title;if(Z!=null&&Z.toLowerCase().includes(F)){C.push({type:"entry",text:`${$.title}`,entry:$});break}}}}return[...C,...I].slice(0,ft)},[S,w]);u.useEffect(()=>{h(R(n)),b(-1)},[n,R]),u.useEffect(()=>{const z=F=>{_.current&&!_.current.contains(F.target)&&f(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),u.useEffect(()=>{const z=F=>{var C,I;if(F.key==="/"&&document.activeElement!==v.current){const $=(C=document.activeElement)==null?void 0:C.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;F.preventDefault(),(I=v.current)==null||I.focus()}};return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[]);const E=u.useCallback(z=>{z.trim()&&(oo(z.trim()),m(Te())),r(z),f(!1)},[r]),L=u.useCallback(z=>{z.type==="history"?(o(z.text),E(z.text)):z.entry&&(s?(s(z.entry),f(!1)):(o(z.text),E(z.text)))},[o,E,s]),A=u.useCallback(z=>{if(!p||x.length===0){z.key==="Enter"&&E(n);return}switch(z.key){case"ArrowDown":z.preventDefault(),b(F=>(F+1)%x.length);break;case"ArrowUp":z.preventDefault(),b(F=>(F-1+x.length)%x.length);break;case"Enter":z.preventDefault(),d>=0&&d<x.length?L(x[d]):E(n);break;case"Escape":z.preventDefault(),f(!1);break}},[p,x,d,n,E,L]),B=u.useCallback((z,F)=>{F.stopPropagation(),ro(z),m(Te()),h(C=>C.filter(I=>!(I.type==="history"&&I.text===z)))},[]),H=u.useCallback(z=>{z.stopPropagation(),io(),m([]),h([])},[]);u.useEffect(()=>{if(d>=0&&j.current){const z=j.current.children;z[d]&&z[d].scrollIntoView({block:"nearest"})}},[d]);const M=!n.trim()&&w.length>0;return e.jsxs("div",{ref:_,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:a,value:n,onChange:z=>{o(z.target.value),f(!0),y()},onFocus:()=>{f(!0),y()},onKeyDown:A,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),p&&x.length>0&&e.jsxs("div",{ref:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[M&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:H,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((z,F)=>e.jsxs("div",{onClick:()=>L(z),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:F===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:z.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.text}),z.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[z.entry.type],z.entry.edition&&` · ${z.entry.edition}`,z.entry.author&&` · ${z.entry.author}`]}),z.type==="history"&&e.jsx("button",{onClick:C=>B(z.text,C),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${z.type}-${z.text}-${F}`))]})]})},Le="bim-recent-ids",gt="bim-recent-entries",ht=50,Ge=5,so=50,lo=200;function Re(){try{const t=localStorage.getItem(Le);if(t)return JSON.parse(t);const n=localStorage.getItem(gt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Le,JSON.stringify(o)),localStorage.removeItem(gt),o}return[]}catch{return[]}}function ao(t){try{const n=Re().filter(o=>o!==t);n.unshift(t),n.length>ht&&(n.length=ht),localStorage.setItem(Le,JSON.stringify(n))}catch{}}function co(t){try{const n=Re().filter(o=>o!==t);localStorage.setItem(Le,JSON.stringify(n))}catch{}}function po(){try{localStorage.removeItem(Le)}catch{}}const xo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xe=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:p,initialQuery:f,onQueryChange:x,headerRight:h})=>{const d=W(),b=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:d.indexType.entity,key:"entities"}],[S,g]=u.useState(f??""),[w,m]=u.useState(null),[v,j]=u.useState(null),[_,k]=u.useState(!1),[y,R]=u.useState(null),[E,L]=u.useState(""),[A,B]=u.useState(!f),[H,M]=u.useState(Re),[z,F]=u.useState([]),[C,I]=u.useState(!1),[$,K]=u.useState(!1),[D,q]=u.useState(null),[Z,le]=u.useState(null),ge=u.useRef(void 0),fe=u.useRef(!1),X=u.useCallback(async(P,G)=>{if(!P.trim()){B(!0),m(null),j(null);return}B(!1),k(!0),L("");try{if(t.searchAll){const N=await t.searchAll(P,G??Ge);m(N)}else{const N=["work","book","collection","entity"],Y=await Promise.all(N.map(Q=>t.search(P,Q,{page:1,pageSize:G??Ge})));m({works:Y[0].entries,books:Y[1].entries,collections:Y[2].entries,entities:Y[3].entries,totalWorks:Y[0].total,totalBooks:Y[1].total,totalCollections:Y[2].total,totalEntities:Y[3].total})}}catch(N){L(N instanceof Error?N.message:String(N)),m(null)}finally{k(!1)}},[t]);u.useEffect(()=>{let P=!1;const G=()=>{var O,te;const N=["work","book","collection","entity"],Y=Promise.all(N.map(ae=>t.loadEntries(ae,{page:1,pageSize:1}).catch(()=>({total:0})))),Q=((O=t.getResourceCounts)==null?void 0:O.call(t).catch(()=>null))??Promise.resolve(null),T=((te=t.getSubtypeStats)==null?void 0:te.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([Y,Q,T]).then(([ae,ce,st])=>{P||(q({works:ae[0].total,books:ae[1].total,collections:ae[2].total,entities:ae[3].total,hasText:ce==null?void 0:ce.hasText,hasImage:ce==null?void 0:ce.hasImage}),st&&le(st))})};return t.getCounts?t.getCounts().then(N=>{var Y,Q;P||(q({works:N.works,books:N.books,collections:N.collections,entities:N.entities,hasText:(Y=N.resourceCounts)==null?void 0:Y.hasText,hasImage:(Q=N.resourceCounts)==null?void 0:Q.hasImage}),N.subtypeStats&&le(N.subtypeStats))}).catch(()=>{P||G()}):G(),()=>{P=!0}},[t]),u.useEffect(()=>{fe.current||!(f!=null&&f.trim())||(fe.current=!0,X(f))},[f,X]);const J=u.useCallback(P=>{if(g(P),x==null||x(P),!P.trim()){B(!0),m(null),j(null);return}ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>{j(null),X(P)},lo)},[X,x]),Ve=u.useCallback(P=>{ge.current&&clearTimeout(ge.current),x==null||x(P),X(P)},[X,x]),Ne=u.useCallback(P=>{j(P),X(S,so)},[S,X]);u.useEffect(()=>{if(!H.length){F([]);return}let P=!1;return I(!0),Promise.all(H.slice(0,10).map(async G=>{var N,Y,Q;try{if(t.getEntry){const O=await t.getEntry(G);if(O)return O}const T=await t.getItem(G);if(T){const O=T.authors;return{id:G,title:T.title||G,type:T.type||"work",author:(N=O==null?void 0:O[0])==null?void 0:N.name,dynasty:(Y=O==null?void 0:O[0])==null?void 0:Y.dynasty,role:(Q=O==null?void 0:O[0])==null?void 0:Q.role,edition:T.edition||void 0}}}catch{}return{id:G,title:G,type:"work",notFound:!0}})).then(G=>{P||(F(G),I(!1))}),()=>{P=!0}},[H,t]);const ke=P=>{R(P.id),ao(P.id),M(Re()),r==null||r(P)},we=P=>{co(P),M(Re())},Ke=()=>{po(),M([])},$e=P=>b.find(G=>G.type===P),Ye=w&&(w.works.length>0||w.books.length>0||w.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!p&&e.jsx(Kt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Yt,{transport:t,value:S,onChange:J,onSearch:Ve,onEntrySelect:ke}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:d.action.newEntry})]}),D&&A&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.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:D.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.collections.toLocaleString()}),D.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.entities.toLocaleString()})]})]})}),D.hasImage!=null&&D.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:D.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:_?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):E?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:E})]}):A?e.jsx("div",{style:{flex:1},children:C?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):z.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:d.search.recentBrowse}),e.jsx("button",{onClick:Ke,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:d.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:z.slice(0,$?10:3).map(P=>P.notFound?e.jsx(uo,{id:P.id,onRemove:we,t:d},P.id):e.jsx(bt,{entry:P,selected:y===P.id,onClick:ke,getConfig:$e,onRemove:we},P.id))}),!$&&z.length>3&&e.jsx("button",{onClick:()=>K(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:d.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Ye?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:P,icon:G,name:N,key:Y})=>{const Q=w[Y]??[],T=xo[Y],O=w[T]??0;if(Q.length===0)return null;const ae=!(v===P)&&O>Ge;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[G," ",N,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[O," ",d.unit.items]})]}),ae&&e.jsx("button",{onClick:()=>Ne(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(ce=>e.jsx(bt,{entry:ce,selected:y===ce.id,onClick:ke,getConfig:$e,query:S},ce.id))})]},P)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:We(d.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},bt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=W(),{convert:a}=U(),c=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&c.length?c.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:a(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),p&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",a(p)]})]}),i?e.jsx("button",{onClick:f=>{f.stopPropagation(),i(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},uo=({id:t,onRemove:n,t:o})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function fo(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function go({data:t}){const{convert:n}=U(),{dynasty:o,birth_year:r,death_year:s}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?i.push(`${r}—${s}`):r!==void 0?i.push(`${r}—?`):s!==void 0&&i.push(`?—${s}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function ho({alt_names:t}){const{convert:n}=U(),o=new Map;for(const i of t){const l=i.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,l)=>{const a=r.indexOf(i),c=r.indexOf(l);return a===-1&&c===-1?0:a===-1?1:c===-1?-1:a-c});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const l=o.get(i);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:i}),e.jsx("span",{children:l.map((a,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(a)]},c))})]},i)})})}function bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function mo({works:t,transport:n,onNavigate:o,renderLink:r}){const s=W(),{convert:i}=U(),l=re(),[a,c]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const d=t.map(S=>S.work_id);return(async()=>{const S=new Map;if(n.getEntriesByIds)try{const v=await n.getEntriesByIds(d);let j=!0;for(let _=0;_<d.length;_++){const k=v[_];k!=null&&k.title?S.set(d[_],k.title):k!=null&&k.primary_name?S.set(d[_],k.primary_name):j=!1}if(j)return S}catch{}if(n.getAllEntries)try{const v=await n.getAllEntries(),j=new Map(v.map(k=>[k.id,k.title||k.primary_name||k.id]));let _=!0;for(const k of d){const y=j.get(k);y?S.set(k,y):_=!1}if(_)return S}catch{}const g=[...d],w=8,m=new Array(w).fill(0).map(async()=>{for(;g.length;){const v=g.shift();if(!v)break;if(!S.has(v))try{if(n.getEntry){const k=await n.getEntry(v);if(k!=null&&k.title){S.set(v,k.title);continue}}const j=await n.getItem(v),_=j&&(j.title||j.primary_name)||v;S.set(v,_)}catch{S.set(v,v)}}});return await Promise.all(m),S})().then(S=>{h||c(S)}),()=>{h=!0}},[t,n]);const p=new Map;for(const h of t){const d=h.role||"";p.has(d)||p.set(d,[]),p.get(d).push(h)}const f=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...p.keys()].sort((h,d)=>{const b=f.indexOf(h),S=f.indexOf(d);return b===-1&&S===-1?h.localeCompare(d):b===-1?1:S===-1?-1:b-S});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(h=>{const d=p.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",d.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:d.map((b,S)=>{const g=i(a.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,g)},S):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},S):e.jsx("li",{children:g},S)})})]},h)})]})}const Gt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var f;const i=W(),{convert:l}=U();let a=!1;try{a=V.extractStatus(t.id)==="draft"}catch{}const c=fo(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[l(t.primary_name),e.jsx(go,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:i.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),c&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(ho,{alt_names:t.alt_names}),e.jsx(bo,{data:t}),((f=t.description)==null?void 0:f.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:l(t.description.text)}),t.works&&t.works.length>0&&e.jsx(mo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},yo=["〇","一","二","三","四","五","六","七","八","九"],mt=["","十","百","千"];function Jt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",s=!1;for(let i=0;i<o;i++){const l=parseInt(n[i]),a=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&a===1&&i===0?r+=mt[a]:r+=yo[l]+mt[a])}return r}function qt({type:t}){const n=W(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function vo({isDraft:t}){const n=W();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function jo({id:t}){const n=W(),[o,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function oe({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function pe({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function Zt({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=U();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const a=s(i.name),c=i.entity_id?e.jsx(se,{id:i.entity_id,label:a,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:a});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),c,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},l)})})}function se({id:t,label:n,onNavigate:o,renderLink:r}){const s=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function So({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:a,headerExtra:c,onNavigate:p,renderLink:f}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(qt,{type:r}),e.jsx(vo,{isDraft:s}),e.jsx(jo,{id:t})]}),((i==null?void 0:i.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(Zt,{authors:i,type:r,onNavigate:p,renderLink:f}),a]})]})}function Xt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=W(),{convert:l}=U();if(!t.length)return null;const[a,c]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((p,f)=>{const x=a===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(x?null:f),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(p.source)}),!x&&o&&p.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(p.title_info)}),p.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(se,{id:p.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(p.title_info||p.author_info||p.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[p.title_info&&e.jsx(pe,{label:i.label.titleInfo,children:l(p.title_info)}),p.author_info&&e.jsx(pe,{label:i.label.authorInfo,children:l(p.author_info)}),p.edition&&e.jsx(pe,{label:i.label.edition,children:l(p.edition)})]}),p.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(p.summary)})]}),p.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.comment)})]}),p.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.additional_comment)})]})]})]},f)})})]})}function ko({items:t,onNavigate:n,renderLink:o}){const r=W();return e.jsx(Xt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Qt({items:t,onNavigate:n,renderLink:o}){const r=W();return e.jsx(Xt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function en({label:t,items:n}){const{convert:o}=U();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const i=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},s)})})]}):null}function wo({items:t}){const n=W();return e.jsx(en,{label:n.section.aliases,items:t})}function Co({items:t}){const n=W();return e.jsx(en,{label:n.section.attachedTexts,items:t})}function _o({items:t}){const n=W(),{convert:o}=U();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function zo({items:t}){const n=W(),{convert:o}=U();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Io({items:t}){const n=W(),{convert:o}=U();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},s))})]}):null}function yt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=U(),[l,a]=u.useState([]);return u.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>o.getItem(p).then(f=>({id:p,title:f?f.title:void 0,edition:f?f.edition:void 0,type:f?f.type:void 0})).catch(()=>({id:p})))).then(p=>{c||a(p)}),()=>{c=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(oe,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(c=>({id:c}))).map(c=>{const p=c.edition?`${i(c.title)||c.id}(${i(c.edition)})`:i(c.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(se,{id:c.id,label:p,onNavigate:r,renderLink:s})},c.id)})})]}):null}function To({book:t,onNavigate:n,renderLink:o}){const r=W(),{convert:s}=U(),[i,l]=u.useState(!1),a=t.resources&&t.resources.length>0,c=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:a&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(se,{id:t.id,label:c,onNavigate:n,renderLink:o})}),a&&e.jsx("span",{onClick:()=>l(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?r.action.expand:r.action.collapse,children:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(tt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ro({ids:t,transport:n,onNavigate:o,renderLink:r}){const s=W(),[i,l]=u.useState([]);return u.useEffect(()=>{if(!t.length){l([]);return}if(!n){l(t.map(c=>({id:c})));return}let a=!1;return Promise.all(t.map(c=>n.getItem(c).then(p=>({id:c,title:p?p.title:void 0,edition:p?p.edition:void 0,resources:p?p.resources:void 0})).catch(()=>({id:c})))).then(c=>{a||l(c)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(oe,{children:[s.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(i.length?i:t.map(a=>({id:a}))).map(a=>e.jsx(To,{book:a,onNavigate:o,renderLink:r},a.id))})]}):null}function Eo({workData:t,onNavigate:n,renderLink:o}){var i,l,a;const r=W(),{convert:s}=U();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(qt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(se,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((i=t.juan_count)==null?void 0:i.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Jt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(Zt,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((l=t.description)==null?void 0:l.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:s(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(pe,{label:r.label.parentWork,children:e.jsx(se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Lo({items:t,onNavigate:n,renderLink:o}){const r=W(),{convert:s}=U();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(se,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:o}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:We(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const nt=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,className:l,style:a})=>{var A,B,H,M,z,F;const c=W(),{convert:p}=U(),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState(null),[g,w]=u.useState(null),[m,v]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let C=!1;return d(!0),S(null),o.getItem(n).then(I=>{C||(I?x(I):S(c.misc.notFoundEntry))}).catch(I=>{C||S(I instanceof Error?I.message:c.misc.loadFailed)}).finally(()=>{C||d(!1)}),()=>{C=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){w(null),v([]);return}let C=!1;const I=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(I?o.getItem(I).then($=>{!C&&$&&$.type==="work"&&w($)}).catch(()=>{}):w(null),j.type==="book"){const $=j;$.contained_in&&$.contained_in.length>0?Promise.all($.contained_in.map(K=>{const D=typeof K=="string"?K:K.id,q=typeof K=="string"?void 0:K.volume_index;return o.getItem(D).then(Z=>({id:D,title:Z&&Z.title||D,volume_index:q})).catch(()=>({id:D,title:D,volume_index:q}))})).then(K=>{C||v(K)}):v([])}else v([]);return()=>{C=!0}},[j,o]),h)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((C,I)=>e.jsx("div",{style:{height:I===1?"32px":"16px",width:`${C}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},I))})});if(b)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:b});if(!j)return null;if(j.type==="entity")return e.jsx("div",{className:l,style:a,children:e.jsx(Gt,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const _=j.type==="book"?j:null,k=j.type==="collection"?j:null,y=j.type==="work"?j:null;let R=!1;try{R=V.extractStatus(j.id)==="draft"}catch{}let E="";j.measure_info?E=p(j.measure_info):(A=j.juan_count)!=null&&A.number?E=Jt(j.juan_count.number)+c.unit.juan:(B=j.juan_count)!=null&&B.description&&(E=p(j.juan_count.description));const L=[];return(H=j.publication_info)!=null&&H.year&&L.push(e.jsx(pe,{label:c.label.year,children:j.publication_info.year},"year")),(M=j.current_location)!=null&&M.name&&L.push(e.jsx(pe,{label:c.label.currentLocation,children:p(j.current_location.name)},"loc")),(z=j.page_count)!=null&&z.description&&L.push(e.jsx(pe,{label:c.label.pageCount,children:j.page_count.description},"page")),_!=null&&_.edition&&L.push(e.jsx(pe,{label:c.label.edition,children:p(_.edition)},"ver")),y!=null&&y.parent_work&&L.push(e.jsx(pe,{label:c.label.parentWork,children:e.jsx(se,{id:y.parent_work.id,label:p(y.parent_work.title),onNavigate:r,renderLink:s})},"pw")),y!=null&&y.parent_works&&y.parent_works.length>0&&!y.parent_work&&L.push(e.jsx(pe,{label:c.label.parentWork,children:y.parent_works.map((C,I)=>e.jsxs("span",{children:[I>0&&"、",e.jsx(se,{id:C,onNavigate:r,renderLink:s})]},C))},"pws")),e.jsxs("div",{className:l,style:a,children:[e.jsx(So,{id:j.id,title:p(j.title),edition:j.edition?p(j.edition):void 0,type:j.type,isDraft:R,authors:j.authors,volumeText:E,meta:L,headerExtra:i,onNavigate:r,renderLink:s}),((F=j.description)==null?void 0:F.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:p(j.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:c.section.containedIn}),e.jsx(Lo,{items:m,onNavigate:r,renderLink:s})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:c.section.belongsToWork}),e.jsx(Eo,{workData:g,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(_o,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(wo,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Co,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(ko,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Qt,{items:j.emendated_by,onNavigate:r,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{children:c.section.resources}),e.jsx(tt,{items:j.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(_==null?void 0:_.location_history)&&_.location_history.length>0&&e.jsx(zo,{items:_.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(Io,{items:k.history}),(_==null?void 0:_.related_books)&&_.related_books.length>0&&e.jsx(yt,{title:c.section.relatedVersions,ids:_.related_books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(yt,{title:c.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(oe,{children:[c.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(C=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(se,{id:C.id,label:p(C.title),onNavigate:r,renderLink:s})},C.id))})]}),(y==null?void 0:y.books)&&y.books.length>0&&e.jsx(Ro,{ids:y.books,transport:o,onNavigate:r,renderLink:s}),(y==null?void 0:y.related_works)&&y.related_works.length>0&&(()=>{const C=[],I=y.related_works.filter(D=>D.relation==="part_of"),$=y.related_works.filter(D=>D.relation==="has_part"),K=y.related_works.filter(D=>!D.relation);return I.length>0&&C.push({label:c.section.belongsToWork,items:I}),$.length>0&&C.push({label:c.section.containedWorks,items:$}),K.length>0&&C.push({label:c.section.relatedWorks,items:K}),C.map(D=>e.jsxs("div",{children:[e.jsxs(oe,{children:[D.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",D.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:D.items.map(q=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(se,{id:q.id,label:p(q.title),onNavigate:r,renderLink:s})},q.id))})]},D.label))})()]})};function Bo({data:t}){const n=W(),{convert:o}=U(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,i=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),i!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",i,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Wo({sections:t,activeSection:n,onSelect:o}){const r=W();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:vt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:vt(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function vt(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function $o({id:t,label:n,onNavigate:o,renderLink:r}){const s=re();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Po(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function jt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=W(),{convert:i}=U(),l=t.book_id||t.work_id,a=r&&t.volumes.length>0?Po(t.volumes,s.unit.volume):null,c=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(p=>i(p)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:c?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx($o,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const tn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const a=W(),[c,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[b,S]=u.useState(null),[g,w]=u.useState(""),m=t||c;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let y=!1;return x(!0),d(null),o.getCollectionCatalog(n).then(R=>{y||(R?p(R):d(a.catalog.notFound))}).catch(R=>{y||d(R instanceof Error?R.message:a.catalog.loadFailed)}).finally(()=>{y||x(!1)}),()=>{y=!0}},[t,n,o,a]);const v=(m==null?void 0:m.sections)&&m.sections.length>0,j=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const y=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(y).size<y.length},[m]),_=u.useMemo(()=>{if(!m)return[];let y=m.books;if(b&&(y=y.filter(R=>R.section===b)),g.trim()){const R=g.trim().toLowerCase();y=y.filter(E=>E.title.toLowerCase().includes(R)||E.sub_items&&E.sub_items.some(L=>L.toLowerCase().includes(R))||E.edition&&E.edition.toLowerCase().includes(R))}return y},[m,b,g]),k=u.useMemo(()=>{if(!j)return null;const y=[],R=new Map;for(const L of _){if(!L.volumes||L.volumes.length===0)continue;const A=L.volumes[0];R.has(A)||R.set(A,[]),R.get(A).push(L)}const E=[...R.keys()].sort((L,A)=>L-A);for(const L of E)y.push({volume:L,books:R.get(L)});return y},[_,j]);return f?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):h?e.jsx("div",{className:i,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:i,style:l,children:[e.jsx(Bo,{data:m}),v&&e.jsx(Wo,{sections:m.sections,activeSection:b,onSelect:S}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:g,onChange:y=>w(y.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[_.length," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((y,R)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:We(a.catalog.volume,{n:y.volume})}),y.books.map((E,L)=>e.jsx(jt,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${y.volume}-${L}`))]},`${y.volume}-${R}`)):_.map((y,R)=>e.jsx(jt,{book:y,onNavigate:r,renderLink:s,showVolumes:!0},R)),_.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},me=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},ee=6,Pe=7,Ao=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,a]=u.useState(!1),[c,p]=u.useState(null),f=u.useRef(null),x=u.useRef(null),h=u.useRef(null),d=u.useCallback(()=>{const g=x.current,w=h.current;if(!g||!w)return;const m=g.getBoundingClientRect(),v=w.getBoundingClientRect(),j=window.innerHeight,_=document.documentElement.clientWidth;let k=o;o==="top"&&m.top-v.height-Pe<8&&(k="bottom"),o==="bottom"&&m.bottom+v.height+Pe>j-8&&(k="top");const y=k==="top"?m.top-v.height-Pe:m.bottom+Pe;let R=m.left+m.width/2-v.width/2;R=Math.max(8,Math.min(R,_-v.width-8)),p({left:R,top:y,placement:k})},[o]),b=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>a(!0),r)},[r]),S=u.useCallback(()=>{f.current&&clearTimeout(f.current),a(!1),p(null)},[]);return u.useEffect(()=>{if(!l)return;const g=requestAnimationFrame(d);return()=>cancelAnimationFrame(g)},[l,d]),u.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:b,onMouseLeave:S,onFocus:b,onBlur:S,style:{display:"inline-block",...i},children:n}),l&&Rn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(c==null?void 0:c.left)??-9999,top:(c==null?void 0:c.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:c?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-ee,width:0,height:0,...c.placement==="top"?{bottom:-ee,borderTop:`${ee}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ee}px solid transparent`,borderRight:`${ee}px solid transparent`}:{top:-ee,borderBottom:`${ee}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ee}px solid transparent`,borderRight:`${ee}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...c.placement==="top"?{bottom:-5,borderTop:`${ee-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ee-1}px solid transparent`,borderRight:`${ee-1}px solid transparent`}:{top:-5,borderBottom:`${ee-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ee-1}px solid transparent`,borderRight:`${ee-1}px solid transparent`}}})]})]}),document.body)]})},St={A:"fine",B:"rough",C:"rough",D:"ocr"};function Fo(t){return typeof t!="string"?null:t in Ot?t:t in St?St[t]:null}const Mo=["〇","一","二","三","四","五","六","七","八","九"],kt=["","十","百","千"],Do=["","萬","億"];function nn(t){if(t===0)return"〇";if(t<0)return`負${nn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Ho(s,r>0)+Do[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ho(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let i=0;i<o.length;i++){const l=o[i],a=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&a===1&&i===0&&!n?s+=kt[a]:s+=Mo[l]+kt[a]}return s.replace(/〇$/,"")}let Ee=null,Ae=null;const He=new Set;function Oo(){return Ee?Promise.resolve():Ae||(Ae=import("opencc-js/t2cn").then(t=>{Ee=t.Converter({from:"tw",to:"cn"}),He.forEach(n=>n())}).catch(()=>{Ee=t=>t,He.forEach(t=>t())}),Ae)}function ue(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Ee)return;const n=()=>t(o=>o+1);return He.add(n),Oo(),()=>{He.delete(n)}},[]),Ee??(n=>n)}function je(t,n){return n(t).toLowerCase()}const ot="#fff59d";function Se(t,n,o){if(!n)return t;const r=je(n,o);if(!r)return t;const s=je(t,o);if(s.length!==t.length)return t;const i=[];let l=0,a=0;for(;l<t.length;){const c=s.indexOf(r,l);if(c===-1){i.push(t.slice(l));break}c>l&&i.push(t.slice(l,c)),i.push(e.jsx("mark",{style:{background:ot,padding:0,color:"inherit"},children:t.slice(c,c+r.length)},a++)),l=c+r.length}return e.jsx(e.Fragment,{children:i})}function rt(t,n,o,r){if(!n)return!0;const s=je(n,r);return(o?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(l=>typeof l=="string"&&je(l,r).includes(s))}function Uo(t,n,o){return n?je(t,o).includes(je(n,o)):!0}const it={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},Vo={考证:"#5d6d7e"};function No(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function on({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=No(t),p=!!(r!=null&&r.vol_label)&&!c.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${ot}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":i?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:i?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:i?.5:1},children:[c,p&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function rn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>rn(r,n)))}function sn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+sn(i),0))||0;return n+o}function Ko(t,n){const o=[],r=l=>{var a;o.push(...l.files),(a=l.children)==null||a.forEach(r)};if(r(t),o.length===0)return;const s=o.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let i=0;for(const l of s)typeof l=="number"&&(i+=l);return i}function ln({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=rn(t,n||""),a=Ko(t,i),c=typeof a=="number"&&a>0,p=a===0,[f,x]=u.useState(l||c),h=sn(t),d=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{l&&x(!0)},[l]),u.useEffect(()=>{c&&x(!0)},[c]),t.files.length===1&&!d){const S=t.files[0],g=n===S,w=i[S],m=w===0,v=w==="loading",j=typeof w=="number"&&w>0;return e.jsxs("button",{onClick:()=>{m||o(S)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:g?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":j?`${ot}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,j&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:w}),v&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!f),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",h,")"]}),c&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",a]}),a==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),f&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(S=>e.jsx(on,{file:S,isActive:n===S,onSelect:o,meta:s==null?void 0:s[S],matchState:i[S]},S))}),d&&t.children.map((S,g)=>e.jsx(ln,{group:S,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function Yo({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((a,c)=>e.jsx(ln,{group:a,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(a=>e.jsx(on,{file:a,isActive:o===a,onSelect:r,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function Go({type:t}){const n=it[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Jo({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=U(),s=re(),i=ue(),l=S=>{if(!S)return"";const g=r(S);return o?Se(g,o,i):g},[a,c]=u.useState(!1),p=!!t.summary,f=!!t.comment,x=!!t.additional_comment,h=!!(t.content&&t.content.length>60),d=p||f||x||h;u.useEffect(()=>{o&&c(!0)},[o]);const b=!a&&h?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>d&&c(!a),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[nn(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!a&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),a&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),h&&!p&&!f&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function qo({section:t,highlightQuery:n=""}){const{convert:o}=U(),r=ue(),s=c=>{if(!c)return"";const p=o(c);return n?Se(p,n,r):p},[i,l]=u.useState(!1),a=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>a&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:a?"pointer":"default",userSelect:"none"},children:[e.jsx(Go,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),a&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&a&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${it[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}function Zo({section:t,highlightQuery:n=""}){const{convert:o}=U(),r=ue();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
2
+ `)),i=n?Se(s,n,r):s,l=it[t.type]||"#717171",a=t.type==="序"||t.type==="结语";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${l}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:l,marginRight:"8px",padding:"1px 5px",border:`1px solid ${l}40`,borderRadius:"2px",background:`${l}08`,verticalAlign:"middle"},children:t.type}),i]})}function Xo(t,n,o){const[r,s]=u.useState({});return u.useEffect(()=>{var p;if(!n||t.length===0)return;let i=!1;const l=t.filter(f=>{var x;return!((x=o==null?void 0:o.current)!=null&&x.has(f))}),a={};for(const f of t)(p=o==null?void 0:o.current)!=null&&p.has(f)&&(a[f]=o.current.get(f));if(Object.keys(a).length>0&&s(a),l.length===0)return;const c=async f=>{var x;try{if(n.getEntry){const g=await n.getEntry(f);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(f);if(!h)return null;const d=h.title||f,b=h.authors,S=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:d,author:S}}catch{return null}};return Promise.all(l.map(async f=>{var h;const x=await c(f);return(h=o==null?void 0:o.current)==null||h.set(f,x),[f,x]})).then(f=>{i||s(x=>{const h={...x};for(const[d,b]of f)h[d]=b;return h})}),()=>{i=!0}},[t.join(","),n]),r}function Qo({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=U(),l=re(),a=ue(),c=m=>{if(!m)return"";const v=i(m);return s?Se(v,s,a):v},[p,f]=u.useState(!1);u.useEffect(()=>{s&&f(!0)},[s]);const x=t.type,h=Vo[x]||"#717171",d=!!t.content,b=t.work_ids||[],S=b.length>1,g=Xo(S?b:[],o,r),w=d&&!p&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>d&&f(!p),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?c(t.header_line):c(t.title)}),!p&&w&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(w)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:l(b[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),S&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:h,border:`1px solid ${h}40`,borderRadius:"2px",background:`${h}08`},children:x})]})]}),S&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(m=>{const v=g[m],j=v?`${i(v.title)}${v.author?`(${i(v.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:l(m),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),_.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",j]},m)})}),p&&d&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${h}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:c(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:c(t.comment)})]})]})}function er({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=U(),l=ue(),a=n.trim(),c=u.useMemo(()=>a?t.sections.filter(x=>rt(x,a,!0,l)):t.sections,[t.sections,a,l]),p=t.sections.filter(x=>x.type==="考证").length,f=c.filter(x=>x.type==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:a?`${f} / ${p} 條`:`${p} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:c.map((x,h)=>e.jsx(Qo,{section:x,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:a},h))}),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function tr({text:t,highlightQuery:n=""}){const{convert:o}=U(),r=ue(),s=l=>{const a=o(l);return n?Se(a,n,r):a},i=t.split(`
3
+ `);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((l,a)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},a);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},a);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},a);if(!l.trim())return a>0&&!i[a-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},a);const c=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:c.map((p,f)=>p.startsWith("**")&&p.endsWith("**")?e.jsx("strong",{children:s(p.slice(2,-2))},f):e.jsx(u.Fragment,{children:s(p)},f))},a)})})}function nr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=U(),s=re(),i=ue(),l=p=>{if(!p)return"";const f=r(p);return o?Se(f,o,i):f},a=[];let c=null;for(const p of t)p.type==="类"?(c&&a.push(c),c={category:p.title,categoryContent:p.content||void 0,items:[]}):p.type==="书"?(c||(c={category:"",items:[]}),c.items.push(p)):(p.type==="序"||p.type==="结语")&&(c||(c={category:"",items:[]}),c.items.push(p),p.type==="结语"&&(a.push(c),c=null));return c&&a.push(c),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:a.map((p,f)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[p.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(p.category),p.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(p.categoryContent)})]}),p.items.map((x,h)=>x.type==="序"||x.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(x.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:l(x.title)})}):e.jsx("strong",{children:l(x.title)}),x.content&&l(x.content)]},h))]},f))})}function or({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=U(),i=ue(),[l,a]=u.useState("catalog"),c=o.trim(),p=u.useMemo(()=>c?t.sections.filter(d=>rt(d,c,!1,i)):t.sections,[t.sections,c,i]),f=t.sections.filter(d=>d.type==="书").length,x=t.sections.filter(d=>d.type==="詩").length,h=c?p.filter(d=>d.type==="书"||d.type==="詩").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(d=>e.jsx("button",{onClick:()=>a(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${x>0?`${x} 首`:`${f} 部書`}`:x>0?`${x} 首`:`${f} 部书`})]}),l==="raw"&&(n?e.jsx(tr,{text:n,highlightQuery:c}):e.jsx(nr,{sections:t.sections,onNavigate:r,highlightQuery:c})),l==="catalog"&&p.map((d,b)=>d.type==="书"||d.type==="詩"?e.jsx(Jo,{section:d,onNavigate:r,highlightQuery:c},b):d.type==="类"?e.jsx(qo,{section:d,highlightQuery:c},b):e.jsx(Zo,{section:d,highlightQuery:c},b)),l==="catalog"&&p.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function an(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function wt(t){const n=an(t);return n.length>0?n[0]:null}function rr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:a,isKaozhen:c}=t,p=ue(),f=u.useRef(new Map),[x,h]=u.useState({});u.useEffect(()=>{s&&i&&f.current.set(s,{juan:i,rawText:l})},[s,i,l]),u.useEffect(()=>{f.current.clear(),h({})},[n]);const d=u.useCallback((b,S)=>{let g=0;if(b.juan)for(const w of b.juan.sections)rt(w,S,c,p)&&g++;return g===0&&b.rawText&&Uo(b.rawText,S,p)&&(g=1),g},[c,p]);return u.useEffect(()=>{const b=a.trim();if(!b){h({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let S=!1;const g={},w=[];for(const k of r){const y=f.current.get(k);y?g[k]=d(y,b):(g[k]="loading",w.push(k))}h(g);const m=8;let v=0;const j=async()=>{var k;for(;v<w.length;){if(S)return;const y=v++,R=w[y];try{const[E,L]=await Promise.all([o.getCollatedJuan(n,R),((k=o.getCollatedJuanText)==null?void 0:k.call(o,n,R))??Promise.resolve(null)]),A={juan:E,rawText:L};if(f.current.set(R,A),S)return;h(B=>({...B,[R]:d(A,b)}))}catch{if(S)return;h(E=>({...E,[R]:0}))}}},_=Array.from({length:Math.min(m,w.length)},()=>j());return Promise.all(_),()=>{S=!0}},[a,n,o,r.join(","),d,p]),{matchStates:x}}const cn=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:l,style:a})=>{const[c,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[b,S]=u.useState(null),[g,w]=u.useState(null),[m,v]=u.useState(!1),[j,_]=u.useState(null),[k,y]=u.useState(""),R=u.useRef(new Map),E=s??b,L=u.useCallback(C=>{S(C),i==null||i(C)},[i]),A=t||c;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let C=!1;return x(!0),d(null),o.getCollatedEditionIndex(n).then(I=>{if(!C)if(!I)d("未找到整理本数据");else{p(I);const $=wt(I);!s&&$&&L($)}}).catch(I=>{C||d(I instanceof Error?I.message:"加载失败")}).finally(()=>{C||x(!1)}),()=>{C=!0}},[t,n,o,s,L]),u.useEffect(()=>{const C=t||c;if(C&&!E){const I=wt(C);I&&L(I)}},[t,c,E,L]);const B=n||(A==null?void 0:A.work_id),H=u.useCallback(async C=>{var I;if(!(!B||!(o!=null&&o.getCollatedJuan))){v(!0),w(null),_(null);try{const[$,K]=await Promise.all([o.getCollatedJuan(B,C),((I=o.getCollatedJuanText)==null?void 0:I.call(o,B,C))??Promise.resolve(null)]);w($),_(K)}catch{w(null),_(null)}finally{v(!1)}}},[B,o]);u.useEffect(()=>{E&&H(E)},[E,H]);const M=C=>{L(C)};if(f)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!A)return null;const z=A.type==="kaozhen",F=an(A);return e.jsx(ir,{className:l,style:a,index:A,allFiles:F,isKaozhen:z,effectiveWorkId:B,transport:o,activeFile:E,handleSelectFile:M,juanData:g,juanRawText:j,juanLoading:m,searchQuery:k,setSearchQuery:y,onNavigate:r,workLabelCacheRef:R})},ir=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:a,handleSelectFile:c,juanData:p,juanRawText:f,juanLoading:x,searchQuery:h,setSearchQuery:d,onNavigate:b,workLabelCacheRef:S})=>{const{matchStates:g}=rr({workId:i,transport:l,files:r,activeFile:a,activeJuan:p,activeRawText:f,query:h,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:h,onChange:w=>d(w.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s?e.jsxs(e.Fragment,{children:[o.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_juan})," 卷"]})}),o.text_quality&&(()=>{const w=Fo(o.text_quality.grade);return w?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Ao,{content:Wn[w],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:$n[w],cursor:"help"},children:Ot[w]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(Yo,{files:r,groups:o.juan_groups,activeFile:a,onSelect:c,juanMeta:o.juan_metadata,matchStates:g}),x?e.jsx(me,{}):p?s?e.jsx(er,{juan:p,searchQuery:h,onNavigate:b,transport:l,workLabelCache:S}):e.jsx(or,{juan:p,rawText:f,searchQuery:h,onNavigate:b}):a?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,o.references&&o.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),o.references.map((w,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,". "]}),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]})]},m))]})]})},sr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},lr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function ar(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const dn=({items:t,loading:n})=>{const o=re();return n?e.jsx(me,{}):t.length===0?e.jsx("div",{style:cr,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=sr[r.type],i=lr[r.status];return e.jsxs("div",{style:dr,children:[e.jsxs("div",{style:pr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Ct,background:s.color},children:s.label}),e.jsx("span",{style:{...Ct,background:i.color},children:i.label})]}),e.jsx("span",{style:xr,children:ar(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:ur,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:_t,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:_t,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:fr,children:r.content}),r.reply&&e.jsxs("div",{style:gr,children:[e.jsx("div",{style:hr,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},cr={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},dr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},pr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ct={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},xr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ur={fontSize:"12px",marginBottom:"6px"},_t={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},fr={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},gr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},hr={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Qe=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=W(),[a,c]=u.useState(null),[p,f]=u.useState([]),[x,h]=u.useState("recommend"),[d,b]=u.useState([]),[S,g]=u.useState(!1),w=r??x,m=B=>{h(B),s==null||s(B)},[v,j]=u.useState(!0),[_,k]=u.useState(null),[y,R]=u.useState(null),[E,L]=u.useState(null);u.useEffect(()=>{let B=!1;const H=z=>{B||c(z)},M=()=>{t.getAllEntries&&t.getAllEntries().then(z=>{H({works:z.filter(F=>F.type==="work").length,books:z.filter(F=>F.type==="book").length,collections:z.filter(F=>F.type==="collection").length})}).catch(()=>{})};return t.getCounts?t.getCounts().then(z=>H({works:z.works,books:z.books,collections:z.collections})).catch(M):M(),()=>{B=!0}},[t]),u.useEffect(()=>{let B=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const M=await t.getRecommended();if(M!=null&&M.groups)return M.groups.flatMap(z=>z.items.map(F=>({...F,group:z.name})))}catch{}return[]})().then(async M=>{if(B)return;const z=M.filter(C=>C.id);if(z.length===0){j(!1);return}const F=await Promise.all(z.map(async C=>{try{let I=null;if(t.getEntry)I=await t.getEntry(C.id);else{const $=await t.getItem(C.id);$&&(I={id:C.id,title:$.title||C.id,type:$.type||"work"})}if(I)return{...I,group:C.group,fallbackDescription:C.description}}catch{}return{id:C.id,title:C.title,type:V.extractType(C.id),group:C.group,fallbackDescription:C.description}}));B||(f(F.filter(C=>C!==null)),j(!1))}),()=>{B=!0}},[t,o]),u.useEffect(()=>{let B=!1;const H=t.getCatalogProgress??t.getResourceProgress;if(H)return H.call(t).then(M=>{B||k(M)}).catch(()=>{}),()=>{B=!0}},[t]),u.useEffect(()=>{if(!t.getCollectionProgress)return;let B=!1;return t.getCollectionProgress().then(H=>{B||R(H)}).catch(()=>{}),()=>{B=!0}},[t]),u.useEffect(()=>{if(!t.getSiteProgress)return;let B=!1;return t.getSiteProgress().then(H=>{B||L(H)}).catch(()=>{}),()=>{B=!0}},[t]),u.useEffect(()=>{if(!i||w!=="feedback")return;let B=!1;return g(!0),fetch(i).then(H=>H.json()).then(H=>{!B&&H.success&&b(H.items||[])}).catch(()=>{}).finally(()=>{B||g(!1)}),()=>{B=!0}},[i,w]);const A=B=>{switch(B){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(ze,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>m("recommend")}),e.jsx(ze,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>m("catalog")}),e.jsx(ze,{label:l.home.collectionTab,active:w==="collection",onClick:()=>m("collection")}),e.jsx(ze,{label:l.home.siteTab,active:w==="site",onClick:()=>m("site")}),i&&e.jsx(ze,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>m("feedback")})]}),w==="recommend"&&e.jsx(br,{recommended:p,loading:v,onNavigate:n,getIcon:A,t:l}),w==="catalog"&&e.jsx(zt,{progress:_,t:l,onNavigate:n}),w==="collection"&&e.jsx(zt,{progress:y,t:l,onNavigate:n}),w==="site"&&e.jsx(yr,{progress:E,t:l,totalWorks:(a==null?void 0:a.works)??0}),w==="feedback"&&i&&e.jsx(dn,{items:d,loading:S})]})})},ze=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),br=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=re();if(n)return e.jsx(me,{});if(t.length===0)return null;const l=new Map;for(const a of t){const c=a.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(a)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([a,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const f=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return e.jsxs("a",{href:i(p.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o==null||o(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(p.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:p.edition})]}),f&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:f})]})]},p.id)})})]},a))})},zt=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(me,{});const r=[...t.resources].sort((a,c)=>a.priority-c.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(a=>{const c=r.filter(p=>p.status===a);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[a]}}),i[a]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>e.jsx(mr,{item:p,t:n,statusColor:l[a],onNavigate:o},p.id))})]},a)})})},mr=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=re(),i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&r?e.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?We(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${i}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},yr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(me,{});const r=[...t.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),i=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),a=o>0?Math.round(l/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",a,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>e.jsx(It,{item:c,t:n,totalWorks:o},c.id))})]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(c=>e.jsx(It,{item:c,t:n,totalWorks:o},c.id))})]})]})},It=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Tt="(max-width: 768px)";function vr(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(Tt).matches);return u.useEffect(()=>{const o=window.matchMedia(Tt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const jr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var F;const i=W(),{convert:l}=U(),a=vr(),[c,p]=u.useState(null),[f,x]=u.useState(null),[h,d]=u.useState(!1),[b,S]=u.useState("detail"),[g,w]=u.useState([]),[m,v]=u.useState(!1),[j,_]=u.useState(null),[k,y]=u.useState(!1),R=u.useCallback(async C=>{if(!t.getCollatedEditionIndex){_(null);return}y(!0);try{const I=await t.getCollatedEditionIndex(C);_(I)}catch{_(null)}finally{y(!1)}},[t]),E=u.useCallback(async C=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){w([]);return}v(!0);try{if(t.getCollectionCatalogs){const I=await t.getCollectionCatalogs(C);w(I||[])}else if(t.getCollectionCatalog){const I=await t.getCollectionCatalog(C);w(I?[{resource_id:"",data:I}]:[])}}catch{w([])}finally{v(!1)}},[t]),L=u.useCallback(async C=>{if(o){o(C);return}p(C),x(null),w([]),_(null),S("detail"),d(!0);try{const I=await t.getItem(C.id);I&&(x(I),I.type==="collection"?E(C.id):I.type==="work"&&I.has_collated&&R(C.id))}catch(I){console.error("加载详情失败:",I)}finally{d(!1)}},[t,o,E,R]),A=u.useCallback(async C=>{x(null),w([]),_(null),S("detail"),d(!0);try{const I=await t.getItem(C);I&&(x(I),p({id:C,title:I.title||C,type:I.type||"book"}),I.type==="collection"?E(C):I.type==="work"&&I.has_collated&&R(C))}catch(I){console.error("导航失败:",I)}finally{d(!1)}},[t,E,R]),B=(f==null?void 0:f.type)==="collection"&&(g.length>0||m)||(f==null?void 0:f.type)==="work"&&(j||k),H=a&&(h||f),M=u.useCallback(()=>{p(null),x(null),w([]),_(null),S("detail")},[]),z=e.jsx(e.Fragment,{children:h?e.jsx(me,{}):f?e.jsxs(e.Fragment,{children:[(B||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>S("detail"),style:Fe(b==="detail"),children:i.detailTab.basicInfo}),f.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Fe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),f.type==="collection"&&g.map(C=>e.jsx("button",{onClick:()=>S(`catalog:${C.resource_id}`),style:Fe(b===`catalog:${C.resource_id}`),children:C.short_name?`${l(C.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},C.resource_id)),f.type==="work"&&(j||k)&&e.jsxs("button",{onClick:()=>S("collated"),style:Fe(b==="collated"),children:[i.detailTab.collatedEdition,k&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(nt,{data:f,transport:t,onNavigate:A}):b.startsWith("catalog:")?e.jsx(tn,{data:(F=g.find(C=>`catalog:${C.resource_id}`===b))==null?void 0:F.data,onNavigate:A}):b==="collated"?e.jsx(cn,{index:j||void 0,workId:f.id,transport:t,onNavigate:A}):null})]}):e.jsx(Qe,{transport:t,onNavigate:A,recommendedIds:r})});return a?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children: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:z})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Xe,{transport:t,onEntryClick:L,hideModeIndicator:n}),!f&&e.jsx(Qe,{transport:t,onNavigate:A,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Xe,{transport:t,onEntryClick:L,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:z})]})};function Fe(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const Sr=({data:t,onNavigate:n,className:o,style:r})=>{var f;const s=W(),{convert:i}=U(),[l,a]=u.useState(((f=t.divisions[0])==null?void 0:f.name)??null),[c,p]=u.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(kr,{division:x,expanded:l===x.name,onToggle:()=>a(l===x.name?null:x.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},x.name))})]})},kr=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:l}=U(),a=t.categories.reduce((c,p)=>{const f=p.stats||{zhulu:0,cunmu:0};return c+(f.zhulu||0)+(f.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const p=`${t.name}/${c.name}`;return e.jsx(wr,{category:c,expanded:r===p,onToggle:()=>s(p),onNavigate:i},c.name)})})]})},wr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var c,p,f,x;const{convert:s}=U(),i=((c=t.books)==null?void 0:c.zhulu)||[],l=((p=t.books)==null?void 0:p.cunmu)||[],a=(((f=t.stats)==null?void 0:f.zhulu)||i.length)+(((x=t.stats)==null?void 0:x.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Rt,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(Rt,{label:"存目",books:l,onNavigate:r})]})]})},Rt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=U(),s=re(),[i,l]=u.useState(n.length<=20),a=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map((c,p)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:c.work_id&&o?e.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(c.title)}):r(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(c.author).slice(0,20)})]},p))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ie=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=W();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:_r,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Cr,children:i.action.save})]})]}),s]})},Cr={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},_r={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ne=({label:t,value:n,onChange:o,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:i=>o(i.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),be=({value:t,onChange:n,placeholder:o})=>{const r=u.useRef(null);return u.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Oe=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function zr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const De=({value:t,onChange:n,label:o})=>{const[r,s]=u.useState(!1),i=u.useRef(null),l=zr(t||"");return u.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Et,children:o}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(Oe,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Et,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:a=>n(a.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Et={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Ir(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Tr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const pn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=W(),[s,i]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},a=x=>{n(t.filter((h,d)=>d!==x)),s===x&&i(null)},c=(x,h,d)=>{const b=[...t];b[x]={...b[x],[h]:d},n(b)},p=(x,h)=>{const d=[...t];d[x]={...d[x],type:h,id:"",name:""},n(d),h==="bookID"&&o&&o(b=>{const S=[...t];S[x]={...S[x],id:b.id,name:b.title,type:"bookID"},n(S)})},f=x=>{o&&o(h=>{const d=[...t];d[x]={...d[x],id:h.id,name:h.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>i(s===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ir(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Tr(x.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Lt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>p(h,"url"),style:{...Lt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:xe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Bt,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>f(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>f(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:xe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:Bt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>c(h,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:d=>c(h,"id",d.target.value),placeholder:"https://...",style:ye})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...xe,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>c(h,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:d=>c(h,"position",d.target.value),placeholder:"如: 卷三, p.52",style:ye})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:d=>c(h,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:d=>c(h,"processor_version",d.target.value),placeholder:"如: v0.1",style:ye})]})]})]})]})})]},h)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},xe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ye={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Lt={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Bt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function xn(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function un(t){return!t||t.length===0?"":JSON.stringify(t)}const fn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:a,childCollections:c,containedBooks:p,siblingBooks:f,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:d,onCreateAndLink:b,onSaveRelations:S})=>{const g=W();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),S&&e.jsx("button",{onClick:S,style:Rr,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),i&&f&&f.length>0&&e.jsx(ve,{direction:"horizontal",title:`${g.relation.siblingVersions} (${f.length})`,entities:f,onView:d,onAdd:()=>b("siblingBook","book",{workId:i.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.parentWork,entity:r,onView:d,onUnlink:()=>h("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),a&&a.length>0&&e.jsx(ve,{direction:"down",title:`${g.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),c&&c.length>0&&e.jsx(ve,{direction:"down",title:`${g.relation.collectionImpl} (${c.length})`,entities:c,onView:d,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(ve,{direction:"down",title:`${g.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>b("childBook","book",{workId:n}),addLabel:g.action.addVersion,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Ie,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ie,{direction:"up",title:g.relation.parentCollection,entity:s,onView:d,onUnlink:()=>h("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(ve,{direction:"down",title:`${g.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:d,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(ve,{direction:"down",title:`${g.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},Ie=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:l,linkLabel:a,createLabel:c,notLinkedLabel:p,viewLabel:f,unlinkLabel:x})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:d}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:gn(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Wt,{onClick:()=>r(o),title:f,children:"👁️"}),e.jsx(Wt,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:p}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(et,{onClick:i,children:a}),e.jsx(et,{onClick:l,primary:!0,children:c})]})]})},ve=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:a})=>{const[c,p]=u.useState(!1),f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=c?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>r(d),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:gn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.length>5&&!c&&e.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(et,{onClick:s,primary:!0,children:["+ ",i]})})]})},Wt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),et=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function gn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Rr={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},hn=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:l,onSearch:a,isLoading:c,excludeId:p})=>{const[f,x]=u.useState(""),h=p?l.filter(g=>g.id!==p):l;u.useEffect(()=>{t&&(x(""),a(""))},[t]);const d=g=>{x(g),a(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Er,children:e.jsxs("div",{style:Lr,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:s,style:Br,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:f,onChange:g=>d(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Wr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Je,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>r(g),style:$r,children:[e.jsx("span",{style:{fontSize:"16px"},children:S}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):f?e.jsxs("div",{style:Je,children:["未找到匹配的",b]}):e.jsxs("div",{style:Je,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:i,style:Pr,children:["创建新",b,"并关联"]})]})]})})},Er={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Br={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Wr={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},$r={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Je={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Pr={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},$t={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ar={work:"📜",book:"📖",collection:"📚",entity:"👤"},bn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,a]=u.useState(""),c=u.useRef(null);u.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,d;(h=c.current)==null||h.focus(),(d=c.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?f():h.key==="Escape"&&i()},f=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const x=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${$t[n]}`}};return e.jsx("div",{style:Fr,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Mr,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ar[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:c,type:"text",value:l,onChange:h=>a(h.target.value),onKeyDown:p,placeholder:`请输入${$t[n]}名称...`,style:Dr})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:Hr,children:"取消"}),e.jsx("button",{onClick:f,disabled:!l.trim(),style:{...Or,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Fr={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Mr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Dr={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},Hr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Or={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Ur(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function mn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Vr(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const yn=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:a,onCancel:c,onCreate:p,onSearch:f})=>{const[x,h]=u.useState(""),[d,b]=u.useState([]),[S,g]=u.useState(!1),[w,m]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!x.trim()){b([]);return}const R=setTimeout(async()=>{g(!0);try{b(await f(x,o))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(R)},[x,o,f]);const v=u.useCallback(R=>{h(R.target.value),R.target.value.trim()&&m("search")},[]),j=u.useCallback(R=>s?R.filter(E=>E.id!==s):R,[s]);if(!t)return null;const _=n||(o==="all"?"选择实体":`选择${mn(o)}`),k=j(r),y=j(d);return e.jsx("div",{style:Kr,children:e.jsxs("div",{style:Yr,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:_}),e.jsx("button",{onClick:c,style:Gr,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:v,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Jr}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),S&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),k.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Pt,{active:w==="recent",onClick:()=>m("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(Pt,{active:w==="search",onClick:()=>m("search"),children:["搜索结果 ",y.length>0&&`(${y.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&k.length>0?e.jsx(At,{entities:k,onSelect:a}):x.trim()?S?e.jsx(qe,{message:"搜索中..."}):y.length>0?e.jsx(At,{entities:y,onSelect:a}):e.jsx(qe,{message:"未找到匹配的结果"}):e.jsx(qe,{message:"输入关键词开始搜索"})}),i&&p&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:p,style:qr,children:l||"创建新实体"})]})]})})},Pt=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),At=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Nr,{entity:o,onClick:()=>n(o)},o.id))}),Nr=({entity:t,onClick:n})=>{const[o,r]=u.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Ur(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Vr(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:mn(t.type)})]})},qe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Kr={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Yr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Gr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Jr={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},qr={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Zr={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Xr={work:"📜",collection:"📚",book:"📖",entity:"👤"},vn=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:a,renderSectionActions:c,onDownloadResource:p,downloadStatuses:f,relations:x,onRelationsChange:h})=>{var Q;const d=W(),[b,S]=u.useState(!1),[g,w]=u.useState("work"),[m,v]=u.useState(""),[j,_]=u.useState(""),[k,y]=u.useState([]),[R,E]=u.useState(!1),[L,A]=u.useState(!1),[B,H]=u.useState("work"),[M,z]=u.useState(""),[F,C]=u.useState(),[I,$]=u.useState(!1),[K,D]=u.useState(null),[q,Z]=u.useState([]);u.useRef(null);const le=t.type,ge=le==="work",fe=le==="collection",X=le==="book",J=u.useCallback((T,O)=>{n({...t,[T]:O})},[t,n]),Ve=u.useCallback((T,O)=>{v(T),w(O),_(d.editor.selectToLink+d.indexType[O]),y([]),S(!0)},[d]),Ne=u.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),ke=u.useCallback(T=>{s==null||s(T.id,T.type)},[s]),we=u.useCallback((T,O,te)=>{const ae={...te,author:(te==null?void 0:te.author)||t.author,dynasty:(te==null?void 0:te.dynasty)||t.dynasty};H(O),z(T),C(ae),A(!0)},[t.author,t.dynasty]),Ke=u.useCallback((T,O)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,M,{type:B,title:T,inheritData:O}),A(!1)},[r,t.id,M,B]),$e=u.useCallback(T=>{if(!T.trim()){y([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(T,g).then(O=>{y(O),E(!1)}).catch(()=>{y([]),E(!1)})},[r,g]),Ye=u.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),S(!1)},[r,t.id,m]),P=u.useCallback(()=>{o()},[o]),G=u.useCallback(T=>{D(()=>T),$(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),N=u.useCallback((T,O)=>r!=null&&r.searchEntities?r.searchEntities(T,O==="all"?void 0:O):Promise.resolve([]),[r]),Y=u.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Z(O=>[T,...O.filter(te=>te.id!==T.id)].slice(0,10)),K==null||K(T),$(!1),D(null)},[r,K]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Xr[le]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Oe,{children:t.id}),e.jsx(Oe,{color:Zr[le],children:d.indexType[le]})]})}),e.jsx(ie,{title:d.section.basicInfo,onSave:o,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(De,{label:ge?d.editor.workTitle:fe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:T=>J("title",T)}),X&&e.jsx(De,{label:d.editor.belongsToWork,value:t.workName||"",onChange:T=>J("workName",T)}),e.jsx(ne,{label:d.editor.authorLabel,value:t.author||"",onChange:T=>J("author",T)}),e.jsx(ne,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>J("dynasty",T)}),(X||fe)&&e.jsx(De,{label:d.editor.containedIn,value:t.collection||"",onChange:T=>J("collection",T)}),(X||fe)&&e.jsx(ne,{label:d.editor.holderLabel,value:t.holder||"",onChange:T=>J("holder",T)}),(X||fe)&&e.jsx(ne,{label:X?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:T=>J("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ne,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>J("firstImage",T)})})]})}),e.jsx(ie,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(be,{value:t.description||"",onChange:T=>J("description",T),placeholder:d.editor.descriptionPlaceholder})}),(((Q=t.additional_works)==null?void 0:Q.length)||0)>0&&e.jsx(ie,{title:d.section.additionalWorks,onSave:o,children:e.jsx(Qr,{items:t.additional_works||[],onChange:T=>J("additional_works",T)})}),e.jsx(ie,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(ei,{items:t.indexed_by||[],onChange:T=>J("indexed_by",T)})}),e.jsx(ie,{title:d.section.emendatedBy,onSave:o,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(ti,{items:t.emendated_by||[],onChange:T=>J("emendated_by",T)})}),e.jsx(ie,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Ze,{items:t.resources||[],onChange:T=>J("resources",T),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(ie,{title:d.section.imageResources,onSave:o,children:e.jsx(Ze,{items:t.resources||[],onChange:T=>J("resources",T),onDownload:p,downloadStatuses:f,filterType:"image"})}),e.jsx(ie,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(pn,{items:xn(t.sources||""),onChange:T=>J("sources",un(T)),onOpenEntityPicker:G})}),(X||fe)&&e.jsx(ie,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(be,{value:t.provenance||"",onChange:T=>J("provenance",T),placeholder:d.editor.provenancePlaceholder})}),X&&e.jsx(ie,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(be,{value:t.otherEditions||"",onChange:T=>J("otherEditions",T),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(fn,{entityType:le,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:Ve,onUnlinkEntity:Ne,onViewEntity:ke,onCreateAndLink:we,onSaveRelations:P}),i&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:d.editor.deleteEntity})]}),e.jsx(hn,{isOpen:b,entityType:g,title:j,onSelect:Ye,onCancel:()=>S(!1),onCreate:()=>{S(!1),we(m,g)},searchResults:k,onSearch:$e,isLoading:R,excludeId:t.id}),e.jsx(bn,{isOpen:L,entityType:B,relationField:M,inheritData:F,onConfirm:Ke,onCancel:()=>A(!1)}),e.jsx(yn,{isOpen:I,title:d.action.selectBookOrWork,filterType:"all",recentEntities:q,excludeId:t.id,onSelect:Y,onCancel:()=>{$(!1),D(null)},onSearch:N})]})};function Qr({items:t,onChange:n}){const o=W(),r=(l,a,c)=>{const p=t.map((f,x)=>x===l?{...f,[a]:c}:f);n(p)},s=l=>n(t.filter((a,c)=>c!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ne,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ne,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(a,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>s(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function jn({items:t,onChange:n,showMeta:o,addLabel:r}){const s=W(),[i,l]=u.useState(null),a=(f,x,h)=>{const d=t.map((b,S)=>S===f?{...b,[x]:h||void 0}:b);n(d)},c=f=>{n(t.filter((x,h)=>h!==f)),i===f&&l(null)},p=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,x)=>{const h=i===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(h?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:f.source||s.editor.unnamedSource}),f.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:f.source_bid}),e.jsx("button",{onClick:d=>{d.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&o&&(f.title_info||f.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[f.title_info,f.title_info&&f.author_info&&" — ",f.author_info]}),h&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ne,{label:s.label.sourceName,value:f.source,onChange:d=>a(x,"source",d)}),e.jsx(ne,{label:s.label.sourceBid,value:f.source_bid||"",onChange:d=>a(x,"source_bid",d)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ne,{label:s.label.titleInfo,value:f.title_info||"",onChange:d=>a(x,"title_info",d)}),e.jsx(ne,{label:s.label.authorInfo,value:f.author_info||"",onChange:d=>a(x,"author_info",d)})]}),e.jsx(ne,{label:s.label.edition,value:f.edition||"",onChange:d=>a(x,"edition",d)})]}),e.jsx(be,{value:f.summary||"",onChange:d=>a(x,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(be,{value:f.comment||"",onChange:d=>a(x,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(be,{value:f.additional_comment||"",onChange:d=>a(x,"additional_comment",d),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function ei({items:t,onChange:n}){const o=W();return e.jsx(jn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function ti({items:t,onChange:n}){const o=W();return e.jsx(jn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Sn(t){var a,c,p,f,x,h,d;const n=((c=(a=t.authors)==null?void 0:a[0])==null?void 0:c.name)||"",o=((p=t.publication_info)==null?void 0:p.year)||"",r=((f=t.current_location)==null?void 0:f.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",l={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:s,description:i,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const S=b.related_works.find(g=>g.relation==="part_of");S&&(l.parentWorkId=S.id,l.parentWorkName=S.title)}}if(t.type==="book"){const b=t;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(d=b.contained_in[0])==null?void 0:d.id)}return l}function ni(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const oi=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:l,onSave:a,onDelete:c,onNavigate:p,renderLink:f,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:S,onRelationsChange:g,headerExtra:w,className:m,style:v}=t;W();const[j,_]=u.useState(s),k=i?s:j;u.useEffect(()=>{s!==j&&_(s)},[s]);const y=u.useCallback(()=>{const M=k==="view"?"edit":"view";i?i(M):_(M)},[k,i]),[R,E]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(M=>{M&&E(M)})},[o,r]);const L=n||R,A=u.useMemo(()=>L?Sn(L):null,[L]),B=i||!n?e.jsx("button",{onClick:y,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,H=e.jsxs(e.Fragment,{children:[B,w]});return!L&&!A?e.jsx(me,{}):k==="view"?e.jsx(nt,{data:L,transport:r,onNavigate:p?M=>p(M):void 0,renderLink:f,headerExtra:H,className:m,style:v}):A?e.jsxs("div",{className:m,style:v,children:[H&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:H}),e.jsx(vn,{data:A,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:b,relations:S,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Ft=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],kn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=u.useState(null),[l,a]=u.useState(""),[c,p]=u.useState("idle"),[f,x]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(i(null),a(""),p("idle"),x(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[s]),u.useEffect(()=>{if(c==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[c,n]),u.useEffect(()=>{if(!t)return;const g=w=>{w.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const d=async()=>{if(!(!s||!l.trim())){p("submitting"),x("");try{await o({type:s,content:l.trim()}),p("success")}catch(g){p("error"),x(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&l.trim()&&c!=="submitting",S=Ft.find(g=>g.value===s);return e.jsx("div",{style:ri,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:ii,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:si,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:li,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:xi,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Ft.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...ai,...s===g.value?ci:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:l,onChange:g=>a(g.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||c==="submitting",style:{...di,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),c==="error"&&e.jsx("div",{style:ui,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...pi,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},ri={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ii={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},si={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},li={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ai={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ci={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},di={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},pi={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},xi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ui={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},fi=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...gi,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(kn,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},gi={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Mt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],hi=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,s]=u.useState(""),[i,l]=u.useState("idle"),[a,c]=u.useState(""),p=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=p.current)==null?void 0:d.focus()},100)},[n]);const f=async()=>{if(!(!n||!r.trim())){l("submitting"),c("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(d){l("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&i!=="submitting",h=Mt.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Dt,children:e.jsxs("div",{style:ji,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Si,children:"继续提交"})]})}):e.jsxs("div",{style:Dt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Mt.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...bi,...n===d.value?mi:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:p,value:r,onChange:d=>s(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...yi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:f,disabled:!x,style:{...vi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:ki,children:a})]})},Dt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},bi={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},mi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},yi={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},vi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ji={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Si={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ki={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},wi=({style:t})=>{const n=u.useContext(Be);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",i=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})};exports.BidLink=V.BidLink;exports.BookIndexError=V.BookIndexError;exports.BookIndexManager=V.BookIndexManager;exports.BookIndexStorage=V.BookIndexStorage;exports.BundleStorage=V.BundleStorage;exports.ConfigError=V.ConfigError;exports.GithubStorage=V.GithubStorage;exports.IdGenerationError=V.IdGenerationError;exports.IdGenerator=V.IdGenerator;exports.LocalStorage=V.LocalStorage;exports.MigrationError=V.MigrationError;exports.StorageError=V.StorageError;exports.base36Decode=V.base36Decode;exports.base36Encode=V.base36Encode;exports.base58Decode=V.base58Decode;exports.buildId=V.buildId;exports.decodeId=V.decodeId;exports.decodeIdString=V.decodeIdString;exports.encodeId=V.encodeId;exports.extractIdFromUrl=V.extractIdFromUrl;exports.extractStatus=V.extractStatus;exports.extractType=V.extractType;exports.normalizeCatalog=V.normalizeCatalog;exports.parseId=V.parseId;exports.smartDecode=V.smartDecode;exports.validateResource=V.validateResource;exports.Badge=Oe;exports.BidUrlProvider=Ln;exports.CollatedEdition=cn;exports.CollectionCatalog=tn;exports.CreateEntityDialog=bn;exports.EmendatedBySection=Qt;exports.EntityDetail=Gt;exports.EntityPickerDialog=yn;exports.EntitySelector=hn;exports.FeedbackButton=fi;exports.FeedbackDialog=kn;exports.FeedbackForm=hi;exports.FeedbackList=dn;exports.FormInput=ne;exports.FormTextArea=be;exports.HomePage=Qe;exports.IndexApp=jr;exports.IndexBrowser=Xe;exports.IndexDetail=nt;exports.IndexEditor=vn;exports.IndexView=oi;exports.LocaleContext=Be;exports.LocaleProvider=Hn;exports.LocaleToggle=wi;exports.ModeIndicator=Kt;exports.RelationPanel=fn;exports.ResourceEditor=Ze;exports.ResourceList=tt;exports.SearchInput=Yt;exports.Section=ie;exports.SmartBidInput=De;exports.SourceEditor=pn;exports.WorkCatalog=Sr;exports.detailToEditor=Sn;exports.editorToDetail=ni;exports.formatTemplate=We;exports.parseSourceString=xn;exports.stringifySources=un;exports.useBidUrl=re;exports.useConvert=U;exports.useT=W;