import{a as l,j as e}from"./vendor-query-DXFmKafw.js";import{u as D,j as A,D as L,a as R,b as I,c as T,d as V,F as H,k as P,l as q,m as B,n as G,I as v,o as K,S,p as b,q as N,r as y,s,h as X,B as z,t as J,v as O}from"./index-DA9bQbeu.js";import{M as Q,E as U,L as W}from"./limit-rules-editor-Q16dwyTA.js";import"./vendor-react-BuboTVMM.js";import"./vendor-charts-DXotOivX.js";import"./vendor-ui-BNl_w7ov.js";const Y=J({name:O().min(1,"Name is required")});function ae({open:E,busy:C,onOpenChange:c,onSubmit:M}){const a=D({resolver:A(Y),defaultValues:{name:""}}),[r,d]=l.useState([]),[m,x]=l.useState([]),[u,h]=l.useState(null),[n,j]=l.useState(""),[i,f]=l.useState("none"),[o,p]=l.useState("none"),F=async t=>{const g=m.filter(w=>w.maxValue>0),k={name:t.name,allowedModels:r.length>0?r:void 0,enforcedModel:n.trim()?n.trim():null,enforcedReasoningEffort:i==="none"?null:i,enforcedServiceTier:o==="none"?null:o,expiresAt:u?.toISOString(),limits:g.length>0?g:void 0};try{await M(k)}catch{return}a.reset(),d([]),x([]),h(null),j(""),f("none"),p("none"),c(!1)};return e.jsx(L,{open:E,onOpenChange:c,children:e.jsxs(R,{className:"sm:max-w-3xl",children:[e.jsxs(I,{children:[e.jsx(T,{children:"Create API key"}),e.jsx(V,{children:"Set restrictions and expiration for this key."})]}),e.jsx(H,{...a,children:e.jsxs("form",{onSubmit:a.handleSubmit(F),children:[e.jsxs("div",{className:"grid gap-x-6 sm:grid-cols-2",children:[e.jsxs("div",{className:"max-h-[55vh] space-y-3 overflow-y-auto overscroll-contain pl-1 pr-2",children:[e.jsx("h4",{className:"sticky top-0 bg-background pb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"General"}),e.jsx(P,{control:a.control,name:"name",render:({field:t})=>e.jsxs(q,{children:[e.jsx(B,{children:"Name"}),e.jsx(G,{children:e.jsx(v,{...t,autoComplete:"off"})}),e.jsx(K,{})]})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Allowed models"}),e.jsx(Q,{value:r,onChange:d})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Enforced model"}),e.jsx(v,{value:n,onChange:t=>j(t.target.value),placeholder:"e.g. gpt-5.3-codex",autoComplete:"off"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Enforced reasoning"}),e.jsxs(S,{value:i,onValueChange:f,children:[e.jsx(b,{children:e.jsx(N,{placeholder:"None"})}),e.jsxs(y,{children:[e.jsx(s,{value:"none",children:"None"}),e.jsx(s,{value:"minimal",children:"Minimal"}),e.jsx(s,{value:"low",children:"Low"}),e.jsx(s,{value:"medium",children:"Medium"}),e.jsx(s,{value:"high",children:"High"}),e.jsx(s,{value:"xhigh",children:"XHigh"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Enforced service tier"}),e.jsxs(S,{value:o,onValueChange:p,children:[e.jsx(b,{children:e.jsx(N,{placeholder:"None"})}),e.jsxs(y,{children:[e.jsx(s,{value:"none",children:"None"}),e.jsx(s,{value:"auto",children:"Auto"}),e.jsx(s,{value:"default",children:"Default"}),e.jsx(s,{value:"priority",children:"Priority"}),e.jsx(s,{value:"flex",children:"Flex"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Expiry"}),e.jsx(U,{value:u,onChange:h})]})]}),e.jsxs("div",{className:"max-h-[55vh] space-y-3 overflow-y-auto overscroll-contain pl-1 pr-2 max-sm:mt-3 max-sm:border-t max-sm:pt-3",children:[e.jsx("h4",{className:"sticky top-0 bg-background pb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Limits"}),e.jsx(W,{rules:m,onChange:x})]})]}),e.jsx(X,{className:"mt-4",children:e.jsx(z,{type:"submit",disabled:C||a.formState.isSubmitting,children:"Create"})})]})})]})})}export{ae as ApiKeyCreateDialog};
