var K=Object.defineProperty;var B=(A)=>A;function k(A,z){this[A]=B.bind(null,z)}var b=(A,z)=>{for(var F in z)K(A,F,{get:z[F],enumerable:!0,configurable:!0,set:k.bind(z,F)})};var C=(A,z)=>()=>(A&&(z=A(A=0)),z);import{Button as P,Input as O,Textarea as m}from"@contractspec/lib.design-system";import{Checkbox as L}from"@contractspec/lib.ui-kit-web/ui/checkbox";import{Label as E}from"@contractspec/lib.ui-kit-web/ui/label";import{Select as Q,SelectContent as R,SelectItem as M,SelectTrigger as U,SelectValue as W}from"@contractspec/lib.ui-kit-web/ui/select";import{Key as I,ShieldCheck as d,TestTube2 as T}from"lucide-react";import*as X from"react";import{jsx as f,jsxs as q}from"react/jsx-runtime";function r({provider:A,initialValues:z,onTestConnection:F,onSave:Y,isSaving:Z,isTesting:_}){let[D,N]=X.useState({apiKey:z?.apiKey??"",secret:z?.secret??"",ownershipMode:z?.ownershipMode??"managed",secretProvider:z?.secretProvider??"env",secretRef:z?.secretRef??"",config:z?.config??`{
  "region": "eu-west-1"
}`}),J=(G)=>{let H=G.target,{name:$,value:w}=H;N((y)=>({...y,[$]:w}))};return q("div",{className:"space-y-4 rounded-2xl border border-border bg-card p-4",children:[q("header",{className:"flex flex-wrap items-center justify-between gap-3",children:[q("div",{children:[q("p",{className:"font-semibold text-sm uppercase tracking-wide",children:[A," credentials"]}),f("p",{className:"text-muted-foreground text-sm",children:"Store encrypted keys with BYOK and run safe connection tests."})]}),f(d,{className:"h-5 w-5 text-muted-foreground"})]}),f("div",{className:"grid gap-4 md:grid-cols-2",children:q("div",{className:"space-y-2",children:[f(E,{htmlFor:"ownershipMode",children:"Ownership"}),q(Q,{value:D.ownershipMode??"managed",onValueChange:(G)=>N((H)=>({...H,ownershipMode:G})),children:[f(U,{id:"ownershipMode",className:"w-full",children:f(W,{})}),q(R,{children:[f(M,{value:"managed",children:"Managed (store encrypted)"}),f(M,{value:"byok",children:"BYOK (store secret reference)"})]})]})]})}),q("div",{className:"grid gap-4 md:grid-cols-2",children:[q("div",{className:"space-y-1 text-sm",children:[f(E,{htmlFor:"apiKey",className:"font-semibold",children:"API key"}),q("div",{className:"relative",children:[f(I,{className:"pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),f(O,{type:"text",name:"apiKey",id:"apiKey",className:"w-full py-2 pr-3 pl-9",value:D.apiKey,onChange:J,required:!0})]})]}),q("div",{className:"space-y-1 text-sm",children:[f(E,{htmlFor:"secret",className:"font-semibold",children:"Secret"}),f(O,{type:"password",id:"secret",name:"secret",className:"w-full px-3 py-2",value:D.secret,onChange:J})]})]}),D.ownershipMode==="byok"?q("div",{className:"space-y-4 rounded-xl border border-blue-500/20 bg-blue-500/5 p-4",children:[f("p",{className:"font-semibold text-sm",children:"BYOK secret reference"}),q("div",{className:"grid gap-4 md:grid-cols-2",children:[q("div",{className:"space-y-2",children:[f(E,{htmlFor:"secretProvider",children:"Secret provider"}),q(Q,{value:D.secretProvider??"env",onValueChange:(G)=>N((H)=>({...H,secretProvider:G})),children:[f(U,{id:"secretProvider",className:"w-full",children:f(W,{})}),q(R,{children:[f(M,{value:"env",children:"Environment"}),f(M,{value:"gcp",children:"GCP Secret Manager"})]})]})]}),q("div",{className:"space-y-2",children:[f(E,{htmlFor:"secretRef",children:"Secret reference"}),f(O,{id:"secretRef",name:"secretRef",placeholder:D.secretProvider==="gcp"?"gcp://projects/.../secrets/...":"env://MY_TOKEN_ENV_VAR",value:D.secretRef??"",onChange:J})]})]})]}):q("div",{className:"flex items-center gap-3 rounded-xl border border-emerald-500/20 bg-emerald-500/5 p-4 text-sm",children:[f(L,{checked:!0,onCheckedChange:()=>{},"aria-label":"Managed"}),q("div",{children:[f("p",{className:"font-semibold",children:"Managed encryption enabled"}),f("p",{className:"text-muted-foreground",children:"Secrets are encrypted server-side for this tenant."})]})]}),q("div",{className:"space-y-1 text-sm",children:[f(E,{htmlFor:"config",className:"font-semibold",children:"Configuration (JSON)"}),f(m,{id:"config",name:"config",className:"min-h-[140px] w-full font-mono text-sm",value:D.config,onChange:J})]}),q("div",{className:"flex flex-wrap items-center gap-3",children:[q(P,{variant:"ghost",onPress:()=>F?.(D),disabled:_,children:[f(T,{className:"h-4 w-4"}),"Test connection"]}),f(P,{variant:"default",onPress:()=>Y?.(D),disabled:Z,children:"Save settings"})]})]})}export{r as IntegrationSettings};
