var F=Object.defineProperty;var x=Object.getOwnPropertySymbols;var v=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var g=(s,d,t)=>d in s?F(s,d,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[d]=t,c=(s,d)=>{for(var t in d||(d={}))v.call(d,t)&&g(s,t,d[t]);if(x)for(var t of x(d))_.call(d,t)&&g(s,t,d[t]);return s};import{k as w,f as y,j as e,_ as l,s as k}from"./main.2.9.0.js";import"./react-router.DMwpH23k.js";import{u as M}from"./CopyIcn.CEA_lFLo.js";import{g as S,a as V}from"./ElasticEmailCommonFunc.CdVhlC2W.js";import{a as $,h as q}from"./Integrations.DL8wqGct.js";import{T as L}from"./TagifyInput.KPPRQJ1B.js";const N=(s,d,t)=>{const n=c({},d);n.field_map.splice(s,0,{}),t(c({},n))},R=(s,d,t)=>{const n=c({},d);n.field_map.length>1&&n.field_map.splice(s,1),t(c({},n))},j=(s,d,t,n)=>{const a=c({},t);a.field_map[d][s.target.name]=s.target.value,s.target.value==="custom"&&(a.field_map[d].customValue=""),n(c({},a))};function I({i:s,formFields:d,field:t,elasticEmailConf:n,setElasticEmailConf:a}){var i,b;if(((i=n==null?void 0:n.field_map)==null?void 0:i.length)===1&&t.elasticEmailField===""){const r=c({},n),h=S(r);r.field_map=h,a(r)}const p=(n==null?void 0:n.elasticEmailFields.filter(r=>r.required===!0))||[],m=(n==null?void 0:n.elasticEmailFields.filter(r=>r.required===!1))||[],u=w(y),{isPro:o}=u;return e.jsx("div",{className:"flx mt-2 mb-2 btcbi-field-map",children:e.jsxs("div",{className:"pos-rel flx",children:[e.jsxs("div",{className:"flx integ-fld-wrp",children:[e.jsxs("select",{className:"btcd-paper-inp mr-2",name:"formField",value:t.formField||"",onChange:r=>j(r,s,n,a),children:[e.jsx("option",{value:"",children:l("Select Field","bit-integrations")}),e.jsx("optgroup",{label:l("Form Fields","bit-integrations"),children:d==null?void 0:d.map(r=>e.jsx("option",{value:r.name,children:r.label},`ff-rm-${r.name}`))}),e.jsx("option",{value:"custom",children:l("Custom...","bit-integrations")}),e.jsx("optgroup",{label:k(l("General Smart Codes %s","bit-integrations"),o?"":`(${l("Pro","bit-integrations")})`),children:o&&((b=$)==null?void 0:b.map(r=>e.jsx("option",{value:r.name,children:r.label},`ff-rm-${r.name}`)))})]}),t.formField==="custom"&&e.jsx(L,{onChange:r=>q(r,s,n,a),label:l("Custom Value","bit-integrations"),className:"mr-2",type:"text",value:t.customValue,placeholder:l("Custom Value","bit-integrations"),formFields:d}),e.jsxs("select",{className:"btcd-paper-inp",disabled:s<p.length,name:"elasticEmailField",value:s<p.length?p[s].label||"":t.elasticEmailField||"",onChange:r=>j(r,s,n,a),children:[e.jsx("option",{value:"",children:l("Select Field","bit-integrations")}),s<p.length?e.jsx("option",{value:p[s].key,children:p[s].label},p[s].key):m.map(({key:r,label:h})=>e.jsx("option",{value:r,children:h},r))]})]}),s>=p.length&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>N(s,n,a),className:"icn-btn sh-sm ml-2 mr-1",type:"button",children:"+"}),e.jsx("button",{onClick:()=>R(s,n,a),className:"icn-btn sh-sm ml-1",type:"button","aria-label":"btn",children:e.jsx("span",{className:"btcd-icn icn-trash-2"})})]})]})})}function H({formFields:s,handleInput:d,elasticEmailConf:t,setElasticEmailConf:n,isLoading:a,setIsLoading:p,setSnackbar:m}){var o;const u=i=>{const b=c({},t);b.list_id=i?i.split(","):[],n(c({},b))};return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsxs("div",{className:"flx",children:[e.jsx("b",{className:"wdt-200 d-in-b",children:l("Lists:","bit-integrations")}),e.jsx(M,{defaultValue:t.list_id,className:"btcd-paper-drpdwn w-5",options:((o=t==null?void 0:t.default)==null?void 0:o.lists)&&t.default.lists.map(i=>({label:i.listName,value:i.listName.toString()})),onChange:i=>u(i)}),e.jsx("button",{onClick:()=>V(t,n,p),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${l("Fetch All Recipients","bit-integrations")}'`},type:"button",disabled:a,children:"↻"})]}),e.jsx("br",{}),e.jsx("div",{className:"mt-5",children:e.jsx("b",{className:"wdt-100",children:l("Field Map","bit-integrations")})}),e.jsx("div",{className:"btcd-hr mt-1"}),e.jsxs("div",{className:"flx flx-around mt-2 mb-2 btcbi-field-map-label",children:[e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:l("Form Fields","bit-integrations")})}),e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:l("Elastic Email Fields","bit-integrations")})})]}),t.list_id&&(t==null?void 0:t.field_map.map((i,b)=>e.jsx(I,{i:b,field:i,elasticEmailConf:t,formFields:s,setElasticEmailConf:n,setSnackbar:m},`rp-m-${b+9}`))),e.jsx("div",{className:"txt-center btcbi-field-map-button mt-2",children:e.jsx("button",{onClick:()=>N(t.field_map.length,t,n),className:"icn-btn sh-sm",type:"button",children:"+"})}),e.jsx("br",{}),e.jsx("br",{})]})}export{H as E};
