1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AISettings-DgOyX3ES.js","assets/rolldown-runtime-BNNRdYrd.js","assets/react-vendor-BqQF_9sx.js","assets/circle-check-DnG-FWXS.js","assets/index-BQuIkJiK.js","assets/platform-capabilities-Bjt71t6g.js","assets/comparison-positioning-DbkxE00R.js","assets/context-sales-routes-BmilJBIO.js","assets/domain-plugin-catalog-lNnBMB9_.js","assets/plan-entitlements-D-LMrELD.js","assets/index-DNsQKlv_.css","assets/coins-BYLwsRmk.js","assets/cpu-DjT5vzRV.js","assets/database-CD_yMAa0.js","assets/external-link-C8Z7ByNT.js","assets/lock-keyhole--2C30OQC.js","assets/rotate-ccw-DMz9bzj3.js","assets/sparkles-HKQN2J4g.js","assets/unplug-B-zhkXLr.js","assets/settings-DI3JjUJK.js","assets/providers-DvRCRqAy.js","assets/intelligence-inputs-DojPSZCC.js","assets/local-inference-telemetry-scF-VAO0.js","assets/db-Dgd9zlNH.js","assets/storage-vendor-HZzIgsIR.js","assets/note-trust-Y3C29qxz.js","assets/semantic-links-BmhOhVmH.js","assets/semantic-note-DyLW_AZF.js","assets/task-utils-NfCAvgr9.js","assets/safe-frontmatter-BdZqnLng.js","assets/desktop-vault-binding-CVzuZYam.js","assets/source-manifest-Du9PY7Qn.js","assets/intelligence-content-hash-CEhOl9kW.js","assets/provider-order-tMtiQtoh.js","assets/StorePurchaseGate-BZuj3vrD.js","assets/ProactiveContextPanel-CbimsTRT.js","assets/chevron-down-CjjHcWdx.js","assets/chevron-right-B2R-Bih2.js","assets/link-2-BMM81MrN.js","assets/minimize-2-Bt4sJbXr.js","assets/activation-C0t7lDsy.js","assets/intelligence-index-lcTkolSu.js","assets/dexie-batching-DceqOBeq.js","assets/knowledge-model-DWJuoUAe.js","assets/attachments-0D7dZ0Hd.js","assets/cloud-sources-0yR8nunz.js","assets/metadata-sync-BmUSMven.js","assets/permanent-memory-BEUfT4yj.js","assets/onboarding-C3SgsVj9.js","assets/workspace-bootstrap-BlZDnksD.js","assets/client-BHTBpyJq.js","assets/resource-model-DDr_1WO_.js","assets/semantic-index-adapter-CD3Ru_NT.js","assets/GooglePlayBillingPanel-CRFPoojh.js","assets/HostedSourceSetup-CGj0TGUw.js","assets/DesktopVaultHosting-S02MyJXu.js","assets/arrow-down-to-line-BdVYxWpn.js","assets/folder-open-CtrjMwyb.js","assets/pause-j99UWzYo.js","assets/desktop-vault-Cj0Xjt1b.js","assets/desktop-update-preparation-AB-eezLX.js","assets/desktop-hosting-CJx3dS8E.js","assets/workspace-transition-BqM1MbBl.js"])))=>i.map(i=>d[i]); 2import{o as Ba}from"./rolldown-runtime-BNNRdYrd.js";import{_ as Ge,b as Ha,f as Ga,g as Va,r as qa,s as Wa}from"./react-vendor-BqQF_9sx.js";import{t as Ka}from"./brain-circuit-DIfZI1Zl.js";import{t as Qa}from"./calendar-clock-BclsjRiR.js";import{t as Ya}from"./check--u4h0CxO.js";import{t as Ae}from"./chevron-right-B2R-Bih2.js";import{t as ta}from"./circle-check-DnG-FWXS.js";import{t as Ja}from"./circle-x-CJEg-f7G.js";import{t as Za}from"./coins-BYLwsRmk.js";import{t as Xa}from"./copy-DelRPOUu.js";import{t as pt}from"./credit-card-DDqxK5zk.js";import{t as es}from"./download-Bzen7iqR.js";import{t as Te}from"./external-link-C8Z7ByNT.js";import{t as ts}from"./eye-Covjisdq.js";import{t as as}from"./file-plus-corner-DwBFRnKu.js";import{t as Rt}from"./folder-open-CtrjMwyb.js";import{t as It}from"./folder-D5YqJ1gP.js";import{t as _t}from"./gauge-CmTqSGr8.js";import{t as aa}from"./hard-drive-Djz7LdUh.js";import{t as ss}from"./inbox-HnW1N_fQ.js";import{t as ut}from"./link-2-BMM81MrN.js";import{t as ns}from"./lock-CzRWSzH0.js";import{t as rs}from"./message-square-text-ClE_ZpzB.js";import{t as it}from"./plus-C2wgNVCw.js";import{t as os}from"./rotate-ccw-clock-CD7vCvcS.js";import{t as ls}from"./rotate-ccw-DMz9bzj3.js";import{t as is}from"./save-DmK8ZpsA.js";import{t as cs}from"./search-C6sOW_II.js";import{t as ds}from"./shield-alert-DZGzjTOO.js";import{t as ps}from"./shield-CxcTmNXe.js";import{t as us}from"./square-check-big-DaMx7SNx.js";import{t as xs}from"./square-D53yantK.js";import{t as ms}from"./terminal-T7C71S_a.js";import{t as Me}from"./trash-Dc9VhwyJ.js";import{t as sa}from"./triangle-alert-DLjvSumf.js";import{t as hs}from"./unplug-B-zhkXLr.js";import{a as Le,c as z,i as Xe,l as Ft,s as bs,t as et,u as gs}from"./plan-entitlements-D-LMrELD.js";import{$t as ge,Bt as xt,D as fs,Dt as ys,Ft as na,Ht as Pe,I as Ot,It as Ce,L as Q,Lt as Se,O as vs,U as Ut,V as ce,Y as we,Z as js,Zt as ws,_t as Ns,dt as ks,et as zt,i as ra,lt as Cs,n as Ss,q as Ps,r as Es,t as As,tt as Ls,zt as Re}from"./index-BQuIkJiK.js";import{r as $s}from"./db-Dgd9zlNH.js";import{_ as $e,d as Ds,f as Ts,g as Bt,h as tt,i as at,l as oe,p as Ms,u as Rs,v as Ht}from"./cloud-sources-0yR8nunz.js";import{_ as Is,a as Gt,c as _s,f as Fs,l as Os,p as Us,s as zs,y as Bs}from"./attachments-0D7dZ0Hd.js";import"./AuthContext-DMnfLAt3.js";import{n as Hs,t as Gs}from"./StorePurchaseGate-BZuj3vrD.js";import{c as Vt,d as Z,i as Vs,l as qs,r as st,s as Ws}from"./sync-health-D3t9OuhN.js";import{t as qt}from"./ContextualHelpTooltip-AM2aubqn.js";import{t as Ks}from"./FeedbackDialog-UYDzWNCa.js";import{r as Qs}from"./noteExport-BrLLFL-D.js";import{t as Ys}
2from"./workspace-permissions-DneGli5K.js";import{n as Js,r as Zs}from"./settings-T1AcS8Fx.js";import{a as Xs,c as ct,d as Ve,i as oa,m as en,n as la,o as ia,p as tn,r as an,t as ca}from"./connections-client-B_gh9b7h.js";import{a as sn,cancelSourceSync as dt,i as nn,n as rn,o as he,parseGitHubRepository as on,queueVaultEncryptionMigration as ln,r as cn,resumePendingNoteHydrations as dn,syncSourceNow as nt,t as pn,testCloudConnection as un,testGitHubRepository as xn}from"./sync-manager-Vopw2-a9.js";import{i as mn,n as hn,r as bn,t as gn}from"./persistent-storage-UFhfykrL.js";import{i as fn}from"./domain-vault-assignments-DDfLFsn7.js";import{configurePhasoricExtensionPairingToken as yn,configuredPhasoricExtensionPairingToken as vn,n as jn,synchronizePhasoricExtension as wn,t as Nn}from"./extension-sync-DhSi1tzj.js";import{t as kn}from"./workspace-id-qCj709rn.js";import{n as Wt}from"./lifecycle-email-DWA2aegP.js";import{getWorkspaceMigrationState as Cn,runWorkspaceMigration as Sn}from"./workspace-migration-BWOmUle7.js";import{n as ze,t as Kt}from"./vaults-B773oxAt.js";import{t as Pn}from"./LegacyWorkspaceCleanupPanel-BuvI-HTe.js";var da={name:"file-cog",size:24,node:[["path",{d:"M15 8a1 1 0 0 1-1-1V2a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8z",key:"1ckgky"}],["path",{d:"M20 8v12a2 2 0 0 1-2 2h-4.182",key:"1726p0"}],["path",{d:"m3.305 19.53.923-.382",key:"ao1pio"}],["path",{d:"M4 10.592V4a2 2 0 0 1 2-2h8",key:"1foop0"}],["path",{d:"m4.228 16.852-.924-.383",key:"1fv9zy"}],["path",{d:"m5.852 15.228-.383-.923",key:"1a9hc2"}],["path",{d:"m5.852 20.772-.383.924",key:"1sh9ke"}],["path",{d:"m8.148 15.228.383-.923",key:"4yu6lf"}],["path",{d:"m8.53 21.696-.382-.924",key:"18b0s9"}],["path",{d:"m9.773 16.852.922-.383",key:"ti6xop"}],["path",{d:"m9.773 19.148.922.383",key:"rws47d"}],["circle",{cx:"7",cy:"18",r:"3",key:"lvkj7j"}]],aliases:["file-cog-2"]};da.node;var En=Pe(da),pa={name:"folder-git-2",size:24,node:[["path",{d:"M18 19a5 5 0 0 1-5-5v8",key:"sz5oeg"}],["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]};pa.node;var An=Pe(pa),ua={name:"key",size:24,node:[["path",{d:"m2 21 9.6-9.6",key:"9l79m3"}],["path",{d:"m7.5 15.5 2.3 2.3a1 1 0 0 1 0 1.4l-2.1 2.1a1 1 0 0 1-1.4 0L4 19",key:"fw8biw"}],["circle",{cx:"15.5",cy:"7.5",r:"5.5",key:"4wxmhb"}]]};ua.node;var Ln=Pe(ua),xa={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};xa.node;var $n=Pe(xa),ma={name:"user-minus",size:24,node:[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]};ma.node;var Dn=Pe(ma),ha={name:"user",size:24,node:[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]};ha.node;var Tn=Pe(ha),o=Ba(Ha(),1),e=qa();function q({label:a,description:r,checked:l,onChange:s}){return(0,e.jsxs)("label",{className:"flex items-center justify-between gap-5 border-b border-basalt-800/70 py-4 last:border-b-0",children:[(0,e.jsxs)("span",{children:[(0,e.jsx)("strong",{className:"block text-xs font-medium text-white",children:a}),(0,e.jsx)("span",{className:"mt-1 block text-[10px] leading-4 text-basalt-500",children:r})]}),(0,e.jsx)("input",{type:"checkbox",checked:l,onChange:m=>s(m.target.checked),className:"h-4 w-4 shrink-0 accent-cyan-300"})]})}function Y({label:a,description:r,value:l,onChange:s,children:m}){return(0,e.jsxs)("label",{className:"flex flex-col gap-3 border-b border-basalt-800/70 py-4 last:border-b-0 sm:flex-row sm:items-center sm:justify-between",children:[(0,e.jsxs)("span",{children:[(0,e.jsx)("strong",{className:"block text-xs font-medium text-white",children:a}),(0,e.jsx)("span",{className:"mt-1 block text-[10px] leading-4 text-basalt-500",children:r})]}
2),(0,e.jsx)("select",{value:l,onChange:j=>s(j.target.value),className:"min-w-40 rounded-lg border border-basalt-700 bg-basalt-950 px-3 py-2 text-xs text-white outline-none focus:border-accent-cyan/60",children:m})]})}function ke({title:a,children:r}){return(0,e.jsxs)("section",{children:[(0,e.jsx)("h3",{className:"mb-2 text-[10px] font-bold uppercase tracking-[0.16em] text-basalt-500",children:a}),(0,e.jsx)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 px-4",children:r})]})}function Mn({settings:a,onChange:r}){const l=(s,m)=>r({...a,[s]:m});return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)(ke,{title:"Workspace behavior",children:[(0,e.jsx)(q,{label:"Always focus new tabs",description:"Switch to a note immediately when it opens in a new tab.",checked:a.focusNewTabs,onChange:s=>l("focusNewTabs",s)}),(0,e.jsxs)(Y,{label:"Default view for new tabs",description:"Choose whether new note tabs begin in an editing or reading view.",value:a.defaultView,onChange:s=>l("defaultView",s),children:[(0,e.jsx)("option",{value:"editing",children:"Editing view"}),(0,e.jsx)("option",{value:"reading",children:"Reading view"})]}),(0,e.jsxs)(Y,{label:"Default editing mode",description:"Live Preview enriches Markdown while Source mode shows every character.",value:a.defaultEditingMode,onChange:s=>l("defaultEditingMode",s),children:[(0,e.jsx)("option",{value:"live",children:"Live Preview"}),(0,e.jsx)("option",{value:"source",children:"Source mode"})]}),(0,e.jsx)(q,{label:"Show editing mode in status bar",description:"Display the three-way mode switch at the bottom of notes.",checked:a.showEditingModeStatus,onChange:s=>l("showEditingModeStatus",s)})]}),(0,e.jsxs)(ke,{title:"Display",children:[(0,e.jsxs)(Y,{label:"Font Size",description:"Adjust text sizing across the entire application for visual comfort.",value:a.fontSize||"14",onChange:s=>l("fontSize",s),children:[(0,e.jsx)("option",{value:"12",children:"Small (12px)"}),(0,e.jsx)("option",{value:"14",children:"Medium (14px - Default)"}),(0,e.jsx)("option",{value:"16",children:"Large (16px - Older Eyes)"}),(0,e.jsx)("option",{value:"18",children:"Extra Large (18px)"})]}),(0,e.jsxs)(Y,{label:"Font Family",description:"Choose typography style for notes and workspace UI.",value:a.fontFamily||"system",onCh
2ange:s=>l("fontFamily",s),children:[(0,e.jsx)("option",{value:"system",children:"System Sans (Inter)"}),(0,e.jsx)("option",{value:"outfit",children:"Modern Outfit"}),(0,e.jsx)("option",{value:"serif",children:"Serif (Merriweather)"}),(0,e.jsx)("option",{value:"mono",children:"Monospace (Fira Code)"})]}),(0,e.jsxs)(Y,{label:"Display Density & Spacing",description:"Adjust container padding and line density.",value:a.displayDensity||"comfortable",onChange:s=>l("displayDensity",s),children:[(0,e.jsx)("option",{value:"compact",children:"Compact (Tighter Spacing)"}),(0,e.jsx)("option",{value:"comfortable",children:"Comfortable (Default)"}),(0,e.jsx)("option",{value:"spacious",children:"Spacious (Relaxed)"})]}),(0,e.jsx)(q,{label:"Readable line length",description:"Constrain long passages to a comfortable reading width.",checked:a.readableLineLength,onChange:s=>l("readableLineLength",s)}),(0,e.jsx)(q,{label:"Strict line breaks",description:"Render a visible break for each single Markdown line break in Reading mode.",checked:a.strictLineBreaks,onChange:s=>l("strictLineBreaks",s)}),(0,e.jsxs)(Y,{label:"Properties in document",description:"Show note properties as a panel, raw frontmatter, or hide them.",value:a.propertiesDisplay,onChange:s=>l("propertiesDisplay",s),children:[(0,e.jsx)("option",{value:"visible",children:"Visible"}),(0,e.jsx)("option",{value:"source",children:"Source"}),(0,e.jsx)("option",{value:"hidden",children:"Hidden"})]}),(0,e.jsx)(q,{label:"Fold headings",description:"Show CodeMirror folding controls for Markdown sections.",checked:a.foldHeadings,onChange:s=>l("foldHeadings",s)}),(0,e.jsx)(q,{label:"Fold indent",description:"Enable folding controls for indented blocks.",checked:a.foldIndent,onChange:s=>l("foldIndent",s)}),(0,e.jsx)(q,{label:"Line numbers",description:"Show line numbers in the editor gutter.",checked:a.lineNumbers,onChange:s=>l("lineNumbers",s)}),(0,e.jsx)(q,{label:"Indentation guides",description:"Show subtle vertical guides for nested content.",checked:a.indentationGuides,onChange:s=>l("indentationGuides",s)})]}),(0,e.jsxs)(ke,{title:"Behavior",children:[(0,e.jsx)(q,{label:"Spellcheck",description:"Use the browser spellchecker while editing.",checked:a.spellcheck,onChange:s=>l("spellcheck",s)}),(0,e.jsxs)(Y,{label:"Spellcheck language",description:"Language hint passed to the browser spellchecker.",value:a.spellcheckLanguage,onChange:s=>l("spellcheckLanguage",s),children:[(0,e.jsx)("option",{value:"en-US",children:"English (United States)"}),(0,e.jsx)("option",{value:"en-GB",children:"English (United Kingdom)"}),(0,e.jsx)("option",{value:"es",children:"Spanish"}),(0,e.jsx)("option",{value:"fr",children:"French"}),(0,e.jsx)("option",{value:"de",children:"German"})]}),(0,e.jsx)(q,{label:"Auto-pair brackets",description:"Complete brackets and quotes automatically.",checked:a.autoPairBrackets,onChange:s=>l("autoPairBrackets",s)}),(0,e.jsx)(q,{label:"Auto-pair Markdown syntax",description:"Pair emphasis, inline code, and other Markdown markers.",checked:a.autoPairMarkdown,onChange:s=>l("autoPairMarkdown",s)}),(0,e.jsx)(q,{label:"Smart lists",description:"Continue list indentation and markers on new lines.",checked:a.smartLists,onChange:s=>l("smartLists",s)}),(0,e.jsx)(q,{label:"Indent using tabs",description:"Insert tab characters instead of spaces when pressing Tab.",checked:a.indentWithTabs,onChange:s=>l("indentWithTabs",s)}),(0,e.jsxs)(Y,{label:"Indent visual width",description:"Number of spaces represented by one indentation level.",value:String(a.indentWidth),onChange:s=>l("indentWidth",Number(s)),children:[(0,e.jsx)("option",{value:"2",children:"2 spaces"}),(0,e.jsx)("option",{value:"4",children:"4 spaces"}),(0,e.jsx)("option",{value:"8",children:"8 spaces"})]}),(0,e.jsx)(q,{label:"Convert pasted HTML to Markdown",description:"Convert rich web content to portable Markdown when pasted.",checked:a.pasteHtmlToMarkdown,onChange:s=>l("pasteHtmlToMarkdown",s)}),(0,e.jsxs)(Y,{label:"Keymap preset",description:"Choose standard, Vim, Emacs-inspired, or Sublime-inspired editor bindings.",value:a.keymapPreset||(a.vimMode?"vim":"standard"),onChange:s=>r({...a,keymapPreset:s,vimMode:s==="vim"}),children:[(0,e.jsx)("option",{value:"standard",children:"Standard"}),(0,e.jsx)("option",{value:"vim",children:"Vim"}),(0,e.jsx)("option",{value:"emacs",children:"Emacs-inspired"}),(0,e.jsx)("option",{value:"sublime",children:"Sublime Text-inspired"})]})]})]})}function Rn({settings:a,onChange:r}){const l=(s,m)=>r({...a,[s]:m});return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)(ke,{title:"Files",children:[(0,e.jsxs)(Y,{label:"Default file to open",description:"Choose the note shown when the workspace starts.",value:a.startupFile,onChange:s=>l("startupFile",s),children:[(0,e.jsx)("option",{value:"last",children:"Last opened"}),(0,e.jsx)("option",{value:"new",children:"New note"}),(0,e.jsx)("option",{value:"none",children:"No note"})]}),(0,e.jsxs)(Y,{label:"Files list sort",description:"Choose how notes are ordered within each folder.",value:a.fileSortBy,onChange:s=>l("fileSortBy",s),children:[(0,e.jsx)("option",{value:"modified",children:"Last modified"}),(0,e.jsx)("option",{value:"created",children:"Date created"}),(0,e.jsx)("option",{value:"alphabetical",children:"Alphabetical"})]}),(0,e.jsxs)(Y,{label:"Files list direction",description:"Set newest or Z-A first, or oldest or A-Z first.",value:a.fileSortDirection,onChange:s=>l("fileSortDirection",s),children:[(0,e.jsx)("option",{value:"desc",children:"Descending"}),(0,e.jsx)("option",{value:"asc",children:"Ascending"})]}),(0,e.jsxs)(Y,{label:"Default location for new notes",description:"Place notes in the current folder, vault root, or a configured folder.",value:a.newNoteLocation,onChange:s=>l("newNoteLocation",s),children:[(0,e.jsx)("option",{value:"current",children:"Current folder"}),(0,e.jsx)("option",{value:"vault",children:"Vault root"}),(0,e.jsx)("option",{value:"configured",children:"Folder specified below"})]}),a.newNoteLocation==="configured"&&(0,e.jsxs)("label",{className:"block border-b border-basalt-800/70 py-4 text-xs",children:[(0,e.jsx)("span",{className:"font-medium text-white",children:"New-note folder"}),(0,e.jsx)("input",{value:a.newNoteFolder,onChange:s=>l("newNoteFolder",s.target.value),placeholder:"Inbox/Notes",className:"mt-2 w-full rounded-lg border border-basalt-700 bg-basalt-950 px-3 py-2 text-xs outline-none focus:border-accent-cyan/60"})]}),(0,e.jsxs)(Y,{label:"Default location for attachments",description:"Keep attachments near their note or in a stable vault folder.",value:a.attachmentLocation,onChange:s=>l("attachmentLocation",s),children:[(0,e.jsx)("option",{value:"note-folder",children:"Same folder as current note"}),(0,e.jsx)("option",{value:"vault",children:"Vault root"}),(0,e.jsx)("option",{value:"configured",children:"Folder specified below"})]}),a.attachmentLocation==="configured"&&(0,e.jsxs)("label",{className:"block border-b border-basalt-800/70 py-4 text-xs",children:[(0,e.jsx)("span",{className:"font-medium text-white",children:"Attachment folder"}),(0,e.jsx)("input",{value:a.attachmentFolder,onChange:s=>l("attachmentFolder",s.target.value),placeholder:"Attachments",className:"mt-2 w-full rounded-lg border border-basalt-700 bg-basalt-950 px-3 py-2 text-xs outline-none focus:border-accent-cyan/60"})]})]}),(0,e.jsxs)(ke,{title:"Links",children:[(0,e.jsxs)(Y,{label:"New link format",description:"Choose how Phasoric generates internal note links.",value:a.linkFormat,onChange:s=>l("linkFormat",s),children:[(0,e.jsx)("option",{value:"shortest",children:"Shortest path when possible"}),(0,e.jsx)("option",{value:"relative",children:"Relative path"}),(0,e.jsx)("option",{value:"absolute",children:"Absolute vault path"})]}
2),(0,e.jsx)(q,{label:"Automatically update internal links",description:"Rewrite links when a file or folder is renamed or moved.",checked:a.updateInternalLinks,onChange:s=>l("updateInternalLinks",s)}),(0,e.jsx)(q,{label:"Use [[Wikilinks]]",description:"Generate portable Wikilinks instead of standard Markdown links.",checked:a.useWikiLinks,onChange:s=>l("useWikiLinks",s)}),(0,e.jsx)(q,{label:"Show all file types",description:"Include supported non-Markdown attachments in library search and navigation.",checked:a.showAllFileTypes,onChange:s=>l("showAllFileTypes",s)})]}),(0,e.jsxs)(ke,{title:"Trash",children:[(0,e.jsx)(q,{label:"Confirm before deleting files",description:"Ask before notes and folders are removed.",checked:a.confirmDelete,onChange:s=>l("confirmDelete",s)}),(0,e.jsxs)("p",{className:"border-b border-basalt-800/70 py-4 text-xs text-basalt-500",children:[(0,e.jsx)("span",{className:"block font-medium text-white",children:"Recover linked attachments"}),(0,e.jsx)("span",{className:"mt-1 block leading-5",children:"Attachments move into Phasoric Trash with their note and return to the original provider path when restored."})]}),(0,e.jsxs)(Y,{label:"Keep deleted notes",description:"Phasoric permanently removes Trash items after this period.",value:String(a.trashRetentionDays),onChange:s=>l("trashRetentionDays",Number(s)),children:[(0,e.jsx)("option",{value:"7",children:"7 days"}),(0,e.jsx)("option",{value:"14",children:"14 days"}),(0,e.jsx)("option",{value:"30",children:"30 days"})]})]})]})}function Qt({percent:a,danger:r=!1,warning:l=!1}){const s=r?"bg-red-400":l?"bg-amber-300":"bg-accent-cyan",m=Math.max(0,Math.min(100,Number(a)||0));return(0,e.jsx)("div",{className:"mt-3 h-1.5 overflow-hidden rounded-full bg-basalt-800",children:(0,e.jsx)("div",{className:`h-full rounded-full ${s}`,style:{width:`${m}%`}})})}function In({user:a}){const[r,l]=(0,o.useState)(null),[s,m]=(0,o.useState)(null),[j,p]=(0,o.useState)([]),[f,u]=(0,o.useState)(""),[E,c]=(0,o.useState)(""),[x,w]=(0,o.useState)(()=>gn()),[y,$]=(0,o.useState)(null),[v,I]=(0,o.useState)(null),[i,C]=(0,o.useState)(null),b=(0,o.useRef)(!1),[F,S]=(0,o.useState)([]),[M,N]=(0,o.useState)(!1),_=(0,o.useCallback)(async()=>{if(l(await Is()),!a?.localOnly)try{const[g,P]=await Promise.all([fetch("/api/usage",{credentials:"include"}),fetch("/api/attachments",{credentials:"include"})]);if(!g.ok)throw new Error((await g.json().catch(()=>({}))).error||"Unable to load hosted usage");m(await g.json()),P.ok&&p((await P.json()).attachments||[]),u("")}catch(g){u(g.message)}},[a?.localOnly]);(0,o.useEffect)(()=>{_()},[_]);const G=async g=>{if(!window.confirm(`Remove the hosted copy of ${g.name}? The local copy will not be deleted.`))return;const P=await fetch(`/api/attachments/${g.id}`,{method:"DELETE",credentials:"include"});if(!P.ok){const U=await P.json().catch(()=>({}));return u(U.error||"Unable to delete hosted attachment")}await Gt(g.local_attachment_id),S(U=>U.filter(J=>J!==g.id)),await _()},B=async()=>{try{const g=await hn();c(g?"Protected: the browser granted persistent storage for this vault.":"The browser did not grant persistent storage. Keep cloud or filesystem backups current."),await _()}catch{c("Persistent storage is unavailable in this browser. Keep cloud or filesystem backups current.")}},de=async g=>{const P=g.target.checked;if(w(P),mn(P),!P){c(r?.browserStoragePersisted?"Automatic requests are off. Browser-granted protection remains active until you change this site's storage permission in the browser.":"Automatic protection is off. You can still request protection manually.");return}try{const U=await bn();c(U?"Protected: the browser granted persistent storage for this vault.":"The browser did not grant persistent storage. Phasoric will wait before asking automatically again; you can retry below at any time."),await _()}catch{c("Persistent storage is unavailable in this browser. Keep cloud or filesystem backups current.")}},se=async()=>{b.current=!0,$({running:!0,downloaded:0,failed:0,remaining:0});const g=await Os({shouldContinue:()=>b.current,onProgress:P=>$({...P,running:!0})});b.current=!1,$({...g,running:!1,remaining:Math.max(0,g.total-g.downloaded-g.failed)}),await _()},ne=async()=>{try{u("Checking notes, history, Trash, captures, and research collections for attachment referencesâ¦");const g=await Us();I(g),u(g.length?`Found ${g.length} unused hosted ${g.length===1?"file":"files"} (${z(g.reduce((P,U)=>P+Number(U.size||0),0),1)}).`:"No unused hosted files were found.")}catch(g){u(g.message||"Unable to scan hosted attachments.")}},ie=async()=>
2{if(!v?.length)return;const g=v.reduce((P,U)=>P+Number(U.size||0),0);if(window.confirm(`Remove ${v.length} unused hosted files (${z(g,1)})? Local and provider copies will remain.`))try{u("Removing unused hosted copiesâ¦");const P=await _s(v.map(U=>U.id));I(null),await _(),u(`Removed ${P.deleted} unused hosted ${P.deleted===1?"copy":"copies"}${P.skipped?`; ${P.skipped} were referenced again and kept`:""}.`)}catch(P){u(`${P.message} Files that could not be confirmed deleted were kept for retry.`)}},k=async()=>{try{u("Checking local and provider-routed attachments for redundant hosted copiesâ¦");const g=await Fs();C(g),u(g.length?`Found ${g.length} redundant hosted ${g.length===1?"copy":"copies"} (${z(g.reduce((P,U)=>P+Number(U.size||0),0),1)}).`:"No removable redundant hosted copies were found.")}catch(g){u(g.message||"Unable to scan redundant hosted copies.")}},D=async()=>{if(!i?.length)return;const g=i.reduce((P,U)=>P+Number(U.size||0),0);if(window.confirm(`Remove ${i.length} redundant hosted copies (${z(g,1)})? Their local copies and any mapped provider copies will remain. Existing public shares that use these attachments may need to be updated.`))try{u("Removing redundant hosted copiesâ¦");const P=await zs(i.map(U=>U.id));C(null),await _(),u(`Removed ${P.deleted} redundant hosted ${P.deleted===1?"copy":"copies"}${P.skipped?`; ${P.skipped} still had pending provider writes and were kept`:""}.`)}catch(P){u(`${P.message} Copies that could not be confirmed deleted were kept for retry.`)}},V=[...j].sort((g,P)=>Number(P.size_bytes)-Number(g.size_bytes)).slice(0,20),X=F.length,Ee=V.filter(g=>F.includes(g.id)).reduce((g,P)=>g+Number(P.size_bytes||0),0),L=V.length>0&&V.every(g=>F.includes(g.id)),R=()=>{S(L?[]:V.map(g=>g.id))},te=g=>{S(P=>P.includes(g)?P.filter(U=>U!==g):[...P,g])},qe=async()=>{const g=V.filter(re=>F.includes(re.id));if(!g.length)return;const P=g.reduce((re,pe)=>re+Number(pe.size_bytes||0),0),U=g.length;if(!window.confirm(`Remove ${U} selected hosted ${U===1?"file":"files"} (${z(P,1)})? The local copies will not be deleted.`))return;N(!0),u(`Removing ${U} selected hosted ${U===1?"file":"files"}â¦`);let J=0,fe=0;for(const re of g)try{const pe=await fetch(`/api/attachments/${re.id}`,{method:"DELETE",credentials:"include"});pe.ok||pe.status===404?(await Gt(re.local_attachment_id),J+=1):fe+=1}catch{fe+=1}S(re=>re.filter(pe=>!g.some(We=>We.id===pe))),N(!1),await _(),fe>0?u(`Removed ${J} hosted ${J===1?"copy":"copies"}; ${fe} could not be deleted.`):u(`Removed ${J} selected hosted ${J===1?"copy":"copies"}.`)},ee=s?.hostedStorage,le=Bs(r||{});return(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-white",children:"Storage & plan usage"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] leading-4 text-basalt-500",children:"Local files do not count against your subscription, but they do use this browser's site-storage allowance. The browser controls that allowance and may adjust it as disk space changes."})]}),(0,e.jsx)("button",{onClick:_,className:"rounded-lg border border-basalt-700 p-2 text-basalt-400 hover:text-white","aria-label":"Refresh storage usage",children:(0,e.jsx)(Se,{size:13})})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,e.jsxs)("article",{className:`rounded-xl border bg-basalt-950/60 p-4 ${le.level==="critical"?"border-red-400/40":le.level==="warning"?"border-amber-300/30":"border-basalt-800"}`,children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold",children:[(0,e.jsx)(aa,{size:14,className:"text-emerald-300"}),"Local browser vault"]}),r?.browserQuotaBytes>0?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mt-3 text-xl font-semibold",children:[z(r.browserUsageBytes,1)," ",(0,e.jsx)("span",{className:"text-xs font-normal text-basalt-500",children:"used"})]}),(0,e.jsxs)("p",{className:"mt-1 text-[10px] text-basalt-400",children:[z(r.browserRemainingBytes,1)," remaining of approximately ",z(r.browserQuotaBytes,1)," (",r.browserUsagePercent.toFixed(1),"% used)"]}),(0,e.jsx)(Qt,{percent:r.browserUsagePercent,danger:le.level==="critical",warning:le.level==="warning"}),le.level!=="healthy"&&(0,e.jsxs)("p",{className:`mt-3 flex gap-2 text-[9px] leading-4 ${le.level==="critical"?"text-red-300":"text-amber-200"}`,children:[(0,e.jsx)(sa,{size:12,className:"mt-0.5 shrink-0"}),le.level==="critical"?"Local storage is nearly full. Pause large imports and free browser or disk space before continuing.":"Local storage is above 75%. Consider freeing browser or disk space before importing large attachments."]})]}):(0,e.jsx)("p",{className:"mt-3 text-[10px] leading-4 text-basalt-500",children:"This browser does not expose a storage quota estimate. Phasoric cannot calculate remaining local capacity here."}),(0,e.jsxs)("div",{className:"mt-3 border-t border-basalt-800 pt-3 text-[9px] leading-4 text-basalt-500",children:["Attachments use ",z(r?.attachmentBytes||0,1)," across ",r?.attachmentCount||0," files. Notes, indexes, history, and application data make up the rest."]}),(0,e.jsxs)("label",{className:"mt-3 flex items-start gap-2.5 rounded-lg border border-basalt-800 bg-basalt-950/50 p-3 text-left",children:[(0,e.jsx)("input",{type:"checkbox",checked:x,onChange:de,className:"mt-0.5 accent-cyan-300"}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-[10px] font-semibold text-basalt-200",children:"Automatically protect local data"}),(0,e.jsx)("small",{className:"mt-1 block text-[9px] leading-4 text-basalt-500",children:"On by default. Phasoric asks after the first local write, not while the workspace is loading."})]})]}),r?.browserStoragePersisted===!0?(0,e.jsxs)("p",{className:"mt-3 flex items-center gap-1.5 text-[9px] text-emerald-300",children:[(0,e.jsx)(Ce,{size:12}),"Protected from automatic storage eviction."]}):(0,e.jsx)("button",{type:"button",onClick:B,className:"mt-3 rounded-lg border border-basalt-700 px-3 py-2 text-[9px] font-semibold text-basalt-300 hover:border-basalt-500 hover:text-white",children:"Protect local data now"}),(0,e.jsx)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-600",children:"Turning automatic protection off prevents future requests. Browsers do not let sites revoke protection that was already granted; use the browser's site-data settings for that."}),E&&(0,e.jsx)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-500",children:E}),(0,e.jsxs)("div",{className:"mt-4 border-t border-basalt-800 pt-3",children:[(0,e.jsx)("div",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:"Remote attachments"}),(0,e.jsxs)("p",{className:"mt-1 text-[9px] leading-4 text-basalt-500",children:[r?.remoteAttachmentCount||0," remote files (",z(r?.remoteAttachmentBytes||0,1),") normally download when opened. Download them all only when you want a complete offline copy on this device."]}),(0,e.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[y?.running?(0,e.jsx)("button",{type:"button",onClick:()=>{b.current=!1},className:"rounded-lg border border-amber-300/25 px-3 py-2 text-[9px] font-semibold text-amber-200",children:"Stop safely"}):(0,e.jsx)("button",{type:"button",onClick:se,className:"rounded-lg border border-basalt-700 px-3 py-2 text-[9px] font-semibold text-basalt-300 hover:border-basalt-500 hover:text-white",children:"Download attachments to this device"}),y&&(0,e.jsxs)("span",{className:"text-[9px] text-basalt-500",children:[y.downloaded||0," downloaded · ",y.failed||0," failed",y.running?` · ${y.remaining||0} remaining`:y.pausedForQuota?" · paused before the 90% storage threshold":y.cancelled?" · stopped safely":""]})]})]})]}),(0,e.jsxs)("article",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-xs font-semibold",children:[(0,e.jsx)(xt,{size:14,className:"text-cyan-300"}),"Hosted storage"]}),a?.localOnly?(0,e.jsx)("p",{className:"mt-3 text-xs leading-5 text-basalt-500",children:"Sign in to use the Free plan's hosted attachment allowance."}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mt-3 text-xl font-semibold",children:[z(ee?.usedBytes||0,1)," ",(0,e.jsxs)("span",{className:"text-xs font-normal text-basalt-500",children:["of ",z(ee?.limitBytes||0)]})]}),(0,e.jsxs)("p",{className:"mt-1 text-[10px] text-basalt-500",children:[s?.plan?.shortName||a?.tier," · up to ",z(s?.plan?.maxHostedAttachmentBytes||0)," per file"]}),(0,e.jsxs)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-500",children:["Phasoric Hosted vault content counts here: ",z(ee?.contentBytes||0,1)," of Markdown/control files and ",z(ee?.attachmentBytes||0,1)," of attachments and hosted-only files. Vaults mapped to Dropbox, Google Drive, or GitHub use that provider instead and do not create a second Phasoric copy."]}),(0,e.jsx)(Qt,{percent:ee?.percent||0,danger:ee?.overLimit})]}),s&&!s.hostedStorageConfigured&&(0,e.jsx)("p",{className:"mt-3 rounded-lg border border-amber-400/20 bg-amber-400/5 p-2 text-[9px] leading-4 text-amber-200",children:"Phasoric Hosted attachment uploads are paused until BLOB_READ_WRITE_TOKEN is configured in production. Hosted Markdown, local files, and external-provider sync remain available."}),ee?.overLimit&&(0,e.jsxs)("p",{className:"mt-3 text-[9px] leading-4 text-red-300",children:["New hosted uploads are paused. Existing files remain accessible. Remove unneeded hosted files",ee.graceEndsAt?` before ${new Date(ee.graceEndsAt).toLocaleDateString()}`:"","."]}
2),!a?.localOnly&&(0,e.jsxs)("div",{className:"mt-4 border-t border-basalt-800 pt-3",children:[(0,e.jsx)("p",{className:"text-[9px] leading-4 text-basalt-500",children:"Remove hosted mirrors from local-only vaults or older provider duplicates after mapped writes complete. Phasoric Hosted vault files and files with pending provider writes are excluded."}),(0,e.jsxs)("div",{className:"mt-2 flex flex-wrap gap-2",children:[(0,e.jsx)("button",{type:"button",onClick:k,className:"rounded-lg border border-basalt-700 px-3 py-2 text-[9px] font-semibold text-basalt-300 hover:border-basalt-500 hover:text-white",children:"Find redundant hosted copies"}),i?.length>0&&(0,e.jsxs)("button",{type:"button",onClick:D,className:"rounded-lg border border-red-400/25 px-3 py-2 text-[9px] font-semibold text-red-200 hover:bg-red-400/10",children:["Remove ",i.length," redundant copies"]})]}),(0,e.jsx)("p",{className:"mt-4 border-t border-basalt-800 pt-3 text-[9px] leading-4 text-basalt-500",children:"Find hosted copies no longer referenced by notes, note history, Trash, captures, or research collections. Local and connected-provider copies are preserved."}),(0,e.jsxs)("div",{className:"mt-2 flex flex-wrap gap-2",children:[(0,e.jsx)("button",{type:"button",onClick:ne,className:"rounded-lg border border-basalt-700 px-3 py-2 text-[9px] font-semibold text-basalt-300 hover:border-basalt-500 hover:text-white",children:"Find unused hosted files"}),v?.length>0&&(0,e.jsxs)("button",{type:"button",onClick:ie,className:"rounded-lg border border-red-400/25 px-3 py-2 text-[9px] font-semibold text-red-200 hover:bg-red-400/10",children:["Remove ",v.length," hosted copies"]})]})]})]})]}),j.length>0&&(0,e.jsxs)("div",{className:"overflow-hidden rounded-xl border border-basalt-800 bg-black/20",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-basalt-800 px-4 py-3",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("input",{type:"checkbox",checked:L,onChange:R,disabled:M,"aria-label":"Select all largest hosted files",className:"h-3.5 w-3.5 rounded border-basalt-700 bg-basalt-900 text-cyan-500 focus:ring-cyan-500 focus:ring-offset-basalt-950 disabled:opacity-50"}),(0,e.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:"Largest hosted files"}),X>0&&(0,e.jsxs)("span",{className:"rounded-full border border-cyan-800/50 bg-cyan-950 px-2 py-0.5 text-[9px] font-semibold text-cyan-300",children:[X," selected (",z(Ee,1),")"]})]}),X>0&&(0,e.jsxs)("button",{type:"button",disabled:M,onClick:qe,className:"inline-flex items-center gap-1.5 rounded-lg border border-red-400/30 bg-red-500/10 px-3 py-1.5 text-[10px] font-semibold text-red-200 transition-colors hover:border-red-400/50 hover:bg-red-500/20 disabled:opacity-50",children:[(0,e.jsx)(Me,{size:12}),"Delete ",X," ",X===1?"file":"files"]})]}),(0,e.jsx)("div",{className:"max-h-64 overflow-y-auto",children:V.map(g=>{const P=F.includes(g.id);return(0,e.jsxs)("div",{className:`flex items-center justify-between gap-3 border-b border-basalt-800/70 px-4 py-3 transition-colors last:border-0 ${P?"bg-cyan-950/20":"hover:bg-basalt-900/40"}`,children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,e.jsx)("input",{type:"checkbox",checked:P,onChange:()=>te(g.id),disabled:M,"aria-label":`Select ${g.name}`,className:"h-3.5 w-3.5 rounded border-basalt-700 bg-basalt-900 text-cyan-500 focus:ring-cyan-500 focus:ring-offset-basalt-950 disabled:opacity-50"}),(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("div",{className:"truncate text-xs text-basalt-300",children:g.name}),(0,e.jsxs)("div",{className:"mt-0.5 text-[9px] text-basalt-600",children:[z(g.size_bytes,1)," · ",new Date(g.created_at).toLocaleDateString()]})]})]}),(0,e.jsx)("button",{disabled:M,onClick:()=>G(g),className:"shrink-0 rounded-md p-1.5 text-basalt-600 hover:bg-red-400/10 hover:text-red-300 disabled:opacity-50","aria-label":`Delete hosted copy of ${g.name}`,children:(0,e.jsx)(Me,{size:13})})]},g.id)})})]}),f&&(0,e.jsx)("p",{className:"text-[10px] text-amber-300",children:f})]})}
2var He="basalt_account_deletion_job",Yt="w-full rounded-lg border border-red-400/20 bg-basalt-950 px-3 py-2.5 text-xs text-white outline-none focus:border-red-300/60";function _n(){try{return JSON.parse(localStorage.getItem(He)||"null")}catch{return null}}function Fn({hosted:a,userId:r}){const[l,s]=(0,o.useState)(""),[m,j]=(0,o.useState)(""),[p,f]=(0,o.useState)(!1),[u,E]=(0,o.useState)(""),[c,x]=(0,o.useState)(()=>{const v=_n();return v?.userId===r?v:null});(0,o.useEffect)(()=>{if(!c?.job?.id||!c.statusToken||c.job.status==="complete")return;let v=!0;const I=async()=>{try{const C=await fetch(`/api/account/deletion/${c.job.id}/status`,{headers:{"X-Deletion-Token":c.statusToken}}),b=await C.json().catch(()=>({}));if(v&&C.ok){const F={...c,job:b.job};x(F),localStorage.setItem(He,JSON.stringify(F)),b.job.status==="complete"&&(localStorage.removeItem("basalt_session"),localStorage.removeItem("basalt_api_key"),localStorage.removeItem("cloud_credentials"))}}catch{}};I();const i=setInterval(I,5e3);return()=>{v=!1,clearInterval(i)}},[c?.job?.id,c?.job?.status,c?.statusToken]);const w=async()=>{f(!0),E("Preparing hosted account exportâ¦");try{const v=await fetch("/api/account/export",{credentials:"include"});if(!v.ok)throw new Error("Unable to export hosted account data.");const I=await v.blob(),i=URL.createObjectURL(I),C=document.createElement("a");C.href=i,C.download=`basalt-account-export-${new Date().toISOString().slice(0,10)}.json`,C.click(),URL.revokeObjectURL(i),E("Hosted account export downloaded. Export the Markdown vault from the Notes dashboard as well.")}catch(v){E(v.message)}finally{f(!1)}},y=async()=>{f(!0),E("Scheduling secure account deletionâ¦");try{const v=await fetch("/api/account/deletion",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:l,confirmation:m})}),I=await v.json().catch(()=>({}));if(!v.ok)throw new Error(I.error||"Unable to schedule account deletion.");const i={userId:r,job:I.job,statusToken:I.statusToken};localStorage.setItem(He,JSON.stringify(i)),x(i),s(""),j(""),E("Sessions and public access have been revoked. Phasoric is deleting hosted data in durable batches.")}catch(v){E(v.message)}finally{f(!1)}},$=async()=>{if(c?.job?.id){f(!0);try{const v=await fetch(`/api/account/deletion/${c.job.id}/retry`,{method:"POST",headers:{"X-Deletion-Token":c.statusToken}}),I=await v.json().catch(()=>({}));if(!v.ok)throw new Error(I.error||"Unable to retry deletion.");const i={...c,job:I.job};localStorage.setItem(He,JSON.stringify(i)),x(i)}catch(v){E(v.message)}finally{f(!1)}}};return c?.job?(0,e.jsxs)("section",{className:"rounded-xl border border-red-400/25 bg-red-400/[0.04] p-4","aria-live":"polite",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h3",{className:"text-sm font-semibold text-red-200",children:["Account deletion ",c.job.status]}),(0,e.jsxs)("p",{className:"mt-1 text-[10px] text-basalt-500",children:["Stage: ",c.job.stage," · attempt ",c.job.attempts||0]})]}),c.job.status==="failed"&&(0,e.jsxs)("button",{type:"button",disabled:p,onClick:$,className:"flex items-center gap-1 rounded-lg border border-red-300/25 px-3 py-2 text-[10px] text-red-200",children:[(0,e.jsx)(Se,{size:11}),"Retry"]})]}),c.job.progress&&(0,e.jsxs)("p",{className:"mt-3 text-[10px] text-basalt-400",children:["Attachments deleted: ",c.job.progress.attachmentsDeleted||0,c.job.progress.attachmentsRemaining?` · ${c.job.progress.attachmentsRemaining} remaining`:""]}),c.job.lastError&&(0,e.jsx)("p",{className:"mt-2 text-[10px] text-red-300",children:"Phasoric could not finish this deletion stage. Your deletion request is saved; use Retry when the service is available."}),c.job.status==="complete"&&(0,e.jsx)("a",{href:"/",className:"mt-3 inline-block rounded-lg bg-white px-3 py-2 text-[10px] font-bold text-black",children:"Return to Phasoric"})]}):a?(0,e.jsxs)("section",{className:"space-y-4 rounded-xl border border-red-400/20 bg-red-400/[0.035] p-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("h3",{className:"flex items-center gap-2 text-sm font-semibold text-red-200",children:[(0,e.jsx)(Me,{size:14}),"Delete hosted account"]}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-500",children:"Download both the hosted export and your local Markdown vault first. Deleti
2on immediately revokes sessions, API tokens, public shares, collaboration access, and billing; hosted attachments and database records are then erased in retryable batches."})]}),(0,e.jsxs)("button",{type:"button",disabled:p,onClick:w,className:"flex items-center gap-2 rounded-lg border border-white/10 px-3 py-2 text-[10px] font-semibold text-basalt-200 disabled:opacity-50",children:[(0,e.jsx)(es,{size:12}),"Download hosted data"]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-red-200",children:["Current password",(0,e.jsx)("input",{type:"password",autoComplete:"current-password",value:l,onChange:v=>s(v.target.value),className:`${Yt} mt-1.5`})]}),(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-red-200",children:["Type DELETE",(0,e.jsx)("input",{value:m,onChange:v=>j(v.target.value),className:`${Yt} mt-1.5`})]})]}),(0,e.jsx)("button",{type:"button",disabled:p||!l||m!=="DELETE",onClick:y,className:"rounded-lg bg-red-400 px-4 py-2 text-xs font-bold text-red-950 disabled:opacity-40",children:"Permanently delete account"}),u&&(0,e.jsx)("p",{className:"text-[10px] leading-4 text-basalt-400","aria-live":"polite",children:u})]}):null}function On({hosted:a}){const[r,l]=(0,o.useState)(()=>Wt()),[s,m]=(0,o.useState)(""),[j,p]=(0,o.useState)(!0);(0,o.useEffect)(()=>{a&&fetch("/api/account/communication-preferences",{credentials:"include"}).then(u=>u.ok?u.json():Promise.reject(new Error("Unable to load communication preferences."))).then(u=>{l(Wt(u.preferences)),p(!1)}).catch(u=>m(u.message))},[a]);const f=async u=>{if(j)return;const E=r;l(u),p(!0),m("Savingâ¦");try{const c=await fetch("/api/account/communication-preferences",{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!c.ok)throw new Error("Unable to save communication preferences.");l((await c.json()).preferences),m("Saved")}catch(c){l(E),m(c.message)}finally{p(!1)}};return a?(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Communication preferences"}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-500",children:"Account creation does not grant marketing consent. Security, account, billing, and service messages remain operational communications."}),(0,e.jsxs)("fieldset",{disabled:j,children:[(0,e.jsxs)("label",{className:"mt-4 flex items-start gap-3 text-xs text-basalt-300",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:r.productEducation,onChange:u=>{f({...r,productEducation:u.target.checked})}}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-white",children:"Getting-started and product education"}),"Occasional guidance and reminders to resume useful work."]})]}),(0,e.jsxs)("label",{className:"mt-3 flex items-start gap-3 text-xs text-basalt-300",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:r.marketing,onChange:u=>{f({...r,marketing:u.target.checked})}}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-white",children:"Product news and offers"}),"Optional marketing announcements. Off by default."]})]}),(0,e.jsxs)("label",{className:"mt-3 flex items-start gap-3 text-xs text-basalt-300",children:[(0,e.jsx)("input",{type:"checkbox",checked:r.watchAlerts,onChange:u=>{f({...r,watchAlerts:u.target.checked})}}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-white",children:"Configured Watch email"}),"Allow email from hosted Watches where you explicitly enabled notifications."]})]}),(0,e.jsxs)("label",{className:"mt-3 flex items-start gap-3 text-xs text-basalt-300",children:[(0,e.jsx)("input",{type:"checkbox",checked:r.reviewAlerts,onChange:u=>{f({...r,reviewAlerts:u.target.checked})}}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-white",children:"Context review reminders"}),"Recorded review needs in authorized published decisions and living briefs."]})]}),(0,e.jsxs)("label",{className:"mt-3 flex items-start gap-3 text-xs text-basalt-300",children:[(0,e.jsx)("input",{type:"checkbox",checked:r.weeklyReview,onChange:u=>{f({...r,weeklyReview:u.target.checked})}}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-white",children:"Weekly intelligence review"}),"Counts from supported published context. Device-only knowledge stays on your device."]})]}),r.weeklyReview&&(0,e.jsxs)("div",{className:"mt-3 flex flex-wrap gap-3 text-xs",children:[(0,e.jsxs)("label",{children:["Day",(0,e.jsx)("select",{className:"ml-2 roun
2ded bg-basalt-900 p-2",value:r.weeklyDay,onChange:u=>{f({...r,weeklyDay:Number(u.target.value)})},children:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"].map((u,E)=>(0,e.jsx)("option",{value:E,children:u},u))})]}),(0,e.jsxs)("label",{children:["Time",(0,e.jsx)("input",{type:"time",className:"ml-2 rounded bg-basalt-900 p-2",value:r.weeklyTime,onChange:u=>{f({...r,weeklyTime:u.target.value})}})]}),(0,e.jsxs)("label",{className:"min-w-0 max-w-full",children:["Time zone",(0,e.jsx)("select",{className:"mt-2 block max-w-full rounded bg-basalt-900 p-2",value:r.weeklyTimeZone,onChange:u=>{f({...r,weeklyTimeZone:u.target.value})},children:[...new Set(["UTC",r.weeklyTimeZone,...Intl.supportedValuesOf?.("timeZone")||[]])].map(u=>(0,e.jsx)("option",{children:u},u))})]})]})]}),s?(0,e.jsx)("p",{className:"mt-3 text-[10px] text-basalt-500","aria-live":"polite",children:s}):null]}):null}var Jt={forgeApproval:"owner_or_admin",externalActions:"disabled",decisionReviewDays:90,publicSharing:"members"},rt={admin:"Workspace Admin",editor:"Editor",reviewer:"Reviewer",commenter:"Commenter",viewer:"Viewer"},Un={admin:"Manage this workspaceâs members, policy, notes, reviews, and automation.",editor:"Edit notes and manage normal workspace workflows.",reviewer:"Read, discuss, and complete assigned reviews.",commenter:"Read notes and participate in discussions.",viewer:"Read workspace knowledge only."};async function be(a,r={}){const l=await fetch(a,{credentials:"include",headers:{"Content-Type":"application/json",...r.headers||{}},...r}),s=l.status===204?{}:await l.json().catch(()=>({}));if(!l.ok)throw new Error(s.error||"Workspace governance request failed.");return s}function ot({label:a,value:r,options:l,onChange:s,disabled:m}){return(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:[a,(0,e.jsx)("select",{value:r,disabled:m,onChange:j=>s(j.target.value),className:"mt-2 w-full rounded-lg border border-white/10 bg-basalt-900 px-3 py-2 text-xs normal-case tracking-normal text-white disabled:opacity-50",children:l.map(([j,p])=>(0,e.jsx)("option",{value:j,children:p},j))})]})}function Zt({title:a,items:r}){return(0,e.jsxs)("div",{children:[(0,e.jsxs)("h4",{className:"flex items-center gap-2 text-xs font-semibold",children:[(0,e.jsx)(os,{size:12}),a]}),(0,e.jsx)("div",{className:"mt-3 max-h-40 space-y-2 overflow-y-auto",children:r.length?r.slice(0,20).map(l=>(0,e.jsxs)("div",{className:"border-t border-white/[.05] pt-2 text-[9px] text-basalt-500 first:border-0",children:[(0,e.jsx)("span",{className:"text-basalt-300",children:String(l.label).replaceAll("."," ").replaceAll("_"," ")}),l.actor?` · ${l.actor}`:""," · ",new Date(l.createdAt).toLocaleString()]},l.id)):(0,e.jsx)("p",{className:"text-[9px] text-basalt-600",children:"No activity recorded yet."})})]})}function zn({workspaceId:a,hosted:r,userId:l}){const s=r&&kn(a),[m,j]=(0,o.useState)([]),[p,f]=(0,o.useState)(""),[u,E]=(0,o.useState)("editor"),[c,x]=(0,o.useState)(Jt),[w,y]=(0,o.useState)([]),[$,v]=(0,o.useState)([]),[I,i]=(0,o.useState)(""),[C,b]=(0,o.useState)(""),[F,S]=(0,o.useState)(!1),M=(0,o.useCallback)(async()=>{if(!s)return;const[k,D,V]=await Promise.all([be(`/api/workspaces/${a}/members`),be(`/api/workspaces/${a}/governance`).catch(()=>null),be(`/api/collaboration/activity?workspaceId=${encodeURIComponent(a)}&limit=50`).catch(()=>null)]);j(k.members||[]),v(V?.activity||[]),D&&(x({...Jt,...D.governance||{}}),y(D.events||[]),i(D.role||""),S(D.planKey==="team"))},[s,a]);(0,o.useEffect)(()=>{M().catch(()=>{})},[M]);const N=m.find(k=>k.role==="owner"),_=I||(N?.user_id===l?"owner":m.find(k=>k.user_id===l)?.role||""),G=Ys(_),B=G.length>0,de=async k=>{k.preventDefault(),b("Adding memberâ¦");try{await be(`/api/workspaces/${a}/members`,{method:"POST",body:JSON.stringify({email:p,role:u})}),f(""),b("Workspace member added and recorded in the audit trail."),await M()}catch(D){b(D.message)}},se=async(k,D)=>{try{await be(`/api/workspaces/${a}/members/${k.user_id}`,{method:"PATCH",body:JSON.stringify({role:D})}),b("Member role changed. Existing collaboration grants were revoked."),await M()}catch(V){b(V.message)}},ne=async k=>
2{if(window.confirm(`Remove ${k.name} from this workspace?`))try{await be(`/api/workspaces/${a}/members/${k.user_id}`,{method:"DELETE"}),b("Workspace access revoked. Active collaboration grants were invalidated."),await M()}catch(D){b(D.message)}},ie=async()=>{try{const k=await be(`/api/workspaces/${a}/governance`,{method:"PATCH",body:JSON.stringify(c)});x(k.governance),b("Governance policy saved and added to the audit trail."),await M()}catch(k){b(k.message)}};return s?(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(Ce,{size:15,className:"text-cyan-300"}),(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Workspace collaboration & governance"})]}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-500",children:"Roles separate workspace management, note editing, assigned review, durable commenting, and read-only access. Writable collaboration grants are revoked when access changes."}),(0,e.jsx)("div",{className:"mt-4 space-y-2",children:m.map(k=>(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border border-white/[0.06] px-3 py-2",children:[(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsx)("div",{className:"truncate text-xs text-basalt-200",children:k.name}),(0,e.jsx)("div",{className:"truncate text-[9px] text-basalt-600",children:k.email}),(0,e.jsx)("div",{className:"mt-1 text-[8px] text-basalt-700",children:k.role==="owner"?"Full ownership of this workspace.":Un[k.role]})]}),k.role==="owner"?(0,e.jsx)("span",{className:"rounded-full border border-violet-300/20 px-2 py-1 text-[9px] font-bold uppercase text-violet-200",children:"Workspace Owner"}):(0,e.jsxs)(e.Fragment,{children:[B&&G.includes(k.role)?(0,e.jsx)("select",{value:k.role,onChange:D=>se(k,D.target.value),className:"rounded-lg border border-white/10 bg-basalt-900 px-2 py-1.5 text-[9px] text-white",children:G.map(D=>(0,e.jsx)("option",{value:D,children:rt[D]},D))}):(0,e.jsx)("span",{className:"text-[9px] text-basalt-500",children:rt[k.role]||k.role}),B&&G.includes(k.role)?(0,e.jsx)("button",{type:"button",onClick:()=>ne(k),"aria-label":`Remove ${k.name}`,className:"rounded-lg p-2 text-red-300 hover:bg-red-400/10",children:(0,e.jsx)(Dn,{size:13})}):null]})]},k.user_id))}),B?(0,e.jsxs)("form",{onSubmit:de,className:"mt-3 grid gap-2 sm:grid-cols-[1fr_auto_auto]",children:[(0,e.jsx)("input",{type:"email",required:!0,value:p,onChange:k=>f(k.target.value),placeholder:"[email protected]",className:"min-w-0 rounded-lg border border-basalt-800 bg-basalt-950 px-3 py-2 text-xs outline-none focus:border-cyan-300/50"}),(0,e.jsx)("select",{value:u,onChange:k=>E(k.target.value),className:"rounded-lg border border-basalt-800 bg-basalt-950 px-3 py-2 text-[10px]",children:G.map(k=>(0,e.jsx)("option",{value:k,children:rt[k]},k))}),(0,e.jsxs)("button",{className:"flex items-center justify-center gap-1 rounded-lg border border-cyan-300/20 px-3 py-2 text-[10px] font-semibold text-cyan-200",children:[(0,e.jsx)(it,{size:11}),"Add member"]})]}):null,(0,e.jsx)("div",{className:"my-5 h-px bg-white/[.06]"}),F?(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h4",{className:"text-xs font-semibold text-white",children:"Team policy"}),(0,e.jsx)("p",{className:"mt-1 text-[9px] text-basalt-600",children:"Applied at the Phasoric workspace boundary."})]}),B?(0,e.jsxs)("button",{type:"button",onClick:ie,className:"inline-flex items-center gap-1 rounded-lg border border-emerald-300/20 px-3 py-2 text-[9px] font-semibold text-emerald-200",children:[(0,e.jsx)(is,{size:11}),"Save policy"]}):null]}),(0,e.jsxs)("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[(0,e.jsx)(ot,{label:"Forge approvals",value:c.forgeApproval,disabled:!B,onChange:k=>x(D=>({...D,forgeApproval:k})),options:[["owner_or_admin","Workspace Owner or Workspace Admin"],["any_editor","Any editor"]]}),(0,e.jsx)(ot,{label:"External actions",value:c.externalActions,disabled:!B,onChange:k=>x(D=>({...D,externalActions:k})),options:[["disabled","Disabled"],["owner_only","Workspace Owner only"],["owner_or_admin","Workspace Owner or Worksp
2ace Admin"]]}),(0,e.jsx)(ot,{label:"Public sharing",value:c.publicSharing,disabled:!B,onChange:k=>x(D=>({...D,publicSharing:k})),options:[["disabled","Disabled"],["owner_or_admin","Workspace Owner or Workspace Admin"],["members","Editors and above"]]}),(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:["Decision review cadence",(0,e.jsx)("input",{type:"number",min:"7",max:"365",disabled:!B,value:c.decisionReviewDays,onChange:k=>x(D=>({...D,decisionReviewDays:Number(k.target.value)})),className:"mt-2 w-full rounded-lg border border-white/10 bg-basalt-900 px-3 py-2 text-xs normal-case tracking-normal text-white disabled:opacity-50"})]})]}),(0,e.jsxs)("div",{className:"mt-5 grid gap-4 lg:grid-cols-2",children:[(0,e.jsx)(Zt,{title:"Governance changes",items:w.map((k,D)=>({id:`${k.created_at}-${D}`,label:k.action,actor:"",createdAt:k.created_at}))}),(0,e.jsx)(Zt,{title:"Knowledge activity",items:$.map(k=>({id:k.id,label:k.type,actor:k.actorName,createdAt:k.createdAt}))})]})]}):(0,e.jsxs)("div",{className:"rounded-xl border border-amber-300/15 bg-amber-300/[.035] p-4",children:[(0,e.jsx)("h4",{className:"text-xs font-semibold text-amber-100",children:"Team governance requires Team & Collaboration"}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-500",children:"Member collaboration remains available where entitled. Team adds role administration, policy controls, and a governance audit trail."}),(0,e.jsx)(Gs,{to:"/pricing?recommended=team",className:"mt-3 inline-block text-[10px] font-semibold text-amber-300",children:"Review Team plan"})]}),C?(0,e.jsx)("p",{className:"mt-3 text-[10px] text-basalt-400","aria-live":"polite",children:C}):null]}):null}var ue="mt-1 w-full rounded-lg border border-basalt-700 bg-basalt-950 px-3 py-2 text-sm",Xt="rounded-lg border border-basalt-600 px-4 py-2 text-xs font-semibold disabled:opacity-50";function Bn({owner:a,initialSettings:r,onChanged:l}){const[s,m]=(0,o.useState)(r),[j,p]=(0,o.useState)(!1),[f,u]=(0,o.useState)(!1),[E,c]=(0,o.useState)(""),[x,w]=(0,o.useState)(1),[y,$]=(0,o.useState)(!1),[v]=(0,o.useState)(()=>crypto.randomUUID()),I=s.autoTopupEnabled&&(!r.autoTopupEnabled||!r.paymentMethodReady||["autoTopupQuantity","autoTopupCapCents","autoTopupThresholdCredits"].some(b=>s[b]!==r[b])),i=(b,F)=>{m(S=>({...S,[b]:F})),p(!1)},C=async(b,F,S)=>{u(!0),c("");try{const M=await fetch(b,{method:F,credentials:"include",headers:{"Content-Type":"application/json","Idempotency-Key":v},body:JSON.stringify(S)}),N=await M.json();if(!M.ok)throw new Error(N.error||"Unable to save billing settings.");if(N.url){window.location.assign(N.url);return}N.settings&&m(N.settings),p(!1),c("Credit controls saved."),l?.()}catch(M){c(M.message)}finally{u(!1)}};return ge()?(0,e.jsxs)("section",{className:"space-y-4 rounded-xl border border-basalt-800 p-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Credit purchases and spending controls"}),(0,e.jsxs)("p",{className:"mt-1 text-xs text-basalt-400",children:["Billed to ",(0,e.jsx)("strong",{className:"text-basalt-100",children:a.label}),". Credits belong to this billing account. A shared vault does not change who pays."]})]}),(0,e.jsxs)("details",{className:"rounded-lg border border-basalt-800 p-3",children:[(0,e.jsx)("summary",{className:"cursor-pointer text-sm font-semibold",children:"Purchase credits"}),(0,e.jsxs)("div",{className:"mt-3 space-y-3 text-xs",children:[(0,e.jsxs)("label",{className:"block max-w-xs",children:["Credit packs",(0,e.jsx)("select",{className:ue,value:x,onChange:b=>{w(Number(b.target.value)),$(!1)},children:[1,2,4].map(b=>(0,e.jsxs)("option",{value:b,children:[Q(Ot(b))," credits · $",(et.priceUsd*b).toFixed(2)]},b))})]}),(0,e.jsx)("p",{children:"Purchased credits never expire and remain after cancellation or downgrade. Credit packs are non-refundable."}),(0,e.jsxs)("label",{className:"flex items-start gap-2",children:[(0,e.jsx)("input",{type:"checkbox",checked:y,onChange:b=>$(b.target.checked)}),(0,e.jsxs)("span",{children:["Purchase for ",a.label,"."]})]}),(0,e.jsxs)("button",{type:"button",className:Xt,disabled:!y||f,onClick:()=>C("/api/billing/create-ai-credit-checkout","POST",{quantity:x,billingOwnerId:a.accountId}),children:["Continue to checkout · $",(et.priceUsd*x).toFixed(2)]})]})]}),(0,e.jsxs)("details",{className:"rounded-lg border border-basalt-800 p-3",children:[(0,e.jsx)("summary",{className:"cursor-pointer text-sm font-semibold",children:"Alerts and request limits"}),(0,e.jsxs)("div",{className:"mt-3 grid gap-4 text-xs sm:grid-cols-2",children:[(0,e.jsxs)("label",{children:["Maximum credits per request",(0,e.jsx)("input",{className:ue,type:"number",min:"0",max:"1000000",value:s.requestLimitCredits??"",placeholder:"Use the service limit",onChange:b=>i("requestLimitCredits",b.target.value===""?null:Number(b.target.value))}),(0,e.jsx)("span",{className:"mt-1 block text-basalt-400",children:"Leave blank for the service limit. Zero pauses new hosted AI requests. The maximum reservation must fit within this limit."})]}),(0,e.jsxs)("label",{children:["Daily AI spending limit (credits)",(0,e.jsx)("input",{className:ue,type:"number",min:"0",max:"100000000",value:s.dailyLimitCredits??"",placeholder:"No daily limit",onChange:b=>i("dailyLimitCredits",b.target.value===""?null:Number(b.target.value))}),(0,e.jsx)("span",{className:"block text-basalt-400",children:"Includes all AI credits and running requests; resets at midnight UTC."})]}),(0,e.jsxs)("label",{children:["Monthly AI spending limit (credits)",(0,e.jsx)("input",{className:ue,type:"number",min:"0",max:"100000000",value:s.monthlyLimitCredits??"",placeholder:"No monthly limit",onChange:b=>i("monthlyLimitCredits",b.target.value===""?null:Number(b.target.value))}),(0,e.jsx)("span",{className:"block text-basalt-400",children:"Separate from the automatic purchase cap. Blank means no additional limit."})]}),(0,e.jsxs)("label",{children:["Low-balance alert threshold (credits)",(0,e.jsx)("input",{className:ue,type:"number",min:"0",max:"1000000",value:s.lowBalanceCredits,onChange:b=>i("lowBalanceCredits",Number(b.target.value))})]}),(0,e.jsxs)("label",{className:"flex gap-2 sm:col-span-2",children:[(0,e.jsx)("input",{type:"checkbox",checked:s.alertsEnabled,onChange:b=>i("alertsEnabled",b.target.checked)}),"Email and notify me when my balance is low (at most once per calendar month)."]})]})]}),(0,e.jsxs)("details",{className:"rounded-lg border border-basalt-800 p-3",children:[(0,e.jsxs)("summary",{className:"cursor-pointer text-sm font-semibold",children:["Automatic top-ups · ",s.autoTopupEnabled?"enabled":"off"]}),(0,e.jsxs)("div",{className:"mt-3 space-y-3 text-xs",children:[(0,e.jsxs)("p",{children:["Confirmed this month: $",((r.topupSpentCents||0)/100).toFixed(2)," · Pending: $",((r.topupPendingCents||0)/100).toFixed(2)," · Remaining purchase cap: $",((r.topupRemainingCents||0)/100).toFixed(2),"."]}),(0,e.jsx)("p",{children:"Automatic purchases use the card you authorize in secure checkout. Reserved credits alone do not trigger a purchase. Monthly caps follow UTC calendar months."}),(0,e.jsxs)("label",{className:"flex gap-2",children:[(0,e.jsx)("input",{type:"checkbox",checked:s.autoTopupEnabled,onChange:b=>i("autoTopupEnabled",b.target.checked)}),"Enable automatic credit purchases"]}),s.autoTopupEnabled&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,e.jsxs)("label",{children:["Top up at or below (credits)",(0,e.jsx)("input",{className:ue,type:"number",min:"0",max:"1000000",value:s.autoTopupThresholdCredits,onChange:b=>i("autoTopupThresholdCredits",Number(b.target.value))})]}),(0,e.jsxs)("label",{children:["Packs per top-up",(0,e.jsx)("input",{className:ue,type:"number",min:"1",max:"20",step:"1",value:s.autoTopupQuantity,onChange:b=>i("autoTopupQuantity",Number(b.target.value))})]}),(0,e.jsxs)("label",{children:["Monthly purchase cap (USD)",(0,e.jsx)("input",{className:ue,type:"number",min:"0",max:"1000",step:"0.01",value:s.autoTopupCapCents/100,onChange:b=>i("autoTopupCapCents",Math.round(Number(b.target.value)*100))})]})]}),I&&(0,e.jsxs)("label",{className:"flex items-start gap-2",children:[(0,e.jsx)("input",{type:"checkbox",checked:j,onChange:b=>p(b.target.checked)}),(0,e.jsxs)("span",{children:["I authorize non-refundable automatic purchases of ",Q(Ot(s.autoTopupQuantity))," credits for $",(s.autoTopupQuantity*et.priceUsd).toFixed(2)," per top-up, up to $",(s.autoTopupCapCents/100).toFixed(2)," per UTC calendar month, for ",a.label,". I can disable future top-ups here. A purchase already submitted may still complete."]})]})]})]})]}),(0,e.jsx)("button",{type:"button",className:Xt,disabled:f||I&&!j,onClick:()=>
2C("/api/billing/credit-settings","PUT",{...s,acceptAutoTopupTerms:j}),children:f?"Savingâ¦":I?"Save and authorize payment method":"Save credit controls"}),E&&(0,e.jsx)("p",{role:"status",className:"text-xs text-amber-200",children:E})]}):(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 p-4 text-xs text-basalt-400",children:[(0,e.jsx)("h3",{className:"font-semibold text-white",children:"Credit controls"}),(0,e.jsx)("p",{className:"mt-2",children:"Your existing credits and spending limits apply. New credit purchases use the payment options available for this app."}),(0,e.jsx)(Hs,{kind:"credits",children:"View Google Play credit packs"})]})}function Ne(a){return`${a}-${crypto.randomUUID()}`}function Be(a){return a?new Date(a).toLocaleDateString():""}async function xe(a,{body:r,idempotency:l}={}){const s=await fetch(`/api/billing${a}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...l?{"Idempotency-Key":l}:{}},body:JSON.stringify(r||{})}),m=await s.json().catch(()=>({}));if(!s.ok)throw new Error(m.error||"Unable to update the subscription.");return m}function Hn({subscription:a,onChanged:r}){const[l]=Va(),s=l.get("targetPlan"),m=l.get("interval"),j=Math.min(500,Math.max(1,Number(l.get("seats"))||1)),p=Xe.includes(s)?{planKey:s,billingInterval:["month","year"].includes(m)?m:"month",seatQuantity:s==="team"?j:1}:null,[f,u]=(0,o.useState)(a?.planKey||"premium"),[E,c]=(0,o.useState)(a?.billingInterval||"month"),[x,w]=(0,o.useState)(a?.seatQuantity||1),[y,$]=(0,o.useState)(null),[v,I]=(0,o.useState)(""),[i,C]=(0,o.useState)("");(0,o.useEffect)(()=>{a&&(u(Xe.includes(s)?s:a.planKey==="free"?"premium":a.planKey),c(["month","year"].includes(m)?m:a.billingInterval||"month"),w(s==="team"?j:a.seatQuantity||1),$(null))},[m,s,j,a]);const b={planKey:f,billingInterval:E,seatQuantity:f==="team"?Math.max(1,Number(x||1)):1},F=!a||a.planKey==="free"||a.status==="free",S=a?.pendingChange&&typeof a.pendingChange=="object"&&Object.keys(a.pendingChange).length?a.pendingChange:null;async function M(N,_,G){I(N),C("");try{const B=await _();C(G),N!=="preview"&&$(null),["apply","cancel","reactivate","cancel-change"].includes(N)&&(await r?.(B),window.dispatchEvent(new CustomEvent("billing-subscription-updated"))),N==="apply"&&ce("subscription_change_requested",{plan_key:f,billing_interval:E}),N==="checkout"&&ce("checkout_started",{plan_key:p?.planKey,billing_interval:p?.billingInterval}),N==="cancel"&&ce("subscription_cancellation_scheduled",{plan_key:a.planKey,billing_interval:a.billingInterval}),N==="reactivate"&&ce("subscription_reactivated",{plan_key:a.planKey,billing_interval:a.billingInterval})}catch(B){C(B.message),["apply","preview"].includes(N)&&ce("subscription_change_failed",{plan_key:f,billing_interval:E,change_kind:N,result:"error"}),N==="checkout"&&ce("checkout_failed",{plan_key:p?.planKey,billing_interval:p?.billingInterval,result:"error"})}finally{I("")}}if(a?.provider==="google_play"){const N=`https://play.google.com/store/account/subscriptions?package=com.phasoric.app${a.productId?`&sku=${encodeURIComponent(a.productId)}`:""}`;return(0,e.jsxs)("section",{className:"space-y-3 rounded-xl border border-basalt-800 p-5",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-white",children:"Google Play subscription"}),(0,e.jsxs)("p",{className:"text-xs text-basalt-300",children:[a.tier||Le[a.planKey]?.shortName," · ",a.status]}),(0,e.jsx)("p",{className:"text-xs text-basalt-400",children:a.cancelAtPeriodEnd?`Renewal is canceled. Access continues through ${Be(a.currentPeriodEnd)||"the current paid period"}.`:"Manage renewal, cancellation and payment details in Google Play."}),ra()&&a.productId?(0,e.jsx)("button",{type:"button",disabled:!!v,onClick:()=>M("manage",()=>Es.manageSubscription(a.productId),"Subscription management opened in Google Play."),className:"min-h-11 rounded-lg border border-cyan-300/20 px-3 py-2 text-xs text-cyan-200 disabled:opacity-50",children:"Manage in Google Play"}):ge()?(0,e.jsx)("a",{href:N,target:"_blank",rel:"noopener noreferrer",className:"inline-flex min-h-11 items-center text-xs text-cyan-200 underline",children:"Manage in Google Play"}):(0,e.jsx)("p",{className:"text-xs text-basalt-400",children:"Open Google Play to manage this subscription."}),i&&(0,e.jsx)("p",{role:"status",className:"text-xs text-basalt-300",children:i})]})}return ge()?F?(0,e.jsxs)("section",{className:"rounded-xl border border-cyan-300/15 bg-cyan-300/[.035] p-5",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-white",children:"Subscription management"}),(0,e.jsx)(qt,{title:"Plans & Subscription Governance",content:(0,e.jsxs)("span",{className:"leading-relaxed",children:["Learn about Free, Premium, Professional, Developer, and Team plan entitlements. ",(0,e.jsx)("a",{href:"/guides/plans-and-subscription-governance",target:"_blank",rel:"noopener noreferrer",className:"font-semibold text-cyan-300 hover:underline",children:"Read guide â"})]})})]}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-400",children:"Your account is on Free. Choose a paid plan to add hosted capacity, automation, connected intelligence, developer access, or team collaboration."}),p?(0,e.jsxs)("div",{className:"mt-4 rounded-lg border border-white/10 bg-black/15 p-4",children:[(0,e.jsxs)("strong",{className:"text-xs text-white",children:["Account ready · ",Le[p.planKey].shortName," selection preserved"]}),(0,e.jsxs)("p",{className:"mt-1 text-[10px] leading-5 text-basalt-400",children:[p.billingInterval==="year"?"Annual billing":"Monthly billing",p.planKey==="team"?` · ${p.seatQuantity} ${p.seatQuantity===1?"seat":"seats"}`:"",". Review the plan and explicitly continue to secure Stripe checkout. Nothing has been charged."]}),(0,e.jsx)("button",{type:"button",disabled:!!v,onClick:()=>M("checkout",async()=>{const N=await xe("/checkout",{body:{...p,openAiAttribution:fs()},idempotency:Ne("subscription-checkout")});if(!N.url)throw new Error("Secure checkout did not return a destination.");return window.location.assign(N.url),N},""),className:"mt-3 inline-flex rounded-lg bg-accent-cyan px-4 py-2 text-[10px] font-bold text-basalt-950 disabled:opacity-50",children:v==="checkout"?"Opening secure checkoutâ¦":"Continue to secure checkout"})]}):(0,e.jsx)(Wa,{to:"/pricing",className:"mt-4 inline-flex rounded-lg bg-accent-cyan px-4 py-2 text-[10px] font-bold text-basalt-950",children:"Compare plans"})]}):(0,e.jsxs)("section",{className:"space-y-4 rounded-xl border border-basalt-800 bg-basalt-950/45 p-5",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-white",children:"Manage subscription"}),(0,e.jsx)(qt,{title:"Plans & Subscription Governance",content:(0,e.jsxs)("span",{className:"leading-relaxed",children:["Learn about plan entitlements, proration previews, and annual savings. ",(0,e.jsx)("a",{href:"/guides/plans-and-subscription-governance",target:"_blank",rel:"noopener noreferrer",className:"font-semibold text-cyan-300 hover:underline",children:"Read guide â"})]})})]}),(0,e.jsxs)("p",{className:"mt-1 text-[10px] leading-4 text-basalt-500",children:["Phasoric controls plan, billing interval, seats, and cancellation. Payments, invoices, and card security are handled directly by ",(0,e.jsx)("strong",{children:"Stripe"}),"."]})]}),(0,e.jsxs)("button",{type:"button",disabled:!!v,onClick:()=>M("payment",async()=>{const N=await xe("/payment-method-session");return window.location.assign(N.url),N},""),className:"inline-flex items-center gap-2 rounded-lg border border-basalt-700 px-3 py-2 text-[10px] font-semibold text-basalt-200 disabled:opacity-50",children:[v==="payment"?(0,e.jsx)(Re,{size:12,className:"animate-spin"}):(0,e.jsx)(pt,{size:12})," Payment methods & invoices"]})]}),S&&(0,e.jsxs)("div",{className:"rounded-lg border border-amber-300/20 bg-amber-300/[.04] p-4 text-[10px] text-amber-100",children:[(0,e.jsxs)("div",{className:"flex items-start gap-2",children:[(0,e.jsx)(Qa,{size:14,className:"mt-0.5 shrink-0"}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("b",{className:"block",children:["Pending ",String(S.kind||"subscription change").replaceAll("_"," ")]}),(0,e.jsxs)("p",{className:"mt-1 text-amber-100/70",children:[S.planKey?`${Le[S.planKey]?.shortName||S.planKey} · `:"",S.billingInterval||"",S.effectiveAt?` · effective ${Be(S.effectiveAt)}`:""]})]})]}
2),S.kind!=="cancellation"&&(0,e.jsxs)("button",{type:"button",disabled:!!v,onClick:()=>M("cancel-change",()=>xe("/subscription/cancel-change",{idempotency:Ne("cancel-change")}),"The pending subscription change was canceled."),className:"mt-3 inline-flex items-center gap-1 rounded-md border border-amber-200/20 px-2.5 py-1.5 font-semibold disabled:opacity-50",children:[(0,e.jsx)(Ja,{size:11})," Cancel pending change"]})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Plan",(0,e.jsx)("select",{value:f,disabled:!!v||!!S,onChange:N=>{u(N.target.value),$(null)},className:"mt-1.5 w-full rounded-lg border border-basalt-700 bg-basalt-900 px-3 py-2.5 text-xs normal-case tracking-normal text-white disabled:opacity-50",children:Xe.map(N=>(0,e.jsxs)("option",{value:N,children:[Le[N].shortName," · ",Ft(N,"month"),"/mo"]},N))})]}),(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Billing interval",(0,e.jsxs)("select",{value:E,disabled:!!v||!!S,onChange:N=>{c(N.target.value),$(null)},className:"mt-1.5 w-full rounded-lg border border-basalt-700 bg-basalt-900 px-3 py-2.5 text-xs normal-case tracking-normal text-white disabled:opacity-50",children:[(0,e.jsx)("option",{value:"month",children:"Monthly"}),(0,e.jsx)("option",{value:"year",children:"Annual"})]})]}),(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Team seats",(0,e.jsx)("input",{type:"number",min:"1",max:"500",value:f==="team"?x:1,disabled:f!=="team"||!!v||!!S,onChange:N=>{w(N.target.value),$(null)},className:"mt-1.5 w-full rounded-lg border border-basalt-700 bg-basalt-900 px-3 py-2.5 text-xs normal-case tracking-normal text-white disabled:opacity-50"})]})]}),(0,e.jsxs)("p",{className:"text-[10px] text-basalt-500",children:["New recurring price: ",(0,e.jsxs)("b",{className:"text-basalt-200",children:[Ft(f,E),f==="team"?" per seat":""," / ",E==="year"?"year":"month"]})]}),y&&(0,e.jsxs)("div",{className:"rounded-lg border border-cyan-300/15 bg-cyan-300/[.035] p-4 text-[10px] leading-5 text-basalt-300",children:[(0,e.jsx)("b",{className:"text-cyan-100",children:y.timing==="immediate"?"Applies after payment confirmation":`Scheduled for ${Be(y.effectiveAt)}`}),(0,e.jsxs)("p",{children:[y.timing==="immediate"?`Amount due now: ${y.currency} ${(y.amountDueCents/100).toFixed(2)}. `:"","Recurring charge: ",y.currency," ",(y.recurringPriceCents/100).toFixed(2),"."]}),(0,e.jsx)("button",{type:"button",disabled:!!v,onClick:()=>
2{window.confirm("Apply this subscription change?")&&M("apply",()=>xe("/subscription/change",{body:{...b,previewToken:y.previewToken},idempotency:Ne("subscription-change")}),"Your subscription change is being processed.")},className:"mt-2 rounded-lg bg-accent-cyan px-3 py-2 font-bold text-basalt-950 disabled:opacity-50",children:"Confirm change"})]}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)("button",{type:"button",disabled:!!v||!!S,onClick:()=>M("preview",async()=>{const N=await xe("/subscription/preview-change",{body:b});return $(N.preview),ce("subscription_change_previewed",{plan_key:f,billing_interval:E,change_kind:N.preview?.timing||"unknown"}),N},""),className:"rounded-lg border border-cyan-300/25 px-3 py-2 text-[10px] font-semibold text-cyan-200 disabled:opacity-50",children:v==="preview"?"Calculatingâ¦":"Preview plan change"}),a.cancelAtPeriodEnd?(0,e.jsxs)("button",{type:"button",disabled:!!v,onClick:()=>M("reactivate",()=>xe("/subscription/reactivate",{idempotency:Ne("reactivate")}),"Automatic renewal was restored."),className:"inline-flex items-center gap-1 rounded-lg border border-emerald-300/20 px-3 py-2 text-[10px] font-semibold text-emerald-200 disabled:opacity-50",children:[(0,e.jsx)(ls,{size:11})," Keep subscription"]}):(0,e.jsx)("button",{type:"button",disabled:!!v||!!S,onClick:()=>{window.confirm("Schedule cancellation for the end of the current billing period?")&&M("cancel",()=>xe("/subscription/cancel",{idempotency:Ne("cancel")}),"Cancellation was scheduled for the end of the billing period.")},className:"rounded-lg border border-red-400/20 px-3 py-2 text-[10px] font-semibold text-red-200 disabled:opacity-50",children:"Cancel at period end"})]}),i&&(0,e.jsx)("p",{role:"status",className:"rounded-lg border border-white/[.08] bg-white/[.025] p-3 text-[10px] text-basalt-300",children:i})]}):(0,e.jsxs)("section",{className:"space-y-3 rounded-xl border border-basalt-800 p-5",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-white",children:"Account access"}),(0,e.jsx)("p",{className:"text-xs text-basalt-400",children:ws}),(0,e.jsxs)("p",{className:"text-xs text-basalt-300",children:[a?.tier||Le[a?.planKey||"free"]?.shortName||"Free"," · ",a?.status||"free"]}),a?.cancelAtPeriodEnd?(0,e.jsxs)("p",{className:"text-xs text-basalt-400",children:["Renewal is canceled. Access continues through ",Be(a.currentPeriodEnd)||"the current paid period","."]}):!F&&(0,e.jsx)("button",{type:"button",disabled:!!v,onClick:()=>{window.confirm("Schedule cancellation for the end of the current billing period?")&&M("cancel",()=>xe("/subscription/cancel",{idempotency:Ne("cancel")}),"Cancellation was scheduled for the end of the billing period.")},className:"rounded-lg border border-red-400/20 px-3 py-2 text-xs text-red-200 disabled:opacity-50",children:"Cancel at period end"}),i&&(0,e.jsx)("p",{role:"status",className:"text-xs text-basalt-300",children:i})]})}function ea(a){return`$${Math.max(0,Number(a)||0).toFixed(2)}`}function De({label:a,usage:r}){if(!r)return null;const l=Number(r.limit)>0,s=l?Math.min(100,Number(r.used||0)/Number(r.limit)*100):0;return(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 p-4",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-3 text-[10px]",children:[(0,e.jsx)("span",{className:"font-semibold text-basalt-200",children:a}),(0,e.jsxs)("span",{className:"text-basalt-500",children:[Number(r.used||0).toLocaleString(),l?` / ${Number(r.limit).toLocaleString()}`:""]})]}),(0,e.jsx)("div",{className:"mt-3 h-1.5 overflow-hidden rounded-full bg-basalt-800",children:(0,e.jsx)("div",{className:"h-full rounded-full bg-accent-cyan",style:{width:`${s}%`}})}),(0,e.jsx)("p",{className:"mt-2 text-[9px] text-basalt-600",children:l?`${Number(r.remaining||0).toLocaleString()} remaining this month`:"Not included with the current plan"})]})}function Gn({usage:a}){return a?(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 p-4 sm:col-span-2",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 text-[10px]",children:[(0,e.jsx)("span",{className:"font-semibold text-basalt-200",children:"Shared hosted storage"}),(0,e.jsxs)("span",{className:"text-basalt-500",children:[z(a.usedBytes||0,1)," / ",z(a.limitBytes||0)]})]}),(0,e.jsx)("div",{className:"mt-3 h-1.5 overflow-hidden rounded-full bg-basalt-800",children:(0,e.jsx)("div",{className:"h-full rounded-full bg-accent-cyan",style:{width:`${Math.min(100,Number(a.percent||0))}%`}})}),(0,e.jsxs)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-600",children:[z(a.remainingBytes||0,1)," remaining · ",z(a.contentBytes||0,1)," Markdown · ",z(a.attachmentBytes||0,1)," attachments · ",z(a.signingBytes||0,1)," E-Sign · ",z(a.privateExchangeBytes||0,1)," Private Exchange"]})]}):null}function Vn({user:a}){const[r,l]=(0,o.useState)(null),[s,m]=(0,o.useState)(!1),[j,p]=(0,o.useState)(""),f=a?.id,u=a?.localOnly,[E,c]=(0,o.useState)(!1),x=async()=>{c(!0),p("");try{const i=await fetch("/api/billing/history/download",{credentials:"include"});if(!i.ok)throw new Error("Unable to download billing history. Please try again.");await Qs("phasoric-billing-history.csv",await i.text(),"text/csv;charset=utf-8")}catch(i){p(i.message)}finally{c(!1)}},w=(0,o.useCallback)(async()=>
2{if(!(!f||u)){m(!0),p("");try{const i=await fetch("/api/billing/history",{credentials:"include"}),C=await i.json().catch(()=>({}));if(!i.ok)throw new Error(C.error||"Unable to load billing and usage history.");l(C)}catch(i){p(i.message)}finally{m(!1)}}},[u,f]);if((0,o.useEffect)(()=>{const i=ge()&&new URLSearchParams(window.location.search).get("credit_setup");i?fetch("/api/billing/credit-setup/verify",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:i})}).then(async C=>{if(!C.ok)throw new Error((await C.json()).error||"Payment setup needs attention.");const b=new URL(window.location.href);b.searchParams.delete("credit_setup"),window.history.replaceState(null,"",b),await w()}).catch(C=>p(C.message)):w()},[w]),a?.localOnly)return(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Billing & Usage"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Subscriptions, purchases, and hosted usage are available for hosted accounts."})]}),(0,e.jsx)("div",{className:"rounded-xl border border-dashed border-basalt-800 p-5 text-center text-xs text-basalt-500",children:"This local-only profile has no hosted billing or usage history."})]});const y=r?.subscription,$=r?.aiCredits,v=r?.aiTransactions||[],I=r?.invoices||[];return(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Billing & Usage"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Track your subscription, purchases, Phasoric Credits, and monthly plan usage."})]}),(0,e.jsx)("div",{className:"flex items-center gap-2",children:(0,e.jsx)("button",{type:"button",onClick:w,disabled:s,className:"rounded-lg border border-basalt-700 p-2 text-basalt-400 hover:text-white disabled:opacity-50","aria-label":"Refresh billing and usage",children:(0,e.jsx)(Se,{size:13,className:s?"animate-spin":""})})})]}),j&&(0,e.jsx)("div",{className:"rounded-lg border border-red-400/20 bg-red-400/[.04] p-3 text-[10px] text-red-200",children:j}),r?.owner&&(0,e.jsx)(Bn,{owner:r.owner,initialSettings:r.creditSettings,onChanged:w}),y?(0,e.jsx)(Hn,{subscription:y,onChanged:w}):s?(0,e.jsx)("div",{className:"rounded-xl border border-dashed border-basalt-800 p-4 text-center text-[10px] text-basalt-600",children:"Loading subscription controlsâ¦"}):null,(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 p-4",children:[(0,e.jsx)(pt,{size:15,className:"text-accent-cyan"}),(0,e.jsx)("p",{className:"mt-3 text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:"Subscription"}),(0,e.jsx)("p",{className:"mt-1 text-sm font-semibold",children:y?.tier||a?.tier||"Free Tier"}),(0,e.jsxs)("p",{className:"mt-1 text-[9px] uppercase text-basalt-500",children:[y?.status||"active",y?.cancelAtPeriodEnd?" · ends this period":"",y?.seatQuantity>1?` · ${y.seatQuantity} seats`:""]}),y?.currentPeriodEnd&&(0,e.jsxs)("p",{className:"mt-1 text-[9px] text-basalt-600",children:["Current period ends ",new Date(y.currentPeriodEnd).toLocaleDateString()]})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 p-4",children:[(0,e.jsx)(Za,{size:15,className:"text-amber-300"}),(0,e.jsx)("p",{className:"mt-3 text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:"Purchased and starter credits"}),(0,e.jsx)("p",{className:"mt-1 text-sm font-semibold",children:Q($?.balanceCredits)}),(0,e.jsx)("p",{className:"mt-1 text-[9px] text-basalt-500",children:"Available after included credits · Never expires · Retained after downgrade"})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 p-4",children:[(0,e.jsx)(_t,{size:15,className:"text-violet-300"}),(0,e.jsx)("p",{className:"mt-3 text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:"Included this month"}),(0,e.jsxs)("p",{className:"mt-1 text-sm font-semibold",children:[Q($?.allowanceRemainingCredits)," credits"]}),(0,e.jsxs)("p",{className:"mt-1 text-[9px] text-basalt-500",children:[Q($?.monthlyAllowanceCredits)," included · ",Q($?.allowanceUsedCredits)," used"]})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/50 p-4",children:[(0,e.jsx)(_t,{size:15,className:"text-emerald-300"}),(0,e.jsx)("p",{className:"mt-3 text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:"Available"}),(0,e.jsxs)("p",{className:"mt-1 text-sm font-semibold",children:[Q($?.availableCredits)," credits"]}),(0,e.jsx)("p",{className:"mt-1 text-[9px] text-basalt-500",children:"Included and purchased credits available for new requests"})]})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 p-4 text-xs leading-6 text-basalt-400",children:[(0,e.jsxs)("p",{children:[(0,e.jsxs)("strong",{className:"text-basalt-100",children:[Q($?.reservedCredits)," credits reserved"]})," by running requests: ",Q($?.allowanceReservedCredits)," included + ",Q($?.purchasedReservedCredits)," purchased. Reservations are excluded from available credits."]}),(0,e.jsxs)("p",{children:["Included credits expire at ",$?.includedExpiresAt?new Date($.includedExpiresAt).toLocaleStr
2ing():"the next calendar month"," (reset: 00:00 UTC on the first). A new allowance is granted only for a funded subscription month. Final-month included credits remain through month end even if paid access ends earlier."]}),(0,e.jsx)("p",{children:"Platform failures incur no charge. Canceling delivery of a submitted request may allow that work to finish; you pay its actual metered cost. Unused reservations are released."})]}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Monthly plan usage"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] text-basalt-500",children:"Current calendar-month operations and the one storage pool shared by every hosted feature."})]}),(0,e.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,e.jsx)(Gn,{usage:r?.usage?.hostedStorage}),(0,e.jsx)(De,{label:"Connected intelligence operations",usage:r?.usage?.connectedIntelligence}),(0,e.jsx)(De,{label:"Hosted MCP operations",usage:r?.usage?.mcp}),(0,e.jsx)(De,{label:"Developer API operations",usage:r?.usage?.developerApi}),(0,e.jsx)(De,{label:"Native E-Sign envelopes",usage:r?.usage?.nativeSigning}),(0,e.jsx)(De,{label:"Private Exchanges",usage:r?.usage?.privateExchange})]}),r?.usage?.nativeSigning||r?.usage?.privateExchange?(0,e.jsxs)("div",{className:"grid gap-2 text-[9px] leading-4 text-basalt-500 sm:grid-cols-2",children:[r?.usage?.nativeSigning?(0,e.jsxs)("p",{className:"rounded-lg border border-basalt-800 px-3 py-2",children:["E-Sign: ",Number(r.usage.nativeSigning.recipientsUsed||0).toLocaleString()," of ",Number(r.usage.nativeSigning.recipientsLimit||0).toLocaleString()," recipients · ",z(r.usage.nativeSigning.storageUsedBytes||0,1)," retained in the shared hosted-storage pool."]}):null,r?.usage?.privateExchange?(0,e.jsxs)("p",{className:"rounded-lg border border-basalt-800 px-3 py-2",children:["Private Exchange: ",z(r.usage.privateExchange.storageUsedBytes||0,1)," retained in the shared hosted-storage pool · up to ",z(r.usage.privateExchange.maxFileBytes||0)," per participant package."]}):null]}):null]}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Phasoric Credit activity"}),(0,e.jsx)("button",{type:"button",onClick:x,disabled:E,className:"text-xs text-accent-cyan disabled:opacity-50",children:E?"Preparing CSVâ¦":"Download billing history (CSV)"})]}),(0,e.jsx)("p",{className:"mt-1 text-[10px] text-basalt-500",children:"Purchases, usage, running reservations, and releases. Each release is a returned hold, not a cash refund."})]}),v.length?(0,e.jsx)("div",{className:"overflow-x-auto rounded-xl border border-basalt-800",children:(0,e.jsxs)("table",{className:"w-full text-left text-[10px]",children:[(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{className:"border-b border-basalt-800 bg-basalt-950/60 text-basalt-500",children:[(0,e.jsx)("th",{className:"px-3 py-2 font-medium",children:"Date"}),(0,e.jsx)("th",{className:"px-3 py-2 font-medium",children:"Activity"}),(0,e.jsx)("th",{className:"px-3 py-2 font-medium",children:"Measurement"}),(0,e.jsx)("th",{className:"px-3 py-2 text-right font-medium",children:"Credits"})]})}),(0,e.jsx)("tbody",{className:"divide-y divide-basalt-800/50 text-basalt-300",children:v.map(i=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{className:"whitespace-nowrap px-3 py-2",children:new Date(i.date).toLocaleString()}),(0,e.jsx)("td",{className:"px-3 py-2 font-medium text-white",children:i.description||(i.type==="starter"?"One-time hosted AI starter allowance":i.type==="purchase"?`${i.quantity}x Phasoric Credit pack`:i.outcome==="user_canceled"?"Canceled request · actual usage":"Hosted intelligence request")}),(0,e.jsx)("td",{className:"px-3 py-2 text-basalt-500",children:i.type==="reversal"?`${Q(i.creditAmountCredits)} credits removed after a Google Play refund`:["reservation","release"].includes(i.type)?`${Q(i.reservedCredits)} credits ${i.type==="release"?"released · no charge":"held · not yet charged"}`:i.type==="starter"?"Included at no charge":i.type==="purchase"?`${Q(i.creditAmountCredits)} credits added${i.purchaseAmount!=null?` · ${ea(i.purchaseAmount)} paid`:""}
2`:`${Number(i.inputTokens||0).toLocaleString()} input · ${Number(i.outputTokens||0).toLocaleString()} output · ${Q(i.allowanceCredits)} included credits · ${Q(i.releasedCredits)} released`}),(0,e.jsx)("td",{className:`whitespace-nowrap px-3 py-2 text-right font-semibold ${["usage","reversal"].includes(i.type)?"text-amber-200":"text-emerald-300"}`,children:["reservation","release"].includes(i.type)?"No charge":(0,e.jsxs)(e.Fragment,{children:[["usage","reversal"].includes(i.type)?"â":"+",Q(i.type==="usage"?i.usageCredits:i.creditAmountCredits)]})})]},i.id))})]})}):(0,e.jsx)("div",{className:"rounded-xl border border-dashed border-basalt-800 p-4 text-center text-[10px] text-basalt-600",children:s?"Loading Phasoric Credit activityâ¦":"No hosted intelligence activity yet."})]}),r?.nextCreditCursor&&(0,e.jsx)("button",{type:"button",disabled:s,className:"rounded-lg border border-basalt-700 px-4 py-2 text-xs",onClick:async()=>{m(!0);try{const i=await fetch(`/api/billing/history/credits?cursor=${encodeURIComponent(r.nextCreditCursor)}`,{credentials:"include"}),C=await i.json();if(!i.ok)throw new Error(C.error||"Unable to load history.");l(b=>({...b,aiTransactions:[...b.aiTransactions,...C.aiTransactions],nextCreditCursor:C.nextCursor}))}catch(i){p(i.message)}finally{m(!1)}},children:"Load older credit activity"}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Refunds and disputes"}),(0,e.jsx)("p",{className:"text-xs text-basalt-400",children:"Google Play purchases follow Google Playâs refund process. Canceling renewal does not itself issue a refund."}),ge()&&(0,e.jsx)("p",{className:"text-xs text-basalt-400",children:"For purchases billed directly by Phasoric, subscription refunds cover unused subscription time based on the amount paid. AI credits are non-refundable and do not reduce the subscription refund. Contact support for a prorated subscription refund."}),[...(r?.refunds||[]).map(i=>({...i,id:i.refund_id,label:"Refund"})),...(r?.disputes||[]).map(i=>({...i,id:i.dispute_id,label:"Dispute"}))].map(i=>(0,e.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 rounded-lg border border-basalt-800 p-3 text-xs",children:[(0,e.jsxs)("span",{children:[i.label," · ",new Date(i.created_at).toLocaleDateString()]}),(0,e.jsxs)("span",{children:[i.currency.toUpperCase()," ",(Number(i.amount_cents)/100).toFixed(2)," · ",i.status.replaceAll("_"," ")]})]},i.id)),!r?.refunds?.length&&!r?.disputes?.length&&(0,e.jsx)("p",{className:"text-xs text-basalt-500",children:"No refunds or disputes recorded."})]}),(0,e.jsxs)("section",{className:"space-y-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Subscription invoices"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] text-basalt-500",children:"Stripe receipts for recurring subscription payments."})]}),I.length?(0,e.jsx)("div",{className:"overflow-x-auto rounded-xl border border-basalt-800",children:(0,e.jsxs)("table",{className:"w-full text-left text-[10px]",children:[(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{className:"border-b border-basalt-800 bg-basalt-950/60 text-basalt-500",children:[(0,e.jsx)("th",{className:"px-3 py-2 font-medium",children:"Date"}),(0,e.jsx)("th",{className:"px-3 py-2 font-medium",children:"Description"}),(0,e.jsx)("th",{className:"px-3 py-2 font-medium",children:"Amount"}),(0,e.jsx)("th",{className:"px-3 py-2 text-right font-medium",children:"Receipt"})]})}),(0,e.jsx)("tbody",{className:"divide-y divide-basalt-800/50 text-basalt-300",children:I.map(i=>(0,e.jsxs)("tr",{children:[(0,e.jsx)("td",{className:"whitespace-nowrap px-3 py-2",children:new Date(i.date).toLocaleDateString()}),(0,e.jsx)("td",{className:"px-3 py-2 font-medium text-white",children:i.description}),(0,e.jsxs)("td",{className:"px-3 py-2",children:[ea(i.amountPaid)," ",i.currency]}),(0,e.jsx)("td",{className:"px-3 py-2 text-right",children:ge()&&i.pdfUrl?(0,e.jsxs)("a",{href:i.pdfUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-accent-cyan hover:underline",children:["View ",(0,e.jsx)(Te,{size:10})]}):(0,e.jsx)("span",{className:"text-basalt-600",children:", "})})]},i.id))})]})}):(0,e.jsx)("div",{className:"rounded-xl border border-dashed border-basalt-800 p-4 text-center text-[10px] text-basalt-600",children:s?"Loading subscription invoicesâ¦":"No subscription invoices yet."})]})]})}function qn(a,r){const l=r==="microsoft"?"outlook":"gmail";return{title:a.subject,captureType:"email",sourceUrl:a.webLink,tags:[r,l,"external-reference"],externalReference:{provider:r,objectType:"mail-message",externalId:a.externalId},content:[`From: ${a.from||"Unknown sender"}`,`Received: ${a.receivedAt||"Unknown time"}`,"",a.bodyPreview||"No message preview was returned.","",`External reference: ${r}/mail-message/${a.externalId}`].join(` 3`)}}function Wn(a){return{title:a.name,captureType:"note",sourceUrl:a.webUrl,tags:["microsoft","onedrive","external-reference"],externalReference:{provider:"microsoft",objectType:a.kind==="folder"?"drive-folder":"drive-file",externalId:a.externalId},content:[`OneDrive ${a.kind}: ${a.name}`,`Last modified: ${a.lastModifiedAt||"Unknown time"}`,a.kind==="folder"?`Children: ${a.childCount}`:`Size: ${a.size} bytes${a.mimeType?` · ${a.mimeType}`:""}`,"",`External reference: microsoft/${a.kind==="folder"?"drive-folder":"drive-file"}/${a.externalId}`].join(` 4`)}}function Kn({connection:a}){const[r,l]=(0,o.useState)([]),[s,m]=(0,o.useState)([]),[j,p]=(0,o.useState)(""),[f,u]=(0,o.useState)(""),E=async w=>{p(w),u("");try{if(w==="mail"){const y=await tn(a.id,{limit:12});l(y.messages||[]),u(`${y.messages?.length||0} ${a.provider==="microsoft"?"Outlook":"Gmail"} messages loaded as temporary context. Nothing was saved.`)}else{const y=await en(a.id,{limit:12});m(y.items||[]),u(`${y.items?.length||0} OneDrive items loaded as temporary context. Nothing was saved.`)}}catch(y){u(y.message)}finally{p("")}},c=async(w,y)=>{p(`${y}:${w.externalId}`),u("");try{const $=await jn(y==="mail"?qn(w,a.provider):Wn(w)),v=await Nn($);u(`Captured locally as ${v.path}. The Microsoft source reference remains attached to the note.`),window.dispatchEvent(new CustomEvent("notes-updated"))}catch($){u($.message)}finally{p("")}},x=[{id:"mail",label:a.provider==="microsoft"?"Outlook mail":"Gmail",icon:ss,rows:r,capability:"mail.messages.read"},{id:"drive",label:"OneDrive root",icon:xt,rows:s,capability:"drive.files.read"}].filter(w=>
4a.capabilities?.includes(w.capability)&&(w.id!=="drive"||a.provider==="microsoft"));return(0,e.jsxs)("div",{className:"mt-4 rounded-xl border border-violet-300/10 bg-violet-300/[.02] p-3",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"text-[9px] font-bold uppercase tracking-wider text-violet-200",children:"Temporary context and explicit capture"}),(0,e.jsx)("p",{className:"mt-1 text-[9px] leading-4 text-basalt-500",children:"Preview data stays in this screen only. Use Capture locally on an individual item to create portable Markdown."})]}),(0,e.jsx)("span",{className:"rounded-full border border-violet-300/15 px-2 py-1 text-[8px] uppercase text-violet-200",children:"Not persisted by server"})]}),(0,e.jsx)("div",{className:"mt-3 grid gap-3 lg:grid-cols-2",children:x.map(w=>(0,e.jsxs)("section",{className:"rounded-lg border border-white/[.06] bg-black/20 p-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-[10px] font-semibold text-white",children:[(0,e.jsx)(w.icon,{size:12,className:"text-cyan-300"}),w.label]}),(0,e.jsxs)("button",{type:"button",disabled:!!j,onClick:()=>E(w.id),className:"inline-flex min-h-9 items-center gap-1.5 rounded-lg border border-cyan-300/15 px-2.5 text-[9px] text-cyan-200 disabled:opacity-40",children:[j===w.id?(0,e.jsx)(Re,{className:"animate-spin",size:11}):(0,e.jsx)(Te,{size:11}),"Preview"]})]}),w.rows.length?(0,e.jsx)("div",{className:"mt-3 max-h-72 space-y-2 overflow-y-auto",children:w.rows.map(y=>(0,e.jsxs)("article",{className:"rounded-lg border border-white/[.05] p-2.5",children:[(0,e.jsx)("div",{className:"text-[9px] font-semibold text-basalt-200",children:w.id==="mail"?y.subject:y.name}),(0,e.jsx)("div",{className:"mt-1 line-clamp-2 text-[8px] leading-4 text-basalt-600",children:w.id==="mail"?`${y.from||"Unknown sender"} · ${y.bodyPreview||"No preview"}`:`${y.kind} · ${y.lastModifiedAt||"Unknown modification time"}`}),(0,e.jsxs)("button",{type:"button",disabled:!!j,onClick:()=>c(y,w.id),className:"mt-2 inline-flex min-h-9 items-center gap-1.5 rounded-lg border border-emerald-300/15 px-2.5 text-[8px] text-emerald-200 disabled:opacity-40",children:[j===`${w.id}:${y.externalId}`?(0,e.jsx)(Re,{className:"animate-spin",size:10}):(0,e.jsx)(as,{size:10}),"Capture locally"]})]},y.externalId))}):(0,e.jsx)("p",{className:"mt-3 text-[8px] text-basalt-600",children:"Choose Preview to inspect a bounded provider response."})]},w.id))}),f?(0,e.jsx)("p",{className:"mt-3 text-[9px] text-cyan-100",role:"status",children:f}):null]})}function Qn(){const a=new URLSearchParams(window.location.search),r=a.get("connection");if(!["google","microsoft","dropbox","github"].includes(r))return"";const l=r==="google"?"Google":r==="microsoft"?"Microsoft":r==="dropbox"?"Dropbox":"GitHub";return a.get("status")==="connected"?`${l} is linked to this Phasoric account. Credentials remain on the server.`:a.get("status")==="error"?`${l} could not be linked. Try again; if access was previously granted, revoke it at ${l} and reconnect.`:""}var Yn=[{id:"google",label:"Google",detail:"Choose Calendar and Gmail for connected context, or use Drive for vault sync."},{id:"microsoft",label:"Microsoft",detail:"Read approved Calendar, Outlook, and OneDrive information. External changes still require your review in Forge."},{id:"dropbox",label:"Dropbox",detail:"Keep a Markdown vault and its attachments in a Dropbox folder you choose."},{id:"github",label:"GitHub",detail:"Connect one repository from Vault storage settings. Phasoric protects the repository key after you submit it."}],Jn=Object.freeze({"calendar.events.read":"Calendar","mail.messages.read":"Mail","drive.files.read":"Files","drive.files.write":"File changes","vault.files.read":"Vault files","vault.files.write":"Vault changes","repository.contents.read":"Repository files","repository.contents.write":"Repository changes"});
4function Zn(a){return Jn[a]||String(a||"").split(".").filter(Boolean).map(r=>r[0]?.toUpperCase()+r.slice(1)).join(" ")}function Xn({user:a}){const[r,l]=(0,o.useState)({available:!1,configured:{},usage:{},connections:[]}),[s,m]=(0,o.useState)(!1),[j,p]=(0,o.useState)(Qn),f=async()=>{if(!a?.localOnly)try{const c=await ct();l({available:!1,configured:{},usage:{},...c,connections:Array.isArray(c?.connections)?c.connections:[]})}catch(c){p(Z(c,{provider:"Connections"}))}};(0,o.useEffect)(()=>{f()},[a?.id,a?.localOnly]);const u=async c=>{m(!0),p(`Opening ${c==="google"?"Google":c==="microsoft"?"Microsoft":"Dropbox"} authorizationâ¦`);try{c==="google"?await oa({services:["calendar","gmail"],returnTab:"connections"}):c==="microsoft"?await Xs({services:["calendar","mail","drive"],returnTab:"connections"}):await la({returnTab:"connections"})}catch(x){p(Z(x,{provider:c==="google"?"Google":c==="microsoft"?"Microsoft":"Dropbox"})),m(!1)}},E=async c=>{m(!0),ca(c.id);const x=Ts(c.id);for(const w of x)dt(w);Rs(r.connections.filter(w=>w.id!==c.id));try{await ia(c.id);const w=c.provider==="google"?"Google":c.provider==="microsoft"?"Microsoft":c.provider==="dropbox"?"Dropbox":"GitHub";p(`${w} access was revoked, its encrypted server credentials were removed, and linked vault mappings were disconnected. Local vault data was not changed.`),await f()}catch(w){const y=c.provider==="google"?"Google":c.provider==="microsoft"?"Microsoft":c.provider==="github"?"GitHub":"Dropbox";p(`${y} vault sync was stopped and its local mappings were removed. ${Z(w,{provider:y})} Retry account revocation here.`)}finally{m(!1)}};return a?.localOnly?(0,e.jsx)("div",{className:"rounded-xl border border-cyan-300/15 bg-cyan-300/[.03] p-5 text-xs leading-5 text-basalt-400",children:"Create a Free Phasoric account to connect an external service securely. Third-party credentials are not stored in a local-only browser profile."}):(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Connections"}),(0,e.jsx)("p",{className:"mt-1 text-xs leading-5 text-basalt-500",children:"Connect services without storing their sign-in credentials in this browser. A GitHub repository key is submitted once and then protected with your Phasoric account."})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-violet-300/15 bg-violet-300/[.03] p-4 text-[10px] leading-5 text-basalt-400",children:[(0,e.jsx)(Ce,{className:"mr-1 inline text-violet-300",size:13}),(0,e.jsx)("strong",{className:"text-violet-200",children:"Your control:"})," note search and ranking continue to work offline. Phasoric only reads the connected information you approve, and external changes still require review."]}),Yn.map(c=>{const x=r.connections.find(y=>y.provider===c.id),w=x&&(c.id==="google"&&!x.capabilities.includes("mail.messages.read")||c.id==="microsoft"&&["calendar.events.read","mail.messages.read","drive.files.read"].some(y=>!x.capabilities.includes(y)));return(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 bg-basalt-950/55 p-4",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(ut,{size:14,className:"text-cyan-300"}),(0,e.jsx)("h3",{className:"text-sm font-semibold",children:c.label}),x?(0,e.jsx)("span",{className:"rounded-full bg-emerald-300/10 px-2 py-1 text-[8px] font-bold uppercase text-emerald-300",children:"Connected"}):null]}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-500",children:c.detail})]}),x?(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[w?(0,e.jsxs)("button",{type:"button",disabled:s||!r.configured?.[c.id],onClick:()=>u(c.id),className:"inline-flex min-h-10 items-center gap-2 rounded-lg border border-cyan-300/20 px-3 text-[10px] text-cyan-200 disabled:opacity-40",children:[(0,e.jsx)(Te,{size:12}),"Add read services"]}):null,(0,e.jsxs)("button",{type:"button",disabled:s,onClick:()=>E(x),className:"inline-flex min-h-10 items-center gap-2 rounded-lg border border-red-300/20 px-3 text-[10px] text-red-200 disabled:opacity-40",children:[(0,e.jsx)(hs,{size:12}),"Revoke"]})]}
4):c.id==="github"?(0,e.jsxs)("a",{href:"/app/settings?tab=sync",className:"inline-flex min-h-10 items-center gap-2 rounded-lg border border-cyan-300/20 px-3 text-[10px] text-cyan-200",children:[(0,e.jsx)(Te,{size:12}),"Add repository token"]}):(0,e.jsxs)("button",{type:"button",disabled:s||!r.available||!r.configured?.[c.id],onClick:()=>u(c.id),className:"inline-flex min-h-10 items-center gap-2 rounded-lg bg-cyan-200 px-3 text-[10px] font-bold text-black disabled:opacity-40",children:[s?(0,e.jsx)(Re,{className:"animate-spin",size:12}):(0,e.jsx)(Te,{size:12}),"Connect ",c.label]})]}),x?(0,e.jsxs)("div",{className:"mt-4 grid gap-2 text-[9px] text-basalt-500 sm:grid-cols-2",children:[(0,e.jsxs)("span",{children:[(0,e.jsx)(ta,{className:"mr-1 inline text-emerald-300",size:11}),x.displayName||`${c.label} account`]}),(0,e.jsxs)("span",{children:["Access: ",x.capabilities.map(Zn).join(" · ")]}),(0,e.jsxs)("span",{children:["Last checked: ",x.lastCheckedAt?new Date(x.lastCheckedAt).toLocaleString():"Not yet"]}),(0,e.jsx)("span",{children:"Sign-in: protected by Phasoric"})]}):null,x&&["google","microsoft"].includes(x.provider)?(0,e.jsx)(Kn,{connection:x}):null,r.available&&!r.configured?.[c.id]?(0,e.jsxs)("p",{className:"mt-4 text-[10px] text-amber-200",children:[c.label," server connection setup is awaiting production configuration."]}):null]},c.id)}),r.available?null:(0,e.jsx)("p",{className:"text-[10px] text-amber-200",children:"This Phasoric account cannot currently create external connections."}),j?(0,e.jsx)("p",{className:"text-[10px] text-cyan-200",children:j}):null]})}function er(a){for(const r of[a?.clientUri,a?.clientId])try{const l=new URL(String(r||""));if(l.protocol==="https:")return l.hostname}catch{}return"Registered OAuth client"}function tr(a){return a==="mcp:read"?"Read vault context":a==="mcp:write"?"Create or change notes":a==="offline_access"?"Stay connected when you are away":a}function lt(a,r){if(!a)return r;const l=new Date(a);return Number.isNaN(l.getTime())?r:l.toLocaleString()}function ar({localOnly:a=!1}){const[r,l]=(0,o.useState)([]),[s,m]=(0,o.useState)(a?"Create an account to connect hosted applications.":"Loading connected applicationsâ¦"),[j,p]=(0,o.useState)(""),f=(0,o.useCallback)(async()=>{if(!a)try{const x=await fetch("/api/oauth/grants",{credentials:"include"}),w=await x.json().catch(()=>({}));if(!x.ok)throw new Error(w.error||"Unable to load connected applications.");l(Array.isArray(w.applications)?w.applications:[]),m("")}catch(x){m(x.message||"Unable to load connected applications.")}},[a]);(0,o.useEffect)(()=>{f()},[f]);const u=async x=>{p(x.id),m("");try{const w=await fetch(`/api/oauth/grants/${encodeURIComponent(x.id)}`,{method:"DELETE",credentials:"include"}),y=await w.json().catch(()=>({}));if(!w.ok)throw new Error(y.error||"Unable to revoke this application.");l($=>$.map(v=>v.id===x.id?{...v,status:"revoked",revokedAt:new Date().toISOString()}:v)),m(`${x.clientName} has been disconnected.`)}catch(w){m(w.message||"Unable to revoke this application.")}finally{p("")}},E=r.filter(x=>x.status==="connected"),c=r.filter(x=>x.status!=="connected");return(0,e.jsxs)("section",{className:"rounded-xl border border-accent-cyan/20 bg-accent-cyan/[.025] p-4","aria-labelledby":"connected-applications-title",children:[(0,e.jsxs)("div",{className:"flex items-start gap-3",children:[(0,e.jsx)("span",{className:"rounded-lg border border-accent-cyan/20 bg-accent-cyan/10 p-2 text-accent-cyan",children:(0,e.jsx)(ut,{size:15})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{id:"connected-applications-title",className:"text-sm font-semibold text-white",children:"Connected applications"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] leading-5 text-basalt-400",children:"OAuth clients appear here after you approve their exact access. Phasoric never shows or stores a reusable access token in this page."})]})]}),E.length?(0,e.jsx)("div",{className:"mt-4 space-y-3",children:E.map(x=>(0,e.jsx)("article",{className:"rounded-xl border border-white/[.07] bg-black/20 p-4",children:(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(Ce,{size:14,className:"shrink-0 text-emerald-300"}),(0,e.jsx)("strong",{className:"truncate text-xs text-white",children:x.clientName})]}),(0,e.jsx)("p",{className:"mt-1 truncate text-[10px] text-basalt-500",children:er(x)}),(0,e.jsx)("div",{className:"mt-3 flex flex-wrap gap-1.5",children:x.scopes.map(w=>(0,e.jsx)("span",{className:"rounded-full border border-white/10 bg-white/[.035] px-2 py-1 text-[9px] text-basalt-300",children:tr(w)},w))}),(0,e.jsxs)("p",{className:"mt-3 text-[9px] leading-4 text-basalt-500",children:["Connected ",lt(x.connectedAt,"recently")," · Last used ",lt(x.lastUsedAt,"not yet")]})]}),(0,e.jsxs)("button",{type:"button",disabled:j===x.id,onClick:()=>u(x),className:"inline-flex min-h-10 items-center justify-center gap-2 rounded-lg border border-red-300/25 px-3 text-[10px] font-semibold text-red-200 hover:border-red-300/50 disabled:opacity-50",children:[(0,e.jsx)(Me,{size:12}),j===x.id?"Disconnectingâ¦":"Disconnect"]})]})},x.id))}):!s&&(0,e.jsxs)("p",{className:"mt-4 rounded-lg border border-white/[.06] bg-black/15 px-3 py-3 text-[10px] leading-5 text-basalt-500",children:["No applications are connected. Add ",(0,e.jsx)("code",{className:"text-basalt-300",children:"https://phasoric.com/api/mcp"})," in a compatible MCP client to begin its OAuth consent flow."]}),c.length?(0,e.jsxs)("details",{className:"mt-4 text-[10px] text-basalt-500",children:[(0,e.jsxs)("summary",{className:"cursor-pointer hover:text-basalt-300",children:["Previously disconnected (",c.length,")"]}),(0,e.jsx)("ul",{className:"mt-2 space-y-1.5",children:c.map(x=>(0,e.jsxs)("li",{children:[x.clientName," · revoked ",lt(x.revokedAt,"previously")]},x.id))})]}
4):null,s&&(0,e.jsx)("p",{role:"status",className:"mt-3 text-[10px] leading-5 text-basalt-400",children:s})]})}async function sr(a,r="/"){const l=r==="/"||!r?"":r.replace(/\/+$/,""),s=await Ve(a,"https://api.dropboxapi.com/2/files/list_folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:l,recursive:!1,include_media_info:!1,include_deleted:!1,include_has_explicit_shared_members:!1,include_mounted_folders:!0,limit:200})});if(!s.ok){const j=await s.json().catch(()=>({}));throw new Error(j.error_summary||"Failed to list Dropbox folders.")}const m=((await s.json()).entries||[]).filter(j=>j[".tag"]==="folder").map(j=>({id:j.id||j.path_lower,name:j.name,path:j.path_display||j.path_lower,type:"folder"})).sort((j,p)=>j.name.localeCompare(p.name));return{currentPath:l||"/",folders:m}}async function nr(a,r="root"){const l=r||"root",s=`'${l}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false`,m=`https://www.googleapis.com/drive/v3/files?q=${encodeURIComponent(s)}&fields=${encodeURIComponent("files(id,name,mimeType,parents)")}&pageSize=200&orderBy=name`,j=await Ve(a,m,{method:"GET"});if(!j.ok){const p=await j.json().catch(()=>({}));throw new Error(p.error?.message||"Failed to list Google Drive folders.")}return{parentId:l,folders:((await j.json()).files||[]).map(p=>({id:p.id,name:p.name,type:"folder",parentId:l})).sort((p,f)=>p.name.localeCompare(f.name))}}async function rr(a){const r=await Ve(a,"https://api.github.com/user/repos?per_page=100&sort=updated",{method:"GET"});if(!r.ok){const s=await r.json().catch(()=>({}));throw new Error(s.message||"Failed to list GitHub repositories.")}const l=await r.json();return Array.isArray(l)?{repositories:l.map(s=>({id:s.id,name:s.name,fullName:s.full_name,owner:s.owner?.login||"",defaultBranch:s.default_branch||"main",private:!!s.private})).sort((s,m)=>s.fullName.localeCompare(m.fullName))}:{repositories:[]}}async function or(a,r,l=""){if(!r)throw new Error("Repository full name (owner/repo) is required.");const s=String(l||"").replace(/^\/+|\/+$/g,""),m=`https://api.github.com/repos/${r}/contents/${encodeURIComponent(s)}`,j=await Ve(a,m,{method:"GET"});if(!j.ok){const f=await j.json().catch(()=>({}));throw new Error(f.message||"Failed to list GitHub repository path.")}const p=await j.json();return Array.isArray(p)?{ownerRepo:r,currentPath:s,folders:p.filter(f=>f.type==="dir").map(f=>({id:f.sha||f.path,name:f.name,path:f.path,type:"folder"})).sort((f,u)=>f.name.localeCompare(u.name))}:{currentPath:s,folders:[]}}function lr({isOpen:a,onClose:r,onSelect:l,provider:s,connectionId:m,initialPath:j="",initialFolderId:p="",initialRepo:f=""}){const[u,E]=(0,o.useState)(!1),[c,x]=(0,o.useState)(""),[w,y]=(0,o.useState)(""),[$,v]=(0,o.useState)(j||"/"),[I,i]=(0,o.useState)(p||"root"),[C,b]=(0,o.useState)(f||""),[F,S]=(0,o.useState)(""),[M,N]=(0,o.useState)([{id:"root",name:"My Drive"}]),[_,G]=(0,o.useState)([]),[B,de]=(0,o.useState)([]);(0,o.useEffect)(()=>{!a||!m||(x(""),y(""),s==="dropbox"?se(j||"/"):s==="google"?ne(p||"root"):s==="github"&&(f?(b(f),k(f,"")):ie()))},[a,m,s]);const se=async L=>{E(!0),x("");try{const R=await sr(m,L);v(R.currentPath),G(R.folders||[])}catch(R){x(R.message||"Failed to load Dropbox folders.")}finally{E(!1)}},ne=async L=>{E(!0),x("");try{const R=await nr(m,L);i(R.parentId),G(R.folders||[])}catch(R){x(R.message||"Failed to load Google Drive folders.")}finally{E(!1)}},ie=async()=>{E(!0),x("");try{const L=await rr(m);de(L.repositories||[]),b(""),G([])}catch(L){x(L.message||"Failed to list GitHub repositories.")}finally{E(!1)}},k=async(L,R)=>{E(!0),x("");try{const te=await or(m,L,R);b(L),S(te.currentPath),G(te.folders||[])}catch(te){x(te.message||"Failed to load GitHub repository contents.")}finally{E(!1)}},D=(0,o.useMemo)(()=>{const L=w.trim().toLowerCase();return s==="github"&&!C?L?B.filter(R=>R.fullName.toLowerCase().includes(L)):B:L?_.filter(R=>R.name.toLowerCase().includes(L)):_},[w,s,C,B,_]);if(!a)return null;const V=L=>{s==="dropbox"?se(L.path):s==="google"?(N(R=>[...R,{id:L.id,name:L.name}]),ne(L.id)):s==="github"&&(C?k(C,L.path):(b(L.fullName),k(L.fullName,"")))},X=L=>
4{if(s==="dropbox"){const R=$.split("/").filter(Boolean).slice(0,L),te=R.length===0?"/":"/"+R.join("/");se(te)}else if(s==="google"){const R=M.slice(0,L+1);N(R);const te=R[R.length-1];ne(te.id)}else if(s==="github")if(L===-1)ie();else{const R=F.split("/").filter(Boolean).slice(0,L).join("/");k(C,R)}},Ee=()=>{if(s==="dropbox")l({remotePath:$,label:$});else if(s==="google"){const L=M[M.length-1];l({remoteFolderId:I,label:L?L.name:"My Drive"})}else s==="github"&&l({repository:C,remotePath:F,label:`${C}${F?`/${F}`:""}`});r()};return(0,e.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4 backdrop-blur-sm",children:(0,e.jsxs)("div",{className:"w-full max-w-xl space-y-4 rounded-2xl border border-white/10 bg-basalt-950 p-6 shadow-2xl",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between border-b border-white/10 pb-3",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(It,{className:"text-cyan-300",size:18}),(0,e.jsxs)("h2",{className:"font-outfit text-base font-semibold text-white",children:["Select ",s==="google"?"Google Drive":s==="dropbox"?"Dropbox":"GitHub"," Folder"]})]}),(0,e.jsx)("button",{type:"button",onClick:r,className:"rounded-lg p-1 text-basalt-400 hover:bg-white/10 hover:text-white",children:(0,e.jsx)(na,{size:16})})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 rounded-xl border border-white/[.06] bg-black/30 px-3 py-2 text-xs text-basalt-300",children:[s==="dropbox"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",onClick:()=>X(0),className:"hover:text-cyan-300",children:"Root"}),$.split("/").filter(Boolean).map((L,R)=>(0,e.jsxs)(o.Fragment,{children:[(0,e.jsx)(Ae,{size:12,className:"text-basalt-600"}),(0,e.jsx)("button",{type:"button",onClick:()=>X(R+1),className:"hover:text-cyan-300",children:L})]},R))]}),s==="google"&&M.map((L,R)=>(0,e.jsxs)(o.Fragment,{children:[R>0&&(0,e.jsx)(Ae,{size:12,className:"text-basalt-600"}),(0,e.jsx)("button",{type:"button",onClick:()=>X(R),className:"hover:text-cyan-300",children:L.name})]},L.id)),s==="github"&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",onClick:()=>X(-1),className:"hover:text-cyan-300",children:"Repositories"}),C&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ae,{size:12,className:"text-basalt-600"}),(0,e.jsx)("span",{className:"font-semibold text-white",children:C}),F.split("/").filter(Boolean).map((L,R)=>(0,e.jsxs)(o.Fragment,{children:[(0,e.jsx)(Ae,{size:12,className:"text-basalt-600"}),(0,e.jsx)("button",{type:"button",onClick:()=>X(R+1),className:"hover:text-cyan-300",children:L})]},R))]})]})]}),(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsx)(cs,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-basalt-500"}),(0,e.jsx)("input",{type:"text",value:w,onChange:L=>y(L.target.value),placeholder:s==="github"&&!C?"Filter repositoriesâ¦":"Filter foldersâ¦",className:"w-full rounded-xl border border-white/10 bg-black/40 py-2 pl-9 pr-3 text-xs text-white placeholder-basalt-600 outline-none focus:border-cyan-300/40"})]}),(0,e.jsxs)("div",{className:"max-h-64 min-h-48 overflow-y-auto rounded-xl border border-white/[.07] bg-black/20 p-2 space-y-1",children:[u&&(0,e.jsxs)("div",{className:"flex min-h-40 items-center justify-center text-xs text-basalt-400",children:[(0,e.jsx)(Re,{className:"mr-2 animate-spin text-cyan-300",size:16}),"Loading remote directoryâ¦"]}),!u&&c&&(0,e.jsxs)("div",{className:"p-4 text-center text-xs text-amber-200",children:[(0,e.jsx)("p",{children:c}),(0,e.jsxs)("button",{type:"button",onClick:()=>{s==="dropbox"?se($):s==="google"?ne(I):s==="github"&&(C?k(C,F):ie())},className:"mt-2 inline-flex items-center gap-1 rounded-lg border border-amber-300/30 px-2.5 py-1 text-[10px] text-amber-100 hover:bg-amber-300/10",children:[(0,e.jsx)(Se,{size:10})," Retry"]})]}),!u&&!c&&D.length===0&&(0,e.jsx)("div",{className:"flex min-h-36 items-center justify-center text-xs text-basalt-500",children:"No subfolders or matches found in this directory."}),!u&&!c&&D.map((L,R)=>(0,e.jsxs)("button",{type:"button",onClick:()=>V(L),className:"flex w-full items-center justify-between rounded-lg p-2.5 text-left text-xs text-basalt-200 hover:bg-white/[.06] hover:text-white",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0",children:[s==="github"&&!C?(0,e.jsx)(An,{size:16,className:"shrink-0 text-cyan-300"}):(0,e.jsx)(It,{size:16,className:"shrink-0 text-cyan-300/80"}),(0,e.jsx)("span",{className:"truncate font-medium",children:L.fullName||L.name})]}),(0,e.jsx)(Ae,{size:14,className:"shrink-0 text-basalt-600"})]},L.id||R))]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-white/10 pt-4",children:[(0,e.jsxs)("div",{className:"text-[10px] text-basalt-400",children:["Selected:"," ",(0,e.jsx)("span",{className:"font-semibold text-cyan-200",children:s==="dropbox"?$:s==="google"?M[M.length-1]?.name||"My Drive":C?`${C}${F?`/${F}`:""}`:"Select a repository"})]}),(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsx)("button",{type:"button",onClick:r,className:"rounded-lg border border-basalt-700 px-3.5 py-2 text-xs text-basalt-300 hover:text-white",children:"Cancel"}),(0,e.jsx)("button",{type:"button",disabled:s==="github"&&!C,onClick:Ee,className:"rounded-lg bg-cyan-300 px-4 py-2 text-xs font-bold text-basalt-950 hover:bg-cyan-200 disabled:opacity-40",children:"Select This Folder"})]})]})]})})}function ir({isOpen:a,onClose:r,onConfirm:l,noteCount:s=0}){const[m,j]=(0,o.useState)(""),[p,f]=(0,o.useState)(""),[u,E]=(0,o.useState)(!1),[c,x]=(0,o.useState)(""),[w,y]=(0,o.useState)(!1);if(o.useEffect(()=>{if(!a)return;const v=I=>{I.key==="Escape"&&r?.()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[a,r]),!a)return null;const $=async v=>{if(v.preventDefault(),x(""),m.length<10)return x("Passphrase must be at least 10 characters long.");if(m!==p)return x("Passphrases do not match.");if(!u)return x("You must acknowledge the encryption notice to proceed.");y(!0);try{await l(m),j(""),f(""),E(!1),r()}catch(I){x(I.message||"Failed to enable vault encryption.")}finally{y(!1)}};return(0,e.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4 backdrop-blur-sm",role:"dialog","aria-modal":"true",children:(0,e.jsxs)("div",{className:"relative w-full max-w-lg overflow-hidden rounded-2xl border border-amber-500/30 bg-basalt-950 p-6 shadow-2xl",children:[(0,e.jsx)("button",{type:"button",onClick:r,className:"absolute right-4 top-4 text-basalt-500 hover:text-white","aria-label":"Close dialog",children:(0,e.jsx)(na,{size:18})}),(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-amber-500/20 text-amber-300",children:(0,e.jsx)(ds,{size:24})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"font-outfit text-lg font-semibold text-white",children:"Enable Zero-Knowledge Vault Encryption"}),(0,e.jsx)("p",{className:"text-[10px] text-amber-300 font-medium",children:"Client-side AES-256-GCM Protection"})]})]}),(0,e.jsxs)("form",{onSubmit:$,className:"mt-4 space-y-4",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-amber-500/20 bg-amber-500/[.04] p-3 text-xs leading-5 text-basalt-300 space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-start gap-2 text-amber-200 font-semibold text-[11px]",children:[(0,e.jsx)(sa,{size:15,className:"shrink-0 mt-0.5"}),(0,e.jsx)("span",{children:"Important Security & Storage Notice"})]}),(0,e.jsxs)("p",{children:["Enabling client-side encryption will queue ",s," Markdown note",s===1?"":"s"," for AES-256-GCM protection and encrypted re-upload to configured cloud providers."]}),(0,e.jsx)("p",{className:"text-amber-200/90 font-medium",children:"â ï¸ Encrypted Markdown will not be readable directly in Phasoric Hosted, Dropbox, Google Drive, or GitHub without your passphrase on this or a newly authorized device. Attachments are not covered by this
4setting."})]}),(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("label",{className:"block text-[10px] font-bold uppercase tracking-wider text-basalt-400",children:["Vault Passphrase (min 10 characters)",(0,e.jsx)("input",{type:"password",required:!0,minLength:10,value:m,onChange:v=>j(v.target.value),className:"mt-1 w-full rounded-lg border border-basalt-800 bg-basalt-900 px-3 py-2 text-xs text-white outline-none focus:border-amber-400",placeholder:"Enter strong passphrase..."})]}),(0,e.jsxs)("label",{className:"block text-[10px] font-bold uppercase tracking-wider text-basalt-400",children:["Confirm Passphrase",(0,e.jsx)("input",{type:"password",required:!0,minLength:10,value:p,onChange:v=>f(v.target.value),className:"mt-1 w-full rounded-lg border border-basalt-800 bg-basalt-900 px-3 py-2 text-xs text-white outline-none focus:border-amber-400",placeholder:"Confirm passphrase..."})]})]}),(0,e.jsxs)("button",{type:"button",onClick:()=>E(!u),className:"flex items-start gap-2 text.left text-[11px] text-basalt-300 hover:text-white transition-colors",children:[u?(0,e.jsx)(us,{size:16,className:"text-amber-400 shrink-0 mt-0.5"}):(0,e.jsx)(xs,{size:16,className:"text-basalt-600 shrink-0 mt-0.5"}),(0,e.jsx)("span",{children:"I understand that hosted cloud files will be encrypted and cannot be read without this passphrase."})]}),c&&(0,e.jsx)("p",{className:"text-[10px] text-red-300",children:c}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-3 pt-2",children:[(0,e.jsx)("button",{type:"button",onClick:r,className:"rounded-xl border border-basalt-800 px-4 py-2 text-xs font-semibold text-basalt-300 hover:text-white",children:"Cancel"}),(0,e.jsxs)("button",{type:"submit",disabled:w||!u,className:"flex items-center gap-2 rounded-xl bg-amber-400 px-4 py-2 text-xs font-bold text-black hover:bg-amber-300 disabled:opacity-40 transition-all",children:[(0,e.jsx)(ns,{size:14}),w?"Enabling Encryption...":"Enable Encryption"]})]})]})]})})}var cr=(0,o.lazy)(()=>Ge(()=>import("./AISettings-DgOyX3ES.js").then(a=>({default:a.AISettings})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52]))),dr=(0,o.lazy)(()=>Ge(()=>import("./GooglePlayBillingPanel-CRFPoojh.js"),__vite__mapDeps([53,1,2,4,5,6,7,8,9,10]))),pr=(0,o.lazy)(()=>Ge(()=>import("./HostedSourceSetup-CGj0TGUw.js").then(a=>a.n),__vite__mapDeps([54,1,2]))),ur=(0,o.lazy)(()=>Ge(()=>import("./DesktopVaultHosting-S02MyJXu.js"),__vite__mapDeps([55,1,2,5,56,4,6,7,8,9,10,57,38,58,18,59,30,60,61,62]))),K="w-full rounded-lg border border-basalt-800 bg-basalt-950 px-3 py-2.5 text-xs text-white outline-none focus:border-accent-cyan/60";function yo(){const{user:a,updateProfile:r,refreshSession:l}=ys(),s=Ga(),[m,j]=(0,o.useState)(()=>new URLSearchParams(s.search).get("tab")||"account");(0,o.useEffect)(()=>{const t=new URLSearchParams(s.search).get("tab");["account","vaults","sync","editor","files","storage","billing","connections","security","intelligence","developer"].includes(t)&&j(t)},[s.search]);const[p,f]=(0,o.useState)({name:"",tenantName:"",vaultName:"",vaults:[]}),[u,E]=(0,o.useState)(""),[c,x]=(0,o.useState)(null),[w,y]=(0,o.useState)(""),[$,v]=(0,o.useState)([]),[I,i]=(0,o.useState)(""),[C,b]=(0,o.useState)(()=>oe()),[F,S]=(0,o.useState)(""),[M,N]=(0,o.useState)(!1),[_,G]=(0,o.useState)(null),[B,de]=(0,o.useState)(null),[se,ne]=(0,o.useState)(!1),[ie,k]=(0,o.useState)(!1),[D,V]=(0,o.useState)({repository:"",branch:"",token:""}),[X,Ee]=(0,o.useState)(()=>localStorage.getItem("basalt_theme_preset")||"basalt"),[L,R]=(0,o.useState)(Js),[te,qe]=(0,o.useState)(()=>localStorage.getItem("basalt_custom_css")||""),[ee,le]=(0,o.useState)(""),[g,P]=(0,o.useState)(he),[U,J]=(0,o.useState)(""),[fe,re]=(0,o.useState)(!1),[pe,We]=(0,o.useState)(0),[ba,ga]=(0,o.useState)(sn),[Ie,mt]=(0,o.useState)(""),[ht,fa]=(0,o.useState)(null),[bt,ya]=(0,o.useState)(vn),[gt,ft]=(0,o.useState)("");(0,o.useEffect)(()=>{const t=new URLSearchParams(s.search).get("tab");t&&j(t)},[s.search]),(0,o.useEffect)(()=>{m!=="developer"||a?.localOnly||fetch("/api/usage",{credentials:"include"}).then(async t=>{const n=await t.json().catch(()=>({}));if(!t.ok)throw new Error(n.error||"Unable to load MCP usage.");fa(n.mcp||null)}
4).catch(t=>me(t.message))},[m,a?.id,a?.localOnly]),(0,o.useEffect)(()=>{const t=n=>P(n.detail?.status||he());return window.addEventListener("basalt-vault-encryption-state",t),()=>window.removeEventListener("basalt-vault-encryption-state",t)},[]);const[va,me]=(0,o.useState)(""),[ja,yt]=(0,o.useState)(!1),[O,Ke]=(0,o.useState)({status:a?.localOnly?"local":"loading",progress:{}}),[vt,jt]=(0,o.useState)(!1),[_e,Qe]=(0,o.useState)([]),[ye,wt]=(0,o.useState)(()=>zt()),Fe=(0,o.useMemo)(()=>{const t=new Set(ye.map(n=>n.workspaceId));return ye.filter(n=>!n.aliasOfWorkspaceId||!t.has(n.aliasOfWorkspaceId))},[ye]),Ye=ye.length-Fe.length,[Je,wa]=(0,o.useState)(""),[Ze,Nt]=(0,o.useState)({available:!1,configured:{},connections:[]}),[ae,kt]=(0,o.useState)({isOpen:!1,provider:"",connectionId:"",sourceId:"",mappingId:"",initialPath:"",initialFolderId:"",initialRepo:""});(0,o.useEffect)(()=>{f({name:a?.name||"Local vault",tenantName:a?.tenantName||"Personal",vaultName:a?.vaultName||"Personal",vaults:a?.vaults||[a?.vaultName||"Personal"]})},[a]),(0,o.useEffect)(()=>{Cn().then(Ke);const t=n=>Ke(n.detail);return window.addEventListener("workspace-migration-updated",t),()=>window.removeEventListener("workspace-migration-updated",t)},[]),(0,o.useEffect)(()=>{a?.localOnly||ct().then(Nt).catch(()=>{})},[a?.id,a?.localOnly]),(0,o.useEffect)(()=>{Vs().then(de).catch(()=>{})},[]),(0,o.useEffect)(()=>{let t=null,n=!1,d=!1,h=!1;const A=async()=>{t=null,d=!1,n=!0;try{const W=await st();h||G(W)}catch{}finally{n=!1,d&&!h&&T()}},T=()=>{d=!0,!n&&t===null&&!h&&(t=window.setTimeout(A,1e3))};return A(),window.addEventListener("sync-health-updated",T),window.addEventListener("notes-updated",T),()=>{h=!0,t!==null&&window.clearTimeout(t),window.removeEventListener("sync-health-updated",T),window.removeEventListener("notes-updated",T)}},[]),(0,o.useEffect)(()=>{const t=h=>{const A=qs(h.detail);A&&S(A)},n=h=>S(Vt(h.detail)),d=h=>{h.detail?.message&&S(h.detail.message)};return window.addEventListener("cloud-sync-progress",t),window.addEventListener("cloud-sync-complete",n),window.addEventListener("cloud-sync-status",d),()=>{window.removeEventListener("cloud-sync-progress",t),window.removeEventListener("cloud-sync-complete",n),window.removeEventListener("cloud-sync-status",d)}},[]),(0,o.useEffect)(()=>{if(a?.localOnly)return Qe([]);fetch("/api/workspaces",{credentials:"include"}).then(t=>t.ok?t.json():{workspaces:[]}).then(t=>Qe(t.workspaces||[])).catch(()=>Qe([]))},[a?.id,a?.localOnly,O.status]),(0,o.useEffect)(()=>{const t=()=>wt(zt());return Ps().then(wt).catch(()=>{}),window.addEventListener("local-workspaces-updated",t),window.addEventListener("cloud-sources-updated",t),()=>{window.removeEventListener("local-workspaces-updated",t),window.removeEventListener("cloud-sources-updated",t)}},[]);const Na=async()=>{jt(!0);try{Ke(await Sn({retry:!0}))}finally{jt(!1)}};(0,o.useEffect)(()=>{const t=new URLSearchParams(window.location.search),n=ge()&&t.get("session_id");if(n){const h=t.get("section")==="intelligence";j(h?"intelligence":"billing"),i(h?"Confirming Phasoric Creditsâ¦":"Confirming subscriptionâ¦"),fetch(`/api/billing/verify-session?session_id=${encodeURIComponent(n)}`).then(async A=>{const T=await A.json().catch(()=>({}));if(!A.ok)throw new Error(T.error||"Unable to confirm subscription");if(await l(),i(h?"Phasoric Credits added.":"Subscription updated."),!h){const W={plan_key:T.user?.billing_plan_key||gs(T.user?.tier),billing_interval:T.user?.billing_interval||"month",result:"paid",...Ns(T.conversionAttribution)};ce("checkout_completed",W),ce("paid_conversion",W),vs(n,T.user)}h&&window.dispatchEvent(new Event("ai-credit-updated"))}).catch(A=>i(A.message)).finally(()=>window.history.replaceState({},document.title,"/app/settings"));return}if(t.get("billing")==="portal"){j("billing"),window.history.replaceState({},document.title,"/app/settings?tab=billing");return}const d=t.get("connection");t.get("tab")==="sync"&&t.get("status")==="connected"&&["dropbox","google"].includes(d)&&(j("sync"),N(!0),ct().then(h=>{Nt(h);const A=h.connections?.find(T=>T.provider===d);if(!A)throw new Error(`${d==="google"?"Google Drive":"Dropbox"} connection was not found.`);return St(A)}).then(h=>(S(`${d==="google"?"Google Drive":"Dropbox"} connected through your Phasoric account. Starting initial sync...`),nt(h.id,{trigger:"startup"}).catch(A=>S(`Connected. ${Z(A,{provider:d==="google"?"Google Drive":"Dropbox"})}`)))).then(()=>S(`${d==="google"?"Google Drive":"Dropbox"} connected and synced.`)).catch(h=>S(Z(h,{provider:d==="google"?"Google Drive":"Dropbox"}))).finally(()=>{N(!1),window.history.replaceState({}
4,document.title,"/app/settings")}))},[]);const Ct=(t,n="")=>{const d=String(t||"").trim().toLowerCase();return oe().flatMap(h=>(h.mappings||[]).map(A=>({source:h,mapping:A}))).find(({mapping:h})=>h.id!==n&&h.direction!=="pull"&&String(h.localVault||"").trim().toLowerCase()===d)},Oe=()=>(a?.vaults||[a?.vaultName||"Personal"]).find(t=>!Ct(t)),St=async(t,n={})=>{const d=t.provider,h=d==="github"?`github:${n.owner}/${n.repository}`:"",A=h?oe().find(W=>W.id===h)||tt(d):tt(d),T=Ht({...A,id:A?.id||h||d,provider:d,connectionId:t.id,owner:n.owner||A?.owner||"",repository:n.repository||A?.repository||"",branch:n.branch||A?.branch||"",name:A?.name||(d==="google"?"Google Drive":d==="github"?`GitHub · ${n.owner}/${n.repository}`:"Dropbox"),accessMode:d==="google"?"full-drive":d==="github"?"repository-scoped":"full-dropbox",mappings:A?.mappings||[at(d,{localVault:Oe()||a?.vaultName||"Personal",direction:Oe()?"two-way":"pull"})]});return b(oe()),T},Pt=async t=>{t.preventDefault(),i("Savingâ¦");try{const n=[...p.vaults];n.some(T=>T.toLowerCase()===p.vaultName.toLowerCase())||n.unshift(p.vaultName),await r({...p,vaults:n,vaultRenames:$});const d=new Set(n.map(T=>T.toLowerCase())),h=js(),A=h.filter(T=>!d.has(T.name.toLowerCase()));A.length&&(Cs({logicalVaults:h.filter(T=>d.has(T.name.toLowerCase()))}),await Promise.all(A.map(T=>fn(T.id))));for(const T of $)for(const W of oe())(W.mappings||[]).some(H=>H.localVault===T.from)&&$e(W.id,{mappings:W.mappings.map(H=>H.localVault===T.from?{...H,localVault:T.to}:H)});b(oe()),v([]),i("Account workspace saved.")}catch(n){i(n.message)}},Et=(0,o.useMemo)(()=>{const t=new Set;return(p.vaults||[]).forEach(n=>n&&t.add(String(n).trim().toLowerCase())),p.vaultName&&t.add(String(p.vaultName).trim().toLowerCase()),(a?.vaults||[]).forEach(n=>n&&t.add(String(n).trim().toLowerCase())),a?.vaultName&&t.add(String(a.vaultName).trim().toLowerCase()),(ye||[]).forEach(n=>{(n.vaults||[]).forEach(d=>d&&t.add(String(d).trim().toLowerCase())),(n.logicalVaults||[]).forEach(d=>d?.name&&t.add(String(d.name).trim().toLowerCase())),n.defaultVault&&t.add(String(n.defaultVault).trim().toLowerCase())}),(_e||[]).forEach(n=>{(n.vaults||[]).forEach(d=>d&&t.add(String(d).trim().toLowerCase())),n.defaultVault&&t.add(String(n.defaultVault).trim().toLowerCase())}),t},[p.vaults,p.vaultName,a?.vaults,a?.vaultName,ye,_e]),At=()=>{const t=Kt(u);if(!t.valid)return i(t.error);if(Et.has(t.name.toLowerCase()))return i("A vault with that name already exists.");const n=ze(a);if(n&&p.vaults.length>=n)return i(`Your ${a?.tier||"Free"} plan supports ${n} hosted vault${n===1?"":"s"}.`);f(d=>({...d,vaults:[...d.vaults,t.name]})),E(""),i("Vault added. Save the workspace to apply it.")},ka=t=>{if(t===p.vaultName)return i("Choose a different default vault before removing this one.");f(n=>({...n,vaults:n.vaults.filter(d=>d!==t)})),i("Vault removed. Save the workspace to apply it.")},Lt=t=>{const n=w.trim();if(!n||n===t){x(null);return}const d=Kt(n);if(!d.valid)return i(d.error);const h=d.name.toLowerCase();if(h!==t.toLowerCase()&&Et.has(h)){i("A vault with that name already exists.");return}f(A=>{const T=A.vaults.map(H=>H===t?d.name:H),W=A.vaultName===t?d.name:A.vaultName;return{...A,vaults:T,vaultName:W}}),v(A=>[...A.filter(T=>T.from!==t),{from:t,to:d.name}]),x(null),i("Vault renamed. Save the workspace to apply it.")},Ue=async t=>{S(""),N(!0);try{if(a?.localOnly)throw new Error("Create a Free Phasoric account before connecting a third-party provider.");if(t==="dropbox")return await la({returnTab:"sync"});if(t==="basalt"){if(!a||a.localOnly)throw new Error("Sign in to add Phasoric Hosted as a vault provider.");const n=Oe();if(!n)throw new Error("Every vault already has a writable storage provider. Add another vault or remove an existing writable mapping first.");const d=await fetch("/api/hosted-vaults/health",{credentials:"include"});if(!d.ok)throw new Error((await d.json().catch(()=>({}))).error||"Phasoric Hosted is not available for this account.");const h=tt("basalt"),A=Ht({...h,id:h?.id||"basalt-hosted",provider:"basalt",name:"Phasoric Hosted",accessMode:"basalt-hosted",credentials:null,mappings:h?.mappings||[at("basalt",{localVault:n})]});return b(oe()),S("Phasoric Hosted connected. Choose a vault mapping, then sync to store its Markdown and attachments with Phasoric."),A}if(t==="github"){const n=on(D.repository),d=await an(D.token.trim()),h={provider:"github",connectionId:d.connection.id,branch:D.branch.trim(),...n},A=await xn(h);if(!A.canPush)throw new Error("This token can read the repository but does not have
4Contents write permission.");const T=D.branch.trim()||A.defaultBranch;await St(d.connection,{...n,branch:T}),V(W=>({...W,token:"",branch:T})),S(`GitHub repository ${A.account} connected. Changes will create commits on ${T}.`);return}await oa({services:["drive"],returnTab:"sync"})}catch(n){S(Z(n,{provider:t==="basalt"?"Phasoric Hosted":t==="google"?"Google Drive":t==="github"?"GitHub":"Dropbox"}))}finally{t==="github"&&V(n=>({...n,token:""})),N(!1)}},Ca=async t=>{N(!0),S("Testing provider permissionsâ¦");try{const n=await un(t),d=n.provider==="google"?"Google Drive":n.provider==="github"?"GitHub":n.provider==="basalt"?"Phasoric Hosted":"Dropbox";S(`Connected to ${d} as ${n.account||"the selected account"}.`)}catch(n){S(Z(n))}finally{N(!1)}},Sa=async t=>{N(!0),S("Scanning mapped folders and all subfoldersâ¦");try{const n=await nt(t,{trigger:"user"}),d=`Sync complete: ${n.imported} imported, ${n.updated} updated, ${n.skipped} unchanged, ${n.attachmentsImported||0} attachments restored, ${n.remoteMoved||0} remote moves applied, ${n.remoteDeleted||0} remote deletions moved to Trash.`,h=n.errors.find(A=>A.includes("Sync paused before the browser memory limit"));S(h?Z(h):n.errors.length?`${d} ${n.errors.length} item${n.errors.length===1?"":"s"} need attention. ${Z(n.errors[0])}`:n.pendingTransfers?Vt(n):d)}catch(n){S(Z(n))}finally{N(!1)}},Pa=async()=>{N(!0);try{for(const t of C)await nt(t.id,{trigger:"user"});await dn({forceSeed:!0}),G(await st()),S("Downloads and pending changes resumed.")}catch(t){S(Z(t))}finally{N(!1)}},Ea=async()=>{const t=await st(),n=URL.createObjectURL(new Blob([JSON.stringify(t,null,2)],{type:"application/json"})),d=document.createElement("a");d.href=n,d.download=`basalt-sync-diagnostics-${new Date().toISOString().slice(0,10)}.json`,d.click(),URL.revokeObjectURL(n)},Aa=async()=>{ne(!0);try{const t=await Ws();de(t),G(t.diagnostics)}finally{ne(!1)}},$t=async t=>{const n=await fetch(`/api/hosted-vaults/${encodeURIComponent(t)}`,{method:"DELETE",credentials:"include"}),d=await n.json().catch(()=>({}));if(!n.ok)throw new Error(d.error||"Phasoric Hosted vault deletion failed.");return d},La=async t=>{if(t.provider==="basalt"){if(!window.confirm("Disconnect Phasoric Hosted and permanently delete the hosted Markdown and attachments for every mapping in this source? Local browser copies remain. This cannot be undone."))return;N(!0);try{for(const n of t.mappings)await $t(n.id)}catch(n){S(`${Z(n,{provider:"Phasoric Hosted"})} Phasoric Hosted remains connected so deletion can be retried safely.`),N(!1);return}N(!1)}if(dt(t.id),t.connectionId&&ca(t.connectionId),Ds(t.id),b(oe()),t.provider!=="basalt"&&t.connectionId){N(!0);try{await ia(t.connectionId)}catch(n){S(`${t.name} sync was stopped and its local mapping was removed. ${Z(n,{provider:t.name})} Retry account revocation in Connections.`),N(!1);return}N(!1)}S(t.provider==="basalt"?"Phasoric Hosted disconnected and its hosted vault data was deleted. Local browser copies were not changed.":`${t.name} disconnected, its account access was revoked, and its saved mapping was removed. Local vault data was not changed.`)},ve=async(t,n,d)=>{const h=C.find(H=>H.id===t);if(!h)return;const A=h.mappings.find(H=>H.id===n);if(d.mcpWriteEnabled===!0&&g!=="disabled"){S("Device-encrypted vaults cannot accept hosted MCP writes because the decryption key stays on this device.");return}const T={...A,...d,...d.direction==="pull"?{mcpWriteEnabled:!1}:{},...d.mcpWriteEnabled!==void 0?{clientEncryptionEnabled:g!=="disabled"}:{}},W=T.direction!=="pull"&&Ct(T.localVault,n);if(W){S(`${T.localVault} already uses ${W.source.name} as its writable storage provider. Use Pull only for an import source, or remove the existing mapping first.`);return}if($e(t,{mappings:h.mappings.map(H=>H.id===n?T:H)}),b(oe()),d.mcpWriteEnabled!==void 0||d.direction==="pull"&&A.mcpWriteEnabled){const H=T.mcpWriteEnabled===!0;try{const za=await Bt({hosted:!a?.localOnly});S(za.mode==="cloud"?`Hosted MCP note changes ${H?"enabled":"disabled"} for ${T.localVault}. Refresh the MCP client's vault list.`:`The ${H?"write grant":"write revocation"} is saved locally but has not reached the hosted MCP gateway yet.`)}catch{S(`The ${H?"write grant":"write revocation"} is saved locally but has not reached the hosted MCP gateway yet.`)}}},$a=t=>
4{if(!ae.sourceId||!ae.mappingId)return;const n={};t.remotePath!==void 0&&(n.remotePath=t.remotePath),t.remoteFolderId!==void 0&&(n.remoteFolderId=t.remoteFolderId),t.repository&&$e(ae.sourceId,{repository:t.repository}),ve(ae.sourceId,ae.mappingId,n)},Da=t=>{const n=Oe();if(!n){S("Every vault already has a writable storage provider. Add another vault or make an existing mapping Pull only first.");return}$e(t.id,{mappings:[...t.mappings,at(t.provider,{localVault:n})]}),b(oe())},Ta=async(t,n)=>{if(t.mappings.length<=1)return S("Each cloud source needs at least one folder mapping.");if(t.provider==="basalt"){if(!window.confirm("Permanently delete the Phasoric Hosted Markdown and attachments for this mapping? Local browser copies remain. This cannot be undone."))return;N(!0);try{await $t(n)}catch(d){S(`${Z(d,{provider:"Phasoric Hosted"})} The mapping was kept so deletion can be retried safely.`),N(!1);return}N(!1)}$e(t.id,{mappings:t.mappings.filter(d=>d.id!==n)}),b(oe()),t.provider==="basalt"&&S("Phasoric Hosted mapping and hosted data deleted. Local browser copies were not changed.")},Ma=t=>{const n=t.trim();return n.match(/\/folders\/([^/?#]+)/)?.[1]||n||"root"},Ra=t=>{qe(t),localStorage.setItem("basalt_custom_css",t);let n=document.getElementById("basalt-custom-css");n||(n=document.createElement("style"),n.id="basalt-custom-css",document.head.appendChild(n)),n.textContent=t,window.dispatchEvent(new CustomEvent("settings-updated"))},Dt=t=>R(Zs(t)),Ia=async()=>{me("Generating secure tokenâ¦");const t=await fetch("/api/usage/mcp-token",{method:"POST"}),n=await t.json().catch(()=>({}));if(!t.ok)return me(n.error||"Unable to generate a hosted access token");mt(n.token),me(`Copy this token now. ${n.monthlyLimit.toLocaleString()} MCP operations/month · ${n.requestsPerMinute}/minute.`)},_a=async()=>{if(me("Revoking tokenâ¦"),!(await fetch("/api/usage/access-token",{method:"DELETE"})).ok)return me("Unable to revoke the hosted access token.");mt(""),me("Hosted access token revoked. Connected clients must use a newly generated token.")},Fa=async()=>{J(""),We(await $s.notes.count().catch(()=>0)),re(!0)},Oa=async t=>{const n=C.some(h=>h.mappings.some(A=>A.mcpWriteEnabled===!0)),d=Ms(C.map(h=>({...h,mappings:h.mappings.map(A=>({...A,mcpWriteEnabled:!1,clientEncryptionEnabled:!0}))})));b(d);try{if(n&&!a?.localOnly&&(await Bt({hosted:!0})).mode!=="cloud")throw new Error("Hosted MCP write access could not be revoked. Reconnect to Phasoric and retry encryption setup.");await pn(t)}catch(h){throw P(he()),J(h.message||"Unable to enable end-to-end cloud encryption."),h}P(he());try{const h=await ln();J(`Encryption is enabled and unlocked. ${h.toLocaleString()} Markdown note${h===1?"":"s"} queued for encrypted re-upload; local note bodies remain readable in Phasoric.`)}catch(h){J(`Encryption is enabled and unlocked, but existing notes could not be queued for encrypted re-upload: ${h.message}`)}},Tt=async()=>{try{await nn(ee),le(""),P(he()),J("Encryption unlocked. Queued cloud changes can resume with encrypted Markdown payloads.")}catch(t){P(he()),J(t.message||"Unable to unlock end-to-end cloud encryption.")}},Ua=()=>{rn(),P(he()),J("Encryption locked. Cloud Markdown writes are paused until you unlock it; plaintext will not be uploaded.")},je=bs(a?.tier),Mt=je.apiOperationsPerMonth>0;return(0,e.jsxs)("div",{className:"h-full overflow-y-auto bg-basalt-950 p-4 text-white sm:p-8",children:[(0,e.jsxs)("div",{className:"mx-auto max-w-5xl",children:[(0,e.jsx)("h1",{className:"font-outfit text-2xl font-semibold",children:"Vault Settings"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Your identity, workspace, storage, and appearance in one place."}),(0,e.jsxs)("div",{className:"mt-7 flex flex-col gap-6 md:flex-row",children:[(0,e.jsx)("nav",{className:"flex gap-1 overflow-x-auto md:w-48 md:shrink-0 md:flex-col",children:[["account",Tn,"Account"],["vaults",Rt,"Vaults"],["sync",xt,"Cloud Sync"],["connections",ut,"Connections"],["editor",$n,"Editor & Theme"],["files",En,"Files & Links"],["storage",aa,"Storage"],["billing",pt,"Billing & Usage"],["security",ps,"Encryption"],["intelligence",Ka,"Intelligence"],["developer",ms,"AI Connections & API"]].map(([t,n,d])=>(0,e.jsxs)("button",{onClick:()=>j(t),className:`flex shrink-0 items-center gap-2 rounded-lg border px-3 py-2.5 text-left text-xs ${m===t?"border-accent-cyan/30 bg-accent-cyan/10 text-accent-cyan":"border-transparent text-basalt-500 hover:bg-basalt-900 hover:text-white"}`,children:[(0,e.jsx)(n,{size:14}),d]},t))}),(0,e.jsxs)("section",{className:"min-w-0 flex-1 rounded-2xl border border-basalt-800 bg-basalt-900/30 p-5 sm:p-6",children:[m==="account"&&(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("form",{onSubmit:Pt,className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Account workspace"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"These values drive the sidebar identity, tenant namespace, and entitlement display."})]}),(0,e.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,e.jsxs)("label",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:["Account name",(0,e.jsx)("input",{className:`${K} mt-2`,value:p.name,onChange:t=>f({...p,name:t.target.value})})]}),(0,e.jsxs)("label",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:["Email",(0,e.jsx)("input",{className:`${K} mt-2 opacity-70`,value:a?.email||"Local-only profile",readOnly:!0})]}),(0,e.jsxs)("label",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:["Tenant space",(0,e.jsx)("input",{className:`${K} mt-2`,value:p.tenantName,onChange:t=>f({...p,tenantName:t.target.value})})]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:"Subscription"}),(0,e.jsx)("div",{className:"mt-1 font-semibold",children:a?.tier||"Free Tier"}
4),a?.billing?.status&&(0,e.jsxs)("div",{className:"mt-1 text-[9px] uppercase text-basalt-500",children:[a.billing.status,a.billing.graceUntil?` · grace through ${new Date(a.billing.graceUntil).toLocaleDateString()}`:""]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[!a?.localOnly&&(0,e.jsx)("button",{type:"button",onClick:()=>j("billing"),className:"rounded-lg border border-white/10 px-3 py-2 text-[10px] font-semibold text-basalt-200",children:"Manage billing"}),(0,e.jsx)("span",{className:`rounded-full px-2 py-1 text-[9px] font-bold uppercase ${a?.localOnly?"bg-cyan-300/10 text-cyan-300":"bg-emerald-300/10 text-emerald-300"}`,children:a?.localOnly?"Local profile":"Hosted account"})]})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-600",children:"Local workspace ownership"}),(0,e.jsx)("div",{className:"mt-1 font-mono text-[10px] text-basalt-400",children:we()})]}),(0,e.jsx)("span",{className:"rounded-full bg-white/5 px-2 py-1 text-[9px] font-bold uppercase text-basalt-300",children:a?.localOnly?"Unclaimed":O.status})]}),(0,e.jsx)("p",{className:"mt-3 text-[10px] leading-5 text-basalt-500",children:a?.localOnly?"Create a hosted account to claim this workspace without losing its local notes.":O.status==="complete"?"Artifact payloads follow each vault storage mapping. Bounded metadata and recovery sidecars are hosted for cross-device synchronization.":O.progress?.waitingForRecovery?"Your workspace is recovering. Migration will resume automatically when recovery finishes.":O.status==="provider-pending"?"Account data is claimed. Connect the mapped provider to finish content migration.":O.lastError||"Migration runs in the background and can safely resume."}),O.progress?.inventory&&(0,e.jsxs)("div",{className:"mt-3 flex flex-wrap gap-3 text-[9px] text-basalt-500",children:[(0,e.jsx)("span",{children:O.progress.noteScanComplete?`${O.progress.inventory.notes} notes inventoried`:`${O.progress.noteScanProcessed||0}/${O.progress.inventory.notes} notes inventoried`}),(0,e.jsxs)("span",{children:[(O.progress.attachmentsLocal||0)+(O.progress.attachmentsUploaded||0)+(O.progress.attachmentsProviderManaged||0),"/",O.progress.inventory.attachments," attachments routed",O.progress.attachmentsLocal?` · ${O.progress.attachmentsLocal} local`:"",O.progress.attachmentsProviderManaged?` · ${O.progress.attachmentsProviderManaged} mapped storage`:"",O.progress.attachmentsUploaded?` · ${O.progress.attachmentsUploaded} hosted`:"",O.progress.attachmentFailures?` · ${O.progress.attachmentFailures} need retry`:""]}),(0,e.jsxs)("span",{children:[O.progress.metadataSynced||0,"/",O.progress.inventory.metadata," metadata protected"]}),O.progress.remainingNotes>0&&(0,e.jsxs)("span",{children:[O.progress.remainingNotes," mapped writes remaining"]})]}),_e.length>1&&(0,e.jsx)("div",{className:"mt-3 space-y-2",children:_e.map(t=>(0,e.jsxs)("button",{type:"button",disabled:t.workspaceId===we(),onClick:()=>{Ls(t.workspaceId,a.id),Ut(t.workspaceId,{destination:"/app/settings",preserveWorkspaceProfile:!0})},className:"flex w-full items-center justify-between rounded-lg border border-basalt-800 px-3 py-2 text-left text-[10px] disabled:border-accent-cyan/20 disabled:text-accent-cyan",children:[(0,e.jsx)("span",{children:t.label}),(0,e.jsx)("span",{className:"uppercase text-basalt-600",children:t.workspaceId===we()?"Current":t.migrationStatus})]},t.workspaceId))}),(0,e.jsx)("button",{type:"button",disabled:vt,onClick:()=>a?.localOnly?window.location.assign("/signup"):Na(),className:"mt-3 rounded-lg border border-accent-cyan/25 px-3 py-2 text-[10px] font-semibold text-accent-cyan disabled:opacity-50",children:a?.localOnly?"Claim with an account":vt?"Migratingâ¦":O.status==="complete"?"Verify migration":"Resume migration"})]}),(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Local databases on this device"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] leading-5 text-basalt-500",children:"Active Vaults presents one workspace per logical vault. Data-bearing historical databases remain listed here for recovery; verified-empty aliases can be reviewed and removed from Manage Vaults."})]}),(0,e.jsxs)("span",{className:"rounded-full bg-cyan-300/10 px-2 py-1 text-[9px] font-bold uppercase text-cyan-300",children:[Fe.length," databases"]})]}),Ye>0?(0,e.jsxs)("p",{role:"status",className:"mt-3 rounded-lg border border-emerald-300/10 bg-emerald-300/[.035] px-3 py-2 text-[9px] leading-4 text-emerald-200",children:[Ye," empty legacy local database ",Ye===1?"is":"copies are"," represented by the matching hosted vault. No local database was deleted automatically."]}):null,(0,e.jsx)("div",{className:"mt-3 space-y-2",children:Fe.map(t=>(0,e.jsxs)("button",{type:"button",disabled:t.workspaceId===we(),onClick:()=>
4Ut(t.workspaceId,{destination:"/app/settings",preserveWorkspaceProfile:!0}),className:"flex w-full items-center justify-between gap-3 rounded-lg border border-basalt-800 px-3 py-2 text-left text-[10px] disabled:border-accent-cyan/20",children:[(0,e.jsxs)("span",{className:"min-w-0",children:[(0,e.jsx)("span",{className:"block truncate text-basalt-200",children:ks(t,Fe)}),(0,e.jsxs)("span",{className:"mt-1 block truncate text-[9px] text-basalt-600",children:[t.vaults?.length||1," vault",(t.vaults?.length||1)===1?"":"s",": ",(t.vaults||[t.defaultVault||"Personal"]).join(", ")," · ",t.providerLabels?.join(" + ")||"Device storage",t.linkedAccountIds?.includes(a?.id)?" · Account linked":""]})]}),(0,e.jsx)("span",{className:"shrink-0 uppercase text-basalt-600",children:t.workspaceId===we()?"Current":"Open"})]},t.workspaceId))})]}),(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("button",{className:"rounded-lg bg-accent-cyan px-4 py-2 text-xs font-bold text-basalt-950",children:"Save workspace"}),(0,e.jsx)("span",{className:"text-xs text-basalt-500",children:I})]})]}),(0,e.jsx)(zn,{workspaceId:we(),hosted:!!(a&&!a.localOnly),userId:a?.id}),(0,e.jsxs)("section",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4",children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:"Privacy preferences"}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-5 text-basalt-500",children:"Basic visitor counts, pageviews, and operational metrics stay enabled. Manage optional analytics cookies, deeper product measurement, and advertising attribution, or withdraw that permission at any time."}),(0,e.jsx)("button",{type:"button",onClick:()=>window.dispatchEvent(new CustomEvent("basalt-open-privacy")),className:"mt-3 rounded-lg border border-white/10 px-3 py-2 text-[10px] font-semibold text-basalt-200",children:"Manage privacy choices"})]}),(0,e.jsx)(On,{hosted:!!(a&&!a.localOnly)}),(0,e.jsx)(Fn,{hosted:!!(a&&!a.localOnly),userId:a?.id})]}),m==="vaults"&&(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsx)(o.Suspense,{fallback:null,children:(0,e.jsx)(ur,{user:a,requested:new URLSearchParams(s.search).get("desktopHosting")==="1"})}),(0,e.jsxs)("form",{onSubmit:Pt,className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Logical vaults"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Each vault is one knowledge container. Local storage and connected providers appear beneath it as storage bindings."})]}),(0,e.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,e.jsxs)("label",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500 sm:col-span-2",children:["Default vault",(0,e.jsx)("select",{className:`${K} mt-2`,value:p.vaultName,onChange:t=>f({...p,vaultName:t.target.value}),children:p.vaults.map(t=>(0,e.jsx)("option",{value:t,children:t},t))})]}),(0,e.jsxs)("div",{className:"sm:col-span-2 space-y-3",children:[(0,e.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:"Available vaults"}),(0,e.jsx)("div",{className:"flex flex-col gap-2",children:p.vaults.map(t=>{const n=c===t,d=t===p.vaultName;return(0,e.jsx)("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-basalt-800 bg-basalt-950 px-3 py-2 text-xs",children:n?(0,e.jsxs)("div",{className:"flex flex-1 gap-2 items-center",children:[(0,e.jsx)("input",{className:"flex-1 rounded border border-accent-cyan/50 bg-basalt-900 px-2 py-1 text-xs text-white outline-none",value:w,onChange:h=>y(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),Lt(t)),h.key==="Escape"&&(h.preventDefault(),x(null))}}),(0,e.jsx)("button",{type:"button",onClick:()=>Lt(t),className:"rounded bg-accent-cyan px-3 py-1 text-[10px] font-bold text-basalt-950",children:"Save"}),(0,e.jsx)("button",{type:"button",onClick:()=>x(null),className:"rounded border border-basalt-700 px-3 py-1 text-[10px] text-basalt-300 hover:text-white",children:"Cancel"})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("span",{className:"font-semibold text-basalt-200",children:t}),d&&(0,e.jsx)("span",{className:"rounded bg-accent-cyan/15 px-1.5 py-0.5 text-[8px] font-bold uppercase tracking-wide text-accent-cyan",children:"Default"})]}),(0,e.jsx)("div",{className:"mt-1 text-[9px] text-basalt-600",children:[{provider:"local",label:"Local"},...C.flatMap(h=>(h.mappings||[]).filter(A=>A.localVault===t).map(()=>({provider:h.provider,label:h.provider==="basalt"?"Phasoric Hosted":h.provider==="google"?"Google Drive":h.provider==="github"?"GitHub":"Dropbox"})))].map(h=>h.label).join(" · ")}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)("button",{type:"button",onClick:()=>{x(t),y(t)},className:"rounded border border-basalt-750 px-2.5 py-1 text-[10px] text-basalt-400 hover:border-basalt-600 hover:text-white transition-colors",children:"Rename"}),(0,e.jsx)("button",{type:"button",disabled:d,onClick:()=>ka(t),className:"rounded border border-red-900/40 px-2.5 py-1 text-[10px] text-red-400 hover:border-red-600 hover:text-red-300 transition-colors disabled:opacity-30 disabled:cursor-not-allowed","aria-label":`Remove ${t} vault`,children:"Delete"})]})]})},t)})}),(0,e.jsxs)("div",{className:"mt-4 border-t border-basalt-800 pt-3",children:[(0,e.jsx)("label",{className:"text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:"Create new vault"}),(0,e.jsxs)("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[(0,e.jsx)("input",{className:K,value:u,maxLength:48,onChange:t=>E(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),At())}
4,placeholder:"e.g. Work, Journal, Project Aâ¦","aria-label":"New vault name"}),(0,e.jsxs)("button",{type:"button",onClick:At,className:"inline-flex shrink-0 items-center justify-center gap-1.5 rounded-lg border border-accent-cyan/25 px-4 py-2.5 text-xs font-semibold text-accent-cyan",children:[(0,e.jsx)(it,{size:12}),"Create vault"]})]})]}),(0,e.jsx)("p",{className:"mt-2 text-[9px] leading-4 text-basalt-600",children:ze(a)?`${p.vaults.length} logical vault${p.vaults.length===1?"":"s"} · your plan supports ${ze(a)} Phasoric Hosted storage binding${ze(a)===1?"":"s"}.`:`${p.vaults.length} logical vaults · storage bindings are managed separately.`})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("button",{className:"rounded-lg bg-accent-cyan px-4 py-2 text-xs font-bold text-basalt-950",children:"Save workspace"}),(0,e.jsx)("span",{className:"text-xs text-basalt-500",children:I})]})]}),(0,e.jsx)(Pn,{})]}),m==="sync"&&(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Storage bindings"}),(0,e.jsx)("p",{className:"mt-1 text-xs leading-5 text-basalt-500",children:"Attach Dropbox, Google Drive, GitHub, or Phasoric Hosted to an existing logical vault. An attachment adds storage and recovery coverage; it does not create another vault."})]}),_&&(0,e.jsxs)("div",{className:"rounded-xl border border-cyan-300/15 bg-cyan-300/[.025] p-4",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-xs font-semibold text-white",children:"Sync health"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] text-basalt-500",children:"Persistent progress and recovery state for this device."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)("button",{disabled:M,onClick:Pa,className:"rounded-lg border border-cyan-300/20 px-3 py-2 text-[10px] text-cyan-200 disabled:opacity-40",children:"Resume all downloads"}),(0,e.jsx)("button",{onClick:Ea,className:"rounded-lg border border-basalt-700 px-3 py-2 text-[10px] text-basalt-300",children:"Export diagnostics"}),(0,e.jsxs)("button",{onClick:()=>k(!0),className:"inline-flex items-center gap-1.5 rounded-lg border border-basalt-700 px-3 py-2 text-[10px] text-basalt-300",children:[(0,e.jsx)(rs,{size:11}),"Report a problem"]})]})]}),(0,e.jsx)("div",{className:"mt-4 grid grid-cols-2 gap-3 sm:grid-cols-4",children:[["Inventory",_.inventory.headers],["Bodies local",_.inventory.localBodies],["Bodies pending",_.inventory.metadataOnly],["Failures",_.queue.failures]].map(([t,n])=>(0,e.jsxs)("div",{className:"rounded-lg border border-white/[.06] bg-black/20 p-3",children:[(0,e.jsx)("b",{className:"block text-lg text-white",children:Number(n).toLocaleString()}),(0,e.jsx)("span",{className:"text-[9px] uppercase tracking-wider text-basalt-600",children:t})]},t))}),_.inventory.metadataOnly>0&&(0,e.jsx)("p",{className:"mt-3 text-[9px] leading-4 text-cyan-200/70",children:"Missing Markdown bodies are saved for automatic download in small background batches. One delayed item will not block the rest."}),_.recovery?.vaults?.length>0&&(0,e.jsx)("div",{className:"mt-3 space-y-2","aria-label":"Recovery by vault",children:_.recovery.vaults.map(t=>(0,e.jsxs)("div",{className:"rounded-lg border border-white/[.06] p-3 text-[10px]",children:[(0,e.jsx)("b",{className:"text-white",children:t.localVault}),(0,e.jsx)("p",{className:"mt-1 text-basalt-400",children:t.state==="ready"?"Recovery complete. This vault can sync.":t.state==="unmapped"?"Recovery is waiting for this vaultâs storage connection. Other recovered vaults can sync.":"Uploads are paused while this vault recovers. Other recovered vaults can sync."}),(t.missingNotes>0||t.missingAttachments>0)&&(0,e.jsxs)("p",{className:"mt-1 text-amber-200",children:[t.missingNotes.toLocaleString()," note bodies and ",t.missingAttachments.toLocaleString()," attachment records still needed."]})]},t.localVault))}),Object.keys(_.queue.failuresByCode||{}).length>0&&(0,e.jsx)("p",{className:"mt-2 text-[9px] leading-4 text-amber-200/80",children:"Some items are waiting for an automatic retry or your review. Choose Resume all downloads; export diagnostics if the count does not fall."}),_.providers.length>0&&(0,e.jsx)("div",{className:"mt-3 space-y-1",children:_.providers.map(t=>(0,e.jsxs)("div",{className:"flex flex-wrap justify-between gap-2 text-[9px] text-basalt-500",children:[(0,e.jsxs)("span",{className:"capitalize",children:[t.provider||"Provider"," · ",t.mappings," mapping",t.mappings===1?"":"s"]}),(0,e.jsxs)("span",{children:[Object.entries(t.states||{}).map(([n,d])=>`${d} ${n}`).join(" · "),t.lastSuccessAt?` · last verified ${new Date(t.lastSuccessAt).toLocaleStr
4ing()}`:""]})]},t.provider))})]}),(0,e.jsxs)("section",{id:"vault-integrity",className:"scroll-mt-24 rounded-xl border border-white/[.08] bg-basalt-950/55 p-4",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(Ce,{size:15,className:"text-cyan-300"}),(0,e.jsx)("h3",{className:"text-xs font-semibold text-white",children:"Vault Integrity Check"})]}),(0,e.jsx)("p",{className:"mt-1 text-[10px] leading-4 text-basalt-500",children:"Compare indexed notes, local Markdown bodies, recovery queues, attachments, and provider completion without reading note content."})]}),(0,e.jsxs)("button",{disabled:se,onClick:Aa,className:"inline-flex items-center gap-2 rounded-lg bg-cyan-300 px-3 py-2 text-[10px] font-bold text-basalt-950 disabled:opacity-40",children:[se?(0,e.jsx)(Se,{size:11,className:"animate-spin"}):(0,e.jsx)(Ce,{size:11}),"Verify this vault"]})]}),B?(0,e.jsxs)("div",{className:"mt-4",children:[(0,e.jsxs)("div",{className:`flex items-center gap-2 rounded-lg border p-3 text-[10px] ${B.status==="verified"?"border-emerald-300/20 bg-emerald-300/[.04] text-emerald-200":B.status==="working"?"border-cyan-300/20 bg-cyan-300/[.04] text-cyan-200":"border-amber-300/20 bg-amber-300/[.04] text-amber-200"}`,children:[B.status==="verified"&&(0,e.jsx)(ta,{size:14}),(0,e.jsx)("b",{className:"capitalize",children:B.status}),(0,e.jsxs)("span",{className:"text-basalt-500",children:["Checked ",new Date(B.checkedAt).toLocaleString()]})]}),(0,e.jsx)("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:B.checks.map(t=>(0,e.jsxs)("div",{className:"rounded-lg border border-white/[.06] bg-black/20 p-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsx)("b",{className:"text-[10px] text-white",children:t.label}),(0,e.jsx)("span",{className:`text-[9px] font-bold uppercase ${t.status==="attention"?"text-amber-300":t.status==="working"?"text-cyan-300":t.status==="passed"?"text-emerald-300":"text-basalt-600"}`,children:t.status})]}),(0,e.jsx)("p",{className:"mt-1 text-[9px] leading-4 text-basalt-500",children:t.detail})]},t.id))})]}):(0,e.jsx)("div",{className:"mt-4 rounded-lg border border-dashed border-basalt-800 p-4 text-center text-[10px] text-basalt-600",children:"No integrity check has been run on this device yet."})]}),C.map(t=>(0,e.jsxs)("div",{className:"space-y-4 rounded-xl border border-basalt-800 bg-basalt-950/55 p-4",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold",children:t.name}),(0,e.jsxs)("p",{className:"mt-1 text-[10px] text-basalt-500",children:[t.accessMode==="full-drive"?"Full Drive recursive access":t.accessMode==="repository-scoped"?`Repository-scoped · ${t.branch||"main"} branch`:t.accessMode==="basalt-hosted"?"Private Phasoric-managed storage":"Full Dropbox recursive access"," · ",t.mappings.length," mapping",t.mappings.length===1?"":"s"]}),t.requiresSecureReconnect?(0,e.jsx)("p",{className:"mt-1 text-[9px] text-amber-200",children:"Legacy browser credentials were removed. Reconnect through your Phasoric account before syncing."}):null]}),(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsx)("button",{disabled:M||t.requiresSecureReconnect,onClick:()=>Ca(t.id),className:"rounded-lg border border-basalt-700 px-3 py-2 text-[10px] hover:text-white disabled:opacity-40",children:"Test"}),M?(0,e.jsx)("button",{onClick:()=>dt(t.id),className:"rounded-lg border border-amber-300/25 px-3 py-2 text-[10px] text-amber-200",children:"Cancel safely"}):(0,e.jsxs)("button",{disabled:t.requiresSecureReconnect,onClick:()=>Sa(t.id),className:"flex items-center gap-1 rounded-lg bg-accent-cyan px-3 py-2 text-[10px] font-bold text-basalt-950 disabled:opacity-40",children:[(0,e.jsx)(Se,{size:11}),"Sync now"]}),(0,e.jsx)("button",{disabled:M,onClick:()=>La(t),className:"rounded-lg border border-red-400/20 px-3 py-2 text-[10px] text-red-300",children:"Disconnect"})]})]}),(0,e.jsx)("div",{className:"space-y-3",children:t.mappings.map(n=>(0,e.jsxs)("div",{className:"grid gap-3 rounded-xl border border-basalt-800 bg-black/20 p-3 sm:grid-cols-2",children:[(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Logical vault",(0,e.jsx)("select",{className:`${K}
4 mt-1.5`,value:n.localVault,onChange:d=>ve(t.id,n.id,{localVault:d.target.value}),children:[...new Set([...a?.vaults||[a?.vaultName||"Personal"],n.localVault])].map(d=>(0,e.jsx)("option",{value:d,children:d},d))})]}),t.provider==="basalt"?(0,e.jsxs)("div",{className:"rounded-lg border border-cyan-300/10 bg-cyan-300/[.025] p-3 text-[9px] leading-4 text-basalt-500",children:[(0,e.jsx)("b",{className:"block uppercase tracking-wider text-cyan-200",children:"Managed vault namespace"}),(0,e.jsx)("span",{className:"mt-1 block",children:"This mapping has an isolated private namespace in your Phasoric account. No second provider path is created."})]}):(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Remote folder path",(0,e.jsxs)("div",{className:"mt-1.5 flex gap-1.5",children:[(0,e.jsx)("input",{className:`${K} min-w-0 flex-1`,value:n.remotePath||"",onChange:d=>ve(t.id,n.id,{remotePath:d.target.value}),placeholder:t.provider==="dropbox"?"/Notes/Personal":t.provider==="github"?"notes/personal":"/Existing Vault"}),t.connectionId&&["dropbox","google","github"].includes(t.provider)&&(0,e.jsxs)("button",{type:"button",onClick:()=>kt({isOpen:!0,provider:t.provider,connectionId:t.connectionId,sourceId:t.id,mappingId:n.id,initialPath:n.remotePath||"/",initialFolderId:n.remoteFolderId||"root",initialRepo:t.repository||""}),className:"inline-flex shrink-0 items-center gap-1 rounded-lg border border-cyan-300/30 bg-cyan-300/10 px-2.5 py-1 text-[10px] font-bold text-cyan-200 hover:bg-cyan-300/20",children:[(0,e.jsx)(Rt,{size:11})," Browseâ¦"]})]})]}),t.provider==="google"&&(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Google folder ID or URL ",(0,e.jsx)("span",{className:"normal-case tracking-normal text-basalt-700",children:"(optional)"}),(0,e.jsx)("input",{className:`${K} mt-1.5`,value:n.remoteFolderId==="root"?"":n.remoteFolderId||"",onChange:d=>ve(t.id,n.id,{remoteFolderId:Ma(d.target.value)}),placeholder:"Paste a Drive folder URL for an exact match"})]}),(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Direction",(0,e.jsxs)("select",{className:`${K} mt-1.5`,value:n.direction,onChange:d=>ve(t.id,n.id,{direction:d.target.value}),children:[(0,e.jsx)("option",{value:"two-way",children:"Two-way sync"}),(0,e.jsx)("option",{value:"pull",children:"Pull from cloud only"}),(0,e.jsx)("option",{value:"push",children:"Push to cloud only"})]})]}),["dropbox","google","github"].includes(t.provider)&&(0,e.jsxs)("label",{className:"flex items-start gap-2 rounded-lg border border-cyan-300/10 bg-cyan-300/[.025] p-3 text-[10px] leading-4 text-basalt-400 sm:col-span-2",children:[(0,e.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:n.mcpWriteEnabled===!0,disabled:n.direction==="pull"||g!=="disabled",onChange:d=>ve(t.id,n.id,{mcpWriteEnabled:d.target.checked})}),(0,e.jsxs)("span",{children:[(0,e.jsx)("b",{className:"block text-cyan-200",children:"Allow hosted MCP note changes"}),"Agents may preview note changes, then create, update, or delete Markdown only after explicit approval. Applied changes require idempotency and current-content hashes. Pull-only and device-encrypted mappings remain read-only; GitHub changes create commits."]})]}),(0,e.jsxs)("div",{className:"flex items-end justify-between gap-3 sm:col-span-2",children:[(0,e.jsx)("p",{className:"text-[10px] leading-4 text-basalt-600",children:"Markdown, nested folders, attachments, and the portable Phasoric manifest are synchronized recursively. Existing folder metadata does not create conflicts."}),(0,e.jsxs)("button",{onClick:()=>Ta(t,n.id),className:"flex shrink-0 items-center gap-1 text-[10px] text-red-300",children:[(0,e.jsx)(Me,{size:11}),"Remove mapping"]})]})]},n.id))}),(0,e.jsxs)("button",{onClick:()=>Da(t),className:"flex items-center gap-1.5 rounded-lg border border-basalt-700 px-3 py-2 text-[10px] hover:border-accent-cyan hover:text-white",children:[(0,e.jsx)(it,{size:12}),"Add folder mapping"]})]},t.id)),C.length===0&&(0,e.jsx)("div",{className:"rounded-xl border border-dashed border-basalt-700 p-5 text-center text-xs text-basalt-500",children:"Your browser vault remains local until you connect a cloud source."}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/20 p-4 space-y-4",children:[(0,e.jsx)("h3",{className:"text-xs font-bold uppercase tracking-wider text-basalt-400",children:"Connect a new provider"}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[!a?.localOnly&&!C.some(t=>t.provider==="basalt")&&(0,e.jsx)("button",{type:"button",disabled:M,onClick:()=>Ue("basalt"),className:"rounded-lg border border-cyan-300/20 bg-cyan-300/[.04] px-3.5 py-2 text-xs font-semibold text-cyan-200 hover:border-cyan-300/40",children:"Add Phasoric Hosted"}),!a?.localOnly&&Ze.configured?.dropbox&&!C.some(t=>t.provider==="dropbox"&&!t.requiresSecureReconnect)&&(0,e.jsx)("button",{type:"button",disabled:M,onClick:()=>Ue("dropbox"),className:"rounded-lg border border-basalt-800 bg-basalt-950/60 px-3.5 py-2 text-xs font-semibold text-basalt-200 hover:border-basalt-600",children:"Connect Dropbox"}),!a?.localOnly&&Ze.configured?.google&&!C.some(t=>t.provider==="google"&&!t.requiresSecureReconnect)&&(0,e.jsx)("button",{type:"button",disabled:M,onClick:()=>Ue("google"),className:"rounded-lg border border-basalt-800 bg-basalt-950/60 px-3.5 py-2 text-xs font-semibold text-basalt-200 hover:border-basalt-600",children:"Connect Google Drive"}),!a?.localOnly&&Ze.configured?.github&&!C.some(t=>t.provider==="github"&&!t.requiresSecureReconnect)&&(0,e.jsx)("button",{type:"button",disabled:M,onClick:()=>{wa(Je==="github"?"":"github"),S("")},className:`rounded-lg border px-3.5 py-2 text-xs font-semibold ${Je==="github"?"border-accent-cyan bg-accent-cyan/10 text-accent-cyan":"border-basalt-800 bg-basalt-950/60 hover:border-basalt-600 text-basalt-200"}`,children:"Connect GitHub Repository"})]}),Je==="github"&&!C.some(t=>t.provider==="github"&&!t.requiresSecureReconnect)&&(0,e.jsxs)("div",{className:"rounded-xl border border-white/10 bg-white/[.025] p-4 space-y-3",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end",children:[(0,e.jsxs)("label",{className:"min-w-0 flex-1 text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["GitHub repository",(0,e.jsx)("input",{className:`${K} mt-1.5`,value:D.repository,onChange:t=>V({...D,repository:t.target.value}),placeholder:"owner/notes or https://github.com/owner/notes"})]}),(0,e.jsxs)("label",{className:"text-[9px] font-bold uppercase tracking-wider text-basalt-500 lg:w-40",children:["Branch ",(0,e.jsx)("span",{className:"normal-case tracking-normal text-basalt-700",children:"(optional)"}),(0,e.jsx)("input",{className:`${K} mt-1.5`,value:D.branch,onChange:t=>V({...D,branch:t.target.value}),placeholder:"Repository default"})]}),(0,e.jsxs)("label",{className:"min-w-0 flex-1 text-[9px] font-bold uppercase tracking-wider text-basalt-500",children:["Fine-grained token",(0,e.jsx)("input",{type:"password",autoComplete:"off",className:`${K} mt-1.5`,value:D.token,onChange:t=>V({...D,token:t.target.value}),placeholder:"Contents: read and write"})]}),(0,e.jsx)("button",{disabled:M||!D.repository.trim()||!D.token.trim(),onClick:()=>Ue("github"),className:"rounded-lg bg-white px-4 py-2.5 text-[10px] font-bold text-black disabled:opacity-40",children:"Connect repository"})]}),(0,e.jsx)("p",{className:"text-[10px] leading-4 text-basalt-600",children:"The repository key is submitted once, protected by your Phasoric account, and not stored in this browser. Limit it to one repository with Contents read and write access; Phasoric checks the current repository version before saving changes."})]}),a?.localOnly?(0,e.jsx)("p",{className:"text-[10px] leading-4 text-amber-200",children:"Create a Free Phasoric account to connect Dropbox, Google Drive, or GitHub securely."}):null]}),(0,e.jsx)("div",{className:"flex items-center gap-3",children:(0,e.jsx)("span",{className:"text-xs text-basalt-400",children:F})})]}),m==="editor"&&(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Editor & theme"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Control note modes, editor behavior, and the visual system."})]}),(0,e.jsx)(Mn,{settings:L,onChange:Dt}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"mb-2 text-[10px] font-bold uppercase tracking-[0.16em] text-basalt-500",children:"Appearance"}),(0,e.jsx)("div",{className:"grid gap-3 sm:grid-cols-2",children:As.map(t=>(0,e.jsxs)("button",{onClick:()=>{Ee(Ss(t.id)),window.dispatchEvent(new CustomEvent("settings-updated"))},className:`rounded-xl border p-4 text-left ${X===t.id?"border-accent-cyan bg-accent-cyan/5":"border-basalt-800 bg-basalt-950/50"}`,children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("span",{className:"text-xs font-semibold",children:t.name}),(0,e.jsx)("span",{className:"flex gap-1",children:t.colors.map(n=>(0,e.jsx)("i",{className:"h-3 w-3 rounded-full border border-white/10",style:{background:n}},n))})]}),(0,e.jsx)("p",{className:"mt-2 text-[10px] leading-4 text-basalt-500",children:t.description})]},t.id))})]}),(0,e.jsxs)("label",{className:"block text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:[(0,e.jsx)(ts,{size:12,className:"mr-1 inline"}),"Custom CSS overrides",(0,e.jsx)("textarea",{rows:7,className:`${K} mt-2 font-mono`,value:te,onChange:t=>Ra(t.target.value),placeholder:".cm-editor { font-size: 15px; }"})]})]}),m==="files"&&(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Files & links"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Set note locations, link behavior, attachments, and deletion safeguards."})]}),(0,e.jsx)(Rn,{settings:L,onChange:Dt})]}),m==="storage"&&(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"Storage"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-500",children:"Monitor local browser capacity, attachment usage, eviction protection, and Phasoric-hosted storage."})]}),(0,e.jsx)(In,{user:a})]}),m==="billing"&&(0,e.jsxs)("div",{className:"space-y-6",children:[ra()&&(0,e.jsx)(o.Suspense,{fallback:(0,e.jsx)("p",{className:"text-sm text-basalt-400",children:"Loading Google Play purchasesâ¦"}),children:(0,e.jsx)(dr,{user:a},a?.id||"signed-out")}),(0,e.jsx)(Vn,{user:a})]}),m==="connections"&&(0,e.jsx)(Xn,{user:a}),m==="security"&&(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold",children:"End-to-end cloud encryption"}),(0,e.jsx)("p",{className:"mt-1 text-xs leading-5 text-basalt-500",children:"AES-256-GCM protects Markdown before provider upload. The passphrase never leaves this device."})]}),g==="disabled"?(0,e.jsx)("button",{type:"button",onClick:Fa,className:"rounded-lg bg-accent-cyan px-4 py-2 text-xs font-bold text-basalt-950",children:"Enable encryption"}):(0,e.jsxs)("div",{className:"space-y-3",children:[g==="locked"&&(0,e.jsx)("input",{type:"password",minLength:10,className:K,value:ee,onChange:t=>le(t.target.value),onKeyDown:t=>{t.key==="Enter"&&Tt()},placeholder:"Vault passphrase"}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[g==="locked"&&(0,e.jsx)("button",{type:"button",disabled:ee.length<10,onClick:Tt,className:"rounded-lg bg-accent-cyan px-4 py-2 text-xs font-bold text-basalt-950 disabled:opacity-40",children:"Unlock"}),g==="unlocked"&&(0,e.jsx)("button",{type:"button",onClick:Ua,className:"rounded-lg border border-basalt-800 px-4 py-2 text-xs",children:"Lock now"})]})]}),(0,e.jsxs)("label",{className:"block text-xs text-basalt-500",children:["Automatically lock the in-memory vault key after inactivity",(0,e.jsxs)("select",{disabled:g==="disabled",className:`${K} mt-2 disabled:opacity-40`,value:ba,onChange:t=>{const n=cn(t.target.value);ga(n)},children:[(0,e.jsx)("option",{value:"5",children:"5 minutes"}),(0,e.jsx)("option",{value:"15",children:"15 minutes"}),(0,e.jsx)("option",{value:"30",children:"30 minutes"}),(0,e.jsx)("option",{value:"60",children:"1 hour"})]})]}),(0,e.jsxs)("div",{className:"text-xs text-basalt-500",children:["Status: ",(0,e.jsx)("strong",{className:"text-white",children:g})]}),U&&(0,e.jsx)("p",{role:"status",className:"rounded-lg border border-white/[.06] bg-white/[.025] px-3 py-2 text-[10px] leading-5 text-basalt-300",children:U}),(0,e.jsx)("p",{className:"text-[10px] leading-5 text-basalt-600",children:"When encryption is locked, Phasoric pauses Markdown cloud writes instead of falling back to plaintext. Attachments are not encrypted by this
4setting."})]}),m==="intelligence"&&(0,e.jsx)(o.Suspense,{fallback:(0,e.jsx)("div",{className:"py-12 text-center text-[10px] font-bold uppercase tracking-widest text-basalt-500",children:"Loading intelligence settings..."}),children:(0,e.jsx)(cr,{user:a})}),m==="developer"&&(0,e.jsxs)("div",{className:"space-y-6",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"font-outfit text-lg font-semibold text-white",children:"Connect AI tools to Phasoric"}),(0,e.jsx)("p",{className:"mt-1 text-xs text-basalt-400",children:"Connect compatible agents to local or hosted vaults through one shared tool contract. Developer REST API access remains a separate plan capability."})]}),(0,e.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-emerald-500/25 bg-emerald-500/[.03] p-4 space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("span",{className:"text-xs font-bold text-emerald-300",children:"Desktop App Sidecar"}),(0,e.jsx)("span",{className:"rounded bg-emerald-400/20 px-2 py-0.5 text-[9px] font-bold text-emerald-300 uppercase",children:"Included Free"})]}),(0,e.jsxs)("p",{className:"text-[11px] leading-5 text-basalt-300",children:["Active when running the ",(0,e.jsx)("strong",{children:"Phasoric Desktop App"})," (",(0,e.jsx)("code",{className:"text-emerald-300 font-mono text-[10px]",children:"http://localhost:18487"}),"). Exposes local markdown files directly."]})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-blue-400/25 bg-blue-400/[.03] p-4 space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("span",{className:"text-xs font-bold text-blue-300",children:"WebMCP Site Tools"}),(0,e.jsx)("span",{className:"rounded bg-blue-400/20 px-2 py-0.5 text-[9px] font-bold text-blue-300 uppercase",children:"Automatic"})]}),(0,e.jsx)("p",{className:"text-[11px] leading-5 text-basalt-300",children:"Compatible in-app browsers can use the active local vault directly or route a hosted vault through Hosted MCP. Hosted calls reuse your secure signed-in session; no bearer token is exposed to the page."})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-purple-500/25 bg-purple-500/[.03] p-4 space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("span",{className:"text-xs font-bold text-purple-300",children:"Chrome Extension Bridge"}),(0,e.jsx)("span",{className:"rounded bg-purple-400/20 px-2 py-0.5 text-[9px] font-bold text-purple-300 uppercase",children:"In-Browser"})]}),(0,e.jsx)("p",{className:"text-[11px] leading-5 text-basalt-300",children:"Keeps a synchronized, browser-local mirror available to WebMCP and paired browser agents even when Phasoric is closed. Reads use the mirror; every durable agent mutation waits in the extension for explicit human approval, then syncs through the trusted Phasoric page bridge."}),(0,e.jsxs)("label",{className:"block text-[10px] font-bold uppercase tracking-wider text-basalt-500",children:["Pairing token",(0,e.jsx)("input",{className:`${K} mt-1`,type:"password",autoComplete:"off",value:bt,onChange:t=>ya(t.target.value),placeholder:"pmcp_⦠from extension options"})]}),(0,e.jsx)("button",{type:"button",className:"rounded-lg border border-purple-400/30 px-3 py-2 text-[10px] font-bold text-purple-200 hover:bg-purple-400/10",onClick:async()=>{try{yn(bt);const t=await wn({hosted:!a?.localOnly});ft(t.supported?"Paired and synchronized.":"Token saved. Install the extension to finish pairing.")}catch(t){ft(t.message)}},children:"Save and verify pairing"}),(0,e.jsx)("p",{className:"text-[9px] leading-4 text-basalt-500",children:"Copy this token from the extension Options page. It stays on this device and is required for every private mirror operation."}),gt&&(0,e.jsx)("p",{role:"status",className:"text-[9px] leading-4 text-purple-200",children:gt})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-accent-cyan/25 bg-accent-cyan/[.03] p-4 space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("span",{className:"text-xs font-bold text-accent-cyan",children:"Web App & Hosted MCP"}),(0,e.jsx)("span",{className:"rounded bg-accent-cyan/20 px-2 py-0.5 text-[9px] font-bold text-accent-cyan uppercase",children:"Premium and above"})]}),(0,e.jsxs)("p",{className:"text-[11px] leading-5 text-basalt-300",children:["Remote cloud vault access via ",(0,e.jsx)("code",{className:"text-accent-cyan font-mono text-[10px]",children:"https://phasoric.com/api/mcp"}),". Compatible clients use OAuth consent with separate read and write permissions."]})]})]}),(0,e.jsx)(ar,{localOnly:!!a?.localOnly}
4),!a?.localOnly&&(0,e.jsx)(o.Suspense,{fallback:(0,e.jsx)("p",{className:"text-sm text-basalt-400",children:"Loading hosted sourcesâ¦"}),children:(0,e.jsx)(pr,{showIdentifiers:!0})}),(0,e.jsxs)("div",{className:"rounded-xl border border-basalt-800 bg-basalt-950/60 p-4 space-y-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("span",{className:"text-xs font-bold text-white uppercase tracking-wider",children:"Hosted MCP Usage & Quota"}),(0,e.jsxs)("span",{className:"text-xs text-basalt-400 font-mono",children:["Tier: ",(0,e.jsx)("strong",{className:"text-accent-cyan capitalize",children:a?.tier||"Free"})]})]}),je.mcpEnabled?(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex justify-between text-xs text-basalt-300 font-mono",children:[(0,e.jsxs)("span",{children:["Monthly Operations: ",Number(ht?.used||0).toLocaleString()," of ",je.mcpOperationsPerMonth.toLocaleString()," used"]}),(0,e.jsxs)("span",{children:["Rate Limit: ",je.mcpRequestsPerMinute," req/min"]})]}),(0,e.jsx)("div",{className:"h-2 w-full overflow-hidden rounded-full bg-basalt-900 border border-basalt-800",children:(0,e.jsx)("div",{className:"h-full bg-accent-cyan transition-all",style:{width:`${Math.min(100,Number(ht?.used||0)/je.mcpOperationsPerMonth*100)}%`}})})]}):(0,e.jsx)("div",{className:"rounded-lg border border-amber-500/20 bg-amber-500/[.04] p-3 text-xs leading-5 text-amber-200",children:"Hosted MCP access is available on Premium and higher plans. Developer REST API access remains limited to Developer & Agent and Team. Local-only vaults remain on this device."})]}),je.mcpEnabled&&(0,e.jsxs)("div",{className:"space-y-3 pt-2",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-xs font-semibold text-white",children:"Manual bearer token"}),(0,e.jsx)("p",{className:"mt-1 text-[10px] leading-5 text-basalt-500",children:"Use this compatibility option only for clients that cannot complete OAuth. OAuth-connected applications are independently reviewable and revocable above."})]}),(0,e.jsxs)("label",{className:"block text-[10px] font-bold uppercase tracking-wider text-basalt-400",children:[(0,e.jsx)(Ln,{size:12,className:"mr-1 inline text-accent-cyan"}),Mt?"REST & Hosted MCP Bearer Token":"Hosted MCP Bearer Token",(0,e.jsxs)("div",{className:"mt-2 flex gap-2",children:[(0,e.jsx)("input",{readOnly:!0,className:K,value:Ie,placeholder:"Generate a bearer token for compatible hosted MCP clients"}),(0,e.jsx)("button",{type:"button",disabled:!Ie,onClick:()=>{navigator.clipboard.writeText(Ie),yt(!0),setTimeout(()=>yt(!1),1500)},className:"rounded-lg border border-basalt-800 px-3 text-xs disabled:opacity-40",children:ja?(0,e.jsx)(Ya,{size:14,className:"text-emerald-400"}):(0,e.jsx)(Xa,{size:14})})]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,e.jsx)("button",{type:"button",onClick:Ia,className:"rounded-lg border border-basalt-700 px-4 py-2 text-xs font-semibold hover:border-accent-cyan",children:Ie?"Rotate secure token":"Generate secure token"}),(0,e.jsx)("button",{type:"button",onClick:_a,className:"rounded-lg border border-red-400/30 px-4 py-2 text-xs font-semibold text-red-200 hover:border-red-300",children:"Revoke token"}),(0,e.jsx)("span",{className:"text-[10px] text-basalt-500",children:va})]}),(0,e.jsxs)("p",{className:"text-[10px] leading-5 text-basalt-500",children:["The token is shown only when generated and is stored only as a hash by Phasoric. Rotating or revoking it disconnects existing clients. ",Mt?"Your current plan also authorizes this token at the Developer REST API.":"Your current plan does not authorize this token at the Developer REST API."]})]})]})]})]})]}),(0,e.jsx)(lr,{isOpen:ae.isOpen,onClose:()=>kt({...ae,isOpen:!1}),onSelect:$a,provider:ae.provider,connectionId:ae.connectionId,initialPath:ae.initialPath,initialFolderId:ae.initialFolderId,initialRepo:ae.initialRepo}),(0,e.jsx)(ir,{isOpen:fe,onClose:()=>re(!1),onConfirm:Oa,noteCount:pe}),(0,e.jsx)(Ks,{open:ie,onClose:()=>k(!1),defaultKind:"sync_problem",defaultEmail:a?.localOnly?"":a?.email||""})]})}
4export{yo as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.