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