1import{n as K,v as X,r as w,j as e}from"./vendor-react-RByCY-Mz.js";import{b as Z,c as ee,C as d,o as se,s as r,d as j}from"./vendor-forms-CfD6x6WJ.js";import{k as t,I as f,T as V,t as k}from"./index-WCS9x8Dk.js";import{F as ie}from"./FormWizard-B0N_pHs8.js";import{a as $}from"./PortalPage-BjArta7-.js";import{R as ne}from"./RiskScoreGauge-LpdW03WX.js";import{C as ae}from"./checkbox-Dx8755r6.js";import{R as b,a as S}from"./radio-group-D0h34ELe.js";import{S as L}from"./skeleton-BYCyQhtn.js";import{S as C,a as N,b as E,c as T,d as v}from"./select-Cm4T0aMn.js";import{C as re,c as te}from"./card-zNIZm2xa.js";import{a as oe,b as le,c as de,d as ce}from"./useAiSystems-Do33s9Rr.js";import{u as me}from"./useOrgMembers-B8I7VchA.js";import{S as pe,G as _e,D as ue,A as xe,E as he,a as fe,b as je,c as ve,d as ye,e as we,L as ge,f as be}from"./ai-systems-CHgsGWNG.js";import{u as Se}from"./vendor-i18n-Brn8V5gU.js";import{e as I,F as Ce,h as Ne,ab as Ee,U as Te,be as ze}from"./vendor-icons-Dq_HR579.js";import"./vendor-query-CnDe4iID.js";import"./vendor-supabase-DyFNpjS2.js";import"./vendor-charts-D79u5_yG.js";import"./vendor-ui-CUSbNqge.js";import"./vendor-motion-CpVQFZS7.js";import"./vendor-markdown-BWDJH5DM.js";import"./PageHeader-Bt1UJhnF.js";import"./SectionHelpButton-BDR9ToUz.js";import"./badge-Dbo8BGdG.js";import"./FeatureGate-NQJtGMd5.js";import"./usePlanFeatures-CkiC608G.js";import"./useSubscription-i5_PvxGD.js";import"./nav-config-BzamokRe.js";import"./supabase-helpers-KjH7AuEi.js";const Fe=se({name:r().min(1),description:r().min(1),internal_ref:r().nullable().optional(),system_type:r().min(1),genai_subtype:r().nullable().optional(),departments:j(r()).default([]),purpose:r().nullable().optional(),affected_population:j(r()).default([]),estimated_volume:r().nullable().optional(),autonomy_level:r().nullable().optional(),sensitive_domains:j(r()).default([]),data_types:j(r()).default([]),system_source:r().nullable().optional(),vendor_name:r().nullable().optional(),model_version:r().nullable().optional(),data_locations:j(r()).default([]),business_owner_id:r().nullable().optional(),tech_owner_id:r().nullable().optional(),privacy_owner_id:r().nullable().optional(),risk_owner_id:r().nullable().optional(),approver_id:r().nullable().optional(),lifecycle_status:r().default("idea"),production_date:r().nullable().optional(),next_review_date:r().nullable().optional(),review_frequency:r().default("quarterly"),notes:r().nullable().optional()});function Pe(i){return w.useMemo(()=>[{id:"identification",label:i("wizard.steps.identification"),description:i("wizard.steps.identificationDesc"),icon:Ce},{id:"scope",label:i("wizard.steps.scope"),description:i("wizard.steps.scopeDesc"),icon:Ne},{id:"data",label:i("wizard.steps.data"),description:i("wizard.steps.dataDesc"),icon:Ee},{id:"owners",label:i("wizard.steps.owners"),description:i("wizard.steps.ownersDesc"),icon:Te},{id:"status",label:i("wizard.steps.status"),description:i("wizard.steps.statusDesc"),icon:ze}],[i])}function y({options:i,value:_,onChange:x,labelFn:u}){function c(m){x(_.includes(m)?_.filter(z=>z!==m):[..._,m])}return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:i.map(m=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx(ae,{checked:_.includes(m),onCheckedChange:()=>c(m)}),u(m)]},m))})}function ds(){const{t:i}=Se("aiSystems"),_=K(),{id:x}=X(),u=!!x,[c,m]=w.useState(0),z=Pe(i),{data:a,isLoading:O}=oe(u?x:void 0),A=le(),D=de(),{data:q=[]}=me(),U=Z({resolver:ee(Fe),defaultValues:{name:"",description:"",internal_ref:"",system_type:"",genai_subtype:"",departments:[],purpose:"",affected_population:[],estimated_volume:"",autonomy_level:"",sensitive_domains:[],data_types:[],system_source:"",vendor_name:"",model_version:"",data_locations:[],business_owner_id:"",tech_owner_id:"",privacy_owner_id:"",risk_owner_id:"",approver_id:"",lifecycle_status:"idea",production_date:"",next_review_date:"",review_frequency:"quarterly",notes:""}}),{register:p,control:l,watch:F,handleSubmit:G,reset:M,formState:{errors:Y}}=U;w.useEffect(()=>{a&&M({name:a.name,description:a.description,internal_ref:a.internal_ref??"",system_type:a.system_type,genai_subtype:a.genai_subtype??"",departments:a.departments??[],purpose:a.purpose??"",affected_population:a.affected_population??[],estimated_volume:a.estimated_volume??"",autonomy_level:a.autonomy_level??"",sensitive_domains:a.sensitive_domains??[],data_types:a.data_types??[],system_source:a.system_source??"",vendor_name:a.vendor_name??"",model_version:a.model_version??"",data_locations:a.data_locations??[],business_owner_id:a.business_owner_id??"",tech_owner_id:a.tech_owner_id??"",privacy_owner_id:a.privacy_owner_id??"",risk_owner_id:a.risk_owner_id??"",approver_id:a.approver_id??"",lifecycle_status:a.lifecycle_status,production_date:a.production_date??"",next_review_date:a.next_review_date??"",review_frequency:a.review_frequency,notes:a.notes??""})}
1,[a,M]);const o=F(),W=w.useMemo(()=>ce({autonomy_level:o.autonomy_level||void 0,data_types:o.data_types,affected_population:o.affected_population,sensitive_domains:o.sensitive_domains}),[o.autonomy_level,o.data_types,o.affected_population,o.sensitive_domains]),B=F("system_type")?.includes("genai"),R=F("system_source"),Q=R==="vendor"||R==="hybrid",H=w.useMemo(()=>c===0?!!o.name&&!!o.description&&!!o.system_type:!0,[c,o.name,o.description,o.system_type]);async function J(s){try{const n={name:s.name,description:s.description,internal_ref:s.internal_ref||null,system_type:s.system_type,genai_subtype:s.genai_subtype||null,departments:s.departments,purpose:s.purpose||null,affected_population:s.affected_population,estimated_volume:s.estimated_volume||null,autonomy_level:s.autonomy_level||null,sensitive_domains:s.sensitive_domains,data_types:s.data_types,system_source:s.system_source||null,vendor_name:s.vendor_name||null,model_version:s.model_version||null,data_locations:s.data_locations,business_owner_id:s.business_owner_id&&s.business_owner_id!=="__none__"?s.business_owner_id:null,tech_owner_id:s.tech_owner_id&&s.tech_owner_id!=="__none__"?s.tech_owner_id:null,privacy_owner_id:s.privacy_owner_id&&s.privacy_owner_id!=="__none__"?s.privacy_owner_id:null,risk_owner_id:s.risk_owner_id&&s.risk_owner_id!=="__none__"?s.risk_owner_id:null,approver_id:s.approver_id&&s.approver_id!=="__none__"?s.approver_id:null,lifecycle_status:s.lifecycle_status,production_date:s.production_date||null,next_review_date:s.next_review_date||null,review_frequency:s.review_frequency,notes:s.notes||null};if(u&&x){const h=await D.mutateAsync({id:x,...n});k.success(i("wizard.updateSuccess")),_(`/ai-systems/${h.id}`)}else{const h=await A.mutateAsync(n);k.success(i("wizard.createSuccess")),_(`/ai-systems/${h.id}`)}}catch{k.error(i("wizard.error"))}}if(u&&O)return e.jsx($,{icon:I,title:i("wizard.editTitle"),description:i("description"),children:e.jsxs("div",{className:"max-w-4xl mx-auto space-y-6",children:[e.jsx(L,{className:"h-8 w-64"}),e.jsx(L,{className:"h-12 w-full"}),e.jsx("div",{className:"space-y-4",children:[1,2,3,4].map(s=>e.jsx(L,{className:"h-10 w-full"},s))})]})});function P(s){return Y[s]?e.jsx("p",{className:"text-sm text-destructive mt-1",children:i("wizard.fieldRequired")}):null}return e.jsx($,{icon:I,title:i(u?"wizard.editTitle":"wizard.createTitle"),description:i("description"),children:e.jsx("div",{className:"max-w-4xl mx-auto",children:e.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[e.jsx("div",{className:"flex-1",children:e.jsxs(ie,{steps:z,currentStep:c,onStepChange:m,onSubmit:G(J),isSubmitting:A.isPending||D.isPending,canGoNext:H,submitLabel:i(u?"wizard.submitUpdate":"wizard.submitCreate"),draftLabel:i("wizard.saveDraft"),previousLabel:i("wizard.previous"),nextLabel:i("wizard.next"),submittingLabel:i("wizard.submitting",{defaultValue:"Envoi en coursâ¦"}),children:[c===0&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs(t,{htmlFor:"name",children:[i("fields.name")," *"]}),e.jsx(f,{id:"name",...p("name"),placeholder:i("fields.namePlaceholder")}),P("name")]}),e.jsxs("div",{children:[e.jsxs(t,{htmlFor:"description",children:[i("fields.description")," *"]}),e.jsx(V,{id:"description",...p("description"),rows:4,placeholder:i("fields.descriptionPlaceholder")}),P("description")]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"internal_ref",children:i("fields.internalRef")}),e.jsx(f,{id:"internal_ref",...p("internal_ref"),placeholder:i("fields.internalRefPlaceholder")})]}),e.jsxs("div",{children:[e.jsxs(t,{children:[i("fields.systemType")," *"]}),e.jsx(d,{name:"system_type",control:l,render:({field:s})=>e.jsx(b,{value:s.value,onValueChange:s.onChange,className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2",children:pe.map(n=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx(S,{value:n}),i(`systemTypes.${n}`)]},n))})}),P("system_type")]}),B&&e.jsxs("div",{children:[e.jsx(t,{children:i("fields.genaiSubtype")}),e.jsx(d,{name:"genai_subtype",control:l,render:({field:s})=>e.jsx(b,{value:s.value??"",onValueChange:s.onChange,className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2",children:_e.map(n=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx(S,{value:n}),i(`genaiSubtypes.${n}`)]},n))})})]})]}),c===1&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(t,{children:i("fields.departments")}),e.jsx(d,{name:"departments",control:l,render:({field:s})=>e.jsx(y,{options:ue,value:s.value,onChange:s.onChange,labelFn:n=>i(`departments.${n}`)})})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"purpose",children:i("fields.purpose")}),e.jsx(V,{id:"purpose",...p("purpose"),rows:3,placeholder:i("fields.purposePlaceholder")})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.affectedPopulation")}),e.jsx(d,{name:"affected_population",control:l,render:({field:s})=>e.jsx(y,{options:xe,value:s.value,onChange:s.onChange,labelFn:n=>i(`affectedPopulations.${n}`)})})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.estimatedVolume")}),e.jsx(d,{name:"estimated_volume",control:l,render:({field:s})=>e.jsxs(C,{value:s.value??"",onValueChange:s.onChange,children:[e.jsx(N,{className:"w-full",children:e.jsx(E,{placeholder:i("fields.estimatedVolumePlaceholder")})}),e.jsx(T,{children:he.map(n=>e.jsx(v,{value:n,children:i(`estimatedVolumes.${n}`)},n))})]})})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.autonomyLevel")}),e.jsx(d,{name:"autonomy_level",control:l,render:({field:s})=>e.jsx(b,{value:s.value??"",onValueChange:s.onChange,className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2",children:fe.map(n=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx(S,{value:n}),i(`autonomyLevels.${n}`)]},n))})})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.sensitiveDomains")}),e.jsx(d,{name:"sensitive_domains",control:l,render:({field:s})=>e.jsx(y,{options:je,value:s.value,onChange:s.onChange,labelFn:n=>i(`sensitiveDomains.${n}`)})})]})]}),c===2&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(t,{children:i("fields.dataTypes")}),e.jsx(d,{name:"data_types",control:l,render:({field:s})=>e.jsx(y,{options:ve,value:s.value,onChange:s.onChange,labelFn:n=>i(`dataTypes.${n}`)})})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.systemSource")}),e.jsx(d,{name:"system_source",control:l,render:({field:s})=>e.jsx(b,{value:s.value??"",onValueChange:s.onChange,className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2",children:ye.map(n=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[e.jsx(S,{value:n}),i(`systemSources.${n}`)]},n))})})]}),Q&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(t,{htmlFor:"vendor_name",children:i("fields.vendorName")}
1),e.jsx(f,{id:"vendor_name",...p("vendor_name"),placeholder:i("fields.vendorNamePlaceholder")})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"model_version",children:i("fields.modelVersion")}),e.jsx(f,{id:"model_version",...p("model_version"),placeholder:i("fields.modelVersionPlaceholder")})]})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.dataLocations")}),e.jsx(d,{name:"data_locations",control:l,render:({field:s})=>e.jsx(y,{options:we,value:s.value,onChange:s.onChange,labelFn:n=>i(`dataLocations.${n}`)})})]})]}),c===3&&e.jsx("div",{className:"space-y-5",children:[["business_owner_id","businessOwner"],["tech_owner_id","techOwner"],["privacy_owner_id","privacyOwner"],["risk_owner_id","riskOwner"],["approver_id","approver"]].map(([s,n])=>e.jsxs("div",{children:[e.jsx(t,{children:i(`fields.${n}`)}),e.jsx(d,{name:s,control:l,render:({field:h})=>e.jsxs(C,{value:h.value,onValueChange:h.onChange,children:[e.jsx(N,{className:"w-full",children:e.jsx(E,{placeholder:i("fields.ownerSelectPlaceholder")})}),e.jsxs(T,{children:[e.jsx(v,{value:"__none__",children:i("fields.ownerNone")}),q.map(g=>e.jsx(v,{value:g.user_id,children:g.full_name||g.email},g.user_id))]})]})})]},s))}),c===4&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(t,{children:i("fields.lifecycleStatus")}),e.jsx(d,{name:"lifecycle_status",control:l,render:({field:s})=>e.jsxs(C,{value:s.value,onValueChange:s.onChange,children:[e.jsx(N,{className:"w-full",children:e.jsx(E,{})}),e.jsx(T,{children:ge.map(n=>e.jsx(v,{value:n,children:i(`lifecycleStatuses.${n}`)},n))})]})})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"production_date",children:i("fields.productionDate")}),e.jsx(f,{id:"production_date",type:"date",...p("production_date")})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"next_review_date",children:i("fields.nextReviewDate")}),e.jsx(f,{id:"next_review_date",type:"date",...p("next_review_date")})]}),e.jsxs("div",{children:[e.jsx(t,{children:i("fields.reviewFrequency")}),e.jsx(d,{name:"review_frequency",control:l,render:({field:s})=>e.jsxs(C,{value:s.value,onValueChange:s.onChange,children:[e.jsx(N,{className:"w-full",children:e.jsx(E,{})}),e.jsx(T,{children:be.map(n=>e.jsx(v,{value:n,children:i(`reviewFrequencies.${n}`)},n))})]})})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"notes",children:i("fields.notes")}),e.jsx(V,{id:"notes",...p("notes"),rows:4,placeholder:i("fields.notesPlaceholder")})]})]})]})}),e.jsx("div",{className:"lg:w-48 shrink-0",children:e.jsx(re,{className:"sticky top-6",children:e.jsxs(te,{className:"flex flex-col items-center gap-2 pt-6",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:i("wizard.riskPreview")}),e.jsx(ne,{score:W.score,size:"md",showLabel:!0})]})})})]})})})}export{ds 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.