tokmon 0.23.3 → 0.23.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +3 -3
  2. package/dist/{bootstrap-ink-MBN74IBQ.js → bootstrap-ink-WA3ENW2M.js} +28 -18
  3. package/dist/{chunk-RM3ZE44Z.js → chunk-3TJVFKXV.js} +1 -1
  4. package/dist/{chunk-DJPUYMZM.js → chunk-5CWOJMAH.js} +2 -0
  5. package/dist/{chunk-2AFQKH5O.js → chunk-IELQ5EY3.js} +2 -1
  6. package/dist/{chunk-VVJF5H4D.js → chunk-MJWFCDBB.js} +62 -75
  7. package/dist/{chunk-HXDAOOSI.js → chunk-SMPY52EV.js} +1 -30
  8. package/dist/cli.js +5 -5
  9. package/dist/{config-5CNJN3P7.js → config-QC5QSP3G.js} +1 -1
  10. package/dist/{daemon-F556JO7S.js → daemon-PVYTXJMS.js} +40 -15
  11. package/dist/{daemon-handle-4F4TXGXJ.js → daemon-handle-Y2N2NA6D.js} +8 -9
  12. package/dist/server-XUCQWX6N.js +10 -0
  13. package/dist/web/assets/{Area-DcTSmlQN.js → Area-DCES17aZ.js} +1 -1
  14. package/dist/web/assets/{analytics-B3HJJ-sr.js → analytics-DDW6zcnj.js} +2 -2
  15. package/dist/web/assets/{breakdown-DQ7IarBK.js → breakdown-D5LPPtqh.js} +1 -1
  16. package/dist/web/assets/{chart-BW9JY_zJ.js → chart-bHY7MQV0.js} +1 -1
  17. package/dist/web/assets/{explore-DuOeq8Ih.js → explore-DdWB-Pu7.js} +1 -1
  18. package/dist/web/assets/index-C9jxb2o3.js +83 -0
  19. package/dist/web/assets/index-m0KfWnN2.css +1 -0
  20. package/dist/web/assets/{models-Cn6g6Mqe.js → models-o1wJnG6w.js} +2 -2
  21. package/dist/web/assets/{overview-kWfchbjn.js → overview-wq2uAEk4.js} +2 -2
  22. package/dist/web/assets/{panel-BXWxMzXF.js → panel-DBnK1oy0.js} +1 -1
  23. package/dist/web/assets/{primitives-DiYNjIRG.js → primitives-CBmteetD.js} +1 -1
  24. package/dist/web/assets/settings-sheet-CZ6GEPl3.js +1 -0
  25. package/dist/web/assets/{share-sheet-BauPSkwE.js → share-sheet-DUee3FlK.js} +1 -1
  26. package/dist/web/assets/{timeline-BUwFGhw1.js → timeline-BxHwOJA_.js} +1 -1
  27. package/dist/web/assets/{use-dialog-trap-BZBp1Cz5.js → use-dialog-trap-30EqxYF-.js} +1 -1
  28. package/dist/web/index.html +2 -2
  29. package/package.json +1 -1
  30. package/dist/server-GBB3CR7Y.js +0 -10
  31. package/dist/web/assets/index-DSj-Bxov.css +0 -1
  32. package/dist/web/assets/index-Dkbzrra_.js +0 -83
  33. package/dist/web/assets/settings-sheet-CmXSOk_F.js +0 -1
