@arudovwen/form-builder-react 1.4.49 → 1.4.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6963,7 +6963,7 @@ const Vs = an(Hs), Fs = B.object({
6963
6963
  "div",
6964
6964
  {
6965
6965
  ref: v,
6966
- className: "bg-white group cursor-pointer rounded-lg max-h-[600px] overflow-y-auto shadow-[rgba(149,157,165,0.2)_0px_2px_2px] transition-colors duration-200",
6966
+ className: "bg-white group cursor-pointer rounded-lg shadow-[rgba(149,157,165,0.2)_0px_2px_2px] transition-colors duration-200",
6967
6967
  children: /* @__PURE__ */ n.jsxs(
6968
6968
  "div",
6969
6969
  {
@@ -7026,7 +7026,7 @@ const Vs = an(Hs), Fs = B.object({
7026
7026
  onClick: () => s(i.id),
7027
7027
  children: [
7028
7028
  /* @__PURE__ */ n.jsx("hr", { className: "group-last:hidden" }),
7029
- /* @__PURE__ */ n.jsx("div", { className: "h-full mt-4 gap-y-6", children: /* @__PURE__ */ n.jsx(
7029
+ /* @__PURE__ */ n.jsx("div", { className: "h-full mt-4 gap-y-6 max-h-[600px] overflow-y-auto", children: /* @__PURE__ */ n.jsx(
7030
7030
  Vs,
7031
7031
  {
7032
7032
  elementData: i.questionData,
@@ -53,8 +53,8 @@ React keys must be passed directly to JSX without using spread:
53
53
  "data": [
54
54
  { "name": "Document Name", "id": "documentMainId", ...restObject },
55
55
  ]
56
- }`})})]})})}),wa=()=>i.jsx("blockquote",{className:"p-4 text-gray-700 bg-gray-100 rounded-md",children:i.jsxs("ul",{children:[i.jsxs("li",{className:"text-xs",children:["Method: GET ",i.jsx("br",{}),"URL format:"," ",i.jsx("code",{children:"https://example.com/validation/{documentId}"})]}),i.jsxs("li",{className:"text-xs",children:[i.jsx("span",{className:"block mb-1",children:" Response example format:"}),i.jsx("pre",{className:"p-2 bg-white rounded-md",children:i.jsxs("code",{children:["{ ",i.jsx("br",{}),'  "data": { ',i.jsx("br",{}),'    "status": true, ',i.jsx("br",{}),'    "isSigned": true ',i.jsx("br",{}),"  } ",i.jsx("br",{}),"}"]})})]})]})});function ka(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const vi=["text","number","boolean"],bn=["equals","not_equals","contains","not_contains"],Aa=["greater","less"];function Sa({register:e,setValue:n,trigger:o,watch:s,id:a}){const{formData:t}=m.useContext(ve),d=s("visibilityDependentFields")||[],r=m.useMemo(()=>{var c;return(c=ka(t).filter(u=>u.id!==a))==null?void 0:c.map(u=>{const p=d.find(v=>v.id===u.id);return{id:u.id,value:u.id,label:u.inputLabel,sectionId:u.sectionId,fieldType:(p==null?void 0:p.fieldType)||"text",operator:(p==null?void 0:p.operator)||"equals",fieldValue:(p==null?void 0:p.fieldValue)!==void 0?p.fieldValue:""}})},[t,d,a]),l=(c,u,p)=>{const v=d==null?void 0:d.map((f,w)=>w===c?{...f,[u]:p}:f);n("visibilityDependentFields",v)};return i.jsxs("div",{className:"visibility-editor",children:[i.jsx("label",{className:"label",children:"Select Dependent Fields"}),i.jsx(ui,{element:{options:r,id:"visibilityDependentFields",value:s("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:o,watch:s}}),d.length>0&&i.jsx("div",{className:"py-1 bg-gray-100 rounded dependent-fields",children:d==null?void 0:d.map((c,u)=>{var p,v;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:c.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.fieldType,onChange:f=>l(u,"fieldType",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldType}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:vi==null?void 0:vi.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f},f))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.operator,onChange:f=>l(u,"operator",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.operator.replace("_"," ")}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(p=c.fieldType==="number"?[...bn,...Aa]:bn)==null?void 0:p.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f.replace("_"," ")},f))})})]})})}),c.fieldType!=="boolean"?i.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:f=>l(u,"fieldValue",f.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(z.Listbox,{value:(v=c.fieldValue)!=null?v:"",onChange:f=>l(u,"fieldValue",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(z.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(z.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},c.id)})})]})}const Na=M.object().shape({inputLabel:M.string().nullable(),placeholder:M.string().nullable(),description:M.string().nullable(),isReadOnly:M.boolean(),isDisabled:M.boolean(),isRequired:M.boolean(),requiredMessage:M.string().nullable(),minLengthMessage:M.string().nullable(),maxLengthMessage:M.string().nullable(),maxLength:M.number().typeError("Expecting a number").nullable(),minLength:M.number().typeError("Expecting a number").nullable(),inputType:M.string().nullable(),maxAmountMessage:M.string().nullable(),maxAmount:M.string().nullable(),options:M.array().of(M.object().shape({label:M.string().nullable(),value:M.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),options1:M.array().of(M.object().shape({label:M.string().nullable(),value:M.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),prefix:M.string().nullable(),url:M.string().nullable(),method:M.string().nullable(),denominators:M.mixed().nullable(),responseType:M.string().nullable(),minAmount:M.string().nullable(),heading:M.string().nullable(),minAmountMessage:M.string().nullable(),columns:M.number().nullable().max(4).min(2),value:M.mixed().nullable(),customClass:M.string().nullable(),elementClass:M.string().nullable(),apiUrl:M.string().nullable(),selectType:M.string().default("list"),dateType:M.string().default("basic"),validationUrl:M.string(),signatureLink:M.string(),minDate:M.string().nullable(),maxDate:M.string().nullable(),canHaveDateRange:M.boolean(),allowYearPicker:M.boolean(),isHidden:M.boolean(),visibilityDependentFields:M.array().nullable(),isMultiple:M.boolean(),acceptedFiles:M.array(),showState:M.boolean()}),ja=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],_a=({isOpen:e,onClose:n,element:o})=>{const s=ja.filter(L=>!qe.includes(o.inputType)||L.key!=="validation"),{updateElement:a}=m.useContext(ve),[t,d]=m.useState("basic"),[r,l]=m.useState(!1),[c,u]=m.useState("manual"),p=pe("config"),{register:v,handleSubmit:f,control:w,setValue:x,watch:h,trigger:g,formState:{errors:y,isSubmitting:N,isValid:A},reset:S}=ke.useForm({resolver:mi(Na),defaultValues:{...o,options:o.options||[]}}),k=h(),{fields:j,append:I,remove:X}=ke.useFieldArray({control:w,name:"options"}),{fields:U,append:Z,remove:B}=ke.useFieldArray({control:w,name:"options1"}),{fields:F,append:D,remove:K}=ke.useFieldArray({control:w,name:"dataColumns"});m.useEffect(()=>{e||S()},[e,S]);const G=L=>{a(L,o.sectionId),n()},E={headers:{Authorization:`Bearer ${pe("token")}`}},T=m.useCallback(async()=>{var L,O,Q;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){xe.toast.info("Please provide a valid API URL");return}try{l(!0);const{status:se,data:J}=await _e.get(k.apiUrl,E);if(se!==200||!J){xe.toast.error("Unexpected response from server.");return}const ae=J.data||J.record||J.result;if(!Array.isArray(ae)){xe.toast.error("Expected an array in response (data, record, or result).");return}((L=o.type)==null?void 0:L.toLowerCase())==="datagrid"?x("dataColumns",ae):x("options",ae)}catch(se){const J=((Q=(O=se==null?void 0:se.response)==null?void 0:O.data)==null?void 0:Q.message)||(se==null?void 0:se.message)||"Unable to load options";xe.toast.error(J)}finally{l(!1)}},[o.type,x,k.apiUrl]),V=["manual","api","sheet"];function de(){c==="api"&&T()}const ee=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:V==null?void 0:V.map(L=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:O=>u(O.target.value),value:L})," ",i.jsxs("span",{children:[L," options"]})]},L))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:h,label:"Load Options from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]}),i.jsx("button",{onClick:de,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(fa,{})]}),c==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(mn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:x,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),j==null?void 0:j.map((L,O)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Label":"",name:`options.${O}.label`,register:v,errors:y,element:o,placeholder:"Label"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Value":"",name:`options.${O}.value`,register:v,errors:y,element:o,placeholder:"Value"})}),i.jsx("button",{disabled:j.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>X(O),children:i.jsx(W,{icon:"iconamoon:sign-times-fill"})})]},L.id))," ",i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>I({label:"",value:"",id:fe.v4()}),children:[i.jsx(W,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),o.type.toLowerCase()==="cascadeselect"&&i.jsxs(i.Fragment,{children:[i.jsx("hr",{className:"my-5"}),i.jsxs("div",{children:[" ",i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Child Options "}),U==null?void 0:U.map((L,O)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Label",name:`options1.${O}.label`,register:v,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Value",name:`options1.${O}.value`,register:v,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Key",name:`options1.${O}.key`,register:v,errors:y,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:U.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>B(O),children:i.jsx(W,{icon:"iconamoon:sign-times-fill"})})]},L.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>Z({label:"",value:"",key:"",id:fe.v4()}),children:[i.jsx(W,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),oe=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:V==null?void 0:V.map(L=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:O=>u(O.target.value),value:L,checked:L===c})," ",i.jsxs("span",{children:[L," options"]})]},L))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:h,label:"Load Columns from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/columns",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]})," ",i.jsx("button",{onClick:de,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(xa,{})]}),c==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(mn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:x,name:"dataColumns"})}),F==null?void 0:F.map((L,O)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"min-w-[140px]",children:i.jsx(Me,{label:O===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"}],register:v,name:`dataColumns.${O}.type`,setValue:x,trigger:g,value:k.dataColumns[O].type})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Field key":"",name:`dataColumns.${O}.field`,register:v,errors:y,element:o,placeholder:"fieldKey"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Display header":"",name:`dataColumns.${O}.headerName`,register:v,errors:y,element:o,placeholder:"header"})}),i.jsx("button",{disabled:F.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>K(O),children:i.jsx(W,{icon:"iconamoon:sign-times-fill"})})]},L.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>D({headerName:"",field:"",editable:!0,id:fe.v4(),type:"text",validate:!1}),children:[i.jsx(W,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),me=m.useCallback(async()=>{const L=pe("token"),{status:O,data:Q}=await _e.get(k.url,{headers:{Authorization:`Bearer ${L}`}});O===200&&x("options",(Q==null?void 0:Q.data)||Q)},[x,k.url]);m.useEffect(()=>{o.type==="document"&&k.url&&me()},[k.url,o.type,me]);const ce=i.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default",onMouseDown:L=>L.stopPropagation(),onPointerDown:L=>L.stopPropagation(),onDragStart:L=>{L.preventDefault(),L.stopPropagation()},children:i.jsxs("div",{className:"w-full lg:w-2/3 xl:w-2/5 bg-white h-screen shadow-xl relative flex flex-col items-center",children:[i.jsx("button",{className:"bg-white h-10 w-10 flex justify-center items-center absolute top-1 -left-12 rounded-lg hover:bg-gray-50",onClick:n,children:i.jsx(W,{icon:"tabler:x",iconClass:"text-xl"})}),i.jsx("div",{className:"w-full pt-4",children:i.jsx(na,{tabs:s,setActiveTab:d,activeTab:t,className:"justify-start !text-left",btnClass:" !text-left"})}),i.jsxs("form",{onSubmit:f(G),className:"w-full flex-1 flex flex-col",children:[i.jsxs("div",{className:"flex-1",children:[" ",i.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[t==="basic"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[bi.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(H,{watch:h,label:"Value",name:"value",register:v,errors:y,element:o})}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:h,label:"Label",name:"inputLabel",register:v,errors:y,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(H,{watch:h,label:"Child Label",name:"childLabel",register:v,errors:y,element:o})]}),ua.includes(o.inputType)&&i.jsx(H,{watch:h,label:"Placeholder",name:"placeholder",register:v,errors:y,element:o}),da.includes(o.inputType)&&i.jsx(H,{watch:h,label:"Prefix",name:"prefix",register:v,errors:y,element:o}),ba.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(ha,{}),i.jsx(H,{watch:h,label:"Api Url",name:"url",register:v,errors:y,element:o}),i.jsx(Me,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:v,name:"method",setValue:x,trigger:g,value:h("method")}),i.jsx(Me,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:v,name:"responseType",setValue:x,trigger:g,value:h("responseType")})]}),va.includes(o.inputType)&&i.jsx(ga,{onChange:L=>{x("denominators",L)},value:h("denominators")}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsx(H,{watch:h,label:"Short Description",name:"description",register:v,errors:y,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Me,{label:"Date Format",options:la,register:v,name:"dateFormat",setValue:x,trigger:g,value:h("dateFormat")}),i.jsx(H,{watch:h,label:"Allow Range",name:"canHaveDateRange",register:v,errors:y,element:o,type:"checkbox",value:k.canHaveDateRange}),(k==null?void 0:k.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx(Qe,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select min date"}),i.jsx(Qe,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),i.jsx(H,{watch:h,label:"Allow Year Picker",name:"allowYearPicker",register:v,errors:y,element:o,type:"checkbox",value:k.allowYearPicker})]}),o.type.toLowerCase()==="country"&&i.jsx(H,{watch:h,label:"Allow States",name:"showState",register:v,errors:y,element:o,type:"checkbox",value:k.showState}),o.type.toLowerCase()==="selectfield"&&i.jsx(Me,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:v,name:"selectType",setValue:x,trigger:g,value:h("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(H,{watch:h,label:"Number of columns (max: 4)",name:"columns",register:v,errors:y,element:o,max:4,min:1}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:h,label:"Document Options Url",name:"url",register:v,errors:y,element:o})," ",i.jsx(ya,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:h,label:"Document Validation Url",name:"validationUrl",register:v,errors:y,element:o}),i.jsx(wa,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(H,{watch:h,label:"Signature Page Url",name:"signatureLink",register:v,errors:y,element:o})})]}),o.type.toLowerCase()==="datagrid"&&oe(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:h,label:"Allow Multiple Uploads",name:"isMultiple",register:v,errors:y,element:o,type:"checkbox",value:k.isMultiple}),i.jsx(ui,{element:{options:pa,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:v,setValue:x,trigger:g,watch:h},placeholder:"Choose file types"})]}),ma.includes(o.inputType)&&ee(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(H,{watch:h,label:"Toggle Visibility",name:"isHidden",register:v,errors:y,element:o,type:"checkbox",value:k.isHidden})})," ",k.isHidden&&i.jsx(Sa,{register:v,setValue:x,trigger:g,watch:h,id:o==null?void 0:o.id})]})]}),!qe.includes(o.type.toLowerCase())&&t==="validation"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Required",name:"isRequired",register:v,errors:y,element:o,type:"checkbox",value:k.isRequired})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"requiredMessage",register:v,errors:y,element:o})})]}),ra.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Min Length",name:"minLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"minLengthMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Max Length",name:"maxLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"maxLengthMessage",register:v,errors:y,element:o})})]})]}),ca.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Min Amount",name:"minAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"minAmountMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Max Amount",name:"maxAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"maxAmountMessage",register:v,errors:y,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest editor_option__cancel",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!A||N,style:{background:(p==null?void 0:p.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!A||N?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!A||N?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:N?"Saving...":"Save"})]})]})]})});return document.body?Pn.createPortal(ce,document.body):ce},pi=m.memo(({state:e,element:n,children:o})=>{const[s,a]=m.useState(!1),{removeElement:t,duplicateElement:d}=m.useContext(ve),r=m.useMemo(()=>{var c;return(c=n==null?void 0:n.acceptedFiles)==null?void 0:c.map(u=>u.label).join(", ")},[n]),l=m.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return i.jsxs("div",{className:"w-full",children:[s&&i.jsx(_a,{isOpen:s,onClose:()=>a(!1),element:n}),i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("span",{children:[" ",n.inputLabel&&i.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",r&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",r==null?void 0:r.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[!n.gridPosition&&i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1",onClick:()=>d(n==null?void 0:n.id,n.sectionId),title:"Duplicate",children:i.jsx(W,{icon:"tabler:copy",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:()=>a(!0),title:"Edit",children:i.jsx(W,{icon:"circum:edit",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:l,title:"Remove",children:i.jsx(W,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});pi.displayName="ElementContainer";function Ca({element:e,validationData:n}){const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:d}=n||{};let r;return t&&(r=t()[e.id]),i.jsx(H,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:s,setValue:a,value:r,prefix:e.prefix,disabled:d,watch:t})}function Ma(e){if(!e)return!1;const n=/^data:image\/(jpeg|png|gif|bmp|webp);base64,/i,o=/\.(jpeg|jpg|png|gif|bmp|webp)$/i;return n.test(e)||o.test(e)}const Ea=({imageUrl:e})=>{const[n,o]=m.useState(!1),s=()=>{o(!0)},a=()=>{o(!1)};return i.jsxs("div",{children:[i.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:s,src:e||"/place.png","data-toggle":"tooltip","data-placement":"top",title:"Click to view"}),n&&i.jsx("div",{className:"modal",style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",justifyContent:"center",alignItems:"center"},onClick:a,children:i.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:t=>t.stopPropagation(),children:[i.jsx("span",{className:"close",onClick:a,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),i.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function Ta({element:e,validationData:n}){var k;const{register:o=()=>({}),setValue:s,watch:a}=n||{},[t,d]=m.useState(),[r,l]=m.useState(!1),[c,u]=m.useState(!1),[p,v]=m.useState(""),f=a&&a(e==null?void 0:e.id);m.useEffect(()=>{d(f)},[f]);const[w,x]=m.useState("");m.useEffect(()=>{o(e.id)},[e.id,o]);const{url:h,method:g,responseType:y}=e||{},A={headers:{Authorization:`Bearer ${pe("token")}`}},S=m.useCallback(async j=>{var I,X,U,Z,B,F,D,K,G,P,E;if(!(!h||!g)){l(!0);try{let T;if(g.toLowerCase()==="get"){const V=`${h}?value=${j}`;T=await _e.get(V,A)}else if(g.toLowerCase()==="post")T=await _e.post(h,{value:j},A);else throw new Error("Unsupported HTTP method");T.status===200&&((((X=(I=T==null?void 0:T.data)==null?void 0:I.data)==null?void 0:X.status)||((U=T==null?void 0:T.data)==null?void 0:U.status))===!0?(u(!0),y==="string"?v(((B=(Z=T==null?void 0:T.data)==null?void 0:Z.data)==null?void 0:B.description)||((F=T==null?void 0:T.data)==null?void 0:F.description)||"Validation successful"):x(((K=(D=T==null?void 0:T.data)==null?void 0:D.data)==null?void 0:K.description)||((G=T==null?void 0:T.data)==null?void 0:G.description)||{})):(console.error("Invalid input:",j),v("Unable to validate input"),u(!1)))}catch(T){console.error("Error validating input:",T),v(((E=(P=T==null?void 0:T.response)==null?void 0:P.data)==null?void 0:E.message)||"Unable to validate input"),u(!1)}finally{l(!1)}}},[g,y,h]);return m.useEffect(()=>{if(t){const j=setTimeout(()=>{S(t)},700);return()=>clearTimeout(j)}},[S,t]),i.jsxs("div",{children:[i.jsxs("div",{className:"relative flex items-center",children:[i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:q("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:j=>{d(j.target.value),s(e==null?void 0:e.id,j.target.value)},disabled:n==null?void 0:n.isReadOnly}),i.jsxs("span",{className:"absolute right-0",children:[r&&i.jsxs("span",{children:[" ",i.jsxs("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})]}),c&&!r&&i.jsx("span",{className:"block pr-3 text-lg text-green-600",children:i.jsx(W,{icon:"gg:check-o"})})]})]}),p&&y==="string"&&i.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:p}),y==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(k=Object.entries(w))==null?void 0:k.map(([j,I])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[j,":"]}),Ma(I)?i.jsx(Ea,{imageUrl:I}):i.jsx("span",{children:String(I)})]},j))})]})}function Ba({onGetTotal:e,readOnly:n,defaultValue:o,denominators:s}){const[a,t]=m.useState([...o]);function d(c,u){t(p=>{const v=[...p];return v[u]={...v[u],value:c},v})}function r(c,u){return parseFloat(c)*parseFloat(u)||0}const l=m.useMemo(()=>a.reduce((c,u)=>{const p=r(u.key,u.value);return c+p},0),[a]);return m.useEffect(()=>{e&&e(a)},[a]),m.useEffect(()=>{if(s!=null&&s.length){const c=s==null?void 0:s.map((u,p)=>({key:u.value,value:Array.isArray(o)&&o[p]?o[p].value:""}));t(c)}},[o,s]),i.jsx("div",{className:"mt-2",children:i.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{className:"",children:"Denomination"})}),i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{children:"Quantity"})}),i.jsx("div",{className:"px-4 py-2",children:i.jsx("span",{children:"Sub total"})})]}),a==null?void 0:a.map((c,u)=>{var p,v;return i.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[i.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:i.jsx("span",{className:"",children:(p=parseFloat(c.key))==null?void 0:p.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(Ge,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:f=>d(f,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(v=r(c.key,c.value))==null?void 0:v.toLocaleString()})})]},u+"index")}),i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),i.jsx("div",{className:"px-4 py-3",children:l==null?void 0:l.toLocaleString()})]})]})})}function La({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,getValues:a}=n||{},t=a&&a(e==null?void 0:e.id)||[];return m.useEffect(()=>{o(e.id)},[e.id,o]),i.jsx("div",{children:i.jsx(Ba,{onGetTotal:d=>{s&&s(e.id,d)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:t,readOnly:e==null?void 0:e.isReadOnly})})}function Pa({element:e}){return i.jsx("div",{className:q("py-6",e==null?void 0:e.customClass)})}function Da({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:q("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Ia({element:e,validationData:n}){const{register:o=()=>({})}=n||{};return i.jsx("div",{children:i.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...o(e==null?void 0:e.id)})})}function Oa({element:e,state:n}){return i.jsx(i.Fragment,{children:i.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&i.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function Ka({row:e,columns:n,isReadOnly:o,editingCell:s,setEditingCell:a,handleCellChange:t,debouncedValidate:d,getValidationStatus:r,deleteRow:l}){const c=u=>(s==null?void 0:s.rowId)===e.id&&(s==null?void 0:s.field)===u;return i.jsxs("tr",{children:[n.map(u=>{var y;const p=e[u.field],v=u.editable&&!o,f=c(u.field),{isValidating:w,result:x}=r(e.id,u.field);let h="border-gray-300";u.validate&&((x==null?void 0:x.isValid)===!1?h="border-red-500 bg-red-50":(x==null?void 0:x.isValid)===!0&&(h="border-green-500 bg-green-50"));const g=`w-full px-2 py-1 border rounded outline-none ${h}`;return i.jsx("td",{title:o?"":"Double click to edit",className:"px-3 py-1 border",onDoubleClick:()=>v&&a({rowId:e.id,field:u.field}),children:v&&f?i.jsxs("div",{className:"relative",children:[u.type==="number"?i.jsx(Ge,{value:p,decimalsLimit:6,allowNegativeValue:!1,className:g,onValueChange:N=>t(N,e.id,u.field),onBlur:()=>{a(null),d(p,e.id,u.field,u)},autoFocus:!0}):u.type==="checkbox"?i.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(N=>{const A=N==="yes",S=`radio-${e.id}-${String(u.field)}-${N}`;return i.jsxs("label",{htmlFor:S,className:"flex items-center gap-1 cursor-pointer",children:[i.jsx("input",{id:S,type:"radio",name:`boolean-${e.id}-${String(u.field)}`,checked:p===A,onChange:()=>t(A,e.id,u.field)}),i.jsx("span",{className:"text-sm",children:A?"Yes":"No"})]},N)})}):i.jsx("input",{type:"text",value:String(p!=null?p:""),onChange:N=>t(N.target.value,e.id,u.field),onBlur:()=>{a(null),d(p,e.id,u.field,u)},className:g,autoFocus:!0}),w&&i.jsx("div",{className:"absolute right-1 top-1",children:i.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):u.validate&&x?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{children:[String(p!=null?p:"")," ",x.data&&`[${x.data}]`]}),x.isValid?i.jsx("span",{className:"text-xs text-green-600",children:"✓"}):i.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(y=x.error)!=null?y:"",children:"✗"})]}):u.type==="checkbox"?i.jsx("span",{className:"block py-1 text-gray-700",children:p===!0?"Yes":p===!1?"No":""}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:String(p!=null?p:"")})},String(u.id))}),!o&&i.jsx("td",{className:"px-3 py-1 text-center border",children:i.jsx("button",{type:"button",onClick:()=>l(e.id),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:i.jsx(W,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const Ga=m.memo(Ka);function Ra({value:e=[],onChange:n,isReadOnly:o=!1,columns:s}){const[a,t]=m.useState(e),[d,r]=m.useState(null),l=m.useRef(null),[c,u]=m.useState(0);m.useEffect(()=>{const x=document.getElementById("form");if(!x)return;const h=y=>{const N=y.getBoundingClientRect().width;u(N?N-58:0)};h(x);const g=new ResizeObserver(y=>{for(const N of y)h(N.target)});return g.observe(x),()=>g.disconnect()},[]),m.useEffect(()=>{t(x=>JSON.stringify(x)!==JSON.stringify(e)?e:x)},[e]),m.useEffect(()=>{n==null||n(a)},[a,n]),m.useEffect(()=>{const x=h=>{l.current&&!l.current.contains(h.target)&&r(null)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);const p=m.useCallback((x,h,g)=>{t(y=>y.map(N=>N.id===h?{...N,[g]:x}:N))},[]),v=m.useCallback(()=>{const x=fe.v4(),h=s.reduce((g,y)=>(g[y.field]=y.field==="id"?x:"",g),{});t(g=>[...g,{id:x,...h}])},[s]),f=m.useCallback(x=>{t(h=>h.filter(g=>g.id!==x))},[]),w=m.useCallback(()=>({isValidating:!1,result:void 0}),[]);return i.jsxs("div",{className:"mt-3 rounded",ref:l,children:[i.jsx("div",{className:"flex justify-end",children:!o&&i.jsx("button",{onClick:v,type:"button",className:"px-2 py-1 mb-3 text-xs text-white bg-gray-600 rounded hover:bg-gray-700",children:"Add Row"})}),i.jsx("div",{className:"w-full max-w-full overflow-x-auto",style:{maxWidth:`${c}px`},children:i.jsxs("table",{className:"min-w-max w-full text-sm border-collapse rounded table-auto bg-gray-50",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"bg-gray-100",children:[s.map((x,h)=>{var g;return i.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border whitespace-nowrap",children:[(g=x.headerName)!=null?g:String(x.field),x.validate&&i.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(x.id)}-${h}`)}),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:a.length>0?a.map(x=>i.jsx(Ga,{row:x,columns:s,isReadOnly:o,editingCell:d,setEditingCell:r,handleCellChange:p,debouncedValidate:()=>{},getValidationStatus:w,deleteRow:f},x.id)):i.jsx("tr",{children:i.jsx("td",{colSpan:s.length+(o?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})})]})}function za({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t}=n||{},d=a&&a(e==null?void 0:e.id)||[];m.useEffect(()=>{o(e.id)},[e.id,o]);const r=m.useCallback(l=>{s==null||s(e.id,l)},[e.id,s]);return i.jsx(Ra,{value:d,onChange:r,columns:e==null?void 0:e.dataColumns,isReadOnly:t})}const vn=({className:e="",options:n=[],placeholder:o="Select",errors:s,register:a,setValue:t,name:d,label:r,value:l,trigger:c,isMultiple:u=!1,isFloatingLabel:p=!1,subText:v,labelClass:f="",loading:w,disabled:x})=>{const[h,g]=m.useState(u?[]:null),y=q("custom-select__control",e),N=m.useMemo(()=>n,[n]);return m.useEffect(()=>{const A=n==null?void 0:n.find(S=>{var k;return typeof S.value=="string"&&typeof l=="string"?S.value.toLowerCase()===l.toLowerCase():typeof S.value=="object"&&typeof l=="object"?((k=S.value)==null?void 0:k.id)===(l==null?void 0:l.id):S.value===l});g(A||null)},[l,n]),m.useEffect(()=>{h&&t&&a&&(t(d,h==null?void 0:h.value),a(d),c==null||c(d))},[d,h]),i.jsxs("div",{className:"custom-select",children:[r&&!p&&i.jsx("label",{className:"custom-select__label",children:r}),p&&r&&i.jsx("label",{className:q("custom-select__floating-label",f),children:r}),i.jsx(z.Listbox,{value:h,onChange:g,multiple:u,disabled:x,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(z.Listbox.Button,{className:y,disabled:x,children:[w?i.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):i.jsx("span",{className:"custom-select__value",children:(h==null?void 0:h.label)||i.jsx("span",{className:"custom-select__placeholder",children:o})}),i.jsx("span",{className:"custom-select__icon",children:i.jsx(W,{icon:"lucide:chevron-down"})})]}),i.jsx(z.Transition,{as:m.Fragment,leave:"custom-select__transition",children:i.jsx(z.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:N==null?void 0:N.map((A,S)=>i.jsx(z.Listbox.Option,{value:A,className:({active:k})=>q("custom-select__option",k&&"custom-select__option--active"),children:({selected:k})=>i.jsx("span",{className:q("custom-select__option-label",k&&"custom-select__option--selected"),children:A.label})},S))})})]})}),v&&!s&&i.jsx("p",{className:"custom-select__subtext",children:v}),s&&i.jsx("span",{className:"custom-select__error",children:s.message})]})},Ha=({element:e,validationData:n})=>{var x;const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:d}=n||{},r=(x=e==null?void 0:e.id)!=null?x:"cascadeValue",[l,c]=m.useState(""),[u,p]=m.useState(""),v=(h,g)=>{const y=h&&g?`${h}_${g}`:"";a==null||a(r,y),s==null||s(r)},f=(h,g)=>{h==="first"?(c(g),p(""),v(g,"")):(p(g),v(l,g))};m.useEffect(()=>{if(t){const h=t(r);if(h!=null&&h.includes("_")){const[g,y]=h.split("_");c(g),p(y)}}},[t,r]);const w=m.useMemo(()=>{var h;return(h=e.options1)==null?void 0:h.filter(g=>g.key===l)},[e.options1,l]);return!e.options||!e.options1?null:i.jsxs("div",{children:[i.jsx("input",{type:"hidden",...o(r)}),i.jsx("div",{className:"relative",children:i.jsx(vn,{setValue:(h,g)=>f("first",g),options:e.options,name:`${r}`,register:o,value:l})}),l&&i.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&i.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),i.jsx(vn,{setValue:(h,g)=>f("second",g),options:w,name:`${r}`,register:o,value:u})]})]})},Fa=({value:e=0,max:n=5,readOnly:o=!1,onChange:s,size:a=24,className:t="",element:d,validationData:r})=>{var g;const{register:l=()=>({}),trigger:c,setValue:u,watch:p,isReadOnly:v}=r||{},f=(g=p==null?void 0:p(d.id))!=null?g:0,[w,x]=m.useState(null);m.useEffect(()=>{f==null&&(u==null||u(d.id,e))},[]);const h=y=>{if(!o&&!v){const N=y+1;u==null||u(d.id,N),c==null||c(d.id),s==null||s(N)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...l(d.id)}),Array.from({length:n},(y,N)=>{const A=w!==null?N<=w:N<f;return i.jsx(rn,{icon:A?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${A?"text-yellow-400":"text-gray-300"}`,width:a,height:a,onMouseEnter:()=>!(o||v)&&x(N),onMouseLeave:()=>!(o||v)&&x(null),onClick:()=>h(N)},N)})]})};function pn({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,trigger:a,isReadOnly:t,watch:d}=n||{},r=(d==null?void 0:d(e.id))||"",{country:l,state:c}=m.useMemo(()=>{var w;if(typeof r=="string"&&r.includes(",")){const[x,h]=(w=r.split(","))==null?void 0:w.map(g=>g.trim());return{country:h,state:x}}return{country:r,state:""}},[r]),u=m.useRef(r),p=m.useMemo(()=>{var w,x;return l?((x=(w=We.find(h=>h.name===l))==null?void 0:w.states)==null?void 0:x.map(h=>({label:h.name,value:h.name})))||[]:[]},[l]),v=(w,x)=>{const g=(x==null?void 0:x.value)||"";s&&g!==u.current&&(s(e.id,g),a==null||a(e.id),u.current=g)},f=(w,x)=>{const h=(x==null?void 0:x.value)||"",g=h?`${h}, ${l}`:l;s&&g!==u.current&&(s(e.id,g),a==null||a(e.id),u.current=g)};return m.useEffect(()=>{u.current=r},[r]),i.jsxs("div",{className:"grid gap-y-6",children:[i.jsx("input",{type:"hidden",...o(e.id)}),i.jsx(ci,{options:e.options,onGetValue:v,name:`${e.id}-country`,readOnly:t,defaultValue:l},`country-${l}`),p.length>0&&e.showState&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),i.jsx(ci,{options:p,onGetValue:f,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function Va({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:s}=n||{},{validationUrl:a,documentObj:t,signatureLink:d}=e,r=m.useMemo(()=>pe("config"),[]),[l,c]=m.useState(!1),[u,p]=m.useState(!1),v=m.useCallback(async()=>{var f,w;if(!(!a||!t))try{p(!0);const h={headers:{Authorization:`Bearer ${pe("token")}`}},{data:g}=await _e.get(`${a}/${t}`,h),y=!!((w=(f=g==null?void 0:g.data)==null?void 0:f.isSigned)!=null?w:g!=null&&g.isSigned);return c(y),y}catch(x){console.error("Failed to check sign status",x)}finally{p(!1)}},[a,t]);return m.useEffect(()=>{let f=null;return!l&&t&&a&&(async()=>{await v()||(f=setInterval(async()=>{await v()&&f&&clearInterval(f)},2e3))})(),()=>{f&&clearInterval(f)}},[v,l,t,a]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:q("field-control",e.customClass),...o(e.id),disabled:s}),i.jsx("a",{href:l?"#":d,children:i.jsxs("button",{type:"button",onClick:v,disabled:u||l,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:q("flex items-center gap-x-1 rounded-lg border border-gray-200 bg-gray-200 px-3 py-[10px] text-sm text-white",{"!opacity-60":u}),children:[i.jsx(W,{icon:u?"solar:refresh-outline":l?"solar:check-circle-bold":"solar:pen-2-line-duotone",iconClass:u?"animate-spin":""}),u?"Checking...":l?"Signed":"Sign"]})})]})}const gi=[{code:"DZ",label:"Algeria",phone:"213",min:9,max:9},{code:"AO",label:"Angola",phone:"244",min:9,max:9},{code:"BJ",label:"Benin",phone:"229",min:8,max:8},{code:"BW",label:"Botswana",phone:"267",min:7,max:7},{code:"BF",label:"Burkina Faso",phone:"226",min:8,max:8},{code:"BI",label:"Burundi",phone:"257",min:8,max:8},{code:"CM",label:"Cameroon",phone:"237",min:9,max:9},{code:"CV",label:"Cape Verde",phone:"238",min:7,max:7},{code:"CF",label:"Central African Republic",phone:"236",min:8,max:8},{code:"TD",label:"Chad",phone:"235",min:8,max:8},{code:"KM",label:"Comoros",phone:"269",min:7,max:7},{code:"CG",label:"Congo",phone:"242",min:9,max:9},{code:"CD",label:"Democratic Republic of Congo",phone:"243",min:9,max:9},{code:"CI",label:"Cote d'Ivoire",phone:"225",min:8,max:8},{code:"DJ",label:"Djibouti",phone:"253",min:8,max:8},{code:"EG",label:"Egypt",phone:"20",min:10,max:10},{code:"GQ",label:"Equatorial Guinea",phone:"240",min:9,max:9},{code:"ER",label:"Eritrea",phone:"291",min:7,max:7},{code:"ET",label:"Ethiopia",phone:"251",min:9,max:9},{code:"GA",label:"Gabon",phone:"241",min:7,max:7},{code:"GM",label:"Gambia",phone:"220",min:7,max:7},{code:"GH",label:"Ghana",phone:"233",min:9,max:9},{code:"GN",label:"Guinea",phone:"224",min:9,max:9},{code:"GW",label:"Guinea-Bissau",phone:"245",min:9,max:9},{code:"KE",label:"Kenya",phone:"254",min:7,max:9},{code:"LS",label:"Lesotho",phone:"266",min:8,max:8},{code:"LR",label:"Liberia",phone:"231",min:8,max:9},{code:"LY",label:"Libya",phone:"218",min:9,max:10},{code:"MG",label:"Madagascar",phone:"261",min:9,max:9},{code:"MW",label:"Malawi",phone:"265",min:9,max:9},{code:"ML",label:"Mali",phone:"223",min:8,max:8},{code:"MR",label:"Mauritania",phone:"222",min:8,max:8},{code:"MU",label:"Mauritius",phone:"230",min:8,max:8},{code:"MA",label:"Morocco",phone:"212",min:9,max:9},{code:"MZ",label:"Mozambique",phone:"258",min:9,max:9},{code:"NA",label:"Namibia",phone:"264",min:9,max:9},{code:"NE",label:"Niger",phone:"227",min:8,max:8},{code:"NG",label:"Nigeria",phone:"234",min:10,max:10},{code:"RW",label:"Rwanda",phone:"250",min:9,max:9},{code:"ST",label:"Sao Tome and Principe",phone:"239",min:7,max:7},{code:"SN",label:"Senegal",phone:"221",min:9,max:9},{code:"SC",label:"Seychelles",phone:"248",min:7,max:7},{code:"SL",label:"Sierra Leone",phone:"232",min:8,max:8},{code:"SO",label:"Somalia",phone:"252",min:8,max:9},{code:"ZA",label:"South Africa",phone:"27",min:10,max:10},{code:"SS",label:"South Sudan",phone:"211",min:9,max:9},{code:"SD",label:"Sudan",phone:"249",min:9,max:9},{code:"TZ",label:"Tanzania",phone:"255",min:9,max:9},{code:"TG",label:"Togo",phone:"228",min:8,max:8},{code:"TN",label:"Tunisia",phone:"216",min:8,max:8},{code:"UG",label:"Uganda",phone:"256",min:9,max:9},{code:"ZM",label:"Zambia",phone:"260",min:9,max:9},{code:"ZW",label:"Zimbabwe",phone:"263",min:9,max:9},{code:"US",label:"United States",phone:"1",min:10,max:10},{code:"CA",label:"Canada",phone:"1",min:10,max:10},{code:"GB",label:"United Kingdom",phone:"44",min:9,max:10},{code:"FR",label:"France",phone:"33",min:9,max:9},{code:"DE",label:"Germany",phone:"49",min:10,max:11},{code:"IT",label:"Italy",phone:"39",min:9,max:10},{code:"ES",label:"Spain",phone:"34",min:9,max:9},{code:"NL",label:"Netherlands",phone:"31",min:9,max:9},{code:"RU",label:"Russia",phone:"7",min:10,max:10},{code:"CN",label:"China",phone:"86",min:11,max:11},{code:"IN",label:"India",phone:"91",min:10,max:10},{code:"JP",label:"Japan",phone:"81",min:10,max:10},{code:"KR",label:"South Korea",phone:"82",min:8,max:9},{code:"BR",label:"Brazil",phone:"55",min:10,max:11},{code:"MX",label:"Mexico",phone:"52",min:10,max:10},{code:"AR",label:"Argentina",phone:"54",min:10,max:10},{code:"CL",label:"Chile",phone:"56",min:9,max:9},{code:"AU",label:"Australia",phone:"61",min:9,max:9},{code:"NZ",label:"New Zealand",phone:"64",min:8,max:9},{code:"SA",label:"Saudi Arabia",phone:"966",min:9,max:9},{code:"AE",label:"United Arab Emirates",phone:"971",min:9,max:9},{code:"TR",label:"Turkey",phone:"90",min:10,max:11},{code:"IR",label:"Iran",phone:"98",min:7,max:10},{code:"PK",label:"Pakistan",phone:"92",min:10,max:10},{code:"BD",label:"Bangladesh",phone:"880",min:10,max:10},{code:"ID",label:"Indonesia",phone:"62",min:9,max:11},{code:"PH",label:"Philippines",phone:"63",min:10,max:10},{code:"CO",label:"Colombia",phone:"57",min:10,max:10},{code:"VE",label:"Venezuela",phone:"58",min:10,max:10},{code:"PE",label:"Peru",phone:"51",min:9,max:9},{code:"EC",label:"Ecuador",phone:"593",min:9,max:9},{code:"UY",label:"Uruguay",phone:"598",min:8,max:8},{code:"PY",label:"Paraguay",phone:"595",min:9,max:9},{code:"BO",label:"Bolivia",phone:"591",min:8,max:8},{code:"GT",label:"Guatemala",phone:"502",min:8,max:8},{code:"HN",label:"Honduras",phone:"504",min:8,max:8},{code:"SV",label:"El Salvador",phone:"503",min:8,max:8},{code:"NI",label:"Nicaragua",phone:"505",min:8,max:8},{code:"CR",label:"Costa Rica",phone:"506",min:8,max:8},{code:"PA",label:"Panama",phone:"507",min:8,max:8},{code:"JM",label:"Jamaica",phone:"1",min:10,max:10},{code:"TT",label:"Trinidad and Tobago",phone:"1",min:10,max:10},{code:"AD",label:"Andorra",phone:"376",min:6,max:6},{code:"AF",label:"Afghanistan",phone:"93",min:9,max:9},{code:"AG",label:"Antigua and Barbuda",phone:"1-268",min:7,max:7},{code:"AI",label:"Anguilla",phone:"1-264",min:7,max:7},{code:"AL",label:"Albania",phone:"355",min:8,max:8},{code:"AM",label:"Armenia",phone:"374",min:8,max:8},{code:"AS",label:"American Samoa",phone:"1-684",min:7,max:7},{code:"AT",label:"Austria",phone:"43",min:10,max:10},{code:"AW",label:"Aruba",phone:"297",min:7,max:7},{code:"AX",label:"Åland Islands",phone:"358",min:6,max:6},{code:"AZ",label:"Azerbaijan",phone:"994",min:9,max:9},{code:"BA",label:"Bosnia and Herzegovina",phone:"387",min:8,max:8},{code:"BB",label:"Barbados",phone:"1-246",min:7,max:7},{code:"BE",label:"Belgium",phone:"32",min:9,max:9},{code:"BG",label:"Bulgaria",phone:"359",min:9,max:9},{code:"BH",label:"Bahrain",phone:"973",min:8,max:8},{code:"BL",label:"Saint Barthélemy",phone:"590",min:9,max:9},{code:"BM",label:"Bermuda",phone:"1-441",min:7,max:7},{code:"BN",label:"Brunei Darussalam",phone:"673",min:7,max:7},{code:"BQ",label:"Bonaire, Sint Eustatius and Saba",phone:"599",min:7,max:7},{code:"BS",label:"Bahamas",phone:"1-242",min:7,max:7},{code:"BT",label:"Bhutan",phone:"975",min:8,max:8},{code:"BV",label:"Bouvet Island",phone:"47",min:8,max:8},{code:"BY",label:"Belarus",phone:"375",min:9,max:9},{code:"BZ",label:"Belize",phone:"501",min:7,max:7},{code:"CC",label:"Cocos (Keeling) Islands",phone:"61",min:7,max:7},{code:"CH",label:"Switzerland",phone:"41",min:9,max:9},{code:"CK",label:"Cook Islands",phone:"682",min:5,max:5},{code:"CU",label:"Cuba",phone:"53",min:8,max:8},{code:"CW",label:"Curaçao",phone:"599",min:7,max:7},{code:"CX",label:"Christmas Island",phone:"61",min:7,max:7},{code:"CY",label:"Cyprus",phone:"357",min:8,max:8},{code:"CZ",label:"Czechia",phone:"420",min:9,max:9},{code:"DK",label:"Denmark",phone:"45",min:8,max:8},{code:"DM",label:"Dominica",phone:"1-767",min:7,max:7},{code:"DO",label:"Dominican Republic",phone:"1-809",min:7,max:7},{code:"EE",label:"Estonia",phone:"372",min:8,max:8},{code:"EH",label:"Western Sahara",phone:"212",min:9,max:9},{code:"FI",label:"Finland",phone:"358",min:9,max:9},{code:"FJ",label:"Fiji",phone:"679",min:7,max:7},{code:"FM",label:"Micronesia (Federated States of)",phone:"691",min:7,max:7},{code:"FO",label:"Faroe Islands",phone:"298",min:6,max:6},{code:"GD",label:"Grenada",phone:"1-473",min:7,max:7},{code:"GE",label:"Georgia",phone:"995",min:9,max:9},{code:"GF",label:"French Guiana",phone:"594",min:9,max:9},{code:"GG",label:"Guernsey",phone:"44",min:9,max:9},{code:"GI",label:"Gibraltar",phone:"350",min:8,max:8},{code:"GL",label:"Greenland",phone:"299",min:6,max:6},{code:"GP",label:"Guadeloupe",phone:"590",min:9,max:9},{code:"GR",label:"Greece",phone:"30",min:10,max:10},{code:"GS",label:"South Georgia and the South Sandwich Islands",phone:"500",min:6,max:6},{code:"GU",label:"Guam",phone:"1-671",min:10,max:10},{code:"GY",label:"Guyana",phone:"592",min:7,max:7},{code:"HK",label:"Hong Kong",phone:"852",min:8,max:8},{code:"HM",label:"Heard Island and McDonald Islands",phone:"672",min:6,max:6},{code:"HR",label:"Croatia",phone:"385",min:9,max:9},{code:"HT",label:"Haiti",phone:"509",min:8,max:8},{code:"HU",label:"Hungary",phone:"36",min:9,max:9},{code:"IE",label:"Ireland",phone:"353",min:9,max:9},{code:"IM",label:"Isle of Man",phone:"44",min:9,max:9},{code:"IO",label:"British Indian Ocean Territory",phone:"246",min:7,max:7},{code:"IQ",label:"Iraq",phone:"964",min:10,max:10},{code:"IS",label:"Iceland",phone:"354",min:7,max:7},{code:"JE",label:"Jersey",phone:"44",min:9,max:9},{code:"JO",label:"Jordan",phone:"962",min:9,max:9},{code:"KG",label:"Kyrgyzstan",phone:"996",min:9,max:9},{code:"KH",label:"Cambodia",phone:"855",min:9,max:9},{code:"KI",label:"Kiribati",phone:"686",min:7,max:7},{code:"KN",label:"Saint Kitts and Nevis",phone:"1-869",min:10,max:10},{code:"KP",label:"North Korea",phone:"850",min:9,max:9},{code:"KW",label:"Kuwait",phone:"965",min:8,max:8},{code:"KY",label:"Cayman Islands",phone:"1-345",min:10,max:10},{code:"KZ",label:"Kazakhstan",phone:"7",min:10,max:10},{code:"MC",label:"Monaco",phone:"377",min:8,max:9},{code:"LI",label:"Liechtenstein",phone:"423",min:7,max:7},{code:"VA",label:"Vatican City",phone:"379",min:9,max:9},{code:"SM",label:"San Marino",phone:"378",min:10,max:10},{code:"ME",label:"Montenegro",phone:"382",min:8,max:8},{code:"RS",label:"Serbia",phone:"381",min:9,max:9},{code:"MK",label:"North Macedonia",phone:"389",min:8,max:8},{code:"SJ",label:"Svalbard and Jan Mayen",phone:"47",min:8,max:8},{code:"MF",label:"Saint Martin",phone:"590",min:9,max:9},{code:"PM",label:"Saint Pierre and Miquelon",phone:"508",min:6,max:6},{code:"WF",label:"Wallis and Futuna",phone:"681",min:6,max:6},{code:"TV",label:"Tuvalu",phone:"688",min:5,max:5},{code:"NR",label:"Nauru",phone:"674",min:7,max:7},{code:"TO",label:"Tonga",phone:"676",min:5,max:5},{code:"WS",label:"Samoa",phone:"685",min:7,max:7},{code:"VU",label:"Vanuatu",phone:"678",min:7,max:7},{code:"SB",label:"Solomon Islands",phone:"677",min:7,max:7},{code:"FM",label:"Micronesia",phone:"691",min:7,max:7},{code:"MH",label:"Marshall Islands",phone:"692",min:7,max:7},{code:"PW",label:"Palau",phone:"680",min:7,max:7}];function Wa({label:e,placeholder:n,classLabel:o,isRequired:s,isOptional:a,name:t,value:d,error:r,disabled:l,readOnly:c,horizontal:u,description:p,validate:v,onChange:f,onError:w}){const[x,h]=m.useState(""),[g,y]=m.useState(null),[N,A]=m.useState(""),S=m.useMemo(()=>{var B;return(B=gi==null?void 0:gi.slice().sort((F,D)=>F.label.localeCompare(D.label)))==null?void 0:B.map(F=>({...F,phone:`+${F.phone}`}))},[]),k=m.useMemo(()=>x?S.filter(B=>`${B.label} ${B.phone}`.toLowerCase().includes(x.toLowerCase())):S,[x,S]),j=(g==null?void 0:g.min)||10,I=(g==null?void 0:g.max)||10,X=()=>N?`${(g==null?void 0:g.phone)||"+234"}-${N}`:"",U=B=>{if(!B)return{code:"+234",number:""};const F=B.split(/[-\s]/);return{code:F[0],number:F.slice(1).join(" ")}};m.useEffect(()=>{if(d){const B=U(d);y(S.find(F=>F.phone===B.code)||S[0]),A(B.number)}},[d,S]);const Z=m.useMemo(()=>{if(r)return r;const B=N.length;return s&&B===0?"Phone number is required":B>0&&!/^\d+$/.test(N)?"Phone number must contain only digits":B>0&&B<j?`Minimum length is ${j}`:B>I?`Maximum length is ${I}`:""},[r,N,j,I,s]);return m.useEffect(()=>{f==null||f(X()),w==null||w(Z||null)},[N,g,Z]),i.jsxs("div",{className:`relative formGroup ${Z&&!c?"has-error":""} ${u?"flex":""} ${!Z&&N.length>0&&!c?"is-valid":""}`,children:[e&&i.jsxs("label",{htmlFor:t,className:`${o} ${u?"flex-0 mr-6 md:w-[100px] w-[60px] break-words":""} flex items-center gap-x-1 input-label text-sm text-[#1B2B41B8]`,children:[e," ",s&&i.jsx("span",{className:"text-red-500",children:"*"}),a&&i.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),i.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[i.jsx(W,{icon:"lucide:phone-call"}),i.jsx(z.Combobox,{value:g,onChange:y,children:i.jsxs("div",{className:"relative",children:[i.jsx(z.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:B=>(B==null?void 0:B.phone)||"+234",placeholder:"+234",onChange:B=>h(B.target.value)}),i.jsx(z.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(W,{icon:"lucide:chevron-down"})}),i.jsx(z.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:k==null?void 0:k.map((B,F)=>i.jsxs(z.Combobox.Option,{value:B,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[B.phone," - ",B.label]},`${B.code}+ ${F}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:N,disabled:l,readOnly:c,onChange:B=>{const F=B.target.value.replace(/\D/g,"");A(F)},placeholder:n,className:"w-full px-3 outline-none",maxLength:I,minLength:j}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!Z&&N.length>0&&!c&&i.jsx("span",{className:"text-green-500",children:i.jsx(W,{icon:"bi:check-lg"})})})]})]}),p&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:p})]})}function Ua({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t,setError:d,clearErrors:r}=n||{};let l;return m.useEffect(()=>{o(e.id)},[e.id,o]),a&&(l=a()[e.id]),i.jsx(Wa,{placeholder:e.placeholder,label:"",name:e.id,value:l,readOnly:t,disabled:t,onError:c=>{c?d==null||d(e.id,{type:"manual",message:c}):r==null||r(e.id)},onChange:c=>{c&&(s==null||s(e.id,c))}})}function qa({element:e,validationData:n}){var c;const{register:o=()=>({}),watch:s}=n||{};let a="";s&&(a=(c=s()[e.id])!=null?c:"");const t=a.trim(),d=/^https?:\/\//i.test(t),r=t?d?t:`https://${t}`:"",l=!d;return i.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&i.jsxs("div",{className:"relative",children:[l&&i.jsx("span",{className:"text-sm absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none select-none",children:"https://"}),i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:q("field-control",l&&"!pl-16",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly})]}),t?i.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:i.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:t})}):(n==null?void 0:n.isReadOnly)&&i.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}const gn={textField:Xe,longText:ia,selectField:ea,multiSelect:ui,numberField:Xe,amountField:Ca,date:Fn,password:Zo,checkbox:Xo,radio:$o,email:Xe,file:Yo,dataGrid:za,section:Qo,validateInput:Ta,tableInput:La,spacer:Pa,divider:Da,header:Ia,basicText:Oa,phoneField:Ua,cascadeSelect:Ha,rating:Fa,country:pn,bank:pn,document:Va,url:qa},hn="edit",Ja=(e,n)=>{const o=gn[e.type];return o?i.jsx(pi,{element:e,state:hn,children:i.jsxs("div",{className:"relative w-full",children:[e.type.toLowerCase()!=="grid"&&i.jsx("div",{className:"absolute top-0 left-0 z-20 w-full h-full"}),i.jsx(o,{element:e,state:hn,sectionId:n})]})}):null},hi=({col:e,children:n,customClass:o})=>i.jsx("div",{className:q("w-full bg-white",o),style:{gridColumn:e},children:n}),Ya=({element:e,sectionId:n,children:o,customClass:s,state:a,draggedElementId:t})=>{const{formData:d,addElement:r,setIsDragging:l,moveElement:c,isDragging:u,removeElement:p}=m.useContext(ve),v=m.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[f,w]=m.useState(null);m.useEffect(()=>{const A=()=>{w(null),l(!1)};return document.addEventListener("dragend",A),()=>document.removeEventListener("dragend",A)},[l]);const x=m.useCallback((A,S)=>{A.preventDefault(),A.stopPropagation(),A.dataTransfer.dropEffect="move",w(S)},[]),h=m.useCallback((A,S)=>{A.preventDefault(),A.stopPropagation(),w(S)},[]),g=m.useCallback((A,S)=>{const k=A.relatedTarget;k&&A.currentTarget.contains(k)||w(j=>j===S?null:j)},[]),y=m.useCallback((A,S)=>{var I;A.preventDefault(),A.stopPropagation(),l(!1),w(null);const k=S+1,j=A.dataTransfer.getData("elementId");if(j){c({draggedId:j,sectionId:n,targetGridId:e.id,targetCol:k});return}try{const X=A.dataTransfer.getData("properties");if(!X)return;const U=JSON.parse(X);if((U==null?void 0:U.type)==="grid")return;const Z=d.find(D=>D.id===n),B=(I=Z==null?void 0:Z.questionData)==null?void 0:I.find(D=>{var K;return D.gridId===e.id&&((K=D.gridPosition)==null?void 0:K.col)===k});B&&p(B.id,n);const F={...U,id:fe.v4(),sectionId:n,gridId:e.id,gridPosition:{col:k}};r(F,n)}catch(X){console.error("Drop failed in grid:",X),l(!1)}},[r,e.id,d,n,l,c]),N=(A,S,k)=>{var K,G,P;const j=A+1,I=(G=(K=d.find(E=>E.id===n))==null?void 0:K.questionData)==null?void 0:G.find(E=>{var T;return E.gridId===e.id&&((T=E.gridPosition)==null?void 0:T.col)===j}),X=(P=I==null?void 0:I.id)!=null?P:null,U=Array.isArray(o)&&o.find(E=>{var T;return((T=E==null?void 0:E.props)==null?void 0:T.col)===j}),Z=u&&f===A,B=!!U,F=u&&!!t,D=B&&X&&k==="edit"?{draggable:!0,onDragStart:E=>{E.stopPropagation(),E.dataTransfer.setData("elementId",X),E.dataTransfer.setData("properties",X),E.dataTransfer.effectAllowed="move",l(!0)},onDragEnd:()=>{w(null),l(!1)}}:{};return i.jsx("div",{children:i.jsxs("div",{id:`grid-cell-${e.id}-${A}`,...D,onDrop:E=>y(E,A),onDragEnter:E=>h(E,A),onDragOver:E=>x(E,A),onDragLeave:E=>g(E,A),className:q("relative border rounded-lg min-h-[110px]","flex items-center justify-center","transition-all duration-200 ease-in-out",k==="edit"?"py-3 ":"",B&&k==="edit"&&"cursor-grab active:cursor-grabbing border-none",S,!F&&!Z&&"bg-white border-gray-200 text-gray-300",F&&!Z&&!B&&"bg-blue-50 border-blue-200 border-dashed text-blue-300",F&&!Z&&B&&"bg-white border-orange-200 border-dashed",Z&&!B&&"bg-blue-100 border-blue-400 border-dashed shadow-inner scale-[1.01] text-blue-500",Z&&B&&"bg-orange-50 border-orange-400 border-dashed shadow-inner scale-[1.01] text-orange-500"),children:[B&&k==="edit"&&i.jsx("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 flex items-center gap-0.5 px-2 py-0.5 rounded-full bg-gray-100 hover:bg-blue-100 text-gray-400 hover:text-blue-500 cursor-grab active:cursor-grabbing transition-colors z-10 opacity-60 hover:opacity-100 pointer-events-none select-none",children:i.jsx(W,{icon:"ph:dots-six-bold"})}),Z&&!B&&i.jsxs("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-blue-400 text-xs font-medium pointer-events-none",children:[i.jsx(W,{icon:"ph:plus-bold"}),"Drop here"]}),Z&&B&&i.jsx("span",{className:"absolute top-1 right-1 text-xs text-orange-400 font-medium pointer-events-none px-1 py-0.5 bg-orange-50 rounded",children:"Replace"}),i.jsx("div",{className:q("w-full select-none",Z&&"opacity-50 pointer-events-none"),children:U||i.jsx("span",{className:"flex items-center justify-center text-gray-300",children:k==="edit"&&i.jsx(W,{icon:"ph:plus-bold"})})})]})},A)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3 items-center",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:v==null?void 0:v.map((A,S)=>N(S,s,a))})})},fi=m.memo(Ya),Za="edit";function xi({index:e,onDrop:n,onDragEnd:o,isDragging:s}){const[a,t]=m.useState(!1),d=a?52:s?28:4;return i.jsx("div",{onDragEnter:r=>{r.preventDefault(),t(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),t(!0)},onDragLeave:()=>t(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),t(!1),n(r,e)},onDragEnd:()=>{t(!1),o()},style:{height:`${d}px`},className:q("w-full rounded-md flex items-center justify-center","transition-all duration-150 ease-in-out overflow-hidden",a?"bg-blue-50 border-2 border-blue-300 border-dashed":s?"border-2 border-blue-200 border-dashed":"border-2 border-transparent"),children:a&&i.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[i.jsx(W,{icon:"octicon:plus-16"}),"Drop here"]})})}function $a({elementData:e,sectionId:n}){const{formData:o,isDragging:s,setIsDragging:a,addElementInPosition:t,moveElement:d}=m.useContext(ve),[r,l]=m.useState(null),c=m.useMemo(()=>{var g;return((g=o.find(y=>y.id===n))==null?void 0:g.questionData)||[]},[o,n]),u=m.useCallback((g,y)=>{g.dataTransfer.setData("elementId",y),g.dataTransfer.setData("properties",y),g.dataTransfer.effectAllowed="move",l(y),a(!0)},[a]),p=m.useCallback(()=>{l(null),a(!1)},[a]);m.useEffect(()=>{!s&&r&&l(null)},[s,r]);const v=m.useCallback(g=>{g.preventDefault(),g.stopPropagation();const y=g.dataTransfer.getData("elementId"),N=g.currentTarget.id;if(!y||!N||y===N){p();return}const A=c.find(k=>k.id===y),S=c.findIndex(k=>k.id===N);A!=null&&A.gridId&&S!==-1?d({draggedId:y,sectionId:n,targetIndex:S}):d({draggedId:y,sectionId:n,targetId:N}),l(null),a(!1)},[n,d,a,p,c]),f=m.useCallback((g,y)=>{g.preventDefault(),g.stopPropagation(),a(!1);const N=g.dataTransfer.getData("elementId");if(N){d({draggedId:N,sectionId:n,targetIndex:y}),l(null);return}try{const A=JSON.parse(g.dataTransfer.getData("properties"));if((A==null?void 0:A.type)==="section")return;const S={...A,id:fe.v4(),sectionId:n};t(S,n,y),l(null)}catch(A){console.error("Drop error:",A)}},[t,n,a,d]),w=m.useCallback((g,y=!1)=>i.jsx("div",{id:g.id,draggable:!0,onDragStart:N=>u(N,g.id),onDragOver:y?void 0:N=>{N.preventDefault(),N.stopPropagation()},onDrop:y?void 0:v,onDragEnd:p,className:q("cursor-grab active:cursor-grabbing border p-4 w-full rounded-lg","transition-all duration-200 ease-in-out",r===g.id?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-300 shadow-inner":r?"bg-white border-dashed border-blue-200 shadow-sm":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:Ja(g,n)},g.id),[r,v,n,u,p]),x=m.useMemo(()=>(e==null?void 0:e.reduce((g,y)=>(y.gridId&&(g[y.gridId]=g[y.gridId]||[],g[y.gridId].push(y)),g),{}))||{},[e]);if(!(e!=null&&e.length))return i.jsx("div",{onDragOver:g=>g.preventDefault(),onDrop:g=>f(g,0),onDragEnd:p,className:"w-full h-full flex items-center justify-center text-gray-400 min-h-[200px] p-10 col-span-2 border border-dashed border-gray-300 rounded-lg",children:"Drag or click an element to display"});const h=e.filter(g=>!g.gridId);return i.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[i.jsx(xi,{index:0,isDragging:s,onDrop:f,onDragEnd:p}),h.map(g=>{const y=c.findIndex(N=>N.id===g.id);if(g.type==="grid"){const N=x[g.id]||[],A=r===g.id,S=!!r&&!A;return i.jsxs("div",{className:"flex flex-col gap-0",children:[i.jsx("div",{id:g.id,draggable:!0,onDragStart:k=>u(k,g.id),onDragOver:k=>{k.preventDefault(),k.stopPropagation()},onDrop:v,onDragEnd:p,className:q("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",A?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":S?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:i.jsx(pi,{element:g,state:"edit",children:i.jsx(fi,{element:g,sectionId:n,state:Za,draggedElementId:r,children:N==null?void 0:N.map(k=>{var j;return i.jsx(hi,{col:(j=k.gridPosition)==null?void 0:j.col,children:w(k,!0)},k.id)})})})}),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},g.id)}return i.jsxs("div",{className:"flex flex-col gap-0",children:[w(g),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},g.id)})]})}const Qa=m.memo($a),Xa=M.object({title:M.string(),description:M.string(),disabled:M.boolean().default(!1),isHidden:M.boolean().default(!1)}).required(),yi=pe("config"),es=({isOpen:e,onClose:n,section:o})=>{const{updateSection:s}=m.useContext(ve),{register:a,handleSubmit:t,watch:d,formState:{errors:r,isSubmitting:l,isValid:c},reset:u}=ke.useForm({resolver:mi(Xa),defaultValues:o});if(m.useEffect(()=>{e||u()},[e,u]),!e)return null;const p=f=>{s(f,o.id),n()},v=d();return i.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:i.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[i.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 mb-6",children:[i.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Update Section Information"}),i.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:i.jsx(W,{icon:"tabler:x"})})]}),i.jsxs("form",{onSubmit:t(p),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(H,{label:"Title",name:"title",register:a,errors:r,watch:d}),i.jsx(H,{label:"Description",name:"description",register:a,errors:r,watch:d,type:"textarea"}),i.jsx(H,{label:"Disable Section",name:"disabled",register:a,errors:r,watch:d,type:"checkbox",value:v.disabled,description:"Disables all fields in this section"}),i.jsx(H,{label:"Hide Section",name:"isHidden",register:a,errors:r,watch:d,type:"checkbox",value:v.isHidden,description:"Hides this section from the form"})]}),i.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!c||l,style:{background:(yi==null?void 0:yi.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!c||l?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!c||l?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:l?"Saving...":"Save"})]})]})]})})},is=({section:e,index:n,selectedSection:o,setSelectedSection:s,activeSections:a,toggleSection:t,handleSectionEdit:d,removeSection:r,formDataLength:l,onDragOver:c,setIsDragging:u})=>{const p=m.useRef(null),v=m.useRef(e.questionData.length);return m.useEffect(()=>{e.questionData.length>v.current&&p.current&&requestAnimationFrame(()=>{var f;(f=p.current)==null||f.scrollTo({top:p.current.scrollHeight,behavior:"smooth"})}),v.current=e.questionData.length},[e.questionData.length]),i.jsx("div",{ref:p,className:"bg-white group cursor-pointer rounded-lg max-h-[600px] overflow-y-auto shadow-[rgba(149,157,165,0.2)_0px_2px_2px] transition-colors duration-200",children:i.jsxs("div",{className:` border border-gray-200 rounded-lg px-4 transition-colors duration-200
57
- ${o===e.id?" border-blue-200 bg-gray-100":"bg-white"} ${a.includes(n)?"min-h-[300px] pb-6 ":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{onClick:()=>s(e.id),className:"flex-1 h-full py-4 cursor-pointer",children:i.jsx("h2",{className:"font-medium",children:e.title||"Section title"})}),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>d(e),children:i.jsx(W,{icon:"fluent:edit-28-regular"})}),l>1&&i.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>r(e.id),children:i.jsx(W,{icon:"lets-icons:trash-duotone-line"})}),i.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>t(n),children:i.jsx(W,{icon:a.includes(n)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(e==null?void 0:e.description)&&a.includes(n)&&i.jsx("p",{className:"mt-2 text-sm text-gray-600",children:e==null?void 0:e.description}),a.includes(n)&&i.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:e.id,onDragOver:c,onDragEnd:()=>u(!1),onClick:()=>s(e.id),children:[i.jsx("hr",{className:"group-last:hidden"}),i.jsx("div",{className:"h-full mt-4 gap-y-6",children:i.jsx(Qa,{elementData:e.questionData,sectionId:e.id})})]})]})},e.id)},ns=()=>{const[e,n]=m.useState(!1),o=m.useRef(null),s=m.useRef(null),{removeSection:a,addSection:t,formData:d,setIsDragging:r,setSelectedSection:l,selectedSection:c,activeSections:u,setActiveSections:p}=m.useContext(ve),v=m.useRef((d==null?void 0:d.length)||0);m.useEffect(()=>{var g;l(((g=d[0])==null?void 0:g.id)||null)},[]),m.useEffect(()=>{(d==null?void 0:d.length)>v.current&&s.current&&requestAnimationFrame(()=>{var g;(g=s.current)==null||g.scrollTo({top:s.current.scrollHeight,behavior:"smooth"})}),v.current=(d==null?void 0:d.length)||0},[d==null?void 0:d.length]);const f=m.useCallback(g=>{g.preventDefault(),g.dataTransfer.dropEffect="move",s.current&&(s.current.scrollTop=s.current.scrollHeight)},[]);function w(g){u.includes(g)?p(y=>y.filter(N=>N!==g)):p(y=>[...y,g])}function x(g){o.current=g,n(!0)}const h=pe("config");return i.jsxs("div",{ref:s,className:"relative flex flex-col h-full pb-5 mx-auto gap-x-4 overflow-y-auto",children:[e&&i.jsx(es,{isOpen:e,onClose:()=>n(!1),section:o.current}),i.jsxs("div",{className:"relative flex flex-col flex-1 w-full gap-y-3",children:[d==null?void 0:d.map((g,y)=>i.jsx(is,{section:g,index:y,selectedSection:c,setSelectedSection:l,activeSections:u,toggleSection:w,handleSectionEdit:x,removeSection:a,formDataLength:d.length,onDragOver:f,setIsDragging:r},g.id)),i.jsx("div",{className:"flex justify-center",children:i.jsxs("button",{type:"button",onClick:()=>t(),style:{color:(h==null?void 0:h.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]})})]})]})},os=()=>{const{formData:e,uploadUrl:n}=m.useContext(ve),o=pe("config");return i.jsx(ki,{form_data:e,ignoreValidation:!0,config:o,uploadUrl:n,renderType:"multi"})};function as({questionData:e,uploadUrl:n}){const{setFormData:o,addSection:s,setUploadUrl:a,showPreview:t}=m.useContext(ve);m.useEffect(()=>{e&&e.length>0&&o(e)},[e,o]),m.useEffect(()=>{a(n)},[n,a]);const d=m.useCallback(r=>{r.preventDefault();try{const l=JSON.parse(r.dataTransfer.getData("properties"));if((l==null?void 0:l.type)==="section"){s();return}}catch(l){console.error("Drop error:",l)}},[]);return i.jsxs("div",{className:"flex gap-x-6 h-full",children:[i.jsx("div",{onDragOver:r=>r.preventDefault(),onDrop:r=>d(r),className:" h-full overflow-y-auto no-scrollbar max-h-[calc(100vh-80px)] flex-1 form_builder",children:i.jsx(ns,{})}),i.jsx(z.Transition,{show:t,as:"div",enter:"transition-all duration-300 ease-in-out origin-right",enterFrom:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",enterTo:"opacity-100 w-2/5 translate-x-0",leave:"transition-all duration-300 ease-in-out origin-right",leaveFrom:"opacity-100 w-2/5 translate-x-0",leaveTo:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",className:"shrink-0 overflow-y-auto no-scrollbar max-h-[calc(100vh-70px)] form_preview w-2/5",children:i.jsx("div",{className:"px-2 shadow_box min-w-[320px] bg-white border border-gray-100 rounded-lg",children:i.jsx(os,{})})})]})}const wi=[{key:"textFields",title:"Text Fields"},{key:"selectionFields",title:"Selection Fields"},{key:"dateAndTime",title:"Date & Time"},{key:"fileAndMedia",title:"File & Media"},{key:"layoutAndDisplay",title:"Layout & Display"},{key:"advancedData",title:"Advanced / Data"}],ss=()=>{const[e,n]=m.useState(""),{setIsDragging:o,addElement:s,selectedSection:a}=m.useContext(ve),t=m.useCallback((f,w)=>{if(!a){xe.toast.error("Please select a section to add an element.");return}f.dataTransfer.setData("properties",JSON.stringify(w)),f.dataTransfer.effectAllowed="move",o(!0)},[o,a]);function d(f){if(!a){xe.toast.error("Please select a section to add an element.");return}const w={...f,id:fe.v4(),sectionId:a};s(w,a)}const r=pe("config")||{},l=r.elementColor,c=r.elementBgColor,u=r.elementBorderColor,p=sa.filter(f=>f.label.toLowerCase().includes(e.toLowerCase())),v=wi==null?void 0:wi.map(f=>({title:f.title,elements:p.filter(w=>{var x;return(x=ta[f.key])==null?void 0:x.includes(w.type)})})).filter(f=>f.elements.length>0);return i.jsxs("div",{className:"pt-4 flex flex-col gap-y-6",children:[i.jsx("div",{className:"px-5",children:i.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:f=>n(f.target.value),name:"search",id:"search"})}),i.jsx("div",{className:"flex-1 overflow-y-auto no-scrollbar max-h-[calc(100vh-100px)]",children:i.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 ",children:v==null?void 0:v.map((f,w)=>{var x;return i.jsxs("li",{children:[i.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:f.title}),i.jsx("ul",{className:"grid grid-cols-2 gap-y-3 gap-x-4 mb-3",children:(x=f.elements)==null?void 0:x.map(h=>i.jsx("li",{onDragStart:g=>t(g,h),onDragEnd:()=>o(!1),onClick:()=>d(h),style:{borderColor:u,backgroundColor:c},className:`cursor-move text-[#475467] flex justify-between items-center \r
56
+ }`})})]})})}),wa=()=>i.jsx("blockquote",{className:"p-4 text-gray-700 bg-gray-100 rounded-md",children:i.jsxs("ul",{children:[i.jsxs("li",{className:"text-xs",children:["Method: GET ",i.jsx("br",{}),"URL format:"," ",i.jsx("code",{children:"https://example.com/validation/{documentId}"})]}),i.jsxs("li",{className:"text-xs",children:[i.jsx("span",{className:"block mb-1",children:" Response example format:"}),i.jsx("pre",{className:"p-2 bg-white rounded-md",children:i.jsxs("code",{children:["{ ",i.jsx("br",{}),'  "data": { ',i.jsx("br",{}),'    "status": true, ',i.jsx("br",{}),'    "isSigned": true ',i.jsx("br",{}),"  } ",i.jsx("br",{}),"}"]})})]})]})});function ka(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const vi=["text","number","boolean"],bn=["equals","not_equals","contains","not_contains"],Aa=["greater","less"];function Sa({register:e,setValue:n,trigger:o,watch:s,id:a}){const{formData:t}=m.useContext(ve),d=s("visibilityDependentFields")||[],r=m.useMemo(()=>{var c;return(c=ka(t).filter(u=>u.id!==a))==null?void 0:c.map(u=>{const p=d.find(v=>v.id===u.id);return{id:u.id,value:u.id,label:u.inputLabel,sectionId:u.sectionId,fieldType:(p==null?void 0:p.fieldType)||"text",operator:(p==null?void 0:p.operator)||"equals",fieldValue:(p==null?void 0:p.fieldValue)!==void 0?p.fieldValue:""}})},[t,d,a]),l=(c,u,p)=>{const v=d==null?void 0:d.map((f,w)=>w===c?{...f,[u]:p}:f);n("visibilityDependentFields",v)};return i.jsxs("div",{className:"visibility-editor",children:[i.jsx("label",{className:"label",children:"Select Dependent Fields"}),i.jsx(ui,{element:{options:r,id:"visibilityDependentFields",value:s("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:o,watch:s}}),d.length>0&&i.jsx("div",{className:"py-1 bg-gray-100 rounded dependent-fields",children:d==null?void 0:d.map((c,u)=>{var p,v;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:c.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.fieldType,onChange:f=>l(u,"fieldType",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldType}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:vi==null?void 0:vi.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f},f))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.operator,onChange:f=>l(u,"operator",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.operator.replace("_"," ")}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(p=c.fieldType==="number"?[...bn,...Aa]:bn)==null?void 0:p.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f.replace("_"," ")},f))})})]})})}),c.fieldType!=="boolean"?i.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:f=>l(u,"fieldValue",f.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(z.Listbox,{value:(v=c.fieldValue)!=null?v:"",onChange:f=>l(u,"fieldValue",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(z.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(z.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},c.id)})})]})}const Na=M.object().shape({inputLabel:M.string().nullable(),placeholder:M.string().nullable(),description:M.string().nullable(),isReadOnly:M.boolean(),isDisabled:M.boolean(),isRequired:M.boolean(),requiredMessage:M.string().nullable(),minLengthMessage:M.string().nullable(),maxLengthMessage:M.string().nullable(),maxLength:M.number().typeError("Expecting a number").nullable(),minLength:M.number().typeError("Expecting a number").nullable(),inputType:M.string().nullable(),maxAmountMessage:M.string().nullable(),maxAmount:M.string().nullable(),options:M.array().of(M.object().shape({label:M.string().nullable(),value:M.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),options1:M.array().of(M.object().shape({label:M.string().nullable(),value:M.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),prefix:M.string().nullable(),url:M.string().nullable(),method:M.string().nullable(),denominators:M.mixed().nullable(),responseType:M.string().nullable(),minAmount:M.string().nullable(),heading:M.string().nullable(),minAmountMessage:M.string().nullable(),columns:M.number().nullable().max(4).min(2),value:M.mixed().nullable(),customClass:M.string().nullable(),elementClass:M.string().nullable(),apiUrl:M.string().nullable(),selectType:M.string().default("list"),dateType:M.string().default("basic"),validationUrl:M.string(),signatureLink:M.string(),minDate:M.string().nullable(),maxDate:M.string().nullable(),canHaveDateRange:M.boolean(),allowYearPicker:M.boolean(),isHidden:M.boolean(),visibilityDependentFields:M.array().nullable(),isMultiple:M.boolean(),acceptedFiles:M.array(),showState:M.boolean()}),ja=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],_a=({isOpen:e,onClose:n,element:o})=>{const s=ja.filter(L=>!qe.includes(o.inputType)||L.key!=="validation"),{updateElement:a}=m.useContext(ve),[t,d]=m.useState("basic"),[r,l]=m.useState(!1),[c,u]=m.useState("manual"),p=pe("config"),{register:v,handleSubmit:f,control:w,setValue:x,watch:h,trigger:g,formState:{errors:y,isSubmitting:N,isValid:A},reset:S}=ke.useForm({resolver:mi(Na),defaultValues:{...o,options:o.options||[]}}),k=h(),{fields:j,append:I,remove:X}=ke.useFieldArray({control:w,name:"options"}),{fields:U,append:Z,remove:B}=ke.useFieldArray({control:w,name:"options1"}),{fields:F,append:D,remove:K}=ke.useFieldArray({control:w,name:"dataColumns"});m.useEffect(()=>{e||S()},[e,S]);const G=L=>{a(L,o.sectionId),n()},E={headers:{Authorization:`Bearer ${pe("token")}`}},T=m.useCallback(async()=>{var L,O,Q;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){xe.toast.info("Please provide a valid API URL");return}try{l(!0);const{status:se,data:J}=await _e.get(k.apiUrl,E);if(se!==200||!J){xe.toast.error("Unexpected response from server.");return}const ae=J.data||J.record||J.result;if(!Array.isArray(ae)){xe.toast.error("Expected an array in response (data, record, or result).");return}((L=o.type)==null?void 0:L.toLowerCase())==="datagrid"?x("dataColumns",ae):x("options",ae)}catch(se){const J=((Q=(O=se==null?void 0:se.response)==null?void 0:O.data)==null?void 0:Q.message)||(se==null?void 0:se.message)||"Unable to load options";xe.toast.error(J)}finally{l(!1)}},[o.type,x,k.apiUrl]),V=["manual","api","sheet"];function de(){c==="api"&&T()}const ee=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:V==null?void 0:V.map(L=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:O=>u(O.target.value),value:L})," ",i.jsxs("span",{children:[L," options"]})]},L))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:h,label:"Load Options from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]}),i.jsx("button",{onClick:de,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(fa,{})]}),c==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(mn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:x,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),j==null?void 0:j.map((L,O)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Label":"",name:`options.${O}.label`,register:v,errors:y,element:o,placeholder:"Label"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Value":"",name:`options.${O}.value`,register:v,errors:y,element:o,placeholder:"Value"})}),i.jsx("button",{disabled:j.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>X(O),children:i.jsx(W,{icon:"iconamoon:sign-times-fill"})})]},L.id))," ",i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>I({label:"",value:"",id:fe.v4()}),children:[i.jsx(W,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),o.type.toLowerCase()==="cascadeselect"&&i.jsxs(i.Fragment,{children:[i.jsx("hr",{className:"my-5"}),i.jsxs("div",{children:[" ",i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Child Options "}),U==null?void 0:U.map((L,O)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Label",name:`options1.${O}.label`,register:v,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Value",name:`options1.${O}.value`,register:v,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Key",name:`options1.${O}.key`,register:v,errors:y,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:U.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>B(O),children:i.jsx(W,{icon:"iconamoon:sign-times-fill"})})]},L.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>Z({label:"",value:"",key:"",id:fe.v4()}),children:[i.jsx(W,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),oe=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:V==null?void 0:V.map(L=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:O=>u(O.target.value),value:L,checked:L===c})," ",i.jsxs("span",{children:[L," options"]})]},L))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:h,label:"Load Columns from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/columns",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]})," ",i.jsx("button",{onClick:de,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(xa,{})]}),c==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(mn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:x,name:"dataColumns"})}),F==null?void 0:F.map((L,O)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"min-w-[140px]",children:i.jsx(Me,{label:O===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"}],register:v,name:`dataColumns.${O}.type`,setValue:x,trigger:g,value:k.dataColumns[O].type})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Field key":"",name:`dataColumns.${O}.field`,register:v,errors:y,element:o,placeholder:"fieldKey"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:O===0?"Display header":"",name:`dataColumns.${O}.headerName`,register:v,errors:y,element:o,placeholder:"header"})}),i.jsx("button",{disabled:F.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>K(O),children:i.jsx(W,{icon:"iconamoon:sign-times-fill"})})]},L.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>D({headerName:"",field:"",editable:!0,id:fe.v4(),type:"text",validate:!1}),children:[i.jsx(W,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),me=m.useCallback(async()=>{const L=pe("token"),{status:O,data:Q}=await _e.get(k.url,{headers:{Authorization:`Bearer ${L}`}});O===200&&x("options",(Q==null?void 0:Q.data)||Q)},[x,k.url]);m.useEffect(()=>{o.type==="document"&&k.url&&me()},[k.url,o.type,me]);const ce=i.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default",onMouseDown:L=>L.stopPropagation(),onPointerDown:L=>L.stopPropagation(),onDragStart:L=>{L.preventDefault(),L.stopPropagation()},children:i.jsxs("div",{className:"w-full lg:w-2/3 xl:w-2/5 bg-white h-screen shadow-xl relative flex flex-col items-center",children:[i.jsx("button",{className:"bg-white h-10 w-10 flex justify-center items-center absolute top-1 -left-12 rounded-lg hover:bg-gray-50",onClick:n,children:i.jsx(W,{icon:"tabler:x",iconClass:"text-xl"})}),i.jsx("div",{className:"w-full pt-4",children:i.jsx(na,{tabs:s,setActiveTab:d,activeTab:t,className:"justify-start !text-left",btnClass:" !text-left"})}),i.jsxs("form",{onSubmit:f(G),className:"w-full flex-1 flex flex-col",children:[i.jsxs("div",{className:"flex-1",children:[" ",i.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[t==="basic"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[bi.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(H,{watch:h,label:"Value",name:"value",register:v,errors:y,element:o})}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:h,label:"Label",name:"inputLabel",register:v,errors:y,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(H,{watch:h,label:"Child Label",name:"childLabel",register:v,errors:y,element:o})]}),ua.includes(o.inputType)&&i.jsx(H,{watch:h,label:"Placeholder",name:"placeholder",register:v,errors:y,element:o}),da.includes(o.inputType)&&i.jsx(H,{watch:h,label:"Prefix",name:"prefix",register:v,errors:y,element:o}),ba.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(ha,{}),i.jsx(H,{watch:h,label:"Api Url",name:"url",register:v,errors:y,element:o}),i.jsx(Me,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:v,name:"method",setValue:x,trigger:g,value:h("method")}),i.jsx(Me,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:v,name:"responseType",setValue:x,trigger:g,value:h("responseType")})]}),va.includes(o.inputType)&&i.jsx(ga,{onChange:L=>{x("denominators",L)},value:h("denominators")}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsx(H,{watch:h,label:"Short Description",name:"description",register:v,errors:y,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Me,{label:"Date Format",options:la,register:v,name:"dateFormat",setValue:x,trigger:g,value:h("dateFormat")}),i.jsx(H,{watch:h,label:"Allow Range",name:"canHaveDateRange",register:v,errors:y,element:o,type:"checkbox",value:k.canHaveDateRange}),(k==null?void 0:k.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx(Qe,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select min date"}),i.jsx(Qe,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),i.jsx(H,{watch:h,label:"Allow Year Picker",name:"allowYearPicker",register:v,errors:y,element:o,type:"checkbox",value:k.allowYearPicker})]}),o.type.toLowerCase()==="country"&&i.jsx(H,{watch:h,label:"Allow States",name:"showState",register:v,errors:y,element:o,type:"checkbox",value:k.showState}),o.type.toLowerCase()==="selectfield"&&i.jsx(Me,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:v,name:"selectType",setValue:x,trigger:g,value:h("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(H,{watch:h,label:"Number of columns (max: 4)",name:"columns",register:v,errors:y,element:o,max:4,min:1}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:h,label:"Document Options Url",name:"url",register:v,errors:y,element:o})," ",i.jsx(ya,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:h,label:"Document Validation Url",name:"validationUrl",register:v,errors:y,element:o}),i.jsx(wa,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(H,{watch:h,label:"Signature Page Url",name:"signatureLink",register:v,errors:y,element:o})})]}),o.type.toLowerCase()==="datagrid"&&oe(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:h,label:"Allow Multiple Uploads",name:"isMultiple",register:v,errors:y,element:o,type:"checkbox",value:k.isMultiple}),i.jsx(ui,{element:{options:pa,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:v,setValue:x,trigger:g,watch:h},placeholder:"Choose file types"})]}),ma.includes(o.inputType)&&ee(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(H,{watch:h,label:"Toggle Visibility",name:"isHidden",register:v,errors:y,element:o,type:"checkbox",value:k.isHidden})})," ",k.isHidden&&i.jsx(Sa,{register:v,setValue:x,trigger:g,watch:h,id:o==null?void 0:o.id})]})]}),!qe.includes(o.type.toLowerCase())&&t==="validation"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Required",name:"isRequired",register:v,errors:y,element:o,type:"checkbox",value:k.isRequired})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"requiredMessage",register:v,errors:y,element:o})})]}),ra.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Min Length",name:"minLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"minLengthMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Max Length",name:"maxLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"maxLengthMessage",register:v,errors:y,element:o})})]})]}),ca.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Min Amount",name:"minAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"minAmountMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:h,label:"Max Amount",name:"maxAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:h,label:"Error message text",name:"maxAmountMessage",register:v,errors:y,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest editor_option__cancel",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!A||N,style:{background:(p==null?void 0:p.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!A||N?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!A||N?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:N?"Saving...":"Save"})]})]})]})});return document.body?Pn.createPortal(ce,document.body):ce},pi=m.memo(({state:e,element:n,children:o})=>{const[s,a]=m.useState(!1),{removeElement:t,duplicateElement:d}=m.useContext(ve),r=m.useMemo(()=>{var c;return(c=n==null?void 0:n.acceptedFiles)==null?void 0:c.map(u=>u.label).join(", ")},[n]),l=m.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return i.jsxs("div",{className:"w-full",children:[s&&i.jsx(_a,{isOpen:s,onClose:()=>a(!1),element:n}),i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("span",{children:[" ",n.inputLabel&&i.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",r&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",r==null?void 0:r.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[!n.gridPosition&&i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1",onClick:()=>d(n==null?void 0:n.id,n.sectionId),title:"Duplicate",children:i.jsx(W,{icon:"tabler:copy",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:()=>a(!0),title:"Edit",children:i.jsx(W,{icon:"circum:edit",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:l,title:"Remove",children:i.jsx(W,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});pi.displayName="ElementContainer";function Ca({element:e,validationData:n}){const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:d}=n||{};let r;return t&&(r=t()[e.id]),i.jsx(H,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:s,setValue:a,value:r,prefix:e.prefix,disabled:d,watch:t})}function Ma(e){if(!e)return!1;const n=/^data:image\/(jpeg|png|gif|bmp|webp);base64,/i,o=/\.(jpeg|jpg|png|gif|bmp|webp)$/i;return n.test(e)||o.test(e)}const Ea=({imageUrl:e})=>{const[n,o]=m.useState(!1),s=()=>{o(!0)},a=()=>{o(!1)};return i.jsxs("div",{children:[i.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:s,src:e||"/place.png","data-toggle":"tooltip","data-placement":"top",title:"Click to view"}),n&&i.jsx("div",{className:"modal",style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",justifyContent:"center",alignItems:"center"},onClick:a,children:i.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:t=>t.stopPropagation(),children:[i.jsx("span",{className:"close",onClick:a,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),i.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function Ta({element:e,validationData:n}){var k;const{register:o=()=>({}),setValue:s,watch:a}=n||{},[t,d]=m.useState(),[r,l]=m.useState(!1),[c,u]=m.useState(!1),[p,v]=m.useState(""),f=a&&a(e==null?void 0:e.id);m.useEffect(()=>{d(f)},[f]);const[w,x]=m.useState("");m.useEffect(()=>{o(e.id)},[e.id,o]);const{url:h,method:g,responseType:y}=e||{},A={headers:{Authorization:`Bearer ${pe("token")}`}},S=m.useCallback(async j=>{var I,X,U,Z,B,F,D,K,G,P,E;if(!(!h||!g)){l(!0);try{let T;if(g.toLowerCase()==="get"){const V=`${h}?value=${j}`;T=await _e.get(V,A)}else if(g.toLowerCase()==="post")T=await _e.post(h,{value:j},A);else throw new Error("Unsupported HTTP method");T.status===200&&((((X=(I=T==null?void 0:T.data)==null?void 0:I.data)==null?void 0:X.status)||((U=T==null?void 0:T.data)==null?void 0:U.status))===!0?(u(!0),y==="string"?v(((B=(Z=T==null?void 0:T.data)==null?void 0:Z.data)==null?void 0:B.description)||((F=T==null?void 0:T.data)==null?void 0:F.description)||"Validation successful"):x(((K=(D=T==null?void 0:T.data)==null?void 0:D.data)==null?void 0:K.description)||((G=T==null?void 0:T.data)==null?void 0:G.description)||{})):(console.error("Invalid input:",j),v("Unable to validate input"),u(!1)))}catch(T){console.error("Error validating input:",T),v(((E=(P=T==null?void 0:T.response)==null?void 0:P.data)==null?void 0:E.message)||"Unable to validate input"),u(!1)}finally{l(!1)}}},[g,y,h]);return m.useEffect(()=>{if(t){const j=setTimeout(()=>{S(t)},700);return()=>clearTimeout(j)}},[S,t]),i.jsxs("div",{children:[i.jsxs("div",{className:"relative flex items-center",children:[i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:q("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:j=>{d(j.target.value),s(e==null?void 0:e.id,j.target.value)},disabled:n==null?void 0:n.isReadOnly}),i.jsxs("span",{className:"absolute right-0",children:[r&&i.jsxs("span",{children:[" ",i.jsxs("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})]}),c&&!r&&i.jsx("span",{className:"block pr-3 text-lg text-green-600",children:i.jsx(W,{icon:"gg:check-o"})})]})]}),p&&y==="string"&&i.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:p}),y==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(k=Object.entries(w))==null?void 0:k.map(([j,I])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[j,":"]}),Ma(I)?i.jsx(Ea,{imageUrl:I}):i.jsx("span",{children:String(I)})]},j))})]})}function Ba({onGetTotal:e,readOnly:n,defaultValue:o,denominators:s}){const[a,t]=m.useState([...o]);function d(c,u){t(p=>{const v=[...p];return v[u]={...v[u],value:c},v})}function r(c,u){return parseFloat(c)*parseFloat(u)||0}const l=m.useMemo(()=>a.reduce((c,u)=>{const p=r(u.key,u.value);return c+p},0),[a]);return m.useEffect(()=>{e&&e(a)},[a]),m.useEffect(()=>{if(s!=null&&s.length){const c=s==null?void 0:s.map((u,p)=>({key:u.value,value:Array.isArray(o)&&o[p]?o[p].value:""}));t(c)}},[o,s]),i.jsx("div",{className:"mt-2",children:i.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{className:"",children:"Denomination"})}),i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{children:"Quantity"})}),i.jsx("div",{className:"px-4 py-2",children:i.jsx("span",{children:"Sub total"})})]}),a==null?void 0:a.map((c,u)=>{var p,v;return i.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[i.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:i.jsx("span",{className:"",children:(p=parseFloat(c.key))==null?void 0:p.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(Ge,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:f=>d(f,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(v=r(c.key,c.value))==null?void 0:v.toLocaleString()})})]},u+"index")}),i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),i.jsx("div",{className:"px-4 py-3",children:l==null?void 0:l.toLocaleString()})]})]})})}function La({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,getValues:a}=n||{},t=a&&a(e==null?void 0:e.id)||[];return m.useEffect(()=>{o(e.id)},[e.id,o]),i.jsx("div",{children:i.jsx(Ba,{onGetTotal:d=>{s&&s(e.id,d)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:t,readOnly:e==null?void 0:e.isReadOnly})})}function Pa({element:e}){return i.jsx("div",{className:q("py-6",e==null?void 0:e.customClass)})}function Da({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:q("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Ia({element:e,validationData:n}){const{register:o=()=>({})}=n||{};return i.jsx("div",{children:i.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...o(e==null?void 0:e.id)})})}function Oa({element:e,state:n}){return i.jsx(i.Fragment,{children:i.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&i.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function Ka({row:e,columns:n,isReadOnly:o,editingCell:s,setEditingCell:a,handleCellChange:t,debouncedValidate:d,getValidationStatus:r,deleteRow:l}){const c=u=>(s==null?void 0:s.rowId)===e.id&&(s==null?void 0:s.field)===u;return i.jsxs("tr",{children:[n.map(u=>{var y;const p=e[u.field],v=u.editable&&!o,f=c(u.field),{isValidating:w,result:x}=r(e.id,u.field);let h="border-gray-300";u.validate&&((x==null?void 0:x.isValid)===!1?h="border-red-500 bg-red-50":(x==null?void 0:x.isValid)===!0&&(h="border-green-500 bg-green-50"));const g=`w-full px-2 py-1 border rounded outline-none ${h}`;return i.jsx("td",{title:o?"":"Double click to edit",className:"px-3 py-1 border",onDoubleClick:()=>v&&a({rowId:e.id,field:u.field}),children:v&&f?i.jsxs("div",{className:"relative",children:[u.type==="number"?i.jsx(Ge,{value:p,decimalsLimit:6,allowNegativeValue:!1,className:g,onValueChange:N=>t(N,e.id,u.field),onBlur:()=>{a(null),d(p,e.id,u.field,u)},autoFocus:!0}):u.type==="checkbox"?i.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(N=>{const A=N==="yes",S=`radio-${e.id}-${String(u.field)}-${N}`;return i.jsxs("label",{htmlFor:S,className:"flex items-center gap-1 cursor-pointer",children:[i.jsx("input",{id:S,type:"radio",name:`boolean-${e.id}-${String(u.field)}`,checked:p===A,onChange:()=>t(A,e.id,u.field)}),i.jsx("span",{className:"text-sm",children:A?"Yes":"No"})]},N)})}):i.jsx("input",{type:"text",value:String(p!=null?p:""),onChange:N=>t(N.target.value,e.id,u.field),onBlur:()=>{a(null),d(p,e.id,u.field,u)},className:g,autoFocus:!0}),w&&i.jsx("div",{className:"absolute right-1 top-1",children:i.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):u.validate&&x?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{children:[String(p!=null?p:"")," ",x.data&&`[${x.data}]`]}),x.isValid?i.jsx("span",{className:"text-xs text-green-600",children:"✓"}):i.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(y=x.error)!=null?y:"",children:"✗"})]}):u.type==="checkbox"?i.jsx("span",{className:"block py-1 text-gray-700",children:p===!0?"Yes":p===!1?"No":""}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:String(p!=null?p:"")})},String(u.id))}),!o&&i.jsx("td",{className:"px-3 py-1 text-center border",children:i.jsx("button",{type:"button",onClick:()=>l(e.id),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:i.jsx(W,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const Ga=m.memo(Ka);function Ra({value:e=[],onChange:n,isReadOnly:o=!1,columns:s}){const[a,t]=m.useState(e),[d,r]=m.useState(null),l=m.useRef(null),[c,u]=m.useState(0);m.useEffect(()=>{const x=document.getElementById("form");if(!x)return;const h=y=>{const N=y.getBoundingClientRect().width;u(N?N-58:0)};h(x);const g=new ResizeObserver(y=>{for(const N of y)h(N.target)});return g.observe(x),()=>g.disconnect()},[]),m.useEffect(()=>{t(x=>JSON.stringify(x)!==JSON.stringify(e)?e:x)},[e]),m.useEffect(()=>{n==null||n(a)},[a,n]),m.useEffect(()=>{const x=h=>{l.current&&!l.current.contains(h.target)&&r(null)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);const p=m.useCallback((x,h,g)=>{t(y=>y.map(N=>N.id===h?{...N,[g]:x}:N))},[]),v=m.useCallback(()=>{const x=fe.v4(),h=s.reduce((g,y)=>(g[y.field]=y.field==="id"?x:"",g),{});t(g=>[...g,{id:x,...h}])},[s]),f=m.useCallback(x=>{t(h=>h.filter(g=>g.id!==x))},[]),w=m.useCallback(()=>({isValidating:!1,result:void 0}),[]);return i.jsxs("div",{className:"mt-3 rounded",ref:l,children:[i.jsx("div",{className:"flex justify-end",children:!o&&i.jsx("button",{onClick:v,type:"button",className:"px-2 py-1 mb-3 text-xs text-white bg-gray-600 rounded hover:bg-gray-700",children:"Add Row"})}),i.jsx("div",{className:"w-full max-w-full overflow-x-auto",style:{maxWidth:`${c}px`},children:i.jsxs("table",{className:"min-w-max w-full text-sm border-collapse rounded table-auto bg-gray-50",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"bg-gray-100",children:[s.map((x,h)=>{var g;return i.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border whitespace-nowrap",children:[(g=x.headerName)!=null?g:String(x.field),x.validate&&i.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(x.id)}-${h}`)}),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:a.length>0?a.map(x=>i.jsx(Ga,{row:x,columns:s,isReadOnly:o,editingCell:d,setEditingCell:r,handleCellChange:p,debouncedValidate:()=>{},getValidationStatus:w,deleteRow:f},x.id)):i.jsx("tr",{children:i.jsx("td",{colSpan:s.length+(o?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})})]})}function za({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t}=n||{},d=a&&a(e==null?void 0:e.id)||[];m.useEffect(()=>{o(e.id)},[e.id,o]);const r=m.useCallback(l=>{s==null||s(e.id,l)},[e.id,s]);return i.jsx(Ra,{value:d,onChange:r,columns:e==null?void 0:e.dataColumns,isReadOnly:t})}const vn=({className:e="",options:n=[],placeholder:o="Select",errors:s,register:a,setValue:t,name:d,label:r,value:l,trigger:c,isMultiple:u=!1,isFloatingLabel:p=!1,subText:v,labelClass:f="",loading:w,disabled:x})=>{const[h,g]=m.useState(u?[]:null),y=q("custom-select__control",e),N=m.useMemo(()=>n,[n]);return m.useEffect(()=>{const A=n==null?void 0:n.find(S=>{var k;return typeof S.value=="string"&&typeof l=="string"?S.value.toLowerCase()===l.toLowerCase():typeof S.value=="object"&&typeof l=="object"?((k=S.value)==null?void 0:k.id)===(l==null?void 0:l.id):S.value===l});g(A||null)},[l,n]),m.useEffect(()=>{h&&t&&a&&(t(d,h==null?void 0:h.value),a(d),c==null||c(d))},[d,h]),i.jsxs("div",{className:"custom-select",children:[r&&!p&&i.jsx("label",{className:"custom-select__label",children:r}),p&&r&&i.jsx("label",{className:q("custom-select__floating-label",f),children:r}),i.jsx(z.Listbox,{value:h,onChange:g,multiple:u,disabled:x,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(z.Listbox.Button,{className:y,disabled:x,children:[w?i.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):i.jsx("span",{className:"custom-select__value",children:(h==null?void 0:h.label)||i.jsx("span",{className:"custom-select__placeholder",children:o})}),i.jsx("span",{className:"custom-select__icon",children:i.jsx(W,{icon:"lucide:chevron-down"})})]}),i.jsx(z.Transition,{as:m.Fragment,leave:"custom-select__transition",children:i.jsx(z.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:N==null?void 0:N.map((A,S)=>i.jsx(z.Listbox.Option,{value:A,className:({active:k})=>q("custom-select__option",k&&"custom-select__option--active"),children:({selected:k})=>i.jsx("span",{className:q("custom-select__option-label",k&&"custom-select__option--selected"),children:A.label})},S))})})]})}),v&&!s&&i.jsx("p",{className:"custom-select__subtext",children:v}),s&&i.jsx("span",{className:"custom-select__error",children:s.message})]})},Ha=({element:e,validationData:n})=>{var x;const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:d}=n||{},r=(x=e==null?void 0:e.id)!=null?x:"cascadeValue",[l,c]=m.useState(""),[u,p]=m.useState(""),v=(h,g)=>{const y=h&&g?`${h}_${g}`:"";a==null||a(r,y),s==null||s(r)},f=(h,g)=>{h==="first"?(c(g),p(""),v(g,"")):(p(g),v(l,g))};m.useEffect(()=>{if(t){const h=t(r);if(h!=null&&h.includes("_")){const[g,y]=h.split("_");c(g),p(y)}}},[t,r]);const w=m.useMemo(()=>{var h;return(h=e.options1)==null?void 0:h.filter(g=>g.key===l)},[e.options1,l]);return!e.options||!e.options1?null:i.jsxs("div",{children:[i.jsx("input",{type:"hidden",...o(r)}),i.jsx("div",{className:"relative",children:i.jsx(vn,{setValue:(h,g)=>f("first",g),options:e.options,name:`${r}`,register:o,value:l})}),l&&i.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&i.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),i.jsx(vn,{setValue:(h,g)=>f("second",g),options:w,name:`${r}`,register:o,value:u})]})]})},Fa=({value:e=0,max:n=5,readOnly:o=!1,onChange:s,size:a=24,className:t="",element:d,validationData:r})=>{var g;const{register:l=()=>({}),trigger:c,setValue:u,watch:p,isReadOnly:v}=r||{},f=(g=p==null?void 0:p(d.id))!=null?g:0,[w,x]=m.useState(null);m.useEffect(()=>{f==null&&(u==null||u(d.id,e))},[]);const h=y=>{if(!o&&!v){const N=y+1;u==null||u(d.id,N),c==null||c(d.id),s==null||s(N)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...l(d.id)}),Array.from({length:n},(y,N)=>{const A=w!==null?N<=w:N<f;return i.jsx(rn,{icon:A?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${A?"text-yellow-400":"text-gray-300"}`,width:a,height:a,onMouseEnter:()=>!(o||v)&&x(N),onMouseLeave:()=>!(o||v)&&x(null),onClick:()=>h(N)},N)})]})};function pn({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,trigger:a,isReadOnly:t,watch:d}=n||{},r=(d==null?void 0:d(e.id))||"",{country:l,state:c}=m.useMemo(()=>{var w;if(typeof r=="string"&&r.includes(",")){const[x,h]=(w=r.split(","))==null?void 0:w.map(g=>g.trim());return{country:h,state:x}}return{country:r,state:""}},[r]),u=m.useRef(r),p=m.useMemo(()=>{var w,x;return l?((x=(w=We.find(h=>h.name===l))==null?void 0:w.states)==null?void 0:x.map(h=>({label:h.name,value:h.name})))||[]:[]},[l]),v=(w,x)=>{const g=(x==null?void 0:x.value)||"";s&&g!==u.current&&(s(e.id,g),a==null||a(e.id),u.current=g)},f=(w,x)=>{const h=(x==null?void 0:x.value)||"",g=h?`${h}, ${l}`:l;s&&g!==u.current&&(s(e.id,g),a==null||a(e.id),u.current=g)};return m.useEffect(()=>{u.current=r},[r]),i.jsxs("div",{className:"grid gap-y-6",children:[i.jsx("input",{type:"hidden",...o(e.id)}),i.jsx(ci,{options:e.options,onGetValue:v,name:`${e.id}-country`,readOnly:t,defaultValue:l},`country-${l}`),p.length>0&&e.showState&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),i.jsx(ci,{options:p,onGetValue:f,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function Va({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:s}=n||{},{validationUrl:a,documentObj:t,signatureLink:d}=e,r=m.useMemo(()=>pe("config"),[]),[l,c]=m.useState(!1),[u,p]=m.useState(!1),v=m.useCallback(async()=>{var f,w;if(!(!a||!t))try{p(!0);const h={headers:{Authorization:`Bearer ${pe("token")}`}},{data:g}=await _e.get(`${a}/${t}`,h),y=!!((w=(f=g==null?void 0:g.data)==null?void 0:f.isSigned)!=null?w:g!=null&&g.isSigned);return c(y),y}catch(x){console.error("Failed to check sign status",x)}finally{p(!1)}},[a,t]);return m.useEffect(()=>{let f=null;return!l&&t&&a&&(async()=>{await v()||(f=setInterval(async()=>{await v()&&f&&clearInterval(f)},2e3))})(),()=>{f&&clearInterval(f)}},[v,l,t,a]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:q("field-control",e.customClass),...o(e.id),disabled:s}),i.jsx("a",{href:l?"#":d,children:i.jsxs("button",{type:"button",onClick:v,disabled:u||l,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:q("flex items-center gap-x-1 rounded-lg border border-gray-200 bg-gray-200 px-3 py-[10px] text-sm text-white",{"!opacity-60":u}),children:[i.jsx(W,{icon:u?"solar:refresh-outline":l?"solar:check-circle-bold":"solar:pen-2-line-duotone",iconClass:u?"animate-spin":""}),u?"Checking...":l?"Signed":"Sign"]})})]})}const gi=[{code:"DZ",label:"Algeria",phone:"213",min:9,max:9},{code:"AO",label:"Angola",phone:"244",min:9,max:9},{code:"BJ",label:"Benin",phone:"229",min:8,max:8},{code:"BW",label:"Botswana",phone:"267",min:7,max:7},{code:"BF",label:"Burkina Faso",phone:"226",min:8,max:8},{code:"BI",label:"Burundi",phone:"257",min:8,max:8},{code:"CM",label:"Cameroon",phone:"237",min:9,max:9},{code:"CV",label:"Cape Verde",phone:"238",min:7,max:7},{code:"CF",label:"Central African Republic",phone:"236",min:8,max:8},{code:"TD",label:"Chad",phone:"235",min:8,max:8},{code:"KM",label:"Comoros",phone:"269",min:7,max:7},{code:"CG",label:"Congo",phone:"242",min:9,max:9},{code:"CD",label:"Democratic Republic of Congo",phone:"243",min:9,max:9},{code:"CI",label:"Cote d'Ivoire",phone:"225",min:8,max:8},{code:"DJ",label:"Djibouti",phone:"253",min:8,max:8},{code:"EG",label:"Egypt",phone:"20",min:10,max:10},{code:"GQ",label:"Equatorial Guinea",phone:"240",min:9,max:9},{code:"ER",label:"Eritrea",phone:"291",min:7,max:7},{code:"ET",label:"Ethiopia",phone:"251",min:9,max:9},{code:"GA",label:"Gabon",phone:"241",min:7,max:7},{code:"GM",label:"Gambia",phone:"220",min:7,max:7},{code:"GH",label:"Ghana",phone:"233",min:9,max:9},{code:"GN",label:"Guinea",phone:"224",min:9,max:9},{code:"GW",label:"Guinea-Bissau",phone:"245",min:9,max:9},{code:"KE",label:"Kenya",phone:"254",min:7,max:9},{code:"LS",label:"Lesotho",phone:"266",min:8,max:8},{code:"LR",label:"Liberia",phone:"231",min:8,max:9},{code:"LY",label:"Libya",phone:"218",min:9,max:10},{code:"MG",label:"Madagascar",phone:"261",min:9,max:9},{code:"MW",label:"Malawi",phone:"265",min:9,max:9},{code:"ML",label:"Mali",phone:"223",min:8,max:8},{code:"MR",label:"Mauritania",phone:"222",min:8,max:8},{code:"MU",label:"Mauritius",phone:"230",min:8,max:8},{code:"MA",label:"Morocco",phone:"212",min:9,max:9},{code:"MZ",label:"Mozambique",phone:"258",min:9,max:9},{code:"NA",label:"Namibia",phone:"264",min:9,max:9},{code:"NE",label:"Niger",phone:"227",min:8,max:8},{code:"NG",label:"Nigeria",phone:"234",min:10,max:10},{code:"RW",label:"Rwanda",phone:"250",min:9,max:9},{code:"ST",label:"Sao Tome and Principe",phone:"239",min:7,max:7},{code:"SN",label:"Senegal",phone:"221",min:9,max:9},{code:"SC",label:"Seychelles",phone:"248",min:7,max:7},{code:"SL",label:"Sierra Leone",phone:"232",min:8,max:8},{code:"SO",label:"Somalia",phone:"252",min:8,max:9},{code:"ZA",label:"South Africa",phone:"27",min:10,max:10},{code:"SS",label:"South Sudan",phone:"211",min:9,max:9},{code:"SD",label:"Sudan",phone:"249",min:9,max:9},{code:"TZ",label:"Tanzania",phone:"255",min:9,max:9},{code:"TG",label:"Togo",phone:"228",min:8,max:8},{code:"TN",label:"Tunisia",phone:"216",min:8,max:8},{code:"UG",label:"Uganda",phone:"256",min:9,max:9},{code:"ZM",label:"Zambia",phone:"260",min:9,max:9},{code:"ZW",label:"Zimbabwe",phone:"263",min:9,max:9},{code:"US",label:"United States",phone:"1",min:10,max:10},{code:"CA",label:"Canada",phone:"1",min:10,max:10},{code:"GB",label:"United Kingdom",phone:"44",min:9,max:10},{code:"FR",label:"France",phone:"33",min:9,max:9},{code:"DE",label:"Germany",phone:"49",min:10,max:11},{code:"IT",label:"Italy",phone:"39",min:9,max:10},{code:"ES",label:"Spain",phone:"34",min:9,max:9},{code:"NL",label:"Netherlands",phone:"31",min:9,max:9},{code:"RU",label:"Russia",phone:"7",min:10,max:10},{code:"CN",label:"China",phone:"86",min:11,max:11},{code:"IN",label:"India",phone:"91",min:10,max:10},{code:"JP",label:"Japan",phone:"81",min:10,max:10},{code:"KR",label:"South Korea",phone:"82",min:8,max:9},{code:"BR",label:"Brazil",phone:"55",min:10,max:11},{code:"MX",label:"Mexico",phone:"52",min:10,max:10},{code:"AR",label:"Argentina",phone:"54",min:10,max:10},{code:"CL",label:"Chile",phone:"56",min:9,max:9},{code:"AU",label:"Australia",phone:"61",min:9,max:9},{code:"NZ",label:"New Zealand",phone:"64",min:8,max:9},{code:"SA",label:"Saudi Arabia",phone:"966",min:9,max:9},{code:"AE",label:"United Arab Emirates",phone:"971",min:9,max:9},{code:"TR",label:"Turkey",phone:"90",min:10,max:11},{code:"IR",label:"Iran",phone:"98",min:7,max:10},{code:"PK",label:"Pakistan",phone:"92",min:10,max:10},{code:"BD",label:"Bangladesh",phone:"880",min:10,max:10},{code:"ID",label:"Indonesia",phone:"62",min:9,max:11},{code:"PH",label:"Philippines",phone:"63",min:10,max:10},{code:"CO",label:"Colombia",phone:"57",min:10,max:10},{code:"VE",label:"Venezuela",phone:"58",min:10,max:10},{code:"PE",label:"Peru",phone:"51",min:9,max:9},{code:"EC",label:"Ecuador",phone:"593",min:9,max:9},{code:"UY",label:"Uruguay",phone:"598",min:8,max:8},{code:"PY",label:"Paraguay",phone:"595",min:9,max:9},{code:"BO",label:"Bolivia",phone:"591",min:8,max:8},{code:"GT",label:"Guatemala",phone:"502",min:8,max:8},{code:"HN",label:"Honduras",phone:"504",min:8,max:8},{code:"SV",label:"El Salvador",phone:"503",min:8,max:8},{code:"NI",label:"Nicaragua",phone:"505",min:8,max:8},{code:"CR",label:"Costa Rica",phone:"506",min:8,max:8},{code:"PA",label:"Panama",phone:"507",min:8,max:8},{code:"JM",label:"Jamaica",phone:"1",min:10,max:10},{code:"TT",label:"Trinidad and Tobago",phone:"1",min:10,max:10},{code:"AD",label:"Andorra",phone:"376",min:6,max:6},{code:"AF",label:"Afghanistan",phone:"93",min:9,max:9},{code:"AG",label:"Antigua and Barbuda",phone:"1-268",min:7,max:7},{code:"AI",label:"Anguilla",phone:"1-264",min:7,max:7},{code:"AL",label:"Albania",phone:"355",min:8,max:8},{code:"AM",label:"Armenia",phone:"374",min:8,max:8},{code:"AS",label:"American Samoa",phone:"1-684",min:7,max:7},{code:"AT",label:"Austria",phone:"43",min:10,max:10},{code:"AW",label:"Aruba",phone:"297",min:7,max:7},{code:"AX",label:"Åland Islands",phone:"358",min:6,max:6},{code:"AZ",label:"Azerbaijan",phone:"994",min:9,max:9},{code:"BA",label:"Bosnia and Herzegovina",phone:"387",min:8,max:8},{code:"BB",label:"Barbados",phone:"1-246",min:7,max:7},{code:"BE",label:"Belgium",phone:"32",min:9,max:9},{code:"BG",label:"Bulgaria",phone:"359",min:9,max:9},{code:"BH",label:"Bahrain",phone:"973",min:8,max:8},{code:"BL",label:"Saint Barthélemy",phone:"590",min:9,max:9},{code:"BM",label:"Bermuda",phone:"1-441",min:7,max:7},{code:"BN",label:"Brunei Darussalam",phone:"673",min:7,max:7},{code:"BQ",label:"Bonaire, Sint Eustatius and Saba",phone:"599",min:7,max:7},{code:"BS",label:"Bahamas",phone:"1-242",min:7,max:7},{code:"BT",label:"Bhutan",phone:"975",min:8,max:8},{code:"BV",label:"Bouvet Island",phone:"47",min:8,max:8},{code:"BY",label:"Belarus",phone:"375",min:9,max:9},{code:"BZ",label:"Belize",phone:"501",min:7,max:7},{code:"CC",label:"Cocos (Keeling) Islands",phone:"61",min:7,max:7},{code:"CH",label:"Switzerland",phone:"41",min:9,max:9},{code:"CK",label:"Cook Islands",phone:"682",min:5,max:5},{code:"CU",label:"Cuba",phone:"53",min:8,max:8},{code:"CW",label:"Curaçao",phone:"599",min:7,max:7},{code:"CX",label:"Christmas Island",phone:"61",min:7,max:7},{code:"CY",label:"Cyprus",phone:"357",min:8,max:8},{code:"CZ",label:"Czechia",phone:"420",min:9,max:9},{code:"DK",label:"Denmark",phone:"45",min:8,max:8},{code:"DM",label:"Dominica",phone:"1-767",min:7,max:7},{code:"DO",label:"Dominican Republic",phone:"1-809",min:7,max:7},{code:"EE",label:"Estonia",phone:"372",min:8,max:8},{code:"EH",label:"Western Sahara",phone:"212",min:9,max:9},{code:"FI",label:"Finland",phone:"358",min:9,max:9},{code:"FJ",label:"Fiji",phone:"679",min:7,max:7},{code:"FM",label:"Micronesia (Federated States of)",phone:"691",min:7,max:7},{code:"FO",label:"Faroe Islands",phone:"298",min:6,max:6},{code:"GD",label:"Grenada",phone:"1-473",min:7,max:7},{code:"GE",label:"Georgia",phone:"995",min:9,max:9},{code:"GF",label:"French Guiana",phone:"594",min:9,max:9},{code:"GG",label:"Guernsey",phone:"44",min:9,max:9},{code:"GI",label:"Gibraltar",phone:"350",min:8,max:8},{code:"GL",label:"Greenland",phone:"299",min:6,max:6},{code:"GP",label:"Guadeloupe",phone:"590",min:9,max:9},{code:"GR",label:"Greece",phone:"30",min:10,max:10},{code:"GS",label:"South Georgia and the South Sandwich Islands",phone:"500",min:6,max:6},{code:"GU",label:"Guam",phone:"1-671",min:10,max:10},{code:"GY",label:"Guyana",phone:"592",min:7,max:7},{code:"HK",label:"Hong Kong",phone:"852",min:8,max:8},{code:"HM",label:"Heard Island and McDonald Islands",phone:"672",min:6,max:6},{code:"HR",label:"Croatia",phone:"385",min:9,max:9},{code:"HT",label:"Haiti",phone:"509",min:8,max:8},{code:"HU",label:"Hungary",phone:"36",min:9,max:9},{code:"IE",label:"Ireland",phone:"353",min:9,max:9},{code:"IM",label:"Isle of Man",phone:"44",min:9,max:9},{code:"IO",label:"British Indian Ocean Territory",phone:"246",min:7,max:7},{code:"IQ",label:"Iraq",phone:"964",min:10,max:10},{code:"IS",label:"Iceland",phone:"354",min:7,max:7},{code:"JE",label:"Jersey",phone:"44",min:9,max:9},{code:"JO",label:"Jordan",phone:"962",min:9,max:9},{code:"KG",label:"Kyrgyzstan",phone:"996",min:9,max:9},{code:"KH",label:"Cambodia",phone:"855",min:9,max:9},{code:"KI",label:"Kiribati",phone:"686",min:7,max:7},{code:"KN",label:"Saint Kitts and Nevis",phone:"1-869",min:10,max:10},{code:"KP",label:"North Korea",phone:"850",min:9,max:9},{code:"KW",label:"Kuwait",phone:"965",min:8,max:8},{code:"KY",label:"Cayman Islands",phone:"1-345",min:10,max:10},{code:"KZ",label:"Kazakhstan",phone:"7",min:10,max:10},{code:"MC",label:"Monaco",phone:"377",min:8,max:9},{code:"LI",label:"Liechtenstein",phone:"423",min:7,max:7},{code:"VA",label:"Vatican City",phone:"379",min:9,max:9},{code:"SM",label:"San Marino",phone:"378",min:10,max:10},{code:"ME",label:"Montenegro",phone:"382",min:8,max:8},{code:"RS",label:"Serbia",phone:"381",min:9,max:9},{code:"MK",label:"North Macedonia",phone:"389",min:8,max:8},{code:"SJ",label:"Svalbard and Jan Mayen",phone:"47",min:8,max:8},{code:"MF",label:"Saint Martin",phone:"590",min:9,max:9},{code:"PM",label:"Saint Pierre and Miquelon",phone:"508",min:6,max:6},{code:"WF",label:"Wallis and Futuna",phone:"681",min:6,max:6},{code:"TV",label:"Tuvalu",phone:"688",min:5,max:5},{code:"NR",label:"Nauru",phone:"674",min:7,max:7},{code:"TO",label:"Tonga",phone:"676",min:5,max:5},{code:"WS",label:"Samoa",phone:"685",min:7,max:7},{code:"VU",label:"Vanuatu",phone:"678",min:7,max:7},{code:"SB",label:"Solomon Islands",phone:"677",min:7,max:7},{code:"FM",label:"Micronesia",phone:"691",min:7,max:7},{code:"MH",label:"Marshall Islands",phone:"692",min:7,max:7},{code:"PW",label:"Palau",phone:"680",min:7,max:7}];function Wa({label:e,placeholder:n,classLabel:o,isRequired:s,isOptional:a,name:t,value:d,error:r,disabled:l,readOnly:c,horizontal:u,description:p,validate:v,onChange:f,onError:w}){const[x,h]=m.useState(""),[g,y]=m.useState(null),[N,A]=m.useState(""),S=m.useMemo(()=>{var B;return(B=gi==null?void 0:gi.slice().sort((F,D)=>F.label.localeCompare(D.label)))==null?void 0:B.map(F=>({...F,phone:`+${F.phone}`}))},[]),k=m.useMemo(()=>x?S.filter(B=>`${B.label} ${B.phone}`.toLowerCase().includes(x.toLowerCase())):S,[x,S]),j=(g==null?void 0:g.min)||10,I=(g==null?void 0:g.max)||10,X=()=>N?`${(g==null?void 0:g.phone)||"+234"}-${N}`:"",U=B=>{if(!B)return{code:"+234",number:""};const F=B.split(/[-\s]/);return{code:F[0],number:F.slice(1).join(" ")}};m.useEffect(()=>{if(d){const B=U(d);y(S.find(F=>F.phone===B.code)||S[0]),A(B.number)}},[d,S]);const Z=m.useMemo(()=>{if(r)return r;const B=N.length;return s&&B===0?"Phone number is required":B>0&&!/^\d+$/.test(N)?"Phone number must contain only digits":B>0&&B<j?`Minimum length is ${j}`:B>I?`Maximum length is ${I}`:""},[r,N,j,I,s]);return m.useEffect(()=>{f==null||f(X()),w==null||w(Z||null)},[N,g,Z]),i.jsxs("div",{className:`relative formGroup ${Z&&!c?"has-error":""} ${u?"flex":""} ${!Z&&N.length>0&&!c?"is-valid":""}`,children:[e&&i.jsxs("label",{htmlFor:t,className:`${o} ${u?"flex-0 mr-6 md:w-[100px] w-[60px] break-words":""} flex items-center gap-x-1 input-label text-sm text-[#1B2B41B8]`,children:[e," ",s&&i.jsx("span",{className:"text-red-500",children:"*"}),a&&i.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),i.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[i.jsx(W,{icon:"lucide:phone-call"}),i.jsx(z.Combobox,{value:g,onChange:y,children:i.jsxs("div",{className:"relative",children:[i.jsx(z.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:B=>(B==null?void 0:B.phone)||"+234",placeholder:"+234",onChange:B=>h(B.target.value)}),i.jsx(z.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(W,{icon:"lucide:chevron-down"})}),i.jsx(z.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:k==null?void 0:k.map((B,F)=>i.jsxs(z.Combobox.Option,{value:B,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[B.phone," - ",B.label]},`${B.code}+ ${F}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:N,disabled:l,readOnly:c,onChange:B=>{const F=B.target.value.replace(/\D/g,"");A(F)},placeholder:n,className:"w-full px-3 outline-none",maxLength:I,minLength:j}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!Z&&N.length>0&&!c&&i.jsx("span",{className:"text-green-500",children:i.jsx(W,{icon:"bi:check-lg"})})})]})]}),p&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:p})]})}function Ua({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t,setError:d,clearErrors:r}=n||{};let l;return m.useEffect(()=>{o(e.id)},[e.id,o]),a&&(l=a()[e.id]),i.jsx(Wa,{placeholder:e.placeholder,label:"",name:e.id,value:l,readOnly:t,disabled:t,onError:c=>{c?d==null||d(e.id,{type:"manual",message:c}):r==null||r(e.id)},onChange:c=>{c&&(s==null||s(e.id,c))}})}function qa({element:e,validationData:n}){var c;const{register:o=()=>({}),watch:s}=n||{};let a="";s&&(a=(c=s()[e.id])!=null?c:"");const t=a.trim(),d=/^https?:\/\//i.test(t),r=t?d?t:`https://${t}`:"",l=!d;return i.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&i.jsxs("div",{className:"relative",children:[l&&i.jsx("span",{className:"text-sm absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none select-none",children:"https://"}),i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:q("field-control",l&&"!pl-16",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly})]}),t?i.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:i.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:t})}):(n==null?void 0:n.isReadOnly)&&i.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}const gn={textField:Xe,longText:ia,selectField:ea,multiSelect:ui,numberField:Xe,amountField:Ca,date:Fn,password:Zo,checkbox:Xo,radio:$o,email:Xe,file:Yo,dataGrid:za,section:Qo,validateInput:Ta,tableInput:La,spacer:Pa,divider:Da,header:Ia,basicText:Oa,phoneField:Ua,cascadeSelect:Ha,rating:Fa,country:pn,bank:pn,document:Va,url:qa},hn="edit",Ja=(e,n)=>{const o=gn[e.type];return o?i.jsx(pi,{element:e,state:hn,children:i.jsxs("div",{className:"relative w-full",children:[e.type.toLowerCase()!=="grid"&&i.jsx("div",{className:"absolute top-0 left-0 z-20 w-full h-full"}),i.jsx(o,{element:e,state:hn,sectionId:n})]})}):null},hi=({col:e,children:n,customClass:o})=>i.jsx("div",{className:q("w-full bg-white",o),style:{gridColumn:e},children:n}),Ya=({element:e,sectionId:n,children:o,customClass:s,state:a,draggedElementId:t})=>{const{formData:d,addElement:r,setIsDragging:l,moveElement:c,isDragging:u,removeElement:p}=m.useContext(ve),v=m.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[f,w]=m.useState(null);m.useEffect(()=>{const A=()=>{w(null),l(!1)};return document.addEventListener("dragend",A),()=>document.removeEventListener("dragend",A)},[l]);const x=m.useCallback((A,S)=>{A.preventDefault(),A.stopPropagation(),A.dataTransfer.dropEffect="move",w(S)},[]),h=m.useCallback((A,S)=>{A.preventDefault(),A.stopPropagation(),w(S)},[]),g=m.useCallback((A,S)=>{const k=A.relatedTarget;k&&A.currentTarget.contains(k)||w(j=>j===S?null:j)},[]),y=m.useCallback((A,S)=>{var I;A.preventDefault(),A.stopPropagation(),l(!1),w(null);const k=S+1,j=A.dataTransfer.getData("elementId");if(j){c({draggedId:j,sectionId:n,targetGridId:e.id,targetCol:k});return}try{const X=A.dataTransfer.getData("properties");if(!X)return;const U=JSON.parse(X);if((U==null?void 0:U.type)==="grid")return;const Z=d.find(D=>D.id===n),B=(I=Z==null?void 0:Z.questionData)==null?void 0:I.find(D=>{var K;return D.gridId===e.id&&((K=D.gridPosition)==null?void 0:K.col)===k});B&&p(B.id,n);const F={...U,id:fe.v4(),sectionId:n,gridId:e.id,gridPosition:{col:k}};r(F,n)}catch(X){console.error("Drop failed in grid:",X),l(!1)}},[r,e.id,d,n,l,c]),N=(A,S,k)=>{var K,G,P;const j=A+1,I=(G=(K=d.find(E=>E.id===n))==null?void 0:K.questionData)==null?void 0:G.find(E=>{var T;return E.gridId===e.id&&((T=E.gridPosition)==null?void 0:T.col)===j}),X=(P=I==null?void 0:I.id)!=null?P:null,U=Array.isArray(o)&&o.find(E=>{var T;return((T=E==null?void 0:E.props)==null?void 0:T.col)===j}),Z=u&&f===A,B=!!U,F=u&&!!t,D=B&&X&&k==="edit"?{draggable:!0,onDragStart:E=>{E.stopPropagation(),E.dataTransfer.setData("elementId",X),E.dataTransfer.setData("properties",X),E.dataTransfer.effectAllowed="move",l(!0)},onDragEnd:()=>{w(null),l(!1)}}:{};return i.jsx("div",{children:i.jsxs("div",{id:`grid-cell-${e.id}-${A}`,...D,onDrop:E=>y(E,A),onDragEnter:E=>h(E,A),onDragOver:E=>x(E,A),onDragLeave:E=>g(E,A),className:q("relative border rounded-lg min-h-[110px]","flex items-center justify-center","transition-all duration-200 ease-in-out",k==="edit"?"py-3 ":"",B&&k==="edit"&&"cursor-grab active:cursor-grabbing border-none",S,!F&&!Z&&"bg-white border-gray-200 text-gray-300",F&&!Z&&!B&&"bg-blue-50 border-blue-200 border-dashed text-blue-300",F&&!Z&&B&&"bg-white border-orange-200 border-dashed",Z&&!B&&"bg-blue-100 border-blue-400 border-dashed shadow-inner scale-[1.01] text-blue-500",Z&&B&&"bg-orange-50 border-orange-400 border-dashed shadow-inner scale-[1.01] text-orange-500"),children:[B&&k==="edit"&&i.jsx("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 flex items-center gap-0.5 px-2 py-0.5 rounded-full bg-gray-100 hover:bg-blue-100 text-gray-400 hover:text-blue-500 cursor-grab active:cursor-grabbing transition-colors z-10 opacity-60 hover:opacity-100 pointer-events-none select-none",children:i.jsx(W,{icon:"ph:dots-six-bold"})}),Z&&!B&&i.jsxs("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-blue-400 text-xs font-medium pointer-events-none",children:[i.jsx(W,{icon:"ph:plus-bold"}),"Drop here"]}),Z&&B&&i.jsx("span",{className:"absolute top-1 right-1 text-xs text-orange-400 font-medium pointer-events-none px-1 py-0.5 bg-orange-50 rounded",children:"Replace"}),i.jsx("div",{className:q("w-full select-none",Z&&"opacity-50 pointer-events-none"),children:U||i.jsx("span",{className:"flex items-center justify-center text-gray-300",children:k==="edit"&&i.jsx(W,{icon:"ph:plus-bold"})})})]})},A)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3 items-center",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:v==null?void 0:v.map((A,S)=>N(S,s,a))})})},fi=m.memo(Ya),Za="edit";function xi({index:e,onDrop:n,onDragEnd:o,isDragging:s}){const[a,t]=m.useState(!1),d=a?52:s?28:4;return i.jsx("div",{onDragEnter:r=>{r.preventDefault(),t(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),t(!0)},onDragLeave:()=>t(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),t(!1),n(r,e)},onDragEnd:()=>{t(!1),o()},style:{height:`${d}px`},className:q("w-full rounded-md flex items-center justify-center","transition-all duration-150 ease-in-out overflow-hidden",a?"bg-blue-50 border-2 border-blue-300 border-dashed":s?"border-2 border-blue-200 border-dashed":"border-2 border-transparent"),children:a&&i.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[i.jsx(W,{icon:"octicon:plus-16"}),"Drop here"]})})}function $a({elementData:e,sectionId:n}){const{formData:o,isDragging:s,setIsDragging:a,addElementInPosition:t,moveElement:d}=m.useContext(ve),[r,l]=m.useState(null),c=m.useMemo(()=>{var g;return((g=o.find(y=>y.id===n))==null?void 0:g.questionData)||[]},[o,n]),u=m.useCallback((g,y)=>{g.dataTransfer.setData("elementId",y),g.dataTransfer.setData("properties",y),g.dataTransfer.effectAllowed="move",l(y),a(!0)},[a]),p=m.useCallback(()=>{l(null),a(!1)},[a]);m.useEffect(()=>{!s&&r&&l(null)},[s,r]);const v=m.useCallback(g=>{g.preventDefault(),g.stopPropagation();const y=g.dataTransfer.getData("elementId"),N=g.currentTarget.id;if(!y||!N||y===N){p();return}const A=c.find(k=>k.id===y),S=c.findIndex(k=>k.id===N);A!=null&&A.gridId&&S!==-1?d({draggedId:y,sectionId:n,targetIndex:S}):d({draggedId:y,sectionId:n,targetId:N}),l(null),a(!1)},[n,d,a,p,c]),f=m.useCallback((g,y)=>{g.preventDefault(),g.stopPropagation(),a(!1);const N=g.dataTransfer.getData("elementId");if(N){d({draggedId:N,sectionId:n,targetIndex:y}),l(null);return}try{const A=JSON.parse(g.dataTransfer.getData("properties"));if((A==null?void 0:A.type)==="section")return;const S={...A,id:fe.v4(),sectionId:n};t(S,n,y),l(null)}catch(A){console.error("Drop error:",A)}},[t,n,a,d]),w=m.useCallback((g,y=!1)=>i.jsx("div",{id:g.id,draggable:!0,onDragStart:N=>u(N,g.id),onDragOver:y?void 0:N=>{N.preventDefault(),N.stopPropagation()},onDrop:y?void 0:v,onDragEnd:p,className:q("cursor-grab active:cursor-grabbing border p-4 w-full rounded-lg","transition-all duration-200 ease-in-out",r===g.id?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-300 shadow-inner":r?"bg-white border-dashed border-blue-200 shadow-sm":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:Ja(g,n)},g.id),[r,v,n,u,p]),x=m.useMemo(()=>(e==null?void 0:e.reduce((g,y)=>(y.gridId&&(g[y.gridId]=g[y.gridId]||[],g[y.gridId].push(y)),g),{}))||{},[e]);if(!(e!=null&&e.length))return i.jsx("div",{onDragOver:g=>g.preventDefault(),onDrop:g=>f(g,0),onDragEnd:p,className:"w-full h-full flex items-center justify-center text-gray-400 min-h-[200px] p-10 col-span-2 border border-dashed border-gray-300 rounded-lg",children:"Drag or click an element to display"});const h=e.filter(g=>!g.gridId);return i.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[i.jsx(xi,{index:0,isDragging:s,onDrop:f,onDragEnd:p}),h.map(g=>{const y=c.findIndex(N=>N.id===g.id);if(g.type==="grid"){const N=x[g.id]||[],A=r===g.id,S=!!r&&!A;return i.jsxs("div",{className:"flex flex-col gap-0",children:[i.jsx("div",{id:g.id,draggable:!0,onDragStart:k=>u(k,g.id),onDragOver:k=>{k.preventDefault(),k.stopPropagation()},onDrop:v,onDragEnd:p,className:q("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",A?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":S?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:i.jsx(pi,{element:g,state:"edit",children:i.jsx(fi,{element:g,sectionId:n,state:Za,draggedElementId:r,children:N==null?void 0:N.map(k=>{var j;return i.jsx(hi,{col:(j=k.gridPosition)==null?void 0:j.col,children:w(k,!0)},k.id)})})})}),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},g.id)}return i.jsxs("div",{className:"flex flex-col gap-0",children:[w(g),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},g.id)})]})}const Qa=m.memo($a),Xa=M.object({title:M.string(),description:M.string(),disabled:M.boolean().default(!1),isHidden:M.boolean().default(!1)}).required(),yi=pe("config"),es=({isOpen:e,onClose:n,section:o})=>{const{updateSection:s}=m.useContext(ve),{register:a,handleSubmit:t,watch:d,formState:{errors:r,isSubmitting:l,isValid:c},reset:u}=ke.useForm({resolver:mi(Xa),defaultValues:o});if(m.useEffect(()=>{e||u()},[e,u]),!e)return null;const p=f=>{s(f,o.id),n()},v=d();return i.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:i.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[i.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 mb-6",children:[i.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Update Section Information"}),i.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:i.jsx(W,{icon:"tabler:x"})})]}),i.jsxs("form",{onSubmit:t(p),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(H,{label:"Title",name:"title",register:a,errors:r,watch:d}),i.jsx(H,{label:"Description",name:"description",register:a,errors:r,watch:d,type:"textarea"}),i.jsx(H,{label:"Disable Section",name:"disabled",register:a,errors:r,watch:d,type:"checkbox",value:v.disabled,description:"Disables all fields in this section"}),i.jsx(H,{label:"Hide Section",name:"isHidden",register:a,errors:r,watch:d,type:"checkbox",value:v.isHidden,description:"Hides this section from the form"})]}),i.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!c||l,style:{background:(yi==null?void 0:yi.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!c||l?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!c||l?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:l?"Saving...":"Save"})]})]})]})})},is=({section:e,index:n,selectedSection:o,setSelectedSection:s,activeSections:a,toggleSection:t,handleSectionEdit:d,removeSection:r,formDataLength:l,onDragOver:c,setIsDragging:u})=>{const p=m.useRef(null),v=m.useRef(e.questionData.length);return m.useEffect(()=>{e.questionData.length>v.current&&p.current&&requestAnimationFrame(()=>{var f;(f=p.current)==null||f.scrollTo({top:p.current.scrollHeight,behavior:"smooth"})}),v.current=e.questionData.length},[e.questionData.length]),i.jsx("div",{ref:p,className:"bg-white group cursor-pointer rounded-lg shadow-[rgba(149,157,165,0.2)_0px_2px_2px] transition-colors duration-200",children:i.jsxs("div",{className:` border border-gray-200 rounded-lg px-4 transition-colors duration-200
57
+ ${o===e.id?" border-blue-200 bg-gray-100":"bg-white"} ${a.includes(n)?"min-h-[300px] pb-6 ":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{onClick:()=>s(e.id),className:"flex-1 h-full py-4 cursor-pointer",children:i.jsx("h2",{className:"font-medium",children:e.title||"Section title"})}),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>d(e),children:i.jsx(W,{icon:"fluent:edit-28-regular"})}),l>1&&i.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>r(e.id),children:i.jsx(W,{icon:"lets-icons:trash-duotone-line"})}),i.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>t(n),children:i.jsx(W,{icon:a.includes(n)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(e==null?void 0:e.description)&&a.includes(n)&&i.jsx("p",{className:"mt-2 text-sm text-gray-600",children:e==null?void 0:e.description}),a.includes(n)&&i.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:e.id,onDragOver:c,onDragEnd:()=>u(!1),onClick:()=>s(e.id),children:[i.jsx("hr",{className:"group-last:hidden"}),i.jsx("div",{className:"h-full mt-4 gap-y-6 max-h-[600px] overflow-y-auto",children:i.jsx(Qa,{elementData:e.questionData,sectionId:e.id})})]})]})},e.id)},ns=()=>{const[e,n]=m.useState(!1),o=m.useRef(null),s=m.useRef(null),{removeSection:a,addSection:t,formData:d,setIsDragging:r,setSelectedSection:l,selectedSection:c,activeSections:u,setActiveSections:p}=m.useContext(ve),v=m.useRef((d==null?void 0:d.length)||0);m.useEffect(()=>{var g;l(((g=d[0])==null?void 0:g.id)||null)},[]),m.useEffect(()=>{(d==null?void 0:d.length)>v.current&&s.current&&requestAnimationFrame(()=>{var g;(g=s.current)==null||g.scrollTo({top:s.current.scrollHeight,behavior:"smooth"})}),v.current=(d==null?void 0:d.length)||0},[d==null?void 0:d.length]);const f=m.useCallback(g=>{g.preventDefault(),g.dataTransfer.dropEffect="move",s.current&&(s.current.scrollTop=s.current.scrollHeight)},[]);function w(g){u.includes(g)?p(y=>y.filter(N=>N!==g)):p(y=>[...y,g])}function x(g){o.current=g,n(!0)}const h=pe("config");return i.jsxs("div",{ref:s,className:"relative flex flex-col h-full pb-5 mx-auto gap-x-4 overflow-y-auto",children:[e&&i.jsx(es,{isOpen:e,onClose:()=>n(!1),section:o.current}),i.jsxs("div",{className:"relative flex flex-col flex-1 w-full gap-y-3",children:[d==null?void 0:d.map((g,y)=>i.jsx(is,{section:g,index:y,selectedSection:c,setSelectedSection:l,activeSections:u,toggleSection:w,handleSectionEdit:x,removeSection:a,formDataLength:d.length,onDragOver:f,setIsDragging:r},g.id)),i.jsx("div",{className:"flex justify-center",children:i.jsxs("button",{type:"button",onClick:()=>t(),style:{color:(h==null?void 0:h.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]})})]})]})},os=()=>{const{formData:e,uploadUrl:n}=m.useContext(ve),o=pe("config");return i.jsx(ki,{form_data:e,ignoreValidation:!0,config:o,uploadUrl:n,renderType:"multi"})};function as({questionData:e,uploadUrl:n}){const{setFormData:o,addSection:s,setUploadUrl:a,showPreview:t}=m.useContext(ve);m.useEffect(()=>{e&&e.length>0&&o(e)},[e,o]),m.useEffect(()=>{a(n)},[n,a]);const d=m.useCallback(r=>{r.preventDefault();try{const l=JSON.parse(r.dataTransfer.getData("properties"));if((l==null?void 0:l.type)==="section"){s();return}}catch(l){console.error("Drop error:",l)}},[]);return i.jsxs("div",{className:"flex gap-x-6 h-full",children:[i.jsx("div",{onDragOver:r=>r.preventDefault(),onDrop:r=>d(r),className:" h-full overflow-y-auto no-scrollbar max-h-[calc(100vh-80px)] flex-1 form_builder",children:i.jsx(ns,{})}),i.jsx(z.Transition,{show:t,as:"div",enter:"transition-all duration-300 ease-in-out origin-right",enterFrom:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",enterTo:"opacity-100 w-2/5 translate-x-0",leave:"transition-all duration-300 ease-in-out origin-right",leaveFrom:"opacity-100 w-2/5 translate-x-0",leaveTo:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",className:"shrink-0 overflow-y-auto no-scrollbar max-h-[calc(100vh-70px)] form_preview w-2/5",children:i.jsx("div",{className:"px-2 shadow_box min-w-[320px] bg-white border border-gray-100 rounded-lg",children:i.jsx(os,{})})})]})}const wi=[{key:"textFields",title:"Text Fields"},{key:"selectionFields",title:"Selection Fields"},{key:"dateAndTime",title:"Date & Time"},{key:"fileAndMedia",title:"File & Media"},{key:"layoutAndDisplay",title:"Layout & Display"},{key:"advancedData",title:"Advanced / Data"}],ss=()=>{const[e,n]=m.useState(""),{setIsDragging:o,addElement:s,selectedSection:a}=m.useContext(ve),t=m.useCallback((f,w)=>{if(!a){xe.toast.error("Please select a section to add an element.");return}f.dataTransfer.setData("properties",JSON.stringify(w)),f.dataTransfer.effectAllowed="move",o(!0)},[o,a]);function d(f){if(!a){xe.toast.error("Please select a section to add an element.");return}const w={...f,id:fe.v4(),sectionId:a};s(w,a)}const r=pe("config")||{},l=r.elementColor,c=r.elementBgColor,u=r.elementBorderColor,p=sa.filter(f=>f.label.toLowerCase().includes(e.toLowerCase())),v=wi==null?void 0:wi.map(f=>({title:f.title,elements:p.filter(w=>{var x;return(x=ta[f.key])==null?void 0:x.includes(w.type)})})).filter(f=>f.elements.length>0);return i.jsxs("div",{className:"pt-4 flex flex-col gap-y-6",children:[i.jsx("div",{className:"px-5",children:i.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:f=>n(f.target.value),name:"search",id:"search"})}),i.jsx("div",{className:"flex-1 overflow-y-auto no-scrollbar max-h-[calc(100vh-100px)]",children:i.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 ",children:v==null?void 0:v.map((f,w)=>{var x;return i.jsxs("li",{children:[i.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:f.title}),i.jsx("ul",{className:"grid grid-cols-2 gap-y-3 gap-x-4 mb-3",children:(x=f.elements)==null?void 0:x.map(h=>i.jsx("li",{onDragStart:g=>t(g,h),onDragEnd:()=>o(!1),onClick:()=>d(h),style:{borderColor:u,backgroundColor:c},className:`cursor-move text-[#475467] flex justify-between items-center \r
58
58
  border-[1.5px] border-[#98A2B3] rounded-lg py-2 px-2 shadow-custom\r
59
59
  hover:shadow-lg transition-all duration-200\r
60
60
  active:opacity-50 element_class`,draggable:!0,children:i.jsxs("span",{className:"flex flex-col items-center justify-center w-full gap-2",children:[i.jsx("span",{style:{color:l},children:i.jsx(W,{icon:h.icon,iconClass:"w-6 h-6"})}),i.jsx("span",{style:{color:l},className:"text-xs font-medium ",children:h.label})]})},h.type))})]},w)})})})]})},ts=m.memo(ss),Ne=({text:e="",isDisabled:n=!1,isLoading:o=!1,btnClass:s="bg-primary-500 text-white",icon:a="",iconPosition:t="left",iconClass:d="text-[20px]",loadingClass:r="",link:l="",div:c=!1,type:u="button",style:p,onClick:v})=>{const f=q("btn inline-flex justify-center",{"pointer-events-none":o,"opacity-40 cursor-not-allowed":n},s),w=()=>o?i.jsxs(i.Fragment,{children:[i.jsxs("svg",{className:`animate-spin -ml-1 mr-3 h-5 w-5 ${r}`,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Submitting..."]}):i.jsxs("span",{className:"flex items-center",children:[a&&t==="left"&&i.jsx("span",{className:`mr-[6px] ${d}`,children:i.jsx(W,{icon:a})}),e&&i.jsx("span",{children:e}),a&&t==="right"&&i.jsx("span",{className:`ml-[6px] ${d}`,children:i.jsx(W,{icon:a})})]});return c?i.jsx("div",{className:f,children:w()}):l?i.jsx(Kn.Link,{to:l,className:f,children:w()}):i.jsx("button",{disabled:n,type:u,className:f,"data-testid":"btn",onClick:v,style:p,children:w()})};function ls(){return i.jsx("div",{children:i.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",fill:"#D5D7DA"}),i.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",stroke:"#E9EAEB"}),i.jsx("path",{d:"M22.5 14L14.5 22M14.5 14L22.5 22",stroke:"#414651",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})]})})}const ds=({isOpen:e,onClose:n})=>{const{formData:o,uploadUrl:s}=m.useContext(ve);if(!e)return null;const a=pe("config");return i.jsxs("div",{className:"fixed inset-0 flex justify-center z-[999] cursor-default no-drag select-none w-screen h-screen pt-20 bg-[#F8F9FC]",children:[i.jsx("button",{type:"button",onClick:n,className:"absolute text-sm top-3 right-4","aria-label":"close",children:i.jsx(ls,{})})," ",i.jsx("div",{className:"max-h-[80vh] overflow-y-auto h-max w-full max-w-[650px] min-w-0 border border-[#D5D9EB] rounded-lg bg-white form_submit",children:i.jsx(ki,{form_data:o,ignoreValidation:!0,config:a,uploadUrl:s})})]})};function rs(){return i.jsx("div",{children:i.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{width:"24",height:"24",rx:"6",fill:"currentColor"}),i.jsx("path",{d:"M14 16L10 12L14 8",stroke:"white",strokeWidth:"1.39167",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function us({title:e,goBackUrl:n,onSubmit:o,onPublish:s,previewLoading:a,saveLoading:t,publishLoading:d,onTitleChange:r}){const{formData:l,setShowPreview:c}=m.useContext(ve),[u,p]=m.useState(!1),[v,f]=m.useState(!1),[w,x]=m.useState(e||""),h=pe("config");function g(){localStorage.setItem("formData",JSON.stringify(l)),o==null||o(l)}function y(){localStorage.setItem("formData",JSON.stringify(l)),s==null||s(l)}function N(){f(!1),r&&w!==e&&r(w.trim())}return i.jsxs("div",{className:"px-[30px] py-3 flex justify-between items-center bg-[#F9F9FB] top_bar border-b h-full",children:[i.jsxs("span",{className:"flex items-center gap-x-2",children:[n&&i.jsx("button",{type:"button",onClick:()=>n(),style:{color:(h==null?void 0:h.buttonColor)||"#333"},className:"flex items-center gap-x-3",children:i.jsx(rs,{})})," ",v?i.jsx("input",{type:"text",value:w,onChange:A=>x(A.target.value),onBlur:N,autoFocus:!0,className:"w-48 px-2 py-1 text-sm font-semibold outline-gray-100 input form_title"}):i.jsx("h1",{title:"Click to edit",className:"text-base font-semibold cursor-pointer form_title",onClick:()=>f(!0),children:w||"Untitled"})]}),u&&i.jsx(ds,{isOpen:u,onClose:()=>p(!1),element:void 0}),i.jsxs("div",{className:"flex justify-end text-xs gap-x-3",children:[i.jsx(Ne,{onClick:()=>c(A=>!A),text:"Preview",btnClass:"px-2 bg-transparent font-medium text-sm form_preview",icon:"solar:eye-bold-duotone",iconClass:"text-base",style:{color:(h==null?void 0:h.buttonColor)||"#333"},isDisabled:a,isLoading:a}),i.jsx(Ne,{onClick:g,text:"Save",btnClass:"px-2 bg-transparent font-medium text-sm form_save__btn",icon:"lets-icons:save-duotone",iconClass:"text-base",style:{color:(h==null?void 0:h.buttonColor)||"#333"},isDisabled:t,isLoading:t}),i.jsx(Ne,{onClick:y,text:"Publish",style:{background:(h==null?void 0:h.buttonColor)||"#333"},btnClass:"border-[#98A2B3] font-medium text-sm py-2 px-6 text-white rounded-lg form_publish__btn",isDisabled:d,isLoading:d})]})]})}const fn=({loadingClass:e})=>{const n=q("h-full w-full min-h-[300px] flex justify-center items-center",e);return m.useEffect(()=>{const o=pe("config"),s=(o==null?void 0:o.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",s)},[]),i.jsx("div",{className:n,children:i.jsx("span",{className:"loader"})})};function cs({onSubmit:e,questionData:n,title:o,goBackUrl:s,loading:a,onPublish:t,previewLoading:d,saveLoading:r,publishLoading:l,onTitleChange:c,uploadUrl:u}){return i.jsxs(Ii,{children:[i.jsx(xe.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),i.jsx("div",{className:"w-full h-full bg-[#F8F9FC] flex flex-col",children:i.jsxs("div",{className:"flex flex-1 ",children:[i.jsx("div",{children:i.jsx("div",{className:"w-[270px] h-screen border-r border-[#E4E7EC] bg-white ",children:i.jsx(ts,{})})}),i.jsxs("div",{className:"flex-1 h-full max-h-full z-[1]",children:[i.jsx("div",{className:" h-[70px]",children:i.jsx(us,{title:o,goBackUrl:s,onSubmit:e,onPublish:t,previewLoading:d,saveLoading:r,publishLoading:l,onTitleChange:c})}),i.jsx("div",{className:"p-6 h-[calc(100vh-70px)]",children:a?i.jsx(fn,{loadingClass:"!w-full !h-[800px]"}):i.jsx(as,{questionData:n,uploadUrl:u})})]})]})})]})}const ms=({onSubmit:e,questionData:n,isReadOnly:o,config:s={buttonColor:"#333"},title:a,loading:t,goBackUrl:d,onPublish:r,previewLoading:l,saveLoading:c,publishLoading:u,onTitleChange:p,uploadUrl:v})=>(m.useEffect(()=>{s&&cn("config",s)},[s]),i.jsx(cs,{onSubmit:e,onPublish:r,questionData:n,isReadOnly:o,title:a,goBackUrl:d,loading:t,previewLoading:l,saveLoading:c,publishLoading:u,onTitleChange:p,uploadUrl:v})),Ae={required:"This field is required",email:"Invalid email format",url:"Invalid url format",minLength:e=>`Minimum length is ${e}`,maxLength:e=>`Maximum length is ${e}`,minAmount:e=>`Minimum amount is ${e}`,maxAmount:e=>`Maximum amount is ${e}`},bs=e=>({textField:M.string().nullable(),longText:M.string().nullable(),numberField:M.number().nullable().transform(o=>isNaN(o)?null:o),amountField:M.number().nullable().transform(o=>isNaN(o)?null:o),selectField:M.string().nullable(),checkbox:M.mixed().nullable(),radio:M.mixed().nullable(),email:M.string().nullable().test("email-format",Ae.email,o=>!o||o.trim()===""?!0:/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/.test(o)),date:M.date().typeError("Invalid date").nullable(),url:M.string().nullable().test("url-format",Ae.url,o=>!o||o.trim()===""?!0:/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/.test(o))})[e]||M.mixed().nullable(),vs=(e,n,o)=>n?e.type==="boolean"?e.oneOf([!0],o||Ae.required):e.required(o||Ae.required):e,ps=(e,{minLength:n,maxLength:o,minLengthMessage:s,maxLengthMessage:a})=>{let t=e;return n&&(t=t.min(n,s||Ae.minLength(n))),o&&(t=t.max(o,a||Ae.maxLength(o))),t},gs=(e,{minAmount:n,maxAmount:o,minAmountMessage:s,maxAmountMessage:a})=>{let t=e;return n&&(t=t.min(parseFloat(String(n)),s||Ae.minAmount(n))),o&&(t=t.max(parseFloat(String(o)),a||Ae.maxAmount(o))),t};function hs(e){const n={};return e.forEach(({questionData:o})=>{o==null||o.forEach(s=>{const{id:a,type:t,isRequired:d,requiredMessage:r,isDisabled:l}=s;let c=bs(t);c=vs(c,l?!1:d,r),t==="textField"||t==="longText"||t==="email"||t==="url"?c=ps(c,s):(t==="numberField"||t==="amountField")&&(c=gs(c,s)),n[a]=c})}),M.object().shape(n)}const Je=({element:e,validationData:n})=>{const o=gn[e.type],{answerData:s}=m.useContext(ve),a=m.useMemo(()=>{var r;return(r=e==null?void 0:e.acceptedFiles)==null?void 0:r.map(l=>l.label).join(", ")},[e]),t=m.useMemo(()=>(e==null?void 0:e.visibilityDependentFields)||[],[e]),d=m.useMemo(()=>t.length?t.every(r=>{if(!e.isHidden)return!0;const l=s==null?void 0:s[r.id],c=r.fieldValue,u=l;switch(r.operator){case"equals":return String(c).toLowerCase()===String(u).toLowerCase();case"not_equals":return String(c).toLowerCase()!==String(u).toLowerCase();case"greater":return Number(u)>Number(c);case"less":return Number(u)<Number(c);case"contains":return String(u).toLowerCase().includes(String(c).toLowerCase());case"not_contains":return!String(u).toLowerCase().includes(String(c).toLowerCase());default:return!0}}):!0,[t,s,e]);return o?i.jsxs("div",{className:d?"":"invisible h-0",children:[i.jsxs("div",{className:"mb-1.5",children:[e.inputLabel&&i.jsxs("label",{className:"block text-sm font-medium input_label",children:[e.inputLabel," ",a&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",a==null?void 0:a.toLowerCase(),")"]})]}),e.description&&i.jsxs("small",{className:"block text-gray-400 mt-0.5 text-xs",children:[" ",e.description]})]}),i.jsx(o,{element:e,state:"edit",validationData:{...n,isReadOnly:n.isReadOnly||e.isDisabled}})]}):null},Ye=(e,n)=>e!=null&&e.allowEdit?{...n,isReadOnly:!1}:n;function fs({form_data:e,options:n}){const o=(a,t)=>i.jsx(fi,{element:a,customClass:"p-0 min-h-[60px] border-none",children:t==null?void 0:t.map(d=>{var r,l,c;return i.jsxs(hi,{col:(r=d.gridPosition)==null?void 0:r.col,customClass:"p-0",children:[i.jsx(Je,{element:d,validationData:Ye(d,n)}),((c=(l=n==null?void 0:n.errors)==null?void 0:l[d.id])==null?void 0:c.message)&&i.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[d.id].message})]},d.id)})},a.id),s=a=>{var t,d;return i.jsxs("div",{className:q("group relative grid gap-y-[6px]",a.elementClass),children:[i.jsx(Je,{element:a,validationData:Ye(a,n)}),((d=(t=n==null?void 0:n.errors)==null?void 0:t[a.id])==null?void 0:d.message)&&i.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[a.id].message})]},a.id)};return i.jsx("div",{className:"grid gap-y-10",children:e==null?void 0:e.map(a=>{var d,r;const t=new Map;return(d=a.questionData)==null||d.forEach(l=>{l.gridId&&(t.has(l.gridId)||t.set(l.gridId,[]),t.get(l.gridId).push(l))}),i.jsxs("div",{className:"pb-6 section_box",children:[(a.title||a.description)&&i.jsxs("div",{className:"py-4 border-b border-gray-100 mb-7 section_box__title",children:[a.title&&i.jsx("h2",{className:"text-lg font-semibold mb-[4px]",children:a.title}),a.description&&i.jsx("p",{className:"text-sm",children:a.description})]}),i.jsx("div",{className:"grid gap-y-6 section_box__content",children:(r=a.questionData)==null?void 0:r.map(l=>l.gridId?null:l.type==="grid"?o(l,t.get(l.id)||[]):s(l))})]},a.id)})})}function xs({form_data:e,options:n,current:o}){var s;return i.jsx("div",{className:"grid gap-y-3 multi_section__content",children:(s=e[o].questionData)==null?void 0:s.map(a=>{var t,d;if(a.type==="grid"){const r=e[o].questionData.filter(l=>l.gridId===a.id);return i.jsx(fi,{element:a,customClass:"p-0 min-h-[60px] border-none",children:r==null?void 0:r.map(l=>{var c,u,p;return i.jsxs(hi,{col:(c=l.gridPosition)==null?void 0:c.col,customClass:"p-0",children:[i.jsx(Je,{element:l,validationData:Ye(l,n)}),i.jsx("div",{className:"mt-1 text-xs text-red-600",children:(p=(u=n==null?void 0:n.errors)==null?void 0:u[l.id])==null?void 0:p.message})]},l.id)})},a.id)}return a.gridId?null:i.jsxs("div",{className:q("group relative grid gap-y-[6px]",a.elementClass),children:[i.jsx(Je,{element:a,validationData:Ye(a,n)}),i.jsx("div",{className:"mt-1 text-xs text-red-600",children:(d=(t=n==null?void 0:n.errors)==null?void 0:t[a.id])==null?void 0:d.message})]},a.id)})})}function ys(e){return e.reduce((n,o)=>(n[o.id]=o.value,n),{})}const ws=({form_data:e,answerData:n=[],ignoreValidation:o=!1,onSubmitData:s,onGetValues:a,isReadOnly:t=!1,renderType:d="multi",children:r,hideFooter:l=!1,uploadUrl:c})=>{var ee,oe,me,ce,L,O,Q,se;const{setAnswerData:u,setUploadUrl:p}=m.useContext(ve),[v,f]=m.useState(0),w=m.useMemo(()=>e.filter(J=>!J.isHidden).map(J=>{var be;return J.isDisabled||J.disabled?{...J,questionData:(be=J.questionData)==null?void 0:be.map(ye=>({...ye,isDisabled:!0}))}:J}),[e]),x=(ee=w==null?void 0:w.length)!=null?ee:0,h=pe("config"),g=m.useMemo(()=>hs(w),[w]),y=ke.useForm({resolver:mi(g),mode:"onSubmit",defaultValues:{}}),{register:N,setValue:A,control:S,handleSubmit:k,reset:j,getValues:I,watch:X,formState:{errors:U,isSubmitting:Z},trigger:B,setError:F,clearErrors:D}=y,K=ke.useWatch({control:S}),G=m.useMemo(()=>K,[JSON.stringify(K)]),P=m.useCallback(J=>{a&&a(J)},[a]);m.useEffect(()=>{p(c)},[p,c]),m.useEffect(()=>{if(!(w!=null&&w.length)||!a)return;const J=w.flatMap(ae=>{var be;return(be=ae.questionData)==null?void 0:be.map(ye=>({id:ye.id,value:G[ye.id]||"",sectionId:ae.id,type:ye.type,metaData:{prefix:ye.prefix}}))});P(J),u(G)},[G,w,P,a,u]),m.useEffect(()=>{n!=null&&n.length&&j(ys(n))},[n,j]);const E=m.useCallback(J=>{const ae=w.flatMap(be=>{var ye;return(ye=be.questionData)==null?void 0:ye.map(Se=>({id:Se.id,value:J[Se.id]||"",sectionId:be.id,type:Se.type,metaData:{prefix:Se.prefix}}))});Object.keys(U).length>0||s==null||s(ae)},[U,w,s]),T=m.useCallback(async()=>{var J,ae;if(!o){const be=(ae=(J=w==null?void 0:w[v])==null?void 0:J.questionData)==null?void 0:ae.map(Se=>Se.id);if(!await B(be))return}f(be=>be+1)},[v,w,o,B]),V=m.useCallback(()=>{f(J=>J-1)},[]),de=m.useMemo(()=>({register:N,setValue:A,watch:X,errors:U,trigger:B,isSubmitting:Z,isReadOnly:t,getValues:I,setError:F,clearErrors:D}),[N,A,X,U,B,Z,t,I,F,D]);return i.jsxs(ke.FormProvider,{...y,children:[i.jsx(xe.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),i.jsxs("form",{onSubmit:k(E),className:"container h-full mx-auto",children:[i.jsx("div",{className:"relative flex flex-col w-full py-4 gap-y-12",children:i.jsxs("div",{className:"multi_section__box",children:[d==="multi"&&(((oe=w==null?void 0:w[v])==null?void 0:oe.title)||((me=w==null?void 0:w[v])==null?void 0:me.description))&&i.jsxs("div",{className:"py-4 mb-4 border-b border-gray-100 multi_section__title",children:[((ce=w[v])==null?void 0:ce.title)&&i.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:(L=w[v])==null?void 0:L.title}),((O=w[v])==null?void 0:O.description)&&i.jsx("p",{className:"text-sm",children:(Q=w[v])==null?void 0:Q.description})]}),d==="multi"?i.jsx(xs,{form_data:w,options:de,current:v}):i.jsx(fs,{form_data:w,options:de})]},(se=w==null?void 0:w[v])==null?void 0:se.id)}),!l&&i.jsx("footer",{className:"flex items-center justify-end gap-4 footer flex-wrap",children:d==="multi"?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex gap-x-4 justify-between navigation_container w-full",children:[i.jsxs("div",{children:[" ",v>0&&i.jsx(Ne,{type:"button",text:"Back",onClick:V,btnClass:"text-gray-700 back_btn text-sm border-[#98A2B3] !font-medium !py-[10px] px-10 bg-gray-200 rounded-lg"})]}),v<x-1&&i.jsx(Ne,{type:"button",text:"Next",onClick:T,style:{background:(h==null?void 0:h.buttonColor)||"#333"},btnClass:"text-gray-700 next_btn text-sm border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg continue_btn"})]}),(v===x-1||t)&&!o&&(r!=null?r:i.jsx(Ne,{isDisabled:Z||Object.keys(U).length>0,isLoading:Z,type:"submit",text:"Submit",style:{background:(h==null?void 0:h.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] submit_btn !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))]}):!o&&(r!=null?r:i.jsx(Ne,{isDisabled:Z||Object.keys(U).length>0,isLoading:Z,type:"submit",text:"Submit",style:{background:(h==null?void 0:h.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] submit_btn !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))})]})]})},ks=m.memo(ws);function ki({answerData:e,form_data:n,ignoreValidation:o,onSubmit:s,isReadOnly:a=!1,loading:t=!1,config:d={buttonColor:"#333"},renderType:r,children:l,hideFooter:c,onGetValues:u,uploadUrl:p}){m.useEffect(()=>{d&&cn("config",d)},[d]);const v=m.useCallback(f=>{u&&u(f)},[u]);return t?i.jsx(fn,{}):n?i.jsxs("div",{id:"form",className:"w-full h-full",children:[i.jsx("div",{id:"root-portal"}),i.jsx(Ii,{children:i.jsx(ks,{form_data:n,answerData:e,ignoreValidation:o,onSubmitData:s,isReadOnly:a,renderType:r,hideFooter:c,onGetValues:v,uploadUrl:p,children:l})})]}):i.jsx("div",{children:i.jsx("p",{className:"p-6 text-sm text-gray-400",children:"Error: No form data available."})})}le.FormBuilder=ms,le.FormViewer=ki,Object.defineProperty(le,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arudovwen/form-builder-react",
3
- "version": "1.4.49",
3
+ "version": "1.4.50",
4
4
  "description": "A React-based form builder component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/form-builder.umd.js",