var S=Object.defineProperty;var T=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var P=(t,r,i)=>r in t?S(t,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[r]=i,w=(t,r)=>{for(var i in r||(r={}))z.call(r,i)&&P(t,i,r[i]);if(T)for(var i of T(r))V.call(r,i)&&P(t,i,r[i]);return t};import{r as A,j as e,T as g,_ as s,n as y,o as F,u as q,y as L,$ as B}from"./main-162.js";import{h as R,c as E,d as Z,e as G}from"./bf-230-72.js";import{u as H}from"./bf-582-127.js";import{r as $,a as f,b as J,d as K,e as Q}from"./bf-336-342.js";import{S as U}from"./bf-361-122.js";import{M as W}from"./bf-527-130.js";function X({deskConf:t,setDeskConf:r,formID:i,formFields:l,setSnackbar:n}){var o,c,M,O,_,I;const[m,d]=A.useState(!1),[p,u]=A.useState({show:!1}),x=(a,j)=>{const v=w({},t);j==="ticket_owner"?a!==""?v.actions.ticket_owner=a:delete v.actions.ticket_owner:j==="product"?a!==""?v.actions.product=a:delete v.actions.product:j==="attachments"&&(a!==""?v.actions.attachments=a:delete v.actions.attachments),r(w({},v))},b=()=>{var a,j;(j=(a=t.default)==null?void 0:a.owners)!=null&&j[t.orgId]||$(i,t,r,d,n),u({show:"ticket_owner"})},N=()=>{var a,j;(j=(a=t.default)==null?void 0:a.products)!=null&&j[t.department]||f(i,t,r,d,n),u({show:"product"})},h=()=>{u({show:!1})};return e.jsxs("div",{className:"pos-rel",children:[e.jsxs("div",{className:"d-flx flx-wrp",children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx(g,{onChange:b,checked:"ticket_owner"in t.actions,className:"wdt-200 mt-4 mr-2",value:"Ticket_Owner",title:s("Ticket Owner"),subTitle:s("Add a owner to ticket pushed to Zoho Desk.")}),!t.actions.ticket_owner&&e.jsx("small",{style:{marginLeft:30,marginTop:10,color:"red"},children:s("ticket owner is required")})]}),e.jsx(g,{onChange:N,checked:"product"in t.actions,className:"wdt-200 mt-4 mr-2",value:"Product_Name",title:s("Product Name"),subTitle:s("Add a product to ticket pushed to Zoho Desk.")}),e.jsx(g,{onChange:()=>u({show:"attachments"}),checked:"attachments"in t.actions,className:"wdt-200 mt-4 mr-2",value:"Attachment",title:s("Attachments"),subTitle:s("Add attachments from BitForm to ticket pushed to Zoho Desk.")})]}),e.jsxs(y,{className:"custom-conf-mdl",mainMdlCls:"o-v",btnClass:"blue",btnTxt:s("Ok"),show:p.show==="ticket_owner",close:h,action:h,title:s("Ticket Owner"),children:[e.jsx("div",{className:"btcd-hr mt-2"}),m?e.jsx(F,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:45,transform:"scale(0.5)"}}):e.jsxs("div",{className:"flx flx-between mt-2",children:[e.jsxs("select",{value:t.actions.ticket_owner,className:"btcd-paper-inp",onChange:a=>x(a.target.value,"ticket_owner"),children:[e.jsx("option",{value:"",children:s("Select Owner")}),(M=(c=(o=t.default)==null?void 0:o.owners)==null?void 0:c[t.orgId])==null?void 0:M.map(a=>e.jsx("option",{value:a.ownerId,children:a.ownerName},a.ownerId))]}),e.jsx("button",{onClick:()=>$(i,t,r,d,n),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh Ticket Owners"'},type:"button",disabled:m,children:"↻"})]})]}),e.jsxs(y,{className:"custom-conf-mdl",mainMdlCls:"o-v",btnClass:"blue",btnTxt:s("Ok"),show:p.show==="product",close:h,action:h,title:s("Product Name"),children:[e.jsx("div",{className:"btcd-hr mt-2"}),m?e.jsx(F,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:45,transform:"scale(0.5)"}}):e.jsxs("div",{className:"flx flx-between mt-2",children:[e.jsxs("select",{value:t.actions.product,className:"btcd-paper-inp",onChange:a=>x(a.target.value,"product"),children:[e.jsx("option",{value:"",children:s("Select Product")}),(I=(_=(O=t.default)==null?void 0:O.products)==null?void 0:_[t.department])==null?void 0:I.map(a=>e.jsx("option",{value:a.productId,children:a.productName},a.productId))]}),e.jsx("button",{onClick:()=>f(i,t,r,d,n),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh Products"'},type:"button",disabled:m,children:"↻"})]})]}),e.jsxs(y,{className:"custom-conf-mdl",mainMdlCls:"o-v",btnClass:"blue",btnTxt:s("Ok"),show:p.show==="attachments",close:h,action:h,title:s("Select Attachment"),children:[e.jsx("div",{className:"btcd-hr mt-2"}),e.jsx("div",{className:"mt-2",children:s("Select file upload fields")}),e.jsx(H,{defaultValue:t.actions.attachments,className:"mt-2 w-9",onChange:a=>x(a,"attachments"),options:l.filter(a=>a.type==="file-up").map(a=>({label:a.name,value:a.key}))})]})]})}function Y({i:t,formFields:r,field:i,deskConf:l,setDeskConf:n}){var x,b,N,h,o;const{orgId:m}=l,d=i.zohoFormField===""||((x=l.default.fields[m].required)==null?void 0:x.indexOf(i.zohoFormField))===-1,p=q(B),{isPro:u}=p;return e.jsxs("div",{className:"flx mt-2 mr-1",children:[e.jsxs("div",{className:"flx integ-fld-wrp",children:[e.jsxs("select",{className:"btcd-paper-inp mr-2",name:"formField",value:i.formField||"",onChange:c=>R(c,t,l,n),children:[e.jsx("option",{value:"",children:s("Select Field")}),e.jsx("optgroup",{label:"Form Fields",children:r.map(c=>c.type!=="file-up"&&e.jsx("option",{value:c.key,children:c.name},`ff-zhcrm-${c.key}`))}),e.jsx("option",{value:"custom",children:s("Custom...")}),e.jsx("optgroup",{label:`General Smart Codes ${u?"":"(PRO)"}`,children:u&&((b=U)==null?void 0:b.map(c=>e.jsx("option",{value:c.name,children:c.label},`ff-rm-${c.name}`)))})]}),i.formField==="custom"&&e.jsx(W,{onChange:c=>E(c,t,l,n),label:s("Custom Value"),className:"mr-2",type:"text",value:i.customValue,placeholder:s("Custom Value")}),e.jsxs("select",{className:"btcd-paper-inp",name:"zohoFormField",value:i.zohoFormField||"",disabled:!d,onChange:c=>R(c,t,l,n),children:[e.jsx("option",{value:"",children:s("Select Field")}),((o=(h=(N=l.default)==null?void 0:N.fields)==null?void 0:h[m])==null?void 0:o.fields)&&Object.values(l.default.fields[m].fields).map(c=>d?c.required===!1&&e.jsx("option",{value:c.apiName,children:c.displayLabel},c.displayLabel):e.jsx("option",{value:c.apiName,children:c.displayLabel},c.displayLabel))]})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>Z(t,l,n),className:"icn-btn sh-sm ml-2 mr-1",type:"button",children:"+"}),e.jsx("button",{onClick:()=>G(t,l,n),className:"icn-btn sh-sm",type:"button","aria-label":"btn",children:e.jsx(L,{})})]})]})}function ae({formID:t,formFields:r,handleInput:i,deskConf:l,setDeskConf:n,isLoading:m,setisLoading:d,setSnackbar:p}){var u,x,b,N,h;return e.jsxs(e.Fragment,{children:[e.jsx("br",{}),e.jsx("b",{className:"wdt-100 d-in-b",children:s("Portal:")}),e.jsxs("select",{onChange:i,name:"orgId",value:l.orgId,className:"btcd-paper-inp w-7",children:[e.jsx("option",{value:"",children:s("Select Portal")}),((u=l==null?void 0:l.default)==null?void 0:u.organizations)&&Object.values(l.default.organizations).map(o=>e.jsx("option",{value:o.orgId,children:o.portalName},o.orgId))]}),e.jsx("button",{onClick:()=>J(t,l,n,d,p),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${s("Refresh Desk Portals")}'`},type:"button",disabled:m,children:"↻"}),e.jsx("br",{}),e.jsx("br",{}),e.jsx("b",{className:"wdt-100 d-in-b",children:s("Department:")}),e.jsxs("select",{onChange:i,name:"department",value:l.department,className:"btcd-paper-inp w-7",children:[e.jsx("option",{value:"",children:s("Select Department")}),((b=(x=l==null?void 0:l.default)==null?void 0:x.departments)==null?void 0:b[l.orgId])&&Object.values(l.default.departments[l.orgId]).map(o=>e.jsx("option",{value:o.departmentId,children:o.departmentName},o.departmentId))]}),e.jsx("button",{onClick:()=>K(t,l,n,d,p),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${s("Refresh Desk Departments")}'`},type:"button",disabled:m,children:"↻"}),e.jsx("br",{}),e.jsx("br",{}),m&&e.jsx(F,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:100,transform:"scale(0.7)"}}),l.department&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4",children:[e.jsx("b",{className:"wdt-100",children:s("Map Fields")}),e.jsx("button",{onClick:()=>Q(t,l,n,d,p),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${s("Refresh Desk Fields")}'`},type:"button",disabled:m,children:"↻"})]}),e.jsx("div",{className:"btcd-hr mt-1"}),((h=(N=l.default)==null?void 0:N.fields)==null?void 0:h[l==null?void 0:l.orgId])&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flx flx-around mt-2 mb-1",children:[e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:s("Form Fields")})}),e.jsx("div",{className:"txt-dp",children:e.jsx("b",{children:s("Zoho Fields")})})]}),l.field_map.map((o,c)=>e.jsx(Y,{i:c,field:o,deskConf:l,formFields:r,setDeskConf:n},`desk-m-${c+9}`)),e.jsx("div",{className:"txt-center mt-2",style:{marginRight:85},children:e.jsx("button",{onClick:()=>Z(l.field_map.length,l,n),className:"icn-btn sh-sm",type:"button",children:"+"})}),e.jsx("br",{}),e.jsx("br",{}),e.jsx("div",{className:"mt-4",children:e.jsx("b",{className:"wdt-100",children:s("Actions")})}),e.jsx("div",{className:"btcd-hr mt-1"}),e.jsx(X,{deskConf:l,setDeskConf:n,formID:t,formFields:r,setSnackbar:p})]})]})]})}export{ae as Z};