// @bun
import{Button as N,Input as M,Textarea as K}from"@contractspec/lib.design-system";import{Checkbox as B}from"@contractspec/lib.ui-kit-web/ui/checkbox";import{Label as D}from"@contractspec/lib.ui-kit-web/ui/label";import{Select as O,SelectContent as P,SelectItem as H,SelectTrigger as Q,SelectValue as R}from"@contractspec/lib.ui-kit-web/ui/select";import{Key as k,ShieldCheck as m,TestTube2 as L}from"lucide-react";import*as U from"react";import{jsx as f,jsxs as q}from"react/jsx-runtime";function h({provider:W,initialValues:A,onTestConnection:X,onSave:Y,isSaving:Z,isTesting:_}){let[z,J]=U.useState({apiKey:A?.apiKey??"",secret:A?.secret??"",ownershipMode:A?.ownershipMode??"managed",secretProvider:A?.secretProvider??"env",secretRef:A?.secretRef??"",config:A?.config??`{
  "region": "eu-west-1"
}`}),G=(E)=>{let F=E.target,{name:$,value:w}=F;J((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:[W," credentials"]}),f("p",{className:"text-muted-foreground text-sm",children:"Store encrypted keys with BYOK and run safe connection tests."})]}),f(m,{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(D,{htmlFor:"ownershipMode",children:"Ownership"}),q(O,{value:z.ownershipMode??"managed",onValueChange:(E)=>J((F)=>({...F,ownershipMode:E})),children:[f(Q,{id:"ownershipMode",className:"w-full",children:f(R,{})}),q(P,{children:[f(H,{value:"managed",children:"Managed (store encrypted)"}),f(H,{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(D,{htmlFor:"apiKey",className:"font-semibold",children:"API key"}),q("div",{className:"relative",children:[f(k,{className:"pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),f(M,{type:"text",name:"apiKey",id:"apiKey",className:"w-full py-2 pr-3 pl-9",value:z.apiKey,onChange:G,required:!0})]})]}),q("div",{className:"space-y-1 text-sm",children:[f(D,{htmlFor:"secret",className:"font-semibold",children:"Secret"}),f(M,{type:"password",id:"secret",name:"secret",className:"w-full px-3 py-2",value:z.secret,onChange:G})]})]}),z.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(D,{htmlFor:"secretProvider",children:"Secret provider"}),q(O,{value:z.secretProvider??"env",onValueChange:(E)=>J((F)=>({...F,secretProvider:E})),children:[f(Q,{id:"secretProvider",className:"w-full",children:f(R,{})}),q(P,{children:[f(H,{value:"env",children:"Environment"}),f(H,{value:"gcp",children:"GCP Secret Manager"})]})]})]}),q("div",{className:"space-y-2",children:[f(D,{htmlFor:"secretRef",children:"Secret reference"}),f(M,{id:"secretRef",name:"secretRef",placeholder:z.secretProvider==="gcp"?"gcp://projects/.../secrets/...":"env://MY_TOKEN_ENV_VAR",value:z.secretRef??"",onChange:G})]})]})]}):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(B,{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(D,{htmlFor:"config",className:"font-semibold",children:"Configuration (JSON)"}),f(K,{id:"config",name:"config",className:"min-h-[140px] w-full font-mono text-sm",value:z.config,onChange:G})]}),q("div",{className:"flex flex-wrap items-center gap-3",children:[q(N,{variant:"ghost",onPress:()=>X?.(z),disabled:_,children:[f(L,{className:"h-4 w-4"}),"Test connection"]}),f(N,{variant:"default",onPress:()=>Y?.(z),disabled:Z,children:"Save settings"})]})]})}export{h as IntegrationSettings};
