import{_ as u,r as h,o as f,c as m,a as s,n as i,t as l,w as d,b as g,d as p,e as M}from"./config-98DzVabT.js";import{M as _}from"./Modal-tRvZdQEx.js";const C={name:"IntegrationConnect",components:{Modal:_},props:{connected:{type:Boolean}},data(){return{statusText:"",showModal:!1,error:!1,errorMessage:"",loading:!1}},computed:{statusClass(){return this.statusText==="Error"?"off":this.statusText==="Connected"?"on":""}},created(){this.statusText=this.connected?"Connected":"Not connected"},methods:{getFormInputs(){let t=[],e=document.getElementById("main-form");return e||(e=document.getElementById("main")),e&&(t=e.querySelectorAll("input, select, textarea")),t},serializeForm(){const t={};return this.getFormInputs().forEach(e=>{const n=e.getAttribute("name");t[n]=e.value}),t},refresh(){this.showModal=!1,this.error=!1,this.errorMessage="",this.loading=!0,this.statusText="Connecting...";const t=this.serializeForm();Craft.sendActionRequest("POST","formie/integrations/check-connection",{data:t}).then(e=>{if(this.loading=!1,e.data.message){this.error=!0,this.showModal=!0,this.errorMessage=Craft.t("formie","An error occurred."),this.errorMessage+=`<br><br><code>${e.data.message}</code>`,this.statusText="Error";return}this.statusText="Connected"}).catch(e=>{this.loading=!1,this.error=!0,this.showModal=!0,this.errorMessage=e,e.response.data.message&&(this.errorMessage+=`<br><br><code>${e.response.data.message}</code>`),this.statusText="Error"})},closeModal(){this.showModal=!1}}},w={class:"field lightswitch-field"},v={class:"heading"},T={class:"input ltr"},b=["title"],x={class:"fui-error-pane error"},y={class:"fui-error-content"},E=s("span",{"data-icon":"alert"},null,-1),k=["innerHTML"];function B(t,e,n,A,r,o){const c=h("modal");return f(),m("div",w,[s("div",v,[s("span",{class:i(["status",o.statusClass])},null,2),s("span",null,l(t.t("formie",r.statusText)),1)]),s("div",T,[s("button",{class:i(["btn small",{"fui-loading fui-loading-tiny":r.loading}]),title:t.t("formie","Refresh"),onClick:e[0]||(e[0]=d((...a)=>o.refresh&&o.refresh(...a),["prevent"]))},l(t.t("formie","Refresh")),11,b),g(c,{ref:"modal",modelValue:r.showModal,"onUpdate:modelValue":e[2]||(e[2]=a=>r.showModal=a),"show-header":!1,"show-footer":!1,"modal-class":"fui-integration-error-modal",onClickOutside:o.closeModal},{body:p(()=>[s("button",{class:"fui-dialog-close",onClick:e[1]||(e[1]=d((...a)=>o.closeModal&&o.closeModal(...a),["prevent"]))}),s("div",x,[s("div",y,[E,s("span",{class:"error",innerHTML:r.errorMessage},null,8,k)])])]),_:1},8,["modelValue","onClickOutside"])])])}const I=u(C,[["render",B]]),V=M({delimiters:["${","}"],components:{IntegrationConnect:I}});V.mount(".fui-integrations-settings #details .meta");$(document).ready(()=>{document.dispatchEvent(new CustomEvent("vite-script-loaded",{detail:{path:"src/js/formie-integration-settings.js"}}))});
//# sourceMappingURL=formie-integration-settings-4-LlGzv4.js.map