@@ -1 +0,0 @@
1
- import{A as U,B as re,E as O,F as X,j as e,r as c,S as P,G as H,H as se,I as _,J as D,K as ae,P as ie,L as Y,N as Z,O as W,Q as oe,U as le,V as ce,W as de,Y as q,X as ee,Z as ue,$ as xe,a0 as fe}from"./index-Dkbzrra_.js";import{F as b,u as te}from"./use-dialog-trap-BZBp1Cz5.js";function be(t,r,a,n){return a?{draft:t,revision:r,conflict:r!==null&&n.config.revision>r}:r!==null&&n.config.revision<r?{draft:t,revision:r,conflict:!1}:{draft:n.config,revision:n.config.revision,conflict:!1}}function me(t){var r;if(t&&typeof t=="object"){const a=t;if(a.kind==="conflict"){const n=a.state,o=(r=n==null?void 0:n.config)==null?void 0:r.revision;return{message:typeof o=="number"?`configuration changed elsewhere (daemon revision ${o})`:"settings changed elsewhere; reload before saving",conflictState:n!=null&&n.config&&typeof o=="number"?n:null}}if(a.kind==="persistence"&&typeof a.message=="string")return{message:a.message,conflictState:null}}return{message:t instanceof Error?t.message:"config update failed",conflictState:null}}function J(t,r={}){return{mode:"add",editingId:null,providerId:r.providerId??U[0],name:r.name??"",homeDir:r.homeDir??"~",color:r.color??re(t.accounts)}}function ge(t){return{mode:"edit",editingId:t.id,providerId:t.providerId,name:t.name,homeDir:t.homeDir,color:t.color||O[t.providerId].color}}function pe(t,r){const a=t.mode==="edit"?r.filter(n=>n.id!==t.editingId):r;return t.mode==="edit"?t.editingId??"":X(t.name.trim()||"account",a)}function he(t,r){const a=t.name.trim(),n=t.homeDir.trim()||"~";return a?t.mode==="add"?{ok:!0,account:{id:X(a,r),providerId:t.providerId,name:a,homeDir:n,color:t.color},mode:"add",editingId:null}:{ok:!0,account:{id:t.editingId,providerId:t.providerId,name:a,homeDir:n,color:t.color},mode:"edit",editingId:t.editingId}:{ok:!1,error:"Name required"}}function V({title:t,right:r,children:a}){return e.jsxs("section",{className:"mb-6 last:mb-0",children:[e.jsxs("div",{className:"mb-2.5 flex items-center gap-2 border-b border-line pb-1.5",children:[e.jsx("h3",{className:"font-display text-[11px] uppercase tracking-wider text-fg-dim",children:t}),r&&e.jsx("div",{className:"ml-auto",children:r})]}),a]})}function E({label:t,hint:r,children:a}){return e.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-fg",children:t}),r&&e.jsx("div",{className:"text-[11px] text-fg-faint",children:r})]}),e.jsx("div",{className:"shrink-0",children:a})]})}function B({label:t,hint:r,children:a}){return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-xs font-medium text-fg",children:t}),a,r&&e.jsx("div",{className:"mt-1 text-[11px] text-fg-faint",children:r})]})}function Q({label:t,value:r,min:a,unit:n,onChange:o}){const i=d=>o(Math.max(a,Math.round(d))),[m,p]=c.useState(null),v=()=>{if(m===null)return;const d=Number(m);i(Number.isFinite(d)&&m.trim()!==""?d:a),p(null)};return e.jsxs("div",{className:"flex items-center overflow-hidden rounded border border-line",children:[e.jsx("button",{type:"button","aria-label":"decrease",onClick:()=>i(r-1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${b}`,children:"−"}),e.jsx("input",{type:"number",name:t.toLowerCase().replace(/\s+/g,"-"),autoComplete:"off",inputMode:"numeric",min:a,value:m??r,onChange:d=>{const h=d.target.value;p(h);const j=Number(h);h.trim()!==""&&Number.isFinite(j)&&j>=a&&i(j)},onBlur:v,"aria-label":`${t} (${n})`,className:`tnum w-12 border-x border-line bg-bg-2 px-1 py-1 text-center text-xs text-fg ${b} [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),e.jsx("span",{className:"px-1.5 text-[10px] text-fg-faint",children:n}),e.jsx("button",{type:"button","aria-label":"increase",onClick:()=>i(r+1),className:`px-2 py-1 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg ${b}`,children:"+"})]})}function F({label:t,onClick:r,disabled:a,danger:n,children:o}){return e.jsx("button",{type:"button","aria-label":t,title:t,disabled:a,onClick:r,className:`rounded p-1 text-fg-faint transition disabled:opacity-30 ${b} ${n?"hover:bg-warning/15 hover:text-warning":"hover:bg-bg-3 hover:text-fg"} disabled:hover:bg-transparent disabled:hover:text-fg-faint`,children:o})}function ve({draft:t,patch:r}){return e.jsxs(V,{title:"General",children:[e.jsx(E,{label:"Refresh interval",hint:"dashboard poll, seconds",children:e.jsx(Q,{label:"Refresh interval",value:t.interval,min:1,unit:"s",onChange:a=>r(n=>({...n,interval:a}))})}),e.jsx(E,{label:"Billing poll",hint:"billing refresh, minutes",children:e.jsx(Q,{label:"Billing poll",value:t.billingInterval,min:1,unit:"m",onChange:a=>r(n=>({...n,billingInterval:a}))})}),e.jsx(E,{label:"Clear screen",hint:"redraw on each refresh",children:e.jsx(P,{size:"xs",ariaLabel:"clear screen",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.clearScreen?"on":"off",onChange:a=>r(n=>({...n,clearScreen:a==="on"}))})}),e.jsx(E,{label:"Privacy mode",hint:"hide email addresses by default",children:e.jsx(P,{size:"xs",ariaLabel:"privacy mode",options:[{value:"on",label:"on"},{value:"off",label:"off"}],value:t.privacyMode?"on":"off",onChange:a=>r(n=>({...n,privacyMode:a==="on"}))})}),e.jsx(E,{label:"Timezone",hint:"IANA name · empty = System",children:e.jsx(je,{value:t.timezone,onChange:a=>r(n=>({...n,timezone:a}))})}),e.jsx(E,{label:"Dashboard",hint:"grid shows all · single cycles",children:e.jsx(P,{size:"xs",ariaLabel:"dashboard layout",options:[{value:"grid",label:"grid"},{value:"single",label:"single"}],value:t.dashboardLayout,onChange:a=>r(n=>({...n,dashboardLayout:a}))})}),e.jsx(E,{label:"Default focus",hint:"on open",children:e.jsx(P,{size:"xs",ariaLabel:"default focus",options:[{value:"all",label:"all"},{value:"last",label:"last"}],value:t.defaultFocus,onChange:a=>r(n=>({...n,defaultFocus:a}))})}),e.jsx(E,{label:"ASCII mode",hint:"glyph fallback",children:e.jsx(P,{size:"xs",ariaLabel:"ascii mode",options:[{value:"auto",label:"auto"},{value:"on",label:"on"},{value:"off",label:"off"}],value:t.ascii,onChange:a=>r(n=>({...n,ascii:a}))})})]})}function je({value:t,onChange:r}){const[a,n]=c.useState(t??""),[o,i]=c.useState(!1),m=c.useId();c.useEffect(()=>{n(t??""),i(!1)},[t]);const p=v=>{const d=H(v);n(d);const h=d.trim();if(!h){i(!1),r(null);return}se(h)?(i(!1),r(h)):i(!0)};return e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("input",{type:"text",name:"timezone",value:a,placeholder:"e.g. Europe/Bucharest…","aria-label":"Timezone","aria-describedby":o?m:void 0,autoComplete:"off",spellCheck:!1,"aria-invalid":o,onChange:v=>p(v.target.value),className:`w-44 rounded border bg-bg-2 px-2 py-1 text-xs text-fg ${b} ${o?"border-warning":"border-line"}`}),o&&e.jsx("span",{id:m,className:"text-[10px] text-warning",role:"alert",children:"Use an IANA zone such as Europe/Bucharest."})]})}function ye({draft:t,patch:r}){const a=(n,o)=>r(i=>({...i,knownProviders:i.knownProviders.includes(n)?i.knownProviders:[...i.knownProviders,n],disabledProviders:o?i.disabledProviders.filter(m=>m!==n):Array.from(new Set([...i.disabledProviders,n]))}));return e.jsx(V,{title:"Providers",children:e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:U.map(n=>{const o=!t.disabledProviders.includes(n),i=O[n];return e.jsxs("button",{type:"button",role:"switch","aria-checked":o,onClick:()=>a(n,!o),className:`flex items-center gap-2.5 rounded border px-3 py-2 text-left text-xs transition ${b} ${o?"border-line-2 bg-bg-2 text-fg":"border-line bg-bg-1 text-fg-faint hover:border-line-2"}`,children:[e.jsx("span",{className:"inline-flex size-4 shrink-0 items-center justify-center rounded-sm border",style:{borderColor:o?D(i.color):"var(--color-line-2)",background:o?D(i.color):"transparent"},children:o&&e.jsx(_,{className:"size-3 text-bg-0"})}),e.jsx("span",{className:"size-2 shrink-0 rounded-full",style:{background:D(i.color)},"aria-hidden":!0}),e.jsx("span",{className:`font-medium ${o?"text-fg":"text-fg-faint"}`,children:i.name}),e.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-wide text-fg-faint",children:o?"tracking":"off"})]},n)})})})}function Ne(t,r){return r?r.accounts.find(a=>a.id===t.id)??null:null}function ke({draft:t,patch:r,snapshot:a,onEdit:n,onConfigure:o,onAdd:i}){const m=ae(t,void 0,(a==null?void 0:a.accounts)??void 0),[p,v]=c.useState(null),d=s=>r(u=>({...u,activeAccountId:s})),h=s=>{if(p!==s){v(s);return}r(u=>({...u,accounts:u.accounts.filter(x=>x.id!==s),activeAccountId:u.activeAccountId===s?null:u.activeAccountId})),v(null)},j=(s,u)=>r(x=>{const k=[...x.accounts],y=s+u;return y<0||y>=k.length?x:([k[s],k[y]]=[k[y],k[s]],{...x,accounts:k})});return e.jsx(V,{title:"Accounts",right:e.jsxs("button",{type:"button",onClick:i,className:`flex items-center gap-1 rounded border border-accent/60 bg-bg-1 px-2 py-1 text-[11px] text-accent transition hover:bg-bg-2 ${b}`,children:[e.jsx(le,{className:"size-3"})," Add account"]}),children:m.length===0?e.jsx("p",{className:"rounded border border-line bg-bg-2/50 px-3 py-3 text-xs text-fg-faint",children:"None configured — enabled providers track automatically."}):e.jsx("ul",{className:"flex flex-col gap-1.5",role:"radiogroup","aria-label":"Active account",children:m.map(s=>{var $;const u=O[s.providerId],x=Ne(s,a),k=(x==null?void 0:x.email)||(x==null?void 0:x.displayName)||s.name||u.name,y=(x==null?void 0:x.plan)??(($=x==null?void 0:x.billing)==null?void 0:$.plan)??null,w=D(s.color||u.color),N=s.id===t.activeAccountId,C=s.source==="configured";return e.jsxs("li",{className:"flex items-center gap-2.5 rounded border border-line bg-bg-2/60 px-2.5 py-2",children:[e.jsx("button",{type:"button",role:"radio","aria-checked":N,"aria-label":`Set ${s.name} active`,title:N?"Active account (click to clear)":"Set active",onClick:()=>d(N?null:s.id),className:`relative inline-flex size-4 shrink-0 items-center justify-center rounded-full border transition ${b}`,style:{borderColor:w},children:N&&e.jsx("span",{className:"size-2 rounded-full",style:{background:w}})}),e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{background:w},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{value:k,privacyMode:t.privacyMode,className:"truncate text-sm text-fg-bright"}),e.jsx("span",{className:"shrink-0 rounded bg-bg-3 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-dim",children:u.name}),y&&e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] text-fg-dim",children:y}),e.jsx("span",{className:"shrink-0 rounded border border-line px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-fg-faint",children:s.source==="auto"?"auto":"configured"})]}),e.jsx("div",{className:"truncate font-mono text-[11px] text-fg-faint",children:s.homeDir})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[p===s.id?e.jsx("span",{className:"mr-1 text-[10px] text-warning",role:"alert",children:"Delete?"}):null,C&&s.explicitIndex!==void 0?e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Move up",disabled:s.explicitIndex===0,onClick:()=>j(s.explicitIndex,-1),children:e.jsx(Y,{className:"size-3.5"})}),e.jsx(F,{label:"Move down",disabled:s.explicitIndex===t.accounts.length-1,onClick:()=>j(s.explicitIndex,1),children:e.jsx(Z,{className:"size-3.5"})}),e.jsx(F,{label:"Edit account",onClick:()=>n(s),children:e.jsx(W,{className:"size-3.5"})}),e.jsx(F,{label:p===s.id?"Confirm delete account":"Delete account",danger:!0,onClick:()=>h(s.id),children:e.jsx(oe,{className:"size-3.5"})})]}):e.jsx(F,{label:"Configure account",onClick:()=>o(s),children:e.jsx(W,{className:"size-3.5"})})]})]},`${s.source}:${s.id}`)})})})}function we(t){const r=(t??"").trim();return r.length>0?r:"~"}function G(t){const r=(t??"").trim();return r.length>0?r:"~"}function Ce(t){const r=[];t.parent!==null&&r.push({kind:"parent",key:"..",label:"..",path:t.parent});for(const a of[...t.entries].filter(n=>n.dir).sort((n,o)=>n.name.localeCompare(o.name)))r.push({kind:"entry",key:a.path,label:a.name,path:a.path});return r}function Ie({editor:t,accounts:r,onChange:a,onCancel:n,onSubmit:o}){const i=c.useRef(null),m=c.useRef(null),[p,v]=c.useState(null),d=D(t.color);te(i,{active:!0,onEscape:n,initialFocusRef:m});const h=pe(t,r),j=()=>{const s=he(t,r);if(!s.ok){v(s.error);return}o(s.account,s.mode,s.editingId)};return e.jsx("div",{className:"dialog-fade fixed inset-0 z-[70] flex items-start justify-center overflow-y-auto overscroll-contain bg-bg-0/60 p-4 backdrop-blur-sm",onMouseDown:s=>{s.target===s.currentTarget&&n()},role:"dialog","aria-modal":"true","aria-labelledby":"account-editor-title",children:e.jsxs("div",{ref:i,tabIndex:-1,className:"dialog-pop my-8 w-full max-w-[460px] overflow-hidden rounded-md border-l-2 border border-line-2 bg-bg-1 focus:outline-none",style:{borderLeftColor:d},children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line px-4 py-3",children:[e.jsx("span",{className:"size-2.5 rounded-full",style:{background:d},"aria-hidden":!0}),e.jsx("h2",{id:"account-editor-title",className:"font-display text-xs uppercase tracking-wider text-fg-bright",children:t.mode==="add"?"New account":"Edit account"})]}),e.jsxs("div",{className:"flex flex-col gap-4 px-4 py-4",children:[e.jsx(B,{label:"Provider",hint:"which tool this account tracks",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.map(s=>{const u=s===t.providerId,x=O[s];return e.jsxs("button",{type:"button",onClick:()=>a({...t,providerId:s}),"aria-pressed":u,className:`flex items-center gap-1.5 rounded border px-2 py-1 text-xs transition ${b} ${u?"border-line-2 bg-bg-3 text-fg-bright":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:"size-2 rounded-full",style:{background:D(x.color)},"aria-hidden":!0}),x.name]},s)})})}),e.jsx(B,{label:"Name",hint:"display name for this account",children:e.jsx("input",{ref:m,type:"text",name:"account-name",value:t.name,placeholder:"e.g. Work…","aria-label":"Account name",autoComplete:"off",spellCheck:!1,onChange:s=>{v(null),a({...t,name:H(s.target.value)})},onKeyDown:s=>{s.key==="Enter"&&j()},className:`w-full rounded border border-line bg-bg-2 px-2.5 py-1.5 text-sm text-fg ${b}`})}),e.jsx(B,{label:"Home directory",hint:"path containing the tool's data dir · ~ for default",children:e.jsx(Se,{value:t.homeDir,onChange:s=>a({...t,homeDir:s}),onEnter:j})}),e.jsx(B,{label:"Accent color",hint:"shows on dashboard, account strip, borders",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(s=>{const u=s===t.color;return e.jsx("button",{type:"button","aria-label":s,"aria-pressed":u,title:s,onClick:()=>a({...t,color:s}),className:`size-6 rounded-full border-2 transition ${b} ${u?"scale-110":"border-transparent hover:scale-105"}`,style:{background:D(s),borderColor:u?"var(--color-fg-bright)":"transparent"}},s)})})}),e.jsxs("div",{className:"flex items-center gap-2 rounded border border-line bg-bg-2/50 px-2.5 py-1.5 text-xs",children:[e.jsx("span",{className:"text-fg-faint",children:"id"}),e.jsx("span",{className:"font-mono text-fg",style:{color:d},children:h||"account"}),e.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:t.mode==="add"?"auto-generated from name":"fixed"})]}),p&&e.jsxs("p",{className:"text-xs text-warning",role:"alert",children:[p,". Check the highlighted account fields and try again."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-line px-4 py-3",children:[e.jsx("button",{type:"button",onClick:n,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${b}`,children:"cancel"}),e.jsxs("button",{type:"button",onClick:j,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] ${b}`,children:[e.jsx(_,{className:"size-3.5"})," ",t.mode==="add"?"Add account":"Save account"]})]})]})})}function Se({value:t,onChange:r,onEnter:a}){const[n,o]=c.useState(!1),[i,m]=c.useState(null),[p,v]=c.useState("~"),[d,h]=c.useState(!1),[j,s]=c.useState(null),u=c.useRef(0),x=c.useCallback(async g=>{const S=++u.current,A=we(g);v(A),h(!0),s(null);try{const z=await de(A);if(S!==u.current)return;m(z)}catch(z){if(S!==u.current)return;m(null),s(z instanceof Error?z.message:"cannot read folder")}finally{S===u.current&&h(!1)}},[]);c.useEffect(()=>()=>{u.current++},[]);const k=()=>{o(!0),x(t)},y=()=>{u.current++,o(!1),h(!1),s(null)},w=g=>{d||x(g)},N=()=>{!i||d||(r(G(i.path)),y())},C=i?Ce(i):[],$=C.filter(g=>g.kind==="entry"),I=G((i==null?void 0:i.path)??p);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex overflow-hidden rounded border border-line bg-bg-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2.5",children:[e.jsx(q,{className:"size-4 shrink-0 text-fg-faint"}),e.jsx("input",{type:"text",name:"account-home-directory",value:t,placeholder:"e.g. ~/work…","aria-label":"Account home directory",autoComplete:"off",spellCheck:!1,onChange:g=>{y(),r(H(g.target.value))},onKeyDown:g=>{g.key==="Enter"&&a()},className:`min-w-0 flex-1 bg-transparent py-1.5 font-mono text-sm text-fg ${b}`})]}),e.jsxs("button",{type:"button",onClick:k,disabled:d,className:`flex shrink-0 items-center gap-1 border-l border-line bg-bg-1 px-2.5 py-1.5 text-xs text-fg-dim transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${b}`,children:[e.jsx(Z,{className:"size-3.5"})," Browse"]})]}),n&&e.jsxs("div",{className:"mt-2 overflow-hidden rounded border border-line-2 bg-bg-1 shadow-[0_18px_60px_rgba(0,0,0,0.35)]",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line bg-bg-2 px-2.5 py-2",children:[e.jsx(q,{className:"size-4 shrink-0 text-accent"}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-xs text-fg-bright",title:I,children:I}),d&&e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-fg-faint",children:"loading"}),e.jsx("button",{type:"button",onClick:y,"aria-label":"Close folder picker",className:`rounded p-1 text-fg-faint transition hover:text-fg ${b}`,children:e.jsx(ee,{className:"size-3.5"})})]}),j?e.jsxs("div",{className:"px-2.5 py-3",children:[e.jsxs("div",{className:"text-xs text-warning",children:["can't read ",G(p)]}),e.jsx("button",{type:"button",onClick:()=>{d||x(p)},disabled:d,className:`mt-2 rounded border border-line bg-bg-2 px-2 py-1 text-[11px] text-fg-dim transition hover:border-line-2 hover:text-fg disabled:opacity-50 ${b}`,children:"retry"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-h-56 overflow-y-auto py-1",children:[C.map(g=>e.jsxs("button",{type:"button",onClick:()=>w(g.path),disabled:d,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition hover:bg-bg-3 hover:text-fg disabled:opacity-50 ${b} ${g.kind==="parent"?"text-fg-dim":"text-fg"}`,children:[g.kind==="parent"?e.jsx(Y,{className:"size-3.5 shrink-0"}):e.jsx(q,{className:"size-3.5 shrink-0 text-fg-faint"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:g.label})]},g.key)),!d&&$.length===0&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",children:"no subdirectories"}),d&&!i&&e.jsx("div",{className:"px-2.5 py-3 text-xs text-fg-faint",role:"status","aria-live":"polite",children:"loading folders…"})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 border-t border-line px-2.5 py-2",children:e.jsxs("button",{type:"button",onClick:N,disabled:!i||d,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-2.5 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${b}`,children:[e.jsx(_,{className:"size-3.5"})," Select this folder"]})})]})]})]})}const ze=[{value:"general",label:"General"},{value:"providers",label:"Providers"},{value:"accounts",label:"Accounts"}];function $e({onClose:t,snapshot:r}){const a=c.useRef(null),[n,o]=c.useState(null),[i,m]=c.useState(null),[p,v]=c.useState(null),[d,h]=c.useState(!1),[j,s]=c.useState(null),[u,x]=c.useState(!1),[k,y]=c.useState(!1),[w,N]=c.useState(null),[C,$]=c.useState("general"),I=c.useRef(!1),g=c.useRef(!1),S=c.useRef(null),A=c.useRef(null),z=c.useCallback(l=>{v(null);const f=be(S.current,A.current,I.current,l);I.current||(S.current=f.draft,A.current=f.revision,o(f.draft),m(f.revision)),f.conflict&&s("settings changed elsewhere; close and reopen settings before saving")},[]);c.useEffect(()=>{let l=!0;return ue().then(f=>{l&&z(f)}).catch(f=>{l&&v(f instanceof Error?f.message:"load failed")}),()=>{l=!1}},[z]),c.useEffect(()=>{const l=f=>{I.current&&f.preventDefault()};return window.addEventListener("beforeunload",l),()=>window.removeEventListener("beforeunload",l)},[]),c.useEffect(()=>{let l=!0;const f=xe(R=>{l&&z(R)});return()=>{l=!1,f()}},[z]);const L=()=>{if(!I.current||g.current){t();return}g.current=!0,y(!0),s("unsaved changes; choose discard to close settings")};te(a,{active:!w,onEscape:L}),c.useEffect(()=>{const l=a.current;l&&(w?l.setAttribute("inert",""):l.removeAttribute("inert"))},[w]);const T=l=>{const f=S.current;if(!f)return;const R={...l(f),revision:f.revision};I.current=!0,S.current=R,x(!0),g.current=!1,y(!1),s(null),o(R)},ne=async()=>{if(n){h(!0),s(null);try{if(i===null)throw new Error("config revision is unavailable");const l=await fe(n,i);S.current=l.config,A.current=l.config.revision,I.current=!1,o(l.config),m(l.config.revision),x(!1),t()}catch(l){const f=me(l);s(f.conflictState?`${f.message}; close and reopen settings before saving`:f.message)}finally{h(!1)}}};return e.jsxs("div",{className:"dialog-fade fixed inset-0 z-[60] flex items-start justify-center overflow-y-auto overscroll-contain bg-bg-0/70 p-4 backdrop-blur-sm",onMouseDown:l=>{l.target===l.currentTarget&&!w&&L()},role:"dialog","aria-modal":"true","aria-labelledby":"settings-title",children:[e.jsxs("div",{ref:a,tabIndex:-1,className:"dialog-pop relative my-6 flex w-full max-w-[720px] flex-col overflow-hidden rounded-md border border-line-2 bg-bg-1 focus:outline-none",children:[e.jsx("h2",{id:"settings-title",className:"pointer-events-none absolute left-3 top-2 font-display text-[11px] uppercase tracking-wider text-fg-dim",children:"settings"}),e.jsx("button",{type:"button",onClick:L,"aria-label":"Close",className:`absolute right-2 top-2 z-10 rounded p-1 text-fg-faint transition hover:text-fg ${b}`,children:e.jsx(ee,{className:"size-4"})}),e.jsx("div",{className:"max-h-[78vh] overflow-y-auto px-5 pb-4 pt-9",children:p&&!n?e.jsxs("div",{className:"rounded border border-warning/50 bg-bg-2 p-4 text-sm text-warning",role:"alert",children:["Could not load settings: ",p,". Close settings and try again."]}):n?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-line pb-3",children:e.jsx(P,{size:"xs",ariaLabel:"settings section",options:ze,value:C,onChange:$,containerClassName:"flex items-center overflow-hidden rounded border border-line bg-bg-1",btnClassName:"px-3 py-1.5 text-[11px] transition"})}),C==="general"&&e.jsx(ve,{draft:n,patch:T}),C==="providers"&&e.jsx(ye,{draft:n,patch:T}),C==="accounts"&&e.jsx(ke,{draft:n,patch:T,snapshot:r,onEdit:l=>N(ge(l)),onConfigure:l=>N(J(n,{providerId:l.providerId,name:l.name,homeDir:l.homeDir,color:l.color})),onAdd:()=>N(J(n))})]}):e.jsx("div",{className:"py-10 text-center text-sm text-fg-dim",children:"loading config…"})}),e.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-line px-5 py-3",children:[j&&e.jsx("span",{className:"mr-auto text-xs text-warning",role:"alert",children:j}),u&&!j&&e.jsx("span",{className:"mr-auto text-xs text-fg-faint",role:"status","aria-live":"polite",children:"unsaved changes"}),e.jsx("button",{type:"button",onClick:L,className:`rounded border border-line bg-bg-1 px-3 py-1.5 text-xs text-fg-dim transition hover:border-line-2 hover:text-fg ${b}`,children:k?"discard":"cancel"}),e.jsxs("button",{type:"button",onClick:ne,disabled:!n||d||!u,className:`flex items-center gap-1.5 rounded border border-accent/60 bg-bg-1 px-3 py-1.5 text-xs text-accent transition hover:bg-bg-2 active:scale-[0.97] disabled:opacity-50 ${b}`,children:[e.jsx(_,{className:"size-3.5"})," ",d?"saving…":"save"]})]})]}),w&&n&&e.jsx(Ie,{editor:w,accounts:n.accounts,onChange:N,onCancel:()=>N(null),onSubmit:(l,f,R)=>{T(M=>f==="add"?{...M,accounts:[...M.accounts,l]}:{...M,accounts:M.accounts.map(K=>K.id===R?l:K)}),N(null)}})]})}export{$e as SettingsSheet};