@arudovwen/form-builder-react 1.4.28 → 1.4.29

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.
@@ -5404,7 +5404,7 @@ function Ms({
5404
5404
  []
5405
5405
  );
5406
5406
  return /* @__PURE__ */ n.jsxs("div", { className: "mt-3 rounded", ref: u, children: [
5407
- /* @__PURE__ */ n.jsx("div", { className: "flex justify-end", children: s.length > 0 && !o && /* @__PURE__ */ n.jsx(
5407
+ /* @__PURE__ */ n.jsx("div", { className: "flex justify-end", children: !o && /* @__PURE__ */ n.jsx(
5408
5408
  "button",
5409
5409
  {
5410
5410
  onClick: b,
@@ -5468,23 +5468,28 @@ function Ts({
5468
5468
  element: i,
5469
5469
  validationData: e
5470
5470
  }) {
5471
- const { register: o = () => ({}), setValue: s, watch: a } = e || {}, l = a && a(i == null ? void 0 : i.id) || [];
5471
+ const {
5472
+ register: o = () => ({}),
5473
+ setValue: s,
5474
+ watch: a,
5475
+ isReadOnly: l
5476
+ } = e || {}, d = a && a(i == null ? void 0 : i.id) || [];
5472
5477
  O(() => {
5473
5478
  o(i.id);
5474
5479
  }, [i.id, o]);
5475
- const d = z(
5476
- (c) => {
5477
- s == null || s(i.id, c);
5480
+ const c = z(
5481
+ (u) => {
5482
+ s == null || s(i.id, u);
5478
5483
  },
5479
5484
  [i.id, s]
5480
5485
  );
5481
5486
  return /* @__PURE__ */ n.jsx(
5482
5487
  Ms,
5483
5488
  {
5484
- value: l,
5485
- onChange: d,
5489
+ value: d,
5490
+ onChange: c,
5486
5491
  columns: i == null ? void 0 : i.dataColumns,
5487
- isReadOnly: i == null ? void 0 : i.isReadOnly
5492
+ isReadOnly: l
5488
5493
  }
5489
5494
  );
5490
5495
  }
@@ -45,7 +45,7 @@ React keys must be passed directly to JSX without using spread:
45
45
  "data": [
46
46
  { "name": "Document Name", "id": "documentMainId", ...restObject },
47
47
  ]
48
- }`})})]})})}),xa=()=>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 ya(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const bi=["text","number","boolean"],un=["equals","not_equals","contains","not_contains"],ka=["greater","less"];function wa({register:e,setValue:n,trigger:o,watch:s,id:a}){const{formData:t}=m.useContext(de),l=s("visibilityDependentFields")||[],r=m.useMemo(()=>{var c;return(c=ya(t).filter(u=>u.id!==a))==null?void 0:c.map(u=>{const h=l.find(v=>v.id===u.id);return{id:u.id,value:u.id,label:u.inputLabel,sectionId:u.sectionId,fieldType:(h==null?void 0:h.fieldType)||"text",operator:(h==null?void 0:h.operator)||"equals",fieldValue:(h==null?void 0:h.fieldValue)!==void 0?h.fieldValue:""}})},[t,l,a]),d=(c,u,h)=>{const v=l==null?void 0:l.map((p,A)=>A===c?{...p,[u]:h}:p);n("visibilityDependentFields",v)};return i.jsxs("div",{className:"visibility-editor",children:[i.jsx("label",{className:"label",children:"Select Dependent Fields"}),i.jsx(ri,{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 h,v;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:c.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(D.Listbox,{value:c.fieldType,onChange:p=>d(u,"fieldType",p),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(D.Listbox.Button,{className:"listbox-button",children:c.fieldType}),i.jsx(D.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(D.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:bi==null?void 0:bi.map(p=>i.jsx(D.Listbox.Option,{value:p,className:"listbox-option",children:p},p))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(D.Listbox,{value:c.operator,onChange:p=>d(u,"operator",p),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(D.Listbox.Button,{className:"listbox-button",children:c.operator.replace("_"," ")}),i.jsx(D.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(D.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(h=c.fieldType==="number"?[...un,...ka]:un)==null?void 0:h.map(p=>i.jsx(D.Listbox.Option,{value:p,className:"listbox-option",children:p.replace("_"," ")},p))})})]})})}),c.fieldType!=="boolean"?i.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:p=>d(u,"fieldValue",p.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(D.Listbox,{value:(v=c.fieldValue)!=null?v:"",onChange:p=>d(u,"fieldValue",p),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(D.Listbox.Button,{className:"listbox-button",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),i.jsx(D.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(D.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(D.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(D.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},c.id)})})]})}const Aa=E.object().shape({inputLabel:E.string().nullable(),placeholder:E.string().nullable(),description:E.string().nullable(),isReadOnly:E.boolean(),isDisabled:E.boolean(),isRequired:E.boolean(),requiredMessage:E.string().nullable(),minLengthMessage:E.string().nullable(),maxLengthMessage:E.string().nullable(),maxLength:E.number().typeError("Expecting a number").nullable(),minLength:E.number().typeError("Expecting a number").nullable(),inputType:E.string().nullable(),maxAmountMessage:E.string().nullable(),maxAmount:E.string().nullable(),options:E.array().of(E.object().shape({label:E.string().nullable(),value:E.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),options1:E.array().of(E.object().shape({label:E.string().nullable(),value:E.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),prefix:E.string().nullable(),url:E.string().nullable(),method:E.string().nullable(),denominators:E.mixed().nullable(),responseType:E.string().nullable(),minAmount:E.string().nullable(),heading:E.string().nullable(),minAmountMessage:E.string().nullable(),columns:E.number().nullable(),value:E.mixed().nullable(),customClass:E.string().nullable(),elementClass:E.string().nullable(),apiUrl:E.string().nullable(),selectType:E.string().default("list"),dateType:E.string().default("basic"),validationUrl:E.string(),signatureLink:E.string(),minDate:E.string().nullable(),maxDate:E.string().nullable(),canHaveDateRange:E.boolean(),allowYearPicker:E.boolean(),isHidden:E.boolean(),visibilityDependentFields:E.array().nullable(),isMultiple:E.boolean(),acceptedFiles:E.array(),showState:E.boolean()}),Sa=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],_a=({isOpen:e,onClose:n,element:o})=>{const s=Sa.filter(R=>!We.includes(o.inputType)||R.key!=="validation"),{updateElement:a}=m.useContext(de),[t,l]=m.useState("basic"),[r,d]=m.useState(!1),[c,u]=m.useState("manual"),h=ue("config"),{register:v,handleSubmit:p,control:A,setValue:g,watch:f,trigger:x,formState:{errors:y,isSubmitting:k,isValid:_},reset:S}=ke.useForm({resolver:ci(Aa),defaultValues:{...o,options:o.options||[]}}),w=f(),{fields:j,append:L,remove:Y}=ke.useFieldArray({control:A,name:"options"}),{fields:W,append:K,remove:M}=ke.useFieldArray({control:A,name:"options1"}),{fields:T,append:B,remove:O}=ke.useFieldArray({control:A,name:"dataColumns"});m.useEffect(()=>{e||S()},[e,S]);const Q=R=>{a(R,o.sectionId),n()},oe={headers:{Authorization:`Bearer ${ue("token")}`}},I=m.useCallback(async()=>{var R,H,te;if(!w.apiUrl||!/^https?:\/\//.test(w.apiUrl)){me.toast.info("Please provide a valid API URL");return}try{d(!0);const{status:Z,data:X}=await Ne.get(w.apiUrl,oe);if(Z!==200||!X){me.toast.error("Unexpected response from server.");return}const le=X.data||X.record||X.result;if(!Array.isArray(le)){me.toast.error("Expected an array in response (data, record, or result).");return}((R=o.type)==null?void 0:R.toLowerCase())==="datagrid"?g("dataColumns",le):g("options",le)}catch(Z){const X=((te=(H=Z==null?void 0:Z.response)==null?void 0:H.data)==null?void 0:te.message)||(Z==null?void 0:Z.message)||"Unable to load options";me.toast.error(X)}finally{d(!1)}},[o.type,g,w.apiUrl]),se=["manual","api","sheet"];function be(){c==="api"&&I()}const pe=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:se==null?void 0:se.map(R=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:H=>u(H.target.value),value:R})," ",i.jsxs("span",{children:[R," options"]})]},R))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(G,{label:"Load Options from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]}),i.jsx("button",{onClick:be,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(ga,{})]}),c==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(rn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:g,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),j==null?void 0:j.map((R,H)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Label",name:`options.${H}.label`,register:v,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Value",name:`options.${H}.value`,register:v,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("button",{disabled:j.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>Y(H),children:i.jsx(V,{icon:"iconamoon:sign-times-fill"})})]},R.id))," ",i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>L({label:"",value:"",id:ve.v4()}),children:[i.jsx(V,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),o.type.toLowerCase()==="cascadeselect"&&i.jsxs(i.Fragment,{children:[i.jsx("hr",{className:"my-5"}),i.jsxs("div",{children:[" ",i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Child Options "}),W==null?void 0:W.map((R,H)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Label",name:`options1.${H}.label`,register:v,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Value",name:`options1.${H}.value`,register:v,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Key",name:`options1.${H}.key`,register:v,errors:y,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:W.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>M(H),children:i.jsx(V,{icon:"iconamoon:sign-times-fill"})})]},R.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>K({label:"",value:"",key:"",id:ve.v4()}),children:[i.jsx(V,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),fe=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:se==null?void 0:se.map(R=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:H=>u(H.target.value),value:R,checked:R===c})," ",i.jsxs("span",{children:[R," options"]})]},R))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(G,{label:"Load Columns from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/columns",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]})," ",i.jsx("button",{onClick:be,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(rn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:g,name:"dataColumns"})}),T==null?void 0:T.map((R,H)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"min-w-[140px]",children:i.jsx(Ce,{label:H===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"}],register:v,name:`dataColumns.${H}.type`,setValue:g,trigger:x,value:w.dataColumns[H].type})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:H===0?"Field key":"",name:`dataColumns.${H}.field`,register:v,errors:y,element:o,placeholder:"fieldKey"})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:H===0?"Display header":"",name:`dataColumns.${H}.headerName`,register:v,errors:y,element:o,placeholder:"header"})}),i.jsx("button",{disabled:T.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>O(H),children:i.jsx(V,{icon:"iconamoon:sign-times-fill"})})]},R.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>B({headerName:"",field:"",editable:!0,id:ve.v4(),type:"text",validate:!1}),children:[i.jsx(V,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),xe=m.useCallback(async()=>{const R=ue("token"),{status:H,data:te}=await Ne.get(w.url,{headers:{Authorization:`Bearer ${R}`}});H===200&&g("options",(te==null?void 0:te.data)||te)},[g,w.url]);return m.useEffect(()=>{o.type==="document"&&w.url&&xe()},[w.url,o.type,xe]),i.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default select-none ",draggable:"true",onDragStart:R=>R.preventDefault(),children:i.jsxs("div",{className:"w-full lg:w-2/3 xl:w-2/5 bg-white h-screen shadow-xl relative flex flex-col items-center select-",draggable:"true",onDragStart:R=>R.preventDefault(),children:[i.jsx("button",{className:"bg-white h-10 w-10 flex justify-center items-center absolute top-1 -left-12 rounded-lg hover:bg-gray-50",onClick:n,children:i.jsx(V,{icon:"tabler:x",iconClass:"text-xl"})}),i.jsx("div",{className:"w-full pt-4",children:i.jsx(ea,{tabs:s,setActiveTab:l,activeTab:t,className:"justify-start !text-left",btnClass:" !text-left"})}),i.jsxs("form",{onSubmit:p(Q),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:[mi.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(G,{label:"Value",name:"value",register:v,errors:y,element:o})}),!mi.includes(o.inputType)&&!We.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(G,{label:"Label",name:"inputLabel",register:v,errors:y,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(G,{label:"Child Label",name:"childLabel",register:v,errors:y,element:o})]}),da.includes(o.inputType)&&i.jsx(G,{label:"Placeholder",name:"placeholder",register:v,errors:y,element:o}),ta.includes(o.inputType)&&i.jsx(G,{label:"Prefix",name:"prefix",register:v,errors:y,element:o}),ca.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(pa,{}),i.jsx(G,{label:"Api Url",name:"url",register:v,errors:y,element:o}),i.jsx(Ce,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:v,name:"method",setValue:g,trigger:x,value:f("method")}),i.jsx(Ce,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:v,name:"responseType",setValue:g,trigger:x,value:f("responseType")})]}),ma.includes(o.inputType)&&i.jsx(va,{onChange:R=>{g("denominators",R)},value:f("denominators")}),!mi.includes(o.inputType)&&!We.includes(o.inputType)&&i.jsx(G,{label:"Short Description",name:"description",register:v,errors:y,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Ce,{label:"Date Format",options:sa,register:v,name:"dateFormat",setValue:g,trigger:x,value:f("dateFormat")}),i.jsx(G,{label:"Allow Range",name:"canHaveDateRange",register:v,errors:y,element:o,type:"checkbox"}),(w==null?void 0:w.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx($e,{name:"minDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select min date"}),i.jsx($e,{name:"maxDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select max date",minDate:w==null?void 0:w.minDate})]}),i.jsx(G,{label:"Allow Year Picker",name:"allowYearPicker",register:v,errors:y,element:o,type:"checkbox"})]}),o.type.toLowerCase()==="country"&&i.jsx(G,{label:"Allow States",name:"showState",register:v,errors:y,element:o,type:"checkbox"}),o.type.toLowerCase()==="selectfield"&&i.jsx(Ce,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:v,name:"selectType",setValue:g,trigger:x,value:f("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(G,{label:"Number of columns",name:"columns",register:v,errors:y,element:o}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(G,{label:"Document Options Url",name:"url",register:v,errors:y,element:o})," ",i.jsx(fa,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(G,{label:"Document Validation Url",name:"validationUrl",register:v,errors:y,element:o}),i.jsx(xa,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(G,{label:"Signature Page Url",name:"signatureLink",register:v,errors:y,element:o})})]}),o.type.toLowerCase()==="datagrid"&&fe(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(G,{label:"Allow Multiple Uploads",name:"isMultiple",register:v,errors:y,element:o,type:"checkbox"}),i.jsx(ri,{element:{options:ba,id:"acceptedFiles",value:w==null?void 0:w.acceptedFiles},validationData:{register:v,setValue:g,trigger:x,watch:f},placeholder:"Choose file types"})]}),ua.includes(o.inputType)&&pe(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(G,{label:"Toggle Visibility",name:"isHidden",register:v,errors:y,element:o,type:"checkbox"})})," ",w.isHidden&&i.jsx(wa,{register:v,setValue:g,trigger:x,watch:f,id:o==null?void 0:o.id})]})]}),!We.includes(o.type.toLowerCase())&&t==="validation"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Required",name:"isRequired",register:v,errors:y,element:o,type:"checkbox"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"requiredMessage",register:v,errors:y,element:o})})]}),la.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Min Length",name:"minLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"minLengthMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Max Length",name:"maxLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"maxLengthMessage",register:v,errors:y,element:o})})]})]}),ra.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Min Amount",name:"minAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"minAmountMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Max Amount",name:"maxAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"maxAmountMessage",register:v,errors:y,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest editor_option__cancel",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!_||k,style:{background:(h==null?void 0:h.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!_||k?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!_||k?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:k?"Saving...":"Save"})]})]})]})})},vi=m.memo(({state:e,element:n,children:o})=>{const[s,a]=m.useState(!1),{removeElement:t,duplicateElement:l}=m.useContext(de),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(_a,{isOpen:s,onClose:()=>a(!1),element:n}),i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("span",{children:[" ",n.inputLabel&&i.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",r&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",r==null?void 0:r.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[!n.gridPosition&&i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:()=>l(n==null?void 0:n.id,n.sectionId),title:"Duplicate",children:i.jsx(V,{icon:"tabler:copy",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:()=>a(!0),title:"Edit",children:i.jsx(V,{icon:"circum:edit",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:d,title:"Remove",children:i.jsx(V,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});vi.displayName="ElementContainer";function Na({element:e,validationData:n}){const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:l}=n||{};let r;return t&&(r=t()[e.id]),i.jsx(G,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:s,setValue:a,value:r,prefix:e.prefix,disabled:l})}function ja(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 Ca=({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 Ma({element:e,validationData:n}){var w;const{register:o=()=>({}),setValue:s,watch:a}=n||{},[t,l]=m.useState(),[r,d]=m.useState(!1),[c,u]=m.useState(!1),[h,v]=m.useState(""),p=a&&a(e==null?void 0:e.id);m.useEffect(()=>{l(p)},[p]);const[A,g]=m.useState("");m.useEffect(()=>{o(e.id)},[e.id,o]);const{url:f,method:x,responseType:y}=e||{},_={headers:{Authorization:`Bearer ${ue("token")}`}},S=m.useCallback(async j=>{var L,Y,W,K,M,T,B,O,Q,q,oe;if(!(!f||!x)){d(!0);try{let I;if(x.toLowerCase()==="get"){const se=`${f}?value=${j}`;I=await Ne.get(se,_)}else if(x.toLowerCase()==="post")I=await Ne.post(f,{value:j},_);else throw new Error("Unsupported HTTP method");I.status===200&&((((Y=(L=I==null?void 0:I.data)==null?void 0:L.data)==null?void 0:Y.status)||((W=I==null?void 0:I.data)==null?void 0:W.status))===!0?(u(!0),y==="string"?v(((M=(K=I==null?void 0:I.data)==null?void 0:K.data)==null?void 0:M.description)||((T=I==null?void 0:I.data)==null?void 0:T.description)||"Validation successful"):g(((O=(B=I==null?void 0:I.data)==null?void 0:B.data)==null?void 0:O.description)||((Q=I==null?void 0:I.data)==null?void 0:Q.description)||{})):(console.error("Invalid input:",j),v("Unable to validate input"),u(!1)))}catch(I){console.error("Error validating input:",I),v(((oe=(q=I==null?void 0:I.response)==null?void 0:q.data)==null?void 0:oe.message)||"Unable to validate input"),u(!1)}finally{d(!1)}}},[x,y,f]);return m.useEffect(()=>{if(t){const j=setTimeout(()=>{S(t)},700);return()=>clearTimeout(j)}},[S,t]),i.jsxs("div",{children:[i.jsxs("div",{className:"relative flex items-center",children:[i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:F("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:j=>{l(j.target.value),s(e==null?void 0:e.id,j.target.value)},disabled:n==null?void 0:n.isReadOnly}),i.jsxs("span",{className:"absolute right-0",children:[r&&i.jsxs("span",{children:[" ",i.jsxs("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})]}),c&&!r&&i.jsx("span",{className:"block pr-3 text-lg text-green-600",children:i.jsx(V,{icon:"gg:check-o"})})]})]}),h&&y==="string"&&i.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:h}),y==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(w=Object.entries(A))==null?void 0:w.map(([j,L])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[j,":"]}),ja(L)?i.jsx(Ca,{imageUrl:L}):i.jsx("span",{children:String(L)})]},j))})]})}function Ta({onGetTotal:e,readOnly:n,defaultValue:o,denominators:s}){const[a,t]=m.useState([...o]);function l(c,u){t(h=>{const v=[...h];return v[u]={...v[u],value:c},v})}function r(c,u){return parseFloat(c)*parseFloat(u)||0}const d=m.useMemo(()=>a.reduce((c,u)=>{const h=r(u.key,u.value);return c+h},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,h)=>({key:u.value,value:Array.isArray(o)&&o[h]?o[h].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 h,v;return i.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[i.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:i.jsx("span",{className:"",children:(h=parseFloat(c.key))==null?void 0:h.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(Ke,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:p=>l(p,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(v=r(c.key,c.value))==null?void 0:v.toLocaleString()})})]},u+"index")}),i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),i.jsx("div",{className:"px-4 py-3",children:d==null?void 0:d.toLocaleString()})]})]})})}function Ea({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 Ba({element:e}){return i.jsx("div",{className:F("py-6",e==null?void 0:e.customClass)})}function La({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:F("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Pa({element:e,validationData:n}){const{register:o=()=>({})}=n||{};return i.jsx("div",{children:i.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...o(e==null?void 0:e.id)})})}function Oa({element:e,state:n}){return i.jsx(i.Fragment,{children:i.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&i.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function Ia({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 h=e[u.field],v=u.editable&&!o,p=c(u.field),{isValidating:A,result:g}=r(e.id,u.field);let f="border-gray-300";u.validate&&((g==null?void 0:g.isValid)===!1?f="border-red-500 bg-red-50":(g==null?void 0:g.isValid)===!0&&(f="border-green-500 bg-green-50"));const x=`w-full px-2 py-1 border rounded outline-none ${f}`;return i.jsx("td",{title:o?"":"Double click to edit",className:"px-3 py-1 border",onDoubleClick:()=>v&&a({rowId:e.id,field:u.field}),children:v&&p?i.jsxs("div",{className:"relative",children:[u.type==="number"?i.jsx(Ke,{value:h,decimalsLimit:6,allowNegativeValue:!1,className:x,onValueChange:k=>t(k,e.id,u.field),onBlur:()=>{a(null),l(h,e.id,u.field,u)},autoFocus:!0}):u.type==="checkbox"?i.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(k=>{const _=k==="yes",S=`radio-${e.id}-${String(u.field)}-${k}`;return i.jsxs("label",{htmlFor:S,className:"flex items-center gap-1 cursor-pointer",children:[i.jsx("input",{id:S,type:"radio",name:`boolean-${e.id}-${String(u.field)}`,checked:h===_,onChange:()=>t(_,e.id,u.field)}),i.jsx("span",{className:"text-sm",children:_?"Yes":"No"})]},k)})}):i.jsx("input",{type:"text",value:String(h!=null?h:""),onChange:k=>t(k.target.value,e.id,u.field),onBlur:()=>{a(null),l(h,e.id,u.field,u)},className:x,autoFocus:!0}),A&&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&&g?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{children:[String(h!=null?h:"")," ",g.data&&`[${g.data}]`]}),g.isValid?i.jsx("span",{className:"text-xs text-green-600",children:"✓"}):i.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(y=g.error)!=null?y:"",children:"✗"})]}):u.type==="checkbox"?i.jsx("span",{className:"block py-1 text-gray-700",children:h===!0?"Yes":h===!1?"No":""}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:String(h!=null?h:"")})},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(V,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const Da=m.memo(Ia);function Ka({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=document.getElementById("form"),u=m.useMemo(()=>{const g=(c==null?void 0:c.getBoundingClientRect().width)||0;return g&&g-48},[c]);m.useEffect(()=>{t(g=>JSON.stringify(g)!==JSON.stringify(e)?e:g)},[e]),m.useEffect(()=>{n==null||n(a)},[a,n]),m.useEffect(()=>{const g=f=>{d.current&&!d.current.contains(f.target)&&r(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[]);const h=m.useCallback((g,f,x)=>{t(y=>y.map(k=>k.id===f?{...k,[x]:g}:k))},[]),v=m.useCallback(()=>{const g=ve.v4(),f=s.reduce((x,y)=>(x[y.field]=y.field==="id"?g:"",x),{});t(x=>[...x,{id:g,...f}])},[s]),p=m.useCallback(g=>{t(f=>f.filter(x=>x.id!==g))},[]),A=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:s.length>0&&!o&&i.jsx("button",{onClick:v,type:"button",className:"px-2 py-1 mb-3 text-xs text-white bg-gray-600 rounded hover:bg-gray-700",children:"Add Row"})}),i.jsx("div",{className:"w-full max-w-full overflow-x-auto",style:{maxWidth:`${u}px`},children:i.jsxs("table",{className:"min-w-max w-full text-sm border-collapse rounded table-auto bg-gray-50",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"bg-gray-100",children:[s.map((g,f)=>{var x;return i.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border whitespace-nowrap",children:[(x=g.headerName)!=null?x:String(g.field),g.validate&&i.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(g.id)}-${f}`)}),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:a.length>0?a.map(g=>i.jsx(Da,{row:g,columns:s,isReadOnly:o,editingCell:l,setEditingCell:r,handleCellChange:h,debouncedValidate:()=>{},getValidationStatus:A,deleteRow:p},g.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 Ga({element:e,validationData:n}){const{register:o=()=>({}),setValue:s,watch:a}=n||{},t=a&&a(e==null?void 0:e.id)||[];m.useEffect(()=>{o(e.id)},[e.id,o]);const l=m.useCallback(r=>{s==null||s(e.id,r)},[e.id,s]);return i.jsx(Ka,{value:t,onChange:l,columns:e==null?void 0:e.dataColumns,isReadOnly:e==null?void 0:e.isReadOnly})}const cn=({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:h=!1,subText:v,labelClass:p="",loading:A,disabled:g})=>{const[f,x]=m.useState(u?[]:null),y=F("custom-select__control",e),k=m.useMemo(()=>n,[n]);return m.useEffect(()=>{const _=n==null?void 0:n.find(S=>{var w;return typeof S.value=="string"&&typeof d=="string"?S.value.toLowerCase()===d.toLowerCase():typeof S.value=="object"&&typeof d=="object"?((w=S.value)==null?void 0:w.id)===(d==null?void 0:d.id):S.value===d});x(_||null)},[d,n]),m.useEffect(()=>{f&&t&&a&&(t(l,f==null?void 0:f.value),a(l),c==null||c(l))},[l,f]),i.jsxs("div",{className:"custom-select",children:[r&&!h&&i.jsx("label",{className:"custom-select__label",children:r}),h&&r&&i.jsx("label",{className:F("custom-select__floating-label",p),children:r}),i.jsx(D.Listbox,{value:f,onChange:x,multiple:u,disabled:g,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(D.Listbox.Button,{className:y,disabled:g,children:[A?i.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):i.jsx("span",{className:"custom-select__value",children:(f==null?void 0:f.label)||i.jsx("span",{className:"custom-select__placeholder",children:o})}),i.jsx("span",{className:"custom-select__icon",children:i.jsx(V,{icon:"lucide:chevron-down"})})]}),i.jsx(D.Transition,{as:m.Fragment,leave:"custom-select__transition",children:i.jsx(D.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:k==null?void 0:k.map((_,S)=>i.jsx(D.Listbox.Option,{value:_,className:({active:w})=>F("custom-select__option",w&&"custom-select__option--active"),children:({selected:w})=>i.jsx("span",{className:F("custom-select__option-label",w&&"custom-select__option--selected"),children:_.label})},S))})})]})}),v&&!s&&i.jsx("p",{className:"custom-select__subtext",children:v}),s&&i.jsx("span",{className:"custom-select__error",children:s.message})]})},Ra=({element:e,validationData:n})=>{var g;const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:l}=n||{},r=(g=e==null?void 0:e.id)!=null?g:"cascadeValue",[d,c]=m.useState(""),[u,h]=m.useState(""),v=(f,x)=>{const y=f&&x?`${f}_${x}`:"";a==null||a(r,y),s==null||s(r)},p=(f,x)=>{f==="first"?(c(x),h(""),v(x,"")):(h(x),v(d,x))};m.useEffect(()=>{if(t){const f=t(r);if(f!=null&&f.includes("_")){const[x,y]=f.split("_");c(x),h(y)}}},[t,r]);const A=m.useMemo(()=>{var f;return(f=e.options1)==null?void 0:f.filter(x=>x.key===d)},[e.options1,d]);return!e.options||!e.options1?null:i.jsxs("div",{children:[i.jsx("input",{type:"hidden",...o(r)}),i.jsx("div",{className:"relative",children:i.jsx(cn,{setValue:(f,x)=>p("first",x),options:e.options,name:`${r}`,register:o,value:d})}),d&&i.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&i.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),i.jsx(cn,{setValue:(f,x)=>p("second",x),options:A,name:`${r}`,register:o,value:u})]})]})},za=({value:e=0,max:n=5,readOnly:o=!1,onChange:s,size:a=24,className:t="",element:l,validationData:r})=>{var x;const{register:d=()=>({}),trigger:c,setValue:u,watch:h,isReadOnly:v}=r||{},p=(x=h==null?void 0:h(l.id))!=null?x:0,[A,g]=m.useState(null);m.useEffect(()=>{p==null&&(u==null||u(l.id,e))},[]);const f=y=>{if(!o&&!v){const k=y+1;u==null||u(l.id,k),c==null||c(l.id),s==null||s(k)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(y,k)=>{const _=A!==null?k<=A:k<p;return i.jsx(tn,{icon:_?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${_?"text-yellow-400":"text-gray-300"}`,width:a,height:a,onMouseEnter:()=>!(o||v)&&g(k),onMouseLeave:()=>!(o||v)&&g(null),onClick:()=>f(k)},k)})]})};function mn({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 A;if(typeof r=="string"&&r.includes(",")){const[g,f]=(A=r.split(","))==null?void 0:A.map(x=>x.trim());return{country:f,state:g}}return{country:r,state:""}},[r]),u=m.useRef(r),h=m.useMemo(()=>{var A,g;return d?((g=(A=Ve.find(f=>f.name===d))==null?void 0:A.states)==null?void 0:g.map(f=>({label:f.name,value:f.name})))||[]:[]},[d]),v=(A,g)=>{const x=(g==null?void 0:g.value)||"";s&&x!==u.current&&(s(e.id,x),a==null||a(e.id),u.current=x)},p=(A,g)=>{const f=(g==null?void 0:g.value)||"",x=f?`${f}, ${d}`:d;s&&x!==u.current&&(s(e.id,x),a==null||a(e.id),u.current=x)};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(ui,{options:e.options,onGetValue:v,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),h.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(ui,{options:h,onGetValue:p,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function Ha({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:s}=n||{},{validationUrl:a,documentObj:t,signatureLink:l}=e,r=m.useMemo(()=>ue("config"),[]),[d,c]=m.useState(!1),[u,h]=m.useState(!1),v=m.useCallback(async()=>{var p,A;if(!(!a||!t))try{h(!0);const f={headers:{Authorization:`Bearer ${ue("token")}`}},{data:x}=await Ne.get(`${a}/${t}`,f),y=!!((A=(p=x==null?void 0:x.data)==null?void 0:p.isSigned)!=null?A:x!=null&&x.isSigned);return c(y),y}catch(g){console.error("Failed to check sign status",g)}finally{h(!1)}},[a,t]);return m.useEffect(()=>{let p=null;return!d&&t&&a&&(async()=>{await v()||(p=setInterval(async()=>{await v()&&p&&clearInterval(p)},2e3))})(),()=>{p&&clearInterval(p)}},[v,d,t,a]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:F("field-control",e.customClass),...o(e.id),disabled:s}),i.jsx("a",{href:d?"#":l,children:i.jsxs("button",{type:"button",onClick:v,disabled:u||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:F("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(V,{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 pi=[{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 Fa({label:e,placeholder:n,classLabel:o,isRequired:s,isOptional:a,name:t,value:l,error:r,disabled:d,readOnly:c,horizontal:u,description:h,validate:v,onChange:p,onError:A}){const[g,f]=m.useState(""),[x,y]=m.useState(null),[k,_]=m.useState(""),S=m.useMemo(()=>{var M;return(M=pi==null?void 0:pi.slice().sort((T,B)=>T.label.localeCompare(B.label)))==null?void 0:M.map(T=>({...T,phone:`+${T.phone}`}))},[]),w=m.useMemo(()=>g?S.filter(M=>`${M.label} ${M.phone}`.toLowerCase().includes(g.toLowerCase())):S,[g,S]),j=(x==null?void 0:x.min)||10,L=(x==null?void 0:x.max)||10,Y=()=>k?`${(x==null?void 0:x.phone)||"+234"}-${k}`:"",W=M=>{if(!M)return{code:"+234",number:""};const T=M.split(/[-\s]/);return{code:T[0],number:T.slice(1).join(" ")}};m.useEffect(()=>{if(l){const M=W(l);y(S.find(T=>T.phone===M.code)||S[0]),_(M.number)}},[l,S]);const K=m.useMemo(()=>{if(r)return r;const M=k.length;return s&&M===0?"Phone number is required":M>0&&!/^\d+$/.test(k)?"Phone number must contain only digits":M>0&&M<j?`Minimum length is ${j}`:M>L?`Maximum length is ${L}`:""},[r,k,j,L,s]);return m.useEffect(()=>{p==null||p(Y()),A==null||A(K||null)},[k,x,K]),i.jsxs("div",{className:`relative formGroup ${K&&!c?"has-error":""} ${u?"flex":""} ${!K&&k.length>0&&!c?"is-valid":""}`,children:[e&&i.jsxs("label",{htmlFor:t,className:`${o} ${u?"flex-0 mr-6 md:w-[100px] w-[60px] break-words":""} flex items-center gap-x-1 input-label text-sm text-[#1B2B41B8]`,children:[e," ",s&&i.jsx("span",{className:"text-red-500",children:"*"}),a&&i.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),i.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[i.jsx(V,{icon:"lucide:phone-call"}),i.jsx(D.Combobox,{value:x,onChange:y,children:i.jsxs("div",{className:"relative",children:[i.jsx(D.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:M=>(M==null?void 0:M.phone)||"+234",placeholder:"+234",onChange:M=>f(M.target.value)}),i.jsx(D.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(V,{icon:"lucide:chevron-down"})}),i.jsx(D.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:w==null?void 0:w.map((M,T)=>i.jsxs(D.Combobox.Option,{value:M,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[M.phone," - ",M.label]},`${M.code}+ ${T}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:k,disabled:d,readOnly:c,onChange:M=>{const T=M.target.value.replace(/\D/g,"");_(T)},placeholder:n,className:"w-full px-3 outline-none"}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!K&&k.length>0&&!c&&i.jsx("span",{className:"text-green-500",children:i.jsx(V,{icon:"bi:check-lg"})})})]})]}),h&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:h})]})}function Va({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(Fa,{placeholder:e.placeholder,label:"",name:e.id,value:d,readOnly:t,disabled:t,onError:c=>{c?l==null||l(e.id,{type:"manual",message:c}):r(e.id)},onChange:c=>{c&&(s==null||s(e.id,c))}})}function Ua({element:e,validationData:n}){const{register:o=()=>({}),watch:s}=n||{};let a;return s&&(a=s()[e.id]),i.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",className:F("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly}),a&&i.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:i.jsx("a",{title:"Visit link",target:"_blank",className:"hover:underline text-blue-700",href:a,children:a})})]})}const bn={textField:Qe,longText:Xo,selectField:Qo,multiSelect:ri,numberField:Qe,amountField:Na,date:zn,password:qo,checkbox:$o,radio:Yo,email:Qe,file:Jo,dataGrid:Ga,section:Zo,validateInput:Ma,tableInput:Ea,spacer:Ba,divider:La,header:Pa,basicText:Oa,phoneField:Va,cascadeSelect:Ra,rating:za,country:mn,bank:mn,document:Ha,link:Ua},vn="edit",pn=(e,n)=>{const o=bn[e.type];return o?i.jsx(vi,{element:e,state:vn,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:vn,sectionId:n})]})}):null},gi=({col:e,children:n,customClass:o})=>i.jsx("div",{className:F("w-full bg-white",o),style:{gridColumn:e},children:n}),Wa=({element:e,sectionId:n,children:o,customClass:s,state:a})=>{const{formData:t,addElement:l,setIsDragging:r}=m.useContext(de),d=m.useMemo(()=>Array.from({length:e.columns}),[e.columns]),c=m.useCallback(v=>{v.preventDefault(),v.stopPropagation(),v.dataTransfer.dropEffect="move"},[]),u=m.useCallback((v,p)=>{var A,g;v.preventDefault(),r(!1);try{const f=v.dataTransfer.getData("properties");if(!f)return;const x=JSON.parse(f);if((x==null?void 0:x.type)==="grid")return;const y=p+1;if((g=(A=t.find(S=>S.id===n))==null?void 0:A.questionData)==null?void 0:g.some(S=>{var w;return S.gridId===e.id&&((w=S.gridPosition)==null?void 0:w.col)===y}))return;const _={...x,id:ve.v4(),sectionId:n,gridId:e.id,gridPosition:{col:y}};l(_,n)}catch(f){console.error("Drop failed in grid:",f),r(!1)}},[l,e.id,t,n,r]),h=(v,p,A)=>{const g=Array.isArray(o)&&o.find(f=>{var x;return((x=f==null?void 0:f.props)==null?void 0:x.col)===v+1});return i.jsx("div",{children:i.jsx("div",{id:v.toString(),onDrop:f=>u(f,v),onDragOver:c,className:F("border rounded-lg min-h-[110px] bg-white ","flex items-center justify-center text-gray-400 transition-colors",`${A==="edit"?"p-3":""}`,p),children:g||i.jsx("span",{children:A==="edit"&&i.jsx(V,{icon:"ph:plus-bold"})})})},v)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:d==null?void 0:d.map((v,p)=>h(p,s,a))})})},hi=m.memo(Wa),Ja="edit";function qa({elementData:e,sectionId:n}){const{formData:o,updateElementPosition:s,isDragging:a,setIsDragging:t,addElementInPosition:l}=m.useContext(de),[r,d]=m.useState(null),[c,u]=m.useState(null),h=m.useMemo(()=>{var k;return((k=o.find(_=>_.id===n))==null?void 0:k.questionData)||[]},[o,n]),v=m.useCallback((k,_)=>{k.dataTransfer.setData("properties",_),d(_)},[]),p=m.useCallback((k,_)=>{k.preventDefault(),k.stopPropagation(),u(_)},[]),A=m.useCallback(k=>{k.preventDefault(),k.stopPropagation();const _=k.dataTransfer.getData("properties"),S=k.currentTarget.id;if(!S||_===S)return;const w=h.findIndex(W=>W.id===_),j=h.findIndex(W=>W.id===S);if(w===-1||j===-1)return;const L=[...h],[Y]=L.splice(w,1);L.splice(j,0,Y),s(L,n),d(null)},[h,n,s]),g=m.useCallback((k,_)=>{k.preventDefault(),t(!1);try{const S=JSON.parse(k.dataTransfer.getData("properties"));if((S==null?void 0:S.type)==="section")return;const w={...S,id:ve.v4(),sectionId:n};l(w,n,_)}catch(S){console.error("Drop error:",S)}},[l,n,t]),f=m.useCallback(k=>i.jsx("div",{className:"transition rounded hover:bg-blue-300",onDragOver:_=>_.preventDefault(),onDrop:_=>g(_,k),onDragEnd:()=>t(!1),children:i.jsx("div",{className:"bg-blue-50 rounded p-6 h-[60px] border-2 border-blue-300 border-dashed flex items-center justify-center text-gray-400 opacity-70",children:i.jsx(V,{icon:"octicon:plus-16"})})},`drop-${k}`),[g,t]),x=m.useCallback(k=>i.jsx("div",{id:k.id,className:F("cursor-move border p-4 w-full rounded-lg transition-colors bg-white",{"bg-gray-100":r===k.id,"border-dashed border-blue-300":r&&r!==k.id}),draggable:!0,onDragStart:_=>v(_,k.id),onDragOver:_=>p(_,k.id),onDrop:A,onDragEnd:()=>d(null),children:pn(k,n)},k.id),[r,A,p,n,v]),y=m.useMemo(()=>(e==null?void 0:e.reduce((k,_)=>(_.gridId&&(k[_.gridId]=k[_.gridId]||[],k[_.gridId].push(_)),k),{}))||{},[e]);return e!=null&&e.length?i.jsx("div",{className:"relative grid w-full h-full grid-cols-1 gap-4",children:e==null?void 0:e.map((k,_)=>{if(k.type==="grid"){const S=y[k.id]||[];return i.jsx("div",{draggable:!0,onDragStart:w=>v(w,k.id),onDragOver:w=>p(w,k.id),onDrop:A,onDragEnd:()=>d(null),className:"w-full p-4 transition-colors bg-white border rounded-lg cursor-move",children:i.jsx(vi,{element:k,state:"edit",children:i.jsx(hi,{element:k,sectionId:n,state:Ja,children:S==null?void 0:S.map(w=>{var j;return i.jsx(gi,{col:(j=w.gridPosition)==null?void 0:j.col,children:pn(w,n)},w.id)})})})},k.id)}return k.gridId?null:i.jsxs("div",{className:F("group relative grid gap-y-[6px]",k.elementClass),children:[a&&c===k.id&&f(_),i.jsx("div",{className:"group",children:x(k)}),a&&c===k.id&&f(_+1)]},k.id)})}):i.jsx("div",{onDragOver:k=>k.preventDefault(),onDrop:k=>g(k,0),onDragEnd:()=>t(!1),className:"w-full h-full flex items-center justify-center text-gray-400 min-h-[200px] p-10 col-span-2 border border-dashed border-gray-300 rounded-lg",children:"Drag or click an element to display"})}const Ya=m.memo(qa),Za=E.object({title:E.string(),description:E.string()}).required(),fi=ue("config"),$a=({isOpen:e,onClose:n,section:o})=>{const{updateSection:s}=m.useContext(de),{register:a,handleSubmit:t,formState:{errors:l,isSubmitting:r,isValid:d},reset:c}=ke.useForm({resolver:ci(Za),defaultValues:o});if(m.useEffect(()=>{e||c()},[e,c]),!e)return null;const u=h=>{s(h,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(V,{icon:"tabler:x"})})]}),i.jsxs("form",{onSubmit:t(u),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(G,{label:"Title",name:"title",register:a,errors:l}),i.jsx(G,{label:"Description",name:"description",register:a,errors:l})]}),i.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!d||r,style:{background:(fi==null?void 0:fi.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!d||r?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!d||r?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:r?"Saving...":"Save"})]})]})]})})},Qa=()=>{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:h}=m.useContext(de);m.useEffect(()=>{var f;d(((f=l[0])==null?void 0:f.id)||null)},[]);const v=m.useCallback(f=>{f.preventDefault(),f.dataTransfer.dropEffect="move",s.current&&(s.current.scrollTop=s.current.scrollHeight)},[]);function p(f){u.includes(f)?h(x=>x.filter(y=>y!==f)):h(x=>[...x,f])}function A(f){o.current=f,n(!0)}const g=ue("config");return i.jsxs("div",{ref:s,className:"relative flex flex-col h-full px-6 pb-5 mx-auto gap-x-4",children:[e&&i.jsx($a,{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((f,x)=>i.jsx("div",{className:"bg-white group cursor-pointer rounded ",children:i.jsxs("div",{className:`border border-gray-100 rounded px-4 shadow-[rgba(149,157,165,0.2)_0px_2px_4px] transition-colors duration-200
48
+ }`})})]})})}),xa=()=>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 ya(e){return e.flatMap(n=>{var o;return(o=n.questionData)!=null?o:[]})}const bi=["text","number","boolean"],un=["equals","not_equals","contains","not_contains"],ka=["greater","less"];function wa({register:e,setValue:n,trigger:o,watch:s,id:a}){const{formData:t}=m.useContext(de),l=s("visibilityDependentFields")||[],r=m.useMemo(()=>{var c;return(c=ya(t).filter(u=>u.id!==a))==null?void 0:c.map(u=>{const h=l.find(v=>v.id===u.id);return{id:u.id,value:u.id,label:u.inputLabel,sectionId:u.sectionId,fieldType:(h==null?void 0:h.fieldType)||"text",operator:(h==null?void 0:h.operator)||"equals",fieldValue:(h==null?void 0:h.fieldValue)!==void 0?h.fieldValue:""}})},[t,l,a]),d=(c,u,h)=>{const v=l==null?void 0:l.map((p,A)=>A===c?{...p,[u]:h}:p);n("visibilityDependentFields",v)};return i.jsxs("div",{className:"visibility-editor",children:[i.jsx("label",{className:"label",children:"Select Dependent Fields"}),i.jsx(ri,{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 h,v;return i.jsxs("div",{className:"dependent-field",children:[i.jsx("input",{type:"text",value:c.label,readOnly:!0,disabled:!0,className:"field-label"}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(D.Listbox,{value:c.fieldType,onChange:p=>d(u,"fieldType",p),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(D.Listbox.Button,{className:"listbox-button",children:c.fieldType}),i.jsx(D.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(D.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:bi==null?void 0:bi.map(p=>i.jsx(D.Listbox.Option,{value:p,className:"listbox-option",children:p},p))})})]})})}),i.jsx("div",{className:"field-listbox min-w-[100px]",children:i.jsx(D.Listbox,{value:c.operator,onChange:p=>d(u,"operator",p),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(D.Listbox.Button,{className:"listbox-button",children:c.operator.replace("_"," ")}),i.jsx(D.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsx(D.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(h=c.fieldType==="number"?[...un,...ka]:un)==null?void 0:h.map(p=>i.jsx(D.Listbox.Option,{value:p,className:"listbox-option",children:p.replace("_"," ")},p))})})]})})}),c.fieldType!=="boolean"?i.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:p=>d(u,"fieldValue",p.target.value),placeholder:"Value",className:"field-value"}):i.jsx("div",{className:"field-listbox",children:i.jsx(D.Listbox,{value:(v=c.fieldValue)!=null?v:"",onChange:p=>d(u,"fieldValue",p),children:i.jsxs("div",{className:"listbox-wrapper",children:[i.jsx(D.Listbox.Button,{className:"listbox-button",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),i.jsx(D.Transition,{as:m.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:i.jsxs(D.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[i.jsx(D.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),i.jsx(D.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},c.id)})})]})}const Aa=E.object().shape({inputLabel:E.string().nullable(),placeholder:E.string().nullable(),description:E.string().nullable(),isReadOnly:E.boolean(),isDisabled:E.boolean(),isRequired:E.boolean(),requiredMessage:E.string().nullable(),minLengthMessage:E.string().nullable(),maxLengthMessage:E.string().nullable(),maxLength:E.number().typeError("Expecting a number").nullable(),minLength:E.number().typeError("Expecting a number").nullable(),inputType:E.string().nullable(),maxAmountMessage:E.string().nullable(),maxAmount:E.string().nullable(),options:E.array().of(E.object().shape({label:E.string().nullable(),value:E.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),options1:E.array().of(E.object().shape({label:E.string().nullable(),value:E.string().when("label",{is:e=>e&&e.length>0,then:e=>e.required("Value is required when label is present"),otherwise:e=>e.nullable()})})).when("inputType",{is:e=>["radio","checkbox"].includes(e),then:e=>e.required("Options are required for radio or checkbox inputs"),otherwise:e=>e.nullable()}),prefix:E.string().nullable(),url:E.string().nullable(),method:E.string().nullable(),denominators:E.mixed().nullable(),responseType:E.string().nullable(),minAmount:E.string().nullable(),heading:E.string().nullable(),minAmountMessage:E.string().nullable(),columns:E.number().nullable(),value:E.mixed().nullable(),customClass:E.string().nullable(),elementClass:E.string().nullable(),apiUrl:E.string().nullable(),selectType:E.string().default("list"),dateType:E.string().default("basic"),validationUrl:E.string(),signatureLink:E.string(),minDate:E.string().nullable(),maxDate:E.string().nullable(),canHaveDateRange:E.boolean(),allowYearPicker:E.boolean(),isHidden:E.boolean(),visibilityDependentFields:E.array().nullable(),isMultiple:E.boolean(),acceptedFiles:E.array(),showState:E.boolean()}),Sa=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],_a=({isOpen:e,onClose:n,element:o})=>{const s=Sa.filter(R=>!We.includes(o.inputType)||R.key!=="validation"),{updateElement:a}=m.useContext(de),[t,l]=m.useState("basic"),[r,d]=m.useState(!1),[c,u]=m.useState("manual"),h=ue("config"),{register:v,handleSubmit:p,control:A,setValue:g,watch:f,trigger:x,formState:{errors:y,isSubmitting:k,isValid:_},reset:S}=ke.useForm({resolver:ci(Aa),defaultValues:{...o,options:o.options||[]}}),w=f(),{fields:j,append:L,remove:Y}=ke.useFieldArray({control:A,name:"options"}),{fields:W,append:K,remove:M}=ke.useFieldArray({control:A,name:"options1"}),{fields:T,append:B,remove:O}=ke.useFieldArray({control:A,name:"dataColumns"});m.useEffect(()=>{e||S()},[e,S]);const Q=R=>{a(R,o.sectionId),n()},oe={headers:{Authorization:`Bearer ${ue("token")}`}},I=m.useCallback(async()=>{var R,H,te;if(!w.apiUrl||!/^https?:\/\//.test(w.apiUrl)){me.toast.info("Please provide a valid API URL");return}try{d(!0);const{status:Z,data:X}=await Ne.get(w.apiUrl,oe);if(Z!==200||!X){me.toast.error("Unexpected response from server.");return}const le=X.data||X.record||X.result;if(!Array.isArray(le)){me.toast.error("Expected an array in response (data, record, or result).");return}((R=o.type)==null?void 0:R.toLowerCase())==="datagrid"?g("dataColumns",le):g("options",le)}catch(Z){const X=((te=(H=Z==null?void 0:Z.response)==null?void 0:H.data)==null?void 0:te.message)||(Z==null?void 0:Z.message)||"Unable to load options";me.toast.error(X)}finally{d(!1)}},[o.type,g,w.apiUrl]),se=["manual","api","sheet"];function be(){c==="api"&&I()}const pe=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:se==null?void 0:se.map(R=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:H=>u(H.target.value),value:R})," ",i.jsxs("span",{children:[R," options"]})]},R))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(G,{label:"Load Options from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]}),i.jsx("button",{onClick:be,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),i.jsx(ga,{})]}),c==="sheet"&&i.jsx("div",{className:"mb-4",children:i.jsx(rn,{isFloating:!0,label:"Load options form sheet (csv, xlsx)",setValue:g,name:"options"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Parent Options "}),j==null?void 0:j.map((R,H)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Label",name:`options.${H}.label`,register:v,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Value",name:`options.${H}.value`,register:v,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("button",{disabled:j.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>Y(H),children:i.jsx(V,{icon:"iconamoon:sign-times-fill"})})]},R.id))," ",i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>L({label:"",value:"",id:ve.v4()}),children:[i.jsx(V,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),o.type.toLowerCase()==="cascadeselect"&&i.jsxs(i.Fragment,{children:[i.jsx("hr",{className:"my-5"}),i.jsxs("div",{children:[" ",i.jsx("h3",{className:"mb-4 text-sm text-gray-500",children:"Child Options "}),W==null?void 0:W.map((R,H)=>i.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Label",name:`options1.${H}.label`,register:v,errors:y,element:o,placeholder:"Label",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Value",name:`options1.${H}.value`,register:v,errors:y,element:o,placeholder:"Value",isFloating:!0})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Key",name:`options1.${H}.key`,register:v,errors:y,element:o,placeholder:"Key",isFloating:!0})}),i.jsx("button",{disabled:W.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>M(H),children:i.jsx(V,{icon:"iconamoon:sign-times-fill"})})]},R.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>K({label:"",value:"",key:"",id:ve.v4()}),children:[i.jsx(V,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]}),fe=()=>i.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[i.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:se==null?void 0:se.map(R=>i.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[i.jsx("input",{type:"radio",name:"optionType",onChange:H=>u(H.target.value),value:R,checked:R===c})," ",i.jsxs("span",{children:[R," options"]})]},R))}),c==="api"&&i.jsxs("div",{className:"mb-4",children:[i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[i.jsx(G,{label:"Load Columns from Api",name:"apiUrl",errors:y,register:v,className:"!w-full",placeholder:"https://example.com/columns",isFloating:!0}),r&&i.jsx("div",{className:"absolute w-4 h-4 mt-1 border-2 border-blue-500 rounded-full border-t-transparent animate-spin right-3 top-1/2"})]})," ",i.jsx("button",{onClick:be,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(rn,{isFloating:!0,label:"Load columns form sheet (csv, xlsx)",setValue:g,name:"dataColumns"})}),T==null?void 0:T.map((R,H)=>i.jsxs("div",{className:"flex items-center gap-x-4 ",children:[i.jsx("div",{className:"min-w-[140px]",children:i.jsx(Ce,{label:H===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"}],register:v,name:`dataColumns.${H}.type`,setValue:g,trigger:x,value:w.dataColumns[H].type})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:H===0?"Field key":"",name:`dataColumns.${H}.field`,register:v,errors:y,element:o,placeholder:"fieldKey"})}),i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:H===0?"Display header":"",name:`dataColumns.${H}.headerName`,register:v,errors:y,element:o,placeholder:"header"})}),i.jsx("button",{disabled:T.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>O(H),children:i.jsx(V,{icon:"iconamoon:sign-times-fill"})})]},R.id)),i.jsxs("div",{children:[" ",i.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>B({headerName:"",field:"",editable:!0,id:ve.v4(),type:"text",validate:!1}),children:[i.jsx(V,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),xe=m.useCallback(async()=>{const R=ue("token"),{status:H,data:te}=await Ne.get(w.url,{headers:{Authorization:`Bearer ${R}`}});H===200&&g("options",(te==null?void 0:te.data)||te)},[g,w.url]);return m.useEffect(()=>{o.type==="document"&&w.url&&xe()},[w.url,o.type,xe]),i.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default select-none ",draggable:"true",onDragStart:R=>R.preventDefault(),children:i.jsxs("div",{className:"w-full lg:w-2/3 xl:w-2/5 bg-white h-screen shadow-xl relative flex flex-col items-center select-",draggable:"true",onDragStart:R=>R.preventDefault(),children:[i.jsx("button",{className:"bg-white h-10 w-10 flex justify-center items-center absolute top-1 -left-12 rounded-lg hover:bg-gray-50",onClick:n,children:i.jsx(V,{icon:"tabler:x",iconClass:"text-xl"})}),i.jsx("div",{className:"w-full pt-4",children:i.jsx(ea,{tabs:s,setActiveTab:l,activeTab:t,className:"justify-start !text-left",btnClass:" !text-left"})}),i.jsxs("form",{onSubmit:p(Q),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:[mi.includes(o.inputType)&&i.jsx(i.Fragment,{children:i.jsx(G,{label:"Value",name:"value",register:v,errors:y,element:o})}),!mi.includes(o.inputType)&&!We.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsx(G,{label:"Label",name:"inputLabel",register:v,errors:y,element:o})," ",o.type.toLowerCase()==="cascadeselect"&&i.jsx(G,{label:"Child Label",name:"childLabel",register:v,errors:y,element:o})]}),da.includes(o.inputType)&&i.jsx(G,{label:"Placeholder",name:"placeholder",register:v,errors:y,element:o}),ta.includes(o.inputType)&&i.jsx(G,{label:"Prefix",name:"prefix",register:v,errors:y,element:o}),ca.includes(o.inputType)&&i.jsxs("div",{className:"grid gap-y-4",children:[i.jsx(pa,{}),i.jsx(G,{label:"Api Url",name:"url",register:v,errors:y,element:o}),i.jsx(Ce,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:v,name:"method",setValue:g,trigger:x,value:f("method")}),i.jsx(Ce,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:v,name:"responseType",setValue:g,trigger:x,value:f("responseType")})]}),ma.includes(o.inputType)&&i.jsx(va,{onChange:R=>{g("denominators",R)},value:f("denominators")}),!mi.includes(o.inputType)&&!We.includes(o.inputType)&&i.jsx(G,{label:"Short Description",name:"description",register:v,errors:y,element:o}),o.type.toLowerCase()==="date"&&i.jsxs(i.Fragment,{children:[i.jsx(Ce,{label:"Date Format",options:sa,register:v,name:"dateFormat",setValue:g,trigger:x,value:f("dateFormat")}),i.jsx(G,{label:"Allow Range",name:"canHaveDateRange",register:v,errors:y,element:o,type:"checkbox"}),(w==null?void 0:w.canHaveDateRange)&&i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsx($e,{name:"minDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select min date"}),i.jsx($e,{name:"maxDate",value:w==null?void 0:w.minDate,onGetValue:g,placeholder:"Select max date",minDate:w==null?void 0:w.minDate})]}),i.jsx(G,{label:"Allow Year Picker",name:"allowYearPicker",register:v,errors:y,element:o,type:"checkbox"})]}),o.type.toLowerCase()==="country"&&i.jsx(G,{label:"Allow States",name:"showState",register:v,errors:y,element:o,type:"checkbox"}),o.type.toLowerCase()==="selectfield"&&i.jsx(Ce,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:v,name:"selectType",setValue:g,trigger:x,value:f("selectType")}),o.type.toLowerCase()==="grid"&&i.jsx(G,{label:"Number of columns",name:"columns",register:v,errors:y,element:o}),o.type.toLowerCase()==="document"&&i.jsxs("div",{className:"grid gap-y-6",children:[i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(G,{label:"Document Options Url",name:"url",register:v,errors:y,element:o})," ",i.jsx(fa,{})]}),i.jsxs("div",{className:"grid gap-y-1",children:[i.jsx(G,{label:"Document Validation Url",name:"validationUrl",register:v,errors:y,element:o}),i.jsx(xa,{})]}),i.jsx("div",{className:"grid gap-y-1",children:i.jsx(G,{label:"Signature Page Url",name:"signatureLink",register:v,errors:y,element:o})})]}),o.type.toLowerCase()==="datagrid"&&fe(),o.type.toLowerCase()==="file"&&i.jsxs(i.Fragment,{children:[i.jsx(G,{label:"Allow Multiple Uploads",name:"isMultiple",register:v,errors:y,element:o,type:"checkbox"}),i.jsx(ri,{element:{options:ba,id:"acceptedFiles",value:w==null?void 0:w.acceptedFiles},validationData:{register:v,setValue:g,trigger:x,watch:f},placeholder:"Choose file types"})]}),ua.includes(o.inputType)&&pe(),i.jsxs("div",{children:[i.jsx("div",{className:"w-[150px] mb-4",children:i.jsx(G,{label:"Toggle Visibility",name:"isHidden",register:v,errors:y,element:o,type:"checkbox"})})," ",w.isHidden&&i.jsx(wa,{register:v,setValue:g,trigger:x,watch:f,id:o==null?void 0:o.id})]})]}),!We.includes(o.type.toLowerCase())&&t==="validation"&&i.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Required",name:"isRequired",register:v,errors:y,element:o,type:"checkbox"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"requiredMessage",register:v,errors:y,element:o})})]}),la.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Min Length",name:"minLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"minLengthMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Max Length",name:"maxLength",register:v,errors:y,element:o,type:"number"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"maxLengthMessage",register:v,errors:y,element:o})})]})]}),ra.includes(o.inputType)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Min Amount",name:"minAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"minAmountMessage",register:v,errors:y,element:o})})]}),i.jsxs("div",{className:"flex items-center gap-x-6",children:[i.jsx("div",{className:"w-[150px]",children:i.jsx(G,{label:"Max Amount",name:"maxAmount",register:v,errors:y,element:o,type:"amount"})})," ",i.jsx("div",{className:"flex-1",children:i.jsx(G,{label:"Error message text",name:"maxAmountMessage",register:v,errors:y,element:o})})]})]})]})]})]}),i.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest editor_option__cancel",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!_||k,style:{background:(h==null?void 0:h.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!_||k?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!_||k?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:k?"Saving...":"Save"})]})]})]})})},vi=m.memo(({state:e,element:n,children:o})=>{const[s,a]=m.useState(!1),{removeElement:t,duplicateElement:l}=m.useContext(de),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(_a,{isOpen:s,onClose:()=>a(!1),element:n}),i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("span",{children:[" ",n.inputLabel&&i.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",r&&i.jsxs("span",{className:"text-gray-400 text-xs",children:["(",r==null?void 0:r.toLowerCase(),")"]})]})]}),e==="edit"&&i.jsxs("span",{className:"flex items-center gap-x-3",children:[!n.gridPosition&&i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:()=>l(n==null?void 0:n.id,n.sectionId),title:"Duplicate",children:i.jsx(V,{icon:"tabler:copy",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:()=>a(!0),title:"Edit",children:i.jsx(V,{icon:"circum:edit",iconClass:"text-base"})}),i.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80",onClick:d,title:"Remove",children:i.jsx(V,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),o]})});vi.displayName="ElementContainer";function Na({element:e,validationData:n}){const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:l}=n||{};let r;return t&&(r=t()[e.id]),i.jsx(G,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:o,trigger:s,setValue:a,value:r,prefix:e.prefix,disabled:l})}function ja(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 Ca=({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 Ma({element:e,validationData:n}){var w;const{register:o=()=>({}),setValue:s,watch:a}=n||{},[t,l]=m.useState(),[r,d]=m.useState(!1),[c,u]=m.useState(!1),[h,v]=m.useState(""),p=a&&a(e==null?void 0:e.id);m.useEffect(()=>{l(p)},[p]);const[A,g]=m.useState("");m.useEffect(()=>{o(e.id)},[e.id,o]);const{url:f,method:x,responseType:y}=e||{},_={headers:{Authorization:`Bearer ${ue("token")}`}},S=m.useCallback(async j=>{var L,Y,W,K,M,T,B,O,Q,q,oe;if(!(!f||!x)){d(!0);try{let I;if(x.toLowerCase()==="get"){const se=`${f}?value=${j}`;I=await Ne.get(se,_)}else if(x.toLowerCase()==="post")I=await Ne.post(f,{value:j},_);else throw new Error("Unsupported HTTP method");I.status===200&&((((Y=(L=I==null?void 0:I.data)==null?void 0:L.data)==null?void 0:Y.status)||((W=I==null?void 0:I.data)==null?void 0:W.status))===!0?(u(!0),y==="string"?v(((M=(K=I==null?void 0:I.data)==null?void 0:K.data)==null?void 0:M.description)||((T=I==null?void 0:I.data)==null?void 0:T.description)||"Validation successful"):g(((O=(B=I==null?void 0:I.data)==null?void 0:B.data)==null?void 0:O.description)||((Q=I==null?void 0:I.data)==null?void 0:Q.description)||{})):(console.error("Invalid input:",j),v("Unable to validate input"),u(!1)))}catch(I){console.error("Error validating input:",I),v(((oe=(q=I==null?void 0:I.response)==null?void 0:q.data)==null?void 0:oe.message)||"Unable to validate input"),u(!1)}finally{d(!1)}}},[x,y,f]);return m.useEffect(()=>{if(t){const j=setTimeout(()=>{S(t)},700);return()=>clearTimeout(j)}},[S,t]),i.jsxs("div",{children:[i.jsxs("div",{className:"relative flex items-center",children:[i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:F("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),onChange:j=>{l(j.target.value),s(e==null?void 0:e.id,j.target.value)},disabled:n==null?void 0:n.isReadOnly}),i.jsxs("span",{className:"absolute right-0",children:[r&&i.jsxs("span",{children:[" ",i.jsxs("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})]}),c&&!r&&i.jsx("span",{className:"block pr-3 text-lg text-green-600",children:i.jsx(V,{icon:"gg:check-o"})})]})]}),h&&y==="string"&&i.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:h}),y==="object"&&i.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(w=Object.entries(A))==null?void 0:w.map(([j,L])=>i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsxs("span",{className:"font-semibold",children:[j,":"]}),ja(L)?i.jsx(Ca,{imageUrl:L}):i.jsx("span",{children:String(L)})]},j))})]})}function Ta({onGetTotal:e,readOnly:n,defaultValue:o,denominators:s}){const[a,t]=m.useState([...o]);function l(c,u){t(h=>{const v=[...h];return v[u]={...v[u],value:c},v})}function r(c,u){return parseFloat(c)*parseFloat(u)||0}const d=m.useMemo(()=>a.reduce((c,u)=>{const h=r(u.key,u.value);return c+h},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,h)=>({key:u.value,value:Array.isArray(o)&&o[h]?o[h].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 h,v;return i.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[i.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:i.jsx("span",{className:"",children:(h=parseFloat(c.key))==null?void 0:h.toLocaleString()})}),i.jsx("div",{className:"border-r px-4 py-1",children:i.jsx("span",{children:i.jsx(Ke,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:p=>l(p,u),disabled:n,allowNegativeValue:!1})})}),i.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:i.jsx("span",{children:(v=r(c.key,c.value))==null?void 0:v.toLocaleString()})})]},u+"index")}),i.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[i.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),i.jsx("div",{className:"px-4 py-3",children:d==null?void 0:d.toLocaleString()})]})]})})}function Ea({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 Ba({element:e}){return i.jsx("div",{className:F("py-6",e==null?void 0:e.customClass)})}function La({element:e}){return i.jsx("div",{children:i.jsx("hr",{className:F("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function Pa({element:e,validationData:n}){const{register:o=()=>({})}=n||{};return i.jsx("div",{children:i.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...o(e==null?void 0:e.id)})})}function Oa({element:e,state:n}){return i.jsx(i.Fragment,{children:i.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&i.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function Ia({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 h=e[u.field],v=u.editable&&!o,p=c(u.field),{isValidating:A,result:g}=r(e.id,u.field);let f="border-gray-300";u.validate&&((g==null?void 0:g.isValid)===!1?f="border-red-500 bg-red-50":(g==null?void 0:g.isValid)===!0&&(f="border-green-500 bg-green-50"));const x=`w-full px-2 py-1 border rounded outline-none ${f}`;return i.jsx("td",{title:o?"":"Double click to edit",className:"px-3 py-1 border",onDoubleClick:()=>v&&a({rowId:e.id,field:u.field}),children:v&&p?i.jsxs("div",{className:"relative",children:[u.type==="number"?i.jsx(Ke,{value:h,decimalsLimit:6,allowNegativeValue:!1,className:x,onValueChange:k=>t(k,e.id,u.field),onBlur:()=>{a(null),l(h,e.id,u.field,u)},autoFocus:!0}):u.type==="checkbox"?i.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(k=>{const _=k==="yes",S=`radio-${e.id}-${String(u.field)}-${k}`;return i.jsxs("label",{htmlFor:S,className:"flex items-center gap-1 cursor-pointer",children:[i.jsx("input",{id:S,type:"radio",name:`boolean-${e.id}-${String(u.field)}`,checked:h===_,onChange:()=>t(_,e.id,u.field)}),i.jsx("span",{className:"text-sm",children:_?"Yes":"No"})]},k)})}):i.jsx("input",{type:"text",value:String(h!=null?h:""),onChange:k=>t(k.target.value,e.id,u.field),onBlur:()=>{a(null),l(h,e.id,u.field,u)},className:x,autoFocus:!0}),A&&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&&g?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{children:[String(h!=null?h:"")," ",g.data&&`[${g.data}]`]}),g.isValid?i.jsx("span",{className:"text-xs text-green-600",children:"✓"}):i.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(y=g.error)!=null?y:"",children:"✗"})]}):u.type==="checkbox"?i.jsx("span",{className:"block py-1 text-gray-700",children:h===!0?"Yes":h===!1?"No":""}):i.jsx("span",{className:"block py-1 text-gray-700 cursor-pointer",children:String(h!=null?h:"")})},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(V,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const Da=m.memo(Ia);function Ka({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=document.getElementById("form"),u=m.useMemo(()=>{const g=(c==null?void 0:c.getBoundingClientRect().width)||0;return g&&g-48},[c]);m.useEffect(()=>{t(g=>JSON.stringify(g)!==JSON.stringify(e)?e:g)},[e]),m.useEffect(()=>{n==null||n(a)},[a,n]),m.useEffect(()=>{const g=f=>{d.current&&!d.current.contains(f.target)&&r(null)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[]);const h=m.useCallback((g,f,x)=>{t(y=>y.map(k=>k.id===f?{...k,[x]:g}:k))},[]),v=m.useCallback(()=>{const g=ve.v4(),f=s.reduce((x,y)=>(x[y.field]=y.field==="id"?g:"",x),{});t(x=>[...x,{id:g,...f}])},[s]),p=m.useCallback(g=>{t(f=>f.filter(x=>x.id!==g))},[]),A=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:v,type:"button",className:"px-2 py-1 mb-3 text-xs text-white bg-gray-600 rounded hover:bg-gray-700",children:"Add Row"})}),i.jsx("div",{className:"w-full max-w-full overflow-x-auto",style:{maxWidth:`${u}px`},children:i.jsxs("table",{className:"min-w-max w-full text-sm border-collapse rounded table-auto bg-gray-50",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"bg-gray-100",children:[s.map((g,f)=>{var x;return i.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border whitespace-nowrap",children:[(x=g.headerName)!=null?x:String(g.field),g.validate&&i.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(g.id)}-${f}`)}),!o&&i.jsx("th",{className:"w-10 px-2 py-2 border"})]})}),i.jsx("tbody",{children:a.length>0?a.map(g=>i.jsx(Da,{row:g,columns:s,isReadOnly:o,editingCell:l,setEditingCell:r,handleCellChange:h,debouncedValidate:()=>{},getValidationStatus:A,deleteRow:p},g.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 Ga({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(Ka,{value:l,onChange:r,columns:e==null?void 0:e.dataColumns,isReadOnly:t})}const cn=({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:h=!1,subText:v,labelClass:p="",loading:A,disabled:g})=>{const[f,x]=m.useState(u?[]:null),y=F("custom-select__control",e),k=m.useMemo(()=>n,[n]);return m.useEffect(()=>{const _=n==null?void 0:n.find(S=>{var w;return typeof S.value=="string"&&typeof d=="string"?S.value.toLowerCase()===d.toLowerCase():typeof S.value=="object"&&typeof d=="object"?((w=S.value)==null?void 0:w.id)===(d==null?void 0:d.id):S.value===d});x(_||null)},[d,n]),m.useEffect(()=>{f&&t&&a&&(t(l,f==null?void 0:f.value),a(l),c==null||c(l))},[l,f]),i.jsxs("div",{className:"custom-select",children:[r&&!h&&i.jsx("label",{className:"custom-select__label",children:r}),h&&r&&i.jsx("label",{className:F("custom-select__floating-label",p),children:r}),i.jsx(D.Listbox,{value:f,onChange:x,multiple:u,disabled:g,children:i.jsxs("div",{className:"custom-select__wrapper",children:[i.jsxs(D.Listbox.Button,{className:y,disabled:g,children:[A?i.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):i.jsx("span",{className:"custom-select__value",children:(f==null?void 0:f.label)||i.jsx("span",{className:"custom-select__placeholder",children:o})}),i.jsx("span",{className:"custom-select__icon",children:i.jsx(V,{icon:"lucide:chevron-down"})})]}),i.jsx(D.Transition,{as:m.Fragment,leave:"custom-select__transition",children:i.jsx(D.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:k==null?void 0:k.map((_,S)=>i.jsx(D.Listbox.Option,{value:_,className:({active:w})=>F("custom-select__option",w&&"custom-select__option--active"),children:({selected:w})=>i.jsx("span",{className:F("custom-select__option-label",w&&"custom-select__option--selected"),children:_.label})},S))})})]})}),v&&!s&&i.jsx("p",{className:"custom-select__subtext",children:v}),s&&i.jsx("span",{className:"custom-select__error",children:s.message})]})},Ra=({element:e,validationData:n})=>{var g;const{register:o=()=>({}),trigger:s,setValue:a,watch:t,isReadOnly:l}=n||{},r=(g=e==null?void 0:e.id)!=null?g:"cascadeValue",[d,c]=m.useState(""),[u,h]=m.useState(""),v=(f,x)=>{const y=f&&x?`${f}_${x}`:"";a==null||a(r,y),s==null||s(r)},p=(f,x)=>{f==="first"?(c(x),h(""),v(x,"")):(h(x),v(d,x))};m.useEffect(()=>{if(t){const f=t(r);if(f!=null&&f.includes("_")){const[x,y]=f.split("_");c(x),h(y)}}},[t,r]);const A=m.useMemo(()=>{var f;return(f=e.options1)==null?void 0:f.filter(x=>x.key===d)},[e.options1,d]);return!e.options||!e.options1?null:i.jsxs("div",{children:[i.jsx("input",{type:"hidden",...o(r)}),i.jsx("div",{className:"relative",children:i.jsx(cn,{setValue:(f,x)=>p("first",x),options:e.options,name:`${r}`,register:o,value:d})}),d&&i.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&i.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),i.jsx(cn,{setValue:(f,x)=>p("second",x),options:A,name:`${r}`,register:o,value:u})]})]})},za=({value:e=0,max:n=5,readOnly:o=!1,onChange:s,size:a=24,className:t="",element:l,validationData:r})=>{var x;const{register:d=()=>({}),trigger:c,setValue:u,watch:h,isReadOnly:v}=r||{},p=(x=h==null?void 0:h(l.id))!=null?x:0,[A,g]=m.useState(null);m.useEffect(()=>{p==null&&(u==null||u(l.id,e))},[]);const f=y=>{if(!o&&!v){const k=y+1;u==null||u(l.id,k),c==null||c(l.id),s==null||s(k)}};return i.jsxs("div",{className:`flex gap-1 ${t}`,children:[i.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(y,k)=>{const _=A!==null?k<=A:k<p;return i.jsx(tn,{icon:_?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${_?"text-yellow-400":"text-gray-300"}`,width:a,height:a,onMouseEnter:()=>!(o||v)&&g(k),onMouseLeave:()=>!(o||v)&&g(null),onClick:()=>f(k)},k)})]})};function mn({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 A;if(typeof r=="string"&&r.includes(",")){const[g,f]=(A=r.split(","))==null?void 0:A.map(x=>x.trim());return{country:f,state:g}}return{country:r,state:""}},[r]),u=m.useRef(r),h=m.useMemo(()=>{var A,g;return d?((g=(A=Ve.find(f=>f.name===d))==null?void 0:A.states)==null?void 0:g.map(f=>({label:f.name,value:f.name})))||[]:[]},[d]),v=(A,g)=>{const x=(g==null?void 0:g.value)||"";s&&x!==u.current&&(s(e.id,x),a==null||a(e.id),u.current=x)},p=(A,g)=>{const f=(g==null?void 0:g.value)||"",x=f?`${f}, ${d}`:d;s&&x!==u.current&&(s(e.id,x),a==null||a(e.id),u.current=x)};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(ui,{options:e.options,onGetValue:v,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),h.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(ui,{options:h,onGetValue:p,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function Ha({element:e,validationData:n}){const{register:o=()=>({}),isReadOnly:s}=n||{},{validationUrl:a,documentObj:t,signatureLink:l}=e,r=m.useMemo(()=>ue("config"),[]),[d,c]=m.useState(!1),[u,h]=m.useState(!1),v=m.useCallback(async()=>{var p,A;if(!(!a||!t))try{h(!0);const f={headers:{Authorization:`Bearer ${ue("token")}`}},{data:x}=await Ne.get(`${a}/${t}`,f),y=!!((A=(p=x==null?void 0:x.data)==null?void 0:p.isSigned)!=null?A:x!=null&&x.isSigned);return c(y),y}catch(g){console.error("Failed to check sign status",g)}finally{h(!1)}},[a,t]);return m.useEffect(()=>{let p=null;return!d&&t&&a&&(async()=>{await v()||(p=setInterval(async()=>{await v()&&p&&clearInterval(p)},2e3))})(),()=>{p&&clearInterval(p)}},[v,d,t,a]),i.jsxs("div",{className:"flex items-center gap-x-2",children:[i.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:F("field-control",e.customClass),...o(e.id),disabled:s}),i.jsx("a",{href:d?"#":l,children:i.jsxs("button",{type:"button",onClick:v,disabled:u||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:F("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(V,{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 pi=[{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 Fa({label:e,placeholder:n,classLabel:o,isRequired:s,isOptional:a,name:t,value:l,error:r,disabled:d,readOnly:c,horizontal:u,description:h,validate:v,onChange:p,onError:A}){const[g,f]=m.useState(""),[x,y]=m.useState(null),[k,_]=m.useState(""),S=m.useMemo(()=>{var M;return(M=pi==null?void 0:pi.slice().sort((T,B)=>T.label.localeCompare(B.label)))==null?void 0:M.map(T=>({...T,phone:`+${T.phone}`}))},[]),w=m.useMemo(()=>g?S.filter(M=>`${M.label} ${M.phone}`.toLowerCase().includes(g.toLowerCase())):S,[g,S]),j=(x==null?void 0:x.min)||10,L=(x==null?void 0:x.max)||10,Y=()=>k?`${(x==null?void 0:x.phone)||"+234"}-${k}`:"",W=M=>{if(!M)return{code:"+234",number:""};const T=M.split(/[-\s]/);return{code:T[0],number:T.slice(1).join(" ")}};m.useEffect(()=>{if(l){const M=W(l);y(S.find(T=>T.phone===M.code)||S[0]),_(M.number)}},[l,S]);const K=m.useMemo(()=>{if(r)return r;const M=k.length;return s&&M===0?"Phone number is required":M>0&&!/^\d+$/.test(k)?"Phone number must contain only digits":M>0&&M<j?`Minimum length is ${j}`:M>L?`Maximum length is ${L}`:""},[r,k,j,L,s]);return m.useEffect(()=>{p==null||p(Y()),A==null||A(K||null)},[k,x,K]),i.jsxs("div",{className:`relative formGroup ${K&&!c?"has-error":""} ${u?"flex":""} ${!K&&k.length>0&&!c?"is-valid":""}`,children:[e&&i.jsxs("label",{htmlFor:t,className:`${o} ${u?"flex-0 mr-6 md:w-[100px] w-[60px] break-words":""} flex items-center gap-x-1 input-label text-sm text-[#1B2B41B8]`,children:[e," ",s&&i.jsx("span",{className:"text-red-500",children:"*"}),a&&i.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),i.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[i.jsx(V,{icon:"lucide:phone-call"}),i.jsx(D.Combobox,{value:x,onChange:y,children:i.jsxs("div",{className:"relative",children:[i.jsx(D.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:M=>(M==null?void 0:M.phone)||"+234",placeholder:"+234",onChange:M=>f(M.target.value)}),i.jsx(D.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:i.jsx(V,{icon:"lucide:chevron-down"})}),i.jsx(D.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:w==null?void 0:w.map((M,T)=>i.jsxs(D.Combobox.Option,{value:M,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[M.phone," - ",M.label]},`${M.code}+ ${T}`))})]})}),i.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[i.jsx("input",{type:"tel",inputMode:"numeric",value:k,disabled:d,readOnly:c,onChange:M=>{const T=M.target.value.replace(/\D/g,"");_(T)},placeholder:n,className:"w-full px-3 outline-none"}),i.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!K&&k.length>0&&!c&&i.jsx("span",{className:"text-green-500",children:i.jsx(V,{icon:"bi:check-lg"})})})]})]}),h&&i.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:h})]})}function Va({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(Fa,{placeholder:e.placeholder,label:"",name:e.id,value:d,readOnly:t,disabled:t,onError:c=>{c?l==null||l(e.id,{type:"manual",message:c}):r(e.id)},onChange:c=>{c&&(s==null||s(e.id,c))}})}function Ua({element:e,validationData:n}){const{register:o=()=>({}),watch:s}=n||{};let a;return s&&(a=s()[e.id]),i.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&i.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",className:F("field-control",e==null?void 0:e.customClass),...o(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly}),a&&i.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:i.jsx("a",{title:"Visit link",target:"_blank",className:"hover:underline text-blue-700",href:a,children:a})})]})}const bn={textField:Qe,longText:Xo,selectField:Qo,multiSelect:ri,numberField:Qe,amountField:Na,date:zn,password:qo,checkbox:$o,radio:Yo,email:Qe,file:Jo,dataGrid:Ga,section:Zo,validateInput:Ma,tableInput:Ea,spacer:Ba,divider:La,header:Pa,basicText:Oa,phoneField:Va,cascadeSelect:Ra,rating:za,country:mn,bank:mn,document:Ha,link:Ua},vn="edit",pn=(e,n)=>{const o=bn[e.type];return o?i.jsx(vi,{element:e,state:vn,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:vn,sectionId:n})]})}):null},gi=({col:e,children:n,customClass:o})=>i.jsx("div",{className:F("w-full bg-white",o),style:{gridColumn:e},children:n}),Wa=({element:e,sectionId:n,children:o,customClass:s,state:a})=>{const{formData:t,addElement:l,setIsDragging:r}=m.useContext(de),d=m.useMemo(()=>Array.from({length:e.columns}),[e.columns]),c=m.useCallback(v=>{v.preventDefault(),v.stopPropagation(),v.dataTransfer.dropEffect="move"},[]),u=m.useCallback((v,p)=>{var A,g;v.preventDefault(),r(!1);try{const f=v.dataTransfer.getData("properties");if(!f)return;const x=JSON.parse(f);if((x==null?void 0:x.type)==="grid")return;const y=p+1;if((g=(A=t.find(S=>S.id===n))==null?void 0:A.questionData)==null?void 0:g.some(S=>{var w;return S.gridId===e.id&&((w=S.gridPosition)==null?void 0:w.col)===y}))return;const _={...x,id:ve.v4(),sectionId:n,gridId:e.id,gridPosition:{col:y}};l(_,n)}catch(f){console.error("Drop failed in grid:",f),r(!1)}},[l,e.id,t,n,r]),h=(v,p,A)=>{const g=Array.isArray(o)&&o.find(f=>{var x;return((x=f==null?void 0:f.props)==null?void 0:x.col)===v+1});return i.jsx("div",{children:i.jsx("div",{id:v.toString(),onDrop:f=>u(f,v),onDragOver:c,className:F("border rounded-lg min-h-[110px] bg-white ","flex items-center justify-center text-gray-400 transition-colors",`${A==="edit"?"p-3":""}`,p),children:g||i.jsx("span",{children:A==="edit"&&i.jsx(V,{icon:"ph:plus-bold"})})})},v)};return i.jsx("div",{className:"relative w-full",children:i.jsx("div",{className:"grid w-full gap-3",style:{gridTemplateColumns:`repeat(${e.columns}, 1fr)`},children:d==null?void 0:d.map((v,p)=>h(p,s,a))})})},hi=m.memo(Wa),Ja="edit";function qa({elementData:e,sectionId:n}){const{formData:o,updateElementPosition:s,isDragging:a,setIsDragging:t,addElementInPosition:l}=m.useContext(de),[r,d]=m.useState(null),[c,u]=m.useState(null),h=m.useMemo(()=>{var k;return((k=o.find(_=>_.id===n))==null?void 0:k.questionData)||[]},[o,n]),v=m.useCallback((k,_)=>{k.dataTransfer.setData("properties",_),d(_)},[]),p=m.useCallback((k,_)=>{k.preventDefault(),k.stopPropagation(),u(_)},[]),A=m.useCallback(k=>{k.preventDefault(),k.stopPropagation();const _=k.dataTransfer.getData("properties"),S=k.currentTarget.id;if(!S||_===S)return;const w=h.findIndex(W=>W.id===_),j=h.findIndex(W=>W.id===S);if(w===-1||j===-1)return;const L=[...h],[Y]=L.splice(w,1);L.splice(j,0,Y),s(L,n),d(null)},[h,n,s]),g=m.useCallback((k,_)=>{k.preventDefault(),t(!1);try{const S=JSON.parse(k.dataTransfer.getData("properties"));if((S==null?void 0:S.type)==="section")return;const w={...S,id:ve.v4(),sectionId:n};l(w,n,_)}catch(S){console.error("Drop error:",S)}},[l,n,t]),f=m.useCallback(k=>i.jsx("div",{className:"transition rounded hover:bg-blue-300",onDragOver:_=>_.preventDefault(),onDrop:_=>g(_,k),onDragEnd:()=>t(!1),children:i.jsx("div",{className:"bg-blue-50 rounded p-6 h-[60px] border-2 border-blue-300 border-dashed flex items-center justify-center text-gray-400 opacity-70",children:i.jsx(V,{icon:"octicon:plus-16"})})},`drop-${k}`),[g,t]),x=m.useCallback(k=>i.jsx("div",{id:k.id,className:F("cursor-move border p-4 w-full rounded-lg transition-colors bg-white",{"bg-gray-100":r===k.id,"border-dashed border-blue-300":r&&r!==k.id}),draggable:!0,onDragStart:_=>v(_,k.id),onDragOver:_=>p(_,k.id),onDrop:A,onDragEnd:()=>d(null),children:pn(k,n)},k.id),[r,A,p,n,v]),y=m.useMemo(()=>(e==null?void 0:e.reduce((k,_)=>(_.gridId&&(k[_.gridId]=k[_.gridId]||[],k[_.gridId].push(_)),k),{}))||{},[e]);return e!=null&&e.length?i.jsx("div",{className:"relative grid w-full h-full grid-cols-1 gap-4",children:e==null?void 0:e.map((k,_)=>{if(k.type==="grid"){const S=y[k.id]||[];return i.jsx("div",{draggable:!0,onDragStart:w=>v(w,k.id),onDragOver:w=>p(w,k.id),onDrop:A,onDragEnd:()=>d(null),className:"w-full p-4 transition-colors bg-white border rounded-lg cursor-move",children:i.jsx(vi,{element:k,state:"edit",children:i.jsx(hi,{element:k,sectionId:n,state:Ja,children:S==null?void 0:S.map(w=>{var j;return i.jsx(gi,{col:(j=w.gridPosition)==null?void 0:j.col,children:pn(w,n)},w.id)})})})},k.id)}return k.gridId?null:i.jsxs("div",{className:F("group relative grid gap-y-[6px]",k.elementClass),children:[a&&c===k.id&&f(_),i.jsx("div",{className:"group",children:x(k)}),a&&c===k.id&&f(_+1)]},k.id)})}):i.jsx("div",{onDragOver:k=>k.preventDefault(),onDrop:k=>g(k,0),onDragEnd:()=>t(!1),className:"w-full h-full flex items-center justify-center text-gray-400 min-h-[200px] p-10 col-span-2 border border-dashed border-gray-300 rounded-lg",children:"Drag or click an element to display"})}const Ya=m.memo(qa),Za=E.object({title:E.string(),description:E.string()}).required(),fi=ue("config"),$a=({isOpen:e,onClose:n,section:o})=>{const{updateSection:s}=m.useContext(de),{register:a,handleSubmit:t,formState:{errors:l,isSubmitting:r,isValid:d},reset:c}=ke.useForm({resolver:ci(Za),defaultValues:o});if(m.useEffect(()=>{e||c()},[e,c]),!e)return null;const u=h=>{s(h,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(V,{icon:"tabler:x"})})]}),i.jsxs("form",{onSubmit:t(u),className:"w-full",children:[i.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[i.jsx(G,{label:"Title",name:"title",register:a,errors:l}),i.jsx(G,{label:"Description",name:"description",register:a,errors:l})]}),i.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[i.jsx("button",{type:"button",onClick:n,className:"flex-1 px-4 py-2.5 bg-white border border-[#D0D5DD] rounded-lg shadow-xs font-semibold text-[#344054] font-onest",children:"Cancel"}),i.jsx("button",{type:"submit",disabled:!d||r,style:{background:(fi==null?void 0:fi.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!d||r?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!d||r?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:r?"Saving...":"Save"})]})]})]})})},Qa=()=>{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:h}=m.useContext(de);m.useEffect(()=>{var f;d(((f=l[0])==null?void 0:f.id)||null)},[]);const v=m.useCallback(f=>{f.preventDefault(),f.dataTransfer.dropEffect="move",s.current&&(s.current.scrollTop=s.current.scrollHeight)},[]);function p(f){u.includes(f)?h(x=>x.filter(y=>y!==f)):h(x=>[...x,f])}function A(f){o.current=f,n(!0)}const g=ue("config");return i.jsxs("div",{ref:s,className:"relative flex flex-col h-full px-6 pb-5 mx-auto gap-x-4",children:[e&&i.jsx($a,{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((f,x)=>i.jsx("div",{className:"bg-white group cursor-pointer rounded ",children:i.jsxs("div",{className:`border border-gray-100 rounded px-4 shadow-[rgba(149,157,165,0.2)_0px_2px_4px] transition-colors duration-200
49
49
  ${c===f.id?"border-dashed border-blue-400 bg-[#f7f8fa]":""} ${u.includes(x)?"min-h-[300px] pb-6 ":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{onClick:()=>d(f.id),className:"flex-1 h-full py-4 cursor-pointer",children:i.jsx("h2",{className:"font-medium",children:f.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:()=>A(f),children:i.jsx(V,{icon:"fluent:edit-28-regular"})}),l.length>1&&i.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>a(f.id),children:i.jsx(V,{icon:"lets-icons:trash-duotone-line"})}),i.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>p(x),children:i.jsx(V,{icon:u.includes(x)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(f==null?void 0:f.description)&&u.includes(x)&&i.jsx("p",{className:"mt-2 text-sm text-gray-600 text-gray-60",children:f==null?void 0:f.description}),u.includes(x)&&i.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:f.id,onDragOver:v,onDragEnd:()=>r(!1),onClick:()=>d(f.id),children:[i.jsx("hr",{className:"group-last:hidden"}),i.jsx("div",{className:"h-full mt-4 gap-y-6",children:i.jsx(Ya,{elementData:f.questionData,sectionId:f.id})})]})]})},f.id)),i.jsx("div",{className:"flex justify-center",children:i.jsxs("button",{type:"button",onClick:()=>t(),style:{color:(g==null?void 0:g.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]})})]})]})};function Xa({questionData:e,uploadUrl:n}){const{setFormData:o,addSection:s,setUploadUrl:a}=m.useContext(de);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(Qa,{})})}const xi=[{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"}],es=()=>{const[e,n]=m.useState(""),{setIsDragging:o,addElement:s,selectedSection:a}=m.useContext(de),t=m.useCallback((p,A)=>{if(!a){me.toast.error("Please select a section to add an element.");return}p.dataTransfer.setData("properties",JSON.stringify(A)),p.dataTransfer.effectAllowed="move",o(!0)},[o,a]);function l(p){if(!a){me.toast.error("Please select a section to add an element.");return}const A={...p,id:ve.v4(),sectionId:a};s(A,a)}const r=ue("config")||{},d=r.elementColor,c=r.elementBgColor,u=r.elementBorderColor,h=oa.filter(p=>p.label.toLowerCase().includes(e.toLowerCase())),v=xi==null?void 0:xi.map(p=>({title:p.title,elements:h.filter(A=>{var g;return(g=aa[p.key])==null?void 0:g.includes(A.type)})})).filter(p=>p.elements.length>0);return console.log({categorizedElements:v}),i.jsxs("div",{className:"pt-4 pb-6",children:[i.jsx(me.ToastContainer,{}),i.jsx("div",{className:"px-5 mb-4",children:i.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:p=>n(p.target.value)})}),i.jsx("hr",{}),i.jsx("div",{children:i.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 max-h-[80vh] overflow-y-auto no-scrollbar",children:v==null?void 0:v.map((p,A)=>{var g;return i.jsxs("li",{children:[i.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:p.title}),i.jsx("ul",{className:"grid gap-y-[6px] mb-3",children:(g=p.elements)==null?void 0:g.map(f=>i.jsx("li",{onDragStart:x=>t(x,f),onDragEnd:()=>o(!1),onClick:()=>l(f),style:{borderColor:u,backgroundColor:c},className:`cursor-move text-[#475467] flex justify-between items-center h-11\r
50
50
  border-[1.5px] border-[#98A2B3] rounded-lg py-3 px-[14px] shadow-custom\r
51
51
  hover:shadow-lg transition-all duration-200\r
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arudovwen/form-builder-react",
3
- "version": "1.4.28",
3
+ "version": "1.4.29",
4
4
  "description": "A React-based form builder component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/form-builder.umd.js",