import{e as v,i as k,r as c,j as e,I as S,d}from"./index-D4ZMoJFe.js";import{A as w}from"./AdminSubnav-B96tphNW.js";import{f as C,h as D,i as M,j as z}from"./adminUtils-Qmlne9KJ.js";import{D as E}from"./download-CFmyYwm2.js";import{S as A}from"./save-DeIgwxFd.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=v("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const T=v("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]),f=()=>({application_name:"",default_language:"fr",date_format:"DD/MM/YYYY",decimal_separator:",",thousands_separator:" ",session_expiration_minutes:480,max_failed_logins_before_lockout:5,password_minimum_length:8,last_backup_at:null,last_backup_size_bytes:null});function G(){const{pushToast:m}=k(),[o,x]=c.useState(!0),[p,u]=c.useState(!1),[g,h]=c.useState(!1),[j,r]=c.useState(""),[l,n]=c.useState(f),N=async()=>{var a,s;x(!0),r("");try{const t=await d.get("/system-settings");n({...f(),...t.data.item})}catch(t){r(((s=(a=t==null?void 0:t.response)==null?void 0:a.data)==null?void 0:s.message)||"Impossible de charger les paramètres système.")}finally{x(!1)}};c.useEffect(()=>{N()},[]);const b=async a=>{var s,t;a.preventDefault(),u(!0),r("");try{const i=await d.put("/system-settings",{...l});n(_=>({..._,...i.data.item})),m({title:"Paramètres système mis à jour",description:i.data.item.application_name,tone:"success"})}catch(i){r(((t=(s=i==null?void 0:i.response)==null?void 0:s.data)==null?void 0:t.message)||"Impossible d'enregistrer les paramètres système.")}finally{u(!1)}},y=async()=>{var a,s;h(!0);try{const t=await d.post("/backup",{},{responseType:"blob"}),i=M(t.headers["content-disposition"],"scf-backup.sql");z(t.data,i),m({title:"Sauvegarde téléchargée",description:i,tone:"success"}),await N()}catch(t){m({title:"Sauvegarde impossible",description:((s=(a=t==null?void 0:t.response)==null?void 0:a.data)==null?void 0:s.message)||"Le téléchargement de la sauvegarde a échoué.",tone:"danger"})}finally{h(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"card-panel p-6 sm:p-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-accent",children:"Administration"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Paramètres système"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-textMuted",children:"Configurez les conventions globales, la politique de sécurité et les sauvegardes."})]}),e.jsx("div",{className:"mt-6",children:e.jsx(w,{})})]}),j?e.jsx("section",{className:"rounded-2xl border border-danger/20 bg-danger/5 px-5 py-4 text-sm text-danger",children:j}):null,e.jsxs("form",{onSubmit:b,className:"space-y-6",children:[e.jsxs("section",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs("div",{className:"card-panel p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{size:18,className:"text-accent"}),e.jsx("h2",{className:"text-xl font-semibold text-text",children:"Général"})]}),e.jsxs("div",{className:"mt-6 grid gap-4",children:[e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Nom de l'application"}),e.jsx("input",{className:"input-dark",value:l.application_name,onChange:a=>n(s=>({...s,application_name:a.target.value}))})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Langue par défaut"}),e.jsxs("select",{className:"input-dark",value:l.default_language,onChange:a=>n(s=>({...s,default_language:a.target.value})),children:[e.jsx("option",{value:"fr",children:"FR"}),e.jsx("option",{value:"en",children:"EN"})]})]}),e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Format date"}),e.jsx("input",{className:"input-dark",value:l.date_format,onChange:a=>n(s=>({...s,date_format:a.target.value}))})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Séparateur décimal"}),e.jsx("input",{className:"input-dark",value:l.decimal_separator,onChange:a=>n(s=>({...s,decimal_separator:a.target.value}))})]}),e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Séparateur milliers"}),e.jsx("input",{className:"input-dark",value:l.thousands_separator,onChange:a=>n(s=>({...s,thousands_separator:a.target.value}))})]})]})]})]}),e.jsxs("div",{className:"card-panel p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(S,{size:18,className:"text-accent2"}),e.jsx("h2",{className:"text-xl font-semibold text-text",children:"Sécurité"})]}),e.jsxs("div",{className:"mt-6 grid gap-4",children:[e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Expiration de session (minutes)"}),e.jsx("input",{type:"number",min:"5",className:"input-dark",value:l.session_expiration_minutes,onChange:a=>n(s=>({...s,session_expiration_minutes:Number(a.target.value)}))})]}),e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Échecs max avant verrouillage"}),e.jsx("input",{type:"number",min:"1",className:"input-dark",value:l.max_failed_logins_before_lockout,onChange:a=>n(s=>({...s,max_failed_logins_before_lockout:Number(a.target.value)}))})]}),e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-text",children:"Longueur minimale du mot de passe"}),e.jsx("input",{type:"number",min:"6",className:"input-dark",value:l.password_minimum_length,onChange:a=>n(s=>({...s,password_minimum_length:Number(a.target.value)}))})]})]})]})]}),e.jsxs("section",{className:"card-panel p-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(L,{size:18,className:"text-gold"}),e.jsx("h2",{className:"text-xl font-semibold text-text",children:"Sauvegarde"})]}),e.jsxs("div",{className:"mt-6 grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"card-panel-elevated p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-textMuted",children:"Dernière sauvegarde"}),e.jsx("div",{className:"mt-2 text-sm font-medium text-text",children:C(l.last_backup_at)})]}),e.jsxs("div",{className:"card-panel-elevated p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-textMuted",children:"Taille"}),e.jsx("div",{className:"mt-2 text-sm font-medium text-text",children:D(l.last_backup_size_bytes)})]}),e.jsxs("div",{className:"card-panel-elevated flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-textMuted",children:"Export base PostgreSQL"}),e.jsx("div",{className:"mt-2 text-sm text-textMuted",children:"Génère un `pg_dump` téléchargeable."})]}),e.jsxs("button",{type:"button",className:"btn-secondary inline-flex items-center gap-2",onClick:y,disabled:g||o,children:[e.jsx(E,{size:16}),g?"Export...":"Télécharger"]})]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",className:"btn-primary inline-flex items-center gap-2",disabled:p||o,children:[e.jsx(A,{size:16}),p?"Enregistrement...":"Enregistrer"]})})]})]})}export{G as default};
