@fgbg/mdocs 1.4.1 → 2.0.0
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/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +19 -0
- package/dist/server/agent/Agent/run-manager.js +1 -0
- package/dist/server/agent/Agent/run-manager.js.map +1 -1
- package/dist/server/agent/Agent/run-pi-agent.js +22 -7
- package/dist/server/agent/Agent/run-pi-agent.js.map +1 -1
- package/dist/server/agent/Agent/run.js +29 -4
- package/dist/server/agent/Agent/run.js.map +1 -1
- package/dist/server/agent/Agent/session-manager.js +45 -5
- package/dist/server/agent/Agent/session-manager.js.map +1 -1
- package/dist/server/agent/Agent/system-prompt.js +5 -3
- package/dist/server/agent/Agent/system-prompt.js.map +1 -1
- package/dist/server/agent/Agent/tools-documents.js +13 -4
- package/dist/server/agent/Agent/tools-documents.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-template.js +2 -1
- package/dist/server/agent/Agent/tools-template.js.map +1 -1
- package/dist/server/agent/Config/config.test.js +21 -0
- package/dist/server/agent/Config/config.test.js.map +1 -1
- package/dist/server/agent/attachments/capabilities.js +52 -0
- package/dist/server/agent/attachments/capabilities.js.map +1 -0
- package/dist/server/agent/attachments/capabilities.test.js +33 -0
- package/dist/server/agent/attachments/capabilities.test.js.map +1 -0
- package/dist/server/agent/attachments/index.js +6 -0
- package/dist/server/agent/attachments/index.js.map +1 -0
- package/dist/server/agent/attachments/inject.js +67 -0
- package/dist/server/agent/attachments/inject.js.map +1 -0
- package/dist/server/agent/attachments/inject.test.js +41 -0
- package/dist/server/agent/attachments/inject.test.js.map +1 -0
- package/dist/server/agent/attachments/object-fs.js +44 -0
- package/dist/server/agent/attachments/object-fs.js.map +1 -0
- package/dist/server/agent/attachments/parse/image.js +22 -0
- package/dist/server/agent/attachments/parse/image.js.map +1 -0
- package/dist/server/agent/attachments/parse/pdf.js +19 -0
- package/dist/server/agent/attachments/parse/pdf.js.map +1 -0
- package/dist/server/agent/attachments/parse/plain-text.js +18 -0
- package/dist/server/agent/attachments/parse/plain-text.js.map +1 -0
- package/dist/server/agent/attachments/prepare-turn.js +32 -0
- package/dist/server/agent/attachments/prepare-turn.js.map +1 -0
- package/dist/server/agent/attachments/store.js +120 -0
- package/dist/server/agent/attachments/store.js.map +1 -0
- package/dist/server/agent/attachments/tools-read-attachment.js +95 -0
- package/dist/server/agent/attachments/tools-read-attachment.js.map +1 -0
- package/dist/server/agent/attachments/types.js +6 -0
- package/dist/server/agent/attachments/types.js.map +1 -0
- package/dist/server/agent/attachments/upload-filename.test.js +39 -0
- package/dist/server/agent/attachments/upload-filename.test.js.map +1 -0
- package/dist/server/agent/attachments/upload.js +11 -0
- package/dist/server/agent/attachments/upload.js.map +1 -0
- package/dist/server/app.js +9 -1
- package/dist/server/app.js.map +1 -1
- package/dist/server/config/index.js +1 -0
- package/dist/server/config/index.js.map +1 -1
- package/dist/server/db/repositories/agent-attachment.repo.js +51 -0
- package/dist/server/db/repositories/agent-attachment.repo.js.map +1 -0
- package/dist/server/db/repositories/document.repo.js +9 -9
- package/dist/server/db/repositories/document.repo.js.map +1 -1
- package/dist/server/db/schema.js +64 -3
- package/dist/server/db/schema.js.map +1 -1
- package/dist/server/documents/document.service.js +2 -3
- package/dist/server/documents/document.service.js.map +1 -1
- package/dist/server/documents/graph.integration.test.js +1 -0
- package/dist/server/documents/graph.integration.test.js.map +1 -1
- package/dist/server/documents/tree-and-folders.test.js +1 -0
- package/dist/server/documents/tree-and-folders.test.js.map +1 -1
- package/dist/server/domains/change-domain-permission.test.js +12 -0
- package/dist/server/domains/change-domain-permission.test.js.map +1 -1
- package/dist/server/routes/agent.routes.js +85 -2
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/server/routes/visitors.routes.js +2 -0
- package/dist/server/routes/visitors.routes.js.map +1 -1
- package/dist/server/search/document-index-manager.js +13 -4
- package/dist/server/search/document-index-manager.js.map +1 -1
- package/dist/server/search/document-index-manager.test.js +14 -3
- package/dist/server/search/document-index-manager.test.js.map +1 -1
- package/dist/server/search/embedding-store.js +9 -0
- package/dist/server/search/embedding-store.js.map +1 -1
- package/dist/server/search/embedding-store.test.js +27 -3
- package/dist/server/search/embedding-store.test.js.map +1 -1
- package/dist/shared/file-type-policy.js +1 -1
- package/dist/shared/file-type-policy.js.map +1 -1
- package/dist/shared/file-type-policy.test.js +2 -1
- package/dist/shared/file-type-policy.test.js.map +1 -1
- package/dist/web/assets/AgentChatPanel-Bhv57WUW.js +47 -0
- package/dist/web/assets/{AiWriteWorkbench-ob4AeDFt.js → AiWriteWorkbench-DOse9-oQ.js} +4 -4
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-BuZCaqLT.js → DiagramEditor-NtNY3sZL-D7sapmVz.js} +1 -1
- package/dist/web/assets/{DocChrome-DwSYxHOP.js → DocChrome-Dj5rSAvl.js} +1 -1
- package/dist/web/assets/{DocumentEditor-C_TFaCan.js → DocumentEditor-BTxsH3UT.js} +1 -1
- package/dist/web/assets/{HtmlEditor-CYPTi1_L.js → HtmlEditor-OEfTnjjz.js} +1 -1
- package/dist/web/assets/MergeView-CGz2CWUZ.js +10 -0
- package/dist/web/assets/{PlaygroundPage-Bt53Sr06.js → PlaygroundPage-BsekHU2o.js} +1 -1
- package/dist/web/assets/{SettingsPage-C2SYz-8K.js → SettingsPage-cVFmyADe.js} +5 -5
- package/dist/web/assets/SheetEditor-1LMR2jA1.js +26 -0
- package/dist/web/assets/SheetEditor-DJOs2u-u.css +1 -0
- package/dist/web/assets/{Toolbar-LRioFemr.js → Toolbar-CPIpQgP1.js} +1 -1
- package/dist/web/assets/VisitorPickerModal-aRuuDomz.js +6 -0
- package/dist/web/assets/{check-65pb-o1o.js → check-NyVbPIj8.js} +1 -1
- package/dist/web/assets/{copy-BT35-MU9.js → copy-C_H9wgwB.js} +1 -1
- package/dist/web/assets/file-type-policy-5jFXMeIz.js +1 -0
- package/dist/web/assets/index-CervldVc.css +1 -0
- package/dist/web/assets/{index-92xZ1zjh.js → index-Kp5r4mc7.js} +48 -48
- package/dist/web/assets/{italic-BmGXEOKX.js → italic-BqrahN0G.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-DeIPntMM.js → meta2dEngine-BD2XbzaV-CUKxedXW.js} +1 -1
- package/dist/web/assets/{plus-Ss1czARp.js → plus-D8tCpRfA.js} +1 -1
- package/dist/web/assets/{react-DHtvOuT-.js → react-DsdrF7vh.js} +3 -3
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/AgentChatPanel-BMOzVvwA.js +0 -42
- package/dist/web/assets/MergeView-FPF3k11v.js +0 -10
- package/dist/web/assets/SheetEditor-BOF-OgqU.js +0 -26
- package/dist/web/assets/SheetEditor-BPTMQ2s5.css +0 -1
- package/dist/web/assets/VisitorPickerModal-iK2QsYfY.js +0 -6
- package/dist/web/assets/file-type-policy-aRrzC4LZ.js +0 -1
- package/dist/web/assets/index-DE_nAopH.css +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import{r as t,j as e}from"./react-vendor-BVS1XoFi.js";import{o as Ae,c as le,a0 as
|
|
1
|
+
import{r as t,j as e}from"./react-vendor-BVS1XoFi.js";import{o as Ae,c as le,a0 as $s,a1 as Vs,W as _s,l as de,a2 as Ws,a3 as qs,a4 as se,a5 as We,a6 as Gs,a7 as Hs,a8 as Js,a as Qs,d as ts,a9 as gs,aa as fs,ab as Zs,ac as Ys,ad as Xs,ae as et,af as st,ag as xs,ah as $e,ai as tt,aj as at,ak as nt,X as it,al as lt,am as ct,f as ys,an as ot,ao as rt,ap as dt,aq as mt,ar as ut,as as Ie,M as bs,at as ht,au as pt,av as gt,aw as ft,ax as xt,ay as yt,az as bt,aA as js,aB as jt,aC as Nt,aD as vt,aE as kt,aF as St,S as wt,aG as Ct,aH as Dt,aI as It,aJ as Tt,aK as At,aL as Mt,aM as as,V as Pt,aN as Et,aO as Rt,aP as Ft,r as Lt,j as zt,aQ as Bt,k as Kt,m as Ot}from"./index-Kp5r4mc7.js";import{V as Ns,a as Ut,U as $t}from"./VisitorPickerModal-aRuuDomz.js";import{C as Vt}from"./check-NyVbPIj8.js";import{ai as Ve,aj as _t,ak as Wt,al as qt,am as Gt,an as Ht,ao as ns,ap as Jt,aq as is}from"./ui-CEFkTVnG.js";import"./diagram-BF8g9yg4.js";import"./motion-BAXVQJfN.js";/**
|
|
2
2
|
* @license lucide-react v0.562.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const Qt=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],Zt=Ae("cloud-upload",Qt);/**
|
|
7
7
|
* @license lucide-react v0.562.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const Yt=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],Xt=Ae("layout-grid",Yt);/**
|
|
12
12
|
* @license lucide-react v0.562.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const ea=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]],sa=Ae("scan-search",ea);/**
|
|
17
17
|
* @license lucide-react v0.562.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const ea=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],sa=Ae("sparkles",ea);function ta({draft:a,onClose:s,onSuccess:p}){const{t:u,lang:b}=le(),[R,f]=t.useState([]),[w,N]=t.useState(a.domainId??""),[h,S]=t.useState([]),[A,I]=t.useState(""),[c,v]=t.useState(`${a.displayName||"untitled"}_recovered.md`),[g,x]=t.useState(!1),[C,z]=t.useState(null),j=t.useRef(null),B=t.useRef(!0);t.useEffect(()=>(B.current=!0,()=>{B.current=!1}),[]),t.useEffect(()=>{Os().then(k=>{B.current&&f(k)})},[]),t.useEffect(()=>{w&&(S([]),I(""),Us(w).then(k=>{B.current&&S(k)}).catch(()=>{B.current&&S([])}))},[w]),t.useEffect(()=>{const k=window.setTimeout(()=>{var K;return(K=j.current)==null?void 0:K.focus()},0);return()=>window.clearTimeout(k)},[]),t.useEffect(()=>{const k=K=>{K.key==="Escape"&&s()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[s]);function O(k,K){for(const D of k){if(D.type==="folder"&&D.path===K)return D.documentId;if(D.type==="folder"){const E=O(D.children,K);if(E)return E}}return null}async function L(k){k.preventDefault(),x(!0),z(null);const K=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),D=K.endsWith(".md")?K:K+".md",E=D.replace(/\.md$/i,"");try{const m=A?`${A}/${D}`:D,o=A?O(h,A)??void 0:void 0;await _s({fileName:D,displayName:E,content:a.content,domainId:w,parentId:o}),p()}catch(m){z(se(u,m))}finally{x(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:k=>{k.target===k.currentTarget&&!g&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:a.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:L,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),R.length>0&&e.jsx($s,{domains:R,value:w,onChange:N,onDomainsChange:f,ariaLabel:u("domainLabel"),localizeName:k=>de(k,b,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(Vs,{nodes:h,activeDocumentId:null,selectedParentPath:A,onOpen:()=>{},onOpenFolder:k=>I(k),onContextMenu:()=>{},onDeselect:()=>I("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:j,value:c,onChange:k=>v(k.target.value),placeholder:"recovered.md",maxLength:200,disabled:g})]}),C&&e.jsx("div",{className:"mdocs-dialog-error",children:C}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!g&&s(),disabled:g,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:g,children:u(g?"creating":"create")})]})]})]})})}function aa({onPublish:a,onClose:s,onCountChange:p,onRecover:u}){const{t:b}=le(),[R,f]=t.useState([]),[w,N]=t.useState(new Set),[h,S]=t.useState(!1),[A,I]=t.useState(null),[c,v]=t.useState(null),[g,x]=t.useState(null),C=t.useRef(null),z=t.useRef(!0);t.useEffect(()=>(z.current=!0,_e().then(o=>{if(!z.current)return;const y=o.filter(T=>!T.published);f(y),p==null||p(y.length)}),()=>{z.current=!1,C.current&&(clearTimeout(C.current),C.current=null)}),[]),t.useEffect(()=>{const o=y=>{y.key==="Escape"&&s()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[s]);const j=t.useCallback((o,y)=>{x({message:o,type:y}),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>x(null),3e3)},[]);async function B(o){await qs(o),N(y=>new Set(y).add(o));try{await a(o),f(y=>{const T=y.filter($=>$.documentId!==o);return p==null||p(T.length),T}),j(b("published"),"success")}catch(y){y instanceof Gs||j(b("publishFailed"),"error");const T=await Hs(o);T&&f($=>$.map(V=>V.documentId===o?T:V))}finally{N(y=>{const T=new Set(y);return T.delete(o),T})}}async function O(o){I(null),await ss(o),f(y=>{const T=y.filter($=>$.documentId!==o);return p==null||p(T.length),T}),j(b("draftDeleted"),"success")}function L(o){const y=R.find(T=>T.documentId===o);y&&v(y)}function k(o){v(null),ss(o),f(y=>{const T=y.filter($=>$.documentId!==o);return p==null||p(T.length),T}),u==null||u(R.find(y=>y.documentId===o)),j(b("published"),"success")}async function K(){S(!0);let o=0,y=0;for(const V of R)try{await a(V.documentId),o++}catch{y++}const $=(await _e()).filter(V=>!V.published);f($),p==null||p($.length),y===0?j(b("publishAll"),"success"):j(`${o} published, ${y} failed`,"error"),S(!1)}const D=o=>new Date(o).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=o=>Ws(b,o,o.publishError??"UNKNOWN"),m=R;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[b("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:b("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":b("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:m.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:b("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(o=>{const y=!!o.publishError;return e.jsxs("div",{className:y?"mdocs-drawer-item mdocs-drawer-item-failed":"mdocs-drawer-item",children:[e.jsx("div",{className:"mdocs-drawer-item-icon","aria-hidden":"true",children:"📄"}),e.jsxs("div",{className:"mdocs-drawer-item-info",children:[e.jsx("span",{className:"mdocs-drawer-item-name",children:o.displayName||b("unknownTitle")}),y?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[D(o.publishErrorAt)," · ",E(o)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[D(o.updatedAt)," · ",b("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[y?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:h,onClick:()=>L(o.documentId),children:b("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(o.documentId)||h,onClick:()=>void B(o.documentId),children:w.has(o.documentId)?b("publishing"):b("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:h,onClick:()=>I(o.documentId),children:b("delete")})]})]},o.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:b("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||h,onClick:()=>void K(),children:h?b("publishing"):`${b("publishAll")} (${m.length})`})]}),g&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+g.type,role:"status",children:g.message})]}),A&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:o=>{o.target===o.currentTarget&&I(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:b("delete")}),e.jsx("p",{className:"muted",children:b("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>I(null),children:b("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void O(A),children:b("delete")})]})]})}),c&&e.jsx(ta,{draft:c,onClose:()=>v(null),onSuccess:()=>k(c.documentId)})]})}function na(){const{t:a,lang:s}=le(),p=ps(),u=t.useRef(!1),[b,R]=t.useState([]),[f,w]=t.useState(!1),[N,h]=t.useState(""),[S,A]=t.useState("restricted"),[I,c]=t.useState(!1),[v,g]=t.useState(null),[x,C]=t.useState(null),[z,j]=t.useState(""),[B,O]=t.useState(""),[L,k]=t.useState("all"),[K,D]=t.useState(null);t.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const E=t.useCallback(async()=>{w(!0),g(null);try{const l=await gs();if(!u.current)return;R(l)}catch(l){if(!u.current)return;g(se(a,l))}finally{u.current&&w(!1)}},[a]);t.useEffect(()=>{E()},[E]);async function m(l){if(l.preventDefault(),!N.trim()){g(a("domainNameRequired"));return}c(!0),g(null);try{if(await Xs({domainName:N.trim(),permission:S}),!u.current)return;h(""),A("restricted"),await E()}catch(r){if(!u.current)return;g(se(a,r))}finally{u.current&&c(!1)}}async function o(l){if(z.trim()){g(null);try{if(await Ys(l,z.trim()),!u.current)return;C(null),D(null),await E()}catch(r){if(!u.current)return;g(se(a,r))}}}function y(l){C(l.domainId),j(l.domainName),D(null)}function T(){C(null),D(null)}async function $(l,r){g(null);try{if(await Qs(l,r),!u.current)return;D(null),await E()}catch(U){if(!u.current)return;g(se(a,U))}}async function V(l){if(window.confirm(a("deleteDomainConfirmDetail",{name:l.domainName,count:String(l.docCount)}))){g(null);try{if(await Zs(l.domainId),!u.current)return;await E()}catch(r){if(!u.current)return;g(se(a,r))}}}const Z=t.useCallback(l=>Js(l,a),[a]),Q=t.useCallback(l=>de(l.domainName,s,a),[s,a]),ee=t.useMemo(()=>{const l=B.trim().toLowerCase();return b.filter(r=>L!=="all"&&r.permission!==L?!1:l?de(r.domainName,s,a).toLowerCase().includes(l)||r.domainName.toLowerCase().includes(l):!0)},[b,B,L,s,a]),H=t.useCallback((l,r)=>{const U=Z(l.permission);return r?`${U} ${a("domainTypeBuiltinSuffix")}`:U},[Z,a]);return{domains:b,loadingDomains:f,domainError:v,newDomainName:N,setNewDomainName:h,newDomainPermission:S,setNewDomainPermission:A,creating:I,handleCreateDomain:m,renamingId:x,setRenamingId:C,renameDraft:z,setRenameDraft:j,startRename:y,cancelRename:T,handleRename:o,changeTypeForId:K,setChangeTypeForId:D,handlePermissionChange:$,handleDelete:V,domainSearch:B,setDomainSearch:O,domainFilter:L,setDomainFilter:k,filteredDomains:ee,visitorId:p,plabel:Z,localizeDomain:Q,domainTypeLabel:H}}const is={private:0,restricted:1,public:2};function ls(a){return Object.prototype.hasOwnProperty.call(is,a)?is[a]:null}function cs(a,s){const p=ls(a),u=ls(s);return p===null||u===null?"invalid":u>p?"upgrade":u<p?"downgrade":"same"}function ia(){const{t:a}=le(),s=na(),[p,u]=t.useState([]),[b,R]=t.useState(null),[f,w]=t.useState(""),N=t.useRef(null),[h,S]=t.useState(null),A=t.useCallback(async()=>{try{const c=await fs();u(c)}catch{u([])}},[]);t.useEffect(()=>{A()},[A]),t.useEffect(()=>{if(!s.changeTypeForId)return;const c=v=>{var g;(g=N.current)!=null&&g.contains(v.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function I(c){R(null);try{const v=await it(c.domainId);S({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:v.map(g=>g.visitorId),memberRows:v})}catch(v){R({kind:"err",text:translateError(a,v)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:a("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:a("domainMgmtRestrictedMemberHint")}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-create",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:a("createDomain")}),e.jsxs("form",{onSubmit:s.handleCreateDomain,className:"mdocs-domain-mgmt-create-form",children:[e.jsxs("label",{className:"mdocs-domain-mgmt-field",children:[e.jsx("span",{className:"mdocs-domain-mgmt-label",children:a("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:a("domainName"),maxLength:100,disabled:s.creating,className:"mdocs-domain-name-input"})]}),e.jsxs("fieldset",{className:"mdocs-domain-mgmt-fieldset",children:[e.jsx("legend",{className:"mdocs-domain-mgmt-label",children:a("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:Ue.map(c=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===c,onChange:()=>s.setNewDomainPermission(c),disabled:s.creating}),e.jsx("span",{children:s.plabel(c)})]},c))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?a("creating"):a("create")})]})]}),b&&e.jsx("div",{className:"mdocs-settings-card",style:{color:b.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:b.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:c=>s.setDomainSearch(c.target.value),placeholder:a("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":a("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":a("domainPermission"),children:["all",...Ue].map(c=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===c?" active":""),"aria-pressed":s.domainFilter===c,onClick:()=>s.setDomainFilter(c),children:c==="all"?a("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("loading")})}):s.domains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("noDomains")})}):s.filteredDomains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("domainNoMatch")})}):e.jsx("div",{className:"mdocs-settings-card mdocs-domain-table-wrap",children:e.jsxs("table",{className:"mdocs-domain-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:a("domainColName")}),e.jsx("th",{scope:"col",children:a("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:a("domainColDocCount")}),e.jsx("th",{scope:"col",children:a("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const v=et(c,s.visitorId),g=st(c.domainId),x=tt(c),C=cs(c.permission,"public")==="upgrade",z=C?x?a("domainTooltipTypeLocked"):void 0:a("domainPermissionAlreadyTop");return e.jsxs("tr",{className:g?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===c.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:j=>s.setRenameDraft(j.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(c.domainId),children:a("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:a("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),g&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:a("domainBuiltIn")}),!v&&!g&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:a("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:z,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,g)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[g&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:a("domainNotModifiable")}),!g&&!v&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:a("domainNotCreator")}),!g&&v&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:N,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":a("domainChangeType"),children:Ue.map(j=>{const O=cs(c.permission,j)==="downgrade";return e.jsx("span",{title:O?a("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":f===j,className:f===j?"active":"",disabled:O,onClick:()=>w(j),children:s.plabel(j)})},j)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":a("save"),disabled:f===""||f===c.permission,onClick:()=>{f&&f!==c.permission&&s.handlePermissionChange(c.domainId,f)},children:e.jsx(Ut,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":a("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(at,{size:14,strokeWidth:2.5})})]}),!g&&v&&s.renamingId!==c.domainId&&s.changeTypeForId!==c.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[c.permission==="restricted"&&e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--primary",onClick:()=>void I(c),children:a("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:x?a("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:x,children:a("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:z,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!C,children:a("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:x?a("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:x,children:a("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(js,{open:h!==null,title:a("domainMembersPickerTitle"),initialSelectedIds:(h==null?void 0:h.initialIds)??[],lockedIds:h?[h.creatorVisitorId]:[],seedMembers:h==null?void 0:h.memberRows,templates:p,onClose:()=>S(null),onConfirm:async c=>{h&&(await nt(h.domainId,c),R({kind:"ok",text:a("domainMembersSaved",{count:String(c.length)})}))}})]})}function os(a){return a.length<=6?a:`${a.slice(0,6)}…`}function la(){const{t:a}=le(),s=t.useRef(!0),[p,u]=t.useState([]),[b,R]=t.useState(!0),[f,w]=t.useState(null),[N,h]=t.useState(1),[S,A]=t.useState(null),[I,c]=t.useState(""),[v,g]=t.useState([]),[x,C]=t.useState(!1),[z,j]=t.useState(null),[B,O]=t.useState(!1),L=ps(),[k,K]=t.useState([]),[D,E]=t.useState("idle"),[m,o]=t.useState("");t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),t.useEffect(()=>{E("loading"),xs().then(d=>{s.current&&(K(d),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const y=t.useMemo(()=>{const d=new Map;for(const M of k)d.set(M.visitorId,M.visitorName);return d},[k]),T=t.useCallback(async()=>{R(!0),j(null);try{const d=await fs();s.current&&u(d)}catch(d){s.current&&j(se(a,d))}finally{s.current&&R(!1)}},[a]);t.useEffect(()=>{T()},[T]);const $=t.useMemo(()=>v.map(d=>{const M=k.find(W=>W.visitorId===d);return{visitorId:d,name:M?M.visitorName:a("visitorPickerUnknownVisitor"),muted:!M}}),[v,k,a]);function V(d){g(M=>M.includes(d)?M.filter(W=>W!==d):[...M,d])}const Z=N===1?I.trim().length>0:N===2?v.length>0:!0;function Q(){if(!(N>=3)){if(!Z){O(!0);return}O(!1),h(N+1),o("")}}function ee(){N<=1||(O(!1),h(N-1))}function H(){w(null),A(null),c(""),g(L?[L]:[]),j(null),h(1),o(""),O(!1)}function l(d){w(null),A(d.id),c(d.displayName);const M=L&&!d.visitorIds.includes(L)?[...d.visitorIds,L]:[...d.visitorIds];g(M),j(null),h(1),o(""),O(!1)}async function r(){if(!(!I.trim()||v.length===0)){C(!0),j(null);try{if(S===null?await lt({displayName:I.trim(),visitorIds:v}):await ct(S,{displayName:I.trim(),visitorIds:v}),!s.current)return;H(),await T()}catch(d){if(!s.current)return;j(se(a,d))}finally{s.current&&C(!1)}}}async function U(d){C(!0),j(null);try{if(await ot(d),!s.current)return;w(null),S===d&&H(),await T()}catch(M){if(!s.current)return;j(se(a,M))}finally{s.current&&C(!1)}}const _=[{key:1,label:a("memberTemplateStepName")},{key:2,label:a("memberTemplateStepMembers")},{key:3,label:a("memberTemplateStepSave")}],F=`${(N-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:a(S!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),S!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:H,style:{fontSize:12},children:a("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:F}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:_.map(d=>{const M=N===d.key,W=N>d.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${M?" current":""}${W?" done":""}`,children:W?"✓":d.key}),e.jsx("span",{className:`mdocs-wizard-step-label${M?" current":""}${W?" done":""}`,children:d.label})]},d.key)})})]}),z&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:z}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[N===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:I,onChange:d=>c(d.target.value),placeholder:a("memberTemplateNamePlaceholder"),maxLength:200,disabled:x,autoFocus:!0,"aria-invalid":B&&!I.trim()}),B&&!I.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:a("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Kt,{visitors:k,loadState:D,searchFilter:m,onSearchChange:o,selectedIds:new Set(v),onToggle:V,selectedRows:$,myVisitorId:L}),e.jsx("p",{className:`mdocs-wizard-hint${B&&v.length===0?" danger":""}`,children:"💡 "+a("memberTemplateStep2Hint")})]}),N===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:I})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:a("memberTemplateSelectedSummary",{count:String(v.length)})})]}),v.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[v.slice(0,15).map(d=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:os(d)},d)),v.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",v.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:ee,children:["← ",a("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:Q,children:[a("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void r(),children:a(x?"saving":S===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:a("memberTemplateSavedList")}),b?e.jsx("span",{className:"mdocs-settings-item-desc",children:a("loading")}):p.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateEmpty")}),S===null&&e.jsx("button",{type:"button",className:"primary",onClick:H,children:a("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:p.map(d=>e.jsx("li",{className:"mdocs-member-template-row",children:f===d.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:a("memberTemplateConfirmDeleteDesc",{name:d.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void U(d.id),children:a(x?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(null),children:a("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:d.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateCount",{count:String(d.visitorIds.length)})}),d.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:d.visitorIds.map(M=>e.jsx("span",{className:"mdocs-member-template-tag",children:y.get(M)??os(M)},M))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>l(d),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(d.id),children:a("memberTemplateDelete")})]})]})},d.id))})]})]})]})}const ca=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],rs=[{value:"off",label:"关(不思考)"},{value:"low",label:"低(推荐)"},{value:"high",label:"高"},{value:"max",label:"最大"}],oa=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function ra(a,s,p){return a==="deepseek"?"Deepseek":s||p}function ds(a){return`${ra(a.kind,a.providerId,a.name)} · ${a.modelId} · ${a.name}`}function da(){const{t:a}=le(),s=t.useRef(!0),[p,u]=t.useState(""),[b,R]=t.useState([]),[f,w]=t.useState(null),[N,h]=t.useState(null),[S,A]=t.useState("deepseek"),[I,c]=t.useState(""),[v,g]=t.useState(""),[x,C]=t.useState(""),[z,j]=t.useState("openai-completions"),[B,O]=t.useState("deepseek-flash"),[L,k]=t.useState(1e6),[K,D]=t.useState(300),[E,m]=t.useState("low"),[o,y]=t.useState(""),[T,$]=t.useState(!1),[V,Z]=t.useState(null),[Q,ee]=t.useState(!1),[H,l]=t.useState(!0),[r,U]=t.useState(!1),[_,F]=t.useState(null),[d,M]=t.useState(!1),[W,te]=t.useState(!1),[ce,ae]=t.useState(!1),[Y,he]=t.useState(null),[pe,ge]=t.useState(null),fe=t.useRef(!1);t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const oe=t.useCallback(async()=>{const i=await rt();if(s.current)return R(i),i},[]);function ne(){h(null),A("deepseek"),c(""),g(""),C(""),j("openai-completions"),O("deepseek-flash"),k(1e6),D(300),m("low"),y(""),$(!1),Z(null),ee(!1),te(!1),ae(!1),F(null),M(!1)}function Me(i){h(i.id),A(i.kind),c(i.name),g(i.providerId??""),C(i.baseUrl),j(i.apiType);const J=i.modelId.trim(),ie=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);O(i.kind==="deepseek"?J==="deepseek-v4-pro"?"deepseek-v4-pro":ie.has(J)?"deepseek-flash":J||"deepseek-flash":J),k(i.contextWindow||1e6),D(typeof i.runTimeoutSeconds=="number"&&i.runTimeoutSeconds>0?i.runTimeoutSeconds:300),m(i.thinkingLevel==="off"||i.thinkingLevel==="high"||i.thinkingLevel==="max"?i.thinkingLevel:"low"),$(i.hasApiKey),Z(i.apiKeyMasked),y(""),ee(i.isDefault)}t.useEffect(()=>{(async()=>{try{const i=await dt();if(!s.current)return;u(i.visitorName);const J=await oe();if(!s.current||!J)return;J.length===0&&(ne(),w("create"))}catch(i){if(!s.current)return;F(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&l(!1)}})()},[oe]);function Ne(){ne(),w("create")}function me(i){Me(i),w("edit"),M(!1),F(null)}function ve(){ne(),w(null)}async function ke(i){if(!(i.isDefault||pe)){ge(i.id),F(null);try{await mt(i.id),await oe()}catch(J){if(!s.current)return;F(J instanceof Error?J.message:String(J))}finally{s.current&&ge(null)}}}async function Pe(){if(Y){U(!0),F(null);try{await ht(Y.id);const i=await oe();if(!s.current)return;f==="edit"&&N===Y.id&&ve(),((i==null?void 0:i.length)??0)===0&&(ne(),w("create"))}catch(i){if(!s.current)return;F(i instanceof Error?i.message:String(i))}finally{s.current&&(U(!1),he(null))}}}async function Ee(){U(!0),F(null),M(!1);try{const i=S==="custom"?{...f==="edit"&&N?{id:N}:{},...f==="create"&&Q?{isDefault:!0}:{},kind:S,baseUrl:x,modelId:B,providerId:v.trim()||void 0,apiType:z,name:I,contextWindow:L,runTimeoutSeconds:K,thinkingLevel:E,...o.trim()?{apiKey:o.trim()}:{}}:{...f==="edit"&&N?{id:N}:{},...f==="create"&&Q?{isDefault:!0}:{},kind:S,modelId:B,name:I,contextWindow:L,runTimeoutSeconds:K,thinkingLevel:E,...o.trim()?{apiKey:o.trim()}:{}};if(await ut(i),!s.current)return;await oe(),M(!0),w(null),ne()}catch(i){if(!s.current)return;F(i instanceof Error?i.message:String(i))}finally{s.current&&U(!1)}}const Se=f!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:a("agentConfig")}),H?null:e.jsx("button",{type:"button",className:"secondary",onClick:Ne,children:"添加配置"})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!H&&b.length>0?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:b.map(i=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:i.isDefault,disabled:pe!==null,onChange:()=>void ke(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:ds(i)}),i.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:i.hasApiKey?`Key ${i.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>me(i),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>he(i),children:"删除"})]})]},i.id))}),d?e.jsx("p",{className:"mdocs-agent-config-ok",children:a("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,Se?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsxs("p",{className:"mdocs-agent-config-lead",children:[f==="create"?"新建模型配置。":"编辑模型配置。","可以保存多套,勾选一条作为默认。智能助手和帮写使用默认那套。"]}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":S==="deepseek",className:S==="deepseek"?"active":"",onClick:()=>A("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":S==="custom",className:S==="custom"?"active":"",onClick:()=>A("custom"),children:"自定义"})]}),S==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigModel")}),e.jsx(Ie,{options:[...ca],value:B,onChange:O})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"思考强度"}),e.jsx(Ie,{options:[...rs],value:E,onChange:i=>m(i)})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:W?"text":"password",value:o,onChange:i=>y(i.target.value),placeholder:T?a("agentConfigApiKeyConfigured").replace("{{masked}}",V??"…"):a("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(W?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>te(i=>!i),children:W?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:x,onChange:i=>{const J=i.target.value;if(C(J),fe.current)return;J.toLowerCase().includes("anthropic")?j("anthropic-messages"):j("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:B,onChange:i=>O(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:W?"text":"password",value:o,onChange:i=>y(i.target.value),placeholder:T?a("agentConfigApiKeyConfigured").replace("{{masked}}",V??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(W?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>te(i=>!i),children:W?"隐藏":"显示"})]})]})]}),S==="custom"?e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"思考强度"}),e.jsx(Ie,{options:[...rs],value:E,onChange:i=>m(i)})]}):null,e.jsxs("details",{className:"mdocs-agent-advanced",open:ce,onToggle:i=>ae(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),S==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:v,onChange:i=>g(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ie,{options:[...oa],value:z,onChange:i=>{fe.current=!0,j(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigName")}),e.jsx("input",{type:"text",value:I,onChange:i=>c(i.target.value),placeholder:a("agentConfigNameDefault").replace("{{name}}",p||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:L,onChange:i=>k(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigContextWindowDesc")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigRunTimeout")}),e.jsx("input",{type:"number",min:60,max:3600,step:30,value:K,onChange:i=>D(Math.max(60,Number(i.target.value)||300))}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigRunTimeoutDesc")})]})]}),f==="create"&&b.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:i=>ee(i.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ee(),disabled:r,children:a(r?"saving":"save")}),b.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ve,disabled:r,children:a("cancel")}):null]})]})]}):H?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:a("loading")})}):null]}),Y?e.jsx(ys,{title:"删除配置",message:`确定删除「${ds(Y)}」?${Y.isDefault&&b.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:a("cancel"),onConfirm:()=>void Pe(),onCancel:()=>he(null)}):null]})}const ma=/^[A-Za-z0-9_]+$/;function Ve(a){return ma.test(a.trim())}function ua(){const a=t.useRef(!0),[s,p]=t.useState([]),[u,b]=t.useState(!0),[R,f]=t.useState(null),[w,N]=t.useState(null),[h,S]=t.useState(!1),[A,I]=t.useState(""),[c,v]=t.useState(""),[g,x]=t.useState(""),[C,z]=t.useState(!1);t.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);async function j(){b(!0),f(null);try{const m=await pt();if(!a.current)return;p(m)}catch(m){if(!a.current)return;f(m instanceof Error?m.message:String(m))}finally{a.current&&b(!1)}}t.useEffect(()=>{j()},[]);function B(){S(!0),N(null),I(""),v(""),x(""),f(null)}function O(m){S(!1),N(m.id),I(m.name),v(m.description),x(m.body),f(null)}function L(){S(!1),N(null),I(""),v(""),x("")}async function k(){const m=A.trim();if(!Ve(m)){f("名称仅允许英文、数字、下划线");return}if(!g.trim()){f("正文不能为空");return}z(!0),f(null);try{if(h?await gt({name:m,description:c,body:g}):w&&await ft(w,{name:m,description:c,body:g}),!a.current)return;L(),await j()}catch(o){if(!a.current)return;f(o instanceof Error?o.message:String(o))}finally{a.current&&z(!1)}}async function K(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){f(null);try{if(await xt(m),!a.current)return;w===m&&L(),await j()}catch(o){if(!a.current)return;f(o instanceof Error?o.message:String(o))}}}const D=h||w!==null,E=!A.trim()||Ve(A);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),D?null:e.jsx("button",{type:"button",className:"secondary",onClick:B,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),R?e.jsx("p",{className:"mdocs-agent-skills-error",children:R}):null,D?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:h?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:A,onChange:m=>I(m.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:E?void 0:"mdocs-agent-skills-input-invalid"}),E?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:c,onChange:m=>v(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:g,onChange:m=>x(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void k(),disabled:C||!E||!A.trim()||!g.trim(),children:C?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:L,disabled:C,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&s.length===0&&!D?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:B,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const o=Ve(m.name),y=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(y?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:m.name}),o?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:m.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>O(m),disabled:D&&!y,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void K(m.id),disabled:D,children:"删除"})]})]},m.id)})}):null]})})]})}const ha={algorithm:Vt.defaultAlgorithm,token:{colorPrimary:"#4CAF50",colorLink:"#4CAF50",colorInfo:"#4CAF50",colorSuccess:"#66BB6A",colorBgBase:"#ffffff",colorBgContainer:"#ffffff",colorText:"#212121",colorTextSecondary:"#616161",colorBorder:"#E0E0E0",colorFillSecondary:"#E8F5E9",borderRadius:8,fontFamily:"inherit"},components:{Table:{headerBg:"#F5F5F5",headerColor:"#212121",rowHoverBg:"#E8F5E9",borderColor:"#E0E0E0"},Button:{primaryShadow:"none"},Tag:{defaultBg:"#F5F5F5",defaultColor:"#616161"}}};function ms(a,s){if(!a)return"—";const p=new Date(a);return Number.isNaN(p.getTime())?"—":p.toLocaleString(s==="zh"?"zh-CN":"en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function pa(a){const{t:s,lang:p}=le(),[u,b]=t.useState(!1),[R,f]=t.useState(!1),[w,N]=t.useState(!1),[h,S]=t.useState([]),[A,I]=t.useState([]),[c,v]=t.useState(null),[g,x]=t.useState(null),[C,z]=t.useState(""),[j,B]=t.useState("keyword"),[O,L]=t.useState(null),[k,K]=t.useState(!1),D=t.useRef(0),[E,m]=t.useState({current:1,pageSize:20}),[o,y]=t.useState(0);async function T(){b(!0),x(null);try{const l=await yt();N(l.modelReady),S(l.items),I([]),y(l.items.length),m(r=>({...r,current:1}))}catch(l){x(se(s,l)||s("embeddingIndexLoadFailed"))}finally{b(!1)}}t.useEffect(()=>{T()},[]);const $=t.useMemo(()=>{const l=new Map;for(const r of h)l.has(r.domainId)||l.set(r.domainId,de(r.domainName,p,s));return Array.from(l.entries()).map(([r,U])=>({text:U,value:r}))},[h,p,s]),V=t.useMemo(()=>{const l=C.trim().toLowerCase();return l?h.filter(r=>(r.displayName||"").toLowerCase().includes(l)||(r.relativePath||"").toLowerCase().includes(l)||r.documentId.toLowerCase().includes(l)):h},[h,C]),Z=j==="semantic"&&!!C.trim();t.useEffect(()=>{if(j!=="semantic")return;const l=C.trim();if(!l){D.current+=1,L(null);return}const r=++D.current;K(!0);const U=window.setTimeout(()=>{(async()=>{try{const _=await bs({query:l,mode:"semantic",topN:50});if(r!==D.current)return;const F=new Map(h.map(d=>[d.documentId,d]));L(_.results.map(d=>{const M=F.get(d.documentId);return M?{...M,snippet:d.snippet}:{documentId:d.documentId,displayName:d.displayName,relativePath:d.relativePath,domainId:d.domainId,domainName:d.domainId,documentUpdatedAt:d.updatedAt,chunkCount:0,chunkUnknown:!0,embeddingUpdatedAt:null,snippet:d.snippet}}))}catch{r===D.current&&L([])}finally{r===D.current&&K(!1)}})()},300);return()=>window.clearTimeout(U)},[j,C,h]);const Q=Z?O??[]:V;t.useEffect(()=>{y(Q.length),m(l=>({...l,current:1}))},[Q.length,j]);const ee=t.useMemo(()=>[{title:s("myDocumentsColTitle"),dataIndex:"displayName",key:"displayName",ellipsis:!0,sorter:(l,r)=>(l.displayName||l.relativePath).localeCompare(r.displayName||r.relativePath,p==="zh"?"zh":"en"),render:(l,r)=>e.jsxs("div",{style:{minWidth:0},children:[e.jsx("button",{type:"button",className:"mdocs-linkish",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontWeight:500,color:"inherit",textAlign:"left"},onClick:()=>a.onOpenDocument(r.documentId),children:r.displayName||r.relativePath||"Untitled"}),r.snippet&&e.jsx("div",{className:"mdocs-embedding-index-snippet",title:r.snippet,children:r.snippet})]})},{title:s("myDocumentsColDomain"),dataIndex:"domainId",key:"domainId",width:160,ellipsis:!0,filters:$,onFilter:(l,r)=>r.domainId===l,sorter:(l,r)=>de(l.domainName,p,s).localeCompare(de(r.domainName,p,s),p==="zh"?"zh":"en"),render:(l,r)=>de(r.domainName,p,s)},{title:s("embeddingIndexColDocUpdated"),dataIndex:"documentUpdatedAt",key:"documentUpdatedAt",width:160,sorter:(l,r)=>new Date(l.documentUpdatedAt).getTime()-new Date(r.documentUpdatedAt).getTime(),defaultSortOrder:"descend",render:l=>ms(l,p)},{title:s("embeddingIndexColStatus"),dataIndex:"chunkCount",key:"buildStatus",width:140,filters:[{text:s("embeddingIndexFilterBuilt"),value:"built"},{text:s("embeddingIndexFilterMissing"),value:"missing"}],onFilter:(l,r)=>l==="built"?r.chunkCount>0:r.chunkCount===0,sorter:(l,r)=>l.chunkCount-r.chunkCount,render:(l,r)=>r.chunkUnknown?e.jsx($e,{color:"success",children:s("embeddingIndexStatusBuiltUnknown")}):l>0?e.jsx($e,{color:"success",children:s("embeddingIndexStatusReady",{chunks:String(l)})}):e.jsx($e,{children:s("embeddingIndexStatusMissing")})},{title:s("embeddingIndexColBuiltAt"),dataIndex:"embeddingUpdatedAt",key:"embeddingUpdatedAt",width:160,sorter:(l,r)=>{const U=l.embeddingUpdatedAt?new Date(l.embeddingUpdatedAt).getTime():0,_=r.embeddingUpdatedAt?new Date(r.embeddingUpdatedAt).getTime():0;return U-_},render:l=>ms(l,p)}],[$,p,a,s]);async function H(){const l=A.map(String);if(l.length!==0){f(!0),v(null),x(null);try{const r=await bt(l);N(r.modelReady),v(s("embeddingIndexRebuildResult",{ok:String(r.ok.length),skipped:String(r.skipped.length),failed:String(r.failed.length)})),await T()}catch(r){x(se(s,r)||s("embeddingIndexRebuildFailed"))}finally{f(!1)}}}return e.jsx($t,{theme:ha,children:e.jsxs("div",{className:"mdocs-settings mdocs-embedding-index",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("embeddingIndex")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"muted",style:{marginTop:0},children:s("embeddingIndexDesc")}),e.jsxs("p",{style:{margin:"0 0 12px",fontSize:13},children:[s("embeddingIndexModel"),":"," ",e.jsx("strong",{children:s(w?"embeddingIndexModelReady":"embeddingIndexModelPending")})]}),e.jsxs(_t,{wrap:!0,style:{marginBottom:12},children:[e.jsx(Wt,{value:j,"aria-label":s("myDocumentsSearchMode"),onChange:l=>B(l),options:[{label:s("myDocumentsModeKeyword"),value:"keyword"},{label:s("myDocumentsModeSemantic"),value:"semantic"}]}),e.jsx(qt.Search,{allowClear:!0,placeholder:s(j==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),"aria-label":s(j==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),value:C,onChange:l=>z(l.target.value),style:{width:240},disabled:u||R}),e.jsx(as,{onClick:()=>void T(),disabled:u||R,children:s("embeddingIndexRefresh")}),e.jsx(as,{type:"primary",onClick:()=>void H(),disabled:R||A.length===0,loading:R,children:s("embeddingIndexRebuildSelected",{count:String(A.length)})})]}),c&&e.jsx("p",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:c}),g&&e.jsx("p",{className:"mdocs-doc-search-error",style:{marginBottom:8},children:g}),Z&&!w&&e.jsx("p",{className:"muted",style:{margin:"0 0 8px",fontSize:13},children:s("myDocumentsSemanticNotReady")}),(()=>{const l=Number(E.pageSize)||20,r=Number(E.current)||1,U=o,_=Math.max(1,Math.ceil(U/l)||1);return e.jsx(Gt,{size:"small",rowKey:"documentId",loading:u||Z&&k,columns:ee,dataSource:Q,rowSelection:{selectedRowKeys:A,onChange:F=>I(F)},pagination:{current:r,pageSize:l,total:U,showSizeChanger:!1,showQuickJumper:!1,showTotal:(F,d)=>s("embeddingIndexPageTotal",{from:String(d[0]??0),to:String(d[1]??0),total:String(F)})},onChange:(F,d,M,W)=>{const te=F.pageSize??l,ce=W.currentDataSource.length,ae=Math.max(1,Math.ceil(ce/te)||1);let Y=F.current??1;Y>ae&&(Y=ae),y(ce),m({current:Y,pageSize:te})},locale:{emptyText:C.trim()?s("myDocumentsNoMatch"):s("embeddingIndexEmpty"),filterReset:s("embeddingIndexFilterReset"),filterConfirm:s("embeddingIndexFilterOk")},scroll:{x:900},footer:()=>e.jsxs("div",{className:"mdocs-embedding-index-pager",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"flex-end",gap:10},children:[e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexPageSize")}),e.jsx(ns,{size:"small",min:5,max:200,step:5,value:l,controls:!0,changeOnWheel:!0,disabled:u||R,"aria-label":s("embeddingIndexPageSize"),onChange:F=>{if(F==null||!Number.isFinite(Number(F)))return;const d=Math.min(200,Math.max(5,Math.floor(Number(F))));m({current:1,pageSize:d})}}),e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexGoPage")}),e.jsx(ns,{size:"small",min:1,max:_,step:1,value:Math.min(r,_),controls:!0,changeOnWheel:!0,disabled:u||R||U===0,"aria-label":s("embeddingIndexGoPage"),onChange:F=>{if(F==null||!Number.isFinite(Number(F)))return;const d=Math.min(_,Math.max(1,Math.floor(Number(F))));m(M=>({...M,current:d}))}}),e.jsxs("span",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:["/ ",_]})]})})})()]})]})})}function us(a,s){const p=localStorage.getItem(a);return p===null?s:p==="true"}function Te(a){const s=new Date(a);if(Number.isNaN(s.getTime()))return"—";const p=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${p}-${u}`}const hs=[{id:"general",labelKey:"general",keywords:["设置","语言","settings","language"],Icon:vt},{id:"bookmarks",labelKey:"bookmarkTitle",keywords:["收藏","bookmark","star"],Icon:kt},{id:"myDocuments",labelKey:"myDocuments",keywords:["文章","文档","documents","articles"],Icon:St},{id:"embeddingIndex",labelKey:"embeddingIndex",keywords:["语义","索引","embedding","vector","检索"],Icon:Xt},{id:"domainManagement",labelKey:"domainManagement",keywords:["域","工作空间","workspace","domain"],Icon:Qt},{id:"memberTemplates",labelKey:"memberTemplates",keywords:["成员","模板","members","template","邀请"],Icon:Ot},{id:"agentConfig",labelKey:"agentConfig",keywords:["ai","助手","模型","agent","llm","deepseek"],Icon:sa},{id:"savePublish",labelKey:"saveAndPublish",keywords:["草稿","发布","同步","draft","publish","sync"],Icon:Jt}];function va(a){const{t:s,lang:p,setLang:u}=le(),{onBack:b,onPublishDraft:R}=a,f=jt(),[w,N]=t.useState(!1);Nt(f,()=>N(!0),{open:w,onClose:()=>N(!1)});const h=t.useRef(!0);t.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]),t.useEffect(()=>{f||N(!1)},[f]);const[S,A]=t.useState(()=>us("mdocs.autoPublish",!1)),[I,c]=t.useState(()=>us("mdocs.autoEdit",!0)),[v,g]=t.useState(!1),[x,C]=t.useState("general"),[z,j]=t.useState("");function B(n){C(n),f&&N(!1)}const O=t.useMemo(()=>{const n=z.trim().toLowerCase();return n?hs.filter(P=>s(P.labelKey).toLowerCase().includes(n)?!0:P.keywords.some(q=>q.toLowerCase().includes(n))):hs},[z,s]),L=s(x==="general"?"general":x==="bookmarks"?"bookmarkTitle":x==="myDocuments"?"myDocuments":x==="embeddingIndex"?"embeddingIndex":x==="domainManagement"?"domainManagement":x==="memberTemplates"?"memberTemplates":x==="agentConfig"?"agentConfig":"saveAndPublish"),[k,K]=t.useState([]),[D,E]=t.useState(!0),[m,o]=t.useState(null),[y,T]=t.useState(!1),[$,V]=t.useState(!1),[Z,Q]=t.useState(!1),[ee,H]=t.useState(!1),[l,r]=t.useState(null),[U,_]=t.useState(!1),[F,d]=t.useState(!1),[M,W]=t.useState(!1),[te,ce]=t.useState(""),[ae,Y]=t.useState(!1),[he,pe]=t.useState(!1),[ge,fe]=t.useState(0),[oe,ne]=t.useState([]),[Me,Ne]=t.useState(!1),[me,ve]=t.useState(""),[ke,Pe]=t.useState([]),[Ee,Se]=t.useState(!1),[i,J]=t.useState(""),[ie,Ns]=t.useState("auto"),[we,Re]=t.useState(null),[We,Fe]=t.useState(!0),[ue,vs]=t.useState(0),[qe,Ge]=t.useState("1"),[He,ks]=t.useState(0),[xe,Ss]=t.useState(""),[Le,ws]=t.useState(""),[Ce,Cs]=t.useState(""),[Ds,Is]=t.useState(null),[Ts,As]=t.useState([]),De=t.useRef(0),ze=20,ye=we!==null,[Je,Ms]=t.useState([]),[Ps,Be]=t.useState(!1),[Ke,Ze]=t.useState(null),[Oe,Qe]=t.useState(new Map);t.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(S))},[S]),t.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(I))},[I]),t.useEffect(()=>{x==="savePublish"&&_e().then(n=>{h.current&&fe(n.filter(P=>!P.published).length)})},[x]),t.useEffect(()=>{x==="bookmarks"&&Es(),x==="myDocuments"&&(je(),xs().then(n=>{h.current&&As(n)}).catch(()=>{}))},[x,xe,Le,Ce]),t.useEffect(()=>{if(x!=="myDocuments")return;const n=i.trim();if(!n){De.current+=1,Re(null),Fe(!0);return}const P=++De.current,G=window.setTimeout(()=>{(async()=>{try{const q=await bs({query:n,mode:ie,domainId:xe||void 0,topN:50});if(!h.current||P!==De.current)return;Re(q.results),Fe(q.modelReady)}catch{if(!h.current||P!==De.current)return;Re([]),Fe(!0)}})()},300);return()=>window.clearTimeout(G)},[x,i,ie,xe]),t.useEffect(()=>{Ye()},[]),t.useEffect(()=>{gs().then(n=>{h.current&&Ms(n)}).catch(()=>{})},[]);const be=new Map(Je.map(n=>[n.domainId,n.domainName]));async function Ye(){try{E(!0);const n=await wt();if(!h.current)return;K(n)}catch{}finally{h.current&&E(!1)}}async function Es(){try{Ne(!0);const n=await Ct();if(!h.current)return;ne(n)}catch{}finally{h.current&&Ne(!1)}}async function je(n=0){try{Se(!0);const P=await Dt({offset:n*ze,limit:ze,domainId:xe||void 0,creatorVisitorId:Le||void 0,groupBy:Ce||void 0});if(!h.current)return;Pe(P.items),Is(P.groups??null),ks(P.total),vs(n),Ge(String(n+1))}catch{}finally{h.current&&Se(!1)}}async function Rs(n){try{await Rt(n),ne(P=>P.filter(G=>G.documentId!==n))}catch{}}function Fs(){if(k.some(P=>!P.revoked)){V(!0);return}Xe()}async function Xe(){try{T(!0);const n=await Lt();o({token:n.token,name:n.name}),await Ye()}finally{T(!1)}}async function Ls(){try{W(!0);const n=await Pt();r(n.recoveryCode)}finally{W(!1)}}async function zs(n){n.preventDefault();const P=te.trim();if(!(P&&P.length<4))try{Y(!0),await Et(P),ce(""),pe(!0),setTimeout(()=>pe(!1),3e3)}finally{Y(!1)}}async function Bs(n){Ze(n);try{const P=await Ft(n),G=new Map;P.forEach(q=>{G.set(q.visitorId,q.permission)}),Qe(G)}catch{Qe(new Map)}Be(!0)}async function Ks(n){if(Ke)try{const P=new Set(n.map(q=>q.visitorId)),G=new Set(Oe.keys());for(const q of G)P.has(q)||await zt(Ke,q);for(const q of n)await Bt(Ke,q.visitorId,q.permission);await je()}finally{Be(!1),Ze(null)}}const es=oe.filter(n=>{if(!me.trim())return!0;const P=me.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(P)||(n.ownerVisitorName||"").toLowerCase().includes(P)||(n.domainId||"").toLowerCase().includes(P)}),re=Math.ceil(He/ze);return e.jsxs("div",{className:"mdocs-layout"+(f?" mdocs-layout--reader mdocs-layout--settings":""),children:[f&&w?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>N(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(f?w?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:It,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),f?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>N(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Tt,{size:18})}):null]}),e.jsx("div",{className:"mdocs-config-nav-search",children:e.jsxs("div",{className:"mdocs-config-nav-search-inner",children:[e.jsx(ts,{size:14,strokeWidth:1.75,"aria-hidden":!0}),e.jsx("input",{type:"search",value:z,onChange:n=>j(n.target.value),placeholder:s("settingsNavSearch"),"aria-label":s("settingsNavSearch")})]})}),e.jsx("nav",{className:"mdocs-config-tree",children:O.length===0?e.jsx("div",{className:"mdocs-config-nav-empty",children:s("settingsNavNoMatch")}):O.map(n=>{const P=n.Icon,G=x===n.id;return e.jsxs("div",{className:"mdocs-config-item"+(G?" active":""),onClick:()=>B(n.id),children:[e.jsx(P,{size:16,strokeWidth:1.75,"aria-hidden":!0}),e.jsx("span",{children:s(n.labelKey)})]},n.id)})}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:b,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[f?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>N(!0),"aria-label":s("expandSidebar"),children:e.jsx(At,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:L})]}):null,Mt(),x==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:p==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:p==="zh"?"active":"",onClick:()=>u("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(I?" active":""),role:"switch","aria-checked":I,onClick:()=>c(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!D&&k.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:k.map(n=>e.jsxs("span",{style:{display:"block"},children:[n.name," — ",new Date(n.createdAt).toLocaleString()," ",n.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},n.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Fs,disabled:y||D,children:y?"…":k.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),m&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:m.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m.token),H(!1),Q(!0),window.setTimeout(()=>Q(!1),2e3)}catch{Q(!1),H(!0),window.setTimeout(()=>H(!1),3e3)}})()},children:s(Z?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>o(null),children:s("close")})]}),Z&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),ee&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Ls,disabled:M,children:M?"…":"生成恢复码"})]}),l&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:l})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(l),d(!1),_(!0),window.setTimeout(()=>_(!1),2e3)}catch{_(!1),d(!0),window.setTimeout(()=>d(!1),3e3)}})()},children:U?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>r(null),children:s("close")})]}),U&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:"复制失败,请手动选中上方内容复制"})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-item",children:e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔐 登录密码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"设置密码后,可在其他浏览器或设备用「用户名+密码」登录。"})]})}),e.jsxs("form",{onSubmit:zs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:te,onChange:n=>ce(n.target.value),minLength:0,style:{marginBottom:8}}),he&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:ae,children:ae?"设置中…":"保存密码"})]})]})]})]}):x==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:me,onChange:n=>ve(n.target.value)}),Me?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:es.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(me?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:es.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):be.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(n.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Rs(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):x==="myDocuments"?e.jsxs("div",{className:"mdocs-settings mdocs-my-docs",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-my-docs-toolbar",children:[e.jsxs("div",{className:"mdocs-my-docs-search",children:[e.jsx(ts,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:i,onChange:n=>J(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:xe,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>Ss(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Je.map(n=>e.jsx("option",{value:n.domainId,children:be.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ie,"aria-label":s("myDocumentsSearchMode"),onChange:n=>Ns(n.target.value),children:[e.jsx("option",{value:"auto",children:s("myDocumentsModeAuto")}),e.jsx("option",{value:"keyword",children:s("myDocumentsModeKeyword")}),e.jsx("option",{value:"semantic",children:s("myDocumentsModeSemantic")})]}),!ye&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Le,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>ws(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),Ts.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),!ye&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Ce,"aria-label":s("myDocumentsGroupBy"),onChange:n=>Cs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsGroupNone")}),e.jsx("option",{value:"domain",children:s("myDocumentsGroupDomain")}),e.jsx("option",{value:"creator",children:s("myDocumentsGroupCreator")})]})]}),Ee&&!ye?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):ye?e.jsx(e.Fragment,{children:we.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(ie==="semantic"&&!We?"myDocumentsSemanticNotReady":"myDocumentsNoMatch")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-my-docs-search-meta",children:[s("myDocumentsResultCount",{count:String(we.length)}),ie==="semantic"&&!We?` · ${s("myDocumentsSemanticNotReadyShort")}`:""]}),e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:we.map(n=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:be.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Te(n.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:n.createdAt?Te(n.createdAt):"—"}),e.jsx("td",{className:"mdocs-my-docs-actions",children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})}):e.jsxs(e.Fragment,{children:[ke.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(i?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:(Ds??[{key:"",items:ke}]).flatMap(n=>{var q;const P=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:Ce==="domain"?be.get(n.key)||n.key:((q=n.items[0])==null?void 0:q.creatorName)||n.key})},`group-${n.key}`):null,G=n.items.map(X=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(X.documentId),children:X.displayName||X.relativePath||"Untitled"}),e.jsx("td",{children:be.get(X.domainId||"")||X.domainId||"—"}),e.jsx("td",{children:X.creatorName||X.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Te(X.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Te(X.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>Bs(X.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(X.documentId),children:s("bookmarkOpen")})]})]},X.documentId));return P?[P,...G]:G})})]})}),!ye&&e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(re>0?ue+1:0),total:String(re),count:String(He)})}),re>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const P=Number.parseInt(qe,10);if(!Number.isFinite(P))return;const G=Math.min(Math.max(P,1),re)-1;G!==ue&&je(G)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:re,"aria-label":s("myDocumentsJumpTo"),value:qe,onChange:n=>Ge(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),re>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:ue<=0,onClick:()=>je(ue-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:ue>=re-1,onClick:()=>je(ue+1),children:s("myDocumentsNext")})]})]})]})]})]}):x==="embeddingIndex"?e.jsx(pa,{onOpenDocument:a.onOpenDocument}):x==="domainManagement"?e.jsx(ia,{}):x==="memberTemplates"?e.jsx(la,{}):x==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(da,{}),e.jsx(ua,{})]}):e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:s("saveAndPublish")}),e.jsx("button",{type:"button",className:"secondary",onClick:b,children:s("backToDocs")})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoSave")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoSaveAlwaysOnDesc")})]}),e.jsx("span",{className:"mdocs-toggle active",role:"switch","aria-checked":"true","aria-disabled":"true",style:{opacity:.6,cursor:"not-allowed"},children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoPublish")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoPublishDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(S?" active":""),role:"switch","aria-checked":S,onClick:()=>A(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),ge>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>g(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",ge,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),v&&e.jsx(aa,{onPublish:R,onClose:()=>g(!1),onCountChange:fe,onRecover:a.onRecoverDraft})]}),$&&e.jsx(ys,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:y,onConfirm:()=>{V(!1),Xe()},onCancel:()=>V(!1)}),e.jsx(js,{open:Ps,title:s("docInfoInviteMember"),initialSelectedIds:[...Oe.keys()],initialPermissions:Oe,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Be(!1),onConfirm:n=>{Ks(n)}})]})}export{va as SettingsPage};
|
|
21
|
+
*/const ta=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],aa=Ae("sparkles",ta);function na({draft:a,onClose:s,onSuccess:p}){const{t:u,lang:b}=le(),[R,f]=t.useState([]),[w,N]=t.useState(a.domainId??""),[h,S]=t.useState([]),[A,I]=t.useState(""),[c,v]=t.useState(`${a.displayName||"untitled"}_recovered.md`),[g,x]=t.useState(!1),[C,z]=t.useState(null),j=t.useRef(null),B=t.useRef(!0);t.useEffect(()=>(B.current=!0,()=>{B.current=!1}),[]),t.useEffect(()=>{$s().then(k=>{B.current&&f(k)})},[]),t.useEffect(()=>{w&&(S([]),I(""),Vs(w).then(k=>{B.current&&S(k)}).catch(()=>{B.current&&S([])}))},[w]),t.useEffect(()=>{const k=window.setTimeout(()=>{var K;return(K=j.current)==null?void 0:K.focus()},0);return()=>window.clearTimeout(k)},[]),t.useEffect(()=>{const k=K=>{K.key==="Escape"&&s()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[s]);function O(k,K){for(const D of k){if(D.type==="folder"&&D.path===K)return D.documentId;if(D.type==="folder"){const E=O(D.children,K);if(E)return E}}return null}async function L(k){k.preventDefault(),x(!0),z(null);const K=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),D=K.endsWith(".md")?K:K+".md",E=D.replace(/\.md$/i,"");try{const m=A?`${A}/${D}`:D,o=A?O(h,A)??void 0:void 0;await qs({fileName:D,displayName:E,content:a.content,domainId:w,parentId:o}),p()}catch(m){z(se(u,m))}finally{x(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:k=>{k.target===k.currentTarget&&!g&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:u("recoverDraft")}),e.jsx("p",{className:"muted",children:u("recoverDraftDesc",{name:a.displayName||u("unknownTitle")})}),e.jsxs("form",{onSubmit:L,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[u("domainLabel"),R.length>0&&e.jsx(_s,{domains:R,value:w,onChange:N,onDomainsChange:f,ariaLabel:u("domainLabel"),localizeName:k=>de(k,b,u)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[u("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(Ws,{nodes:h,activeDocumentId:null,selectedParentPath:A,onOpen:()=>{},onOpenFolder:k=>I(k),onContextMenu:()=>{},onDeselect:()=>I("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[u("fileNameLabel"),e.jsx("input",{ref:j,value:c,onChange:k=>v(k.target.value),placeholder:"recovered.md",maxLength:200,disabled:g})]}),C&&e.jsx("div",{className:"mdocs-dialog-error",children:C}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!g&&s(),disabled:g,children:u("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:g,children:u(g?"creating":"create")})]})]})]})})}function ia({onPublish:a,onClose:s,onCountChange:p,onRecover:u}){const{t:b}=le(),[R,f]=t.useState([]),[w,N]=t.useState(new Set),[h,S]=t.useState(!1),[A,I]=t.useState(null),[c,v]=t.useState(null),[g,x]=t.useState(null),C=t.useRef(null),z=t.useRef(!0);t.useEffect(()=>(z.current=!0,We().then(o=>{if(!z.current)return;const y=o.filter(T=>!T.published);f(y),p==null||p(y.length)}),()=>{z.current=!1,C.current&&(clearTimeout(C.current),C.current=null)}),[]),t.useEffect(()=>{const o=y=>{y.key==="Escape"&&s()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[s]);const j=t.useCallback((o,y)=>{x({message:o,type:y}),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>x(null),3e3)},[]);async function B(o){await Hs(o),N(y=>new Set(y).add(o));try{await a(o),f(y=>{const T=y.filter($=>$.documentId!==o);return p==null||p(T.length),T}),j(b("published"),"success")}catch(y){y instanceof Js||j(b("publishFailed"),"error");const T=await Qs(o);T&&f($=>$.map(V=>V.documentId===o?T:V))}finally{N(y=>{const T=new Set(y);return T.delete(o),T})}}async function O(o){I(null),await ts(o),f(y=>{const T=y.filter($=>$.documentId!==o);return p==null||p(T.length),T}),j(b("draftDeleted"),"success")}function L(o){const y=R.find(T=>T.documentId===o);y&&v(y)}function k(o){v(null),ts(o),f(y=>{const T=y.filter($=>$.documentId!==o);return p==null||p(T.length),T}),u==null||u(R.find(y=>y.documentId===o)),j(b("published"),"success")}async function K(){S(!0);let o=0,y=0;for(const V of R)try{await a(V.documentId),o++}catch{y++}const $=(await We()).filter(V=>!V.published);f($),p==null||p($.length),y===0?j(b("publishAll"),"success"):j(`${o} published, ${y} failed`,"error"),S(!1)}const D=o=>new Date(o).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=o=>Gs(b,o,o.publishError??"UNKNOWN"),m=R;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mdocs-drawer-overlay",onClick:s}),e.jsxs("div",{className:"mdocs-drawer",role:"dialog","aria-modal":"true",children:[e.jsxs("header",{className:"mdocs-drawer-header",children:[e.jsxs("div",{className:"mdocs-drawer-header-text",children:[e.jsxs("h2",{className:"mdocs-drawer-title",children:[b("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:b("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":b("close"),children:"×"})]}),e.jsx("div",{className:"mdocs-drawer-body",children:m.length===0?e.jsxs("div",{className:"mdocs-drawer-empty",children:[e.jsx("div",{className:"mdocs-drawer-empty-icon","aria-hidden":"true",children:"✓"}),e.jsx("p",{className:"mdocs-drawer-empty-text",children:b("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(o=>{const y=!!o.publishError;return e.jsxs("div",{className:y?"mdocs-drawer-item mdocs-drawer-item-failed":"mdocs-drawer-item",children:[e.jsx("div",{className:"mdocs-drawer-item-icon","aria-hidden":"true",children:"📄"}),e.jsxs("div",{className:"mdocs-drawer-item-info",children:[e.jsx("span",{className:"mdocs-drawer-item-name",children:o.displayName||b("unknownTitle")}),y?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[D(o.publishErrorAt)," · ",E(o)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[D(o.updatedAt)," · ",b("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[y?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:h,onClick:()=>L(o.documentId),children:b("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(o.documentId)||h,onClick:()=>void B(o.documentId),children:w.has(o.documentId)?b("publishing"):b("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:h,onClick:()=>I(o.documentId),children:b("delete")})]})]},o.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:b("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||h,onClick:()=>void K(),children:h?b("publishing"):`${b("publishAll")} (${m.length})`})]}),g&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+g.type,role:"status",children:g.message})]}),A&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:o=>{o.target===o.currentTarget&&I(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:b("delete")}),e.jsx("p",{className:"muted",children:b("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>I(null),children:b("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void O(A),children:b("delete")})]})]})}),c&&e.jsx(na,{draft:c,onClose:()=>v(null),onSuccess:()=>k(c.documentId)})]})}function la(){const{t:a,lang:s}=le(),p=gs(),u=t.useRef(!1),[b,R]=t.useState([]),[f,w]=t.useState(!1),[N,h]=t.useState(""),[S,A]=t.useState("restricted"),[I,c]=t.useState(!1),[v,g]=t.useState(null),[x,C]=t.useState(null),[z,j]=t.useState(""),[B,O]=t.useState(""),[L,k]=t.useState("all"),[K,D]=t.useState(null);t.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const E=t.useCallback(async()=>{w(!0),g(null);try{const l=await fs();if(!u.current)return;R(l)}catch(l){if(!u.current)return;g(se(a,l))}finally{u.current&&w(!1)}},[a]);t.useEffect(()=>{E()},[E]);async function m(l){if(l.preventDefault(),!N.trim()){g(a("domainNameRequired"));return}c(!0),g(null);try{if(await st({domainName:N.trim(),permission:S}),!u.current)return;h(""),A("restricted"),await E()}catch(r){if(!u.current)return;g(se(a,r))}finally{u.current&&c(!1)}}async function o(l){if(z.trim()){g(null);try{if(await et(l,z.trim()),!u.current)return;C(null),D(null),await E()}catch(r){if(!u.current)return;g(se(a,r))}}}function y(l){C(l.domainId),j(l.domainName),D(null)}function T(){C(null),D(null)}async function $(l,r){g(null);try{if(await Xs(l,r),!u.current)return;D(null),await E()}catch(U){if(!u.current)return;g(se(a,U))}}async function V(l){if(window.confirm(a("deleteDomainConfirmDetail",{name:l.domainName,count:String(l.docCount)}))){g(null);try{if(await Ys(l.domainId),!u.current)return;await E()}catch(r){if(!u.current)return;g(se(a,r))}}}const Q=t.useCallback(l=>Zs(l,a),[a]),Z=t.useCallback(l=>de(l.domainName,s,a),[s,a]),ee=t.useMemo(()=>{const l=B.trim().toLowerCase();return b.filter(r=>L!=="all"&&r.permission!==L?!1:l?de(r.domainName,s,a).toLowerCase().includes(l)||r.domainName.toLowerCase().includes(l):!0)},[b,B,L,s,a]),H=t.useCallback((l,r)=>{const U=Q(l.permission);return r?`${U} ${a("domainTypeBuiltinSuffix")}`:U},[Q,a]);return{domains:b,loadingDomains:f,domainError:v,newDomainName:N,setNewDomainName:h,newDomainPermission:S,setNewDomainPermission:A,creating:I,handleCreateDomain:m,renamingId:x,setRenamingId:C,renameDraft:z,setRenameDraft:j,startRename:y,cancelRename:T,handleRename:o,changeTypeForId:K,setChangeTypeForId:D,handlePermissionChange:$,handleDelete:V,domainSearch:B,setDomainSearch:O,domainFilter:L,setDomainFilter:k,filteredDomains:ee,visitorId:p,plabel:Q,localizeDomain:Z,domainTypeLabel:H}}const ls={private:0,restricted:1,public:2};function cs(a){return Object.prototype.hasOwnProperty.call(ls,a)?ls[a]:null}function os(a,s){const p=cs(a),u=cs(s);return p===null||u===null?"invalid":u>p?"upgrade":u<p?"downgrade":"same"}function ca(){const{t:a}=le(),s=la(),[p,u]=t.useState([]),[b,R]=t.useState(null),[f,w]=t.useState(""),N=t.useRef(null),[h,S]=t.useState(null),A=t.useCallback(async()=>{try{const c=await xs();u(c)}catch{u([])}},[]);t.useEffect(()=>{A()},[A]),t.useEffect(()=>{if(!s.changeTypeForId)return;const c=v=>{var g;(g=N.current)!=null&&g.contains(v.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function I(c){R(null);try{const v=await ct(c.domainId);S({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:v.map(g=>g.visitorId),memberRows:v})}catch(v){R({kind:"err",text:translateError(a,v)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:a("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:a("domainMgmtRestrictedMemberHint")}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-create",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:a("createDomain")}),e.jsxs("form",{onSubmit:s.handleCreateDomain,className:"mdocs-domain-mgmt-create-form",children:[e.jsxs("label",{className:"mdocs-domain-mgmt-field",children:[e.jsx("span",{className:"mdocs-domain-mgmt-label",children:a("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:a("domainName"),maxLength:100,disabled:s.creating,className:"mdocs-domain-name-input"})]}),e.jsxs("fieldset",{className:"mdocs-domain-mgmt-fieldset",children:[e.jsx("legend",{className:"mdocs-domain-mgmt-label",children:a("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:$e.map(c=>e.jsxs("label",{className:"mdocs-domain-mgmt-radio",children:[e.jsx("input",{type:"radio",name:"newDomainPermission",checked:s.newDomainPermission===c,onChange:()=>s.setNewDomainPermission(c),disabled:s.creating}),e.jsx("span",{children:s.plabel(c)})]},c))})]}),e.jsx("button",{type:"submit",className:"primary mdocs-domain-mgmt-submit",disabled:s.creating,children:s.creating?a("creating"):a("create")})]})]}),b&&e.jsx("div",{className:"mdocs-settings-card",style:{color:b.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:b.text})}),s.domainError&&e.jsx("div",{className:"mdocs-settings-card mdocs-domain-error",children:e.jsx("span",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)"},children:s.domainError})}),e.jsxs("div",{className:"mdocs-settings-card mdocs-domain-mgmt-toolbar",children:[e.jsx("input",{type:"search",value:s.domainSearch,onChange:c=>s.setDomainSearch(c.target.value),placeholder:a("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":a("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":a("domainPermission"),children:["all",...$e].map(c=>e.jsx("button",{type:"button",className:"mdocs-domain-mgmt-filter"+(s.domainFilter===c?" active":""),"aria-pressed":s.domainFilter===c,onClick:()=>s.setDomainFilter(c),children:c==="all"?a("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("loading")})}):s.domains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("noDomains")})}):s.filteredDomains.length===0?e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:a("domainNoMatch")})}):e.jsx("div",{className:"mdocs-settings-card mdocs-domain-table-wrap",children:e.jsxs("table",{className:"mdocs-domain-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:a("domainColName")}),e.jsx("th",{scope:"col",children:a("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:a("domainColDocCount")}),e.jsx("th",{scope:"col",children:a("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const v=tt(c,s.visitorId),g=at(c.domainId),x=nt(c),C=os(c.permission,"public")==="upgrade",z=C?x?a("domainTooltipTypeLocked"):void 0:a("domainPermissionAlreadyTop");return e.jsxs("tr",{className:g?"mdocs-domain-table-row-builtin":void 0,children:[e.jsx("td",{children:s.renamingId===c.domainId?e.jsxs("div",{className:"mdocs-domain-table-rename",children:[e.jsx("input",{value:s.renameDraft,onChange:j=>s.setRenameDraft(j.target.value),maxLength:100,autoFocus:!0,className:"mdocs-domain-name-input"}),e.jsx("button",{type:"button",className:"primary",onClick:()=>void s.handleRename(c.domainId),children:a("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:a("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),g&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:a("domainBuiltIn")}),!v&&!g&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:a("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:z,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,g)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[g&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:a("domainNotModifiable")}),!g&&!v&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:a("domainNotCreator")}),!g&&v&&s.changeTypeForId===c.domainId&&e.jsxs("div",{className:"mdocs-domain-change-type-panel",ref:N,children:[e.jsx("div",{className:"mdocs-domain-type-segment",role:"radiogroup","aria-label":a("domainChangeType"),children:$e.map(j=>{const O=os(c.permission,j)==="downgrade";return e.jsx("span",{title:O?a("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":f===j,className:f===j?"active":"",disabled:O,onClick:()=>w(j),children:s.plabel(j)})},j)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":a("save"),disabled:f===""||f===c.permission,onClick:()=>{f&&f!==c.permission&&s.handlePermissionChange(c.domainId,f)},children:e.jsx(Vt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":a("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(it,{size:14,strokeWidth:2.5})})]}),!g&&v&&s.renamingId!==c.domainId&&s.changeTypeForId!==c.domainId&&e.jsxs("div",{className:"mdocs-domain-action-buttons",children:[c.permission==="restricted"&&e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--primary",onClick:()=>void I(c),children:a("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:x?a("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:x,children:a("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:z,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!C,children:a("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:x?a("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:x,children:a("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(Ns,{open:h!==null,title:a("domainMembersPickerTitle"),initialSelectedIds:(h==null?void 0:h.initialIds)??[],lockedIds:h?[h.creatorVisitorId]:[],seedMembers:h==null?void 0:h.memberRows,templates:p,onClose:()=>S(null),onConfirm:async c=>{h&&(await lt(h.domainId,c),R({kind:"ok",text:a("domainMembersSaved",{count:String(c.length)})}))}})]})}function rs(a){return a.length<=6?a:`${a.slice(0,6)}…`}function oa(){const{t:a}=le(),s=t.useRef(!0),[p,u]=t.useState([]),[b,R]=t.useState(!0),[f,w]=t.useState(null),[N,h]=t.useState(1),[S,A]=t.useState(null),[I,c]=t.useState(""),[v,g]=t.useState([]),[x,C]=t.useState(!1),[z,j]=t.useState(null),[B,O]=t.useState(!1),L=gs(),[k,K]=t.useState([]),[D,E]=t.useState("idle"),[m,o]=t.useState("");t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),t.useEffect(()=>{E("loading"),ys().then(d=>{s.current&&(K(d),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const y=t.useMemo(()=>{const d=new Map;for(const M of k)d.set(M.visitorId,M.visitorName);return d},[k]),T=t.useCallback(async()=>{R(!0),j(null);try{const d=await xs();s.current&&u(d)}catch(d){s.current&&j(se(a,d))}finally{s.current&&R(!1)}},[a]);t.useEffect(()=>{T()},[T]);const $=t.useMemo(()=>v.map(d=>{const M=k.find(W=>W.visitorId===d);return{visitorId:d,name:M?M.visitorName:a("visitorPickerUnknownVisitor"),muted:!M}}),[v,k,a]);function V(d){g(M=>M.includes(d)?M.filter(W=>W!==d):[...M,d])}const Q=N===1?I.trim().length>0:N===2?v.length>0:!0;function Z(){if(!(N>=3)){if(!Q){O(!0);return}O(!1),h(N+1),o("")}}function ee(){N<=1||(O(!1),h(N-1))}function H(){w(null),A(null),c(""),g(L?[L]:[]),j(null),h(1),o(""),O(!1)}function l(d){w(null),A(d.id),c(d.displayName);const M=L&&!d.visitorIds.includes(L)?[...d.visitorIds,L]:[...d.visitorIds];g(M),j(null),h(1),o(""),O(!1)}async function r(){if(!(!I.trim()||v.length===0)){C(!0),j(null);try{if(S===null?await ot({displayName:I.trim(),visitorIds:v}):await rt(S,{displayName:I.trim(),visitorIds:v}),!s.current)return;H(),await T()}catch(d){if(!s.current)return;j(se(a,d))}finally{s.current&&C(!1)}}}async function U(d){C(!0),j(null);try{if(await dt(d),!s.current)return;w(null),S===d&&H(),await T()}catch(M){if(!s.current)return;j(se(a,M))}finally{s.current&&C(!1)}}const _=[{key:1,label:a("memberTemplateStepName")},{key:2,label:a("memberTemplateStepMembers")},{key:3,label:a("memberTemplateStepSave")}],F=`${(N-1)/2*100}%`;return e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:a(S!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),S!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:H,style:{fontSize:12},children:a("memberTemplateCancelEdit")})]}),e.jsxs("div",{className:"mdocs-wizard-progress",children:[e.jsx("div",{className:"mdocs-wizard-progress-track",children:e.jsx("div",{className:"mdocs-wizard-progress-fill",style:{width:F}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:_.map(d=>{const M=N===d.key,W=N>d.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${M?" current":""}${W?" done":""}`,children:W?"✓":d.key}),e.jsx("span",{className:`mdocs-wizard-step-label${M?" current":""}${W?" done":""}`,children:d.label})]},d.key)})})]}),z&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:z}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsxs("div",{className:"mdocs-settings-card mdocs-wizard-card",children:[N===1&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx("input",{className:"mdocs-wizard-name-input",value:I,onChange:d=>c(d.target.value),placeholder:a("memberTemplateNamePlaceholder"),maxLength:200,disabled:x,autoFocus:!0,"aria-invalid":B&&!I.trim()}),B&&!I.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:a("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(Ut,{visitors:k,loadState:D,searchFilter:m,onSearchChange:o,selectedIds:new Set(v),onToggle:V,selectedRows:$,myVisitorId:L}),e.jsx("p",{className:`mdocs-wizard-hint${B&&v.length===0?" danger":""}`,children:"💡 "+a("memberTemplateStep2Hint")})]}),N===3&&e.jsx("div",{className:"mdocs-wizard-step-content",children:e.jsxs("div",{className:"mdocs-wizard-preview-card",children:[e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:I})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:a("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:a("memberTemplateSelectedSummary",{count:String(v.length)})})]}),v.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[v.slice(0,15).map(d=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:rs(d)},d)),v.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",v.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:ee,children:["← ",a("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:Z,children:[a("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void r(),children:a(x?"saving":S===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:a("memberTemplateSavedList")}),b?e.jsx("span",{className:"mdocs-settings-item-desc",children:a("loading")}):p.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateEmpty")}),S===null&&e.jsx("button",{type:"button",className:"primary",onClick:H,children:a("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:p.map(d=>e.jsx("li",{className:"mdocs-member-template-row",children:f===d.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:a("memberTemplateConfirmDeleteDesc",{name:d.displayName})}),e.jsxs("div",{className:"mdocs-member-template-confirm-actions",children:[e.jsx("button",{type:"button",className:"secondary",style:{color:"var(--mdocs-danger)"},onClick:()=>void U(d.id),children:a(x?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(null),children:a("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:d.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:a("memberTemplateCount",{count:String(d.visitorIds.length)})}),d.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:d.visitorIds.map(M=>e.jsx("span",{className:"mdocs-member-template-tag",children:y.get(M)??rs(M)},M))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>l(d),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(d.id),children:a("memberTemplateDelete")})]})]})},d.id))})]})]})]})}const ra=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],ds=[{value:"off",label:"关(不思考)"},{value:"low",label:"低(推荐)"},{value:"high",label:"高"},{value:"max",label:"最大"}],da=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function ma(a,s,p){return a==="deepseek"?"Deepseek":s||p}function ms(a){return`${ma(a.kind,a.providerId,a.name)} · ${a.modelId} · ${a.name}`}function ua(){const{t:a}=le(),s=t.useRef(!0),[p,u]=t.useState(""),[b,R]=t.useState([]),[f,w]=t.useState(null),[N,h]=t.useState(null),[S,A]=t.useState("deepseek"),[I,c]=t.useState(""),[v,g]=t.useState(""),[x,C]=t.useState(""),[z,j]=t.useState("openai-completions"),[B,O]=t.useState("deepseek-flash"),[L,k]=t.useState(1e6),[K,D]=t.useState(300),[E,m]=t.useState("low"),[o,y]=t.useState(""),[T,$]=t.useState(!1),[V,Q]=t.useState(null),[Z,ee]=t.useState(!1),[H,l]=t.useState(!0),[r,U]=t.useState(!1),[_,F]=t.useState(null),[d,M]=t.useState(!1),[W,te]=t.useState(!1),[ce,ae]=t.useState(!1),[Y,pe]=t.useState(null),[ge,fe]=t.useState(null),xe=t.useRef(!1);t.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const oe=t.useCallback(async()=>{const i=await mt();if(s.current)return R(i),i},[]);function ne(){h(null),A("deepseek"),c(""),g(""),C(""),j("openai-completions"),O("deepseek-flash"),k(1e6),D(300),m("low"),y(""),$(!1),Q(null),ee(!1),te(!1),ae(!1),F(null),M(!1)}function Me(i){h(i.id),A(i.kind),c(i.name),g(i.providerId??""),C(i.baseUrl),j(i.apiType);const J=i.modelId.trim(),ie=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);O(i.kind==="deepseek"?J==="deepseek-v4-pro"?"deepseek-v4-pro":ie.has(J)?"deepseek-flash":J||"deepseek-flash":J),k(i.contextWindow||1e6),D(typeof i.runTimeoutSeconds=="number"&&i.runTimeoutSeconds>0?i.runTimeoutSeconds:300),m(i.thinkingLevel==="off"||i.thinkingLevel==="high"||i.thinkingLevel==="max"?i.thinkingLevel:"low"),$(i.hasApiKey),Q(i.apiKeyMasked),y(""),ee(i.isDefault)}t.useEffect(()=>{(async()=>{try{const i=await ut();if(!s.current)return;u(i.visitorName);const J=await oe();if(!s.current||!J)return;J.length===0&&(ne(),w("create"))}catch(i){if(!s.current)return;F(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&l(!1)}})()},[oe]);function Ne(){ne(),w("create")}function me(i){Me(i),w("edit"),M(!1),F(null)}function ve(){ne(),w(null)}async function ke(i){if(!(i.isDefault||ge)){fe(i.id),F(null);try{await ht(i.id),await oe()}catch(J){if(!s.current)return;F(J instanceof Error?J.message:String(J))}finally{s.current&&fe(null)}}}async function Pe(){if(Y){U(!0),F(null);try{await gt(Y.id);const i=await oe();if(!s.current)return;f==="edit"&&N===Y.id&&ve(),((i==null?void 0:i.length)??0)===0&&(ne(),w("create"))}catch(i){if(!s.current)return;F(i instanceof Error?i.message:String(i))}finally{s.current&&(U(!1),pe(null))}}}async function Ee(){U(!0),F(null),M(!1);try{const i=S==="custom"?{...f==="edit"&&N?{id:N}:{},...f==="create"&&Z?{isDefault:!0}:{},kind:S,baseUrl:x,modelId:B,providerId:v.trim()||void 0,apiType:z,name:I,contextWindow:L,runTimeoutSeconds:K,thinkingLevel:E,...o.trim()?{apiKey:o.trim()}:{}}:{...f==="edit"&&N?{id:N}:{},...f==="create"&&Z?{isDefault:!0}:{},kind:S,modelId:B,name:I,contextWindow:L,runTimeoutSeconds:K,thinkingLevel:E,...o.trim()?{apiKey:o.trim()}:{}};if(await pt(i),!s.current)return;await oe(),M(!0),w(null),ne()}catch(i){if(!s.current)return;F(i instanceof Error?i.message:String(i))}finally{s.current&&U(!1)}}const Se=f!==null;return e.jsxs("div",{className:"mdocs-agent-config-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:a("agentConfig")}),H?null:e.jsx("button",{type:"button",className:"secondary",onClick:Ne,children:"添加配置"})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!H&&b.length>0?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:"选择默认配置后,智能助手与帮写将使用该模型。"}),e.jsx("ul",{className:"mdocs-agent-config-list",children:b.map(i=>e.jsxs("li",{className:"mdocs-agent-config-item",children:[e.jsxs("label",{className:"mdocs-agent-config-item-default",children:[e.jsx("input",{type:"radio",name:"agent-default-config",checked:i.isDefault,disabled:ge!==null,onChange:()=>void ke(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:ms(i)}),i.kind==="custom"?e.jsx("span",{className:"mdocs-agent-badge",children:"自定义"}):null,e.jsx("p",{className:"mdocs-agent-config-item-meta",children:i.hasApiKey?`Key ${i.apiKeyMasked??"已配置"}`:"未配置 Key"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>me(i),children:a("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>pe(i),children:"删除"})]})]},i.id))}),d?e.jsx("p",{className:"mdocs-agent-config-ok",children:a("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,Se?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsxs("p",{className:"mdocs-agent-config-lead",children:[f==="create"?"新建模型配置。":"编辑模型配置。","可以保存多套,勾选一条作为默认。智能助手和帮写使用默认那套。"]}),e.jsxs("div",{className:"mdocs-agent-form",children:[e.jsxs("div",{className:"mdocs-agent-kind-tabs",role:"tablist","aria-label":"配置方式",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":S==="deepseek",className:S==="deepseek"?"active":"",onClick:()=>A("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":S==="custom",className:S==="custom"?"active":"",onClick:()=>A("custom"),children:"自定义"})]}),S==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigModel")}),e.jsx(Ie,{options:[...ra],value:B,onChange:O})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"思考强度"}),e.jsx(Ie,{options:[...ds],value:E,onChange:i=>m(i)})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:W?"text":"password",value:o,onChange:i=>y(i.target.value),placeholder:T?a("agentConfigApiKeyConfigured").replace("{{masked}}",V??"…"):a("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(W?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>te(i=>!i),children:W?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:x,onChange:i=>{const J=i.target.value;if(C(J),xe.current)return;J.toLowerCase().includes("anthropic")?j("anthropic-messages"):j("openai-completions")},placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Model ID"}),e.jsx("input",{type:"text",value:B,onChange:i=>O(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:W?"text":"password",value:o,onChange:i=>y(i.target.value),placeholder:T?a("agentConfigApiKeyConfigured").replace("{{masked}}",V??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":a(W?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>te(i=>!i),children:W?"隐藏":"显示"})]})]})]}),S==="custom"?e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"思考强度"}),e.jsx(Ie,{options:[...ds],value:E,onChange:i=>m(i)})]}):null,e.jsxs("details",{className:"mdocs-agent-advanced",open:ce,onToggle:i=>ae(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),S==="custom"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"Provider ID(选填)"}),e.jsx("input",{type:"text",value:v,onChange:i=>g(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ie,{options:[...da],value:z,onChange:i=>{xe.current=!0,j(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigName")}),e.jsx("input",{type:"text",value:I,onChange:i=>c(i.target.value),placeholder:a("agentConfigNameDefault").replace("{{name}}",p||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:L,onChange:i=>k(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigContextWindowDesc")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:a("agentConfigRunTimeout")}),e.jsx("input",{type:"number",min:60,max:3600,step:30,value:K,onChange:i=>D(Math.max(60,Number(i.target.value)||300))}),e.jsx("p",{className:"mdocs-agent-field-hint",children:a("agentConfigRunTimeoutDesc")})]})]}),f==="create"&&b.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:Z,onChange:i=>ee(i.target.checked)}),e.jsx("span",{children:"保存后设为默认配置"})]}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null,e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void Ee(),disabled:r,children:a(r?"saving":"save")}),b.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ve,disabled:r,children:a("cancel")}):null]})]})]}):H?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:a("loading")})}):null]}),Y?e.jsx(bs,{title:"删除配置",message:`确定删除「${ms(Y)}」?${Y.isDefault&&b.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:a("cancel"),onConfirm:()=>void Pe(),onCancel:()=>pe(null)}):null]})}const ha=/^[A-Za-z0-9_]+$/;function _e(a){return ha.test(a.trim())}function pa(){const a=t.useRef(!0),[s,p]=t.useState([]),[u,b]=t.useState(!0),[R,f]=t.useState(null),[w,N]=t.useState(null),[h,S]=t.useState(!1),[A,I]=t.useState(""),[c,v]=t.useState(""),[g,x]=t.useState(""),[C,z]=t.useState(!1);t.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);async function j(){b(!0),f(null);try{const m=await ft();if(!a.current)return;p(m)}catch(m){if(!a.current)return;f(m instanceof Error?m.message:String(m))}finally{a.current&&b(!1)}}t.useEffect(()=>{j()},[]);function B(){S(!0),N(null),I(""),v(""),x(""),f(null)}function O(m){S(!1),N(m.id),I(m.name),v(m.description),x(m.body),f(null)}function L(){S(!1),N(null),I(""),v(""),x("")}async function k(){const m=A.trim();if(!_e(m)){f("名称仅允许英文、数字、下划线");return}if(!g.trim()){f("正文不能为空");return}z(!0),f(null);try{if(h?await xt({name:m,description:c,body:g}):w&&await yt(w,{name:m,description:c,body:g}),!a.current)return;L(),await j()}catch(o){if(!a.current)return;f(o instanceof Error?o.message:String(o))}finally{a.current&&z(!1)}}async function K(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){f(null);try{if(await bt(m),!a.current)return;w===m&&L(),await j()}catch(o){if(!a.current)return;f(o instanceof Error?o.message:String(o))}}}const D=h||w!==null,E=!A.trim()||_e(A);return e.jsxs("div",{className:"mdocs-agent-skills-panel",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsxs("h2",{className:"mdocs-settings-title",children:["Agent Skills",!u&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),D?null:e.jsx("button",{type:"button",className:"secondary",onClick:B,children:"新建"})]}),e.jsx("div",{className:"mdocs-settings-cards",children:e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"mdocs-settings-item-desc mdocs-agent-skills-lead",children:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),R?e.jsx("p",{className:"mdocs-agent-skills-error",children:R}):null,D?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:h?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:A,onChange:m=>I(m.target.value),maxLength:64,spellCheck:!1,autoComplete:"off",placeholder:"e.g. weekly_report",className:E?void 0:"mdocs-agent-skills-input-invalid"}),E?e.jsx("span",{className:"mdocs-agent-skills-hint",children:"引用与索引键,保存后按此名称使用"}):e.jsx("span",{className:"mdocs-agent-skills-hint-bad",children:"仅允许 A–Z、a–z、0–9、_"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"简介(可选)"}),e.jsx("input",{type:"text",value:c,onChange:m=>v(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:g,onChange:m=>x(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void k(),disabled:C||!E||!A.trim()||!g.trim(),children:C?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:L,disabled:C,children:"取消"})]})]}):null,u?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!u&&s.length===0&&!D?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:B,children:"新建第一个"})]}):null,!u&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const o=_e(m.name),y=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(y?" mdocs-agent-skills-item-active":""),children:[e.jsxs("div",{className:"mdocs-agent-skills-item-main",children:[e.jsxs("div",{className:"mdocs-agent-skills-item-title-row",children:[e.jsx("code",{className:"mdocs-agent-skills-name",children:m.name}),o?null:e.jsx("span",{className:"mdocs-agent-skills-badge-warn",title:"名称含非法字符,请编辑改为英文数字下划线",children:"需改名"})]}),e.jsx("span",{className:"mdocs-agent-skills-desc",children:m.description.trim()||"无简介"})]}),e.jsxs("div",{className:"mdocs-agent-skills-item-actions",children:[e.jsx("button",{type:"button",className:"secondary small",onClick:()=>O(m),disabled:D&&!y,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void K(m.id),disabled:D,children:"删除"})]})]},m.id)})}):null]})})]})}const ga={algorithm:Wt.defaultAlgorithm,token:{colorPrimary:"#4CAF50",colorLink:"#4CAF50",colorInfo:"#4CAF50",colorSuccess:"#66BB6A",colorBgBase:"#ffffff",colorBgContainer:"#ffffff",colorText:"#212121",colorTextSecondary:"#616161",colorBorder:"#E0E0E0",colorFillSecondary:"#E8F5E9",borderRadius:8,fontFamily:"inherit"},components:{Table:{headerBg:"#F5F5F5",headerColor:"#212121",rowHoverBg:"#E8F5E9",borderColor:"#E0E0E0"},Button:{primaryShadow:"none"},Tag:{defaultBg:"#F5F5F5",defaultColor:"#616161"}}};function us(a,s){if(!a)return"—";const p=new Date(a);return Number.isNaN(p.getTime())?"—":p.toLocaleString(s==="zh"?"zh-CN":"en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function fa(a){const{t:s,lang:p}=le(),[u,b]=t.useState(!1),[R,f]=t.useState(!1),[w,N]=t.useState(!1),[h,S]=t.useState([]),[A,I]=t.useState([]),[c,v]=t.useState(null),[g,x]=t.useState(null),[C,z]=t.useState(""),[j,B]=t.useState("keyword"),[O,L]=t.useState(null),[k,K]=t.useState(!1),D=t.useRef(0),[E,m]=t.useState({current:1,pageSize:20}),[o,y]=t.useState(0);async function T(){b(!0),x(null);try{const l=await jt();N(l.modelReady),S(l.items),I([]),y(l.items.length),m(r=>({...r,current:1}))}catch(l){x(se(s,l)||s("embeddingIndexLoadFailed"))}finally{b(!1)}}t.useEffect(()=>{T()},[]);const $=t.useMemo(()=>{const l=new Map;for(const r of h)l.has(r.domainId)||l.set(r.domainId,de(r.domainName,p,s));return Array.from(l.entries()).map(([r,U])=>({text:U,value:r}))},[h,p,s]),V=t.useMemo(()=>{const l=C.trim().toLowerCase();return l?h.filter(r=>(r.displayName||"").toLowerCase().includes(l)||(r.relativePath||"").toLowerCase().includes(l)||r.documentId.toLowerCase().includes(l)):h},[h,C]),Q=j==="semantic"&&!!C.trim();t.useEffect(()=>{if(j!=="semantic")return;const l=C.trim();if(!l){D.current+=1,L(null);return}const r=++D.current;K(!0);const U=window.setTimeout(()=>{(async()=>{try{const _=await js({query:l,mode:"semantic",topN:50});if(r!==D.current)return;const F=new Map(h.map(d=>[d.documentId,d]));L(_.results.map(d=>{const M=F.get(d.documentId);return M?{...M,snippet:d.snippet}:{documentId:d.documentId,displayName:d.displayName,relativePath:d.relativePath,domainId:d.domainId,domainName:d.domainId,documentUpdatedAt:d.updatedAt,chunkCount:0,chunkUnknown:!0,embeddingUpdatedAt:null,snippet:d.snippet}}))}catch{r===D.current&&L([])}finally{r===D.current&&K(!1)}})()},300);return()=>window.clearTimeout(U)},[j,C,h]);const Z=Q?O??[]:V;t.useEffect(()=>{y(Z.length),m(l=>({...l,current:1}))},[Z.length,j]);const ee=t.useMemo(()=>[{title:s("myDocumentsColTitle"),dataIndex:"displayName",key:"displayName",ellipsis:!0,sorter:(l,r)=>(l.displayName||l.relativePath).localeCompare(r.displayName||r.relativePath,p==="zh"?"zh":"en"),render:(l,r)=>e.jsxs("div",{style:{minWidth:0},children:[e.jsx("button",{type:"button",className:"mdocs-linkish",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontWeight:500,color:"inherit",textAlign:"left"},onClick:()=>a.onOpenDocument(r.documentId),children:r.displayName||r.relativePath||"Untitled"}),r.snippet&&e.jsx("div",{className:"mdocs-embedding-index-snippet",title:r.snippet,children:r.snippet})]})},{title:s("myDocumentsColDomain"),dataIndex:"domainId",key:"domainId",width:160,ellipsis:!0,filters:$,onFilter:(l,r)=>r.domainId===l,sorter:(l,r)=>de(l.domainName,p,s).localeCompare(de(r.domainName,p,s),p==="zh"?"zh":"en"),render:(l,r)=>de(r.domainName,p,s)},{title:s("embeddingIndexColDocUpdated"),dataIndex:"documentUpdatedAt",key:"documentUpdatedAt",width:160,sorter:(l,r)=>new Date(l.documentUpdatedAt).getTime()-new Date(r.documentUpdatedAt).getTime(),defaultSortOrder:"descend",render:l=>us(l,p)},{title:s("embeddingIndexColStatus"),dataIndex:"chunkCount",key:"buildStatus",width:140,filters:[{text:s("embeddingIndexFilterBuilt"),value:"built"},{text:s("embeddingIndexFilterMissing"),value:"missing"}],onFilter:(l,r)=>l==="built"?r.chunkCount>0:r.chunkCount===0,sorter:(l,r)=>l.chunkCount-r.chunkCount,render:(l,r)=>r.chunkUnknown?e.jsx(Ve,{color:"success",children:s("embeddingIndexStatusBuiltUnknown")}):l>0?e.jsx(Ve,{color:"success",children:s("embeddingIndexStatusReady",{chunks:String(l)})}):e.jsx(Ve,{children:s("embeddingIndexStatusMissing")})},{title:s("embeddingIndexColBuiltAt"),dataIndex:"embeddingUpdatedAt",key:"embeddingUpdatedAt",width:160,sorter:(l,r)=>{const U=l.embeddingUpdatedAt?new Date(l.embeddingUpdatedAt).getTime():0,_=r.embeddingUpdatedAt?new Date(r.embeddingUpdatedAt).getTime():0;return U-_},render:l=>us(l,p)}],[$,p,a,s]);async function H(){const l=A.map(String);if(l.length!==0){f(!0),v(null),x(null);try{const r=await Nt(l);N(r.modelReady),v(s("embeddingIndexRebuildResult",{ok:String(r.ok.length),skipped:String(r.skipped.length),failed:String(r.failed.length)})),await T()}catch(r){x(se(s,r)||s("embeddingIndexRebuildFailed"))}finally{f(!1)}}}return e.jsx(_t,{theme:ga,children:e.jsxs("div",{className:"mdocs-settings mdocs-embedding-index",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("embeddingIndex")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("p",{className:"muted",style:{marginTop:0},children:s("embeddingIndexDesc")}),e.jsxs("p",{style:{margin:"0 0 12px",fontSize:13},children:[s("embeddingIndexModel"),":"," ",e.jsx("strong",{children:s(w?"embeddingIndexModelReady":"embeddingIndexModelPending")})]}),e.jsxs(qt,{wrap:!0,style:{marginBottom:12},children:[e.jsx(Gt,{value:j,"aria-label":s("myDocumentsSearchMode"),onChange:l=>B(l),options:[{label:s("myDocumentsModeKeyword"),value:"keyword"},{label:s("myDocumentsModeSemantic"),value:"semantic"}]}),e.jsx(Ht.Search,{allowClear:!0,placeholder:s(j==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),"aria-label":s(j==="semantic"?"embeddingIndexSearchSemanticPlaceholder":"embeddingIndexSearchPlaceholder"),value:C,onChange:l=>z(l.target.value),style:{width:240},disabled:u||R}),e.jsx(ns,{onClick:()=>void T(),disabled:u||R,children:s("embeddingIndexRefresh")}),e.jsx(ns,{type:"primary",onClick:()=>void H(),disabled:R||A.length===0,loading:R,children:s("embeddingIndexRebuildSelected",{count:String(A.length)})})]}),c&&e.jsx("p",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:c}),g&&e.jsx("p",{className:"mdocs-doc-search-error",style:{marginBottom:8},children:g}),Q&&!w&&e.jsx("p",{className:"muted",style:{margin:"0 0 8px",fontSize:13},children:s("myDocumentsSemanticNotReady")}),(()=>{const l=Number(E.pageSize)||20,r=Number(E.current)||1,U=o,_=Math.max(1,Math.ceil(U/l)||1);return e.jsx(Jt,{size:"small",rowKey:"documentId",loading:u||Q&&k,columns:ee,dataSource:Z,rowSelection:{selectedRowKeys:A,onChange:F=>I(F)},pagination:{current:r,pageSize:l,total:U,showSizeChanger:!1,showQuickJumper:!1,showTotal:(F,d)=>s("embeddingIndexPageTotal",{from:String(d[0]??0),to:String(d[1]??0),total:String(F)})},onChange:(F,d,M,W)=>{const te=F.pageSize??l,ce=W.currentDataSource.length,ae=Math.max(1,Math.ceil(ce/te)||1);let Y=F.current??1;Y>ae&&(Y=ae),y(ce),m({current:Y,pageSize:te})},locale:{emptyText:C.trim()?s("myDocumentsNoMatch"):s("embeddingIndexEmpty"),filterReset:s("embeddingIndexFilterReset"),filterConfirm:s("embeddingIndexFilterOk")},scroll:{x:900},footer:()=>e.jsxs("div",{className:"mdocs-embedding-index-pager",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"flex-end",gap:10},children:[e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexPageSize")}),e.jsx(is,{size:"small",min:5,max:200,step:5,value:l,controls:!0,changeOnWheel:!0,disabled:u||R,"aria-label":s("embeddingIndexPageSize"),onChange:F=>{if(F==null||!Number.isFinite(Number(F)))return;const d=Math.min(200,Math.max(5,Math.floor(Number(F))));m({current:1,pageSize:d})}}),e.jsx("span",{style:{fontSize:13},children:s("embeddingIndexGoPage")}),e.jsx(is,{size:"small",min:1,max:_,step:1,value:Math.min(r,_),controls:!0,changeOnWheel:!0,disabled:u||R||U===0,"aria-label":s("embeddingIndexGoPage"),onChange:F=>{if(F==null||!Number.isFinite(Number(F)))return;const d=Math.min(_,Math.max(1,Math.floor(Number(F))));m(M=>({...M,current:d}))}}),e.jsxs("span",{style:{fontSize:13,color:"var(--mdocs-text-muted)"},children:["/ ",_]})]})})})()]})]})})}function hs(a,s){const p=localStorage.getItem(a);return p===null?s:p==="true"}function Te(a){const s=new Date(a);if(Number.isNaN(s.getTime()))return"—";const p=String(s.getMonth()+1).padStart(2,"0"),u=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${p}-${u}`}function xa(a,s){return a==="md"?s("myDocumentsFileTypeMd"):a==="sheet"?s("myDocumentsFileTypeSheet"):a==="html"?s("myDocumentsFileTypeHtml"):a||"—"}const ps=[{id:"general",labelKey:"general",keywords:["设置","语言","settings","language"],Icon:St},{id:"bookmarks",labelKey:"bookmarkTitle",keywords:["收藏","bookmark","star"],Icon:wt},{id:"myDocuments",labelKey:"myDocuments",keywords:["文章","文档","documents","articles"],Icon:Ct},{id:"embeddingIndex",labelKey:"embeddingIndex",keywords:["语义","索引","embedding","vector","检索"],Icon:sa},{id:"domainManagement",labelKey:"domainManagement",keywords:["域","工作空间","workspace","domain"],Icon:Xt},{id:"memberTemplates",labelKey:"memberTemplates",keywords:["成员","模板","members","template","邀请"],Icon:$t},{id:"agentConfig",labelKey:"agentConfig",keywords:["ai","助手","模型","agent","llm","deepseek"],Icon:aa},{id:"savePublish",labelKey:"saveAndPublish",keywords:["草稿","发布","同步","draft","publish","sync"],Icon:Zt}];function wa(a){const{t:s,lang:p,setLang:u}=le(),{onBack:b,onPublishDraft:R}=a,f=vt(),[w,N]=t.useState(!1);kt(f,()=>N(!0),{open:w,onClose:()=>N(!1)});const h=t.useRef(!0);t.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]),t.useEffect(()=>{f||N(!1)},[f]);const[S,A]=t.useState(()=>hs("mdocs.autoPublish",!1)),[I,c]=t.useState(()=>hs("mdocs.autoEdit",!0)),[v,g]=t.useState(!1),[x,C]=t.useState("general"),[z,j]=t.useState("");function B(n){C(n),f&&N(!1)}const O=t.useMemo(()=>{const n=z.trim().toLowerCase();return n?ps.filter(P=>s(P.labelKey).toLowerCase().includes(n)?!0:P.keywords.some(q=>q.toLowerCase().includes(n))):ps},[z,s]),L=s(x==="general"?"general":x==="bookmarks"?"bookmarkTitle":x==="myDocuments"?"myDocuments":x==="embeddingIndex"?"embeddingIndex":x==="domainManagement"?"domainManagement":x==="memberTemplates"?"memberTemplates":x==="agentConfig"?"agentConfig":"saveAndPublish"),[k,K]=t.useState([]),[D,E]=t.useState(!0),[m,o]=t.useState(null),[y,T]=t.useState(!1),[$,V]=t.useState(!1),[Q,Z]=t.useState(!1),[ee,H]=t.useState(!1),[l,r]=t.useState(null),[U,_]=t.useState(!1),[F,d]=t.useState(!1),[M,W]=t.useState(!1),[te,ce]=t.useState(""),[ae,Y]=t.useState(!1),[pe,ge]=t.useState(!1),[fe,xe]=t.useState(0),[oe,ne]=t.useState([]),[Me,Ne]=t.useState(!1),[me,ve]=t.useState(""),[ke,Pe]=t.useState([]),[Ee,Se]=t.useState(!1),[i,J]=t.useState(""),[ie,vs]=t.useState("auto"),[we,Re]=t.useState(null),[qe,Fe]=t.useState(!0),[ue,ks]=t.useState(0),[Ge,He]=t.useState("1"),[Je,Ss]=t.useState(0),[ye,ws]=t.useState(""),[Le,Cs]=t.useState(""),[ze,Ds]=t.useState(""),[Ce,Is]=t.useState(""),[Ts,As]=t.useState(null),[Ms,Ps]=t.useState([]),De=t.useRef(0),Be=20,he=we!==null,[Qe,Es]=t.useState([]),[Rs,Ke]=t.useState(!1),[Oe,Ze]=t.useState(null),[Ue,Ye]=t.useState(new Map);t.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(S))},[S]),t.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(I))},[I]),t.useEffect(()=>{x==="savePublish"&&We().then(n=>{h.current&&xe(n.filter(P=>!P.published).length)})},[x]),t.useEffect(()=>{x==="bookmarks"&&Fs(),x==="myDocuments"&&(je(),ys().then(n=>{h.current&&Ps(n)}).catch(()=>{}))},[x,ye,Le,ze,Ce]),t.useEffect(()=>{if(x!=="myDocuments")return;const n=i.trim();if(!n){De.current+=1,Re(null),Fe(!0);return}const P=++De.current,G=window.setTimeout(()=>{(async()=>{try{const q=await js({query:n,mode:ie,domainId:ye||void 0,topN:50});if(!h.current||P!==De.current)return;Re(q.results),Fe(q.modelReady)}catch{if(!h.current||P!==De.current)return;Re([]),Fe(!0)}})()},300);return()=>window.clearTimeout(G)},[x,i,ie,ye]),t.useEffect(()=>{Xe()},[]),t.useEffect(()=>{fs().then(n=>{h.current&&Es(n)}).catch(()=>{})},[]);const be=new Map(Qe.map(n=>[n.domainId,n.domainName]));async function Xe(){try{E(!0);const n=await Dt();if(!h.current)return;K(n)}catch{}finally{h.current&&E(!1)}}async function Fs(){try{Ne(!0);const n=await It();if(!h.current)return;ne(n)}catch{}finally{h.current&&Ne(!1)}}async function je(n=0){try{Se(!0);const P=await Tt({offset:n*Be,limit:Be,domainId:ye||void 0,creatorVisitorId:Le||void 0,fileType:ze||void 0,groupBy:Ce||void 0});if(!h.current)return;Pe(P.items),As(P.groups??null),Ss(P.total),ks(n),He(String(n+1))}catch{}finally{h.current&&Se(!1)}}async function Ls(n){try{await Lt(n),ne(P=>P.filter(G=>G.documentId!==n))}catch{}}function zs(){if(k.some(P=>!P.revoked)){V(!0);return}es()}async function es(){try{T(!0);const n=await Bt();o({token:n.token,name:n.name}),await Xe()}finally{T(!1)}}async function Bs(){try{W(!0);const n=await Rt();r(n.recoveryCode)}finally{W(!1)}}async function Ks(n){n.preventDefault();const P=te.trim();if(!(P&&P.length<4))try{Y(!0),await Ft(P),ce(""),ge(!0),setTimeout(()=>ge(!1),3e3)}finally{Y(!1)}}async function Os(n){Ze(n);try{const P=await zt(n),G=new Map;P.forEach(q=>{G.set(q.visitorId,q.permission)}),Ye(G)}catch{Ye(new Map)}Ke(!0)}async function Us(n){if(Oe)try{const P=new Set(n.map(q=>q.visitorId)),G=new Set(Ue.keys());for(const q of G)P.has(q)||await Kt(Oe,q);for(const q of n)await Ot(Oe,q.visitorId,q.permission);await je()}finally{Ke(!1),Ze(null)}}const ss=oe.filter(n=>{if(!me.trim())return!0;const P=me.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(P)||(n.ownerVisitorName||"").toLowerCase().includes(P)||(n.domainId||"").toLowerCase().includes(P)}),re=Math.ceil(Je/Be);return e.jsxs("div",{className:"mdocs-layout"+(f?" mdocs-layout--reader mdocs-layout--settings":""),children:[f&&w?e.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":s("collapseSidebar"),onClick:()=>N(!1)}):null,e.jsxs("aside",{className:"mdocs-sidebar"+(f?w?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":""),children:[e.jsxs("header",{className:"mdocs-sidebar-header",children:[e.jsxs("div",{className:"mdocs-brand",children:[e.jsx("img",{src:At,alt:s("brand"),className:"mdocs-brand-logo"}),e.jsx("span",{children:s("brand")})]}),f?e.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:()=>N(!1),"aria-label":s("collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Mt,{size:18})}):null]}),e.jsx("div",{className:"mdocs-config-nav-search",children:e.jsxs("div",{className:"mdocs-config-nav-search-inner",children:[e.jsx(as,{size:14,strokeWidth:1.75,"aria-hidden":!0}),e.jsx("input",{type:"search",value:z,onChange:n=>j(n.target.value),placeholder:s("settingsNavSearch"),"aria-label":s("settingsNavSearch")})]})}),e.jsx("nav",{className:"mdocs-config-tree",children:O.length===0?e.jsx("div",{className:"mdocs-config-nav-empty",children:s("settingsNavNoMatch")}):O.map(n=>{const P=n.Icon,G=x===n.id;return e.jsxs("div",{className:"mdocs-config-item"+(G?" active":""),onClick:()=>B(n.id),children:[e.jsx(P,{size:16,strokeWidth:1.75,"aria-hidden":!0}),e.jsx("span",{children:s(n.labelKey)})]},n.id)})}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:b,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[f?e.jsxs("div",{className:"mdocs-settings-mobile-bar",children:[e.jsx("button",{type:"button",className:"mdocs-reader-nav-btn",onClick:()=>N(!0),"aria-label":s("expandSidebar"),children:e.jsx(Pt,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:L})]}):null,Et(),x==="general"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("general")})}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsx("span",{className:"mdocs-settings-item-info",children:e.jsx("span",{className:"mdocs-settings-card-title",children:s("language")})}),e.jsxs("span",{className:"mdocs-settings-lang",children:[e.jsx("button",{type:"button",className:p==="en"?"active":"",onClick:()=>u("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:p==="zh"?"active":"",onClick:()=>u("zh"),children:"中"})]})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoEdit")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoEditDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(I?" active":""),role:"switch","aria-checked":I,onClick:()=>c(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliToken")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("cliTokenDesc")}),!D&&k.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:k.map(n=>e.jsxs("span",{style:{display:"block"},children:[n.name," — ",new Date(n.createdAt).toLocaleString()," ",n.revoked?`(${s("cliTokenRevoked")})`:`(${s("cliTokenActive")})`]},n.tokenId))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:zs,disabled:y||D,children:y?"…":k.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),m&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--ok",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("cliTokenGenerated")}),e.jsx("span",{className:"mdocs-settings-secret-value",children:m.token})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(m.token),H(!1),Z(!0),window.setTimeout(()=>Z(!1),2e3)}catch{Z(!1),H(!0),window.setTimeout(()=>H(!1),3e3)}})()},children:s(Q?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>o(null),children:s("close")})]}),Q&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),ee&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:s("cliTokenCopyFailed")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"当 Token 丢失时,可用恢复码找回身份。生成后请立即保存,仅显示一次。"})]}),e.jsx("button",{type:"button",className:"secondary",onClick:Bs,disabled:M,children:M?"…":"生成恢复码"})]}),l&&e.jsxs("div",{className:"mdocs-settings-secret-result mdocs-settings-secret-result--warn",children:[e.jsxs("div",{className:"mdocs-settings-secret-result-head",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔑 你的恢复码"}),e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8},children:"请立即复制保存,关闭后不可再查看。"}),e.jsx("div",{className:"mdocs-settings-secret-code",children:l})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(l),d(!1),_(!0),window.setTimeout(()=>_(!1),2e3)}catch{_(!1),d(!0),window.setTimeout(()=>d(!1),3e3)}})()},children:U?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>r(null),children:s("close")})]}),U&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),F&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--err",role:"status",children:"复制失败,请手动选中上方内容复制"})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-item",children:e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:"🔐 登录密码"}),e.jsx("span",{className:"mdocs-settings-item-desc",children:"设置密码后,可在其他浏览器或设备用「用户名+密码」登录。"})]})}),e.jsxs("form",{onSubmit:Ks,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:te,onChange:n=>ce(n.target.value),minLength:0,style:{marginBottom:8}}),pe&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:ae,children:ae?"设置中…":"保存密码"})]})]})]})]}):x==="bookmarks"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("bookmarkTitle")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("input",{type:"text",className:"mdocs-settings-search",placeholder:s("bookmarkSearch"),value:me,onChange:n=>ve(n.target.value)}),Me?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:ss.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(me?"bookmarkNoMatch":"bookmarkEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("bookmarkColTitle")}),e.jsx("th",{children:s("bookmarkColDomain")}),e.jsx("th",{children:s("bookmarkColAuthor")}),e.jsx("th",{children:s("bookmarkColTime")}),e.jsx("th",{style:{textAlign:"right"}})]})}),e.jsx("tbody",{children:ss.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):be.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{children:new Date(n.bookmarkedAt).toLocaleDateString()}),e.jsx("td",{style:{textAlign:"right"},children:e.jsx("button",{type:"button",className:"secondary small",onClick:()=>Ls(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):x==="myDocuments"?e.jsxs("div",{className:"mdocs-settings mdocs-my-docs",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:s("myDocuments")})}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsxs("div",{className:"mdocs-my-docs-toolbar",children:[e.jsxs("div",{className:"mdocs-my-docs-search",children:[e.jsx(as,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:i,onChange:n=>J(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ye,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ws(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Qe.map(n=>e.jsx("option",{value:n.domainId,children:be.get(n.domainId)||n.domainName},n.domainId))]}),!he&&e.jsxs("select",{className:"mdocs-my-docs-select",value:ze,"aria-label":s("myDocumentsFilterFileType"),onChange:n=>Ds(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllFileTypes")}),e.jsx("option",{value:"md",children:s("myDocumentsFileTypeMd")}),e.jsx("option",{value:"sheet",children:s("myDocumentsFileTypeSheet")}),e.jsx("option",{value:"html",children:s("myDocumentsFileTypeHtml")})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ie,"aria-label":s("myDocumentsSearchMode"),onChange:n=>vs(n.target.value),children:[e.jsx("option",{value:"auto",children:s("myDocumentsModeAuto")}),e.jsx("option",{value:"keyword",children:s("myDocumentsModeKeyword")}),e.jsx("option",{value:"semantic",children:s("myDocumentsModeSemantic")})]}),!he&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Le,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>Cs(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),Ms.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),!he&&e.jsxs("select",{className:"mdocs-my-docs-select",value:Ce,"aria-label":s("myDocumentsGroupBy"),onChange:n=>Is(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsGroupNone")}),e.jsx("option",{value:"domain",children:s("myDocumentsGroupDomain")}),e.jsx("option",{value:"creator",children:s("myDocumentsGroupCreator")})]})]}),Ee&&!he?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):he?e.jsx(e.Fragment,{children:we.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(ie==="semantic"&&!qe?"myDocumentsSemanticNotReady":"myDocumentsNoMatch")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-my-docs-search-meta",children:[s("myDocumentsResultCount",{count:String(we.length)}),ie==="semantic"&&!qe?` · ${s("myDocumentsSemanticNotReadyShort")}`:""]}),e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:we.map(n=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:be.get(n.domainId||"")||n.domainId||"—"}),e.jsx("td",{children:n.ownerVisitorName||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Te(n.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:n.createdAt?Te(n.createdAt):"—"}),e.jsx("td",{className:"mdocs-my-docs-actions",children:e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(n.documentId),children:s("bookmarkOpen")})})]},n.documentId))})]})})]})}):e.jsxs(e.Fragment,{children:[ke.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(i?"myDocumentsNoMatch":"myDocumentsEmpty")}):e.jsx("div",{className:"mdocs-settings-table-wrap",children:e.jsxs("table",{className:"mdocs-settings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("myDocumentsColTitle")}),e.jsx("th",{children:s("myDocumentsColFileType")}),e.jsx("th",{children:s("myDocumentsColDomain")}),e.jsx("th",{children:s("myDocumentsColCreator")}),e.jsx("th",{children:s("myDocumentsColUpdated")}),e.jsx("th",{children:s("myDocumentsColCreated")}),e.jsx("th",{})]})}),e.jsx("tbody",{children:(Ts??[{key:"",items:ke}]).flatMap(n=>{var q;const P=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:7,children:Ce==="domain"?be.get(n.key)||n.key:((q=n.items[0])==null?void 0:q.creatorName)||n.key})},`group-${n.key}`):null,G=n.items.map(X=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>a.onOpenDocument(X.documentId),children:X.displayName||X.relativePath||"Untitled"}),e.jsx("td",{children:xa(X.fileType,s)}),e.jsx("td",{children:be.get(X.domainId||"")||X.domainId||"—"}),e.jsx("td",{children:X.creatorName||X.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Te(X.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Te(X.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>Os(X.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>a.onOpenDocument(X.documentId),children:s("bookmarkOpen")})]})]},X.documentId));return P?[P,...G]:G})})]})}),!he&&e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(re>0?ue+1:0),total:String(re),count:String(Je)})}),re>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const P=Number.parseInt(Ge,10);if(!Number.isFinite(P))return;const G=Math.min(Math.max(P,1),re)-1;G!==ue&&je(G)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:re,"aria-label":s("myDocumentsJumpTo"),value:Ge,onChange:n=>He(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),re>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:ue<=0,onClick:()=>je(ue-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:ue>=re-1,onClick:()=>je(ue+1),children:s("myDocumentsNext")})]})]})]})]})]}):x==="embeddingIndex"?e.jsx(fa,{onOpenDocument:a.onOpenDocument}):x==="domainManagement"?e.jsx(ca,{}):x==="memberTemplates"?e.jsx(oa,{}):x==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(ua,{}),e.jsx(pa,{})]}):e.jsxs("div",{className:"mdocs-settings",children:[e.jsxs("div",{className:"mdocs-settings-header",children:[e.jsx("h2",{className:"mdocs-settings-title",children:s("saveAndPublish")}),e.jsx("button",{type:"button",className:"secondary",onClick:b,children:s("backToDocs")})]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoSave")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoSaveAlwaysOnDesc")})]}),e.jsx("span",{className:"mdocs-toggle active",role:"switch","aria-checked":"true","aria-disabled":"true",style:{opacity:.6,cursor:"not-allowed"},children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),e.jsx("div",{className:"mdocs-settings-card",children:e.jsxs("label",{className:"mdocs-settings-item",children:[e.jsxs("span",{className:"mdocs-settings-item-info",children:[e.jsx("span",{className:"mdocs-settings-card-title",children:s("autoPublish")}),e.jsx("span",{className:"mdocs-settings-item-desc",children:s("autoPublishDesc")})]}),e.jsx("button",{type:"button",className:"mdocs-toggle"+(S?" active":""),role:"switch","aria-checked":S,onClick:()=>A(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),fe>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>g(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",fe,")"]}),e.jsx("span",{className:"mdocs-settings-draft-arrow","aria-hidden":"true",children:"›"})]}):e.jsx("div",{className:"mdocs-settings-card mdocs-settings-draft-empty",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:s("noDrafts")})})]})]}),v&&e.jsx(ia,{onPublish:R,onClose:()=>g(!1),onCountChange:xe,onRecover:a.onRecoverDraft})]}),$&&e.jsx(bs,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:y,onConfirm:()=>{V(!1),es()},onCancel:()=>V(!1)}),e.jsx(Ns,{open:Rs,title:s("docInfoInviteMember"),initialSelectedIds:[...Ue.keys()],initialPermissions:Ue,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Ke(!1),onConfirm:n=>{Us(n)}})]})}export{wa as SettingsPage};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{r as l,j as n}from"./react-vendor-BVS1XoFi.js";import{o as p,c as st,p as be,q as it,t as Me,a as ot,s as at,e as lt,f as dt,g as ct,u as rt,v as T,h as ut,w as ee,S as mt,x as ht,y as ft,z as ze,A as xt,B as gt,E as It,F as vt,G as bt,H as Be,I as yt,J as wt,K as kt,X as jt,L as Ct,M as St,O as Nt,l as Dt,r as Et,i as Mt,j as zt,P as Bt,Q as Pt,R as Rt,T as At,D as te,k as Tt,m as Wt}from"./index-Kp5r4mc7.js";import{D as $t,S as Lt}from"./DocChrome-Dj5rSAvl.js";import{V as Vt,U as Ft}from"./VisitorPickerModal-aRuuDomz.js";import{P as ye}from"./plus-D8tCpRfA.js";import{B as _t,I as pt}from"./italic-BqrahN0G.js";import"./ui-CEFkTVnG.js";import"./motion-BAXVQJfN.js";import"./diagram-BF8g9yg4.js";import"./file-type-policy-5jFXMeIz.js";/**
|
|
2
|
+
* @license lucide-react v0.562.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Ot=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Ut=p("columns-3",Ot);/**
|
|
7
|
+
* @license lucide-react v0.562.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const qt=[["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}],["path",{d:"M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22",key:"1hyw0i"}],["path",{d:"m20 22-5-5",key:"1m27yz"}]],Kt=p("merge",qt);/**
|
|
12
|
+
* @license lucide-react v0.562.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Ht=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]],Qt=p("rows-3",Ht);/**
|
|
17
|
+
* @license lucide-react v0.562.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Gt=[["path",{d:"M8 19H5c-1 0-2-1-2-2V7c0-1 1-2 2-2h3",key:"lubmu8"}],["path",{d:"M16 5h3c1 0 2 1 2 2v10c0 1-1 2-2 2h-3",key:"1ag34g"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]],Jt=p("square-split-horizontal",Gt);/**
|
|
22
|
+
* @license lucide-react v0.562.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Xt=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Pe=p("trash-2",Xt);function w(t){return`${t.rowId}::${t.colId}`}function Yt(t){let i=t+1,u="";for(;i>0;){const c=(i-1)%26;u=String.fromCharCode(65+c)+u,i=Math.floor((i-1)/26)}return u}function Zt(t,i){const u=t.columns.findIndex(r=>r.id===i.colId),c=t.rows.findIndex(r=>r.id===i.rowId);return u<0||c<0?"":`${Yt(u)}${c+1}`}function en(t,i,u,c){return!i||!u||c.size===0?null:i.rowId===u.rowId&&t.columns.length>0&&t.columns.every(m=>c.has(w({rowId:i.rowId,colId:m.id})))?{rowId:i.rowId,colId:t.columns[0].id}:i.colId===u.colId&&t.rows.length>0&&t.rows.every(m=>c.has(w({rowId:m.id,colId:i.colId})))?{rowId:t.rows[0].id,colId:i.colId}:u}function tn(t,i,u,c){if(!u.has(w(i)))return"mdocs-sheet-td";const r=t.rows.findIndex(y=>y.id===i.rowId),x=t.columns.findIndex(y=>y.id===i.colId),m=["mdocs-sheet-td","is-selected"];if(c&&c.rowId===i.rowId&&c.colId===i.colId&&m.push("is-active"),r<0||x<0)return m.join(" ");const C=r>0?w({rowId:t.rows[r-1].id,colId:i.colId}):null,E=r<t.rows.length-1?w({rowId:t.rows[r+1].id,colId:i.colId}):null,M=x>0?w({rowId:i.rowId,colId:t.columns[x-1].id}):null,A=x<t.columns.length-1?w({rowId:i.rowId,colId:t.columns[x+1].id}):null;return(!C||!u.has(C))&&m.push("sel-t"),(!E||!u.has(E))&&m.push("sel-b"),(!M||!u.has(M))&&m.push("sel-l"),(!A||!u.has(A))&&m.push("sel-r"),m.join(" ")}function nn(t,i,u){const c=t.rows.findIndex(h=>h.id===i.rowId),r=t.rows.findIndex(h=>h.id===u.rowId),x=t.columns.findIndex(h=>h.id===i.colId),m=t.columns.findIndex(h=>h.id===u.colId);if(c<0||r<0||x<0||m<0)return[i];const C=Math.min(c,r),E=Math.max(c,r),M=Math.min(x,m),A=Math.max(x,m),y=[];for(let h=C;h<=E;h+=1)for(let z=M;z<=A;z+=1)y.push({rowId:t.rows[h].id,colId:t.columns[z].id});return y}function sn(t){return t?{background:t.bg,color:t.color,fontWeight:t.bold?700:void 0,fontStyle:t.italic?"italic":void 0,fontSize:t.fontSize?`${t.fontSize}px`:void 0}:{}}function xn(t){var Ee;const{t:i,lang:u}=st(),c=t.meta.documentId,[r,x]=l.useState(()=>be(t.initialContent)),[m,C]=l.useState(t.initialDisplayName),[E,M]=l.useState(!1),[A,y]=l.useState(t.hasLocalDraft??!1),[h,z]=l.useState(!1),[ne,we]=l.useState(!1),[O,se]=l.useState(!1),[ie,oe]=l.useState(!1),[Re,Ae]=l.useState([]),[Te,W]=l.useState(!1),[ae,le]=l.useState(t.meta.permission),[de,ke]=l.useState(!1),[We,ce]=l.useState(!1),[U,$e]=l.useState(new Map),[Le,re]=l.useState(null),[ue,me]=l.useState(null),[je,q]=l.useState(null),[B,$]=l.useState(null),[v,j]=l.useState(null),[L,he]=l.useState(""),S=l.useRef(null),K=l.useRef(!1),P=l.useRef(null),H=l.useRef(r),Q=l.useRef(m),fe=l.useRef(null),xe=l.useRef(null);H.current=r,Q.current=m,P.current=B,l.useEffect(()=>{const e=()=>{K.current=!1};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);const d=it(r)??r.sheets[0],I=B&&v?nn(d,B,v):[],V=new Set(I.map(w)),f=en(d,B,v,V),Ce=f?Zt(d,f):"",G=f?Me((Ee=d.rows.find(e=>e.id===f.rowId))==null?void 0:Ee.cells[f.colId]):"";l.useEffect(()=>{he(G)},[G,f==null?void 0:f.rowId,f==null?void 0:f.colId]),l.useEffect(()=>{x(be(t.initialContent)),C(t.initialDisplayName),$(null),j(null),q(null)},[c,t.contentRevision,t.initialContent,t.initialDisplayName]),l.useEffect(()=>{let e=!1;return(async()=>{var s;const o=await ot(c);e||!o||o.contentKind!=="sheet"||(x(be(o.content)),o.displayName&&C(o.displayName),y(!0),(s=t.onDraftExistsChange)==null||s.call(t,!0))})(),()=>{e=!0}},[c]),l.useEffect(()=>at((e,o)=>{var s;e===c&&(y(o),(s=t.onDraftExistsChange)==null||s.call(t,o))}),[c]),l.useEffect(()=>{let e=!1;return lt(c).then(o=>{e||z(!!(o!=null&&o.bookmarked))}),()=>{e=!0}},[c]),l.useEffect(()=>{let e=!0;return dt().then(o=>{e&&Ae(o)}).catch(()=>{}),()=>{e=!1}},[]),l.useEffect(()=>{le(t.meta.permission)},[t.meta.permission,c]),l.useEffect(()=>{const e=o=>{fe.current&&!fe.current.contains(o.target)&&se(!1),xe.current&&!xe.current.contains(o.target)&&oe(!1)};return(O||ie)&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[O,ie]);const ge=l.useCallback(async()=>{var e;await ct(c).execute(()=>rt({documentId:c,content:T(H.current),displayName:Q.current,contentKind:"sheet",localBaseCommitIdAtEditStart:t.meta.headCommitId??null,snapshotMeta:{permission:t.meta.permission,ownerVisitorId:t.meta.ownerVisitorId,domainId:t.meta.domainId}})),y(!0),(e=t.onDraftExistsChange)==null||e.call(t,!0)},[c,t]),Se=l.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{ge()},1e3)},[ge]);l.useEffect(()=>()=>{S.current&&clearTimeout(S.current)},[]);function J(e){var o;t.canEdit&&(x(e),(o=t.onContentChange)==null||o.call(t,T(e)),Se())}function k(e){J(Bt(r,e))}function Ve(e,o,s){if(o&&P.current){s.preventDefault(),j(e);return}K.current=!0,$(e),j(e),P.current=e}function Fe(e){K.current&&j(e)}function Ie(e,o){$(e),j(o),P.current=e}function _e(e,o,s){s.preventDefault();const a=d.rows;if(a.length===0)return;const D=a[0].id,b=a[a.length-1].id;if(o&&P.current){j({rowId:b,colId:e});return}Ie({rowId:D,colId:e},{rowId:b,colId:e})}function pe(e,o,s){s.preventDefault();const a=d.columns;if(a.length===0)return;const D=a[0].id,b=a[a.length-1].id;if(o&&P.current){j({rowId:e,colId:b});return}Ie({rowId:e,colId:D},{rowId:e,colId:b})}function Oe(e){e.preventDefault();const o=d.rows,s=d.columns;o.length===0||s.length===0||Ie({rowId:o[0].id,colId:s[0].id},{rowId:o[o.length-1].id,colId:s[s.length-1].id})}function F(e){if(!t.canEdit||I.length===0)return;let o=d;for(const s of I)o=Pt(o,s.rowId,s.colId,e);k(o)}function Ue(){var s;const e=I[0];if(!e)return;const o=ee((s=d.rows.find(a=>a.id===e.rowId))==null?void 0:s.cells[e.colId]);F({bold:!(o!=null&&o.bold)})}function qe(){var s;const e=I[0];if(!e)return;const o=ee((s=d.rows.find(a=>a.id===e.rowId))==null?void 0:s.cells[e.colId]);F({italic:!(o!=null&&o.italic)})}function Ke(){if(!(!t.canEdit||!B||!v))try{k(Rt(d,{startRowId:B.rowId,startColId:B.colId,endRowId:v.rowId,endColId:v.colId}))}catch{}}function He(){if(!t.canEdit||!v)return;const{tab:e}=At(d,v.rowId,v.colId);k(e)}async function Ne(){var a;if(!t.canEdit)return;const e=document.querySelector(".mdocs-sheet-scroll"),o=(e==null?void 0:e.scrollTop)??null,s=(e==null?void 0:e.scrollLeft)??null;M(!0);try{S.current&&(clearTimeout(S.current),S.current=null),await ge(),await t.onPublish(T(H.current),Q.current.trim()||m,c),y(!1),(a=t.onDraftExistsChange)==null||a.call(t,!1)}finally{M(!1),e&&o!=null&&(e.scrollTop=o,s!=null&&(e.scrollLeft=s),requestAnimationFrame(()=>{e.scrollTop=o,s!=null&&(e.scrollLeft=s)}))}}async function Qe(){if(t.canEdit&&m.trim()!==t.initialDisplayName.trim())try{await Ne()}catch{}}async function ve(){var e,o;if(!ne){we(!0);try{h?(await Et(c),z(!1),(e=t.onShowToast)==null||e.call(t,i("bookmarkRemoved"))):(await Mt(c),z(!0),(o=t.onShowToast)==null||o.call(t,i("bookmarkAdded")))}finally{we(!1)}}}function Ge(e){const o=Re.find(s=>s.visitorId===e);return(o==null?void 0:o.visitorName)??e.slice(0,8)}function Je(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const N=l.useMemo(()=>t.domains.find(e=>e.domainId===t.meta.domainId),[t.domains,t.meta.domainId]),Xe=l.useMemo(()=>{const e=(N==null?void 0:N.permission)??"public";return ut(e)},[N==null?void 0:N.permission]);function Ye(e){return e===te.PRIVATE?i("permissionPrivate"):e===te.DOMAIN_READ?i("permissionInvite"):e===te.DOMAIN_WRITE?i("permissionDomainWrite"):e===te.PUBLIC_READ?i("permissionPublicRead"):i("permissionPublicEdit")}async function Ze(){if(de||ae===t.meta.permission){W(!1);return}ke(!0);try{await t.onPublish(T(H.current),Q.current.trim()||m,c,ae),W(!1)}finally{ke(!1)}}async function et(e){const o=new Set(e.map(s=>s.visitorId));for(const[s]of U)o.has(s)||await Tt(c,s);for(const s of e)U.get(s.visitorId)!==s.permission&&await Wt(c,s.visitorId,s.permission);ce(!1)}function X(){se(!1),oe(!1)}function De(e,o){const s=(o==null?void 0:o.includeBookmark)??!0,a={width:"100%",textAlign:"left",padding:"8px 16px",background:"none",border:"none",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"8px"},D=T(r);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:{padding:"4px 16px",fontSize:"13px"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreator")}),n.jsx("span",{children:Ge(t.meta.ownerVisitorId)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoCreatedAt")}),n.jsx("span",{children:new Date(t.meta.createdAt).toLocaleString(u==="zh"?"zh-CN":"en-US")})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"6px"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoSize")}),n.jsx("span",{children:Je(new Blob([D]).size)})]}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[n.jsx("span",{style:{color:"var(--mdocs-text-muted, #888)"},children:i("docInfoUpdatedAt")}),n.jsx("span",{children:new Date(t.meta.updatedAt).toLocaleString(u==="zh"?"zh-CN":"en-US")})]})]}),n.jsx("div",{style:{height:"1px",background:"var(--mdocs-border, #e5e5e5)",margin:"8px 0"}}),s?n.jsxs("button",{type:"button",style:a,onClick:()=>{ve(),e()},children:[n.jsx("span",{children:h?"⭐":"☆"}),n.jsx("span",{children:i(h?"bookmarkRemove":"bookmarkAdd")})]}):null,t.canManageInvites?n.jsxs("button",{type:"button",style:a,onClick:()=>{e(),(async()=>{const b=await zt(c);$e(new Map(b.map(_=>[_.visitorId,_.permission]))),ce(!0)})()},children:[n.jsx(Ft,{size:14}),n.jsx("span",{children:i("docInfoInviteMember")})]}):null,n.jsxs("button",{type:"button",style:a,onClick:()=>{e(),le(t.meta.permission),W(!0)},children:[n.jsx(Lt,{size:14}),n.jsx("span",{children:i("docInfoChangePermission")})]})]})}const g=(()=>{var o;const e=I[0];if(e)return ee((o=d.rows.find(s=>s.id===e.rowId))==null?void 0:o.cells[e.colId])})();function tt(){!t.canEdit||!f||L!==G&&k(Be(d,f.rowId,f.colId,L))}return n.jsxs("div",{className:"mdocs-sheet-editor",children:[n.jsx($t,{fileType:"sheet",displayName:m,onDisplayNameChange:C,onDisplayNameBlur:()=>void Qe(),domains:t.domains,currentDomainId:t.currentDomainId,onDomainChange:t.onDomainChange,onDomainsChange:t.onDomainsChange,canEdit:t.canEdit,editing:!0,actionsAlwaysVisible:!0,syncBehind:t.syncBehind,onSyncClick:t.onSyncClick,busy:E,draftExists:A,onPublish:()=>void Ne(),onDelete:()=>void t.onDelete(),isBookmarked:h,bookmarkBusy:ne,onToggleBookmark:()=>void ve(),onToggleComments:t.onToggleComments,commentPanelOpen:t.commentPanelOpen,commentCount:t.commentCount,docInfoMenu:De(X),docInfoOpen:O,onToggleDocInfo:()=>se(!O),docInfoMenuRef:fe,readerChrome:t.readerChrome,readerHeaderDocked:!!t.readerChrome,onOpenMobileNav:t.onOpenMobileNav,readerMoreOpen:ie,onToggleReaderMore:()=>oe(e=>!e),readerMoreMenuRef:xe,readerMoreMenu:n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",className:"mdocs-reader-more-item",disabled:ne,onClick:()=>{ve(),X()},children:[n.jsx(mt,{size:16,strokeWidth:1.5,style:{color:h?"#faad14":"var(--mdocs-text-secondary, #6b7280)",fill:h?"#faad14":"none"}}),n.jsx("span",{children:i(h?"bookmarkRemove":"bookmarkAdd")})]}),n.jsx("div",{className:"mdocs-reader-more-divider"}),t.canEdit?n.jsx("button",{type:"button",className:"mdocs-reader-more-item mdocs-reader-more-item--danger",disabled:E,onClick:()=>{X(),t.onDelete()},children:n.jsx("span",{children:i("delete")})}):null,n.jsx("div",{className:"mdocs-reader-more-divider"}),De(X,{includeBookmark:!1})]})}),n.jsxs("div",{className:"mdocs-sheet-toolbar",children:[n.jsxs("div",{className:"mdocs-sheet-toolbar-left",children:[n.jsxs("button",{type:"button",className:"mdocs-sheet-btn mdocs-sheet-btn-add",disabled:!t.canEdit,onClick:()=>k(ht(d)),children:[n.jsxs("span",{className:"mdocs-sheet-btn-add-icon","aria-hidden":!0,children:[n.jsx(Qt,{size:14,strokeWidth:2.4}),n.jsx(ye,{size:10,strokeWidth:3,className:"mdocs-sheet-btn-add-plus"})]}),n.jsx("span",{children:i("sheetAddRow")})]}),n.jsxs("button",{type:"button",className:"mdocs-sheet-btn mdocs-sheet-btn-add",disabled:!t.canEdit,onClick:()=>k(ft(d)),children:[n.jsxs("span",{className:"mdocs-sheet-btn-add-icon","aria-hidden":!0,children:[n.jsx(Ut,{size:14,strokeWidth:2.4}),n.jsx(ye,{size:10,strokeWidth:3,className:"mdocs-sheet-btn-add-plus"})]}),n.jsx("span",{children:i("sheetAddColumn")})]}),n.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),n.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${g!=null&&g.bold?" is-active":""}`,disabled:!t.canEdit||I.length===0,title:i("sheetBold"),onClick:Ue,children:n.jsx(_t,{size:13,strokeWidth:2.4})}),n.jsx("button",{type:"button",className:`mdocs-sheet-btn mdocs-sheet-btn-icon${g!=null&&g.italic?" is-active":""}`,disabled:!t.canEdit||I.length===0,title:i("sheetItalic"),onClick:qe,children:n.jsx(pt,{size:13,strokeWidth:2.4})}),n.jsx("label",{className:"mdocs-sheet-style-label",title:i("sheetFontSize"),children:n.jsxs("select",{className:"mdocs-sheet-font-size",disabled:!t.canEdit||I.length===0,value:(g==null?void 0:g.fontSize)??"",onChange:e=>{const o=e.target.value;F(o?{fontSize:Number(o)}:{fontSize:void 0})},children:[n.jsx("option",{value:"",children:"Aa"}),[12,13,14,16,18,20,24].map(e=>n.jsx("option",{value:e,children:e},e))]})}),n.jsx("label",{className:"mdocs-sheet-style-label",title:i("sheetTextColor"),children:n.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||I.length===0,value:(g==null?void 0:g.color)??"#212121",onChange:e=>F({color:e.target.value})})}),n.jsx("label",{className:"mdocs-sheet-style-label",title:i("sheetBgColor"),children:n.jsx("input",{type:"color",className:"mdocs-sheet-color",disabled:!t.canEdit||I.length===0,value:(g==null?void 0:g.bg)??"#ffffff",onChange:e=>F({bg:e.target.value})})}),n.jsx("span",{className:"mdocs-sheet-toolbar-sep","aria-hidden":!0}),n.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||I.length<2,title:`${i("sheetMerge")}(按住拖选,或 Shift+点第二格)`,onClick:Ke,children:[n.jsx(Kt,{size:13,strokeWidth:2.2}),n.jsx("span",{children:i("sheetMerge")})]}),n.jsxs("button",{type:"button",className:"mdocs-sheet-btn",disabled:!t.canEdit||!v||!ze(d,v.rowId,v.colId),title:i("sheetUnmerge"),onClick:He,children:[n.jsx(Jt,{size:13,strokeWidth:2.2}),n.jsx("span",{children:i("sheetUnmerge")})]})]}),n.jsx("div",{className:"mdocs-sheet-toolbar-right",children:n.jsxs("span",{className:"mdocs-sheet-stats-badge",children:[d.name," · ",d.rows.length," 行 × ",d.columns.length," 列"]})})]}),n.jsx("div",{className:"mdocs-sheet-formula-bar","aria-label":"单元格信息栏",children:n.jsxs("div",{className:"mdocs-sheet-formula-bar-inner",children:[n.jsx("input",{className:"mdocs-sheet-name-box",readOnly:!0,tabIndex:-1,value:Ce,placeholder:"—",title:Ce||"单元格地址","aria-label":"单元格地址"}),n.jsx("input",{className:"mdocs-sheet-formula-input",value:L,disabled:!t.canEdit||!f,placeholder:f?"":"点击单元格查看内容",title:L,"aria-label":"单元格内容",style:t.readerChrome?{width:`${Math.max(28,Math.min((L||" ").length+4,96))}ch`}:void 0,onChange:e=>he(e.target.value),onBlur:()=>tt(),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),e.target.blur()),e.key==="Escape"&&(he(G),e.target.blur())}})]})}),n.jsx("div",{className:"mdocs-sheet-scroll",children:n.jsxs("table",{className:"mdocs-sheet-table",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{className:"mdocs-sheet-corner-cell",title:"全选",onMouseDown:Oe,children:"#"}),d.columns.map(e=>{const o=I.length>0&&d.rows.every(s=>V.has(w({rowId:s.id,colId:e.id})));return n.jsx("th",{className:`mdocs-sheet-th${o?" is-selected":""}`,onMouseDown:s=>{je!==e.id&&(s.target.closest(".mdocs-sheet-col-del")||_e(e.id,s.shiftKey,s))},children:n.jsxs("div",{className:"mdocs-sheet-header-cell",children:[je===e.id&&t.canEdit?n.jsx("input",{className:"mdocs-sheet-header-input",autoFocus:!0,defaultValue:e.name,title:"编辑列名",onClick:s=>s.stopPropagation(),onMouseDown:s=>s.stopPropagation(),onBlur:s=>{q(null);const a=s.target.value.trim();!a||a===e.name||k(xt(d,e.id,a))},onKeyDown:s=>{s.key==="Enter"&&s.target.blur(),s.key==="Escape"&&q(null)}}):n.jsx("button",{type:"button",className:"mdocs-sheet-header-label",title:"单击全选列;双击重命名",onDoubleClick:s=>{s.preventDefault(),s.stopPropagation(),t.canEdit&&q(e.id)},children:e.name}),t.canEdit&&d.columns.length>1&&n.jsx("button",{type:"button",className:"mdocs-sheet-col-del",title:i("sheetDeleteColumn"),onMouseDown:s=>s.stopPropagation(),onClick:()=>{try{const{tab:s}=gt(d,[e.id]);k(s)}catch{}},children:n.jsx(Pe,{size:12,strokeWidth:1.8})})]})},e.id)}),n.jsx("th",{className:"mdocs-sheet-actions-header"})]})}),n.jsx("tbody",{children:d.rows.map((e,o)=>{const s=I.length>0&&d.columns.every(a=>V.has(w({rowId:e.id,colId:a.id})));return n.jsxs("tr",{className:`mdocs-sheet-tr${s?" is-row-selected":""}`,children:[n.jsx("td",{className:`mdocs-sheet-rownum${s?" is-selected":""}`,title:"单击全选行",onMouseDown:a=>pe(e.id,a.shiftKey,a),children:o+1}),d.columns.map(a=>{if(It(d,e.id,a.id))return null;const D=e.cells[a.id],b=ee(D),_=ze(d,e.id,a.id),nt=vt(d,e.id,a.id),Y=_&&nt?bt(d,_):{rowSpan:1,colSpan:1},R={rowId:e.id,colId:a.id};return V.has(w(R)),n.jsx("td",{className:tn(d,R,V,v),rowSpan:Y.rowSpan>1?Y.rowSpan:void 0,colSpan:Y.colSpan>1?Y.colSpan:void 0,style:b!=null&&b.bg?{background:b.bg}:void 0,onMouseEnter:()=>Fe(R),children:n.jsx("input",{className:"mdocs-sheet-cell-input",style:sn(b),value:Me(D),disabled:!t.canEdit,onMouseDown:Z=>Ve(R,Z.shiftKey,Z),onFocus:()=>{K.current||($(R),j(R),P.current=R)},onChange:Z=>k(Be(d,e.id,a.id,Z.target.value))})},a.id)}),n.jsx("td",{className:"mdocs-sheet-actions-col",children:n.jsx("button",{type:"button",className:"mdocs-sheet-row-del",disabled:!t.canEdit,title:i("sheetDeleteRow"),onClick:()=>k(yt(d,e.id)),children:n.jsx(Pe,{size:13,strokeWidth:1.8})})})]},e.id)})})]})}),n.jsxs("footer",{className:"mdocs-sheet-footer",children:[n.jsxs("div",{className:"mdocs-sheet-tabs",role:"tablist",children:[r.sheets.map(e=>{const o=e.id===d.id;return n.jsxs("div",{className:`mdocs-sheet-tab${o?" mdocs-sheet-tab--active":""}`,role:"tab","aria-selected":o,children:[Le===e.id&&t.canEdit?n.jsx("input",{className:"mdocs-sheet-tab-rename",autoFocus:!0,defaultValue:e.name,onBlur:s=>{re(null);const a=s.target.value.trim();if(!(!a||a===e.name))try{J(wt(r,e.id,a))}catch{}},onKeyDown:s=>{s.key==="Enter"&&s.target.blur(),s.key==="Escape"&&re(null)}}):n.jsx("button",{type:"button",className:"mdocs-sheet-tab-btn",title:"双击可重命名工作表",onClick:()=>{var a;if(o)return;const s=kt(r,e.id);x(s),$(null),j(null),t.canEdit&&((a=t.onContentChange)==null||a.call(t,T(s)),Se())},onDoubleClick:()=>{t.canEdit&&re(e.id)},children:e.name}),t.canEdit&&r.sheets.length>1?n.jsx("button",{type:"button",className:"mdocs-sheet-tab-close",title:i("sheetDeleteSheet"),onClick:s=>{s.stopPropagation(),me({id:e.id,name:e.name})},children:n.jsx(jt,{size:11,strokeWidth:2.4})}):null]},e.id)}),n.jsxs("button",{type:"button",className:"mdocs-sheet-tab-add",disabled:!t.canEdit,title:i("sheetAddSheet"),onClick:()=>{const{doc:e}=Ct(r);J(e)},children:[n.jsx(ye,{size:14,strokeWidth:2.4}),n.jsx("span",{children:i("sheetAddSheet")})]})]}),n.jsx("div",{className:"mdocs-sheet-footer-info",children:n.jsxs("span",{children:["共 ",r.sheets.length," 个工作表"]})})]}),ue?n.jsx(St,{title:i("sheetDeleteSheet"),message:`确定删除工作表「${ue.name}」?其中的数据将一并删除。`,confirmLabel:i("delete"),cancelLabel:i("cancel"),danger:!0,onCancel:()=>me(null),onConfirm:()=>{try{J(Nt(r,ue.id))}finally{me(null)}}}):null,Te&&n.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:e=>{e.target===e.currentTarget&&W(!1)},children:n.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480},children:[n.jsx("h1",{style:{fontSize:"1.1rem",marginBottom:12},children:i("docInfoChangePermission")}),n.jsxs("div",{className:"muted",style:{marginBottom:12},children:[i("domainPermission"),":",N?Dt(N.domainName,u,i):t.meta.domainId]}),n.jsx("div",{style:{display:"grid",gap:8},children:Xe.map(e=>n.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[n.jsx("input",{type:"radio",name:"sheet-doc-permission",value:e,checked:ae===e,onChange:()=>le(e)}),n.jsx("span",{children:Ye(e)})]},e))}),n.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:16},children:[n.jsx("button",{type:"button",onClick:()=>W(!1),children:i("cancel")}),n.jsx("button",{type:"button",className:"primary",disabled:de,onClick:()=>void Ze(),children:i(de?"publishing":"saveAndPublish")})]})]})}),t.canManageInvites?n.jsx(Vt,{open:We,title:i("docInfoInviteMember"),initialSelectedIds:[...U.keys()],initialPermissions:U,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:i("invitePermissionRead")},{value:"edit",label:i("invitePermissionEdit")}],onClose:()=>ce(!1),onConfirm:e=>{et(e)}}):null]})}export{xn as SheetEditor};
|