1import{j as e,r as m}from"./index-B-tnKWcX.js";import{e as Js,H as F,J as Xs,K as Zs,O as et,Q as st,U as tt,f as S,V as at,X as se,Y as rt,Z as cs,$ as ms,a0 as us,a1 as ie,a2 as de,a3 as z,a4 as ps,a5 as nt,a6 as ot,a7 as lt,a8 as it,a9 as dt,aa as ct,ab as mt,ac as ut,ad as pt,ae as hs,af as ht,ag as xt,z as P,ah as ce,ai as me,aj as ue,ak as pe,al as he,am as xe,D as fe,an as ft,x as xs,ao as gt,v as yt,L as bt,ap as vt,y as jt,aq as Nt,ar as wt,as as te,at as ae,au as Ct}from"./Index-CJ97Z0YX.js";import{P as kt}from"./PortalShell-CYQ8bobq.js";import{C as w,a as C}from"./card-C-rSe2cG.js";import{s as I}from"./client-9JQ50rx0.js";import{u as B}from"./CurrentOrgContext-cHOqhdZA.js";import{S as _t}from"./SecurityTab-DzpteHG9.js";import{T as fs,u as gs}from"./App-eUFnF2UU.js";import{P as oe,g as St,V as At,a as ys,b as $e,f as Pt,E as Rt,c as Et,C as V,n as os,d as bs,e as It,i as Mt,h as Ot,j as Tt,k as Ue,l as Ft,m as Te,o as Dt,v as Lt,p as qt,q as zt,r as Kt,O as ls,F as Bt,s as Ut,t as le,u as $t,B as Vt,w as Ht,x as Yt}from"./use-platform-ai-setups-BpiShOnJ.js";import{E as vs}from"./eye-Ds2mtGJZ.js";import{R as Qt}from"./rotate-cw-By6ddZiB.js";import{T as Gt}from"./trash-2-kuZAz6f9.js";import{S as Fe,a as De,b as Le,c as qe,d as ze}from"./select-CHCf0UGf.js";import{C as js}from"./checkbox-CCuUsgRq.js";import{e as H,a as Wt}from"./edge-error-zK3VLR66.js";import{u as Jt}from"./useQuery-DT6H2bUV.js";import{u as Xt,R as Zt}from"./use-team-CwPZmath.js";import{P as ea}from"./plus-zuBca-0W.js";import{u as sa}from"./index-D76g0itW.js";import{C as ta}from"./ConfirmActionDialog-BIrwo8Er.js";import{S as q}from"./skeleton-D_dSMpof.js";import"./resources-XWdWEoHc.js";import"./use-mfa-m_5Bufns.js";import"./download-DkL3RkNo.js";import"./formatDistanceToNow-DLNP-i6y.js";import"./en-US-WEIbtoXf.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const is=Js("LockKeyhole",[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]]),aa={neutral:"border-border bg-muted text-muted-foreground",green:"border-primary/40 bg-primary/5 text-primary",amber:"border-warning/40 bg-warning/5 text-warning",red:"border-destructive/40 bg-destructive/5 text-destructive"};function ra({badge:s,className:r}){const t=e.jsxs("span",{className:F("inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium",aa[s.color],r),children:[(s.color==="amber"||s.color==="red")&&e.jsx(fs,{"aria-hidden":!0,className:"h-3 w-3"}),s.label]});return s.warning?e.jsxs(Xs,{children:[e.jsx(Zs,{asChild:!0,children:t}),e.jsx(et,{className:"max-w-xs text-xs",children:s.warning})]}):t}const na={all:"border border-primary/30 bg-primary/5 text-primary",creator_only:"border border-warning/40 bg-warning/5 text-warning",selected:"border border-border bg-secondary/40 text-secondary-foreground"};function oa({keyRow:s,canManage:r,onEdit:t,onRotate:a,onReveal:n,onRemove:i}){const d=oe[s.provider_slug],o=s.redacted_config??{},u=ia(o.endpoint)?o.endpoint:{},h=!!o.has_api_key,x=o.api_key_last4??null,p=St(s.provider_slug,{base_url:u.base_url}),c=o.config_status==="legacy"||o.config_status==="invalid",f=o.config_error==="Stored provider configuration is unavailable",y=s.visibility==="selected"?`Select members · ${s.member_user_ids.length}`:At[s.visibility];return e.jsxs("div",{className:"flex items-start gap-4 border-b border-border/60 px-4 py-4 last:border-b-0",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate font-display text-base font-semibold tracking-tight",children:s.name}),e.jsx("span",{className:"rounded-full border border-border bg-muted px-2 py-0.5 text-xs font-medium",children:d.label}),e.jsx(ra,{badge:p}),c&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-warning/40 bg-warning/5 px-2 py-0.5 text-xs font-medium text-warning",children:[e.jsx(fs,{className:"h-3 w-3"}),f?r?"Configuration unavailable â remove":"Configuration unavailable":o.config_status==="legacy"?"Legacy setup â replace or remove":"Invalid setup â replace or remove"]}),e.jsx("span",{className:F("rounded-full px-2 py-0.5 text-xs font-medium",na[s.visibility]),children:y})]}),e.jsxs("dl",{className:"mt-2 grid gap-x-6 gap-y-1 text-xs text-muted-foreground sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"inline",children:"Model "}
vendor: 4,500 bytes, line 6
6),e.jsx("dd",{className:"inline text-foreground/80",children:ys(s.provider_slug,s.model)||"â"}),e.jsx("p",{className:"mt-1 font-mono",children:s.model}),e.jsx("p",{className:"mt-1",children:$e(s.provider_slug,s.model)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"inline",children:"Key "}),e.jsx("dd",{className:"inline font-mono text-foreground/80",children:Pt(s.provider_slug,h,x)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"inline",children:"Added "}),e.jsx("dd",{className:"inline font-mono text-foreground/80",children:la(s.created_at)})]})]})]}),r&&e.jsxs(st,{children:[e.jsx(tt,{asChild:!0,children:e.jsxs(S,{variant:"ghost",size:"icon",className:"shrink-0 rounded-full",children:[e.jsx(Rt,{className:"h-4 w-4"}),e.jsxs("span",{className:"sr-only",children:["Manage ",s.name]})]})}),e.jsxs(at,{align:"end",className:"w-44",children:[!c&&e.jsxs(e.Fragment,{children:[e.jsxs(se,{onClick:n,children:[e.jsx(vs,{className:"mr-2 h-4 w-4"})," Reveal key"]}),e.jsxs(se,{onClick:t,children:[e.jsx(Et,{className:"mr-2 h-4 w-4"})," Edit"]})]}),!f&&e.jsxs(e.Fragment,{children:[e.jsxs(se,{onClick:a,children:[e.jsx(Qt,{className:"mr-2 h-4 w-4"})," ",c?"Replace setup":"Rotate key"]}),e.jsx(rt,{})]}),e.jsxs(se,{onClick:i,className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[e.jsx(Gt,{className:"mr-2 h-4 w-4"})," Remove"]})]})]})]})}function la(s){return new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function ia(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}var ge="Popover",[Ns,Nr]=cs(ge,[ms]),Y=ms(),[da,M]=Ns(ge),ws=s=>{const{__scopePopover:r,children:t,open:a,defaultOpen:n,onOpenChange:i,modal:d=!1}=s,o=Y(r),u=m.useRef(null),[h,x]=m.useState(!1),[p,c]=hs({prop:a,defaultProp:n??!1,onChange:i,caller:ge});return e.jsx(ht,{...o,children:e.jsx(da,{scope:r,contentId:xt(),triggerRef:u,open:p,onOpenChange:c,onOpenToggle:m.useCallback(()=>c(f=>!f),[c]),hasCustomAnchor:h,onCustomAnchorAdd:m.useCallback(()=>x(!0),[]),onCustomAnchorRemove:m.useCallback(()=>x(!1),[]),modal:d,children:t})})};ws.displayName=ge;var Cs="PopoverAnchor",ca=m.forwardRef((s,r)=>{const{__scopePopover:t,...a}=s,n=M(Cs,t),i=Y(t),{onCustomAnchorAdd:d,onCustomAnchorRemove:o}=n;return m.useEffect(()=>(d(),()=>o()),[d,o]),e.jsx(us,{...i,...a,ref:r})});ca.displayName=Cs;var ks="PopoverTrigger",_s=m.forwardRef((s,r)=>{const{__scopePopover:t,...a}=s,n=M(ks,t),i=Y(t),d=ie(r,n.triggerRef),o=e.jsx(de.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":Es(n.open),...a,ref:d,onClick:z(s.onClick,n.onOpenToggle)});return n.hasCustomAnchor?o:e.jsx(us,{asChild:!0,...i,children:o})});_s.displayName=ks;var Ve="PopoverPortal",[ma,ua]=Ns(Ve,{forceMount:void 0}),Ss=s=>{const{__scopePopover:r,forceMount:t,children:a,container:n}=s,i=M(Ve,r);return e.jsx(ma,{scope:r,forceMount:t,children:e.jsx(ps,{present:t||i.open,children:e.jsx(ut,{asChild:!0,container:n,children:a})})})};Ss.displayName=Ve;var K="PopoverContent",As=m.forwardRef((s,r)=>{const t=ua(K,s.__scopePopover),{forceMount:a=t.forceMount,...n}=s,i=M(K,s.__scopePopover);return e.jsx(ps,{present:a||i.open,children:i.modal?e.jsx(ha,{...n,ref:r}):e.jsx(xa,{...n,ref:r})})});As.displayName=K;var pa=pt("PopoverContent.RemoveScroll"),ha=m.forwardRef((s,r)=>{const t=M(K,s.__scopePopover),a=m.useRef(null),n=ie(r,a),i=m.useRef(!1);return m.useEffect(()=>{const d=a.current;if(d)return nt(d)},[]),e.jsx(ot,{as:pa,allowPinchZoom:!0,children:e.jsx(Ps,{...s,ref:n,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:z(s.onCloseAutoFocus,d=>{var o;d.preventDefault(),i.current||(o=t.triggerRef.current)==null||o.focus()}),onPointerDownOutside:z(s.onPointerDownOutside,d=>{const o=d.detail.originalEvent,u=o.button===0&&o.ctrlKey===!0,h=o.button===2||u;i.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:z(s.onFocusOutside,d=>d.preventDefault(),{checkForDefaultPrevented:!1})})})}),xa=m.forwardRef((s,r)=>{const t=M(K,s.__scopePopover),a=m.useRef(!1),n=m.useRef(!1);return e.jsx(Ps,{...s,ref:r,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var d,o;(d=s.onCloseAutoFocus)==null||d.call(s,i),i.defaultPrevented||(a.current||(o=t.triggerRef.current)==null||o.focus(),i.preventDefault()),a.current=!1,n.current=!1},onInteractOutside:i=>{var u,h;(u=s.onInteractOutside)==null||u.call(s,i),i.defaultPrevented||(a.current=!0,i.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const d=i.target;
6((h=t.triggerRef.current)==null?void 0:h.contains(d))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&n.current&&i.preventDefault()}})}),Ps=m.forwardRef((s,r)=>{const{__scopePopover:t,trapFocus:a,onOpenAutoFocus:n,onCloseAutoFocus:i,disableOutsidePointerEvents:d,onEscapeKeyDown:o,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:x,...p}=s,c=M(K,t),f=Y(t);return lt(),e.jsx(it,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:n,onUnmountAutoFocus:i,children:e.jsx(dt,{asChild:!0,disableOutsidePointerEvents:d,onInteractOutside:x,onEscapeKeyDown:o,onPointerDownOutside:u,onFocusOutside:h,onDismiss:()=>c.onOpenChange(!1),children:e.jsx(ct,{"data-state":Es(c.open),role:"dialog",id:c.contentId,...f,...p,ref:r,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Rs="PopoverClose",fa=m.forwardRef((s,r)=>{const{__scopePopover:t,...a}=s,n=M(Rs,t);return e.jsx(de.button,{type:"button",...a,ref:r,onClick:z(s.onClick,()=>n.onOpenChange(!1))})});fa.displayName=Rs;var ga="PopoverArrow",ya=m.forwardRef((s,r)=>{const{__scopePopover:t,...a}=s,n=Y(t);return e.jsx(mt,{...n,...a,ref:r})});ya.displayName=ga;function Es(s){return s?"open":"closed"}var ba=ws,va=_s,ja=Ss,Is=As;const Na=ba,wa=va,Ms=m.forwardRef(({className:s,align:r="center",sideOffset:t=4,...a},n)=>e.jsx(ja,{children:e.jsx(Is,{ref:n,align:r,sideOffset:t,className:F("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...a})}));Ms.displayName=Is.displayName;const Ca=3e4;function ka(){const{session:s,checked:r}=gs(),{selectedOrganizationId:t}=B(),a=(s==null?void 0:s.user.id)??null,n=Jt({queryKey:["org-ai-keys",a,t],queryFn:async()=>{const{data:i,error:d}=await I.functions.invoke("list-org-ai-keys",{body:{organization_id:t}});if(d)throw new Error(H(d,"Failed to load AI keys"));return(i??{}).keys??[]},staleTime:Ca,enabled:r&&!!a&&!!t});return{keys:n.data??[],loading:!r||!!a&&!!t&&n.isLoading,error:n.error?n.error.message??null:null,refetch:()=>{n.refetch()}}}async function _a(s){const{data:r,error:t}=await I.functions.invoke("set-org-ai-key",{body:s});if(t)throw t;return r}async function Sa(s,r,t){const{error:a}=await I.functions.invoke("remove-org-ai-key",{body:{key_id:s,organization_id:r,expected_updated_at:t}});if(a)throw a}async function Aa(s,r){var d;const{data:t,error:a}=await I.functions.invoke("get-org-ai-keys",{body:{reveal:!0,key_id:s,organization_id:r}});if(a)throw a;const i=(d=(t??{}).keys)==null?void 0:d.find(o=>o.id===s);return(i==null?void 0:i.config)??null}function Pa(s){const{selectedOrganizationId:r}=B(),[t,a]=m.useState(!1),[n,i]=m.useState(null),[d,o]=m.useState(null),u=m.useCallback(async()=>{if(!(!s||!r)){a(!0),o(null);try{const x=await Aa(s,r);i(x),x||o("Key no longer exists")}catch(x){o(H(x,"Could not reveal key")),P.error(H(x,"Could not reveal key"))}finally{a(!1)}}},[s,r]),h=m.useCallback(()=>{i(null),o(null)},[]);return{config:n,revealing:t,error:d,reveal:u,clear:h}}const T="w-full rounded-lg border border-input bg-background px-3 py-2 text-sm outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60";function Ke({open:s,onOpenChange:r,mode:t,existing:a,onSaved:n}){var as,rs,ns;const i=t==="create",d=t==="edit",o=t==="rotate",{data:u}=B(),h=(u==null?void 0:u.organization.id)??null,{members:x}=Xt(h),p=m.useMemo(()=>Ra(a,t),[a,t]),[c,f]=m.useState(p.slug),[y,k]=m.useState(p.name),[E,R]=m.useState(p.modelChoice),[D,_]=m.useState(p.customModel),[A,He]=m.useState(p.visibility),[be,Ye]=m.useState(p.selectedMembers),[ve,Q]=m.useState(""),[G,W]=m.useState(!1),[je,J]=m.useState(p.baseUrl),[Ne,we]=m.useState(p.deploymentName),[Ce,ke]=m.useState(p.apiVersion),[Qe,X]=m.useState(p.advanced),[Ge,_e]=m.useState([]),[b,Se]=m.useState(!1);m.useEffect(()=>{s&&(f(p.slug),k(p.name),R(p.modelChoice),_(p.customModel),He(p.visibility),Ye(p.selectedMembers),Q(""),W(!1),J(p.baseUrl),we(p.deploymentName),ke(p.apiVersion),X(p.advanced),_e([]),Se(!1))},[p,s]);const v=oe[c],N=E===V?D.trim():E,Z=!!a&&N!==a.model,L=i||Z?os(c,N,Qe):Qe,O=bs(c,N),Bs=!ls,Ae=It(c),Us=O&&!Ae.some(l=>l.value===O.value)?[O,...Ae]:Ae,We=Mt(c,N),Je=Ot(c,N),$s=Tt(c,N),Xe=Ue(c,N).filter(l=>(!Je||l.key!=="thinkingMode"&&l.key!=="thinkingBudgetTokens")&&(c!=="openai"||l.key!=="speedMode"||$s)),Ze=!!((as=a==null?void 0:a.redacted_config)!=null&&as.has_api_key),U=((rs=a==null?void 0:a.redacted_config)==null?void 0:rs.config_status)==="legacy"||((ns=a==null?void 0:a.redacted_config)==null?void 0:ns.config_status)==="invalid",Pe=!o||U,es=Ge.length>0,Vs=Ft({baseUrl:je,deploymentName:Ne,apiVersion:Ce,advanced:L},d&&!Z?Ge:void 0),Hs={api_key:ve.trim(),base_url:je.trim()||Te(c,N)||"",deployment_name:Ne.trim(),api_version:Ce.trim(),advanced:L},Re=Dt({mode:t,apiKey:ve,requiresApiKey:v.requiresApiKey,clearStoredKey:G}),Ee=Lt(c,N)??null,Ie=y.trim()?null:"Name is required",Me=A==="selected"&&be.length===0?"Select at least one member":null,$=i||o||d&&(es||Z)?qt(c,Hs,{requireApiKey:(i||o)&&v.requiresApiKey,model:N})??zt(c,N,L):null,Oe=Re?null:o&&!v.requiresApiKey?"Enter a new API key, or choose to remove the stored key":"API key is required",ss=!h||!!(Ie||Ee||Me||$||Oe),Ys=l=>{const g=le(l);f(l),R(g),_(""),Q(""),W(!1),J(Te(l,g)??""),we(""),ke(""),X(Ht(l,g))},Qs=l=>{R(l),_(""),i&&J(Te(c,l)??""),l!==V&&X(g=>os(c,l,g)),_e(g=>
6Array.from(new Set([...g,...Ue(c,l).map(j=>`advanced:${j.key}`)])))},Gs=l=>{_(l)},ee=l=>{_e(g=>g.includes(l)?g:[...g,l])},ts=(l,g)=>{X(j=>({...j,[l]:g})),ee(`advanced:${l}`)},Ws=async l=>{if(l.preventDefault(),!(ss||b||!h||!Re)){Se(!0);try{const g=await _a({organization_id:h,key_id:a==null?void 0:a.id,expected_updated_at:a==null?void 0:a.updated_at,provider_slug:c,name:y.trim(),model:N,visibility:A,member_user_ids:A==="selected"?be:void 0,config_patch:i||d&&(es||Z)||o&&U?Vs:void 0,credential:Re}),j=g.action==="added"?"saved":g.action==="rotated"?"rotated":"updated";P.success(`${g.name} ${j}`),r(!1),n()}catch(g){const j=await Wt(g,"Could not save key");P.error(j.message)}finally{Se(!1)}}};return e.jsx(ce,{open:s,onOpenChange:r,children:e.jsxs(me,{className:"max-h-[90vh] overflow-y-auto sm:max-w-xl",children:[e.jsxs(ue,{children:[e.jsx(pe,{children:i?"Add AI provider":U?`Replace unsupported setup: ${(a==null?void 0:a.name)??"AI provider"}`:o?`Rotate ${(a==null?void 0:a.name)??"AI key"}`:`Edit ${(a==null?void 0:a.name)??"AI provider"}`}),e.jsx(he,{children:i?"Match the provider and model settings used by the desktop app. The credential is encrypted in your organization vault.":U?"This setup is unsupported or invalid. Choose a current model, re-enter the required settings, and provide a new credential to replace it.":o?"Replace only the stored credential. Provider, model, access, and runtime options stay unchanged.":"Update the model, access, endpoint, or runtime options. The stored credential is kept and is not revealed."})]}),e.jsxs("form",{onSubmit:Ws,className:"space-y-4",children:[Pe?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"key-name",className:"text-sm font-medium",children:"Name"}),e.jsx("input",{id:"key-name",type:"text",required:!0,autoFocus:!0,value:y,onChange:l=>k(l.target.value),disabled:b,className:T,placeholder:"e.g. Production Claude",maxLength:80}),Ie&&e.jsx("p",{className:"text-xs text-destructive",children:Ie})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"key-provider",className:"text-sm font-medium",children:"Provider"}),e.jsxs(Fe,{value:c,onValueChange:l=>Ys(l),disabled:!i||b,children:[e.jsx(De,{id:"key-provider",className:"rounded-lg",children:e.jsx(Le,{})}),e.jsx(qe,{children:Kt.map(l=>e.jsx(ze,{value:l,children:oe[l].label},l))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:v.description})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"key-model",className:"text-sm font-medium",children:"Model"}),e.jsxs(Fe,{value:E,onValueChange:Qs,disabled:b,children:[e.jsx(De,{id:"key-model",className:"rounded-lg",children:e.jsx(Le,{})}),e.jsx(qe,{className:"max-w-[30rem]",children:Us.map(l=>e.jsxs(ze,{value:l.value,disabled:!ls,className:"whitespace-normal py-2",children:[e.jsx("span",{className:"font-mono text-xs",children:l.value}),e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:l.label})]},l.value))})]},c),E===V&&e.jsx("input",{type:"text",required:!0,value:D,onChange:l=>Gs(l.target.value),disabled:b,className:`${T} mt-1.5 font-mono`,placeholder:"Paste exact model ID",maxLength:256}),(O==null?void 0:O.appProfile)==="orchestrated"&&e.jsxs("div",{className:"rounded-md border border-primary/20 bg-primary/5 px-3 py-2 text-xs text-muted-foreground",children:[e.jsxs("p",{className:"font-medium text-foreground",children:["How ",O.label," works"]}),e.jsx("p",{className:"mt-1",children:$e(c,N)}),e.jsx("p",{className:"mt-1",children:"In Analyze, Code, SuiteQL and HTML reports, it can ask specialist AI models for help up to twice. Other AI features do not call specialists."}),e.jsx("p",{className:"mt-1",children:"Each specialist sees only the task sent to it. It cannot access your NetSuite account, netQuery tools, repository, or earlier messages. Each specialist call adds to your AI provider usage and may increase cost."})]}),Bs,Je&&e.jsxs("div",{className:"space-y-1 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Adaptive thinking â required"}),e.jsx("p",{children:We?"Claude Fable 5 always uses adaptive thinking; use Response effort to control its depth.":"Claude Opus 5 always uses adaptive thinking; use Response effort to control its depth."}),We&&e.jsx("p",{children:Bt})]}),Ee&&e.jsx("p",{className:"text-xs text-destructive",children:Ee})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Visibility"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:["all","creator_only","selected"].map(l=>e.jsxs("button",{type:"button",disabled:b,onClick:()=>He(l),className:F("rounded-lg border px-3 py-2 text-left text-sm transition-colors",A===l?"border-primary bg-primary/5 text-foreground":"border-border bg-background text-muted-foreground hover:text-foreground"),children:[e.jsx("p",{className:"font-medium",children:l==="all"?"All members":l==="creator_only"?"Only me":"Select members"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l==="all"?"Every active org member can use it":l==="creator_only"?"Only you can use it":"Pick which members"})]},l))}
6),A==="selected"&&e.jsx(Ea,{members:x.map(l=>{var g;return{user_id:l.user_id,label:((g=l.display_name)==null?void 0:g.trim())||l.email}}),value:be,onChange:Ye,disabled:b}),Me&&e.jsx("p",{className:"text-xs text-destructive",children:Me})]})]}):e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-4 text-sm",children:[e.jsx("p",{className:"font-medium",children:a==null?void 0:a.name}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[v.label," · ",e.jsx("span",{className:"font-mono",children:N})]})]}),(i||o||d&&!v.requiresApiKey&&Ze)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-muted/30 p-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:o?"New credential":"Credential"}),(i||o)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{htmlFor:"key-api-key",className:"text-sm font-medium",children:[o?"New API key":"API key",v.requiresApiKey?"":" (optional)"]}),e.jsx("input",{id:"key-api-key",type:"password",autoComplete:"new-password",value:ve,onChange:l=>{Q(l.target.value),l.target.value&&W(!1)},disabled:b||G,className:`${T} font-mono`,placeholder:o?"Paste replacement key":v.apiKeyPlaceholder,maxLength:8192}),e.jsx("p",{className:"text-xs text-muted-foreground",children:v.keyHelp})]}),!v.requiresApiKey&&(Ze||o)&&e.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[e.jsx(js,{checked:G,onCheckedChange:l=>{W(l===!0),l&&Q("")},disabled:b,className:"mt-0.5"}),e.jsxs("span",{children:["Remove the stored API key",e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:"Use this only when the OpenAI-compatible endpoint accepts unauthenticated requests."})]})]}),Oe&&e.jsx("p",{className:"text-xs text-destructive",children:Oe})]}),Pe&&e.jsxs("div",{className:"space-y-4 rounded-lg border border-border p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Endpoint & runtime options"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:v.residencySummary})]}),v.requiresBaseUrl&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"key-base-url",className:"text-sm font-medium",children:"Base URL"}),e.jsx("input",{id:"key-base-url",type:"url",value:je,onChange:l=>{J(l.target.value),ee("baseUrl")},disabled:b,className:`${T} font-mono`,placeholder:v.baseUrlPlaceholder??"https://",maxLength:2048}),c==="nebius"&&N==="moonshotai/Kimi-K3"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Kimi K3 is currently recommended at Nebius EU West 2 (`https://api.tokenfactory.eu-west2.nebius.com/v1`). Existing endpoints are preserved; confirm K3 availability in your selected region."})]}),v.requiresDeployment&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"key-deployment",className:"text-sm font-medium",children:"Deployment name"}),e.jsx("input",{id:"key-deployment",type:"text",value:Ne,onChange:l=>{we(l.target.value),ee("deploymentName")},disabled:b,className:`${T} font-mono`,placeholder:"Your Azure deployment name",maxLength:256}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This is the Azure deployment name, not the model ID selected above."})]}),v.showApiVersion&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"key-api-version",className:"text-sm font-medium",children:"API version (optional)"}),e.jsx("input",{id:"key-api-version",type:"text",value:Ce,onChange:l=>{ke(l.target.value),ee("apiVersion")},disabled:b,className:`${T} font-mono`,placeholder:"2024-10-21",maxLength:64})]}),Xe.length>0&&e.jsxs("div",{className:"space-y-3 border-t border-border/70 pt-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"Advanced model options"}),Xe.map(l=>{if(!Ut(l,L))return null;const g=`advanced-${l.key}`;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:g,className:"text-sm font-medium",children:l.label}),l.type==="select"?e.jsxs(Fe,{value:String(L[l.key]??l.default),onValueChange:j=>ts(l.key,j),disabled:b,children:[e.jsx(De,{id:g,className:"rounded-lg",children:e.jsx(Le,{})}),e.jsx(qe,{children:l.options.map(j=>e.jsx(ze,{value:j.value,children:j.label},j.value))})]}):e.jsx("input",{id:g,type:"number",min:l.min,max:l.max,step:l.step,value:L[l.key]??l.default,onCh
6ange:j=>ts(l.key,j.target.value===""?"":Number(j.target.value)),disabled:b,className:`${T} font-mono`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.help})]},l.key)})]}),v.capabilityWarning&&e.jsx("p",{className:"rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-xs text-muted-foreground",children:v.capabilityWarning}),$&&e.jsx("p",{className:"text-xs text-destructive",children:$})]}),o&&!Pe&&$&&e.jsx("p",{className:"text-xs text-destructive",children:$}),e.jsxs(xe,{className:"gap-2 sm:gap-2",children:[e.jsx(S,{type:"button",variant:"outline",onClick:()=>r(!1),disabled:b,className:"rounded-full",children:"Cancel"}),e.jsx(S,{type:"submit",disabled:ss||b,className:"rounded-full",children:b?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving"]}):i?"Add provider":U?"Replace setup":o?G?"Remove stored key":"Rotate key":"Save changes"})]})]})]})})}function Ra(s,r){var o,u;const t=(s==null?void 0:s.provider_slug)??"anthropic",a=r==="rotate"&&(((o=s==null?void 0:s.redacted_config)==null?void 0:o.config_status)==="legacy"||((u=s==null?void 0:s.redacted_config)==null?void 0:u.config_status)==="invalid"),n=a?le(t):(s==null?void 0:s.model)??le(t),i=Ia(t,n),d=$t(t,a?null:s==null?void 0:s.redacted_config,n);return{slug:t,name:(s==null?void 0:s.name)??"",modelChoice:i,customModel:i===V?n:"",visibility:(s==null?void 0:s.visibility)??"all",selectedMembers:(s==null?void 0:s.member_user_ids)??[],...d}}function Ea({members:s,value:r,onChange:t,disabled:a}){const[n,i]=m.useState(!1),d=u=>{t(r.includes(u)?r.filter(h=>h!==u):[...r,u])},o=new Map(s.map(u=>[u.user_id,u.label]));return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Na,{open:n,onOpenChange:i,children:[e.jsx(wa,{asChild:!0,children:e.jsxs(S,{type:"button",variant:"outline",disabled:a,className:"w-full justify-between rounded-lg font-normal",children:[e.jsx("span",{className:"truncate",children:r.length===0?"Select membersâ¦":`${r.length} member${r.length===1?"":"s"} selected`}),e.jsx(ft,{className:"h-4 w-4 opacity-60"})]})}),e.jsx(Ms,{align:"start",className:"w-[--radix-popover-trigger-width] p-0",children:e.jsxs("div",{role:"listbox","aria-label":"Organization members","aria-multiselectable":"true",className:"max-h-60 overflow-y-auto overscroll-contain p-1",children:[s.length===0&&e.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No members yet â invite teammates first."}),s.map(u=>{const h=r.includes(u.user_id);return e.jsxs("button",{type:"button",role:"option","aria-selected":h,onClick:()=>d(u.user_id),className:"flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted",children:[e.jsx(js,{checked:h,className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate text-left",children:u.label}),h&&e.jsx(xs,{className:"h-4 w-4 text-primary"})]},u.user_id)})]})})]}),r.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map(u=>e.jsxs(Vt,{variant:"secondary",className:"gap-1",children:[o.get(u)??u.slice(0,8),e.jsx("button",{type:"button",onClick:()=>d(u),disabled:a,"aria-label":"Remove",className:"ml-1 text-muted-foreground hover:text-foreground",children:"Ã"})]},u))})]})}function Ia(s,r){return r?bs(s,r)?r:V:le(s)}function Ma({open:s,onOpenChange:r,keyRow:t,onRemoved:a}){const[n,i]=m.useState(!1),{selectedOrganizationId:d}=B(),o=async()=>{i(!0);try{if(!d)throw new Error("Choose an organization first");await Sa(t.id,d,t.updated_at),P.success(`${t.name} removed`),r(!1),a()}catch(u){P.error(H(u,"Could not remove key"))}finally{i(!1)}};return e.jsx(ce,{open:s,onOpenChange:r,children:e.jsxs(me,{className:"sm:max-w-md",children:[e.jsxs(ue,{children:[e.jsxs(pe,{children:["Remove ",t.name,"?"]}),e.jsx(he,{children:"The plaintext key will be purged from our vault immediately. Anyone who could use it via their desktop app will lose access on their next fetch."})]}),e.jsxs(xe,{className:"gap-2 sm:gap-2",children:[e.jsx(S,{variant:"outline",onClick:()=>r(!1),disabled:n,className:"rounded-full",children:"Cancel"}),e.jsx(S,{variant:"destructive",onClick:o,disabled:n,className:"rounded-full",children:n?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing"]}):"Remove key"})]})]})})}function Oa({open:s,onOpenChange:r,keyRow:t}){const{config:a,revealing:n,error:i,reveal:d,clear:o}=Pa(t.id),[u,h]=m.useState(!1),[x,p]=m.useState(!1),c=Be(a==null?void 0:a.credentials)?a.credentials:{},f=Be(a==null?void 0:a.endpoint)?a.endpoint:{},y=Be(a==null?void 0:a.advanced)?a.advanced:{},k=typeof c.api_key=="string"?c.api_key:null,E=Ue(t.provider_slug,t.model);m.useEffect(()=>{s||(o(),h(!1),p(!1))},[s,o]);const R=()=>{p(!0),d()},D=async()=>
6{if(k)try{await navigator.clipboard.writeText(k),h(!0),P.success("Key copied"),setTimeout(()=>h(!1),2e3)}catch{P.error("Could not copy")}};return e.jsx(ce,{open:s,onOpenChange:r,children:e.jsxs(me,{className:"sm:max-w-md",children:[e.jsxs(ue,{children:[e.jsx(pe,{children:t.name}),e.jsx(he,{children:"Reveals the plaintext key stored for your organization. The reveal is recorded in the audit trail."})]}),e.jsxs("div",{className:"space-y-3",children:[!x&&e.jsxs(S,{onClick:R,variant:"outline",className:"w-full rounded-full",children:[e.jsx(vs,{className:"mr-2 h-4 w-4"}),"Reveal key"]}),x&&n&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(fe,{className:"h-4 w-4 animate-spin"}),"Loadingâ¦"]}),x&&!n&&i&&e.jsx("p",{className:"text-sm text-destructive",children:i}),x&&!n&&a&&e.jsxs("div",{className:"space-y-2",children:[k&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"API key"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 break-all rounded-lg border border-border bg-muted px-3 py-2 font-mono text-xs",children:k}),e.jsx(S,{variant:"outline",size:"sm",onClick:D,className:"shrink-0 rounded-full",children:u?e.jsx(xs,{className:"h-4 w-4"}):e.jsx(gt,{className:"h-4 w-4"})})]})]}),typeof f.base_url=="string"&&e.jsx(re,{label:"Base URL",value:f.base_url}),typeof f.deployment_name=="string"&&e.jsx(re,{label:"Deployment name",value:f.deployment_name}),typeof f.api_version=="string"&&e.jsx(re,{label:"API version",value:f.api_version}),E.map(_=>{const A=y[_.key];return typeof A=="string"||typeof A=="number"?e.jsx(re,{label:_.label,value:String(A)},_.key):null})]})]}),e.jsx(xe,{className:"gap-2 sm:gap-2",children:e.jsx(S,{variant:"outline",onClick:()=>r(!1),className:"rounded-full",children:"Close"})})]})})}function Be(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}function re({label:s,value:r}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:s}),e.jsx("code",{className:"block break-all rounded-lg border border-border bg-muted px-3 py-2 font-mono text-xs",children:r})]})}function Ta(){const{setups:s,loading:r,error:t,refetch:a}=Yt();return e.jsxs("section",{"aria-labelledby":"shared-platform-ai-setups-heading",className:"space-y-4",children:[e.jsx(w,{className:"border-primary/25 bg-primary/[0.03]",children:e.jsx(C,{className:"py-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(is,{className:"mt-0.5 h-5 w-5 shrink-0 text-primary","aria-hidden":!0}),e.jsxs("div",{children:[e.jsx("p",{id:"shared-platform-ai-setups-heading",className:"eyebrow mb-2",children:"SHARED BY NETQUERY"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"netQuery makes these provider setups available to you. They are locked here: only netQuery administrators can change, rotate, or remove them. Choose one in the desktop app when you want to use it."})]})]})})}),r&&e.jsx("p",{className:"text-sm text-muted-foreground","aria-live":"polite",children:"Loading netQuery-shared AI setupsâ¦"}),!r&&t&&e.jsx(w,{children:e.jsxs(C,{className:"flex flex-wrap items-center justify-between gap-3 py-5",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Organization AI keys are still available, but netQuery-shared setups could not be loaded."}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"rounded-full",onClick:a,children:[e.jsx(Zt,{className:"mr-2 h-3.5 w-3.5","aria-hidden":!0}),"Try again"]})]})}),!r&&!t&&s.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No AI setups are currently shared by netQuery."}),!r&&!t&&s.length>0&&e.jsx(w,{className:"overflow-hidden",children:e.jsx(C,{className:"p-0",children:s.map(n=>e.jsx("div",{className:"flex items-start gap-4 border-b border-border/60 px-4 py-4 last:border-b-0",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate font-display text-base font-semibold tracking-tight",children:n.name}),e.jsx("span",{className:"rounded-full border border-border bg-muted px-2 py-0.5 text-xs font-medium",children:oe[n.provider_slug].label}),e.jsx("span",{className:"rounded-full border border-primary/30 bg-primary/5 px-2 py-0.5 text-xs font-medium text-primary",children:"Shared by netQuery"}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-xs text-muted-foreground",children:[e.jsx(is,{className:"h-3 w-3","aria-hidden":!0}),"Locked"]})]}),e.jsx("dl",{className:"mt-2 text-xs text-muted-foreground",children:e.jsxs("div",{children:[e.jsx("dt",{className:"inline",children:"Model "}
6),e.jsx("dd",{className:"inline text-foreground/80",children:ys(n.provider_slug,n.model)||"â"}),e.jsx("p",{className:"mt-1 font-mono",children:n.model}),e.jsx("p",{className:"mt-1",children:$e(n.provider_slug,n.model)})]})})]})},n.id))})})]})}function Fa(){const{data:s}=B(),{assurance:r}=gs(),t=(s==null?void 0:s.membership.role)??"member",a=t==="owner"||t==="admin",n=a&&r==="aal2",{keys:i,loading:d,error:o,refetch:u}=ka(),[h,x]=m.useState({kind:"none"}),p=()=>x({kind:"none"});return m.useEffect(()=>{n||x({kind:"none"})},[n]),e.jsxs(e.Fragment,{children:[e.jsx(w,{children:e.jsxs(C,{className:"py-6",children:[e.jsx("p",{className:"eyebrow mb-2",children:"ORG-SHARED AI KEYS"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a?"Credentials are encrypted in your organization vault. Authorized members' desktop apps receive them at runtime to call the provider directly; portal plaintext reveals require MFA and are audit logged.":"These are the AI providers your organization makes available. Your desktop app securely retrieves the authorized credential at runtime, so you don't need to enter it locally."})]})}),a&&r!=="aal2"&&e.jsx(w,{className:"border-primary/30 bg-primary/5",children:e.jsxs(C,{className:"flex items-start gap-3 py-5",children:[e.jsx(yt,{className:"mt-0.5 h-5 w-5 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium",children:"Two-factor authentication required"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Set up and verify MFA before adding, changing, revealing, or removing organization keys."}),e.jsx(S,{asChild:!0,className:"mt-4 rounded-full",size:"sm",children:e.jsx(bt,{to:`/security/mfa?next=${encodeURIComponent("/portal/account?tab=ai-keys")}`,children:"Set up two-factor authentication"})})]})]})}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(S,{onClick:()=>x({kind:"create"}),className:"rounded-full",children:[e.jsx(ea,{className:"mr-2 h-4 w-4"}),"Add AI key"]})}),d&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading AI keysâ¦"}),!d&&o&&e.jsx(w,{children:e.jsx(C,{className:"py-8",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Could not load AI keys. ",o," ",e.jsx("button",{onClick:u,className:"text-primary underline-offset-4 hover:underline",children:"Try again"}),"."]})})}),!d&&!o&&i.length===0&&e.jsx(w,{children:e.jsxs(C,{className:"py-12 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"No AI keys configured yet."}),n&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Add a key to make a provider available to your team."})]})}),!d&&!o&&i.length>0&&e.jsx(w,{className:"overflow-hidden",children:e.jsx(C,{className:"p-0",children:i.map(c=>e.jsx(oa,{keyRow:c,canManage:n,onEdit:()=>x({kind:"edit",key:c}),onRotate:()=>x({kind:"rotate",key:c}),onReveal:()=>x({kind:"reveal",key:c}),onRemove:()=>x({kind:"remove",key:c})},c.id))})}),h.kind==="create"&&e.jsx(Ke,{open:!0,mode:"create",onOpenChange:c=>!c&&p(),existing:null,onSaved:u}),h.kind==="edit"&&e.jsx(Ke,{open:!0,mode:"edit",onOpenChange:c=>!c&&p(),existing:h.key,onSaved:u}),h.kind==="rotate"&&e.jsx(Ke,{open:!0,mode:"rotate",onOpenChange:c=>!c&&p(),existing:h.key,onSaved:u}),h.kind==="remove"&&e.jsx(Ma,{open:!0,onOpenChange:c=>!c&&p(),keyRow:h.key,onRemoved:u}),h.kind==="reveal"&&e.jsx(Oa,{open:!0,onOpenChange:c=>!c&&p(),keyRow:h.key}),e.jsx(Ta,{})]})}var ye="Switch",[Da,wr]=cs(ye),[La,qa]=Da(ye),Os=m.forwardRef((s,r)=>{const{__scopeSwitch:t,name:a,checked:n,defaultChecked:i,required:d,disabled:o,value:u="on",onCheckedChange:h,form:x,...p}=s,[c,f]=m.useState(null),y=ie(r,_=>f(_)),k=m.useRef(!1),E=c?x||!!c.closest("form"):!0,[R,D]=hs({prop:n,defaultProp:i??!1,onChange:h,caller:ye});return e.jsxs(La,{scope:t,checked:R,disabled:o,children:[e.jsx(de.button,{type:"button",role:"switch","aria-checked":R,"aria-required":d,"data-state":Ls(R),"data-disabled":o?"":void 0,disabled:o,value:u,...p,ref:y,onClick:z(s.onClick,_=>{D(A=>!A),E&&(k.current=_.isPropagationStopped(),k.current||_.stopPropagation())})}),E&&e.jsx(Ds,{control:c,bubbles:!k.current,name:a,value:u,checked:R,required:d,disabled:o,form:x,style:{transform:"translateX(-100%)"}})]})});Os.displayName=ye;var Ts="SwitchThumb",Fs=m.forwardRef((s,r)=>{const{__scopeSwitch:t,...a}
6=s,n=qa(Ts,t);return e.jsx(de.span,{"data-state":Ls(n.checked),"data-disabled":n.disabled?"":void 0,...a,ref:r})});Fs.displayName=Ts;var za="SwitchBubbleInput",Ds=m.forwardRef(({__scopeSwitch:s,control:r,checked:t,bubbles:a=!0,...n},i)=>{const d=m.useRef(null),o=ie(d,i),u=sa(t),h=vt(r);return m.useEffect(()=>{const x=d.current;if(!x)return;const p=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(p,"checked").set;if(u!==t&&f){const y=new Event("click",{bubbles:a});f.call(x,t),x.dispatchEvent(y)}},[u,t,a]),e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:t,...n,tabIndex:-1,ref:o,style:{...n.style,...h,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Ds.displayName=za;function Ls(s){return s?"checked":"unchecked"}var qs=Os,Ka=Fs;const zs=m.forwardRef(({className:s,...r},t)=>e.jsx(qs,{className:F("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",s),...r,ref:t,children:e.jsx(Ka,{className:F("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));zs.displayName=qs.displayName;function Ba(s){return s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"â"}function Ua({orgData:s,onUpdate:r}){const t=s.organization,a=s.membership.role==="owner",n=!!t.mfa_required,[i,d]=m.useState(!1),[o,u]=m.useState(!1),[h,x]=m.useState(null);m.useEffect(()=>{let f=!1;if(!n||!t.mfa_required_set_by){x(null);return}return(async()=>{var k;const{data:y}=await I.from("users").select("display_name").eq("id",t.mfa_required_set_by).maybeSingle();f||x(((k=y==null?void 0:y.display_name)==null?void 0:k.trim())||null)})(),()=>{f=!0}},[n,t.mfa_required_set_by]);const p=async f=>{d(!0);try{const{error:y}=await I.functions.invoke("set-org-mfa-required",{body:{mfa_required:f,organization_id:t.id}});if(y){P.error(H(y,"Could not update MFA mandate"));return}P.success(f?"MFA is now required for all members":"MFA mandate disabled"),r()}finally{d(!1)}},c=f=>{if(f&&!n){u(!0);return}p(f)};return e.jsxs(e.Fragment,{children:[e.jsx(w,{children:e.jsxs(C,{className:"py-6",children:[e.jsx("p",{className:"eyebrow mb-4",children:"SECURITY"}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Require MFA for all members"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a?"Members without two-factor authentication will be blocked from the portal until they enroll.":"Only owners can change this setting."})]}),e.jsx(zs,{checked:n,disabled:!a||i,onCheckedChange:c,"aria-label":"Require MFA for all members"})]}),n&&e.jsxs("p",{className:"mt-4 text-xs text-muted-foreground",children:["Required",h&&e.jsxs(e.Fragment,{children:[" ","by ",e.jsx("span",{className:"text-foreground",children:h})]}),t.mfa_required_set_at&&e.jsxs(e.Fragment,{children:[" ","on"," ",e.jsx("span",{className:"font-mono",children:Ba(t.mfa_required_set_at)})]}),"."]})]})}),e.jsx(ta,{open:o,onOpenChange:u,title:"Require MFA for all members?",description:"Members without two-factor authentication will be blocked from the portal until they enroll. This applies immediately.",confirmLabel:"Require MFA",loading:i,onConfirm:()=>{u(!1),p(!0)}})]})}const ds="w-full rounded-lg border border-input bg-background px-3 py-2 text-sm outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60",ne="-mb-px rounded-none border-b-2 border-transparent bg-transparent px-4 py-3 text-sm font-medium text-muted-foreground shadow-none transition-colors hover:text-foreground data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none";function Ks(s){return s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"â"}function $a(s){return s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"long"}):"â"}const Cr=()=>e.jsx(kt,{children:e.jsx(Va,{})});function Va(){const{data:s,loading:r,error:t,refetch:a}=B(),[n,i]=jt(),d=m.useMemo(()=>{const o=n.get("tab");return["profile","organization","security","ai-keys"].includes(o??"")?o:"profile"},[n]);return m.useEffect(()=>{document.title="Account | netQuery.ai"},[]),e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsx("h1",{className:"font-display text-4xl font-extrabold tracking-tight md:text-5xl lg:text-6xl",children:"Account"}),r&&e.jsxs("div",{className:"mt-10","aria-busy":"true","aria-label":"Loading account",children:[e.jsx("div",{className:"flex gap-2 border-b border-border pb-1",children:Array.from({length:4}).map((o,u)=>e.jsx(q,{className:"h-8 w-24 rounded-md"},u))}),e.jsx(w,{className:"mt-6",children:e.jsxs(C,{className:"space-y-4 py-6",children:[e.jsx(q,{className:"h-3 w-32"}),e.jsx(q,{className:"h-10 w-full"}),e.jsx(q,{className:"h-3 w-40"}),e.jsx(q,{className:"h-10 w-full"}),e.jsx(q,{className:"ml-auto h-9 w-28 rounded-full"})]})})]}),!r&&t&&e.jsx(w,{className:"mt-8",children:e.jsx(C,{className:"py-8",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Could not load your account. If this persists, contact"," ",e.jsx("a",{href:"mailto:[email protected]",className:"text-primary underline-offset-4 hover:underline",children:"[email protected]"}),"."]})})}),!r&&s&&e.jsxs(Nt,{value:d,onValueChange:o=>{const u=new URLSearchParams(n);o==="profile"?u.delete("tab"):u.set("tab",o),i(u,{replace:!0})},className:"mt-10",children:[e.jsxs(wt,{className:"h-auto w-full justify-start gap-2 rounded-none border-b border-border bg-transparent p-0",children:[e.jsx(te,{value:"profile",className:ne,children:"Profile"}),e.jsx(te,{value:"organization",className:ne,children:"Organization"}),e.jsx(te,{value:"security",className:ne,children:"Security"}),e.jsx(te,{value:"ai-keys",className:ne,children:"AI keys"})]}),e.jsx(ae,{value:"profile",className:"mt-6 space-y-6",children:e.jsx(Ha,{orgData:s,onUpdate:a})}),e.jsx(ae,{value:"organization",className:"mt-6 space-y-6",children:e.jsx(Ya,{orgData:s,onUpdate:a})}),e.jsx(ae,{value:"security",className:"mt-6 space-y-6",children:e.jsx(_t,{})}),e.jsx(ae,{value:"ai-keys",className:"mt-6 space-y-6",children:e.jsx(Fa,{})})]})]})}function Ha({orgData:s,onUpdate:r}){const[t,a]=m.useState(s.user.display_name??""),[n,i]=m.useState(!1),[d,o]=m.useState(null);m.useEffect(()=>{let p=!1;return(async()=>{const{count:c}=await I.from("organization_memberships").select("*",{count:"exact",head:!0}).eq("organization_id",s.organization.id).neq("user_id",s.user.id).in("role",["owner","admin"]).is("deleted_at",null);p||o(c??0)})(),()=>{p=!0}},[s.organization.id,s.user.id]);const h=(s.membership.role==="owner"||s.membership.role==="admin")&&d===0,x=async p=>{p.preventDefault(),i(!0);try{const{error:c}=await I.rpc("update_user_profile",{p_display_name:t.trim()||null});if(c)throw c;P.success("Profile updated"),r()}catch(c){console.error("[account] profile update failed:",c),P.error("Could not save your profile. Please try again.")}finally{i(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(w,{children:e.jsxs(C,{className:"py-6",children:[e.jsx("p",{className:"eyebrow mb-4",children:"PROFILE"}),e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"email",className:"text-sm font-medium",children:"Email"}),e.jsx("input",{id:"email",type:"email",value:s.user.email,disabled:!0,className:ds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Contact support to change your email address."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"display_name",className:"text-sm font-medium",children:"Display name"}),e.jsx("input",{id:"display_name",type:"text",value:t,onChange:p=>a(p.target.value),className:ds,placeholder:"Your name"})]}),e.jsx(S,{type:"submit",disabled:n,className:"rounded-full",children:n?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving"]}):"Save changes"})]})]})}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[e.jsxs("p",{children:["Member since"," ",e.jsx("span",{className:"font-mono",children:$a(s.user.created_at)})]}
6),s.user.eula_version_accepted&&e.jsxs("p",{children:["Terms · v",e.jsx("span",{className:"font-mono",children:s.user.eula_version_accepted})," · ",e.jsx("span",{className:"font-mono",children:Ks(s.user.eula_accepted_at)})]})]}),e.jsxs("div",{className:"border-t border-border/60 pt-6",children:[d!==null&&!h&&e.jsxs(ce,{children:[e.jsx(Ct,{asChild:!0,children:e.jsx("button",{className:"text-sm text-destructive underline-offset-4 hover:underline",children:"Delete my account"})}),e.jsxs(me,{children:[e.jsxs(ue,{children:[e.jsx(pe,{children:"Delete account"}),e.jsxs(he,{children:["Coming soon â contact"," ",e.jsx("a",{href:"mailto:[email protected]",className:"underline",children:"[email protected]"})," ","to delete your account."]})]}),e.jsx(xe,{})]})]}),h&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"You're the only owner / admin of this organization. Promote another member to admin before deleting your account."})]})]})}function Ya({orgData:s,onUpdate:r}){const t=s.organization,a=[t.billing_address_line1,t.billing_address_line2,[t.billing_city,t.billing_state,t.billing_postal_code].filter(Boolean).join(", "),t.billing_country].filter(d=>!!(d&&d.trim()!=="")),n=!!(t.stripe_customer_id||t.vat_number||t.phone||a.length>0),i=s.membership.role==="owner"?"border border-primary/40 bg-primary/5 text-primary":s.membership.role==="admin"?"border border-border bg-secondary/30 text-secondary-foreground":"bg-muted text-muted-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(w,{children:e.jsxs(C,{className:"py-6",children:[e.jsx("p",{className:"eyebrow mb-4",children:"IDENTITY"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx("h3",{className:"font-display text-2xl font-bold tracking-tight",children:t.name}),t.is_business&&e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-0.5 text-xs font-medium text-secondary-foreground",children:"Business"})]}),t.legal_name&&e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t.legal_name})]})}),n&&e.jsx(w,{children:e.jsxs(C,{className:"py-6",children:[e.jsx("p",{className:"eyebrow mb-4",children:"BILLING DETAILS"}),e.jsxs("dl",{className:"space-y-3 text-sm",children:[t.stripe_customer_id&&e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Stripe customer"}),e.jsx("dd",{className:"text-right font-mono text-xs text-muted-foreground",children:t.stripe_customer_id})]}),t.vat_number&&e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-muted-foreground",children:"VAT number"}),e.jsx("dd",{className:"text-right font-mono",children:t.vat_number})]}),t.phone&&e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Phone"}),e.jsx("dd",{className:"text-right",children:t.phone})]}),a.length>0&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Billing address"}),e.jsx("dd",{className:"space-y-0.5",children:a.map((d,o)=>e.jsx("p",{children:d},o))})]})]}),e.jsx("p",{className:"mt-4 text-xs italic text-muted-foreground",children:"To update billing details, use Manage in Stripe from the Billing page."})]})}),e.jsx(w,{children:e.jsxs(C,{className:"py-6",children:[e.jsx("p",{className:"eyebrow mb-4",children:"YOUR MEMBERSHIP"}),e.jsxs("dl",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Role"}),e.jsx("dd",{children:e.jsx("span",{className:F("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize",i),children:s.membership.role})})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Joined"}),e.jsx("dd",{className:"text-right font-mono",children:Ks(s.membership.joined_at)})]})]})]})}),e.jsx(Ua,{orgData:s,onUpdate:r})]})}export{Cr 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.