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