import{C as e,E as t,Ht as n,Q as r,R as i,W as a,X as o,_ as s,b as c,f as l,ut as u,w as d,y as f}from"./vue.runtime.esm-bundler-56z_v_HH.js";import{t as p}from"./notification.store-EczSZ_VB.js";import{n as m,r as h}from"./error-handling-S7N4FACK.js";import{t as g}from"./company.service-BUBqxT6X.js";import{n as _}from"./vue-i18n-DhldrKy8.js";import{I as v}from"./main-CkEZzrzw.js";import{n as y,t as b}from"./MailTestModal-qxcF9_aw.js";import{t as x}from"./MailConfigurationForm-B2XI8M18.js";var S={class:`mt-8`},C={key:0,class:`mt-8`},w={key:1,class:`mt-4 p-4 rounded-lg bg-green-500/10 border border-green-500/20 text-sm text-status-green flex items-center`},T=t({__name:`MailConfigView`,setup(t){let{t:T}=_(),E=v(),D=p(),O=u(!1),k=u(!1),A=u(!1),j=u(null),M=u([]);N();async function N(){k.value=!0;try{let[e,t]=await Promise.all([y.getDrivers(),g.getMailConfig()]);M.value=e,j.value=t,A.value=t.use_custom_mail_config===`YES`}catch(e){let t=h(e);D.showNotification({type:`error`,message:m(t.message)??t.message})}finally{k.value=!1}}o(A,async(e,t)=>{if(t!==void 0&&!e){O.value=!0;try{await g.saveMailConfig({use_custom_mail_config:`NO`}),j.value&&(j.value.use_custom_mail_config=`NO`),D.showNotification({type:`success`,message:`settings.mail.company_mail_config_updated`})}catch(e){let t=h(e);D.showNotification({type:`error`,message:m(t.message)??t.message}),A.value=!0}finally{O.value=!1}}});async function P(e){try{O.value=!0,await g.saveMailConfig({...e,use_custom_mail_config:`YES`}),j.value&&={...j.value,...e,use_custom_mail_config:`YES`},D.showNotification({type:`success`,message:`settings.mail.company_mail_config_updated`})}catch(e){let t=h(e);D.showNotification({type:`error`,message:m(t.message)??t.message})}finally{O.value=!1}}function F(){E.openModal({title:T(`general.test_mail_conf`),componentName:`MailTestModal`,size:`sm`})}return(t,o)=>{let u=a(`BaseSwitchSection`),p=a(`BaseButton`),m=a(`BaseIcon`),h=a(`BaseSettingCard`);return i(),c(l,null,[d(b,{"store-type":`company`}),d(h,{title:t.$t(`settings.mail.company_mail_config`),description:t.$t(`settings.mail.company_mail_config_desc`)},{default:r(()=>[s(`div`,S,[d(u,{modelValue:A.value,"onUpdate:modelValue":o[0]||=e=>A.value=e,title:t.$t(`settings.mail.use_custom_mail_config`),description:t.$t(`settings.mail.use_custom_mail_config_desc`)},null,8,[`modelValue`,`title`,`description`])]),A.value&&j.value?(i(),c(`div`,C,[d(x,{"config-data":j.value,"is-saving":O.value,"mail-drivers":M.value,"is-fetching-initial-data":k.value,onSubmitData:P},{default:r(()=>[d(p,{variant:`primary-outline`,type:`button`,class:`ml-2`,"content-loading":k.value,onClick:F},{default:r(()=>[e(n(t.$t(`general.test_mail_conf`)),1)]),_:1},8,[`content-loading`])]),_:1},8,[`config-data`,`is-saving`,`mail-drivers`,`is-fetching-initial-data`])])):f(``,!0),A.value?f(``,!0):(i(),c(`div`,w,[d(m,{name:`CheckCircleIcon`,class:`w-5 h-5 mr-2 shrink-0`}),e(` `+n(t.$t(`settings.mail.using_global_mail_config`)),1)]))]),_:1},8,[`title`,`description`])],64)}}});export{T as default};