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