import{aE as k,aF as E,aG as S,j as e,P as u,bZ as F,w,a as C,bR as P,r as c,bX as A,bY as B,B as b,e as g,a8 as D,T as p,H as d,M as s,ay as h,aw as N,ax as V,D as $,bC as Y,b_ as q,k as G}from"./strapi-BZkmC8So.js";const H=(i,t)=>!i||!t?{}:{[i]:t[i]},O=i=>(i?.inner||[]).reduce((t,a)=>(a.path&&(t[a.path.split("[").join(".").split("]").join("")]={id:a.message,defaultMessage:a.message,values:H(a?.type,a?.params)}),t),{}),M=k().shape({email:E().email(S.email.id).required(S.required.id)}),_=G.a`
  color: ${({theme:i})=>i.colors.primary600};
`,Z=()=>e.jsx(u.Protect,{permissions:F.settings,children:e.jsx(Q,{})}),Q=()=>{const{toggleNotification:i}=w(),{formatMessage:t}=C(),{get:a,post:y}=P(),[l,v]=c.useState(""),[I,f]=c.useState(!1),[x,R]=c.useState({}),{data:o,isLoading:j}=A(["email","settings"],async()=>{const n=await a("/email/settings"),{data:{config:r}}=n;return r}),m=B(async n=>{await y("/email/test",n)},{onError(){i({type:"danger",message:t({id:"email.Settings.email.plugin.notification.test.error",defaultMessage:"Failed to send a test mail to {to}"},{to:l})})},onSuccess(){i({type:"success",message:t({id:"email.Settings.email.plugin.notification.test.success",defaultMessage:"Email test succeeded, check the {to} mailbox"},{to:l})})},retry:!1});c.useEffect(()=>{M.validate({email:l},{abortEarly:!1}).then(()=>f(!0)).catch(()=>f(!1))},[l]);const T=n=>{v(()=>n.target.value)},L=async n=>{n.preventDefault();try{await M.validate({email:l},{abortEarly:!1})}catch(r){r instanceof q&&R(O(r))}m.mutate({to:l})};return j?e.jsx(u.Loading,{}):e.jsxs(u.Main,{labelledBy:"title","aria-busy":j||m.isLoading,children:[e.jsx(u.Title,{children:t({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:t({id:"email.Settings.email.plugin.title",defaultMessage:"Configuration"})})}),e.jsx(b.Header,{id:"title",title:t({id:"email.Settings.email.plugin.title",defaultMessage:"Configuration"}),subtitle:t({id:"email.Settings.email.plugin.subTitle",defaultMessage:"Test the settings for the Email plugin"})}),e.jsx(b.Content,{children:o&&e.jsx("form",{onSubmit:L,children:e.jsxs(g,{direction:"column",alignItems:"stretch",gap:7,children:[e.jsx(D,{background:"neutral0",hasRadius:!0,shadow:"filterShadow",paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,children:e.jsxs(g,{direction:"column",alignItems:"stretch",gap:4,children:[e.jsxs(g,{direction:"column",alignItems:"stretch",gap:1,children:[e.jsx(p,{variant:"delta",tag:"h2",children:t({id:"email.Settings.email.plugin.title.config",defaultMessage:"Configuration"})}),e.jsx(p,{children:t({id:"email.Settings.email.plugin.text.configuration",defaultMessage:"The plugin is configured through the {file} file, checkout this {link} for the documentation."},{file:"./config/plugins.js",link:e.jsx(_,{href:"https://docs.strapi.io/developer-docs/latest/plugins/email.html",target:"_blank",rel:"noopener noreferrer",children:t({id:"email.link",defaultMessage:"Link"})})})})]}),e.jsxs(d.Root,{gap:5,children:[e.jsx(d.Item,{col:6,s:12,direction:"column",alignItems:"stretch",children:e.jsxs(s.Root,{name:"shipper-email",children:[e.jsx(s.Label,{children:t({id:"email.Settings.email.plugin.label.defaultFrom",defaultMessage:"Default sender email"})}),e.jsx(h,{placeholder:t({id:"email.Settings.email.plugin.placeholder.defaultFrom",defaultMessage:"ex: Strapi No-Reply '<'no-reply@strapi.io'>'"}),disabled:!0,value:o.settings.defaultFrom})]})}),e.jsx(d.Item,{col:6,s:12,direction:"column",alignItems:"stretch",children:e.jsxs(s.Root,{name:"response-email",children:[e.jsx(s.Label,{children:t({id:"email.Settings.email.plugin.label.defaultReplyTo",defaultMessage:"Default response email"})}),e.jsx(h,{placeholder:t({id:"email.Settings.email.plugin.placeholder.defaultReplyTo",defaultMessage:"ex: Strapi '<'example@strapi.io'>'"}),disabled:!0,value:o.settings.defaultReplyTo})]})}),e.jsx(d.Item,{col:6,s:12,direction:"column",alignItems:"stretch",children:e.jsxs(s.Root,{name:"email-provider",children:[e.jsx(s.Label,{children:t({id:"email.Settings.email.plugin.label.provider",defaultMessage:"Email provider"})}),e.jsx(N,{disabled:!0,value:o.provider,children:e.jsx(V,{value:o.provider,children:o.provider})})]})})]})]})}),e.jsxs(g,{alignItems:"stretch",background:"neutral0",direction:"column",gap:4,hasRadius:!0,shadow:"filterShadow",paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,children:[e.jsx(p,{variant:"delta",tag:"h2",children:t({id:"email.Settings.email.plugin.title.test",defaultMessage:"Test email delivery"})}),e.jsxs(d.Root,{gap:5,children:[e.jsx(d.Item,{col:6,s:12,direction:"column",alignItems:"stretch",children:e.jsxs(s.Root,{name:"test-address",error:x.email?.id&&t({id:`email.${x.email?.id}`,defaultMessage:"This is not a valid email"}),children:[e.jsx(s.Label,{children:t({id:"email.Settings.email.plugin.label.testAddress",defaultMessage:"Recipient email"})}),e.jsx(h,{onChange:T,value:l,placeholder:t({id:"email.Settings.email.plugin.placeholder.testAddress",defaultMessage:"ex: developer@example.com"})})]})}),e.jsx(d.Item,{col:7,s:12,direction:"column",alignItems:"start",children:e.jsx($,{loading:m.isLoading,disabled:!I,type:"submit",startIcon:e.jsx(Y,{}),children:t({id:"email.Settings.email.plugin.button.test-email",defaultMessage:"Send test email"})})})]})]})]})})})]})};export{Z as ProtectedSettingsPage};
