@arudovwen/form-builder-react 1.4.36 → 1.4.37

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.
@@ -2742,7 +2742,7 @@ const F = ({
2742
2742
  sn,
2743
2743
  {
2744
2744
  onValueChange: (S) => {
2745
- u(e, S), o && o(e), c && c(e);
2745
+ console.log({ value: S, prefix: v }), u(e, { value: S, prefix: v }), o && o(e), c && c(e);
2746
2746
  },
2747
2747
  placeholder: d,
2748
2748
  className: `field-control ${s != null && s[e] ? "border-red-300" : "border-[#D0D5DD]"}`,
@@ -5055,7 +5055,7 @@ function hs({
5055
5055
  register: o,
5056
5056
  trigger: s,
5057
5057
  setValue: a,
5058
- value: t,
5058
+ value: t == null ? void 0 : t.value,
5059
5059
  prefix: i.prefix,
5060
5060
  disabled: d,
5061
5061
  watch: l
@@ -7520,15 +7520,11 @@ const xl = ({
7520
7520
  selectField: B.string().nullable(),
7521
7521
  checkbox: B.mixed().nullable(),
7522
7522
  radio: B.mixed().nullable(),
7523
- email: B.string().nullable().matches(
7524
- /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/,
7525
- Ci.email
7526
- ),
7523
+ email: B.string().nullable().test("email-format", Ci.email, (o) => !o || o.trim() === "" ? !0 : /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/.test(o)),
7527
7524
  date: B.date().typeError("Invalid date").nullable(),
7528
- url: B.string().nullable().matches(
7529
- /^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/,
7530
- Ci.url
7531
- )
7525
+ url: B.string().nullable().test("url-format", Ci.url, (o) => !o || o.trim() === "" ? !0 : /^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/.test(
7526
+ o
7527
+ ))
7532
7528
  })[i] || B.mixed().nullable(), Qs = (i, e, o) => e ? i.type === "boolean" ? i.oneOf([!0], o || Ci.required) : i.required(o || Ci.required) : i, Xs = (i, {
7533
7529
  minLength: e,
7534
7530
  maxLength: o,
@@ -32,7 +32,7 @@ React keys must be passed directly to JSX without using spread:
32
32
  file:rounded-[6px] file:py-[6px] file:border-0\r
33
33
  file:text-sm file:font-semibold\r
34
34
  file:bg-blue-50 file:text-blue-700\r
35
- hover:file:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed`}),N&&i.jsx("button",{type:"button",className:"p-2 text-lg text-red-500 hover:text-red-600 transition-colors disabled:opacity-50",onClick:()=>y(),disabled:u,"aria-label":"Remove all files",children:i.jsx(F,{icon:"lets-icons:trash-duotone"})})]}),N&&i.jsxs("div",{className:"relative grid gap-y-1 flex-1 w-full",children:[u&&i.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/60 rounded",children:i.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-600 font-medium",children:[i.jsx("span",{className:"animate-spin h-4 w-4 border-2 border-blue-500 border-t-transparent rounded-full"}),"Uploading..."]})}),typeof d=="object"&&(d==null?void 0:d.map((S,A)=>i.jsx(rn,{fileUrl:S.base64,fileName:S.name,removeFile:()=>y(A)},`${S.name}-${A}`)))]})]})}function Jo({element:e,validationData:n}){var u;const[o,s]=m.useState((u=e==null?void 0:e.value)!=null?u:null),{register:a=()=>({}),setValue:t,isReadOnly:l,watch:r}=n||{};m.useEffect(()=>{a(e.id)},[e.id,a]),m.useEffect(()=>{if(r){const p=r(g=>{s(g[e.id])});return()=>{var g;return(g=p.unsubscribe)==null?void 0:g.call(p)}}},[r,e.id]);const d=m.useCallback(p=>{t==null||t(e.id,p),s(p)},[e.id,t]),c=()=>{t==null||t(e.id,null),s(null)};return i.jsxs("div",{children:[!l&&i.jsx(qo,{onFileLoaded:d,disabled:l,multiple:e==null?void 0:e.isMultiple,handleDeleteFile:c,list:o,accept:e==null?void 0:e.acceptedFiles}),o&&l&&i.jsx("div",{className:"relative grid gap-y-1 flex-1 w-full",children:typeof o=="object"&&(o==null?void 0:o.map((p,g)=>i.jsx("div",{children:i.jsx(rn,{fileUrl:p.base64,fileName:p.name})},g)))})]})}function Yo({element:e,validationData:n}){const{register:o=()=>({})}=n||{};return i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:U("field-control",e==null?void 0:e.customClass),...o(e.id),disabled:n==null?void 0:n.isReadOnly})}const H=({label:e,name:n,register:o,errors:s,className:a,type:t="text",placeholder:l="",isFloating:r,setValue:d,value:c,trigger:u,prefix:p,disabled:g,watch:f,min:w,max:x})=>{var h,y,N,S;const b=o?{...o(n)}:{};if(t==="amount")return i.jsxs("div",{className:"space-y-1.5 relative",children:[i.jsx("label",{className:`block text-sm font-medium text-[#344054] font-onest ${r?"z-[40] absolute block text-[#667085] bg-white py-[2px] px-1 -top-[12px] left-3 ":"relative"}`,children:e}),i.jsx(Ge,{onValueChange:A=>{d(n,A),o&&o(n),u&&u(n)},placeholder:l,className:`field-control ${s!=null&&s[n]?"border-red-300":"border-[#D0D5DD]"}`,decimalsLimit:2,value:c,prefix:p,disabled:g}),(s==null?void 0:s[n])&&i.jsx("p",{className:"mt-1 text-sm text-red-600",children:(h=s[n])==null?void 0:h.message})]});if(["checkbox","radio"].includes(t)){const A=(f==null?void 0:f(n))||null;let k=!1;return A&&(A!=null&&A.length&&t==="checkbox"?k=A==null?void 0:A.includes(c):k=A==c),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer select-none",children:[i.jsx("input",{...b,type:t,value:c||"",disabled:g,className:"peer sr-only"}),i.jsx("div",{className:`
35
+ hover:file:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed`}),N&&i.jsx("button",{type:"button",className:"p-2 text-lg text-red-500 hover:text-red-600 transition-colors disabled:opacity-50",onClick:()=>y(),disabled:u,"aria-label":"Remove all files",children:i.jsx(F,{icon:"lets-icons:trash-duotone"})})]}),N&&i.jsxs("div",{className:"relative grid gap-y-1 flex-1 w-full",children:[u&&i.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/60 rounded",children:i.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-600 font-medium",children:[i.jsx("span",{className:"animate-spin h-4 w-4 border-2 border-blue-500 border-t-transparent rounded-full"}),"Uploading..."]})}),typeof d=="object"&&(d==null?void 0:d.map((S,A)=>i.jsx(rn,{fileUrl:S.base64,fileName:S.name,removeFile:()=>y(A)},`${S.name}-${A}`)))]})]})}function Jo({element:e,validationData:n}){var u;const[o,s]=m.useState((u=e==null?void 0:e.value)!=null?u:null),{register:a=()=>({}),setValue:t,isReadOnly:l,watch:r}=n||{};m.useEffect(()=>{a(e.id)},[e.id,a]),m.useEffect(()=>{if(r){const p=r(g=>{s(g[e.id])});return()=>{var g;return(g=p.unsubscribe)==null?void 0:g.call(p)}}},[r,e.id]);const d=m.useCallback(p=>{t==null||t(e.id,p),s(p)},[e.id,t]),c=()=>{t==null||t(e.id,null),s(null)};return i.jsxs("div",{children:[!l&&i.jsx(qo,{onFileLoaded:d,disabled:l,multiple:e==null?void 0:e.isMultiple,handleDeleteFile:c,list:o,accept:e==null?void 0:e.acceptedFiles}),o&&l&&i.jsx("div",{className:"relative grid gap-y-1 flex-1 w-full",children:typeof o=="object"&&(o==null?void 0:o.map((p,g)=>i.jsx("div",{children:i.jsx(rn,{fileUrl:p.base64,fileName:p.name})},g)))})]})}function Yo({element:e,validationData:n}){const{register:o=()=>({})}=n||{};return i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:U("field-control",e==null?void 0:e.customClass),...o(e.id),disabled:n==null?void 0:n.isReadOnly})}const H=({label:e,name:n,register:o,errors:s,className:a,type:t="text",placeholder:l="",isFloating:r,setValue:d,value:c,trigger:u,prefix:p,disabled:g,watch:f,min:w,max:x})=>{var h,y,N,S;const b=o?{...o(n)}:{};if(t==="amount")return i.jsxs("div",{className:"space-y-1.5 relative",children:[i.jsx("label",{className:`block text-sm font-medium text-[#344054] font-onest ${r?"z-[40] absolute block text-[#667085] bg-white py-[2px] px-1 -top-[12px] left-3 ":"relative"}`,children:e}),i.jsx(Ge,{onValueChange:A=>{console.log({value:A,prefix:p}),d(n,{value:A,prefix:p}),o&&o(n),u&&u(n)},placeholder:l,className:`field-control ${s!=null&&s[n]?"border-red-300":"border-[#D0D5DD]"}`,decimalsLimit:2,value:c,prefix:p,disabled:g}),(s==null?void 0:s[n])&&i.jsx("p",{className:"mt-1 text-sm text-red-600",children:(h=s[n])==null?void 0:h.message})]});if(["checkbox","radio"].includes(t)){const A=(f==null?void 0:f(n))||null;let k=!1;return A&&(A!=null&&A.length&&t==="checkbox"?k=A==null?void 0:A.includes(c):k=A==c),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer select-none",children:[i.jsx("input",{...b,type:t,value:c||"",disabled:g,className:"peer sr-only"}),i.jsx("div",{className:`
36
36
  w-[18px] h-[18px] flex items-center justify-center
37
37
  border rounded-md transition-all duration-200
38
38
  ${s!=null&&s[n]?"border-red-300":"border-[#D0D5DD]"}
@@ -53,8 +53,8 @@ React keys must be passed directly to JSX without using spread:
53
53
  "data": [
54
54
  { "name": "Document Name", "id": "documentMainId", ...restObject },
55
55
  ]
56
- }`})})]})})}),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 wa(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const vi=["text","number","boolean"],mn=["equals","not_equals","contains","not_contains"],ka=["greater","less"];function Aa({register:e,setValue:n,trigger:o,watch:s,id:a}){const{formData:t}=m.useContext(me),l=s("visibilityDependentFields")||[],r=m.useMemo(()=>{var c;return(c=wa(t).filter(u=>u.id!==a))==null?void 0:c.map(u=>{const p=l.find(g=>g.id===u.id);return{id:u.id,value:u.id,label:u.inputLabel,sectionId:u.sectionId,fieldType:(p==null?void 0:p.fieldType)||"text",operator:(p==null?void 0:p.operator)||"equals",fieldValue:(p==null?void 0:p.fieldValue)!==void 0?p.fieldValue:""}})},[t,l,a]),d=(c,u,p)=>{const g=l==null?void 0:l.map((f,w)=>w===c?{...f,[u]:p}:f);n("visibilityDependentFields",g)};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 p,g;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:c.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.fieldType,onChange:f=>d(u,"fieldType",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldType}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:vi==null?void 0:vi.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f},f))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.operator,onChange:f=>d(u,"operator",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.operator.replace("_"," ")}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(p=c.fieldType==="number"?[...mn,...ka]:mn)==null?void 0:p.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f.replace("_"," ")},f))})})]})})}),c.fieldType!=="boolean"?i.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:f=>d(u,"fieldValue",f.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(z.Listbox,{value:(g=c.fieldValue)!=null?g:"",onChange:f=>d(u,"fieldValue",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(z.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(z.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},c.id)})})]})}const Sa=T.object().shape({inputLabel:T.string().nullable(),placeholder:T.string().nullable(),description:T.string().nullable(),isReadOnly:T.boolean(),isDisabled:T.boolean(),isRequired:T.boolean(),requiredMessage:T.string().nullable(),minLengthMessage:T.string().nullable(),maxLengthMessage:T.string().nullable(),maxLength:T.number().typeError("Expecting a number").nullable(),minLength:T.number().typeError("Expecting a number").nullable(),inputType:T.string().nullable(),maxAmountMessage:T.string().nullable(),maxAmount:T.string().nullable(),options:T.array().of(T.object().shape({label:T.string().nullable(),value:T.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:T.array().of(T.object().shape({label:T.string().nullable(),value:T.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:T.string().nullable(),url:T.string().nullable(),method:T.string().nullable(),denominators:T.mixed().nullable(),responseType:T.string().nullable(),minAmount:T.string().nullable(),heading:T.string().nullable(),minAmountMessage:T.string().nullable(),columns:T.number().nullable().max(4).min(2),value:T.mixed().nullable(),customClass:T.string().nullable(),elementClass:T.string().nullable(),apiUrl:T.string().nullable(),selectType:T.string().default("list"),dateType:T.string().default("basic"),validationUrl:T.string(),signatureLink:T.string(),minDate:T.string().nullable(),maxDate:T.string().nullable(),canHaveDateRange:T.boolean(),allowYearPicker:T.boolean(),isHidden:T.boolean(),visibilityDependentFields:T.array().nullable(),isMultiple:T.boolean(),acceptedFiles:T.array(),showState:T.boolean()}),Na=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],ja=({isOpen:e,onClose:n,element:o})=>{const s=Na.filter(G=>!qe.includes(o.inputType)||G.key!=="validation"),{updateElement:a}=m.useContext(me),[t,l]=m.useState("basic"),[r,d]=m.useState(!1),[c,u]=m.useState("manual"),p=ve("config"),{register:g,handleSubmit:f,control:w,setValue:x,watch:b,trigger:h,formState:{errors:y,isSubmitting:N,isValid:S},reset:A}=ye.useForm({resolver:mi(Sa),defaultValues:{...o,options:o.options||[]}}),k=b(),{fields:_,append:O,remove:$}=ye.useFieldArray({control:w,name:"options"}),{fields:V,append:J,remove:C}=ye.useFieldArray({control:w,name:"options1"}),{fields:E,append:L,remove:B}=ye.useFieldArray({control:w,name:"dataColumns"});m.useEffect(()=>{e||A()},[e,A]);const K=G=>{a(G,o.sectionId),n()},P={headers:{Authorization:`Bearer ${ve("token")}`}},D=m.useCallback(async()=>{var G,I,oe;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){he.toast.info("Please provide a valid API URL");return}try{d(!0);const{status:te,data:ne}=await _e.get(k.apiUrl,P);if(te!==200||!ne){he.toast.error("Unexpected response from server.");return}const ae=ne.data||ne.record||ne.result;if(!Array.isArray(ae)){he.toast.error("Expected an array in response (data, record, or result).");return}((G=o.type)==null?void 0:G.toLowerCase())==="datagrid"?x("dataColumns",ae):x("options",ae)}catch(te){const ne=((oe=(I=te==null?void 0:te.response)==null?void 0:I.data)==null?void 0:oe.message)||(te==null?void 0:te.message)||"Unable to load options";he.toast.error(ne)}finally{d(!1)}},[o.type,x,k.apiUrl]),W=["manual","api","sheet"];function X(){c==="api"&&D()}const ce=()=>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:W==null?void 0:W.map(G=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:I=>u(I.target.value),value:G})," ",i.jsxs("span",{children:[G," options"]})]},G))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:b,label:"Load Options from Api",name:"apiUrl",errors:y,register:g,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:X,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(cn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:x,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),_==null?void 0:_.map((G,I)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Label":"",name:`options.${I}.label`,register:g,errors:y,element:o,placeholder:"Label"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Value":"",name:`options.${I}.value`,register:g,errors:y,element:o,placeholder:"Value"})}),i.jsx("button",{disabled:_.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>$(I),children:i.jsx(F,{icon:"iconamoon:sign-times-fill"})})]},G.id))," ",i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>O({label:"",value:"",id:ge.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 "}),V==null?void 0:V.map((G,I)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Label",name:`options1.${I}.label`,register:g,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Value",name:`options1.${I}.value`,register:g,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Key",name:`options1.${I}.key`,register:g,errors:y,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:V.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>C(I),children:i.jsx(F,{icon:"iconamoon:sign-times-fill"})})]},G.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:()=>J({label:"",value:"",key:"",id:ge.v4()}),children:[i.jsx(F,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),ue=()=>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:W==null?void 0:W.map(G=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:I=>u(I.target.value),value:G,checked:G===c})," ",i.jsxs("span",{children:[G," options"]})]},G))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:b,label:"Load Columns from Api",name:"apiUrl",errors:y,register:g,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:X,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(cn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:x,name:"dataColumns"})}),E==null?void 0:E.map((G,I)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"min-w-[140px]",children:i.jsx(Me,{label:I===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"}],register:g,name:`dataColumns.${I}.type`,setValue:x,trigger:h,value:k.dataColumns[I].type})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Field key":"",name:`dataColumns.${I}.field`,register:g,errors:y,element:o,placeholder:"fieldKey"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Display header":"",name:`dataColumns.${I}.headerName`,register:g,errors:y,element:o,placeholder:"header"})}),i.jsx("button",{disabled:E.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>B(I),children:i.jsx(F,{icon:"iconamoon:sign-times-fill"})})]},G.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({headerName:"",field:"",editable:!0,id:ge.v4(),type:"text",validate:!1}),children:[i.jsx(F,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),ie=m.useCallback(async()=>{const G=ve("token"),{status:I,data:oe}=await _e.get(k.url,{headers:{Authorization:`Bearer ${G}`}});I===200&&x("options",(oe==null?void 0:oe.data)||oe)},[x,k.url]);return m.useEffect(()=>{o.type==="document"&&k.url&&ie()},[k.url,o.type,ie]),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:G=>G.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:G=>G.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:f(K),className:"w-full flex-1 flex flex-col",children:[i.jsxs("div",{className:"flex-1",children:[" ",i.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[t==="basic"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[bi.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(H,{watch:b,label:"Value",name:"value",register:g,errors:y,element:o})}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:b,label:"Label",name:"inputLabel",register:g,errors:y,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(H,{watch:b,label:"Child Label",name:"childLabel",register:g,errors:y,element:o})]}),ra.includes(o.inputType)&&i.jsx(H,{watch:b,label:"Placeholder",name:"placeholder",register:g,errors:y,element:o}),la.includes(o.inputType)&&i.jsx(H,{watch:b,label:"Prefix",name:"prefix",register:g,errors:y,element:o}),ma.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(ga,{}),i.jsx(H,{watch:b,label:"Api Url",name:"url",register:g,errors:y,element:o}),i.jsx(Me,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:g,name:"method",setValue:x,trigger:h,value:b("method")}),i.jsx(Me,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:g,name:"responseType",setValue:x,trigger:h,value:b("responseType")})]}),ba.includes(o.inputType)&&i.jsx(pa,{onChange:G=>{x("denominators",G)},value:b("denominators")}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsx(H,{watch:b,label:"Short Description",name:"description",register:g,errors:y,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Me,{label:"Date Format",options:ta,register:g,name:"dateFormat",setValue:x,trigger:h,value:b("dateFormat")}),i.jsx(H,{watch:b,label:"Allow Range",name:"canHaveDateRange",register:g,errors:y,element:o,type:"checkbox"}),(k==null?void 0:k.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx(Qe,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select min date"}),i.jsx(Qe,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),i.jsx(H,{watch:b,label:"Allow Year Picker",name:"allowYearPicker",register:g,errors:y,element:o,type:"checkbox"})]}),o.type.toLowerCase()==="country"&&i.jsx(H,{watch:b,label:"Allow States",name:"showState",register:g,errors:y,element:o,type:"checkbox"}),o.type.toLowerCase()==="selectfield"&&i.jsx(Me,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:g,name:"selectType",setValue:x,trigger:h,value:b("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(H,{watch:b,label:"Number of columns (max: 4)",name:"columns",register:g,errors:y,element:o,max:4,min:1}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:b,label:"Document Options Url",name:"url",register:g,errors:y,element:o})," ",i.jsx(xa,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:b,label:"Document Validation Url",name:"validationUrl",register:g,errors:y,element:o}),i.jsx(ya,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(H,{watch:b,label:"Signature Page Url",name:"signatureLink",register:g,errors:y,element:o})})]}),o.type.toLowerCase()==="datagrid"&&ue(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:b,label:"Allow Multiple Uploads",name:"isMultiple",register:g,errors:y,element:o,type:"checkbox"}),i.jsx(ui,{element:{options:va,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:g,setValue:x,trigger:h,watch:b},placeholder:"Choose file types"})]}),ca.includes(o.inputType)&&ce(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(H,{watch:b,label:"Toggle Visibility",name:"isHidden",register:g,errors:y,element:o,type:"checkbox"})})," ",k.isHidden&&i.jsx(Aa,{register:g,setValue:x,trigger:h,watch:b,id:o==null?void 0:o.id})]})]}),!qe.includes(o.type.toLowerCase())&&t==="validation"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:b,label:"Required",name:"isRequired",register:g,errors:y,element:o,type:"checkbox"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"requiredMessage",register:g,errors:y,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(H,{watch:b,label:"Min Length",name:"minLength",register:g,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"minLengthMessage",register:g,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:b,label:"Max Length",name:"maxLength",register:g,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"maxLengthMessage",register:g,errors:y,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(H,{watch:b,label:"Min Amount",name:"minAmount",register:g,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"minAmountMessage",register:g,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:b,label:"Max Amount",name:"maxAmount",register:g,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"maxAmountMessage",register:g,errors:y,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest editor_option__cancel",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!S||N,style:{background:(p==null?void 0:p.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!S||N?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!S||N?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:N?"Saving...":"Save"})]})]})]})})},pi=m.memo(({state:e,element:n,children:o})=>{const[s,a]=m.useState(!1),{removeElement:t,duplicateElement:l}=m.useContext(me),r=m.useMemo(()=>{var c;return(c=n==null?void 0:n.acceptedFiles)==null?void 0:c.map(u=>u.label).join(", ")},[n]),d=m.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return i.jsxs("div",{className:"w-full",children:[s&&i.jsx(ja,{isOpen:s,onClose:()=>a(!1),element:n}),i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("span",{children:[" ",n.inputLabel&&i.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",r&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",r==null?void 0:r.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[!n.gridPosition&&i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1",onClick:()=>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 text-gray-600 py-1",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 text-gray-600 py-1",onClick:d,title:"Remove",children:i.jsx(F,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});pi.displayName="ElementContainer";function _a({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(H,{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]=m.useState(!1),s=()=>{o(!0)},a=()=>{o(!1)};return i.jsxs("div",{children:[i.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:s,src:e||"/place.png","data-toggle":"tooltip","data-placement":"top",title:"Click to view"}),n&&i.jsx("div",{className:"modal",style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",justifyContent:"center",alignItems:"center"},onClick:a,children:i.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:t=>t.stopPropagation(),children:[i.jsx("span",{className:"close",onClick:a,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),i.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function Ea({element:e,validationData:n}){var k;const{register:o=()=>({}),setValue:s,watch:a}=n||{},[t,l]=m.useState(),[r,d]=m.useState(!1),[c,u]=m.useState(!1),[p,g]=m.useState(""),f=a&&a(e==null?void 0:e.id);m.useEffect(()=>{l(f)},[f]);const[w,x]=m.useState("");m.useEffect(()=>{o(e.id)},[e.id,o]);const{url:b,method:h,responseType:y}=e||{},S={headers:{Authorization:`Bearer ${ve("token")}`}},A=m.useCallback(async _=>{var O,$,V,J,C,E,L,B,K,Y,P;if(!(!b||!h)){d(!0);try{let D;if(h.toLowerCase()==="get"){const W=`${b}?value=${_}`;D=await _e.get(W,S)}else if(h.toLowerCase()==="post")D=await _e.post(b,{value:_},S);else throw new Error("Unsupported HTTP method");D.status===200&&(((($=(O=D==null?void 0:D.data)==null?void 0:O.data)==null?void 0:$.status)||((V=D==null?void 0:D.data)==null?void 0:V.status))===!0?(u(!0),y==="string"?g(((C=(J=D==null?void 0:D.data)==null?void 0:J.data)==null?void 0:C.description)||((E=D==null?void 0:D.data)==null?void 0:E.description)||"Validation successful"):x(((B=(L=D==null?void 0:D.data)==null?void 0:L.data)==null?void 0:B.description)||((K=D==null?void 0:D.data)==null?void 0:K.description)||{})):(console.error("Invalid input:",_),g("Unable to validate input"),u(!1)))}catch(D){console.error("Error validating input:",D),g(((P=(Y=D==null?void 0:D.response)==null?void 0:Y.data)==null?void 0:P.message)||"Unable to validate input"),u(!1)}finally{d(!1)}}},[h,y,b]);return m.useEffect(()=>{if(t){const _=setTimeout(()=>{A(t)},700);return()=>clearTimeout(_)}},[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:U("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:_=>{l(_.target.value),s(e==null?void 0:e.id,_.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"})})]})]}),p&&y==="string"&&i.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:p}),y==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(k=Object.entries(w))==null?void 0:k.map(([_,O])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[_,":"]}),Ca(O)?i.jsx(Ma,{imageUrl:O}):i.jsx("span",{children:String(O)})]},_))})]})}function Ta({onGetTotal:e,readOnly:n,defaultValue:o,denominators:s}){const[a,t]=m.useState([...o]);function l(c,u){t(p=>{const g=[...p];return g[u]={...g[u],value:c},g})}function r(c,u){return parseFloat(c)*parseFloat(u)||0}const d=m.useMemo(()=>a.reduce((c,u)=>{const p=r(u.key,u.value);return c+p},0),[a]);return m.useEffect(()=>{e&&e(a)},[a]),m.useEffect(()=>{if(s!=null&&s.length){const c=s==null?void 0:s.map((u,p)=>({key:u.value,value:Array.isArray(o)&&o[p]?o[p].value:""}));t(c)}},[o,s]),i.jsx("div",{className:"mt-2",children:i.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{className:"",children:"Denomination"})}),i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{children:"Quantity"})}),i.jsx("div",{className:"px-4 py-2",children:i.jsx("span",{children:"Sub total"})})]}),a==null?void 0:a.map((c,u)=>{var p,g;return i.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[i.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:i.jsx("span",{className:"",children:(p=parseFloat(c.key))==null?void 0:p.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(Ge,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:f=>l(f,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(g=r(c.key,c.value))==null?void 0:g.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 m.useEffect(()=>{o(e.id)},[e.id,o]),i.jsx("div",{children:i.jsx(Ta,{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:U("py-6",e==null?void 0:e.customClass)})}function Pa({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:U("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Da({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 Oa({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 y;const p=e[u.field],g=u.editable&&!o,f=c(u.field),{isValidating:w,result:x}=r(e.id,u.field);let b="border-gray-300";u.validate&&((x==null?void 0:x.isValid)===!1?b="border-red-500 bg-red-50":(x==null?void 0:x.isValid)===!0&&(b="border-green-500 bg-green-50"));const h=`w-full px-2 py-1 border rounded outline-none ${b}`;return i.jsx("td",{title:o?"":"Double click to edit",className:"px-3 py-1 border",onDoubleClick:()=>g&&a({rowId:e.id,field:u.field}),children:g&&f?i.jsxs("div",{className:"relative",children:[u.type==="number"?i.jsx(Ge,{value:p,decimalsLimit:6,allowNegativeValue:!1,className:h,onValueChange:N=>t(N,e.id,u.field),onBlur:()=>{a(null),l(p,e.id,u.field,u)},autoFocus:!0}):u.type==="checkbox"?i.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(N=>{const S=N==="yes",A=`radio-${e.id}-${String(u.field)}-${N}`;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:p===S,onChange:()=>t(S,e.id,u.field)}),i.jsx("span",{className:"text-sm",children:S?"Yes":"No"})]},N)})}):i.jsx("input",{type:"text",value:String(p!=null?p:""),onChange:N=>t(N.target.value,e.id,u.field),onBlur:()=>{a(null),l(p,e.id,u.field,u)},className:h,autoFocus:!0}),w&&i.jsx("div",{className:"absolute right-1 top-1",children:i.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):u.validate&&x?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{children:[String(p!=null?p:"")," ",x.data&&`[${x.data}]`]}),x.isValid?i.jsx("span",{className:"text-xs text-green-600",children:"✓"}):i.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(y=x.error)!=null?y:"",children:"✗"})]}):u.type==="checkbox"?i.jsx("span",{className:"block py-1 text-gray-700",children:p===!0?"Yes":p===!1?"No":""}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:String(p!=null?p:"")})},String(u.id))}),!o&&i.jsx("td",{className:"px-3 py-1 text-center border",children:i.jsx("button",{type:"button",onClick:()=>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=m.memo(Oa);function Ga({value:e=[],onChange:n,isReadOnly:o=!1,columns:s}){const[a,t]=m.useState(e),[l,r]=m.useState(null),d=m.useRef(null),[c,u]=m.useState(0);m.useEffect(()=>{const x=document.getElementById("form");if(!x)return;const b=y=>{const N=y.getBoundingClientRect().width;u(N?N-58:0)};b(x);const h=new ResizeObserver(y=>{for(const N of y)b(N.target)});return h.observe(x),()=>h.disconnect()},[]),m.useEffect(()=>{t(x=>JSON.stringify(x)!==JSON.stringify(e)?e:x)},[e]),m.useEffect(()=>{n==null||n(a)},[a,n]),m.useEffect(()=>{const x=b=>{d.current&&!d.current.contains(b.target)&&r(null)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);const p=m.useCallback((x,b,h)=>{t(y=>y.map(N=>N.id===b?{...N,[h]:x}:N))},[]),g=m.useCallback(()=>{const x=ge.v4(),b=s.reduce((h,y)=>(h[y.field]=y.field==="id"?x:"",h),{});t(h=>[...h,{id:x,...b}])},[s]),f=m.useCallback(x=>{t(b=>b.filter(h=>h.id!==x))},[]),w=m.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:g,type:"button",className:"px-2 py-1 mb-3 text-xs text-white bg-gray-600 rounded hover:bg-gray-700",children:"Add Row"})}),i.jsx("div",{className:"w-full max-w-full overflow-x-auto",style:{maxWidth:`${c}px`},children:i.jsxs("table",{className:"min-w-max w-full text-sm border-collapse rounded table-auto bg-gray-50",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"bg-gray-100",children:[s.map((x,b)=>{var h;return i.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border whitespace-nowrap",children:[(h=x.headerName)!=null?h:String(x.field),x.validate&&i.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(x.id)}-${b}`)}),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:a.length>0?a.map(x=>i.jsx(Ka,{row:x,columns:s,isReadOnly:o,editingCell:l,setEditingCell:r,handleCellChange:p,debouncedValidate:()=>{},getValidationStatus:w,deleteRow:f},x.id)):i.jsx("tr",{children:i.jsx("td",{colSpan:s.length+(o?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})})]})}function Ra({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t}=n||{},l=a&&a(e==null?void 0:e.id)||[];m.useEffect(()=>{o(e.id)},[e.id,o]);const r=m.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 bn=({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:p=!1,subText:g,labelClass:f="",loading:w,disabled:x})=>{const[b,h]=m.useState(u?[]:null),y=U("custom-select__control",e),N=m.useMemo(()=>n,[n]);return m.useEffect(()=>{const S=n==null?void 0:n.find(A=>{var k;return typeof A.value=="string"&&typeof d=="string"?A.value.toLowerCase()===d.toLowerCase():typeof A.value=="object"&&typeof d=="object"?((k=A.value)==null?void 0:k.id)===(d==null?void 0:d.id):A.value===d});h(S||null)},[d,n]),m.useEffect(()=>{b&&t&&a&&(t(l,b==null?void 0:b.value),a(l),c==null||c(l))},[l,b]),i.jsxs("div",{className:"custom-select",children:[r&&!p&&i.jsx("label",{className:"custom-select__label",children:r}),p&&r&&i.jsx("label",{className:U("custom-select__floating-label",f),children:r}),i.jsx(z.Listbox,{value:b,onChange:h,multiple:u,disabled:x,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(z.Listbox.Button,{className:y,disabled:x,children:[w?i.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):i.jsx("span",{className:"custom-select__value",children:(b==null?void 0:b.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(z.Transition,{as:m.Fragment,leave:"custom-select__transition",children:i.jsx(z.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:N==null?void 0:N.map((S,A)=>i.jsx(z.Listbox.Option,{value:S,className:({active:k})=>U("custom-select__option",k&&"custom-select__option--active"),children:({selected:k})=>i.jsx("span",{className:U("custom-select__option-label",k&&"custom-select__option--selected"),children:S.label})},A))})})]})}),g&&!s&&i.jsx("p",{className:"custom-select__subtext",children:g}),s&&i.jsx("span",{className:"custom-select__error",children:s.message})]})},za=({element:e,validationData:n})=>{var x;const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:l}=n||{},r=(x=e==null?void 0:e.id)!=null?x:"cascadeValue",[d,c]=m.useState(""),[u,p]=m.useState(""),g=(b,h)=>{const y=b&&h?`${b}_${h}`:"";a==null||a(r,y),s==null||s(r)},f=(b,h)=>{b==="first"?(c(h),p(""),g(h,"")):(p(h),g(d,h))};m.useEffect(()=>{if(t){const b=t(r);if(b!=null&&b.includes("_")){const[h,y]=b.split("_");c(h),p(y)}}},[t,r]);const w=m.useMemo(()=>{var b;return(b=e.options1)==null?void 0:b.filter(h=>h.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(bn,{setValue:(b,h)=>f("first",h),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(bn,{setValue:(b,h)=>f("second",h),options:w,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 h;const{register:d=()=>({}),trigger:c,setValue:u,watch:p,isReadOnly:g}=r||{},f=(h=p==null?void 0:p(l.id))!=null?h:0,[w,x]=m.useState(null);m.useEffect(()=>{f==null&&(u==null||u(l.id,e))},[]);const b=y=>{if(!o&&!g){const N=y+1;u==null||u(l.id,N),c==null||c(l.id),s==null||s(N)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(y,N)=>{const S=w!==null?N<=w:N<f;return i.jsx(dn,{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||g)&&x(N),onMouseLeave:()=>!(o||g)&&x(null),onClick:()=>b(N)},N)})]})};function vn({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}=m.useMemo(()=>{var w;if(typeof r=="string"&&r.includes(",")){const[x,b]=(w=r.split(","))==null?void 0:w.map(h=>h.trim());return{country:b,state:x}}return{country:r,state:""}},[r]),u=m.useRef(r),p=m.useMemo(()=>{var w,x;return d?((x=(w=We.find(b=>b.name===d))==null?void 0:w.states)==null?void 0:x.map(b=>({label:b.name,value:b.name})))||[]:[]},[d]),g=(w,x)=>{const h=(x==null?void 0:x.value)||"";s&&h!==u.current&&(s(e.id,h),a==null||a(e.id),u.current=h)},f=(w,x)=>{const b=(x==null?void 0:x.value)||"",h=b?`${b}, ${d}`:d;s&&h!==u.current&&(s(e.id,h),a==null||a(e.id),u.current=h)};return m.useEffect(()=>{u.current=r},[r]),i.jsxs("div",{className:"grid gap-y-6",children:[i.jsx("input",{type:"hidden",...o(e.id)}),i.jsx(ci,{options:e.options,onGetValue:g,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),p.length>0&&e.showState&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),i.jsx(ci,{options:p,onGetValue:f,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function Fa({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:s}=n||{},{validationUrl:a,documentObj:t,signatureLink:l}=e,r=m.useMemo(()=>ve("config"),[]),[d,c]=m.useState(!1),[u,p]=m.useState(!1),g=m.useCallback(async()=>{var f,w;if(!(!a||!t))try{p(!0);const b={headers:{Authorization:`Bearer ${ve("token")}`}},{data:h}=await _e.get(`${a}/${t}`,b),y=!!((w=(f=h==null?void 0:h.data)==null?void 0:f.isSigned)!=null?w:h!=null&&h.isSigned);return c(y),y}catch(x){console.error("Failed to check sign status",x)}finally{p(!1)}},[a,t]);return m.useEffect(()=>{let f=null;return!d&&t&&a&&(async()=>{await g()||(f=setInterval(async()=>{await g()&&f&&clearInterval(f)},2e3))})(),()=>{f&&clearInterval(f)}},[g,d,t,a]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:U("field-control",e.customClass),...o(e.id),disabled:s}),i.jsx("a",{href:d?"#":l,children:i.jsxs("button",{type:"button",onClick:g,disabled:u||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:U("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:p,validate:g,onChange:f,onError:w}){const[x,b]=m.useState(""),[h,y]=m.useState(null),[N,S]=m.useState(""),A=m.useMemo(()=>{var C;return(C=gi==null?void 0:gi.slice().sort((E,L)=>E.label.localeCompare(L.label)))==null?void 0:C.map(E=>({...E,phone:`+${E.phone}`}))},[]),k=m.useMemo(()=>x?A.filter(C=>`${C.label} ${C.phone}`.toLowerCase().includes(x.toLowerCase())):A,[x,A]),_=(h==null?void 0:h.min)||10,O=(h==null?void 0:h.max)||10,$=()=>N?`${(h==null?void 0:h.phone)||"+234"}-${N}`:"",V=C=>{if(!C)return{code:"+234",number:""};const E=C.split(/[-\s]/);return{code:E[0],number:E.slice(1).join(" ")}};m.useEffect(()=>{if(l){const C=V(l);y(A.find(E=>E.phone===C.code)||A[0]),S(C.number)}},[l,A]);const J=m.useMemo(()=>{if(r)return r;const C=N.length;return s&&C===0?"Phone number is required":C>0&&!/^\d+$/.test(N)?"Phone number must contain only digits":C>0&&C<_?`Minimum length is ${_}`:C>O?`Maximum length is ${O}`:""},[r,N,_,O,s]);return m.useEffect(()=>{f==null||f($()),w==null||w(J||null)},[N,h,J]),i.jsxs("div",{className:`relative formGroup ${J&&!c?"has-error":""} ${u?"flex":""} ${!J&&N.length>0&&!c?"is-valid":""}`,children:[e&&i.jsxs("label",{htmlFor:t,className:`${o} ${u?"flex-0 mr-6 md:w-[100px] w-[60px] break-words":""} flex items-center gap-x-1 input-label text-sm text-[#1B2B41B8]`,children:[e," ",s&&i.jsx("span",{className:"text-red-500",children:"*"}),a&&i.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),i.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[i.jsx(F,{icon:"lucide:phone-call"}),i.jsx(z.Combobox,{value:h,onChange:y,children:i.jsxs("div",{className:"relative",children:[i.jsx(z.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:C=>(C==null?void 0:C.phone)||"+234",placeholder:"+234",onChange:C=>b(C.target.value)}),i.jsx(z.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(F,{icon:"lucide:chevron-down"})}),i.jsx(z.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:k==null?void 0:k.map((C,E)=>i.jsxs(z.Combobox.Option,{value:C,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[C.phone," - ",C.label]},`${C.code}+ ${E}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:N,disabled:d,readOnly:c,onChange:C=>{const E=C.target.value.replace(/\D/g,"");S(E)},placeholder:n,className:"w-full px-3 outline-none",maxLength:O,minLength:_}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!J&&N.length>0&&!c&&i.jsx("span",{className:"text-green-500",children:i.jsx(F,{icon:"bi:check-lg"})})})]})]}),p&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:p})]})}function Wa({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t,setError:l,clearErrors:r}=n||{};let d;return m.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 Ua({element:e,validationData:n}){var c;const{register:o=()=>({}),watch:s}=n||{};let a="";s&&(a=(c=s()[e.id])!=null?c:"");const t=a.trim(),l=/^https?:\/\//i.test(t),r=t?l?t:`https://${t}`:"",d=!l;return i.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&i.jsxs("div",{className:"relative",children:[d&&i.jsx("span",{className:"text-sm absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none select-none",children:"https://"}),i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:U("field-control",d&&"!pl-16",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly})]}),t?i.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:i.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:t})}):(n==null?void 0:n.isReadOnly)&&i.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}const pn={textField:Xe,longText:ea,selectField:Xo,multiSelect:ui,numberField:Xe,amountField:_a,date:Hn,password:Yo,checkbox:Qo,radio:Zo,email:Xe,file:Jo,dataGrid:Ra,section:$o,validateInput:Ea,tableInput:Ba,spacer:La,divider:Pa,header:Da,basicText:Ia,phoneField:Wa,cascadeSelect:za,rating:Ha,country:vn,bank:vn,document:Fa,url:Ua},gn="edit",qa=(e,n)=>{const o=pn[e.type];return o?i.jsx(pi,{element:e,state:gn,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:gn,sectionId:n})]})}):null},hi=({col:e,children:n,customClass:o})=>i.jsx("div",{className:U("w-full bg-white",o),style:{gridColumn:e},children:n}),Ja=({element:e,sectionId:n,children:o,customClass:s,state:a,draggedElementId:t})=>{const{formData:l,addElement:r,setIsDragging:d,moveElement:c,isDragging:u,removeElement:p}=m.useContext(me),g=m.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[f,w]=m.useState(null);m.useEffect(()=>{const S=()=>{w(null),d(!1)};return document.addEventListener("dragend",S),()=>document.removeEventListener("dragend",S)},[d]);const x=m.useCallback((S,A)=>{S.preventDefault(),S.stopPropagation(),S.dataTransfer.dropEffect="move",w(A)},[]),b=m.useCallback((S,A)=>{S.preventDefault(),S.stopPropagation(),w(A)},[]),h=m.useCallback((S,A)=>{const k=S.relatedTarget;k&&S.currentTarget.contains(k)||w(_=>_===A?null:_)},[]),y=m.useCallback((S,A)=>{var O;S.preventDefault(),S.stopPropagation(),d(!1),w(null);const k=A+1,_=S.dataTransfer.getData("elementId");if(_){c({draggedId:_,sectionId:n,targetGridId:e.id,targetCol:k});return}try{const $=S.dataTransfer.getData("properties");if(!$)return;const V=JSON.parse($);if((V==null?void 0:V.type)==="grid")return;const J=l.find(L=>L.id===n),C=(O=J==null?void 0:J.questionData)==null?void 0:O.find(L=>{var B;return L.gridId===e.id&&((B=L.gridPosition)==null?void 0:B.col)===k});C&&p(C.id,n);const E={...V,id:ge.v4(),sectionId:n,gridId:e.id,gridPosition:{col:k}};r(E,n)}catch($){console.error("Drop failed in grid:",$),d(!1)}},[r,e.id,l,n,d,c]),N=(S,A,k)=>{var B,K,Y;const _=S+1,O=(K=(B=l.find(P=>P.id===n))==null?void 0:B.questionData)==null?void 0:K.find(P=>{var D;return P.gridId===e.id&&((D=P.gridPosition)==null?void 0:D.col)===_}),$=(Y=O==null?void 0:O.id)!=null?Y:null,V=Array.isArray(o)&&o.find(P=>{var D;return((D=P==null?void 0:P.props)==null?void 0:D.col)===_}),J=u&&f===S,C=!!V,E=u&&!!t,L=C&&$&&k==="edit"?{draggable:!0,onDragStart:P=>{P.stopPropagation(),P.dataTransfer.setData("elementId",$),P.dataTransfer.setData("properties",$),P.dataTransfer.effectAllowed="move",d(!0)},onDragEnd:()=>{w(null),d(!1)}}:{};return i.jsx("div",{children:i.jsxs("div",{id:`grid-cell-${e.id}-${S}`,...L,onDrop:P=>y(P,S),onDragEnter:P=>b(P,S),onDragOver:P=>x(P,S),onDragLeave:P=>h(P,S),className:U("relative border rounded-lg min-h-[110px]","flex items-center justify-center","transition-all duration-200 ease-in-out",k==="edit"?"py-3 ":"",C&&k==="edit"&&"cursor-grab active:cursor-grabbing border-none",A,!E&&!J&&"bg-white border-gray-200 text-gray-300",E&&!J&&!C&&"bg-blue-50 border-blue-200 border-dashed text-blue-300",E&&!J&&C&&"bg-white border-orange-200 border-dashed",J&&!C&&"bg-blue-100 border-blue-400 border-dashed shadow-inner scale-[1.01] text-blue-500",J&&C&&"bg-orange-50 border-orange-400 border-dashed shadow-inner scale-[1.01] text-orange-500"),children:[C&&k==="edit"&&i.jsx("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 flex items-center gap-0.5 px-2 py-0.5 rounded-full bg-gray-100 hover:bg-blue-100 text-gray-400 hover:text-blue-500 cursor-grab active:cursor-grabbing transition-colors z-10 opacity-60 hover:opacity-100 pointer-events-none select-none",children:i.jsx(F,{icon:"ph:dots-six-bold"})}),J&&!C&&i.jsxs("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-blue-400 text-xs font-medium pointer-events-none",children:[i.jsx(F,{icon:"ph:plus-bold"}),"Drop here"]}),J&&C&&i.jsx("span",{className:"absolute top-1 right-1 text-xs text-orange-400 font-medium pointer-events-none px-1 py-0.5 bg-orange-50 rounded",children:"Replace"}),i.jsx("div",{className:U("w-full select-none",J&&"opacity-50 pointer-events-none"),children:V||i.jsx("span",{className:"flex items-center justify-center text-gray-300",children:k==="edit"&&i.jsx(F,{icon:"ph:plus-bold"})})})]})},S)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3 items-center",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:g==null?void 0:g.map((S,A)=>N(A,s,a))})})},fi=m.memo(Ja),Ya="edit";function xi({index:e,onDrop:n,onDragEnd:o,isDragging:s}){const[a,t]=m.useState(!1),l=a?52:s?28:4;return i.jsx("div",{onDragEnter:r=>{r.preventDefault(),t(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),t(!0)},onDragLeave:()=>t(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),t(!1),n(r,e)},onDragEnd:()=>{t(!1),o()},style:{height:`${l}px`},className:U("w-full rounded-md flex items-center justify-center","transition-all duration-150 ease-in-out overflow-hidden",a?"bg-blue-50 border-2 border-blue-400 border-dashed":s?"border-2 border-blue-200 border-dashed":"border-2 border-transparent"),children:a&&i.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[i.jsx(F,{icon:"octicon:plus-16"}),"Drop here"]})})}function Za({elementData:e,sectionId:n}){const{formData:o,isDragging:s,setIsDragging:a,addElementInPosition:t,moveElement:l}=m.useContext(me),[r,d]=m.useState(null),c=m.useMemo(()=>{var h;return((h=o.find(y=>y.id===n))==null?void 0:h.questionData)||[]},[o,n]),u=m.useCallback((h,y)=>{h.dataTransfer.setData("elementId",y),h.dataTransfer.setData("properties",y),h.dataTransfer.effectAllowed="move",d(y),a(!0)},[a]),p=m.useCallback(()=>{d(null),a(!1)},[a]);m.useEffect(()=>{!s&&r&&d(null)},[s,r]);const g=m.useCallback(h=>{h.preventDefault(),h.stopPropagation();const y=h.dataTransfer.getData("elementId"),N=h.currentTarget.id;if(!y||!N||y===N){p();return}const S=c.find(k=>k.id===y),A=c.findIndex(k=>k.id===N);S!=null&&S.gridId&&A!==-1?l({draggedId:y,sectionId:n,targetIndex:A}):l({draggedId:y,sectionId:n,targetId:N}),d(null),a(!1)},[n,l,a,p,c]),f=m.useCallback((h,y)=>{h.preventDefault(),h.stopPropagation(),a(!1);const N=h.dataTransfer.getData("elementId");if(N){l({draggedId:N,sectionId:n,targetIndex:y}),d(null);return}try{const S=JSON.parse(h.dataTransfer.getData("properties"));if((S==null?void 0:S.type)==="section")return;const A={...S,id:ge.v4(),sectionId:n};t(A,n,y),d(null)}catch(S){console.error("Drop error:",S)}},[t,n,a,l]),w=m.useCallback((h,y=!1)=>i.jsx("div",{id:h.id,draggable:!0,onDragStart:N=>u(N,h.id),onDragOver:y?void 0:N=>{N.preventDefault(),N.stopPropagation()},onDrop:y?void 0:g,onDragEnd:p,className:U("cursor-grab active:cursor-grabbing border p-4 w-full rounded-lg","transition-all duration-200 ease-in-out",r===h.id?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-300 shadow-inner":r?"bg-white border-dashed border-blue-200 shadow-sm":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:qa(h,n)},h.id),[r,g,n,u,p]),x=m.useMemo(()=>(e==null?void 0:e.reduce((h,y)=>(y.gridId&&(h[y.gridId]=h[y.gridId]||[],h[y.gridId].push(y)),h),{}))||{},[e]);if(!(e!=null&&e.length))return i.jsx("div",{onDragOver:h=>h.preventDefault(),onDrop:h=>f(h,0),onDragEnd:p,className:"w-full h-full flex items-center justify-center text-gray-400 min-h-[200px] p-10 col-span-2 border border-dashed border-gray-300 rounded-lg",children:"Drag or click an element to display"});const b=e.filter(h=>!h.gridId);return i.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[i.jsx(xi,{index:0,isDragging:s,onDrop:f,onDragEnd:p}),b.map(h=>{const y=c.findIndex(N=>N.id===h.id);if(h.type==="grid"){const N=x[h.id]||[],S=r===h.id,A=!!r&&!S;return i.jsxs("div",{className:"flex flex-col gap-0",children:[i.jsx("div",{id:h.id,draggable:!0,onDragStart:k=>u(k,h.id),onDragOver:k=>{k.preventDefault(),k.stopPropagation()},onDrop:g,onDragEnd:p,className:U("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",S?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":A?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:i.jsx(pi,{element:h,state:"edit",children:i.jsx(fi,{element:h,sectionId:n,state:Ya,draggedElementId:r,children:N==null?void 0:N.map(k=>{var _;return i.jsx(hi,{col:(_=k.gridPosition)==null?void 0:_.col,children:w(k,!0)},k.id)})})})}),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},h.id)}return i.jsxs("div",{className:"flex flex-col gap-0",children:[w(h),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},h.id)})]})}const $a=m.memo(Za),Qa=T.object({title:T.string(),description:T.string()}).required(),yi=ve("config"),Xa=({isOpen:e,onClose:n,section:o})=>{const{updateSection:s}=m.useContext(me),{register:a,handleSubmit:t,watch:l,formState:{errors:r,isSubmitting:d,isValid:c},reset:u}=ye.useForm({resolver:mi(Qa),defaultValues:o});if(m.useEffect(()=>{e||u()},[e,u]),!e)return null;const p=g=>{s(g,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(p),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(H,{label:"Title",name:"title",register:a,errors:r,watch:l}),i.jsx(H,{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:(yi==null?void 0:yi.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"})]})]})]})})},es=()=>{const[e,n]=m.useState(!1),o=m.useRef(null),s=m.useRef(null),{removeSection:a,addSection:t,formData:l,setIsDragging:r,setSelectedSection:d,selectedSection:c,activeSections:u,setActiveSections:p}=m.useContext(me);m.useEffect(()=>{var b;d(((b=l[0])==null?void 0:b.id)||null)},[]);const g=m.useCallback(b=>{b.preventDefault(),b.dataTransfer.dropEffect="move",s.current&&(s.current.scrollTop=s.current.scrollHeight)},[]);function f(b){u.includes(b)?p(h=>h.filter(y=>y!==b)):p(h=>[...h,b])}function w(b){o.current=b,n(!0)}const x=ve("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(Xa,{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((b,h)=>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 wa(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const vi=["text","number","boolean"],mn=["equals","not_equals","contains","not_contains"],ka=["greater","less"];function Aa({register:e,setValue:n,trigger:o,watch:s,id:a}){const{formData:t}=m.useContext(me),l=s("visibilityDependentFields")||[],r=m.useMemo(()=>{var c;return(c=wa(t).filter(u=>u.id!==a))==null?void 0:c.map(u=>{const p=l.find(g=>g.id===u.id);return{id:u.id,value:u.id,label:u.inputLabel,sectionId:u.sectionId,fieldType:(p==null?void 0:p.fieldType)||"text",operator:(p==null?void 0:p.operator)||"equals",fieldValue:(p==null?void 0:p.fieldValue)!==void 0?p.fieldValue:""}})},[t,l,a]),d=(c,u,p)=>{const g=l==null?void 0:l.map((f,w)=>w===c?{...f,[u]:p}:f);n("visibilityDependentFields",g)};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 p,g;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:c.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.fieldType,onChange:f=>d(u,"fieldType",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldType}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:vi==null?void 0:vi.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f},f))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(z.Listbox,{value:c.operator,onChange:f=>d(u,"operator",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.operator.replace("_"," ")}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(p=c.fieldType==="number"?[...mn,...ka]:mn)==null?void 0:p.map(f=>i.jsx(z.Listbox.Option,{value:f,className:"listbox-option",children:f.replace("_"," ")},f))})})]})})}),c.fieldType!=="boolean"?i.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:f=>d(u,"fieldValue",f.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(z.Listbox,{value:(g=c.fieldValue)!=null?g:"",onChange:f=>d(u,"fieldValue",f),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(z.Listbox.Button,{className:"listbox-button",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),i.jsx(z.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(z.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(z.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(z.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},c.id)})})]})}const Sa=T.object().shape({inputLabel:T.string().nullable(),placeholder:T.string().nullable(),description:T.string().nullable(),isReadOnly:T.boolean(),isDisabled:T.boolean(),isRequired:T.boolean(),requiredMessage:T.string().nullable(),minLengthMessage:T.string().nullable(),maxLengthMessage:T.string().nullable(),maxLength:T.number().typeError("Expecting a number").nullable(),minLength:T.number().typeError("Expecting a number").nullable(),inputType:T.string().nullable(),maxAmountMessage:T.string().nullable(),maxAmount:T.string().nullable(),options:T.array().of(T.object().shape({label:T.string().nullable(),value:T.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:T.array().of(T.object().shape({label:T.string().nullable(),value:T.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:T.string().nullable(),url:T.string().nullable(),method:T.string().nullable(),denominators:T.mixed().nullable(),responseType:T.string().nullable(),minAmount:T.string().nullable(),heading:T.string().nullable(),minAmountMessage:T.string().nullable(),columns:T.number().nullable().max(4).min(2),value:T.mixed().nullable(),customClass:T.string().nullable(),elementClass:T.string().nullable(),apiUrl:T.string().nullable(),selectType:T.string().default("list"),dateType:T.string().default("basic"),validationUrl:T.string(),signatureLink:T.string(),minDate:T.string().nullable(),maxDate:T.string().nullable(),canHaveDateRange:T.boolean(),allowYearPicker:T.boolean(),isHidden:T.boolean(),visibilityDependentFields:T.array().nullable(),isMultiple:T.boolean(),acceptedFiles:T.array(),showState:T.boolean()}),Na=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],ja=({isOpen:e,onClose:n,element:o})=>{const s=Na.filter(G=>!qe.includes(o.inputType)||G.key!=="validation"),{updateElement:a}=m.useContext(me),[t,l]=m.useState("basic"),[r,d]=m.useState(!1),[c,u]=m.useState("manual"),p=ve("config"),{register:g,handleSubmit:f,control:w,setValue:x,watch:b,trigger:h,formState:{errors:y,isSubmitting:N,isValid:S},reset:A}=ye.useForm({resolver:mi(Sa),defaultValues:{...o,options:o.options||[]}}),k=b(),{fields:_,append:O,remove:$}=ye.useFieldArray({control:w,name:"options"}),{fields:V,append:J,remove:C}=ye.useFieldArray({control:w,name:"options1"}),{fields:E,append:L,remove:B}=ye.useFieldArray({control:w,name:"dataColumns"});m.useEffect(()=>{e||A()},[e,A]);const K=G=>{a(G,o.sectionId),n()},P={headers:{Authorization:`Bearer ${ve("token")}`}},D=m.useCallback(async()=>{var G,I,oe;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){he.toast.info("Please provide a valid API URL");return}try{d(!0);const{status:te,data:ne}=await _e.get(k.apiUrl,P);if(te!==200||!ne){he.toast.error("Unexpected response from server.");return}const ae=ne.data||ne.record||ne.result;if(!Array.isArray(ae)){he.toast.error("Expected an array in response (data, record, or result).");return}((G=o.type)==null?void 0:G.toLowerCase())==="datagrid"?x("dataColumns",ae):x("options",ae)}catch(te){const ne=((oe=(I=te==null?void 0:te.response)==null?void 0:I.data)==null?void 0:oe.message)||(te==null?void 0:te.message)||"Unable to load options";he.toast.error(ne)}finally{d(!1)}},[o.type,x,k.apiUrl]),W=["manual","api","sheet"];function X(){c==="api"&&D()}const ce=()=>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:W==null?void 0:W.map(G=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:I=>u(I.target.value),value:G})," ",i.jsxs("span",{children:[G," options"]})]},G))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:b,label:"Load Options from Api",name:"apiUrl",errors:y,register:g,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:X,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(cn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:x,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),_==null?void 0:_.map((G,I)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Label":"",name:`options.${I}.label`,register:g,errors:y,element:o,placeholder:"Label"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Value":"",name:`options.${I}.value`,register:g,errors:y,element:o,placeholder:"Value"})}),i.jsx("button",{disabled:_.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>$(I),children:i.jsx(F,{icon:"iconamoon:sign-times-fill"})})]},G.id))," ",i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>O({label:"",value:"",id:ge.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 "}),V==null?void 0:V.map((G,I)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Label",name:`options1.${I}.label`,register:g,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Value",name:`options1.${I}.value`,register:g,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Key",name:`options1.${I}.key`,register:g,errors:y,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:V.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>C(I),children:i.jsx(F,{icon:"iconamoon:sign-times-fill"})})]},G.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:()=>J({label:"",value:"",key:"",id:ge.v4()}),children:[i.jsx(F,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),ue=()=>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:W==null?void 0:W.map(G=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:I=>u(I.target.value),value:G,checked:G===c})," ",i.jsxs("span",{children:[G," options"]})]},G))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(H,{watch:b,label:"Load Columns from Api",name:"apiUrl",errors:y,register:g,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:X,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(cn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:x,name:"dataColumns"})}),E==null?void 0:E.map((G,I)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"min-w-[140px]",children:i.jsx(Me,{label:I===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"}],register:g,name:`dataColumns.${I}.type`,setValue:x,trigger:h,value:k.dataColumns[I].type})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Field key":"",name:`dataColumns.${I}.field`,register:g,errors:y,element:o,placeholder:"fieldKey"})}),i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:I===0?"Display header":"",name:`dataColumns.${I}.headerName`,register:g,errors:y,element:o,placeholder:"header"})}),i.jsx("button",{disabled:E.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>B(I),children:i.jsx(F,{icon:"iconamoon:sign-times-fill"})})]},G.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({headerName:"",field:"",editable:!0,id:ge.v4(),type:"text",validate:!1}),children:[i.jsx(F,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),ie=m.useCallback(async()=>{const G=ve("token"),{status:I,data:oe}=await _e.get(k.url,{headers:{Authorization:`Bearer ${G}`}});I===200&&x("options",(oe==null?void 0:oe.data)||oe)},[x,k.url]);return m.useEffect(()=>{o.type==="document"&&k.url&&ie()},[k.url,o.type,ie]),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:G=>G.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:G=>G.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:f(K),className:"w-full flex-1 flex flex-col",children:[i.jsxs("div",{className:"flex-1",children:[" ",i.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[t==="basic"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[bi.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(H,{watch:b,label:"Value",name:"value",register:g,errors:y,element:o})}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:b,label:"Label",name:"inputLabel",register:g,errors:y,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(H,{watch:b,label:"Child Label",name:"childLabel",register:g,errors:y,element:o})]}),ra.includes(o.inputType)&&i.jsx(H,{watch:b,label:"Placeholder",name:"placeholder",register:g,errors:y,element:o}),la.includes(o.inputType)&&i.jsx(H,{watch:b,label:"Prefix",name:"prefix",register:g,errors:y,element:o}),ma.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(ga,{}),i.jsx(H,{watch:b,label:"Api Url",name:"url",register:g,errors:y,element:o}),i.jsx(Me,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:g,name:"method",setValue:x,trigger:h,value:b("method")}),i.jsx(Me,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:g,name:"responseType",setValue:x,trigger:h,value:b("responseType")})]}),ba.includes(o.inputType)&&i.jsx(pa,{onChange:G=>{x("denominators",G)},value:b("denominators")}),!bi.includes(o.inputType)&&!qe.includes(o.inputType)&&i.jsx(H,{watch:b,label:"Short Description",name:"description",register:g,errors:y,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Me,{label:"Date Format",options:ta,register:g,name:"dateFormat",setValue:x,trigger:h,value:b("dateFormat")}),i.jsx(H,{watch:b,label:"Allow Range",name:"canHaveDateRange",register:g,errors:y,element:o,type:"checkbox"}),(k==null?void 0:k.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx(Qe,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select min date"}),i.jsx(Qe,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:x,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),i.jsx(H,{watch:b,label:"Allow Year Picker",name:"allowYearPicker",register:g,errors:y,element:o,type:"checkbox"})]}),o.type.toLowerCase()==="country"&&i.jsx(H,{watch:b,label:"Allow States",name:"showState",register:g,errors:y,element:o,type:"checkbox"}),o.type.toLowerCase()==="selectfield"&&i.jsx(Me,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:g,name:"selectType",setValue:x,trigger:h,value:b("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(H,{watch:b,label:"Number of columns (max: 4)",name:"columns",register:g,errors:y,element:o,max:4,min:1}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:b,label:"Document Options Url",name:"url",register:g,errors:y,element:o})," ",i.jsx(xa,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(H,{watch:b,label:"Document Validation Url",name:"validationUrl",register:g,errors:y,element:o}),i.jsx(ya,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(H,{watch:b,label:"Signature Page Url",name:"signatureLink",register:g,errors:y,element:o})})]}),o.type.toLowerCase()==="datagrid"&&ue(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(H,{watch:b,label:"Allow Multiple Uploads",name:"isMultiple",register:g,errors:y,element:o,type:"checkbox"}),i.jsx(ui,{element:{options:va,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:g,setValue:x,trigger:h,watch:b},placeholder:"Choose file types"})]}),ca.includes(o.inputType)&&ce(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(H,{watch:b,label:"Toggle Visibility",name:"isHidden",register:g,errors:y,element:o,type:"checkbox"})})," ",k.isHidden&&i.jsx(Aa,{register:g,setValue:x,trigger:h,watch:b,id:o==null?void 0:o.id})]})]}),!qe.includes(o.type.toLowerCase())&&t==="validation"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:b,label:"Required",name:"isRequired",register:g,errors:y,element:o,type:"checkbox"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"requiredMessage",register:g,errors:y,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(H,{watch:b,label:"Min Length",name:"minLength",register:g,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"minLengthMessage",register:g,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:b,label:"Max Length",name:"maxLength",register:g,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"maxLengthMessage",register:g,errors:y,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(H,{watch:b,label:"Min Amount",name:"minAmount",register:g,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"minAmountMessage",register:g,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(H,{watch:b,label:"Max Amount",name:"maxAmount",register:g,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(H,{watch:b,label:"Error message text",name:"maxAmountMessage",register:g,errors:y,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest editor_option__cancel",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!S||N,style:{background:(p==null?void 0:p.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!S||N?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!S||N?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:N?"Saving...":"Save"})]})]})]})})},pi=m.memo(({state:e,element:n,children:o})=>{const[s,a]=m.useState(!1),{removeElement:t,duplicateElement:l}=m.useContext(me),r=m.useMemo(()=>{var c;return(c=n==null?void 0:n.acceptedFiles)==null?void 0:c.map(u=>u.label).join(", ")},[n]),d=m.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return i.jsxs("div",{className:"w-full",children:[s&&i.jsx(ja,{isOpen:s,onClose:()=>a(!1),element:n}),i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("span",{children:[" ",n.inputLabel&&i.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",r&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",r==null?void 0:r.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[!n.gridPosition&&i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1",onClick:()=>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 text-gray-600 py-1",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 text-gray-600 py-1",onClick:d,title:"Remove",children:i.jsx(F,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});pi.displayName="ElementContainer";function _a({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(H,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:s,setValue:a,value:r==null?void 0:r.value,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]=m.useState(!1),s=()=>{o(!0)},a=()=>{o(!1)};return i.jsxs("div",{children:[i.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:s,src:e||"/place.png","data-toggle":"tooltip","data-placement":"top",title:"Click to view"}),n&&i.jsx("div",{className:"modal",style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",justifyContent:"center",alignItems:"center"},onClick:a,children:i.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:t=>t.stopPropagation(),children:[i.jsx("span",{className:"close",onClick:a,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),i.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function Ea({element:e,validationData:n}){var k;const{register:o=()=>({}),setValue:s,watch:a}=n||{},[t,l]=m.useState(),[r,d]=m.useState(!1),[c,u]=m.useState(!1),[p,g]=m.useState(""),f=a&&a(e==null?void 0:e.id);m.useEffect(()=>{l(f)},[f]);const[w,x]=m.useState("");m.useEffect(()=>{o(e.id)},[e.id,o]);const{url:b,method:h,responseType:y}=e||{},S={headers:{Authorization:`Bearer ${ve("token")}`}},A=m.useCallback(async _=>{var O,$,V,J,C,E,L,B,K,Y,P;if(!(!b||!h)){d(!0);try{let D;if(h.toLowerCase()==="get"){const W=`${b}?value=${_}`;D=await _e.get(W,S)}else if(h.toLowerCase()==="post")D=await _e.post(b,{value:_},S);else throw new Error("Unsupported HTTP method");D.status===200&&(((($=(O=D==null?void 0:D.data)==null?void 0:O.data)==null?void 0:$.status)||((V=D==null?void 0:D.data)==null?void 0:V.status))===!0?(u(!0),y==="string"?g(((C=(J=D==null?void 0:D.data)==null?void 0:J.data)==null?void 0:C.description)||((E=D==null?void 0:D.data)==null?void 0:E.description)||"Validation successful"):x(((B=(L=D==null?void 0:D.data)==null?void 0:L.data)==null?void 0:B.description)||((K=D==null?void 0:D.data)==null?void 0:K.description)||{})):(console.error("Invalid input:",_),g("Unable to validate input"),u(!1)))}catch(D){console.error("Error validating input:",D),g(((P=(Y=D==null?void 0:D.response)==null?void 0:Y.data)==null?void 0:P.message)||"Unable to validate input"),u(!1)}finally{d(!1)}}},[h,y,b]);return m.useEffect(()=>{if(t){const _=setTimeout(()=>{A(t)},700);return()=>clearTimeout(_)}},[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:U("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:_=>{l(_.target.value),s(e==null?void 0:e.id,_.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"})})]})]}),p&&y==="string"&&i.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:p}),y==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(k=Object.entries(w))==null?void 0:k.map(([_,O])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[_,":"]}),Ca(O)?i.jsx(Ma,{imageUrl:O}):i.jsx("span",{children:String(O)})]},_))})]})}function Ta({onGetTotal:e,readOnly:n,defaultValue:o,denominators:s}){const[a,t]=m.useState([...o]);function l(c,u){t(p=>{const g=[...p];return g[u]={...g[u],value:c},g})}function r(c,u){return parseFloat(c)*parseFloat(u)||0}const d=m.useMemo(()=>a.reduce((c,u)=>{const p=r(u.key,u.value);return c+p},0),[a]);return m.useEffect(()=>{e&&e(a)},[a]),m.useEffect(()=>{if(s!=null&&s.length){const c=s==null?void 0:s.map((u,p)=>({key:u.value,value:Array.isArray(o)&&o[p]?o[p].value:""}));t(c)}},[o,s]),i.jsx("div",{className:"mt-2",children:i.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{className:"",children:"Denomination"})}),i.jsx("div",{className:"border-r px-4 py-2",children:i.jsx("span",{children:"Quantity"})}),i.jsx("div",{className:"px-4 py-2",children:i.jsx("span",{children:"Sub total"})})]}),a==null?void 0:a.map((c,u)=>{var p,g;return i.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[i.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:i.jsx("span",{className:"",children:(p=parseFloat(c.key))==null?void 0:p.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(Ge,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:f=>l(f,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(g=r(c.key,c.value))==null?void 0:g.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 m.useEffect(()=>{o(e.id)},[e.id,o]),i.jsx("div",{children:i.jsx(Ta,{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:U("py-6",e==null?void 0:e.customClass)})}function Pa({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:U("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Da({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 Oa({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 y;const p=e[u.field],g=u.editable&&!o,f=c(u.field),{isValidating:w,result:x}=r(e.id,u.field);let b="border-gray-300";u.validate&&((x==null?void 0:x.isValid)===!1?b="border-red-500 bg-red-50":(x==null?void 0:x.isValid)===!0&&(b="border-green-500 bg-green-50"));const h=`w-full px-2 py-1 border rounded outline-none ${b}`;return i.jsx("td",{title:o?"":"Double click to edit",className:"px-3 py-1 border",onDoubleClick:()=>g&&a({rowId:e.id,field:u.field}),children:g&&f?i.jsxs("div",{className:"relative",children:[u.type==="number"?i.jsx(Ge,{value:p,decimalsLimit:6,allowNegativeValue:!1,className:h,onValueChange:N=>t(N,e.id,u.field),onBlur:()=>{a(null),l(p,e.id,u.field,u)},autoFocus:!0}):u.type==="checkbox"?i.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(N=>{const S=N==="yes",A=`radio-${e.id}-${String(u.field)}-${N}`;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:p===S,onChange:()=>t(S,e.id,u.field)}),i.jsx("span",{className:"text-sm",children:S?"Yes":"No"})]},N)})}):i.jsx("input",{type:"text",value:String(p!=null?p:""),onChange:N=>t(N.target.value,e.id,u.field),onBlur:()=>{a(null),l(p,e.id,u.field,u)},className:h,autoFocus:!0}),w&&i.jsx("div",{className:"absolute right-1 top-1",children:i.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):u.validate&&x?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{children:[String(p!=null?p:"")," ",x.data&&`[${x.data}]`]}),x.isValid?i.jsx("span",{className:"text-xs text-green-600",children:"✓"}):i.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(y=x.error)!=null?y:"",children:"✗"})]}):u.type==="checkbox"?i.jsx("span",{className:"block py-1 text-gray-700",children:p===!0?"Yes":p===!1?"No":""}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:String(p!=null?p:"")})},String(u.id))}),!o&&i.jsx("td",{className:"px-3 py-1 text-center border",children:i.jsx("button",{type:"button",onClick:()=>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=m.memo(Oa);function Ga({value:e=[],onChange:n,isReadOnly:o=!1,columns:s}){const[a,t]=m.useState(e),[l,r]=m.useState(null),d=m.useRef(null),[c,u]=m.useState(0);m.useEffect(()=>{const x=document.getElementById("form");if(!x)return;const b=y=>{const N=y.getBoundingClientRect().width;u(N?N-58:0)};b(x);const h=new ResizeObserver(y=>{for(const N of y)b(N.target)});return h.observe(x),()=>h.disconnect()},[]),m.useEffect(()=>{t(x=>JSON.stringify(x)!==JSON.stringify(e)?e:x)},[e]),m.useEffect(()=>{n==null||n(a)},[a,n]),m.useEffect(()=>{const x=b=>{d.current&&!d.current.contains(b.target)&&r(null)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);const p=m.useCallback((x,b,h)=>{t(y=>y.map(N=>N.id===b?{...N,[h]:x}:N))},[]),g=m.useCallback(()=>{const x=ge.v4(),b=s.reduce((h,y)=>(h[y.field]=y.field==="id"?x:"",h),{});t(h=>[...h,{id:x,...b}])},[s]),f=m.useCallback(x=>{t(b=>b.filter(h=>h.id!==x))},[]),w=m.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:g,type:"button",className:"px-2 py-1 mb-3 text-xs text-white bg-gray-600 rounded hover:bg-gray-700",children:"Add Row"})}),i.jsx("div",{className:"w-full max-w-full overflow-x-auto",style:{maxWidth:`${c}px`},children:i.jsxs("table",{className:"min-w-max w-full text-sm border-collapse rounded table-auto bg-gray-50",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"bg-gray-100",children:[s.map((x,b)=>{var h;return i.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border whitespace-nowrap",children:[(h=x.headerName)!=null?h:String(x.field),x.validate&&i.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(x.id)}-${b}`)}),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:a.length>0?a.map(x=>i.jsx(Ka,{row:x,columns:s,isReadOnly:o,editingCell:l,setEditingCell:r,handleCellChange:p,debouncedValidate:()=>{},getValidationStatus:w,deleteRow:f},x.id)):i.jsx("tr",{children:i.jsx("td",{colSpan:s.length+(o?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})})]})}function Ra({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t}=n||{},l=a&&a(e==null?void 0:e.id)||[];m.useEffect(()=>{o(e.id)},[e.id,o]);const r=m.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 bn=({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:p=!1,subText:g,labelClass:f="",loading:w,disabled:x})=>{const[b,h]=m.useState(u?[]:null),y=U("custom-select__control",e),N=m.useMemo(()=>n,[n]);return m.useEffect(()=>{const S=n==null?void 0:n.find(A=>{var k;return typeof A.value=="string"&&typeof d=="string"?A.value.toLowerCase()===d.toLowerCase():typeof A.value=="object"&&typeof d=="object"?((k=A.value)==null?void 0:k.id)===(d==null?void 0:d.id):A.value===d});h(S||null)},[d,n]),m.useEffect(()=>{b&&t&&a&&(t(l,b==null?void 0:b.value),a(l),c==null||c(l))},[l,b]),i.jsxs("div",{className:"custom-select",children:[r&&!p&&i.jsx("label",{className:"custom-select__label",children:r}),p&&r&&i.jsx("label",{className:U("custom-select__floating-label",f),children:r}),i.jsx(z.Listbox,{value:b,onChange:h,multiple:u,disabled:x,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(z.Listbox.Button,{className:y,disabled:x,children:[w?i.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):i.jsx("span",{className:"custom-select__value",children:(b==null?void 0:b.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(z.Transition,{as:m.Fragment,leave:"custom-select__transition",children:i.jsx(z.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:N==null?void 0:N.map((S,A)=>i.jsx(z.Listbox.Option,{value:S,className:({active:k})=>U("custom-select__option",k&&"custom-select__option--active"),children:({selected:k})=>i.jsx("span",{className:U("custom-select__option-label",k&&"custom-select__option--selected"),children:S.label})},A))})})]})}),g&&!s&&i.jsx("p",{className:"custom-select__subtext",children:g}),s&&i.jsx("span",{className:"custom-select__error",children:s.message})]})},za=({element:e,validationData:n})=>{var x;const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:l}=n||{},r=(x=e==null?void 0:e.id)!=null?x:"cascadeValue",[d,c]=m.useState(""),[u,p]=m.useState(""),g=(b,h)=>{const y=b&&h?`${b}_${h}`:"";a==null||a(r,y),s==null||s(r)},f=(b,h)=>{b==="first"?(c(h),p(""),g(h,"")):(p(h),g(d,h))};m.useEffect(()=>{if(t){const b=t(r);if(b!=null&&b.includes("_")){const[h,y]=b.split("_");c(h),p(y)}}},[t,r]);const w=m.useMemo(()=>{var b;return(b=e.options1)==null?void 0:b.filter(h=>h.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(bn,{setValue:(b,h)=>f("first",h),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(bn,{setValue:(b,h)=>f("second",h),options:w,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 h;const{register:d=()=>({}),trigger:c,setValue:u,watch:p,isReadOnly:g}=r||{},f=(h=p==null?void 0:p(l.id))!=null?h:0,[w,x]=m.useState(null);m.useEffect(()=>{f==null&&(u==null||u(l.id,e))},[]);const b=y=>{if(!o&&!g){const N=y+1;u==null||u(l.id,N),c==null||c(l.id),s==null||s(N)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(y,N)=>{const S=w!==null?N<=w:N<f;return i.jsx(dn,{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||g)&&x(N),onMouseLeave:()=>!(o||g)&&x(null),onClick:()=>b(N)},N)})]})};function vn({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}=m.useMemo(()=>{var w;if(typeof r=="string"&&r.includes(",")){const[x,b]=(w=r.split(","))==null?void 0:w.map(h=>h.trim());return{country:b,state:x}}return{country:r,state:""}},[r]),u=m.useRef(r),p=m.useMemo(()=>{var w,x;return d?((x=(w=We.find(b=>b.name===d))==null?void 0:w.states)==null?void 0:x.map(b=>({label:b.name,value:b.name})))||[]:[]},[d]),g=(w,x)=>{const h=(x==null?void 0:x.value)||"";s&&h!==u.current&&(s(e.id,h),a==null||a(e.id),u.current=h)},f=(w,x)=>{const b=(x==null?void 0:x.value)||"",h=b?`${b}, ${d}`:d;s&&h!==u.current&&(s(e.id,h),a==null||a(e.id),u.current=h)};return m.useEffect(()=>{u.current=r},[r]),i.jsxs("div",{className:"grid gap-y-6",children:[i.jsx("input",{type:"hidden",...o(e.id)}),i.jsx(ci,{options:e.options,onGetValue:g,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),p.length>0&&e.showState&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),i.jsx(ci,{options:p,onGetValue:f,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function Fa({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:s}=n||{},{validationUrl:a,documentObj:t,signatureLink:l}=e,r=m.useMemo(()=>ve("config"),[]),[d,c]=m.useState(!1),[u,p]=m.useState(!1),g=m.useCallback(async()=>{var f,w;if(!(!a||!t))try{p(!0);const b={headers:{Authorization:`Bearer ${ve("token")}`}},{data:h}=await _e.get(`${a}/${t}`,b),y=!!((w=(f=h==null?void 0:h.data)==null?void 0:f.isSigned)!=null?w:h!=null&&h.isSigned);return c(y),y}catch(x){console.error("Failed to check sign status",x)}finally{p(!1)}},[a,t]);return m.useEffect(()=>{let f=null;return!d&&t&&a&&(async()=>{await g()||(f=setInterval(async()=>{await g()&&f&&clearInterval(f)},2e3))})(),()=>{f&&clearInterval(f)}},[g,d,t,a]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:U("field-control",e.customClass),...o(e.id),disabled:s}),i.jsx("a",{href:d?"#":l,children:i.jsxs("button",{type:"button",onClick:g,disabled:u||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:U("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:p,validate:g,onChange:f,onError:w}){const[x,b]=m.useState(""),[h,y]=m.useState(null),[N,S]=m.useState(""),A=m.useMemo(()=>{var C;return(C=gi==null?void 0:gi.slice().sort((E,L)=>E.label.localeCompare(L.label)))==null?void 0:C.map(E=>({...E,phone:`+${E.phone}`}))},[]),k=m.useMemo(()=>x?A.filter(C=>`${C.label} ${C.phone}`.toLowerCase().includes(x.toLowerCase())):A,[x,A]),_=(h==null?void 0:h.min)||10,O=(h==null?void 0:h.max)||10,$=()=>N?`${(h==null?void 0:h.phone)||"+234"}-${N}`:"",V=C=>{if(!C)return{code:"+234",number:""};const E=C.split(/[-\s]/);return{code:E[0],number:E.slice(1).join(" ")}};m.useEffect(()=>{if(l){const C=V(l);y(A.find(E=>E.phone===C.code)||A[0]),S(C.number)}},[l,A]);const J=m.useMemo(()=>{if(r)return r;const C=N.length;return s&&C===0?"Phone number is required":C>0&&!/^\d+$/.test(N)?"Phone number must contain only digits":C>0&&C<_?`Minimum length is ${_}`:C>O?`Maximum length is ${O}`:""},[r,N,_,O,s]);return m.useEffect(()=>{f==null||f($()),w==null||w(J||null)},[N,h,J]),i.jsxs("div",{className:`relative formGroup ${J&&!c?"has-error":""} ${u?"flex":""} ${!J&&N.length>0&&!c?"is-valid":""}`,children:[e&&i.jsxs("label",{htmlFor:t,className:`${o} ${u?"flex-0 mr-6 md:w-[100px] w-[60px] break-words":""} flex items-center gap-x-1 input-label text-sm text-[#1B2B41B8]`,children:[e," ",s&&i.jsx("span",{className:"text-red-500",children:"*"}),a&&i.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),i.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[i.jsx(F,{icon:"lucide:phone-call"}),i.jsx(z.Combobox,{value:h,onChange:y,children:i.jsxs("div",{className:"relative",children:[i.jsx(z.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:C=>(C==null?void 0:C.phone)||"+234",placeholder:"+234",onChange:C=>b(C.target.value)}),i.jsx(z.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(F,{icon:"lucide:chevron-down"})}),i.jsx(z.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:k==null?void 0:k.map((C,E)=>i.jsxs(z.Combobox.Option,{value:C,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[C.phone," - ",C.label]},`${C.code}+ ${E}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:N,disabled:d,readOnly:c,onChange:C=>{const E=C.target.value.replace(/\D/g,"");S(E)},placeholder:n,className:"w-full px-3 outline-none",maxLength:O,minLength:_}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!J&&N.length>0&&!c&&i.jsx("span",{className:"text-green-500",children:i.jsx(F,{icon:"bi:check-lg"})})})]})]}),p&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:p})]})}function Wa({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a,isReadOnly:t,setError:l,clearErrors:r}=n||{};let d;return m.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 Ua({element:e,validationData:n}){var c;const{register:o=()=>({}),watch:s}=n||{};let a="";s&&(a=(c=s()[e.id])!=null?c:"");const t=a.trim(),l=/^https?:\/\//i.test(t),r=t?l?t:`https://${t}`:"",d=!l;return i.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&i.jsxs("div",{className:"relative",children:[d&&i.jsx("span",{className:"text-sm absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none select-none",children:"https://"}),i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:U("field-control",d&&"!pl-16",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly})]}),t?i.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:i.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:t})}):(n==null?void 0:n.isReadOnly)&&i.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}const pn={textField:Xe,longText:ea,selectField:Xo,multiSelect:ui,numberField:Xe,amountField:_a,date:Hn,password:Yo,checkbox:Qo,radio:Zo,email:Xe,file:Jo,dataGrid:Ra,section:$o,validateInput:Ea,tableInput:Ba,spacer:La,divider:Pa,header:Da,basicText:Ia,phoneField:Wa,cascadeSelect:za,rating:Ha,country:vn,bank:vn,document:Fa,url:Ua},gn="edit",qa=(e,n)=>{const o=pn[e.type];return o?i.jsx(pi,{element:e,state:gn,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:gn,sectionId:n})]})}):null},hi=({col:e,children:n,customClass:o})=>i.jsx("div",{className:U("w-full bg-white",o),style:{gridColumn:e},children:n}),Ja=({element:e,sectionId:n,children:o,customClass:s,state:a,draggedElementId:t})=>{const{formData:l,addElement:r,setIsDragging:d,moveElement:c,isDragging:u,removeElement:p}=m.useContext(me),g=m.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[f,w]=m.useState(null);m.useEffect(()=>{const S=()=>{w(null),d(!1)};return document.addEventListener("dragend",S),()=>document.removeEventListener("dragend",S)},[d]);const x=m.useCallback((S,A)=>{S.preventDefault(),S.stopPropagation(),S.dataTransfer.dropEffect="move",w(A)},[]),b=m.useCallback((S,A)=>{S.preventDefault(),S.stopPropagation(),w(A)},[]),h=m.useCallback((S,A)=>{const k=S.relatedTarget;k&&S.currentTarget.contains(k)||w(_=>_===A?null:_)},[]),y=m.useCallback((S,A)=>{var O;S.preventDefault(),S.stopPropagation(),d(!1),w(null);const k=A+1,_=S.dataTransfer.getData("elementId");if(_){c({draggedId:_,sectionId:n,targetGridId:e.id,targetCol:k});return}try{const $=S.dataTransfer.getData("properties");if(!$)return;const V=JSON.parse($);if((V==null?void 0:V.type)==="grid")return;const J=l.find(L=>L.id===n),C=(O=J==null?void 0:J.questionData)==null?void 0:O.find(L=>{var B;return L.gridId===e.id&&((B=L.gridPosition)==null?void 0:B.col)===k});C&&p(C.id,n);const E={...V,id:ge.v4(),sectionId:n,gridId:e.id,gridPosition:{col:k}};r(E,n)}catch($){console.error("Drop failed in grid:",$),d(!1)}},[r,e.id,l,n,d,c]),N=(S,A,k)=>{var B,K,Y;const _=S+1,O=(K=(B=l.find(P=>P.id===n))==null?void 0:B.questionData)==null?void 0:K.find(P=>{var D;return P.gridId===e.id&&((D=P.gridPosition)==null?void 0:D.col)===_}),$=(Y=O==null?void 0:O.id)!=null?Y:null,V=Array.isArray(o)&&o.find(P=>{var D;return((D=P==null?void 0:P.props)==null?void 0:D.col)===_}),J=u&&f===S,C=!!V,E=u&&!!t,L=C&&$&&k==="edit"?{draggable:!0,onDragStart:P=>{P.stopPropagation(),P.dataTransfer.setData("elementId",$),P.dataTransfer.setData("properties",$),P.dataTransfer.effectAllowed="move",d(!0)},onDragEnd:()=>{w(null),d(!1)}}:{};return i.jsx("div",{children:i.jsxs("div",{id:`grid-cell-${e.id}-${S}`,...L,onDrop:P=>y(P,S),onDragEnter:P=>b(P,S),onDragOver:P=>x(P,S),onDragLeave:P=>h(P,S),className:U("relative border rounded-lg min-h-[110px]","flex items-center justify-center","transition-all duration-200 ease-in-out",k==="edit"?"py-3 ":"",C&&k==="edit"&&"cursor-grab active:cursor-grabbing border-none",A,!E&&!J&&"bg-white border-gray-200 text-gray-300",E&&!J&&!C&&"bg-blue-50 border-blue-200 border-dashed text-blue-300",E&&!J&&C&&"bg-white border-orange-200 border-dashed",J&&!C&&"bg-blue-100 border-blue-400 border-dashed shadow-inner scale-[1.01] text-blue-500",J&&C&&"bg-orange-50 border-orange-400 border-dashed shadow-inner scale-[1.01] text-orange-500"),children:[C&&k==="edit"&&i.jsx("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 flex items-center gap-0.5 px-2 py-0.5 rounded-full bg-gray-100 hover:bg-blue-100 text-gray-400 hover:text-blue-500 cursor-grab active:cursor-grabbing transition-colors z-10 opacity-60 hover:opacity-100 pointer-events-none select-none",children:i.jsx(F,{icon:"ph:dots-six-bold"})}),J&&!C&&i.jsxs("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-blue-400 text-xs font-medium pointer-events-none",children:[i.jsx(F,{icon:"ph:plus-bold"}),"Drop here"]}),J&&C&&i.jsx("span",{className:"absolute top-1 right-1 text-xs text-orange-400 font-medium pointer-events-none px-1 py-0.5 bg-orange-50 rounded",children:"Replace"}),i.jsx("div",{className:U("w-full select-none",J&&"opacity-50 pointer-events-none"),children:V||i.jsx("span",{className:"flex items-center justify-center text-gray-300",children:k==="edit"&&i.jsx(F,{icon:"ph:plus-bold"})})})]})},S)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3 items-center",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:g==null?void 0:g.map((S,A)=>N(A,s,a))})})},fi=m.memo(Ja),Ya="edit";function xi({index:e,onDrop:n,onDragEnd:o,isDragging:s}){const[a,t]=m.useState(!1),l=a?52:s?28:4;return i.jsx("div",{onDragEnter:r=>{r.preventDefault(),t(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),t(!0)},onDragLeave:()=>t(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),t(!1),n(r,e)},onDragEnd:()=>{t(!1),o()},style:{height:`${l}px`},className:U("w-full rounded-md flex items-center justify-center","transition-all duration-150 ease-in-out overflow-hidden",a?"bg-blue-50 border-2 border-blue-400 border-dashed":s?"border-2 border-blue-200 border-dashed":"border-2 border-transparent"),children:a&&i.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[i.jsx(F,{icon:"octicon:plus-16"}),"Drop here"]})})}function Za({elementData:e,sectionId:n}){const{formData:o,isDragging:s,setIsDragging:a,addElementInPosition:t,moveElement:l}=m.useContext(me),[r,d]=m.useState(null),c=m.useMemo(()=>{var h;return((h=o.find(y=>y.id===n))==null?void 0:h.questionData)||[]},[o,n]),u=m.useCallback((h,y)=>{h.dataTransfer.setData("elementId",y),h.dataTransfer.setData("properties",y),h.dataTransfer.effectAllowed="move",d(y),a(!0)},[a]),p=m.useCallback(()=>{d(null),a(!1)},[a]);m.useEffect(()=>{!s&&r&&d(null)},[s,r]);const g=m.useCallback(h=>{h.preventDefault(),h.stopPropagation();const y=h.dataTransfer.getData("elementId"),N=h.currentTarget.id;if(!y||!N||y===N){p();return}const S=c.find(k=>k.id===y),A=c.findIndex(k=>k.id===N);S!=null&&S.gridId&&A!==-1?l({draggedId:y,sectionId:n,targetIndex:A}):l({draggedId:y,sectionId:n,targetId:N}),d(null),a(!1)},[n,l,a,p,c]),f=m.useCallback((h,y)=>{h.preventDefault(),h.stopPropagation(),a(!1);const N=h.dataTransfer.getData("elementId");if(N){l({draggedId:N,sectionId:n,targetIndex:y}),d(null);return}try{const S=JSON.parse(h.dataTransfer.getData("properties"));if((S==null?void 0:S.type)==="section")return;const A={...S,id:ge.v4(),sectionId:n};t(A,n,y),d(null)}catch(S){console.error("Drop error:",S)}},[t,n,a,l]),w=m.useCallback((h,y=!1)=>i.jsx("div",{id:h.id,draggable:!0,onDragStart:N=>u(N,h.id),onDragOver:y?void 0:N=>{N.preventDefault(),N.stopPropagation()},onDrop:y?void 0:g,onDragEnd:p,className:U("cursor-grab active:cursor-grabbing border p-4 w-full rounded-lg","transition-all duration-200 ease-in-out",r===h.id?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-300 shadow-inner":r?"bg-white border-dashed border-blue-200 shadow-sm":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:qa(h,n)},h.id),[r,g,n,u,p]),x=m.useMemo(()=>(e==null?void 0:e.reduce((h,y)=>(y.gridId&&(h[y.gridId]=h[y.gridId]||[],h[y.gridId].push(y)),h),{}))||{},[e]);if(!(e!=null&&e.length))return i.jsx("div",{onDragOver:h=>h.preventDefault(),onDrop:h=>f(h,0),onDragEnd:p,className:"w-full h-full flex items-center justify-center text-gray-400 min-h-[200px] p-10 col-span-2 border border-dashed border-gray-300 rounded-lg",children:"Drag or click an element to display"});const b=e.filter(h=>!h.gridId);return i.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[i.jsx(xi,{index:0,isDragging:s,onDrop:f,onDragEnd:p}),b.map(h=>{const y=c.findIndex(N=>N.id===h.id);if(h.type==="grid"){const N=x[h.id]||[],S=r===h.id,A=!!r&&!S;return i.jsxs("div",{className:"flex flex-col gap-0",children:[i.jsx("div",{id:h.id,draggable:!0,onDragStart:k=>u(k,h.id),onDragOver:k=>{k.preventDefault(),k.stopPropagation()},onDrop:g,onDragEnd:p,className:U("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",S?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":A?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:i.jsx(pi,{element:h,state:"edit",children:i.jsx(fi,{element:h,sectionId:n,state:Ya,draggedElementId:r,children:N==null?void 0:N.map(k=>{var _;return i.jsx(hi,{col:(_=k.gridPosition)==null?void 0:_.col,children:w(k,!0)},k.id)})})})}),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},h.id)}return i.jsxs("div",{className:"flex flex-col gap-0",children:[w(h),i.jsx(xi,{index:y+1,isDragging:s,onDrop:f,onDragEnd:p})]},h.id)})]})}const $a=m.memo(Za),Qa=T.object({title:T.string(),description:T.string()}).required(),yi=ve("config"),Xa=({isOpen:e,onClose:n,section:o})=>{const{updateSection:s}=m.useContext(me),{register:a,handleSubmit:t,watch:l,formState:{errors:r,isSubmitting:d,isValid:c},reset:u}=ye.useForm({resolver:mi(Qa),defaultValues:o});if(m.useEffect(()=>{e||u()},[e,u]),!e)return null;const p=g=>{s(g,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(p),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(H,{label:"Title",name:"title",register:a,errors:r,watch:l}),i.jsx(H,{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:(yi==null?void 0:yi.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"})]})]})]})})},es=()=>{const[e,n]=m.useState(!1),o=m.useRef(null),s=m.useRef(null),{removeSection:a,addSection:t,formData:l,setIsDragging:r,setSelectedSection:d,selectedSection:c,activeSections:u,setActiveSections:p}=m.useContext(me);m.useEffect(()=>{var b;d(((b=l[0])==null?void 0:b.id)||null)},[]);const g=m.useCallback(b=>{b.preventDefault(),b.dataTransfer.dropEffect="move",s.current&&(s.current.scrollTop=s.current.scrollHeight)},[]);function f(b){u.includes(b)?p(h=>h.filter(y=>y!==b)):p(h=>[...h,b])}function w(b){o.current=b,n(!0)}const x=ve("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(Xa,{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((b,h)=>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===b.id?"border-dashed border-blue-400 bg-[#f7f8fa]":""} ${u.includes(h)?"min-h-[300px] pb-6 ":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{onClick:()=>d(b.id),className:"flex-1 h-full py-4 cursor-pointer",children:i.jsx("h2",{className:"font-medium",children:b.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:()=>w(b),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(b.id),children:i.jsx(F,{icon:"lets-icons:trash-duotone-line"})}),i.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>f(h),children:i.jsx(F,{icon:u.includes(h)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(b==null?void 0:b.description)&&u.includes(h)&&i.jsx("p",{className:"mt-2 text-sm text-gray-600 text-gray-60",children:b==null?void 0:b.description}),u.includes(h)&&i.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:b.id,onDragOver:g,onDragEnd:()=>r(!1),onClick:()=>d(b.id),children:[i.jsx("hr",{className:"group-last:hidden"}),i.jsx("div",{className:"h-full mt-4 gap-y-6",children:i.jsx($a,{elementData:b.questionData,sectionId:b.id})})]})]})},b.id)),i.jsx("div",{className:"flex justify-center",children:i.jsxs("button",{type:"button",onClick:()=>t(),style:{color:(x==null?void 0:x.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]})})]})]})};function is({questionData:e,uploadUrl:n}){const{setFormData:o,addSection:s,setUploadUrl:a}=m.useContext(me);m.useEffect(()=>{e&&e.length>0&&o(e)},[e,o]),m.useEffect(()=>{a(n)},[n,a]);const t=m.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(es,{})})}const wi=[{key:"textFields",title:"Text Fields"},{key:"selectionFields",title:"Selection Fields"},{key:"dateAndTime",title:"Date & Time"},{key:"fileAndMedia",title:"File & Media"},{key:"layoutAndDisplay",title:"Layout & Display"},{key:"advancedData",title:"Advanced / Data"}],ns=()=>{const[e,n]=m.useState(""),{setIsDragging:o,addElement:s,selectedSection:a}=m.useContext(me),t=m.useCallback((f,w)=>{if(!a){he.toast.error("Please select a section to add an element.");return}f.dataTransfer.setData("properties",JSON.stringify(w)),f.dataTransfer.effectAllowed="move",o(!0)},[o,a]);function l(f){if(!a){he.toast.error("Please select a section to add an element.");return}const w={...f,id:ge.v4(),sectionId:a};s(w,a)}const r=ve("config")||{},d=r.elementColor,c=r.elementBgColor,u=r.elementBorderColor,p=aa.filter(f=>f.label.toLowerCase().includes(e.toLowerCase())),g=wi==null?void 0:wi.map(f=>({title:f.title,elements:p.filter(w=>{var x;return(x=sa[f.key])==null?void 0:x.includes(w.type)})})).filter(f=>f.elements.length>0);return i.jsxs("div",{className:"pt-4 pb-6",children:[i.jsx("div",{className:"px-5 mb-4",children:i.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:f=>n(f.target.value),name:"search",id:"search"})}),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:g==null?void 0:g.map((f,w)=>{var x;return i.jsxs("li",{children:[i.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:f.title}),i.jsx("ul",{className:"grid gap-y-[6px] mb-3",children:(x=f.elements)==null?void 0:x.map(b=>i.jsx("li",{onDragStart:h=>t(h,b),onDragEnd:()=>o(!1),onClick:()=>l(b),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
60
- active:opacity-50 element_class`,draggable:!0,children:i.jsxs("span",{className:"flex flex-row-reverse items-center justify-between w-full gap-x-3",children:[i.jsx("span",{style:{color:d},children:i.jsx(F,{icon:b.icon,iconClass:"w-4 h-4"})}),i.jsx("span",{style:{color:d},className:"text-sm font-medium leading-[0]",children:b.label})]})},b.type))})]},w)})})})]})},os=m.memo(ns),Se=({text:e="",isDisabled:n=!1,isLoading:o=!1,btnClass:s="bg-primary-500 text-white",icon:a="",iconPosition:t="left",iconClass:l="text-[20px]",loadingClass:r="",link:d="",div:c=!1,type:u="button",style:p,onClick:g})=>{const f=U("btn inline-flex justify-center",{"pointer-events-none":o,"opacity-40 cursor-not-allowed":n},s),w=()=>o?i.jsxs(i.Fragment,{children:[i.jsxs("svg",{className:`animate-spin -ml-1 mr-3 h-5 w-5 ${r}`,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Submitting..."]}):i.jsxs("span",{className:"flex items-center",children:[a&&t==="left"&&i.jsx("span",{className:`mr-[6px] ${l}`,children:i.jsx(F,{icon:a})}),e&&i.jsx("span",{children:e}),a&&t==="right"&&i.jsx("span",{className:`ml-[6px] ${l}`,children:i.jsx(F,{icon:a})})]});return c?i.jsx("div",{className:f,children:w()}):d?i.jsx(On.Link,{to:d,className:f,children:w()}):i.jsx("button",{disabled:n,type:u,className:f,"data-testid":"btn",onClick:g,style:p,children:w()})};function as(){return i.jsx("div",{children:i.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",fill:"#D5D7DA"}),i.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",stroke:"#E9EAEB"}),i.jsx("path",{d:"M22.5 14L14.5 22M14.5 14L22.5 22",stroke:"#414651",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})]})})}const ss=({isOpen:e,onClose:n})=>{const{formData:o,uploadUrl:s}=m.useContext(me);if(!e)return null;const a=ve("config");return i.jsxs("div",{className:"fixed inset-0 flex justify-center z-[999] cursor-default no-drag select-none w-screen h-screen pt-20 bg-[#F8F9FC]",children:[i.jsx("button",{type:"button",onClick:n,className:"absolute text-sm top-3 right-4","aria-label":"close",children:i.jsx(as,{})})," ",i.jsx("div",{className:"max-h-[80vh] overflow-y-auto h-max w-full max-w-[650px] min-w-0 border border-[#D5D9EB] rounded-lg bg-white form_submit",children:i.jsx(fn,{form_data:o,ignoreValidation:!0,config:a,uploadUrl:s})})]})};function ts(){return i.jsx("div",{children:i.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{width:"24",height:"24",rx:"6",fill:"currentColor"}),i.jsx("path",{d:"M14 16L10 12L14 8",stroke:"white",strokeWidth:"1.39167",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function ls({title:e,goBackUrl:n,onSubmit:o,onPublish:s,previewLoading:a,saveLoading:t,publishLoading:l,onTitleChange:r}){const{formData:d}=m.useContext(me),[c,u]=m.useState(!1),[p,g]=m.useState(!1),[f,w]=m.useState(e||""),x=ve("config");function b(){localStorage.setItem("formData",JSON.stringify(d)),o==null||o(d)}function h(){localStorage.setItem("formData",JSON.stringify(d)),s==null||s(d)}function y(){g(!1),r&&f!==e&&r(f.trim())}return i.jsxs("div",{className:"px-[30px] py-3 flex justify-between items-center bg-[#F9F9FB] top_bar",children:[i.jsxs("span",{className:"flex items-center gap-x-2",children:[n&&i.jsx("button",{type:"button",onClick:()=>n(),style:{color:(x==null?void 0:x.buttonColor)||"#333"},className:"flex items-center gap-x-3",children:i.jsx(ts,{})})," ",p?i.jsx("input",{type:"text",value:f,onChange:N=>w(N.target.value),onBlur:y,autoFocus:!0,className:"w-48 px-2 py-1 text-sm font-semibold outline-gray-100 input form_title"}):i.jsx("h1",{title:"Click to edit",className:"text-base font-semibold cursor-pointer form_title",onClick:()=>g(!0),children:f||"Untitled"})]}),c&&i.jsx(ss,{isOpen:c,onClose:()=>u(!1),element:void 0}),i.jsxs("div",{className:"flex justify-end text-xs gap-x-3",children:[i.jsx(Se,{onClick:()=>u(!0),text:"Preview",btnClass:"px-2 bg-transparent font-medium text-sm form_preview",icon:"solar:eye-bold-duotone",iconClass:"text-base",style:{color:(x==null?void 0:x.buttonColor)||"#333"},isDisabled:a,isLoading:a}),i.jsx(Se,{onClick:b,text:"Save",btnClass:"px-2 bg-transparent font-medium text-sm form_save__btn",icon:"lets-icons:save-duotone",iconClass:"text-base",style:{color:(x==null?void 0:x.buttonColor)||"#333"},isDisabled:t,isLoading:t}),i.jsx(Se,{onClick:h,text:"Publish",style:{background:(x==null?void 0:x.buttonColor)||"#333"},btnClass:"border-[#98A2B3] font-medium text-sm py-[8px] px-6 text-white rounded-lg form_publish__btn",isDisabled:l,isLoading:l})]})]})}const hn=({loadingClass:e})=>{const n=U("h-full w-full min-h-[300px] flex justify-center items-center",e);return m.useEffect(()=>{const o=ve("config"),s=(o==null?void 0:o.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",s)},[]),i.jsx("div",{className:n,children:i.jsx("span",{className:"loader"})})};function ds({onSubmit:e,questionData:n,title:o,goBackUrl:s,loading:a,onPublish:t,previewLoading:l,saveLoading:r,publishLoading:d,onTitleChange:c,uploadUrl:u}){return i.jsxs(Di,{children:[i.jsx(he.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),i.jsxs("div",{className:"w-full h-full bg-[#F8F9FC] flex flex-col",children:[i.jsx("div",{className:"border-b bg-white border-[#E4E7EC]",children:i.jsx(ls,{title:o,goBackUrl:s,onSubmit:e,onPublish:t,previewLoading:l,saveLoading:r,publishLoading:d,onTitleChange:c})}),i.jsxs("div",{className:"flex flex-1 ",children:[i.jsx("div",{children:i.jsx("div",{className:"w-[260px] h-[calc(100vh-64px)] border-r border-[#E4E7EC] bg-white ",children:i.jsx(os,{})})}),i.jsx("div",{className:"flex-1 h-full max-h-full z-[1]",children:a?i.jsx(hn,{loadingClass:"!w-full !h-[800px]"}):i.jsx(is,{questionData:n,uploadUrl:u})})]})]})]})}const rs=({onSubmit:e,questionData:n,isReadOnly:o,config:s={buttonColor:"#333"},title:a,loading:t,goBackUrl:l,onPublish:r,previewLoading:d,saveLoading:c,publishLoading:u,onTitleChange:p,uploadUrl:g})=>(m.useEffect(()=>{s&&un("config",s)},[s]),i.jsx(ds,{onSubmit:e,onPublish:r,questionData:n,isReadOnly:o,title:a,goBackUrl:l,loading:t,previewLoading:d,saveLoading:c,publishLoading:u,onTitleChange:p,uploadUrl:g})),Ae={required:"This field is required",email:"Invalid email format",url:"Invalid url format",minLength:e=>`Minimum length is ${e}`,maxLength:e=>`Maximum length is ${e}`,minAmount:e=>`Minimum amount is ${e}`,maxAmount:e=>`Maximum amount is ${e}`},us=e=>({textField:T.string().nullable(),longText:T.string().nullable(),numberField:T.number().nullable().transform(o=>isNaN(o)?null:o),amountField:T.number().nullable().transform(o=>isNaN(o)?null:o),selectField:T.string().nullable(),checkbox:T.mixed().nullable(),radio:T.mixed().nullable(),email:T.string().nullable().matches(/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/,Ae.email),date:T.date().typeError("Invalid date").nullable(),url:T.string().nullable().matches(/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/,Ae.url)})[e]||T.mixed().nullable(),cs=(e,n,o)=>n?e.type==="boolean"?e.oneOf([!0],o||Ae.required):e.required(o||Ae.required):e,ms=(e,{minLength:n,maxLength:o,minLengthMessage:s,maxLengthMessage:a})=>{let t=e;return n&&(t=t.min(n,s||Ae.minLength(n))),o&&(t=t.max(o,a||Ae.maxLength(o))),t},bs=(e,{minAmount:n,maxAmount:o,minAmountMessage:s,maxAmountMessage:a})=>{let t=e;return n&&(t=t.min(parseFloat(String(n)),s||Ae.minAmount(n))),o&&(t=t.max(parseFloat(String(o)),a||Ae.maxAmount(o))),t};function vs(e){const n={};return e.forEach(({questionData:o})=>{o==null||o.forEach(s=>{const{id:a,type:t,isRequired:l,requiredMessage:r}=s;let d=us(t);d=cs(d,l,r),t==="textField"||t==="longText"||t==="email"||t==="url"?d=ms(d,s):(t==="numberField"||t==="amountField")&&(d=bs(d,s)),n[a]=d})}),T.object().shape(n)}const Je=(e,n)=>{const o=pn[e.type],{answerData:s}=m.useContext(me),a=m.useMemo(()=>{var r;return(r=e==null?void 0:e.acceptedFiles)==null?void 0:r.map(d=>d.label).join(", ")},[e]),t=m.useMemo(()=>(e==null?void 0:e.visibilityDependentFields)||[],[e]),l=m.useMemo(()=>t.length?t.every(r=>{if(!e.isHidden)return!0;const d=s==null?void 0:s[r.id],c=r.fieldValue,u=d;switch(r.operator){case"equals":return String(c).toLowerCase()===String(u).toLowerCase();case"not_equals":return String(c).toLowerCase()!==String(u).toLowerCase();case"greater":return Number(u)>Number(c);case"less":return Number(u)<Number(c);case"contains":return String(u).toLowerCase().includes(String(c).toLowerCase());case"not_contains":return!String(u).toLowerCase().includes(String(c).toLowerCase());default:return!0}}):!0,[t,s,e]);return o?i.jsxs("div",{className:l?"":"invisible h-0",children:[i.jsxs("div",{className:"mb-1.5",children:[e.inputLabel&&i.jsxs("label",{className:"block text-sm font-medium input_label",children:[e.inputLabel," ",a&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",a==null?void 0:a.toLowerCase(),")"]})]}),e.description&&i.jsxs("small",{className:"block text-gray-400 mt-0.5 text-xs",children:[" ",e.description]})]}),i.jsx(o,{element:e,state:"edit",validationData:n})]}):null},Ye=(e,n)=>e!=null&&e.allowEdit?{...n,isReadOnly:!1}:n;function ps({form_data:e,options:n}){const o=(a,t)=>i.jsx(fi,{element:a,customClass:"p-0 min-h-[60px] border-none",children:t==null?void 0:t.map(l=>{var r,d,c;return i.jsxs(hi,{col:(r=l.gridPosition)==null?void 0:r.col,customClass:"p-0",children:[Je(l,Ye(l,n)),((c=(d=n==null?void 0:n.errors)==null?void 0:d[l.id])==null?void 0:c.message)&&i.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[l.id].message})]},l.id)})},a.id),s=a=>{var t,l;return i.jsxs("div",{className:U("group relative grid gap-y-[6px]",a.elementClass),children:[Je(a,Ye(a,n)),((l=(t=n==null?void 0:n.errors)==null?void 0:t[a.id])==null?void 0:l.message)&&i.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[a.id].message})]},a.id)};return i.jsx("div",{className:"grid gap-y-10",children:e==null?void 0:e.map(a=>{var l,r;const t=new Map;return(l=a.questionData)==null||l.forEach(d=>{d.gridId&&(t.has(d.gridId)||t.set(d.gridId,[]),t.get(d.gridId).push(d))}),i.jsxs("div",{className:"pb-6 section_box",children:[(a.title||a.description)&&i.jsxs("div",{className:"py-4 border-b border-gray-100 mb-7 section_box__title",children:[a.title&&i.jsx("h2",{className:"text-lg font-semibold mb-[4px]",children:a.title}),a.description&&i.jsx("p",{className:"text-sm",children:a.description})]}),i.jsx("div",{className:"grid gap-y-6 section_box__content",children:(r=a.questionData)==null?void 0:r.map(d=>d.gridId?null:d.type==="grid"?o(d,t.get(d.id)||[]):s(d))})]},a.id)})})}function gs({form_data:e,options:n,current:o}){var s;return i.jsx("div",{className:"grid gap-y-3 multi_section__content",children:(s=e[o].questionData)==null?void 0:s.map(a=>{var t,l;if(a.type==="grid"){const r=e[o].questionData.filter(d=>d.gridId===a.id);return i.jsx(fi,{element:a,customClass:"p-0 min-h-[60px] border-none",children:r==null?void 0:r.map(d=>{var c,u,p;return i.jsxs(hi,{col:(c=d.gridPosition)==null?void 0:c.col,customClass:"p-0",children:[Je(d,Ye(d,n)),i.jsx("div",{className:"mt-1 text-xs text-red-600",children:(p=(u=n==null?void 0:n.errors)==null?void 0:u[d.id])==null?void 0:p.message})]},d.id)})},a.id)}return a.gridId?null:i.jsxs("div",{className:U("group relative grid gap-y-[6px]",a.elementClass),children:[Je(a,Ye(a,n)),i.jsx("div",{className:"mt-1 text-xs text-red-600",children:(l=(t=n==null?void 0:n.errors)==null?void 0:t[a.id])==null?void 0:l.message})]},a.id)})})}function hs(e){return e.reduce((n,o)=>(n[o.id]=o.value,n),{})}const fs=({form_data:e,answerData:n=[],ignoreValidation:o=!1,onSubmitData:s,onGetValues:a,isReadOnly:t=!1,renderType:l="multi",children:r,hideFooter:d=!1,uploadUrl:c})=>{var ce,ue,ie,G,I,oe,te,ne;const{setAnswerData:u,setUploadUrl:p}=m.useContext(me),[g,f]=m.useState(0),w=m.useMemo(()=>e.filter(ae=>!ae.disabled),[e]),x=(ce=w==null?void 0:w.length)!=null?ce:0,b=ve("config"),h=m.useMemo(()=>vs(w),[w]),y=ye.useForm({resolver:mi(h),mode:"onSubmit",defaultValues:{}}),{register:N,setValue:S,control:A,handleSubmit:k,reset:_,getValues:O,watch:$,formState:{errors:V,isSubmitting:J},trigger:C,setError:E,clearErrors:L}=y,B=ye.useWatch({control:A}),K=m.useMemo(()=>B,[JSON.stringify(B)]),Y=m.useCallback(ae=>{a&&a(ae)},[a]);m.useEffect(()=>{p(c)},[p,c]),m.useEffect(()=>{if(!(w!=null&&w.length)||!a)return;const ae=w.flatMap(we=>{var fe;return(fe=we.questionData)==null?void 0:fe.map(ke=>({id:ke.id,value:K[ke.id],sectionId:we.id,type:ke.type}))});Y(ae),u(K)},[K,w,Y,a,u]),m.useEffect(()=>{n!=null&&n.length&&_(hs(n))},[n,_]);const P=m.useCallback(ae=>{const we=w.flatMap(fe=>{var ke;return(ke=fe.questionData)==null?void 0:ke.map(Ne=>({id:Ne.id,value:ae[Ne.id],sectionId:fe.id,type:Ne.type}))});Object.keys(V).length>0||s==null||s(we)},[V,w,s]),D=m.useCallback(async()=>{var ae,we;if(!o){const fe=(we=(ae=w==null?void 0:w[g])==null?void 0:ae.questionData)==null?void 0:we.map(Ne=>Ne.id);if(!await C(fe))return}f(fe=>fe+1)},[g,w,o,C]),W=m.useCallback(()=>{f(ae=>ae-1)},[]),X=m.useMemo(()=>({register:N,setValue:S,watch:$,errors:V,trigger:C,isSubmitting:J,isReadOnly:t,getValues:O,setError:E,clearErrors:L}),[N,S,$,V,C,J,t,O,E,L]);return i.jsxs(ye.FormProvider,{...y,children:[i.jsx(he.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),i.jsxs("form",{onSubmit:k(P),className:"container h-full mx-auto",children:[i.jsx("div",{className:"relative flex flex-col w-full py-4 gap-y-12",children:i.jsxs("div",{className:"multi_section__box",children:[l==="multi"&&(((ue=w==null?void 0:w[g])==null?void 0:ue.title)||((ie=w==null?void 0:w[g])==null?void 0:ie.description))&&i.jsxs("div",{className:"py-4 mb-4 border-b border-gray-100 multi_section__title",children:[((G=w[g])==null?void 0:G.title)&&i.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:(I=w[g])==null?void 0:I.title}),((oe=w[g])==null?void 0:oe.description)&&i.jsx("p",{className:"text-sm",children:(te=w[g])==null?void 0:te.description})]}),l==="multi"?i.jsx(gs,{form_data:w,options:X,current:g}):i.jsx(ps,{form_data:w,options:X})]},(ne=w==null?void 0:w[g])==null?void 0:ne.id)}),!d&&i.jsx("footer",{className:"flex items-center justify-end gap-4 footer",children:l==="multi"?i.jsxs(i.Fragment,{children:[g>0&&i.jsx(Se,{type:"button",text:"Back",onClick:W,btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-gray-200 rounded-lg"}),g<x-1?i.jsx(Se,{type:"button",text:"Continue",onClick:D,style:{background:(b==null?void 0:b.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg continue_btn"}):!o&&(r!=null?r:i.jsx(Se,{isDisabled:J||Object.keys(V).length>0,isLoading:J,type:"submit",text:"Submit",style:{background:(b==null?void 0:b.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))]}):!o&&(r!=null?r:i.jsx(Se,{isDisabled:J||Object.keys(V).length>0,isLoading:J,type:"submit",text:"Submit",style:{background:(b==null?void 0:b.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))})]})]})},xs=m.memo(fs);function fn({answerData:e,form_data:n,ignoreValidation:o,onSubmit:s,isReadOnly:a=!1,loading:t=!1,config:l={buttonColor:"#333"},renderType:r,children:d,hideFooter:c,onGetValues:u,uploadUrl:p}){m.useEffect(()=>{l&&un("config",l)},[l]);const g=m.useCallback(f=>{u&&u(f)},[u]);return t?i.jsx(hn,{}):n?i.jsxs("div",{id:"form",className:"w-full h-full",children:[i.jsx("div",{id:"root-portal"}),i.jsx(Di,{children:i.jsx(xs,{form_data:n,answerData:e,ignoreValidation:o,onSubmitData:s,isReadOnly:a,renderType:r,hideFooter:c,onGetValues:g,uploadUrl:p,children:d})})]}):i.jsx("div",{children:i.jsx("p",{className:"p-6 text-sm text-gray-400",children:"Error: No form data available."})})}de.FormBuilder=rs,de.FormViewer=fn,Object.defineProperty(de,Symbol.toStringTag,{value:"Module"})});
60
+ active:opacity-50 element_class`,draggable:!0,children:i.jsxs("span",{className:"flex flex-row-reverse items-center justify-between w-full gap-x-3",children:[i.jsx("span",{style:{color:d},children:i.jsx(F,{icon:b.icon,iconClass:"w-4 h-4"})}),i.jsx("span",{style:{color:d},className:"text-sm font-medium leading-[0]",children:b.label})]})},b.type))})]},w)})})})]})},os=m.memo(ns),Se=({text:e="",isDisabled:n=!1,isLoading:o=!1,btnClass:s="bg-primary-500 text-white",icon:a="",iconPosition:t="left",iconClass:l="text-[20px]",loadingClass:r="",link:d="",div:c=!1,type:u="button",style:p,onClick:g})=>{const f=U("btn inline-flex justify-center",{"pointer-events-none":o,"opacity-40 cursor-not-allowed":n},s),w=()=>o?i.jsxs(i.Fragment,{children:[i.jsxs("svg",{className:`animate-spin -ml-1 mr-3 h-5 w-5 ${r}`,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Submitting..."]}):i.jsxs("span",{className:"flex items-center",children:[a&&t==="left"&&i.jsx("span",{className:`mr-[6px] ${l}`,children:i.jsx(F,{icon:a})}),e&&i.jsx("span",{children:e}),a&&t==="right"&&i.jsx("span",{className:`ml-[6px] ${l}`,children:i.jsx(F,{icon:a})})]});return c?i.jsx("div",{className:f,children:w()}):d?i.jsx(On.Link,{to:d,className:f,children:w()}):i.jsx("button",{disabled:n,type:u,className:f,"data-testid":"btn",onClick:g,style:p,children:w()})};function as(){return i.jsx("div",{children:i.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",fill:"#D5D7DA"}),i.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",stroke:"#E9EAEB"}),i.jsx("path",{d:"M22.5 14L14.5 22M14.5 14L22.5 22",stroke:"#414651",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})]})})}const ss=({isOpen:e,onClose:n})=>{const{formData:o,uploadUrl:s}=m.useContext(me);if(!e)return null;const a=ve("config");return i.jsxs("div",{className:"fixed inset-0 flex justify-center z-[999] cursor-default no-drag select-none w-screen h-screen pt-20 bg-[#F8F9FC]",children:[i.jsx("button",{type:"button",onClick:n,className:"absolute text-sm top-3 right-4","aria-label":"close",children:i.jsx(as,{})})," ",i.jsx("div",{className:"max-h-[80vh] overflow-y-auto h-max w-full max-w-[650px] min-w-0 border border-[#D5D9EB] rounded-lg bg-white form_submit",children:i.jsx(fn,{form_data:o,ignoreValidation:!0,config:a,uploadUrl:s})})]})};function ts(){return i.jsx("div",{children:i.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[i.jsx("rect",{width:"24",height:"24",rx:"6",fill:"currentColor"}),i.jsx("path",{d:"M14 16L10 12L14 8",stroke:"white",strokeWidth:"1.39167",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function ls({title:e,goBackUrl:n,onSubmit:o,onPublish:s,previewLoading:a,saveLoading:t,publishLoading:l,onTitleChange:r}){const{formData:d}=m.useContext(me),[c,u]=m.useState(!1),[p,g]=m.useState(!1),[f,w]=m.useState(e||""),x=ve("config");function b(){localStorage.setItem("formData",JSON.stringify(d)),o==null||o(d)}function h(){localStorage.setItem("formData",JSON.stringify(d)),s==null||s(d)}function y(){g(!1),r&&f!==e&&r(f.trim())}return i.jsxs("div",{className:"px-[30px] py-3 flex justify-between items-center bg-[#F9F9FB] top_bar",children:[i.jsxs("span",{className:"flex items-center gap-x-2",children:[n&&i.jsx("button",{type:"button",onClick:()=>n(),style:{color:(x==null?void 0:x.buttonColor)||"#333"},className:"flex items-center gap-x-3",children:i.jsx(ts,{})})," ",p?i.jsx("input",{type:"text",value:f,onChange:N=>w(N.target.value),onBlur:y,autoFocus:!0,className:"w-48 px-2 py-1 text-sm font-semibold outline-gray-100 input form_title"}):i.jsx("h1",{title:"Click to edit",className:"text-base font-semibold cursor-pointer form_title",onClick:()=>g(!0),children:f||"Untitled"})]}),c&&i.jsx(ss,{isOpen:c,onClose:()=>u(!1),element:void 0}),i.jsxs("div",{className:"flex justify-end text-xs gap-x-3",children:[i.jsx(Se,{onClick:()=>u(!0),text:"Preview",btnClass:"px-2 bg-transparent font-medium text-sm form_preview",icon:"solar:eye-bold-duotone",iconClass:"text-base",style:{color:(x==null?void 0:x.buttonColor)||"#333"},isDisabled:a,isLoading:a}),i.jsx(Se,{onClick:b,text:"Save",btnClass:"px-2 bg-transparent font-medium text-sm form_save__btn",icon:"lets-icons:save-duotone",iconClass:"text-base",style:{color:(x==null?void 0:x.buttonColor)||"#333"},isDisabled:t,isLoading:t}),i.jsx(Se,{onClick:h,text:"Publish",style:{background:(x==null?void 0:x.buttonColor)||"#333"},btnClass:"border-[#98A2B3] font-medium text-sm py-[8px] px-6 text-white rounded-lg form_publish__btn",isDisabled:l,isLoading:l})]})]})}const hn=({loadingClass:e})=>{const n=U("h-full w-full min-h-[300px] flex justify-center items-center",e);return m.useEffect(()=>{const o=ve("config"),s=(o==null?void 0:o.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",s)},[]),i.jsx("div",{className:n,children:i.jsx("span",{className:"loader"})})};function ds({onSubmit:e,questionData:n,title:o,goBackUrl:s,loading:a,onPublish:t,previewLoading:l,saveLoading:r,publishLoading:d,onTitleChange:c,uploadUrl:u}){return i.jsxs(Di,{children:[i.jsx(he.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),i.jsxs("div",{className:"w-full h-full bg-[#F8F9FC] flex flex-col",children:[i.jsx("div",{className:"border-b bg-white border-[#E4E7EC]",children:i.jsx(ls,{title:o,goBackUrl:s,onSubmit:e,onPublish:t,previewLoading:l,saveLoading:r,publishLoading:d,onTitleChange:c})}),i.jsxs("div",{className:"flex flex-1 ",children:[i.jsx("div",{children:i.jsx("div",{className:"w-[260px] h-[calc(100vh-64px)] border-r border-[#E4E7EC] bg-white ",children:i.jsx(os,{})})}),i.jsx("div",{className:"flex-1 h-full max-h-full z-[1]",children:a?i.jsx(hn,{loadingClass:"!w-full !h-[800px]"}):i.jsx(is,{questionData:n,uploadUrl:u})})]})]})]})}const rs=({onSubmit:e,questionData:n,isReadOnly:o,config:s={buttonColor:"#333"},title:a,loading:t,goBackUrl:l,onPublish:r,previewLoading:d,saveLoading:c,publishLoading:u,onTitleChange:p,uploadUrl:g})=>(m.useEffect(()=>{s&&un("config",s)},[s]),i.jsx(ds,{onSubmit:e,onPublish:r,questionData:n,isReadOnly:o,title:a,goBackUrl:l,loading:t,previewLoading:d,saveLoading:c,publishLoading:u,onTitleChange:p,uploadUrl:g})),Ae={required:"This field is required",email:"Invalid email format",url:"Invalid url format",minLength:e=>`Minimum length is ${e}`,maxLength:e=>`Maximum length is ${e}`,minAmount:e=>`Minimum amount is ${e}`,maxAmount:e=>`Maximum amount is ${e}`},us=e=>({textField:T.string().nullable(),longText:T.string().nullable(),numberField:T.number().nullable().transform(o=>isNaN(o)?null:o),amountField:T.number().nullable().transform(o=>isNaN(o)?null:o),selectField:T.string().nullable(),checkbox:T.mixed().nullable(),radio:T.mixed().nullable(),email:T.string().nullable().test("email-format",Ae.email,o=>!o||o.trim()===""?!0:/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/.test(o)),date:T.date().typeError("Invalid date").nullable(),url:T.string().nullable().test("url-format",Ae.url,o=>!o||o.trim()===""?!0:/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/.test(o))})[e]||T.mixed().nullable(),cs=(e,n,o)=>n?e.type==="boolean"?e.oneOf([!0],o||Ae.required):e.required(o||Ae.required):e,ms=(e,{minLength:n,maxLength:o,minLengthMessage:s,maxLengthMessage:a})=>{let t=e;return n&&(t=t.min(n,s||Ae.minLength(n))),o&&(t=t.max(o,a||Ae.maxLength(o))),t},bs=(e,{minAmount:n,maxAmount:o,minAmountMessage:s,maxAmountMessage:a})=>{let t=e;return n&&(t=t.min(parseFloat(String(n)),s||Ae.minAmount(n))),o&&(t=t.max(parseFloat(String(o)),a||Ae.maxAmount(o))),t};function vs(e){const n={};return e.forEach(({questionData:o})=>{o==null||o.forEach(s=>{const{id:a,type:t,isRequired:l,requiredMessage:r}=s;let d=us(t);d=cs(d,l,r),t==="textField"||t==="longText"||t==="email"||t==="url"?d=ms(d,s):(t==="numberField"||t==="amountField")&&(d=bs(d,s)),n[a]=d})}),T.object().shape(n)}const Je=(e,n)=>{const o=pn[e.type],{answerData:s}=m.useContext(me),a=m.useMemo(()=>{var r;return(r=e==null?void 0:e.acceptedFiles)==null?void 0:r.map(d=>d.label).join(", ")},[e]),t=m.useMemo(()=>(e==null?void 0:e.visibilityDependentFields)||[],[e]),l=m.useMemo(()=>t.length?t.every(r=>{if(!e.isHidden)return!0;const d=s==null?void 0:s[r.id],c=r.fieldValue,u=d;switch(r.operator){case"equals":return String(c).toLowerCase()===String(u).toLowerCase();case"not_equals":return String(c).toLowerCase()!==String(u).toLowerCase();case"greater":return Number(u)>Number(c);case"less":return Number(u)<Number(c);case"contains":return String(u).toLowerCase().includes(String(c).toLowerCase());case"not_contains":return!String(u).toLowerCase().includes(String(c).toLowerCase());default:return!0}}):!0,[t,s,e]);return o?i.jsxs("div",{className:l?"":"invisible h-0",children:[i.jsxs("div",{className:"mb-1.5",children:[e.inputLabel&&i.jsxs("label",{className:"block text-sm font-medium input_label",children:[e.inputLabel," ",a&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",a==null?void 0:a.toLowerCase(),")"]})]}),e.description&&i.jsxs("small",{className:"block text-gray-400 mt-0.5 text-xs",children:[" ",e.description]})]}),i.jsx(o,{element:e,state:"edit",validationData:n})]}):null},Ye=(e,n)=>e!=null&&e.allowEdit?{...n,isReadOnly:!1}:n;function ps({form_data:e,options:n}){const o=(a,t)=>i.jsx(fi,{element:a,customClass:"p-0 min-h-[60px] border-none",children:t==null?void 0:t.map(l=>{var r,d,c;return i.jsxs(hi,{col:(r=l.gridPosition)==null?void 0:r.col,customClass:"p-0",children:[Je(l,Ye(l,n)),((c=(d=n==null?void 0:n.errors)==null?void 0:d[l.id])==null?void 0:c.message)&&i.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[l.id].message})]},l.id)})},a.id),s=a=>{var t,l;return i.jsxs("div",{className:U("group relative grid gap-y-[6px]",a.elementClass),children:[Je(a,Ye(a,n)),((l=(t=n==null?void 0:n.errors)==null?void 0:t[a.id])==null?void 0:l.message)&&i.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[a.id].message})]},a.id)};return i.jsx("div",{className:"grid gap-y-10",children:e==null?void 0:e.map(a=>{var l,r;const t=new Map;return(l=a.questionData)==null||l.forEach(d=>{d.gridId&&(t.has(d.gridId)||t.set(d.gridId,[]),t.get(d.gridId).push(d))}),i.jsxs("div",{className:"pb-6 section_box",children:[(a.title||a.description)&&i.jsxs("div",{className:"py-4 border-b border-gray-100 mb-7 section_box__title",children:[a.title&&i.jsx("h2",{className:"text-lg font-semibold mb-[4px]",children:a.title}),a.description&&i.jsx("p",{className:"text-sm",children:a.description})]}),i.jsx("div",{className:"grid gap-y-6 section_box__content",children:(r=a.questionData)==null?void 0:r.map(d=>d.gridId?null:d.type==="grid"?o(d,t.get(d.id)||[]):s(d))})]},a.id)})})}function gs({form_data:e,options:n,current:o}){var s;return i.jsx("div",{className:"grid gap-y-3 multi_section__content",children:(s=e[o].questionData)==null?void 0:s.map(a=>{var t,l;if(a.type==="grid"){const r=e[o].questionData.filter(d=>d.gridId===a.id);return i.jsx(fi,{element:a,customClass:"p-0 min-h-[60px] border-none",children:r==null?void 0:r.map(d=>{var c,u,p;return i.jsxs(hi,{col:(c=d.gridPosition)==null?void 0:c.col,customClass:"p-0",children:[Je(d,Ye(d,n)),i.jsx("div",{className:"mt-1 text-xs text-red-600",children:(p=(u=n==null?void 0:n.errors)==null?void 0:u[d.id])==null?void 0:p.message})]},d.id)})},a.id)}return a.gridId?null:i.jsxs("div",{className:U("group relative grid gap-y-[6px]",a.elementClass),children:[Je(a,Ye(a,n)),i.jsx("div",{className:"mt-1 text-xs text-red-600",children:(l=(t=n==null?void 0:n.errors)==null?void 0:t[a.id])==null?void 0:l.message})]},a.id)})})}function hs(e){return e.reduce((n,o)=>(n[o.id]=o.value,n),{})}const fs=({form_data:e,answerData:n=[],ignoreValidation:o=!1,onSubmitData:s,onGetValues:a,isReadOnly:t=!1,renderType:l="multi",children:r,hideFooter:d=!1,uploadUrl:c})=>{var ce,ue,ie,G,I,oe,te,ne;const{setAnswerData:u,setUploadUrl:p}=m.useContext(me),[g,f]=m.useState(0),w=m.useMemo(()=>e.filter(ae=>!ae.disabled),[e]),x=(ce=w==null?void 0:w.length)!=null?ce:0,b=ve("config"),h=m.useMemo(()=>vs(w),[w]),y=ye.useForm({resolver:mi(h),mode:"onSubmit",defaultValues:{}}),{register:N,setValue:S,control:A,handleSubmit:k,reset:_,getValues:O,watch:$,formState:{errors:V,isSubmitting:J},trigger:C,setError:E,clearErrors:L}=y,B=ye.useWatch({control:A}),K=m.useMemo(()=>B,[JSON.stringify(B)]),Y=m.useCallback(ae=>{a&&a(ae)},[a]);m.useEffect(()=>{p(c)},[p,c]),m.useEffect(()=>{if(!(w!=null&&w.length)||!a)return;const ae=w.flatMap(we=>{var fe;return(fe=we.questionData)==null?void 0:fe.map(ke=>({id:ke.id,value:K[ke.id],sectionId:we.id,type:ke.type}))});Y(ae),u(K)},[K,w,Y,a,u]),m.useEffect(()=>{n!=null&&n.length&&_(hs(n))},[n,_]);const P=m.useCallback(ae=>{const we=w.flatMap(fe=>{var ke;return(ke=fe.questionData)==null?void 0:ke.map(Ne=>({id:Ne.id,value:ae[Ne.id],sectionId:fe.id,type:Ne.type}))});Object.keys(V).length>0||s==null||s(we)},[V,w,s]),D=m.useCallback(async()=>{var ae,we;if(!o){const fe=(we=(ae=w==null?void 0:w[g])==null?void 0:ae.questionData)==null?void 0:we.map(Ne=>Ne.id);if(!await C(fe))return}f(fe=>fe+1)},[g,w,o,C]),W=m.useCallback(()=>{f(ae=>ae-1)},[]),X=m.useMemo(()=>({register:N,setValue:S,watch:$,errors:V,trigger:C,isSubmitting:J,isReadOnly:t,getValues:O,setError:E,clearErrors:L}),[N,S,$,V,C,J,t,O,E,L]);return i.jsxs(ye.FormProvider,{...y,children:[i.jsx(he.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),i.jsxs("form",{onSubmit:k(P),className:"container h-full mx-auto",children:[i.jsx("div",{className:"relative flex flex-col w-full py-4 gap-y-12",children:i.jsxs("div",{className:"multi_section__box",children:[l==="multi"&&(((ue=w==null?void 0:w[g])==null?void 0:ue.title)||((ie=w==null?void 0:w[g])==null?void 0:ie.description))&&i.jsxs("div",{className:"py-4 mb-4 border-b border-gray-100 multi_section__title",children:[((G=w[g])==null?void 0:G.title)&&i.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:(I=w[g])==null?void 0:I.title}),((oe=w[g])==null?void 0:oe.description)&&i.jsx("p",{className:"text-sm",children:(te=w[g])==null?void 0:te.description})]}),l==="multi"?i.jsx(gs,{form_data:w,options:X,current:g}):i.jsx(ps,{form_data:w,options:X})]},(ne=w==null?void 0:w[g])==null?void 0:ne.id)}),!d&&i.jsx("footer",{className:"flex items-center justify-end gap-4 footer",children:l==="multi"?i.jsxs(i.Fragment,{children:[g>0&&i.jsx(Se,{type:"button",text:"Back",onClick:W,btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-gray-200 rounded-lg"}),g<x-1?i.jsx(Se,{type:"button",text:"Continue",onClick:D,style:{background:(b==null?void 0:b.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg continue_btn"}):!o&&(r!=null?r:i.jsx(Se,{isDisabled:J||Object.keys(V).length>0,isLoading:J,type:"submit",text:"Submit",style:{background:(b==null?void 0:b.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))]}):!o&&(r!=null?r:i.jsx(Se,{isDisabled:J||Object.keys(V).length>0,isLoading:J,type:"submit",text:"Submit",style:{background:(b==null?void 0:b.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))})]})]})},xs=m.memo(fs);function fn({answerData:e,form_data:n,ignoreValidation:o,onSubmit:s,isReadOnly:a=!1,loading:t=!1,config:l={buttonColor:"#333"},renderType:r,children:d,hideFooter:c,onGetValues:u,uploadUrl:p}){m.useEffect(()=>{l&&un("config",l)},[l]);const g=m.useCallback(f=>{u&&u(f)},[u]);return t?i.jsx(hn,{}):n?i.jsxs("div",{id:"form",className:"w-full h-full",children:[i.jsx("div",{id:"root-portal"}),i.jsx(Di,{children:i.jsx(xs,{form_data:n,answerData:e,ignoreValidation:o,onSubmitData:s,isReadOnly:a,renderType:r,hideFooter:c,onGetValues:g,uploadUrl:p,children:d})})]}):i.jsx("div",{children:i.jsx("p",{className:"p-6 text-sm text-gray-400",children:"Error: No form data available."})})}de.FormBuilder=rs,de.FormViewer=fn,Object.defineProperty(de,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arudovwen/form-builder-react",
3
- "version": "1.4.36",
3
+ "version": "1.4.37",
4
4
  "description": "A React-based form builder component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/form-builder.umd.js",