@fgbg/mdocs 1.3.15 → 1.3.16

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.
Files changed (68) hide show
  1. package/README.md +6 -6
  2. package/agent-skills/changelog/SKILL.md +16 -1
  3. package/agent-skills/core-concepts-all-files/SKILL.md +3 -3
  4. package/agent-skills/core-concepts-domain/SKILL.md +49 -46
  5. package/agent-skills/core-concepts-invitation/SKILL.md +9 -9
  6. package/agent-skills/core-concepts-no-account/SKILL.md +1 -1
  7. package/agent-skills/deployment-requirements/SKILL.md +2 -2
  8. package/agent-skills/faq/SKILL.md +2 -2
  9. package/agent-skills/getting-started-first-kb/SKILL.md +2 -2
  10. package/agent-skills/getting-started-installation/SKILL.md +3 -3
  11. package/agent-skills/index/SKILL.md +2 -2
  12. package/agent-skills/index.json +8 -8
  13. package/agent-skills/usage-bookmarks/SKILL.md +5 -5
  14. package/agent-skills/usage-cli-token/SKILL.md +6 -6
  15. package/agent-skills/usage-comments/SKILL.md +1 -1
  16. package/agent-skills/usage-domain-members/SKILL.md +27 -27
  17. package/agent-skills/usage-html-documents/SKILL.md +1 -1
  18. package/agent-skills/usage-knowledge-graph/SKILL.md +5 -5
  19. package/agent-skills/usage-my-documents/SKILL.md +8 -8
  20. package/agent-skills/usage-onboarding-ai/SKILL.md +6 -6
  21. package/agent-skills/usage-search/SKILL.md +2 -2
  22. package/agent-skills/usage-settings/SKILL.md +8 -8
  23. package/dist/server/agent/Agent/system-prompt.js +3 -3
  24. package/dist/server/agent/Agent/system-prompt.js.map +1 -1
  25. package/dist/server/agent/Agent/tool-ui-effects.js +1 -1
  26. package/dist/server/agent/Agent/tools-documents.js +12 -12
  27. package/dist/server/agent/Agent/tools-documents.js.map +1 -1
  28. package/dist/server/agent/Agent/tools-domains.js +14 -14
  29. package/dist/server/agent/Agent/tools-domains.js.map +1 -1
  30. package/dist/server/agent/Agent/tools-visitors.js +1 -1
  31. package/dist/server/agent/Agent/tools-visitors.js.map +1 -1
  32. package/dist/server/documents/document.service.js +6 -6
  33. package/dist/server/documents/document.service.js.map +1 -1
  34. package/dist/server/documents/graph-task.js +1 -1
  35. package/dist/server/documents/graph-task.js.map +1 -1
  36. package/dist/server/documents/graph.service.js +1 -1
  37. package/dist/server/documents/graph.service.js.map +1 -1
  38. package/dist/server/domains/change-domain-permission.js +1 -1
  39. package/dist/server/domains/change-domain-permission.js.map +1 -1
  40. package/dist/server/routes/folders.routes.js +4 -4
  41. package/dist/server/routes/folders.routes.js.map +1 -1
  42. package/dist/web/assets/AgentChatPanel-Bsx3DwQ7.js +22 -0
  43. package/dist/web/assets/{AgentSkillFormCard-llRkQdK_.js → AgentSkillFormCard-TFpdC5LM.js} +3 -3
  44. package/dist/web/assets/AiWriteWorkbench-Jl0I9eM9.js +7 -0
  45. package/dist/web/assets/{DiagramEditor-NtNY3sZL-D0FE-I9-.js → DiagramEditor-NtNY3sZL-CAEe_iNQ.js} +1 -1
  46. package/dist/web/assets/DocChrome-BWMgRxlr.js +21 -0
  47. package/dist/web/assets/DocumentEditor-DALklXO2.js +1 -0
  48. package/dist/web/assets/HtmlEditor-CX0e0ifD.js +1 -0
  49. package/dist/web/assets/{MergeView-DsVxYKKc.js → MergeView-DNu_ac5f.js} +2 -2
  50. package/dist/web/assets/{PlaygroundPage-BEqH8lAT.js → PlaygroundPage-mv9P6czE.js} +1 -1
  51. package/dist/web/assets/{SettingsPage-ClwYG9Q8.js → SettingsPage-nT9hvcPA.js} +2 -2
  52. package/dist/web/assets/{Toolbar-D5TrWh7K.js → Toolbar-Hsam79hu.js} +1 -1
  53. package/dist/web/assets/{VisitorPickerModal-B0fxKY7g.js → VisitorPickerModal-CqHzml8s.js} +1 -1
  54. package/dist/web/assets/{check-s9DVK_zH.js → check-soiTDN2u.js} +2 -2
  55. package/dist/web/assets/{copy-D_-gX8nM.js → copy-B4fvX0p8.js} +2 -2
  56. package/dist/web/assets/{index-B3TBoi2p.css → index-CuXb3X2-.css} +1 -1
  57. package/dist/web/assets/index-OmOf_og0.js +283 -0
  58. package/dist/web/assets/{meta2dEngine-BD2XbzaV-DLBNOz_m.js → meta2dEngine-BD2XbzaV-Bq3HuUfD.js} +1 -1
  59. package/dist/web/assets/{plus-BR1kwsYl.js → plus-DKKQ-AoS.js} +2 -2
  60. package/dist/web/assets/{react-DCTIdd3e.js → react-CI5PDFXT.js} +3 -3
  61. package/dist/web/index.html +2 -2
  62. package/package.json +1 -1
  63. package/dist/web/assets/AgentChatPanel-ePXffWJl.js +0 -22
  64. package/dist/web/assets/AiWriteWorkbench-DtD5xWmd.js +0 -7
  65. package/dist/web/assets/DocChrome-BkDnBqBu.js +0 -21
  66. package/dist/web/assets/DocumentEditor-CUdNMfU8.js +0 -1
  67. package/dist/web/assets/HtmlEditor-BFOWf-Xl.js +0 -1
  68. package/dist/web/assets/index-vbUbFD-2.js +0 -283
