@arudovwen/form-builder-react 1.4.19 → 1.4.20
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.
- package/dist/form-builder.es.js +14 -11
- package/dist/form-builder.umd.js +1 -1
- package/package.json +1 -1
package/dist/form-builder.es.js
CHANGED
|
@@ -5465,17 +5465,20 @@ function me({
|
|
|
5465
5465
|
},
|
|
5466
5466
|
`country-${u}`
|
|
5467
5467
|
),
|
|
5468
|
-
g.length > 0 && i.showState && /* @__PURE__ */ n.
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5468
|
+
g.length > 0 && i.showState && /* @__PURE__ */ n.jsxs("div", { children: [
|
|
5469
|
+
/* @__PURE__ */ n.jsx("label", { className: "block text-sm font-medium mb-1.5 input_label", children: "Select State" }),
|
|
5470
|
+
/* @__PURE__ */ n.jsx(
|
|
5471
|
+
yn,
|
|
5472
|
+
{
|
|
5473
|
+
options: g,
|
|
5474
|
+
onGetValue: v,
|
|
5475
|
+
name: `${i.id}-state`,
|
|
5476
|
+
readOnly: l,
|
|
5477
|
+
defaultValue: b
|
|
5478
|
+
},
|
|
5479
|
+
`state-${b}`
|
|
5480
|
+
)
|
|
5481
|
+
] })
|
|
5479
5482
|
] });
|
|
5480
5483
|
}
|
|
5481
5484
|
function Ts({
|
package/dist/form-builder.umd.js
CHANGED
|
@@ -45,7 +45,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
45
45
|
"data": [
|
|
46
46
|
{ "name": "Document Name", "id": "documentMainId", ...restObject },
|
|
47
47
|
]
|
|
48
|
-
}`})})]})})}),ga=()=>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 ha(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const fa=["text","number","boolean"],tn=["equals","not_equals","contains","not_contains"],xa=["greater","less"];function ya({register:e,setValue:n,trigger:o,watch:a,id:s}){const{formData:t}=v.useContext(ae),l=a("visibilityDependentFields")||[],r=v.useMemo(()=>ha(t).filter(b=>b.id!==s).map(b=>{const u=l.find(f=>f.id===b.id);return{id:b.id,value:b.id,label:b.inputLabel,sectionId:b.sectionId,fieldType:(u==null?void 0:u.fieldType)||"text",operator:(u==null?void 0:u.operator)||"equals",fieldValue:(u==null?void 0:u.fieldValue)!==void 0?u.fieldValue:""}}),[t,l,s]),d=(b,u,f)=>{const c=l.map((p,y)=>y===b?{...p,[u]:f}:p);n("visibilityDependentFields",c)};return i.jsxs("div",{className:"visibility-editor",children:[i.jsx("label",{className:"label",children:"Select Dependent Fields"}),i.jsx(si,{element:{options:r,id:"visibilityDependentFields",value:a("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:o,watch:a}}),l.length>0&&i.jsx("div",{className:"py-1 bg-gray-100 rounded dependent-fields",children:l.map((b,u)=>{var f;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:b.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(P.Listbox,{value:b.fieldType,onChange:c=>d(u,"fieldType",c),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(P.Listbox.Button,{className:"listbox-button",children:b.fieldType}),i.jsx(P.Transition,{as:v.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(P.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:fa.map(c=>i.jsx(P.Listbox.Option,{value:c,className:"listbox-option",children:c},c))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(P.Listbox,{value:b.operator,onChange:c=>d(u,"operator",c),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(P.Listbox.Button,{className:"listbox-button",children:b.operator.replace("_"," ")}),i.jsx(P.Transition,{as:v.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(P.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(b.fieldType==="number"?[...tn,...xa]:tn).map(c=>i.jsx(P.Listbox.Option,{value:c,className:"listbox-option",children:c.replace("_"," ")},c))})})]})})}),b.fieldType!=="boolean"?i.jsx("input",{type:b.fieldType,value:b.fieldValue||"",onChange:c=>d(u,"fieldValue",c.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(P.Listbox,{value:(f=b.fieldValue)!=null?f:"",onChange:c=>d(u,"fieldValue",c),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(P.Listbox.Button,{className:"listbox-button",children:b.fieldValue===!0?"True":b.fieldValue===!1?"False":"Select value"}),i.jsx(P.Transition,{as:v.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(P.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(P.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(P.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},b.id)})})]})}const ka=j.object().shape({inputLabel:j.string().nullable(),placeholder:j.string().nullable(),description:j.string().nullable(),isReadOnly:j.boolean(),isDisabled:j.boolean(),isRequired:j.boolean(),requiredMessage:j.string().nullable(),minLengthMessage:j.string().nullable(),maxLengthMessage:j.string().nullable(),maxLength:j.number().typeError("Expecting a number").nullable(),minLength:j.number().typeError("Expecting a number").nullable(),inputType:j.string().nullable(),maxAmountMessage:j.string().nullable(),maxAmount:j.string().nullable(),options:j.array().of(j.object().shape({label:j.string().nullable(),value:j.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:j.array().of(j.object().shape({label:j.string().nullable(),value:j.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:j.string().nullable(),url:j.string().nullable(),method:j.string().nullable(),denominators:j.mixed().nullable(),responseType:j.string().nullable(),minAmount:j.string().nullable(),heading:j.string().nullable(),minAmountMessage:j.string().nullable(),columns:j.number().nullable(),value:j.mixed().nullable(),customClass:j.string().nullable(),elementClass:j.string().nullable(),apiUrl:j.string().nullable(),selectType:j.string().default("list"),dateType:j.string().default("basic"),validationUrl:j.string(),signatureLink:j.string(),minDate:j.string().nullable(),maxDate:j.string().nullable(),canHaveDateRange:j.boolean(),allowYearPicker:j.boolean(),isHidden:j.boolean(),visibilityDependentFields:j.array().nullable(),isMultiple:j.boolean(),acceptedFiles:j.array(),showState:j.boolean()}),wa=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],Aa=({isOpen:e,onClose:n,element:o})=>{const a=wa.filter(F=>!ze.includes(o.inputType)||F.key!=="validation"),{updateElement:s}=v.useContext(ae),[t,l]=v.useState("basic"),[r,d]=v.useState(!1),[b,u]=v.useState("manual"),f=te("config"),{register:c,handleSubmit:p,control:y,setValue:g,watch:h,trigger:x,formState:{errors:k,isSubmitting:A,isValid:S},reset:N}=me.useForm({resolver:li(ka),defaultValues:{...o,options:o.options||[]}}),w=h(),{fields:T,append:G,remove:Z}=me.useFieldArray({control:y,name:"options"}),{fields:B,append:O,remove:M}=me.useFieldArray({control:y,name:"options1"}),{fields:E,append:I,remove:q}=me.useFieldArray({control:y,name:"dataColumns"});v.useEffect(()=>{e||N()},[e,N]);const oe=F=>{s(F,o.sectionId),n()},R={headers:{Authorization:`Bearer ${te("token")}`}},be=v.useCallback(async()=>{var F,U,$;if(!w.apiUrl||!/^https?:\/\//.test(w.apiUrl)){de.toast.info("Please provide a valid API URL");return}try{d(!0);const{status:Q,data:X}=await Ae.get(w.apiUrl,R);if(Q!==200||!X){de.toast.error("Unexpected response from server.");return}const re=X.data||X.record||X.result;if(!Array.isArray(re)){de.toast.error("Expected an array in response (data, record, or result).");return}((F=o.type)==null?void 0:F.toLowerCase())==="datagrid"?g("dataColumns",re):g("options",re)}catch(Q){const X=(($=(U=Q==null?void 0:Q.response)==null?void 0:U.data)==null?void 0:$.message)||(Q==null?void 0:Q.message)||"Unable to load options";de.toast.error(X)}finally{d(!1)}},[o.type,g,w.apiUrl]),pe=["manual","api","sheet"];function ge(){b==="api"&&be()}const xe=()=>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:pe.map(F=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:U=>u(U.target.value),value:F})," ",i.jsxs("span",{children:[F," options"]})]},F))}),b==="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(D,{label:"Load Options from Api",name:"apiUrl",errors:k,register:c,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:ge,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(ba,{})]}),b==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(sn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:g,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),T.map((F,U)=>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(D,{label:"Label",name:`options.${U}.label`,register:c,errors:k,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Value",name:`options.${U}.value`,register:c,errors:k,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("button",{disabled:T.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>Z(U),children:i.jsx(H,{icon:"iconamoon:sign-times-fill"})})]},F.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:()=>G({label:"",value:"",id:ve.v4()}),children:[i.jsx(H,{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 "}),B==null?void 0:B.map((F,U)=>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(D,{label:"Label",name:`options1.${U}.label`,register:c,errors:k,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Value",name:`options1.${U}.value`,register:c,errors:k,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Key",name:`options1.${U}.key`,register:c,errors:k,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:B.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>M(U),children:i.jsx(H,{icon:"iconamoon:sign-times-fill"})})]},F.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:()=>O({label:"",value:"",key:"",id:ve.v4()}),children:[i.jsx(H,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),ye=()=>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:pe.map(F=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:U=>u(U.target.value),value:F,checked:F===b})," ",i.jsxs("span",{children:[F," options"]})]},F))}),b==="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(D,{label:"Load Columns from Api",name:"apiUrl",errors:k,register:c,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:ge,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(va,{})]}),b==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(sn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:g,name:"dataColumns"})}),E.map((F,U)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Field key",name:`dataColumns.${U}.field`,register:c,errors:k,element:o,placeholder:"Field",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Header Name",name:`dataColumns.${U}.headerName`,register:c,errors:k,element:o,placeholder:"headerName",isFloating:!0})}),i.jsx("button",{disabled:E.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>q(U),children:i.jsx(H,{icon:"iconamoon:sign-times-fill"})})]},F.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({headerName:"",field:"",editable:!0,id:ve.v4()}),children:[i.jsx(H,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),ke=v.useCallback(async()=>{const F=te("token"),{status:U,data:$}=await Ae.get(w.url,{headers:{Authorization:`Bearer ${F}`}});U===200&&(console.log({data:$}),g("options",($==null?void 0:$.data)||$))},[g,w.url]);return v.useEffect(()=>{o.type==="document"&&w.url&&ke()},[w.url,o.type,ke]),i.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-end z-[999] cursor-default select-none ",draggable:"true",onDragStart:F=>F.preventDefault(),children:i.jsxs("div",{className:"w-full lg:w-1/3 xl:w-1/4 bg-white h-screen shadow-xl relative flex flex-col items-center select-",draggable:"true",onDragStart:F=>F.preventDefault(),children:[i.jsx("div",{className:"w-full pt-4",children:i.jsx($o,{tabs:a,setActiveTab:l,activeTab:t,className:"justify-start !text-left",btnClass:" !text-left"})}),i.jsxs("form",{onSubmit:p(oe),className:"w-full flex-1 flex flex-col",children:[i.jsxs("div",{className:"flex-1",children:[" ",i.jsxs("div",{className:" max-h-[75vh] overflow-y-auto flex-1",children:[t==="basic"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[di.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(D,{label:"Value",name:"value",register:c,errors:k,element:o})}),!di.includes(o.inputType)&&!ze.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(D,{label:"Label",name:"inputLabel",register:c,errors:k,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(D,{label:"Child Label",name:"childLabel",register:c,errors:k,element:o})]}),sa.includes(o.inputType)&&i.jsx(D,{label:"Placeholder",name:"placeholder",register:c,errors:k,element:o}),oa.includes(o.inputType)&&i.jsx(D,{label:"Prefix",name:"prefix",register:c,errors:k,element:o}),da.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(ma,{}),i.jsx(D,{label:"Api Url",name:"url",register:c,errors:k,element:o}),i.jsx(Le,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:c,name:"method",setValue:g,trigger:x,value:h("method")}),i.jsx(Le,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:c,name:"responseType",setValue:g,trigger:x,value:h("responseType")})]}),ra.includes(o.inputType)&&i.jsx(ca,{onChange:F=>{g("denominators",F)},value:h("denominators")}),!di.includes(o.inputType)&&!ze.includes(o.inputType)&&i.jsx(D,{label:"Short Description",name:"description",register:c,errors:k,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Le,{label:"Date Format",options:na,register:c,name:"dateFormat",setValue:g,trigger:x,value:h("dateFormat")}),i.jsx(D,{label:"Allow Range",name:"canHaveDateRange",register:c,errors:k,element:o,type:"checkbox"}),(w==null?void 0:w.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx(Je,{name:"minDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select min date"}),i.jsx(Je,{name:"maxDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select max date",minDate:w==null?void 0:w.minDate})]}),i.jsx(D,{label:"Allow Year Picker",name:"allowYearPicker",register:c,errors:k,element:o,type:"checkbox"})]}),o.type.toLowerCase()==="country"&&i.jsx(D,{label:"Allow States",name:"showState",register:c,errors:k,element:o,type:"checkbox"}),o.type.toLowerCase()==="selectfield"&&i.jsx(Le,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:c,name:"selectType",setValue:g,trigger:x,value:h("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(D,{label:"Number of columns",name:"columns",register:c,errors:k,element:o}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(D,{label:"Document Options Url",name:"url",register:c,errors:k,element:o})," ",i.jsx(pa,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(D,{label:"Document Validation Url",name:"validationUrl",register:c,errors:k,element:o}),i.jsx(ga,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(D,{label:"Signature Page Url",name:"signatureLink",register:c,errors:k,element:o})})]}),o.type.toLowerCase()==="datagrid"&&ye(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(D,{label:"Allow Multiple Uploads",name:"isMultiple",register:c,errors:k,element:o,type:"checkbox"}),i.jsx(si,{element:{options:ua,id:"acceptedFiles",value:w==null?void 0:w.acceptedFiles},validationData:{register:c,setValue:g,trigger:x,watch:h},placeholder:"Choose file types"})]}),la.includes(o.inputType)&&xe(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(D,{label:"Toggle Visibility",name:"isHidden",register:c,errors:k,element:o,type:"checkbox"})})," ",w.isHidden&&i.jsx(ya,{register:c,setValue:g,trigger:x,watch:h,id:o==null?void 0:o.id})]})]}),!ze.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(D,{label:"Required",name:"isRequired",register:c,errors:k,element:o,type:"checkbox"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"requiredMessage",register:c,errors:k,element:o})})]}),aa.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(D,{label:"Min Length",name:"minLength",register:c,errors:k,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"minLengthMessage",register:c,errors:k,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(D,{label:"Max Length",name:"maxLength",register:c,errors:k,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"maxLengthMessage",register:c,errors:k,element:o})})]})]}),ta.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(D,{label:"Min Amount",name:"minAmount",register:c,errors:k,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"minAmountMessage",register:c,errors:k,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(D,{label:"Max Amount",name:"maxAmount",register:c,errors:k,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"maxAmountMessage",register:c,errors:k,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-4 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:!S||A,style:{background:(f==null?void 0:f.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!S||A?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!S||A?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:A?"Saving...":"Save"})]})]})]})})},ri=v.memo(({state:e,element:n,children:o})=>{const[a,s]=v.useState(!1),{removeElement:t}=v.useContext(ae),l=v.useMemo(()=>{var d;return(d=n==null?void 0:n.acceptedFiles)==null?void 0:d.map(b=>b.label).join(", ")},[n]),r=v.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return i.jsxs("div",{className:"w-full",children:[a&&i.jsx(Aa,{isOpen:a,onClose:()=>s(!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," ",l&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",l==null?void 0:l.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:()=>s(!0),children:i.jsx(H,{icon:"circum:edit",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:r,children:i.jsx(H,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});ri.displayName="ElementContainer";function Sa({element:e,validationData:n}){const{register:o=()=>({}),trigger:a,setValue:s,watch:t,isReadOnly:l}=n||{};let r;return t&&(r=t()[e.id]),i.jsx(D,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:a,setValue:s,value:r,prefix:e.prefix,disabled:l})}function _a(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 Na=({imageUrl:e})=>{const[n,o]=v.useState(!1),a=()=>{o(!0)},s=()=>{o(!1)};return i.jsxs("div",{children:[i.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:a,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:s,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:s,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 Ca({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,watch:s}=n||{},[t,l]=v.useState(),[r,d]=v.useState(!1),[b,u]=v.useState(!1),[f,c]=v.useState(""),p=s&&s(e==null?void 0:e.id);v.useEffect(()=>{l(p)},[p]);const[y,g]=v.useState("");v.useEffect(()=>{o(e.id)},[e.id,o]);const{url:h,method:x,responseType:k}=e||{},S={headers:{Authorization:`Bearer ${te("token")}`}},N=v.useCallback(async w=>{var T,G,Z,B,O,M,E,I,q,oe,ce;if(!(!h||!x)){d(!0);try{let R;if(x.toLowerCase()==="get"){const be=`${h}?value=${w}`;R=await Ae.get(be,S)}else if(x.toLowerCase()==="post")R=await Ae.post(h,{value:w},S);else throw new Error("Unsupported HTTP method");R.status===200&&((((G=(T=R==null?void 0:R.data)==null?void 0:T.data)==null?void 0:G.status)||((Z=R==null?void 0:R.data)==null?void 0:Z.status))===!0?(u(!0),k==="string"?c(((O=(B=R==null?void 0:R.data)==null?void 0:B.data)==null?void 0:O.description)||((M=R==null?void 0:R.data)==null?void 0:M.description)||"Validation successful"):g(((I=(E=R==null?void 0:R.data)==null?void 0:E.data)==null?void 0:I.description)||((q=R==null?void 0:R.data)==null?void 0:q.description)||{})):(console.error("Invalid input:",w),c("Unable to validate input"),u(!1)))}catch(R){console.error("Error validating input:",R),c(((ce=(oe=R==null?void 0:R.response)==null?void 0:oe.data)==null?void 0:ce.message)||"Unable to validate input"),u(!1)}finally{d(!1)}}},[x,k,h]);return v.useEffect(()=>{if(t){const w=setTimeout(()=>{N(t)},700);return()=>clearTimeout(w)}},[N,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:V("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:w=>{l(w.target.value),a(e==null?void 0:e.id,w.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"})]})]}),b&&!r&&i.jsx("span",{className:"block pr-3 text-lg text-green-600",children:i.jsx(H,{icon:"gg:check-o"})})]})]}),f&&k==="string"&&i.jsx("span",{className:`${b?"text-green-600":"text-red-600"} text-sm`,children:f}),k==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:Object.entries(y).map(([w,T])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[w,":"]}),_a(T)?i.jsx(Na,{imageUrl:T}):i.jsx("span",{children:String(T)})]},w))})]})}function ja({onGetTotal:e,readOnly:n,defaultValue:o,denominators:a}){const[s,t]=v.useState([...o]);function l(b,u){t(f=>{const c=[...f];return c[u]={...c[u],value:b},c})}function r(b,u){return parseFloat(b)*parseFloat(u)||0}const d=v.useMemo(()=>s.reduce((b,u)=>{const f=r(u.key,u.value);return b+f},0),[s]);return v.useEffect(()=>{e&&e(s)},[s]),v.useEffect(()=>{if(a!=null&&a.length){const b=a.map((u,f)=>({key:u.value,value:Array.isArray(o)&&o[f]?o[f].value:""}));t(b)}},[o,a]),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"})})]}),s.map((b,u)=>{var f,c;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:(f=parseFloat(b.key))==null?void 0:f.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(De,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:b.value,onValueChange:p=>l(p,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(c=r(b.key,b.value))==null?void 0:c.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:d==null?void 0:d.toLocaleString()})]})]})})}function Ma({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,getValues:s}=n||{},t=s&&s(e==null?void 0:e.id)||[];return v.useEffect(()=>{o(e.id)},[e.id,o]),i.jsx("div",{children:i.jsx(ja,{onGetTotal:l=>{a&&a(e.id,l)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:t,readOnly:e==null?void 0:e.isReadOnly})})}function Ta({element:e}){return i.jsx("div",{className:V("py-6",e==null?void 0:e.customClass)})}function Ea({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:V("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Ba({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 La({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 Pa({value:e=[],onChange:n,isReadOnly:o,columns:a=[]}){const[s,t]=v.useState(e),[l,r]=v.useState(null);v.useEffect(()=>{t(e)},[]);const d=(c,p,y)=>{const g=s.map((h,x)=>x===p?{...h,[y]:c}:h);t(g),n&&n(g)},b=()=>{const c=s.length>0?Math.max(...s.map(g=>Number(g.id)||0))+1:1,p=a.reduce((g,h)=>({...g,[h.field]:h.field==="id"?c:""}),{}),y=[...s,p];t(y),n&&n(y)},u=c=>{const p=s.filter((y,g)=>g!==c);t(p),n&&n(p)},f=(c,p)=>(l==null?void 0:l.rowIndex)===c&&(l==null?void 0:l.field)===p;return i.jsxs("div",{className:"mt-4 rounded",children:[i.jsx("div",{className:"flex justify-end",children:(a==null?void 0:a.length)>0&&!o&&i.jsx("button",{onClick:b,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.jsxs("table",{className:"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:[a.map(c=>i.jsx("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border",children:c.headerName||c.field},c.field)),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:s.length>0?s.map((c,p)=>{var y;return i.jsxs("tr",{children:[a.map(g=>{var h,x;return i.jsx("td",{className:"px-2 py-1 border",onDoubleClick:()=>g.editable&&!o&&r({rowIndex:p,field:g.field}),children:g.editable&&f(p,g.field)&&!o?i.jsx(i.Fragment,{children:g.type==="number"?i.jsx(De,{value:(h=c[g.field])!=null?h:"",onValueChange:k=>d(k,p,g.field),decimalsLimit:6,allowNegativeValue:!1,placeholder:"",className:"w-full px-2 py-1 border rounded outline-none"}):i.jsx("input",{autoFocus:!0,type:"text",value:(x=c[g.field])!=null?x:"",onChange:k=>d(k.target.value,p,g.field),onBlur:()=>r(null),className:"w-full px-2 py-1 text-gray-600 border rounded outline-none"})}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:c[g.field]})},g.field)}),!o&&i.jsx("td",{className:"px-2 py-1 text-center border",children:i.jsx("button",{onClick:()=>u(p),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:i.jsx(H,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]},(y=c.id)!=null?y:p)}):i.jsx("tr",{children:i.jsx("td",{colSpan:a.length+(o?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})]})}function Da({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,watch:s}=n||{},t=s&&s(e==null?void 0:e.id)||[];return v.useEffect(()=>{o(e.id)},[e.id,o]),console.log(e),i.jsx(Pa,{value:t,onChange:l=>{a(e.id,l)},columns:e==null?void 0:e.dataColumns,isReadOnly:e==null?void 0:e.isReadOnly})}const ln=({className:e="",options:n=[],placeholder:o="Select",errors:a,register:s,setValue:t,name:l,label:r,value:d,trigger:b,isMultiple:u=!1,isFloatingLabel:f=!1,subText:c,labelClass:p="",loading:y,disabled:g})=>{const[h,x]=v.useState(u?[]:null),k=V("custom-select__control",e),A=v.useMemo(()=>n,[n]);return v.useEffect(()=>{const S=n==null?void 0:n.find(N=>{var w;return typeof N.value=="string"&&typeof d=="string"?N.value.toLowerCase()===d.toLowerCase():typeof N.value=="object"&&typeof d=="object"?((w=N.value)==null?void 0:w.id)===(d==null?void 0:d.id):N.value===d});x(S||null)},[d,n]),v.useEffect(()=>{h&&t&&s&&(t(l,h==null?void 0:h.value),s(l),b==null||b(l))},[l,h]),i.jsxs("div",{className:"custom-select",children:[r&&!f&&i.jsx("label",{className:"custom-select__label",children:r}),f&&r&&i.jsx("label",{className:V("custom-select__floating-label",p),children:r}),i.jsx(P.Listbox,{value:h,onChange:x,multiple:u,disabled:g,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(P.Listbox.Button,{className:k,disabled:g,children:[y?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(H,{icon:"lucide:chevron-down"})})]}),i.jsx(P.Transition,{as:v.Fragment,leave:"custom-select__transition",children:i.jsx(P.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:A.map((S,N)=>i.jsx(P.Listbox.Option,{value:S,className:({active:w})=>V("custom-select__option",w&&"custom-select__option--active"),children:({selected:w})=>i.jsx("span",{className:V("custom-select__option-label",w&&"custom-select__option--selected"),children:S.label})},N))})})]})}),c&&!a&&i.jsx("p",{className:"custom-select__subtext",children:c}),a&&i.jsx("span",{className:"custom-select__error",children:a.message})]})},Oa=({element:e,validationData:n})=>{var g;const{register:o=()=>({}),trigger:a,setValue:s,watch:t,isReadOnly:l}=n||{},r=(g=e==null?void 0:e.id)!=null?g:"cascadeValue",[d,b]=v.useState(""),[u,f]=v.useState(""),c=(h,x)=>{const k=h&&x?`${h}_${x}`:"";s==null||s(r,k),a==null||a(r)},p=(h,x)=>{h==="first"?(b(x),f(""),c(x,"")):(f(x),c(d,x))};v.useEffect(()=>{if(t){const h=t(r);if(h!=null&&h.includes("_")){const[x,k]=h.split("_");b(x),f(k)}}},[t,r]);const y=v.useMemo(()=>{var h;return(h=e.options1)==null?void 0:h.filter(x=>x.key===d)},[e.options1,d]);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(ln,{setValue:(h,x)=>p("first",x),options:e.options,name:`${r}`,register:o,value:d})}),d&&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(ln,{setValue:(h,x)=>p("second",x),options:y,name:`${r}`,register:o,value:u})]})]})},Ia=({value:e=0,max:n=5,readOnly:o=!1,onChange:a,size:s=24,className:t="",element:l,validationData:r})=>{var x;const{register:d=()=>({}),trigger:b,setValue:u,watch:f,isReadOnly:c}=r||{},p=(x=f==null?void 0:f(l.id))!=null?x:0,[y,g]=v.useState(null);v.useEffect(()=>{p==null&&(u==null||u(l.id,e))},[]);const h=k=>{if(!o&&!c){const A=k+1;u==null||u(l.id,A),b==null||b(l.id),a==null||a(A)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(k,A)=>{const S=y!==null?A<=y:A<p;return i.jsx(en,{icon:S?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${S?"text-yellow-400":"text-gray-300"}`,width:s,height:s,onMouseEnter:()=>!(o||c)&&g(A),onMouseLeave:()=>!(o||c)&&g(null),onClick:()=>h(A)},A)})]})};function dn({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,trigger:s,isReadOnly:t,watch:l}=n||{},r=(l==null?void 0:l(e.id))||"",{country:d,state:b}=v.useMemo(()=>{if(typeof r=="string"&&r.includes(",")){const[y,g]=r.split(",").map(h=>h.trim());return{country:g,state:y}}return{country:r,state:""}},[r]),u=v.useRef(r),f=v.useMemo(()=>{var y,g;return d?((g=(y=an.find(h=>h.name===d))==null?void 0:y.states)==null?void 0:g.map(h=>({label:h.name,value:h.name})))||[]:[]},[d]),c=(y,g)=>{const x=(g==null?void 0:g.value)||"";a&&x!==u.current&&(a(e.id,x),s==null||s(e.id),u.current=x)},p=(y,g)=>{const h=(g==null?void 0:g.value)||"",x=h?`${h}, ${d}`:d;a&&x!==u.current&&(a(e.id,x),s==null||s(e.id),u.current=x)};return v.useEffect(()=>{u.current=r},[r]),i.jsxs("div",{className:"grid gap-y-6",children:[i.jsx("input",{type:"hidden",...o(e.id)}),i.jsx(ti,{options:e.options,onGetValue:c,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),f.length>0&&e.showState&&i.jsx(ti,{options:f,onGetValue:p,name:`${e.id}-state`,readOnly:t,defaultValue:b},`state-${b}`)]})}function Ka({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:a}=n||{},{validationUrl:s,documentObj:t,signatureLink:l}=e,r=v.useMemo(()=>te("config"),[]),[d,b]=v.useState(!1),[u,f]=v.useState(!1),c=v.useCallback(async()=>{var p,y;if(!(!s||!t))try{f(!0);const h={headers:{Authorization:`Bearer ${te("token")}`}},{data:x}=await Ae.get(`${s}/${t}`,h),k=!!((y=(p=x==null?void 0:x.data)==null?void 0:p.isSigned)!=null?y:x!=null&&x.isSigned);return b(k),k}catch(g){console.error("Failed to check sign status",g)}finally{f(!1)}},[s,t]);return v.useEffect(()=>{let p=null;return!d&&t&&s&&(async()=>{await c()||(p=setInterval(async()=>{await c()&&p&&clearInterval(p)},2e3))})(),()=>{p&&clearInterval(p)}},[c,d,t,s]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:V("field-control",e.customClass),...o(e.id),disabled:a}),i.jsx("a",{href:d?"#":l,children:i.jsxs("button",{type:"button",onClick:c,disabled:u||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:V("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(H,{icon:u?"solar:refresh-outline":d?"solar:check-circle-bold":"solar:pen-2-line-duotone",iconClass:u?"animate-spin":""}),u?"Checking...":d?"Signed":"Sign"]})})]})}const ui=[{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 Ga({label:e,placeholder:n,classLabel:o,isRequired:a,isOptional:s,name:t,value:l,error:r,disabled:d,readOnly:b,horizontal:u,description:f,validate:c,onChange:p,onError:y}){const[g,h]=v.useState(""),[x,k]=v.useState(null),[A,S]=v.useState(""),N=v.useMemo(()=>ui==null?void 0:ui.slice().sort((M,E)=>M.label.localeCompare(E.label)).map(M=>({...M,phone:`+${M.phone}`})),[]),w=v.useMemo(()=>g?N.filter(M=>`${M.label} ${M.phone}`.toLowerCase().includes(g.toLowerCase())):N,[g,N]),T=(x==null?void 0:x.min)||10,G=(x==null?void 0:x.max)||10,Z=()=>A?`${(x==null?void 0:x.phone)||"+234"}-${A}`:"",B=M=>{if(!M)return{code:"+234",number:""};const E=M.split(/[-\s]/);return{code:E[0],number:E.slice(1).join(" ")}};v.useEffect(()=>{if(l){const M=B(l);k(N.find(E=>E.phone===M.code)||N[0]),S(M.number)}},[l,N]);const O=v.useMemo(()=>{if(r)return r;const M=A.length;return a&&M===0?"Phone number is required":M>0&&!/^\d+$/.test(A)?"Phone number must contain only digits":M>0&&M<T?`Minimum length is ${T}`:M>G?`Maximum length is ${G}`:""},[r,A,T,G,a]);return v.useEffect(()=>{p==null||p(Z()),y==null||y(O||null)},[A,x,O]),i.jsxs("div",{className:`relative formGroup ${O?"has-error":""} ${u?"flex":""} ${!O&&A.length>0?"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," ",a&&i.jsx("span",{className:"text-red-500",children:"*"}),s&&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(H,{icon:"lucide:phone-call"}),i.jsx(P.Combobox,{value:x,onChange:k,children:i.jsxs("div",{className:"relative",children:[i.jsx(P.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:M=>(M==null?void 0:M.phone)||"+234",placeholder:"+234",onChange:M=>h(M.target.value)}),i.jsx(P.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(H,{icon:"lucide:chevron-down"})}),i.jsx(P.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:w.map((M,E)=>i.jsxs(P.Combobox.Option,{value:M,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[M.phone," - ",M.label]},`${M.code}+ ${E}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:A,disabled:d,readOnly:b,onChange:M=>{const E=M.target.value.replace(/\D/g,"");S(E)},placeholder:n,className:"w-full px-3 outline-none"}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!O&&A.length>0&&i.jsx("span",{className:"text-green-500",children:i.jsx(H,{icon:"bi:check-lg"})})})]})]}),O?i.jsx("span",{className:"block mt-1 text-sm text-red-500",children:O}):A.length>0&&c&&i.jsx("span",{className:"block mt-1 text-sm text-green-500",children:c}),f&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:f})]})}function Ra({element:e,validationData:n}){const{register:o=()=>({}),trigger:a,setValue:s,watch:t,isReadOnly:l}=n||{};let r;return v.useEffect(()=>{o(e.id)},[e.id,o]),t&&(r=t()[e.id]),i.jsx(Ga,{placeholder:e.placeholder,label:"",name:e.id,value:r,readOnly:l,disabled:l,onChange:d=>{d&&(s==null||s(e.id,d),a==null||a(e.id))}})}const rn={textField:qe,longText:Zo,selectField:Yo,multiSelect:si,numberField:qe,amountField:Sa,date:Kn,password:Wo,checkbox:qo,radio:Uo,email:qe,file:Vo,dataGrid:Da,section:Jo,validateInput:Ca,tableInput:Ma,spacer:Ta,divider:Ea,header:Ba,basicText:La,phoneField:Ra,cascadeSelect:Oa,rating:Ia,country:dn,bank:dn,document:Ka},un="edit",cn=(e,n)=>{const o=rn[e.type];return o?i.jsx(ri,{element:e,state:un,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:un,sectionId:n})]})}):null},ci=({col:e,children:n,customClass:o})=>i.jsx("div",{className:V("w-full bg-white",o),style:{gridColumn:e},children:n}),Fa=({element:e,sectionId:n,children:o,customClass:a,state:s})=>{const{formData:t,addElement:l,setIsDragging:r}=v.useContext(ae),d=v.useMemo(()=>Array.from({length:e.columns}),[e.columns]),b=v.useCallback(c=>{c.preventDefault(),c.stopPropagation(),c.dataTransfer.dropEffect="move"},[]),u=v.useCallback((c,p)=>{var y,g;c.preventDefault(),r(!1);try{const h=c.dataTransfer.getData("properties");if(!h)return;const x=JSON.parse(h);if((x==null?void 0:x.type)==="grid")return;const k=p+1;if((g=(y=t.find(N=>N.id===n))==null?void 0:y.questionData)==null?void 0:g.some(N=>{var w;return N.gridId===e.id&&((w=N.gridPosition)==null?void 0:w.col)===k}))return;const S={...x,id:ve.v4(),sectionId:n,gridId:e.id,gridPosition:{col:k}};l(S,n)}catch(h){console.error("Drop failed in grid:",h),r(!1)}},[l,e.id,t,n,r]),f=(c,p,y)=>{const g=Array.isArray(o)&&o.find(h=>{var x;return((x=h==null?void 0:h.props)==null?void 0:x.col)===c+1});return i.jsx("div",{children:i.jsx("div",{id:c.toString(),onDrop:h=>u(h,c),onDragOver:b,className:V("border rounded-lg min-h-[110px] bg-white ","flex items-center justify-center text-gray-400 transition-colors",`${y==="edit"?"p-3":""}`,p),children:g||i.jsx("span",{children:y==="edit"&&i.jsx(H,{icon:"ph:plus-bold"})})})},c)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:d.map((c,p)=>f(p,a,s))})})},mi=v.memo(Fa),za="edit";function Ha({elementData:e,sectionId:n}){const{formData:o,updateElementPosition:a,isDragging:s,setIsDragging:t,addElementInPosition:l}=v.useContext(ae),[r,d]=v.useState(null),[b,u]=v.useState(null),f=v.useMemo(()=>{var A;return((A=o.find(S=>S.id===n))==null?void 0:A.questionData)||[]},[o,n]),c=v.useCallback((A,S)=>{A.dataTransfer.setData("properties",S),d(S)},[]),p=v.useCallback((A,S)=>{A.preventDefault(),A.stopPropagation(),u(S)},[]),y=v.useCallback(A=>{A.preventDefault(),A.stopPropagation();const S=A.dataTransfer.getData("properties"),N=A.currentTarget.id;if(!N||S===N)return;const w=f.findIndex(B=>B.id===S),T=f.findIndex(B=>B.id===N);if(w===-1||T===-1)return;const G=[...f],[Z]=G.splice(w,1);G.splice(T,0,Z),a(G,n),d(null)},[f,n,a]),g=v.useCallback((A,S)=>{A.preventDefault(),t(!1);try{const N=JSON.parse(A.dataTransfer.getData("properties"));if(console.log({data:N}),(N==null?void 0:N.type)==="section")return;const w={...N,id:ve.v4(),sectionId:n};l(w,n,S)}catch(N){console.error("Drop error:",N)}},[l,n,t]),h=v.useCallback(A=>i.jsx("div",{className:"transition rounded hover:bg-blue-300",onDragOver:S=>S.preventDefault(),onDrop:S=>g(S,A),onDragEnd:()=>t(!1),children:i.jsx("div",{className:"bg-blue-50 rounded p-6 h-[60px] border-2 border-blue-300 border-dashed flex items-center justify-center text-gray-400 opacity-70",children:i.jsx(H,{icon:"octicon:plus-16"})})},`drop-${A}`),[g,t]),x=v.useCallback(A=>i.jsx("div",{id:A.id,className:V("cursor-move border p-4 w-full rounded-lg transition-colors bg-white",{"bg-gray-100":r===A.id,"border-dashed border-blue-300":r&&r!==A.id}),draggable:!0,onDragStart:S=>c(S,A.id),onDragOver:S=>p(S,A.id),onDrop:y,onDragEnd:()=>d(null),children:cn(A,n)},A.id),[r,y,p,n,c]),k=v.useMemo(()=>(e==null?void 0:e.reduce((A,S)=>(S.gridId&&(A[S.gridId]=A[S.gridId]||[],A[S.gridId].push(S)),A),{}))||{},[e]);return e!=null&&e.length?i.jsx("div",{className:"relative grid w-full h-full grid-cols-1 gap-4",children:e.map((A,S)=>{if(A.type==="grid"){const N=k[A.id]||[];return i.jsx("div",{draggable:!0,onDragStart:w=>c(w,A.id),onDragOver:w=>p(w,A.id),onDrop:y,onDragEnd:()=>d(null),className:"w-full p-4 transition-colors bg-white border rounded-lg cursor-move",children:i.jsx(ri,{element:A,state:"edit",children:i.jsx(mi,{element:A,sectionId:n,state:za,children:N.map(w=>{var T;return i.jsx(ci,{col:(T=w.gridPosition)==null?void 0:T.col,children:cn(w,n)},w.id)})})})},A.id)}return A.gridId?null:i.jsxs("div",{className:V("group relative grid gap-y-[6px]",A.elementClass),children:[s&&b===A.id&&h(S),i.jsx("div",{className:"group",children:x(A)}),s&&b===A.id&&h(S+1)]},A.id)})}):i.jsx("div",{onDragOver:A=>A.preventDefault(),onDrop:A=>g(A,0),onDragEnd:()=>t(!1),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 Va=v.memo(Ha),Wa=j.object({title:j.string(),description:j.string()}).required(),bi=te("config"),Ua=({isOpen:e,onClose:n,section:o})=>{const{updateSection:a}=v.useContext(ae),{register:s,handleSubmit:t,formState:{errors:l,isSubmitting:r,isValid:d},reset:b}=me.useForm({resolver:li(Wa),defaultValues:o});if(v.useEffect(()=>{e||b()},[e,b]),!e)return null;const u=f=>{a(f,o.id),n()};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(H,{icon:"tabler:x"})})]}),i.jsxs("form",{onSubmit:t(u),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(D,{label:"Title",name:"title",register:s,errors:l}),i.jsx(D,{label:"Description",name:"description",register:s,errors:l})]}),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:!d||r,style:{background:(bi==null?void 0:bi.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!d||r?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!d||r?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:r?"Saving...":"Save"})]})]})]})})},Ja=()=>{const[e,n]=v.useState(!1),o=v.useRef(null),a=v.useRef(null),{removeSection:s,addSection:t,formData:l,setIsDragging:r,setSelectedSection:d,selectedSection:b,activeSections:u,setActiveSections:f}=v.useContext(ae);v.useEffect(()=>{var h;d(((h=l[0])==null?void 0:h.id)||null)},[]);const c=v.useCallback(h=>{h.preventDefault(),h.dataTransfer.dropEffect="move",a.current&&(a.current.scrollTop=a.current.scrollHeight)},[]);function p(h){u.includes(h)?f(x=>x.filter(k=>k!==h)):f(x=>[...x,h])}function y(h){o.current=h,n(!0)}const g=te("config");return i.jsxs("div",{ref:a,className:"relative flex flex-col h-full px-6 pb-5 mx-auto gap-x-4",children:[e&&i.jsx(Ua,{isOpen:e,onClose:()=>n(!1),section:o.current}),i.jsxs("div",{className:"relative flex flex-col flex-1 w-full py-4 gap-y-6",children:[l.map((h,x)=>i.jsx("div",{className:"bg-white group cursor-pointer rounded ",children:i.jsxs("div",{className:`border border-gray-100 rounded px-4 shadow-[rgba(149,157,165,0.2)_0px_2px_4px] transition-colors duration-200
|
|
48
|
+
}`})})]})})}),ga=()=>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 ha(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const fa=["text","number","boolean"],tn=["equals","not_equals","contains","not_contains"],xa=["greater","less"];function ya({register:e,setValue:n,trigger:o,watch:a,id:s}){const{formData:t}=v.useContext(ae),l=a("visibilityDependentFields")||[],r=v.useMemo(()=>ha(t).filter(b=>b.id!==s).map(b=>{const u=l.find(f=>f.id===b.id);return{id:b.id,value:b.id,label:b.inputLabel,sectionId:b.sectionId,fieldType:(u==null?void 0:u.fieldType)||"text",operator:(u==null?void 0:u.operator)||"equals",fieldValue:(u==null?void 0:u.fieldValue)!==void 0?u.fieldValue:""}}),[t,l,s]),d=(b,u,f)=>{const c=l.map((p,y)=>y===b?{...p,[u]:f}:p);n("visibilityDependentFields",c)};return i.jsxs("div",{className:"visibility-editor",children:[i.jsx("label",{className:"label",children:"Select Dependent Fields"}),i.jsx(si,{element:{options:r,id:"visibilityDependentFields",value:a("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:o,watch:a}}),l.length>0&&i.jsx("div",{className:"py-1 bg-gray-100 rounded dependent-fields",children:l.map((b,u)=>{var f;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:b.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(P.Listbox,{value:b.fieldType,onChange:c=>d(u,"fieldType",c),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(P.Listbox.Button,{className:"listbox-button",children:b.fieldType}),i.jsx(P.Transition,{as:v.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(P.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:fa.map(c=>i.jsx(P.Listbox.Option,{value:c,className:"listbox-option",children:c},c))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(P.Listbox,{value:b.operator,onChange:c=>d(u,"operator",c),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(P.Listbox.Button,{className:"listbox-button",children:b.operator.replace("_"," ")}),i.jsx(P.Transition,{as:v.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(P.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(b.fieldType==="number"?[...tn,...xa]:tn).map(c=>i.jsx(P.Listbox.Option,{value:c,className:"listbox-option",children:c.replace("_"," ")},c))})})]})})}),b.fieldType!=="boolean"?i.jsx("input",{type:b.fieldType,value:b.fieldValue||"",onChange:c=>d(u,"fieldValue",c.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(P.Listbox,{value:(f=b.fieldValue)!=null?f:"",onChange:c=>d(u,"fieldValue",c),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(P.Listbox.Button,{className:"listbox-button",children:b.fieldValue===!0?"True":b.fieldValue===!1?"False":"Select value"}),i.jsx(P.Transition,{as:v.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(P.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(P.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(P.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},b.id)})})]})}const ka=j.object().shape({inputLabel:j.string().nullable(),placeholder:j.string().nullable(),description:j.string().nullable(),isReadOnly:j.boolean(),isDisabled:j.boolean(),isRequired:j.boolean(),requiredMessage:j.string().nullable(),minLengthMessage:j.string().nullable(),maxLengthMessage:j.string().nullable(),maxLength:j.number().typeError("Expecting a number").nullable(),minLength:j.number().typeError("Expecting a number").nullable(),inputType:j.string().nullable(),maxAmountMessage:j.string().nullable(),maxAmount:j.string().nullable(),options:j.array().of(j.object().shape({label:j.string().nullable(),value:j.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:j.array().of(j.object().shape({label:j.string().nullable(),value:j.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:j.string().nullable(),url:j.string().nullable(),method:j.string().nullable(),denominators:j.mixed().nullable(),responseType:j.string().nullable(),minAmount:j.string().nullable(),heading:j.string().nullable(),minAmountMessage:j.string().nullable(),columns:j.number().nullable(),value:j.mixed().nullable(),customClass:j.string().nullable(),elementClass:j.string().nullable(),apiUrl:j.string().nullable(),selectType:j.string().default("list"),dateType:j.string().default("basic"),validationUrl:j.string(),signatureLink:j.string(),minDate:j.string().nullable(),maxDate:j.string().nullable(),canHaveDateRange:j.boolean(),allowYearPicker:j.boolean(),isHidden:j.boolean(),visibilityDependentFields:j.array().nullable(),isMultiple:j.boolean(),acceptedFiles:j.array(),showState:j.boolean()}),wa=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],Aa=({isOpen:e,onClose:n,element:o})=>{const a=wa.filter(F=>!ze.includes(o.inputType)||F.key!=="validation"),{updateElement:s}=v.useContext(ae),[t,l]=v.useState("basic"),[r,d]=v.useState(!1),[b,u]=v.useState("manual"),f=te("config"),{register:c,handleSubmit:p,control:y,setValue:g,watch:h,trigger:x,formState:{errors:k,isSubmitting:A,isValid:S},reset:N}=me.useForm({resolver:li(ka),defaultValues:{...o,options:o.options||[]}}),w=h(),{fields:T,append:G,remove:Z}=me.useFieldArray({control:y,name:"options"}),{fields:B,append:O,remove:M}=me.useFieldArray({control:y,name:"options1"}),{fields:E,append:I,remove:q}=me.useFieldArray({control:y,name:"dataColumns"});v.useEffect(()=>{e||N()},[e,N]);const oe=F=>{s(F,o.sectionId),n()},R={headers:{Authorization:`Bearer ${te("token")}`}},be=v.useCallback(async()=>{var F,U,$;if(!w.apiUrl||!/^https?:\/\//.test(w.apiUrl)){de.toast.info("Please provide a valid API URL");return}try{d(!0);const{status:Q,data:X}=await Ae.get(w.apiUrl,R);if(Q!==200||!X){de.toast.error("Unexpected response from server.");return}const re=X.data||X.record||X.result;if(!Array.isArray(re)){de.toast.error("Expected an array in response (data, record, or result).");return}((F=o.type)==null?void 0:F.toLowerCase())==="datagrid"?g("dataColumns",re):g("options",re)}catch(Q){const X=(($=(U=Q==null?void 0:Q.response)==null?void 0:U.data)==null?void 0:$.message)||(Q==null?void 0:Q.message)||"Unable to load options";de.toast.error(X)}finally{d(!1)}},[o.type,g,w.apiUrl]),pe=["manual","api","sheet"];function ge(){b==="api"&&be()}const xe=()=>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:pe.map(F=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:U=>u(U.target.value),value:F})," ",i.jsxs("span",{children:[F," options"]})]},F))}),b==="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(D,{label:"Load Options from Api",name:"apiUrl",errors:k,register:c,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:ge,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(ba,{})]}),b==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(sn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:g,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),T.map((F,U)=>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(D,{label:"Label",name:`options.${U}.label`,register:c,errors:k,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Value",name:`options.${U}.value`,register:c,errors:k,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("button",{disabled:T.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>Z(U),children:i.jsx(H,{icon:"iconamoon:sign-times-fill"})})]},F.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:()=>G({label:"",value:"",id:ve.v4()}),children:[i.jsx(H,{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 "}),B==null?void 0:B.map((F,U)=>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(D,{label:"Label",name:`options1.${U}.label`,register:c,errors:k,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Value",name:`options1.${U}.value`,register:c,errors:k,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Key",name:`options1.${U}.key`,register:c,errors:k,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:B.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>M(U),children:i.jsx(H,{icon:"iconamoon:sign-times-fill"})})]},F.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:()=>O({label:"",value:"",key:"",id:ve.v4()}),children:[i.jsx(H,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),ye=()=>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:pe.map(F=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:U=>u(U.target.value),value:F,checked:F===b})," ",i.jsxs("span",{children:[F," options"]})]},F))}),b==="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(D,{label:"Load Columns from Api",name:"apiUrl",errors:k,register:c,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:ge,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(va,{})]}),b==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(sn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:g,name:"dataColumns"})}),E.map((F,U)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Field key",name:`dataColumns.${U}.field`,register:c,errors:k,element:o,placeholder:"Field",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Header Name",name:`dataColumns.${U}.headerName`,register:c,errors:k,element:o,placeholder:"headerName",isFloating:!0})}),i.jsx("button",{disabled:E.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>q(U),children:i.jsx(H,{icon:"iconamoon:sign-times-fill"})})]},F.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({headerName:"",field:"",editable:!0,id:ve.v4()}),children:[i.jsx(H,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),ke=v.useCallback(async()=>{const F=te("token"),{status:U,data:$}=await Ae.get(w.url,{headers:{Authorization:`Bearer ${F}`}});U===200&&(console.log({data:$}),g("options",($==null?void 0:$.data)||$))},[g,w.url]);return v.useEffect(()=>{o.type==="document"&&w.url&&ke()},[w.url,o.type,ke]),i.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-end z-[999] cursor-default select-none ",draggable:"true",onDragStart:F=>F.preventDefault(),children:i.jsxs("div",{className:"w-full lg:w-1/3 xl:w-1/4 bg-white h-screen shadow-xl relative flex flex-col items-center select-",draggable:"true",onDragStart:F=>F.preventDefault(),children:[i.jsx("div",{className:"w-full pt-4",children:i.jsx($o,{tabs:a,setActiveTab:l,activeTab:t,className:"justify-start !text-left",btnClass:" !text-left"})}),i.jsxs("form",{onSubmit:p(oe),className:"w-full flex-1 flex flex-col",children:[i.jsxs("div",{className:"flex-1",children:[" ",i.jsxs("div",{className:" max-h-[75vh] overflow-y-auto flex-1",children:[t==="basic"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[di.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(D,{label:"Value",name:"value",register:c,errors:k,element:o})}),!di.includes(o.inputType)&&!ze.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(D,{label:"Label",name:"inputLabel",register:c,errors:k,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(D,{label:"Child Label",name:"childLabel",register:c,errors:k,element:o})]}),sa.includes(o.inputType)&&i.jsx(D,{label:"Placeholder",name:"placeholder",register:c,errors:k,element:o}),oa.includes(o.inputType)&&i.jsx(D,{label:"Prefix",name:"prefix",register:c,errors:k,element:o}),da.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(ma,{}),i.jsx(D,{label:"Api Url",name:"url",register:c,errors:k,element:o}),i.jsx(Le,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:c,name:"method",setValue:g,trigger:x,value:h("method")}),i.jsx(Le,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:c,name:"responseType",setValue:g,trigger:x,value:h("responseType")})]}),ra.includes(o.inputType)&&i.jsx(ca,{onChange:F=>{g("denominators",F)},value:h("denominators")}),!di.includes(o.inputType)&&!ze.includes(o.inputType)&&i.jsx(D,{label:"Short Description",name:"description",register:c,errors:k,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Le,{label:"Date Format",options:na,register:c,name:"dateFormat",setValue:g,trigger:x,value:h("dateFormat")}),i.jsx(D,{label:"Allow Range",name:"canHaveDateRange",register:c,errors:k,element:o,type:"checkbox"}),(w==null?void 0:w.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx(Je,{name:"minDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select min date"}),i.jsx(Je,{name:"maxDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select max date",minDate:w==null?void 0:w.minDate})]}),i.jsx(D,{label:"Allow Year Picker",name:"allowYearPicker",register:c,errors:k,element:o,type:"checkbox"})]}),o.type.toLowerCase()==="country"&&i.jsx(D,{label:"Allow States",name:"showState",register:c,errors:k,element:o,type:"checkbox"}),o.type.toLowerCase()==="selectfield"&&i.jsx(Le,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:c,name:"selectType",setValue:g,trigger:x,value:h("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(D,{label:"Number of columns",name:"columns",register:c,errors:k,element:o}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(D,{label:"Document Options Url",name:"url",register:c,errors:k,element:o})," ",i.jsx(pa,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(D,{label:"Document Validation Url",name:"validationUrl",register:c,errors:k,element:o}),i.jsx(ga,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(D,{label:"Signature Page Url",name:"signatureLink",register:c,errors:k,element:o})})]}),o.type.toLowerCase()==="datagrid"&&ye(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(D,{label:"Allow Multiple Uploads",name:"isMultiple",register:c,errors:k,element:o,type:"checkbox"}),i.jsx(si,{element:{options:ua,id:"acceptedFiles",value:w==null?void 0:w.acceptedFiles},validationData:{register:c,setValue:g,trigger:x,watch:h},placeholder:"Choose file types"})]}),la.includes(o.inputType)&&xe(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(D,{label:"Toggle Visibility",name:"isHidden",register:c,errors:k,element:o,type:"checkbox"})})," ",w.isHidden&&i.jsx(ya,{register:c,setValue:g,trigger:x,watch:h,id:o==null?void 0:o.id})]})]}),!ze.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(D,{label:"Required",name:"isRequired",register:c,errors:k,element:o,type:"checkbox"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"requiredMessage",register:c,errors:k,element:o})})]}),aa.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(D,{label:"Min Length",name:"minLength",register:c,errors:k,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"minLengthMessage",register:c,errors:k,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(D,{label:"Max Length",name:"maxLength",register:c,errors:k,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"maxLengthMessage",register:c,errors:k,element:o})})]})]}),ta.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(D,{label:"Min Amount",name:"minAmount",register:c,errors:k,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"minAmountMessage",register:c,errors:k,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(D,{label:"Max Amount",name:"maxAmount",register:c,errors:k,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(D,{label:"Error message text",name:"maxAmountMessage",register:c,errors:k,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-4 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:!S||A,style:{background:(f==null?void 0:f.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!S||A?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!S||A?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:A?"Saving...":"Save"})]})]})]})})},ri=v.memo(({state:e,element:n,children:o})=>{const[a,s]=v.useState(!1),{removeElement:t}=v.useContext(ae),l=v.useMemo(()=>{var d;return(d=n==null?void 0:n.acceptedFiles)==null?void 0:d.map(b=>b.label).join(", ")},[n]),r=v.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return i.jsxs("div",{className:"w-full",children:[a&&i.jsx(Aa,{isOpen:a,onClose:()=>s(!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," ",l&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",l==null?void 0:l.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:()=>s(!0),children:i.jsx(H,{icon:"circum:edit",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:r,children:i.jsx(H,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});ri.displayName="ElementContainer";function Sa({element:e,validationData:n}){const{register:o=()=>({}),trigger:a,setValue:s,watch:t,isReadOnly:l}=n||{};let r;return t&&(r=t()[e.id]),i.jsx(D,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:a,setValue:s,value:r,prefix:e.prefix,disabled:l})}function _a(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 Na=({imageUrl:e})=>{const[n,o]=v.useState(!1),a=()=>{o(!0)},s=()=>{o(!1)};return i.jsxs("div",{children:[i.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:a,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:s,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:s,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 Ca({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,watch:s}=n||{},[t,l]=v.useState(),[r,d]=v.useState(!1),[b,u]=v.useState(!1),[f,c]=v.useState(""),p=s&&s(e==null?void 0:e.id);v.useEffect(()=>{l(p)},[p]);const[y,g]=v.useState("");v.useEffect(()=>{o(e.id)},[e.id,o]);const{url:h,method:x,responseType:k}=e||{},S={headers:{Authorization:`Bearer ${te("token")}`}},N=v.useCallback(async w=>{var T,G,Z,B,O,M,E,I,q,oe,ce;if(!(!h||!x)){d(!0);try{let R;if(x.toLowerCase()==="get"){const be=`${h}?value=${w}`;R=await Ae.get(be,S)}else if(x.toLowerCase()==="post")R=await Ae.post(h,{value:w},S);else throw new Error("Unsupported HTTP method");R.status===200&&((((G=(T=R==null?void 0:R.data)==null?void 0:T.data)==null?void 0:G.status)||((Z=R==null?void 0:R.data)==null?void 0:Z.status))===!0?(u(!0),k==="string"?c(((O=(B=R==null?void 0:R.data)==null?void 0:B.data)==null?void 0:O.description)||((M=R==null?void 0:R.data)==null?void 0:M.description)||"Validation successful"):g(((I=(E=R==null?void 0:R.data)==null?void 0:E.data)==null?void 0:I.description)||((q=R==null?void 0:R.data)==null?void 0:q.description)||{})):(console.error("Invalid input:",w),c("Unable to validate input"),u(!1)))}catch(R){console.error("Error validating input:",R),c(((ce=(oe=R==null?void 0:R.response)==null?void 0:oe.data)==null?void 0:ce.message)||"Unable to validate input"),u(!1)}finally{d(!1)}}},[x,k,h]);return v.useEffect(()=>{if(t){const w=setTimeout(()=>{N(t)},700);return()=>clearTimeout(w)}},[N,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:V("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:w=>{l(w.target.value),a(e==null?void 0:e.id,w.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"})]})]}),b&&!r&&i.jsx("span",{className:"block pr-3 text-lg text-green-600",children:i.jsx(H,{icon:"gg:check-o"})})]})]}),f&&k==="string"&&i.jsx("span",{className:`${b?"text-green-600":"text-red-600"} text-sm`,children:f}),k==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:Object.entries(y).map(([w,T])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[w,":"]}),_a(T)?i.jsx(Na,{imageUrl:T}):i.jsx("span",{children:String(T)})]},w))})]})}function ja({onGetTotal:e,readOnly:n,defaultValue:o,denominators:a}){const[s,t]=v.useState([...o]);function l(b,u){t(f=>{const c=[...f];return c[u]={...c[u],value:b},c})}function r(b,u){return parseFloat(b)*parseFloat(u)||0}const d=v.useMemo(()=>s.reduce((b,u)=>{const f=r(u.key,u.value);return b+f},0),[s]);return v.useEffect(()=>{e&&e(s)},[s]),v.useEffect(()=>{if(a!=null&&a.length){const b=a.map((u,f)=>({key:u.value,value:Array.isArray(o)&&o[f]?o[f].value:""}));t(b)}},[o,a]),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"})})]}),s.map((b,u)=>{var f,c;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:(f=parseFloat(b.key))==null?void 0:f.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(De,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:b.value,onValueChange:p=>l(p,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(c=r(b.key,b.value))==null?void 0:c.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:d==null?void 0:d.toLocaleString()})]})]})})}function Ma({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,getValues:s}=n||{},t=s&&s(e==null?void 0:e.id)||[];return v.useEffect(()=>{o(e.id)},[e.id,o]),i.jsx("div",{children:i.jsx(ja,{onGetTotal:l=>{a&&a(e.id,l)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:t,readOnly:e==null?void 0:e.isReadOnly})})}function Ta({element:e}){return i.jsx("div",{className:V("py-6",e==null?void 0:e.customClass)})}function Ea({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:V("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Ba({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 La({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 Pa({value:e=[],onChange:n,isReadOnly:o,columns:a=[]}){const[s,t]=v.useState(e),[l,r]=v.useState(null);v.useEffect(()=>{t(e)},[]);const d=(c,p,y)=>{const g=s.map((h,x)=>x===p?{...h,[y]:c}:h);t(g),n&&n(g)},b=()=>{const c=s.length>0?Math.max(...s.map(g=>Number(g.id)||0))+1:1,p=a.reduce((g,h)=>({...g,[h.field]:h.field==="id"?c:""}),{}),y=[...s,p];t(y),n&&n(y)},u=c=>{const p=s.filter((y,g)=>g!==c);t(p),n&&n(p)},f=(c,p)=>(l==null?void 0:l.rowIndex)===c&&(l==null?void 0:l.field)===p;return i.jsxs("div",{className:"mt-4 rounded",children:[i.jsx("div",{className:"flex justify-end",children:(a==null?void 0:a.length)>0&&!o&&i.jsx("button",{onClick:b,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.jsxs("table",{className:"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:[a.map(c=>i.jsx("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border",children:c.headerName||c.field},c.field)),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:s.length>0?s.map((c,p)=>{var y;return i.jsxs("tr",{children:[a.map(g=>{var h,x;return i.jsx("td",{className:"px-2 py-1 border",onDoubleClick:()=>g.editable&&!o&&r({rowIndex:p,field:g.field}),children:g.editable&&f(p,g.field)&&!o?i.jsx(i.Fragment,{children:g.type==="number"?i.jsx(De,{value:(h=c[g.field])!=null?h:"",onValueChange:k=>d(k,p,g.field),decimalsLimit:6,allowNegativeValue:!1,placeholder:"",className:"w-full px-2 py-1 border rounded outline-none"}):i.jsx("input",{autoFocus:!0,type:"text",value:(x=c[g.field])!=null?x:"",onChange:k=>d(k.target.value,p,g.field),onBlur:()=>r(null),className:"w-full px-2 py-1 text-gray-600 border rounded outline-none"})}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:c[g.field]})},g.field)}),!o&&i.jsx("td",{className:"px-2 py-1 text-center border",children:i.jsx("button",{onClick:()=>u(p),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:i.jsx(H,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]},(y=c.id)!=null?y:p)}):i.jsx("tr",{children:i.jsx("td",{colSpan:a.length+(o?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})]})}function Da({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,watch:s}=n||{},t=s&&s(e==null?void 0:e.id)||[];return v.useEffect(()=>{o(e.id)},[e.id,o]),console.log(e),i.jsx(Pa,{value:t,onChange:l=>{a(e.id,l)},columns:e==null?void 0:e.dataColumns,isReadOnly:e==null?void 0:e.isReadOnly})}const ln=({className:e="",options:n=[],placeholder:o="Select",errors:a,register:s,setValue:t,name:l,label:r,value:d,trigger:b,isMultiple:u=!1,isFloatingLabel:f=!1,subText:c,labelClass:p="",loading:y,disabled:g})=>{const[h,x]=v.useState(u?[]:null),k=V("custom-select__control",e),A=v.useMemo(()=>n,[n]);return v.useEffect(()=>{const S=n==null?void 0:n.find(N=>{var w;return typeof N.value=="string"&&typeof d=="string"?N.value.toLowerCase()===d.toLowerCase():typeof N.value=="object"&&typeof d=="object"?((w=N.value)==null?void 0:w.id)===(d==null?void 0:d.id):N.value===d});x(S||null)},[d,n]),v.useEffect(()=>{h&&t&&s&&(t(l,h==null?void 0:h.value),s(l),b==null||b(l))},[l,h]),i.jsxs("div",{className:"custom-select",children:[r&&!f&&i.jsx("label",{className:"custom-select__label",children:r}),f&&r&&i.jsx("label",{className:V("custom-select__floating-label",p),children:r}),i.jsx(P.Listbox,{value:h,onChange:x,multiple:u,disabled:g,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(P.Listbox.Button,{className:k,disabled:g,children:[y?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(H,{icon:"lucide:chevron-down"})})]}),i.jsx(P.Transition,{as:v.Fragment,leave:"custom-select__transition",children:i.jsx(P.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:A.map((S,N)=>i.jsx(P.Listbox.Option,{value:S,className:({active:w})=>V("custom-select__option",w&&"custom-select__option--active"),children:({selected:w})=>i.jsx("span",{className:V("custom-select__option-label",w&&"custom-select__option--selected"),children:S.label})},N))})})]})}),c&&!a&&i.jsx("p",{className:"custom-select__subtext",children:c}),a&&i.jsx("span",{className:"custom-select__error",children:a.message})]})},Oa=({element:e,validationData:n})=>{var g;const{register:o=()=>({}),trigger:a,setValue:s,watch:t,isReadOnly:l}=n||{},r=(g=e==null?void 0:e.id)!=null?g:"cascadeValue",[d,b]=v.useState(""),[u,f]=v.useState(""),c=(h,x)=>{const k=h&&x?`${h}_${x}`:"";s==null||s(r,k),a==null||a(r)},p=(h,x)=>{h==="first"?(b(x),f(""),c(x,"")):(f(x),c(d,x))};v.useEffect(()=>{if(t){const h=t(r);if(h!=null&&h.includes("_")){const[x,k]=h.split("_");b(x),f(k)}}},[t,r]);const y=v.useMemo(()=>{var h;return(h=e.options1)==null?void 0:h.filter(x=>x.key===d)},[e.options1,d]);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(ln,{setValue:(h,x)=>p("first",x),options:e.options,name:`${r}`,register:o,value:d})}),d&&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(ln,{setValue:(h,x)=>p("second",x),options:y,name:`${r}`,register:o,value:u})]})]})},Ia=({value:e=0,max:n=5,readOnly:o=!1,onChange:a,size:s=24,className:t="",element:l,validationData:r})=>{var x;const{register:d=()=>({}),trigger:b,setValue:u,watch:f,isReadOnly:c}=r||{},p=(x=f==null?void 0:f(l.id))!=null?x:0,[y,g]=v.useState(null);v.useEffect(()=>{p==null&&(u==null||u(l.id,e))},[]);const h=k=>{if(!o&&!c){const A=k+1;u==null||u(l.id,A),b==null||b(l.id),a==null||a(A)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(k,A)=>{const S=y!==null?A<=y:A<p;return i.jsx(en,{icon:S?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${S?"text-yellow-400":"text-gray-300"}`,width:s,height:s,onMouseEnter:()=>!(o||c)&&g(A),onMouseLeave:()=>!(o||c)&&g(null),onClick:()=>h(A)},A)})]})};function dn({element:e,validationData:n}){const{register:o=()=>({}),setValue:a,trigger:s,isReadOnly:t,watch:l}=n||{},r=(l==null?void 0:l(e.id))||"",{country:d,state:b}=v.useMemo(()=>{if(typeof r=="string"&&r.includes(",")){const[y,g]=r.split(",").map(h=>h.trim());return{country:g,state:y}}return{country:r,state:""}},[r]),u=v.useRef(r),f=v.useMemo(()=>{var y,g;return d?((g=(y=an.find(h=>h.name===d))==null?void 0:y.states)==null?void 0:g.map(h=>({label:h.name,value:h.name})))||[]:[]},[d]),c=(y,g)=>{const x=(g==null?void 0:g.value)||"";a&&x!==u.current&&(a(e.id,x),s==null||s(e.id),u.current=x)},p=(y,g)=>{const h=(g==null?void 0:g.value)||"",x=h?`${h}, ${d}`:d;a&&x!==u.current&&(a(e.id,x),s==null||s(e.id),u.current=x)};return v.useEffect(()=>{u.current=r},[r]),i.jsxs("div",{className:"grid gap-y-6",children:[i.jsx("input",{type:"hidden",...o(e.id)}),i.jsx(ti,{options:e.options,onGetValue:c,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),f.length>0&&e.showState&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"Select State"}),i.jsx(ti,{options:f,onGetValue:p,name:`${e.id}-state`,readOnly:t,defaultValue:b},`state-${b}`)]})]})}function Ka({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:a}=n||{},{validationUrl:s,documentObj:t,signatureLink:l}=e,r=v.useMemo(()=>te("config"),[]),[d,b]=v.useState(!1),[u,f]=v.useState(!1),c=v.useCallback(async()=>{var p,y;if(!(!s||!t))try{f(!0);const h={headers:{Authorization:`Bearer ${te("token")}`}},{data:x}=await Ae.get(`${s}/${t}`,h),k=!!((y=(p=x==null?void 0:x.data)==null?void 0:p.isSigned)!=null?y:x!=null&&x.isSigned);return b(k),k}catch(g){console.error("Failed to check sign status",g)}finally{f(!1)}},[s,t]);return v.useEffect(()=>{let p=null;return!d&&t&&s&&(async()=>{await c()||(p=setInterval(async()=>{await c()&&p&&clearInterval(p)},2e3))})(),()=>{p&&clearInterval(p)}},[c,d,t,s]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:V("field-control",e.customClass),...o(e.id),disabled:a}),i.jsx("a",{href:d?"#":l,children:i.jsxs("button",{type:"button",onClick:c,disabled:u||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:V("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(H,{icon:u?"solar:refresh-outline":d?"solar:check-circle-bold":"solar:pen-2-line-duotone",iconClass:u?"animate-spin":""}),u?"Checking...":d?"Signed":"Sign"]})})]})}const ui=[{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 Ga({label:e,placeholder:n,classLabel:o,isRequired:a,isOptional:s,name:t,value:l,error:r,disabled:d,readOnly:b,horizontal:u,description:f,validate:c,onChange:p,onError:y}){const[g,h]=v.useState(""),[x,k]=v.useState(null),[A,S]=v.useState(""),N=v.useMemo(()=>ui==null?void 0:ui.slice().sort((M,E)=>M.label.localeCompare(E.label)).map(M=>({...M,phone:`+${M.phone}`})),[]),w=v.useMemo(()=>g?N.filter(M=>`${M.label} ${M.phone}`.toLowerCase().includes(g.toLowerCase())):N,[g,N]),T=(x==null?void 0:x.min)||10,G=(x==null?void 0:x.max)||10,Z=()=>A?`${(x==null?void 0:x.phone)||"+234"}-${A}`:"",B=M=>{if(!M)return{code:"+234",number:""};const E=M.split(/[-\s]/);return{code:E[0],number:E.slice(1).join(" ")}};v.useEffect(()=>{if(l){const M=B(l);k(N.find(E=>E.phone===M.code)||N[0]),S(M.number)}},[l,N]);const O=v.useMemo(()=>{if(r)return r;const M=A.length;return a&&M===0?"Phone number is required":M>0&&!/^\d+$/.test(A)?"Phone number must contain only digits":M>0&&M<T?`Minimum length is ${T}`:M>G?`Maximum length is ${G}`:""},[r,A,T,G,a]);return v.useEffect(()=>{p==null||p(Z()),y==null||y(O||null)},[A,x,O]),i.jsxs("div",{className:`relative formGroup ${O?"has-error":""} ${u?"flex":""} ${!O&&A.length>0?"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," ",a&&i.jsx("span",{className:"text-red-500",children:"*"}),s&&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(H,{icon:"lucide:phone-call"}),i.jsx(P.Combobox,{value:x,onChange:k,children:i.jsxs("div",{className:"relative",children:[i.jsx(P.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:M=>(M==null?void 0:M.phone)||"+234",placeholder:"+234",onChange:M=>h(M.target.value)}),i.jsx(P.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(H,{icon:"lucide:chevron-down"})}),i.jsx(P.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:w.map((M,E)=>i.jsxs(P.Combobox.Option,{value:M,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[M.phone," - ",M.label]},`${M.code}+ ${E}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:A,disabled:d,readOnly:b,onChange:M=>{const E=M.target.value.replace(/\D/g,"");S(E)},placeholder:n,className:"w-full px-3 outline-none"}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!O&&A.length>0&&i.jsx("span",{className:"text-green-500",children:i.jsx(H,{icon:"bi:check-lg"})})})]})]}),O?i.jsx("span",{className:"block mt-1 text-sm text-red-500",children:O}):A.length>0&&c&&i.jsx("span",{className:"block mt-1 text-sm text-green-500",children:c}),f&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:f})]})}function Ra({element:e,validationData:n}){const{register:o=()=>({}),trigger:a,setValue:s,watch:t,isReadOnly:l}=n||{};let r;return v.useEffect(()=>{o(e.id)},[e.id,o]),t&&(r=t()[e.id]),i.jsx(Ga,{placeholder:e.placeholder,label:"",name:e.id,value:r,readOnly:l,disabled:l,onChange:d=>{d&&(s==null||s(e.id,d),a==null||a(e.id))}})}const rn={textField:qe,longText:Zo,selectField:Yo,multiSelect:si,numberField:qe,amountField:Sa,date:Kn,password:Wo,checkbox:qo,radio:Uo,email:qe,file:Vo,dataGrid:Da,section:Jo,validateInput:Ca,tableInput:Ma,spacer:Ta,divider:Ea,header:Ba,basicText:La,phoneField:Ra,cascadeSelect:Oa,rating:Ia,country:dn,bank:dn,document:Ka},un="edit",cn=(e,n)=>{const o=rn[e.type];return o?i.jsx(ri,{element:e,state:un,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:un,sectionId:n})]})}):null},ci=({col:e,children:n,customClass:o})=>i.jsx("div",{className:V("w-full bg-white",o),style:{gridColumn:e},children:n}),Fa=({element:e,sectionId:n,children:o,customClass:a,state:s})=>{const{formData:t,addElement:l,setIsDragging:r}=v.useContext(ae),d=v.useMemo(()=>Array.from({length:e.columns}),[e.columns]),b=v.useCallback(c=>{c.preventDefault(),c.stopPropagation(),c.dataTransfer.dropEffect="move"},[]),u=v.useCallback((c,p)=>{var y,g;c.preventDefault(),r(!1);try{const h=c.dataTransfer.getData("properties");if(!h)return;const x=JSON.parse(h);if((x==null?void 0:x.type)==="grid")return;const k=p+1;if((g=(y=t.find(N=>N.id===n))==null?void 0:y.questionData)==null?void 0:g.some(N=>{var w;return N.gridId===e.id&&((w=N.gridPosition)==null?void 0:w.col)===k}))return;const S={...x,id:ve.v4(),sectionId:n,gridId:e.id,gridPosition:{col:k}};l(S,n)}catch(h){console.error("Drop failed in grid:",h),r(!1)}},[l,e.id,t,n,r]),f=(c,p,y)=>{const g=Array.isArray(o)&&o.find(h=>{var x;return((x=h==null?void 0:h.props)==null?void 0:x.col)===c+1});return i.jsx("div",{children:i.jsx("div",{id:c.toString(),onDrop:h=>u(h,c),onDragOver:b,className:V("border rounded-lg min-h-[110px] bg-white ","flex items-center justify-center text-gray-400 transition-colors",`${y==="edit"?"p-3":""}`,p),children:g||i.jsx("span",{children:y==="edit"&&i.jsx(H,{icon:"ph:plus-bold"})})})},c)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:d.map((c,p)=>f(p,a,s))})})},mi=v.memo(Fa),za="edit";function Ha({elementData:e,sectionId:n}){const{formData:o,updateElementPosition:a,isDragging:s,setIsDragging:t,addElementInPosition:l}=v.useContext(ae),[r,d]=v.useState(null),[b,u]=v.useState(null),f=v.useMemo(()=>{var A;return((A=o.find(S=>S.id===n))==null?void 0:A.questionData)||[]},[o,n]),c=v.useCallback((A,S)=>{A.dataTransfer.setData("properties",S),d(S)},[]),p=v.useCallback((A,S)=>{A.preventDefault(),A.stopPropagation(),u(S)},[]),y=v.useCallback(A=>{A.preventDefault(),A.stopPropagation();const S=A.dataTransfer.getData("properties"),N=A.currentTarget.id;if(!N||S===N)return;const w=f.findIndex(B=>B.id===S),T=f.findIndex(B=>B.id===N);if(w===-1||T===-1)return;const G=[...f],[Z]=G.splice(w,1);G.splice(T,0,Z),a(G,n),d(null)},[f,n,a]),g=v.useCallback((A,S)=>{A.preventDefault(),t(!1);try{const N=JSON.parse(A.dataTransfer.getData("properties"));if(console.log({data:N}),(N==null?void 0:N.type)==="section")return;const w={...N,id:ve.v4(),sectionId:n};l(w,n,S)}catch(N){console.error("Drop error:",N)}},[l,n,t]),h=v.useCallback(A=>i.jsx("div",{className:"transition rounded hover:bg-blue-300",onDragOver:S=>S.preventDefault(),onDrop:S=>g(S,A),onDragEnd:()=>t(!1),children:i.jsx("div",{className:"bg-blue-50 rounded p-6 h-[60px] border-2 border-blue-300 border-dashed flex items-center justify-center text-gray-400 opacity-70",children:i.jsx(H,{icon:"octicon:plus-16"})})},`drop-${A}`),[g,t]),x=v.useCallback(A=>i.jsx("div",{id:A.id,className:V("cursor-move border p-4 w-full rounded-lg transition-colors bg-white",{"bg-gray-100":r===A.id,"border-dashed border-blue-300":r&&r!==A.id}),draggable:!0,onDragStart:S=>c(S,A.id),onDragOver:S=>p(S,A.id),onDrop:y,onDragEnd:()=>d(null),children:cn(A,n)},A.id),[r,y,p,n,c]),k=v.useMemo(()=>(e==null?void 0:e.reduce((A,S)=>(S.gridId&&(A[S.gridId]=A[S.gridId]||[],A[S.gridId].push(S)),A),{}))||{},[e]);return e!=null&&e.length?i.jsx("div",{className:"relative grid w-full h-full grid-cols-1 gap-4",children:e.map((A,S)=>{if(A.type==="grid"){const N=k[A.id]||[];return i.jsx("div",{draggable:!0,onDragStart:w=>c(w,A.id),onDragOver:w=>p(w,A.id),onDrop:y,onDragEnd:()=>d(null),className:"w-full p-4 transition-colors bg-white border rounded-lg cursor-move",children:i.jsx(ri,{element:A,state:"edit",children:i.jsx(mi,{element:A,sectionId:n,state:za,children:N.map(w=>{var T;return i.jsx(ci,{col:(T=w.gridPosition)==null?void 0:T.col,children:cn(w,n)},w.id)})})})},A.id)}return A.gridId?null:i.jsxs("div",{className:V("group relative grid gap-y-[6px]",A.elementClass),children:[s&&b===A.id&&h(S),i.jsx("div",{className:"group",children:x(A)}),s&&b===A.id&&h(S+1)]},A.id)})}):i.jsx("div",{onDragOver:A=>A.preventDefault(),onDrop:A=>g(A,0),onDragEnd:()=>t(!1),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 Va=v.memo(Ha),Wa=j.object({title:j.string(),description:j.string()}).required(),bi=te("config"),Ua=({isOpen:e,onClose:n,section:o})=>{const{updateSection:a}=v.useContext(ae),{register:s,handleSubmit:t,formState:{errors:l,isSubmitting:r,isValid:d},reset:b}=me.useForm({resolver:li(Wa),defaultValues:o});if(v.useEffect(()=>{e||b()},[e,b]),!e)return null;const u=f=>{a(f,o.id),n()};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(H,{icon:"tabler:x"})})]}),i.jsxs("form",{onSubmit:t(u),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(D,{label:"Title",name:"title",register:s,errors:l}),i.jsx(D,{label:"Description",name:"description",register:s,errors:l})]}),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:!d||r,style:{background:(bi==null?void 0:bi.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!d||r?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!d||r?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:r?"Saving...":"Save"})]})]})]})})},Ja=()=>{const[e,n]=v.useState(!1),o=v.useRef(null),a=v.useRef(null),{removeSection:s,addSection:t,formData:l,setIsDragging:r,setSelectedSection:d,selectedSection:b,activeSections:u,setActiveSections:f}=v.useContext(ae);v.useEffect(()=>{var h;d(((h=l[0])==null?void 0:h.id)||null)},[]);const c=v.useCallback(h=>{h.preventDefault(),h.dataTransfer.dropEffect="move",a.current&&(a.current.scrollTop=a.current.scrollHeight)},[]);function p(h){u.includes(h)?f(x=>x.filter(k=>k!==h)):f(x=>[...x,h])}function y(h){o.current=h,n(!0)}const g=te("config");return i.jsxs("div",{ref:a,className:"relative flex flex-col h-full px-6 pb-5 mx-auto gap-x-4",children:[e&&i.jsx(Ua,{isOpen:e,onClose:()=>n(!1),section:o.current}),i.jsxs("div",{className:"relative flex flex-col flex-1 w-full py-4 gap-y-6",children:[l.map((h,x)=>i.jsx("div",{className:"bg-white group cursor-pointer rounded ",children:i.jsxs("div",{className:`border border-gray-100 rounded px-4 shadow-[rgba(149,157,165,0.2)_0px_2px_4px] transition-colors duration-200
|
|
49
49
|
${b===h.id?"border-dashed border-blue-400 bg-[#f7f8fa]":""} ${u.includes(x)?"min-h-[300px] pb-6 ":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{onClick:()=>d(h.id),className:"flex-1 h-full py-4 cursor-pointer",children:i.jsx("h2",{className:"font-medium",children:h.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:()=>y(h),children:i.jsx(H,{icon:"fluent:edit-28-regular"})}),l.length>1&&i.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>s(h.id),children:i.jsx(H,{icon:"lets-icons:trash-duotone-line"})}),i.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>p(x),children:i.jsx(H,{icon:u.includes(x)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(h==null?void 0:h.description)&&u.includes(x)&&i.jsx("p",{className:"mt-2 text-sm text-gray-600 text-gray-60",children:h==null?void 0:h.description}),u.includes(x)&&i.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:h.id,onDragOver:c,onDragEnd:()=>r(!1),onClick:()=>d(h.id),children:[i.jsx("hr",{className:"group-last:hidden"}),i.jsx("div",{className:"h-full mt-4 gap-y-6",children:i.jsx(Va,{elementData:h.questionData,sectionId:h.id})})]})]})},h.id)),i.jsx("div",{className:"flex justify-center",children:i.jsxs("button",{type:"button",onClick:()=>t(),style:{color:(g==null?void 0:g.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]})})]})]})};function qa({questionData:e,uploadUrl:n}){const{setFormData:o,addSection:a,setUploadUrl:s}=v.useContext(ae);v.useEffect(()=>{e&&e.length>0&&o(e)},[e,o]),v.useEffect(()=>{s(n)},[n,s]);const t=v.useCallback(l=>{l.preventDefault();try{const r=JSON.parse(l.dataTransfer.getData("properties"));if((r==null?void 0:r.type)==="section"){a();return}}catch(r){console.error("Drop error:",r)}},[]);return i.jsx("div",{onDragOver:l=>l.preventDefault(),onDrop:l=>t(l),className:"bg-white p-4 border border-[#E4E7EC] h-full overflow-y-auto no-scrollbar max-h-[calc(100vh-60px)]",children:i.jsx(Ja,{})})}const Ya=[{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"}],Za=()=>{const[e,n]=v.useState(""),{setIsDragging:o,addElement:a,selectedSection:s}=v.useContext(ae),t=v.useCallback((p,y)=>{if(!s){de.toast.error("Please select a section to add an element.");return}p.dataTransfer.setData("properties",JSON.stringify(y)),p.dataTransfer.effectAllowed="move",o(!0)},[o,s]);function l(p){if(!s){de.toast.error("Please select a section to add an element.");return}const y={...p,id:ve.v4(),sectionId:s};a(y,s)}const r=te("config")||{},d=r.elementColor,b=r.elementBgColor,u=r.elementBorderColor,f=ea.filter(p=>p.label.toLowerCase().includes(e.toLowerCase())),c=Ya.map(p=>({title:p.title,elements:f.filter(y=>{var g;return(g=ia[p.key])==null?void 0:g.includes(y.type)})})).filter(p=>p.elements.length>0);return i.jsxs("div",{className:"pt-4 pb-6",children:[i.jsx(de.ToastContainer,{}),i.jsx("div",{className:"px-5 mb-4",children:i.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:p=>n(p.target.value)})}),i.jsx("hr",{}),i.jsx("div",{children:i.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 max-h-[80vh] overflow-y-auto no-scrollbar",children:c.map((p,y)=>i.jsxs("li",{children:[i.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:p.title}),i.jsx("ul",{className:"grid gap-y-[6px] mb-3",children:p.elements.map(g=>i.jsx("li",{onDragStart:h=>t(h,g),onDragEnd:()=>o(!1),onClick:()=>l(g),style:{borderColor:u,backgroundColor:b},className:`cursor-move text-[#475467] flex justify-between items-center h-11\r
|
|
50
50
|
border-[1.5px] border-[#98A2B3] rounded-lg py-3 px-[14px] shadow-custom\r
|
|
51
51
|
hover:shadow-lg transition-all duration-200\r
|