var y=Object.defineProperty;var n=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var v=(e,t,s)=>t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,u=(e,t)=>{for(var s in t||(t={}))k.call(t,s)&&v(e,s,t[s]);if(n)for(var s of n(t))_.call(t,s)&&v(e,s,t[s]);return e};import{h as I,j as l,L}from"./main-406.js";import{k as w,_ as r,l as S,m as M,L as $}from"./bi.394.85.js";import{h as F,a as g,d as q}from"./bi.968.816.js";import{g as R,a as N}from"./bi.567.825.js";import{T as V}from"./bi.704.707.js";function T({i:e,field:t,formFields:s,moosendConf:i,setMoosendConf:m}){var d;const b=I(w),{isPro:h}=b,p=(i==null?void 0:i.moosendFields.filter(a=>a.required===!0))||[],c=(i==null?void 0:i.moosendFields.filter(a=>a.required===!1))||[];return l.jsx("div",{className:"flx mt-2 mb-2 btcbi-field-map",children:l.jsxs("div",{className:"pos-rel flx",children:[l.jsxs("div",{className:"flx integ-fld-wrp",children:[l.jsxs("select",{className:"btcd-paper-inp mr-2",name:"formFields",onChange:a=>{F(a,e,i,m)},value:t.formFields||"",children:[l.jsx("option",{value:"",children:r("Select Field")}),l.jsx("optgroup",{label:"Form Fields",children:s==null?void 0:s.map(a=>l.jsx("option",{value:a.name,children:a.label},`ff-rm-${a.name}`))}),l.jsx("option",{value:"custom",children:r("Custom...")}),l.jsx("optgroup",{label:`General Smart Codes ${h?"":"(PRO)"}`,children:h&&((d=S)==null?void 0:d.map(a=>l.jsx("option",{value:a.name,children:a.label},`ff-rm-${a.name}`)))})]}),t.formField==="custom"&&l.jsx(V,{onChange:a=>M(a,e,i,m),label:r("Custom Value","bit-integrations"),className:"mr-2",type:"text",value:t.customValue,placeholder:r("Custom Value","bit-integrations"),formFields:s}),l.jsxs("select",{className:"btcd-paper-inp",disabled:e<p.length,name:"moosendFormFields",onChange:a=>{F(a,e,i,m)},value:e<p.length?p[e].key||"":t.moosendFormFields||"",children:[l.jsx("option",{value:"",children:r("Select Field")}),e<p.length?l.jsx("option",{value:p[e].key,children:p[e].label},p[e].key):c.map(({key:a,label:x})=>l.jsx("option",{value:a,children:x},a))]})]}),(i==null?void 0:i.method)==="1"&&l.jsxs(l.Fragment,{children:[l.jsx("button",{onClick:()=>g(e,i,m),className:"icn-btn sh-sm ml-2 mr-1",type:"button",children:"+"}),l.jsx("button",{onClick:()=>q(e,i,m),className:"icn-btn sh-sm ml-1",type:"button","aria-label":"btn",children:l.jsx("span",{className:"btcd-icn icn-trash-2"})})]})]})})}function G({moosendConf:e,setMoosendConf:t,formFields:s,loading:i,setLoading:m}){var p;const b=[{key:"1",name:"Subscribe"},{key:"0",name:"Unsubscribe"},{key:"2",name:"Unsubscribe from list"}],h=c=>{let d;const a=u({},e),{name:x,value:j}=c.target;switch(j!==""?a[x]=j:delete a[x],x){case"listId":a.field_map=[{formFields:"",moosendFormFields:""}],d=N(a),a.field_map=d;break;case"method":a.listId="",a.field_map=[{formFields:"",moosendFormFields:""}],d=N(a),a.field_map=d;break}t(u({},a))};return l.jsxs("div",{className:"mt-2",children:[!i.page&&l.jsxs("div",{className:"flx mt-2",children:[l.jsx("b",{className:"wdt-200 d-in-b ",children:r("Method:")}),l.jsxs("select",{onChange:h,name:"method",value:e==null?void 0:e.method,className:"btcd-paper-inp w-5 mx-0",children:[l.jsx("option",{value:"",children:r("Select Method")}),b.map(c=>l.jsx("option",{value:c.key,children:c.name},c.key))]})]}),e.method&&e.method!=="0"&&l.jsxs("div",{className:"flx mt-2",children:[l.jsx("b",{className:"wdt-200 d-in-b ",children:r("List:")}),l.jsxs("select",{onChange:h,name:"listId",value:e==null?void 0:e.listId,className:"btcd-paper-inp w-5 mx-0",children:[l.jsx("option",{value:"",children:r("Select List")}),((p=e==null?void 0:e.default)==null?void 0:p.lists)&&e.default.lists.map(c=>l.jsx("option",{value:c.ID,children:c.Name},c.ID))]}),l.jsx("button",{onClick:()=>R(e,t,i,m),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh list"'},type:"button",disabled:i.list,children:"↻"}),i.list&&l.jsx($,{size:"20",clr:"#022217",className:"ml-2"})]}),(e==null?void 0:e.method)&&l.jsxs("div",{className:"mt-5",children:[l.jsx("b",{className:"wdt-100",children:r("Field Map")}),l.jsx("div",{className:"btcd-hr mt-2 mb-4"}),l.jsxs("div",{className:"flx flx-around mt-2 mb-2 btcbi-field-map-label",children:[l.jsx("div",{className:"txt-dp",children:l.jsx("b",{children:r("Form Fields")})}),l.jsx("div",{className:"txt-dp",children:l.jsx("b",{children:r("Moosend Fields")})})]}),e==null?void 0:e.field_map.map((c,d)=>l.jsx(T,{i:d,field:c,formFields:s,moosendConf:e,setMoosendConf:t},`ko-m-${d+8}`)),(e==null?void 0:e.method)==="1"&&l.jsx("div",{className:"txt-center btcbi-field-map-button mt-2",children:l.jsx("button",{onClick:()=>g(e.field_map.length,e,t),className:"icn-btn sh-sm",type:"button",children:"+"})})]}),i.page&&l.jsx(L,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:100,transform:"scale(0.7)"}})]})}export{G as M};
