var I=Object.defineProperty;var _=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var y=(a,r,l)=>r in a?I(a,r,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[r]=l,o=(a,r)=>{for(var l in r||(r={}))M.call(r,l)&&y(a,l,r[l]);if(_)for(var l of _(r))k.call(r,l)&&y(a,l,r[l]);return a};import{k as w,f as S,j as e,_ as d,s as T}from"./main.2.8.10.js";import{a as L,h as U,b as V}from"./Integrations.BFhED4ck.js";import{a as q}from"./Table.DSsAy4VI.js";import{T as $}from"./TagifyInput.C4ilRm4k.js";const D=(a,r,l,i)=>{const m=o({},r);m.name=a.target.value,l(o({},m))},H=a=>!((a!=null&&a.field_map?a.field_map.filter(l=>!l.formField||!l.getgistFormField||!l.formField==="custom"&&!l.customValue):[]).length>0),R=a=>{const r=a==null?void 0:a.gistFields.filter(l=>l.required===!0);return r.length>0?r.map(l=>({formField:"",getgistFormField:l.key})):[{formField:"",getgistFormField:""}]};function E({i:a,formFields:r,field:l,getgistConf:i,setGetgistConf:m}){var u,c,N;const v=w(S),{isPro:h}=v;if(((u=i==null?void 0:i.field_map)==null?void 0:u.length)===1&&(l==null?void 0:l.getgistFormField)===""){const s=o({},i),t=R(s);s.field_map=t,m(s)}const x=s=>{const t=o({},i);t.field_map.splice(s,0,{}),m(t)},j=s=>{const t=o({},i);t.field_map.length>1&&t.field_map.splice(s,1),m(t)},b=(s,t)=>{const F=o({},i);F.field_map[t][s.target.name]=s.target.value,s.target.value==="custom"&&(F.field_map[t].customValue=""),m(F)},n=(i==null?void 0:i.gistFields.filter(s=>s.required===!0))||[],p=(i==null?void 0:i.gistFields.filter(s=>s.required===!1))||[];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:l.formField||"",onChange:s=>b(s,a),children:[e.jsx("option",{value:"",children:d("Select Field","bit-integrations")}),e.jsx("optgroup",{label:d("Form Fields","bit-integrations"),children:r.map(s=>s.type!=="file"&&e.jsx("option",{value:s.name,children:s.label},`ff-getgist-${s.name}`))}),e.jsx("option",{value:"custom",children:d("Custom...","bit-integrations")}),e.jsx("optgroup",{label:T(d("General Smart Codes %s","bit-integrations"),h?"":`(${d("Pro","bit-integrations")})`),children:h&&((c=L)==null?void 0:c.map(s=>e.jsx("option",{value:s.name,children:s.label},`ff-rm-${s.name}`)))})]}),l.formField==="custom"&&e.jsx($,{onChange:s=>U(s,a,i,m),label:d("Custom Value","bit-integrations"),className:"mr-2",type:"text",value:l.customValue,placeholder:d("Custom Value","bit-integrations"),formFields:r}),e.jsxs("select",{className:"btcd-paper-inp",disabled:a<n.length,name:"getgistFormField",value:a<n.length?((N=n[a])==null?void 0:N.key)||"":l.getgistFormField||"",onChange:s=>b(s,a),children:[e.jsx("option",{value:"",children:d("Select Field","bit-integrations")}),a<n.length?e.jsx("option",{value:n[a].key,children:n[a].label},n[a].key):p.map(({key:s,label:t})=>e.jsx("option",{value:s,children:t},s))]})]}),a>=(n==null?void 0:n.length)&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>x(a),className:"icn-btn sh-sm ml-2",type:"button",children:"+"}),e.jsx("button",{onClick:()=>j(a),className:"icn-btn sh-sm ml-2",type:"button","aria-label":"btn",children:e.jsx(q,{})})]})]})})}function J({formFields:a,getgistConf:r,setGetgistConf:l,isLoading:i,setIsLoading:m,error:v,setError:h}){const x=[{key:"User",label:"User"},{key:"Lead",label:"Lead"}],j=()=>Math.floor((1+Math.random())*4294967296).toString(16).substring(1),b=n=>{const{name:p,value:u}=n.target,c=o({},r);c[p]=u,u==="User"?u==="User"&&(c.userId=j()):c!=null&&c.userId&&delete c.userId,l(o({},c))};return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("b",{className:"wdt-200 d-in-b",children:d("User Type:","bit-integrations")}),e.jsxs("select",{onChange:b,name:"user_type",value:r==null?void 0:r.user_type,className:"btcd-paper-inp w-5",children:[e.jsx("option",{value:"",children:d("Select User Type","bit-integrations")}),x.map(({key:n,label:p})=>e.jsx("option",{value:n,children:p},n))]}),e.jsx("div",{className:"mt-4",children:e.jsx("b",{className:"wdt-100",children:d("Map Fields","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:d("Form Fields","bit-integrations")})}),e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:d("Gist Fields","bit-integrations")})})]}),r==null?void 0:r.field_map.map((n,p)=>e.jsx(E,{i:p,field:n,getgistConf:r,formFields:a,setGetgistConf:l},`getgist-m-${p+9}`)),e.jsx("div",{className:"txt-center btcbi-field-map-button mt-2",children:e.jsx("button",{onClick:()=>V(r.field_map.length,r,l),className:"icn-btn sh-sm",type:"button",children:"+"})}),e.jsx("br",{}),e.jsx("br",{})]})}export{J as G,H as c,D as h};
