var w=Object.defineProperty,L=Object.defineProperties;var M=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var y=(e,l,t)=>l in e?w(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,F=(e,l)=>{for(var t in l||(l={}))S.call(l,t)&&y(e,t,l[t]);if(N)for(var t of N(l))P.call(l,t)&&y(e,t,l[t]);return e},v=(e,l)=>L(e,M(l));var k=(e,l,t)=>new Promise((a,c)=>{var x=b=>{try{m(t.next(b))}catch(p){c(p)}},h=b=>{try{m(t.throw(b))}catch(p){c(p)}},m=b=>b.done?a(b.value):Promise.resolve(b.value).then(x,h);m((t=t.apply(e,l)).next())});import{k as R,g as q,j as s,_ as d,s as T,L as V}from"./main.2.8.1.js";import{z as D,a9 as z}from"./Note.BeM7sN-p.js";import{h as I,b as $,d as A}from"./GlobalIntegrationHelper.CgnhJgll.js";import{g as E,a as G,b as _}from"./NotionCommonFunc.Dv7od-KB.js";import{a as U,h as B}from"./Integrations.D2bgBas2.js";import{T as H}from"./TagifyInput.Cu0YIRbG.js";function J({i:e,field:l,formFields:t,notionConf:a,setNotionConf:c}){var p,r,u,j;const x=R(q),{isPro:h}=x;if(((p=a==null?void 0:a.field_map)==null?void 0:p.length)===1&&l.notionFormFields===""){const i=F({},a),g=E(i);i.field_map=g,c(i)}const m=((r=a==null?void 0:a.notionFields)==null?void 0:r.filter(i=>i.required===!0))||[],b=((u=a==null?void 0:a.notionFields)==null?void 0:u.filter(i=>i.required===!1))||[];return s.jsx("div",{className:"flx mt-2 mb-2 btcbi-field-map",children:s.jsxs("div",{className:"pos-rel flx",children:[s.jsxs("div",{className:"flx integ-fld-wrp",children:[s.jsxs("select",{className:"btcd-paper-inp mr-2",name:"formFields",onChange:i=>{I(i,e,a,c)},value:l.formFields||"",children:[s.jsx("option",{value:"",children:d("Select Field")}),s.jsx("optgroup",{label:d("Form Fields","bit-integrations"),children:t==null?void 0:t.map(i=>s.jsx("option",{value:i.name,children:i.label},`ff-rm-${i.name}`))}),s.jsx("option",{value:"custom",children:d("Custom...")}),s.jsx("optgroup",{label:T(d("General Smart Codes %s","bit-integrations"),h?"":`(${d("Pro","bit-integrations")})`),children:h&&((j=U)==null?void 0:j.map(i=>s.jsx("option",{value:i.name,children:i.label},`ff-rm-${i.name}`)))})]}),l.formFields==="custom"&&s.jsx(H,{onChange:i=>B(i,e,a,c),label:d("Custom Value","bit-integrations"),className:"mr-2",type:"text",value:l.customValue,placeholder:d("Custom Value","bit-integrations"),formFields:t}),s.jsxs("select",{className:"btcd-paper-inp",disabled:e<m.length,name:"notionFormFields",onChange:i=>{I(i,e,a,c)},value:e<m.length?m[e].label||"":l.notionFormFields||"",children:[s.jsx("option",{value:"",children:d("Select Field")}),e<m.length?s.jsx("option",{value:m[e].label,children:m[e].label},m[e].key):b.map(({key:i,label:g})=>s.jsx("option",{value:g,children:g},g))]})]}),s.jsx("button",{onClick:()=>$(e,a,c),className:"icn-btn sh-sm ml-2 mr-1",type:"button",children:"+"}),s.jsx("button",{onClick:()=>A(e,a,c),className:"icn-btn sh-sm ml-1",type:"button","aria-label":"btn",children:s.jsx("span",{className:"btcd-icn icn-trash-2"})})]})})}function n({notionConf:e,setNotionConf:l,formFields:t,loading:a,setLoading:c}){var m,b;const x=p=>k(null,null,function*(){const r=F({},e),{name:u,value:j}=p.target;j!==""?r[u]=j:delete r[u],u==="databaseId"&&(r.databaseId===""&&(r.field_map=[{formFields:"",notionFormFields:""}]),r.databaseId&&(c(v(F({},a),{field:!0})),r.notionFields=yield _(r,l),r.notionFields&&c(v(F({},a),{field:!1})))),l(r)}),h=`
    <b>${d("Files & Media","bit-integrations")}</b>
    <p>${d("The Notion API does not yet support uploading files to Notion.","bit-integrations")}</p>
    <p>${d("Please Provide a public URL of the file instead of file attachment.","bit-integrations")}</p>
  `;return s.jsxs("div",{className:"mt-2",children:[!a.page&&((m=e==null?void 0:e.default)==null?void 0:m.databaseLists)&&s.jsxs("div",{className:"flx mt-2",children:[s.jsx("b",{className:"wdt-200 d-in-b ",children:d("Database List:","bit-integrations")}),s.jsxs("select",{onChange:x,name:"databaseId",value:e==null?void 0:e.databaseId,className:"btcd-paper-inp w-5 mx-0",children:[s.jsx("option",{value:"",children:d("Select Database","bit-integrations")}),((b=e==null?void 0:e.default)==null?void 0:b.databaseLists)&&(e==null?void 0:e.default.databaseLists.map(p=>s.jsx("option",{value:p.id,children:p.name},p.id)))]}),s.jsx("button",{onClick:()=>G(e,l,a,c),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":'"Refresh list"'},type:"button",disabled:a.list,children:"↻"}),a.list&&s.jsx(D,{size:"20",clr:"#022217",className:"ml-2"})]}),(e==null?void 0:e.databaseId)&&s.jsxs("div",{className:"mt-5",children:[s.jsx("b",{className:"wdt-100",children:d("Field Map","bit-integrations")}),s.jsx("button",{onClick:()=>_(e,l,a,c),className:"icn-btn sh-sm ml-2 mr-2 tooltip",style:{"--tooltip-txt":`'${d("Refresh custom fields","bit-integrations")}'`},type:"button",disabled:a.field,children:"↻"}),s.jsx("div",{className:"btcd-hr mt-2 mb-4"}),s.jsxs("div",{className:"flx flx-around mt-2 mb-2 btcbi-field-map-label",children:[s.jsx("div",{className:"txt-dp",children:s.jsx("b",{children:d("Form Fields","bit-integrations")})}),s.jsx("div",{className:"txt-dp",children:s.jsx("b",{children:d("Notion Fields","bit-integrations")})})]}),e==null?void 0:e.field_map.map((p,r)=>s.jsx(J,{i:r,field:p,formFields:t,notionConf:e,setNotionConf:l},`ko-m-${r+8}`)),s.jsx("div",{className:"txt-center btcbi-field-map-button mt-2",children:s.jsx("button",{onClick:()=>$(e.field_map.length,e,l),className:"icn-btn sh-sm",type:"button",children:"+"})})]}),(a.page||a.field)&&s.jsx(V,{style:{display:"flex",justifyContent:"center",alignItems:"center",height:100,transform:"scale(0.7)"}}),s.jsx(z,{note:h})]})}export{n as N};
