import{a as E,r as a,s as S,j as e,L,B as b,t as N}from"./index-B8oXSmui.js";import{u as A}from"./useIsAdmin-4zkN3lQd.js";import{I as l}from"./input-BeAjoI93.js";import{L as n}from"./label-D89q0mK-.js";import{C as I}from"./card-BGuHQar-.js";import{A as w}from"./arrow-left-CdXF6txo.js";import{S as P}from"./save-DXXxSfaP.js";function H(){const t=A(),i=E(),[o,m]=a.useState(""),[c,u]=a.useState(465),[d,p]=a.useState(""),[x,f]=a.useState(""),[h,g]=a.useState(""),[_,y]=a.useState(!0),[v,j]=a.useState(!1);a.useEffect(()=>{t===!1&&i({to:"/app"})},[t,i]),a.useEffect(()=>{t&&S.from("email_settings").select("*").eq("id",1).maybeSingle().then(({data:s})=>{const r=s;r&&(m(r.email_host??""),u(r.email_port??465),p(r.email_user??""),f(r.email_pass??""),g(r.from_name??"")),y(!1)})},[t]);const C=async()=>{j(!0);const{error:s}=await S.from("email_settings").update({email_host:o||null,email_port:c,email_user:d||null,email_pass:x||null,from_name:h||null,updated_at:new Date().toISOString()}).eq("id",1);if(j(!1),s)return N.error(s.message);N.success("Configuration enregistrée")};return t===null||_?e.jsx("div",{className:"p-10 text-muted-foreground",children:"Chargement…"}):t?e.jsxs("div",{className:"mx-auto max-w-2xl p-6 md:p-10",children:[e.jsxs(L,{to:"/app",className:"mb-4 inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(w,{className:"h-4 w-4"})," Retour"]}),e.jsx("h1",{className:"mb-1 text-3xl font-bold",children:"Configuration Email"}),e.jsx("p",{className:"mb-8 text-sm text-muted-foreground",children:"Paramètres SMTP utilisés pour envoyer les communications. Laissez vide pour utiliser les variables système."}),e.jsxs(I,{className:"space-y-4 p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"Nom de l'expéditeur"}),e.jsx(l,{value:h,onChange:s=>g(s.target.value),placeholder:"Communications Studio"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"EMAIL_HOST"}),e.jsx(l,{value:o,onChange:s=>m(s.target.value),placeholder:"smtp.gmail.com"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"EMAIL_PORT"}),e.jsx(l,{type:"number",value:c,onChange:s=>u(parseInt(s.target.value||"465",10))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"EMAIL_USER"}),e.jsx(l,{type:"email",value:d,onChange:s=>p(s.target.value),placeholder:"user@gmail.com"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{children:"EMAIL_PASS"}),e.jsx(l,{type:"password",value:x,onChange:s=>f(s.target.value),placeholder:"mot de passe d'application"})]}),e.jsxs(b,{onClick:C,disabled:v,className:"w-full",children:[e.jsx(P,{className:"h-4 w-4"})," ",v?"...":"Enregistrer"]})]})]}):null}export{H as component};
