import{a as N,k as l,r as o,j as e,c as h,P as v,T as K,n as S,o as A}from"./index-CUDottTv.js";import{C as W}from"./chevron-right-Df1qu9CE.js";import{T as k}from"./trash-2-C4Tvwfqn.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const E=N("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=N("Users",[["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"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]),C="bg-bg-elevated border border-border-default rounded-lg",b="h-8 px-3 rounded-md text-[12px] font-medium transition-colors cursor-pointer inline-flex items-center gap-1.5",m=`${b} bg-accent text-white hover:bg-accent/90`,u=`${b} text-text-secondary hover:text-text-primary hover:bg-bg-hover`,w=`${b} text-red hover:bg-red/10`;function M(){const t=l(a=>a.workspaces),c=l(a=>a.workspacesLoading),n=l(a=>a.fetchWorkspaces);o.useEffect(()=>{n()},[n]);const[r,d]=o.useState(null),x=t.find(a=>a.id===r)??null;return o.useEffect(()=>{!r&&t.length>0&&d(t[0].id)},[t,r]),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("div",{className:"w-[300px] border-r border-border-muted flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-muted",children:[e.jsx("h2",{className:"text-[13px] font-semibold uppercase tracking-wider text-text-muted",children:"Workspaces"}),e.jsx(P,{})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[c&&t.length===0&&e.jsx("div",{className:"text-[12px] text-text-muted px-3 py-4",children:"Loading…"}),t.map(a=>e.jsxs("button",{onClick:()=>d(a.id),className:h("w-full flex items-center justify-between gap-2 px-3 py-2 rounded-md text-[13px] text-left cursor-pointer transition-colors",r===a.id?"bg-accent-muted text-text-primary":"hover:bg-bg-hover text-text-secondary"),children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx(L,{size:14,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:a.name}),a.isDefault&&e.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide",children:"default"})]}),e.jsx(W,{size:14,className:"text-text-muted shrink-0"})]},a.id))]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:x?e.jsx(z,{workspace:x}):e.jsx("div",{className:"text-[13px] text-text-muted",children:"Select a workspace"})})]})}function P(){const t=l(i=>i.createWorkspace),[c,n]=o.useState(!1),[r,d]=o.useState(""),[x,a]=o.useState(""),p=async()=>{if(!r.trim())return;await t({name:r.trim(),description:x.trim()||void 0})&&(d(""),a(""),n(!1))};return c?e.jsxs("div",{className:"absolute top-14 left-2 right-2 z-20 bg-bg-surface border border-border-strong rounded-lg p-3 shadow-lg space-y-2",children:[e.jsx("input",{autoFocus:!0,value:r,onChange:i=>d(i.target.value),onKeyDown:i=>{i.key==="Enter"&&p(),i.key==="Escape"&&n(!1)},placeholder:"Workspace name",className:"w-full h-8 bg-bg-input border border-border-strong rounded-md px-2 text-[12px] outline-none focus:border-accent-border"}),e.jsx("input",{value:x,onChange:i=>a(i.target.value),placeholder:"Description (optional)",className:"w-full h-8 bg-bg-input border border-border-strong rounded-md px-2 text-[12px] outline-none focus:border-accent-border"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>n(!1),className:u,children:"Cancel"}),e.jsx("button",{onClick:p,className:m,children:"Create"})]})]}):e.jsxs("button",{onClick:()=>n(!0),className:m,children:[e.jsx(v,{size:12}),"New"]})}function z({workspace:t}){const c=l(r=>r.deleteWorkspace),n=l(r=>r.updateWorkspace);return e.jsxs("div",{className:"max-w-3xl space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-text-primary",children:t.name}),t.description&&e.jsx("p",{className:"text-[13px] text-text-muted mt-0.5",children:t.description}),e.jsxs("p",{className:"text-[11px] text-text-muted font-mono mt-1",children:[t.id," · slug: ",t.slug]})]}),!t.isDefault&&e.jsxs("button",{onClick:()=>{confirm(`Delete workspace "${t.name}"? Its projects will be moved to the default workspace.`)&&c(t.id)},className:w,children:[e.jsx(k,{size:12}),"Delete"]})]}),e.jsx(T,{workspace:t,onSave:r=>n(t.id,r)}),e.jsx($,{workspaceId:t.id})]})}function T({workspace:t,onSave:c}){const[n,r]=o.useState(t.name),[d,x]=o.useState(t.description??""),a=n!==t.name||(d||void 0)!==t.description;return o.useEffect(()=>{r(t.name),x(t.description??"")},[t.id]),e.jsxs("div",{className:`${C} p-4 space-y-3`,children:[e.jsx("h3",{className:"text-[13px] font-semibold",children:"Details"}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[11px] uppercase text-text-muted tracking-wider",children:"Name"}),e.jsx("input",{value:n,onChange:p=>r(p.target.value),className:"w-full mt-1 h-8 bg-bg-input border border-border-strong rounded-md px-2.5 text-[13px] outline-none focus:border-accent-border"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[11px] uppercase text-text-muted tracking-wider",children:"Description"}),e.jsx("input",{value:d,onChange:p=>x(p.target.value),className:"w-full mt-1 h-8 bg-bg-input border border-border-strong rounded-md px-2.5 text-[13px] outline-none focus:border-accent-border"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{disabled:!a,onClick:()=>c({name:n,description:d||void 0}),className:h(m,!a&&"opacity-40 cursor-not-allowed"),children:"Save"})})]})}function $({workspaceId:t}){const c=l(s=>s.apiKeysByWorkspace[t]??[]),n=l(s=>s.apiKeysLoading[t]??!1),r=l(s=>s.fetchApiKeys),d=l(s=>s.createApiKey),x=l(s=>s.revokeApiKey),a=l(s=>s.newlyCreatedKey),p=l(s=>s.clearNewlyCreatedKey),[i,f]=o.useState(""),[g,j]=o.useState(!1);o.useEffect(()=>{r(t),p()},[t,r,p]);const y=o.useCallback(async()=>{if(!i.trim())return;await d(t,i.trim())&&f("")},[i,t,d]),D=o.useCallback(s=>{navigator.clipboard.writeText(s),j(!0),setTimeout(()=>j(!1),2e3)},[]);return e.jsxs("div",{className:`${C} p-4 space-y-3`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-[13px] font-semibold flex items-center gap-2",children:[e.jsx(E,{size:14}),"API Keys"]}),e.jsxs("span",{className:"text-[11px] text-text-muted",children:[c.length," active"]})]}),a&&a.workspaceId===t&&e.jsxs("div",{className:"bg-amber/10 border border-amber/40 rounded-md p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(K,{size:14,className:"text-amber shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-[12px] text-text-primary",children:[e.jsx("div",{className:"font-semibold",children:"Copy this secret now — it won't be shown again."}),e.jsxs("div",{className:"text-text-tertiary mt-0.5",children:["Use it in a DSN: ",e.jsxs("code",{className:"font-mono text-[11px]",children:["runtimescope://proj_xxx:",a.key.slice(0,12),"...@host/app"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 font-mono text-[12px] bg-bg-input px-2 py-1.5 rounded border border-border-strong overflow-x-auto",children:a.key}),e.jsxs("button",{onClick:()=>D(a.key),className:u,title:"Copy to clipboard",children:[g?e.jsx(S,{size:12}):e.jsx(A,{size:12}),g?"Copied":"Copy"]}),e.jsx("button",{onClick:p,className:u,children:"Done"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:s=>f(s.target.value),onKeyDown:s=>{s.key==="Enter"&&y()},placeholder:"Label (e.g. 'CI server', 'Production backend')",className:"flex-1 h-8 bg-bg-input border border-border-strong rounded-md px-2.5 text-[13px] outline-none focus:border-accent-border"}),e.jsxs("button",{onClick:y,disabled:!i.trim(),className:h(m,!i.trim()&&"opacity-40 cursor-not-allowed"),children:[e.jsx(v,{size:12}),"Create key"]})]}),n&&c.length===0&&e.jsx("div",{className:"text-[12px] text-text-muted py-3",children:"Loading…"}),!n&&c.length===0&&e.jsx("div",{className:"text-[12px] text-text-muted py-3",children:"No API keys yet. Create one to let SDKs authenticate with this workspace."}),c.length>0&&e.jsx("div",{className:"space-y-1",children:c.map(s=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-md hover:bg-bg-hover group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-text-primary",children:s.label}),e.jsxs("div",{className:"text-[11px] text-text-muted font-mono truncate",children:[s.keyPrefix,"…",s.keyLast4," · created ",new Date(s.createdAt).toLocaleDateString(),s.lastUsedAt&&` · last used ${new Date(s.lastUsedAt).toLocaleString()}`]})]}),e.jsxs("button",{onClick:()=>{confirm(`Revoke key "${s.label}"? SDKs using it will stop authenticating.`)&&x(s.keyPrefix,t)},className:`${w} opacity-0 group-hover:opacity-100`,children:[e.jsx(k,{size:12}),"Revoke"]})]},s.keyPrefix))})]})}export{M as SettingsPage};
