book-index-ui 0.2.1 → 0.2.4

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 Qt=Object.create;var Ue=Object.defineProperty;var en=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames;var nn=Object.getPrototypeOf,on=Object.prototype.hasOwnProperty;var rn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of tn(n))!on.call(t,i)&&i!==o&&Ue(t,i,{get:()=>n[i],enumerable:!(r=en(n,i))||r.enumerable});return t};var ln=(t,n,o)=>(o=t!=null?Qt(nn(t)):{},rn(n||!t||!t.__esModule?Ue(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("./storage-entry-DawKmokc.cjs"),e=require("react/jsx-runtime"),p=require("react"),Se=p.createContext(null),yt={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:"清除全部",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:"圖片資源"}},sn={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:"清除全部",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:"图片资源"}},an={"zh-Hant":yt,"zh-Hans":sn},vt="bim-locale";function dn(){try{const t=localStorage.getItem(vt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function cn(t){try{localStorage.setItem(vt,t)}catch{}}const pn="zh-Hant",xn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=p.useState(t??pn),l=t??r;p.useEffect(()=>{if(t)return;const g=dn();g&&g!==r&&i(g)},[]);const[d,a]=p.useState(null);p.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});a(()=>x)}).catch(()=>{a(()=>g=>g)}):a(null)},[l]);const s=p.useCallback(g=>{i(g),cn(g),n==null||n(g)},[n]),u=p.useMemo(()=>({locale:l,setLocale:s,messages:an[l],converter:d}),[l,s,d]);return e.jsx(Se.Provider,{value:u,children:o})};function A(){const t=p.useContext(Se);return(t==null?void 0:t.messages)??yt}const un=2e3;function H(){const t=p.useContext(Se),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=p.useRef(new Map),i=p.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=p.useCallback(d=>{if(!d)return"";if(!o)return d;const a=r.current.get(d);if(a!==void 0)return a;const s=o(d);if(r.current.size>=un){const u=r.current.keys().next().value;u!==void 0&&r.current.delete(u)}return r.current.set(d,s),s},[o]);return p.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function ke(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function gn(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 fn(){return{id:"",name:"",url:"",type:"text",details:""}}const $e=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=A(),[d,a]=p.useState(null),s=[{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}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],g=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})=>g(b.type)),h=()=>{const b=fn();i&&(b.type=i),n([...t,b]),a(t.length)},c=b=>{n(t.filter((_,m)=>m!==b)),a(null)},y=(b,_,m)=>{const T=[...t];if(T[b]={...T[b],[_]:m},_==="url"&&!T[b].id){const w=gn(m);w&&(T[b].id=w)}n(T)},I=(b,_,m)=>{const w={...t[b].metadata||{}};m?w[_]=m:delete w[_],y(b,"metadata",Object.keys(w).length>0?w:void 0)},f=(b,_)=>{const m=_.trim()?_.split(/[,,、]/).map(T=>T.trim()).filter(Boolean):void 0;y(b,"structure",m)},E=(b,_,m)=>{const w=t[b].coverage||{level:1,ranges:""};_==="level"?w.level=parseInt(m)||1:w.ranges=m,y(b,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:_})=>{var m,T,w,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:()=>a(d===_?null:_),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:d===_?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:hn(b.type),color:"#fff"},children:((m=s.find(v=>v.value===b.type))==null?void 0:m.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&&bn(_,r==null?void 0:r[_],o,l),e.jsx("button",{onClick:v=>{v.stopPropagation(),c(_)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),d===_&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(b.type==="image"||b.type==="text+image")&&b.url&&mn(b,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:me,children:[e.jsx("span",{style:ye,children:l.label.type}),e.jsx("select",{value:b.type,onChange:v=>y(_,"type",v.target.value),style:{...le,flex:1},children:s.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value))})]}),e.jsxs("label",{style:me,children:[e.jsx("span",{style:ye,children:l.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:v=>y(_,"root_type",v.target.value),style:{...le,flex:1},children:u.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=>y(_,"id",v.target.value),placeholder:l.editor.idAutoExtract,style:{...le,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:v=>y(_,"name",v.target.value),placeholder:l.editor.resourceName,style:{...le,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:v=>y(_,"url",v.target.value),placeholder:l.editor.resourceUrl,style:le}),e.jsx("input",{type:"text",value:((T=b.structure)==null?void 0:T.join("、"))||"",onChange:v=>f(_,v.target.value),placeholder:l.editor.structurePlaceholder,style:le}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:me,children:[e.jsx("span",{style:ye,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=b.coverage)==null?void 0:w.level)??"",onChange:v=>E(_,"level",v.target.value),placeholder:"1",style:{...le,width:"60px"}})]}),e.jsxs("label",{style:{...me,flex:1},children:[e.jsx("span",{style:ye,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((S=b.coverage)==null?void 0:S.ranges)||"",onChange:v=>E(_,"ranges",v.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...le,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:v=>y(_,"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,B])=>{var C;return e.jsxs("label",{style:{...me,gap:"4px"},children:[e.jsx("span",{style:{...ye,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((C=b.metadata)==null?void 0:C[v])||"",onChange:W=>I(_,v,W.target.value),placeholder:B,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 hn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function bn(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:d=>{d.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 mn(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"},me={display:"flex",alignItems:"center",gap:"6px"},ye={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},yn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function vn(t){try{const n=new URL(t).hostname;return yn[n]}catch{return}}const Ne={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},jn=["text","image","text+image","physical"];function Sn(t){const n=l=>{const d=l.match(/^(.+?)·第(\d+)[冊册]$/);if(d)return[d[1],parseInt(d[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const d=t[l];if(d.volumes&&d.volumes.length>0)continue;const a=n(d.name);if(!a)continue;const[s,u]=a,g=`${s}|${d.type}`;o.has(g)||o.set(g,{base:{...d,name:s,url:"",volumes:[]},volumes:[]}),o.get(g).volumes.push({volume:u,url:d.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((d,a)=>d.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let d=0;d<t.length;d++)if(i.has(d)){const a=n(t[d].name);a&&`${a[0]}|${t[d].type}`==`${l.base.name}|${l.base.type}`&&i.delete(d)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const He=({items:t,groupByType:n=!0})=>{const o=A(),r=p.useMemo(()=>Sn(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((d,a)=>e.jsx(Ge,{item:d},d.id||a))});const l=jn.map(d=>({type:d,items:r.filter(a=>a.type===d)})).filter(d=>d.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:l.map(({type:d,items:a})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ne[d],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ne[d]}}),i[d],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",a.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:a.map((s,u)=>e.jsx(Ge,{item:s},s.id||u))})]},d))})},Ye=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},jt=({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})},kn=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(jt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function wn(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 Cn(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 In(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 zn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ge=({item:t})=>{var h;const n=A(),{convert:o}=H(),[r,i]=p.useState(!1),l=p.useMemo(()=>(t.url?vn(t.url):void 0)||o(t.name),[t.url,t.name,o]),d=p.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(c=>({...c,url:c.url||In(c)})),[t.volumes]),a=d&&d.length>0,s=a?d.filter(c=>c.status!=="missing").length:0,u=a?d.length-s:0,g=t.expected_volumes??(a?d.length:0),x=t.color_mode?{...zn[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:Ye(t)||a?"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(jt,{value:t.metadata.check_type}),a&&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:[s,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:r?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const c=Cn(t.metadata);return c?wn(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})]}),Ye(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,y])=>e.jsxs("span",{children:[n.metadata[c]||c,": ",kn(c,y,n,o)]},c)),t.details&&!a&&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]})]}),a&&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:d.map(c=>{const y=c.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:c.url&&!y?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:y?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1,lineHeight:1.4},children:c.volume})},c.volume)})})]})},St=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:d})=>{const a=A(),s=t==="local",u=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",x=g?g.split(/[/\\]/).pop()||g:"",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)"},c={onMouseOver:I=>I.currentTarget.style.opacity="0.8",onMouseOut:I=>I.currentTarget.style.opacity="1"},y=e.jsxs("div",{onClick:i,title:u?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...c,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return o==="index-browser"?s?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[y,e.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:h,...c,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:d,title:g||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...c,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:[y,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:h,...c,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||a.mode.configurePath,style:{...h,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:s?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...c,children:[e.jsx("span",{children:s?"📁":"🌐"}),e.jsx("span",{children:s?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),s&&e.jsxs("div",{onClick:d,title:g||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...c,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!s&&x&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Re="bim-search-history",Ke=10,Je=8;function je(){try{const t=localStorage.getItem(Re);return t?JSON.parse(t):[]}catch{return[]}}function _n(t){try{const n=je().filter(o=>o!==t);n.unshift(t),n.length>Ke&&(n.length=Ke),localStorage.setItem(Re,JSON.stringify(n))}catch{}}function Tn(t){try{const n=je().filter(o=>o!==t);localStorage.setItem(Re,JSON.stringify(n))}catch{}}function Rn(){try{localStorage.removeItem(Re)}catch{}}const kt=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const d=A(),a=l??d.search.placeholder,s={work:d.indexType.work,book:d.indexType.book,collection:d.indexType.collection},[u,g]=p.useState(!1),[x,h]=p.useState([]),[c,y]=p.useState(-1),[I,f]=p.useState(null),[E,b]=p.useState(je),_=p.useRef(null),m=p.useRef(null),T=p.useRef(null);p.useEffect(()=>{if(!t.getAllEntries)return;let j=!1;return t.getAllEntries().then(P=>{j||f(P)}).catch(()=>{}),()=>{j=!0}},[t]);const w=p.useCallback(j=>{if(!j.trim())return E.map(k=>({type:"history",text:k}));if(!I)return[];const P=j.toLowerCase(),$=[],O=[];for(const k of I){if($.length+O.length>=Je*2)break;const L=k.title.toLowerCase();if(L.startsWith(P))$.push({type:"entry",text:k.title,entry:k});else if(L.includes(P))O.push({type:"entry",text:k.title,entry:k});else{const N=[...k.additional_titles||[],...k.attached_texts||[]];for(const U of N){const F=typeof U=="string"?U:U==null?void 0:U.book_title;if(F!=null&&F.toLowerCase().includes(P)){$.push({type:"entry",text:`${k.title}`,entry:k});break}}}}return[...$,...O].slice(0,Je)},[I,E]);p.useEffect(()=>{h(w(n)),y(-1)},[n,w]),p.useEffect(()=>{const j=P=>{T.current&&!T.current.contains(P.target)&&g(!1)};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[]),p.useEffect(()=>{const j=P=>{var $,O;if(P.key==="/"&&document.activeElement!==_.current){const k=($=document.activeElement)==null?void 0:$.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT")return;P.preventDefault(),(O=_.current)==null||O.focus()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[]);const S=p.useCallback(j=>{j.trim()&&(_n(j.trim()),b(je())),r(j),g(!1)},[r]),v=p.useCallback(j=>{j.type==="history"?(o(j.text),S(j.text)):j.entry&&(i?(i(j.entry),g(!1)):(o(j.text),S(j.text)))},[o,S,i]),B=p.useCallback(j=>{if(!u||x.length===0){j.key==="Enter"&&S(n);return}switch(j.key){case"ArrowDown":j.preventDefault(),y(P=>(P+1)%x.length);break;case"ArrowUp":j.preventDefault(),y(P=>(P-1+x.length)%x.length);break;case"Enter":j.preventDefault(),c>=0&&c<x.length?v(x[c]):S(n);break;case"Escape":j.preventDefault(),g(!1);break}},[u,x,c,n,S,v]),C=p.useCallback((j,P)=>{P.stopPropagation(),Tn(j),b(je()),h($=>$.filter(O=>!(O.type==="history"&&O.text===j)))},[]),W=p.useCallback(j=>{j.stopPropagation(),Rn(),b([]),h([])},[]);p.useEffect(()=>{if(c>=0&&m.current){const j=m.current.children;j[c]&&j[c].scrollIntoView({block:"nearest"})}},[c]);const R=!n.trim()&&E.length>0;return e.jsxs("div",{ref:T,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:_,type:"text",placeholder:a,value:n,onChange:j=>{o(j.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:B,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"}}),u&&x.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&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:d.search.history}),e.jsx("button",{onClick:W,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:d.search.clearAll})]}),x.map((j,P)=>e.jsxs("div",{onClick:()=>v(j),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:P===c?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:j.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.text}),j.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[s[j.entry.type],j.entry.edition&&` · ${j.entry.edition}`,j.entry.author&&` · ${j.entry.author}`]}),j.type==="history"&&e.jsx("button",{onClick:$=>C(j.text,$),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:d.action.remove,children:"×"})]},`${j.type}-${j.text}-${P}`))]})]})},Pe="bim-recent-ids",Ze="bim-recent-entries",Xe=50,Le=5,En=50,Ln=200;function Ae(){try{const t=localStorage.getItem(Pe);if(t)return JSON.parse(t);const n=localStorage.getItem(Ze);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Pe,JSON.stringify(o)),localStorage.removeItem(Ze),o}return[]}catch{return[]}}function Bn(t){try{const n=Ae().filter(o=>o!==t);n.unshift(t),n.length>Xe&&(n.length=Xe),localStorage.setItem(Pe,JSON.stringify(n))}catch{}}const Wn={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},Me=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:d,onConfigurePath:a,onSelectFolder:s,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:h})=>{const c=A(),y=[{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"}],[I,f]=p.useState(g??""),[E,b]=p.useState(null),[_,m]=p.useState(null),[T,w]=p.useState(!1),[S,v]=p.useState(null),[B,C]=p.useState(""),[W,R]=p.useState(!g),[j,P]=p.useState(Ae),[$,O]=p.useState([]),[k,L]=p.useState(!1),[N,U]=p.useState(!1),[F,oe]=p.useState(null),te=p.useRef(void 0),re=p.useRef(!1),ie=p.useCallback(async(M,K)=>{if(!M.trim()){R(!0),b(null),m(null);return}R(!1),w(!0),C("");try{if(t.searchAll){const G=await t.searchAll(M,K??Le);b(G)}else{const G=["work","book","collection"],J=await Promise.all(G.map(Q=>t.search(M,Q,{page:1,pageSize:K??Le})));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(G){C(G instanceof Error?G.message:String(G)),b(null)}finally{w(!1)}},[t]);p.useEffect(()=>{var Q;let M=!1;const K=["work","book","collection"],G=Promise.all(K.map(Z=>t.loadEntries(Z,{page:1,pageSize:1}).catch(()=>({total:0})))),J=((Q=t.getResourceCounts)==null?void 0:Q.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([G,J]).then(([Z,V])=>{M||oe({works:Z[0].total,books:Z[1].total,collections:Z[2].total,hasText:V==null?void 0:V.hasText,hasImage:V==null?void 0:V.hasImage})}),()=>{M=!0}},[t]),p.useEffect(()=>{re.current||!(g!=null&&g.trim())||(re.current=!0,ie(g))},[g,ie]);const xe=p.useCallback(M=>{if(f(M),x==null||x(M),!M.trim()){R(!0),b(null),m(null);return}te.current&&clearTimeout(te.current),te.current=setTimeout(()=>{m(null),ie(M)},Ln)},[ie,x]),de=p.useCallback(M=>{te.current&&clearTimeout(te.current),x==null||x(M),ie(M)},[ie,x]),Y=p.useCallback(M=>{m(M),ie(I,En)},[I,ie]);p.useEffect(()=>{if(!j.length){O([]);return}let M=!1;return L(!0),Promise.all(j.slice(0,10).map(async K=>{var G,J,Q;try{if(t.getEntry){const V=await t.getEntry(K);if(V)return V}const Z=await t.getItem(K);if(Z){const V=Z.authors;return{id:K,title:Z.title||K,type:Z.type||"work",author:(G=V==null?void 0:V[0])==null?void 0:G.name,dynasty:(J=V==null?void 0:V[0])==null?void 0:J.dynasty,role:(Q=V==null?void 0:V[0])==null?void 0:Q.role,edition:Z.edition||void 0}}}catch{}return null})).then(K=>{M||(O(K.filter(G=>G!==null)),L(!1))}),()=>{M=!0}},[j,t]);const be=M=>{v(M.id),Bn(M.id),P(Ae()),r==null||r(M)},we=M=>y.find(K=>K.type===M),Ee=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:c.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&e.jsx(St,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:d,onConfigurePath:a,onSelectFolder:s})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(kt,{transport:t,value:I,onChange:xe,onSearch:de,onEntrySelect:be}),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:c.action.newEntry})]}),F&&W&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between"},children:[e.jsxs("span",{children:[c.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[c.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),c.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:c.search.searching}):B?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:B})]}):W?e.jsx("div",{style:{flex:1},children:k?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.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:c.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,N?10:3).map(M=>e.jsx(qe,{entry:M,selected:S===M.id,onClick:be,getConfig:we},M.id))}),!N&&$.length>3&&e.jsx("button",{onClick:()=>U(!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})]})}):Ee?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:y.map(({type:M,icon:K,name:G,key:J})=>{const Q=E[J],Z=Wn[J],V=E[Z];if(Q.length===0)return null;const Ce=!(_===M)&&V>Le;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," ",G,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[V," ",c.unit.items]})]}),Ce&&e.jsx("button",{onClick:()=>Y(M),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:Q.map(z=>e.jsx(qe,{entry:z,selected:S===z.id,onClick:be,getConfig:we,query:I},z.id))})]},M)})}):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:ke(c.search.noResultsFor,{query:I})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.search.tryOther})]})})]})},qe=({entry:t,selected:n,onClick:o,getConfig:r,query:i})=>{const l=A(),{convert:d}=H(),a=[...t.additional_titles||[],...t.attached_texts||[]],s=i&&a.length?a.find(u=>{const g=typeof u=="string"?u:u==null?void 0:u.book_title;return g==null?void 0:g.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:d(t.title)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:d(t.edition)}),t.juan_count!=null&&t.juan_count>0&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]})]}),(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)]})]}),s&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",d(s)]})]}),e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},$n=["〇","一","二","三","四","五","六","七","八","九"],Qe=["","十","百","千"];function wt(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 d=parseInt(n[l]),a=o-1-l;d===0?i=!0:(i&&r&&(r+="〇"),i=!1,d===1&&a===1&&l===0?r+=Qe[a]:r+=$n[d]+Qe[a])}return r}function Ct({type:t}){const n=A(),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 Pn({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 An({id:t}){const n=A(),[o,r]=p.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 ee({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 It({authors:t,type:n}){const{convert:o}=H();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}){return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:`/book-index?id=${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 Mn({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:d,meta:a,headerExtra:s}){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}),d&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:d})]}),s&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:s})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Ct,{type:r}),e.jsx(Pn,{isDraft:i}),e.jsx(An,{id:t})]}),((l==null?void 0:l.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(It,{authors:l,type:r}),a]})]})}function zt({items:t,label:n,showMeta:o,onNavigate:r,renderLink:i}){const l=A(),{convert:d}=H();if(!t.length)return null;const[a,s]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((u,g)=>{const x=a===g;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:()=>s(x?null:g),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:d(u.source)}),!x&&o&&u.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d(u.title_info)}),u.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ae,{id:u.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&&(u.title_info||u.author_info||u.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[u.title_info&&e.jsx(se,{label:l.label.titleInfo,children:d(u.title_info)}),u.author_info&&e.jsx(se,{label:l.label.authorInfo,children:d(u.author_info)}),u.edition&&e.jsx(se,{label:l.label.edition,children:d(u.edition)})]}),u.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:d(u.summary)})]}),u.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:d(u.comment)})]}),u.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:d(u.additional_comment)})]})]})]},g)})})]})}function Fn({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(zt,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function _t({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(zt,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Tt({label:t,items:n}){const{convert:o}=H();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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 Dn({items:t}){const n=A();return e.jsx(Tt,{label:n.section.aliases,items:t})}function Hn({items:t}){const n=A();return e.jsx(Tt,{label:n.section.attachedTexts,items:t})}function On({items:t}){const n=A(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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 Vn({items:t}){const n=A(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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 Un({items:t}){const n=A(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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 et({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=H(),[d,a]=p.useState([]);return p.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(u=>({id:u})));return}let s=!1;return Promise.all(n.map(u=>o.getItem(u).then(g=>({id:u,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:u})))).then(u=>{s||a(u)}),()=>{s=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ee,{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:(d.length?d:n.map(s=>({id:s}))).map(s=>{const u=s.edition?`${l(s.title)||s.id}(${l(s.edition)})`:l(s.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:s.id,label:u,onNavigate:r,renderLink:i})},s.id)})})]}):null}function Nn({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=H(),[l,d]=p.useState(!1),a=t.resources&&t.resources.length>0,s=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:a&&!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:s,onNavigate:n,renderLink:o})}),a&&e.jsx("span",{onClick:()=>d(u=>!u),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:"▼"})]}),a&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(He,{items:t.resources,groupByType:!0})})]})}function Yn({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),[l,d]=p.useState([]);return p.useEffect(()=>{if(!t.length){d([]);return}if(!n){d(t.map(s=>({id:s})));return}let a=!1;return Promise.all(t.map(s=>n.getItem(s).then(u=>({id:s,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:s})))).then(s=>{a||d(s)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ee,{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(a=>({id:a}))).map(a=>e.jsx(Nn,{book:a,onNavigate:o,renderLink:r},a.id))})]}):null}function Gn({workData:t,onNavigate:n,renderLink:o}){var l,d,a;const r=A(),{convert:i}=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(Ct,{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})}),((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:[wt(t.juan_count.number),r.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(It,{authors:t.authors,type:"work"}),((d=t.description)==null?void 0:d.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children: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 Kn({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=H();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:ke(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Oe=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:d,style:a})=>{var W,R,j,P,$,O;const s=A(),{convert:u}=H(),[g,x]=p.useState(null),[h,c]=p.useState(!1),[y,I]=p.useState(null),[f,E]=p.useState(null),[b,_]=p.useState([]),m=t||g;if(p.useEffect(()=>{if(t||!n||!o)return;let k=!1;return c(!0),I(null),o.getItem(n).then(L=>{k||(L?x(L):I(s.misc.notFoundEntry))}).catch(L=>{k||I(L instanceof Error?L.message:s.misc.loadFailed)}).finally(()=>{k||c(!1)}),()=>{k=!0}},[t,n,o]),p.useEffect(()=>{if(!m||!o){E(null),_([]);return}let k=!1;const L=m.type==="book"||m.type==="collection"?m.work_id:void 0;if(L?o.getItem(L).then(N=>{!k&&N&&N.type==="work"&&E(N)}).catch(()=>{}):E(null),m.type==="book"){const N=m;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(U=>{const F=typeof U=="string"?U:U.id,oe=typeof U=="string"?void 0:U.volume_index;return o.getItem(F).then(te=>({id:F,title:te&&te.title||F,volume_index:oe})).catch(()=>({id:F,title:F,volume_index:oe}))})).then(U=>{k||_(U)}):_([])}else _([]);return()=>{k=!0}},[m,o]),h)return e.jsx("div",{className:d,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((k,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${k}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(y)return e.jsx("div",{className:d,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!m)return null;const T=m.type==="book"?m:null,w=m.type==="collection"?m:null,S=m.type==="work"?m:null;let v=!1;try{v=D.extractStatus(m.id)==="draft"}catch{}let B="";(W=m.juan_count)!=null&&W.number?B=wt(m.juan_count.number)+s.unit.juan:(R=m.juan_count)!=null&&R.description&&(B=u(m.juan_count.description));const C=[];return(j=m.publication_info)!=null&&j.year&&C.push(e.jsx(se,{label:s.label.year,children:m.publication_info.year},"year")),(P=m.current_location)!=null&&P.name&&C.push(e.jsx(se,{label:s.label.currentLocation,children:u(m.current_location.name)},"loc")),($=m.page_count)!=null&&$.description&&C.push(e.jsx(se,{label:s.label.pageCount,children:m.page_count.description},"page")),T!=null&&T.edition&&C.push(e.jsx(se,{label:s.label.edition,children:u(T.edition)},"ver")),S!=null&&S.parent_work&&C.push(e.jsx(se,{label:s.label.parentWork,children:e.jsx(ae,{id:S.parent_work.id,label:u(S.parent_work.title),onNavigate:r,renderLink:i})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&C.push(e.jsx(se,{label:s.label.parentWork,children:S.parent_works.map((k,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(ae,{id:k,onNavigate:r,renderLink:i})]},k))},"pws")),e.jsxs("div",{className:d,style:a,children:[e.jsx(Mn,{id:m.id,title:u(m.title),edition:m.edition?u(m.edition):void 0,type:m.type,isDraft:v,authors:m.authors,volumeText:B,meta:C,headerExtra:l}),((O=m.description)==null?void 0:O.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(m.description.text)}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:s.section.containedIn}),e.jsx(Kn,{items:b,onNavigate:r,renderLink:i})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:s.section.belongsToWork}),e.jsx(Gn,{workData:f,onNavigate:r,renderLink:i})]}),m.additional_works&&m.additional_works.length>0&&e.jsx(On,{items:m.additional_works}),m.additional_titles&&m.additional_titles.length>0&&e.jsx(Dn,{items:m.additional_titles}),m.attached_texts&&m.attached_texts.length>0&&e.jsx(Hn,{items:m.attached_texts}),m.indexed_by&&m.indexed_by.length>0&&e.jsx(Fn,{items:m.indexed_by,onNavigate:r,renderLink:i}),m.emendated_by&&m.emendated_by.length>0&&e.jsx(_t,{items:m.emendated_by,onNavigate:r,renderLink:i}),m.resources&&m.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:s.section.resources}),e.jsx(He,{items:m.resources,groupByType:!0})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&e.jsx(Vn,{items:T.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&e.jsx(Un,{items:w.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&e.jsx(et,{title:s.section.relatedVersions,ids:T.related_books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(et,{title:s.section.containedBooks,ids:w.books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ee,{children:[s.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",w.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(k=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ae,{id:k.id,label:u(k.title),onNavigate:r,renderLink:i})},k.id))})]}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Yn,{ids:S.books,transport:o,onNavigate:r,renderLink:i}),(S==null?void 0:S.related_works)&&S.related_works.length>0&&(()=>{const k=[],L=S.related_works.filter(F=>F.relation==="part_of"),N=S.related_works.filter(F=>F.relation==="has_part"),U=S.related_works.filter(F=>!F.relation);return L.length>0&&k.push({label:s.section.belongsToWork,items:L}),N.length>0&&k.push({label:s.section.containedWorks,items:N}),U.length>0&&k.push({label:s.section.relatedWorks,items:U}),k.map(F=>e.jsxs("div",{children:[e.jsxs(ee,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(oe=>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:oe.id,label:u(oe.title),onNavigate:r,renderLink:i})},oe.id))})]},F.label))})()]})};function Jn({data:t}){const n=A(),{convert:o}=H(),{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 Zn({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:tt(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:tt(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 tt(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 Xn({id:t,label:n,onNavigate:o,renderLink:r}){return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:`/book-index?id=${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 qn(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 nt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=A(),{convert:l}=H(),d=t.book_id||t.work_id,a=r&&t.volumes.length>0?qn(t.volumes,i.unit.volume):null,s=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[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(u=>l(u)).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:s?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),d&&e.jsx(Xn,{id:d,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!d&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const Rt=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:d})=>{const a=A(),[s,u]=p.useState(null),[g,x]=p.useState(!1),[h,c]=p.useState(null),[y,I]=p.useState(null),[f,E]=p.useState(""),b=t||s;p.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),c(null),o.getCollectionCatalog(n).then(v=>{S||(v?u(v):c(a.catalog.notFound))}).catch(v=>{S||c(v instanceof Error?v.message:a.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,a]);const _=(b==null?void 0:b.sections)&&b.sections.length>0,m=p.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const S=b.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(S).size<S.length},[b]),T=p.useMemo(()=>{if(!b)return[];let S=b.books;if(y&&(S=S.filter(v=>v.section===y)),f.trim()){const v=f.trim().toLowerCase();S=S.filter(B=>B.title.toLowerCase().includes(v)||B.sub_items&&B.sub_items.some(C=>C.toLowerCase().includes(v))||B.edition&&B.edition.toLowerCase().includes(v))}return S},[b,y,f]),w=p.useMemo(()=>{if(!m)return null;const S=[],v=new Map;for(const C of T){if(!C.volumes||C.volumes.length===0)continue;const W=C.volumes[0];v.has(W)||v.set(W,[]),v.get(W).push(C)}const B=[...v.keys()].sort((C,W)=>C-W);for(const C of B)S.push({volume:C,books:v.get(C)});return S},[T,m]);return g?e.jsx("div",{className:l,style:{...d,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):h?e.jsx("div",{className:l,style:{...d,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):b?e.jsxs("div",{className:l,style:d,children:[e.jsx(Jn,{data:b}),_&&e.jsx(Zn,{sections:b.sections,activeSection:y,onSelect:I}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:f,onChange:S=>E(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:[T.length," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((S,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:ke(a.catalog.volume,{n:S.volume})}),S.books.map((B,C)=>e.jsx(nt,{book:B,onNavigate:r,renderLink:i,showVolumes:B.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${v}`)):T.map((S,v)=>e.jsx(nt,{book:S,onNavigate:r,renderLink:i,showVolumes:!0},v)),T.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},ge=()=>{const[t,n]=p.useState(1);return p.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)})},Qn=["〇","一","二","三","四","五","六","七","八","九"],ot=["","十","百","千"],eo=["","萬","億"];function Et(t){if(t===0)return"〇";if(t<0)return`負${Et(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(to(i,r>0)+eo[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function to(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 d=o[l],a=o.length-1-l;d===0?i&&!i.endsWith("〇")&&(i+="〇"):d===1&&a===1&&l===0&&!n?i+=ot[a]:i+=Qn[d]+ot[a]}return i.replace(/〇$/,"")}const Lt={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function no(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Bt({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:no(t)})}function Wt(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Wt(r,n)))}function $t(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+$t(l),0))||0;return n+o}function Pt({group:t,activeFile:n,onSelect:o,depth:r=0}){var u;const i=Wt(t,n||""),[l,d]=p.useState(i),a=$t(t),s=!!((u=t.children)!=null&&u.length);if(p.useEffect(()=>{i&&d(!0)},[i]),t.files.length===1&&!s){const g=t.files[0],x=n===g;return e.jsx("button",{onClick:()=>o(g),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:()=>d(!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:["(",a,")"]})]}),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(g=>e.jsx(Bt,{file:g,isActive:n===g,onSelect:o},g))}),s&&t.children.map((g,x)=>e.jsx(Pt,{group:g,activeFile:n,onSelect:o,depth:r+1},x))]})]})}function oo({files:t,groups:n,activeFile:o,onSelect:r}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((i,l)=>e.jsx(Pt,{group:i,activeFile:o,onSelect:r},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(i=>e.jsx(Bt,{file:i,isActive:o===i,onSelect:r},i))})}function ro({type:t}){const n=Lt[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(t){if(!t)return null;const n=t.match(/^[^。]*。(.+)$/s);return n&&n[1].trim()?n[1].trim():null}function lo({section:t,onNavigate:n}){const{convert:o}=H(),[r,i]=p.useState(!1),l=!!t.summary,d=!!t.comment,a=!!t.additional_comment,s=t.author_info?null:io(t.content),u=l||d||a;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>u&&i(!r),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:r?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},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:[Et(t.n_juan),"卷"]})]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",flexShrink:0,whiteSpace:"nowrap"},children:o(t.author_info||t.author)}),s&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"50%",flexShrink:1},children:o(s)}),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:`/book-index?id=${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:"→作品"})]}),r&&u&&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)})]})]})]})}function so({section:t}){const{convert:n}=H(),[o,r]=p.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(ro,{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 ${Lt[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 ao({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
- `));return e.jsx("div",{style:{padding:"6px 0",fontSize:"13px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.7,whiteSpace:"pre-line"},children:o})}function co({sections:t,onNavigate:n}){const{convert:o}=H(),r=[];let i=null;for(const l of t)l.type==="类"?(i&&r.push(i),i={category:l.title,items:[]}):l.type==="书"?(i||(i={category:"",items:[]}),i.items.push(l)):l.type==="序"&&(i?(i.items.push(l),r.push(i),i=null):r.push({category:"",items:[l]}));return i&&r.push(i),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.map((l,d)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[l.category&&e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:o(l.category.replace(/^[^·]*·?/,""))}),l.items.map((a,s)=>{if(a.type==="序")return e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},s);const u=a.content||a.title;return e.jsx("div",{children:n&&a.work_id?e.jsx("a",{href:`/book-index?id=${a.work_id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.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:o(u)}):o(u)},s)})]},d))})}function po({juan:t,searchQuery:n,onNavigate:o}){const{convert:r}=H(),[i,l]=p.useState("catalog"),d=p.useMemo(()=>{if(!n.trim())return t.sections;const s=n.trim().toLowerCase();return t.sections.filter(u=>{var g,x,h,c,y,I;return((g=u.title)==null?void 0:g.toLowerCase().includes(s))||((x=u.book_title)==null?void 0:x.toLowerCase().includes(s))||((h=u.author)==null?void 0:h.toLowerCase().includes(s))||((c=u.author_info)==null?void 0:c.toLowerCase().includes(s))||((y=u.summary)==null?void 0:y.toLowerCase().includes(s))||((I=u.content)==null?void 0:I.toLowerCase().includes(s))})},[t.sections,n]),a=d.filter(s=>s.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(s=>e.jsx("button",{onClick:()=>l(s),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:s==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:i===s?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:i===s?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:s==="catalog"?"目錄":"原文"},s))}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[a," 部书"]})]}),i==="raw"&&e.jsx(co,{sections:d,onNavigate:o}),i==="catalog"&&d.map((s,u)=>s.type==="书"?e.jsx(lo,{section:s,onNavigate:o},u):s.type==="部"||s.type==="类"?e.jsx(so,{section:s},u):e.jsx(ao,{section:s},u)),d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const At=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:i,onJuanChange:l,className:d,style:a})=>{const[s,u]=p.useState(null),[g,x]=p.useState(!1),[h,c]=p.useState(null),[y,I]=p.useState(null),[f,E]=p.useState(null),[b,_]=p.useState(!1),[m,T]=p.useState(""),w=i??y,S=p.useCallback(R=>{I(R),l==null||l(R)},[l]),v=t||s;p.useEffect(()=>{t&&(x(!1),c(null))},[t]),p.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let R=!1;return x(!0),c(null),o.getCollatedEditionIndex(n).then(j=>{R||(j?(u(j),!i&&j.juan_files.length>0&&S(j.juan_files[0])):c("未找到整理本数据"))}).catch(j=>{R||c(j instanceof Error?j.message:"加载失败")}).finally(()=>{R||x(!1)}),()=>{R=!0}},[t,n,o,i,S]),p.useEffect(()=>{const R=t||s;R&&R.juan_files&&R.juan_files.length>0&&!w&&S(R.juan_files[0])},[t,s,w,S]);const B=n||(v==null?void 0:v.work_id),C=p.useCallback(async R=>{if(!(!B||!(o!=null&&o.getCollatedJuan))){_(!0),E(null);try{const j=await o.getCollatedJuan(B,R);E(j)}catch{E(null)}finally{_(!1)}}},[B,o]);p.useEffect(()=>{w&&C(w)},[w,C]);const W=R=>{S(R),T("")};return g?e.jsx("div",{className:d,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):h?e.jsx("div",{className:d,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):v?e.jsxs("div",{className:d,style:a,children:[e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:v.total_juan})," 卷"]})}),e.jsx(oo,{files:v.juan_files,groups:v.juan_groups,activeFile:w,onSelect:W}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:m,onChange:R=>T(R.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,{}):f?e.jsx(po,{juan:f,searchQuery:m,onNavigate:r}):w?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,v.references&&v.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:"參考文獻"}),v.references.map((R,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),R.url?e.jsx("a",{href:R.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:R.title}):e.jsx("span",{children:R.title}),R.author&&e.jsxs("span",{children:[",",R.author]}),R.note&&e.jsxs("span",{children:["。",R.note]})]},j))]})]}):null},xo={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},uo={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function go(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 Mt=({items:t,loading:n})=>n?e.jsx(ge,{}):t.length===0?e.jsx("div",{style:fo,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const r=xo[o.type],i=uo[o.status];return e.jsxs("div",{style:ho,children:[e.jsxs("div",{style:bo,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...rt,background:r.color},children:r.label}),e.jsx("span",{style:{...rt,background:i.color},children:i.label})]}),e.jsx("span",{style:mo,children:go(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:yo,children:[o.resourceId&&e.jsx("a",{href:`/book-index?id=${o.resourceId}`,style:it,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:it,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:vo,children:o.content}),o.reply&&e.jsxs("div",{style:jo,children:[e.jsx("div",{style:So,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})}),fo={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ho={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},bo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},rt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},mo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},yo={fontSize:"12px",marginBottom:"6px"},it={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},vo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},jo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},So={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},ko=[{id:"FCNcSJbF77V",title:"欽定四庫全書·文淵閣本",description:"清·紀昀等編,藏於臺灣國立故宮博物院",group:"推薦叢編"},{id:"FCmH8kWxMhR",title:"二十四史百衲本",description:"民國·張元濟輯,商務印書館影印",group:"推薦叢編"},{id:"FCmYiXcTfuZ",title:"二十四史武英殿本",description:"清乾隆四年武英殿刻本",group:"推薦叢編"},{id:"FCmbeajrbJw",title:"武英殿聚珍版叢書",description:"清乾隆間武英殿活字印本",group:"推薦叢編"},{id:"GY4HvsY3w3u",title:"欽定四庫全書總目",description:"清·紀昀等編,200卷",group:"經典作品"},{id:"GY4JKKQaPYB",title:"欽定四庫全書簡明目錄",description:"清·紀昀等編,20卷",group:"經典作品"},{id:"GY4JM7j7yi7",title:"史記",description:"西漢·司馬遷,130卷",group:"經典作品"},{id:"GY3ty2LN9ro",title:"易經",description:"西周·周文王",group:"經典作品"}],Fe=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:i,feedbackApiUrl:l})=>{const d=A(),[a,s]=p.useState(null),[u,g]=p.useState([]),[x,h]=p.useState("recommend"),[c,y]=p.useState([]),[I,f]=p.useState(!1),E=r??x,b=C=>{h(C),i==null||i(C)},[_,m]=p.useState(!0),[T,w]=p.useState(null),[S,v]=p.useState(null);p.useEffect(()=>{if(!t.getAllEntries)return;let C=!1;return t.getAllEntries().then(W=>{if(C)return;const R=W.filter($=>$.type==="work").length,j=W.filter($=>$.type==="book").length,P=W.filter($=>$.type==="collection").length;s({works:R,books:j,collections:P})}).catch(()=>{}),()=>{C=!0}},[t]),p.useEffect(()=>{let C=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const R=await t.getRecommended();if(R!=null&&R.groups)return R.groups.flatMap(j=>j.items.map(P=>({...P,group:j.name})))}catch{}return ko})().then(async R=>{if(C)return;const j=R.filter($=>$.id);if(j.length===0){m(!1);return}const P=await Promise.all(j.map(async $=>{try{let O=null;if(t.getEntry)O=await t.getEntry($.id);else{const k=await t.getItem($.id);k&&(O={id:$.id,title:k.title||$.id,type:k.type||"work"})}if(O)return{...O,group:$.group,fallbackDescription:$.description}}catch{}return{id:$.id,title:$.title,type:$.id.startsWith("FC")?"collection":"work",group:$.group,fallbackDescription:$.description}}));C||(g(P.filter($=>$!==null)),m(!1))}),()=>{C=!0}},[t,o]),p.useEffect(()=>{if(!t.getResourceProgress)return;let C=!1;return t.getResourceProgress().then(W=>{C||w(W)}).catch(()=>{}),()=>{C=!0}},[t]),p.useEffect(()=>{if(!t.getSiteProgress)return;let C=!1;return t.getSiteProgress().then(W=>{C||v(W)}).catch(()=>{}),()=>{C=!0}},[t]),p.useEffect(()=>{if(!l||E!=="feedback")return;let C=!1;return f(!0),fetch(l).then(W=>W.json()).then(W=>{!C&&W.success&&y(W.items||[])}).catch(()=>{}).finally(()=>{C||f(!1)}),()=>{C=!0}},[l,E]);const B=C=>{switch(C){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(Ie,{label:d.home.recommendTab,active:E==="recommend",onClick:()=>b("recommend")}),e.jsx(Ie,{label:d.home.catalogTab,active:E==="catalog",onClick:()=>b("catalog")}),e.jsx(Ie,{label:d.home.siteTab,active:E==="site",onClick:()=>b("site")}),l&&e.jsx(Ie,{label:d.home.feedbackTab,active:E==="feedback",onClick:()=>b("feedback")})]}),E==="recommend"&&e.jsx(wo,{recommended:u,loading:_,onNavigate:n,getIcon:B,t:d}),E==="catalog"&&e.jsx(Co,{progress:T,t:d,onNavigate:n}),E==="site"&&e.jsx(zo,{progress:S,t:d,totalWorks:(a==null?void 0:a.works)??0}),E==="feedback"&&l&&e.jsx(Mt,{items:c,loading:I})]})})},Ie=({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}),wo=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:i})=>{if(n)return e.jsx(ge,{});if(t.length===0)return null;const l=new Map;for(const d of t){const a=d.group||i.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(d)}return e.jsx(e.Fragment,{children:Array.from(l.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(s=>{const u=s.dynasty||s.author?`${s.dynasty?`〔${s.dynasty}〕`:""}${s.author||""}`:s.fallbackDescription;return e.jsxs("a",{href:`/book-index?id=${s.id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),o==null||o(s.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(s.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s.title,s.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:s.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},s.id)})})]},d))})},Co=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((a,s)=>a.priority-s.priority),i=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},d={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:i.map(a=>{const s=r.filter(u=>u.status===a);return s.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:d[a]}}),l[a]," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(u=>e.jsx(Io,{item:u,t:n,statusColor:d[a],onNavigate:o},u.id))})]},a)})})},Io=({item:t,t:n,statusColor:o,onNavigate:r})=>{const i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const d=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:`/book-index?id=${a}`,onClick:s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.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:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?ke(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})]})},zo=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((s,u)=>s.priority-u.priority),i=r.filter(s=>s.imported>0),l=r.filter(s=>s.imported===0),d=i.reduce((s,u)=>Math.max(s,u.imported),0),a=o>0?Math.round(d/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:d.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",a,"%)"]}),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(s=>e.jsx(lt,{item:s,t:n,totalWorks:o},s.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(s=>e.jsx(lt,{item:s,t:n,totalWorks:o},s.id))})]})]})},lt=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},st="(max-width: 768px)";function _o(){const[t,n]=p.useState(()=>typeof window>"u"?!1:window.matchMedia(st).matches);return p.useEffect(()=>{const o=window.matchMedia(st),r=i=>n(i.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const To=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:i})=>{var O;const l=A(),{convert:d}=H(),a=_o(),[s,u]=p.useState(null),[g,x]=p.useState(null),[h,c]=p.useState(!1),[y,I]=p.useState("detail"),[f,E]=p.useState([]),[b,_]=p.useState(!1),[m,T]=p.useState(null),[w,S]=p.useState(!1),v=p.useCallback(async k=>{if(!t.getCollatedEditionIndex){T(null);return}S(!0);try{const L=await t.getCollatedEditionIndex(k);T(L)}catch{T(null)}finally{S(!1)}},[t]),B=p.useCallback(async k=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){E([]);return}_(!0);try{if(t.getCollectionCatalogs){const L=await t.getCollectionCatalogs(k);E(L||[])}else if(t.getCollectionCatalog){const L=await t.getCollectionCatalog(k);E(L?[{resource_id:"",data:L}]:[])}}catch{E([])}finally{_(!1)}},[t]),C=p.useCallback(async k=>{if(o){o(k);return}u(k),x(null),E([]),T(null),I("detail"),c(!0);try{const L=await t.getItem(k.id);L&&(x(L),L.type==="collection"?B(k.id):L.type==="work"&&L.has_collated&&v(k.id))}catch(L){console.error("加载详情失败:",L)}finally{c(!1)}},[t,o,B,v]),W=p.useCallback(async k=>{x(null),E([]),T(null),I("detail"),c(!0);try{const L=await t.getItem(k);L&&(x(L),u({id:k,title:L.title||k,type:L.type||"book"}),L.type==="collection"?B(k):L.type==="work"&&L.has_collated&&v(k))}catch(L){console.error("导航失败:",L)}finally{c(!1)}},[t,B,v]),R=(g==null?void 0:g.type)==="collection"&&(f.length>0||b)||(g==null?void 0:g.type)==="work"&&(m||w),j=a&&(h||g),P=p.useCallback(()=>{u(null),x(null),E([]),T(null),I("detail")},[]),$=e.jsx(e.Fragment,{children:h?e.jsx(ge,{}):g?e.jsxs(e.Fragment,{children:[(R||i)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>I("detail"),style:ze(y==="detail"),children:l.detailTab.basicInfo}),g.type==="collection"&&b&&f.length===0&&e.jsxs("button",{onClick:()=>{},style:ze(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),g.type==="collection"&&f.map(k=>e.jsx("button",{onClick:()=>I(`catalog:${k.resource_id}`),style:ze(y===`catalog:${k.resource_id}`),children:k.short_name?`${d(k.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},k.resource_id)),g.type==="work"&&(m||w)&&e.jsxs("button",{onClick:()=>I("collated"),style:ze(y==="collated"),children:[l.detailTab.collatedEdition,w&&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:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:y==="detail"?e.jsx(Oe,{data:g,transport:t,onNavigate:W}):y.startsWith("catalog:")?e.jsx(Rt,{data:(O=f.find(k=>`catalog:${k.resource_id}`===y))==null?void 0:O.data,onNavigate:W}):y==="collated"?e.jsx(At,{index:m||void 0,workId:g.id,transport:t,onNavigate:W}):null})]}):e.jsx(Fe,{transport:t,onNavigate:W,recommendedIds:r})});return a?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:j?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:P,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:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Me,{transport:t,onEntryClick:C,hideModeIndicator:n}),!g&&e.jsx(Fe,{transport:t,onNavigate:W,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(Me,{transport:t,onEntryClick:C,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function ze(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 Ro=({data:t,onNavigate:n,className:o,style:r})=>{var g;const i=A(),{convert:l}=H(),[d,a]=p.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[s,u]=p.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(Eo,{division:x,expanded:d===x.name,onToggle:()=>a(d===x.name?null:x.name),expandedCat:s,onCatToggle:h=>u(s===h?null:h),onNavigate:n},x.name))})]})},Eo=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:i,onNavigate:l})=>{const{convert:d}=H(),a=t.categories.reduce((s,u)=>{const g=u.stats||{zhulu:0,cunmu:0};return s+(g.zhulu||0)+(g.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:d(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(s=>{const u=`${t.name}/${s.name}`;return e.jsx(Lo,{category:s,expanded:r===u,onToggle:()=>i(u),onNavigate:l},s.name)})})]})},Lo=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var s,u,g,x;const{convert:i}=H(),l=((s=t.books)==null?void 0:s.zhulu)||[],d=((u=t.books)==null?void 0:u.cunmu)||[],a=(((g=t.stats)==null?void 0:g.zhulu)||l.length)+(((x=t.stats)==null?void 0:x.cunmu)||d.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:[a," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(at,{label:"著錄",books:l,onNavigate:r}),d.length>0&&e.jsx(at,{label:"存目",books:d,onNavigate:r})]})]})},at=({label:t,books:n,onNavigate:o})=>{const{convert:r}=H(),[i,l]=p.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,s)=>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:`/book-index?id=${a.work_id}`,onClick:u=>{u.metaKey||u.ctrlKey||(u.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)})]},s))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ne=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:i})=>{const l=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:Wo,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Bo,children:l.action.save})]})]}),i]})},Bo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Wo={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},q=({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"}})]}),ue=({value:t,onChange:n,placeholder:o})=>{const r=p.useRef(null);return p.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"}})},Te=({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 $o(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const _e=({value:t,onChange:n,label:o})=>{const[r,i]=p.useState(!1),l=p.useRef(null),d=$o(t||"");return p.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&d?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:dt,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:d.name}),e.jsx(Te,{children:d.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:dt,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:a=>n(a.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"}})]})},dt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Po(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Ao(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ft=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[i,l]=p.useState(null),d=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},a=x=>{n(t.filter((h,c)=>c!==x)),i===x&&l(null)},s=(x,h,c)=>{const y=[...t];y[x]={...y[x],[h]:c},n(y)},u=(x,h)=>{const c=[...t];c[x]={...c[x],type:h,id:"",name:""},n(c),h==="bookID"&&o&&o(y=>{const I=[...t];I[x]={...I[x],id:y.id,name:y.title,type:"bookID"},n(I)})},g=x=>{o&&o(h=>{const c=[...t];c[x]={...c[x],id:h.id,name:h.title,type:"bookID"},n(c)})};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:Po(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Ao(x.type)}),e.jsx("button",{onClick:c=>{c.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),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:()=>u(h,"bookID"),style:{...ct,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:()=>u(h,"url"),style:{...ct,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 c=[...t];c[h]={...c[h],type:"",id:"",name:""},n(c)},style:pt,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:()=>g(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:()=>g(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 c=[...t];c[h]={...c[h],type:"",id:"",name:""},n(c)},style:pt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:c=>s(h,"name",c.target.value),placeholder:r.editor.sourceNamePlaceholder,style:fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:c=>s(h,"id",c.target.value),placeholder:"https://...",style:fe})]})]}),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:c=>s(h,"details",c.target.value),placeholder:r.editor.detailsPlaceholder,style:fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:c=>s(h,"position",c.target.value),placeholder:"如: 卷三, p.52",style:fe})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:c=>s(h,"version",c.target.value),placeholder:"如: v1.0, 2024-01",style:fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:c=>s(h,"processor_version",c.target.value),placeholder:"如: v0.1",style:fe})]})]})]})]})})]},h)),e.jsxs("button",{onClick:d,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},fe={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},ct={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"},pt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Dt(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 Ht(t){return!t||t.length===0?"":JSON.stringify(t)}const Ot=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:i,belongsToWork:l,belongsToCollection:d,childWorks:a,childCollections:s,containedBooks:u,siblingBooks:g,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:c,onCreateAndLink:y,onSaveRelations:I})=>{const f=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:f.section.relations})]}),I&&e.jsx("button",{onClick:I,style:Mo,children:f.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{direction:"up",title:f.relation.belongsToWork,entity:l,onView:c,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),e.jsx(ve,{direction:"up",title:f.relation.containedInCollection,entity:d,onView:c,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>y("collectionId","collection",{title:o}),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),l&&g&&g.length>0&&e.jsx(he,{direction:"horizontal",title:`${f.relation.siblingVersions} (${g.length})`,entities:g,onView:c,onAdd:()=>y("siblingBook","book",{workId:l.id}),addLabel:f.relation.addVersionForWork,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{direction:"up",title:f.relation.parentWork,entity:r,onView:c,onUnlink:()=>h("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>y("parentWorkId","work"),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),a&&a.length>0&&e.jsx(he,{direction:"down",title:`${f.relation.childWorks} (${a.length})`,entities:a,onView:c,onAdd:()=>y("childWork","work",{parentWorkId:n}),addLabel:f.action.addSubWork,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),s&&s.length>0&&e.jsx(he,{direction:"down",title:`${f.relation.collectionImpl} (${s.length})`,entities:s,onView:c,onAdd:()=>y("childCollection","collection",{workId:n}),addLabel:f.action.addCollectionImpl,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),e.jsx(he,{direction:"down",title:`${f.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:c,onAdd:()=>y("childBook","book",{workId:n}),addLabel:f.action.addVersion,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{direction:"up",title:f.relation.correspondingWork,entity:l,onView:c,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>y("workId","work",{title:o}),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),e.jsx(ve,{direction:"up",title:f.relation.parentCollection,entity:i,onView:c,onUnlink:()=>h("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>y("parentCollectionId","collection"),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),e.jsx(he,{direction:"down",title:`${f.relation.childCollections} (${(s==null?void 0:s.length)??0})`,entities:s||[],onView:c,onAdd:()=>y("childCollection","collection",{parentCollectionId:n}),addLabel:f.action.addSubCollection,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),e.jsx(he,{direction:"down",title:`${f.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:c,onAdd:()=>y("childBook","book",{collectionId:n}),addLabel:f.action.addBook,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore})]})]})]})},ve=({direction:t,title:n,entity:o,onView:r,onUnlink:i,onLink:l,onCreate:d,linkLabel:a,createLabel:s,notLinkedLabel:u,viewLabel:g,unlinkLabel:x})=>{const h=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:h,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:Vt(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(xt,{onClick:()=>r(o),title:g,children:"👁️"}),e.jsx(xt,{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:u}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(De,{onClick:l,children:a}),e.jsx(De,{onClick:d,primary:!0,children:s})]})]})},he=({direction:t,title:n,entities:o,onView:r,onAdd:i,addLabel:l,noneLabel:d,expandMoreLabel:a})=>{const[s,u]=p.useState(!1),g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=s?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:g,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(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:Vt(c.type)}),e.jsx("span",{children:c.title})]},c.id)),o.length>5&&!s&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(De,{onClick:i,primary:!0,children:["+ ",l]})})]})},xt=({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}),De=({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 Vt(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Mo={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"},Ut=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:i,onCreate:l,searchResults:d,onSearch:a,isLoading:s,excludeId:u})=>{const[g,x]=p.useState(""),h=u?d.filter(f=>f.id!==u):d;p.useEffect(()=>{t&&(x(""),a(""))},[t]);const c=f=>{x(f),a(f)};if(!t)return null;const y=n==="work"?"作品":n==="book"?"书籍":"丛编",I=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Fo,children:e.jsxs("div",{style:Do,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:Ho,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:f=>c(f.target.value),placeholder:`搜索${y}名称或 ID...`,autoFocus:!0,style:Oo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:s?e.jsx("div",{style:Be,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(f=>e.jsxs("div",{onClick:()=>r(f),style:Vo,children:[e.jsx("span",{style:{fontSize:"16px"},children:I}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[f.title,f.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:f.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[f.id,f.author&&` · ${f.author}`,f.dynasty&&` · ${f.dynasty}`]})]})]},f.id))}):g?e.jsxs("div",{style:Be,children:["未找到匹配的",y]}):e.jsxs("div",{style:Be,children:["输入关键词搜索",y]})}),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:Uo,children:["创建新",y,"并关联"]})]})]})})},Fo={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},Do={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)"},Ho={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Oo={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"},Vo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Be={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Uo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ut={work:"作品",book:"书籍",collection:"丛编"},No={work:"📜",book:"📖",collection:"📚"},Nt=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:i,onCancel:l})=>{const[d,a]=p.useState(""),s=p.useRef(null);p.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,c;(h=s.current)==null||h.focus(),(c=s.current)==null||c.select()},100))},[t,r==null?void 0:r.title]);const u=h=>{h.key==="Enter"&&d.trim()?g():h.key==="Escape"&&l()},g=()=>{d.trim()&&i(d.trim(),{...r,title:d.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`创建新${ut[n]}`}};return e.jsx("div",{style:Yo,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:Go,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:No[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:s,type:"text",value:d,onChange:h=>a(h.target.value),onKeyDown:u,placeholder:`请输入${ut[n]}名称...`,style:Ko})]}),((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:Jo,children:"取消"}),e.jsx("button",{onClick:g,disabled:!d.trim(),style:{...Zo,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Yo={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},Go={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)"},Ko={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"},Jo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Zo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Xo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Yt(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function qo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Gt=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:i,showCreateButton:l=!1,createButtonText:d,onSelect:a,onCancel:s,onCreate:u,onSearch:g})=>{const[x,h]=p.useState(""),[c,y]=p.useState([]),[I,f]=p.useState(!1),[E,b]=p.useState("recent");p.useEffect(()=>{t&&(h(""),y([]),b(r.length>0?"recent":"search"))},[t,r.length]),p.useEffect(()=>{if(!x.trim()){y([]);return}const v=setTimeout(async()=>{f(!0);try{y(await g(x,o))}catch{y([])}finally{f(!1)}},300);return()=>clearTimeout(v)},[x,o,g]);const _=p.useCallback(v=>{h(v.target.value),v.target.value.trim()&&b("search")},[]),m=p.useCallback(v=>i?v.filter(B=>B.id!==i):v,[i]);if(!t)return null;const T=n||(o==="all"?"选择实体":`选择${Yt(o)}`),w=m(r),S=m(c);return e.jsx("div",{style:er,children:e.jsxs("div",{style:tr,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:T}),e.jsx("button",{onClick:s,style:nr,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:or}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),I&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(gt,{active:E==="recent",onClick:()=>b("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(gt,{active:E==="search",onClick:()=>b("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:E==="recent"&&w.length>0?e.jsx(ft,{entities:w,onSelect:a}):x.trim()?I?e.jsx(We,{message:"搜索中..."}):S.length>0?e.jsx(ft,{entities:S,onSelect:a}):e.jsx(We,{message:"未找到匹配的结果"}):e.jsx(We,{message:"输入关键词开始搜索"})}),l&&u&&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:u,style:rr,children:d||"创建新实体"})]})]})})},gt=({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}),ft=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Qo,{entity:o,onClick:()=>n(o)},o.id))}),Qo=({entity:t,onClick:n})=>{const[o,r]=p.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:Xo(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:qo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Yt(t.type)})]})},We=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),er={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},tr={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)"},nr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},or={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"},rr={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"},lr={work:"📜",collection:"📚",book:"📖"},Kt=({data:t,onChange:n,onSave:o,transport:r,onNavigate:i,showDelete:l,onDelete:d,onAskAI:a,renderSectionActions:s,onDownloadResource:u,downloadStatuses:g,relations:x,onRelationsChange:h})=>{var Ce;const c=A(),[y,I]=p.useState(!1),[f,E]=p.useState("work"),[b,_]=p.useState(""),[m,T]=p.useState(""),[w,S]=p.useState([]),[v,B]=p.useState(!1),[C,W]=p.useState(!1),[R,j]=p.useState("work"),[P,$]=p.useState(""),[O,k]=p.useState(),[L,N]=p.useState(!1),[U,F]=p.useState(null),[oe,te]=p.useState([]);p.useRef(null);const re=t.type,ie=re==="work",xe=re==="collection",de=re==="book",Y=p.useCallback((z,X)=>{n({...t,[z]:X})},[t,n]),be=p.useCallback((z,X)=>{_(z),E(X),T(c.editor.selectToLink+c.indexType[X]),S([]),I(!0)},[c]),we=p.useCallback(z=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,z)},[r,t.id]),Ee=p.useCallback(z=>{i==null||i(z.id,z.type)},[i]),M=p.useCallback((z,X,ce)=>{const qt={...ce,author:(ce==null?void 0:ce.author)||t.author,dynasty:(ce==null?void 0:ce.dynasty)||t.dynasty};j(X),$(z),k(qt),W(!0)},[t.author,t.dynasty]),K=p.useCallback((z,X)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,P,{type:R,title:z,inheritData:X}),W(!1)},[r,t.id,P,R]),G=p.useCallback(z=>{if(!z.trim()){S([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(z,f).then(X=>{S(X),B(!1)}).catch(()=>{S([]),B(!1)})},[r,f]),J=p.useCallback(z=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,z.id),I(!1)},[r,t.id,b]),Q=p.useCallback(()=>{o()},[o]),Z=p.useCallback(z=>{F(()=>z),N(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(te).catch(()=>{})},[r]),V=p.useCallback((z,X)=>r!=null&&r.searchEntities?r.searchEntities(z,X==="all"?void 0:X):Promise.resolve([]),[r]),Ve=p.useCallback(z=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(z),te(X=>[z,...X.filter(ce=>ce.id!==z.id)].slice(0,10)),U==null||U(z),N(!1),F(null)},[r,U]);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:lr[re]}),e.jsx("span",{children:t.title||c.editor.untitled}),e.jsx(Te,{children:t.id}),e.jsx(Te,{color:ir[re],children:c.indexType[re]})]})}),e.jsx(ne,{title:c.section.basicInfo,onSave:o,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:s==null?void 0:s("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(_e,{label:ie?c.editor.workTitle:xe?c.editor.collectionTitle:c.editor.bookTitle,value:t.title,onChange:z=>Y("title",z)}),de&&e.jsx(_e,{label:c.editor.belongsToWork,value:t.workName||"",onChange:z=>Y("workName",z)}),e.jsx(q,{label:c.editor.authorLabel,value:t.author||"",onChange:z=>Y("author",z)}),e.jsx(q,{label:c.editor.dynastyLabel,value:t.dynasty||"",onChange:z=>Y("dynasty",z)}),(de||xe)&&e.jsx(_e,{label:c.editor.containedIn,value:t.collection||"",onChange:z=>Y("collection",z)}),(de||xe)&&e.jsx(q,{label:c.editor.holderLabel,value:t.holder||"",onChange:z=>Y("holder",z)}),(de||xe)&&e.jsx(q,{label:de?c.editor.pageLabel:c.editor.volumeLabel,value:t.pages||"",onChange:z=>Y("pages",z)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(q,{label:c.editor.firstImageLabel,value:t.firstImage||"",onChange:z=>Y("firstImage",z)})})]})}),e.jsx(ne,{title:c.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:z=>Y("description",z),placeholder:c.editor.descriptionPlaceholder})}),(((Ce=t.additional_works)==null?void 0:Ce.length)||0)>0&&e.jsx(ne,{title:c.section.additionalWorks,onSave:o,children:e.jsx(sr,{items:t.additional_works||[],onChange:z=>Y("additional_works",z)})}),e.jsx(ne,{title:c.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(ar,{items:t.indexed_by||[],onChange:z=>Y("indexed_by",z)})}),e.jsx(ne,{title:c.section.emendatedBy,onSave:o,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(dr,{items:t.emendated_by||[],onChange:z=>Y("emendated_by",z)})}),e.jsx(ne,{title:c.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx($e,{items:t.resources||[],onChange:z=>Y("resources",z),onDownload:u,downloadStatuses:g,filterType:"text"})}),e.jsx(ne,{title:c.section.imageResources,onSave:o,children:e.jsx($e,{items:t.resources||[],onChange:z=>Y("resources",z),onDownload:u,downloadStatuses:g,filterType:"image"})}),e.jsx(ne,{title:c.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(Ft,{items:Dt(t.sources||""),onChange:z=>Y("sources",Ht(z)),onOpenEntityPicker:Z})}),(de||xe)&&e.jsx(ne,{title:c.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:z=>Y("provenance",z),placeholder:c.editor.provenancePlaceholder})}),de&&e.jsx(ne,{title:c.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:z=>Y("otherEditions",z),placeholder:c.editor.otherEditionsPlaceholder})}),e.jsx(Ot,{entityType:re,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:be,onUnlinkEntity:we,onViewEntity:Ee,onCreateAndLink:M,onSaveRelations:Q}),l&&d&&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:d,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(Ut,{isOpen:y,entityType:f,title:m,onSelect:J,onCancel:()=>I(!1),onCreate:()=>{I(!1),M(b,f)},searchResults:w,onSearch:G,isLoading:v,excludeId:t.id}),e.jsx(Nt,{isOpen:C,entityType:R,relationField:P,inheritData:O,onConfirm:K,onCancel:()=>W(!1)}),e.jsx(Gt,{isOpen:L,title:c.action.selectBookOrWork,filterType:"all",recentEntities:oe,excludeId:t.id,onSelect:Ve,onCancel:()=>{N(!1),F(null)},onSearch:V})]})};function sr({items:t,onChange:n}){const o=A(),r=(d,a,s)=>{const u=t.map((g,x)=>x===d?{...g,[a]:s}:g);n(u)},i=d=>n(t.filter((a,s)=>s!==d)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((d,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(q,{label:o.editor.bookNameLabel,value:d.book_title,onChange:s=>r(a,"book_title",s)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(q,{label:o.label.juanCount,value:d.n_juan!=null?String(d.n_juan):"",onChange:s=>r(a,"n_juan",s&&parseInt(s,10)||void 0)})}),e.jsx("button",{onClick:()=>i(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),e.jsx("button",{onClick: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 Jt({items:t,onChange:n,showMeta:o,addLabel:r}){const i=A(),[l,d]=p.useState(null),a=(g,x,h)=>{const c=t.map((y,I)=>I===g?{...y,[x]:h||void 0}:y);n(c)},s=g=>{n(t.filter((x,h)=>h!==g)),l===g&&d(null)},u=()=>{n([...t,{source:""}]),d(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((g,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:()=>d(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:g.source||i.editor.unnamedSource}),g.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:g.source_bid}),e.jsx("button",{onClick:c=>{c.stopPropagation(),s(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!h&&o&&(g.title_info||g.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[g.title_info,g.title_info&&g.author_info&&" — ",g.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(q,{label:i.label.sourceName,value:g.source,onChange:c=>a(x,"source",c)}),e.jsx(q,{label:i.label.sourceBid,value:g.source_bid||"",onChange:c=>a(x,"source_bid",c)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(q,{label:i.label.titleInfo,value:g.title_info||"",onChange:c=>a(x,"title_info",c)}),e.jsx(q,{label:i.label.authorInfo,value:g.author_info||"",onChange:c=>a(x,"author_info",c)})]}),e.jsx(q,{label:i.label.edition,value:g.edition||"",onChange:c=>a(x,"edition",c)})]}),e.jsx(ue,{value:g.summary||"",onChange:c=>a(x,"summary",c),placeholder:i.editor.summaryPlaceholder}),e.jsx(ue,{value:g.comment||"",onChange:c=>a(x,"comment",c),placeholder:i.editor.commentPlaceholder}),e.jsx(ue,{value:g.additional_comment||"",onChange:c=>a(x,"additional_comment",c),placeholder:i.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:u,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function ar({items:t,onChange:n}){const o=A();return e.jsx(Jt,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function dr({items:t,onChange:n}){const o=A();return e.jsx(Jt,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Zt(t){var a,s,u,g,x,h,c;const n=((s=(a=t.authors)==null?void 0:a[0])==null?void 0:s.name)||"",o=((u=t.publication_info)==null?void 0:u.year)||"",r=((g=t.current_location)==null?void 0:g.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||"",d={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 y=t;if(Array.isArray(y.related_works)){const I=y.related_works.find(f=>f.relation==="part_of");I&&(d.parentWorkId=I.id,d.parentWorkName=I.title)}}if(t.type==="book"){const y=t;d.workId=y.work_id,Array.isArray(y.contained_in)&&y.contained_in.length>0&&(d.collectionId=(c=y.contained_in[0])==null?void 0:c.id)}return d}function cr(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 pr=t=>{const{data:n,id:o,transport:r,mode:i="view",onModeChange:l,onChange:d,onSave:a,onDelete:s,onNavigate:u,renderLink:g,onAskAI:x,renderSectionActions:h,onDownloadResource:c,downloadStatuses:y,relations:I,onRelationsChange:f,headerExtra:E,className:b,style:_}=t;A();const[m,T]=p.useState(i),w=l?i:m;p.useEffect(()=>{i!==m&&T(i)},[i]);const S=p.useCallback(()=>{const P=w==="view"?"edit":"view";l?l(P):T(P)},[w,l]),[v,B]=p.useState(null);p.useEffect(()=>{o&&r&&r.getItem(o).then(P=>{P&&B(P)})},[o,r]);const C=n||v,W=p.useMemo(()=>C?Zt(C):null,[C]),R=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,j=e.jsxs(e.Fragment,{children:[R,E]});return!C&&!W?e.jsx(ge,{}):w==="view"?e.jsx(Oe,{data:C,transport:r,onNavigate:u?P=>u(P):void 0,renderLink:g,headerExtra:j,className:b,style:_}):W?e.jsxs("div",{className:b,style:_,children:[j&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:j}),e.jsx(Kt,{data:W,onChange:d||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:u,showDelete:!!s,onDelete:s,onAskAI:x,renderSectionActions:h,onDownloadResource:c,downloadStatuses:y,relations:I,onRelationsChange:f})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},ht=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Xt=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[i,l]=p.useState(null),[d,a]=p.useState(""),[s,u]=p.useState("idle"),[g,x]=p.useState(""),h=p.useRef(null);p.useEffect(()=>{t&&(l(null),a(""),u("idle"),x(""))},[t]),p.useEffect(()=>{i&&setTimeout(()=>{var f;return(f=h.current)==null?void 0:f.focus()},100)},[i]),p.useEffect(()=>{if(s==="success"){const f=setTimeout(n,2e3);return()=>clearTimeout(f)}},[s,n]),p.useEffect(()=>{if(!t)return;const f=E=>{E.key==="Escape"&&n()};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t,n]);const c=async()=>{if(!(!i||!d.trim())){u("submitting"),x("");try{await o({type:i,content:d.trim()}),u("success")}catch(f){u("error"),x(f instanceof Error?f.message:"提交失败,请稍后重试")}}};if(!t)return null;const y=i&&d.trim()&&s!=="submitting",I=ht.find(f=>f.value===i);return e.jsx("div",{style:xr,onClick:f=>{f.target===f.currentTarget&&n()},children:e.jsxs("div",{style:ur,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:gr,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:fr,"aria-label":"关闭",children:"✕"})]}),s==="success"?e.jsxs("div",{style:vr,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:ht.map(f=>e.jsxs("button",{onClick:()=>l(f.value),style:{...hr,...i===f.value?br:{}},children:[e.jsx("span",{children:f.icon})," ",f.label]},f.value))}),e.jsx("textarea",{ref:h,value:d,onChange:f=>a(f.target.value),placeholder:(I==null?void 0:I.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!i||s==="submitting",style:{...mr,opacity:i?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),s==="error"&&e.jsx("div",{style:jr,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:c,disabled:!y,style:{...yr,opacity:y?1:.6,cursor:y?"pointer":"not-allowed"},children:s==="submitting"?"提交中...":"提交反馈"})})]})]})})},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",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},gr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},fr={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},hr={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"},br={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"},yr={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},vr={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},jr={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Sr=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,i]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>i(!0),style:{...kr,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(Xt,{isOpen:r,onClose:()=>i(!1),onSubmit:t,feedbackListUrl:o})]})},kr={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"},bt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],wr=({onSubmit:t})=>{const[n,o]=p.useState("bug"),[r,i]=p.useState(""),[l,d]=p.useState("idle"),[a,s]=p.useState(""),u=p.useRef(null);p.useEffect(()=>{n&&setTimeout(()=>{var c;return(c=u.current)==null?void 0:c.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){d("submitting"),s("");try{await t({type:n,content:r.trim()}),d("success"),i(""),o("bug")}catch(c){d("error"),s(c instanceof Error?c.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&l!=="submitting",h=bt.find(c=>c.value===n);return l==="success"?e.jsx("div",{style:mt,children:e.jsxs("div",{style:Tr,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>d("idle"),style:Rr,children:"继续提交"})]})}):e.jsxs("div",{style:mt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:bt.map(c=>e.jsxs("button",{onClick:()=>o(c.value),style:{...Cr,...n===c.value?Ir:{}},children:[e.jsx("span",{children:c.icon})," ",c.label]},c.value))}),e.jsx("textarea",{ref:u,value:r,onChange:c=>i(c.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...zr}}),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:g,disabled:!x,style:{..._r,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&e.jsx("div",{style:Er,children:a})]})},mt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Cr={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"},Ir={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},zr={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"},_r={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Tr={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Rr={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Er={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},Lr=({style:t})=>{const n=p.useContext(Se);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=D.BidLink;exports.BookIndexError=D.BookIndexError;exports.BookIndexManager=D.BookIndexManager;exports.BookIndexStorage=D.BookIndexStorage;exports.BundleStorage=D.BundleStorage;exports.ConfigError=D.ConfigError;exports.GithubStorage=D.GithubStorage;exports.IdGenerationError=D.IdGenerationError;exports.IdGenerator=D.IdGenerator;exports.LocalStorage=D.LocalStorage;exports.MigrationError=D.MigrationError;exports.StorageError=D.StorageError;exports.base36Decode=D.base36Decode;exports.base36Encode=D.base36Encode;exports.base58Decode=D.base58Decode;exports.buildId=D.buildId;exports.decodeId=D.decodeId;exports.decodeIdString=D.decodeIdString;exports.encodeId=D.encodeId;exports.extractIdFromUrl=D.extractIdFromUrl;exports.extractStatus=D.extractStatus;exports.extractType=D.extractType;exports.normalizeCatalog=D.normalizeCatalog;exports.parseId=D.parseId;exports.smartDecode=D.smartDecode;exports.validateResource=D.validateResource;exports.Badge=Te;exports.CollatedEdition=At;exports.CollectionCatalog=Rt;exports.CreateEntityDialog=Nt;exports.EmendatedBySection=_t;exports.EntityPickerDialog=Gt;exports.EntitySelector=Ut;exports.FeedbackButton=Sr;exports.FeedbackDialog=Xt;exports.FeedbackForm=wr;exports.FeedbackList=Mt;exports.FormInput=q;exports.FormTextArea=ue;exports.HomePage=Fe;exports.IndexApp=To;exports.IndexBrowser=Me;exports.IndexDetail=Oe;exports.IndexEditor=Kt;exports.IndexView=pr;exports.LocaleContext=Se;exports.LocaleProvider=xn;exports.LocaleToggle=Lr;exports.ModeIndicator=St;exports.RelationPanel=Ot;exports.ResourceEditor=$e;exports.ResourceList=He;exports.SearchInput=kt;exports.Section=ne;exports.SmartBidInput=_e;exports.SourceEditor=Ft;exports.WorkCatalog=Ro;exports.detailToEditor=Zt;exports.editorToDetail=cr;exports.formatTemplate=ke;exports.parseSourceString=Dt;exports.stringifySources=Ht;exports.useConvert=H;exports.useT=A;
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;