book-index-ui 0.2.3 → 0.2.5

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,2 +1,2 @@
1
- "use strict";var cn=Object.create;var Je=Object.defineProperty;var dn=Object.getOwnPropertyDescriptor;var pn=Object.getOwnPropertyNames;var xn=Object.getPrototypeOf,un=Object.prototype.hasOwnProperty;var fn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of pn(n))!un.call(t,i)&&i!==o&&Je(t,i,{get:()=>n[i],enumerable:!(r=dn(n,i))||r.enumerable});return t};var gn=(t,n,o)=>(o=t!=null?cn(xn(t)):{},fn(n||!t||!t.__esModule?Je(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-BGrOtGe_.cjs"),e=require("react/jsx-runtime"),u=require("react"),hn=require("react-dom"),bn=t=>`/book-index?id=${t}`,zt=u.createContext(bn);function mn({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(zt.Provider,{value:o,children:n})}function ce(){return u.useContext(zt)}const ze=u.createContext(null),_t={indexType:{work:"作品",book:"書籍",collection:"叢編"},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:"上級作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},yn={indexType:{work:"作品",book:"书籍",collection:"丛编"},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:"上级作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},vn={"zh-Hant":_t,"zh-Hans":yn},Tt="bim-locale";function jn(){try{const t=localStorage.getItem(Tt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Sn(t){try{localStorage.setItem(Tt,t)}catch{}}const kn="zh-Hant",wn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=u.useState(t??kn),l=t??r;u.useEffect(()=>{if(t)return;const f=jn();f&&f!==r&&i(f)},[]);const[s,c]=u.useState(null);u.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(f=>{const x=f.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>f=>f)}):c(null)},[l]);const a=u.useCallback(f=>{i(f),Sn(f),n==null||n(f)},[n]),p=u.useMemo(()=>({locale:l,setLocale:a,messages:vn[l],converter:s}),[l,a,s]);return e.jsx(ze.Provider,{value:p,children:o})};function P(){const t=u.useContext(ze);return(t==null?void 0:t.messages)??_t}const Cn=2e3;function U(){const t=u.useContext(ze),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=u.useRef(new Map),i=u.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=u.useCallback(s=>{if(!s)return"";if(!o)return s;const c=r.current.get(s);if(c!==void 0)return c;const a=o(s);if(r.current.size>=Cn){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(s,a),a},[o]);return u.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function _e(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function In(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 zn(){return{id:"",name:"",url:"",type:"text",details:""}}const Ue=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=P(),[s,c]=u.useState(null),a=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],p=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],f=b=>i?i==="text"?b==="text"||b==="text+image":i==="image"?b==="image"||b==="text+image"||b==="physical":b===i:!0,x=t.map((b,_)=>({item:b,originalIndex:_})).filter(({item:b})=>f(b.type)),h=()=>{const b=zn();i&&(b.type=i),n([...t,b]),c(t.length)},d=b=>{n(t.filter((_,y)=>y!==b)),c(null)},m=(b,_,y)=>{const R=[...t];if(R[b]={...R[b],[_]:y},_==="url"&&!R[b].id){const z=In(y);z&&(R[b].id=z)}n(R)},S=(b,_,y)=>{const z={...t[b].metadata||{}};y?z[_]=y:delete z[_],m(b,"metadata",Object.keys(z).length>0?z:void 0)},g=(b,_)=>{const y=_.trim()?_.split(/[,,、]/).map(R=>R.trim()).filter(Boolean):void 0;m(b,"structure",y)},E=(b,_,y)=>{const z=t[b].coverage||{level:1,ranges:""};_==="level"?z.level=parseInt(y)||1:z.ranges=y,m(b,"coverage",z.ranges?z:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:_})=>{var y,R,z,j;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(s===_?null:_),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===_?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:_n(b.type),color:"#fff"},children:((y=a.find(v=>v.value===b.type))==null?void 0:y.label)||b.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${l.editor.resourcePlaceholder} ${_+1}`}),b.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:v=>v.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&b.url&&Tn(_,r==null?void 0:r[_],o,l),e.jsx("button",{onClick:v=>{v.stopPropagation(),d(_)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),s===_&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(b.type==="image"||b.type==="text+image")&&b.url&&Rn(b,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.type}),e.jsx("select",{value:b.type,onChange:v=>m(_,"type",v.target.value),style:{...le,flex:1},children:a.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value))})]}),e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:v=>m(_,"root_type",v.target.value),style:{...le,flex:1},children:p.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:v=>m(_,"id",v.target.value),placeholder:l.editor.idAutoExtract,style:{...le,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:v=>m(_,"name",v.target.value),placeholder:l.editor.resourceName,style:{...le,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:v=>m(_,"url",v.target.value),placeholder:l.editor.resourceUrl,style:le}),e.jsx("input",{type:"text",value:((R=b.structure)==null?void 0:R.join("、"))||"",onChange:v=>g(_,v.target.value),placeholder:l.editor.structurePlaceholder,style:le}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((z=b.coverage)==null?void 0:z.level)??"",onChange:v=>E(_,"level",v.target.value),placeholder:"1",style:{...le,width:"60px"}})]}),e.jsxs("label",{style:{...je,flex:1},children:[e.jsx("span",{style:Se,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((j=b.coverage)==null?void 0:j.ranges)||"",onChange:v=>E(_,"ranges",v.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...le,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:v=>m(_,"details",v.target.value),placeholder:l.editor.detailsPlaceholder,style:{...le,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:l.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(l.metadata).map(([v,L])=>{var T;return e.jsxs("label",{style:{...je,gap:"4px"},children:[e.jsx("span",{style:{...Se,minWidth:"56px"},children:L}),e.jsx("input",{type:"text",value:((T=b.metadata)==null?void 0:T[v])||"",onChange:$=>S(_,v,$.target.value),placeholder:L,style:{...le,flex:1}})]},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:l.action.addResource})]})]})};function _n(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Tn(t,n,o,r){const i=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:s=>{s.stopPropagation(),i||o(t,"")},disabled:i,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:l?r.download.completed:i?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":i?"⏳":"⬇"})}function Rn(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 le={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"},je={display:"flex",alignItems:"center",gap:"6px"},Se={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Ln={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function En(t){try{const n=new URL(t).hostname;return Ln[n]}catch{return}}const Ze={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},Bn=["text","image","text+image","physical"];function Wn(t){const n=l=>{const s=l.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const c=l.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const s=t[l];if(s.volumes&&s.volumes.length>0)continue;const c=n(s.name);if(!c)continue;const[a,p]=c,f=`${a}|${s.type}`;o.has(f)||o.set(f,{base:{...s,name:a,url:"",volumes:[]},volumes:[]}),o.get(f).volumes.push({volume:p,url:s.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((s,c)=>s.volume-c.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let s=0;s<t.length;s++)if(i.has(s)){const c=n(t[s].name);c&&`${c[0]}|${t[s].type}`==`${l.base.name}|${l.base.type}`&&i.delete(s)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const Ke=({items:t,groupByType:n=!0})=>{const o=P(),r=u.useMemo(()=>Wn(t||[]),[t]),i={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical};if(!r||r.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:r.map((s,c)=>e.jsx(Qe,{item:s},s.id||c))});const l=Bn.map(s=>({type:s,items:r.filter(c=>c.type===s)})).filter(s=>s.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:l.map(({type:s,items:c})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ze[s],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ze[s]}}),i[s],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",c.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:c.map((a,p)=>e.jsx(Qe,{item:a},a.id||p))})]},s))})},Xe=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},Rt=({value:t})=>{const o=P().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},$n=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Rt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function Pn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const i=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(i)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(i[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function An(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 Fn(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 Mn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Qe=({item:t})=>{var h;const n=P(),{convert:o}=U(),[r,i]=u.useState(!1),l=u.useMemo(()=>(t.url?En(t.url):void 0)||o(t.name),[t.url,t.name,o]),s=u.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(d=>({...d,url:d.url||Fn(d)})),[t.volumes]),c=s&&s.length>0,a=c?s.filter(d=>d.status!=="missing").length:0,p=c?s.length-a:0,f=t.expected_volumes??(c?s.length:0),x=t.color_mode?{...Mn[t.color_mode],label:n.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:Xe(t)||c?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:l}),x&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((h=t.metadata)==null?void 0:h.check_type)&&e.jsx(Rt,{value:t.metadata.check_type}),c&&e.jsxs("button",{onClick:()=>i(!r),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[a,"/",f,n.unit.volume,p>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",p]}),e.jsx("span",{style:{marginLeft:"4px"},children:r?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const d=An(t.metadata);return d?Pn(t.url,d):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),Xe(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(([d])=>d!=="check_type").map(([d,m])=>e.jsxs("span",{children:[n.metadata[d]||d,": ",$n(d,m,n,o)]},d)),t.details&&!c&&e.jsx("span",{children:o(t.details)}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),c&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:s.map(d=>{const m=d.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:d.url&&!m?e.jsx("a",{href:d.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:d.label||`${d.volume}`,children:d.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:m?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:m?"line-through":"none",opacity:m?.6:1,lineHeight:1.4},children:d.volume})},d.volume)})})]})},Lt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:s})=>{const c=P(),a=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"},m=e.jsxs("div",{onClick:i,title:p?c.mode.switchToOfficial:c.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"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[m,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:s,title:f||c.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:[m,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||c.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:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:s,title:f||c.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})]}),!a&&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})]})]})},$e="bim-search-history",et=10,tt=8;function we(){try{const t=localStorage.getItem($e);return t?JSON.parse(t):[]}catch{return[]}}function Dn(t){try{const n=we().filter(o=>o!==t);n.unshift(t),n.length>et&&(n.length=et),localStorage.setItem($e,JSON.stringify(n))}catch{}}function Hn(t){try{const n=we().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function On(){try{localStorage.removeItem($e)}catch{}}const Et=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const s=P(),c=l??s.search.placeholder,a={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection},[p,f]=u.useState(!1),[x,h]=u.useState([]),[d,m]=u.useState(-1),[S,g]=u.useState(null),[E,b]=u.useState(we),_=u.useRef(null),y=u.useRef(null),R=u.useRef(null);u.useEffect(()=>{if(!t.getAllEntries)return;let k=!1;return t.getAllEntries().then(B=>{k||g(B)}).catch(()=>{}),()=>{k=!0}},[t]);const z=u.useCallback(k=>{if(!k.trim())return E.map(C=>({type:"history",text:C}));if(!S)return[];const B=k.toLowerCase(),w=[],A=[];for(const C of S){if(w.length+A.length>=tt*2)break;const W=(C.title??"").toLowerCase();if(W.startsWith(B))w.push({type:"entry",text:C.title,entry:C});else if(W.includes(B))A.push({type:"entry",text:C.title,entry:C});else{const N=[...C.additional_titles||[],...C.attached_texts||[]];for(const V of N){const M=typeof V=="string"?V:V==null?void 0:V.book_title;if(M!=null&&M.toLowerCase().includes(B)){w.push({type:"entry",text:`${C.title}`,entry:C});break}}}}return[...w,...A].slice(0,tt)},[S,E]);u.useEffect(()=>{h(z(n)),m(-1)},[n,z]),u.useEffect(()=>{const k=B=>{R.current&&!R.current.contains(B.target)&&f(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]),u.useEffect(()=>{const k=B=>{var w,A;if(B.key==="/"&&document.activeElement!==_.current){const C=(w=document.activeElement)==null?void 0:w.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT")return;B.preventDefault(),(A=_.current)==null||A.focus()}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[]);const j=u.useCallback(k=>{k.trim()&&(Dn(k.trim()),b(we())),r(k),f(!1)},[r]),v=u.useCallback(k=>{k.type==="history"?(o(k.text),j(k.text)):k.entry&&(i?(i(k.entry),f(!1)):(o(k.text),j(k.text)))},[o,j,i]),L=u.useCallback(k=>{if(!p||x.length===0){k.key==="Enter"&&j(n);return}switch(k.key){case"ArrowDown":k.preventDefault(),m(B=>(B+1)%x.length);break;case"ArrowUp":k.preventDefault(),m(B=>(B-1+x.length)%x.length);break;case"Enter":k.preventDefault(),d>=0&&d<x.length?v(x[d]):j(n);break;case"Escape":k.preventDefault(),f(!1);break}},[p,x,d,n,j,v]),T=u.useCallback((k,B)=>{B.stopPropagation(),Hn(k),b(we()),h(w=>w.filter(A=>!(A.type==="history"&&A.text===k)))},[]),$=u.useCallback(k=>{k.stopPropagation(),On(),b([]),h([])},[]);u.useEffect(()=>{if(d>=0&&y.current){const k=y.current.children;k[d]&&k[d].scrollIntoView({block:"nearest"})}},[d]);const H=!n.trim()&&E.length>0;return e.jsxs("div",{ref:R,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:_,type:"text",placeholder:c,value:n,onChange:k=>{o(k.target.value),f(!0)},onFocus:()=>f(!0),onKeyDown:L,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),p&&x.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[H&&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:$,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),x.map((k,B)=>e.jsxs("div",{onClick:()=>v(k),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:k.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.text}),k.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[k.entry.type],k.entry.edition&&` · ${k.entry.edition}`,k.entry.author&&` · ${k.entry.author}`]}),k.type==="history"&&e.jsx("button",{onClick:w=>T(k.text,w),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:"×"})]},`${k.type}-${k.text}-${B}`))]})]})},Ie="bim-recent-ids",nt="bim-recent-entries",ot=50,De=5,Un=50,Vn=200;function Ce(){try{const t=localStorage.getItem(Ie);if(t)return JSON.parse(t);const n=localStorage.getItem(nt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Ie,JSON.stringify(o)),localStorage.removeItem(nt),o}return[]}catch{return[]}}function Nn(t){try{const n=Ce().filter(o=>o!==t);n.unshift(t),n.length>ot&&(n.length=ot),localStorage.setItem(Ie,JSON.stringify(n))}catch{}}function Yn(t){try{const n=Ce().filter(o=>o!==t);localStorage.setItem(Ie,JSON.stringify(n))}catch{}}function Kn(){try{localStorage.removeItem(Ie)}catch{}}const Gn={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},Ve=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:p,initialQuery:f,onQueryChange:x,headerRight:h})=>{const d=P(),m=[{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"}],[S,g]=u.useState(f??""),[E,b]=u.useState(null),[_,y]=u.useState(null),[R,z]=u.useState(!1),[j,v]=u.useState(null),[L,T]=u.useState(""),[$,H]=u.useState(!f),[k,B]=u.useState(Ce),[w,A]=u.useState([]),[C,W]=u.useState(!1),[N,V]=u.useState(!1),[M,re]=u.useState(null),[Q,de]=u.useState(null),ue=u.useRef(void 0),xe=u.useRef(!1),G=u.useCallback(async(F,K)=>{if(!F.trim()){H(!0),b(null),y(null);return}H(!1),z(!0),T("");try{if(t.searchAll){const q=await t.searchAll(F,K??De);b(q)}else{const q=["work","book","collection"],J=await Promise.all(q.map(te=>t.search(F,te,{page:1,pageSize:K??De})));b({works:J[0].entries,books:J[1].entries,collections:J[2].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total})}}catch(q){T(q instanceof Error?q.message:String(q)),b(null)}finally{z(!1)}},[t]);u.useEffect(()=>{var I,D;let F=!1;const K=["work","book","collection"],q=Promise.all(K.map(Z=>t.loadEntries(Z,{page:1,pageSize:1}).catch(()=>({total:0})))),J=((I=t.getResourceCounts)==null?void 0:I.call(t).catch(()=>null))??Promise.resolve(null),te=((D=t.getSubtypeStats)==null?void 0:D.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([q,J,te]).then(([Z,ie,he])=>{F||(re({works:Z[0].total,books:Z[1].total,collections:Z[2].total,hasText:ie==null?void 0:ie.hasText,hasImage:ie==null?void 0:ie.hasImage}),he&&de(he))}),()=>{F=!0}},[t]),u.useEffect(()=>{xe.current||!(f!=null&&f.trim())||(xe.current=!0,G(f))},[f,G]);const Y=u.useCallback(F=>{if(g(F),x==null||x(F),!F.trim()){H(!0),b(null),y(null);return}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>{y(null),G(F)},Vn)},[G,x]),Pe=u.useCallback(F=>{ue.current&&clearTimeout(ue.current),x==null||x(F),G(F)},[G,x]),Ae=u.useCallback(F=>{y(F),G(S,Un)},[S,G]);u.useEffect(()=>{if(!k.length){A([]);return}let F=!1;return W(!0),Promise.all(k.slice(0,10).map(async K=>{var q,J,te;try{if(t.getEntry){const D=await t.getEntry(K);if(D)return D}const I=await t.getItem(K);if(I){const D=I.authors;return{id:K,title:I.title||K,type:I.type||"work",author:(q=D==null?void 0:D[0])==null?void 0:q.name,dynasty:(J=D==null?void 0:D[0])==null?void 0:J.dynasty,role:(te=D==null?void 0:D[0])==null?void 0:te.role,edition:I.edition||void 0}}}catch{}return{id:K,title:K,type:"work",notFound:!0}})).then(K=>{F||(A(K),W(!1))}),()=>{F=!0}},[k,t]);const ye=F=>{v(F.id),Nn(F.id),B(Ce()),r==null||r(F)},ve=F=>{Yn(F),B(Ce())},Fe=()=>{Kn(),B([])},Te=F=>m.find(K=>K.type===F),Me=E&&(E.works.length>0||E.books.length>0||E.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(Lt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:s,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Et,{transport:t,value:S,onChange:Y,onSearch:Pe,onEntrySelect:ye}),i&&e.jsx("button",{onClick:()=>i("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:d.action.newEntry})]}),M&&$&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()})]})}),M.hasImage!=null&&M.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:R?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):L?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:L})]}):$?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}):w.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:Fe,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:w.slice(0,N?10:3).map(F=>F.notFound?e.jsx(qn,{id:F.id,onRemove:ve,t:d},F.id):e.jsx(rt,{entry:F,selected:j===F.id,onClick:ye,getConfig:Te,onRemove:ve},F.id))}),!N&&w.length>3&&e.jsx("button",{onClick:()=>V(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:d.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Me?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:F,icon:K,name:q,key:J})=>{const te=E[J],I=Gn[J],D=E[I];if(te.length===0)return null;const ie=!(_===F)&&D>De;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[K," ",q,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[D," ",d.unit.items]})]}),ie&&e.jsx("button",{onClick:()=>Ae(F),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(he=>e.jsx(rt,{entry:he,selected:j===he.id,onClick:ye,getConfig:Te,query:S},he.id))})]},F)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:_e(d.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},rt=({entry:t,selected:n,onClick:o,getConfig:r,query:i,onRemove:l})=>{const s=P(),{convert:c}=U(),a=[...t.additional_titles||[],...t.attached_texts||[]],p=i&&a.length?a.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(i.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title)}),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:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,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:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]})]}),p&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[s.search.alias,":",c(p)]})]}),l?e.jsx("button",{onClick:f=>{f.stopPropagation(),l(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:"→"})]})},qn=({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:"×"})]}),Jn=["〇","一","二","三","四","五","六","七","八","九"],it=["","十","百","千"];function Bt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",i=!1;for(let l=0;l<o;l++){const s=parseInt(n[l]),c=o-1-l;s===0?i=!0:(i&&r&&(r+="〇"),i=!1,s===1&&c===1&&l===0?r+=it[c]:r+=Jn[s]+it[c])}return r}function Wt({type:t}){const n=P(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};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 Zn({isDraft:t}){const n=P();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function Xn({id:t}){const n=P(),[o,r]=u.useState(!1),i=()=>{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:i,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ne({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function se({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 $t({authors:t,type:n}){const{convert:o}=U();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,i)=>e.jsxs("span",{children:[i>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",o(r.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:o(r.name)}),r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",o(r.role)]})]},i))})}function ae({id:t,label:n,onNavigate:o,renderLink:r}){const i=ce();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.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:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Qn({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:s,meta:c,headerExtra:a}){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}),s&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Wt,{type:r}),e.jsx(Zn,{isDraft:i}),e.jsx(Xn,{id:t})]}),((l==null?void 0:l.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx($t,{authors:l,type:r}),c]})]})}function Pt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:i}){const l=P(),{convert:s}=U();if(!t.length)return null;const[c,a]=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=c===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:()=>a(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&&o&&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(ae,{id:p.source_bid,label:l.action.view,onNavigate:r,renderLink:i})})]}),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(se,{label:l.label.titleInfo,children:s(p.title_info)}),p.author_info&&e.jsx(se,{label:l.label.authorInfo,children:s(p.author_info)}),p.edition&&e.jsx(se,{label:l.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:l.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:l.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:l.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 eo({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(Pt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function At({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(Pt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Ft({label:t,items:n}){const{convert:o}=U();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,i)=>{const l=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(l)},i)})})]}):null}function to({items:t}){const n=P();return e.jsx(Ft,{label:n.section.aliases,items:t})}function no({items:t}){const n=P();return e.jsx(Ft,{label:n.section.attachedTexts,items:t})}function oo({items:t}){const n=P(),{convert:o}=U();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,i)=>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]})]},i))})]}):null}function ro({items:t}){const n=P(),{convert:o}=U();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,i)=>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)})]},i))]})]}):null}function io({items:t}){const n=P(),{convert:o}=U();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,i)=>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)]},i))})]}):null}function lt({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=U(),[s,c]=u.useState([]);return u.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(p=>({id:p})));return}let a=!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=>{a||c(p)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(s.length?s:n.map(a=>({id:a}))).map(a=>{const p=a.edition?`${l(a.title)||a.id}(${l(a.edition)})`:l(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ae,{id:a.id,label:p,onNavigate:r,renderLink:i})},a.id)})})]}):null}function lo({book:t,onNavigate:n,renderLink:o}){const r=P(),{convert:i}=U(),[l,s]=u.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?i(t.edition):i(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:c&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ae,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&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:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Ke,{items:t.resources,groupByType:!0})})]})}function so({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=P(),[l,s]=u.useState([]);return u.useEffect(()=>{if(!t.length){s([]);return}if(!n){s(t.map(a=>({id:a})));return}let c=!1;return Promise.all(t.map(a=>n.getItem(a).then(p=>({id:a,title:p?p.title:void 0,edition:p?p.edition:void 0,resources:p?p.resources:void 0})).catch(()=>({id:a})))).then(a=>{c||s(a)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[i.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:(l.length?l:t.map(c=>({id:c}))).map(c=>e.jsx(lo,{book:c,onNavigate:o,renderLink:r},c.id))})]}):null}function ao({workData:t,onNavigate:n,renderLink:o}){var l,s,c;const r=P(),{convert:i}=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(Wt,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ae,{id:t.id,label:i(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:i(t.measure_info)}):((l=t.juan_count)==null?void 0:l.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Bt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx($t,{authors:t.authors,type:"work"}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(c=t.authors)!=null&&c.length?"8px 0 0":"0",textAlign:"justify"},children:i(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(se,{label:r.label.parentWork,children:e.jsx(ae,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function co({items:t,onNavigate:n,renderLink:o}){const r=P(),{convert:i}=U();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>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(ae,{id:l.id,label:i(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:_e(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Ge=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:s,style:c})=>{var $,H,k,B,w,A;const a=P(),{convert:p}=U(),[f,x]=u.useState(null),[h,d]=u.useState(!1),[m,S]=u.useState(null),[g,E]=u.useState(null),[b,_]=u.useState([]),y=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let C=!1;return d(!0),S(null),o.getItem(n).then(W=>{C||(W?x(W):S(a.misc.notFoundEntry))}).catch(W=>{C||S(W instanceof Error?W.message:a.misc.loadFailed)}).finally(()=>{C||d(!1)}),()=>{C=!0}},[t,n,o]),u.useEffect(()=>{if(!y||!o){E(null),_([]);return}let C=!1;const W=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(W?o.getItem(W).then(N=>{!C&&N&&N.type==="work"&&E(N)}).catch(()=>{}):E(null),y.type==="book"){const N=y;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(V=>{const M=typeof V=="string"?V:V.id,re=typeof V=="string"?void 0:V.volume_index;return o.getItem(M).then(Q=>({id:M,title:Q&&Q.title||M,volume_index:re})).catch(()=>({id:M,title:M,volume_index:re}))})).then(V=>{C||_(V)}):_([])}else _([]);return()=>{C=!0}},[y,o]),h)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((C,W)=>e.jsx("div",{style:{height:W===1?"32px":"16px",width:`${C}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},W))})});if(m)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:m});if(!y)return null;const R=y.type==="book"?y:null,z=y.type==="collection"?y:null,j=y.type==="work"?y:null;let v=!1;try{v=O.extractStatus(y.id)==="draft"}catch{}let L="";y.measure_info?L=p(y.measure_info):($=y.juan_count)!=null&&$.number?L=Bt(y.juan_count.number)+a.unit.juan:(H=y.juan_count)!=null&&H.description&&(L=p(y.juan_count.description));const T=[];return(k=y.publication_info)!=null&&k.year&&T.push(e.jsx(se,{label:a.label.year,children:y.publication_info.year},"year")),(B=y.current_location)!=null&&B.name&&T.push(e.jsx(se,{label:a.label.currentLocation,children:p(y.current_location.name)},"loc")),(w=y.page_count)!=null&&w.description&&T.push(e.jsx(se,{label:a.label.pageCount,children:y.page_count.description},"page")),R!=null&&R.edition&&T.push(e.jsx(se,{label:a.label.edition,children:p(R.edition)},"ver")),j!=null&&j.parent_work&&T.push(e.jsx(se,{label:a.label.parentWork,children:e.jsx(ae,{id:j.parent_work.id,label:p(j.parent_work.title),onNavigate:r,renderLink:i})},"pw")),j!=null&&j.parent_works&&j.parent_works.length>0&&!j.parent_work&&T.push(e.jsx(se,{label:a.label.parentWork,children:j.parent_works.map((C,W)=>e.jsxs("span",{children:[W>0&&"、",e.jsx(ae,{id:C,onNavigate:r,renderLink:i})]},C))},"pws")),e.jsxs("div",{className:s,style:c,children:[e.jsx(Qn,{id:y.id,title:p(y.title),edition:y.edition?p(y.edition):void 0,type:y.type,isDraft:v,authors:y.authors,volumeText:L,meta:T,headerExtra:l}),((A=y.description)==null?void 0:A.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:p(y.description.text)}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.containedIn}),e.jsx(co,{items:b,onNavigate:r,renderLink:i})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.belongsToWork}),e.jsx(ao,{workData:g,onNavigate:r,renderLink:i})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(oo,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(to,{items:y.additional_titles}),y.attached_texts&&y.attached_texts.length>0&&e.jsx(no,{items:y.attached_texts}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(eo,{items:y.indexed_by,onNavigate:r,renderLink:i}),y.emendated_by&&y.emendated_by.length>0&&e.jsx(At,{items:y.emendated_by,onNavigate:r,renderLink:i}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.resources}),e.jsx(Ke,{items:y.resources,groupByType:!0})]}),(R==null?void 0:R.location_history)&&R.location_history.length>0&&e.jsx(ro,{items:R.location_history}),(z==null?void 0:z.history)&&z.history.length>0&&e.jsx(io,{items:z.history}),(R==null?void 0:R.related_books)&&R.related_books.length>0&&e.jsx(lt,{title:a.section.relatedVersions,ids:R.related_books,transport:o,onNavigate:r,renderLink:i}),(z==null?void 0:z.books)&&z.books.length>0&&e.jsx(lt,{title:a.section.containedBooks,ids:z.books,transport:o,onNavigate:r,renderLink:i}),(z==null?void 0:z.contained_works)&&z.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[a.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",z.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:z.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(ae,{id:C.id,label:p(C.title),onNavigate:r,renderLink:i})},C.id))})]}),(j==null?void 0:j.books)&&j.books.length>0&&e.jsx(so,{ids:j.books,transport:o,onNavigate:r,renderLink:i}),(j==null?void 0:j.related_works)&&j.related_works.length>0&&(()=>{const C=[],W=j.related_works.filter(M=>M.relation==="part_of"),N=j.related_works.filter(M=>M.relation==="has_part"),V=j.related_works.filter(M=>!M.relation);return W.length>0&&C.push({label:a.section.belongsToWork,items:W}),N.length>0&&C.push({label:a.section.containedWorks,items:N}),V.length>0&&C.push({label:a.section.relatedWorks,items:V}),C.map(M=>e.jsxs("div",{children:[e.jsxs(ne,{children:[M.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",M.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:M.items.map(re=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ae,{id:re.id,label:p(re.title),onNavigate:r,renderLink:i})},re.id))})]},M.label))})()]})};function po({data:t}){const n=P(),{convert:o}=U(),{stats:r}=t,i=r.processed_volumes??r.total_found_volumes,l=i!=null&&t.total_volumes>0?Math.round(i/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]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",l,"%)"]}),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 xo({sections:t,activeSection:n,onSelect:o}){const r=P();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:st(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:st(n===i.name),children:[i.name,i.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function st(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function uo({id:t,label:n,onNavigate:o,renderLink:r}){const i=ce();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:i(t),onClick:l=>{l.metaKey||l.ctrlKey||(l.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:l=>l.currentTarget.style.borderBottomStyle="solid",onMouseLeave:l=>l.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function fo(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 at({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=P(),{convert:l}=U(),s=t.book_id||t.work_id,c=r&&t.volumes.length>0?fo(t.volumes,i.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[l(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=>l(p)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),s&&e.jsx(uo,{id:s,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!s&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const Mt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:s})=>{const c=P(),[a,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[m,S]=u.useState(null),[g,E]=u.useState(""),b=t||a;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let j=!1;return x(!0),d(null),o.getCollectionCatalog(n).then(v=>{j||(v?p(v):d(c.catalog.notFound))}).catch(v=>{j||d(v instanceof Error?v.message:c.catalog.loadFailed)}).finally(()=>{j||x(!1)}),()=>{j=!0}},[t,n,o,c]);const _=(b==null?void 0:b.sections)&&b.sections.length>0,y=u.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const j=b.books.map(L=>L.volumes[0]).filter(L=>L!=null);return new Set(j).size<j.length},[b]),R=u.useMemo(()=>{if(!b)return[];let j=b.books;if(m&&(j=j.filter(v=>v.section===m)),g.trim()){const v=g.trim().toLowerCase();j=j.filter(L=>L.title.toLowerCase().includes(v)||L.sub_items&&L.sub_items.some(T=>T.toLowerCase().includes(v))||L.edition&&L.edition.toLowerCase().includes(v))}return j},[b,m,g]),z=u.useMemo(()=>{if(!y)return null;const j=[],v=new Map;for(const T of R){if(!T.volumes||T.volumes.length===0)continue;const $=T.volumes[0];v.has($)||v.set($,[]),v.get($).push(T)}const L=[...v.keys()].sort((T,$)=>T-$);for(const T of L)j.push({volume:T,books:v.get(T)});return j},[R,y]);return f?e.jsx("div",{className:l,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):h?e.jsx("div",{className:l,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):b?e.jsxs("div",{className:l,style:s,children:[e.jsx(po,{data:b}),_&&e.jsx(xo,{sections:b.sections,activeSection:m,onSelect:S}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:j=>E(j.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:[R.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[z?z.map((j,v)=>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:_e(c.catalog.volume,{n:j.volume})}),j.books.map((L,T)=>e.jsx(at,{book:L,onNavigate:r,renderLink:i,showVolumes:L.volumes.length>1},`${j.volume}-${T}`))]},`${j.volume}-${v}`)):R.map((j,v)=>e.jsx(at,{book:j,onNavigate:r,renderLink:i,showVolumes:!0},v)),R.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Dt={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},go={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},ho={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},ge=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Re=7,bo=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:i=280,wrapperStyle:l})=>{const[s,c]=u.useState(!1),[a,p]=u.useState(null),f=u.useRef(null),x=u.useRef(null),h=u.useRef(null),d=u.useCallback(()=>{const g=x.current,E=h.current;if(!g||!E)return;const b=g.getBoundingClientRect(),_=E.getBoundingClientRect(),y=window.innerHeight,R=document.documentElement.clientWidth;let z=o;o==="top"&&b.top-_.height-Re<8&&(z="bottom"),o==="bottom"&&b.bottom+_.height+Re>y-8&&(z="top");const j=z==="top"?b.top-_.height-Re:b.bottom+Re;let v=b.left+b.width/2-_.width/2;v=Math.max(8,Math.min(v,R-_.width-8)),p({left:v,top:j,placement:z})},[o]),m=u.useCallback(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>c(!0),r)},[r]),S=u.useCallback(()=>{f.current&&clearTimeout(f.current),c(!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:m,onMouseLeave:S,onFocus:m,onBlur:S,style:{display:"inline-block",...l},children:n}),s&&hn.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:i,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-X,width:0,height:0,...a.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,...a.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)]})},ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function mo(t){return typeof t!="string"?null:t in Dt?t:t in ct?ct[t]:null}const yo=["〇","一","二","三","四","五","六","七","八","九"],dt=["","十","百","千"],vo=["","萬","億"];function Ht(t){if(t===0)return"〇";if(t<0)return`負${Ht(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(jo(i,r>0)+vo[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function jo(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let i="";for(let l=0;l<o.length;l++){const s=o[l],c=o.length-1-l;s===0?i&&!i.endsWith("〇")&&(i+="〇"):s===1&&c===1&&l===0&&!n?i+=dt[c]:i+=yo[s]+dt[c]}return i.replace(/〇$/,"")}const qe={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},So={考证:"#5d6d7e"};function ko(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 Ot({file:t,isActive:n,onSelect:o}){return e.jsx("button",{onClick:()=>o(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:ko(t)})}function Ut(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Ut(r,n)))}function Vt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+Vt(l),0))||0;return n+o}function Nt({group:t,activeFile:n,onSelect:o,depth:r=0}){var p;const i=Ut(t,n||""),[l,s]=u.useState(i),c=Vt(t),a=!!((p=t.children)!=null&&p.length);if(u.useEffect(()=>{i&&s(!0)},[i]),t.files.length===1&&!a){const f=t.files[0],x=n===f;return e.jsx("button",{onClick:()=>o(f),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:x?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:x?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:x?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:x?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>s(!l),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:i?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:l?"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:["(",c,")"]})]}),l&&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(f=>e.jsx(Ot,{file:f,isActive:n===f,onSelect:o},f))}),a&&t.children.map((f,x)=>e.jsx(Nt,{group:f,activeFile:n,onSelect:o,depth:r+1},x))]})]})}function wo({files:t,groups:n,activeFile:o,onSelect:r}){const i=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((l,s)=>e.jsx(Nt,{group:l,activeFile:o,onSelect:r},s))}):i.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:i.map(l=>e.jsx(Ot,{file:l,isActive:o===l,onSelect:r},l))})}function Co({type:t}){const n=qe[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 Io({section:t,onNavigate:n}){const{convert:o}=U(),r=ce(),[i,l]=u.useState(!1),s=!!t.summary,c=!!t.comment,a=!!t.additional_comment,p=!!(t.content&&t.content.length>60),f=s||c||a||p,x=!i&&p?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:()=>f&&l(!i),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:f?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[f&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:i?"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?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ht(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:o(t.author_info||t.author)})]}),!i&&x&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:o(x)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(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:r(t.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),h.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),i&&f&&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:o(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:o(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:o(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:o(t.additional_comment)})]}),p&&!s&&!c&&!a&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(t.content)})]})]})}function zo({section:t}){const{convert:n}=U(),[o,r]=u.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(Co,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),i&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${qe[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:n(t.content)})})]})}function _o({section:t}){const{convert:n}=U();if(!t.content&&!t.title)return null;const o=n((t.content||t.title||"").replace(/\n{2,}/g,`
2
- `)),r=qe[t.type]||"#717171",i=t.type==="序"||t.type==="结语";return e.jsxs("div",{style:{padding:i?"10px 12px":"6px 0",margin:i?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:i?`3px solid ${r}40`:void 0,background:i?"var(--bim-bg, #fafafa)":void 0,borderRadius:i?"0 4px 4px 0":void 0,position:"relative"},children:[i&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:r,marginRight:"8px",padding:"1px 5px",border:`1px solid ${r}40`,borderRadius:"2px",background:`${r}08`,verticalAlign:"middle"},children:t.type}),o]})}function To(t,n,o){const[r,i]=u.useState({});return u.useEffect(()=>{var p;if(!n||t.length===0)return;let l=!1;const s=t.filter(f=>{var x;return!((x=o==null?void 0:o.current)!=null&&x.has(f))}),c={};for(const f of t)(p=o==null?void 0:o.current)!=null&&p.has(f)&&(c[f]=o.current.get(f));if(Object.keys(c).length>0&&i(c),s.length===0)return;const a=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,m=h.authors,S=(x=m==null?void 0:m[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 a(f);return(h=o==null?void 0:o.current)==null||h.set(f,x),[f,x]})).then(f=>{l||i(x=>{const h={...x};for(const[d,m]of f)h[d]=m;return h})}),()=>{l=!0}},[t.join(","),n]),r}function Ro({section:t,onNavigate:n,transport:o,workLabelCache:r}){const{convert:i}=U(),l=ce(),[s,c]=u.useState(!1),a=t.type,p=So[a]||"#717171",f=!!t.content,x=t.work_ids||[],h=x.length>1,d=To(h?x:[],o,r),m=f&&!s&&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:()=>f&&c(!s),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:f?"pointer":"default",userSelect:"none"},children:[f&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:s?"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?i(t.header_line):i(t.title)}),!s&&m&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:i(m)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[x.length===1&&n&&e.jsx("a",{href:l(x[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(x[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),h&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[x.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:p,border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`},children:a})]})]}),h&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:x.map(S=>{const g=d[S],E=g?`${i(g.title)}${g.author?`(${i(g.author)})`:""}`:S.slice(0,8)+"…";return e.jsxs("a",{href:l(S),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),b.stopPropagation(),n(S))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:S,children:["→",E]},S)})}),s&&f&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${p}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:i(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:i(t.comment)})]})]})}function Lo({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:i}){const{convert:l}=U(),s=u.useMemo(()=>{if(!n.trim())return t.sections;const a=n.trim().toLowerCase();return t.sections.filter(p=>{var f,x,h;return((f=p.title)==null?void 0:f.toLowerCase().includes(a))||((x=p.content)==null?void 0:x.toLowerCase().includes(a))||((h=p.comment)==null?void 0:h.toLowerCase().includes(a))})},[t.sections,n]),c=s.filter(a=>a.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:l(t.title)}),c>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[c," 條"]})]}),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:s.map((a,p)=>e.jsx(Ro,{section:a,onNavigate:o,transport:r,workLabelCache:i},p))}),s.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Eo({sections:t,onNavigate:n}){const{convert:o}=U(),r=ce(),i=[];let l=null;for(const s of t)s.type==="类"?(l&&i.push(l),l={category:s.title,categoryContent:s.content||void 0,items:[]}):s.type==="书"?(l||(l={category:"",items:[]}),l.items.push(s)):(s.type==="序"||s.type==="结语")&&(l||(l={category:"",items:[]}),l.items.push(s),s.type==="结语"&&(i.push(l),l=null));return l&&i.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((s,c)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[s.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[o(s.category),s.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:o(s.categoryContent)})]}),s.items.map((a,p)=>a.type==="序"||a.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},p):(a.content?a.title+a.content:a.title,e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&a.work_id?e.jsx("a",{href:r(a.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),f.stopPropagation(),n(a.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(a.title),children:e.jsx("strong",{children:o(a.title)})}):e.jsx("strong",{children:o(a.title)}),a.content&&o(a.content)]},p)))]},c))})}function Bo({juan:t,searchQuery:n,onNavigate:o}){const{convert:r}=U(),[i,l]=u.useState("catalog"),s=u.useMemo(()=>{if(!n.trim())return t.sections;const p=n.trim().toLowerCase();return t.sections.filter(f=>{var x,h,d,m,S,g;return((x=f.title)==null?void 0:x.toLowerCase().includes(p))||((h=f.book_title)==null?void 0:h.toLowerCase().includes(p))||((d=f.author)==null?void 0:d.toLowerCase().includes(p))||((m=f.author_info)==null?void 0:m.toLowerCase().includes(p))||((S=f.summary)==null?void 0:S.toLowerCase().includes(p))||((g=f.content)==null?void 0:g.toLowerCase().includes(p))})},[t.sections,n]),c=s.filter(p=>p.type==="书").length,a=s.filter(p=>p.type==="詩").length;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:r(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(p=>e.jsx("button",{onClick:()=>l(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:i===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:i===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:a>0?`${a} 首`:`${c} 部书`})]}),i==="raw"&&e.jsx(Eo,{sections:s,onNavigate:o}),i==="catalog"&&s.map((p,f)=>p.type==="书"||p.type==="詩"?e.jsx(Io,{section:p,onNavigate:o},f):p.type==="类"?e.jsx(zo,{section:p},f):e.jsx(_o,{section:p},f)),s.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Yt(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 pt(t){const n=Yt(t);return n.length>0?n[0]:null}const Kt=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:i,onJuanChange:l,className:s,style:c})=>{const[a,p]=u.useState(null),[f,x]=u.useState(!1),[h,d]=u.useState(null),[m,S]=u.useState(null),[g,E]=u.useState(null),[b,_]=u.useState(!1),[y,R]=u.useState(""),z=u.useRef(new Map),j=i??m,v=u.useCallback(w=>{S(w),l==null||l(w)},[l]),L=t||a;u.useEffect(()=>{t&&(x(!1),d(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let w=!1;return x(!0),d(null),o.getCollatedEditionIndex(n).then(A=>{if(!w)if(!A)d("未找到整理本数据");else{p(A);const C=pt(A);!i&&C&&v(C)}}).catch(A=>{w||d(A instanceof Error?A.message:"加载失败")}).finally(()=>{w||x(!1)}),()=>{w=!0}},[t,n,o,i,v]),u.useEffect(()=>{const w=t||a;if(w&&!j){const A=pt(w);A&&v(A)}},[t,a,j,v]);const T=n||(L==null?void 0:L.work_id),$=u.useCallback(async w=>{if(!(!T||!(o!=null&&o.getCollatedJuan))){_(!0),E(null);try{const A=await o.getCollatedJuan(T,w);E(A)}catch{E(null)}finally{_(!1)}}},[T,o]);u.useEffect(()=>{j&&$(j)},[j,$]);const H=w=>{v(w),R("")};if(f)return e.jsx("div",{className:s,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:s,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!L)return null;const k=L.type==="kaozhen",B=Yt(L);return e.jsxs("div",{className:s,style:c,children:[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:k?e.jsxs(e.Fragment,{children:[L.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:L.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:B.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:L.total_juan})," 卷"]})}),L.text_quality&&(()=>{const w=mo(L.text_quality.grade);return w?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(bo,{content:go[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:ho[w],cursor:"help"},children:Dt[w]})}),L.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",L.text_quality.source_note]})]}):null})()]}),e.jsx(wo,{files:B,groups:L.juan_groups,activeFile:j,onSelect:H}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:k?"搜索条目、考证内容...":"搜索书名、作者...",value:y,onChange:w=>R(w.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),b?e.jsx(ge,{}):g?k?e.jsx(Lo,{juan:g,searchQuery:y,onNavigate:r,transport:o,workLabelCache:z}):e.jsx(Bo,{juan:g,searchQuery:y,onNavigate:r}):j?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,L.references&&L.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:"參考文獻"}),L.references.map((w,A)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[A+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]})]},A))]})]})},Wo={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},$o={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Po(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 Gt=({items:t,loading:n})=>{const o=ce();return n?e.jsx(ge,{}):t.length===0?e.jsx("div",{style:Ao,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const i=Wo[r.type],l=$o[r.status];return e.jsxs("div",{style:Fo,children:[e.jsxs("div",{style:Mo,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...xt,background:i.color},children:i.label}),e.jsx("span",{style:{...xt,background:l.color},children:l.label})]}),e.jsx("span",{style:Do,children:Po(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Ho,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:ut,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:ut,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Oo,children:r.content}),r.reply&&e.jsxs("div",{style:Uo,children:[e.jsx("div",{style:Vo,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ao={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Fo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Mo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Do={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Ho={fontSize:"12px",marginBottom:"6px"},ut={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Oo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Uo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Vo={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Ne=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:i,feedbackApiUrl:l})=>{const s=P(),[c,a]=u.useState(null),[p,f]=u.useState([]),[x,h]=u.useState("recommend"),[d,m]=u.useState([]),[S,g]=u.useState(!1),E=r??x,b=T=>{h(T),i==null||i(T)},[_,y]=u.useState(!0),[R,z]=u.useState(null),[j,v]=u.useState(null);u.useEffect(()=>{if(!t.getAllEntries)return;let T=!1;return t.getAllEntries().then($=>{if(T)return;const H=$.filter(w=>w.type==="work").length,k=$.filter(w=>w.type==="book").length,B=$.filter(w=>w.type==="collection").length;a({works:H,books:k,collections:B})}).catch(()=>{}),()=>{T=!0}},[t]),u.useEffect(()=>{let T=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const H=await t.getRecommended();if(H!=null&&H.groups)return H.groups.flatMap(k=>k.items.map(B=>({...B,group:k.name})))}catch{}return[]})().then(async H=>{if(T)return;const k=H.filter(w=>w.id);if(k.length===0){y(!1);return}const B=await Promise.all(k.map(async w=>{try{let A=null;if(t.getEntry)A=await t.getEntry(w.id);else{const C=await t.getItem(w.id);C&&(A={id:w.id,title:C.title||w.id,type:C.type||"work"})}if(A)return{...A,group:w.group,fallbackDescription:w.description}}catch{}return{id:w.id,title:w.title,type:O.extractType(w.id),group:w.group,fallbackDescription:w.description}}));T||(f(B.filter(w=>w!==null)),y(!1))}),()=>{T=!0}},[t,o]),u.useEffect(()=>{if(!t.getResourceProgress)return;let T=!1;return t.getResourceProgress().then($=>{T||z($)}).catch(()=>{}),()=>{T=!0}},[t]),u.useEffect(()=>{if(!t.getSiteProgress)return;let T=!1;return t.getSiteProgress().then($=>{T||v($)}).catch(()=>{}),()=>{T=!0}},[t]),u.useEffect(()=>{if(!l||E!=="feedback")return;let T=!1;return g(!0),fetch(l).then($=>$.json()).then($=>{!T&&$.success&&m($.items||[])}).catch(()=>{}).finally(()=>{T||g(!1)}),()=>{T=!0}},[l,E]);const L=T=>{switch(T){case"work":return"✍️";case"book":return"📖";case"collection":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(Le,{label:s.home.recommendTab,active:E==="recommend",onClick:()=>b("recommend")}),e.jsx(Le,{label:s.home.catalogTab,active:E==="catalog",onClick:()=>b("catalog")}),e.jsx(Le,{label:s.home.siteTab,active:E==="site",onClick:()=>b("site")}),l&&e.jsx(Le,{label:s.home.feedbackTab,active:E==="feedback",onClick:()=>b("feedback")})]}),E==="recommend"&&e.jsx(No,{recommended:p,loading:_,onNavigate:n,getIcon:L,t:s}),E==="catalog"&&e.jsx(Yo,{progress:R,t:s,onNavigate:n}),E==="site"&&e.jsx(Go,{progress:j,t:s,totalWorks:(c==null?void 0:c.works)??0}),E==="feedback"&&l&&e.jsx(Gt,{items:d,loading:S})]})})},Le=({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}),No=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:i})=>{const l=ce();if(n)return e.jsx(ge,{});if(t.length===0)return null;const s=new Map;for(const c of t){const a=c.group||i.home.recommendedBrowse;s.has(a)||s.set(a,[]),s.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(s.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(p=>{const f=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return e.jsxs("a",{href:l(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)})})]},c))})},Yo=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),i=["in_progress","done","todo"],l={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:i.map(c=>{const a=r.filter(p=>p.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:s[c]}}),l[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(p=>e.jsx(Ko,{item:p,t:n,statusColor:s[c],onNavigate:o},p.id))})]},c)})})},Ko=({item:t,t:n,statusColor:o,onNavigate:r})=>{const i=ce(),l=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 c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:i(a),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(a))},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:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:s})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?_e(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:`${l}%`,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})]})},Go=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((a,p)=>a.priority-p.priority),i=r.filter(a=>a.imported>0),l=r.filter(a=>a.imported===0),s=i.reduce((a,p)=>Math.max(a,p.imported),0),c=o>0?Math.round(s/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:s.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),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:"#10b981"}}),n.home.statusInProgress," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]}),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:"#9ca3af"}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]})]})},ft=({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})]})},gt="(max-width: 768px)";function qo(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(gt).matches);return u.useEffect(()=>{const o=window.matchMedia(gt),r=i=>n(i.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Jo=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:i})=>{var A;const l=P(),{convert:s}=U(),c=qo(),[a,p]=u.useState(null),[f,x]=u.useState(null),[h,d]=u.useState(!1),[m,S]=u.useState("detail"),[g,E]=u.useState([]),[b,_]=u.useState(!1),[y,R]=u.useState(null),[z,j]=u.useState(!1),v=u.useCallback(async C=>{if(!t.getCollatedEditionIndex){R(null);return}j(!0);try{const W=await t.getCollatedEditionIndex(C);R(W)}catch{R(null)}finally{j(!1)}},[t]),L=u.useCallback(async C=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){E([]);return}_(!0);try{if(t.getCollectionCatalogs){const W=await t.getCollectionCatalogs(C);E(W||[])}else if(t.getCollectionCatalog){const W=await t.getCollectionCatalog(C);E(W?[{resource_id:"",data:W}]:[])}}catch{E([])}finally{_(!1)}},[t]),T=u.useCallback(async C=>{if(o){o(C);return}p(C),x(null),E([]),R(null),S("detail"),d(!0);try{const W=await t.getItem(C.id);W&&(x(W),W.type==="collection"?L(C.id):W.type==="work"&&W.has_collated&&v(C.id))}catch(W){console.error("加载详情失败:",W)}finally{d(!1)}},[t,o,L,v]),$=u.useCallback(async C=>{x(null),E([]),R(null),S("detail"),d(!0);try{const W=await t.getItem(C);W&&(x(W),p({id:C,title:W.title||C,type:W.type||"book"}),W.type==="collection"?L(C):W.type==="work"&&W.has_collated&&v(C))}catch(W){console.error("导航失败:",W)}finally{d(!1)}},[t,L,v]),H=(f==null?void 0:f.type)==="collection"&&(g.length>0||b)||(f==null?void 0:f.type)==="work"&&(y||z),k=c&&(h||f),B=u.useCallback(()=>{p(null),x(null),E([]),R(null),S("detail")},[]),w=e.jsx(e.Fragment,{children:h?e.jsx(ge,{}):f?e.jsxs(e.Fragment,{children:[(H||i)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[H&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>S("detail"),style:Ee(m==="detail"),children:l.detailTab.basicInfo}),f.type==="collection"&&b&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:Ee(!1),children:[l.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:Ee(m===`catalog:${C.resource_id}`),children:C.short_name?`${s(C.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},C.resource_id)),f.type==="work"&&(y||z)&&e.jsxs("button",{onClick:()=>S("collated"),style:Ee(m==="collated"),children:[l.detailTab.collatedEdition,z&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),i&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:i})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:m==="detail"?e.jsx(Ge,{data:f,transport:t,onNavigate:$}):m.startsWith("catalog:")?e.jsx(Mt,{data:(A=g.find(C=>`catalog:${C.resource_id}`===m))==null?void 0:A.data,onNavigate:$}):m==="collated"?e.jsx(Kt,{index:y||void 0,workId:f.id,transport:t,onNavigate:$}):null})]}):e.jsx(Ne,{transport:t,onNavigate:$,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:k?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick: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:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:w})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ve,{transport:t,onEntryClick:T,hideModeIndicator:n}),!f&&e.jsx(Ne,{transport:t,onNavigate:$,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(Ve,{transport:t,onEntryClick:T,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:w})]})};function Ee(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 Zo=({data:t,onNavigate:n,className:o,style:r})=>{var f;const i=P(),{convert:l}=U(),[s,c]=u.useState(((f=t.divisions[0])==null?void 0:f.name)??null),[a,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:l(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:[i.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",i.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",i.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",i.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(Xo,{division:x,expanded:s===x.name,onToggle:()=>c(s===x.name?null:x.name),expandedCat:a,onCatToggle:h=>p(a===h?null:h),onNavigate:n},x.name))})]})},Xo=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:i,onNavigate:l})=>{const{convert:s}=U(),c=t.categories.reduce((a,p)=>{const f=p.stats||{zhulu:0,cunmu:0};return a+(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:s(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const p=`${t.name}/${a.name}`;return e.jsx(Qo,{category:a,expanded:r===p,onToggle:()=>i(p),onNavigate:l},a.name)})})]})},Qo=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,p,f,x;const{convert:i}=U(),l=((a=t.books)==null?void 0:a.zhulu)||[],s=((p=t.books)==null?void 0:p.cunmu)||[],c=(((f=t.stats)==null?void 0:f.zhulu)||l.length)+(((x=t.stats)==null?void 0:x.cunmu)||s.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:[i(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||s.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(ht,{label:"著錄",books:l,onNavigate:r}),s.length>0&&e.jsx(ht,{label:"存目",books:s,onNavigate:r})]})]})},ht=({label:t,books:n,onNavigate:o})=>{const{convert:r}=U(),i=ce(),[l,s]=u.useState(n.length<=20),c=l?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,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:a.work_id&&o?e.jsx("a",{href:i(a.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},p))}),!l&&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:o,extraButtons:r,children:i})=>{const l=P();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:tr,children:"AI"}),n&&e.jsx("button",{onClick:n,style:er,children:l.action.save})]})]}),i]})},er={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},tr={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:o,placeholder:r,disabled:i})=>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:l=>o(l.target.value),placeholder:r,disabled:i,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"}})]}),fe=({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:i=>n(i.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"}})},We=({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 nr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Be=({value:t,onChange:n,label:o})=>{const[r,i]=u.useState(!1),l=u.useRef(null),s=nr(t||"");return u.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&s?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsxs("div",{onClick:()=>i(!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(We,{children:s.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>i(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},bt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function or(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function rr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const qt=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=P(),[i,l]=u.useState(null),s=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},c=x=>{n(t.filter((h,d)=>d!==x)),i===x&&l(null)},a=(x,h,d)=>{const m=[...t];m[x]={...m[x],[h]:d},n(m)},p=(x,h)=>{const d=[...t];d[x]={...d[x],type:h,id:"",name:""},n(d),h==="bookID"&&o&&o(m=>{const S=[...t];S[x]={...S[x],id:m.id,name:m.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:()=>l(i===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===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:or(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:rr(x.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),c(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),i===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:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...mt,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:{...mt,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:pe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:yt,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:pe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:yt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>a(h,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:d=>a(h,"id",d.target.value),placeholder:"https://...",style:be})]})]}),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:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>a(h,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:d=>a(h,"position",d.target.value),placeholder:"如: 卷三, p.52",style:be})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:d=>a(h,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:d=>a(h,"processor_version",d.target.value),placeholder:"如: v0.1",style:be})]})]})]})]})})]},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:r.action.addSource})]})]})},pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},be={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"},mt={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"},yt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Jt(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 Zt(t){return!t||t.length===0?"":JSON.stringify(t)}const Xt=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:i,belongsToWork:l,belongsToCollection:s,childWorks:c,childCollections:a,containedBooks:p,siblingBooks:f,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:d,onCreateAndLink:m,onSaveRelations:S})=>{const g=P();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:g.section.relations})]}),S&&e.jsx("button",{onClick:S,style:ir,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.belongsToWork,entity:l,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>m("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(ke,{direction:"up",title:g.relation.containedInCollection,entity:s,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>m("collectionId","collection",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),l&&f&&f.length>0&&e.jsx(me,{direction:"horizontal",title:`${g.relation.siblingVersions} (${f.length})`,entities:f,onView:d,onAdd:()=>m("siblingBook","book",{workId:l.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:g.relation.parentWork,entity:r,onView:d,onUnlink:()=>h("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>m("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),c&&c.length>0&&e.jsx(me,{direction:"down",title:`${g.relation.childWorks} (${c.length})`,entities:c,onView:d,onAdd:()=>m("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(me,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:d,onAdd:()=>m("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(me,{direction:"down",title:`${g.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>m("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(ke,{direction:"up",title:g.relation.correspondingWork,entity:l,onView:d,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>m("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(ke,{direction:"up",title:g.relation.parentCollection,entity:i,onView:d,onUnlink:()=>h("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>m("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(me,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:d,onAdd:()=>m("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(me,{direction:"down",title:`${g.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:d,onAdd:()=>m("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},ke=({direction:t,title:n,entity:o,onView:r,onUnlink:i,onLink:l,onCreate:s,linkLabel:c,createLabel:a,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:Qt(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(vt,{onClick:()=>r(o),title:f,children:"👁️"}),e.jsx(vt,{onClick:i,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(Ye,{onClick:l,children:c}),e.jsx(Ye,{onClick:s,primary:!0,children:a})]})]})},me=({direction:t,title:n,entities:o,onView:r,onAdd:i,addLabel:l,noneLabel:s,expandMoreLabel:c})=>{const[a,p]=u.useState(!1),f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color: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:Qt(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:s}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ye,{onClick:i,primary:!0,children:["+ ",l]})})]})},vt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:i=>{i.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}),Ye=({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 Qt(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const ir={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"},en=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:i,onCreate:l,searchResults:s,onSearch:c,isLoading:a,excludeId:p})=>{const[f,x]=u.useState(""),h=p?s.filter(g=>g.id!==p):s;u.useEffect(()=>{t&&(x(""),c(""))},[t]);const d=g=>{x(g),c(g)};if(!t)return null;const m=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:lr,children:e.jsxs("div",{style:sr,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:i,style:ar,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:f,onChange:g=>d(g.target.value),placeholder:`搜索${m}名称或 ID...`,autoFocus:!0,style:cr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:He,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:dr,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:He,children:["未找到匹配的",m]}):e.jsxs("div",{style:He,children:["输入关键词搜索",m]})}),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:l,style:pr,children:["创建新",m,"并关联"]})]})]})})},lr={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},sr={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)"},ar={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},cr={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"},dr={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},He={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"},jt={work:"作品",book:"书籍",collection:"丛编"},xr={work:"📜",book:"📖",collection:"📚"},tn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:i,onCancel:l})=>{const[s,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var h,d;(h=a.current)==null||h.focus(),(d=a.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&s.trim()?f():h.key==="Escape"&&l()},f=()=>{s.trim()&&i(s.trim(),{...r,title:s.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`创建新${jt[n]}`}};return e.jsx("div",{style:ur,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:fr,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:xr[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:a,type:"text",value:s,onChange:h=>c(h.target.value),onKeyDown:p,placeholder:`请输入${jt[n]}名称...`,style:gr})]}),((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:l,style:hr,children:"取消"}),e.jsx("button",{onClick:f,disabled:!s.trim(),style:{...br,opacity:s.trim()?1:.6,cursor:s.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},ur={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},fr={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)"},gr={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"},br={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function mr(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function nn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function yr(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const on=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:i,showCreateButton:l=!1,createButtonText:s,onSelect:c,onCancel:a,onCreate:p,onSearch:f})=>{const[x,h]=u.useState(""),[d,m]=u.useState([]),[S,g]=u.useState(!1),[E,b]=u.useState("recent");u.useEffect(()=>{t&&(h(""),m([]),b(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!x.trim()){m([]);return}const v=setTimeout(async()=>{g(!0);try{m(await f(x,o))}catch{m([])}finally{g(!1)}},300);return()=>clearTimeout(v)},[x,o,f]);const _=u.useCallback(v=>{h(v.target.value),v.target.value.trim()&&b("search")},[]),y=u.useCallback(v=>i?v.filter(L=>L.id!==i):v,[i]);if(!t)return null;const R=n||(o==="all"?"选择实体":`选择${nn(o)}`),z=y(r),j=y(d);return e.jsx("div",{style:jr,children:e.jsxs("div",{style:Sr,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:R}),e.jsx("button",{onClick:a,style:kr,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:_,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:wr}),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:"搜索中..."})]})}),z.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(St,{active:E==="recent",onClick:()=>b("recent"),children:["最近使用 (",z.length,")"]}),e.jsxs(St,{active:E==="search",onClick:()=>b("search"),children:["搜索结果 ",j.length>0&&`(${j.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:E==="recent"&&z.length>0?e.jsx(kt,{entities:z,onSelect:c}):x.trim()?S?e.jsx(Oe,{message:"搜索中..."}):j.length>0?e.jsx(kt,{entities:j,onSelect:c}):e.jsx(Oe,{message:"未找到匹配的结果"}):e.jsx(Oe,{message:"输入关键词开始搜索"})}),l&&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:Cr,children:s||"创建新实体"})]})]})})},St=({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}),kt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(vr,{entity:o,onClick:()=>n(o)},o.id))}),vr=({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:mr(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:yr(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:nn(t.type)})]})},Oe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),jr={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},Sr={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)"},kr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},wr={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"},Cr={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ir={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},zr={work:"📜",collection:"📚",book:"📖"},rn=({data:t,onChange:n,onSave:o,transport:r,onNavigate:i,showDelete:l,onDelete:s,onAskAI:c,renderSectionActions:a,onDownloadResource:p,downloadStatuses:f,relations:x,onRelationsChange:h})=>{var te;const d=P(),[m,S]=u.useState(!1),[g,E]=u.useState("work"),[b,_]=u.useState(""),[y,R]=u.useState(""),[z,j]=u.useState([]),[v,L]=u.useState(!1),[T,$]=u.useState(!1),[H,k]=u.useState("work"),[B,w]=u.useState(""),[A,C]=u.useState(),[W,N]=u.useState(!1),[V,M]=u.useState(null),[re,Q]=u.useState([]);u.useRef(null);const de=t.type,ue=de==="work",xe=de==="collection",G=de==="book",Y=u.useCallback((I,D)=>{n({...t,[I]:D})},[t,n]),Pe=u.useCallback((I,D)=>{_(I),E(D),R(d.editor.selectToLink+d.indexType[D]),j([]),S(!0)},[d]),Ae=u.useCallback(I=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,I)},[r,t.id]),ye=u.useCallback(I=>{i==null||i(I.id,I.type)},[i]),ve=u.useCallback((I,D,Z)=>{const ie={...Z,author:(Z==null?void 0:Z.author)||t.author,dynasty:(Z==null?void 0:Z.dynasty)||t.dynasty};k(D),w(I),C(ie),$(!0)},[t.author,t.dynasty]),Fe=u.useCallback((I,D)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,B,{type:H,title:I,inheritData:D}),$(!1)},[r,t.id,B,H]),Te=u.useCallback(I=>{if(!I.trim()){j([]);return}L(!0),r!=null&&r.searchEntities&&r.searchEntities(I,g).then(D=>{j(D),L(!1)}).catch(()=>{j([]),L(!1)})},[r,g]),Me=u.useCallback(I=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,I.id),S(!1)},[r,t.id,b]),F=u.useCallback(()=>{o()},[o]),K=u.useCallback(I=>{M(()=>I),N(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),q=u.useCallback((I,D)=>r!=null&&r.searchEntities?r.searchEntities(I,D==="all"?void 0:D):Promise.resolve([]),[r]),J=u.useCallback(I=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(I),Q(D=>[I,...D.filter(Z=>Z.id!==I.id)].slice(0,10)),V==null||V(I),N(!1),M(null)},[r,V]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:zr[de]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(We,{children:t.id}),e.jsx(We,{color:Ir[de],children:d.indexType[de]})]})}),e.jsx(oe,{title:d.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Be,{label:ue?d.editor.workTitle:xe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:I=>Y("title",I)}),G&&e.jsx(Be,{label:d.editor.belongsToWork,value:t.workName||"",onChange:I=>Y("workName",I)}),e.jsx(ee,{label:d.editor.authorLabel,value:t.author||"",onChange:I=>Y("author",I)}),e.jsx(ee,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:I=>Y("dynasty",I)}),(G||xe)&&e.jsx(Be,{label:d.editor.containedIn,value:t.collection||"",onChange:I=>Y("collection",I)}),(G||xe)&&e.jsx(ee,{label:d.editor.holderLabel,value:t.holder||"",onChange:I=>Y("holder",I)}),(G||xe)&&e.jsx(ee,{label:G?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:I=>Y("pages",I)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:I=>Y("firstImage",I)})})]})}),e.jsx(oe,{title:d.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(fe,{value:t.description||"",onChange:I=>Y("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:o,children:e.jsx(_r,{items:t.additional_works||[],onChange:I=>Y("additional_works",I)})}),e.jsx(oe,{title:d.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Tr,{items:t.indexed_by||[],onChange:I=>Y("indexed_by",I)})}),e.jsx(oe,{title:d.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(Rr,{items:t.emendated_by||[],onChange:I=>Y("emendated_by",I)})}),e.jsx(oe,{title:d.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(Ue,{items:t.resources||[],onChange:I=>Y("resources",I),onDownload:p,downloadStatuses:f,filterType:"text"})}),e.jsx(oe,{title:d.section.imageResources,onSave:o,children:e.jsx(Ue,{items:t.resources||[],onChange:I=>Y("resources",I),onDownload:p,downloadStatuses:f,filterType:"image"})}),e.jsx(oe,{title:d.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(qt,{items:Jt(t.sources||""),onChange:I=>Y("sources",Zt(I)),onOpenEntityPicker:K})}),(G||xe)&&e.jsx(oe,{title:d.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(fe,{value:t.provenance||"",onChange:I=>Y("provenance",I),placeholder:d.editor.provenancePlaceholder})}),G&&e.jsx(oe,{title:d.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(fe,{value:t.otherEditions||"",onChange:I=>Y("otherEditions",I),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(Xt,{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:Pe,onUnlinkEntity:Ae,onViewEntity:ye,onCreateAndLink:ve,onSaveRelations:F}),l&&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(en,{isOpen:m,entityType:g,title:y,onSelect:Me,onCancel:()=>S(!1),onCreate:()=>{S(!1),ve(b,g)},searchResults:z,onSearch:Te,isLoading:v,excludeId:t.id}),e.jsx(tn,{isOpen:T,entityType:H,relationField:B,inheritData:A,onConfirm:Fe,onCancel:()=>$(!1)}),e.jsx(on,{isOpen:W,title:d.action.selectBookOrWork,filterType:"all",recentEntities:re,excludeId:t.id,onSelect:J,onCancel:()=>{N(!1),M(null)},onSearch:q})]})};function _r({items:t,onChange:n}){const o=P(),r=(s,c,a)=>{const p=t.map((f,x)=>x===s?{...f,[c]:a}:f);n(p)},i=s=>n(t.filter((c,a)=>a!==s)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ee,{label:o.editor.bookNameLabel,value:s.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ee,{label:o.label.juanCount,value:s.n_juan!=null?String(s.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>i(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:l,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 ln({items:t,onChange:n,showMeta:o,addLabel:r}){const i=P(),[l,s]=u.useState(null),c=(f,x,h)=>{const d=t.map((m,S)=>S===f?{...m,[x]:h||void 0}:m);n(d)},a=f=>{n(t.filter((x,h)=>h!==f)),l===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=l===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||i.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(),a(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(ee,{label:i.label.sourceName,value:f.source,onChange:d=>c(x,"source",d)}),e.jsx(ee,{label:i.label.sourceBid,value:f.source_bid||"",onChange:d=>c(x,"source_bid",d)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:i.label.titleInfo,value:f.title_info||"",onChange:d=>c(x,"title_info",d)}),e.jsx(ee,{label:i.label.authorInfo,value:f.author_info||"",onChange:d=>c(x,"author_info",d)})]}),e.jsx(ee,{label:i.label.edition,value:f.edition||"",onChange:d=>c(x,"edition",d)})]}),e.jsx(fe,{value:f.summary||"",onChange:d=>c(x,"summary",d),placeholder:i.editor.summaryPlaceholder}),e.jsx(fe,{value:f.comment||"",onChange:d=>c(x,"comment",d),placeholder:i.editor.commentPlaceholder}),e.jsx(fe,{value:f.additional_comment||"",onChange:d=>c(x,"additional_comment",d),placeholder:i.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 Tr({items:t,onChange:n}){const o=P();return e.jsx(ln,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Rr({items:t,onChange:n}){const o=P();return e.jsx(ln,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function sn(t){var c,a,p,f,x,h,d;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",o=((p=t.publication_info)==null?void 0:p.year)||"",r=((f=t.current_location)==null?void 0:f.name)||"",i=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",s={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:i,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const m=t;if(Array.isArray(m.related_works)){const S=m.related_works.find(g=>g.relation==="part_of");S&&(s.parentWorkId=S.id,s.parentWorkName=S.title)}}if(t.type==="book"){const m=t;s.workId=m.work_id,Array.isArray(m.contained_in)&&m.contained_in.length>0&&(s.collectionId=(d=m.contained_in[0])==null?void 0:d.id)}return s}function Lr(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 Er=t=>{const{data:n,id:o,transport:r,mode:i="view",onModeChange:l,onChange:s,onSave:c,onDelete:a,onNavigate:p,renderLink:f,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:m,relations:S,onRelationsChange:g,headerExtra:E,className:b,style:_}=t;P();const[y,R]=u.useState(i),z=l?i:y;u.useEffect(()=>{i!==y&&R(i)},[i]);const j=u.useCallback(()=>{const B=z==="view"?"edit":"view";l?l(B):R(B)},[z,l]),[v,L]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(B=>{B&&L(B)})},[o,r]);const T=n||v,$=u.useMemo(()=>T?sn(T):null,[T]),H=l||!n?e.jsx("button",{onClick:j,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:z==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:z==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,k=e.jsxs(e.Fragment,{children:[H,E]});return!T&&!$?e.jsx(ge,{}):z==="view"?e.jsx(Ge,{data:T,transport:r,onNavigate:p?B=>p(B):void 0,renderLink:f,headerExtra:k,className:b,style:_}):$?e.jsxs("div",{className:b,style:_,children:[k&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:k}),e.jsx(rn,{data:$,onChange:s||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:p,showDelete:!!a,onDelete:a,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:m,relations:S,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},wt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],an=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[i,l]=u.useState(null),[s,c]=u.useState(""),[a,p]=u.useState("idle"),[f,x]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(l(null),c(""),p("idle"),x(""))},[t]),u.useEffect(()=>{i&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[i]),u.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),u.useEffect(()=>{if(!t)return;const g=E=>{E.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const d=async()=>{if(!(!i||!s.trim())){p("submitting"),x("");try{await o({type:i,content:s.trim()}),p("success")}catch(g){p("error"),x(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const m=i&&s.trim()&&a!=="submitting",S=wt.find(g=>g.value===i);return e.jsx("div",{style:Br,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:Wr,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:$r,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Pr,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Hr,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:wt.map(g=>e.jsxs("button",{onClick:()=>l(g.value),style:{...Ar,...i===g.value?Fr:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:s,onChange:g=>c(g.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!i||a==="submitting",style:{...Mr,opacity:i?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),a==="error"&&e.jsx("div",{style:Or,children:f}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!m,style:{...Dr,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Br={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},Wr={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)"},$r={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Pr={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Ar={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"},Fr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Mr={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"},Dr={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Hr={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Or={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Ur=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,i]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>i(!0),style:{...Vr,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(an,{isOpen:r,onClose:()=>i(!1),onSubmit:t,feedbackListUrl:o})]})},Vr={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"},Ct=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Nr=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,i]=u.useState(""),[l,s]=u.useState("idle"),[c,a]=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())){s("submitting"),a("");try{await t({type:n,content:r.trim()}),s("success"),i(""),o("bug")}catch(d){s("error"),a(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&l!=="submitting",h=Ct.find(d=>d.value===n);return l==="success"?e.jsx("div",{style:It,children:e.jsxs("div",{style:Jr,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>s("idle"),style:Zr,children:"继续提交"})]})}):e.jsxs("div",{style:It,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ct.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...Yr,...n===d.value?Kr:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:p,value:r,onChange:d=>i(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...Gr}}),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:{...qr,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&e.jsx("div",{style:Xr,children:c})]})},It={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Yr={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"},Kr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Gr={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"},qr={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Jr={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Zr={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Xr={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},Qr=({style:t})=>{const n=u.useContext(ze);if(!n)return null;const{locale:o,setLocale:r}=n,i=o==="zh-Hant",l=()=>r(i?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:i?"切换为简体":"切換為繁體",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:i?"var(--bim-primary, #0078d4)":void 0,fontWeight:i?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:i?void 0:"var(--bim-primary, #0078d4)",fontWeight:i?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=We;exports.BidUrlProvider=mn;exports.CollatedEdition=Kt;exports.CollectionCatalog=Mt;exports.CreateEntityDialog=tn;exports.EmendatedBySection=At;exports.EntityPickerDialog=on;exports.EntitySelector=en;exports.FeedbackButton=Ur;exports.FeedbackDialog=an;exports.FeedbackForm=Nr;exports.FeedbackList=Gt;exports.FormInput=ee;exports.FormTextArea=fe;exports.HomePage=Ne;exports.IndexApp=Jo;exports.IndexBrowser=Ve;exports.IndexDetail=Ge;exports.IndexEditor=rn;exports.IndexView=Er;exports.LocaleContext=ze;exports.LocaleProvider=wn;exports.LocaleToggle=Qr;exports.ModeIndicator=Lt;exports.RelationPanel=Xt;exports.ResourceEditor=Ue;exports.ResourceList=Ke;exports.SearchInput=Et;exports.Section=oe;exports.SmartBidInput=Be;exports.SourceEditor=qt;exports.WorkCatalog=Zo;exports.detailToEditor=sn;exports.editorToDetail=Lr;exports.formatTemplate=_e;exports.parseSourceString=Jt;exports.stringifySources=Zt;exports.useBidUrl=ce;exports.useConvert=U;exports.useT=P;
1
+ "use strict";var dn=Object.create;var Je=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var xn=Object.getOwnPropertyNames;var un=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var gn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of xn(n))!fn.call(t,l)&&l!==o&&Je(t,l,{get:()=>n[l],enumerable:!(r=pn(n,l))||r.enumerable});return t};var hn=(t,n,o)=>(o=t!=null?dn(un(t)):{},gn(n||!t||!t.__esModule?Je(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-B-bJSFri.cjs"),e=require("react/jsx-runtime"),f=require("react"),bn=require("react-dom"),mn=t=>`/book-index?id=${t}`,It=f.createContext(mn);function yn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(It.Provider,{value:o,children:n})}function ie(){return f.useContext(It)}const Ie=f.createContext(null),zt={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"叢書目錄",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},vn={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"实体资源"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"实体"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"丛书目录",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"基本信息",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},jn={"zh-Hant":zt,"zh-Hans":vn},Tt="bim-locale";function Sn(){try{const t=localStorage.getItem(Tt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function kn(t){try{localStorage.setItem(Tt,t)}catch{}}const wn="zh-Hant",Cn=({locale:t,onLocaleChange:n,children:o})=>{const[r,l]=f.useState(t??wn),i=t??r;f.useEffect(()=>{if(t)return;const x=Sn();x&&x!==r&&l(x)},[]);const[s,d]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(x=>{const u=x.Converter({from:"tw",to:"cn"});d(()=>u)}).catch(()=>{d(()=>x=>x)}):d(null)},[i]);const a=f.useCallback(x=>{l(x),kn(x),n==null||n(x)},[n]),p=f.useMemo(()=>({locale:i,setLocale:a,messages:jn[i],converter:s}),[i,a,s]);return e.jsx(Ie.Provider,{value:p,children:o})};function A(){const t=f.useContext(Ie);return(t==null?void 0:t.messages)??zt}const _n=2e3;function H(){const t=f.useContext(Ie),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),l=f.useRef(n);l.current!==n&&(r.current.clear(),l.current=n);const i=f.useCallback(s=>{if(!s)return"";if(!o)return s;const d=r.current.get(s);if(d!==void 0)return d;const a=o(s);if(r.current.size>=_n){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(s,a),a},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function ze(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function In(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 zn(){return{id:"",name:"",url:"",type:"text",details:""}}const Ue=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:l})=>{const i=A(),[s,d]=f.useState(null),a=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],p=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],x=m=>l?l==="text"?m==="text"||m==="text+image":l==="image"?m==="image"||m==="text+image"||m==="physical":m===l:!0,u=t.map((m,w)=>({item:m,originalIndex:w})).filter(({item:m})=>x(m.type)),g=()=>{const m=zn();l&&(m.type=l),n([...t,m]),d(t.length)},c=m=>{n(t.filter((w,y)=>y!==m)),d(null)},b=(m,w,y)=>{const z=[...t];if(z[m]={...z[m],[w]:y},w==="url"&&!z[m].id){const k=In(y);k&&(z[m].id=k)}n(z)},v=(m,w,y)=>{const k={...t[m].metadata||{}};y?k[w]=y:delete k[w],b(m,"metadata",Object.keys(k).length>0?k:void 0)},h=(m,w)=>{const y=w.trim()?w.split(/[,,、]/).map(z=>z.trim()).filter(Boolean):void 0;b(m,"structure",y)},L=(m,w,y)=>{const k=t[m].coverage||{level:1,ranges:""};w==="level"?k.level=parseInt(y)||1:k.ranges=y,b(m,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[u.map(({item:m,originalIndex:w})=>{var y,z,k,S;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:()=>d(s===w?null:w),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===w?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Tn(m.type),color:"#fff"},children:((y=a.find(j=>j.value===m.type))==null?void 0:y.label)||m.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${w+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:j=>j.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Rn(w,r==null?void 0:r[w],o,i),e.jsx("button",{onClick:j=>{j.stopPropagation(),c(w)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),s===w&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(m.type==="image"||m.type==="text+image")&&m.url&&Ln(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:i.label.type}),e.jsx("select",{value:m.type,onChange:j=>b(w,"type",j.target.value),style:{...ae,flex:1},children:a.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]}),e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:j=>b(w,"root_type",j.target.value),style:{...ae,flex:1},children:p.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:j=>b(w,"id",j.target.value),placeholder:i.editor.idAutoExtract,style:{...ae,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:j=>b(w,"name",j.target.value),placeholder:i.editor.resourceName,style:{...ae,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:j=>b(w,"url",j.target.value),placeholder:i.editor.resourceUrl,style:ae}),e.jsx("input",{type:"text",value:((z=m.structure)==null?void 0:z.join("、"))||"",onChange:j=>h(w,j.target.value),placeholder:i.editor.structurePlaceholder,style:ae}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:je,children:[e.jsx("span",{style:Se,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=m.coverage)==null?void 0:k.level)??"",onChange:j=>L(w,"level",j.target.value),placeholder:"1",style:{...ae,width:"60px"}})]}),e.jsxs("label",{style:{...je,flex:1},children:[e.jsx("span",{style:Se,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((S=m.coverage)==null?void 0:S.ranges)||"",onChange:j=>L(w,"ranges",j.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...ae,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:j=>b(w,"details",j.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(([j,E])=>{var R;return e.jsxs("label",{style:{...je,gap:"4px"},children:[e.jsx("span",{style:{...Se,minWidth:"56px"},children:E}),e.jsx("input",{type:"text",value:((R=m.metadata)==null?void 0:R[j])||"",onChange:$=>v(w,j,$.target.value),placeholder:E,style:{...ae,flex:1}})]},j)})})]})]})]})]},w)}),e.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addResource})]})]})};function Tn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function Rn(t,n,o,r){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||o(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?r.download.completed:l?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":l?"⏳":"⬇"})}function Ln(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 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"},je={display:"flex",alignItems:"center",gap:"6px"},Se={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},En={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function Bn(t){try{const n=new URL(t).hostname;return En[n]}catch{return}}const Ze={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},Wn=["text","image","text+image","physical"];function $n(t){const n=i=>{const s=i.match(/^(.+?)·第(\d+)[冊册]$/);if(s)return[s[1],parseInt(s[2])];const d=i.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},o=new Map,r=[],l=new Set;for(let i=0;i<t.length;i++){const s=t[i];if(s.volumes&&s.volumes.length>0)continue;const d=n(s.name);if(!d)continue;const[a,p]=d,x=`${a}|${s.type}`;o.has(x)||o.set(x,{base:{...s,name:a,url:"",volumes:[]},volumes:[]}),o.get(x).volumes.push({volume:p,url:s.url||void 0,status:"found"}),l.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((s,d)=>s.volume-d.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let s=0;s<t.length;s++)if(l.has(s)){const d=n(t[s].name);d&&`${d[0]}|${t[s].type}`==`${i.base.name}|${i.base.type}`&&l.delete(s)}for(let i=0;i<t.length;i++)l.has(i)||r.push(t[i]);return r}const Ke=({items:t,groupByType:n=!0})=>{const o=A(),r=f.useMemo(()=>$n(t||[]),[t]),l={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical};if(!r||r.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:r.map((s,d)=>e.jsx(Qe,{item:s},s.id||d))});const i=Wn.map(s=>({type:s,items:r.filter(d=>d.type===s)})).filter(s=>s.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:i.map(({type:s,items:d})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ze[s],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ze[s]}}),l[s],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",d.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:d.map((a,p)=>e.jsx(Qe,{item:a},a.id||p))})]},s))})},Xe=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},Rt=({value:t})=>{const o=A().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})},An=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(Rt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const l=String(n);return r?r(l):l};function Pn(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 Fn(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 Mn(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 Dn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Qe=({item:t})=>{var g;const n=A(),{convert:o}=H(),[r,l]=f.useState(!1),i=f.useMemo(()=>(t.url?Bn(t.url):void 0)||o(t.name),[t.url,t.name,o]),s=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(c=>({...c,url:c.url||Mn(c)})),[t.volumes]),d=s&&s.length>0,a=d?s.filter(c=>c.status!=="missing").length:0,p=d?s.length-a:0,x=t.expected_volumes??(d?s.length:0),u=t.color_mode?{...Dn[t.color_mode],label:n.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:Xe(t)||d?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i}),u&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:u.bg,color:u.fg},children:u.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((g=t.metadata)==null?void 0:g.check_type)&&e.jsx(Rt,{value:t.metadata.check_type}),d&&e.jsxs("button",{onClick:()=>l(!r),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[a,"/",x,n.unit.volume,p>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",p]}),e.jsx("span",{style:{marginLeft:"4px"},children:r?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const c=Fn(t.metadata);return c?Pn(t.url,c):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),Xe(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(([c])=>c!=="check_type").map(([c,b])=>e.jsxs("span",{children:[n.metadata[c]||c,": ",An(c,b,n,o)]},c)),t.details&&!d&&e.jsx("span",{children:o(t.details)}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),d&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:s.map(c=>{const b=c.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:c.url&&!b?e.jsx("a",{href:c.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:c.label||`${c.volume}`,children:c.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:b?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:b?"line-through":"none",opacity:b?.6:1,lineHeight:1.4},children:c.volume})},c.volume)})})]})},Lt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:l,onConfigurePath:i,onSelectFolder:s})=>{const d=A(),a=t==="local",p=(n==null?void 0:n.isDraft)??!0,x=(n==null?void 0:n.repoPath)||"",u=x?x.split(/[/\\]/).pop()||x:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},c={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:l,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:p?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...c,children:[e.jsx("span",{children:p?"📝":"📚"}),e.jsx("span",{children:p?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:g,...c,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:d.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:s,title:x||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...c,children:[e.jsx("span",{children:"📂"}),u&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]})]}):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:d.mode.switchToLocal,style:g,...c,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:d.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:u||d.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...c,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...c,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?d.mode.localMode:d.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:s,title:x||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:x?"100px":"auto",justifyContent:"space-between"},...c,children:[e.jsx("span",{children:"📂"}),u&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]}),!a&&u&&e.jsxs("div",{style:{...g,background:"#2196f3",color:"white",cursor:"default"},title:x,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:u})]})]})},$e="bim-search-history",et=10,tt=8;function we(){try{const t=localStorage.getItem($e);return t?JSON.parse(t):[]}catch{return[]}}function Hn(t){try{const n=we().filter(o=>o!==t);n.unshift(t),n.length>et&&(n.length=et),localStorage.setItem($e,JSON.stringify(n))}catch{}}function On(t){try{const n=we().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function Un(){try{localStorage.removeItem($e)}catch{}}const Et=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:l,placeholder:i})=>{const s=A(),d=i??s.search.placeholder,a={work:s.indexType.work,book:s.indexType.book,collection:s.indexType.collection,entity:s.indexType.entity},[p,x]=f.useState(!1),[u,g]=f.useState([]),[c,b]=f.useState(-1),[v,h]=f.useState(null),[L,m]=f.useState(we),w=f.useRef(null),y=f.useRef(null),z=f.useRef(null);f.useEffect(()=>{if(!t.getAllEntries)return;let C=!1;return t.getAllEntries().then(B=>{C||h(B)}).catch(()=>{}),()=>{C=!0}},[t]);const k=f.useCallback(C=>{if(!C.trim())return L.map(I=>({type:"history",text:I}));if(!v)return[];const B=C.toLowerCase(),_=[],P=[];for(const I of v){if(_.length+P.length>=tt*2)break;const W=(I.title??"").toLowerCase();if(W.startsWith(B))_.push({type:"entry",text:I.title,entry:I});else if(W.includes(B))P.push({type:"entry",text:I.title,entry:I});else{const N=[...I.additional_titles||[],...I.attached_texts||[]];for(const V of N){const M=typeof V=="string"?V:V==null?void 0:V.book_title;if(M!=null&&M.toLowerCase().includes(B)){_.push({type:"entry",text:`${I.title}`,entry:I});break}}}}return[..._,...P].slice(0,tt)},[v,L]);f.useEffect(()=>{g(k(n)),b(-1)},[n,k]),f.useEffect(()=>{const C=B=>{z.current&&!z.current.contains(B.target)&&x(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=B=>{var _,P;if(B.key==="/"&&document.activeElement!==w.current){const I=(_=document.activeElement)==null?void 0:_.tagName;if(I==="INPUT"||I==="TEXTAREA"||I==="SELECT")return;B.preventDefault(),(P=w.current)==null||P.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const S=f.useCallback(C=>{C.trim()&&(Hn(C.trim()),m(we())),r(C),x(!1)},[r]),j=f.useCallback(C=>{C.type==="history"?(o(C.text),S(C.text)):C.entry&&(l?(l(C.entry),x(!1)):(o(C.text),S(C.text)))},[o,S,l]),E=f.useCallback(C=>{if(!p||u.length===0){C.key==="Enter"&&S(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(B=>(B+1)%u.length);break;case"ArrowUp":C.preventDefault(),b(B=>(B-1+u.length)%u.length);break;case"Enter":C.preventDefault(),c>=0&&c<u.length?j(u[c]):S(n);break;case"Escape":C.preventDefault(),x(!1);break}},[p,u,c,n,S,j]),R=f.useCallback((C,B)=>{B.stopPropagation(),On(C),m(we()),g(_=>_.filter(P=>!(P.type==="history"&&P.text===C)))},[]),$=f.useCallback(C=>{C.stopPropagation(),Un(),m([]),g([])},[]);f.useEffect(()=>{if(c>=0&&y.current){const C=y.current.children;C[c]&&C[c].scrollIntoView({block:"nearest"})}},[c]);const U=!n.trim()&&L.length>0;return e.jsxs("div",{ref:z,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:w,type:"text",placeholder:d,value:n,onChange:C=>{o(C.target.value),x(!0)},onFocus:()=>x(!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&&u.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[U&&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:$,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:s.search.clearAll})]}),u.map((C,B)=>e.jsxs("div",{onClick:()=>j(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===c?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:_=>R(C.text,_),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:"×"})]},`${C.type}-${C.text}-${B}`))]})]})},_e="bim-recent-ids",nt="bim-recent-entries",ot=50,De=5,Vn=50,Nn=200;function Ce(){try{const t=localStorage.getItem(_e);if(t)return JSON.parse(t);const n=localStorage.getItem(nt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(_e,JSON.stringify(o)),localStorage.removeItem(nt),o}return[]}catch{return[]}}function Yn(t){try{const n=Ce().filter(o=>o!==t);n.unshift(t),n.length>ot&&(n.length=ot),localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Kn(t){try{const n=Ce().filter(o=>o!==t);localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Gn(){try{localStorage.removeItem(_e)}catch{}}const qn={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Ve=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:l,onSwitchMode:i,onToggleDraft:s,onConfigurePath:d,onSelectFolder:a,hideModeIndicator:p,initialQuery:x,onQueryChange:u,headerRight:g})=>{const c=A(),b=[{type:"work",icon:"✍️",name:c.indexType.work,key:"works"},{type:"book",icon:"📖",name:c.indexType.book,key:"books"},{type:"collection",icon:"📚",name:c.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:c.indexType.entity,key:"entities"}],[v,h]=f.useState(x??""),[L,m]=f.useState(null),[w,y]=f.useState(null),[z,k]=f.useState(!1),[S,j]=f.useState(null),[E,R]=f.useState(""),[$,U]=f.useState(!x),[C,B]=f.useState(Ce),[_,P]=f.useState([]),[I,W]=f.useState(!1),[N,V]=f.useState(!1),[M,le]=f.useState(null),[Q,de]=f.useState(null),ue=f.useRef(void 0),xe=f.useRef(!1),J=f.useCallback(async(F,K)=>{if(!F.trim()){U(!0),m(null),y(null);return}U(!1),k(!0),R("");try{if(t.searchAll){const Z=await t.searchAll(F,K??De);m(Z)}else{const Z=["work","book","collection","entity"],G=await Promise.all(Z.map(te=>t.search(F,te,{page:1,pageSize:K??De})));m({works:G[0].entries,books:G[1].entries,collections:G[2].entries,entities:G[3].entries,totalWorks:G[0].total,totalBooks:G[1].total,totalCollections:G[2].total,totalEntities:G[3].total})}}catch(Z){R(Z instanceof Error?Z.message:String(Z)),m(null)}finally{k(!1)}},[t]);f.useEffect(()=>{var T,D;let F=!1;const K=["work","book","collection","entity"],Z=Promise.all(K.map(q=>t.loadEntries(q,{page:1,pageSize:1}).catch(()=>({total:0})))),G=((T=t.getResourceCounts)==null?void 0:T.call(t).catch(()=>null))??Promise.resolve(null),te=((D=t.getSubtypeStats)==null?void 0:D.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([Z,G,te]).then(([q,se,he])=>{F||(le({works:q[0].total,books:q[1].total,collections:q[2].total,entities:q[3].total,hasText:se==null?void 0:se.hasText,hasImage:se==null?void 0:se.hasImage}),he&&de(he))}),()=>{F=!0}},[t]),f.useEffect(()=>{xe.current||!(x!=null&&x.trim())||(xe.current=!0,J(x))},[x,J]);const Y=f.useCallback(F=>{if(h(F),u==null||u(F),!F.trim()){U(!0),m(null),y(null);return}ue.current&&clearTimeout(ue.current),ue.current=setTimeout(()=>{y(null),J(F)},Nn)},[J,u]),Ae=f.useCallback(F=>{ue.current&&clearTimeout(ue.current),u==null||u(F),J(F)},[J,u]),Pe=f.useCallback(F=>{y(F),J(v,Vn)},[v,J]);f.useEffect(()=>{if(!C.length){P([]);return}let F=!1;return W(!0),Promise.all(C.slice(0,10).map(async K=>{var Z,G,te;try{if(t.getEntry){const D=await t.getEntry(K);if(D)return D}const T=await t.getItem(K);if(T){const D=T.authors;return{id:K,title:T.title||K,type:T.type||"work",author:(Z=D==null?void 0:D[0])==null?void 0:Z.name,dynasty:(G=D==null?void 0:D[0])==null?void 0:G.dynasty,role:(te=D==null?void 0:D[0])==null?void 0:te.role,edition:T.edition||void 0}}}catch{}return{id:K,title:K,type:"work",notFound:!0}})).then(K=>{F||(P(K),W(!1))}),()=>{F=!0}},[C,t]);const ye=F=>{j(F.id),Yn(F.id),B(Ce()),r==null||r(F)},ve=F=>{Kn(F),B(Ce())},Fe=()=>{Gn(),B([])},Te=F=>b.find(K=>K.type===F),Me=L&&(L.works.length>0||L.books.length>0||L.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:c.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!p&&e.jsx(Lt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:s,onConfigurePath:d,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Et,{transport:t,value:v,onChange:Y,onSearch:Ae,onEntrySelect:ye}),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:c.action.newEntry})]}),M&&$&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Q?e.jsxs(e.Fragment,{children:[(Q.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()})," 本"]}),Q.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.article.toLocaleString()})," 篇"]}):null,Q.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Q.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[c.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()}),M.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.entities.toLocaleString()})]})]})}),M.hasImage!=null&&M.hasText!=null&&e.jsxs("span",{children:[c.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.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})]}):$?e.jsx("div",{style:{flex:1},children:I?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.loading}):_.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:c.search.recentBrowse}),e.jsx("button",{onClick:Fe,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:c.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:_.slice(0,N?10:3).map(F=>F.notFound?e.jsx(Jn,{id:F.id,onRemove:ve,t:c},F.id):e.jsx(rt,{entry:F,selected:S===F.id,onClick:ye,getConfig:Te,onRemove:ve},F.id))}),!N&&_.length>3&&e.jsx("button",{onClick:()=>V(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:c.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:c.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.searchSubtitle})]})}):Me?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:F,icon:K,name:Z,key:G})=>{const te=L[G]??[],T=qn[G],D=L[T]??0;if(te.length===0)return null;const se=!(w===F)&&D>De;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[K," ",Z,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[D," ",c.unit.items]})]}),se&&e.jsx("button",{onClick:()=>Pe(F),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:c.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:te.map(he=>e.jsx(rt,{entry:he,selected:S===he.id,onClick:ye,getConfig:Te,query:v},he.id))})]},F)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:ze(c.search.noResultsFor,{query:v})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.tryOther})]})})]})},rt=({entry:t,selected:n,onClick:o,getConfig:r,query:l,onRemove:i})=>{const s=A(),{convert:d}=H(),a=[...t.additional_titles||[],...t.attached_texts||[]],p=l&&a.length?a.find(x=>{const u=typeof x=="string"?x:x==null?void 0:x.book_title;return u==null?void 0:u.toLowerCase().includes(l.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:d(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:d(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:d(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:["〔",d(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:d(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",d(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,":",d(p)]})]}),i?e.jsx("button",{onClick:x=>{x.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:"→"})]})},Jn=({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 Zn(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 Xn({data:t}){const{convert:n}=H(),{dynasty:o,birth_year:r,death_year:l}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&l!==void 0?i.push(`${r}—${l}`):r!==void 0?i.push(`${r}—?`):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 Qn({alt_names:t}){const{convert:n}=H(),o=new Map;for(const i of t){const s=i.type||"別名";o.has(s)||o.set(s,[]),o.get(s).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],l=[...o.keys()].sort((i,s)=>{const d=r.indexOf(i),a=r.indexOf(s);return d===-1&&a===-1?0:d===-1?1:a===-1?-1:d-a});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=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:s.map((d,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(d)]},a))})]},i)})})}function eo({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 to({works:t,transport:n,onNavigate:o,renderLink:r}){const l=A(),{convert:i}=H(),s=ie(),[d,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const c=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const w=await n.getEntriesByIds(c);let y=!0;for(let z=0;z<c.length;z++){const k=w[z];k!=null&&k.title?v.set(c[z],k.title):k!=null&&k.primary_name?v.set(c[z],k.primary_name):y=!1}if(y)return v}catch{}if(n.getAllEntries)try{const w=await n.getAllEntries(),y=new Map(w.map(k=>[k.id,k.title||k.primary_name||k.id]));let z=!0;for(const k of c){const S=y.get(k);S?v.set(k,S):z=!1}if(z)return v}catch{}const h=[...c],L=8,m=new Array(L).fill(0).map(async()=>{for(;h.length;){const w=h.shift();if(!w)break;if(!v.has(w))try{if(n.getEntry){const k=await n.getEntry(w);if(k!=null&&k.title){v.set(w,k.title);continue}}const y=await n.getItem(w),z=y&&(y.title||y.primary_name)||w;v.set(w,z)}catch{v.set(w,w)}}});return await Promise.all(m),v})().then(v=>{g||a(v)}),()=>{g=!0}},[t,n]);const p=new Map;for(const g of t){const c=g.role||"";p.has(c)||p.set(c,[]),p.get(c).push(g)}const x=["撰","編","注","輯","集","校","評","譯","述","作",""],u=[...p.keys()].sort((g,c)=>{const b=x.indexOf(g),v=x.indexOf(c);return b===-1&&v===-1?g.localeCompare(c):b===-1?1:v===-1?-1:b-v});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[l.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),u.map(g=>{const c=p.get(g);return e.jsxs("div",{style:{marginBottom:"8px"},children:[g&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",c.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:c.map((b,v)=>{const h=i(d.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,h)},v):o?e.jsx("li",{children:e.jsx("a",{href:s(b.work_id),onClick:L=>{L.metaKey||L.ctrlKey||(L.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:h})},v):e.jsx("li",{children:h},v)})})]},g)})]})}const Bt=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:l})=>{var x;const i=A(),{convert:s}=H();let d=!1;try{d=O.extractStatus(t.id)==="draft"}catch{}const a=Zn(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(Xn,{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}),d&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),a&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Qn,{alt_names:t.alt_names}),e.jsx(eo,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:s(t.description.text)}),t.works&&t.works.length>0&&e.jsx(to,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},no=["〇","一","二","三","四","五","六","七","八","九"],it=["","十","百","千"];function Wt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",l=!1;for(let i=0;i<o;i++){const s=parseInt(n[i]),d=o-1-i;s===0?l=!0:(l&&r&&(r+="〇"),l=!1,s===1&&d===1&&i===0?r+=it[d]:r+=no[s]+it[d])}return r}function $t({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function oo({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function ro({id:t}){const n=A(),[o,r]=f.useState(!1),l=()=>{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:l,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ne({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function 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 At({authors:t,type:n,onNavigate:o,renderLink:r}){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 d=l(i.name),a=i.entity_id?e.jsx(re,{id:i.entity_id,label:d,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:d});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),"〕"]}),a,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",l(i.role)]})]},s)})})}function re({id:t,label:n,onNavigate:o,renderLink:r}){const l=ie();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:l(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 io({id:t,title:n,edition:o,type:r,isDraft:l,authors:i,volumeText:s,meta:d,headerExtra:a,onNavigate:p,renderLink:x}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),s&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:s})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx($t,{type:r}),e.jsx(oo,{isDraft:l}),e.jsx(ro,{id:t})]}),((i==null?void 0:i.length)||d.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(At,{authors:i,type:r,onNavigate:p,renderLink:x}),d]})]})}function Pt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:l}){const i=A(),{convert:s}=H();if(!t.length)return null;const[d,a]=f.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,x)=>{const u=d===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(u?null:x),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:u?"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)}),!u&&o&&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:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(re,{id:p.source_bid,label:i.action.view,onNavigate:r,renderLink:l})})]}),u&&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(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)})]})]})]},x)})})]})}function lo({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ft({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(Pt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Mt({label:t,items:n}){const{convert:o}=H();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,l)=>{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)},l)})})]}):null}function so({items:t}){const n=A();return e.jsx(Mt,{label:n.section.aliases,items:t})}function ao({items:t}){const n=A();return e.jsx(Mt,{label:n.section.attachedTexts,items:t})}function co({items:t}){const n=A(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,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:["《",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]})]},l))})]}):null}function po({items:t}){const n=A(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,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:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},l))]})]}):null}function xo({items:t}){const n=A(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,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:"·"}),o(r)]},l))})]}):null}function lt({title:t,ids:n,transport:o,onNavigate:r,renderLink:l}){const{convert:i}=H(),[s,d]=f.useState([]);return f.useEffect(()=>{if(!n.length){d([]);return}if(!o){d(n.map(p=>({id:p})));return}let a=!1;return Promise.all(n.map(p=>o.getItem(p).then(x=>({id:p,title:x?x.title:void 0,edition:x?x.edition:void 0,type:x?x.type:void 0})).catch(()=>({id:p})))).then(p=>{a||d(p)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ne,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(s.length?s:n.map(a=>({id:a}))).map(a=>{const p=a.edition?`${i(a.title)||a.id}(${i(a.edition)})`:i(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(re,{id:a.id,label:p,onNavigate:r,renderLink:l})},a.id)})})]}):null}function uo({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:l}=H(),[i,s]=f.useState(!1),d=t.resources&&t.resources.length>0,a=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:d&&!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(re,{id:t.id,label:a,onNavigate:n,renderLink:o})}),d&&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?r.action.expand:r.action.collapse,children:"▼"})]}),d&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(Ke,{items:t.resources,groupByType:!0})})]})}function fo({ids:t,transport:n,onNavigate:o,renderLink:r}){const l=A(),[i,s]=f.useState([]);return f.useEffect(()=>{if(!t.length){s([]);return}if(!n){s(t.map(a=>({id:a})));return}let d=!1;return Promise.all(t.map(a=>n.getItem(a).then(p=>({id:a,title:p?p.title:void 0,edition:p?p.edition:void 0,resources:p?p.resources:void 0})).catch(()=>({id:a})))).then(a=>{d||s(a)}),()=>{d=!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(d=>({id:d}))).map(d=>e.jsx(uo,{book:d,onNavigate:o,renderLink:r},d.id))})]}):null}function go({workData:t,onNavigate:n,renderLink:o}){var i,s,d;const r=A(),{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($t,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(re,{id:t.id,label:l(t.title),onNavigate:n,renderLink:o})}),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:[Wt(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(At,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((s=t.description)==null?void 0:s.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(d=t.authors)!=null&&d.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:r.label.parentWork,children:e.jsx(re,{id:t.parent_work.id,label:l(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function ho({items:t,onNavigate:n,renderLink:o}){const r=A(),{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:r.indexType.collection}),e.jsx(re,{id:i.id,label:l(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:ze(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const Ge=({data:t,id:n,transport:o,onNavigate:r,renderLink:l,headerExtra:i,className:s,style:d})=>{var $,U,C,B,_,P;const a=A(),{convert:p}=H(),[x,u]=f.useState(null),[g,c]=f.useState(!1),[b,v]=f.useState(null),[h,L]=f.useState(null),[m,w]=f.useState([]),y=t||x;if(f.useEffect(()=>{if(t||!n||!o)return;let I=!1;return c(!0),v(null),o.getItem(n).then(W=>{I||(W?u(W):v(a.misc.notFoundEntry))}).catch(W=>{I||v(W instanceof Error?W.message:a.misc.loadFailed)}).finally(()=>{I||c(!1)}),()=>{I=!0}},[t,n,o]),f.useEffect(()=>{if(!y||!o){L(null),w([]);return}let I=!1;const W=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(W?o.getItem(W).then(N=>{!I&&N&&N.type==="work"&&L(N)}).catch(()=>{}):L(null),y.type==="book"){const N=y;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(V=>{const M=typeof V=="string"?V:V.id,le=typeof V=="string"?void 0:V.volume_index;return o.getItem(M).then(Q=>({id:M,title:Q&&Q.title||M,volume_index:le})).catch(()=>({id:M,title:M,volume_index:le}))})).then(V=>{I||w(V)}):w([])}else w([]);return()=>{I=!0}},[y,o]),g)return e.jsx("div",{className:s,style:{...d,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((I,W)=>e.jsx("div",{style:{height:W===1?"32px":"16px",width:`${I}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},W))})});if(b)return e.jsx("div",{className:s,style:{...d,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:b});if(!y)return null;if(y.type==="entity")return e.jsx("div",{className:s,style:d,children:e.jsx(Bt,{data:y,transport:o,onNavigate:r,renderLink:l,headerExtra:i})});const z=y.type==="book"?y:null,k=y.type==="collection"?y:null,S=y.type==="work"?y:null;let j=!1;try{j=O.extractStatus(y.id)==="draft"}catch{}let E="";y.measure_info?E=p(y.measure_info):($=y.juan_count)!=null&&$.number?E=Wt(y.juan_count.number)+a.unit.juan:(U=y.juan_count)!=null&&U.description&&(E=p(y.juan_count.description));const R=[];return(C=y.publication_info)!=null&&C.year&&R.push(e.jsx(ce,{label:a.label.year,children:y.publication_info.year},"year")),(B=y.current_location)!=null&&B.name&&R.push(e.jsx(ce,{label:a.label.currentLocation,children:p(y.current_location.name)},"loc")),(_=y.page_count)!=null&&_.description&&R.push(e.jsx(ce,{label:a.label.pageCount,children:y.page_count.description},"page")),z!=null&&z.edition&&R.push(e.jsx(ce,{label:a.label.edition,children:p(z.edition)},"ver")),S!=null&&S.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:e.jsx(re,{id:S.parent_work.id,label:p(S.parent_work.title),onNavigate:r,renderLink:l})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&R.push(e.jsx(ce,{label:a.label.parentWork,children:S.parent_works.map((I,W)=>e.jsxs("span",{children:[W>0&&"、",e.jsx(re,{id:I,onNavigate:r,renderLink:l})]},I))},"pws")),e.jsxs("div",{className:s,style:d,children:[e.jsx(io,{id:y.id,title:p(y.title),edition:y.edition?p(y.edition):void 0,type:y.type,isDraft:j,authors:y.authors,volumeText:E,meta:R,headerExtra:i,onNavigate:r,renderLink:l}),((P=y.description)==null?void 0:P.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:p(y.description.text)}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.containedIn}),e.jsx(ho,{items:m,onNavigate:r,renderLink:l})]}),h&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.belongsToWork}),e.jsx(go,{workData:h,onNavigate:r,renderLink:l})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(co,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(so,{items:y.additional_titles}),y.attached_texts&&y.attached_texts.length>0&&e.jsx(ao,{items:y.attached_texts}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(lo,{items:y.indexed_by,onNavigate:r,renderLink:l}),y.emendated_by&&y.emendated_by.length>0&&e.jsx(Ft,{items:y.emendated_by,onNavigate:r,renderLink:l}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{children:a.section.resources}),e.jsx(Ke,{items:y.resources,groupByType:!0})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(po,{items:z.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx(xo,{items:k.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(lt,{title:a.section.relatedVersions,ids:z.related_books,transport:o,onNavigate:r,renderLink:l}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(lt,{title:a.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:l}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ne,{children:[a.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(I=>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(re,{id:I.id,label:p(I.title),onNavigate:r,renderLink:l})},I.id))})]}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(fo,{ids:S.books,transport:o,onNavigate:r,renderLink:l}),(S==null?void 0:S.related_works)&&S.related_works.length>0&&(()=>{const I=[],W=S.related_works.filter(M=>M.relation==="part_of"),N=S.related_works.filter(M=>M.relation==="has_part"),V=S.related_works.filter(M=>!M.relation);return W.length>0&&I.push({label:a.section.belongsToWork,items:W}),N.length>0&&I.push({label:a.section.containedWorks,items:N}),V.length>0&&I.push({label:a.section.relatedWorks,items:V}),I.map(M=>e.jsxs("div",{children:[e.jsxs(ne,{children:[M.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",M.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:M.items.map(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(re,{id:le.id,label:p(le.title),onNavigate:r,renderLink:l})},le.id))})]},M.label))})()]})};function bo({data:t}){const n=A(),{convert:o}=H(),{stats:r}=t,l=r.processed_volumes??r.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: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:l})," ",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 mo({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:st(n===null),children:r.catalog.all}),t.map(l=>e.jsxs("button",{onClick:()=>o(l.name),style:st(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 st(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function yo({id:t,label:n,onNavigate:o,renderLink:r}){const l=ie();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:l(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 vo(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 at({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const l=A(),{convert:i}=H(),s=t.book_id||t.work_id,d=r&&t.volumes.length>0?vo(t.volumes,l.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:d}),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:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,l.unit.volume]}),s&&e.jsx(yo,{id:s,label:t.book_id?l.indexType.book:l.indexType.work,onNavigate:n,renderLink:o}),!s&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:l.catalog.unmatched_label})]})}const Dt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:l,className:i,style:s})=>{const d=A(),[a,p]=f.useState(null),[x,u]=f.useState(!1),[g,c]=f.useState(null),[b,v]=f.useState(null),[h,L]=f.useState(""),m=t||a;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return u(!0),c(null),o.getCollectionCatalog(n).then(j=>{S||(j?p(j):c(d.catalog.notFound))}).catch(j=>{S||c(j instanceof Error?j.message:d.catalog.loadFailed)}).finally(()=>{S||u(!1)}),()=>{S=!0}},[t,n,o,d]);const w=(m==null?void 0:m.sections)&&m.sections.length>0,y=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const S=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[m]),z=f.useMemo(()=>{if(!m)return[];let S=m.books;if(b&&(S=S.filter(j=>j.section===b)),h.trim()){const j=h.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(j)||E.sub_items&&E.sub_items.some(R=>R.toLowerCase().includes(j))||E.edition&&E.edition.toLowerCase().includes(j))}return S},[m,b,h]),k=f.useMemo(()=>{if(!y)return null;const S=[],j=new Map;for(const R of z){if(!R.volumes||R.volumes.length===0)continue;const $=R.volumes[0];j.has($)||j.set($,[]),j.get($).push(R)}const E=[...j.keys()].sort((R,$)=>R-$);for(const R of E)S.push({volume:R,books:j.get(R)});return S},[z,y]);return x?e.jsx("div",{className:i,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.catalog.loading})}):g?e.jsx("div",{className:i,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:i,style:s,children:[e.jsx(bo,{data:m}),w&&e.jsx(mo,{sections:m.sections,activeSection:b,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:h,onChange:S=>L(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[z.length," ",d.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((S,j)=>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:ze(d.catalog.volume,{n:S.volume})}),S.books.map((E,R)=>e.jsx(at,{book:E,onNavigate:r,renderLink:l,showVolumes:E.volumes.length>1},`${S.volume}-${R}`))]},`${S.volume}-${j}`)):z.map((S,j)=>e.jsx(at,{book:S,onNavigate:r,renderLink:l,showVolumes:!0},j)),z.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Ht={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},jo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},So={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},ge=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},X=6,Re=7,ko=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:l=280,wrapperStyle:i})=>{const[s,d]=f.useState(!1),[a,p]=f.useState(null),x=f.useRef(null),u=f.useRef(null),g=f.useRef(null),c=f.useCallback(()=>{const h=u.current,L=g.current;if(!h||!L)return;const m=h.getBoundingClientRect(),w=L.getBoundingClientRect(),y=window.innerHeight,z=document.documentElement.clientWidth;let k=o;o==="top"&&m.top-w.height-Re<8&&(k="bottom"),o==="bottom"&&m.bottom+w.height+Re>y-8&&(k="top");const S=k==="top"?m.top-w.height-Re:m.bottom+Re;let j=m.left+m.width/2-w.width/2;j=Math.max(8,Math.min(j,z-w.width-8)),p({left:j,top:S,placement:k})},[o]),b=f.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>d(!0),r)},[r]),v=f.useCallback(()=>{x.current&&clearTimeout(x.current),d(!1),p(null)},[]);return f.useEffect(()=>{if(!s)return;const h=requestAnimationFrame(c);return()=>cancelAnimationFrame(h)},[s,c]),f.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:u,onMouseEnter:b,onMouseLeave:v,onFocus:b,onBlur:v,style:{display:"inline-block",...i},children:n}),s&&bn.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.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:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-X,width:0,height:0,...a.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,...a.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)]})},ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function wo(t){return typeof t!="string"?null:t in Ht?t:t in ct?ct[t]:null}const Co=["〇","一","二","三","四","五","六","七","八","九"],dt=["","十","百","千"],_o=["","萬","億"];function Ot(t){if(t===0)return"〇";if(t<0)return`負${Ot(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const l=o%1e4;l>0?n.unshift(Io(l,r>0)+_o[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Io(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let l="";for(let i=0;i<o.length;i++){const s=o[i],d=o.length-1-i;s===0?l&&!l.endsWith("〇")&&(l+="〇"):s===1&&d===1&&i===0&&!n?l+=dt[d]:l+=Co[s]+dt[d]}return l.replace(/〇$/,"")}const qe={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},zo={考证:"#5d6d7e"};function To(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 Ut({file:t,isActive:n,onSelect:o}){return e.jsx("button",{onClick:()=>o(t),style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:n?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4},children:To(t)})}function Vt(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Vt(r,n)))}function Nt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((l,i)=>l+Nt(i),0))||0;return n+o}function Yt({group:t,activeFile:n,onSelect:o,depth:r=0}){var p;const l=Vt(t,n||""),[i,s]=f.useState(l),d=Nt(t),a=!!((p=t.children)!=null&&p.length);if(f.useEffect(()=>{l&&s(!0)},[l]),t.files.length===1&&!a){const x=t.files[0],u=n===x;return e.jsx("button",{onClick:()=>o(x),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:u?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:u?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:u?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:u?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>s(!i),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)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:i?"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:["(",d,")"]})]}),i&&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(x=>e.jsx(Ut,{file:x,isActive:n===x,onSelect:o},x))}),a&&t.children.map((x,u)=>e.jsx(Yt,{group:x,activeFile:n,onSelect:o,depth:r+1},u))]})]})}function Ro({files:t,groups:n,activeFile:o,onSelect:r}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((i,s)=>e.jsx(Yt,{group:i,activeFile:o,onSelect:r},s))}):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(i=>e.jsx(Ut,{file:i,isActive:o===i,onSelect:r},i))})}function Lo({type:t}){const n=qe[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 Eo({section:t,onNavigate:n}){const{convert:o}=H(),r=ie(),[l,i]=f.useState(!1),s=!!t.summary,d=!!t.comment,a=!!t.additional_comment,p=!!(t.content&&t.content.length>60),x=s||d||a||p,u=!l&&p?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>x&&i(!l),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:x?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[x&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ot(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:o(t.author_info||t.author)})]}),!l&&u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:o(u)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(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:r(t.work_id),onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),l&&x&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:o(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:o(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:o(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:o(t.additional_comment)})]}),p&&!s&&!d&&!a&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:o(t.content)})]})]})}function Bo({section:t}){const{convert:n}=H(),[o,r]=f.useState(!1),l=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>l&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:l?"pointer":"default",userSelect:"none"},children:[e.jsx(Lo,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),l&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&l&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${qe[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:n(t.content)})})]})}function Wo({section:t}){const{convert:n}=H();if(!t.content&&!t.title)return null;const o=n((t.content||t.title||"").replace(/\n{2,}/g,`
2
+ `)),r=qe[t.type]||"#717171",l=t.type==="序"||t.type==="结语";return e.jsxs("div",{style:{padding:l?"10px 12px":"6px 0",margin:l?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:l?`3px solid ${r}40`:void 0,background:l?"var(--bim-bg, #fafafa)":void 0,borderRadius:l?"0 4px 4px 0":void 0,position:"relative"},children:[l&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:r,marginRight:"8px",padding:"1px 5px",border:`1px solid ${r}40`,borderRadius:"2px",background:`${r}08`,verticalAlign:"middle"},children:t.type}),o]})}function $o(t,n,o){const[r,l]=f.useState({});return f.useEffect(()=>{var p;if(!n||t.length===0)return;let i=!1;const s=t.filter(x=>{var u;return!((u=o==null?void 0:o.current)!=null&&u.has(x))}),d={};for(const x of t)(p=o==null?void 0:o.current)!=null&&p.has(x)&&(d[x]=o.current.get(x));if(Object.keys(d).length>0&&l(d),s.length===0)return;const a=async x=>{var u;try{if(n.getEntry){const h=await n.getEntry(x);if(h)return{title:h.title,author:h.author}}const g=await n.getItem(x);if(!g)return null;const c=g.title||x,b=g.authors,v=(u=b==null?void 0:b[0])==null?void 0:u.name;return{title:c,author:v}}catch{return null}};return Promise.all(s.map(async x=>{var g;const u=await a(x);return(g=o==null?void 0:o.current)==null||g.set(x,u),[x,u]})).then(x=>{i||l(u=>{const g={...u};for(const[c,b]of x)g[c]=b;return g})}),()=>{i=!0}},[t.join(","),n]),r}function Ao({section:t,onNavigate:n,transport:o,workLabelCache:r}){const{convert:l}=H(),i=ie(),[s,d]=f.useState(!1),a=t.type,p=zo[a]||"#717171",x=!!t.content,u=t.work_ids||[],g=u.length>1,c=$o(g?u:[],o,r),b=x&&!s&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>x&&d(!s),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:x?"pointer":"default",userSelect:"none"},children:[x&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:s?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?l(t.header_line):l(t.title)}),!s&&b&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:l(b)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[u.length===1&&n&&e.jsx("a",{href:i(u[0]),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(u[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),g&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[u.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:p,border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`},children:a})]})]}),g&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:u.map(v=>{const h=c[v],L=h?`${l(h.title)}${h.author?`(${l(h.author)})`:""}`:v.slice(0,8)+"…";return e.jsxs("a",{href:i(v),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(v))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:v,children:["→",L]},v)})}),s&&x&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${p}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:l(t.comment)})]})]})}function Po({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:l}){const{convert:i}=H(),s=f.useMemo(()=>{if(!n.trim())return t.sections;const a=n.trim().toLowerCase();return t.sections.filter(p=>{var x,u,g;return((x=p.title)==null?void 0:x.toLowerCase().includes(a))||((u=p.content)==null?void 0:u.toLowerCase().includes(a))||((g=p.comment)==null?void 0:g.toLowerCase().includes(a))})},[t.sections,n]),d=s.filter(a=>a.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)}),d>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[d," 條"]})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:s.map((a,p)=>e.jsx(Ao,{section:a,onNavigate:o,transport:r,workLabelCache:l},p))}),s.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Fo({sections:t,onNavigate:n}){const{convert:o}=H(),r=ie(),l=[];let i=null;for(const s of t)s.type==="类"?(i&&l.push(i),i={category:s.title,categoryContent:s.content||void 0,items:[]}):s.type==="书"?(i||(i={category:"",items:[]}),i.items.push(s)):(s.type==="序"||s.type==="结语")&&(i||(i={category:"",items:[]}),i.items.push(s),s.type==="结语"&&(l.push(i),i=null));return i&&l.push(i),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:l.map((s,d)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[s.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[o(s.category),s.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:o(s.categoryContent)})]}),s.items.map((a,p)=>a.type==="序"||a.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},p):(a.content?a.title+a.content:a.title,e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&a.work_id?e.jsx("a",{href:r(a.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),x.stopPropagation(),n(a.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(a.title),children:e.jsx("strong",{children:o(a.title)})}):e.jsx("strong",{children:o(a.title)}),a.content&&o(a.content)]},p)))]},d))})}function Mo({juan:t,searchQuery:n,onNavigate:o}){const{convert:r}=H(),[l,i]=f.useState("catalog"),s=f.useMemo(()=>{if(!n.trim())return t.sections;const p=n.trim().toLowerCase();return t.sections.filter(x=>{var u,g,c,b,v,h;return((u=x.title)==null?void 0:u.toLowerCase().includes(p))||((g=x.book_title)==null?void 0:g.toLowerCase().includes(p))||((c=x.author)==null?void 0:c.toLowerCase().includes(p))||((b=x.author_info)==null?void 0:b.toLowerCase().includes(p))||((v=x.summary)==null?void 0:v.toLowerCase().includes(p))||((h=x.content)==null?void 0:h.toLowerCase().includes(p))})},[t.sections,n]),d=s.filter(p=>p.type==="书").length,a=s.filter(p=>p.type==="詩").length;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:r(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(p=>e.jsx("button",{onClick:()=>i(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:a>0?`${a} 首`:`${d} 部书`})]}),l==="raw"&&e.jsx(Fo,{sections:s,onNavigate:o}),l==="catalog"&&s.map((p,x)=>p.type==="书"||p.type==="詩"?e.jsx(Eo,{section:p,onNavigate:o},x):p.type==="类"?e.jsx(Bo,{section:p},x):e.jsx(Wo,{section:p},x)),s.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Kt(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 pt(t){const n=Kt(t);return n.length>0?n[0]:null}const Gt=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:l,onJuanChange:i,className:s,style:d})=>{const[a,p]=f.useState(null),[x,u]=f.useState(!1),[g,c]=f.useState(null),[b,v]=f.useState(null),[h,L]=f.useState(null),[m,w]=f.useState(!1),[y,z]=f.useState(""),k=f.useRef(new Map),S=l??b,j=f.useCallback(_=>{v(_),i==null||i(_)},[i]),E=t||a;f.useEffect(()=>{t&&(u(!1),c(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let _=!1;return u(!0),c(null),o.getCollatedEditionIndex(n).then(P=>{if(!_)if(!P)c("未找到整理本数据");else{p(P);const I=pt(P);!l&&I&&j(I)}}).catch(P=>{_||c(P instanceof Error?P.message:"加载失败")}).finally(()=>{_||u(!1)}),()=>{_=!0}},[t,n,o,l,j]),f.useEffect(()=>{const _=t||a;if(_&&!S){const P=pt(_);P&&j(P)}},[t,a,S,j]);const R=n||(E==null?void 0:E.work_id),$=f.useCallback(async _=>{if(!(!R||!(o!=null&&o.getCollatedJuan))){w(!0),L(null);try{const P=await o.getCollatedJuan(R,_);L(P)}catch{L(null)}finally{w(!1)}}},[R,o]);f.useEffect(()=>{S&&$(S)},[S,$]);const U=_=>{j(_),z("")};if(x)return e.jsx("div",{className:s,style:{...d,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:s,style:{...d,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!E)return null;const C=E.type==="kaozhen",B=Kt(E);return e.jsxs("div",{className:s,style:d,children:[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:C?e.jsxs(e.Fragment,{children:[E.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:E.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:B.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:E.total_juan})," 卷"]})}),E.text_quality&&(()=>{const _=wo(E.text_quality.grade);return _?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(ko,{content:jo[_],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:So[_],cursor:"help"},children:Ht[_]})}),E.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",E.text_quality.source_note]})]}):null})()]}),e.jsx(Ro,{files:B,groups:E.juan_groups,activeFile:S,onSelect:U}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:C?"搜索条目、考证内容...":"搜索书名、作者...",value:y,onChange:_=>z(_.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"}})}),m?e.jsx(ge,{}):h?C?e.jsx(Po,{juan:h,searchQuery:y,onNavigate:r,transport:o,workLabelCache:k}):e.jsx(Mo,{juan:h,searchQuery:y,onNavigate:r}):S?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,E.references&&E.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:"參考文獻"}),E.references.map((_,P)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[P+1,". "]}),_.url?e.jsx("a",{href:_.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:_.title}):e.jsx("span",{children:_.title}),_.author&&e.jsxs("span",{children:[",",_.author]}),_.note&&e.jsxs("span",{children:["。",_.note]})]},P))]})]})},Do={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Ho={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Oo(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 qt=({items:t,loading:n})=>{const o=ie();return n?e.jsx(ge,{}):t.length===0?e.jsx("div",{style:Uo,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const l=Do[r.type],i=Ho[r.status];return e.jsxs("div",{style:Vo,children:[e.jsxs("div",{style:No,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...xt,background:l.color},children:l.label}),e.jsx("span",{style:{...xt,background:i.color},children:i.label})]}),e.jsx("span",{style:Yo,children:Oo(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Ko,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:ut,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:ut,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Go,children:r.content}),r.reply&&e.jsxs("div",{style:qo,children:[e.jsx("div",{style:Jo,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Uo={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Vo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},No={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Yo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Ko={fontSize:"12px",marginBottom:"6px"},ut={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Go={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},qo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Jo={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Ne=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:l,feedbackApiUrl:i})=>{const s=A(),[d,a]=f.useState(null),[p,x]=f.useState([]),[u,g]=f.useState("recommend"),[c,b]=f.useState([]),[v,h]=f.useState(!1),L=r??u,m=R=>{g(R),l==null||l(R)},[w,y]=f.useState(!0),[z,k]=f.useState(null),[S,j]=f.useState(null);f.useEffect(()=>{if(!t.getAllEntries)return;let R=!1;return t.getAllEntries().then($=>{if(R)return;const U=$.filter(_=>_.type==="work").length,C=$.filter(_=>_.type==="book").length,B=$.filter(_=>_.type==="collection").length;a({works:U,books:C,collections:B})}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{let R=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const U=await t.getRecommended();if(U!=null&&U.groups)return U.groups.flatMap(C=>C.items.map(B=>({...B,group:C.name})))}catch{}return[]})().then(async U=>{if(R)return;const C=U.filter(_=>_.id);if(C.length===0){y(!1);return}const B=await Promise.all(C.map(async _=>{try{let P=null;if(t.getEntry)P=await t.getEntry(_.id);else{const I=await t.getItem(_.id);I&&(P={id:_.id,title:I.title||_.id,type:I.type||"work"})}if(P)return{...P,group:_.group,fallbackDescription:_.description}}catch{}return{id:_.id,title:_.title,type:O.extractType(_.id),group:_.group,fallbackDescription:_.description}}));R||(x(B.filter(_=>_!==null)),y(!1))}),()=>{R=!0}},[t,o]),f.useEffect(()=>{if(!t.getResourceProgress)return;let R=!1;return t.getResourceProgress().then($=>{R||k($)}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{if(!t.getSiteProgress)return;let R=!1;return t.getSiteProgress().then($=>{R||j($)}).catch(()=>{}),()=>{R=!0}},[t]),f.useEffect(()=>{if(!i||L!=="feedback")return;let R=!1;return h(!0),fetch(i).then($=>$.json()).then($=>{!R&&$.success&&b($.items||[])}).catch(()=>{}).finally(()=>{R||h(!1)}),()=>{R=!0}},[i,L]);const E=R=>{switch(R){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Le,{label:s.home.recommendTab,active:L==="recommend",onClick:()=>m("recommend")}),e.jsx(Le,{label:s.home.catalogTab,active:L==="catalog",onClick:()=>m("catalog")}),e.jsx(Le,{label:s.home.siteTab,active:L==="site",onClick:()=>m("site")}),i&&e.jsx(Le,{label:s.home.feedbackTab,active:L==="feedback",onClick:()=>m("feedback")})]}),L==="recommend"&&e.jsx(Zo,{recommended:p,loading:w,onNavigate:n,getIcon:E,t:s}),L==="catalog"&&e.jsx(Xo,{progress:z,t:s,onNavigate:n}),L==="site"&&e.jsx(er,{progress:S,t:s,totalWorks:(d==null?void 0:d.works)??0}),L==="feedback"&&i&&e.jsx(qt,{items:c,loading:v})]})})},Le=({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}),Zo=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:l})=>{const i=ie();if(n)return e.jsx(ge,{});if(t.length===0)return null;const s=new Map;for(const d of t){const a=d.group||l.home.recommendedBrowse;s.has(a)||s.set(a,[]),s.get(a).push(d)}return e.jsx(e.Fragment,{children:Array.from(s.entries()).map(([d,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:d}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(p=>{const x=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return e.jsxs("a",{href:i(p.id),onClick:u=>{u.metaKey||u.ctrlKey||(u.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})]}),x&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x})]})]},p.id)})})]},d))})},Xo=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((d,a)=>d.priority-a.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(d=>{const a=r.filter(p=>p.status===d);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:s[d]}}),i[d]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(p=>e.jsx(Qo,{item:p,t:n,statusColor:s[d],onNavigate:o},p.id))})]},d)})})},Qo=({item:t,t:n,statusColor:o,onNavigate:r})=>{const l=ie(),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 d=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:l(a),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(a))},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:d}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),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?ze(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})]})},er=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((a,p)=>a.priority-p.priority),l=r.filter(a=>a.imported>0),i=r.filter(a=>a.imported===0),s=l.reduce((a,p)=>Math.max(a,p.imported),0),d=o>0?Math.round(s/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:s.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),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(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(a=>e.jsx(ft,{item:a,t:n,totalWorks:o},a.id))})]})]})},ft=({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})]})},gt="(max-width: 768px)";function tr(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(gt).matches);return f.useEffect(()=>{const o=window.matchMedia(gt),r=l=>n(l.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const nr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:l})=>{var P;const i=A(),{convert:s}=H(),d=tr(),[a,p]=f.useState(null),[x,u]=f.useState(null),[g,c]=f.useState(!1),[b,v]=f.useState("detail"),[h,L]=f.useState([]),[m,w]=f.useState(!1),[y,z]=f.useState(null),[k,S]=f.useState(!1),j=f.useCallback(async I=>{if(!t.getCollatedEditionIndex){z(null);return}S(!0);try{const W=await t.getCollatedEditionIndex(I);z(W)}catch{z(null)}finally{S(!1)}},[t]),E=f.useCallback(async I=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){L([]);return}w(!0);try{if(t.getCollectionCatalogs){const W=await t.getCollectionCatalogs(I);L(W||[])}else if(t.getCollectionCatalog){const W=await t.getCollectionCatalog(I);L(W?[{resource_id:"",data:W}]:[])}}catch{L([])}finally{w(!1)}},[t]),R=f.useCallback(async I=>{if(o){o(I);return}p(I),u(null),L([]),z(null),v("detail"),c(!0);try{const W=await t.getItem(I.id);W&&(u(W),W.type==="collection"?E(I.id):W.type==="work"&&W.has_collated&&j(I.id))}catch(W){console.error("加载详情失败:",W)}finally{c(!1)}},[t,o,E,j]),$=f.useCallback(async I=>{u(null),L([]),z(null),v("detail"),c(!0);try{const W=await t.getItem(I);W&&(u(W),p({id:I,title:W.title||I,type:W.type||"book"}),W.type==="collection"?E(I):W.type==="work"&&W.has_collated&&j(I))}catch(W){console.error("导航失败:",W)}finally{c(!1)}},[t,E,j]),U=(x==null?void 0:x.type)==="collection"&&(h.length>0||m)||(x==null?void 0:x.type)==="work"&&(y||k),C=d&&(g||x),B=f.useCallback(()=>{p(null),u(null),L([]),z(null),v("detail")},[]),_=e.jsx(e.Fragment,{children:g?e.jsx(ge,{}):x?e.jsxs(e.Fragment,{children:[(U||l)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:d?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:d?"auto":void 0},children:[U&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:Ee(b==="detail"),children:i.detailTab.basicInfo}),x.type==="collection"&&m&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:Ee(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),x.type==="collection"&&h.map(I=>e.jsx("button",{onClick:()=>v(`catalog:${I.resource_id}`),style:Ee(b===`catalog:${I.resource_id}`),children:I.short_name?`${s(I.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},I.resource_id)),x.type==="work"&&(y||k)&&e.jsxs("button",{onClick:()=>v("collated"),style:Ee(b==="collated"),children:[i.detailTab.collatedEdition,k&&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:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(Ge,{data:x,transport:t,onNavigate:$}):b.startsWith("catalog:")?e.jsx(Dt,{data:(P=h.find(I=>`catalog:${I.resource_id}`===b))==null?void 0:P.data,onNavigate:$}):b==="collated"?e.jsx(Gt,{index:y||void 0,workId:x.id,transport:t,onNavigate:$}):null})]}):e.jsx(Ne,{transport:t,onNavigate:$,recommendedIds:r})});return d?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:C?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:_})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ve,{transport:t,onEntryClick:R,hideModeIndicator:n}),!x&&e.jsx(Ne,{transport:t,onNavigate:$,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(Ve,{transport:t,onEntryClick:R,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:_})]})};function Ee(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const or=({data:t,onNavigate:n,className:o,style:r})=>{var x;const l=A(),{convert:i}=H(),[s,d]=f.useState(((x=t.divisions[0])==null?void 0:x.name)??null),[a,p]=f.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[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(u=>e.jsx(rr,{division:u,expanded:s===u.name,onToggle:()=>d(s===u.name?null:u.name),expandedCat:a,onCatToggle:g=>p(a===g?null:g),onNavigate:n},u.name))})]})},rr=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:l,onNavigate:i})=>{const{convert:s}=H(),d=t.categories.reduce((a,p)=>{const x=p.stats||{zhulu:0,cunmu:0};return a+(x.zhulu||0)+(x.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:s(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",d," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const p=`${t.name}/${a.name}`;return e.jsx(ir,{category:a,expanded:r===p,onToggle:()=>l(p),onNavigate:i},a.name)})})]})},ir=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,p,x,u;const{convert:l}=H(),i=((a=t.books)==null?void 0:a.zhulu)||[],s=((p=t.books)==null?void 0:p.cunmu)||[],d=(((x=t.stats)==null?void 0:x.zhulu)||i.length)+(((u=t.stats)==null?void 0:u.cunmu)||s.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:[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:[d," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||s.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(ht,{label:"著錄",books:i,onNavigate:r}),s.length>0&&e.jsx(ht,{label:"存目",books:s,onNavigate:r})]})]})},ht=({label:t,books:n,onNavigate:o})=>{const{convert:r}=H(),l=ie(),[i,s]=f.useState(n.length<=20),d=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:d.map((a,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:a.work_id&&o?e.jsx("a",{href:l(a.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},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:o,extraButtons:r,children:l})=>{const i=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:sr,children:"AI"}),n&&e.jsx("button",{onClick:n,style:lr,children:i.action.save})]})]}),l]})},lr={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},sr={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:o,placeholder:r,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=>o(i.target.value),placeholder:r,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"}})]}),fe=({value:t,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:l=>n(l.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"}})},We=({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 ar(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Be=({value:t,onChange:n,label:o})=>{const[r,l]=f.useState(!1),i=f.useRef(null),s=ar(t||"");return f.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&s?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),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(We,{children:s.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bt,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:d=>n(d.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"}})]})},bt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function cr(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function dr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Jt=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[l,i]=f.useState(null),s=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},d=u=>{n(t.filter((g,c)=>c!==u)),l===u&&i(null)},a=(u,g,c)=>{const b=[...t];b[u]={...b[u],[g]:c},n(b)},p=(u,g)=>{const c=[...t];c[u]={...c[u],type:g,id:"",name:""},n(c),g==="bookID"&&o&&o(b=>{const v=[...t];v[u]={...v[u],id:b.id,name:b.title,type:"bookID"},n(v)})},x=u=>{o&&o(g=>{const c=[...t];c[u]={...c[u],id:g.id,name:g.title,type:"bookID"},n(c)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>i(l===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:u.name||`${r.editor.sourcePlaceholder} ${g+1}`}),u.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:cr(u.type),color:"white",borderRadius:"3px",fontWeight:500},children:dr(u.type)}),e.jsx("button",{onClick:c=>{c.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),l===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!u.type&&e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>p(g,"bookID"),style:{...mt,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(g,"url"),style:{...mt,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})]})]})]}),u.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:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const c=[...t];c[g]={...c[g],type:"",id:"",name:""},n(c)},style:yt,children:r.action.changeType})]}),u.id&&u.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:u.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:u.id})]}),e.jsx("button",{onClick:()=>x(g),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>x(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),u.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:r.label.sourceName}),e.jsx("button",{onClick:()=>{const c=[...t];c[g]={...c[g],type:"",id:"",name:""},n(c)},style:yt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:u.name,onChange:c=>a(g,"name",c.target.value),placeholder:r.editor.sourceNamePlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:u.id,onChange:c=>a(g,"id",c.target.value),placeholder:"https://...",style:be})]})]}),u.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:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:u.details,onChange:c=>a(g,"details",c.target.value),placeholder:r.editor.detailsPlaceholder,style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:u.position,onChange:c=>a(g,"position",c.target.value),placeholder:"如: 卷三, p.52",style:be})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:u.version,onChange:c=>a(g,"version",c.target.value),placeholder:"如: v1.0, 2024-01",style:be})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:u.processor_version,onChange:c=>a(g,"processor_version",c.target.value),placeholder:"如: v0.1",style:be})]})]})]})]})})]},g)),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:r.action.addSource})]})]})},pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},be={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"},mt={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"},yt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Zt(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 Xt(t){return!t||t.length===0?"":JSON.stringify(t)}const Qt=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:l,belongsToWork:i,belongsToCollection:s,childWorks:d,childCollections:a,containedBooks:p,siblingBooks:x,onLinkEntity:u,onUnlinkEntity:g,onViewEntity:c,onCreateAndLink:b,onSaveRelations:v})=>{const h=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:h.section.relations})]}),v&&e.jsx("button",{onClick:v,style:pr,children:h.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:h.relation.belongsToWork,entity:i,onView:c,onUnlink:()=>g("workId"),onLink:()=>u("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ke,{direction:"up",title:h.relation.containedInCollection,entity:s,onView:c,onUnlink:()=>g("collectionId"),onLink:()=>u("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),i&&x&&x.length>0&&e.jsx(me,{direction:"horizontal",title:`${h.relation.siblingVersions} (${x.length})`,entities:x,onView:c,onAdd:()=>b("siblingBook","book",{workId:i.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:h.relation.parentWork,entity:r,onView:c,onUnlink:()=>g("parentWorkId"),onLink:()=>u("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),d&&d.length>0&&e.jsx(me,{direction:"down",title:`${h.relation.childWorks} (${d.length})`,entities:d,onView:c,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),a&&a.length>0&&e.jsx(me,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:c,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(me,{direction:"down",title:`${h.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:c,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{direction:"up",title:h.relation.correspondingWork,entity:i,onView:c,onUnlink:()=>g("workId"),onLink:()=>u("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ke,{direction:"up",title:h.relation.parentCollection,entity:l,onView:c,onUnlink:()=>g("parentCollectionId"),onLink:()=>u("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(me,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:c,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(me,{direction:"down",title:`${h.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:c,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},ke=({direction:t,title:n,entity:o,onView:r,onUnlink:l,onLink:i,onCreate:s,linkLabel:d,createLabel:a,notLinkedLabel:p,viewLabel:x,unlinkLabel:u})=>{const g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",c=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:c}),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:en(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(vt,{onClick:()=>r(o),title:x,children:"👁️"}),e.jsx(vt,{onClick:l,title:u,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(Ye,{onClick:i,children:d}),e.jsx(Ye,{onClick:s,primary:!0,children:a})]})]})},me=({direction:t,title:n,entities:o,onView:r,onAdd:l,addLabel:i,noneLabel:s,expandMoreLabel:d})=>{const[a,p]=f.useState(!1),x=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",u=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=a?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:u}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(c=>e.jsxs("div",{onClick:()=>r(c),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:en(c.type)}),e.jsx("span",{children:c.title})]},c.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[d," (",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:s}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Ye,{onClick:l,primary:!0,children:["+ ",i]})})]})},vt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:l=>{l.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}),Ye=({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 en(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const pr={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"},tn=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:l,onCreate:i,searchResults:s,onSearch:d,isLoading:a,excludeId:p})=>{const[x,u]=f.useState(""),g=p?s.filter(h=>h.id!==p):s;f.useEffect(()=>{t&&(u(""),d(""))},[t]);const c=h=>{u(h),d(h)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:xr,children:e.jsxs("div",{style:ur,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:l,style:fr,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:x,onChange:h=>c(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:gr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:He,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(h=>e.jsxs("div",{onClick:()=>r(h),style:hr,children:[e.jsx("span",{style:{fontSize:"16px"},children:v}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):x?e.jsxs("div",{style:He,children:["未找到匹配的",b]}):e.jsxs("div",{style:He,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:br,children:["创建新",b,"并关联"]})]})]})})},xr={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},ur={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)"},fr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},gr={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"},hr={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},He={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},br={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},jt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},mr={work:"📜",book:"📖",collection:"📚",entity:"👤"},nn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:l,onCancel:i})=>{const[s,d]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{t&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var g,c;(g=a.current)==null||g.focus(),(c=a.current)==null||c.select()},100))},[t,r==null?void 0:r.title]);const p=g=>{g.key==="Enter"&&s.trim()?x():g.key==="Escape"&&i()},x=()=>{s.trim()&&l(s.trim(),{...r,title:s.trim()})};if(!t)return null;const u=()=>{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`创建新${jt[n]}`}};return e.jsx("div",{style:yr,onClick:g=>{g.target===g.currentTarget&&i()},children:e.jsxs("div",{style:vr,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:mr[n]}),e.jsx("span",{children:u()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:s,onChange:g=>d(g.target.value),onKeyDown:p,placeholder:`请输入${jt[n]}名称...`,style:jr})]}),((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:Sr,children:"取消"}),e.jsx("button",{onClick:x,disabled:!s.trim(),style:{...kr,opacity:s.trim()?1:.6,cursor:s.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},yr={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},vr={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)"},jr={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"},Sr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},kr={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function wr(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function on(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Cr(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const rn=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:l,showCreateButton:i=!1,createButtonText:s,onSelect:d,onCancel:a,onCreate:p,onSearch:x})=>{const[u,g]=f.useState(""),[c,b]=f.useState([]),[v,h]=f.useState(!1),[L,m]=f.useState("recent");f.useEffect(()=>{t&&(g(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!u.trim()){b([]);return}const j=setTimeout(async()=>{h(!0);try{b(await x(u,o))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(j)},[u,o,x]);const w=f.useCallback(j=>{g(j.target.value),j.target.value.trim()&&m("search")},[]),y=f.useCallback(j=>l?j.filter(E=>E.id!==l):j,[l]);if(!t)return null;const z=n||(o==="all"?"选择实体":`选择${on(o)}`),k=y(r),S=y(c);return e.jsx("div",{style:Ir,children:e.jsxs("div",{style:zr,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:a,style:Tr,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:u,onChange:w,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Rr}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),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(St,{active:L==="recent",onClick:()=>m("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(St,{active:L==="search",onClick:()=>m("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:L==="recent"&&k.length>0?e.jsx(kt,{entities:k,onSelect:d}):u.trim()?v?e.jsx(Oe,{message:"搜索中..."}):S.length>0?e.jsx(kt,{entities:S,onSelect:d}):e.jsx(Oe,{message:"未找到匹配的结果"}):e.jsx(Oe,{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:Lr,children:s||"创建新实体"})]})]})})},St=({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}),kt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(_r,{entity:o,onClick:()=>n(o)},o.id))}),_r=({entity:t,onClick:n})=>{const[o,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:wr(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:Cr(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:on(t.type)})]})},Oe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Ir={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},zr={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)"},Tr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Rr={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"},Lr={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Er={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},Br={work:"📜",collection:"📚",book:"📖",entity:"👤"},ln=({data:t,onChange:n,onSave:o,transport:r,onNavigate:l,showDelete:i,onDelete:s,onAskAI:d,renderSectionActions:a,onDownloadResource:p,downloadStatuses:x,relations:u,onRelationsChange:g})=>{var te;const c=A(),[b,v]=f.useState(!1),[h,L]=f.useState("work"),[m,w]=f.useState(""),[y,z]=f.useState(""),[k,S]=f.useState([]),[j,E]=f.useState(!1),[R,$]=f.useState(!1),[U,C]=f.useState("work"),[B,_]=f.useState(""),[P,I]=f.useState(),[W,N]=f.useState(!1),[V,M]=f.useState(null),[le,Q]=f.useState([]);f.useRef(null);const de=t.type,ue=de==="work",xe=de==="collection",J=de==="book",Y=f.useCallback((T,D)=>{n({...t,[T]:D})},[t,n]),Ae=f.useCallback((T,D)=>{w(T),L(D),z(c.editor.selectToLink+c.indexType[D]),S([]),v(!0)},[c]),Pe=f.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),ye=f.useCallback(T=>{l==null||l(T.id,T.type)},[l]),ve=f.useCallback((T,D,q)=>{const se={...q,author:(q==null?void 0:q.author)||t.author,dynasty:(q==null?void 0:q.dynasty)||t.dynasty};C(D),_(T),I(se),$(!0)},[t.author,t.dynasty]),Fe=f.useCallback((T,D)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,B,{type:U,title:T,inheritData:D}),$(!1)},[r,t.id,B,U]),Te=f.useCallback(T=>{if(!T.trim()){S([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(T,h).then(D=>{S(D),E(!1)}).catch(()=>{S([]),E(!1)})},[r,h]),Me=f.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),v(!1)},[r,t.id,m]),F=f.useCallback(()=>{o()},[o]),K=f.useCallback(T=>{M(()=>T),N(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Q).catch(()=>{})},[r]),Z=f.useCallback((T,D)=>r!=null&&r.searchEntities?r.searchEntities(T,D==="all"?void 0:D):Promise.resolve([]),[r]),G=f.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Q(D=>[T,...D.filter(q=>q.id!==T.id)].slice(0,10)),V==null||V(T),N(!1),M(null)},[r,V]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Br[de]}),e.jsx("span",{children:t.title||c.editor.untitled}),e.jsx(We,{children:t.id}),e.jsx(We,{color:Er[de],children:c.indexType[de]})]})}),e.jsx(oe,{title:c.section.basicInfo,onSave:o,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Be,{label:ue?c.editor.workTitle:xe?c.editor.collectionTitle:c.editor.bookTitle,value:t.title,onChange:T=>Y("title",T)}),J&&e.jsx(Be,{label:c.editor.belongsToWork,value:t.workName||"",onChange:T=>Y("workName",T)}),e.jsx(ee,{label:c.editor.authorLabel,value:t.author||"",onChange:T=>Y("author",T)}),e.jsx(ee,{label:c.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>Y("dynasty",T)}),(J||xe)&&e.jsx(Be,{label:c.editor.containedIn,value:t.collection||"",onChange:T=>Y("collection",T)}),(J||xe)&&e.jsx(ee,{label:c.editor.holderLabel,value:t.holder||"",onChange:T=>Y("holder",T)}),(J||xe)&&e.jsx(ee,{label:J?c.editor.pageLabel:c.editor.volumeLabel,value:t.pages||"",onChange:T=>Y("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ee,{label:c.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>Y("firstImage",T)})})]})}),e.jsx(oe,{title:c.section.description,onSave:o,onAskAI:d?()=>d("介绍"):void 0,children:e.jsx(fe,{value:t.description||"",onChange:T=>Y("description",T),placeholder:c.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(oe,{title:c.section.additionalWorks,onSave:o,children:e.jsx(Wr,{items:t.additional_works||[],onChange:T=>Y("additional_works",T)})}),e.jsx(oe,{title:c.section.indexedBy,onSave:o,onAskAI:d?()=>d("收录于"):void 0,children:e.jsx($r,{items:t.indexed_by||[],onChange:T=>Y("indexed_by",T)})}),e.jsx(oe,{title:c.section.emendatedBy,onSave:o,onAskAI:d?()=>d("考证"):void 0,children:e.jsx(Ar,{items:t.emendated_by||[],onChange:T=>Y("emendated_by",T)})}),e.jsx(oe,{title:c.section.textResources,onSave:o,onAskAI:d?()=>d("资源"):void 0,children:e.jsx(Ue,{items:t.resources||[],onChange:T=>Y("resources",T),onDownload:p,downloadStatuses:x,filterType:"text"})}),e.jsx(oe,{title:c.section.imageResources,onSave:o,children:e.jsx(Ue,{items:t.resources||[],onChange:T=>Y("resources",T),onDownload:p,downloadStatuses:x,filterType:"image"})}),e.jsx(oe,{title:c.section.sources,onSave:o,onAskAI:d?()=>d("资料来源"):void 0,children:e.jsx(Jt,{items:Zt(t.sources||""),onChange:T=>Y("sources",Xt(T)),onOpenEntityPicker:K})}),(J||xe)&&e.jsx(oe,{title:c.section.provenance,onSave:o,onAskAI:d?()=>d("收藏历史"):void 0,children:e.jsx(fe,{value:t.provenance||"",onChange:T=>Y("provenance",T),placeholder:c.editor.provenancePlaceholder})}),J&&e.jsx(oe,{title:c.section.otherEditions,onSave:o,onAskAI:d?()=>d("其他版本"):void 0,children:e.jsx(fe,{value:t.otherEditions||"",onChange:T=>Y("otherEditions",T),placeholder:c.editor.otherEditionsPlaceholder})}),e.jsx(Qt,{entityType:de,entityId:t.id,entityTitle:t.title,parentWork:u==null?void 0:u.parentWork,parentCollection:u==null?void 0:u.parentCollection,belongsToWork:u==null?void 0:u.belongsToWork,belongsToCollection:u==null?void 0:u.belongsToCollection,childWorks:u==null?void 0:u.childWorks,childCollections:u==null?void 0:u.childCollections,containedBooks:u==null?void 0:u.containedBooks,siblingBooks:u==null?void 0:u.siblingBooks,onLinkEntity:Ae,onUnlinkEntity:Pe,onViewEntity:ye,onCreateAndLink:ve,onSaveRelations:F}),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:c.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:c.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:c.editor.deleteEntity})]}),e.jsx(tn,{isOpen:b,entityType:h,title:y,onSelect:Me,onCancel:()=>v(!1),onCreate:()=>{v(!1),ve(m,h)},searchResults:k,onSearch:Te,isLoading:j,excludeId:t.id}),e.jsx(nn,{isOpen:R,entityType:U,relationField:B,inheritData:P,onConfirm:Fe,onCancel:()=>$(!1)}),e.jsx(rn,{isOpen:W,title:c.action.selectBookOrWork,filterType:"all",recentEntities:le,excludeId:t.id,onSelect:G,onCancel:()=>{N(!1),M(null)},onSearch:Z})]})};function Wr({items:t,onChange:n}){const o=A(),r=(s,d,a)=>{const p=t.map((x,u)=>u===s?{...x,[d]:a}:x);n(p)},l=s=>n(t.filter((d,a)=>a!==s)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,d)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ee,{label:o.editor.bookNameLabel,value:s.book_title,onChange:a=>r(d,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ee,{label:o.label.juanCount,value:s.n_juan!=null?String(s.n_juan):"",onChange:a=>r(d,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>l(d),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},d)),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 sn({items:t,onChange:n,showMeta:o,addLabel:r}){const l=A(),[i,s]=f.useState(null),d=(x,u,g)=>{const c=t.map((b,v)=>v===x?{...b,[u]:g||void 0}:b);n(c)},a=x=>{n(t.filter((u,g)=>g!==x)),i===x&&s(null)},p=()=>{n([...t,{source:""}]),s(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,u)=>{const g=i===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>s(g?null:u),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:x.source||l.editor.unnamedSource}),x.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:x.source_bid}),e.jsx("button",{onClick:c=>{c.stopPropagation(),a(u)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&o&&(x.title_info||x.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[x.title_info,x.title_info&&x.author_info&&" — ",x.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ee,{label:l.label.sourceName,value:x.source,onChange:c=>d(u,"source",c)}),e.jsx(ee,{label:l.label.sourceBid,value:x.source_bid||"",onChange:c=>d(u,"source_bid",c)})]}),o&&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:x.title_info||"",onChange:c=>d(u,"title_info",c)}),e.jsx(ee,{label:l.label.authorInfo,value:x.author_info||"",onChange:c=>d(u,"author_info",c)})]}),e.jsx(ee,{label:l.label.edition,value:x.edition||"",onChange:c=>d(u,"edition",c)})]}),e.jsx(fe,{value:x.summary||"",onChange:c=>d(u,"summary",c),placeholder:l.editor.summaryPlaceholder}),e.jsx(fe,{value:x.comment||"",onChange:c=>d(u,"comment",c),placeholder:l.editor.commentPlaceholder}),e.jsx(fe,{value:x.additional_comment||"",onChange:c=>d(u,"additional_comment",c),placeholder:l.editor.additionalCommentPlaceholder})]})]},u)}),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 $r({items:t,onChange:n}){const o=A();return e.jsx(sn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Ar({items:t,onChange:n}){const o=A();return e.jsx(sn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function an(t){var d,a,p,x,u,g,c;const n=((a=(d=t.authors)==null?void 0:d[0])==null?void 0:a.name)||"",o=((p=t.publication_info)==null?void 0:p.year)||"",r=((x=t.current_location)==null?void 0:x.name)||"",l=(u=t.page_count)!=null&&u.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",s={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,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 v=b.related_works.find(h=>h.relation==="part_of");v&&(s.parentWorkId=v.id,s.parentWorkName=v.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=(c=b.contained_in[0])==null?void 0:c.id)}return s}function Pr(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 Fr=t=>{const{data:n,id:o,transport:r,mode:l="view",onModeChange:i,onChange:s,onSave:d,onDelete:a,onNavigate:p,renderLink:x,onAskAI:u,renderSectionActions:g,onDownloadResource:c,downloadStatuses:b,relations:v,onRelationsChange:h,headerExtra:L,className:m,style:w}=t;A();const[y,z]=f.useState(l),k=i?l:y;f.useEffect(()=>{l!==y&&z(l)},[l]);const S=f.useCallback(()=>{const B=k==="view"?"edit":"view";i?i(B):z(B)},[k,i]),[j,E]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(B=>{B&&E(B)})},[o,r]);const R=n||j,$=f.useMemo(()=>R?an(R):null,[R]),U=i||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:k==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:k==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:k==="view"?"切换到编辑模式":"切换到查看模式",children:k==="view"?"✏️ 编辑":"👁 查看"}):null,C=e.jsxs(e.Fragment,{children:[U,L]});return!R&&!$?e.jsx(ge,{}):k==="view"?e.jsx(Ge,{data:R,transport:r,onNavigate:p?B=>p(B):void 0,renderLink:x,headerExtra:C,className:m,style:w}):$?e.jsxs("div",{className:m,style:w,children:[C&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:C}),e.jsx(ln,{data:$,onChange:s||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:p,showDelete:!!a,onDelete:a,onAskAI:u,renderSectionActions:g,onDownloadResource:c,downloadStatuses:b,relations:v,onRelationsChange:h})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},wt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],cn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[l,i]=f.useState(null),[s,d]=f.useState(""),[a,p]=f.useState("idle"),[x,u]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(i(null),d(""),p("idle"),u(""))},[t]),f.useEffect(()=>{l&&setTimeout(()=>{var h;return(h=g.current)==null?void 0:h.focus()},100)},[l]),f.useEffect(()=>{if(a==="success"){const h=setTimeout(n,2e3);return()=>clearTimeout(h)}},[a,n]),f.useEffect(()=>{if(!t)return;const h=L=>{L.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t,n]);const c=async()=>{if(!(!l||!s.trim())){p("submitting"),u("");try{await o({type:l,content:s.trim()}),p("success")}catch(h){p("error"),u(h instanceof Error?h.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=l&&s.trim()&&a!=="submitting",v=wt.find(h=>h.value===l);return e.jsx("div",{style:Mr,onClick:h=>{h.target===h.currentTarget&&n()},children:e.jsxs("div",{style:Dr,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:Hr,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Or,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Kr,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:wt.map(h=>e.jsxs("button",{onClick:()=>i(h.value),style:{...Ur,...l===h.value?Vr:{}},children:[e.jsx("span",{children:h.icon})," ",h.label]},h.value))}),e.jsx("textarea",{ref:g,value:s,onChange:h=>d(h.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!l||a==="submitting",style:{...Nr,opacity:l?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[s.length," / 2000"]}),a==="error"&&e.jsx("div",{style:Gr,children:x}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:c,disabled:!b,style:{...Yr,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Mr={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},Dr={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)"},Hr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Or={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Ur={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"},Vr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Nr={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"},Yr={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Kr={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Gr={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},qr=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,l]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>l(!0),style:{...Jr,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(cn,{isOpen:r,onClose:()=>l(!1),onSubmit:t,feedbackListUrl:o})]})},Jr={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"},Ct=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Zr=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,l]=f.useState(""),[i,s]=f.useState("idle"),[d,a]=f.useState(""),p=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var c;return(c=p.current)==null?void 0:c.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){s("submitting"),a("");try{await t({type:n,content:r.trim()}),s("success"),l(""),o("bug")}catch(c){s("error"),a(c instanceof Error?c.message:"提交失败,请稍后重试")}}},u=n&&r.trim()&&i!=="submitting",g=Ct.find(c=>c.value===n);return i==="success"?e.jsx("div",{style:_t,children:e.jsxs("div",{style:ni,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>s("idle"),style:oi,children:"继续提交"})]})}):e.jsxs("div",{style:_t,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ct.map(c=>e.jsxs("button",{onClick:()=>o(c.value),style:{...Xr,...n===c.value?Qr:{}},children:[e.jsx("span",{children:c.icon})," ",c.label]},c.value))}),e.jsx("textarea",{ref:p,value:r,onChange:c=>l(c.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...ei}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:x,disabled:!u,style:{...ti,opacity:u?1:.6,cursor:u?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:ri,children:d})]})},_t={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Xr={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"},Qr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ei={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ti={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ni={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},oi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ri={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},ii=({style:t})=>{const n=f.useContext(Ie);if(!n)return null;const{locale:o,setLocale:r}=n,l=o==="zh-Hant",i=()=>r(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=We;exports.BidUrlProvider=yn;exports.CollatedEdition=Gt;exports.CollectionCatalog=Dt;exports.CreateEntityDialog=nn;exports.EmendatedBySection=Ft;exports.EntityDetail=Bt;exports.EntityPickerDialog=rn;exports.EntitySelector=tn;exports.FeedbackButton=qr;exports.FeedbackDialog=cn;exports.FeedbackForm=Zr;exports.FeedbackList=qt;exports.FormInput=ee;exports.FormTextArea=fe;exports.HomePage=Ne;exports.IndexApp=nr;exports.IndexBrowser=Ve;exports.IndexDetail=Ge;exports.IndexEditor=ln;exports.IndexView=Fr;exports.LocaleContext=Ie;exports.LocaleProvider=Cn;exports.LocaleToggle=ii;exports.ModeIndicator=Lt;exports.RelationPanel=Qt;exports.ResourceEditor=Ue;exports.ResourceList=Ke;exports.SearchInput=Et;exports.Section=oe;exports.SmartBidInput=Be;exports.SourceEditor=Jt;exports.WorkCatalog=or;exports.detailToEditor=an;exports.editorToDetail=Pr;exports.formatTemplate=ze;exports.parseSourceString=Zt;exports.stringifySources=Xt;exports.useBidUrl=ie;exports.useConvert=H;exports.useT=A;