@@ -1,6 +1,6 @@
1
- import{r as a,j as e}from"./react-vendor-BuABiQkA.js";import{n as bs,b as ie,q as Ns,s as vs,o as ks,l as Ae,t as ws,v as Ss,w as X,x as Pe,y as Cs,z as Ds,A as Is,a as Ts,d as Oe,B as qe,G as Ye,H as As,I as Ps,J as Ms,K as Es,L as Rs,O as Qe,Q as Ie,T as Ls,U as Fs,V as zs,X as Bs,W as $s,Y as Ks,f as Xe,Z as Os,_ as Vs,$ as Us,a0 as Ws,a1 as _s,a2 as es,a3 as Gs,a4 as Hs,a5 as Js,a6 as Zs,a7 as qs,a8 as Ys,a9 as Qs,aa as Xs,ab as et,ac as st,ad as tt,ae as at,af as nt,P as it,ag as ct,ah as lt,ai as ot,r as rt,i as dt,aj as mt,j as ut,k as ht}from"./index-vbUbFD-2.js";import{V as ss,a as pt,M as Ve}from"./VisitorPickerModal-B0fxKY7g.js";import{C as gt}from"./check-s9DVK_zH.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.js";/**
1
+ import{r as a,j as e}from"./react-vendor-BuABiQkA.js";import{o as bs,c as ie,t as Ns,v as vs,p as ks,l as Ae,w as ws,x as Ss,y as Q,z as Pe,A as Cs,B as Ds,G as Is,a as Ts,d as Oe,H as Ye,I as qe,J as As,K as Ps,L as Ms,O as Es,Q as Rs,T as Xe,U as Ie,V as Ls,W as Fs,X as zs,Y as Bs,Z as $s,_ as Ks,f as Qe,$ as Os,a0 as Vs,a1 as Us,a2 as Ws,a3 as _s,a4 as es,a5 as Gs,a6 as Hs,a7 as Js,a8 as Zs,a9 as Ys,aa as qs,ab as Xs,ac as Qs,ad as et,ae as st,af as tt,ag as at,ah as nt,P as it,ai as ct,aj as lt,ak as ot,r as rt,j as dt,al as mt,k as ut,m as ht}from"./index-OmOf_og0.js";import{V as ss,a as pt,M as Ve}from"./VisitorPickerModal-CqHzml8s.js";import{C as gt}from"./check-soiTDN2u.js";import"./ui-CvA4pq3d.js";import"./motion-DFABYlwt.js";import"./diagram-Bk84WZto.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 ft=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],xt=bs("search",ft);function jt({draft:t,onClose:s,onSuccess:j}){const{t:d,lang:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(t.domainId??""),[g,k]=a.useState([]),[T,S]=a.useState(""),[c,x]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[o,h]=a.useState(!1),[I,A]=a.useState(null),y=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),a.useEffect(()=>{Ns().then(v=>{M.current&&u(v)})},[]),a.useEffect(()=>{w&&(k([]),S(""),vs(w).then(v=>{M.current&&k(v)}).catch(()=>{M.current&&k([])}))},[w]),a.useEffect(()=>{const v=window.setTimeout(()=>{var P;return(P=y.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(v)},[]),a.useEffect(()=>{const v=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[s]);function z(v,P){for(const C of v){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const E=z(C.children,P);if(E)return E}}return null}async function F(v){v.preventDefault(),h(!0),A(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",E=C.replace(/\.md$/i,"");try{const m=T?`${T}/${C}`:C,l=T?z(g,T)??void 0:void 0;await Ss({fileName:C,displayName:E,content:t.content,domainId:w,parentId:l}),j()}catch(m){A(X(d,m))}finally{h(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&!o&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:d("recoverDraft")}),e.jsx("p",{className:"muted",children:d("recoverDraftDesc",{name:t.displayName||d("unknownTitle")})}),e.jsxs("form",{onSubmit:F,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[d("domainLabel"),B.length>0&&e.jsx(ks,{domains:B,value:w,onChange:N,onDomainsChange:u,ariaLabel:d("domainLabel"),localizeName:v=>Ae(v,p,d)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[d("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(ws,{nodes:g,activeDocumentId:null,selectedParentPath:T,onOpen:()=>{},onOpenFolder:v=>S(v),onContextMenu:()=>{},onDeselect:()=>S("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[d("fileNameLabel"),e.jsx("input",{ref:y,value:c,onChange:v=>x(v.target.value),placeholder:"recovered.md",maxLength:200,disabled:o})]}),I&&e.jsx("div",{className:"mdocs-dialog-error",children:I}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!o&&s(),disabled:o,children:d("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:o,children:d(o?"creating":"create")})]})]})]})})}function yt({onPublish:t,onClose:s,onCountChange:j,onRecover:d}){const{t:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(new Set),[g,k]=a.useState(!1),[T,S]=a.useState(null),[c,x]=a.useState(null),[o,h]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,Pe().then(l=>{if(!A.current)return;const f=l.filter(D=>!D.published);u(f),j==null||j(f.length)}),()=>{A.current=!1,I.current&&(clearTimeout(I.current),I.current=null)}),[]),a.useEffect(()=>{const l=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s]);const y=a.useCallback((l,f)=>{h({message:l,type:f}),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>h(null),3e3)},[]);async function M(l){await Ds(l),N(f=>new Set(f).add(l));try{await t(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("published"),"success")}catch(f){f instanceof Is||y(p("publishFailed"),"error");const D=await Ts(l);D&&u($=>$.map(U=>U.documentId===l?D:U))}finally{N(f=>{const D=new Set(f);return D.delete(l),D})}}async function z(l){S(null),await Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("draftDeleted"),"success")}function F(l){const f=B.find(D=>D.documentId===l);f&&x(f)}function v(l){x(null),Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),d==null||d(B.find(f=>f.documentId===l)),y(p("published"),"success")}async function P(){k(!0);let l=0,f=0;for(const U of B)try{await t(U.documentId),l++}catch{f++}const $=(await Pe()).filter(U=>!U.published);u($),j==null||j($.length),f===0?y(p("publishAll"),"success"):y(`${l} published, ${f} failed`,"error"),k(!1)}const C=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=l=>Cs(p,l,l.publishError??"UNKNOWN"),m=B;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:[p("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:p("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":p("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:p("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(l=>{const f=!!l.publishError;return e.jsxs("div",{className:f?"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:l.displayName||p("unknownTitle")}),f?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(l.publishErrorAt)," · ",E(l)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(l.updatedAt)," · ",p("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[f?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:g,onClick:()=>F(l.documentId),children:p("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(l.documentId)||g,onClick:()=>void M(l.documentId),children:w.has(l.documentId)?p("publishing"):p("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:g,onClick:()=>S(l.documentId),children:p("delete")})]})]},l.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:p("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||g,onClick:()=>void P(),children:g?p("publishing"):`${p("publishAll")} (${m.length})`})]}),o&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+o.type,role:"status",children:o.message})]}),T&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&S(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:p("delete")}),e.jsx("p",{className:"muted",children:p("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>S(null),children:p("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void z(T),children:p("delete")})]})]})}),c&&e.jsx(jt,{draft:c,onClose:()=>x(null),onSuccess:()=>v(c.documentId)})]})}function bt(){const{t,lang:s}=ie(),j=qe(),d=a.useRef(!1),[p,B]=a.useState([]),[u,w]=a.useState(!1),[N,g]=a.useState(""),[k,T]=a.useState("restricted"),[S,c]=a.useState(!1),[x,o]=a.useState(null),[h,I]=a.useState(null),[A,y]=a.useState(""),[M,z]=a.useState(""),[F,v]=a.useState("all"),[P,C]=a.useState(null);a.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const E=a.useCallback(async()=>{w(!0),o(null);try{const b=await Ye();if(!d.current)return;B(b)}catch(b){if(!d.current)return;o(X(t,b))}finally{d.current&&w(!1)}},[t]);a.useEffect(()=>{E()},[E]);async function m(b){if(b.preventDefault(),!N.trim()){o(t("domainNameRequired"));return}c(!0),o(null);try{if(await Rs({domainName:N.trim(),permission:k}),!d.current)return;g(""),T("restricted"),await E()}catch(K){if(!d.current)return;o(X(t,K))}finally{d.current&&c(!1)}}async function l(b){if(A.trim()){o(null);try{if(await Es(b,A.trim()),!d.current)return;I(null),C(null),await E()}catch(K){if(!d.current)return;o(X(t,K))}}}function f(b){I(b.domainId),y(b.domainName),C(null)}function D(){I(null),C(null)}async function $(b,K){o(null);try{if(await Ms(b,K),!d.current)return;C(null),await E()}catch(W){if(!d.current)return;o(X(t,W))}}async function U(b){if(window.confirm(t("deleteDomainConfirmDetail",{name:b.domainName,count:String(b.docCount)}))){o(null);try{if(await Ps(b.domainId),!d.current)return;await E()}catch(K){if(!d.current)return;o(X(t,K))}}}const Z=a.useCallback(b=>As(b,t),[t]),q=a.useCallback(b=>Ae(b.domainName,s,t),[s,t]),Y=a.useMemo(()=>{const b=M.trim().toLowerCase();return p.filter(K=>F!=="all"&&K.permission!==F?!1:b?Ae(K.domainName,s,t).toLowerCase().includes(b)||K.domainName.toLowerCase().includes(b):!0)},[p,M,F,s,t]),_=a.useCallback((b,K)=>{const W=Z(b.permission);return K?`${W} ${t("domainTypeBuiltinSuffix")}`:W},[Z,t]);return{domains:p,loadingDomains:u,domainError:x,newDomainName:N,setNewDomainName:g,newDomainPermission:k,setNewDomainPermission:T,creating:S,handleCreateDomain:m,renamingId:h,setRenamingId:I,renameDraft:A,setRenameDraft:y,startRename:f,cancelRename:D,handleRename:l,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:$,handleDelete:U,domainSearch:M,setDomainSearch:z,domainFilter:F,setDomainFilter:v,filteredDomains:Y,visitorId:j,plabel:Z,localizeDomain:q,domainTypeLabel:_}}const Ue={private:0,restricted:1,public:2};function We(t){return Object.prototype.hasOwnProperty.call(Ue,t)?Ue[t]:null}function _e(t,s){const j=We(t),d=We(s);return j===null||d===null?"invalid":d>j?"upgrade":d<j?"downgrade":"same"}function Nt(){const{t}=ie(),s=bt(),[j,d]=a.useState([]),[p,B]=a.useState(null),[u,w]=a.useState(""),N=a.useRef(null),[g,k]=a.useState(null),T=a.useCallback(async()=>{try{const c=await Qe();d(c)}catch{d([])}},[]);a.useEffect(()=>{T()},[T]),a.useEffect(()=>{if(!s.changeTypeForId)return;const c=x=>{var o;(o=N.current)!=null&&o.contains(x.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function S(c){B(null);try{const x=await Ks(c.domainId);k({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:x.map(o=>o.visitorId),memberRows:x})}catch(x){B({kind:"err",text:translateError(t,x)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:t("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:t("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:t("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:t("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:t("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:t("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:Ie.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?t("creating"):t("create")})]})]}),p&&e.jsx("div",{className:"mdocs-settings-card",style:{color:p.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:p.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:t("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":t("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":t("domainPermission"),children:["all",...Ie].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"?t("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("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:t("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:t("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:t("domainColName")}),e.jsx("th",{scope:"col",children:t("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:t("domainColDocCount")}),e.jsx("th",{scope:"col",children:t("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const x=Ls(c,s.visitorId),o=Fs(c.domainId),h=zs(c),I=_e(c.permission,"public")==="upgrade",A=I?h?t("domainTooltipTypeLocked"):void 0:t("domainPermissionAlreadyTop");return e.jsxs("tr",{className:o?"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:y=>s.setRenameDraft(y.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:t("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:t("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),o&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!x&&!o&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:A,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,o)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[o&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!o&&!x&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!o&&x&&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":t("domainChangeType"),children:Ie.map(y=>{const z=_e(c.permission,y)==="downgrade";return e.jsx("span",{title:z?t("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":u===y,className:u===y?"active":"",disabled:z,onClick:()=>w(y),children:s.plabel(y)})},y)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":t("save"),disabled:u===""||u===c.permission,onClick:()=>{u&&u!==c.permission&&s.handlePermissionChange(c.domainId,u)},children:e.jsx(gt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":t("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(Bs,{size:14,strokeWidth:2.5})})]}),!o&&x&&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 S(c),children:t("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:h?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:h,children:t("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:A,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:h?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:h,children:t("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(ss,{open:g!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(g==null?void 0:g.initialIds)??[],lockedIds:g?[g.creatorVisitorId]:[],seedMembers:g==null?void 0:g.memberRows,templates:j,onClose:()=>k(null),onConfirm:async c=>{g&&(await $s(g.domainId,c),B({kind:"ok",text:t("domainMembersSaved",{count:String(c.length)})}))}})]})}function Ge(t){return t.length<=6?t:`${t.slice(0,6)}…`}function vt(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState([]),[p,B]=a.useState(!0),[u,w]=a.useState(null),[N,g]=a.useState(1),[k,T]=a.useState(null),[S,c]=a.useState(""),[x,o]=a.useState([]),[h,I]=a.useState(!1),[A,y]=a.useState(null),[M,z]=a.useState(!1),F=qe(),[v,P]=a.useState([]),[C,E]=a.useState("idle"),[m,l]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{E("loading"),Xe().then(r=>{s.current&&(P(r),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const f=a.useMemo(()=>{const r=new Map;for(const R of v)r.set(R.visitorId,R.visitorName);return r},[v]),D=a.useCallback(async()=>{B(!0),y(null);try{const r=await Qe();s.current&&d(r)}catch(r){s.current&&y(X(t,r))}finally{s.current&&B(!1)}},[t]);a.useEffect(()=>{D()},[D]);const $=a.useMemo(()=>x.map(r=>{const R=v.find(O=>O.visitorId===r);return{visitorId:r,name:R?R.visitorName:t("visitorPickerUnknownVisitor"),muted:!R}}),[x,v,t]);function U(r){o(R=>R.includes(r)?R.filter(O=>O!==r):[...R,r])}const Z=N===1?S.trim().length>0:N===2?x.length>0:!0;function q(){if(!(N>=3)){if(!Z){z(!0);return}z(!1),g(N+1),l("")}}function Y(){N<=1||(z(!1),g(N-1))}function _(){w(null),T(null),c(""),o(F?[F]:[]),y(null),g(1),l(""),z(!1)}function b(r){w(null),T(r.id),c(r.displayName);const R=F&&!r.visitorIds.includes(F)?[...r.visitorIds,F]:[...r.visitorIds];o(R),y(null),g(1),l(""),z(!1)}async function K(){if(!(!S.trim()||x.length===0)){I(!0),y(null);try{if(k===null?await Os({displayName:S.trim(),visitorIds:x}):await Vs(k,{displayName:S.trim(),visitorIds:x}),!s.current)return;_(),await D()}catch(r){if(!s.current)return;y(X(t,r))}finally{s.current&&I(!1)}}}async function W(r){I(!0),y(null);try{if(await Us(r),!s.current)return;w(null),k===r&&_(),await D()}catch(R){if(!s.current)return;y(X(t,R))}finally{s.current&&I(!1)}}const Q=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(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:t(k!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),k!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:_,style:{fontSize:12},children:t("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:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:Q.map(r=>{const R=N===r.key,O=N>r.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${R?" current":""}${O?" done":""}`,children:O?"✓":r.key}),e.jsx("span",{className:`mdocs-wizard-step-label${R?" current":""}${O?" done":""}`,children:r.label})]},r.key)})})]}),A&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:A}),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:S,onChange:r=>c(r.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:h,autoFocus:!0,"aria-invalid":M&&!S.trim()}),M&&!S.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(pt,{visitors:v,loadState:C,searchFilter:m,onSearchChange:l,selectedIds:new Set(x),onToggle:U,selectedRows:$,myVisitorId:F}),e.jsx("p",{className:`mdocs-wizard-hint${M&&x.length===0?" danger":""}`,children:"💡 "+t("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:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:S})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:t("memberTemplateSelectedSummary",{count:String(x.length)})})]}),x.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[x.slice(0,15).map(r=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Ge(r)},r)),x.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",x.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:Y,children:["← ",t("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:q,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void K(),children:t(h?"saving":k===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),p?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):j.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),k===null&&e.jsx("button",{type:"button",className:"primary",onClick:_,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:j.map(r=>e.jsx("li",{className:"mdocs-member-template-row",children:u===r.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:r.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 W(r.id),children:t(h?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:r.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(r.visitorIds.length)})}),r.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:r.visitorIds.map(R=>e.jsx("span",{className:"mdocs-member-template-tag",children:f.get(R)??Ge(R)},R))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>b(r),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(r.id),children:t("memberTemplateDelete")})]})]})},r.id))})]})]})]})}const kt=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],wt=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function St(t,s,j){return t==="deepseek"?"Deepseek":s||j}function He(t){return`${St(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Ct(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState(""),[p,B]=a.useState([]),[u,w]=a.useState(null),[N,g]=a.useState(null),[k,T]=a.useState("deepseek"),[S,c]=a.useState(""),[x,o]=a.useState(""),[h,I]=a.useState(""),[A,y]=a.useState("openai-completions"),[M,z]=a.useState("deepseek-flash"),[F,v]=a.useState(1e6),[P,C]=a.useState(""),[E,m]=a.useState(!1),[l,f]=a.useState(null),[D,$]=a.useState(!1),[U,Z]=a.useState(!0),[q,Y]=a.useState(!1),[_,b]=a.useState(null),[K,W]=a.useState(!1),[Q,ee]=a.useState(!1),[r,R]=a.useState(!1),[O,ce]=a.useState(null),[ue,oe]=a.useState(null),re=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const se=a.useCallback(async()=>{const i=await Ws();if(s.current)return B(i),i},[]);function te(){g(null),T("deepseek"),c(""),o(""),I(""),y("openai-completions"),z("deepseek-flash"),v(1e6),C(""),m(!1),f(null),$(!1),ee(!1),R(!1),b(null),W(!1)}function he(i){g(i.id),T(i.kind),c(i.name),o(i.providerId??""),I(i.baseUrl),y(i.apiType);const V=i.modelId.trim(),fe=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);z(i.kind==="deepseek"?V==="deepseek-v4-pro"?"deepseek-v4-pro":fe.has(V)?"deepseek-flash":V||"deepseek-flash":V),v(i.contextWindow||1e6),m(i.hasApiKey),f(i.apiKeyMasked),C(""),$(i.isDefault)}a.useEffect(()=>{(async()=>{try{const i=await _s();if(!s.current)return;d(i.visitorName);const V=await se();if(!s.current||!V)return;V.length===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&Z(!1)}})()},[se]);function ye(){te(),w("create")}function pe(i){he(i),w("edit"),W(!1),b(null)}function ae(){te(),w(null)}async function be(i){if(!(i.isDefault||ue)){oe(i.id),b(null);try{await Gs(i.id),await se()}catch(V){if(!s.current)return;b(V instanceof Error?V.message:String(V))}finally{s.current&&oe(null)}}}async function ge(){if(O){Y(!0),b(null);try{await Js(O.id);const i=await se();if(!s.current)return;u==="edit"&&N===O.id&&ae(),((i==null?void 0:i.length)??0)===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&(Y(!1),ce(null))}}}async function Ne(){Y(!0),b(null),W(!1);try{const i=k==="custom"?{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,baseUrl:h,modelId:M,providerId:x.trim()||void 0,apiType:A,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}}:{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,modelId:M,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}};if(await Hs(i),!s.current)return;await se(),W(!0),w(null),te()}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&Y(!1)}}const de=u!==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:t("agentConfig")}),!U&&!de?e.jsx("button",{type:"button",className:"secondary",onClick:ye,children:"添加配置"}):null]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!U&&p.length>0&&!de?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:p.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:ue!==null,onChange:()=>void be(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:He(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:()=>pe(i),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ce(i),children:"删除"})]})]},i.id))}),K?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,de?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:u==="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":k==="deepseek",className:k==="deepseek"?"active":"",onClick:()=>T("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="custom",className:k==="custom"?"active":"",onClick:()=>T("custom"),children:"自定义"})]}),k==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Ve,{options:[...kt],value:M,onChange:z})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Q?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Q?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:Q?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:h,onChange:i=>{const V=i.target.value;if(I(V),re.current)return;V.toLowerCase().includes("anthropic")?y("anthropic-messages"):y("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:M,onChange:i=>z(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:Q?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(Q?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:Q?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:r,onToggle:i=>R(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),k==="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:x,onChange:i=>o(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ve,{options:[...wt],value:A,onChange:i=>{re.current=!0,y(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:S,onChange:i=>c(i.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",j||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:F,onChange:i=>v(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),u==="create"&&p.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:i=>$(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 Ne(),disabled:q,children:t(q?"saving":"save")}),p.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ae,disabled:q,children:t("cancel")}):null]})]})]}):U?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(es,{title:"删除配置",message:`确定删除「${He(O)}」?${O.isDefault&&p.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void ge(),onCancel:()=>ce(null)}):null]})}const Dt=/^[A-Za-z0-9_]+$/;function Te(t){return Dt.test(t.trim())}function It(){const t=a.useRef(!0),[s,j]=a.useState([]),[d,p]=a.useState(!0),[B,u]=a.useState(null),[w,N]=a.useState(null),[g,k]=a.useState(!1),[T,S]=a.useState(""),[c,x]=a.useState(""),[o,h]=a.useState(""),[I,A]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function y(){p(!0),u(null);try{const m=await Zs();if(!t.current)return;j(m)}catch(m){if(!t.current)return;u(m instanceof Error?m.message:String(m))}finally{t.current&&p(!1)}}a.useEffect(()=>{y()},[]);function M(){k(!0),N(null),S(""),x(""),h(""),u(null)}function z(m){k(!1),N(m.id),S(m.name),x(m.description),h(m.body),u(null)}function F(){k(!1),N(null),S(""),x(""),h("")}async function v(){const m=T.trim();if(!Te(m)){u("名称仅允许英文、数字、下划线");return}if(!o.trim()){u("正文不能为空");return}A(!0),u(null);try{if(g?await qs({name:m,description:c,body:o}):w&&await Ys(w,{name:m,description:c,body:o}),!t.current)return;F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}finally{t.current&&A(!1)}}async function P(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){u(null);try{if(await Qs(m),!t.current)return;w===m&&F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}}}const C=g||w!==null,E=!T.trim()||Te(T);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",!d&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:M,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),B?e.jsx("p",{className:"mdocs-agent-skills-error",children:B}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:g?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:T,onChange:m=>S(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=>x(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:o,onChange:m=>h(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void v(),disabled:I||!E||!T.trim()||!o.trim(),children:I?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:F,disabled:I,children:"取消"})]})]}):null,d?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!d&&s.length===0&&!C?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:M,children:"新建第一个"})]}):null,!d&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const l=Te(m.name),f=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(f?" 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}),l?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:()=>z(m),disabled:C&&!f,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(m.id),disabled:C,children:"删除"})]})]},m.id)})}):null]})})]})}function Je(t,s){const j=localStorage.getItem(t);return j===null?s:j==="true"}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"—";const j=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${j}-${d}`}function Ft(t){const{t:s,lang:j,setLang:d}=ie(),{onBack:p,onPublishDraft:B}=t,u=Xs(),[w,N]=a.useState(!1),g=a.useRef(!0);a.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),a.useEffect(()=>{u||N(!1)},[u]);const[k,T]=a.useState(()=>Je("mdocs.autoPublish",!1)),[S,c]=a.useState(()=>Je("mdocs.autoEdit",!0)),[x,o]=a.useState(!1),[h,I]=a.useState("general");function A(n){I(n),u&&N(!1)}const y=s(h==="general"?"general":h==="bookmarks"?"bookmarkTitle":h==="myDocuments"?"myDocuments":h==="domainManagement"?"domainManagement":h==="memberTemplates"?"memberTemplates":h==="agentConfig"?"agentConfig":"saveAndPublish"),[M,z]=a.useState([]),[F,v]=a.useState(!0),[P,C]=a.useState(null),[E,m]=a.useState(!1),[l,f]=a.useState(!1),[D,$]=a.useState(!1),[U,Z]=a.useState(!1),[q,Y]=a.useState(null),[_,b]=a.useState(!1),[K,W]=a.useState(!1),[Q,ee]=a.useState(!1),[r,R]=a.useState(""),[O,ce]=a.useState(!1),[ue,oe]=a.useState(!1),[re,se]=a.useState(0),[te,he]=a.useState([]),[ye,pe]=a.useState(!1),[ae,be]=a.useState(""),[ge,Ne]=a.useState([]),[de,i]=a.useState(!1),[V,fe]=a.useState(""),[le,ts]=a.useState(0),[Me,Ee]=a.useState("1"),[Re,as]=a.useState(0),[ve,ns]=a.useState(""),[ke,is]=a.useState(""),[xe,cs]=a.useState(""),[ls,os]=a.useState(null),[rs,ds]=a.useState([]),we=20,[Le,ms]=a.useState([]),[us,Se]=a.useState(!1),[Ce,Fe]=a.useState(null),[De,ze]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(k))},[k]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(S))},[S]),a.useEffect(()=>{h==="savePublish"&&Pe().then(n=>{g.current&&se(n.filter(L=>!L.published).length)})},[h]),a.useEffect(()=>{h==="bookmarks"&&hs(),h==="myDocuments"&&(me(),Xe().then(n=>{g.current&&ds(n)}).catch(()=>{}))},[h,ve,ke,xe]),a.useEffect(()=>{Be()},[]),a.useEffect(()=>{Ye().then(n=>{g.current&&ms(n)}).catch(()=>{})},[]);const je=new Map(Le.map(n=>[n.domainId,n.domainName]));async function Be(){try{v(!0);const n=await et();if(!g.current)return;z(n)}catch{}finally{g.current&&v(!1)}}async function hs(){try{pe(!0);const n=await st();if(!g.current)return;he(n)}catch{}finally{g.current&&pe(!1)}}async function me(n=0){try{i(!0);const L=await tt({offset:n*we,limit:we,domainId:ve||void 0,creatorVisitorId:ke||void 0,groupBy:xe||void 0});if(!g.current)return;Ne(L.items),os(L.groups??null),as(L.total),ts(n),Ee(String(n+1))}catch{}finally{g.current&&i(!1)}}async function ps(n){try{await rt(n),he(L=>L.filter(H=>H.documentId!==n))}catch{}}function gs(){if(M.some(L=>!L.revoked)){f(!0);return}$e()}async function $e(){try{m(!0);const n=await mt();C({token:n.token,name:n.name}),await Be()}finally{m(!1)}}async function fs(){try{ee(!0);const n=await lt();Y(n.recoveryCode)}finally{ee(!1)}}async function xs(n){n.preventDefault();const L=r.trim();if(!(L&&L.length<4))try{ce(!0),await ot(L),R(""),oe(!0),setTimeout(()=>oe(!1),3e3)}finally{ce(!1)}}async function js(n){Fe(n);try{const L=await dt(n),H=new Map;L.forEach(G=>{H.set(G.visitorId,G.permission)}),ze(H)}catch{ze(new Map)}Se(!0)}async function ys(n){if(Ce)try{const L=new Set(n.map(G=>G.visitorId)),H=new Set(De.keys());for(const G of H)L.has(G)||await ut(Ce,G);for(const G of n)await ht(Ce,G.visitorId,G.permission);await me()}finally{Se(!1),Fe(null)}}const Ke=te.filter(n=>{if(!ae.trim())return!0;const L=ae.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(L)||(n.ownerVisitorName||"").toLowerCase().includes(L)||(n.domainId||"").toLowerCase().includes(L)}),ne=Math.ceil(Re/we);return e.jsxs("div",{className:"mdocs-layout"+(u?" mdocs-layout--reader mdocs-layout--settings":""),children:[u&&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"+(u?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")})]}),u?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(nt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(h==="general"?" active":""),onClick:()=>A("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(h==="bookmarks"?" active":""),onClick:()=>A("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(h==="myDocuments"?" active":""),onClick:()=>A("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(h==="domainManagement"?" active":""),onClick:()=>A("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(h==="memberTemplates"?" active":""),onClick:()=>A("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(h==="agentConfig"?" active":""),onClick:()=>A("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(h==="savePublish"?" active":""),onClick:()=>A("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:p,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[u?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(it,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:y})]}):null,ct(),h==="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:j==="en"?"active":"",onClick:()=>d("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:j==="zh"?"active":"",onClick:()=>d("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"+(S?" active":""),role:"switch","aria-checked":S,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")}),!F&&M.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:M.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:gs,disabled:E||F,children:E?"…":M.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),P&&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:P.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(P.token),Z(!1),$(!0),window.setTimeout(()=>$(!1),2e3)}catch{$(!1),Z(!0),window.setTimeout(()=>Z(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),U&&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:fs,disabled:Q,children:Q?"…":"生成恢复码"})]}),q&&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:q})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(q),W(!1),b(!0),window.setTimeout(()=>b(!1),2e3)}catch{b(!1),W(!0),window.setTimeout(()=>W(!1),3e3)}})()},children:_?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>Y(null),children:s("close")})]}),_&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),K&&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:xs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:r,onChange:n=>R(n.target.value),minLength:0,style:{marginBottom:8}}),ue&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):h==="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:ae,onChange:n=>be(n.target.value)}),ye?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ke.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(ae?"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:Ke.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):je.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:()=>ps(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):h==="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(xt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:V,onChange:n=>fe(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ns(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Le.map(n=>e.jsx("option",{value:n.domainId,children:je.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ke,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>is(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),rs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:xe,"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")})]})]}),de?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):e.jsxs(e.Fragment,{children:[ge.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(V?"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:(ls??[{key:"",items:ge}]).flatMap(n=>{var G;const L=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:xe==="domain"?je.get(n.key)||n.key:((G=n.items[0])==null?void 0:G.creatorName)||n.key})},`group-${n.key}`):null,H=n.items.map(J=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>t.onOpenDocument(J.documentId),children:J.displayName||J.relativePath||"Untitled"}),e.jsx("td",{children:je.get(J.domainId||"")||J.domainId||"—"}),e.jsx("td",{children:J.creatorName||J.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>js(J.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(J.documentId),children:s("bookmarkOpen")})]})]},J.documentId));return L?[L,...H]:H})})]})}),e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(ne>0?le+1:0),total:String(ne),count:String(Re)})}),ne>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const L=Number.parseInt(Me,10);if(!Number.isFinite(L))return;const H=Math.min(Math.max(L,1),ne)-1;H!==le&&me(H)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:ne,"aria-label":s("myDocumentsJumpTo"),value:Me,onChange:n=>Ee(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),ne>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:le<=0,onClick:()=>me(le-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:le>=ne-1,onClick:()=>me(le+1),children:s("myDocumentsNext")})]})]})]})]})]}):h==="domainManagement"?e.jsx(Nt,{}):h==="memberTemplates"?e.jsx(vt,{}):h==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Ct,{}),e.jsx(It,{})]}):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:p,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"+(k?" active":""),role:"switch","aria-checked":k,onClick:()=>T(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),re>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>o(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",re,")"]}),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")})})]})]}),x&&e.jsx(yt,{onPublish:B,onClose:()=>o(!1),onCountChange:se,onRecover:t.onRecoverDraft})]}),l&&e.jsx(es,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:E,onConfirm:()=>{f(!1),$e()},onCancel:()=>f(!1)}),e.jsx(ss,{open:us,title:s("docInfoInviteMember"),initialSelectedIds:[...De.keys()],initialPermissions:De,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Se(!1),onConfirm:n=>{ys(n)}})]})}export{Ft as SettingsPage};
6
+ */const ft=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],xt=bs("search",ft);function jt({draft:t,onClose:s,onSuccess:j}){const{t:d,lang:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(t.domainId??""),[g,k]=a.useState([]),[T,S]=a.useState(""),[c,x]=a.useState(`${t.displayName||"untitled"}_recovered.md`),[o,h]=a.useState(!1),[I,A]=a.useState(null),y=a.useRef(null),M=a.useRef(!0);a.useEffect(()=>(M.current=!0,()=>{M.current=!1}),[]),a.useEffect(()=>{Ns().then(v=>{M.current&&u(v)})},[]),a.useEffect(()=>{w&&(k([]),S(""),vs(w).then(v=>{M.current&&k(v)}).catch(()=>{M.current&&k([])}))},[w]),a.useEffect(()=>{const v=window.setTimeout(()=>{var P;return(P=y.current)==null?void 0:P.focus()},0);return()=>window.clearTimeout(v)},[]),a.useEffect(()=>{const v=P=>{P.key==="Escape"&&s()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[s]);function z(v,P){for(const C of v){if(C.type==="folder"&&C.path===P)return C.documentId;if(C.type==="folder"){const E=z(C.children,P);if(E)return E}}return null}async function F(v){v.preventDefault(),h(!0),A(null);const P=c.replace(/\s+/g,"_").replace(/[^a-zA-Z0-9_\-.]/g,""),C=P.endsWith(".md")?P:P+".md",E=C.replace(/\.md$/i,"");try{const m=T?`${T}/${C}`:C,l=T?z(g,T)??void 0:void 0;await Ss({fileName:C,displayName:E,content:t.content,domainId:w,parentId:l}),j()}catch(m){A(Q(d,m))}finally{h(!1)}}return e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&!o&&s()},children:e.jsxs("div",{className:"mdocs-dialog card mdocs-recovery-dialog",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:d("recoverDraft")}),e.jsx("p",{className:"muted",children:d("recoverDraftDesc",{name:t.displayName||d("unknownTitle")})}),e.jsxs("form",{onSubmit:F,className:"mdocs-dialog-form",children:[e.jsxs("label",{className:"mdocs-dialog-label",children:[d("domainLabel"),B.length>0&&e.jsx(ks,{domains:B,value:w,onChange:N,onDomainsChange:u,ariaLabel:d("domainLabel"),localizeName:v=>Ae(v,p,d)})]}),e.jsxs("label",{className:"mdocs-dialog-label mdocs-recovery-tree-label",children:[d("recoverTargetFolder"),e.jsx("div",{className:"mdocs-recovery-tree",children:e.jsx(ws,{nodes:g,activeDocumentId:null,selectedParentPath:T,onOpen:()=>{},onOpenFolder:v=>S(v),onContextMenu:()=>{},onDeselect:()=>S("")})})]}),e.jsxs("label",{className:"mdocs-dialog-label",children:[d("fileNameLabel"),e.jsx("input",{ref:y,value:c,onChange:v=>x(v.target.value),placeholder:"recovered.md",maxLength:200,disabled:o})]}),I&&e.jsx("div",{className:"mdocs-dialog-error",children:I}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>!o&&s(),disabled:o,children:d("cancel")}),e.jsx("button",{type:"submit",className:"primary",disabled:o,children:d(o?"creating":"create")})]})]})]})})}function yt({onPublish:t,onClose:s,onCountChange:j,onRecover:d}){const{t:p}=ie(),[B,u]=a.useState([]),[w,N]=a.useState(new Set),[g,k]=a.useState(!1),[T,S]=a.useState(null),[c,x]=a.useState(null),[o,h]=a.useState(null),I=a.useRef(null),A=a.useRef(!0);a.useEffect(()=>(A.current=!0,Pe().then(l=>{if(!A.current)return;const f=l.filter(D=>!D.published);u(f),j==null||j(f.length)}),()=>{A.current=!1,I.current&&(clearTimeout(I.current),I.current=null)}),[]),a.useEffect(()=>{const l=f=>{f.key==="Escape"&&s()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s]);const y=a.useCallback((l,f)=>{h({message:l,type:f}),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>h(null),3e3)},[]);async function M(l){await Ds(l),N(f=>new Set(f).add(l));try{await t(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("published"),"success")}catch(f){f instanceof Is||y(p("publishFailed"),"error");const D=await Ts(l);D&&u($=>$.map(U=>U.documentId===l?D:U))}finally{N(f=>{const D=new Set(f);return D.delete(l),D})}}async function z(l){S(null),await Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),y(p("draftDeleted"),"success")}function F(l){const f=B.find(D=>D.documentId===l);f&&x(f)}function v(l){x(null),Oe(l),u(f=>{const D=f.filter($=>$.documentId!==l);return j==null||j(D.length),D}),d==null||d(B.find(f=>f.documentId===l)),y(p("published"),"success")}async function P(){k(!0);let l=0,f=0;for(const U of B)try{await t(U.documentId),l++}catch{f++}const $=(await Pe()).filter(U=>!U.published);u($),j==null||j($.length),f===0?y(p("publishAll"),"success"):y(`${l} published, ${f} failed`,"error"),k(!1)}const C=l=>new Date(l).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),E=l=>Cs(p,l,l.publishError??"UNKNOWN"),m=B;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:[p("unpublishedDrafts"),m.length>0&&e.jsx("span",{className:"mdocs-drawer-count-badge",children:m.length})]}),e.jsx("span",{className:"mdocs-drawer-subtitle",children:p("draftCount",{count:String(m.length)})})]}),e.jsx("button",{type:"button",className:"mdocs-drawer-close-btn",onClick:s,"aria-label":p("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:p("draftsEmptyState")})]}):e.jsx("div",{className:"mdocs-drawer-items",children:m.map(l=>{const f=!!l.publishError;return e.jsxs("div",{className:f?"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:l.displayName||p("unknownTitle")}),f?e.jsxs("span",{className:"mdocs-drawer-item-error",children:[C(l.publishErrorAt)," · ",E(l)]}):e.jsxs("span",{className:"mdocs-drawer-item-meta",children:[C(l.updatedAt)," · ",p("localSnapshot")]})]}),e.jsxs("div",{className:"mdocs-drawer-item-actions",children:[f?e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:g,onClick:()=>F(l.documentId),children:p("recoverDraft")}):e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-primary",disabled:w.has(l.documentId)||g,onClick:()=>void M(l.documentId),children:w.has(l.documentId)?p("publishing"):p("publish")}),e.jsx("button",{type:"button",className:"mdocs-btn-ghost mdocs-btn-ghost-danger",disabled:g,onClick:()=>S(l.documentId),children:p("delete")})]})]},l.documentId)})})}),e.jsxs("footer",{className:"mdocs-drawer-footer",children:[e.jsx("button",{type:"button",onClick:s,children:p("close")}),e.jsx("button",{type:"button",className:"primary",disabled:m.length===0||g,onClick:()=>void P(),children:g?p("publishing"):`${p("publishAll")} (${m.length})`})]}),o&&e.jsx("div",{className:"mdocs-drawer-toast mdocs-drawer-toast--"+o.type,role:"status",children:o.message})]}),T&&e.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&S(null)},children:e.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[e.jsx("h1",{children:p("delete")}),e.jsx("p",{className:"muted",children:p("confirmDeleteDraft")}),e.jsxs("div",{className:"mdocs-dialog-actions",children:[e.jsx("button",{type:"button",onClick:()=>S(null),children:p("cancel")}),e.jsx("button",{type:"button",className:"danger",onClick:()=>void z(T),children:p("delete")})]})]})}),c&&e.jsx(jt,{draft:c,onClose:()=>x(null),onSuccess:()=>v(c.documentId)})]})}function bt(){const{t,lang:s}=ie(),j=Ye(),d=a.useRef(!1),[p,B]=a.useState([]),[u,w]=a.useState(!1),[N,g]=a.useState(""),[k,T]=a.useState("restricted"),[S,c]=a.useState(!1),[x,o]=a.useState(null),[h,I]=a.useState(null),[A,y]=a.useState(""),[M,z]=a.useState(""),[F,v]=a.useState("all"),[P,C]=a.useState(null);a.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const E=a.useCallback(async()=>{w(!0),o(null);try{const b=await qe();if(!d.current)return;B(b)}catch(b){if(!d.current)return;o(Q(t,b))}finally{d.current&&w(!1)}},[t]);a.useEffect(()=>{E()},[E]);async function m(b){if(b.preventDefault(),!N.trim()){o(t("domainNameRequired"));return}c(!0),o(null);try{if(await Rs({domainName:N.trim(),permission:k}),!d.current)return;g(""),T("restricted"),await E()}catch(K){if(!d.current)return;o(Q(t,K))}finally{d.current&&c(!1)}}async function l(b){if(A.trim()){o(null);try{if(await Es(b,A.trim()),!d.current)return;I(null),C(null),await E()}catch(K){if(!d.current)return;o(Q(t,K))}}}function f(b){I(b.domainId),y(b.domainName),C(null)}function D(){I(null),C(null)}async function $(b,K){o(null);try{if(await Ms(b,K),!d.current)return;C(null),await E()}catch(W){if(!d.current)return;o(Q(t,W))}}async function U(b){if(window.confirm(t("deleteDomainConfirmDetail",{name:b.domainName,count:String(b.docCount)}))){o(null);try{if(await Ps(b.domainId),!d.current)return;await E()}catch(K){if(!d.current)return;o(Q(t,K))}}}const Z=a.useCallback(b=>As(b,t),[t]),Y=a.useCallback(b=>Ae(b.domainName,s,t),[s,t]),q=a.useMemo(()=>{const b=M.trim().toLowerCase();return p.filter(K=>F!=="all"&&K.permission!==F?!1:b?Ae(K.domainName,s,t).toLowerCase().includes(b)||K.domainName.toLowerCase().includes(b):!0)},[p,M,F,s,t]),_=a.useCallback((b,K)=>{const W=Z(b.permission);return K?`${W} ${t("domainTypeBuiltinSuffix")}`:W},[Z,t]);return{domains:p,loadingDomains:u,domainError:x,newDomainName:N,setNewDomainName:g,newDomainPermission:k,setNewDomainPermission:T,creating:S,handleCreateDomain:m,renamingId:h,setRenamingId:I,renameDraft:A,setRenameDraft:y,startRename:f,cancelRename:D,handleRename:l,changeTypeForId:P,setChangeTypeForId:C,handlePermissionChange:$,handleDelete:U,domainSearch:M,setDomainSearch:z,domainFilter:F,setDomainFilter:v,filteredDomains:q,visitorId:j,plabel:Z,localizeDomain:Y,domainTypeLabel:_}}const Ue={private:0,restricted:1,public:2};function We(t){return Object.prototype.hasOwnProperty.call(Ue,t)?Ue[t]:null}function _e(t,s){const j=We(t),d=We(s);return j===null||d===null?"invalid":d>j?"upgrade":d<j?"downgrade":"same"}function Nt(){const{t}=ie(),s=bt(),[j,d]=a.useState([]),[p,B]=a.useState(null),[u,w]=a.useState(""),N=a.useRef(null),[g,k]=a.useState(null),T=a.useCallback(async()=>{try{const c=await Xe();d(c)}catch{d([])}},[]);a.useEffect(()=>{T()},[T]),a.useEffect(()=>{if(!s.changeTypeForId)return;const c=x=>{var o;(o=N.current)!=null&&o.contains(x.target)||s.setChangeTypeForId(null)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[s.changeTypeForId,s.setChangeTypeForId]);async function S(c){B(null);try{const x=await Ks(c.domainId);k({domainId:c.domainId,creatorVisitorId:c.creatorVisitorId,initialIds:x.map(o=>o.visitorId),memberRows:x})}catch(x){B({kind:"err",text:translateError(t,x)})}}return e.jsxs("div",{className:"mdocs-settings",children:[e.jsx("div",{className:"mdocs-settings-header",children:e.jsx("h2",{className:"mdocs-settings-title",children:t("domainManagement")})}),e.jsx("p",{className:"mdocs-domain-mgmt-restricted-hint",children:t("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:t("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:t("domainName")}),e.jsx("input",{value:s.newDomainName,onChange:c=>s.setNewDomainName(c.target.value),placeholder:t("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:t("domainPermission")}),e.jsx("div",{className:"mdocs-domain-mgmt-type-radios",children:Ie.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?t("creating"):t("create")})]})]}),p&&e.jsx("div",{className:"mdocs-settings-card",style:{color:p.kind==="ok"?"var(--mdocs-success, #0a7)":"var(--mdocs-danger)"},children:e.jsx("span",{className:"mdocs-settings-item-desc",children:p.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:t("domainSearchPlaceholder"),className:"mdocs-domain-mgmt-search","aria-label":t("domainSearchPlaceholder")}),e.jsx("div",{className:"mdocs-domain-mgmt-filters",role:"group","aria-label":t("domainPermission"),children:["all",...Ie].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"?t("domainFilterAll"):s.plabel(c)},c))})]}),s.loadingDomains?e.jsx("div",{className:"mdocs-settings-card",children:e.jsx("span",{className:"mdocs-settings-item-desc",children:t("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:t("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:t("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:t("domainColName")}),e.jsx("th",{scope:"col",children:t("domainColType")}),e.jsx("th",{scope:"col",className:"mdocs-domain-table-num",children:t("domainColDocCount")}),e.jsx("th",{scope:"col",children:t("domainColActions")})]})}),e.jsx("tbody",{children:s.filteredDomains.map(c=>{const x=Ls(c,s.visitorId),o=Fs(c.domainId),h=zs(c),I=_e(c.permission,"public")==="upgrade",A=I?h?t("domainTooltipTypeLocked"):void 0:t("domainPermissionAlreadyTop");return e.jsxs("tr",{className:o?"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:y=>s.setRenameDraft(y.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:t("save")}),e.jsx("button",{type:"button",onClick:s.cancelRename,children:t("cancel")})]}):e.jsxs("div",{className:"mdocs-domain-table-name-cell",children:[e.jsx("span",{className:"mdocs-domain-table-name",children:s.localizeDomain(c)}),o&&e.jsx("span",{className:"mdocs-domain-badge-builtin",children:t("domainBuiltIn")}),!x&&!o&&e.jsx("span",{className:"mdocs-domain-badge-shared",children:t("shared")})]})}),e.jsx("td",{children:e.jsx("span",{className:"mdocs-domain-table-type",title:A,children:e.jsx("span",{className:"mdocs-domain-permission-badge","data-permission":c.permission,children:s.domainTypeLabel(c,o)})})}),e.jsx("td",{className:"mdocs-domain-table-num",children:c.docCount}),e.jsxs("td",{className:"mdocs-domain-table-actions",children:[o&&e.jsx("span",{className:"mdocs-domain-not-modifiable",children:t("domainNotModifiable")}),!o&&!x&&e.jsx("span",{className:"mdocs-domain-not-creator-inline",children:t("domainNotCreator")}),!o&&x&&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":t("domainChangeType"),children:Ie.map(y=>{const z=_e(c.permission,y)==="downgrade";return e.jsx("span",{title:z?t("domainPermissionNoDowngrade"):void 0,children:e.jsx("button",{type:"button",role:"radio","aria-checked":u===y,className:u===y?"active":"",disabled:z,onClick:()=>w(y),children:s.plabel(y)})},y)})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon confirm","aria-label":t("save"),disabled:u===""||u===c.permission,onClick:()=>{u&&u!==c.permission&&s.handlePermissionChange(c.domainId,u)},children:e.jsx(gt,{size:14,strokeWidth:2.5})}),e.jsx("button",{type:"button",className:"mdocs-domain-type-icon cancel","aria-label":t("cancel"),onClick:()=>s.setChangeTypeForId(null),children:e.jsx(Bs,{size:14,strokeWidth:2.5})})]}),!o&&x&&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 S(c),children:t("domainMembersManageButton")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:h?t("domainLocked"):void 0,onClick:()=>{s.setChangeTypeForId(null),s.startRename(c)},disabled:h,children:t("rename")}),e.jsx("button",{type:"button",className:"mdocs-domain-action",title:A,onClick:()=>{s.setRenamingId(null),w(c.permission),s.setChangeTypeForId(c.domainId)},disabled:!I,children:t("domainChangeType")}),e.jsx("button",{type:"button",className:"mdocs-domain-action mdocs-domain-action--danger",title:h?t("domainLocked"):void 0,onClick:()=>void s.handleDelete(c),disabled:h,children:t("deleteDomain")})]})]})]},c.domainId)})})]})})]}),e.jsx(ss,{open:g!==null,title:t("domainMembersPickerTitle"),initialSelectedIds:(g==null?void 0:g.initialIds)??[],lockedIds:g?[g.creatorVisitorId]:[],seedMembers:g==null?void 0:g.memberRows,templates:j,onClose:()=>k(null),onConfirm:async c=>{g&&(await $s(g.domainId,c),B({kind:"ok",text:t("domainMembersSaved",{count:String(c.length)})}))}})]})}function Ge(t){return t.length<=6?t:`${t.slice(0,6)}…`}function vt(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState([]),[p,B]=a.useState(!0),[u,w]=a.useState(null),[N,g]=a.useState(1),[k,T]=a.useState(null),[S,c]=a.useState(""),[x,o]=a.useState([]),[h,I]=a.useState(!1),[A,y]=a.useState(null),[M,z]=a.useState(!1),F=Ye(),[v,P]=a.useState([]),[C,E]=a.useState("idle"),[m,l]=a.useState("");a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]),a.useEffect(()=>{E("loading"),Qe().then(r=>{s.current&&(P(r),E("ok"))}).catch(()=>{s.current&&E("err")})},[]);const f=a.useMemo(()=>{const r=new Map;for(const R of v)r.set(R.visitorId,R.visitorName);return r},[v]),D=a.useCallback(async()=>{B(!0),y(null);try{const r=await Xe();s.current&&d(r)}catch(r){s.current&&y(Q(t,r))}finally{s.current&&B(!1)}},[t]);a.useEffect(()=>{D()},[D]);const $=a.useMemo(()=>x.map(r=>{const R=v.find(O=>O.visitorId===r);return{visitorId:r,name:R?R.visitorName:t("visitorPickerUnknownVisitor"),muted:!R}}),[x,v,t]);function U(r){o(R=>R.includes(r)?R.filter(O=>O!==r):[...R,r])}const Z=N===1?S.trim().length>0:N===2?x.length>0:!0;function Y(){if(!(N>=3)){if(!Z){z(!0);return}z(!1),g(N+1),l("")}}function q(){N<=1||(z(!1),g(N-1))}function _(){w(null),T(null),c(""),o(F?[F]:[]),y(null),g(1),l(""),z(!1)}function b(r){w(null),T(r.id),c(r.displayName);const R=F&&!r.visitorIds.includes(F)?[...r.visitorIds,F]:[...r.visitorIds];o(R),y(null),g(1),l(""),z(!1)}async function K(){if(!(!S.trim()||x.length===0)){I(!0),y(null);try{if(k===null?await Os({displayName:S.trim(),visitorIds:x}):await Vs(k,{displayName:S.trim(),visitorIds:x}),!s.current)return;_(),await D()}catch(r){if(!s.current)return;y(Q(t,r))}finally{s.current&&I(!1)}}}async function W(r){I(!0),y(null);try{if(await Us(r),!s.current)return;w(null),k===r&&_(),await D()}catch(R){if(!s.current)return;y(Q(t,R))}finally{s.current&&I(!1)}}const X=[{key:1,label:t("memberTemplateStepName")},{key:2,label:t("memberTemplateStepMembers")},{key:3,label:t("memberTemplateStepSave")}],ee=`${(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:t(k!==null?"memberTemplateUpdate":"memberTemplateFormNew")}),k!==null&&e.jsx("button",{type:"button",className:"secondary",onClick:_,style:{fontSize:12},children:t("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:ee}})}),e.jsx("div",{className:"mdocs-wizard-progress-steps",children:X.map(r=>{const R=N===r.key,O=N>r.key;return e.jsxs("div",{className:"mdocs-wizard-step-indicator",children:[e.jsx("div",{className:`mdocs-wizard-step-circle${R?" current":""}${O?" done":""}`,children:O?"✓":r.key}),e.jsx("span",{className:`mdocs-wizard-step-label${R?" current":""}${O?" done":""}`,children:r.label})]},r.key)})})]}),A&&e.jsx("div",{className:"mdocs-settings-item-desc",style:{color:"var(--mdocs-danger)",marginBottom:12,marginTop:12},children:A}),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:S,onChange:r=>c(r.target.value),placeholder:t("memberTemplateNamePlaceholder"),maxLength:200,disabled:h,autoFocus:!0,"aria-invalid":M&&!S.trim()}),M&&!S.trim()&&e.jsx("p",{className:"mdocs-wizard-hint",style:{color:"var(--mdocs-danger)"},children:t("domainNameRequired")})]}),N===2&&e.jsxs("div",{className:"mdocs-wizard-step-content",children:[e.jsx(pt,{visitors:v,loadState:C,searchFilter:m,onSearchChange:l,selectedIds:new Set(x),onToggle:U,selectedRows:$,myVisitorId:F}),e.jsx("p",{className:`mdocs-wizard-hint${M&&x.length===0?" danger":""}`,children:"💡 "+t("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:t("memberTemplateNameLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:S})]}),e.jsxs("div",{className:"mdocs-wizard-preview-row",children:[e.jsx("span",{className:"mdocs-wizard-preview-label",children:t("memberTemplateIdsLabel")}),e.jsx("span",{className:"mdocs-wizard-preview-value",children:t("memberTemplateSelectedSummary",{count:String(x.length)})})]}),x.length>0&&e.jsxs("div",{className:"mdocs-wizard-preview-tags",children:[x.slice(0,15).map(r=>e.jsx("span",{className:"mdocs-wizard-preview-tag",children:Ge(r)},r)),x.length>15&&e.jsxs("span",{className:"mdocs-wizard-preview-tag mdocs-wizard-preview-tag-more",children:["+",x.length-15]})]})]})}),e.jsxs("div",{className:"mdocs-wizard-footer",children:[e.jsxs("button",{type:"button",className:"secondary",onClick:q,children:["← ",t("memberTemplateWizardBack")]}),N<3?e.jsxs("button",{type:"button",className:"primary",onClick:Y,children:[t("memberTemplateWizardNext")," →"]}):e.jsx("button",{type:"button",className:"primary",onClick:()=>void K(),children:t(h?"saving":k===null?"memberTemplateCreate":"memberTemplateUpdate")})]})]}),e.jsxs("div",{className:"mdocs-settings-card",children:[e.jsx("div",{className:"mdocs-settings-card-title",children:t("memberTemplateSavedList")}),p?e.jsx("span",{className:"mdocs-settings-item-desc",children:t("loading")}):j.length===0?e.jsxs("div",{className:"mdocs-member-template-empty",children:[e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateEmpty")}),k===null&&e.jsx("button",{type:"button",className:"primary",onClick:_,children:t("memberTemplateEmptyAction")})]}):e.jsx("ul",{className:"mdocs-member-template-list",children:j.map(r=>e.jsx("li",{className:"mdocs-member-template-row",children:u===r.id?e.jsxs("div",{className:"mdocs-member-template-confirm-row",children:[e.jsx("span",{className:"mdocs-member-template-confirm-text",children:t("memberTemplateConfirmDeleteDesc",{name:r.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 W(r.id),children:t(h?"saving":"memberTemplateConfirmDeleteSubmit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(null),children:t("memberTemplateConfirmDeleteCancel")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mdocs-member-template-row-head",children:[e.jsx("strong",{children:r.displayName}),e.jsx("span",{className:"mdocs-settings-item-desc",children:t("memberTemplateCount",{count:String(r.visitorIds.length)})}),r.visitorIds.length>0&&e.jsx("div",{className:"mdocs-member-template-tags mdocs-member-template-tags-scroll",children:r.visitorIds.map(R=>e.jsx("span",{className:"mdocs-member-template-tag",children:f.get(R)??Ge(R)},R))})]}),e.jsxs("div",{className:"mdocs-member-template-row-actions",children:[e.jsx("button",{type:"button",className:"secondary",onClick:()=>b(r),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>w(r.id),children:t("memberTemplateDelete")})]})]})},r.id))})]})]})]})}const kt=[{value:"deepseek-flash",label:"deepseek-flash(V4.1 Flash)"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro(将路由至 Flash)"}],wt=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function St(t,s,j){return t==="deepseek"?"Deepseek":s||j}function He(t){return`${St(t.kind,t.providerId,t.name)} · ${t.modelId} · ${t.name}`}function Ct(){const{t}=ie(),s=a.useRef(!0),[j,d]=a.useState(""),[p,B]=a.useState([]),[u,w]=a.useState(null),[N,g]=a.useState(null),[k,T]=a.useState("deepseek"),[S,c]=a.useState(""),[x,o]=a.useState(""),[h,I]=a.useState(""),[A,y]=a.useState("openai-completions"),[M,z]=a.useState("deepseek-flash"),[F,v]=a.useState(1e6),[P,C]=a.useState(""),[E,m]=a.useState(!1),[l,f]=a.useState(null),[D,$]=a.useState(!1),[U,Z]=a.useState(!0),[Y,q]=a.useState(!1),[_,b]=a.useState(null),[K,W]=a.useState(!1),[X,ee]=a.useState(!1),[r,R]=a.useState(!1),[O,ce]=a.useState(null),[ue,oe]=a.useState(null),re=a.useRef(!1);a.useEffect(()=>(s.current=!0,()=>{s.current=!1}),[]);const se=a.useCallback(async()=>{const i=await Ws();if(s.current)return B(i),i},[]);function te(){g(null),T("deepseek"),c(""),o(""),I(""),y("openai-completions"),z("deepseek-flash"),v(1e6),C(""),m(!1),f(null),$(!1),ee(!1),R(!1),b(null),W(!1)}function he(i){g(i.id),T(i.kind),c(i.name),o(i.providerId??""),I(i.baseUrl),y(i.apiType);const V=i.modelId.trim(),fe=new Set(["deepseek-flash","deepseek-v4-flash","deepseek-v4-flash-vision-exp","deepseek-v4.1-flash","deepseek-v4.1-flash-expires-on-0910"]);z(i.kind==="deepseek"?V==="deepseek-v4-pro"?"deepseek-v4-pro":fe.has(V)?"deepseek-flash":V||"deepseek-flash":V),v(i.contextWindow||1e6),m(i.hasApiKey),f(i.apiKeyMasked),C(""),$(i.isDefault)}a.useEffect(()=>{(async()=>{try{const i=await _s();if(!s.current)return;d(i.visitorName);const V=await se();if(!s.current||!V)return;V.length===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i)),w("create")}finally{s.current&&Z(!1)}})()},[se]);function ye(){te(),w("create")}function pe(i){he(i),w("edit"),W(!1),b(null)}function ae(){te(),w(null)}async function be(i){if(!(i.isDefault||ue)){oe(i.id),b(null);try{await Gs(i.id),await se()}catch(V){if(!s.current)return;b(V instanceof Error?V.message:String(V))}finally{s.current&&oe(null)}}}async function ge(){if(O){q(!0),b(null);try{await Js(O.id);const i=await se();if(!s.current)return;u==="edit"&&N===O.id&&ae(),((i==null?void 0:i.length)??0)===0&&(te(),w("create"))}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&(q(!1),ce(null))}}}async function Ne(){q(!0),b(null),W(!1);try{const i=k==="custom"?{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,baseUrl:h,modelId:M,providerId:x.trim()||void 0,apiType:A,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}}:{...u==="edit"&&N?{id:N}:{},...u==="create"&&D?{isDefault:!0}:{},kind:k,modelId:M,name:S,contextWindow:F,...P.trim()?{apiKey:P.trim()}:{}};if(await Hs(i),!s.current)return;await se(),W(!0),w(null),te()}catch(i){if(!s.current)return;b(i instanceof Error?i.message:String(i))}finally{s.current&&q(!1)}}const de=u!==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:t("agentConfig")}),!U&&!de?e.jsx("button",{type:"button",className:"secondary",onClick:ye,children:"添加配置"}):null]}),e.jsxs("div",{className:"mdocs-settings-cards",children:[!U&&p.length>0&&!de?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:p.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:ue!==null,onChange:()=>void be(i)}),e.jsx("span",{children:i.isDefault?"默认":"设为默认"})]}),e.jsxs("div",{className:"mdocs-agent-config-item-main",children:[e.jsx("strong",{children:He(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:()=>pe(i),children:t("edit")}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>ce(i),children:"删除"})]})]},i.id))}),K?e.jsx("p",{className:"mdocs-agent-config-ok",children:t("saved")}):null,_?e.jsx("p",{className:"mdocs-agent-config-error",children:_}):null]}):null,de?e.jsxs("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:[e.jsx("p",{className:"mdocs-agent-config-lead",children:u==="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":k==="deepseek",className:k==="deepseek"?"active":"",onClick:()=>T("deepseek"),children:"Deepseek"}),e.jsx("button",{type:"button",role:"tab","aria-selected":k==="custom",className:k==="custom"?"active":"",onClick:()=>T("custom"),children:"自定义"})]}),k==="deepseek"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigModel")}),e.jsx(Ve,{options:[...kt],value:M,onChange:z})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:X?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):t("agentConfigApiKeyPlaceholder"),autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(X?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:X?"隐藏":"显示"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 地址"}),e.jsx("input",{type:"url",value:h,onChange:i=>{const V=i.target.value;if(I(V),re.current)return;V.toLowerCase().includes("anthropic")?y("anthropic-messages"):y("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:M,onChange:i=>z(i.target.value),placeholder:"模型名称,如 gpt-4o",className:"mdocs-agent-mono"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigApiKey")}),e.jsxs("div",{className:"mdocs-agent-config-apikey",children:[e.jsx("input",{type:X?"text":"password",value:P,onChange:i=>C(i.target.value),placeholder:E?t("agentConfigApiKeyConfigured").replace("{{masked}}",l??"…"):"粘贴 API Key",autoComplete:"off"}),e.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":t(X?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>ee(i=>!i),children:X?"隐藏":"显示"})]})]})]}),e.jsxs("details",{className:"mdocs-agent-advanced",open:r,onToggle:i=>R(i.target.open),children:[e.jsx("summary",{children:"高级选项"}),k==="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:x,onChange:i=>o(i.target.value),placeholder:"不填则自动从 API 地址提取域名"})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:"API 协议"}),e.jsx(Ve,{options:[...wt],value:A,onChange:i=>{re.current=!0,y(i)}})]})]}):null,e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigName")}),e.jsx("input",{type:"text",value:S,onChange:i=>c(i.target.value),placeholder:t("agentConfigNameDefault").replace("{{name}}",j||"…")})]}),e.jsxs("label",{className:"mdocs-agent-field",children:[e.jsx("span",{children:t("agentConfigContextWindow")}),e.jsx("input",{type:"number",min:1e3,max:2e6,step:1e3,value:F,onChange:i=>v(Number(i.target.value)||1e6)}),e.jsx("p",{className:"mdocs-agent-field-hint",children:t("agentConfigContextWindowDesc")})]})]}),u==="create"&&p.length>0?e.jsxs("label",{className:"mdocs-agent-config-default-check",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:i=>$(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 Ne(),disabled:Y,children:t(Y?"saving":"save")}),p.length>0?e.jsx("button",{type:"button",className:"secondary",onClick:ae,disabled:Y,children:t("cancel")}):null]})]})]}):U?e.jsx("div",{className:"mdocs-settings-card mdocs-agent-config-card",children:e.jsx("p",{className:"mdocs-agent-config-muted",children:t("loading")})}):null]}),O?e.jsx(es,{title:"删除配置",message:`确定删除「${He(O)}」?${O.isDefault&&p.length>1?" 删除后将自动把另一条设为默认。":""}`,confirmLabel:"删除",cancelLabel:t("cancel"),onConfirm:()=>void ge(),onCancel:()=>ce(null)}):null]})}const Dt=/^[A-Za-z0-9_]+$/;function Te(t){return Dt.test(t.trim())}function It(){const t=a.useRef(!0),[s,j]=a.useState([]),[d,p]=a.useState(!0),[B,u]=a.useState(null),[w,N]=a.useState(null),[g,k]=a.useState(!1),[T,S]=a.useState(""),[c,x]=a.useState(""),[o,h]=a.useState(""),[I,A]=a.useState(!1);a.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]);async function y(){p(!0),u(null);try{const m=await Zs();if(!t.current)return;j(m)}catch(m){if(!t.current)return;u(m instanceof Error?m.message:String(m))}finally{t.current&&p(!1)}}a.useEffect(()=>{y()},[]);function M(){k(!0),N(null),S(""),x(""),h(""),u(null)}function z(m){k(!1),N(m.id),S(m.name),x(m.description),h(m.body),u(null)}function F(){k(!1),N(null),S(""),x(""),h("")}async function v(){const m=T.trim();if(!Te(m)){u("名称仅允许英文、数字、下划线");return}if(!o.trim()){u("正文不能为空");return}A(!0),u(null);try{if(g?await Ys({name:m,description:c,body:o}):w&&await qs(w,{name:m,description:c,body:o}),!t.current)return;F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}finally{t.current&&A(!1)}}async function P(m){if(window.confirm("删除该 Skill?已引用的历史轮次将跳过缺失项。")){u(null);try{if(await Xs(m),!t.current)return;w===m&&F(),await y()}catch(l){if(!t.current)return;u(l instanceof Error?l.message:String(l))}}}const C=g||w!==null,E=!T.trim()||Te(T);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",!d&&s.length>0?e.jsx("span",{className:"mdocs-agent-skills-count",children:s.length}):null]}),C?null:e.jsx("button",{type:"button",className:"secondary",onClick:M,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:"私人提示词宏。名称对本账号唯一,仅英文、数字、下划线;智能助手 / 帮写里按名称引用。"}),B?e.jsx("p",{className:"mdocs-agent-skills-error",children:B}):null,C?e.jsxs("div",{className:"mdocs-agent-skills-form",children:[e.jsx("div",{className:"mdocs-agent-skills-form-head",children:e.jsx("strong",{children:g?"新建 Skill":"编辑 Skill"})}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"名称"}),e.jsx("input",{type:"text",value:T,onChange:m=>S(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=>x(m.target.value),maxLength:200,placeholder:"一句话说明用途"})]}),e.jsxs("label",{className:"mdocs-agent-skills-field",children:[e.jsx("span",{children:"正文"}),e.jsx("textarea",{value:o,onChange:m=>h(m.target.value),rows:10,placeholder:"写入 Agent 应遵守的步骤与约束…"})]}),e.jsxs("div",{className:"mdocs-agent-config-actions",children:[e.jsx("button",{type:"button",onClick:()=>void v(),disabled:I||!E||!T.trim()||!o.trim(),children:I?"保存中…":"保存"}),e.jsx("button",{type:"button",className:"secondary",onClick:F,disabled:I,children:"取消"})]})]}):null,d?e.jsx("p",{className:"mdocs-settings-item-desc",children:"加载中…"}):null,!d&&s.length===0&&!C?e.jsxs("div",{className:"mdocs-agent-skills-empty",children:[e.jsx("p",{children:"还没有 Skill"}),e.jsx("button",{type:"button",className:"secondary",onClick:M,children:"新建第一个"})]}):null,!d&&s.length>0?e.jsx("ul",{className:"mdocs-agent-skills-list",children:s.map(m=>{const l=Te(m.name),f=w===m.id;return e.jsxs("li",{className:"mdocs-agent-skills-item"+(f?" 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}),l?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:()=>z(m),disabled:C&&!f,children:"编辑"}),e.jsx("button",{type:"button",className:"secondary small",onClick:()=>void P(m.id),disabled:C,children:"删除"})]})]},m.id)})}):null]})})]})}function Je(t,s){const j=localStorage.getItem(t);return j===null?s:j==="true"}function Ze(t){const s=new Date(t);if(Number.isNaN(s.getTime()))return"—";const j=String(s.getMonth()+1).padStart(2,"0"),d=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${j}-${d}`}function Ft(t){const{t:s,lang:j,setLang:d}=ie(),{onBack:p,onPublishDraft:B}=t,u=Qs(),[w,N]=a.useState(!1),g=a.useRef(!0);a.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),a.useEffect(()=>{u||N(!1)},[u]);const[k,T]=a.useState(()=>Je("mdocs.autoPublish",!1)),[S,c]=a.useState(()=>Je("mdocs.autoEdit",!0)),[x,o]=a.useState(!1),[h,I]=a.useState("general");function A(n){I(n),u&&N(!1)}const y=s(h==="general"?"general":h==="bookmarks"?"bookmarkTitle":h==="myDocuments"?"myDocuments":h==="domainManagement"?"domainManagement":h==="memberTemplates"?"memberTemplates":h==="agentConfig"?"agentConfig":"saveAndPublish"),[M,z]=a.useState([]),[F,v]=a.useState(!0),[P,C]=a.useState(null),[E,m]=a.useState(!1),[l,f]=a.useState(!1),[D,$]=a.useState(!1),[U,Z]=a.useState(!1),[Y,q]=a.useState(null),[_,b]=a.useState(!1),[K,W]=a.useState(!1),[X,ee]=a.useState(!1),[r,R]=a.useState(""),[O,ce]=a.useState(!1),[ue,oe]=a.useState(!1),[re,se]=a.useState(0),[te,he]=a.useState([]),[ye,pe]=a.useState(!1),[ae,be]=a.useState(""),[ge,Ne]=a.useState([]),[de,i]=a.useState(!1),[V,fe]=a.useState(""),[le,ts]=a.useState(0),[Me,Ee]=a.useState("1"),[Re,as]=a.useState(0),[ve,ns]=a.useState(""),[ke,is]=a.useState(""),[xe,cs]=a.useState(""),[ls,os]=a.useState(null),[rs,ds]=a.useState([]),we=20,[Le,ms]=a.useState([]),[us,Se]=a.useState(!1),[Ce,Fe]=a.useState(null),[De,ze]=a.useState(new Map);a.useEffect(()=>{localStorage.setItem("mdocs.autoPublish",String(k))},[k]),a.useEffect(()=>{localStorage.setItem("mdocs.autoEdit",String(S))},[S]),a.useEffect(()=>{h==="savePublish"&&Pe().then(n=>{g.current&&se(n.filter(L=>!L.published).length)})},[h]),a.useEffect(()=>{h==="bookmarks"&&hs(),h==="myDocuments"&&(me(),Qe().then(n=>{g.current&&ds(n)}).catch(()=>{}))},[h,ve,ke,xe]),a.useEffect(()=>{Be()},[]),a.useEffect(()=>{qe().then(n=>{g.current&&ms(n)}).catch(()=>{})},[]);const je=new Map(Le.map(n=>[n.domainId,n.domainName]));async function Be(){try{v(!0);const n=await et();if(!g.current)return;z(n)}catch{}finally{g.current&&v(!1)}}async function hs(){try{pe(!0);const n=await st();if(!g.current)return;he(n)}catch{}finally{g.current&&pe(!1)}}async function me(n=0){try{i(!0);const L=await tt({offset:n*we,limit:we,domainId:ve||void 0,creatorVisitorId:ke||void 0,groupBy:xe||void 0});if(!g.current)return;Ne(L.items),os(L.groups??null),as(L.total),ts(n),Ee(String(n+1))}catch{}finally{g.current&&i(!1)}}async function ps(n){try{await rt(n),he(L=>L.filter(H=>H.documentId!==n))}catch{}}function gs(){if(M.some(L=>!L.revoked)){f(!0);return}$e()}async function $e(){try{m(!0);const n=await mt();C({token:n.token,name:n.name}),await Be()}finally{m(!1)}}async function fs(){try{ee(!0);const n=await lt();q(n.recoveryCode)}finally{ee(!1)}}async function xs(n){n.preventDefault();const L=r.trim();if(!(L&&L.length<4))try{ce(!0),await ot(L),R(""),oe(!0),setTimeout(()=>oe(!1),3e3)}finally{ce(!1)}}async function js(n){Fe(n);try{const L=await dt(n),H=new Map;L.forEach(G=>{H.set(G.visitorId,G.permission)}),ze(H)}catch{ze(new Map)}Se(!0)}async function ys(n){if(Ce)try{const L=new Set(n.map(G=>G.visitorId)),H=new Set(De.keys());for(const G of H)L.has(G)||await ut(Ce,G);for(const G of n)await ht(Ce,G.visitorId,G.permission);await me()}finally{Se(!1),Fe(null)}}const Ke=te.filter(n=>{if(!ae.trim())return!0;const L=ae.toLowerCase();return(n.displayName||n.relativePath||"").toLowerCase().includes(L)||(n.ownerVisitorName||"").toLowerCase().includes(L)||(n.domainId||"").toLowerCase().includes(L)}),ne=Math.ceil(Re/we);return e.jsxs("div",{className:"mdocs-layout"+(u?" mdocs-layout--reader mdocs-layout--settings":""),children:[u&&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"+(u?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")})]}),u?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(nt,{size:18})}):null]}),e.jsxs("nav",{className:"mdocs-config-tree",children:[e.jsx("div",{className:"mdocs-config-item"+(h==="general"?" active":""),onClick:()=>A("general"),children:s("general")}),e.jsx("div",{className:"mdocs-config-item"+(h==="bookmarks"?" active":""),onClick:()=>A("bookmarks"),children:s("bookmarkTitle")}),e.jsx("div",{className:"mdocs-config-item"+(h==="myDocuments"?" active":""),onClick:()=>A("myDocuments"),children:s("myDocuments")}),e.jsx("div",{className:"mdocs-config-item"+(h==="domainManagement"?" active":""),onClick:()=>A("domainManagement"),children:s("domainManagement")}),e.jsx("div",{className:"mdocs-config-item"+(h==="memberTemplates"?" active":""),onClick:()=>A("memberTemplates"),children:s("memberTemplates")}),e.jsx("div",{className:"mdocs-config-item"+(h==="agentConfig"?" active":""),onClick:()=>A("agentConfig"),children:s("agentConfig")}),e.jsx("div",{className:"mdocs-config-item"+(h==="savePublish"?" active":""),onClick:()=>A("savePublish"),children:s("saveAndPublish")})]}),e.jsx("footer",{className:"mdocs-settings-sidebar-footer",onClick:p,children:s("backToDocs")})]}),e.jsxs("main",{className:"mdocs-main",children:[u?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(it,{size:18,strokeWidth:1.75})}),e.jsx("span",{className:"mdocs-settings-mobile-bar-title",children:y})]}):null,ct(),h==="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:j==="en"?"active":"",onClick:()=>d("en"),children:"EN"}),e.jsx("span",{children:"/"}),e.jsx("button",{type:"button",className:j==="zh"?"active":"",onClick:()=>d("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"+(S?" active":""),role:"switch","aria-checked":S,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")}),!F&&M.length>0&&e.jsx("span",{className:"mdocs-settings-item-desc",style:{marginTop:8,fontSize:"0.85em",opacity:.8},children:M.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:gs,disabled:E||F,children:E?"…":M.some(n=>!n.revoked)?s("cliTokenReset"):s("cliTokenCreate")})]}),P&&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:P.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(P.token),Z(!1),$(!0),window.setTimeout(()=>$(!1),2e3)}catch{$(!1),Z(!0),window.setTimeout(()=>Z(!1),3e3)}})()},children:s(D?"cliTokenCopied":"cliTokenCopy")}),e.jsx("button",{type:"button",onClick:()=>C(null),children:s("close")})]}),D&&e.jsxs("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:["✓ ",s("cliTokenCopied")]}),U&&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:fs,disabled:X,children:X?"…":"生成恢复码"})]}),Y&&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:Y})]}),e.jsxs("div",{className:"mdocs-settings-secret-result-actions",children:[e.jsx("button",{type:"button",className:"primary",onClick:()=>{(async()=>{try{await navigator.clipboard.writeText(Y),W(!1),b(!0),window.setTimeout(()=>b(!1),2e3)}catch{b(!1),W(!0),window.setTimeout(()=>W(!1),3e3)}})()},children:_?"已复制":"复制恢复码"}),e.jsx("button",{type:"button",onClick:()=>q(null),children:s("close")})]}),_&&e.jsx("div",{className:"mdocs-settings-copy-feedback mdocs-settings-copy-feedback--ok",role:"status",children:"✓ 已复制到剪贴板"}),K&&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:xs,style:{marginTop:12},children:[e.jsx("input",{type:"password",placeholder:"输入新密码(至少 4 位,留空则清除密码)",value:r,onChange:n=>R(n.target.value),minLength:0,style:{marginBottom:8}}),ue&&e.jsx("div",{style:{color:"#4caf50",marginBottom:8,fontSize:"0.875rem"},children:"✓ 密码设置成功"}),e.jsx("button",{type:"submit",className:"secondary",disabled:O,children:O?"设置中…":"保存密码"})]})]})]})]}):h==="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:ae,onChange:n=>be(n.target.value)}),ye?e.jsx("div",{style:{textAlign:"center",padding:"40px 0"},children:s("loading")}):e.jsx(e.Fragment,{children:Ke.length===0?e.jsx("div",{style:{textAlign:"center",padding:"40px 0",opacity:.6},children:s(ae?"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:Ke.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{cursor:"pointer",fontWeight:500},onClick:()=>t.onOpenDocument(n.documentId),children:n.displayName||n.relativePath||"Untitled"}),e.jsx("td",{children:n.isDeleted?e.jsx("span",{style:{opacity:.5,fontStyle:"italic"},children:"已删除"}):je.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:()=>ps(n.documentId),children:s("bookmarkRemove")})})]},n.documentId))})]})})})]})]}):h==="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(xt,{size:16,strokeWidth:2,"aria-hidden":"true"}),e.jsx("input",{type:"text",placeholder:"搜索文章…",value:V,onChange:n=>fe(n.target.value)})]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ve,"aria-label":s("myDocumentsFilterDomain"),onChange:n=>ns(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllDomains")}),Le.map(n=>e.jsx("option",{value:n.domainId,children:je.get(n.domainId)||n.domainName},n.domainId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:ke,"aria-label":s("myDocumentsFilterCreator"),onChange:n=>is(n.target.value),children:[e.jsx("option",{value:"",children:s("myDocumentsFilterAllCreators")}),rs.map(n=>e.jsx("option",{value:n.visitorId,children:n.visitorName},n.visitorId))]}),e.jsxs("select",{className:"mdocs-my-docs-select",value:xe,"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")})]})]}),de?e.jsx("div",{className:"mdocs-my-docs-empty",children:s("loading")}):e.jsxs(e.Fragment,{children:[ge.length===0?e.jsx("div",{className:"mdocs-my-docs-empty",children:s(V?"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:(ls??[{key:"",items:ge}]).flatMap(n=>{var G;const L=n.key?e.jsx("tr",{className:"mdocs-my-docs-group",children:e.jsx("td",{colSpan:6,children:xe==="domain"?je.get(n.key)||n.key:((G=n.items[0])==null?void 0:G.creatorName)||n.key})},`group-${n.key}`):null,H=n.items.map(J=>e.jsxs("tr",{children:[e.jsx("td",{className:"mdocs-my-docs-title",onClick:()=>t.onOpenDocument(J.documentId),children:J.displayName||J.relativePath||"Untitled"}),e.jsx("td",{children:je.get(J.domainId||"")||J.domainId||"—"}),e.jsx("td",{children:J.creatorName||J.creatorVisitorId||"—"}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.updatedAt)}),e.jsx("td",{className:"mdocs-my-docs-date",children:Ze(J.createdAt)}),e.jsxs("td",{className:"mdocs-my-docs-actions",children:[e.jsx("button",{type:"button",className:"ghost small",onClick:()=>js(J.documentId),children:s("docInfoInviteMember")}),e.jsx("button",{type:"button",className:"primary small",onClick:()=>t.onOpenDocument(J.documentId),children:s("bookmarkOpen")})]})]},J.documentId));return L?[L,...H]:H})})]})}),e.jsxs("div",{className:"mdocs-my-docs-footer",children:[e.jsx("span",{className:"mdocs-settings-page-info",children:s("myDocumentsPageInfo",{current:String(ne>0?le+1:0),total:String(ne),count:String(Re)})}),ne>1&&e.jsxs("form",{className:"mdocs-my-docs-jump",onSubmit:n=>{n.preventDefault();const L=Number.parseInt(Me,10);if(!Number.isFinite(L))return;const H=Math.min(Math.max(L,1),ne)-1;H!==le&&me(H)},children:[e.jsx("span",{children:s("myDocumentsJumpTo")}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,max:ne,"aria-label":s("myDocumentsJumpTo"),value:Me,onChange:n=>Ee(n.target.value)}),e.jsx("button",{type:"submit",className:"secondary small",children:s("myDocumentsJump")})]}),ne>1&&e.jsxs("div",{className:"mdocs-settings-pagination",children:[e.jsx("button",{type:"button",className:"secondary small",disabled:le<=0,onClick:()=>me(le-1),children:s("myDocumentsPrev")}),e.jsx("button",{type:"button",className:"secondary small",disabled:le>=ne-1,onClick:()=>me(le+1),children:s("myDocumentsNext")})]})]})]})]})]}):h==="domainManagement"?e.jsx(Nt,{}):h==="memberTemplates"?e.jsx(vt,{}):h==="agentConfig"?e.jsxs("div",{className:"mdocs-settings",children:[e.jsx(Ct,{}),e.jsx(It,{})]}):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:p,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"+(k?" active":""),role:"switch","aria-checked":k,onClick:()=>T(n=>!n),children:e.jsx("span",{className:"mdocs-toggle-knob"})})]})}),re>0?e.jsxs("button",{className:"mdocs-settings-card mdocs-settings-draft-link",onClick:()=>o(!0),children:[e.jsxs("span",{className:"mdocs-settings-draft-link-text",children:["📄 ",s("viewDrafts")," (",re,")"]}),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")})})]})]}),x&&e.jsx(yt,{onPublish:B,onClose:()=>o(!1),onCountChange:se,onRecover:t.onRecoverDraft})]}),l&&e.jsx(es,{title:s("cliToken"),message:s("cliTokenResetConfirm"),confirmLabel:s("cliTokenReset"),cancelLabel:s("cancel"),busy:E,onConfirm:()=>{f(!1),$e()},onCancel:()=>f(!1)}),e.jsx(ss,{open:us,title:s("docInfoInviteMember"),initialSelectedIds:[...De.keys()],initialPermissions:De,templates:[],showPermissionSelect:!0,permissionOptions:[{value:"read",label:s("invitePermissionRead")},{value:"edit",label:s("invitePermissionEdit")}],onClose:()=>Se(!1),onConfirm:n=>{ys(n)}})]})}export{Ft as SettingsPage};
@@ -1,4 +1,4 @@
1
- import{n as t,C as _}from"./index-vbUbFD-2.js";import{r as u,j as r}from"./react-vendor-BuABiQkA.js";import{F as C,G as v,L as N,H as c,J as l,K as L,M as j,q as z,N as H,P as $}from"./react-DCTIdd3e.js";import{z as f,V as g}from"./editor-CL03se2B.js";/**
1
+ import{o as t,C as _}from"./index-OmOf_og0.js";import{r as u,j as r}from"./react-vendor-BuABiQkA.js";import{F as C,G as v,L as N,H as c,J as l,K as L,M as j,q as z,N as H,P as $}from"./react-CI5PDFXT.js";import{z as f,V as g}from"./editor-CL03se2B.js";/**
2
2
  * @license lucide-react v0.562.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r,j as e}from"./react-vendor-BuABiQkA.js";import{b as G,B as ee,f as se,w as z}from"./index-vbUbFD-2.js";function ie({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=G(),w=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):w.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:te(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(ie,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function ne(v){var U;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=G(),w=r.useRef(i);w.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[P,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,F]=r.useState(""),[C,A]=r.useState(""),[M,B]=r.useState(!1),$=r.useRef(null),[K,W]=r.useState(!1),[q,I]=r.useState(null),D=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),H=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),F(""),A(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(w.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||B(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of P){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=H.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,P,H,O,i]),X=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[C,p,m]);async function _(){I(null),W(!0);try{if(u){const s=[...P].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...P].sort();await o(s)}j()}catch(s){I(z(i,s))}finally{W(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),D.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:$,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>B(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:C?(U=D.find(s=>String(s.id)===C))==null?void 0:U.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:D.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{A(String(s.id)),B(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},children:i("visitorPickerApplyTemplate")})]})}),q&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:q}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:F,selectedIds:P,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
1
+ import{r,j as e}from"./react-vendor-BuABiQkA.js";import{c as G,H as ee,f as se,y as z}from"./index-OmOf_og0.js";function ie({options:v,value:a,onChange:b}){const[d,f]=r.useState(!1),y=r.useRef(null),x=r.useRef(null),p=v.find(o=>o.value===a);r.useEffect(()=>{if(!d)return;const o=u=>{var N,k;!((N=y.current)!=null&&N.contains(u.target))&&!((k=x.current)!=null&&k.contains(u.target))&&f(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[d]),r.useEffect(()=>{if(!d)return;const o=u=>{var N;u.key==="Escape"&&(f(!1),(N=y.current)==null||N.focus())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[d]);function j(o){b(o),f(!1)}return e.jsxs("div",{className:"mdocs-mini-select",style:{position:"relative"},children:[e.jsxs("button",{ref:y,type:"button",className:"mdocs-mini-select-trigger","aria-expanded":d,"aria-haspopup":"listbox",onClick:()=>f(o=>!o),children:[e.jsx("span",{children:p==null?void 0:p.label}),e.jsx("svg",{className:"mdocs-mini-select-chevron"+(d?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),d&&e.jsx("div",{ref:x,className:"mdocs-mini-select-menu card",role:"listbox",children:v.map(o=>e.jsx("button",{type:"button",className:"mdocs-mini-select-option"+(o.value===a?" active":""),role:"option","aria-selected":o.value===a,onClick:()=>j(o.value),children:o.label},o.value))})]})}function te(v){return v.length<=6?v:`${v.slice(0,6)}…`}function re(v){const{visitors:a,loadState:b,searchFilter:d,onSearchChange:f,selectedIds:y,onToggle:x,selectedRows:p,lockedIds:j=new Set,myVisitorId:o,showPermissionSelect:u=!1,permissionOptions:N=[],onPermissionChange:k}=v,{t:i}=G(),P=r.useMemo(()=>{const t=d.trim().toLowerCase();let g=t?a.filter(m=>m.visitorName.toLowerCase().includes(t)||m.visitorId.toLowerCase().includes(t)):a;return o&&(g=[...g].sort((m,R)=>m.visitorId===o?-1:R.visitorId===o?1:0)),g},[a,d,o]);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"search",className:"mdocs-visitor-picker-search",placeholder:i("visitorPickerSearchPlaceholder"),value:d,onChange:t=>f(t.target.value),disabled:b!=="ok"}),b==="loading"&&e.jsx("div",{className:"mdocs-visitor-picker-loading",children:i("loading")}),b==="err"&&e.jsx("div",{className:"mdocs-visitor-picker-error",children:i("visitorPickerLoadError")}),b==="ok"&&e.jsxs("div",{className:"mdocs-visitor-picker-columns",children:[e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnAll")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdShort")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col",children:i("visitorPickerColPick")})]})}),e.jsx("tbody",{children:P.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"mdocs-visitor-picker-empty-cell",children:a.length===0?i("visitorPickerEmptyDirectory"):i("domainNoMatch")})}):P.map(t=>{const g=j.has(t.visitorId),m=y.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-short",children:te(t.visitorId)})}),e.jsxs("td",{children:[t.visitorName,t.visitorId===o&&e.jsx("span",{className:"mdocs-visitor-picker-self-marker",children:i("visitorPickerSelfMarker")})]}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:e.jsx("input",{type:"checkbox",checked:m,disabled:g,onChange:()=>x(t.visitorId),"aria-label":t.visitorName})})]},t.visitorId)})})]})})]}),e.jsxs("div",{className:"mdocs-visitor-picker-col",children:[e.jsx("h3",{className:"mdocs-visitor-picker-col-title",children:i("visitorPickerColumnSelected")}),e.jsx("div",{className:"mdocs-visitor-picker-table-wrap",children:e.jsxs("table",{className:"mdocs-visitor-picker-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:i("visitorPickerColIdFull")}),e.jsx("th",{scope:"col",children:i("visitorPickerColName")}),u&&e.jsx("th",{scope:"col",children:i("permissionLabel")}),e.jsx("th",{scope:"col",className:"mdocs-visitor-picker-check-col"})]})}),e.jsx("tbody",{children:p.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:u?4:3,className:"mdocs-visitor-picker-empty-cell",children:i("visitorPickerNoSelection")})}):p.map(t=>{const g=j.has(t.visitorId);return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{className:"mdocs-visitor-picker-id-full",children:t.visitorId})}),e.jsx("td",{className:t.muted?"mdocs-visitor-picker-name-muted":void 0,children:t.name}),u&&e.jsx("td",{children:e.jsx(ie,{options:N,value:t.permission??"read",onChange:m=>k==null?void 0:k(t.visitorId,m)})}),e.jsx("td",{className:"mdocs-visitor-picker-check-col",children:g?e.jsx("span",{className:"mdocs-visitor-picker-locked",title:i("visitorPickerLockedHint"),children:"—"}):e.jsx("button",{type:"button",className:"mdocs-visitor-picker-remove",onClick:()=>x(t.visitorId),"aria-label":i("visitorPickerRemove"),children:"×"})})]},t.visitorId)})})]})})]})]})]})}function ne(v){var U;const{open:a,title:b,initialSelectedIds:d,lockedIds:f=[],seedMembers:y,excludeTemplateId:x,templates:p,onClose:j,onConfirm:o,showPermissionSelect:u=!1,permissionOptions:N=[],initialPermissions:k}=v,{t:i}=G(),P=r.useRef(i);P.current=i;const t=r.useMemo(()=>new Set(f),[f]),g=ee(),[m,R]=r.useState([]),[E,T]=r.useState("idle"),[w,V]=r.useState(()=>new Set),[O,L]=r.useState(()=>new Map),[J,A]=r.useState(""),[C,B]=r.useState(""),[M,D]=r.useState(!1),$=r.useRef(null),[K,H]=r.useState(!1),[W,I]=r.useState(null),F=r.useMemo(()=>p.filter(s=>x==null||s.id!==x),[p,x]),q=r.useMemo(()=>new Map((y??[]).map(s=>[s.visitorId,s])),[y]);r.useEffect(()=>{a&&(V(new Set(d)),L(k?new Map(k):new Map),A(""),B(""),I(null))},[a,d,k]),r.useEffect(()=>{if(!a)return;let s=!1;return T("loading"),se().then(n=>{s||(R(n),T("ok"))}).catch(n=>{s||(T("err"),I(z(P.current,n)))}),()=>{s=!0}},[a]),r.useEffect(()=>{if(!M)return;const s=n=>{var c;(c=$.current)!=null&&c.contains(n.target)||D(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[M]);const Q=r.useMemo(()=>{const s=new Map(m.map(c=>[c.visitorId,c])),n=[];for(const c of w){const l=O.get(c),h=s.get(c);if(h){n.push({visitorId:c,name:h.visitorName,muted:!1,permission:l});continue}const S=q.get(c);if(S){S.missing?n.push({visitorId:c,name:i("visitorPickerMemberMissing"),muted:!0,permission:l}):S.disabled?n.push({visitorId:c,name:`${S.visitorName} · ${i("visitorPickerDisabledTag")}`,muted:!0,permission:l}):n.push({visitorId:c,name:S.visitorName,muted:!1,permission:l});continue}n.push({visitorId:c,name:i("visitorPickerUnknownVisitor"),muted:!0,permission:l})}return n.sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),n},[m,w,q,O,i]),X=r.useCallback(s=>{t.has(s)||V(n=>{const c=new Set(n);return c.has(s)?(c.delete(s),L(l=>{const h=new Map(l);return h.delete(s),h})):(c.add(s),L(l=>{const h=new Map(l);return h.set(s,"read"),h})),c})},[t]),Y=r.useCallback((s,n)=>{L(c=>{const l=new Map(c);return l.set(s,n),l})},[]),Z=r.useCallback(()=>{const s=Number(C);if(!Number.isInteger(s)||s<1)return;const n=p.find(l=>l.id===s);if(!n)return;const c=new Set(m.map(l=>l.visitorId));V(l=>{const h=new Set(l);for(const S of n.visitorIds)c.has(S)&&h.add(S);return h})},[C,p,m]);async function _(){I(null),H(!0);try{if(u){const s=[...w].sort().map(n=>({visitorId:n,permission:O.get(n)??"read"}));await o(s)}else{const s=[...w].sort();await o(s)}j()}catch(s){I(z(i,s))}finally{H(!1)}}return a?e.jsx("div",{className:"mdocs-visitor-picker-overlay",role:"presentation",onMouseDown:s=>s.target===s.currentTarget&&j(),children:e.jsxs("div",{className:"mdocs-visitor-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"mdocs-visitor-picker-title",children:[e.jsxs("header",{className:"mdocs-visitor-picker-header",children:[e.jsx("h2",{id:"mdocs-visitor-picker-title",className:"mdocs-visitor-picker-title",children:b}),e.jsx("button",{type:"button",className:"mdocs-visitor-picker-close",onClick:j,"aria-label":i("close"),children:"×"})]}),F.length>0&&e.jsx("div",{className:"mdocs-visitor-picker-toolbar",children:e.jsxs("div",{className:"mdocs-visitor-picker-template-bar",children:[e.jsxs("div",{ref:$,className:"mdocs-template-picker",children:[e.jsxs("button",{type:"button",className:"mdocs-template-picker-trigger",onClick:()=>D(s=>!s),disabled:E!=="ok","aria-haspopup":"listbox","aria-expanded":M,children:[e.jsx("span",{className:"mdocs-template-picker-text",children:C?(U=F.find(s=>String(s.id)===C))==null?void 0:U.displayName:i("visitorPickerPickTemplate")}),e.jsx("svg",{className:"mdocs-template-picker-chevron"+(M?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M1 1l4 4 4-4"})})]}),M&&e.jsx("div",{className:"mdocs-template-picker-menu card",role:"listbox",children:F.map(s=>e.jsx("button",{type:"button",className:"mdocs-template-picker-option"+(String(s.id)===C?" active":""),role:"option","aria-selected":String(s.id)===C,onClick:()=>{B(String(s.id)),D(!1)},children:s.displayName},s.id))})]}),e.jsx("button",{type:"button",className:"secondary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}if(!C){I(i("visitorPickerPickTemplate"));return}Z()},children:i("visitorPickerApplyTemplate")})]})}),W&&e.jsx("div",{className:"mdocs-visitor-picker-error",role:"alert",children:W}),e.jsx("div",{style:{padding:"8px 18px 12px"},children:e.jsx(re,{visitors:m,loadState:E,searchFilter:J,onSearchChange:A,selectedIds:w,onToggle:X,selectedRows:Q,lockedIds:t,myVisitorId:g,showPermissionSelect:u,permissionOptions:N,onPermissionChange:Y})}),e.jsxs("footer",{className:"mdocs-visitor-picker-footer",children:[e.jsx("button",{type:"button",className:"secondary",onClick:j,children:i("cancel")}),e.jsx("button",{type:"button",className:"primary",onClick:()=>{if(E!=="ok"){I(i("loading"));return}_()},children:i(K?"saving":"visitorPickerConfirm")})]})]})}):null}export{ie as M,ne as V,re as a};
@@ -1,6 +1,6 @@
1
- import{n as c}from"./index-vbUbFD-2.js";/**
1
+ import{o as c}from"./index-OmOf_og0.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 e=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],t=c("check",e);export{t as C};
6
+ */const o=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],t=c("check",o);export{t as C};
@@ -1,6 +1,6 @@
1
- import{n as c}from"./index-vbUbFD-2.js";/**
1
+ import{o as c}from"./index-OmOf_og0.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 e=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],t=c("copy",e);export{t as C};
6
+ */const o=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],t=c("copy",o);export{t as C};