book-index-ui 0.1.21 → 0.1.23
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 +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +771 -756
- package/dist/storage.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Zt=Object.create;var Ve=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,en=Object.prototype.hasOwnProperty;var tn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of qt(n))!en.call(t,i)&&i!==o&&Ve(t,i,{get:()=>n[i],enumerable:!(r=Xt(n,i))||r.enumerable});return t};var nn=(t,n,o)=>(o=t!=null?Zt(Qt(t)):{},tn(n||!t||!t.__esModule?Ve(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-ltSZanAI.cjs"),e=require("react/jsx-runtime"),p=require("react"),je=p.createContext(null),yt={indexType:{work:"作品",book:"書籍",collection:"叢編"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",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:"別名",attachedTexts:"附載篇目",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:"圖片資源"}},on={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:"别名",attachedTexts:"附载篇目",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:"图片资源"}},rn={"zh-Hant":yt,"zh-Hans":on},vt="bim-locale";function ln(){try{const t=localStorage.getItem(vt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function sn(t){try{localStorage.setItem(vt,t)}catch{}}const an="zh-Hant",cn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=p.useState(t??an),l=t??r;p.useEffect(()=>{if(t)return;const g=ln();g&&g!==r&&i(g)},[]);const[c,a]=p.useState(null);p.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const x=g.Converter({from:"tw",to:"cn"});a(()=>x)}).catch(()=>{a(()=>g=>g)}):a(null)},[l]);const s=p.useCallback(g=>{i(g),sn(g),n==null||n(g)},[n]),u=p.useMemo(()=>({locale:l,setLocale:s,messages:rn[l],converter:c}),[l,s,c]);return e.jsx(je.Provider,{value:u,children:o})};function A(){const t=p.useContext(je);return(t==null?void 0:t.messages)??yt}const dn=2e3;function D(){const t=p.useContext(je),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=p.useRef(new Map),i=p.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=p.useCallback(c=>{if(!c)return"";if(!o)return c;const a=r.current.get(c);if(a!==void 0)return a;const s=o(c);if(r.current.size>=dn){const u=r.current.keys().next().value;u!==void 0&&r.current.delete(u)}return r.current.set(c,s),s},[o]);return p.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function Se(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function pn(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function xn(){return{id:"",name:"",url:"",type:"text",details:""}}const We=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=A(),[c,a]=p.useState(null),s=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],u=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],g=b=>i?i==="text"?b==="text"||b==="text+image":i==="image"?b==="image"||b==="text+image"||b==="physical":b===i:!0,x=t.map((b,_)=>({item:b,originalIndex:_})).filter(({item:b})=>g(b.type)),h=()=>{const b=xn();i&&(b.type=i),n([...t,b]),a(t.length)},d=b=>{n(t.filter((_,y)=>y!==b)),a(null)},v=(b,_,y)=>{const T=[...t];if(T[b]={...T[b],[_]:y},_==="url"&&!T[b].id){const C=pn(y);C&&(T[b].id=C)}n(T)},I=(b,_,y)=>{const C={...t[b].metadata||{}};y?C[_]=y:delete C[_],v(b,"metadata",Object.keys(C).length>0?C:void 0)},f=(b,_)=>{const y=_.trim()?_.split(/[,,、]/).map(T=>T.trim()).filter(Boolean):void 0;v(b,"structure",y)},L=(b,_,y)=>{const C=t[b].coverage||{level:1,ranges:""};_==="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:_})=>{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:()=>a(c===_?null:_),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===_?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:un(b.type),color:"#fff"},children:((y=s.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} ${_+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&&gn(_,r==null?void 0:r[_],o,l),e.jsx("button",{onClick:m=>{m.stopPropagation(),d(_)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===_&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(b.type==="image"||b.type==="text+image")&&b.url&&fn(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(_,"type",m.target.value),style:{...ie,flex:1},children:s.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(_,"root_type",m.target.value),style:{...ie,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(_,"id",m.target.value),placeholder:l.editor.idAutoExtract,style:{...ie,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:m=>v(_,"name",m.target.value),placeholder:l.editor.resourceName,style:{...ie,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:m=>v(_,"url",m.target.value),placeholder:l.editor.resourceUrl,style:ie}),e.jsx("input",{type:"text",value:((T=b.structure)==null?void 0:T.join("、"))||"",onChange:m=>f(_,m.target.value),placeholder:l.editor.structurePlaceholder,style:ie}),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=>L(_,"level",m.target.value),placeholder:"1",style:{...ie,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=>L(_,"ranges",m.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ie,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:m=>v(_,"details",m.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ie,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,B])=>{var w;return e.jsxs("label",{style:{...be,gap:"4px"},children:[e.jsx("span",{style:{...me,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((w=b.metadata)==null?void 0:w[m])||"",onChange:W=>I(_,m,W.target.value),placeholder:B,style:{...ie,flex:1}})]},m)})})]})]})]})]},_)}),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 un(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function gn(t,n,o,r){const i=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:c=>{c.stopPropagation(),i||o(t,"")},disabled:i,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:l?r.download.completed:i?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":i?"⏳":"⬇"})}function fn(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ie={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"},hn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function bn(t){try{const n=new URL(t).hostname;return hn[n]}catch{return}}const Ne={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},mn=["text","image","text+image","physical"];function yn(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[s,u]=a,g=`${s}|${c.type}`;o.has(g)||o.set(g,{base:{...c,name:s,url:"",volumes:[]},volumes:[]}),o.get(g).volumes.push({volume:u,url:c.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((c,a)=>c.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let c=0;c<t.length;c++)if(i.has(c)){const a=n(t[c].name);a&&`${a[0]}|${t[c].type}`==`${l.base.name}|${l.base.type}`&&i.delete(c)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const De=({items:t,groupByType:n=!0})=>{const o=A(),r=p.useMemo(()=>yn(t||[]),[t]),i={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical};if(!r||r.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:r.map((c,a)=>e.jsx(Ye,{item:c},c.id||a))});const l=mn.map(c=>({type:c,items:r.filter(a=>a.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:a})=>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]}}),i[c],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",a.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:a.map((s,u)=>e.jsx(Ye,{item:s},s.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},jt=({value:t})=>{const o=A().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},vn=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(jt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function jn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const i=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(i)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(i[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function Sn(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 kn(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 wn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ye=({item:t})=>{var h;const n=A(),{convert:o}=D(),[r,i]=p.useState(!1),l=p.useMemo(()=>(t.url?bn(t.url):void 0)||o(t.name),[t.url,t.name,o]),c=p.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(d=>({...d,url:d.url||kn(d)})),[t.volumes]),a=c&&c.length>0,s=a?c.filter(d=>d.status!=="missing").length:0,u=a?c.length-s:0,g=t.expected_volumes??(a?c.length:0),x=t.color_mode?{...wn[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)||a?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:l}),x&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((h=t.metadata)==null?void 0:h.check_type)&&e.jsx(jt,{value:t.metadata.check_type}),a&&e.jsxs("button",{onClick:()=>i(!r),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[s,"/",g,n.unit.volume,u>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",u]}),e.jsx("span",{style:{marginLeft:"4px"},children:r?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const d=Sn(t.metadata);return d?jn(t.url,d):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),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(([d])=>d!=="check_type").map(([d,v])=>e.jsxs("span",{children:[n.metadata[d]||d,": ",vn(d,v,n,o)]},d)),t.details&&!a&&e.jsx("span",{children:o(t.details)}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),a&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:c.map(d=>{const v=d.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:d.url&&!v?e.jsx("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:d.label||`${d.volume}`,children:d.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:v?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1,lineHeight:1.4},children:d.volume})},d.volume)})})]})},St=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:c})=>{const a=A(),s=t==="local",u=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",x=g?g.split(/[/\\]/).pop()||g:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},d={onMouseOver:I=>I.currentTarget.style.opacity="0.8",onMouseOut:I=>I.currentTarget.style.opacity="1"},v=e.jsxs("div",{onClick:i,title:u?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:u?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:u?"📝":"📚"}),e.jsx("span",{children:u?"draft":"official"})]});return o==="index-browser"?s?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[v,e.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:h,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:c,title:g||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[v,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:x||a.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:s?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:s?"📁":"🌐"}),e.jsx("span",{children:s?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),s&&e.jsxs("div",{onClick:c,title:g||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!s&&x&&e.jsxs("div",{style:{...h,background:"#2196f3",color:"white",cursor:"default"},title:g,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Te="bim-search-history",Ge=10,Ke=8;function ve(){try{const t=localStorage.getItem(Te);return t?JSON.parse(t):[]}catch{return[]}}function Cn(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 In(t){try{const n=ve().filter(o=>o!==t);localStorage.setItem(Te,JSON.stringify(n))}catch{}}function zn(){try{localStorage.removeItem(Te)}catch{}}const kt=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const c=A(),a=l??c.search.placeholder,s={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection},[u,g]=p.useState(!1),[x,h]=p.useState([]),[d,v]=p.useState(-1),[I,f]=p.useState(null),[L,b]=p.useState(ve),_=p.useRef(null),y=p.useRef(null),T=p.useRef(null);p.useEffect(()=>{if(!t.getAllEntries)return;let j=!1;return t.getAllEntries().then(P=>{j||f(P)}).catch(()=>{}),()=>{j=!0}},[t]);const C=p.useCallback(j=>{if(!j.trim())return L.map(k=>({type:"history",text:k}));if(!I)return[];const P=j.toLowerCase(),$=[],H=[];for(const k of I){if($.length+H.length>=Ke*2)break;const E=k.title.toLowerCase();if(E.startsWith(P))$.push({type:"entry",text:k.title,entry:k});else if(E.includes(P))H.push({type:"entry",text:k.title,entry:k});else{const U=[...k.additional_titles||[],...k.attached_texts||[]];for(const V of U){const F=typeof V=="string"?V:V==null?void 0:V.book_title;if(F!=null&&F.toLowerCase().includes(P)){$.push({type:"entry",text:`${k.title}`,entry:k});break}}}}return[...$,...H].slice(0,Ke)},[I,L]);p.useEffect(()=>{h(C(n)),v(-1)},[n,C]),p.useEffect(()=>{const j=P=>{T.current&&!T.current.contains(P.target)&&g(!1)};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[]),p.useEffect(()=>{const j=P=>{var $,H;if(P.key==="/"&&document.activeElement!==_.current){const k=($=document.activeElement)==null?void 0:$.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT")return;P.preventDefault(),(H=_.current)==null||H.focus()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[]);const S=p.useCallback(j=>{j.trim()&&(Cn(j.trim()),b(ve())),r(j),g(!1)},[r]),m=p.useCallback(j=>{j.type==="history"?(o(j.text),S(j.text)):j.entry&&(i?(i(j.entry),g(!1)):(o(j.text),S(j.text)))},[o,S,i]),B=p.useCallback(j=>{if(!u||x.length===0){j.key==="Enter"&&S(n);return}switch(j.key){case"ArrowDown":j.preventDefault(),v(P=>(P+1)%x.length);break;case"ArrowUp":j.preventDefault(),v(P=>(P-1+x.length)%x.length);break;case"Enter":j.preventDefault(),d>=0&&d<x.length?m(x[d]):S(n);break;case"Escape":j.preventDefault(),g(!1);break}},[u,x,d,n,S,m]),w=p.useCallback((j,P)=>{P.stopPropagation(),In(j),b(ve()),h($=>$.filter(H=>!(H.type==="history"&&H.text===j)))},[]),W=p.useCallback(j=>{j.stopPropagation(),zn(),b([]),h([])},[]);p.useEffect(()=>{if(d>=0&&y.current){const j=y.current.children;j[d]&&j[d].scrollIntoView({block:"nearest"})}},[d]);const R=!n.trim()&&L.length>0;return e.jsxs("div",{ref:T,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:_,type:"text",placeholder:a,value:n,onChange:j=>{o(j.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:B,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),u&&x.length>0&&e.jsxs("div",{ref: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:[R&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:c.search.history}),e.jsx("button",{onClick:W,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),x.map((j,P)=>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===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:j.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.text}),j.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[s[j.entry.type],j.entry.edition&&` · ${j.entry.edition}`,j.entry.author&&` · ${j.entry.author}`]}),j.type==="history"&&e.jsx("button",{onClick:$=>w(j.text,$),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}-${P}`))]})]})},$e="bim-recent-ids",Je="bim-recent-entries",Ze=50,Le=5,_n=50,Tn=200;function Pe(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(Je);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem($e,JSON.stringify(o)),localStorage.removeItem(Je),o}return[]}catch{return[]}}function Rn(t){try{const n=Pe().filter(o=>o!==t);n.unshift(t),n.length>Ze&&(n.length=Ze),localStorage.setItem($e,JSON.stringify(n))}catch{}}const Ln={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},Ae=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:c,onConfigurePath:a,onSelectFolder:s,hideModeIndicator:u,initialQuery:g,onQueryChange:x,headerRight:h})=>{const d=A(),v=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"}],[I,f]=p.useState(g??""),[L,b]=p.useState(null),[_,y]=p.useState(null),[T,C]=p.useState(!1),[S,m]=p.useState(null),[B,w]=p.useState(""),[W,R]=p.useState(!g),[j,P]=p.useState(Pe),[$,H]=p.useState([]),[k,E]=p.useState(!1),[U,V]=p.useState(!1),[F,ne]=p.useState(null),ee=p.useRef(void 0),oe=p.useRef(!1),re=p.useCallback(async(M,K)=>{if(!M.trim()){R(!0),b(null),y(null);return}R(!1),C(!0),w("");try{if(t.searchAll){const G=await t.searchAll(M,K??Le);b(G)}else{const G=["work","book","collection"],J=await Promise.all(G.map(Q=>t.search(M,Q,{page:1,pageSize:K??Le})));b({works:J[0].entries,books:J[1].entries,collections:J[2].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total})}}catch(G){w(G instanceof Error?G.message:String(G)),b(null)}finally{C(!1)}},[t]);p.useEffect(()=>{var Q;let M=!1;const K=["work","book","collection"],G=Promise.all(K.map(Z=>t.loadEntries(Z,{page:1,pageSize:1}).catch(()=>({total:0})))),J=((Q=t.getResourceCounts)==null?void 0:Q.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([G,J]).then(([Z,O])=>{M||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})}),()=>{M=!0}},[t]),p.useEffect(()=>{oe.current||!(g!=null&&g.trim())||(oe.current=!0,re(g))},[g,re]);const xe=p.useCallback(M=>{if(f(M),x==null||x(M),!M.trim()){R(!0),b(null),y(null);return}ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{y(null),re(M)},Tn)},[re,x]),ae=p.useCallback(M=>{ee.current&&clearTimeout(ee.current),x==null||x(M),re(M)},[re,x]),Y=p.useCallback(M=>{y(M),re(I,_n)},[I,re]);p.useEffect(()=>{if(!j.length){H([]);return}let M=!1;return E(!0),Promise.all(j.slice(0,10).map(async K=>{var G,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:(G=O==null?void 0:O[0])==null?void 0:G.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=>{M||(H(K.filter(G=>G!==null)),E(!1))}),()=>{M=!0}},[j,t]);const he=M=>{m(M.id),Rn(M.id),P(Pe()),r==null||r(M)},ke=M=>v.find(K=>K.type===M),Re=L&&(L.works.length>0||L.books.length>0||L.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!u&&e.jsx(St,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:c,onConfigurePath:a,onSelectFolder:s})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(kt,{transport:t,value:I,onChange:xe,onSearch:ae,onEntrySelect:he}),i&&e.jsx("button",{onClick:()=>i("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:d.action.newEntry})]}),F&&W&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between"},children:[e.jsxs("span",{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):B?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):W?e.jsx("div",{style:{flex:1},children:k?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:d.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,U?10:3).map(M=>e.jsx(Xe,{entry:M,selected:S===M.id,onClick:he,getConfig:ke},M.id))}),!U&&$.length>3&&e.jsx("button",{onClick:()=>V(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:d.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Re?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:v.map(({type:M,icon:K,name:G,key:J})=>{const Q=L[J],Z=Ln[J],O=L[Z];if(Q.length===0)return null;const we=!(_===M)&&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," ",G,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[O," ",d.unit.items]})]}),we&&e.jsx("button",{onClick:()=>Y(M),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(z=>e.jsx(Xe,{entry:z,selected:S===z.id,onClick:he,getConfig:ke,query:I},z.id))})]},M)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Se(d.search.noResultsFor,{query:I})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},Xe=({entry:t,selected:n,onClick:o,getConfig:r,query:i})=>{const l=A(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],s=i&&a.length?a.find(u=>{const g=typeof u=="string"?u:u==null?void 0:u.book_title;return g==null?void 0:g.toLowerCase().includes(i.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children: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:"→"})]})},En=["〇","一","二","三","四","五","六","七","八","九"],qe=["","十","百","千"];function wt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",i=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),a=o-1-l;c===0?i=!0:(i&&r&&(r+="〇"),i=!1,c===1&&a===1&&l===0?r+=qe[a]:r+=En[c]+qe[a])}return r}function Ct({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function Bn({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 Wn({id:t}){const n=A(),[o,r]=p.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"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:i,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 It({authors:t,type:n}){const{convert:o}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,i)=>e.jsxs("span",{children:[i>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",o(r.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:o(r.name)}),r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",o(r.role)]})]},i))})}function pe({id:t,label:n,onNavigate:o,renderLink:r}){return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:`/${t}`,onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function $n({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:c,meta:a,headerExtra:s}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px",flexWrap:"wrap"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.3,letterSpacing:"0.5px",flex:1,minWidth:0,wordBreak:"break-word"},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(Ct,{type:r}),e.jsx(Bn,{isDraft:i}),e.jsx(Wn,{id:t}),s]})]}),((l==null?void 0:l.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(It,{authors:l,type:r}),a]})]})}function Pn({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();if(!t.length)return null;const[l,c]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(te,{children:r.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((a,s)=>{const u=l===s;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:s),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:i(a.source)}),!u&&a.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i(a.title_info)}),a.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(pe,{id:a.source_bid,label:r.action.view,onNavigate:n,renderLink:o})})]}),u&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(a.title_info||a.author_info||a.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[a.title_info&&e.jsx(se,{label:r.label.titleInfo,children:i(a.title_info)}),a.author_info&&e.jsx(se,{label:r.label.authorInfo,children:i(a.author_info)}),a.edition&&e.jsx(se,{label:r.label.edition,children:i(a.edition)})]}),a.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:r.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:i(a.summary)})]}),a.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:r.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(a.comment)})]}),a.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:r.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(a.additional_comment)})]})]})]},s)})})]})}function zt({label:t,items:n}){const{convert:o}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(te,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,i)=>{const l=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(l)},i)})})]}):null}function An({items:t}){const n=A();return e.jsx(zt,{label:n.section.aliases,items:t})}function Mn({items:t}){const n=A();return e.jsx(zt,{label:n.section.attachedTexts,items:t})}function Fn({items:t}){const n=A(),{convert:o}=D();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((r,i)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},i))})]}):null}function Dn({items:t}){const n=A(),{convert:o}=D();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((r,i)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},i))]})]}):null}function Hn({items:t}){const n=A(),{convert:o}=D();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((r,i)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},i))})]}):null}function Qe({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=D(),[c,a]=p.useState([]);return p.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(u=>({id:u})));return}let s=!1;return Promise.all(n.map(u=>o.getItem(u).then(g=>({id:u,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:u})))).then(u=>{s||a(u)}),()=>{s=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(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(s=>({id:s}))).map(s=>{const u=s.edition?`${l(s.title)||s.id}(${l(s.edition)})`:l(s.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(pe,{id:s.id,label:u,onNavigate:r,renderLink:i})},s.id)})})]}):null}function On({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D(),[l,c]=p.useState(!1),a=t.resources&&t.resources.length>0,s=t.edition?i(t.edition):i(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:a&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(pe,{id:t.id,label:s,onNavigate:n,renderLink:o})}),a&&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?r.action.expand:r.action.collapse,children:"▼"})]}),a&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(De,{items:t.resources,groupByType:!0})})]})}function Vn({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),[l,c]=p.useState([]);return p.useEffect(()=>{if(!t.length){c([]);return}if(!n){c(t.map(s=>({id:s})));return}let a=!1;return Promise.all(t.map(s=>n.getItem(s).then(u=>({id:s,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:s})))).then(s=>{a||c(s)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(te,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(l.length?l:t.map(a=>({id:a}))).map(a=>e.jsx(On,{book:a,onNavigate:o,renderLink:r},a.id))})]}):null}function Nn({workData:t,onNavigate:n,renderLink:o}){var l,c,a;const r=A(),{convert:i}=D();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(Ct,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(pe,{id:t.id,label:i(t.title),onNavigate:n,renderLink:o})}),((l=t.juan_count)==null?void 0:l.number)!=null&&t.juan_count.number>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[wt(t.juan_count.number),r.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(It,{authors:t.authors,type:"work"}),((c=t.description)==null?void 0:c.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:i(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(se,{label:r.label.parentWork,children:e.jsx(pe,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Un({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(pe,{id:l.id,label:i(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Se(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const He=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:c,style:a})=>{var W,R,j,P,$,H;const s=A(),{convert:u}=D(),[g,x]=p.useState(null),[h,d]=p.useState(!1),[v,I]=p.useState(null),[f,L]=p.useState(null),[b,_]=p.useState([]),y=t||g;if(p.useEffect(()=>{if(t||!n||!o)return;let k=!1;return d(!0),I(null),o.getItem(n).then(E=>{k||(E?x(E):I(s.misc.notFoundEntry))}).catch(E=>{k||I(E instanceof Error?E.message:s.misc.loadFailed)}).finally(()=>{k||d(!1)}),()=>{k=!0}},[t,n,o]),p.useEffect(()=>{if(!y||!o){L(null),_([]);return}let k=!1;const E=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(E?o.getItem(E).then(U=>{!k&&U&&U.type==="work"&&L(U)}).catch(()=>{}):L(null),y.type==="book"){const U=y;U.contained_in&&U.contained_in.length>0?Promise.all(U.contained_in.map(V=>{const F=typeof V=="string"?V:V.id,ne=typeof V=="string"?void 0:V.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(V=>{k||_(V)}):_([])}else _([]);return()=>{k=!0}},[y,o]),h)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((k,E)=>e.jsx("div",{style:{height:E===1?"32px":"16px",width:`${k}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},E))})});if(v)return e.jsx("div",{className:c,style:{...a,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=N.extractStatus(y.id)==="draft"}catch{}let B="";(W=y.juan_count)!=null&&W.number?B=wt(y.juan_count.number)+s.unit.juan:(R=y.juan_count)!=null&&R.description&&(B=u(y.juan_count.description));const w=[];return(j=y.publication_info)!=null&&j.year&&w.push(e.jsx(se,{label:s.label.year,children:y.publication_info.year},"year")),(P=y.current_location)!=null&&P.name&&w.push(e.jsx(se,{label:s.label.currentLocation,children:u(y.current_location.name)},"loc")),($=y.page_count)!=null&&$.description&&w.push(e.jsx(se,{label:s.label.pageCount,children:y.page_count.description},"page")),T!=null&&T.edition&&w.push(e.jsx(se,{label:s.label.edition,children:u(T.edition)},"ver")),S!=null&&S.parent_work&&w.push(e.jsx(se,{label:s.label.parentWork,children:e.jsx(pe,{id:S.parent_work.id,label:u(S.parent_work.title),onNavigate:r,renderLink:i})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&w.push(e.jsx(se,{label:s.label.parentWork,children:S.parent_works.map((k,E)=>e.jsxs("span",{children:[E>0&&"、",e.jsx(pe,{id:k,onNavigate:r,renderLink:i})]},k))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx($n,{id:y.id,title:u(y.title),edition:y.edition?u(y.edition):void 0,type:y.type,isDraft:m,authors:y.authors,volumeText:B,meta:w,headerExtra:l}),((H=y.description)==null?void 0:H.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:s.section.containedIn}),e.jsx(Un,{items:b,onNavigate:r,renderLink:i})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:s.section.belongsToWork}),e.jsx(Nn,{workData:f,onNavigate:r,renderLink:i})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(Fn,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(An,{items:y.additional_titles}),y.attached_texts&&y.attached_texts.length>0&&e.jsx(Mn,{items:y.attached_texts}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(Pn,{items:y.indexed_by,onNavigate:r,renderLink:i}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(te,{children:s.section.resources}),e.jsx(De,{items:y.resources,groupByType:!0})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&e.jsx(Dn,{items:T.location_history}),(C==null?void 0:C.history)&&C.history.length>0&&e.jsx(Hn,{items:C.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&e.jsx(Qe,{title:s.section.relatedVersions,ids:T.related_books,transport:o,onNavigate:r,renderLink:i}),(C==null?void 0:C.books)&&C.books.length>0&&e.jsx(Qe,{title:s.section.containedBooks,ids:C.books,transport:o,onNavigate:r,renderLink:i}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Vn,{ids:S.books,transport:o,onNavigate:r,renderLink:i}),(S==null?void 0:S.related_works)&&S.related_works.length>0&&(()=>{const k=[],E=S.related_works.filter(F=>F.relation==="part_of"),U=S.related_works.filter(F=>F.relation==="has_part"),V=S.related_works.filter(F=>!F.relation);return E.length>0&&k.push({label:s.section.belongsToWork,items:E}),U.length>0&&k.push({label:s.section.containedWorks,items:U}),V.length>0&&k.push({label:s.section.relatedWorks,items:V}),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:r,renderLink:i})},ne.id))})]},F.label))})()]})};function Yn({data:t}){const n=A(),{convert:o}=D(),{stats:r}=t,i=r.processed_volumes??r.total_found_volumes,l=i!=null&&t.total_volumes>0?Math.round(i/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Gn({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:et(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:et(n===i.name),children:[i.name,i.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function 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 Kn({id:t,label:n,onNavigate:o,renderLink:r}){return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:`/${t}`,onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Jn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function tt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=A(),{convert:l}=D(),c=t.book_id||t.work_id,a=r&&t.volumes.length>0?Jn(t.volumes,i.unit.volume):null,s=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[l(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(u=>l(u)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:s?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),c&&e.jsx(Kn,{id:c,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!c&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const _t=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:c})=>{const a=A(),[s,u]=p.useState(null),[g,x]=p.useState(!1),[h,d]=p.useState(null),[v,I]=p.useState(null),[f,L]=p.useState(""),b=t||s;p.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),d(null),o.getCollectionCatalog(n).then(m=>{S||(m?u(m):d(a.catalog.notFound))}).catch(m=>{S||d(m instanceof Error?m.message:a.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,a]);const _=(b==null?void 0:b.sections)&&b.sections.length>0,y=p.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const S=b.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(S).size<S.length},[b]),T=p.useMemo(()=>{if(!b)return[];let S=b.books;if(v&&(S=S.filter(m=>m.section===v)),f.trim()){const m=f.trim().toLowerCase();S=S.filter(B=>B.title.toLowerCase().includes(m)||B.sub_items&&B.sub_items.some(w=>w.toLowerCase().includes(m))||B.edition&&B.edition.toLowerCase().includes(m))}return S},[b,v,f]),C=p.useMemo(()=>{if(!y)return null;const S=[],m=new Map;for(const w of T){if(!w.volumes||w.volumes.length===0)continue;const W=w.volumes[0];m.has(W)||m.set(W,[]),m.get(W).push(w)}const B=[...m.keys()].sort((w,W)=>w-W);for(const w of B)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:a.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(Yn,{data:b}),_&&e.jsx(Gn,{sections:b.sections,activeSection:v,onSelect:I}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:f,onChange:S=>L(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[T.length," ",a.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(a.catalog.volume,{n:S.volume})}),S.books.map((B,w)=>e.jsx(tt,{book:B,onNavigate:r,renderLink:i,showVolumes:B.volumes.length>1},`${S.volume}-${w}`))]},`${S.volume}-${m}`)):T.map((S,m)=>e.jsx(tt,{book:S,onNavigate:r,renderLink:i,showVolumes:!0},m)),T.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},Zn=["〇","一","二","三","四","五","六","七","八","九"],nt=["","十","百","千"],Xn=["","萬","億"];function Tt(t){if(t===0)return"〇";if(t<0)return`負${Tt(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(qn(i,r>0)+Xn[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function qn(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let i="";for(let l=0;l<o.length;l++){const c=o[l],a=o.length-1-l;c===0?i&&!i.endsWith("〇")&&(i+="〇"):c===1&&a===1&&l===0&&!n?i+=nt[a]:i+=Zn[c]+nt[a]}return i.replace(/〇$/,"")}const Rt={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Qn(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 Lt({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:Qn(t)})}function Et(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Et(r,n)))}function Bt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+Bt(l),0))||0;return n+o}function Wt({group:t,activeFile:n,onSelect:o,depth:r=0}){var u;const i=Et(t,n||""),[l,c]=p.useState(i),a=Bt(t),s=!!((u=t.children)!=null&&u.length);if(p.useEffect(()=>{i&&c(!0)},[i]),t.files.length===1&&!s){const g=t.files[0],x=n===g;return e.jsx("button",{onClick:()=>o(g),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:x?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:x?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:x?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:x?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:i?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",a,")"]})]}),l&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(g=>e.jsx(Lt,{file:g,isActive:n===g,onSelect:o},g))}),s&&t.children.map((g,x)=>e.jsx(Wt,{group:g,activeFile:n,onSelect:o,depth:r+1},x))]})]})}function eo({files:t,groups:n,activeFile:o,onSelect:r}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((i,l)=>e.jsx(Wt,{group:i,activeFile:o,onSelect:r},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(i=>e.jsx(Lt,{file:i,isActive:o===i,onSelect:r},i))})}function to({type:t}){const n=Rt[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 no(t){if(!t)return null;const n=t.match(/^[^。]*。(.+)$/s);return n&&n[1].trim()?n[1].trim():null}function oo({section:t,onNavigate:n}){const{convert:o}=D(),[r,i]=p.useState(!1),l=!!t.summary,c=!!t.comment,a=!!t.additional_comment,s=t.author_info?null:no(t.content),u=l||c||a;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>u&&i(!r),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:r?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},children:[t.book_title?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Tt(t.n_juan),"卷"]})]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",flexShrink:0,whiteSpace:"nowrap"},children:o(t.author_info||t.author)}),s&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"50%",flexShrink:1},children:o(s)}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:`/${t.work_id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),r&&u&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:o(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:o(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o(t.additional_comment)})]})]})]})}function ro({section:t}){const{convert:n}=D(),[o,r]=p.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(to,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),i&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${Rt[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 io({section:t}){const{convert:n}=D();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 lo({sections:t,onNavigate:n}){const{convert:o}=D(),r=[];let i=null;for(const l of t)l.type==="类"?(i&&r.push(i),i={category:l.title,items:[]}):l.type==="书"?(i||(i={category:"",items:[]}),i.items.push(l)):l.type==="序"&&(i?(i.items.push(l),r.push(i),i=null):r.push({category:"",items:[l]}));return i&&r.push(i),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.map((l,c)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[l.category&&e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:o(l.category.replace(/^[^·]*·?/,""))}),l.items.map((a,s)=>{if(a.type==="序")return e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},s);const u=a.content||a.title;return e.jsx("div",{children:n&&a.work_id?e.jsx("a",{href:`/${a.work_id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(a.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(a.title),children:o(u)}):o(u)},s)})]},c))})}function so({juan:t,searchQuery:n,onNavigate:o}){const{convert:r}=D(),[i,l]=p.useState("catalog"),c=p.useMemo(()=>{if(!n.trim())return t.sections;const s=n.trim().toLowerCase();return t.sections.filter(u=>{var g,x,h,d,v,I;return((g=u.title)==null?void 0:g.toLowerCase().includes(s))||((x=u.book_title)==null?void 0:x.toLowerCase().includes(s))||((h=u.author)==null?void 0:h.toLowerCase().includes(s))||((d=u.author_info)==null?void 0:d.toLowerCase().includes(s))||((v=u.summary)==null?void 0:v.toLowerCase().includes(s))||((I=u.content)==null?void 0:I.toLowerCase().includes(s))})},[t.sections,n]),a=c.filter(s=>s.type==="书").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:r(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(s=>e.jsx("button",{onClick:()=>l(s),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:s==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:i===s?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:i===s?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:s==="catalog"?"目錄":"原文"},s))}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[a," 部书"]})]}),i==="raw"&&e.jsx(lo,{sections:c,onNavigate:o}),i==="catalog"&&c.map((s,u)=>s.type==="书"?e.jsx(oo,{section:s,onNavigate:o},u):s.type==="部"||s.type==="类"?e.jsx(ro,{section:s},u):e.jsx(io,{section:s},u)),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const $t=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:i,onJuanChange:l,className:c,style:a})=>{const[s,u]=p.useState(null),[g,x]=p.useState(!1),[h,d]=p.useState(null),[v,I]=p.useState(null),[f,L]=p.useState(null),[b,_]=p.useState(!1),[y,T]=p.useState(""),C=i??v,S=p.useCallback(R=>{I(R),l==null||l(R)},[l]),m=t||s;p.useEffect(()=>{t&&(x(!1),d(null))},[t]),p.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let R=!1;return x(!0),d(null),o.getCollatedEditionIndex(n).then(j=>{R||(j?(u(j),!i&&j.juan_files.length>0&&S(j.juan_files[0])):d("未找到整理本数据"))}).catch(j=>{R||d(j instanceof Error?j.message:"加载失败")}).finally(()=>{R||x(!1)}),()=>{R=!0}},[t,n,o,i,S]),p.useEffect(()=>{const R=t||s;R&&R.juan_files&&R.juan_files.length>0&&!C&&S(R.juan_files[0])},[t,s,C,S]);const B=n||(m==null?void 0:m.work_id),w=p.useCallback(async R=>{if(!(!B||!(o!=null&&o.getCollatedJuan))){_(!0),L(null);try{const j=await o.getCollatedJuan(B,R);L(j)}catch{L(null)}finally{_(!1)}}},[B,o]);p.useEffect(()=>{C&&w(C)},[C,w]);const W=R=>{S(R),T("")};return g?e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):h?e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:c,style:a,children:[e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:m.total_juan})," 卷"]})}),e.jsx(eo,{files:m.juan_files,groups:m.juan_groups,activeFile:C,onSelect:W}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:y,onChange:R=>T(R.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),b?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载中..."}):f?e.jsx(so,{juan:f,searchQuery:y,onNavigate:r}):C?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,m.references&&m.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),m.references.map((R,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),R.url?e.jsx("a",{href:R.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:R.title}):e.jsx("span",{children:R.title}),R.author&&e.jsxs("span",{children:[",",R.author]}),R.note&&e.jsxs("span",{children:["。",R.note]})]},j))]})]}):null},ao={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},co={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function po(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const Pt=({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 r=ao[o.type],i=co[o.status];return e.jsxs("div",{style:xo,children:[e.jsxs("div",{style:uo,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...rt,background:r.color},children:r.label}),e.jsx("span",{style:{...rt,background:i.color},children:i.label})]}),e.jsx("span",{style:go,children:po(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:fo,children:[o.resourceId&&e.jsx("a",{href:`/book-index?id=${o.resourceId}`,style:it,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:it,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:ho,children:o.content}),o.reply&&e.jsxs("div",{style:bo,children:[e.jsx("div",{style:mo,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})}),ot={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},xo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},uo={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},rt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},go={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},fo={fontSize:"12px",marginBottom:"6px"},it={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},ho={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},bo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},mo={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},yo=[{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:r,onTabChange:i,feedbackApiUrl:l})=>{const c=A(),[a,s]=p.useState(null),[u,g]=p.useState([]),[x,h]=p.useState("recommend"),[d,v]=p.useState([]),[I,f]=p.useState(!1),L=r??x,b=w=>{h(w),i==null||i(w)},[_,y]=p.useState(!0),[T,C]=p.useState(null),[S,m]=p.useState(null);p.useEffect(()=>{if(!t.getAllEntries)return;let w=!1;return t.getAllEntries().then(W=>{if(w)return;const R=W.filter($=>$.type==="work").length,j=W.filter($=>$.type==="book").length,P=W.filter($=>$.type==="collection").length;s({works:R,books:j,collections:P})}).catch(()=>{}),()=>{w=!0}},[t]),p.useEffect(()=>{let w=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const R=await t.getRecommended();if(R!=null&&R.groups)return R.groups.flatMap(j=>j.items.map(P=>({...P,group:j.name})))}catch{}return yo})().then(async R=>{if(w)return;const j=R.filter($=>$.id);if(j.length===0){y(!1);return}const P=await Promise.all(j.map(async $=>{try{let H=null;if(t.getEntry)H=await t.getEntry($.id);else{const k=await t.getItem($.id);k&&(H={id:$.id,title:k.title||$.id,type:k.type||"work"})}if(H)return{...H,group:$.group,fallbackDescription:$.description}}catch{}return{id:$.id,title:$.title,type:$.id.startsWith("FC")?"collection":"work",group:$.group,fallbackDescription:$.description}}));w||(g(P.filter($=>$!==null)),y(!1))}),()=>{w=!0}},[t,o]),p.useEffect(()=>{if(!t.getResourceProgress)return;let w=!1;return t.getResourceProgress().then(W=>{w||C(W)}).catch(()=>{}),()=>{w=!0}},[t]),p.useEffect(()=>{if(!t.getSiteProgress)return;let w=!1;return t.getSiteProgress().then(W=>{w||m(W)}).catch(()=>{}),()=>{w=!0}},[t]),p.useEffect(()=>{if(!l||L!=="feedback")return;let w=!1;return f(!0),fetch(l).then(W=>W.json()).then(W=>{!w&&W.success&&v(W.items||[])}).catch(()=>{}).finally(()=>{w||f(!1)}),()=>{w=!0}},[l,L]);const B=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:L==="recommend",onClick:()=>b("recommend")}),e.jsx(Ce,{label:c.home.catalogTab,active:L==="catalog",onClick:()=>b("catalog")}),e.jsx(Ce,{label:c.home.siteTab,active:L==="site",onClick:()=>b("site")}),l&&e.jsx(Ce,{label:c.home.feedbackTab,active:L==="feedback",onClick:()=>b("feedback")})]}),L==="recommend"&&e.jsx(vo,{recommended:u,loading:_,onNavigate:n,getIcon:B,t:c}),L==="catalog"&&e.jsx(jo,{progress:T,t:c,onNavigate:n}),L==="site"&&e.jsx(ko,{progress:S,t:c,totalWorks:(a==null?void 0:a.works)??0}),L==="feedback"&&l&&e.jsx(Pt,{items:d,loading:I})]})})},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}),vo=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:i})=>{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 a=c.group||i.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(s=>{const u=s.dynasty||s.author?`${s.dynasty?`〔${s.dynasty}〕`:""}${s.author||""}`:s.fallbackDescription;return e.jsxs("a",{href:`/${s.id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),o==null||o(s.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(s.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s.title,s.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:s.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},s.id)})})]},c))})},jo=({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 r=[...t.resources].sort((a,s)=>a.priority-s.priority),i=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:i.map(a=>{const s=r.filter(u=>u.status===a);return s.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[a]}}),l[a]," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(u=>e.jsx(So,{item:u,t:n,statusColor:c[a],onNavigate:o},u.id))})]},a)})})},So=({item:t,t:n,statusColor:o,onNavigate:r})=>{const i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:`/${a}`,onClick:s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.currentTarget.style.borderBottomStyle="dashed",children: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:`${i}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},ko=({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 r=[...t.resources].sort((s,u)=>s.priority-u.priority),i=r.filter(s=>s.imported>0),l=r.filter(s=>s.imported===0),c=i.reduce((s,u)=>Math.max(s,u.imported),0),a=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," (",a,"%)"]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(s=>e.jsx(lt,{item:s,t:n,totalWorks:o},s.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(s=>e.jsx(lt,{item:s,t:n,totalWorks:o},s.id))})]})]})},lt=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},st="(max-width: 768px)";function wo(){const[t,n]=p.useState(()=>typeof window>"u"?!1:window.matchMedia(st).matches);return p.useEffect(()=>{const o=window.matchMedia(st),r=i=>n(i.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Co=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:i})=>{var H;const l=A(),{convert:c}=D(),a=wo(),[s,u]=p.useState(null),[g,x]=p.useState(null),[h,d]=p.useState(!1),[v,I]=p.useState("detail"),[f,L]=p.useState([]),[b,_]=p.useState(!1),[y,T]=p.useState(null),[C,S]=p.useState(!1),m=p.useCallback(async k=>{if(!t.getCollatedEditionIndex){T(null);return}S(!0);try{const E=await t.getCollatedEditionIndex(k);T(E)}catch{T(null)}finally{S(!1)}},[t]),B=p.useCallback(async k=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){L([]);return}_(!0);try{if(t.getCollectionCatalogs){const E=await t.getCollectionCatalogs(k);L(E||[])}else if(t.getCollectionCatalog){const E=await t.getCollectionCatalog(k);L(E?[{resource_id:"",data:E}]:[])}}catch{L([])}finally{_(!1)}},[t]),w=p.useCallback(async k=>{if(o){o(k);return}u(k),x(null),L([]),T(null),I("detail"),d(!0);try{const E=await t.getItem(k.id);E&&(x(E),E.type==="collection"?B(k.id):E.type==="work"&&E.has_collated&&m(k.id))}catch(E){console.error("加载详情失败:",E)}finally{d(!1)}},[t,o,B,m]),W=p.useCallback(async k=>{x(null),L([]),T(null),I("detail"),d(!0);try{const E=await t.getItem(k);E&&(x(E),u({id:k,title:E.title||k,type:E.type||"book"}),E.type==="collection"?B(k):E.type==="work"&&E.has_collated&&m(k))}catch(E){console.error("导航失败:",E)}finally{d(!1)}},[t,B,m]),R=(g==null?void 0:g.type)==="collection"&&(f.length>0||b)||(g==null?void 0:g.type)==="work"&&(y||C),j=a&&(h||g),P=p.useCallback(()=>{u(null),x(null),L([]),T(null),I("detail")},[]),$=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:[(R||i)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>I("detail"),style: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:()=>I(`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:()=>I("collated"),style:Ie(v==="collated"),children:[l.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),i&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:i})]}),e.jsx("div",{style:{padding:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:v==="detail"?e.jsx(He,{data:g,transport:t,onNavigate:W}):v.startsWith("catalog:")?e.jsx(_t,{data:(H=f.find(k=>`catalog:${k.resource_id}`===v))==null?void 0:H.data,onNavigate:W}):v==="collated"?e.jsx($t,{index:y||void 0,workId:g.id,transport:t,onNavigate:W}):null})]}):e.jsx(Me,{transport:t,onNavigate:W,recommendedIds:r})});return a?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:j?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:P,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ae,{transport:t,onEntryClick:w,hideModeIndicator:n}),!g&&e.jsx(Me,{transport:t,onNavigate:W,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(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:$})]})};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 Io=({data:t,onNavigate:n,className:o,style:r})=>{var g;const i=A(),{convert:l}=D(),[c,a]=p.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[s,u]=p.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:l(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[i.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",i.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",i.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",i.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(zo,{division:x,expanded:c===x.name,onToggle:()=>a(c===x.name?null:x.name),expandedCat:s,onCatToggle:h=>u(s===h?null:h),onNavigate:n},x.name))})]})},zo=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:i,onNavigate:l})=>{const{convert:c}=D(),a=t.categories.reduce((s,u)=>{const g=u.stats||{zhulu:0,cunmu:0};return s+(g.zhulu||0)+(g.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:c(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(s=>{const u=`${t.name}/${s.name}`;return e.jsx(_o,{category:s,expanded:r===u,onToggle:()=>i(u),onNavigate:l},s.name)})})]})},_o=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var s,u,g,x;const{convert:i}=D(),l=((s=t.books)==null?void 0:s.zhulu)||[],c=((u=t.books)==null?void 0:u.cunmu)||[],a=(((g=t.stats)==null?void 0:g.zhulu)||l.length)+(((x=t.stats)==null?void 0:x.cunmu)||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:[i(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(at,{label:"著錄",books:l,onNavigate:r}),c.length>0&&e.jsx(at,{label:"存目",books:c,onNavigate:r})]})]})},at=({label:t,books:n,onNavigate:o})=>{const{convert:r}=D(),[i,l]=p.useState(n.length<=20),c=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,s)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:`/${a.work_id}`,onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},s))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},le=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:i})=>{const l=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:Ro,children:"AI"}),n&&e.jsx("button",{onClick:n,style:To,children:l.action.save})]})]}),i]})},To={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ro={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},q=({label:t,value:n,onChange:o,placeholder:r,disabled:i})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:i,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),ue=({value:t,onChange:n,placeholder:o})=>{const r=p.useRef(null);return p.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:i=>n(i.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},_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 Lo(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ze=({value:t,onChange:n,label:o})=>{const[r,i]=p.useState(!1),l=p.useRef(null),c=Lo(t||"");return p.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ct,children:o}),e.jsxs("div",{onClick:()=>i(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:c.name}),e.jsx(_e,{children:c.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ct,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:a=>n(a.target.value),onBlur:()=>i(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},ct={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Eo(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Bo(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const At=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[i,l]=p.useState(null),c=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},a=x=>{n(t.filter((h,d)=>d!==x)),i===x&&l(null)},s=(x,h,d)=>{const v=[...t];v[x]={...v[x],[h]:d},n(v)},u=(x,h)=>{const d=[...t];d[x]={...d[x],type:h,id:"",name:""},n(d),h==="bookID"&&o&&o(v=>{const I=[...t];I[x]={...I[x],id:v.id,name:v.title,type:"bookID"},n(I)})},g=x=>{o&&o(h=>{const d=[...t];d[x]={...d[x],id:h.id,name:h.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(i===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${h+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Eo(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Bo(x.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),i===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:de,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>u(h,"bookID"),style:{...dt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>u(h,"url"),style:{...dt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:de,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:pt,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>g(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>g(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:de,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:pt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:d=>s(h,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:de,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:d=>s(h,"id",d.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:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:de,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:d=>s(h,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:de,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:d=>s(h,"position",d.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:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:d=>s(h,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:ge})]}),e.jsxs("div",{children:[e.jsx("label",{style:de,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:d=>s(h,"processor_version",d.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:r.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"},dt={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},pt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Mt(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 Ft(t){return!t||t.length===0?"":JSON.stringify(t)}const Dt=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:i,belongsToWork:l,belongsToCollection:c,childWorks:a,childCollections:s,containedBooks:u,siblingBooks:g,onLinkEntity:x,onUnlinkEntity:h,onViewEntity:d,onCreateAndLink:v,onSaveRelations:I})=>{const f=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:f.section.relations})]}),I&&e.jsx("button",{onClick:I,style:Wo,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:d,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:d,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:d,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:r,onView:d,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}),a&&a.length>0&&e.jsx(fe,{direction:"down",title:`${f.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>v("childWork","work",{parentWorkId:n}),addLabel:f.action.addSubWork,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),s&&s.length>0&&e.jsx(fe,{direction:"down",title:`${f.relation.collectionImpl} (${s.length})`,entities:s,onView:d,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:d,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:d,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:i,onView:d,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} (${(s==null?void 0:s.length)??0})`,entities:s||[],onView:d,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:d,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:r,onUnlink:i,onLink:l,onCreate:c,linkLabel:a,createLabel:s,notLinkedLabel:u,viewLabel:g,unlinkLabel:x})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:d}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ht(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(xt,{onClick:()=>r(o),title:g,children:"👁️"}),e.jsx(xt,{onClick:i,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:u}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Fe,{onClick:l,children:a}),e.jsx(Fe,{onClick:c,primary:!0,children:s})]})]})},fe=({direction:t,title:n,entities:o,onView:r,onAdd:i,addLabel:l,noneLabel:c,expandMoreLabel:a})=>{const[s,u]=p.useState(!1),g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=s?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>r(d),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Ht(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.length>5&&!s&&e.jsxs("div",{onClick:()=>u(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:c}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Fe,{onClick:i,primary:!0,children:["+ ",l]})})]})},xt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:i=>{i.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),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 Ht(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Wo={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"},Ot=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:i,onCreate:l,searchResults:c,onSearch:a,isLoading:s,excludeId:u})=>{const[g,x]=p.useState(""),h=u?c.filter(f=>f.id!==u):c;p.useEffect(()=>{t&&(x(""),a(""))},[t]);const d=f=>{x(f),a(f)};if(!t)return null;const v=n==="work"?"作品":n==="book"?"书籍":"丛编",I=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:$o,children:e.jsxs("div",{style:Po,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:i,style:Ao,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:f=>d(f.target.value),placeholder:`搜索${v}名称或 ID...`,autoFocus:!0,style:Mo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:s?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:()=>r(f),style:Fo,children:[e.jsx("span",{style:{fontSize:"16px"},children:I}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[f.title,f.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:f.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[f.id,f.author&&` · ${f.author}`,f.dynasty&&` · ${f.dynasty}`]})]})]},f.id))}):g?e.jsxs("div",{style: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:Do,children:["创建新",v,"并关联"]})]})]})})},$o={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",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Ao={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Mo={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"},Fo={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)"},Do={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ut={work:"作品",book:"书籍",collection:"丛编"},Ho={work:"📜",book:"📖",collection:"📚"},Vt=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:i,onCancel:l})=>{const[c,a]=p.useState(""),s=p.useRef(null);p.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,d;(h=s.current)==null||h.focus(),(d=s.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const u=h=>{h.key==="Enter"&&c.trim()?g():h.key==="Escape"&&l()},g=()=>{c.trim()&&i(c.trim(),{...r,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`创建新${ut[n]}`}};return e.jsx("div",{style:Oo,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:Vo,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:Ho[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:s,type:"text",value:c,onChange:h=>a(h.target.value),onKeyDown:u,placeholder:`请输入${ut[n]}名称...`,style:No})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:Uo,children:"取消"}),e.jsx("button",{onClick:g,disabled:!c.trim(),style:{...Yo,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},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",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},No={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"},Uo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Yo={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Go(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Nt(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ko(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Ut=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:i,showCreateButton:l=!1,createButtonText:c,onSelect:a,onCancel:s,onCreate:u,onSearch:g})=>{const[x,h]=p.useState(""),[d,v]=p.useState([]),[I,f]=p.useState(!1),[L,b]=p.useState("recent");p.useEffect(()=>{t&&(h(""),v([]),b(r.length>0?"recent":"search"))},[t,r.length]),p.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 _=p.useCallback(m=>{h(m.target.value),m.target.value.trim()&&b("search")},[]),y=p.useCallback(m=>i?m.filter(B=>B.id!==i):m,[i]);if(!t)return null;const T=n||(o==="all"?"选择实体":`选择${Nt(o)}`),C=y(r),S=y(d);return e.jsx("div",{style:Zo,children:e.jsxs("div",{style:Xo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:T}),e.jsx("button",{onClick:s,style:qo,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:_,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Qo}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),I&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),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(gt,{active:L==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(gt,{active:L==="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:L==="recent"&&C.length>0?e.jsx(ft,{entities:C,onSelect:a}):x.trim()?I?e.jsx(Be,{message:"搜索中..."}):S.length>0?e.jsx(ft,{entities:S,onSelect:a}):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:er,children:c||"创建新实体"})]})]})})},gt=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),ft=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Jo,{entity:o,onClick:()=>n(o)},o.id))}),Jo=({entity:t,onClick:n})=>{const[o,r]=p.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Go(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:Ko(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Nt(t.type)})]})},Be=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),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},Xo={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)"},qo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Qo={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"},er={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},tr={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},nr={work:"📜",collection:"📚",book:"📖"},Yt=({data:t,onChange:n,onSave:o,transport:r,onNavigate:i,showDelete:l,onDelete:c,onAskAI:a,renderSectionActions:s,onDownloadResource:u,downloadStatuses:g,relations:x,onRelationsChange:h})=>{var we;const d=A(),[v,I]=p.useState(!1),[f,L]=p.useState("work"),[b,_]=p.useState(""),[y,T]=p.useState(""),[C,S]=p.useState([]),[m,B]=p.useState(!1),[w,W]=p.useState(!1),[R,j]=p.useState("work"),[P,$]=p.useState(""),[H,k]=p.useState(),[E,U]=p.useState(!1),[V,F]=p.useState(null),[ne,ee]=p.useState([]);p.useRef(null);const oe=t.type,re=oe==="work",xe=oe==="collection",ae=oe==="book",Y=p.useCallback((z,X)=>{n({...t,[z]:X})},[t,n]),he=p.useCallback((z,X)=>{_(z),L(X),T(d.editor.selectToLink+d.indexType[X]),S([]),I(!0)},[d]),ke=p.useCallback(z=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,z)},[r,t.id]),Re=p.useCallback(z=>{i==null||i(z.id,z.type)},[i]),M=p.useCallback((z,X,ce)=>{const Jt={...ce,author:(ce==null?void 0:ce.author)||t.author,dynasty:(ce==null?void 0:ce.dynasty)||t.dynasty};j(X),$(z),k(Jt),W(!0)},[t.author,t.dynasty]),K=p.useCallback((z,X)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,P,{type:R,title:z,inheritData:X}),W(!1)},[r,t.id,P,R]),G=p.useCallback(z=>{if(!z.trim()){S([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(z,f).then(X=>{S(X),B(!1)}).catch(()=>{S([]),B(!1)})},[r,f]),J=p.useCallback(z=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,z.id),I(!1)},[r,t.id,b]),Q=p.useCallback(()=>{o()},[o]),Z=p.useCallback(z=>{F(()=>z),U(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(ee).catch(()=>{})},[r]),O=p.useCallback((z,X)=>r!=null&&r.searchEntities?r.searchEntities(z,X==="all"?void 0:X):Promise.resolve([]),[r]),Oe=p.useCallback(z=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(z),ee(X=>[z,...X.filter(ce=>ce.id!==z.id)].slice(0,10)),V==null||V(z),U(!1),F(null)},[r,V]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:nr[oe]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(_e,{children:t.id}),e.jsx(_e,{color:tr[oe],children:d.indexType[oe]})]})}),e.jsx(le,{title:d.section.basicInfo,onSave:o,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:s==null?void 0:s("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(ze,{label:re?d.editor.workTitle:xe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:z=>Y("title",z)}),ae&&e.jsx(ze,{label:d.editor.belongsToWork,value:t.workName||"",onChange:z=>Y("workName",z)}),e.jsx(q,{label:d.editor.authorLabel,value:t.author||"",onChange:z=>Y("author",z)}),e.jsx(q,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:z=>Y("dynasty",z)}),(ae||xe)&&e.jsx(ze,{label:d.editor.containedIn,value:t.collection||"",onChange:z=>Y("collection",z)}),(ae||xe)&&e.jsx(q,{label:d.editor.holderLabel,value:t.holder||"",onChange:z=>Y("holder",z)}),(ae||xe)&&e.jsx(q,{label:ae?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:z=>Y("pages",z)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(q,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:z=>Y("firstImage",z)})})]})}),e.jsx(le,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:z=>Y("description",z),placeholder:d.editor.descriptionPlaceholder})}),(((we=t.additional_works)==null?void 0:we.length)||0)>0&&e.jsx(le,{title:d.section.additionalWorks,onSave:o,children:e.jsx(or,{items:t.additional_works||[],onChange:z=>Y("additional_works",z)})}),e.jsx(le,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(rr,{items:t.indexed_by||[],onChange:z=>Y("indexed_by",z)})}),e.jsx(le,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(We,{items:t.resources||[],onChange:z=>Y("resources",z),onDownload:u,downloadStatuses:g,filterType:"text"})}),e.jsx(le,{title:d.section.imageResources,onSave:o,children:e.jsx(We,{items:t.resources||[],onChange:z=>Y("resources",z),onDownload:u,downloadStatuses:g,filterType:"image"})}),e.jsx(le,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(At,{items:Mt(t.sources||""),onChange:z=>Y("sources",Ft(z)),onOpenEntityPicker:Z})}),(ae||xe)&&e.jsx(le,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:z=>Y("provenance",z),placeholder:d.editor.provenancePlaceholder})}),ae&&e.jsx(le,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:z=>Y("otherEditions",z),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(Dt,{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:M,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:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick: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:d.editor.deleteEntity})]}),e.jsx(Ot,{isOpen:v,entityType:f,title:y,onSelect:J,onCancel:()=>I(!1),onCreate:()=>{I(!1),M(b,f)},searchResults:C,onSearch:G,isLoading:m,excludeId:t.id}),e.jsx(Vt,{isOpen:w,entityType:R,relationField:P,inheritData:H,onConfirm:K,onCancel:()=>W(!1)}),e.jsx(Ut,{isOpen:E,title:d.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:Oe,onCancel:()=>{U(!1),F(null)},onSearch:O})]})};function or({items:t,onChange:n}){const o=A(),r=(c,a,s)=>{const u=t.map((g,x)=>x===c?{...g,[a]:s}:g);n(u)},i=c=>n(t.filter((a,s)=>s!==c)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((c,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(q,{label:o.editor.bookNameLabel,value:c.book_title,onChange:s=>r(a,"book_title",s)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(q,{label:o.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:s=>r(a,"n_juan",s&&parseInt(s,10)||void 0)})}),e.jsx("button",{onClick:()=>i(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function rr({items:t,onChange:n}){const o=A(),[r,i]=p.useState(null),l=(s,u,g)=>{const x=t.map((h,d)=>d===s?{...h,[u]:g||void 0}:h);n(x)},c=s=>{n(t.filter((u,g)=>g!==s)),r===s&&i(null)},a=()=>{n([...t,{source:""}]),i(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,u)=>{const g=r===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:()=>i(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:s.source||o.editor.unnamedSource}),s.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:s.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&&(s.title_info||s.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[s.title_info,s.title_info&&s.author_info&&" — ",s.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:s.source,onChange:x=>l(u,"source",x)}),e.jsx(q,{label:o.label.sourceBid,value:s.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:s.title_info||"",onChange:x=>l(u,"title_info",x)}),e.jsx(q,{label:o.label.authorInfo,value:s.author_info||"",onChange:x=>l(u,"author_info",x)})]}),e.jsx(q,{label:o.label.edition,value:s.edition||"",onChange:x=>l(u,"edition",x)}),e.jsx(ue,{value:s.summary||"",onChange:x=>l(u,"summary",x),placeholder:o.editor.summaryPlaceholder}),e.jsx(ue,{value:s.comment||"",onChange:x=>l(u,"comment",x),placeholder:o.editor.commentPlaceholder}),e.jsx(ue,{value:s.additional_comment||"",onChange:x=>l(u,"additional_comment",x),placeholder:o.editor.additionalCommentPlaceholder})]})]},u)}),e.jsx("button",{onClick:a,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 Gt(t){var a,s,u,g,x,h,d;const n=((s=(a=t.authors)==null?void 0:a[0])==null?void 0:s.name)||"",o=((u=t.publication_info)==null?void 0:u.year)||"",r=((g=t.current_location)==null?void 0:g.name)||"",i=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.description)||"",l=typeof t.description=="object"&&t.description!==null&&t.description.text||"",c={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:i,description:l,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by};if(t.type==="work"){const v=t;if(Array.isArray(v.related_works)){const I=v.related_works.find(f=>f.relation==="part_of");I&&(c.parentWorkId=I.id,c.parentWorkName=I.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=(d=v.contained_in[0])==null?void 0:d.id)}return c}function ir(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 lr=t=>{const{data:n,id:o,transport:r,mode:i="view",onModeChange:l,onChange:c,onSave:a,onDelete:s,onNavigate:u,renderLink:g,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:v,relations:I,onRelationsChange:f,headerExtra:L,className:b,style:_}=t;A();const[y,T]=p.useState(i),C=l?i:y;p.useEffect(()=>{i!==y&&T(i)},[i]);const S=p.useCallback(()=>{const P=C==="view"?"edit":"view";l?l(P):T(P)},[C,l]),[m,B]=p.useState(null);p.useEffect(()=>{o&&r&&r.getItem(o).then(P=>{P&&B(P)})},[o,r]);const w=n||m,W=p.useMemo(()=>w?Gt(w):null,[w]),R=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background: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:[R,L]});return!w&&!W?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"加载中..."}):C==="view"?e.jsx(He,{data:w,transport:r,onNavigate:u?P=>u(P):void 0,renderLink:g,headerExtra:j,className:b,style:_}):W?e.jsxs("div",{className:b,style:_,children:[j&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:j}),e.jsx(Yt,{data:W,onChange:c||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:u,showDelete:!!s,onDelete:s,onAskAI:x,renderSectionActions:h,onDownloadResource:d,downloadStatuses:v,relations:I,onRelationsChange:f})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},ht=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Kt=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[i,l]=p.useState(null),[c,a]=p.useState(""),[s,u]=p.useState("idle"),[g,x]=p.useState(""),h=p.useRef(null);p.useEffect(()=>{t&&(l(null),a(""),u("idle"),x(""))},[t]),p.useEffect(()=>{i&&setTimeout(()=>{var f;return(f=h.current)==null?void 0:f.focus()},100)},[i]),p.useEffect(()=>{if(s==="success"){const f=setTimeout(n,2e3);return()=>clearTimeout(f)}},[s,n]),p.useEffect(()=>{if(!t)return;const f=L=>{L.key==="Escape"&&n()};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t,n]);const d=async()=>{if(!(!i||!c.trim())){u("submitting"),x("");try{await o({type:i,content:c.trim()}),u("success")}catch(f){u("error"),x(f instanceof Error?f.message:"提交失败,请稍后重试")}}};if(!t)return null;const v=i&&c.trim()&&s!=="submitting",I=ht.find(f=>f.value===i);return e.jsx("div",{style:sr,onClick:f=>{f.target===f.currentTarget&&n()},children:e.jsxs("div",{style:ar,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:cr,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:dr,"aria-label":"关闭",children:"✕"})]}),s==="success"?e.jsxs("div",{style:fr,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:ht.map(f=>e.jsxs("button",{onClick:()=>l(f.value),style:{...pr,...i===f.value?xr:{}},children:[e.jsx("span",{children:f.icon})," ",f.label]},f.value))}),e.jsx("textarea",{ref:h,value:c,onChange:f=>a(f.target.value),placeholder:(I==null?void 0:I.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!i||s==="submitting",style:{...ur,opacity:i?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),s==="error"&&e.jsx("div",{style:hr,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!v,style:{...gr,opacity:v?1:.6,cursor:v?"pointer":"not-allowed"},children:s==="submitting"?"提交中...":"提交反馈"})})]})]})})},sr={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},ar={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)"},cr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},dr={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},pr={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"},xr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ur={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"},gr={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},fr={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},hr={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},br=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,i]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>i(!0),style:{...mr,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(Kt,{isOpen:r,onClose:()=>i(!1),onSubmit:t,feedbackListUrl:o})]})},mr={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},bt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],yr=({onSubmit:t})=>{const[n,o]=p.useState("bug"),[r,i]=p.useState(""),[l,c]=p.useState("idle"),[a,s]=p.useState(""),u=p.useRef(null);p.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=u.current)==null?void 0:d.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){c("submitting"),s("");try{await t({type:n,content:r.trim()}),c("success"),i(""),o("bug")}catch(d){c("error"),s(d instanceof Error?d.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&l!=="submitting",h=bt.find(d=>d.value===n);return l==="success"?e.jsx("div",{style:mt,children:e.jsxs("div",{style:wr,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>c("idle"),style:Cr,children:"继续提交"})]})}):e.jsxs("div",{style:mt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:bt.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...vr,...n===d.value?jr:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:u,value:r,onChange:d=>i(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...Sr}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:g,disabled:!x,style:{...kr,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&e.jsx("div",{style:Ir,children:a})]})},mt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},vr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},jr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Sr={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},kr={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},wr={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Cr={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Ir={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},zr=({style:t})=>{const n=p.useContext(je);if(!n)return null;const{locale:o,setLocale:r}=n,i=o==="zh-Hant",l=()=>r(i?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:i?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:i?"var(--bim-primary, #0078d4)":void 0,fontWeight:i?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:i?void 0:"var(--bim-primary, #0078d4)",fontWeight:i?400:700},children:"简"})]})};exports.BidLink=N.BidLink;exports.BookIndexError=N.BookIndexError;exports.BookIndexManager=N.BookIndexManager;exports.BookIndexStorage=N.BookIndexStorage;exports.BundleStorage=N.BundleStorage;exports.ConfigError=N.ConfigError;exports.GithubStorage=N.GithubStorage;exports.IdGenerationError=N.IdGenerationError;exports.IdGenerator=N.IdGenerator;exports.LocalStorage=N.LocalStorage;exports.MigrationError=N.MigrationError;exports.StorageError=N.StorageError;exports.base58Decode=N.base58Decode;exports.base58Encode=N.base58Encode;exports.buildId=N.buildId;exports.decodeIdString=N.decodeIdString;exports.extractIdFromUrl=N.extractIdFromUrl;exports.extractStatus=N.extractStatus;exports.extractType=N.extractType;exports.normalizeCatalog=N.normalizeCatalog;exports.parseId=N.parseId;exports.validateResource=N.validateResource;exports.Badge=_e;exports.CollatedEdition=$t;exports.CollectionCatalog=_t;exports.CreateEntityDialog=Vt;exports.EntityPickerDialog=Ut;exports.EntitySelector=Ot;exports.FeedbackButton=br;exports.FeedbackDialog=Kt;exports.FeedbackForm=yr;exports.FeedbackList=Pt;exports.FormInput=q;exports.FormTextArea=ue;exports.HomePage=Me;exports.IndexApp=Co;exports.IndexBrowser=Ae;exports.IndexDetail=He;exports.IndexEditor=Yt;exports.IndexView=lr;exports.LocaleContext=je;exports.LocaleProvider=cn;exports.LocaleToggle=zr;exports.ModeIndicator=St;exports.RelationPanel=Dt;exports.ResourceEditor=We;exports.ResourceList=De;exports.SearchInput=kt;exports.Section=le;exports.SmartBidInput=ze;exports.SourceEditor=At;exports.WorkCatalog=Io;exports.detailToEditor=Gt;exports.editorToDetail=ir;exports.formatTemplate=Se;exports.parseSourceString=Mt;exports.stringifySources=Ft;exports.useConvert=D;exports.useT=A;
|
|
1
|
+
"use strict";var Zt=Object.create;var Ne=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,en=Object.prototype.hasOwnProperty;var tn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of qt(n))!en.call(t,i)&&i!==o&&Ne(t,i,{get:()=>n[i],enumerable:!(r=Xt(n,i))||r.enumerable});return t};var nn=(t,n,o)=>(o=t!=null?Zt(Qt(t)):{},tn(n||!t||!t.__esModule?Ne(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-ltSZanAI.cjs"),e=require("react/jsx-runtime"),p=require("react"),Se=p.createContext(null),yt={indexType:{work:"作品",book:"書籍",collection:"叢編"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"實體資源"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"實體"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",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:"別名",attachedTexts:"附載篇目",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:"圖片資源"}},on={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:"别名",attachedTexts:"附载篇目",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:"图片资源"}},rn={"zh-Hant":yt,"zh-Hans":on},vt="bim-locale";function ln(){try{const t=localStorage.getItem(vt);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function sn(t){try{localStorage.setItem(vt,t)}catch{}}const an="zh-Hant",cn=({locale:t,onLocaleChange:n,children:o})=>{const[r,i]=p.useState(t??an),l=t??r;p.useEffect(()=>{if(t)return;const g=ln();g&&g!==r&&i(g)},[]);const[c,a]=p.useState(null);p.useEffect(()=>{l==="zh-Hans"?import("opencc-js/t2cn").then(g=>{const u=g.Converter({from:"tw",to:"cn"});a(()=>u)}).catch(()=>{a(()=>g=>g)}):a(null)},[l]);const s=p.useCallback(g=>{i(g),sn(g),n==null||n(g)},[n]),x=p.useMemo(()=>({locale:l,setLocale:s,messages:rn[l],converter:c}),[l,s,c]);return e.jsx(Se.Provider,{value:x,children:o})};function A(){const t=p.useContext(Se);return(t==null?void 0:t.messages)??yt}const dn=2e3;function D(){const t=p.useContext(Se),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=p.useRef(new Map),i=p.useRef(n);i.current!==n&&(r.current.clear(),i.current=n);const l=p.useCallback(c=>{if(!c)return"";if(!o)return c;const a=r.current.get(c);if(a!==void 0)return a;const s=o(c);if(r.current.size>=dn){const x=r.current.keys().next().value;x!==void 0&&r.current.delete(x)}return r.current.set(c,s),s},[o]);return p.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function ke(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function pn(t){if(!t)return"";try{const n=new URL(t).hostname,o={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function xn(){return{id:"",name:"",url:"",type:"text",details:""}}const $e=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:i})=>{const l=A(),[c,a]=p.useState(null),s=[{value:"text",label:l.resourceTypeShort.text},{value:"image",label:l.resourceTypeShort.image},{value:"text+image",label:l.resourceTypeShort.textImage},{value:"physical",label:l.resourceTypeShort.physical}],x=[{value:"catalog",label:l.rootType.catalog},{value:"search",label:l.rootType.search}],g=b=>i?i==="text"?b==="text"||b==="text+image":i==="image"?b==="image"||b==="text+image"||b==="physical":b===i:!0,u=t.map((b,_)=>({item:b,originalIndex:_})).filter(({item:b})=>g(b.type)),h=()=>{const b=xn();i&&(b.type=i),n([...t,b]),a(t.length)},d=b=>{n(t.filter((_,y)=>y!==b)),a(null)},v=(b,_,y)=>{const T=[...t];if(T[b]={...T[b],[_]:y},_==="url"&&!T[b].id){const w=pn(y);w&&(T[b].id=w)}n(T)},I=(b,_,y)=>{const w={...t[b].metadata||{}};y?w[_]=y:delete w[_],v(b,"metadata",Object.keys(w).length>0?w:void 0)},f=(b,_)=>{const y=_.trim()?_.split(/[,,、]/).map(T=>T.trim()).filter(Boolean):void 0;v(b,"structure",y)},L=(b,_,y)=>{const w=t[b].coverage||{level:1,ranges:""};_==="level"?w.level=parseInt(y)||1:w.ranges=y,v(b,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[u.map(({item:b,originalIndex:_})=>{var y,T,w,S;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(c===_?null:_),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:c===_?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:un(b.type),color:"#fff"},children:((y=s.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} ${_+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&&gn(_,r==null?void 0:r[_],o,l),e.jsx("button",{onClick:m=>{m.stopPropagation(),d(_)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:l.editor.deleteThisResource,children:"✕"})]}),c===_&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(b.type==="image"||b.type==="text+image")&&b.url&&fn(b,l),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:me,children:[e.jsx("span",{style:ye,children:l.label.type}),e.jsx("select",{value:b.type,onChange:m=>v(_,"type",m.target.value),style:{...ie,flex:1},children:s.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))})]}),e.jsxs("label",{style:me,children:[e.jsx("span",{style:ye,children:l.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:m=>v(_,"root_type",m.target.value),style:{...ie,flex:1},children:x.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(_,"id",m.target.value),placeholder:l.editor.idAutoExtract,style:{...ie,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:m=>v(_,"name",m.target.value),placeholder:l.editor.resourceName,style:{...ie,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:m=>v(_,"url",m.target.value),placeholder:l.editor.resourceUrl,style:ie}),e.jsx("input",{type:"text",value:((T=b.structure)==null?void 0:T.join("、"))||"",onChange:m=>f(_,m.target.value),placeholder:l.editor.structurePlaceholder,style:ie}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:me,children:[e.jsx("span",{style:ye,children:l.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=b.coverage)==null?void 0:w.level)??"",onChange:m=>L(_,"level",m.target.value),placeholder:"1",style:{...ie,width:"60px"}})]}),e.jsxs("label",{style:{...me,flex:1},children:[e.jsx("span",{style:ye,children:l.label.coverageRange}),e.jsx("input",{type:"text",value:((S=b.coverage)==null?void 0:S.ranges)||"",onChange:m=>L(_,"ranges",m.target.value),placeholder:l.editor.coverageRangePlaceholder,style:{...ie,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:m=>v(_,"details",m.target.value),placeholder:l.editor.detailsPlaceholder,style:{...ie,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,B])=>{var C;return e.jsxs("label",{style:{...me,gap:"4px"},children:[e.jsx("span",{style:{...ye,minWidth:"56px"},children:B}),e.jsx("input",{type:"text",value:((C=b.metadata)==null?void 0:C[m])||"",onChange:W=>I(_,m,W.target.value),placeholder:B,style:{...ie,flex:1}})]},m)})})]})]})]})]},_)}),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 un(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function gn(t,n,o,r){const i=(n==null?void 0:n.status)==="downloading",l=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:c=>{c.stopPropagation(),i||o(t,"")},disabled:i,style:{background:"transparent",border:"none",color:l?"var(--bim-success, #4caf50)":i?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:i?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:i?.6:.9},title:l?r.download.completed:i?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:l?"✓":i?"⏳":"⬇"})}function fn(t,n){const o=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const ie={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},me={display:"flex",alignItems:"center",gap:"6px"},ye={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},hn={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function bn(t){try{const n=new URL(t).hostname;return hn[n]}catch{return}}const Ue={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"},mn=["text","image","text+image","physical"];function yn(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map,r=[],i=new Set;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[s,x]=a,g=`${s}|${c.type}`;o.has(g)||o.set(g,{base:{...c,name:s,url:"",volumes:[]},volumes:[]}),o.get(g).volumes.push({volume:x,url:c.url||void 0,status:"found"}),i.add(l)}for(const[,l]of o)if(l.volumes.length>=2)l.volumes.sort((c,a)=>c.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,r.push(l.base);else for(let c=0;c<t.length;c++)if(i.has(c)){const a=n(t[c].name);a&&`${a[0]}|${t[c].type}`==`${l.base.name}|${l.base.type}`&&i.delete(c)}for(let l=0;l<t.length;l++)i.has(l)||r.push(t[l]);return r}const He=({items:t,groupByType:n=!0})=>{const o=A(),r=p.useMemo(()=>yn(t||[]),[t]),i={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical};if(!r||r.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:r.map((c,a)=>e.jsx(Ge,{item:c},c.id||a))});const l=mn.map(c=>({type:c,items:r.filter(a=>a.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:a})=>e.jsxs("div",{children:[e.jsxs("h4",{style:{margin:"0 0 8px",fontSize:"13px",fontWeight:600,color:Ue[c],display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{display:"inline-block",width:"4px",height:"14px",borderRadius:"2px",background:Ue[c]}}),i[c],e.jsxs("span",{style:{fontWeight:400,opacity:.6},children:["(",a.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:a.map((s,x)=>e.jsx(Ge,{item:s},s.id||x))})]},c))})},Ye=t=>{const n=t.volumes&&t.volumes.length>0;return t.details&&!n||t.structure||t.coverage||t.metadata&&Object.keys(t.metadata).length>0},jt=({value:t})=>{const o=A().checkType[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:o.bg,color:o.fg},children:o.label}):e.jsx("span",{children:t})},vn=(t,n,o,r)=>{if(t==="check_type"&&typeof n=="string")return e.jsx(jt,{value:n});if(t==="has_translation")return n?o.misc.hasTranslation:o.misc.noTranslation;const i=String(n);return r?r(i):i};function jn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const i=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(i)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(i[1]))}&page=${n}`;const l=new URL(t);return l.searchParams.set("page",String(n)),l.toString()}return t}catch{return t}}function Sn(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 kn(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 wn={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},Ge=({item:t})=>{var h;const n=A(),{convert:o}=D(),[r,i]=p.useState(!1),l=p.useMemo(()=>(t.url?bn(t.url):void 0)||o(t.name),[t.url,t.name,o]),c=p.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(d=>({...d,url:d.url||kn(d)})),[t.volumes]),a=c&&c.length>0,s=a?c.filter(d=>d.status!=="missing").length:0,x=a?c.length-s:0,g=t.expected_volumes??(a?c.length:0),u=t.color_mode?{...wn[t.color_mode],label:n.colorMode[t.color_mode]}:null;return e.jsxs("div",{style:{padding:"10px 14px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:Ye(t)||a?"6px":"0"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:l}),u&&e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",borderRadius:"3px",fontSize:"11px",fontWeight:500,background:u.bg,color:u.fg},children:u.label}),t.source_label&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",fontStyle:"italic"},children:t.source_label}),((h=t.metadata)==null?void 0:h.check_type)&&e.jsx(jt,{value:t.metadata.check_type}),a&&e.jsxs("button",{onClick:()=>i(!r),style:{padding:"1px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer"},children:[s,"/",g,n.unit.volume,x>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"4px"},children:["缺",x]}),e.jsx("span",{style:{marginLeft:"4px"},children:r?"▲":"▼"})]}),t.url&&e.jsx("a",{href:(()=>{const d=Sn(t.metadata);return d?jn(t.url,d):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:n.action.visit})]}),Ye(t)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[t.metadata&&Object.entries(t.metadata).filter(([d])=>d!=="check_type").map(([d,v])=>e.jsxs("span",{children:[n.metadata[d]||d,": ",vn(d,v,n,o)]},d)),t.details&&!a&&e.jsx("span",{children:o(t.details)}),t.structure&&e.jsxs("span",{children:[n.misc.structure,": ",t.structure.join(" → ")]}),t.coverage&&e.jsxs("span",{children:[n.misc.coverage,": L",t.coverage.level," ",t.coverage.ranges]})]}),a&&r&&e.jsx("div",{style:{marginTop:"8px",padding:"8px 0",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",display:"flex",flexWrap:"wrap",gap:"4px"},children:c.map(d=>{const v=d.status==="missing";return e.jsx("span",{style:{display:"inline-flex"},children:d.url&&!v?e.jsx("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",lineHeight:1.4},title:d.label||`${d.volume}`,children:d.volume}):e.jsx("span",{style:{display:"inline-block",padding:"2px 6px",fontSize:"11px",borderRadius:"3px",border:"1px solid transparent",color:v?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1,lineHeight:1.4},children:d.volume})},d.volume)})})]})},St=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:i,onConfigurePath:l,onSelectFolder:c})=>{const a=A(),s=t==="local",x=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",u=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)"},d={onMouseOver:I=>I.currentTarget.style.opacity="0.8",onMouseOut:I=>I.currentTarget.style.opacity="1"},v=e.jsxs("div",{onClick:i,title:x?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...h,background:x?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:x?"📝":"📚"}),e.jsx("span",{children:x?"draft":"official"})]});return o==="index-browser"?s?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[v,e.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:h,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:c,title:g||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),u&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[v,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:l,title:u||a.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:s?a.mode.switchToGithub:a.mode.switchToLocal,style:h,...d,children:[e.jsx("span",{children:s?"📁":"🌐"}),e.jsx("span",{children:s?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),s&&e.jsxs("div",{onClick:c,title:g||a.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),u&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]}),!s&&u&&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:u})]})]})},Re="bim-search-history",Ke=10,Je=8;function je(){try{const t=localStorage.getItem(Re);return t?JSON.parse(t):[]}catch{return[]}}function Cn(t){try{const n=je().filter(o=>o!==t);n.unshift(t),n.length>Ke&&(n.length=Ke),localStorage.setItem(Re,JSON.stringify(n))}catch{}}function In(t){try{const n=je().filter(o=>o!==t);localStorage.setItem(Re,JSON.stringify(n))}catch{}}function zn(){try{localStorage.removeItem(Re)}catch{}}const kt=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:i,placeholder:l})=>{const c=A(),a=l??c.search.placeholder,s={work:c.indexType.work,book:c.indexType.book,collection:c.indexType.collection},[x,g]=p.useState(!1),[u,h]=p.useState([]),[d,v]=p.useState(-1),[I,f]=p.useState(null),[L,b]=p.useState(je),_=p.useRef(null),y=p.useRef(null),T=p.useRef(null);p.useEffect(()=>{if(!t.getAllEntries)return;let j=!1;return t.getAllEntries().then(P=>{j||f(P)}).catch(()=>{}),()=>{j=!0}},[t]);const w=p.useCallback(j=>{if(!j.trim())return L.map(k=>({type:"history",text:k}));if(!I)return[];const P=j.toLowerCase(),$=[],H=[];for(const k of I){if($.length+H.length>=Je*2)break;const E=k.title.toLowerCase();if(E.startsWith(P))$.push({type:"entry",text:k.title,entry:k});else if(E.includes(P))H.push({type:"entry",text:k.title,entry:k});else{const U=[...k.additional_titles||[],...k.attached_texts||[]];for(const V of U){const F=typeof V=="string"?V:V==null?void 0:V.book_title;if(F!=null&&F.toLowerCase().includes(P)){$.push({type:"entry",text:`${k.title}`,entry:k});break}}}}return[...$,...H].slice(0,Je)},[I,L]);p.useEffect(()=>{h(w(n)),v(-1)},[n,w]),p.useEffect(()=>{const j=P=>{T.current&&!T.current.contains(P.target)&&g(!1)};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[]),p.useEffect(()=>{const j=P=>{var $,H;if(P.key==="/"&&document.activeElement!==_.current){const k=($=document.activeElement)==null?void 0:$.tagName;if(k==="INPUT"||k==="TEXTAREA"||k==="SELECT")return;P.preventDefault(),(H=_.current)==null||H.focus()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[]);const S=p.useCallback(j=>{j.trim()&&(Cn(j.trim()),b(je())),r(j),g(!1)},[r]),m=p.useCallback(j=>{j.type==="history"?(o(j.text),S(j.text)):j.entry&&(i?(i(j.entry),g(!1)):(o(j.text),S(j.text)))},[o,S,i]),B=p.useCallback(j=>{if(!x||u.length===0){j.key==="Enter"&&S(n);return}switch(j.key){case"ArrowDown":j.preventDefault(),v(P=>(P+1)%u.length);break;case"ArrowUp":j.preventDefault(),v(P=>(P-1+u.length)%u.length);break;case"Enter":j.preventDefault(),d>=0&&d<u.length?m(u[d]):S(n);break;case"Escape":j.preventDefault(),g(!1);break}},[x,u,d,n,S,m]),C=p.useCallback((j,P)=>{P.stopPropagation(),In(j),b(je()),h($=>$.filter(H=>!(H.type==="history"&&H.text===j)))},[]),W=p.useCallback(j=>{j.stopPropagation(),zn(),b([]),h([])},[]);p.useEffect(()=>{if(d>=0&&y.current){const j=y.current.children;j[d]&&j[d].scrollIntoView({block:"nearest"})}},[d]);const R=!n.trim()&&L.length>0;return e.jsxs("div",{ref:T,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:_,type:"text",placeholder:a,value:n,onChange:j=>{o(j.target.value),g(!0)},onFocus:()=>g(!0),onKeyDown:B,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),x&&u.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:c.search.history}),e.jsx("button",{onClick:W,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:c.search.clearAll})]}),u.map((j,P)=>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===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:j.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.text}),j.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[s[j.entry.type],j.entry.edition&&` · ${j.entry.edition}`,j.entry.author&&` · ${j.entry.author}`]}),j.type==="history"&&e.jsx("button",{onClick:$=>C(j.text,$),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:c.action.remove,children:"×"})]},`${j.type}-${j.text}-${P}`))]})]})},Pe="bim-recent-ids",Ze="bim-recent-entries",Xe=50,Ee=5,_n=50,Tn=200;function Ae(){try{const t=localStorage.getItem(Pe);if(t)return JSON.parse(t);const n=localStorage.getItem(Ze);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Pe,JSON.stringify(o)),localStorage.removeItem(Ze),o}return[]}catch{return[]}}function Rn(t){try{const n=Ae().filter(o=>o!==t);n.unshift(t),n.length>Xe&&(n.length=Xe),localStorage.setItem(Pe,JSON.stringify(n))}catch{}}const Ln={works:"totalWorks",books:"totalBooks",collections:"totalCollections"},Me=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:i,onSwitchMode:l,onToggleDraft:c,onConfigurePath:a,onSelectFolder:s,hideModeIndicator:x,initialQuery:g,onQueryChange:u,headerRight:h})=>{const d=A(),v=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"}],[I,f]=p.useState(g??""),[L,b]=p.useState(null),[_,y]=p.useState(null),[T,w]=p.useState(!1),[S,m]=p.useState(null),[B,C]=p.useState(""),[W,R]=p.useState(!g),[j,P]=p.useState(Ae),[$,H]=p.useState([]),[k,E]=p.useState(!1),[U,V]=p.useState(!1),[F,ne]=p.useState(null),te=p.useRef(void 0),oe=p.useRef(!1),re=p.useCallback(async(M,K)=>{if(!M.trim()){R(!0),b(null),y(null);return}R(!1),w(!0),C("");try{if(t.searchAll){const G=await t.searchAll(M,K??Ee);b(G)}else{const G=["work","book","collection"],J=await Promise.all(G.map(Q=>t.search(M,Q,{page:1,pageSize:K??Ee})));b({works:J[0].entries,books:J[1].entries,collections:J[2].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total})}}catch(G){C(G instanceof Error?G.message:String(G)),b(null)}finally{w(!1)}},[t]);p.useEffect(()=>{var Q;let M=!1;const K=["work","book","collection"],G=Promise.all(K.map(Z=>t.loadEntries(Z,{page:1,pageSize:1}).catch(()=>({total:0})))),J=((Q=t.getResourceCounts)==null?void 0:Q.call(t).catch(()=>null))??Promise.resolve(null);return Promise.all([G,J]).then(([Z,O])=>{M||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})}),()=>{M=!0}},[t]),p.useEffect(()=>{oe.current||!(g!=null&&g.trim())||(oe.current=!0,re(g))},[g,re]);const xe=p.useCallback(M=>{if(f(M),u==null||u(M),!M.trim()){R(!0),b(null),y(null);return}te.current&&clearTimeout(te.current),te.current=setTimeout(()=>{y(null),re(M)},Tn)},[re,u]),ce=p.useCallback(M=>{te.current&&clearTimeout(te.current),u==null||u(M),re(M)},[re,u]),Y=p.useCallback(M=>{y(M),re(I,_n)},[I,re]);p.useEffect(()=>{if(!j.length){H([]);return}let M=!1;return E(!0),Promise.all(j.slice(0,10).map(async K=>{var G,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:(G=O==null?void 0:O[0])==null?void 0:G.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=>{M||(H(K.filter(G=>G!==null)),E(!1))}),()=>{M=!0}},[j,t]);const be=M=>{m(M.id),Rn(M.id),P(Ae()),r==null||r(M)},we=M=>v.find(K=>K.type===M),Le=L&&(L.works.length>0||L.books.length>0||L.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!x&&e.jsx(St,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:l,onToggleDraft:c,onConfigurePath:a,onSelectFolder:s})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(kt,{transport:t,value:I,onChange:xe,onSearch:ce,onEntrySelect:be}),i&&e.jsx("button",{onClick:()=>i("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:d.action.newEntry})]}),F&&W&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between"},children:[e.jsxs("span",{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.collections.toLocaleString()})]}),F.hasImage!=null&&F.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:F.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.searching}):B?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:B})]}):W?e.jsx("div",{style:{flex:1},children:k?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:d.search.recentBrowse}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,U?10:3).map(M=>e.jsx(qe,{entry:M,selected:S===M.id,onClick:be,getConfig:we},M.id))}),!U&&$.length>3&&e.jsx("button",{onClick:()=>V(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:d.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Le?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:v.map(({type:M,icon:K,name:G,key:J})=>{const Q=L[J],Z=Ln[J],O=L[Z];if(Q.length===0)return null;const Ce=!(_===M)&&O>Ee;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[K," ",G,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[O," ",d.unit.items]})]}),Ce&&e.jsx("button",{onClick:()=>Y(M),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(z=>e.jsx(qe,{entry:z,selected:S===z.id,onClick:be,getConfig:we,query:I},z.id))})]},M)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:ke(d.search.noResultsFor,{query:I})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},qe=({entry:t,selected:n,onClick:o,getConfig:r,query:i})=>{const l=A(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],s=i&&a.length?a.find(x=>{const g=typeof x=="string"?x:x==null?void 0:x.book_title;return g==null?void 0:g.toLowerCase().includes(i.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children: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:"→"})]})},En=["〇","一","二","三","四","五","六","七","八","九"],Qe=["","十","百","千"];function wt(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",i=!1;for(let l=0;l<o;l++){const c=parseInt(n[l]),a=o-1-l;c===0?i=!0:(i&&r&&(r+="〇"),i=!1,c===1&&a===1&&l===0?r+=Qe[a]:r+=En[c]+Qe[a])}return r}function Ct({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function Bn({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 Wn({id:t}){const n=A(),[o,r]=p.useState(!1),i=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#f6f6f6",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:i,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:l=>l.currentTarget.style.opacity="1",onMouseLeave:l=>l.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ee({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function se({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function It({authors:t,type:n}){const{convert:o}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,i)=>e.jsxs("span",{children:[i>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",o(r.dynasty),"〕"]}),e.jsx("span",{style:{fontWeight:500},children:o(r.name)}),r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",o(r.role)]})]},i))})}function ae({id:t,label:n,onNavigate:o,renderLink:r}){return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:`/${t}`,onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function $n({id:t,title:n,edition:o,type:r,isDraft:i,authors:l,volumeText:c,meta:a,headerExtra:s}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),c&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:c})]}),s&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:s})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Ct,{type:r}),e.jsx(Bn,{isDraft:i}),e.jsx(Wn,{id:t})]}),((l==null?void 0:l.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[l&&l.length>0&&e.jsx(It,{authors:l,type:r}),a]})]})}function Pn({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();if(!t.length)return null;const[l,c]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:r.section.indexed}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((a,s)=>{const x=l===s;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(x?null:s),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:i(a.source)}),!x&&a.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i(a.title_info)}),a.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ae,{id:a.source_bid,label:r.action.view,onNavigate:n,renderLink:o})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[(a.title_info||a.author_info||a.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[a.title_info&&e.jsx(se,{label:r.label.titleInfo,children:i(a.title_info)}),a.author_info&&e.jsx(se,{label:r.label.authorInfo,children:i(a.author_info)}),a.edition&&e.jsx(se,{label:r.label.edition,children:i(a.edition)})]}),a.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:r.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:i(a.summary)})]}),a.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:r.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(a.comment)})]}),a.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:r.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:i(a.additional_comment)})]})]})]},s)})})]})}function zt({label:t,items:n}){const{convert:o}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,i)=>{const l=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(l)},i)})})]}):null}function An({items:t}){const n=A();return e.jsx(zt,{label:n.section.aliases,items:t})}function Mn({items:t}){const n=A();return e.jsx(zt,{label:n.section.attachedTexts,items:t})}function Fn({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,i)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},i))})]}):null}function Dn({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,i)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},i))]})]}):null}function Hn({items:t}){const n=A(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,i)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},i))})]}):null}function et({title:t,ids:n,transport:o,onNavigate:r,renderLink:i}){const{convert:l}=D(),[c,a]=p.useState([]);return p.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(x=>({id:x})));return}let s=!1;return Promise.all(n.map(x=>o.getItem(x).then(g=>({id:x,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:x})))).then(x=>{s||a(x)}),()=>{s=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ee,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(c.length?c:n.map(s=>({id:s}))).map(s=>{const x=s.edition?`${l(s.title)||s.id}(${l(s.edition)})`:l(s.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ae,{id:s.id,label:x,onNavigate:r,renderLink:i})},s.id)})})]}):null}function On({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D(),[l,c]=p.useState(!1),a=t.resources&&t.resources.length>0,s=t.edition?i(t.edition):i(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:a&&!l?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(ae,{id:t.id,label:s,onNavigate:n,renderLink:o})}),a&&e.jsx("span",{onClick:()=>c(x=>!x),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:l?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:l?r.action.expand:r.action.collapse,children:"▼"})]}),a&&!l&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(He,{items:t.resources,groupByType:!0})})]})}function Vn({ids:t,transport:n,onNavigate:o,renderLink:r}){const i=A(),[l,c]=p.useState([]);return p.useEffect(()=>{if(!t.length){c([]);return}if(!n){c(t.map(s=>({id:s})));return}let a=!1;return Promise.all(t.map(s=>n.getItem(s).then(x=>({id:s,title:x?x.title:void 0,edition:x?x.edition:void 0,resources:x?x.resources:void 0})).catch(()=>({id:s})))).then(s=>{a||c(s)}),()=>{a=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ee,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:(l.length?l:t.map(a=>({id:a}))).map(a=>e.jsx(On,{book:a,onNavigate:o,renderLink:r},a.id))})]}):null}function Nn({workData:t,onNavigate:n,renderLink:o}){var l,c,a;const r=A(),{convert:i}=D();return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(Ct,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ae,{id:t.id,label:i(t.title),onNavigate:n,renderLink:o})}),((l=t.juan_count)==null?void 0:l.number)!=null&&t.juan_count.number>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[wt(t.juan_count.number),r.unit.juan]})]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(It,{authors:t.authors,type:"work"}),((c=t.description)==null?void 0:c.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:i(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(se,{label:r.label.parentWork,children:e.jsx(ae,{id:t.parent_work.id,label:i(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Un({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:i}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(l=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(ae,{id:l.id,label:i(l.title)||l.id,onNavigate:n,renderLink:o}),l.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:ke(r.catalog.volume,{n:l.volume_index})})]},l.id))}):null}const Oe=({data:t,id:n,transport:o,onNavigate:r,renderLink:i,headerExtra:l,className:c,style:a})=>{var W,R,j,P,$,H;const s=A(),{convert:x}=D(),[g,u]=p.useState(null),[h,d]=p.useState(!1),[v,I]=p.useState(null),[f,L]=p.useState(null),[b,_]=p.useState([]),y=t||g;if(p.useEffect(()=>{if(t||!n||!o)return;let k=!1;return d(!0),I(null),o.getItem(n).then(E=>{k||(E?u(E):I(s.misc.notFoundEntry))}).catch(E=>{k||I(E instanceof Error?E.message:s.misc.loadFailed)}).finally(()=>{k||d(!1)}),()=>{k=!0}},[t,n,o]),p.useEffect(()=>{if(!y||!o){L(null),_([]);return}let k=!1;const E=y.type==="book"||y.type==="collection"?y.work_id:void 0;if(E?o.getItem(E).then(U=>{!k&&U&&U.type==="work"&&L(U)}).catch(()=>{}):L(null),y.type==="book"){const U=y;U.contained_in&&U.contained_in.length>0?Promise.all(U.contained_in.map(V=>{const F=typeof V=="string"?V:V.id,ne=typeof V=="string"?void 0:V.volume_index;return o.getItem(F).then(te=>({id:F,title:te&&te.title||F,volume_index:ne})).catch(()=>({id:F,title:F,volume_index:ne}))})).then(V=>{k||_(V)}):_([])}else _([]);return()=>{k=!0}},[y,o]),h)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((k,E)=>e.jsx("div",{style:{height:E===1?"32px":"16px",width:`${k}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},E))})});if(v)return e.jsx("div",{className:c,style:{...a,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,w=y.type==="collection"?y:null,S=y.type==="work"?y:null;let m=!1;try{m=N.extractStatus(y.id)==="draft"}catch{}let B="";(W=y.juan_count)!=null&&W.number?B=wt(y.juan_count.number)+s.unit.juan:(R=y.juan_count)!=null&&R.description&&(B=x(y.juan_count.description));const C=[];return(j=y.publication_info)!=null&&j.year&&C.push(e.jsx(se,{label:s.label.year,children:y.publication_info.year},"year")),(P=y.current_location)!=null&&P.name&&C.push(e.jsx(se,{label:s.label.currentLocation,children:x(y.current_location.name)},"loc")),($=y.page_count)!=null&&$.description&&C.push(e.jsx(se,{label:s.label.pageCount,children:y.page_count.description},"page")),T!=null&&T.edition&&C.push(e.jsx(se,{label:s.label.edition,children:x(T.edition)},"ver")),S!=null&&S.parent_work&&C.push(e.jsx(se,{label:s.label.parentWork,children:e.jsx(ae,{id:S.parent_work.id,label:x(S.parent_work.title),onNavigate:r,renderLink:i})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&C.push(e.jsx(se,{label:s.label.parentWork,children:S.parent_works.map((k,E)=>e.jsxs("span",{children:[E>0&&"、",e.jsx(ae,{id:k,onNavigate:r,renderLink:i})]},k))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx($n,{id:y.id,title:x(y.title),edition:y.edition?x(y.edition):void 0,type:y.type,isDraft:m,authors:y.authors,volumeText:B,meta:C,headerExtra:l}),((H=y.description)==null?void 0:H.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:x(y.description.text)}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:s.section.containedIn}),e.jsx(Un,{items:b,onNavigate:r,renderLink:i})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:s.section.belongsToWork}),e.jsx(Nn,{workData:f,onNavigate:r,renderLink:i})]}),y.additional_works&&y.additional_works.length>0&&e.jsx(Fn,{items:y.additional_works}),y.additional_titles&&y.additional_titles.length>0&&e.jsx(An,{items:y.additional_titles}),y.attached_texts&&y.attached_texts.length>0&&e.jsx(Mn,{items:y.attached_texts}),y.indexed_by&&y.indexed_by.length>0&&e.jsx(Pn,{items:y.indexed_by,onNavigate:r,renderLink:i}),y.resources&&y.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:s.section.resources}),e.jsx(He,{items:y.resources,groupByType:!0})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&e.jsx(Dn,{items:T.location_history}),(w==null?void 0:w.history)&&w.history.length>0&&e.jsx(Hn,{items:w.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&e.jsx(et,{title:s.section.relatedVersions,ids:T.related_books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.books)&&w.books.length>0&&e.jsx(et,{title:s.section.containedBooks,ids:w.books,transport:o,onNavigate:r,renderLink:i}),(w==null?void 0:w.contained_works)&&w.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ee,{children:[s.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",w.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.contained_works.map(k=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ae,{id:k.id,label:x(k.title),onNavigate:r,renderLink:i})},k.id))})]}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Vn,{ids:S.books,transport:o,onNavigate:r,renderLink:i}),(S==null?void 0:S.related_works)&&S.related_works.length>0&&(()=>{const k=[],E=S.related_works.filter(F=>F.relation==="part_of"),U=S.related_works.filter(F=>F.relation==="has_part"),V=S.related_works.filter(F=>!F.relation);return E.length>0&&k.push({label:s.section.belongsToWork,items:E}),U.length>0&&k.push({label:s.section.containedWorks,items:U}),V.length>0&&k.push({label:s.section.relatedWorks,items:V}),k.map(F=>e.jsxs("div",{children:[e.jsxs(ee,{children:[F.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",F.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:F.items.map(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(ae,{id:ne.id,label:x(ne.title),onNavigate:r,renderLink:i})},ne.id))})]},F.label))})()]})};function Yn({data:t}){const n=A(),{convert:o}=D(),{stats:r}=t,i=r.processed_volumes??r.total_found_volumes,l=i!=null&&t.total_volumes>0?Math.round(i/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),l!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i})," ",n.unit.volume," (",l,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Gn({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:tt(n===null),children:r.catalog.all}),t.map(i=>e.jsxs("button",{onClick:()=>o(i.name),style:tt(n===i.name),children:[i.name,i.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[i.volume_range[0],"–",i.volume_range[1]]})]},i.name))]})}function tt(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Kn({id:t,label:n,onNavigate:o,renderLink:r}){return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:`/${t}`,onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Jn(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function nt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const i=A(),{convert:l}=D(),c=t.book_id||t.work_id,a=r&&t.volumes.length>0?Jn(t.volumes,i.unit.volume):null,s=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:a}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[l(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(x=>l(x)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:l(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:s?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,i.unit.volume]}),c&&e.jsx(Kn,{id:c,label:t.book_id?i.indexType.book:i.indexType.work,onNavigate:n,renderLink:o}),!c&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:i.catalog.unmatched_label})]})}const _t=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:i,className:l,style:c})=>{const a=A(),[s,x]=p.useState(null),[g,u]=p.useState(!1),[h,d]=p.useState(null),[v,I]=p.useState(null),[f,L]=p.useState(""),b=t||s;p.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return u(!0),d(null),o.getCollectionCatalog(n).then(m=>{S||(m?x(m):d(a.catalog.notFound))}).catch(m=>{S||d(m instanceof Error?m.message:a.catalog.loadFailed)}).finally(()=>{S||u(!1)}),()=>{S=!0}},[t,n,o,a]);const _=(b==null?void 0:b.sections)&&b.sections.length>0,y=p.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const S=b.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(S).size<S.length},[b]),T=p.useMemo(()=>{if(!b)return[];let S=b.books;if(v&&(S=S.filter(m=>m.section===v)),f.trim()){const m=f.trim().toLowerCase();S=S.filter(B=>B.title.toLowerCase().includes(m)||B.sub_items&&B.sub_items.some(C=>C.toLowerCase().includes(m))||B.edition&&B.edition.toLowerCase().includes(m))}return S},[b,v,f]),w=p.useMemo(()=>{if(!y)return null;const S=[],m=new Map;for(const C of T){if(!C.volumes||C.volumes.length===0)continue;const W=C.volumes[0];m.has(W)||m.set(W,[]),m.get(W).push(C)}const B=[...m.keys()].sort((C,W)=>C-W);for(const C of B)S.push({volume:C,books:m.get(C)});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:a.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(Yn,{data:b}),_&&e.jsx(Gn,{sections:b.sections,activeSection:v,onSelect:I}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:f,onChange:S=>L(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[T.length," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((S,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:ke(a.catalog.volume,{n:S.volume})}),S.books.map((B,C)=>e.jsx(nt,{book:B,onNavigate:r,renderLink:i,showVolumes:B.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${m}`)):T.map((S,m)=>e.jsx(nt,{book:S,onNavigate:r,renderLink:i,showVolumes:!0},m)),T.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.catalog.noMatch})]})]}):null},ge=()=>{const[t,n]=p.useState(1);return p.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},Zn=["〇","一","二","三","四","五","六","七","八","九"],ot=["","十","百","千"],Xn=["","萬","億"];function Tt(t){if(t===0)return"〇";if(t<0)return`負${Tt(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const i=o%1e4;i>0?n.unshift(qn(i,r>0)+Xn[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function qn(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let i="";for(let l=0;l<o.length;l++){const c=o[l],a=o.length-1-l;c===0?i&&!i.endsWith("〇")&&(i+="〇"):c===1&&a===1&&l===0&&!n?i+=ot[a]:i+=Zn[c]+ot[a]}return i.replace(/〇$/,"")}const Rt={部:"#2471a3",类:"#8e6f3e",书:"#c0392b",其他:"#717171"};function Qn(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 Lt({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:Qn(t)})}function Et(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>Et(r,n)))}function Bt(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((i,l)=>i+Bt(l),0))||0;return n+o}function Wt({group:t,activeFile:n,onSelect:o,depth:r=0}){var x;const i=Et(t,n||""),[l,c]=p.useState(i),a=Bt(t),s=!!((x=t.children)!=null&&x.length);if(p.useEffect(()=>{i&&c(!0)},[i]),t.files.length===1&&!s){const g=t.files[0],u=n===g;return e.jsx("button",{onClick:()=>o(g),style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:u?"1px solid var(--bim-primary, #8e6f3e)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:u?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":"transparent",color:u?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"12px",fontWeight:u?600:400,lineHeight:1.4},children:t.label})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>c(!l),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:i?"var(--bim-primary, #8e6f3e)":"var(--bim-fg, #333)"},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",a,")"]})]}),l&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(g=>e.jsx(Lt,{file:g,isActive:n===g,onSelect:o},g))}),s&&t.children.map((g,u)=>e.jsx(Wt,{group:g,activeFile:n,onSelect:o,depth:r+1},u))]})]})}function eo({files:t,groups:n,activeFile:o,onSelect:r}){return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((i,l)=>e.jsx(Wt,{group:i,activeFile:o,onSelect:r},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:t.map(i=>e.jsx(Lt,{file:i,isActive:o===i,onSelect:r},i))})}function to({type:t}){const n=Rt[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 no(t){if(!t)return null;const n=t.match(/^[^。]*。(.+)$/s);return n&&n[1].trim()?n[1].trim():null}function oo({section:t,onNavigate:n}){const{convert:o}=D(),[r,i]=p.useState(!1),l=!!t.summary,c=!!t.comment,a=!!t.additional_comment,s=t.author_info?null:no(t.content),x=l||c||a;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>x&&i(!r),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:x?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[x&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:r?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",flex:1},children:[t.book_title?`《${o(t.book_title)}》`:o(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Tt(t.n_juan),"卷"]})]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",flexShrink:0,whiteSpace:"nowrap"},children:o(t.author_info||t.author)}),s&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"50%",flexShrink:1},children:o(s)}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:`/${t.work_id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),r&&x&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:o(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:o(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:o(t.additional_comment)})]})]})]})}function ro({section:t}){const{convert:n}=D(),[o,r]=p.useState(!1),i=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>i&&r(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:i?"pointer":"default",userSelect:"none"},children:[e.jsx(to,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:n(t.title)}),i&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&i&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${Rt[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 io({section:t}){const{convert:n}=D();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 lo({sections:t,onNavigate:n}){const{convert:o}=D(),r=[];let i=null;for(const l of t)l.type==="类"?(i&&r.push(i),i={category:l.title,items:[]}):l.type==="书"?(i||(i={category:"",items:[]}),i.items.push(l)):l.type==="序"&&(i?(i.items.push(l),r.push(i),i=null):r.push({category:"",items:[l]}));return i&&r.push(i),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.map((l,c)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[l.category&&e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:o(l.category.replace(/^[^·]*·?/,""))}),l.items.map((a,s)=>{if(a.type==="序")return e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:o(a.content||"")},s);const x=a.content||a.title;return e.jsx("div",{children:n&&a.work_id?e.jsx("a",{href:`/${a.work_id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),g.stopPropagation(),n(a.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(a.title),children:o(x)}):o(x)},s)})]},c))})}function so({juan:t,searchQuery:n,onNavigate:o}){const{convert:r}=D(),[i,l]=p.useState("catalog"),c=p.useMemo(()=>{if(!n.trim())return t.sections;const s=n.trim().toLowerCase();return t.sections.filter(x=>{var g,u,h,d,v,I;return((g=x.title)==null?void 0:g.toLowerCase().includes(s))||((u=x.book_title)==null?void 0:u.toLowerCase().includes(s))||((h=x.author)==null?void 0:h.toLowerCase().includes(s))||((d=x.author_info)==null?void 0:d.toLowerCase().includes(s))||((v=x.summary)==null?void 0:v.toLowerCase().includes(s))||((I=x.content)==null?void 0:I.toLowerCase().includes(s))})},[t.sections,n]),a=c.filter(s=>s.type==="书").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:r(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(s=>e.jsx("button",{onClick:()=>l(s),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:s==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:i===s?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:i===s?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:s==="catalog"?"目錄":"原文"},s))}),e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:[a," 部书"]})]}),i==="raw"&&e.jsx(lo,{sections:c,onNavigate:o}),i==="catalog"&&c.map((s,x)=>s.type==="书"?e.jsx(oo,{section:s,onNavigate:o},x):s.type==="部"||s.type==="类"?e.jsx(ro,{section:s},x):e.jsx(io,{section:s},x)),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}const $t=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:i,onJuanChange:l,className:c,style:a})=>{const[s,x]=p.useState(null),[g,u]=p.useState(!1),[h,d]=p.useState(null),[v,I]=p.useState(null),[f,L]=p.useState(null),[b,_]=p.useState(!1),[y,T]=p.useState(""),w=i??v,S=p.useCallback(R=>{I(R),l==null||l(R)},[l]),m=t||s;p.useEffect(()=>{t&&(u(!1),d(null))},[t]),p.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let R=!1;return u(!0),d(null),o.getCollatedEditionIndex(n).then(j=>{R||(j?(x(j),!i&&j.juan_files.length>0&&S(j.juan_files[0])):d("未找到整理本数据"))}).catch(j=>{R||d(j instanceof Error?j.message:"加载失败")}).finally(()=>{R||u(!1)}),()=>{R=!0}},[t,n,o,i,S]),p.useEffect(()=>{const R=t||s;R&&R.juan_files&&R.juan_files.length>0&&!w&&S(R.juan_files[0])},[t,s,w,S]);const B=n||(m==null?void 0:m.work_id),C=p.useCallback(async R=>{if(!(!B||!(o!=null&&o.getCollatedJuan))){_(!0),L(null);try{const j=await o.getCollatedJuan(B,R);L(j)}catch{L(null)}finally{_(!1)}}},[B,o]);p.useEffect(()=>{w&&C(w)},[w,C]);const W=R=>{S(R),T("")};return g?e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})}):h?e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:c,style:a,children:[e.jsx("div",{style:{marginBottom:"16px"},children:e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:m.total_juan})," 卷"]})}),e.jsx(eo,{files:m.juan_files,groups:m.juan_groups,activeFile:w,onSelect:W}),e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:"搜索书名、作者...",value:y,onChange:R=>T(R.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),b?e.jsx(ge,{}):f?e.jsx(so,{juan:f,searchQuery:y,onNavigate:r}):w?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,m.references&&m.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),m.references.map((R,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),R.url?e.jsx("a",{href:R.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:R.title}):e.jsx("span",{children:R.title}),R.author&&e.jsxs("span",{children:[",",R.author]}),R.note&&e.jsxs("span",{children:["。",R.note]})]},j))]})]}):null},ao={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},co={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function po(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const Pt=({items:t,loading:n})=>n?e.jsx(ge,{}):t.length===0?e.jsx("div",{style:xo,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const r=ao[o.type],i=co[o.status];return e.jsxs("div",{style:uo,children:[e.jsxs("div",{style:go,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...rt,background:r.color},children:r.label}),e.jsx("span",{style:{...rt,background:i.color},children:i.label})]}),e.jsx("span",{style:fo,children:po(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:ho,children:[o.resourceId&&e.jsx("a",{href:`/book-index?id=${o.resourceId}`,style:it,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:it,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:bo,children:o.content}),o.reply&&e.jsxs("div",{style:mo,children:[e.jsx("div",{style:yo,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})}),xo={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},uo={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},go={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},rt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},fo={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ho={fontSize:"12px",marginBottom:"6px"},it={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},bo={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},mo={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},yo={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},vo=[{id:"FCNcSJbF77V",title:"欽定四庫全書·文淵閣本",description:"清·紀昀等編,藏於臺灣國立故宮博物院",group:"推薦叢編"},{id:"FCmH8kWxMhR",title:"二十四史百衲本",description:"民國·張元濟輯,商務印書館影印",group:"推薦叢編"},{id:"FCmYiXcTfuZ",title:"二十四史武英殿本",description:"清乾隆四年武英殿刻本",group:"推薦叢編"},{id:"FCmbeajrbJw",title:"武英殿聚珍版叢書",description:"清乾隆間武英殿活字印本",group:"推薦叢編"},{id:"GY4HvsY3w3u",title:"欽定四庫全書總目",description:"清·紀昀等編,200卷",group:"經典作品"},{id:"GY4JKKQaPYB",title:"欽定四庫全書簡明目錄",description:"清·紀昀等編,20卷",group:"經典作品"},{id:"GY4JM7j7yi7",title:"史記",description:"西漢·司馬遷,130卷",group:"經典作品"},{id:"GY3ty2LN9ro",title:"易經",description:"西周·周文王",group:"經典作品"}],Fe=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:i,feedbackApiUrl:l})=>{const c=A(),[a,s]=p.useState(null),[x,g]=p.useState([]),[u,h]=p.useState("recommend"),[d,v]=p.useState([]),[I,f]=p.useState(!1),L=r??u,b=C=>{h(C),i==null||i(C)},[_,y]=p.useState(!0),[T,w]=p.useState(null),[S,m]=p.useState(null);p.useEffect(()=>{if(!t.getAllEntries)return;let C=!1;return t.getAllEntries().then(W=>{if(C)return;const R=W.filter($=>$.type==="work").length,j=W.filter($=>$.type==="book").length,P=W.filter($=>$.type==="collection").length;s({works:R,books:j,collections:P})}).catch(()=>{}),()=>{C=!0}},[t]),p.useEffect(()=>{let C=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const R=await t.getRecommended();if(R!=null&&R.groups)return R.groups.flatMap(j=>j.items.map(P=>({...P,group:j.name})))}catch{}return vo})().then(async R=>{if(C)return;const j=R.filter($=>$.id);if(j.length===0){y(!1);return}const P=await Promise.all(j.map(async $=>{try{let H=null;if(t.getEntry)H=await t.getEntry($.id);else{const k=await t.getItem($.id);k&&(H={id:$.id,title:k.title||$.id,type:k.type||"work"})}if(H)return{...H,group:$.group,fallbackDescription:$.description}}catch{}return{id:$.id,title:$.title,type:$.id.startsWith("FC")?"collection":"work",group:$.group,fallbackDescription:$.description}}));C||(g(P.filter($=>$!==null)),y(!1))}),()=>{C=!0}},[t,o]),p.useEffect(()=>{if(!t.getResourceProgress)return;let C=!1;return t.getResourceProgress().then(W=>{C||w(W)}).catch(()=>{}),()=>{C=!0}},[t]),p.useEffect(()=>{if(!t.getSiteProgress)return;let C=!1;return t.getSiteProgress().then(W=>{C||m(W)}).catch(()=>{}),()=>{C=!0}},[t]),p.useEffect(()=>{if(!l||L!=="feedback")return;let C=!1;return f(!0),fetch(l).then(W=>W.json()).then(W=>{!C&&W.success&&v(W.items||[])}).catch(()=>{}).finally(()=>{C||f(!1)}),()=>{C=!0}},[l,L]);const B=C=>{switch(C){case"work":return"✍️";case"book":return"📖";case"collection":return"📚"}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Ie,{label:c.home.recommendTab,active:L==="recommend",onClick:()=>b("recommend")}),e.jsx(Ie,{label:c.home.catalogTab,active:L==="catalog",onClick:()=>b("catalog")}),e.jsx(Ie,{label:c.home.siteTab,active:L==="site",onClick:()=>b("site")}),l&&e.jsx(Ie,{label:c.home.feedbackTab,active:L==="feedback",onClick:()=>b("feedback")})]}),L==="recommend"&&e.jsx(jo,{recommended:x,loading:_,onNavigate:n,getIcon:B,t:c}),L==="catalog"&&e.jsx(So,{progress:T,t:c,onNavigate:n}),L==="site"&&e.jsx(wo,{progress:S,t:c,totalWorks:(a==null?void 0:a.works)??0}),L==="feedback"&&l&&e.jsx(Pt,{items:d,loading:I})]})})},Ie=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),jo=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:i})=>{if(n)return e.jsx(ge,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||i.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(s=>{const x=s.dynasty||s.author?`${s.dynasty?`〔${s.dynasty}〕`:""}${s.author||""}`:s.fallbackDescription;return e.jsxs("a",{href:`/${s.id}`,onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),o==null||o(s.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(s.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s.title,s.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:s.edition})]}),x&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x})]})]},s.id)})})]},c))})},So=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((a,s)=>a.priority-s.priority),i=["in_progress","done","todo"],l={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},c={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:i.map(a=>{const s=r.filter(x=>x.status===a);return s.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:c[a]}}),l[a]," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(x=>e.jsx(ko,{item:x,t:n,statusColor:c[a],onNavigate:o},x.id))})]},a)})})},ko=({item:t,t:n,statusColor:o,onNavigate:r})=>{const i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:`/${a}`,onClick:s=>{s.metaKey||s.ctrlKey||(s.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:s=>s.currentTarget.style.borderBottomStyle="solid",onMouseLeave:s=>s.currentTarget.style.borderBottomStyle="dashed",children: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?ke(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${i}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},wo=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ge,{});const r=[...t.resources].sort((s,x)=>s.priority-x.priority),i=r.filter(s=>s.imported>0),l=r.filter(s=>s.imported===0),c=i.reduce((s,x)=>Math.max(s,x.imported),0),a=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," (",a,"%)"]}),i.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#10b981"}}),n.home.statusInProgress," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(s=>e.jsx(lt,{item:s,t:n,totalWorks:o},s.id))})]}),l.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"#9ca3af"}}),n.home.statusTodo," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(s=>e.jsx(lt,{item:s,t:n,totalWorks:o},s.id))})]})]})},lt=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"#10b981",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},st="(max-width: 768px)";function Co(){const[t,n]=p.useState(()=>typeof window>"u"?!1:window.matchMedia(st).matches);return p.useEffect(()=>{const o=window.matchMedia(st),r=i=>n(i.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Io=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:i})=>{var H;const l=A(),{convert:c}=D(),a=Co(),[s,x]=p.useState(null),[g,u]=p.useState(null),[h,d]=p.useState(!1),[v,I]=p.useState("detail"),[f,L]=p.useState([]),[b,_]=p.useState(!1),[y,T]=p.useState(null),[w,S]=p.useState(!1),m=p.useCallback(async k=>{if(!t.getCollatedEditionIndex){T(null);return}S(!0);try{const E=await t.getCollatedEditionIndex(k);T(E)}catch{T(null)}finally{S(!1)}},[t]),B=p.useCallback(async k=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){L([]);return}_(!0);try{if(t.getCollectionCatalogs){const E=await t.getCollectionCatalogs(k);L(E||[])}else if(t.getCollectionCatalog){const E=await t.getCollectionCatalog(k);L(E?[{resource_id:"",data:E}]:[])}}catch{L([])}finally{_(!1)}},[t]),C=p.useCallback(async k=>{if(o){o(k);return}x(k),u(null),L([]),T(null),I("detail"),d(!0);try{const E=await t.getItem(k.id);E&&(u(E),E.type==="collection"?B(k.id):E.type==="work"&&E.has_collated&&m(k.id))}catch(E){console.error("加载详情失败:",E)}finally{d(!1)}},[t,o,B,m]),W=p.useCallback(async k=>{u(null),L([]),T(null),I("detail"),d(!0);try{const E=await t.getItem(k);E&&(u(E),x({id:k,title:E.title||k,type:E.type||"book"}),E.type==="collection"?B(k):E.type==="work"&&E.has_collated&&m(k))}catch(E){console.error("导航失败:",E)}finally{d(!1)}},[t,B,m]),R=(g==null?void 0:g.type)==="collection"&&(f.length>0||b)||(g==null?void 0:g.type)==="work"&&(y||w),j=a&&(h||g),P=p.useCallback(()=>{x(null),u(null),L([]),T(null),I("detail")},[]),$=e.jsx(e.Fragment,{children:h?e.jsx(ge,{}):g?e.jsxs(e.Fragment,{children:[(R||i)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>I("detail"),style:ze(v==="detail"),children:l.detailTab.basicInfo}),g.type==="collection"&&b&&f.length===0&&e.jsxs("button",{onClick:()=>{},style:ze(!1),children:[l.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),g.type==="collection"&&f.map(k=>e.jsx("button",{onClick:()=>I(`catalog:${k.resource_id}`),style:ze(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||w)&&e.jsxs("button",{onClick:()=>I("collated"),style:ze(v==="collated"),children:[l.detailTab.collatedEdition,w&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),i&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:i})]}),e.jsx("div",{style:{padding:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:v==="detail"?e.jsx(Oe,{data:g,transport:t,onNavigate:W}):v.startsWith("catalog:")?e.jsx(_t,{data:(H=f.find(k=>`catalog:${k.resource_id}`===v))==null?void 0:H.data,onNavigate:W}):v==="collated"?e.jsx($t,{index:y||void 0,workId:g.id,transport:t,onNavigate:W}):null})]}):e.jsx(Fe,{transport:t,onNavigate:W,recommendedIds:r})});return a?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:j?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:P,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",l.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Me,{transport:t,onEntryClick:C,hideModeIndicator:n}),!g&&e.jsx(Fe,{transport:t,onNavigate:W,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Me,{transport:t,onEntryClick:C,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function ze(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}const zo=({data:t,onNavigate:n,className:o,style:r})=>{var g;const i=A(),{convert:l}=D(),[c,a]=p.useState(((g=t.divisions[0])==null?void 0:g.name)??null),[s,x]=p.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:l(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[i.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",i.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",i.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",i.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(u=>e.jsx(_o,{division:u,expanded:c===u.name,onToggle:()=>a(c===u.name?null:u.name),expandedCat:s,onCatToggle:h=>x(s===h?null:h),onNavigate:n},u.name))})]})},_o=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:i,onNavigate:l})=>{const{convert:c}=D(),a=t.categories.reduce((s,x)=>{const g=x.stats||{zhulu:0,cunmu:0};return s+(g.zhulu||0)+(g.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:c(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(s=>{const x=`${t.name}/${s.name}`;return e.jsx(To,{category:s,expanded:r===x,onToggle:()=>i(x),onNavigate:l},s.name)})})]})},To=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var s,x,g,u;const{convert:i}=D(),l=((s=t.books)==null?void 0:s.zhulu)||[],c=((x=t.books)==null?void 0:x.cunmu)||[],a=(((g=t.stats)==null?void 0:g.zhulu)||l.length)+(((u=t.stats)==null?void 0:u.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:[i(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a," 部 ",n?"▲":"▼"]})]}),n&&(l.length>0||c.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&e.jsx(at,{label:"著錄",books:l,onNavigate:r}),c.length>0&&e.jsx(at,{label:"存目",books:c,onNavigate:r})]})]})},at=({label:t,books:n,onNavigate:o})=>{const{convert:r}=D(),[i,l]=p.useState(n.length<=20),c=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,s)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:`/${a.work_id}`,onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},s))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},le=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:i})=>{const l=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:Lo,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ro,children:l.action.save})]})]}),i]})},Ro={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Lo={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},q=({label:t,value:n,onChange:o,placeholder:r,disabled:i})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:l=>o(l.target.value),placeholder:r,disabled:i,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),ue=({value:t,onChange:n,placeholder:o})=>{const r=p.useRef(null);return p.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:i=>n(i.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Te=({children:t,color:n,style:o})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...o},children:t});function Eo(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const _e=({value:t,onChange:n,label:o})=>{const[r,i]=p.useState(!1),l=p.useRef(null),c=Eo(t||"");return p.useEffect(()=>{r&&l.current&&l.current.focus()},[r]),!r&&c?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ct,children:o}),e.jsxs("div",{onClick:()=>i(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:c.name}),e.jsx(Te,{children:c.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ct,children:o}),e.jsx("input",{ref:l,type:"text",value:t||"",onChange:a=>n(a.target.value),onBlur:()=>i(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},ct={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Bo(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Wo(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const At=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[i,l]=p.useState(null),c=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),l(t.length)},a=u=>{n(t.filter((h,d)=>d!==u)),i===u&&l(null)},s=(u,h,d)=>{const v=[...t];v[u]={...v[u],[h]:d},n(v)},x=(u,h)=>{const d=[...t];d[u]={...d[u],type:h,id:"",name:""},n(d),h==="bookID"&&o&&o(v=>{const I=[...t];I[u]={...I[u],id:v.id,name:v.title,type:"bookID"},n(I)})},g=u=>{o&&o(h=>{const d=[...t];d[u]={...d[u],id:h.id,name:h.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,h)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>l(i===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:i===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:u.name||`${r.editor.sourcePlaceholder} ${h+1}`}),u.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Bo(u.type),color:"white",borderRadius:"3px",fontWeight:500},children:Wo(u.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),i===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!u.type&&e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>x(h,"bookID"),style:{...dt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>x(h,"url"),style:{...dt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),u.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:pt,children:r.action.changeType})]}),u.id&&u.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:u.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:u.id})]}),e.jsx("button",{onClick:()=>g(h),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>g(h),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),u.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:pe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[h]={...d[h],type:"",id:"",name:""},n(d)},style:pt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:u.name,onChange:d=>s(h,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:u.id,onChange:d=>s(h,"id",d.target.value),placeholder:"https://...",style:fe})]})]}),u.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...pe,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:u.details,onChange:d=>s(h,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:u.position,onChange:d=>s(h,"position",d.target.value),placeholder:"如: 卷三, p.52",style:fe})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:u.version,onChange:d=>s(h,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:fe})]}),e.jsxs("div",{children:[e.jsx("label",{style:pe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:u.processor_version,onChange:d=>s(h,"processor_version",d.target.value),placeholder:"如: v0.1",style:fe})]})]})]})]})})]},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:r.action.addSource})]})]})},pe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},fe={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},dt={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},pt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Mt(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 Ft(t){return!t||t.length===0?"":JSON.stringify(t)}const Dt=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:i,belongsToWork:l,belongsToCollection:c,childWorks:a,childCollections:s,containedBooks:x,siblingBooks:g,onLinkEntity:u,onUnlinkEntity:h,onViewEntity:d,onCreateAndLink:v,onSaveRelations:I})=>{const f=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:f.section.relations})]}),I&&e.jsx("button",{onClick:I,style:$o,children:f.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{direction:"up",title:f.relation.belongsToWork,entity:l,onView:d,onUnlink:()=>h("workId"),onLink:()=>u("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(ve,{direction:"up",title:f.relation.containedInCollection,entity:c,onView:d,onUnlink:()=>h("collectionId"),onLink:()=>u("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(he,{direction:"horizontal",title:`${f.relation.siblingVersions} (${g.length})`,entities:g,onView:d,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(ve,{direction:"up",title:f.relation.parentWork,entity:r,onView:d,onUnlink:()=>h("parentWorkId"),onLink:()=>u("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}),a&&a.length>0&&e.jsx(he,{direction:"down",title:`${f.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>v("childWork","work",{parentWorkId:n}),addLabel:f.action.addSubWork,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),s&&s.length>0&&e.jsx(he,{direction:"down",title:`${f.relation.collectionImpl} (${s.length})`,entities:s,onView:d,onAdd:()=>v("childCollection","collection",{workId:n}),addLabel:f.action.addCollectionImpl,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),e.jsx(he,{direction:"down",title:`${f.relation.allVersions} (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:d,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(ve,{direction:"up",title:f.relation.correspondingWork,entity:l,onView:d,onUnlink:()=>h("workId"),onLink:()=>u("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(ve,{direction:"up",title:f.relation.parentCollection,entity:i,onView:d,onUnlink:()=>h("parentCollectionId"),onLink:()=>u("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(he,{direction:"down",title:`${f.relation.childCollections} (${(s==null?void 0:s.length)??0})`,entities:s||[],onView:d,onAdd:()=>v("childCollection","collection",{parentCollectionId:n}),addLabel:f.action.addSubCollection,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore}),e.jsx(he,{direction:"down",title:`${f.relation.containedBooks} (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:d,onAdd:()=>v("childBook","book",{collectionId:n}),addLabel:f.action.addBook,noneLabel:f.relation.none,expandMoreLabel:f.action.expandMore})]})]})]})},ve=({direction:t,title:n,entity:o,onView:r,onUnlink:i,onLink:l,onCreate:c,linkLabel:a,createLabel:s,notLinkedLabel:x,viewLabel:g,unlinkLabel:u})=>{const h=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:d}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ht(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(xt,{onClick:()=>r(o),title:g,children:"👁️"}),e.jsx(xt,{onClick:i,title:u,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:x}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(De,{onClick:l,children:a}),e.jsx(De,{onClick:c,primary:!0,children:s})]})]})},he=({direction:t,title:n,entities:o,onView:r,onAdd:i,addLabel:l,noneLabel:c,expandMoreLabel:a})=>{const[s,x]=p.useState(!1),g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",u=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=s?o:o.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:u}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(d=>e.jsxs("div",{onClick:()=>r(d),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Ht(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.length>5&&!s&&e.jsxs("div",{onClick:()=>x(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:c}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(De,{onClick:i,primary:!0,children:["+ ",l]})})]})},xt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:i=>{i.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),De=({onClick:t,primary:n,children:o})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:o});function Ht(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const $o={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"},Ot=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:i,onCreate:l,searchResults:c,onSearch:a,isLoading:s,excludeId:x})=>{const[g,u]=p.useState(""),h=x?c.filter(f=>f.id!==x):c;p.useEffect(()=>{t&&(u(""),a(""))},[t]);const d=f=>{u(f),a(f)};if(!t)return null;const v=n==="work"?"作品":n==="book"?"书籍":"丛编",I=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Po,children:e.jsxs("div",{style:Ao,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),e.jsx("button",{onClick:i,style:Mo,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:g,onChange:f=>d(f.target.value),placeholder:`搜索${v}名称或 ID...`,autoFocus:!0,style:Fo})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:s?e.jsx("div",{style:Be,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(f=>e.jsxs("div",{onClick:()=>r(f),style:Do,children:[e.jsx("span",{style:{fontSize:"16px"},children:I}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[f.title,f.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:f.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[f.id,f.author&&` · ${f.author}`,f.dynasty&&` · ${f.dynasty}`]})]})]},f.id))}):g?e.jsxs("div",{style:Be,children:["未找到匹配的",v]}):e.jsxs("div",{style:Be,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:Ho,children:["创建新",v,"并关联"]})]})]})})},Po={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},Ao={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)"},Mo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Fo={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"},Do={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Be={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Ho={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ut={work:"作品",book:"书籍",collection:"丛编"},Oo={work:"📜",book:"📖",collection:"📚"},Vt=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:i,onCancel:l})=>{const[c,a]=p.useState(""),s=p.useRef(null);p.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var h,d;(h=s.current)==null||h.focus(),(d=s.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const x=h=>{h.key==="Enter"&&c.trim()?g():h.key==="Escape"&&l()},g=()=>{c.trim()&&i(c.trim(),{...r,title:c.trim()})};if(!t)return null;const u=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${ut[n]}`}};return e.jsx("div",{style:Vo,onClick:h=>{h.target===h.currentTarget&&l()},children:e.jsxs("div",{style:No,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:Oo[n]}),e.jsx("span",{children:u()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:s,type:"text",value:c,onChange:h=>a(h.target.value),onKeyDown:x,placeholder:`请输入${ut[n]}名称...`,style:Uo})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:l,style:Yo,children:"取消"}),e.jsx("button",{onClick:g,disabled:!c.trim(),style:{...Go,opacity:c.trim()?1:.6,cursor:c.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},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:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Uo={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"},Yo={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Go={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Ko(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Nt(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Jo(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Ut=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:i,showCreateButton:l=!1,createButtonText:c,onSelect:a,onCancel:s,onCreate:x,onSearch:g})=>{const[u,h]=p.useState(""),[d,v]=p.useState([]),[I,f]=p.useState(!1),[L,b]=p.useState("recent");p.useEffect(()=>{t&&(h(""),v([]),b(r.length>0?"recent":"search"))},[t,r.length]),p.useEffect(()=>{if(!u.trim()){v([]);return}const m=setTimeout(async()=>{f(!0);try{v(await g(u,o))}catch{v([])}finally{f(!1)}},300);return()=>clearTimeout(m)},[u,o,g]);const _=p.useCallback(m=>{h(m.target.value),m.target.value.trim()&&b("search")},[]),y=p.useCallback(m=>i?m.filter(B=>B.id!==i):m,[i]);if(!t)return null;const T=n||(o==="all"?"选择实体":`选择${Nt(o)}`),w=y(r),S=y(d);return e.jsx("div",{style:Xo,children:e.jsxs("div",{style:qo,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:T}),e.jsx("button",{onClick:s,style:Qo,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:u,onChange:_,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:er}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),I&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(gt,{active:L==="recent",onClick:()=>b("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(gt,{active:L==="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:L==="recent"&&w.length>0?e.jsx(ft,{entities:w,onSelect:a}):u.trim()?I?e.jsx(We,{message:"搜索中..."}):S.length>0?e.jsx(ft,{entities:S,onSelect:a}):e.jsx(We,{message:"未找到匹配的结果"}):e.jsx(We,{message:"输入关键词开始搜索"})}),l&&x&&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:x,style:tr,children:c||"创建新实体"})]})]})})},gt=({active:t,onClick:n,children:o})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:o}),ft=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Zo,{entity:o,onClick:()=>n(o)},o.id))}),Zo=({entity:t,onClick:n})=>{const[o,r]=p.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Ko(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:Jo(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Nt(t.type)})]})},We=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Xo={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},qo={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)"},Qo={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},er={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"},tr={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},nr={work:"#4caf50",collection:"#2196f3",book:"#ff9800"},or={work:"📜",collection:"📚",book:"📖"},Yt=({data:t,onChange:n,onSave:o,transport:r,onNavigate:i,showDelete:l,onDelete:c,onAskAI:a,renderSectionActions:s,onDownloadResource:x,downloadStatuses:g,relations:u,onRelationsChange:h})=>{var Ce;const d=A(),[v,I]=p.useState(!1),[f,L]=p.useState("work"),[b,_]=p.useState(""),[y,T]=p.useState(""),[w,S]=p.useState([]),[m,B]=p.useState(!1),[C,W]=p.useState(!1),[R,j]=p.useState("work"),[P,$]=p.useState(""),[H,k]=p.useState(),[E,U]=p.useState(!1),[V,F]=p.useState(null),[ne,te]=p.useState([]);p.useRef(null);const oe=t.type,re=oe==="work",xe=oe==="collection",ce=oe==="book",Y=p.useCallback((z,X)=>{n({...t,[z]:X})},[t,n]),be=p.useCallback((z,X)=>{_(z),L(X),T(d.editor.selectToLink+d.indexType[X]),S([]),I(!0)},[d]),we=p.useCallback(z=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,z)},[r,t.id]),Le=p.useCallback(z=>{i==null||i(z.id,z.type)},[i]),M=p.useCallback((z,X,de)=>{const Jt={...de,author:(de==null?void 0:de.author)||t.author,dynasty:(de==null?void 0:de.dynasty)||t.dynasty};j(X),$(z),k(Jt),W(!0)},[t.author,t.dynasty]),K=p.useCallback((z,X)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,P,{type:R,title:z,inheritData:X}),W(!1)},[r,t.id,P,R]),G=p.useCallback(z=>{if(!z.trim()){S([]);return}B(!0),r!=null&&r.searchEntities&&r.searchEntities(z,f).then(X=>{S(X),B(!1)}).catch(()=>{S([]),B(!1)})},[r,f]),J=p.useCallback(z=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,z.id),I(!1)},[r,t.id,b]),Q=p.useCallback(()=>{o()},[o]),Z=p.useCallback(z=>{F(()=>z),U(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(te).catch(()=>{})},[r]),O=p.useCallback((z,X)=>r!=null&&r.searchEntities?r.searchEntities(z,X==="all"?void 0:X):Promise.resolve([]),[r]),Ve=p.useCallback(z=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(z),te(X=>[z,...X.filter(de=>de.id!==z.id)].slice(0,10)),V==null||V(z),U(!1),F(null)},[r,V]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:or[oe]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Te,{children:t.id}),e.jsx(Te,{color:nr[oe],children:d.indexType[oe]})]})}),e.jsx(le,{title:d.section.basicInfo,onSave:o,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:s==null?void 0:s("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(_e,{label:re?d.editor.workTitle:xe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:z=>Y("title",z)}),ce&&e.jsx(_e,{label:d.editor.belongsToWork,value:t.workName||"",onChange:z=>Y("workName",z)}),e.jsx(q,{label:d.editor.authorLabel,value:t.author||"",onChange:z=>Y("author",z)}),e.jsx(q,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:z=>Y("dynasty",z)}),(ce||xe)&&e.jsx(_e,{label:d.editor.containedIn,value:t.collection||"",onChange:z=>Y("collection",z)}),(ce||xe)&&e.jsx(q,{label:d.editor.holderLabel,value:t.holder||"",onChange:z=>Y("holder",z)}),(ce||xe)&&e.jsx(q,{label:ce?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:z=>Y("pages",z)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(q,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:z=>Y("firstImage",z)})})]})}),e.jsx(le,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(ue,{value:t.description||"",onChange:z=>Y("description",z),placeholder:d.editor.descriptionPlaceholder})}),(((Ce=t.additional_works)==null?void 0:Ce.length)||0)>0&&e.jsx(le,{title:d.section.additionalWorks,onSave:o,children:e.jsx(rr,{items:t.additional_works||[],onChange:z=>Y("additional_works",z)})}),e.jsx(le,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(ir,{items:t.indexed_by||[],onChange:z=>Y("indexed_by",z)})}),e.jsx(le,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx($e,{items:t.resources||[],onChange:z=>Y("resources",z),onDownload:x,downloadStatuses:g,filterType:"text"})}),e.jsx(le,{title:d.section.imageResources,onSave:o,children:e.jsx($e,{items:t.resources||[],onChange:z=>Y("resources",z),onDownload:x,downloadStatuses:g,filterType:"image"})}),e.jsx(le,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(At,{items:Mt(t.sources||""),onChange:z=>Y("sources",Ft(z)),onOpenEntityPicker:Z})}),(ce||xe)&&e.jsx(le,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(ue,{value:t.provenance||"",onChange:z=>Y("provenance",z),placeholder:d.editor.provenancePlaceholder})}),ce&&e.jsx(le,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(ue,{value:t.otherEditions||"",onChange:z=>Y("otherEditions",z),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(Dt,{entityType:oe,entityId:t.id,entityTitle:t.title,parentWork:u==null?void 0:u.parentWork,parentCollection:u==null?void 0:u.parentCollection,belongsToWork:u==null?void 0:u.belongsToWork,belongsToCollection:u==null?void 0:u.belongsToCollection,childWorks:u==null?void 0:u.childWorks,childCollections:u==null?void 0:u.childCollections,containedBooks:u==null?void 0:u.containedBooks,siblingBooks:u==null?void 0:u.siblingBooks,onLinkEntity:be,onUnlinkEntity:we,onViewEntity:Le,onCreateAndLink:M,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:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick: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:d.editor.deleteEntity})]}),e.jsx(Ot,{isOpen:v,entityType:f,title:y,onSelect:J,onCancel:()=>I(!1),onCreate:()=>{I(!1),M(b,f)},searchResults:w,onSearch:G,isLoading:m,excludeId:t.id}),e.jsx(Vt,{isOpen:C,entityType:R,relationField:P,inheritData:H,onConfirm:K,onCancel:()=>W(!1)}),e.jsx(Ut,{isOpen:E,title:d.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:Ve,onCancel:()=>{U(!1),F(null)},onSearch:O})]})};function rr({items:t,onChange:n}){const o=A(),r=(c,a,s)=>{const x=t.map((g,u)=>u===c?{...g,[a]:s}:g);n(x)},i=c=>n(t.filter((a,s)=>s!==c)),l=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((c,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(q,{label:o.editor.bookNameLabel,value:c.book_title,onChange:s=>r(a,"book_title",s)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(q,{label:o.label.juanCount,value:c.n_juan!=null?String(c.n_juan):"",onChange:s=>r(a,"n_juan",s&&parseInt(s,10)||void 0)})}),e.jsx("button",{onClick:()=>i(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),e.jsx("button",{onClick:l,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function ir({items:t,onChange:n}){const o=A(),[r,i]=p.useState(null),l=(s,x,g)=>{const u=t.map((h,d)=>d===s?{...h,[x]:g||void 0}:h);n(u)},c=s=>{n(t.filter((x,g)=>g!==s)),r===s&&i(null)},a=()=>{n([...t,{source:""}]),i(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((s,x)=>{const g=r===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>i(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:s.source||o.editor.unnamedSource}),s.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:s.source_bid}),e.jsx("button",{onClick:u=>{u.stopPropagation(),c(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&(s.title_info||s.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[s.title_info,s.title_info&&s.author_info&&" — ",s.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:s.source,onChange:u=>l(x,"source",u)}),e.jsx(q,{label:o.label.sourceBid,value:s.source_bid||"",onChange:u=>l(x,"source_bid",u)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(q,{label:o.label.titleInfo,value:s.title_info||"",onChange:u=>l(x,"title_info",u)}),e.jsx(q,{label:o.label.authorInfo,value:s.author_info||"",onChange:u=>l(x,"author_info",u)})]}),e.jsx(q,{label:o.label.edition,value:s.edition||"",onChange:u=>l(x,"edition",u)}),e.jsx(ue,{value:s.summary||"",onChange:u=>l(x,"summary",u),placeholder:o.editor.summaryPlaceholder}),e.jsx(ue,{value:s.comment||"",onChange:u=>l(x,"comment",u),placeholder:o.editor.commentPlaceholder}),e.jsx(ue,{value:s.additional_comment||"",onChange:u=>l(x,"additional_comment",u),placeholder:o.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:a,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 Gt(t){var a,s,x,g,u,h,d;const n=((s=(a=t.authors)==null?void 0:a[0])==null?void 0:s.name)||"",o=((x=t.publication_info)==null?void 0:x.year)||"",r=((g=t.current_location)==null?void 0:g.name)||"",i=(u=t.page_count)!=null&&u.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:r,pages:i,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 I=v.related_works.find(f=>f.relation==="part_of");I&&(c.parentWorkId=I.id,c.parentWorkName=I.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=(d=v.contained_in[0])==null?void 0:d.id)}return c}function lr(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by};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 sr=t=>{const{data:n,id:o,transport:r,mode:i="view",onModeChange:l,onChange:c,onSave:a,onDelete:s,onNavigate:x,renderLink:g,onAskAI:u,renderSectionActions:h,onDownloadResource:d,downloadStatuses:v,relations:I,onRelationsChange:f,headerExtra:L,className:b,style:_}=t;A();const[y,T]=p.useState(i),w=l?i:y;p.useEffect(()=>{i!==y&&T(i)},[i]);const S=p.useCallback(()=>{const P=w==="view"?"edit":"view";l?l(P):T(P)},[w,l]),[m,B]=p.useState(null);p.useEffect(()=>{o&&r&&r.getItem(o).then(P=>{P&&B(P)})},[o,r]);const C=n||m,W=p.useMemo(()=>C?Gt(C):null,[C]),R=l||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,j=e.jsxs(e.Fragment,{children:[R,L]});return!C&&!W?e.jsx(ge,{}):w==="view"?e.jsx(Oe,{data:C,transport:r,onNavigate:x?P=>x(P):void 0,renderLink:g,headerExtra:j,className:b,style:_}):W?e.jsxs("div",{className:b,style:_,children:[j&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:j}),e.jsx(Yt,{data:W,onChange:c||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:x,showDelete:!!s,onDelete:s,onAskAI:u,renderSectionActions:h,onDownloadResource:d,downloadStatuses:v,relations:I,onRelationsChange:f})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},ht=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Kt=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[i,l]=p.useState(null),[c,a]=p.useState(""),[s,x]=p.useState("idle"),[g,u]=p.useState(""),h=p.useRef(null);p.useEffect(()=>{t&&(l(null),a(""),x("idle"),u(""))},[t]),p.useEffect(()=>{i&&setTimeout(()=>{var f;return(f=h.current)==null?void 0:f.focus()},100)},[i]),p.useEffect(()=>{if(s==="success"){const f=setTimeout(n,2e3);return()=>clearTimeout(f)}},[s,n]),p.useEffect(()=>{if(!t)return;const f=L=>{L.key==="Escape"&&n()};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[t,n]);const d=async()=>{if(!(!i||!c.trim())){x("submitting"),u("");try{await o({type:i,content:c.trim()}),x("success")}catch(f){x("error"),u(f instanceof Error?f.message:"提交失败,请稍后重试")}}};if(!t)return null;const v=i&&c.trim()&&s!=="submitting",I=ht.find(f=>f.value===i);return e.jsx("div",{style:ar,onClick:f=>{f.target===f.currentTarget&&n()},children:e.jsxs("div",{style:cr,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:dr,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:pr,"aria-label":"关闭",children:"✕"})]}),s==="success"?e.jsxs("div",{style:hr,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:ht.map(f=>e.jsxs("button",{onClick:()=>l(f.value),style:{...xr,...i===f.value?ur:{}},children:[e.jsx("span",{children:f.icon})," ",f.label]},f.value))}),e.jsx("textarea",{ref:h,value:c,onChange:f=>a(f.target.value),placeholder:(I==null?void 0:I.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!i||s==="submitting",style:{...gr,opacity:i?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[c.length," / 2000"]}),s==="error"&&e.jsx("div",{style:br,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!v,style:{...fr,opacity:v?1:.6,cursor:v?"pointer":"not-allowed"},children:s==="submitting"?"提交中...":"提交反馈"})})]})]})})},ar={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},cr={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)"},dr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},pr={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},xr={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"},ur={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},gr={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"},fr={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},hr={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},br={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},mr=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,i]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>i(!0),style:{...yr,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(Kt,{isOpen:r,onClose:()=>i(!1),onSubmit:t,feedbackListUrl:o})]})},yr={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},bt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],vr=({onSubmit:t})=>{const[n,o]=p.useState("bug"),[r,i]=p.useState(""),[l,c]=p.useState("idle"),[a,s]=p.useState(""),x=p.useRef(null);p.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=x.current)==null?void 0:d.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){c("submitting"),s("");try{await t({type:n,content:r.trim()}),c("success"),i(""),o("bug")}catch(d){c("error"),s(d instanceof Error?d.message:"提交失败,请稍后重试")}}},u=n&&r.trim()&&l!=="submitting",h=bt.find(d=>d.value===n);return l==="success"?e.jsx("div",{style:mt,children:e.jsxs("div",{style:Cr,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>c("idle"),style:Ir,children:"继续提交"})]})}):e.jsxs("div",{style:mt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:bt.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...jr,...n===d.value?Sr:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:x,value:r,onChange:d=>i(d.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:l==="submitting",style:{...kr}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:g,disabled:!u,style:{...wr,opacity:u?1:.6,cursor:u?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交"})]}),l==="error"&&e.jsx("div",{style:zr,children:a})]})},mt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},jr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Sr={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},kr={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},wr={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Cr={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Ir={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},zr={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},_r=({style:t})=>{const n=p.useContext(Se);if(!n)return null;const{locale:o,setLocale:r}=n,i=o==="zh-Hant",l=()=>r(i?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:l,title:i?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:i?"var(--bim-primary, #0078d4)":void 0,fontWeight:i?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:i?void 0:"var(--bim-primary, #0078d4)",fontWeight:i?400:700},children:"简"})]})};exports.BidLink=N.BidLink;exports.BookIndexError=N.BookIndexError;exports.BookIndexManager=N.BookIndexManager;exports.BookIndexStorage=N.BookIndexStorage;exports.BundleStorage=N.BundleStorage;exports.ConfigError=N.ConfigError;exports.GithubStorage=N.GithubStorage;exports.IdGenerationError=N.IdGenerationError;exports.IdGenerator=N.IdGenerator;exports.LocalStorage=N.LocalStorage;exports.MigrationError=N.MigrationError;exports.StorageError=N.StorageError;exports.base58Decode=N.base58Decode;exports.base58Encode=N.base58Encode;exports.buildId=N.buildId;exports.decodeIdString=N.decodeIdString;exports.extractIdFromUrl=N.extractIdFromUrl;exports.extractStatus=N.extractStatus;exports.extractType=N.extractType;exports.normalizeCatalog=N.normalizeCatalog;exports.parseId=N.parseId;exports.validateResource=N.validateResource;exports.Badge=Te;exports.CollatedEdition=$t;exports.CollectionCatalog=_t;exports.CreateEntityDialog=Vt;exports.EntityPickerDialog=Ut;exports.EntitySelector=Ot;exports.FeedbackButton=mr;exports.FeedbackDialog=Kt;exports.FeedbackForm=vr;exports.FeedbackList=Pt;exports.FormInput=q;exports.FormTextArea=ue;exports.HomePage=Fe;exports.IndexApp=Io;exports.IndexBrowser=Me;exports.IndexDetail=Oe;exports.IndexEditor=Yt;exports.IndexView=sr;exports.LocaleContext=Se;exports.LocaleProvider=cn;exports.LocaleToggle=_r;exports.ModeIndicator=St;exports.RelationPanel=Dt;exports.ResourceEditor=$e;exports.ResourceList=He;exports.SearchInput=kt;exports.Section=le;exports.SmartBidInput=_e;exports.SourceEditor=At;exports.WorkCatalog=zo;exports.detailToEditor=Gt;exports.editorToDetail=lr;exports.formatTemplate=ke;exports.parseSourceString=Mt;exports.stringifySources=Ft;exports.useConvert=D;exports.useT=A;
|