book-index-ui 0.1.13 → 0.1.14

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 Ut=Object.create;var Ve=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Kt=Object.getPrototypeOf,Jt=Object.prototype.hasOwnProperty;var Zt=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Gt(n))!Jt.call(t,r)&&r!==i&&Ve(t,r,{get:()=>n[r],enumerable:!(o=Yt(n,r))||o.enumerable});return t};var Xt=(t,n,i)=>(i=t!=null?Ut(Kt(t)):{},Zt(n||!t||!t.__esModule?Ve(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./storage-entry-BseF1nPm.cjs"),e=require("react/jsx-runtime"),c=require("react"),je=c.createContext(null),ht={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:"+ 添加收錄來源",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:"📖 著錄於",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",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:"推薦",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:"圖片資源"}},qt={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:"+ 添加收录来源",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:"📖 著录于",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",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:"推荐",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:"图片资源"}},Qt={"zh-Hant":ht,"zh-Hans":qt},bt="bim-locale";function en(){try{const t=localStorage.getItem(bt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function tn(t){try{localStorage.setItem(bt,t)}catch{}}const nn="zh-Hant",on=({locale:t,onLocaleChange:n,children:i})=>{const[o,r]=c.useState(t??nn),l=t??o;c.useEffect(()=>{if(t)return;const g=en();g&&g!==o&&r(g)},[]);const[d,s]=c.useState(null);c.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});s(()=>x)}).catch(()=>{s(()=>g=>g)}):s(null)},[l]);const a=c.useCallback(g=>{r(g),tn(g),n==null||n(g)},[n]),u=c.useMemo(()=>({locale:l,setLocale:a,messages:Qt[l],converter:d}),[l,a,d]);return e.jsx(je.Provider,{value:u,children:i})};function A(){const t=c.useContext(je);return(t==null?void 0:t.messages)??ht}const rn=2e3;function F(){const t=c.useContext(je),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=c.useRef(new Map),r=c.useRef(n);r.current!==n&&(o.current.clear(),r.current=n);const l=c.useCallback(d=>{if(!d)return"";if(!i)return d;const s=o.current.get(d);if(s!==void 0)return s;const a=i(d);if(o.current.size>=rn){const u=o.current.keys().next().value;u!==void 0&&o.current.delete(u)}return o.current.set(d,a),a},[i]);return c.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Se(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function ln(t){if(!t)return"";try{const n=new URL(t).hostname,i={"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(i[n])return i[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function sn(){return{id:"",name:"",url:"",type:"text",details:""}}const We=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:r})=>{const l=A(),[d,s]=c.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}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],g=b=>r?r==="text"?b==="text"||b==="text+image":r==="image"?b==="image"||b==="text+image"||b==="physical":b===r:!0,x=t.map((b,T)=>({item:b,originalIndex:T})).filter(({item:b})=>g(b.type)),f=()=>{const b=sn();r&&(b.type=r),n([...t,b]),s(t.length)},p=b=>{n(t.filter((T,j)=>j!==b)),s(null)},v=(b,T,j)=>{const w=[...t];if(w[b]={...w[b],[T]:j},T==="url"&&!w[b].id){const C=ln(j);C&&(w[b].id=C)}n(w)},S=(b,T,j)=>{const C={...t[b].metadata||{}};j?C[T]=j:delete C[T],v(b,"metadata",Object.keys(C).length>0?C:void 0)},h=(b,T)=>{const j=T.trim()?T.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;v(b,"structure",j)},E=(b,T,j)=>{const C=t[b].coverage||{level:1,ranges:""};T==="level"?C.level=parseInt(j)||1:C.ranges=j,v(b,"coverage",C.ranges?C:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:T})=>{var j,w,C,y;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:()=>s(d===T?null:T),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:d===T?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:an(b.type),color:"#fff"},children:((j=a.find(m=>m.value===b.type))==null?void 0:j.label)||b.type}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${l.editor.resourcePlaceholder} ${T+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:m=>m.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&b.url&&dn(T,o==null?void 0:o[T],i,l),e.jsx("button",{onClick:m=>{m.stopPropagation(),p(T)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),d===T&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(b.type==="image"||b.type==="text+image")&&b.url&&cn(b,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:l.label.type}),e.jsx("select",{value:b.type,onChange:m=>v(T,"type",m.target.value),style:{...re,flex:1},children:a.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]}),e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:l.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:m=>v(T,"root_type",m.target.value),style:{...re,flex:1},children:u.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:m=>v(T,"id",m.target.value),placeholder:l.editor.idAutoExtract,style:{...re,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:m=>v(T,"name",m.target.value),placeholder:l.editor.resourceName,style:{...re,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:m=>v(T,"url",m.target.value),placeholder:l.editor.resourceUrl,style:re}),e.jsx("input",{type:"text",value:((w=b.structure)==null?void 0:w.join("、"))||"",onChange:m=>h(T,m.target.value),placeholder:l.editor.structurePlaceholder,style:re}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((C=b.coverage)==null?void 0:C.level)??"",onChange:m=>E(T,"level",m.target.value),placeholder:"1",style:{...re,width:"60px"}})]}),e.jsxs("label",{style:{...be,flex:1},children:[e.jsx("span",{style:me,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((y=b.coverage)==null?void 0:y.ranges)||"",onChange:m=>E(T,"ranges",m.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...re,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:m=>v(T,"details",m.target.value),placeholder:l.editor.detailsPlaceholder,style:{...re,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(([m,R])=>{var I;return e.jsxs("label",{style:{...be,gap:"4px"},children:[e.jsx("span",{style:{...me,minWidth:"56px"},children:R}),e.jsx("input",{type:"text",value:((I=b.metadata)==null?void 0:I[m])||"",onChange:P=>S(T,m,P.target.value),placeholder:R,style:{...re,flex:1}})]},m)})})]})]})]})]},T)}),e.jsxs("button",{onClick:f,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 an(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function dn(t,n,i,o){const r=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:d=>{d.stopPropagation(),r||i(t,"")},disabled:r,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":r?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:r?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:r?.6:.9},title:l?o.download.completed:r?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:l?"✓":r?"⏳":"⬇"})}function cn(t,n){const i=/\.(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:i?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const re={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"},be={display:"flex",alignItems:"center",gap:"6px"},me={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},pn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function xn(t){try{const n=new URL(t).hostname;return pn[n]}catch{return}}const Ne={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},un=["text","image","text+image","physical"];function gn(t){const n=l=>{const d=l.match(/^(.+?)·第(\d+)[冊册]$/);if(d)return[d[1],parseInt(d[2])];const s=l.match(/^(.+?)[·(](\d+)[)]?$/);return s?[s[1],parseInt(s[2])]:null},i=new Map,o=[],r=new Set;for(let l=0;l<t.length;l++){const d=t[l];if(d.volumes&&d.volumes.length>0)continue;const s=n(d.name);if(!s)continue;const[a,u]=s,g=`${a}|${d.type}`;i.has(g)||i.set(g,{base:{...d,name:a,url:"",volumes:[]},volumes:[]}),i.get(g).volumes.push({volume:u,url:d.url||void 0,status:"found"}),r.add(l)}for(const[,l]of i)if(l.volumes.length>=2)l.volumes.sort((d,s)=>d.volume-s.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,o.push(l.base);else for(let d=0;d<t.length;d++)if(r.has(d)){const s=n(t[d].name);s&&`${s[0]}|${t[d].type}`==`${l.base.name}|${l.base.type}`&&r.delete(d)}for(let l=0;l<t.length;l++)r.has(l)||o.push(t[l]);return o}const De=({items:t,groupByType:n=!0})=>{const i=A(),o=c.useMemo(()=>gn(t||[]),[t]),r={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical};if(!o||o.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:o.map((d,s)=>e.jsx(Ye,{item:d},d.id||s))});const l=un.map(d=>({type:d,items:o.filter(s=>s.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:s})=>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]}}),r[d],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",s.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:s.map((a,u)=>e.jsx(Ye,{item:a},a.id||u))})]},d))})},Ue=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},mt=({value:t})=>{const i=A().checkType[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:i.bg,color:i.fg},children:i.label}):e.jsx("span",{children:t})},fn=(t,n,i,o)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(mt,{value:n});if(t==="has_translation")return n?i.misc.hasTranslation:i.misc.noTranslation;const r=String(n);return o?o(r):r};function hn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const r=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function bn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function mn(t){if(t.url)return t.url;for(const[n,i]of Object.entries(t))if(n.endsWith("_url")&&typeof i=="string")return i}const yn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ye=({item:t})=>{var f;const n=A(),{convert:i}=F(),[o,r]=c.useState(!1),l=c.useMemo(()=>(t.url?xn(t.url):void 0)||i(t.name),[t.url,t.name,i]),d=c.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(p=>({...p,url:p.url||mn(p)})),[t.volumes]),s=d&&d.length>0,a=s?d.filter(p=>p.status!=="missing").length:0,u=s?d.length-a:0,g=t.expected_volumes??(s?d.length:0),x=t.color_mode?{...yn[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:Ue(t)||s?"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}),((f=t.metadata)==null?void 0:f.check_type)&&e.jsx(mt,{value:t.metadata.check_type}),s&&e.jsxs("button",{onClick:()=>r(!o),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,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:o?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const p=bn(t.metadata);return p?hn(t.url,p):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),Ue(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(([p])=>p!=="check_type").map(([p,v])=>e.jsxs("span",{children:[n.metadata[p]||p,": ",fn(p,v,n,i)]},p)),t.details&&!s&&e.jsx("span",{children:i(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]})]}),s&&o&&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(p=>{const v=p.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:p.url&&!v?e.jsx("a",{href:p.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:p.label||`${p.volume}`,children:p.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:v?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1,lineHeight:1.4},children:p.volume})},p.volume)})})]})},yt=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:r,onConfigurePath:l,onSelectFolder:d})=>{const s=A(),a=t==="local",u=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",x=g?g.split(/[/\\]/).pop()||g:"",f={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},p={onMouseOver:S=>S.currentTarget.style.opacity="0.8",onMouseOut:S=>S.currentTarget.style.opacity="1"},v=e.jsxs("div",{onClick:r,title:u?s.mode.switchToOfficial:s.mode.switchToDraft,style:{...f,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return i==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[v,e.jsxs("div",{onClick:o,title:s.mode.switchToSync,style:f,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:s.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:d,title:g||s.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[v,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:s.mode.switchToLocal,style:f,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:s.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||s.mode.configurePath,style:{...f,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:a?s.mode.switchToGithub:s.mode.switchToLocal,style:f,...p,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?s.mode.localMode:s.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:d,title:g||s.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!a&&x&&e.jsxs("div",{style:{...f,background:"#2196f3",color:"white",cursor:"default"},title:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},_e="bim-search-history",Ge=10,Ke=8;function ve(){try{const t=localStorage.getItem(_e);return t?JSON.parse(t):[]}catch{return[]}}function vn(t){try{const n=ve().filter(i=>i!==t);n.unshift(t),n.length>Ge&&(n.length=Ge),localStorage.setItem(_e,JSON.stringify(n))}catch{}}function jn(t){try{const n=ve().filter(i=>i!==t);localStorage.setItem(_e,JSON.stringify(n))}catch{}}function Sn(){try{localStorage.removeItem(_e)}catch{}}const vt=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:r,placeholder:l})=>{const d=A(),s=l??d.search.placeholder,a={work:d.indexType.work,book:d.indexType.book,collection:d.indexType.collection},[u,g]=c.useState(!1),[x,f]=c.useState([]),[p,v]=c.useState(-1),[S,h]=c.useState(null),[E,b]=c.useState(ve),T=c.useRef(null),j=c.useRef(null),w=c.useRef(null);c.useEffect(()=>{if(!t.getAllEntries)return;let k=!1;return t.getAllEntries().then(W=>{k||h(W)}).catch(()=>{}),()=>{k=!0}},[t]);const C=c.useCallback(k=>{if(!k.trim())return E.map(z=>({type:"history",text:z}));if(!S)return[];const W=k.toLowerCase(),H=[],V=[];for(const z of S){if(H.length+V.length>=Ke*2)break;const L=z.title.toLowerCase();if(L.startsWith(W))H.push({type:"entry",text:z.title,entry:z});else if(L.includes(W))V.push({type:"entry",text:z.title,entry:z});else if(z.additional_titles){for(const N of z.additional_titles)if(N.toLowerCase().includes(W)){H.push({type:"entry",text:`${z.title}`,entry:z});break}}}return[...H,...V].slice(0,Ke)},[S,E]);c.useEffect(()=>{f(C(n)),v(-1)},[n,C]),c.useEffect(()=>{const k=W=>{w.current&&!w.current.contains(W.target)&&g(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]),c.useEffect(()=>{const k=W=>{var H,V;if(W.key==="/"&&document.activeElement!==T.current){const z=(H=document.activeElement)==null?void 0:H.tagName;if(z==="INPUT"||z==="TEXTAREA"||z==="SELECT")return;W.preventDefault(),(V=T.current)==null||V.focus()}};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[]);const y=c.useCallback(k=>{k.trim()&&(vn(k.trim()),b(ve())),o(k),g(!1)},[o]),m=c.useCallback(k=>{k.type==="history"?(i(k.text),y(k.text)):k.entry&&(r?(r(k.entry),g(!1)):(i(k.text),y(k.text)))},[i,y,r]),R=c.useCallback(k=>{if(!u||x.length===0){k.key==="Enter"&&y(n);return}switch(k.key){case"ArrowDown":k.preventDefault(),v(W=>(W+1)%x.length);break;case"ArrowUp":k.preventDefault(),v(W=>(W-1+x.length)%x.length);break;case"Enter":k.preventDefault(),p>=0&&p<x.length?m(x[p]):y(n);break;case"Escape":k.preventDefault(),g(!1);break}},[u,x,p,n,y,m]),I=c.useCallback((k,W)=>{W.stopPropagation(),jn(k),b(ve()),f(H=>H.filter(V=>!(V.type==="history"&&V.text===k)))},[]),P=c.useCallback(k=>{k.stopPropagation(),Sn(),b([]),f([])},[]);c.useEffect(()=>{if(p>=0&&j.current){const k=j.current.children;k[p]&&k[p].scrollIntoView({block:"nearest"})}},[p]);const B=!n.trim()&&E.length>0;return e.jsxs("div",{ref:w,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:T,type:"text",placeholder:s,value:n,onChange:k=>{i(k.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:R,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:j,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[B&&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:P,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:d.search.clearAll})]}),x.map((k,W)=>e.jsxs("div",{onClick:()=>m(k),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:W===p?"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:H=>I(k.text,H),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:"×"})]},`${k.type}-${k.text}-${W}`))]})]})},Pe="bim-recent-ids",Je="bim-recent-entries",Ze=50,Re=5,kn=50,wn=200;function $e(){try{const t=localStorage.getItem(Pe);if(t)return JSON.parse(t);const n=localStorage.getItem(Je);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Pe,JSON.stringify(i)),localStorage.removeItem(Je),i}return[]}catch{return[]}}function Cn(t){try{const n=$e().filter(i=>i!==t);n.unshift(t),n.length>Ze&&(n.length=Ze),localStorage.setItem(Pe,JSON.stringify(n))}catch{}}const In={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},Ae=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:r,onSwitchMode:l,onToggleDraft:d,onConfigurePath:s,onSelectFolder:a,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:f})=>{const p=A(),v=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"}],[S,h]=c.useState(g??""),[E,b]=c.useState(null),[T,j]=c.useState(null),[w,C]=c.useState(!1),[y,m]=c.useState(null),[R,I]=c.useState(""),[P,B]=c.useState(!g),[k,W]=c.useState($e),[H,V]=c.useState([]),[z,L]=c.useState(!1),[N,G]=c.useState(!1),[M,ne]=c.useState(null),ee=c.useRef(void 0),oe=c.useRef(!1),ie=c.useCallback(async($,K)=>{if(!$.trim()){B(!0),b(null),j(null);return}B(!1),C(!0),I("");try{if(t.searchAll){const Y=await t.searchAll($,K??Re);b(Y)}else{const Y=["work","book","collection"],J=await Promise.all(Y.map(Q=>t.search($,Q,{page:1,pageSize:K??Re})));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(Y){I(Y instanceof Error?Y.message:String(Y)),b(null)}finally{C(!1)}},[t]);c.useEffect(()=>{var Q;let $=!1;const K=["work","book","collection"],Y=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([Y,J]).then(([Z,D])=>{$||ne({works:Z[0].total,books:Z[1].total,collections:Z[2].total,hasText:D==null?void 0:D.hasText,hasImage:D==null?void 0:D.hasImage})}),()=>{$=!0}},[t]),c.useEffect(()=>{oe.current||!(g!=null&&g.trim())||(oe.current=!0,ie(g))},[g,ie]);const xe=c.useCallback($=>{if(h($),x==null||x($),!$.trim()){B(!0),b(null),j(null);return}ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{j(null),ie($)},wn)},[ie,x]),ae=c.useCallback($=>{ee.current&&clearTimeout(ee.current),x==null||x($),ie($)},[ie,x]),U=c.useCallback($=>{j($),ie(S,kn)},[S,ie]);c.useEffect(()=>{if(!k.length){V([]);return}let $=!1;return L(!0),Promise.all(k.slice(0,10).map(async K=>{var Y,J,Q;try{if(t.getEntry){const D=await t.getEntry(K);if(D)return D}const Z=await t.getItem(K);if(Z){const D=Z.authors;return{id:K,title:Z.title||K,type:Z.type||"work",author:(Y=D==null?void 0:D[0])==null?void 0:Y.name,dynasty:(J=D==null?void 0:D[0])==null?void 0:J.dynasty,role:(Q=D==null?void 0:D[0])==null?void 0:Q.role,edition:Z.edition||void 0}}}catch{}return null})).then(K=>{$||(V(K.filter(Y=>Y!==null)),L(!1))}),()=>{$=!0}},[k,t]);const he=$=>{m($.id),Cn($.id),W($e()),o==null||o($)},ke=$=>v.find(K=>K.type===$),Te=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:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[f,!u&&e.jsx(yt,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:l,onToggleDraft:d,onConfigurePath:s,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(vt,{transport:t,value:S,onChange:xe,onSearch:ae,onEntrySelect:he}),r&&e.jsx("button",{onClick:()=>r("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:p.action.newEntry})]}),M&&P&&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:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()})]}),M.hasImage!=null&&M.hasText!=null&&e.jsxs("span",{children:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:w?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.searching}):R?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:R})]}):P?e.jsx("div",{style:{flex:1},children:z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.loading}):H.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:p.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:H.slice(0,N?10:3).map($=>e.jsx(Xe,{entry:$,selected:y===$.id,onClick:he,getConfig:ke},$.id))}),!N&&H.length>3&&e.jsx("button",{onClick:()=>G(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:p.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):Te?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:v.map(({type:$,icon:K,name:Y,key:J})=>{const Q=E[J],Z=In[J],D=E[Z];if(Q.length===0)return null;const we=!(T===$)&&D>Re;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," ",Y,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[D," ",p.unit.items]})]}),we&&e.jsx("button",{onClick:()=>U($),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(_=>e.jsx(Xe,{entry:_,selected:y===_.id,onClick:he,getConfig:ke,query:S},_.id))})]},$)})}):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:Se(p.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},Xe=({entry:t,selected:n,onClick:i,getConfig:o,query:r})=>{const l=A(),{convert:d}=F(),s=r&&t.additional_titles?t.additional_titles.find(a=>a.toLowerCase().includes(r.toLowerCase())):void 0;return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children: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:"→"})]})},zn=["〇","一","二","三","四","五","六","七","八","九"],qe=["","十","百","千"];function jt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",r=!1;for(let l=0;l<i;l++){const d=parseInt(n[l]),s=i-1-l;d===0?r=!0:(r&&o&&(o+="〇"),r=!1,d===1&&s===1&&l===0?o+=qe[s]:o+=zn[d]+qe[s])}return o}function St({type:t}){const n=A(),i={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:i[t],border:`1px solid ${i[t]}40`,borderRadius:"2px",background:`${i[t]}08`},children:n.indexType[t]})}function _n({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 Tn({id:t}){const n=A(),[i,o]=c.useState(!1),r=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px 3px 10px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"12px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:r,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"13px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function te({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 kt({authors:t,type:n}){const{convert:i}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,r)=>e.jsxs("span",{children:[r>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",i(o.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:i(o.name)}),o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",i(o.role)]})]},r))})}function pe({id:t,label:n,onNavigate:i,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:`/${t}`,onClick:r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Rn({id:t,title:n,edition:i,type:o,isDraft:r,authors:l,volumeText:d,meta:s,headerExtra:a}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[e.jsxs("h1",{style:{fontSize:"24px",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),d&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:d})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0,paddingTop:"4px"},children:[e.jsx(St,{type:o}),e.jsx(_n,{isDraft:r}),e.jsx(Tn,{id:t}),a]})]}),((l==null?void 0:l.length)||s.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(kt,{authors:l,type:o}),s]})]})}function Ln({items:t,onNavigate:n,renderLink:i}){const o=A(),{convert:r}=F();if(!t.length)return null;const[l,d]=c.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(te,{children:o.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((s,a)=>{const u=l===a;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>d(u?null:a),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:r(s.source)}),!u&&s.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r(s.title_info)}),s.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(pe,{id:s.source_bid,label:o.action.view,onNavigate:n,renderLink:i})})]}),u&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(s.title_info||s.author_info||s.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[s.title_info&&e.jsx(se,{label:o.label.titleInfo,children:r(s.title_info)}),s.author_info&&e.jsx(se,{label:o.label.authorInfo,children:r(s.author_info)}),s.edition&&e.jsx(se,{label:o.label.edition,children:r(s.edition)})]}),s.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:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:r(s.summary)})]}),s.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:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:r(s.comment)})]}),s.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:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:r(s.additional_comment)})]})]})]},a)})})]})}function En({items:t}){const n=A(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.aliases}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,r)=>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:i(o)},r))})]}):null}function Bn({items:t}){const n=A(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,r)=>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:["《",i(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},r))})]}):null}function Wn({items:t}){const n=A(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,r)=>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:i(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(o.description)})]},r))]})]}):null}function Pn({items:t}){const n=A(),{convert:i}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,r)=>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:"·"}),i(o)]},r))})]}):null}function Qe({title:t,ids:n,transport:i,onNavigate:o,renderLink:r}){const{convert:l}=F(),[d,s]=c.useState([]);return c.useEffect(()=>{if(!n.length){s([]);return}if(!i){s(n.map(u=>({id:u})));return}let a=!1;return Promise.all(n.map(u=>i.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=>{a||s(u)}),()=>{a=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(te,{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(a=>({id:a}))).map(a=>{const u=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(pe,{id:a.id,label:u,onNavigate:o,renderLink:r})},a.id)})})]}):null}function $n({book:t,onNavigate:n,renderLink:i}){const o=A(),{convert:r}=F(),[l,d]=c.useState(!1),s=t.resources&&t.resources.length>0,a=t.edition?`${r(t.title)||t.id}(${r(t.edition)})`:r(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:s&&!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(pe,{id:t.id,label:a,onNavigate:n,renderLink:i})}),s&&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?o.action.expand:o.action.collapse,children:"▼"})]}),s&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(De,{items:t.resources,groupByType:!0})})]})}function An({ids:t,transport:n,onNavigate:i,renderLink:o}){const r=A(),[l,d]=c.useState([]);return c.useEffect(()=>{if(!t.length){d([]);return}if(!n){d(t.map(a=>({id:a})));return}let s=!1;return Promise.all(t.map(a=>n.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:a})))).then(a=>{s||d(a)}),()=>{s=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(te,{children:[r.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(s=>({id:s}))).map(s=>e.jsx($n,{book:s,onNavigate:i,renderLink:o},s.id))})]}):null}function Mn({workData:t,onNavigate:n,renderLink:i}){var l,d,s;const o=A(),{convert:r}=F();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(St,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(pe,{id:t.id,label:r(t.title),onNavigate:n,renderLink:i})}),((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:[jt(t.juan_count.number),o.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(kt,{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:(s=t.authors)!=null&&s.length?"8px 0 0":"0",textAlign:"justify"},children:r(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(se,{label:o.label.parentWork,children:e.jsx(pe,{id:t.parent_work.id,label:r(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Fn({items:t,onNavigate:n,renderLink:i}){const o=A(),{convert:r}=F();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:o.indexType.collection}),e.jsx(pe,{id:l.id,label:r(l.title)||l.id,onNavigate:n,renderLink:i}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Se(o.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const He=({data:t,id:n,transport:i,onNavigate:o,renderLink:r,headerExtra:l,className:d,style:s})=>{var P,B,k,W,H,V;const a=A(),{convert:u}=F(),[g,x]=c.useState(null),[f,p]=c.useState(!1),[v,S]=c.useState(null),[h,E]=c.useState(null),[b,T]=c.useState([]),j=t||g;if(c.useEffect(()=>{if(t||!n||!i)return;let z=!1;return p(!0),S(null),i.getItem(n).then(L=>{z||(L?x(L):S(a.misc.notFoundEntry))}).catch(L=>{z||S(L instanceof Error?L.message:a.misc.loadFailed)}).finally(()=>{z||p(!1)}),()=>{z=!0}},[t,n,i]),c.useEffect(()=>{if(!j||!i){E(null),T([]);return}let z=!1;const L=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(L?i.getItem(L).then(N=>{!z&&N&&N.type==="work"&&E(N)}).catch(()=>{}):E(null),j.type==="book"){const N=j;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(G=>{const M=typeof G=="string"?G:G.id,ne=typeof G=="string"?void 0:G.volume_index;return i.getItem(M).then(ee=>({id:M,title:ee&&ee.title||M,volume_index:ne})).catch(()=>({id:M,title:M,volume_index:ne}))})).then(G=>{z||T(G)}):T([])}else T([]);return()=>{z=!0}},[j,i]),f)return e.jsx("div",{className:d,style:{...s,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((z,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${z}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(v)return e.jsx("div",{className:d,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!j)return null;const w=j.type==="book"?j:null,C=j.type==="collection"?j:null,y=j.type==="work"?j:null;let m=!1;try{m=O.extractStatus(j.id)==="draft"}catch{}let R="";(P=j.juan_count)!=null&&P.number?R=jt(j.juan_count.number)+a.unit.juan:(B=j.juan_count)!=null&&B.description&&(R=u(j.juan_count.description));const I=[];return(k=j.publication_info)!=null&&k.year&&I.push(e.jsx(se,{label:a.label.year,children:j.publication_info.year},"year")),(W=j.current_location)!=null&&W.name&&I.push(e.jsx(se,{label:a.label.currentLocation,children:u(j.current_location.name)},"loc")),(H=j.page_count)!=null&&H.description&&I.push(e.jsx(se,{label:a.label.pageCount,children:j.page_count.description},"page")),w!=null&&w.edition&&I.push(e.jsx(se,{label:a.label.edition,children:u(w.edition)},"ver")),y!=null&&y.parent_work&&I.push(e.jsx(se,{label:a.label.parentWork,children:e.jsx(pe,{id:y.parent_work.id,label:u(y.parent_work.title),onNavigate:o,renderLink:r})},"pw")),y!=null&&y.parent_works&&y.parent_works.length>0&&!y.parent_work&&I.push(e.jsx(se,{label:a.label.parentWork,children:y.parent_works.map((z,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(pe,{id:z,onNavigate:o,renderLink:r})]},z))},"pws")),e.jsxs("div",{className:d,style:s,children:[e.jsx(Rn,{id:j.id,title:u(j.title),edition:j.edition?u(j.edition):void 0,type:j.type,isDraft:m,authors:j.authors,volumeText:R,meta:I,headerExtra:l}),((V=j.description)==null?void 0:V.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(j.description.text)}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:a.section.containedIn}),e.jsx(Fn,{items:b,onNavigate:o,renderLink:r})]}),h&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:a.section.belongsToWork}),e.jsx(Mn,{workData:h,onNavigate:o,renderLink:r})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(Bn,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(En,{items:j.additional_titles}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(Ln,{items:j.indexed_by,onNavigate:o,renderLink:r}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:a.section.resources}),e.jsx(De,{items:j.resources,groupByType:!0})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(Wn,{items:w.location_history}),(C==null?void 0:C.history)&&C.history.length>0&&e.jsx(Pn,{items:C.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(Qe,{title:a.section.relatedVersions,ids:w.related_books,transport:i,onNavigate:o,renderLink:r}),(C==null?void 0:C.books)&&C.books.length>0&&e.jsx(Qe,{title:a.section.containedBooks,ids:C.books,transport:i,onNavigate:o,renderLink:r}),(y==null?void 0:y.books)&&y.books.length>0&&e.jsx(An,{ids:y.books,transport:i,onNavigate:o,renderLink:r}),(y==null?void 0:y.related_works)&&y.related_works.length>0&&(()=>{const z=[],L=y.related_works.filter(M=>M.relation==="part_of"),N=y.related_works.filter(M=>M.relation==="has_part"),G=y.related_works.filter(M=>!M.relation);return L.length>0&&z.push({label:a.section.belongsToWork,items:L}),N.length>0&&z.push({label:a.section.containedWorks,items:N}),G.length>0&&z.push({label:a.section.relatedWorks,items:G}),z.map(M=>e.jsxs("div",{children:[e.jsxs(te,{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(ne=>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(pe,{id:ne.id,label:u(ne.title),onNavigate:o,renderLink:r})},ne.id))})]},M.label))})()]})};function Dn({data:t}){const n=A(),{convert:i}=F(),{stats:o}=t,r=o.processed_volumes??o.total_found_volumes,l=r!=null&&t.total_volumes>0?Math.round(r/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:i(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(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:r})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Hn({sections:t,activeSection:n,onSelect:i}){const o=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:et(n===null),children:o.catalog.all}),t.map(r=>e.jsxs("button",{onClick:()=>i(r.name),style:et(n===r.name),children:[r.name,r.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[r.volume_range[0],"–",r.volume_range[1]]})]},r.name))]})}function et(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 On({id:t,label:n,onNavigate:i,renderLink:o}){return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:`/${t}`,onClick:r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i(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:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Vn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],o=t[t.length-1];return o-i+1===t.length?`${i}–${o}`:t.length<=3?t.join(", "):`${i}–${o} (${t.length}${n})`}function tt({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const r=A(),{convert:l}=F(),d=t.book_id||t.work_id,s=o&&t.volumes.length>0?Vn(t.volumes,r.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:s}),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:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,r.unit.volume]}),d&&e.jsx(On,{id:d,label:t.book_id?r.indexType.book:r.indexType.work,onNavigate:n,renderLink:i}),!d&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:r.catalog.unmatched_label})]})}const wt=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:r,className:l,style:d})=>{const s=A(),[a,u]=c.useState(null),[g,x]=c.useState(!1),[f,p]=c.useState(null),[v,S]=c.useState(null),[h,E]=c.useState(""),b=t||a;c.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let y=!1;return x(!0),p(null),i.getCollectionCatalog(n).then(m=>{y||(m?u(m):p(s.catalog.notFound))}).catch(m=>{y||p(m instanceof Error?m.message:s.catalog.loadFailed)}).finally(()=>{y||x(!1)}),()=>{y=!0}},[t,n,i,s]);const T=(b==null?void 0:b.sections)&&b.sections.length>0,j=c.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const y=b.books.map(R=>R.volumes[0]).filter(R=>R!=null);return new Set(y).size<y.length},[b]),w=c.useMemo(()=>{if(!b)return[];let y=b.books;if(v&&(y=y.filter(m=>m.section===v)),h.trim()){const m=h.trim().toLowerCase();y=y.filter(R=>R.title.toLowerCase().includes(m)||R.sub_items&&R.sub_items.some(I=>I.toLowerCase().includes(m))||R.edition&&R.edition.toLowerCase().includes(m))}return y},[b,v,h]),C=c.useMemo(()=>{if(!j)return null;const y=[],m=new Map;for(const I of w){if(!I.volumes||I.volumes.length===0)continue;const P=I.volumes[0];m.has(P)||m.set(P,[]),m.get(P).push(I)}const R=[...m.keys()].sort((I,P)=>I-P);for(const I of R)y.push({volume:I,books:m.get(I)});return y},[w,j]);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:s.catalog.loading})}):f?e.jsx("div",{className:l,style:{...d,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):b?e.jsxs("div",{className:l,style:d,children:[e.jsx(Dn,{data:b}),T&&e.jsx(Hn,{sections:b.sections,activeSection:v,onSelect:S}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:s.search.searchBookName,value:h,onChange:y=>E(y.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[w.length," ",s.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[C?C.map((y,m)=>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:Se(s.catalog.volume,{n:y.volume})}),y.books.map((R,I)=>e.jsx(tt,{book:R,onNavigate:o,renderLink:r,showVolumes:R.volumes.length>1},`${y.volume}-${I}`))]},`${y.volume}-${m}`)):w.map((y,m)=>e.jsx(tt,{book:y,onNavigate:o,renderLink:r,showVolumes:!0},m)),w.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:s.catalog.noMatch})]})]}):null},Nn=["〇","一","二","三","四","五","六","七","八","九"],nt=["","十","百","千"],Un=["","萬","億"];function Ct(t){if(t===0)return"〇";if(t<0)return`負${Ct(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const r=i%1e4;r>0?n.unshift(Yn(r,o>0)+Un[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Yn(t,n){const i=[];let o=t;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let r="";for(let l=0;l<i.length;l++){const d=i[l],s=i.length-1-l;d===0?r&&!r.endsWith("〇")&&(r+="〇"):d===1&&s===1&&l===0&&!n?r+=nt[s]:r+=Nn[d]+nt[s]}return r.replace(/〇$/,"")}const It={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Gn(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 zt({file:t,isActive:n,onSelect:i}){return e.jsx("button",{onClick:()=>i(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:Gn(t)})}function _t(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>_t(o,n)))}function Tt(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((r,l)=>r+Tt(l),0))||0;return n+i}function Rt({group:t,activeFile:n,onSelect:i,depth:o=0}){var u;const r=_t(t,n||""),[l,d]=c.useState(r),s=Tt(t),a=!!((u=t.children)!=null&&u.length);return c.useEffect(()=>{r&&d(!0)},[r]),e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:r?"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:["(",s,")"]})]}),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+o*16}px`},children:t.files.map(g=>e.jsx(zt,{file:g,isActive:n===g,onSelect:i},g))}),a&&t.children.map((g,x)=>e.jsx(Rt,{group:g,activeFile:n,onSelect:i,depth:o+1},x))]})]})}function Kn({files:t,groups:n,activeFile:i,onSelect:o}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((r,l)=>e.jsx(Rt,{group:r,activeFile:i,onSelect:o},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(r=>e.jsx(zt,{file:r,isActive:i===r,onSelect:o},r))})}function Jn({type:t}){const n=It[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Zn({section:t,onNavigate:n}){const{convert:i}=F(),[o,r]=c.useState(!1),l=!!t.summary,d=!!t.comment,s=!!t.additional_comment,a=l||d||s;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>a&&r(!o),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:a?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[a&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:o?"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?`《${i(t.book_title)}》`:i(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ct(t.n_juan),"卷"]})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:i(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:`/${t.work_id}`,onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),o&&a&&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:i(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:i(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:i(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:i(t.additional_comment)})]})]})]})}function Xn({section:t}){const{convert:n}=F(),[i,o]=c.useState(!1),r=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>r&&o(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:r?"pointer":"default",userSelect:"none"},children:[e.jsx(Jn,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),r&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${It[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:n(t.content)})})]})}function qn({section:t}){const{convert:n}=F();if(!t.content&&!t.title)return null;const i=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:i})}function Qn({juan:t,searchQuery:n,onNavigate:i}){const{convert:o}=F(),r=c.useMemo(()=>{if(!n.trim())return t.sections;const d=n.trim().toLowerCase();return t.sections.filter(s=>{var a,u,g,x,f;return((a=s.title)==null?void 0:a.toLowerCase().includes(d))||((u=s.book_title)==null?void 0:u.toLowerCase().includes(d))||((g=s.author)==null?void 0:g.toLowerCase().includes(d))||((x=s.author_info)==null?void 0:x.toLowerCase().includes(d))||((f=s.summary)==null?void 0:f.toLowerCase().includes(d))})},[t.sections,n]),l=r.filter(d=>d.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:o(t.title)}),t.source_url&&e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:"原文 ↗"}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[l," 部书"]})]}),r.map((d,s)=>d.type==="书"?e.jsx(Zn,{section:d,onNavigate:i},s):d.type==="部"||d.type==="类"?e.jsx(Xn,{section:d},s):e.jsx(qn,{section:d},s)),r.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const Lt=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:r,onJuanChange:l,className:d,style:s})=>{const[a,u]=c.useState(null),[g,x]=c.useState(!1),[f,p]=c.useState(null),[v,S]=c.useState(null),[h,E]=c.useState(null),[b,T]=c.useState(!1),[j,w]=c.useState(""),C=r??v,y=c.useCallback(B=>{S(B),l==null||l(B)},[l]),m=t||a;c.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let B=!1;return x(!0),p(null),i.getCollatedEditionIndex(n).then(k=>{B||(k?(u(k),!r&&k.juan_files.length>0&&y(k.juan_files[0])):p("未找到整理本数据"))}).catch(k=>{B||p(k instanceof Error?k.message:"加载失败")}).finally(()=>{B||x(!1)}),()=>{B=!0}},[t,n,i,r,y]),c.useEffect(()=>{const B=t||a;B&&B.juan_files&&B.juan_files.length>0&&!C&&y(B.juan_files[0])},[t,a,C,y]);const R=n||(m==null?void 0:m.work_id),I=c.useCallback(async B=>{if(!(!R||!(i!=null&&i.getCollatedJuan))){T(!0),E(null);try{const k=await i.getCollatedJuan(R,B);E(k)}catch{E(null)}finally{T(!1)}}},[R,i]);c.useEffect(()=>{C&&I(C)},[C,I]);const P=B=>{y(B),w("")};return g?e.jsx("div",{className:d,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):f?e.jsx("div",{className:d,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):m?e.jsxs("div",{className:d,style:s,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:m.total_juan})," 卷"]})}),e.jsx(Kn,{files:m.juan_files,groups:m.juan_groups,activeFile:C,onSelect:P}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:j,onChange:B=>w(B.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("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载中..."}):h?e.jsx(Qn,{juan:h,searchQuery:j,onNavigate:o}):C?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null]}):null},eo=[{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:"經典作品"}],Me=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:r})=>{const l=A(),[d,s]=c.useState(null),[a,u]=c.useState([]),[g,x]=c.useState("recommend"),f=o??g,p=w=>{x(w),r==null||r(w)},[v,S]=c.useState(!0),[h,E]=c.useState(null),[b,T]=c.useState(null);c.useEffect(()=>{if(!t.getAllEntries)return;let w=!1;return t.getAllEntries().then(C=>{if(w)return;const y=C.filter(I=>I.type==="work").length,m=C.filter(I=>I.type==="book").length,R=C.filter(I=>I.type==="collection").length;s({works:y,books:m,collections:R})}).catch(()=>{}),()=>{w=!0}},[t]),c.useEffect(()=>{let w=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const y=await t.getRecommended();if(y!=null&&y.groups)return y.groups.flatMap(m=>m.items.map(R=>({...R,group:m.name})))}catch{}return eo})().then(async y=>{if(w)return;const m=y.filter(I=>I.id);if(m.length===0){S(!1);return}const R=await Promise.all(m.map(async I=>{try{let P=null;if(t.getEntry)P=await t.getEntry(I.id);else{const B=await t.getItem(I.id);B&&(P={id:I.id,title:B.title||I.id,type:B.type||"work"})}if(P)return{...P,group:I.group,fallbackDescription:I.description}}catch{}return{id:I.id,title:I.title,type:I.id.startsWith("FC")?"collection":"work",group:I.group,fallbackDescription:I.description}}));w||(u(R.filter(I=>I!==null)),S(!1))}),()=>{w=!0}},[t,i]),c.useEffect(()=>{if(!t.getResourceProgress)return;let w=!1;return t.getResourceProgress().then(C=>{w||E(C)}).catch(()=>{}),()=>{w=!0}},[t]),c.useEffect(()=>{if(!t.getSiteProgress)return;let w=!1;return t.getSiteProgress().then(C=>{w||T(C)}).catch(()=>{}),()=>{w=!0}},[t]);const j=w=>{switch(w){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:l.home.recommendTab,active:f==="recommend",onClick:()=>p("recommend")}),e.jsx(Le,{label:l.home.catalogTab,active:f==="catalog",onClick:()=>p("catalog")}),e.jsx(Le,{label:l.home.siteTab,active:f==="site",onClick:()=>p("site")})]}),f==="recommend"&&e.jsx(to,{recommended:a,loading:v,onNavigate:n,getIcon:j,t:l}),f==="catalog"&&e.jsx(no,{progress:h,t:l,onNavigate:n}),f==="site"&&e.jsx(io,{progress:b,t:l,totalWorks:(d==null?void 0:d.works)??0})]})})},Le=({label:t,active:n,onClick:i})=>e.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),to=({recommended:t,loading:n,onNavigate:i,getIcon:o,t:r})=>{if(n)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});if(t.length===0)return null;const l=new Map;for(const d of t){const s=d.group||r.home.recommendedBrowse;l.has(s)||l.set(s,[]),l.get(s).push(d)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([d,s])=>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:s.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return e.jsxs("a",{href:`/${a.id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),i==null||i(a.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(a.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a.title,a.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:a.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},a.id)})})]},d))})},no=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const o=[...t.resources].sort((s,a)=>s.priority-a.priority),r=["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:r.map(s=>{const a=o.filter(u=>u.status===s);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:d[s]}}),l[s]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(u=>e.jsx(oo,{item:u,t:n,statusColor:d[s],onNavigate:i},u.id))})]},s)})})},oo=({item:t,t:n,statusColor:i,onNavigate:o})=>{const r=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,s=t.collection_id||t.work_id;return s&&o?e.jsx("a",{href:`/${s}`,onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o(s))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.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?Se(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:`${r}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},io=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const o=[...t.resources].sort((a,u)=>a.priority-u.priority),r=o.filter(a=>a.imported>0),l=o.filter(a=>a.imported===0),d=r.reduce((a,u)=>Math.max(a,u.imported),0),s=i>0?Math.round(d/i*100):0;return e.jsxs("div",{children:[i>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()})," / ",i.toLocaleString()," ",n.indexType.work," (",s,"%)"]}),r.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," (",r.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map(a=>e.jsx(ot,{item:a,t:n,totalWorks:i},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(ot,{item:a,t:n,totalWorks:i},a.id))})]})]})},ot=({item:t,t:n,totalWorks:i})=>{const o=i>0?Math.round(t.imported/i*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&i>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},it="(max-width: 768px)";function ro(){const[t,n]=c.useState(()=>typeof window>"u"?!1:window.matchMedia(it).matches);return c.useEffect(()=>{const i=window.matchMedia(it),o=r=>n(r.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),t}const lo=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:r})=>{var V;const l=A(),{convert:d}=F(),s=ro(),[a,u]=c.useState(null),[g,x]=c.useState(null),[f,p]=c.useState(!1),[v,S]=c.useState("detail"),[h,E]=c.useState([]),[b,T]=c.useState(!1),[j,w]=c.useState(null),[C,y]=c.useState(!1),m=c.useCallback(async z=>{if(!t.getCollatedEditionIndex){w(null);return}y(!0);try{const L=await t.getCollatedEditionIndex(z);w(L)}catch{w(null)}finally{y(!1)}},[t]),R=c.useCallback(async z=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){E([]);return}T(!0);try{if(t.getCollectionCatalogs){const L=await t.getCollectionCatalogs(z);E(L||[])}else if(t.getCollectionCatalog){const L=await t.getCollectionCatalog(z);E(L?[{resource_id:"",data:L}]:[])}}catch{E([])}finally{T(!1)}},[t]),I=c.useCallback(async z=>{if(i){i(z);return}u(z),x(null),E([]),w(null),S("detail"),p(!0);try{const L=await t.getItem(z.id);L&&(x(L),L.type==="collection"?R(z.id):L.type==="work"&&L.has_collated&&m(z.id))}catch(L){console.error("加载详情失败:",L)}finally{p(!1)}},[t,i,R,m]),P=c.useCallback(async z=>{x(null),E([]),w(null),S("detail"),p(!0);try{const L=await t.getItem(z);L&&(x(L),u({id:z,title:L.title||z,type:L.type||"book"}),L.type==="collection"?R(z):L.type==="work"&&L.has_collated&&m(z))}catch(L){console.error("导航失败:",L)}finally{p(!1)}},[t,R,m]),B=(g==null?void 0:g.type)==="collection"&&(h.length>0||b)||(g==null?void 0:g.type)==="work"&&(j||C),k=s&&(f||g),W=c.useCallback(()=>{u(null),x(null),E([]),w(null),S("detail")},[]),H=e.jsx(e.Fragment,{children:f?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中..."})}):g?e.jsxs(e.Fragment,{children:[(B||r)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:s?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:s?"auto":void 0},children:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>S("detail"),style:Ce(v==="detail"),children:l.detailTab.basicInfo}),g.type==="collection"&&b&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:Ce(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),g.type==="collection"&&h.map(z=>e.jsx("button",{onClick:()=>S(`catalog:${z.resource_id}`),style:Ce(v===`catalog:${z.resource_id}`),children:z.short_name?`${d(z.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},z.resource_id)),g.type==="work"&&(j||C)&&e.jsxs("button",{onClick:()=>S("collated"),style:Ce(v==="collated"),children:[l.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),r&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:r})]}),e.jsx("div",{style:{padding:s?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:v==="detail"?e.jsx(He,{data:g,transport:t,onNavigate:P}):v.startsWith("catalog:")?e.jsx(wt,{data:(V=h.find(z=>`catalog:${z.resource_id}`===v))==null?void 0:V.data,onNavigate:P}):v==="collated"?e.jsx(Lt,{index:j||void 0,workId:g.id,transport:t,onNavigate:P}):null})]}):e.jsx(Me,{transport:t,onNavigate:P,recommendedIds:o})});return s?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:W,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:H})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ae,{transport:t,onEntryClick:I,hideModeIndicator:n}),!g&&e.jsx(Me,{transport:t,onNavigate:P,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Ae,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:H})]})};function Ce(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 so=({data:t,onNavigate:n,className:i,style:o})=>{var g;const r=A(),{convert:l}=F(),[d,s]=c.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[a,u]=c.useState(null);return e.jsxs("div",{className:i,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children: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:[r.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",r.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",r.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",r.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(ao,{division:x,expanded:d===x.name,onToggle:()=>s(d===x.name?null:x.name),expandedCat:a,onCatToggle:f=>u(a===f?null:f),onNavigate:n},x.name))})]})},ao=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:r,onNavigate:l})=>{const{convert:d}=F(),s=t.categories.reduce((a,u)=>{const g=u.stats||{zhulu:0,cunmu:0};return a+(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:i,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," 類 · ",s," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const u=`${t.name}/${a.name}`;return e.jsx(co,{category:a,expanded:o===u,onToggle:()=>r(u),onNavigate:l},a.name)})})]})},co=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var a,u,g,x;const{convert:r}=F(),l=((a=t.books)==null?void 0:a.zhulu)||[],d=((u=t.books)==null?void 0:u.cunmu)||[],s=(((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:i,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:[r(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:[s," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(rt,{label:"著錄",books:l,onNavigate:o}),d.length>0&&e.jsx(rt,{label:"存目",books:d,onNavigate:o})]})]})},rt=({label:t,books:n,onNavigate:i})=>{const{convert:o}=F(),[r,l]=c.useState(n.length<=20),d=r?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((s,a)=>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:s.work_id&&i?e.jsx("a",{href:`/${s.work_id}`,onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(s.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(s.title)}):o(s.title)}),s.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(s.volumes)}),s.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(s.author).slice(0,20)})]},a))}),!r&&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," 條"]})]})},le=({title:t,onSave:n,onAskAI:i,extraButtons:o,children:r})=>{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:[o,i&&e.jsx("button",{onClick:i,style:xo,children:"AI"}),n&&e.jsx("button",{onClick:n,style:po,children:l.action.save})]})]}),r]})},po={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},xo={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:i,placeholder:o,disabled:r})=>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=>i(l.target.value),placeholder:o,disabled:r,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:i})=>{const o=c.useRef(null);return c.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:r=>n(r.target.value),placeholder:i,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"}})},ze=({children:t,color:n,style:i})=>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)",...i},children:t});function uo(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ie=({value:t,onChange:n,label:i})=>{const[o,r]=c.useState(!1),l=c.useRef(null),d=uo(t||"");return c.useEffect(()=>{o&&l.current&&l.current.focus()},[o]),!o&&d?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:lt,children:i}),e.jsxs("div",{onClick:()=>r(!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(ze,{children:d.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:lt,children:i}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:s=>n(s.target.value),onBlur:()=>r(!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"}})]})},lt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function go(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function fo(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Et=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=A(),[r,l]=c.useState(null),d=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},s=x=>{n(t.filter((f,p)=>p!==x)),r===x&&l(null)},a=(x,f,p)=>{const v=[...t];v[x]={...v[x],[f]:p},n(v)},u=(x,f)=>{const p=[...t];p[x]={...p[x],type:f,id:"",name:""},n(p),f==="bookID"&&i&&i(v=>{const S=[...t];S[x]={...S[x],id:v.id,name:v.title,type:"bookID"},n(S)})},g=x=>{i&&i(f=>{const p=[...t];p[x]={...p[x],id:f.id,name:f.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>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(r===f?null:f),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:r===f?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${o.editor.sourcePlaceholder} ${f+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:go(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:fo(x.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),s(f)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),r===f&&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:ce,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>u(f,"bookID"),style:{...st,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>u(f,"url"),style:{...st,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ce,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[f]={...p[f],type:"",id:"",name:""},n(p)},style:at,children:o.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>g(f),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>g(f),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ce,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[f]={...p[f],type:"",id:"",name:""},n(p)},style:at,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:p=>a(f,"name",p.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:p=>a(f,"id",p.target.value),placeholder:"https://...",style:ge})]})]}),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:{...ce,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:p=>a(f,"details",p.target.value),placeholder:o.editor.detailsPlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:p=>a(f,"position",p.target.value),placeholder:"如: 卷三, p.52",style:ge})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:p=>a(f,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:ce,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:p=>a(f,"processor_version",p.target.value),placeholder:"如: v0.1",style:ge})]})]})]})]})})]},f)),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:o.action.addSource})]})]})},ce={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ge={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"},st={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},at={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Bt(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Wt(t){return!t||t.length===0?"":JSON.stringify(t)}const Pt=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:r,belongsToWork:l,belongsToCollection:d,childWorks:s,childCollections:a,containedBooks:u,siblingBooks:g,onLinkEntity:x,onUnlinkEntity:f,onViewEntity:p,onCreateAndLink:v,onSaveRelations:S})=>{const h=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:h.section.relations})]}),S&&e.jsx("button",{onClick:S,style:ho,children:h.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:h.relation.belongsToWork,entity:l,onView:p,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>v("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ye,{direction:"up",title:h.relation.containedInCollection,entity:d,onView:p,onUnlink:()=>f("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>v("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),l&&g&&g.length>0&&e.jsx(fe,{direction:"horizontal",title:`${h.relation.siblingVersions} (${g.length})`,entities:g,onView:p,onAdd:()=>v("siblingBook","book",{workId:l.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:h.relation.parentWork,entity:o,onView:p,onUnlink:()=>f("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>v("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),s&&s.length>0&&e.jsx(fe,{direction:"down",title:`${h.relation.childWorks} (${s.length})`,entities:s,onView:p,onAdd:()=>v("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),a&&a.length>0&&e.jsx(fe,{direction:"down",title:`${h.relation.collectionImpl} (${a.length})`,entities:a,onView:p,onAdd:()=>v("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(fe,{direction:"down",title:`${h.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:p,onAdd:()=>v("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:h.relation.correspondingWork,entity:l,onView:p,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>v("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ye,{direction:"up",title:h.relation.parentCollection,entity:r,onView:p,onUnlink:()=>f("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>v("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(fe,{direction:"down",title:`${h.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:p,onAdd:()=>v("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(fe,{direction:"down",title:`${h.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:p,onAdd:()=>v("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},ye=({direction:t,title:n,entity:i,onView:o,onUnlink:r,onLink:l,onCreate:d,linkLabel:s,createLabel:a,notLinkedLabel:u,viewLabel:g,unlinkLabel:x})=>{const f=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),i?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:$t(i.type)}),e.jsx("span",{style:{fontWeight:500},children:i.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(dt,{onClick:()=>o(i),title:g,children:"👁️"}),e.jsx(dt,{onClick:r,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(Fe,{onClick:l,children:s}),e.jsx(Fe,{onClick:d,primary:!0,children:a})]})]})},fe=({direction:t,title:n,entities:i,onView:o,onAdd:r,addLabel:l,noneLabel:d,expandMoreLabel:s})=>{const[a,u]=c.useState(!1),g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",f=a?i:i.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})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[f.map(p=>e.jsxs("div",{onClick:()=>o(p),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:$t(p.type)}),e.jsx("span",{children:p.title})]},p.id)),i.length>5&&!a&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[s," (",i.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(Fe,{onClick:r,primary:!0,children:["+ ",l]})})]})},dt=({onClick:t,title:n,danger:i,children:o})=>e.jsx("button",{onClick:r=>{r.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),Fe=({onClick:t,primary:n,children:i})=>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:i});function $t(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const ho={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"},At=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:r,onCreate:l,searchResults:d,onSearch:s,isLoading:a,excludeId:u})=>{const[g,x]=c.useState(""),f=u?d.filter(h=>h.id!==u):d;c.useEffect(()=>{t&&(x(""),s(""))},[t]);const p=h=>{x(h),s(h)};if(!t)return null;const v=n==="work"?"作品":n==="book"?"书籍":"丛编",S=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:bo,children:e.jsxs("div",{style:mo,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:i}),e.jsx("button",{onClick:r,style:yo,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:h=>p(h.target.value),placeholder:`搜索${v}名称或 ID...`,autoFocus:!0,style:vo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Ee,children:"搜索中..."}):f.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:f.map(h=>e.jsxs("div",{onClick:()=>o(h),style:jo,children:[e.jsx("span",{style:{fontSize:"16px"},children:S}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):g?e.jsxs("div",{style:Ee,children:["未找到匹配的",v]}):e.jsxs("div",{style:Ee,children:["输入关键词搜索",v]})}),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:So,children:["创建新",v,"并关联"]})]})]})})},bo={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},mo={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)"},yo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},vo={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"},jo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ee={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},So={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ct={work:"作品",book:"书籍",collection:"丛编"},ko={work:"📜",book:"📖",collection:"📚"},Mt=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:r,onCancel:l})=>{const[d,s]=c.useState(""),a=c.useRef(null);c.useEffect(()=>{t&&(s((o==null?void 0:o.title)||""),setTimeout(()=>{var f,p;(f=a.current)==null||f.focus(),(p=a.current)==null||p.select()},100))},[t,o==null?void 0:o.title]);const u=f=>{f.key==="Enter"&&d.trim()?g():f.key==="Escape"&&l()},g=()=>{d.trim()&&r(d.trim(),{...o,title:d.trim()})};if(!t)return null;const x=()=>{switch(i){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`创建新${ct[n]}`}};return e.jsx("div",{style:wo,onClick:f=>{f.target===f.currentTarget&&l()},children:e.jsxs("div",{style:Co,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ko[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:d,onChange:f=>s(f.target.value),onKeyDown:u,placeholder:`请输入${ct[n]}名称...`,style:Io})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:zo,children:"取消"}),e.jsx("button",{onClick:g,disabled:!d.trim(),style:{..._o,opacity:d.trim()?1:.6,cursor:d.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},wo={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},Co={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)"},Io={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"},zo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},_o={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function To(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Ft(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ro(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Dt=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:r,showCreateButton:l=!1,createButtonText:d,onSelect:s,onCancel:a,onCreate:u,onSearch:g})=>{const[x,f]=c.useState(""),[p,v]=c.useState([]),[S,h]=c.useState(!1),[E,b]=c.useState("recent");c.useEffect(()=>{t&&(f(""),v([]),b(o.length>0?"recent":"search"))},[t,o.length]),c.useEffect(()=>{if(!x.trim()){v([]);return}const m=setTimeout(async()=>{h(!0);try{v(await g(x,i))}catch{v([])}finally{h(!1)}},300);return()=>clearTimeout(m)},[x,i,g]);const T=c.useCallback(m=>{f(m.target.value),m.target.value.trim()&&b("search")},[]),j=c.useCallback(m=>r?m.filter(R=>R.id!==r):m,[r]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${Ft(i)}`),C=j(o),y=j(p);return e.jsx("div",{style:Eo,children:e.jsxs("div",{style:Bo,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:w}),e.jsx("button",{onClick:a,style:Wo,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:T,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Po}),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:"搜索中..."})]})}),C.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(pt,{active:E==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(pt,{active:E==="search",onClick:()=>b("search"),children:["搜索结果 ",y.length>0&&`(${y.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:E==="recent"&&C.length>0?e.jsx(xt,{entities:C,onSelect:s}):x.trim()?S?e.jsx(Be,{message:"搜索中..."}):y.length>0?e.jsx(xt,{entities:y,onSelect:s}):e.jsx(Be,{message:"未找到匹配的结果"}):e.jsx(Be,{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:$o,children:d||"创建新实体"})]})]})})},pt=({active:t,onClick:n,children:i})=>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:i}),xt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(Lo,{entity:i,onClick:()=>n(i)},i.id))}),Lo=({entity:t,onClick:n})=>{const[i,o]=c.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i?"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:To(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:Ro(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Ft(t.type)})]})},Be=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Eo={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},Bo={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)"},Wo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Po={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"},$o={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ao={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},Mo={work:"📜",collection:"📚",book:"📖"},Ht=({data:t,onChange:n,onSave:i,transport:o,onNavigate:r,showDelete:l,onDelete:d,onAskAI:s,renderSectionActions:a,onDownloadResource:u,downloadStatuses:g,relations:x,onRelationsChange:f})=>{var we;const p=A(),[v,S]=c.useState(!1),[h,E]=c.useState("work"),[b,T]=c.useState(""),[j,w]=c.useState(""),[C,y]=c.useState([]),[m,R]=c.useState(!1),[I,P]=c.useState(!1),[B,k]=c.useState("work"),[W,H]=c.useState(""),[V,z]=c.useState(),[L,N]=c.useState(!1),[G,M]=c.useState(null),[ne,ee]=c.useState([]);c.useRef(null);const oe=t.type,ie=oe==="work",xe=oe==="collection",ae=oe==="book",U=c.useCallback((_,X)=>{n({...t,[_]:X})},[t,n]),he=c.useCallback((_,X)=>{T(_),E(X),w(p.editor.selectToLink+p.indexType[X]),y([]),S(!0)},[p]),ke=c.useCallback(_=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,_)},[o,t.id]),Te=c.useCallback(_=>{r==null||r(_.id,_.type)},[r]),$=c.useCallback((_,X,de)=>{const Nt={...de,author:(de==null?void 0:de.author)||t.author,dynasty:(de==null?void 0:de.dynasty)||t.dynasty};k(X),H(_),z(Nt),P(!0)},[t.author,t.dynasty]),K=c.useCallback((_,X)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,W,{type:B,title:_,inheritData:X}),P(!1)},[o,t.id,W,B]),Y=c.useCallback(_=>{if(!_.trim()){y([]);return}R(!0),o!=null&&o.searchEntities&&o.searchEntities(_,h).then(X=>{y(X),R(!1)}).catch(()=>{y([]),R(!1)})},[o,h]),J=c.useCallback(_=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,b,_.id),S(!1)},[o,t.id,b]),Q=c.useCallback(()=>{i()},[i]),Z=c.useCallback(_=>{M(()=>_),N(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(ee).catch(()=>{})},[o]),D=c.useCallback((_,X)=>o!=null&&o.searchEntities?o.searchEntities(_,X==="all"?void 0:X):Promise.resolve([]),[o]),Oe=c.useCallback(_=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(_),ee(X=>[_,...X.filter(de=>de.id!==_.id)].slice(0,10)),G==null||G(_),N(!1),M(null)},[o,G]);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:Mo[oe]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(ze,{children:t.id}),e.jsx(ze,{color:Ao[oe],children:p.indexType[oe]})]})}),e.jsx(le,{title:p.section.basicInfo,onSave:i,onAskAI:s?()=>s("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ie,{label:ie?p.editor.workTitle:xe?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:_=>U("title",_)}),ae&&e.jsx(Ie,{label:p.editor.belongsToWork,value:t.workName||"",onChange:_=>U("workName",_)}),e.jsx(q,{label:p.editor.authorLabel,value:t.author||"",onChange:_=>U("author",_)}),e.jsx(q,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:_=>U("dynasty",_)}),(ae||xe)&&e.jsx(Ie,{label:p.editor.containedIn,value:t.collection||"",onChange:_=>U("collection",_)}),(ae||xe)&&e.jsx(q,{label:p.editor.holderLabel,value:t.holder||"",onChange:_=>U("holder",_)}),(ae||xe)&&e.jsx(q,{label:ae?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:_=>U("pages",_)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(q,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:_=>U("firstImage",_)})})]})}),e.jsx(le,{title:p.section.description,onSave:i,onAskAI:s?()=>s("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:_=>U("description",_),placeholder:p.editor.descriptionPlaceholder})}),(((we=t.additional_works)==null?void 0:we.length)||0)>0&&e.jsx(le,{title:p.section.additionalWorks,onSave:i,children:e.jsx(Fo,{items:t.additional_works||[],onChange:_=>U("additional_works",_)})}),e.jsx(le,{title:p.section.indexedBy,onSave:i,onAskAI:s?()=>s("收录于"):void 0,children:e.jsx(Do,{items:t.indexed_by||[],onChange:_=>U("indexed_by",_)})}),e.jsx(le,{title:p.section.textResources,onSave:i,onAskAI:s?()=>s("资源"):void 0,children:e.jsx(We,{items:t.resources||[],onChange:_=>U("resources",_),onDownload:u,downloadStatuses:g,filterType:"text"})}),e.jsx(le,{title:p.section.imageResources,onSave:i,children:e.jsx(We,{items:t.resources||[],onChange:_=>U("resources",_),onDownload:u,downloadStatuses:g,filterType:"image"})}),e.jsx(le,{title:p.section.sources,onSave:i,onAskAI:s?()=>s("资料来源"):void 0,children:e.jsx(Et,{items:Bt(t.sources||""),onChange:_=>U("sources",Wt(_)),onOpenEntityPicker:Z})}),(ae||xe)&&e.jsx(le,{title:p.section.provenance,onSave:i,onAskAI:s?()=>s("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:_=>U("provenance",_),placeholder:p.editor.provenancePlaceholder})}),ae&&e.jsx(le,{title:p.section.otherEditions,onSave:i,onAskAI:s?()=>s("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:_=>U("otherEditions",_),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(Pt,{entityType:oe,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:he,onUnlinkEntity:ke,onViewEntity:Te,onCreateAndLink:$,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:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.editor.dangerZoneDesc}),e.jsx("button",{onClick: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:p.editor.deleteEntity})]}),e.jsx(At,{isOpen:v,entityType:h,title:j,onSelect:J,onCancel:()=>S(!1),onCreate:()=>{S(!1),$(b,h)},searchResults:C,onSearch:Y,isLoading:m,excludeId:t.id}),e.jsx(Mt,{isOpen:I,entityType:B,relationField:W,inheritData:V,onConfirm:K,onCancel:()=>P(!1)}),e.jsx(Dt,{isOpen:L,title:p.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:Oe,onCancel:()=>{N(!1),M(null)},onSearch:D})]})};function Fo({items:t,onChange:n}){const i=A(),o=(d,s,a)=>{const u=t.map((g,x)=>x===d?{...g,[s]:a}:g);n(u)},r=d=>n(t.filter((s,a)=>a!==d)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((d,s)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(q,{label:i.editor.bookNameLabel,value:d.book_title,onChange:a=>o(s,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(q,{label:i.label.juanCount,value:d.n_juan!=null?String(d.n_juan):"",onChange:a=>o(s,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>r(s),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},s)),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:i.action.addAdditionalWork})]})}function Do({items:t,onChange:n}){const i=A(),[o,r]=c.useState(null),l=(a,u,g)=>{const x=t.map((f,p)=>p===a?{...f,[u]:g||void 0}:f);n(x)},d=a=>{n(t.filter((u,g)=>g!==a)),o===a&&r(null)},s=()=>{n([...t,{source:""}]),r(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,u)=>{const g=o===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>r(g?null:u),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:a.source||i.editor.unnamedSource}),a.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),d(u)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&(a.title_info||a.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[a.title_info,a.title_info&&a.author_info&&" — ",a.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(q,{label:i.label.sourceName,value:a.source,onChange:x=>l(u,"source",x)}),e.jsx(q,{label:i.label.sourceBid,value:a.source_bid||"",onChange:x=>l(u,"source_bid",x)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(q,{label:i.label.titleInfo,value:a.title_info||"",onChange:x=>l(u,"title_info",x)}),e.jsx(q,{label:i.label.authorInfo,value:a.author_info||"",onChange:x=>l(u,"author_info",x)})]}),e.jsx(q,{label:i.label.edition,value:a.edition||"",onChange:x=>l(u,"edition",x)}),e.jsx(ue,{value:a.summary||"",onChange:x=>l(u,"summary",x),placeholder:i.editor.summaryPlaceholder}),e.jsx(ue,{value:a.comment||"",onChange:x=>l(u,"comment",x),placeholder:i.editor.commentPlaceholder}),e.jsx(ue,{value:a.additional_comment||"",onChange:x=>l(u,"additional_comment",x),placeholder:i.editor.additionalCommentPlaceholder})]})]},u)}),e.jsx("button",{onClick:s,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:i.action.addIndexedBy})]})}function Ot(t){var s,a,u,g,x,f,p;const n=((a=(s=t.authors)==null?void 0:s[0])==null?void 0:a.name)||"",i=((u=t.publication_info)==null?void 0:u.year)||"",o=((g=t.current_location)==null?void 0:g.name)||"",r=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((f=t.page_count)==null?void 0:f.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:i,holder:o,pages:r,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by};if(t.type==="work"){const v=t;if(Array.isArray(v.related_works)){const S=v.related_works.find(h=>h.relation==="part_of");S&&(d.parentWorkId=S.id,d.parentWorkName=S.title)}}if(t.type==="book"){const v=t;d.workId=v.work_id,Array.isArray(v.contained_in)&&v.contained_in.length>0&&(d.collectionId=(p=v.contained_in[0])==null?void 0:p.id)}return d}function Ho(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};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 Oo=t=>{const{data:n,id:i,transport:o,mode:r="view",onModeChange:l,onChange:d,onSave:s,onDelete:a,onNavigate:u,renderLink:g,onAskAI:x,renderSectionActions:f,onDownloadResource:p,downloadStatuses:v,relations:S,onRelationsChange:h,headerExtra:E,className:b,style:T}=t;A();const[j,w]=c.useState(r),C=l?r:j;c.useEffect(()=>{r!==j&&w(r)},[r]);const y=c.useCallback(()=>{const W=C==="view"?"edit":"view";l?l(W):w(W)},[C,l]),[m,R]=c.useState(null);c.useEffect(()=>{i&&o&&o.getItem(i).then(W=>{W&&R(W)})},[i,o]);const I=n||m,P=c.useMemo(()=>I?Ot(I):null,[I]),B=l||!n?e.jsx("button",{onClick:y,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:C==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:C==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?"切换到编辑模式":"切换到查看模式",children:C==="view"?"✏️ 编辑":"👁 查看"}):null,k=e.jsxs(e.Fragment,{children:[B,E]});return!I&&!P?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"加载中..."}):C==="view"?e.jsx(He,{data:I,transport:o,onNavigate:u?W=>u(W):void 0,renderLink:g,headerExtra:k,className:b,style:T}):P?e.jsxs("div",{className:b,style:T,children:[k&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:k}),e.jsx(Ht,{data:P,onChange:d||(()=>{}),onSave:s||(()=>{}),transport:o,onNavigate:u,showDelete:!!a,onDelete:a,onAskAI:x,renderSectionActions:f,onDownloadResource:p,downloadStatuses:v,relations:S,onRelationsChange:h})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},ut=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Vt=({isOpen:t,onClose:n,onSubmit:i})=>{const[o,r]=c.useState(null),[l,d]=c.useState(""),[s,a]=c.useState("idle"),[u,g]=c.useState(""),x=c.useRef(null);c.useEffect(()=>{t&&(r(null),d(""),a("idle"),g(""))},[t]),c.useEffect(()=>{o&&setTimeout(()=>{var S;return(S=x.current)==null?void 0:S.focus()},100)},[o]),c.useEffect(()=>{if(s==="success"){const S=setTimeout(n,2e3);return()=>clearTimeout(S)}},[s,n]),c.useEffect(()=>{if(!t)return;const S=h=>{h.key==="Escape"&&n()};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[t,n]);const f=async()=>{if(!(!o||!l.trim())){a("submitting"),g("");try{await i({type:o,content:l.trim()}),a("success")}catch(S){a("error"),g(S instanceof Error?S.message:"提交失败,请稍后重试")}}};if(!t)return null;const p=o&&l.trim()&&s!=="submitting",v=ut.find(S=>S.value===o);return e.jsx("div",{style:Vo,onClick:S=>{S.target===S.currentTarget&&n()},children:e.jsxs("div",{style:No,onClick:S=>S.stopPropagation(),children:[e.jsxs("div",{style:Uo,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Yo,"aria-label":"关闭",children:"✕"})]}),s==="success"?e.jsxs("div",{style:Xo,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:ut.map(S=>e.jsxs("button",{onClick:()=>r(S.value),style:{...Go,...o===S.value?Ko:{}},children:[e.jsx("span",{children:S.icon})," ",S.label]},S.value))}),e.jsx("textarea",{ref:x,value:l,onChange:S=>d(S.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!o||s==="submitting",style:{...Jo,opacity:o?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),s==="error"&&e.jsx("div",{style:qo,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:f,disabled:!p,style:{...Zo,opacity:p?1:.6,cursor:p?"pointer":"not-allowed"},children:s==="submitting"?"提交中...":"提交反馈"})})]})]})})},Vo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},No={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)"},Uo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Yo={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Go={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"},Ko={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Jo={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"},Zo={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Xo={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},qo={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Qo=({onSubmit:t,position:n={bottom:24,right:24}})=>{const[i,o]=c.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>o(!0),style:{...ei,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(Vt,{isOpen:i,onClose:()=>o(!1),onSubmit:t})]})},ei={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"},ti={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},ni={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function oi(t){try{const n=new Date(t),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const ii=({items:t,loading:n})=>n?e.jsx("div",{style:gt,children:"加载中..."}):t.length===0?e.jsx("div",{style:gt,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(i=>{const o=ti[i.type],r=ni[i.status];return e.jsxs("div",{style:ri,children:[e.jsxs("div",{style:li,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...ft,background:o.color},children:o.label}),e.jsx("span",{style:{...ft,background:r.color},children:r.label})]}),e.jsx("span",{style:si,children:oi(i.createdAt)})]}),e.jsx("div",{style:ai,children:i.content}),i.reply&&e.jsxs("div",{style:di,children:[e.jsx("div",{style:ci,children:"回复"}),e.jsx("div",{children:i.reply})]})]},i.id)})}),gt={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ri={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},li={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ft={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},si={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ai={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},di={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},ci={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},pi=({style:t})=>{const n=c.useContext(je);if(!n)return null;const{locale:i,setLocale:o}=n,r=i==="zh-Hant",l=()=>o(r?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:r?"切换为简体":"切換為繁體",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:r?"var(--bim-primary, #0078d4)":void 0,fontWeight:r?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:r?void 0:"var(--bim-primary, #0078d4)",fontWeight:r?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.base58Decode=O.base58Decode;exports.base58Encode=O.base58Encode;exports.buildId=O.buildId;exports.decodeIdString=O.decodeIdString;exports.extractIdFromUrl=O.extractIdFromUrl;exports.extractStatus=O.extractStatus;exports.extractType=O.extractType;exports.normalizeCatalog=O.normalizeCatalog;exports.parseId=O.parseId;exports.validateResource=O.validateResource;exports.Badge=ze;exports.CollatedEdition=Lt;exports.CollectionCatalog=wt;exports.CreateEntityDialog=Mt;exports.EntityPickerDialog=Dt;exports.EntitySelector=At;exports.FeedbackButton=Qo;exports.FeedbackDialog=Vt;exports.FeedbackList=ii;exports.FormInput=q;exports.FormTextArea=ue;exports.HomePage=Me;exports.IndexApp=lo;exports.IndexBrowser=Ae;exports.IndexDetail=He;exports.IndexEditor=Ht;exports.IndexView=Oo;exports.LocaleContext=je;exports.LocaleProvider=on;exports.LocaleToggle=pi;exports.ModeIndicator=yt;exports.RelationPanel=Pt;exports.ResourceEditor=We;exports.ResourceList=De;exports.SearchInput=vt;exports.Section=le;exports.SmartBidInput=Ie;exports.SourceEditor=Et;exports.WorkCatalog=so;exports.detailToEditor=Ot;exports.editorToDetail=Ho;exports.formatTemplate=Se;exports.parseSourceString=Bt;exports.stringifySources=Wt;exports.useConvert=F;exports.useT=A;
1
+ "use strict";var Yt=Object.create;var Ve=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,Zt=Object.prototype.hasOwnProperty;var Xt=(t,n,o,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Kt(n))!Zt.call(t,r)&&r!==o&&Ve(t,r,{get:()=>n[r],enumerable:!(i=Gt(n,r))||i.enumerable});return t};var qt=(t,n,o)=>(o=t!=null?Yt(Jt(t)):{},Xt(n||!t||!t.__esModule?Ve(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("./storage-entry-BseF1nPm.cjs"),e=require("react/jsx-runtime"),d=require("react"),je=d.createContext(null),ht={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:"+ 添加收錄來源",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:"📖 著錄於",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉���史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄",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:"圖片資源"}},Qt={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:"+ 添加收录来源",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:"📖 著录于",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录",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:"图片资源"}},en={"zh-Hant":ht,"zh-Hans":Qt},bt="bim-locale";function tn(){try{const t=localStorage.getItem(bt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function nn(t){try{localStorage.setItem(bt,t)}catch{}}const on="zh-Hant",rn=({locale:t,onLocaleChange:n,children:o})=>{const[i,r]=d.useState(t??on),l=t??i;d.useEffect(()=>{if(t)return;const g=tn();g&&g!==i&&r(g)},[]);const[c,s]=d.useState(null);d.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});s(()=>x)}).catch(()=>{s(()=>g=>g)}):s(null)},[l]);const a=d.useCallback(g=>{r(g),nn(g),n==null||n(g)},[n]),u=d.useMemo(()=>({locale:l,setLocale:a,messages:en[l],converter:c}),[l,a,c]);return e.jsx(je.Provider,{value:u,children:o})};function M(){const t=d.useContext(je);return(t==null?void 0:t.messages)??ht}const ln=2e3;function H(){const t=d.useContext(je),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,i=d.useRef(new Map),r=d.useRef(n);r.current!==n&&(i.current.clear(),r.current=n);const l=d.useCallback(c=>{if(!c)return"";if(!o)return c;const s=i.current.get(c);if(s!==void 0)return s;const a=o(c);if(i.current.size>=ln){const u=i.current.keys().next().value;u!==void 0&&i.current.delete(u)}return i.current.set(c,a),a},[o]);return d.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Se(t,n){return t.replace(/\{(\w+)\}/g,(o,i)=>String(n[i]??""))}function sn(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 i=n.split(".");return i.length>=2?i[i.length-2]:n}catch{return""}}function an(){return{id:"",name:"",url:"",type:"text",details:""}}const We=({items:t,onChange:n,onDownload:o,downloadStatuses:i,filterType:r})=>{const l=M(),[c,s]=d.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}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],g=b=>r?r==="text"?b==="text"||b==="text+image":r==="image"?b==="image"||b==="text+image"||b==="physical":b===r:!0,x=t.map((b,z)=>({item:b,originalIndex:z})).filter(({item:b})=>g(b.type)),h=()=>{const b=an();r&&(b.type=r),n([...t,b]),s(t.length)},p=b=>{n(t.filter((z,y)=>y!==b)),s(null)},v=(b,z,y)=>{const T=[...t];if(T[b]={...T[b],[z]:y},z==="url"&&!T[b].id){const C=sn(y);C&&(T[b].id=C)}n(T)},_=(b,z,y)=>{const C={...t[b].metadata||{}};y?C[z]=y:delete C[z],v(b,"metadata",Object.keys(C).length>0?C:void 0)},f=(b,z)=>{const y=z.trim()?z.split(/[,,、]/).map(T=>T.trim()).filter(Boolean):void 0;v(b,"structure",y)},R=(b,z,y)=>{const C=t[b].coverage||{level:1,ranges:""};z==="level"?C.level=parseInt(y)||1:C.ranges=y,v(b,"coverage",C.ranges?C:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:z})=>{var y,T,C,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:()=>s(c===z?null:z),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===z?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:cn(b.type),color:"#fff"},children:((y=a.find(m=>m.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} ${z+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:m=>m.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&b.url&&dn(z,i==null?void 0:i[z],o,l),e.jsx("button",{onClick:m=>{m.stopPropagation(),p(z)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===z&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(b.type==="image"||b.type==="text+image")&&b.url&&pn(b,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:l.label.type}),e.jsx("select",{value:b.type,onChange:m=>v(z,"type",m.target.value),style:{...re,flex:1},children:a.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]}),e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:l.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:m=>v(z,"root_type",m.target.value),style:{...re,flex:1},children:u.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:m=>v(z,"id",m.target.value),placeholder:l.editor.idAutoExtract,style:{...re,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:m=>v(z,"name",m.target.value),placeholder:l.editor.resourceName,style:{...re,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:m=>v(z,"url",m.target.value),placeholder:l.editor.resourceUrl,style:re}),e.jsx("input",{type:"text",value:((T=b.structure)==null?void 0:T.join("、"))||"",onChange:m=>f(z,m.target.value),placeholder:l.editor.structurePlaceholder,style:re}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:be,children:[e.jsx("span",{style:me,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((C=b.coverage)==null?void 0:C.level)??"",onChange:m=>R(z,"level",m.target.value),placeholder:"1",style:{...re,width:"60px"}})]}),e.jsxs("label",{style:{...be,flex:1},children:[e.jsx("span",{style:me,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((S=b.coverage)==null?void 0:S.ranges)||"",onChange:m=>R(z,"ranges",m.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...re,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:m=>v(z,"details",m.target.value),placeholder:l.editor.detailsPlaceholder,style:{...re,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(([m,E])=>{var w;return e.jsxs("label",{style:{...be,gap:"4px"},children:[e.jsx("span",{style:{...me,minWidth:"56px"},children:E}),e.jsx("input",{type:"text",value:((w=b.metadata)==null?void 0:w[m])||"",onChange:B=>_(z,m,B.target.value),placeholder:E,style:{...re,flex:1}})]},m)})})]})]})]})]},z)}),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 cn(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function dn(t,n,o,i){const r=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:c=>{c.stopPropagation(),r||o(t,"")},disabled:r,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":r?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:r?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:r?.6:.9},title:l?i.download.completed:r?`${i.download.downloading} ${(n==null?void 0:n.progress)||0}%`:i.download.downloadThis,children:l?"✓":r?"⏳":"⬇"})}function pn(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:i=>{i.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 re={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"},be={display:"flex",alignItems:"center",gap:"6px"},me={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},xn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function un(t){try{const n=new URL(t).hostname;return xn[n]}catch{return}}const Ne={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},gn=["text","image","text+image","physical"];function fn(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const s=l.match(/^(.+?)[·(](\d+)[)]?$/);return s?[s[1],parseInt(s[2])]:null},o=new Map,i=[],r=new Set;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const s=n(c.name);if(!s)continue;const[a,u]=s,g=`${a}|${c.type}`;o.has(g)||o.set(g,{base:{...c,name:a,url:"",volumes:[]},volumes:[]}),o.get(g).volumes.push({volume:u,url:c.url||void 0,status:"found"}),r.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((c,s)=>c.volume-s.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,i.push(l.base);else for(let c=0;c<t.length;c++)if(r.has(c)){const s=n(t[c].name);s&&`${s[0]}|${t[c].type}`==`${l.base.name}|${l.base.type}`&&r.delete(c)}for(let l=0;l<t.length;l++)r.has(l)||i.push(t[l]);return i}const De=({items:t,groupByType:n=!0})=>{const o=M(),i=d.useMemo(()=>fn(t||[]),[t]),r={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical};if(!i||i.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:i.map((c,s)=>e.jsx(Ye,{item:c},c.id||s))});const l=gn.map(c=>({type:c,items:i.filter(s=>s.type===c)})).filter(c=>c.items.length>0);return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:l.map(({type:c,items:s})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ne[c],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ne[c]}}),r[c],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",s.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:s.map((a,u)=>e.jsx(Ye,{item:a},a.id||u))})]},c))})},Ue=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},mt=({value:t})=>{const o=M().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})},hn=(t,n,o,i)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(mt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const r=String(n);return i?i(r):r};function bn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const r=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function mn(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 yn(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 vn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ye=({item:t})=>{var h;const n=M(),{convert:o}=H(),[i,r]=d.useState(!1),l=d.useMemo(()=>(t.url?un(t.url):void 0)||o(t.name),[t.url,t.name,o]),c=d.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(p=>({...p,url:p.url||yn(p)})),[t.volumes]),s=c&&c.length>0,a=s?c.filter(p=>p.status!=="missing").length:0,u=s?c.length-a:0,g=t.expected_volumes??(s?c.length:0),x=t.color_mode?{...vn[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:Ue(t)||s?"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(mt,{value:t.metadata.check_type}),s&&e.jsxs("button",{onClick:()=>r(!i),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,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:i?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const p=mn(t.metadata);return p?bn(t.url,p):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),Ue(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(([p])=>p!=="check_type").map(([p,v])=>e.jsxs("span",{children:[n.metadata[p]||p,": ",hn(p,v,n,o)]},p)),t.details&&!s&&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]})]}),s&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:c.map(p=>{const v=p.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:p.url&&!v?e.jsx("a",{href:p.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:p.label||`${p.volume}`,children:p.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:v?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1,lineHeight:1.4},children:p.volume})},p.volume)})})]})},yt=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:i,onToggleDraft:r,onConfigurePath:l,onSelectFolder:c})=>{const s=M(),a=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)"},p={onMouseOver:_=>_.currentTarget.style.opacity="0.8",onMouseOut:_=>_.currentTarget.style.opacity="1"},v=e.jsxs("div",{onClick:r,title:u?s.mode.switchToOfficial:s.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[v,e.jsxs("div",{onClick:i,title:s.mode.switchToSync,style:h,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:s.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:c,title:g||s.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[v,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:i,title:s.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:s.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||s.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:i,title:a?s.mode.switchToGithub:s.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?s.mode.localMode:s.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:c,title:g||s.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...p,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:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Te="bim-search-history",Ge=10,Ke=8;function ve(){try{const t=localStorage.getItem(Te);return t?JSON.parse(t):[]}catch{return[]}}function jn(t){try{const n=ve().filter(o=>o!==t);n.unshift(t),n.length>Ge&&(n.length=Ge),localStorage.setItem(Te,JSON.stringify(n))}catch{}}function Sn(t){try{const n=ve().filter(o=>o!==t);localStorage.setItem(Te,JSON.stringify(n))}catch{}}function kn(){try{localStorage.removeItem(Te)}catch{}}const vt=({transport:t,value:n,onChange:o,onSearch:i,onEntrySelect:r,placeholder:l})=>{const c=M(),s=l??c.search.placeholder,a={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection},[u,g]=d.useState(!1),[x,h]=d.useState([]),[p,v]=d.useState(-1),[_,f]=d.useState(null),[R,b]=d.useState(ve),z=d.useRef(null),y=d.useRef(null),T=d.useRef(null);d.useEffect(()=>{if(!t.getAllEntries)return;let j=!1;return t.getAllEntries().then($=>{j||f($)}).catch(()=>{}),()=>{j=!0}},[t]);const C=d.useCallback(j=>{if(!j.trim())return R.map(k=>({type:"history",text:k}));if(!_)return[];const $=j.toLowerCase(),P=[],D=[];for(const k of _){if(P.length+D.length>=Ke*2)break;const L=k.title.toLowerCase();if(L.startsWith($))P.push({type:"entry",text:k.title,entry:k});else if(L.includes($))D.push({type:"entry",text:k.title,entry:k});else if(k.additional_titles){for(const N of k.additional_titles)if(N.toLowerCase().includes($)){P.push({type:"entry",text:`${k.title}`,entry:k});break}}}return[...P,...D].slice(0,Ke)},[_,R]);d.useEffect(()=>{h(C(n)),v(-1)},[n,C]),d.useEffect(()=>{const j=$=>{T.current&&!T.current.contains($.target)&&g(!1)};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[]),d.useEffect(()=>{const j=$=>{var P,D;if($.key==="/"&&document.activeElement!==z.current){const k=(P=document.activeElement)==null?void 0:P.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT")return;$.preventDefault(),(D=z.current)==null||D.focus()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[]);const S=d.useCallback(j=>{j.trim()&&(jn(j.trim()),b(ve())),i(j),g(!1)},[i]),m=d.useCallback(j=>{j.type==="history"?(o(j.text),S(j.text)):j.entry&&(r?(r(j.entry),g(!1)):(o(j.text),S(j.text)))},[o,S,r]),E=d.useCallback(j=>{if(!u||x.length===0){j.key==="Enter"&&S(n);return}switch(j.key){case"ArrowDown":j.preventDefault(),v($=>($+1)%x.length);break;case"ArrowUp":j.preventDefault(),v($=>($-1+x.length)%x.length);break;case"Enter":j.preventDefault(),p>=0&&p<x.length?m(x[p]):S(n);break;case"Escape":j.preventDefault(),g(!1);break}},[u,x,p,n,S,m]),w=d.useCallback((j,$)=>{$.stopPropagation(),Sn(j),b(ve()),h(P=>P.filter(D=>!(D.type==="history"&&D.text===j)))},[]),B=d.useCallback(j=>{j.stopPropagation(),kn(),b([]),h([])},[]);d.useEffect(()=>{if(p>=0&&y.current){const j=y.current.children;j[p]&&j[p].scrollIntoView({block:"nearest"})}},[p]);const W=!n.trim()&&R.length>0;return e.jsxs("div",{ref:T,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:z,type:"text",placeholder:s,value:n,onChange:j=>{o(j.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:E,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),u&&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:[W&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:c.search.history}),e.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),x.map((j,$)=>e.jsxs("div",{onClick:()=>m(j),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:$===p?"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:[a[j.entry.type],j.entry.edition&&` · ${j.entry.edition}`,j.entry.author&&` · ${j.entry.author}`]}),j.type==="history"&&e.jsx("button",{onClick:P=>w(j.text,P),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${j.type}-${j.text}-${$}`))]})]})},Pe="bim-recent-ids",Je="bim-recent-entries",Ze=50,Le=5,wn=50,Cn=200;function $e(){try{const t=localStorage.getItem(Pe);if(t)return JSON.parse(t);const n=localStorage.getItem(Je);if(n){const o=JSON.parse(n).map(i=>i.id);return localStorage.setItem(Pe,JSON.stringify(o)),localStorage.removeItem(Je),o}return[]}catch{return[]}}function In(t){try{const n=$e().filter(o=>o!==t);n.unshift(t),n.length>Ze&&(n.length=Ze),localStorage.setItem(Pe,JSON.stringify(n))}catch{}}const zn={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},Ae=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:i,onNewEntry:r,onSwitchMode:l,onToggleDraft:c,onConfigurePath:s,onSelectFolder:a,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:h})=>{const p=M(),v=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"}],[_,f]=d.useState(g??""),[R,b]=d.useState(null),[z,y]=d.useState(null),[T,C]=d.useState(!1),[S,m]=d.useState(null),[E,w]=d.useState(""),[B,W]=d.useState(!g),[j,$]=d.useState($e),[P,D]=d.useState([]),[k,L]=d.useState(!1),[N,G]=d.useState(!1),[F,ne]=d.useState(null),ee=d.useRef(void 0),oe=d.useRef(!1),ie=d.useCallback(async(A,K)=>{if(!A.trim()){W(!0),b(null),y(null);return}W(!1),C(!0),w("");try{if(t.searchAll){const Y=await t.searchAll(A,K??Le);b(Y)}else{const Y=["work","book","collection"],J=await Promise.all(Y.map(Q=>t.search(A,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(Y){w(Y instanceof Error?Y.message:String(Y)),b(null)}finally{C(!1)}},[t]);d.useEffect(()=>{var Q;let A=!1;const K=["work","book","collection"],Y=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([Y,J]).then(([Z,O])=>{A||ne({works:Z[0].total,books:Z[1].total,collections:Z[2].total,hasText:O==null?void 0:O.hasText,hasImage:O==null?void 0:O.hasImage})}),()=>{A=!0}},[t]),d.useEffect(()=>{oe.current||!(g!=null&&g.trim())||(oe.current=!0,ie(g))},[g,ie]);const xe=d.useCallback(A=>{if(f(A),x==null||x(A),!A.trim()){W(!0),b(null),y(null);return}ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{y(null),ie(A)},Cn)},[ie,x]),ae=d.useCallback(A=>{ee.current&&clearTimeout(ee.current),x==null||x(A),ie(A)},[ie,x]),U=d.useCallback(A=>{y(A),ie(_,wn)},[_,ie]);d.useEffect(()=>{if(!j.length){D([]);return}let A=!1;return L(!0),Promise.all(j.slice(0,10).map(async K=>{var Y,J,Q;try{if(t.getEntry){const O=await t.getEntry(K);if(O)return O}const Z=await t.getItem(K);if(Z){const O=Z.authors;return{id:K,title:Z.title||K,type:Z.type||"work",author:(Y=O==null?void 0:O[0])==null?void 0:Y.name,dynasty:(J=O==null?void 0:O[0])==null?void 0:J.dynasty,role:(Q=O==null?void 0:O[0])==null?void 0:Q.role,edition:Z.edition||void 0}}}catch{}return null})).then(K=>{A||(D(K.filter(Y=>Y!==null)),L(!1))}),()=>{A=!0}},[j,t]);const he=A=>{m(A.id),In(A.id),$($e()),i==null||i(A)},ke=A=>v.find(K=>K.type===A),Re=R&&(R.works.length>0||R.books.length>0||R.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&e.jsx(yt,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:c,onConfigurePath:s,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(vt,{transport:t,value:_,onChange:xe,onSearch:ae,onEntrySelect:he}),r&&e.jsx("button",{onClick:()=>r("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:p.action.newEntry})]}),F&&B&&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:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.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:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.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:p.search.searching}):E?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:E})]}):B?e.jsx("div",{style:{flex:1},children:k?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.loading}):P.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:p.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:P.slice(0,N?10:3).map(A=>e.jsx(Xe,{entry:A,selected:S===A.id,onClick:he,getConfig:ke},A.id))}),!N&&P.length>3&&e.jsx("button",{onClick:()=>G(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:p.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):Re?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:v.map(({type:A,icon:K,name:Y,key:J})=>{const Q=R[J],Z=zn[J],O=R[Z];if(Q.length===0)return null;const we=!(z===A)&&O>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," ",Y,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[O," ",p.unit.items]})]}),we&&e.jsx("button",{onClick:()=>U(A),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(I=>e.jsx(Xe,{entry:I,selected:S===I.id,onClick:he,getConfig:ke,query:_},I.id))})]},A)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Se(p.search.noResultsFor,{query:_})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},Xe=({entry:t,selected:n,onClick:o,getConfig:i,query:r})=>{const l=M(),{convert:c}=H(),s=r&&t.additional_titles?t.additional_titles.find(a=>a.toLowerCase().includes(r.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:i(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:i(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:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.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:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]})]}),s&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(s)]})]}),e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},_n=["〇","一","二","三","四","五","六","七","八","九"],qe=["","十","百","千"];function jt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let i="",r=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),s=o-1-l;c===0?r=!0:(r&&i&&(i+="〇"),r=!1,c===1&&s===1&&l===0?i+=qe[s]:i+=_n[c]+qe[s])}return i}function St({type:t}){const n=M(),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 Tn({isDraft:t}){const n=M();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function Rn({id:t}){const n=M(),[o,i]=d.useState(!1),r=()=>{navigator.clipboard.writeText(t).then(()=>{i(!0),setTimeout(()=>i(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px 3px 10px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"12px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:r,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"13px",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 te({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 kt({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((i,r)=>e.jsxs("span",{children:[r>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",o(i.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:o(i.name)}),i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",o(i.role)]})]},r))})}function pe({id:t,label:n,onNavigate:o,renderLink:i}){return i?e.jsx(e.Fragment,{children:i(t,n)}):o?e.jsx("a",{href:`/${t}`,onClick:r=>{r.metaKey||r.ctrlKey||(r.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:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Ln({id:t,title:n,edition:o,type:i,isDraft:r,authors:l,volumeText:c,meta:s,headerExtra:a}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[e.jsxs("h1",{style:{fontSize:"24px",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",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}),c&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexShrink:0,paddingTop:"4px"},children:[e.jsx(St,{type:i}),e.jsx(Tn,{isDraft:r}),e.jsx(Rn,{id:t}),a]})]}),((l==null?void 0:l.length)||s.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(kt,{authors:l,type:i}),s]})]})}function En({items:t,onNavigate:n,renderLink:o}){const i=M(),{convert:r}=H();if(!t.length)return null;const[l,c]=d.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(te,{children:i.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((s,a)=>{const u=l===a;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(u?null:a),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:r(s.source)}),!u&&s.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r(s.title_info)}),s.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(pe,{id:s.source_bid,label:i.action.view,onNavigate:n,renderLink:o})})]}),u&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(s.title_info||s.author_info||s.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[s.title_info&&e.jsx(se,{label:i.label.titleInfo,children:r(s.title_info)}),s.author_info&&e.jsx(se,{label:i.label.authorInfo,children:r(s.author_info)}),s.edition&&e.jsx(se,{label:i.label.edition,children:r(s.edition)})]}),s.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:r(s.summary)})]}),s.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:r(s.comment)})]}),s.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:r(s.additional_comment)})]})]})]},a)})})]})}function Bn({items:t}){const n=M(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.aliases}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((i,r)=>e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},r))})]}):null}function Wn({items:t}){const n=M(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((i,r)=>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(i.book_title),"》",i.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[i.n_juan,n.unit.juan]})]},r))})]}):null}function Pn({items:t}){const n=M(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{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((i,r)=>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(i.name)}),i.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(i.description)})]},r))]})]}):null}function $n({items:t}){const n=M(),{convert:o}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((i,r)=>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(i)]},r))})]}):null}function Qe({title:t,ids:n,transport:o,onNavigate:i,renderLink:r}){const{convert:l}=H(),[c,s]=d.useState([]);return d.useEffect(()=>{if(!n.length){s([]);return}if(!o){s(n.map(u=>({id:u})));return}let a=!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=>{a||s(u)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(te,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(c.length?c:n.map(a=>({id:a}))).map(a=>{const u=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(pe,{id:a.id,label:u,onNavigate:i,renderLink:r})},a.id)})})]}):null}function An({book:t,onNavigate:n,renderLink:o}){const i=M(),{convert:r}=H(),[l,c]=d.useState(!1),s=t.resources&&t.resources.length>0,a=t.edition?`${r(t.title)||t.id}(${r(t.edition)})`:r(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:s&&!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(pe,{id:t.id,label:a,onNavigate:n,renderLink:o})}),s&&e.jsx("span",{onClick:()=>c(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?i.action.expand:i.action.collapse,children:"▼"})]}),s&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(De,{items:t.resources,groupByType:!0})})]})}function Mn({ids:t,transport:n,onNavigate:o,renderLink:i}){const r=M(),[l,c]=d.useState([]);return d.useEffect(()=>{if(!t.length){c([]);return}if(!n){c(t.map(a=>({id:a})));return}let s=!1;return Promise.all(t.map(a=>n.getItem(a).then(u=>({id:a,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:a})))).then(a=>{s||c(a)}),()=>{s=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(te,{children:[r.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(s=>({id:s}))).map(s=>e.jsx(An,{book:s,onNavigate:o,renderLink:i},s.id))})]}):null}function Fn({workData:t,onNavigate:n,renderLink:o}){var l,c,s;const i=M(),{convert:r}=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(St,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(pe,{id:t.id,label:r(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:[jt(t.juan_count.number),i.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(kt,{authors:t.authors,type:"work"}),((c=t.description)==null?void 0:c.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(s=t.authors)!=null&&s.length?"8px 0 0":"0",textAlign:"justify"},children:r(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(se,{label:i.label.parentWork,children:e.jsx(pe,{id:t.parent_work.id,label:r(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Dn({items:t,onNavigate:n,renderLink:o}){const i=M(),{convert:r}=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:i.indexType.collection}),e.jsx(pe,{id:l.id,label:r(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:Se(i.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const He=({data:t,id:n,transport:o,onNavigate:i,renderLink:r,headerExtra:l,className:c,style:s})=>{var B,W,j,$,P,D;const a=M(),{convert:u}=H(),[g,x]=d.useState(null),[h,p]=d.useState(!1),[v,_]=d.useState(null),[f,R]=d.useState(null),[b,z]=d.useState([]),y=t||g;if(d.useEffect(()=>{if(t||!n||!o)return;let k=!1;return p(!0),_(null),o.getItem(n).then(L=>{k||(L?x(L):_(a.misc.notFoundEntry))}).catch(L=>{k||_(L instanceof Error?L.message:a.misc.loadFailed)}).finally(()=>{k||p(!1)}),()=>{k=!0}},[t,n,o]),d.useEffect(()=>{if(!y||!o){R(null),z([]);return}let k=!1;const L=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(L?o.getItem(L).then(N=>{!k&&N&&N.type==="work"&&R(N)}).catch(()=>{}):R(null),y.type==="book"){const N=y;N.contained_in&&N.contained_in.length>0?Promise.all(N.contained_in.map(G=>{const F=typeof G=="string"?G:G.id,ne=typeof G=="string"?void 0:G.volume_index;return o.getItem(F).then(ee=>({id:F,title:ee&&ee.title||F,volume_index:ne})).catch(()=>({id:F,title:F,volume_index:ne}))})).then(G=>{k||z(G)}):z([])}else z([]);return()=>{k=!0}},[y,o]),h)return e.jsx("div",{className:c,style:{...s,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(v)return e.jsx("div",{className:c,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!y)return null;const T=y.type==="book"?y:null,C=y.type==="collection"?y:null,S=y.type==="work"?y:null;let m=!1;try{m=V.extractStatus(y.id)==="draft"}catch{}let E="";(B=y.juan_count)!=null&&B.number?E=jt(y.juan_count.number)+a.unit.juan:(W=y.juan_count)!=null&&W.description&&(E=u(y.juan_count.description));const w=[];return(j=y.publication_info)!=null&&j.year&&w.push(e.jsx(se,{label:a.label.year,children:y.publication_info.year},"year")),($=y.current_location)!=null&&$.name&&w.push(e.jsx(se,{label:a.label.currentLocation,children:u(y.current_location.name)},"loc")),(P=y.page_count)!=null&&P.description&&w.push(e.jsx(se,{label:a.label.pageCount,children:y.page_count.description},"page")),T!=null&&T.edition&&w.push(e.jsx(se,{label:a.label.edition,children:u(T.edition)},"ver")),S!=null&&S.parent_work&&w.push(e.jsx(se,{label:a.label.parentWork,children:e.jsx(pe,{id:S.parent_work.id,label:u(S.parent_work.title),onNavigate:i,renderLink:r})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&w.push(e.jsx(se,{label:a.label.parentWork,children:S.parent_works.map((k,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(pe,{id:k,onNavigate:i,renderLink:r})]},k))},"pws")),e.jsxs("div",{className:c,style:s,children:[e.jsx(Ln,{id:y.id,title:u(y.title),edition:y.edition?u(y.edition):void 0,type:y.type,isDraft:m,authors:y.authors,volumeText:E,meta:w,headerExtra:l}),((D=y.description)==null?void 0:D.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(y.description.text)}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:a.section.containedIn}),e.jsx(Dn,{items:b,onNavigate:i,renderLink:r})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:a.section.belongsToWork}),e.jsx(Fn,{workData:f,onNavigate:i,renderLink:r})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(Wn,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(Bn,{items:y.additional_titles}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(En,{items:y.indexed_by,onNavigate:i,renderLink:r}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:a.section.resources}),e.jsx(De,{items:y.resources,groupByType:!0})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&e.jsx(Pn,{items:T.location_history}),(C==null?void 0:C.history)&&C.history.length>0&&e.jsx($n,{items:C.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&e.jsx(Qe,{title:a.section.relatedVersions,ids:T.related_books,transport:o,onNavigate:i,renderLink:r}),(C==null?void 0:C.books)&&C.books.length>0&&e.jsx(Qe,{title:a.section.containedBooks,ids:C.books,transport:o,onNavigate:i,renderLink:r}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Mn,{ids:S.books,transport:o,onNavigate:i,renderLink:r}),(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"),G=S.related_works.filter(F=>!F.relation);return L.length>0&&k.push({label:a.section.belongsToWork,items:L}),N.length>0&&k.push({label:a.section.containedWorks,items:N}),G.length>0&&k.push({label:a.section.relatedWorks,items:G}),k.map(F=>e.jsxs("div",{children:[e.jsxs(te,{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(ne=>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(pe,{id:ne.id,label:u(ne.title),onNavigate:i,renderLink:r})},ne.id))})]},F.label))})()]})};function Hn({data:t}){const n=M(),{convert:o}=H(),{stats:i}=t,r=i.processed_volumes??i.total_found_volumes,l=r!=null&&t.total_volumes>0?Math.round(r/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:r})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.total_books})," ",n.unit.bu]}),i.matched_works!=null&&i.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.matched_works})," ",n.unit.bu]}),i.unmatched_works!=null&&i.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:i.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 On({sections:t,activeSection:n,onSelect:o}){const i=M();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:et(n===null),children:i.catalog.all}),t.map(r=>e.jsxs("button",{onClick:()=>o(r.name),style:et(n===r.name),children:[r.name,r.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[r.volume_range[0],"–",r.volume_range[1]]})]},r.name))]})}function et(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 Vn({id:t,label:n,onNavigate:o,renderLink:i}){return i?e.jsx(e.Fragment,{children:i(t,n)}):o?e.jsx("a",{href:`/${t}`,onClick:r=>{r.metaKey||r.ctrlKey||(r.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:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Nn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],i=t[t.length-1];return i-o+1===t.length?`${o}–${i}`:t.length<=3?t.join(", "):`${o}–${i} (${t.length}${n})`}function tt({book:t,onNavigate:n,renderLink:o,showVolumes:i}){const r=M(),{convert:l}=H(),c=t.book_id||t.work_id,s=i&&t.volumes.length>0?Nn(t.volumes,r.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:[i&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:s}),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:a?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,r.unit.volume]}),c&&e.jsx(Vn,{id:c,label:t.book_id?r.indexType.book:r.indexType.work,onNavigate:n,renderLink:o}),!c&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:r.catalog.unmatched_label})]})}const wt=({data:t,collectionId:n,transport:o,onNavigate:i,renderLink:r,className:l,style:c})=>{const s=M(),[a,u]=d.useState(null),[g,x]=d.useState(!1),[h,p]=d.useState(null),[v,_]=d.useState(null),[f,R]=d.useState(""),b=t||a;d.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),p(null),o.getCollectionCatalog(n).then(m=>{S||(m?u(m):p(s.catalog.notFound))}).catch(m=>{S||p(m instanceof Error?m.message:s.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,s]);const z=(b==null?void 0:b.sections)&&b.sections.length>0,y=d.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const S=b.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[b]),T=d.useMemo(()=>{if(!b)return[];let S=b.books;if(v&&(S=S.filter(m=>m.section===v)),f.trim()){const m=f.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(m)||E.sub_items&&E.sub_items.some(w=>w.toLowerCase().includes(m))||E.edition&&E.edition.toLowerCase().includes(m))}return S},[b,v,f]),C=d.useMemo(()=>{if(!y)return null;const S=[],m=new Map;for(const w of T){if(!w.volumes||w.volumes.length===0)continue;const B=w.volumes[0];m.has(B)||m.set(B,[]),m.get(B).push(w)}const E=[...m.keys()].sort((w,B)=>w-B);for(const w of E)S.push({volume:w,books:m.get(w)});return S},[T,y]);return g?e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:s.catalog.loading})}):h?e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):b?e.jsxs("div",{className:l,style:c,children:[e.jsx(Hn,{data:b}),z&&e.jsx(On,{sections:b.sections,activeSection:v,onSelect:_}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:s.search.searchBookName,value:f,onChange:S=>R(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," ",s.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[C?C.map((S,m)=>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:Se(s.catalog.volume,{n:S.volume})}),S.books.map((E,w)=>e.jsx(tt,{book:E,onNavigate:i,renderLink:r,showVolumes:E.volumes.length>1},`${S.volume}-${w}`))]},`${S.volume}-${m}`)):T.map((S,m)=>e.jsx(tt,{book:S,onNavigate:i,renderLink:r,showVolumes:!0},m)),T.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:s.catalog.noMatch})]})]}):null},Un=["〇","一","二","三","四","五","六","七","八","九"],nt=["","十","百","千"],Yn=["","萬","億"];function Ct(t){if(t===0)return"〇";if(t<0)return`負${Ct(-t)}`;const n=[];let o=t,i=0;for(;o>0;){const r=o%1e4;r>0?n.unshift(Gn(r,i>0)+Yn[i]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),i++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Gn(t,n){const o=[];let i=t;for(;i>0;)o.unshift(i%10),i=Math.floor(i/10);let r="";for(let l=0;l<o.length;l++){const c=o[l],s=o.length-1-l;c===0?r&&!r.endsWith("〇")&&(r+="〇"):c===1&&s===1&&l===0&&!n?r+=nt[s]:r+=Un[c]+nt[s]}return r.replace(/〇$/,"")}const It={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Kn(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 zt({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:Kn(t)})}function _t(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(i=>_t(i,n)))}function Tt(t){var i;const n=t.files.length,o=((i=t.children)==null?void 0:i.reduce((r,l)=>r+Tt(l),0))||0;return n+o}function Rt({group:t,activeFile:n,onSelect:o,depth:i=0}){var u;const r=_t(t,n||""),[l,c]=d.useState(r),s=Tt(t),a=!!((u=t.children)!=null&&u.length);return d.useEffect(()=>{r&&c(!0)},[r]),e.jsxs("div",{style:{marginBottom:i===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"6px",padding:i===0?"4px 8px":"2px 8px",paddingLeft:`${8+i*16}px`,cursor:"pointer",userSelect:"none",fontSize:i===0?"13px":"12px",fontWeight:i===0?600:500,color:r?"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:["(",s,")"]})]}),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+i*16}px`},children:t.files.map(g=>e.jsx(zt,{file:g,isActive:n===g,onSelect:o},g))}),a&&t.children.map((g,x)=>e.jsx(Rt,{group:g,activeFile:n,onSelect:o,depth:i+1},x))]})]})}function Jn({files:t,groups:n,activeFile:o,onSelect:i}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((r,l)=>e.jsx(Rt,{group:r,activeFile:o,onSelect:i},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(r=>e.jsx(zt,{file:r,isActive:o===r,onSelect:i},r))})}function Zn({type:t}){const n=It[t]||"#717171";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Xn({section:t,onNavigate:n}){const{convert:o}=H(),[i,r]=d.useState(!1),l=!!t.summary,c=!!t.comment,s=!!t.additional_comment,a=l||c||s;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>a&&r(!i),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:a?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[a&&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("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:[Ct(t.n_juan),"卷"]})]}),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:`/${t.work_id}`,onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),i&&a&&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 qn({section:t}){const{convert:n}=H(),[o,i]=d.useState(!1),r=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>r&&i(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:r?"pointer":"default",userSelect:"none"},children:[e.jsx(Zn,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),r&&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&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${It[t.type]||"#717171"}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:n(t.content)})})]})}function Qn({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 eo({juan:t,searchQuery:n,onNavigate:o}){const{convert:i}=H(),r=d.useMemo(()=>{if(!n.trim())return t.sections;const c=n.trim().toLowerCase();return t.sections.filter(s=>{var a,u,g,x,h;return((a=s.title)==null?void 0:a.toLowerCase().includes(c))||((u=s.book_title)==null?void 0:u.toLowerCase().includes(c))||((g=s.author)==null?void 0:g.toLowerCase().includes(c))||((x=s.author_info)==null?void 0:x.toLowerCase().includes(c))||((h=s.summary)==null?void 0:h.toLowerCase().includes(c))})},[t.sections,n]),l=r.filter(c=>c.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:i(t.title)}),t.source_url&&e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:"原文 ↗"}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[l," 部书"]})]}),r.map((c,s)=>c.type==="书"?e.jsx(Xn,{section:c,onNavigate:o},s):c.type==="部"||c.type==="类"?e.jsx(qn,{section:c},s):e.jsx(Qn,{section:c},s)),r.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const Lt=({index:t,workId:n,transport:o,onNavigate:i,activeJuan:r,onJuanChange:l,className:c,style:s})=>{const[a,u]=d.useState(null),[g,x]=d.useState(!1),[h,p]=d.useState(null),[v,_]=d.useState(null),[f,R]=d.useState(null),[b,z]=d.useState(!1),[y,T]=d.useState(""),C=r??v,S=d.useCallback(W=>{_(W),l==null||l(W)},[l]),m=t||a;d.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let W=!1;return x(!0),p(null),o.getCollatedEditionIndex(n).then(j=>{W||(j?(u(j),!r&&j.juan_files.length>0&&S(j.juan_files[0])):p("未找到整理本数据"))}).catch(j=>{W||p(j instanceof Error?j.message:"加载失败")}).finally(()=>{W||x(!1)}),()=>{W=!0}},[t,n,o,r,S]),d.useEffect(()=>{const W=t||a;W&&W.juan_files&&W.juan_files.length>0&&!C&&S(W.juan_files[0])},[t,a,C,S]);const E=n||(m==null?void 0:m.work_id),w=d.useCallback(async W=>{if(!(!E||!(o!=null&&o.getCollatedJuan))){z(!0),R(null);try{const j=await o.getCollatedJuan(E,W);R(j)}catch{R(null)}finally{z(!1)}}},[E,o]);d.useEffect(()=>{C&&w(C)},[C,w]);const B=W=>{S(W),T("")};return g?e.jsx("div",{className:c,style:{...s,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):h?e.jsx("div",{className:c,style:{...s,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:c,style:s,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:m.total_juan})," 卷"]})}),e.jsx(Jn,{files:m.juan_files,groups:m.juan_groups,activeFile:C,onSelect:B}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:y,onChange:W=>T(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("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载中..."}):f?e.jsx(eo,{juan:f,searchQuery:y,onNavigate:i}):C?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null]}):null},to={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},no={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function oo(t){try{const n=new Date(t),o=i=>String(i).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const Et=({items:t,loading:n})=>n?e.jsx("div",{style:ot,children:"加载中..."}):t.length===0?e.jsx("div",{style:ot,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const i=to[o.type],r=no[o.status];return e.jsxs("div",{style:io,children:[e.jsxs("div",{style:ro,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...it,background:i.color},children:i.label}),e.jsx("span",{style:{...it,background:r.color},children:r.label})]}),e.jsx("span",{style:lo,children:oo(o.createdAt)})]}),e.jsx("div",{style:so,children:o.content}),o.reply&&e.jsxs("div",{style:ao,children:[e.jsx("div",{style:co,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})}),ot={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},io={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},ro={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},it={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},lo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},so={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},ao={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},co={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},po=[{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:"經典作品"}],Me=({transport:t,onNavigate:n,recommendedIds:o,activeTab:i,onTabChange:r,feedbackApiUrl:l})=>{const c=M(),[s,a]=d.useState(null),[u,g]=d.useState([]),[x,h]=d.useState("recommend"),[p,v]=d.useState([]),[_,f]=d.useState(!1),R=i??x,b=w=>{h(w),r==null||r(w)},[z,y]=d.useState(!0),[T,C]=d.useState(null),[S,m]=d.useState(null);d.useEffect(()=>{if(!t.getAllEntries)return;let w=!1;return t.getAllEntries().then(B=>{if(w)return;const W=B.filter(P=>P.type==="work").length,j=B.filter(P=>P.type==="book").length,$=B.filter(P=>P.type==="collection").length;a({works:W,books:j,collections:$})}).catch(()=>{}),()=>{w=!0}},[t]),d.useEffect(()=>{let w=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const W=await t.getRecommended();if(W!=null&&W.groups)return W.groups.flatMap(j=>j.items.map($=>({...$,group:j.name})))}catch{}return po})().then(async W=>{if(w)return;const j=W.filter(P=>P.id);if(j.length===0){y(!1);return}const $=await Promise.all(j.map(async P=>{try{let D=null;if(t.getEntry)D=await t.getEntry(P.id);else{const k=await t.getItem(P.id);k&&(D={id:P.id,title:k.title||P.id,type:k.type||"work"})}if(D)return{...D,group:P.group,fallbackDescription:P.description}}catch{}return{id:P.id,title:P.title,type:P.id.startsWith("FC")?"collection":"work",group:P.group,fallbackDescription:P.description}}));w||(g($.filter(P=>P!==null)),y(!1))}),()=>{w=!0}},[t,o]),d.useEffect(()=>{if(!t.getResourceProgress)return;let w=!1;return t.getResourceProgress().then(B=>{w||C(B)}).catch(()=>{}),()=>{w=!0}},[t]),d.useEffect(()=>{if(!t.getSiteProgress)return;let w=!1;return t.getSiteProgress().then(B=>{w||m(B)}).catch(()=>{}),()=>{w=!0}},[t]),d.useEffect(()=>{if(!l||R!=="feedback")return;let w=!1;return f(!0),fetch(l).then(B=>B.json()).then(B=>{!w&&B.success&&v(B.items||[])}).catch(()=>{}).finally(()=>{w||f(!1)}),()=>{w=!0}},[l,R]);const E=w=>{switch(w){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(Ce,{label:c.home.recommendTab,active:R==="recommend",onClick:()=>b("recommend")}),e.jsx(Ce,{label:c.home.catalogTab,active:R==="catalog",onClick:()=>b("catalog")}),e.jsx(Ce,{label:c.home.siteTab,active:R==="site",onClick:()=>b("site")}),l&&e.jsx(Ce,{label:c.home.feedbackTab,active:R==="feedback",onClick:()=>b("feedback")})]}),R==="recommend"&&e.jsx(xo,{recommended:u,loading:z,onNavigate:n,getIcon:E,t:c}),R==="catalog"&&e.jsx(uo,{progress:T,t:c,onNavigate:n}),R==="site"&&e.jsx(fo,{progress:S,t:c,totalWorks:(s==null?void 0:s.works)??0}),R==="feedback"&&l&&e.jsx(Et,{items:p,loading:_})]})})},Ce=({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}),xo=({recommended:t,loading:n,onNavigate:o,getIcon:i,t:r})=>{if(n)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});if(t.length===0)return null;const l=new Map;for(const c of t){const s=c.group||r.home.recommendedBrowse;l.has(s)||l.set(s,[]),l.get(s).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,s])=>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:s.map(a=>{const u=a.dynasty||a.author?`${a.dynasty?`〔${a.dynasty}〕`:""}${a.author||""}`:a.fallbackDescription;return e.jsxs("a",{href:`/${a.id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),o==null||o(a.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:i(a.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a.title,a.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:a.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},a.id)})})]},c))})},uo=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const i=[...t.resources].sort((s,a)=>s.priority-a.priority),r=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:r.map(s=>{const a=i.filter(u=>u.status===s);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[s]}}),l[s]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(u=>e.jsx(go,{item:u,t:n,statusColor:c[s],onNavigate:o},u.id))})]},s)})})},go=({item:t,t:n,statusColor:o,onNavigate:i})=>{const r=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,s=t.collection_id||t.work_id;return s&&i?e.jsx("a",{href:`/${s}`,onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i(s))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Se(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:`${r}%`,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})]})},fo=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"..."});const i=[...t.resources].sort((a,u)=>a.priority-u.priority),r=i.filter(a=>a.imported>0),l=i.filter(a=>a.imported===0),c=r.reduce((a,u)=>Math.max(a,u.imported),0),s=o>0?Math.round(c/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:c.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",s,"%)"]}),r.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," (",r.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map(a=>e.jsx(rt,{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(rt,{item:a,t:n,totalWorks:o},a.id))})]})]})},rt=({item:t,t:n,totalWorks:o})=>{const i=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} (${i}%)`: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:`${i}%`,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})]})},lt="(max-width: 768px)";function ho(){const[t,n]=d.useState(()=>typeof window>"u"?!1:window.matchMedia(lt).matches);return d.useEffect(()=>{const o=window.matchMedia(lt),i=r=>n(r.matches);return o.addEventListener("change",i),()=>o.removeEventListener("change",i)},[]),t}const bo=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:i,headerRight:r})=>{var D;const l=M(),{convert:c}=H(),s=ho(),[a,u]=d.useState(null),[g,x]=d.useState(null),[h,p]=d.useState(!1),[v,_]=d.useState("detail"),[f,R]=d.useState([]),[b,z]=d.useState(!1),[y,T]=d.useState(null),[C,S]=d.useState(!1),m=d.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]),E=d.useCallback(async k=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){R([]);return}z(!0);try{if(t.getCollectionCatalogs){const L=await t.getCollectionCatalogs(k);R(L||[])}else if(t.getCollectionCatalog){const L=await t.getCollectionCatalog(k);R(L?[{resource_id:"",data:L}]:[])}}catch{R([])}finally{z(!1)}},[t]),w=d.useCallback(async k=>{if(o){o(k);return}u(k),x(null),R([]),T(null),_("detail"),p(!0);try{const L=await t.getItem(k.id);L&&(x(L),L.type==="collection"?E(k.id):L.type==="work"&&L.has_collated&&m(k.id))}catch(L){console.error("加载详情失败:",L)}finally{p(!1)}},[t,o,E,m]),B=d.useCallback(async k=>{x(null),R([]),T(null),_("detail"),p(!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"?E(k):L.type==="work"&&L.has_collated&&m(k))}catch(L){console.error("导航失败:",L)}finally{p(!1)}},[t,E,m]),W=(g==null?void 0:g.type)==="collection"&&(f.length>0||b)||(g==null?void 0:g.type)==="work"&&(y||C),j=s&&(h||g),$=d.useCallback(()=>{u(null),x(null),R([]),T(null),_("detail")},[]),P=e.jsx(e.Fragment,{children:h?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中..."})}):g?e.jsxs(e.Fragment,{children:[(W||r)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:s?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:s?"auto":void 0},children:[W&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>_("detail"),style:Ie(v==="detail"),children:l.detailTab.basicInfo}),g.type==="collection"&&b&&f.length===0&&e.jsxs("button",{onClick:()=>{},style:Ie(!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:()=>_(`catalog:${k.resource_id}`),style:Ie(v===`catalog:${k.resource_id}`),children:k.short_name?`${c(k.short_name)}${l.detailTab.catalogSuffix}`:l.detailTab.collectionCatalog},k.resource_id)),g.type==="work"&&(y||C)&&e.jsxs("button",{onClick:()=>_("collated"),style:Ie(v==="collated"),children:[l.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),r&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:r})]}),e.jsx("div",{style:{padding:s?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:v==="detail"?e.jsx(He,{data:g,transport:t,onNavigate:B}):v.startsWith("catalog:")?e.jsx(wt,{data:(D=f.find(k=>`catalog:${k.resource_id}`===v))==null?void 0:D.data,onNavigate:B}):v==="collated"?e.jsx(Lt,{index:y||void 0,workId:g.id,transport:t,onNavigate:B}):null})]}):e.jsx(Me,{transport:t,onNavigate:B,recommendedIds:i})});return s?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:$,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:P})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ae,{transport:t,onEntryClick:w,hideModeIndicator:n}),!g&&e.jsx(Me,{transport:t,onNavigate:B,recommendedIds:i})]})}):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(Ae,{transport:t,onEntryClick:w,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:P})]})};function Ie(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 mo=({data:t,onNavigate:n,className:o,style:i})=>{var g;const r=M(),{convert:l}=H(),[c,s]=d.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[a,u]=d.useState(null);return e.jsxs("div",{className:o,style:i,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:[r.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",r.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",r.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",r.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(yo,{division:x,expanded:c===x.name,onToggle:()=>s(c===x.name?null:x.name),expandedCat:a,onCatToggle:h=>u(a===h?null:h),onNavigate:n},x.name))})]})},yo=({division:t,expanded:n,onToggle:o,expandedCat:i,onCatToggle:r,onNavigate:l})=>{const{convert:c}=H(),s=t.categories.reduce((a,u)=>{const g=u.stats||{zhulu:0,cunmu:0};return a+(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:c(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",s," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const u=`${t.name}/${a.name}`;return e.jsx(vo,{category:a,expanded:i===u,onToggle:()=>r(u),onNavigate:l},a.name)})})]})},vo=({category:t,expanded:n,onToggle:o,onNavigate:i})=>{var a,u,g,x;const{convert:r}=H(),l=((a=t.books)==null?void 0:a.zhulu)||[],c=((u=t.books)==null?void 0:u.cunmu)||[],s=(((g=t.stats)==null?void 0:g.zhulu)||l.length)+(((x=t.stats)==null?void 0:x.cunmu)||c.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:[r(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:[s," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(st,{label:"著錄",books:l,onNavigate:i}),c.length>0&&e.jsx(st,{label:"存目",books:c,onNavigate:i})]})]})},st=({label:t,books:n,onNavigate:o})=>{const{convert:i}=H(),[r,l]=d.useState(n.length<=20),c=r?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((s,a)=>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:s.work_id&&o?e.jsx("a",{href:`/${s.work_id}`,onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(s.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:i(s.title)}):i(s.title)}),s.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:i(s.volumes)}),s.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:i(s.author).slice(0,20)})]},a))}),!r&&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," 條"]})]})},le=({title:t,onSave:n,onAskAI:o,extraButtons:i,children:r})=>{const l=M();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[i,o&&e.jsx("button",{onClick:o,style:So,children:"AI"}),n&&e.jsx("button",{onClick:n,style:jo,children:l.action.save})]})]}),r]})},jo={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},So={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:i,disabled:r})=>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:i,disabled:r,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 i=d.useRef(null);return d.useEffect(()=>{i.current&&(i.current.style.height="auto",i.current.style.height=`${i.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:i,value:t||"",onChange:r=>n(r.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"}})},_e=({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 ko(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ze=({value:t,onChange:n,label:o})=>{const[i,r]=d.useState(!1),l=d.useRef(null),c=ko(t||"");return d.useEffect(()=>{i&&l.current&&l.current.focus()},[i]),!i&&c?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:at,children:o}),e.jsxs("div",{onClick:()=>r(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:c.name}),e.jsx(_e,{children:c.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:at,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:s=>n(s.target.value),onBlur:()=>r(!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"}})]})},at={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function wo(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Co(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Bt=({items:t,onChange:n,onOpenEntityPicker:o})=>{const i=M(),[r,l]=d.useState(null),c=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},s=x=>{n(t.filter((h,p)=>p!==x)),r===x&&l(null)},a=(x,h,p)=>{const v=[...t];v[x]={...v[x],[h]:p},n(v)},u=(x,h)=>{const p=[...t];p[x]={...p[x],type:h,id:"",name:""},n(p),h==="bookID"&&o&&o(v=>{const _=[...t];_[x]={..._[x],id:v.id,name:v.title,type:"bookID"},n(_)})},g=x=>{o&&o(h=>{const p=[...t];p[x]={...p[x],id:h.id,name:h.title,type:"bookID"},n(p)})};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(r===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:r===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${i.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:wo(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Co(x.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),s(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisSource,children:"✕"})]}),r===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:de,children:i.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:i.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:i.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:de,children:i.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:dt,children:i.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:i.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:i.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:de,children:i.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:dt,children:i.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:p=>a(h,"name",p.target.value),placeholder:i.editor.sourceNamePlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:de,children:i.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:p=>a(h,"id",p.target.value),placeholder:"https://...",style:ge})]})]}),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:{...de,opacity:.7},children:i.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:de,children:i.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:p=>a(h,"details",p.target.value),placeholder:i.editor.detailsPlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:de,children:i.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:p=>a(h,"position",p.target.value),placeholder:"如: 卷三, p.52",style:ge})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:de,children:i.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:p=>a(h,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:de,children:i.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:p=>a(h,"processor_version",p.target.value),placeholder:"如: v0.1",style:ge})]})]})]})]})})]},h)),e.jsxs("button",{onClick:c,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:i.action.addSource})]})]})},de={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ge={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"},dt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Wt(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 Pt(t){return!t||t.length===0?"":JSON.stringify(t)}const $t=({entityType:t,entityId:n,entityTitle:o,parentWork:i,parentCollection:r,belongsToWork:l,belongsToCollection:c,childWorks:s,childCollections:a,containedBooks:u,siblingBooks:g,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:p,onCreateAndLink:v,onSaveRelations:_})=>{const f=M();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:f.section.relations})]}),_&&e.jsx("button",{onClick:_,style:Io,children:f.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{direction:"up",title:f.relation.belongsToWork,entity:l,onView:p,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>v("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(ye,{direction:"up",title:f.relation.containedInCollection,entity:c,onView:p,onUnlink:()=>h("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>v("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(fe,{direction:"horizontal",title:`${f.relation.siblingVersions} (${g.length})`,entities:g,onView:p,onAdd:()=>v("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(ye,{direction:"up",title:f.relation.parentWork,entity:i,onView:p,onUnlink:()=>h("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>v("parentWorkId","work"),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),s&&s.length>0&&e.jsx(fe,{direction:"down",title:`${f.relation.childWorks} (${s.length})`,entities:s,onView:p,onAdd:()=>v("childWork","work",{parentWorkId:n}),addLabel:f.action.addSubWork,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),a&&a.length>0&&e.jsx(fe,{direction:"down",title:`${f.relation.collectionImpl} (${a.length})`,entities:a,onView:p,onAdd:()=>v("childCollection","collection",{workId:n}),addLabel:f.action.addCollectionImpl,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),e.jsx(fe,{direction:"down",title:`${f.relation.allVersions} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:p,onAdd:()=>v("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(ye,{direction:"up",title:f.relation.correspondingWork,entity:l,onView:p,onUnlink:()=>h("workId"),onLink:()=>x("workId","work"),onCreate:()=>v("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(ye,{direction:"up",title:f.relation.parentCollection,entity:r,onView:p,onUnlink:()=>h("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>v("parentCollectionId","collection"),linkLabel:f.action.linkExisting,createLabel:f.action.createAndLink,notLinkedLabel:f.relation.notLinked,viewLabel:f.action.viewEntity,unlinkLabel:f.action.unlink}),e.jsx(fe,{direction:"down",title:`${f.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:p,onAdd:()=>v("childCollection","collection",{parentCollectionId:n}),addLabel:f.action.addSubCollection,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),e.jsx(fe,{direction:"down",title:`${f.relation.containedBooks} (${(u==null?void 0:u.length)??0})`,entities:u||[],onView:p,onAdd:()=>v("childBook","book",{collectionId:n}),addLabel:f.action.addBook,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore})]})]})]})},ye=({direction:t,title:n,entity:o,onView:i,onUnlink:r,onLink:l,onCreate:c,linkLabel:s,createLabel:a,notLinkedLabel:u,viewLabel:g,unlinkLabel:x})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:At(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(pt,{onClick:()=>i(o),title:g,children:"👁️"}),e.jsx(pt,{onClick:r,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(Fe,{onClick:l,children:s}),e.jsx(Fe,{onClick:c,primary:!0,children:a})]})]})},fe=({direction:t,title:n,entities:o,onView:i,onAdd:r,addLabel:l,noneLabel:c,expandMoreLabel:s})=>{const[a,u]=d.useState(!1),g=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: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(p=>e.jsxs("div",{onClick:()=>i(p),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:At(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[s," (",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:c}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Fe,{onClick:r,primary:!0,children:["+ ",l]})})]})},pt=({onClick:t,title:n,danger:o,children:i})=>e.jsx("button",{onClick:r=>{r.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:i}),Fe=({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 At(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Io={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"},Mt=({isOpen:t,entityType:n,title:o,onSelect:i,onCancel:r,onCreate:l,searchResults:c,onSearch:s,isLoading:a,excludeId:u})=>{const[g,x]=d.useState(""),h=u?c.filter(f=>f.id!==u):c;d.useEffect(()=>{t&&(x(""),s(""))},[t]);const p=f=>{x(f),s(f)};if(!t)return null;const v=n==="work"?"作品":n==="book"?"书籍":"丛编",_=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:zo,children:e.jsxs("div",{style:_o,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:r,style:To,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:f=>p(f.target.value),placeholder:`搜索${v}名称或 ID...`,autoFocus:!0,style:Ro})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Ee,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(f=>e.jsxs("div",{onClick:()=>i(f),style:Lo,children:[e.jsx("span",{style:{fontSize:"16px"},children:_}),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:Ee,children:["未找到匹配的",v]}):e.jsxs("div",{style:Ee,children:["输入关键词搜索",v]})}),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:Eo,children:["创建新",v,"并关联"]})]})]})})},zo={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},_o={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)"},To={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Ro={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"},Lo={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ee={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Eo={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},xt={work:"作品",book:"书籍",collection:"丛编"},Bo={work:"📜",book:"📖",collection:"📚"},Ft=({isOpen:t,entityType:n,relationField:o,inheritData:i,onConfirm:r,onCancel:l})=>{const[c,s]=d.useState(""),a=d.useRef(null);d.useEffect(()=>{t&&(s((i==null?void 0:i.title)||""),setTimeout(()=>{var h,p;(h=a.current)==null||h.focus(),(p=a.current)==null||p.select()},100))},[t,i==null?void 0:i.title]);const u=h=>{h.key==="Enter"&&c.trim()?g():h.key==="Escape"&&l()},g=()=>{c.trim()&&r(c.trim(),{...i,title:c.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`创建新${xt[n]}`}};return e.jsx("div",{style:Wo,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:Po,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:Bo[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:c,onChange:h=>s(h.target.value),onKeyDown:u,placeholder:`请输入${xt[n]}名称...`,style:$o})]}),((i==null?void 0:i.author)||(i==null?void 0:i.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:"将继承以下信息:"}),(i==null?void 0:i.author)&&e.jsxs("div",{children:["作者: ",i.author]}),(i==null?void 0:i.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",i.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:Ao,children:"取消"}),e.jsx("button",{onClick:g,disabled:!c.trim(),style:{...Mo,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Wo={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},Po={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)"},$o={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"},Ao={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Mo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Fo(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Dt(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Do(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Ht=({isOpen:t,title:n,filterType:o="all",recentEntities:i=[],excludeId:r,showCreateButton:l=!1,createButtonText:c,onSelect:s,onCancel:a,onCreate:u,onSearch:g})=>{const[x,h]=d.useState(""),[p,v]=d.useState([]),[_,f]=d.useState(!1),[R,b]=d.useState("recent");d.useEffect(()=>{t&&(h(""),v([]),b(i.length>0?"recent":"search"))},[t,i.length]),d.useEffect(()=>{if(!x.trim()){v([]);return}const m=setTimeout(async()=>{f(!0);try{v(await g(x,o))}catch{v([])}finally{f(!1)}},300);return()=>clearTimeout(m)},[x,o,g]);const z=d.useCallback(m=>{h(m.target.value),m.target.value.trim()&&b("search")},[]),y=d.useCallback(m=>r?m.filter(E=>E.id!==r):m,[r]);if(!t)return null;const T=n||(o==="all"?"选择实体":`选择${Dt(o)}`),C=y(i),S=y(p);return e.jsx("div",{style:Oo,children:e.jsxs("div",{style:Vo,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:a,style:No,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:z,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Uo}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),_&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),C.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ut,{active:R==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(ut,{active:R==="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:R==="recent"&&C.length>0?e.jsx(gt,{entities:C,onSelect:s}):x.trim()?_?e.jsx(Be,{message:"搜索中..."}):S.length>0?e.jsx(gt,{entities:S,onSelect:s}):e.jsx(Be,{message:"未找到匹配的结果"}):e.jsx(Be,{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:Yo,children:c||"创建新实体"})]})]})})},ut=({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}),gt=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Ho,{entity:o,onClick:()=>n(o)},o.id))}),Ho=({entity:t,onClick:n})=>{const[o,i]=d.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!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:Fo(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:Do(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Dt(t.type)})]})},Be=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Oo={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},Vo={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)"},No={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Uo={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"},Yo={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Go={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},Ko={work:"📜",collection:"📚",book:"📖"},Ot=({data:t,onChange:n,onSave:o,transport:i,onNavigate:r,showDelete:l,onDelete:c,onAskAI:s,renderSectionActions:a,onDownloadResource:u,downloadStatuses:g,relations:x,onRelationsChange:h})=>{var we;const p=M(),[v,_]=d.useState(!1),[f,R]=d.useState("work"),[b,z]=d.useState(""),[y,T]=d.useState(""),[C,S]=d.useState([]),[m,E]=d.useState(!1),[w,B]=d.useState(!1),[W,j]=d.useState("work"),[$,P]=d.useState(""),[D,k]=d.useState(),[L,N]=d.useState(!1),[G,F]=d.useState(null),[ne,ee]=d.useState([]);d.useRef(null);const oe=t.type,ie=oe==="work",xe=oe==="collection",ae=oe==="book",U=d.useCallback((I,X)=>{n({...t,[I]:X})},[t,n]),he=d.useCallback((I,X)=>{z(I),R(X),T(p.editor.selectToLink+p.indexType[X]),S([]),_(!0)},[p]),ke=d.useCallback(I=>{i!=null&&i.unlinkEntity&&i.unlinkEntity(t.id,I)},[i,t.id]),Re=d.useCallback(I=>{r==null||r(I.id,I.type)},[r]),A=d.useCallback((I,X,ce)=>{const Ut={...ce,author:(ce==null?void 0:ce.author)||t.author,dynasty:(ce==null?void 0:ce.dynasty)||t.dynasty};j(X),P(I),k(Ut),B(!0)},[t.author,t.dynasty]),K=d.useCallback((I,X)=>{i!=null&&i.createAndLink&&i.createAndLink(t.id,$,{type:W,title:I,inheritData:X}),B(!1)},[i,t.id,$,W]),Y=d.useCallback(I=>{if(!I.trim()){S([]);return}E(!0),i!=null&&i.searchEntities&&i.searchEntities(I,f).then(X=>{S(X),E(!1)}).catch(()=>{S([]),E(!1)})},[i,f]),J=d.useCallback(I=>{i!=null&&i.linkEntity&&i.linkEntity(t.id,b,I.id),_(!1)},[i,t.id,b]),Q=d.useCallback(()=>{o()},[o]),Z=d.useCallback(I=>{F(()=>I),N(!0),i!=null&&i.getRecentEntities&&i.getRecentEntities().then(ee).catch(()=>{})},[i]),O=d.useCallback((I,X)=>i!=null&&i.searchEntities?i.searchEntities(I,X==="all"?void 0:X):Promise.resolve([]),[i]),Oe=d.useCallback(I=>{i!=null&&i.addRecentEntity&&i.addRecentEntity(I),ee(X=>[I,...X.filter(ce=>ce.id!==I.id)].slice(0,10)),G==null||G(I),N(!1),F(null)},[i,G]);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:Ko[oe]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(_e,{children:t.id}),e.jsx(_e,{color:Go[oe],children:p.indexType[oe]})]})}),e.jsx(le,{title:p.section.basicInfo,onSave:o,onAskAI:s?()=>s("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(ze,{label:ie?p.editor.workTitle:xe?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:I=>U("title",I)}),ae&&e.jsx(ze,{label:p.editor.belongsToWork,value:t.workName||"",onChange:I=>U("workName",I)}),e.jsx(q,{label:p.editor.authorLabel,value:t.author||"",onChange:I=>U("author",I)}),e.jsx(q,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:I=>U("dynasty",I)}),(ae||xe)&&e.jsx(ze,{label:p.editor.containedIn,value:t.collection||"",onChange:I=>U("collection",I)}),(ae||xe)&&e.jsx(q,{label:p.editor.holderLabel,value:t.holder||"",onChange:I=>U("holder",I)}),(ae||xe)&&e.jsx(q,{label:ae?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:I=>U("pages",I)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(q,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:I=>U("firstImage",I)})})]})}),e.jsx(le,{title:p.section.description,onSave:o,onAskAI:s?()=>s("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:I=>U("description",I),placeholder:p.editor.descriptionPlaceholder})}),(((we=t.additional_works)==null?void 0:we.length)||0)>0&&e.jsx(le,{title:p.section.additionalWorks,onSave:o,children:e.jsx(Jo,{items:t.additional_works||[],onChange:I=>U("additional_works",I)})}),e.jsx(le,{title:p.section.indexedBy,onSave:o,onAskAI:s?()=>s("收录于"):void 0,children:e.jsx(Zo,{items:t.indexed_by||[],onChange:I=>U("indexed_by",I)})}),e.jsx(le,{title:p.section.textResources,onSave:o,onAskAI:s?()=>s("资源"):void 0,children:e.jsx(We,{items:t.resources||[],onChange:I=>U("resources",I),onDownload:u,downloadStatuses:g,filterType:"text"})}),e.jsx(le,{title:p.section.imageResources,onSave:o,children:e.jsx(We,{items:t.resources||[],onChange:I=>U("resources",I),onDownload:u,downloadStatuses:g,filterType:"image"})}),e.jsx(le,{title:p.section.sources,onSave:o,onAskAI:s?()=>s("资料来源"):void 0,children:e.jsx(Bt,{items:Wt(t.sources||""),onChange:I=>U("sources",Pt(I)),onOpenEntityPicker:Z})}),(ae||xe)&&e.jsx(le,{title:p.section.provenance,onSave:o,onAskAI:s?()=>s("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:I=>U("provenance",I),placeholder:p.editor.provenancePlaceholder})}),ae&&e.jsx(le,{title:p.section.otherEditions,onSave:o,onAskAI:s?()=>s("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:I=>U("otherEditions",I),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx($t,{entityType:oe,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:he,onUnlinkEntity:ke,onViewEntity:Re,onCreateAndLink:A,onSaveRelations:Q}),l&&c&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.editor.dangerZoneDesc}),e.jsx("button",{onClick:c,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:p.editor.deleteEntity})]}),e.jsx(Mt,{isOpen:v,entityType:f,title:y,onSelect:J,onCancel:()=>_(!1),onCreate:()=>{_(!1),A(b,f)},searchResults:C,onSearch:Y,isLoading:m,excludeId:t.id}),e.jsx(Ft,{isOpen:w,entityType:W,relationField:$,inheritData:D,onConfirm:K,onCancel:()=>B(!1)}),e.jsx(Ht,{isOpen:L,title:p.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:Oe,onCancel:()=>{N(!1),F(null)},onSearch:O})]})};function Jo({items:t,onChange:n}){const o=M(),i=(c,s,a)=>{const u=t.map((g,x)=>x===c?{...g,[s]:a}:g);n(u)},r=c=>n(t.filter((s,a)=>a!==c)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((c,s)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(q,{label:o.editor.bookNameLabel,value:c.book_title,onChange:a=>i(s,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(q,{label:o.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:a=>i(s,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>r(s),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},s)),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 Zo({items:t,onChange:n}){const o=M(),[i,r]=d.useState(null),l=(a,u,g)=>{const x=t.map((h,p)=>p===a?{...h,[u]:g||void 0}:h);n(x)},c=a=>{n(t.filter((u,g)=>g!==a)),i===a&&r(null)},s=()=>{n([...t,{source:""}]),r(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,u)=>{const g=i===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>r(g?null:u),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:a.source||o.editor.unnamedSource}),a.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),c(u)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&(a.title_info||a.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[a.title_info,a.title_info&&a.author_info&&" — ",a.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(q,{label:o.label.sourceName,value:a.source,onChange:x=>l(u,"source",x)}),e.jsx(q,{label:o.label.sourceBid,value:a.source_bid||"",onChange:x=>l(u,"source_bid",x)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(q,{label:o.label.titleInfo,value:a.title_info||"",onChange:x=>l(u,"title_info",x)}),e.jsx(q,{label:o.label.authorInfo,value:a.author_info||"",onChange:x=>l(u,"author_info",x)})]}),e.jsx(q,{label:o.label.edition,value:a.edition||"",onChange:x=>l(u,"edition",x)}),e.jsx(ue,{value:a.summary||"",onChange:x=>l(u,"summary",x),placeholder:o.editor.summaryPlaceholder}),e.jsx(ue,{value:a.comment||"",onChange:x=>l(u,"comment",x),placeholder:o.editor.commentPlaceholder}),e.jsx(ue,{value:a.additional_comment||"",onChange:x=>l(u,"additional_comment",x),placeholder:o.editor.additionalCommentPlaceholder})]})]},u)}),e.jsx("button",{onClick:s,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addIndexedBy})]})}function Vt(t){var s,a,u,g,x,h,p;const n=((a=(s=t.authors)==null?void 0:s[0])==null?void 0:a.name)||"",o=((u=t.publication_info)==null?void 0:u.year)||"",i=((g=t.current_location)==null?void 0:g.name)||"",r=(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||"",c={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:i,pages:r,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by};if(t.type==="work"){const v=t;if(Array.isArray(v.related_works)){const _=v.related_works.find(f=>f.relation==="part_of");_&&(c.parentWorkId=_.id,c.parentWorkName=_.title)}}if(t.type==="book"){const v=t;c.workId=v.work_id,Array.isArray(v.contained_in)&&v.contained_in.length>0&&(c.collectionId=(p=v.contained_in[0])==null?void 0:p.id)}return c}function Xo(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};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 qo=t=>{const{data:n,id:o,transport:i,mode:r="view",onModeChange:l,onChange:c,onSave:s,onDelete:a,onNavigate:u,renderLink:g,onAskAI:x,renderSectionActions:h,onDownloadResource:p,downloadStatuses:v,relations:_,onRelationsChange:f,headerExtra:R,className:b,style:z}=t;M();const[y,T]=d.useState(r),C=l?r:y;d.useEffect(()=>{r!==y&&T(r)},[r]);const S=d.useCallback(()=>{const $=C==="view"?"edit":"view";l?l($):T($)},[C,l]),[m,E]=d.useState(null);d.useEffect(()=>{o&&i&&i.getItem(o).then($=>{$&&E($)})},[o,i]);const w=n||m,B=d.useMemo(()=>w?Vt(w):null,[w]),W=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:C==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:C==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?"切换到编辑模式":"切换到查看模式",children:C==="view"?"✏️ 编辑":"👁 查看"}):null,j=e.jsxs(e.Fragment,{children:[W,R]});return!w&&!B?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"加载中..."}):C==="view"?e.jsx(He,{data:w,transport:i,onNavigate:u?$=>u($):void 0,renderLink:g,headerExtra:j,className:b,style:z}):B?e.jsxs("div",{className:b,style:z,children:[j&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:j}),e.jsx(Ot,{data:B,onChange:c||(()=>{}),onSave:s||(()=>{}),transport:i,onNavigate:u,showDelete:!!a,onDelete:a,onAskAI:x,renderSectionActions:h,onDownloadResource:p,downloadStatuses:v,relations:_,onRelationsChange:f})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},ft=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Nt=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:i})=>{const[r,l]=d.useState(null),[c,s]=d.useState(""),[a,u]=d.useState("idle"),[g,x]=d.useState(""),h=d.useRef(null);d.useEffect(()=>{t&&(l(null),s(""),u("idle"),x(""))},[t]),d.useEffect(()=>{r&&setTimeout(()=>{var f;return(f=h.current)==null?void 0:f.focus()},100)},[r]),d.useEffect(()=>{if(a==="success"){const f=setTimeout(n,2e3);return()=>clearTimeout(f)}},[a,n]),d.useEffect(()=>{if(!t)return;const f=R=>{R.key==="Escape"&&n()};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t,n]);const p=async()=>{if(!(!r||!c.trim())){u("submitting"),x("");try{await o({type:r,content:c.trim()}),u("success")}catch(f){u("error"),x(f instanceof Error?f.message:"提交失败,请稍后重试")}}};if(!t)return null;const v=r&&c.trim()&&a!=="submitting",_=ft.find(f=>f.value===r);return e.jsx("div",{style:Qo,onClick:f=>{f.target===f.currentTarget&&n()},children:e.jsxs("div",{style:ei,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:ti,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ni,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:si,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),i&&e.jsx("a",{href:i,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:ft.map(f=>e.jsxs("button",{onClick:()=>l(f.value),style:{...oi,...r===f.value?ii:{}},children:[e.jsx("span",{children:f.icon})," ",f.label]},f.value))}),e.jsx("textarea",{ref:h,value:c,onChange:f=>s(f.target.value),placeholder:(_==null?void 0:_.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!r||a==="submitting",style:{...ri,opacity:r?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),a==="error"&&e.jsx("div",{style:ai,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!v,style:{...li,opacity:v?1:.6,cursor:v?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Qo={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ei={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)"},ti={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ni={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},oi={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ii={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ri={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"},li={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},si={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ai={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ci=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[i,r]=d.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>r(!0),style:{...di,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(Nt,{isOpen:i,onClose:()=>r(!1),onSubmit:t,feedbackListUrl:o})]})},di={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"},pi=({style:t})=>{const n=d.useContext(je);if(!n)return null;const{locale:o,setLocale:i}=n,r=o==="zh-Hant",l=()=>i(r?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:r?"切换为简体":"切換為繁體",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:r?"var(--bim-primary, #0078d4)":void 0,fontWeight:r?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:r?void 0:"var(--bim-primary, #0078d4)",fontWeight:r?400:700},children:"简"})]})};exports.BidLink=V.BidLink;exports.BookIndexError=V.BookIndexError;exports.BookIndexManager=V.BookIndexManager;exports.BookIndexStorage=V.BookIndexStorage;exports.BundleStorage=V.BundleStorage;exports.ConfigError=V.ConfigError;exports.GithubStorage=V.GithubStorage;exports.IdGenerationError=V.IdGenerationError;exports.IdGenerator=V.IdGenerator;exports.LocalStorage=V.LocalStorage;exports.MigrationError=V.MigrationError;exports.StorageError=V.StorageError;exports.base58Decode=V.base58Decode;exports.base58Encode=V.base58Encode;exports.buildId=V.buildId;exports.decodeIdString=V.decodeIdString;exports.extractIdFromUrl=V.extractIdFromUrl;exports.extractStatus=V.extractStatus;exports.extractType=V.extractType;exports.normalizeCatalog=V.normalizeCatalog;exports.parseId=V.parseId;exports.validateResource=V.validateResource;exports.Badge=_e;exports.CollatedEdition=Lt;exports.CollectionCatalog=wt;exports.CreateEntityDialog=Ft;exports.EntityPickerDialog=Ht;exports.EntitySelector=Mt;exports.FeedbackButton=ci;exports.FeedbackDialog=Nt;exports.FeedbackList=Et;exports.FormInput=q;exports.FormTextArea=ue;exports.HomePage=Me;exports.IndexApp=bo;exports.IndexBrowser=Ae;exports.IndexDetail=He;exports.IndexEditor=Ot;exports.IndexView=qo;exports.LocaleContext=je;exports.LocaleProvider=rn;exports.LocaleToggle=pi;exports.ModeIndicator=yt;exports.RelationPanel=$t;exports.ResourceEditor=We;exports.ResourceList=De;exports.SearchInput=vt;exports.Section=le;exports.SmartBidInput=ze;exports.SourceEditor=Bt;exports.WorkCatalog=mo;exports.detailToEditor=Vt;exports.editorToDetail=Xo;exports.formatTemplate=Se;exports.parseSourceString=Wt;exports.stringifySources=Pt;exports.useConvert=H;exports.useT=M;