@arudovwen/form-builder-react 1.8.4 → 1.8.5

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.
@@ -23,8 +23,8 @@
23
23
  "data": [
24
24
  { "name": "Document Name", "id": "documentMainId", ...restObject },
25
25
  ]
26
- }`})})]})})}),qd=()=>t.jsx("blockquote",{className:"p-4 text-gray-700 bg-gray-100 rounded-md",children:t.jsxs("ul",{children:[t.jsxs("li",{className:"text-xs",children:["Method: GET ",t.jsx("br",{}),"URL format:"," ",t.jsx("code",{children:"https://example.com/validation/{documentId}"})]}),t.jsxs("li",{className:"text-xs",children:[t.jsx("span",{className:"block mb-1",children:" Response example format:"}),t.jsx("pre",{className:"p-2 bg-white rounded-md",children:t.jsxs("code",{children:["{ ",t.jsx("br",{}),'  "data": { ',t.jsx("br",{}),'    "status": true, ',t.jsx("br",{}),'    "isSigned": true ',t.jsx("br",{}),"  } ",t.jsx("br",{}),"}"]})})]})]})});function Yd(e){return e.flatMap(n=>{var i;return(i=n==null?void 0:n.questionData)!=null?i:[]})}const bo=["text","number","boolean"],Xs=["equals","not_equals","contains","not_contains"],Jd=["greater","less"];function Zd({register:e,setValue:n,trigger:i,watch:o,id:s}){const{formData:a}=x.useContext(Ae),l=o("visibilityDependentFields")||[],r=x.useMemo(()=>{var u;return(u=Yd(a).filter(m=>m.id!==s))==null?void 0:u.map(m=>{const c=l.find(b=>b.id===m.id);return{id:m.id,value:m.id,label:m.inputLabel,sectionId:m.sectionId,fieldType:(c==null?void 0:c.fieldType)||"text",operator:(c==null?void 0:c.operator)||"equals",fieldValue:(c==null?void 0:c.fieldValue)!==void 0?c.fieldValue:""}})},[a,l,s]),d=(u,m,c)=>{const b=l==null?void 0:l.map((v,h)=>h===u?{...v,[m]:c}:v);n("visibilityDependentFields",b)};return t.jsxs("div",{className:"visibility-editor",children:[t.jsx("label",{className:"label",children:"Select Dependent Fields"}),t.jsx(lo,{element:{options:r,id:"visibilityDependentFields",value:o("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:i,watch:o}}),l.length>0&&t.jsx("div",{className:"py-1 bg-gray-100 rounded dependent-fields",children:l==null?void 0:l.map((u,m)=>{var c,b;return t.jsxs("div",{className:"dependent-field",children:[t.jsx("input",{type:"text",value:u.label,readOnly:!0,disabled:!0,className:"field-label"}),t.jsx("div",{className:"field-listbox min-w-[100px]",children:t.jsx(re.Listbox,{value:u.fieldType,onChange:v=>d(m,"fieldType",v),children:t.jsxs("div",{className:"listbox-wrapper",children:[t.jsx(re.Listbox.Button,{className:"listbox-button",children:u.fieldType}),t.jsx(re.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t.jsx(re.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:bo==null?void 0:bo.map(v=>t.jsx(re.Listbox.Option,{value:v,className:"listbox-option",children:v},v))})})]})})}),t.jsx("div",{className:"field-listbox min-w-[100px]",children:t.jsx(re.Listbox,{value:u.operator,onChange:v=>d(m,"operator",v),children:t.jsxs("div",{className:"listbox-wrapper",children:[t.jsx(re.Listbox.Button,{className:"listbox-button",children:u.operator.replace("_"," ")}),t.jsx(re.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t.jsx(re.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(c=u.fieldType==="number"?[...Xs,...Jd]:Xs)==null?void 0:c.map(v=>t.jsx(re.Listbox.Option,{value:v,className:"listbox-option",children:v.replace("_"," ")},v))})})]})})}),u.fieldType!=="boolean"?t.jsx("input",{type:u.fieldType,value:u.fieldValue||"",onChange:v=>d(m,"fieldValue",v.target.value),placeholder:"Value",className:"field-value"}):t.jsx("div",{className:"field-listbox",children:t.jsx(re.Listbox,{value:(b=u.fieldValue)!=null?b:"",onChange:v=>d(m,"fieldValue",v),children:t.jsxs("div",{className:"listbox-wrapper",children:[t.jsx(re.Listbox.Button,{className:"listbox-button",children:u.fieldValue===!0?"True":u.fieldValue===!1?"False":"Select value"}),t.jsx(re.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t.jsxs(re.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[t.jsx(re.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),t.jsx(re.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},u.id)})})]})}function Qs(e){const n=[],i=/@\[([^\]]+)\]\(([^)]+)\)/g;let o=0,s;for(;(s=i.exec(e))!==null;){const l=e.slice(o,s.index);l&&n.push({type:"operator",value:l}),n.push({type:"field",id:s[2],display:s[1]}),o=s.index+s[0].length}const a=e.slice(o);return a&&n.push({type:"operator",value:a}),n}function Xd(e){return e.map(n=>n.type==="field"?`@[${n.display}](${n.id})`:n.value).join("")}function Qd({value:e,onChange:n,fields:i,placeholder:o}){const[s,a]=x.useState(()=>Qs(e)),[l,r]=x.useState(null),[d,u]=x.useState(!1),[m,c]=x.useState(""),[b,v]=x.useState(null),h=x.useRef(null),p=x.useRef(null),y=x.useRef(new Map);x.useEffect(()=>{const k=Qs(e);a(k)},[]);const f=x.useCallback(k=>{n(Xd(k))},[n]),N=(k,B)=>{const P=[...s];P[k]={type:"operator",value:B},a(P),f(P)},g=k=>{const B=s.filter((P,T)=>T!==k);a(B),f(B)},S=k=>{v(k),c(""),u(!0)},w=(k,B)=>{const P=B!==void 0?B:b!=null?b:s.length,T=[...s],O=T.slice(0,P),M=T.slice(P),D=[...O,{type:"field",id:k.id,display:k.display},...M],I=A(D);a(I),f(I),u(!1),v(null)};function A(k){const B=[];if(k.length===0)return[{type:"operator",value:""}];k[0].type==="field"&&B.push({type:"operator",value:""});for(let P=0;P<k.length;P++)B.push(k[P]),k[P].type==="field"&&(P+1>=k.length||k[P+1].type==="field")&&B.push({type:"operator",value:""});return B}const C=i.filter(k=>k.display.toLowerCase().includes(m.toLowerCase())),E=s.every(k=>k.type==="operator"&&k.value.trim()==="");return t.jsxs("div",{className:"relative",ref:p,children:[t.jsxs("div",{className:"field-control flex flex-wrap items-center gap-1 min-h-[44px] cursor-text",style:{padding:"6px 10px"},onClick:()=>{var B;const k=[...s].reverse().findIndex(P=>P.type==="operator");if(k!==-1){const P=s.length-1-k;(B=y.current.get(P))==null||B.focus()}},children:[E&&t.jsx("span",{className:"text-gray-400 text-sm pointer-events-none select-none",children:o||"Build your formula..."}),s.map((k,B)=>k.type==="field"?t.jsxs("span",{className:"inline-flex items-center gap-1 bg-blue-100 text-blue-800 text-sm px-2 py-0.5 rounded-full font-medium select-none",children:[k.display,t.jsx("button",{type:"button",onMouseDown:P=>{P.preventDefault(),g(B)},className:"text-blue-400 hover:text-blue-700 leading-none ml-0.5","aria-label":`Remove ${k.display}`,children:"×"})]},B):t.jsx("input",{ref:P=>{P?y.current.set(B,P):y.current.delete(B)},type:"text",value:k.value,onChange:P=>N(B,P.target.value),onFocus:()=>r(B),onBlur:()=>r(null),className:"border-none outline-none bg-transparent text-sm font-mono p-0 m-0",style:{width:`${Math.max(k.value.length*9+8,l===B?40:14)}px`,minWidth:"14px",maxWidth:"200px"},placeholder:"","aria-label":`Operator at position ${B}`},B)),t.jsx("button",{type:"button",onMouseDown:k=>{k.preventDefault(),S(s.length)},className:"inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800 hover:bg-blue-50 px-1.5 py-0.5 rounded transition-colors",title:"Insert a field",children:t.jsx("span",{className:"text-base leading-none",children:"@"})})]}),!E&&t.jsxs("div",{className:"mt-2 text-xs bg-blue-50 text-blue-800 border border-blue-100 rounded px-2 py-1.5 font-mono break-words",children:[t.jsx("span",{className:"font-sans font-semibold text-blue-500 uppercase tracking-wide mr-1",children:"Preview:"}),s.map(k=>k.type==="field"?`[${k.display}]`:k.value).join("")]}),d&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-40",onMouseDown:()=>u(!1)}),t.jsxs("div",{ref:h,className:"absolute left-0 right-0 z-50 bg-white border border-gray-200 rounded-lg shadow-xl overflow-hidden",style:{top:"calc(100% + 4px)"},children:[t.jsx("div",{className:"p-2 border-b border-gray-100",children:t.jsx("input",{autoFocus:!0,type:"text",placeholder:"Search fields...",value:m,onChange:k=>c(k.target.value),className:"w-full text-sm px-2 py-1 border border-gray-200 rounded outline-none focus:border-blue-300",onKeyDown:k=>{k.key==="Escape"&&u(!1),k.key==="Enter"&&C.length>0&&w(C[0])}})}),t.jsxs("div",{className:"max-h-48 overflow-y-auto",children:[C.length===0&&t.jsx("p",{className:"text-xs text-gray-400 text-center py-3",children:"No matching fields"}),C.map(k=>t.jsxs("div",{onMouseDown:B=>{B.preventDefault(),w(k)},className:"px-3 py-2 text-sm cursor-pointer flex items-center justify-between hover:bg-blue-50 group",children:[t.jsx("span",{className:"font-medium text-gray-800",children:k.display}),t.jsxs("span",{className:"text-xs text-gray-400 font-mono group-hover:text-blue-400",children:[k.id.slice(0,8),"..."]})]},k.id))]})]})]}),i.length>0&&t.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:i.map(k=>t.jsxs("button",{type:"button",onMouseDown:B=>{B.preventDefault(),w(k,s.length)},className:"text-xs bg-gray-100 hover:bg-blue-50 hover:text-blue-700 border text-gray-600 px-2 py-0.5 rounded-full transition-colors",children:["+ ",k.display]},k.id))})]})}const Rd=ne.object().shape({inputLabel:ne.string().nullable(),placeholder:ne.string().nullable(),description:ne.string().nullable(),isReadOnly:ne.boolean(),isDisabled:ne.boolean(),isRequired:ne.boolean(),requiredMessage:ne.string().nullable(),minLengthMessage:ne.string().nullable(),maxLengthMessage:ne.string().nullable(),maxLength:ne.number().typeError("Expecting a number").nullable(),minLength:ne.number().typeError("Expecting a number").nullable(),inputType:ne.string().nullable(),maxAmountMessage:ne.string().nullable(),maxAmount:ne.string().nullable(),options:ne.array().of(ne.object().shape({label:ne.string().nullable(),value:ne.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:ne.array().of(ne.object().shape({label:ne.string().nullable(),value:ne.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:ne.string().nullable(),url:ne.string().nullable(),method:ne.string().nullable(),denominators:ne.mixed().nullable(),responseType:ne.string().nullable(),minAmount:ne.string().nullable(),heading:ne.string().nullable(),minAmountMessage:ne.string().nullable(),columns:ne.number().nullable().max(4).min(2),value:ne.mixed().nullable(),customClass:ne.string().nullable(),elementClass:ne.string().nullable(),apiUrl:ne.string().nullable(),selectType:ne.string().default("list"),dateType:ne.string().default("basic"),validationUrl:ne.string(),signatureLink:ne.string(),minDate:ne.string().nullable(),maxDate:ne.string().nullable(),canHaveDateRange:ne.boolean(),allowYearPicker:ne.boolean(),isHidden:ne.boolean(),visibilityDependentFields:ne.array().nullable(),isMultiple:ne.boolean(),acceptedFiles:ne.array(),showState:ne.boolean(),formula:ne.string().nullable(),fetchExternalResults:ne.boolean(),externalApiUrl:ne.string().nullable()}),eu=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],nu=({isOpen:e,onClose:n,element:i})=>{var V;const o=eu.filter(G=>!ti.includes(i.inputType)||G.key!=="validation"),{updateElement:s,formData:a}=x.useContext(Ae),[l,r]=x.useState("basic"),[d,u]=x.useState(!1),[m,c]=x.useState("manual"),b=((V=a==null?void 0:a.flatMap(G=>(G==null?void 0:G.questionData)||[]))==null?void 0:V.length)||0,v=x.useMemo(()=>(a==null?void 0:a.flatMap(G=>(G==null?void 0:G.questionData)||[]).filter(G=>{var H;return G.id!==(i==null?void 0:i.id)&&!["spacer","divider","section","grid"].includes((H=G.type)==null?void 0:H.toLowerCase())}).map(G=>({id:G.id,display:G.inputLabel||G.label||"Unnamed"})))||[],[b,i==null?void 0:i.id]),h=xe("config"),{register:p,handleSubmit:y,control:f,setValue:N,watch:g,trigger:S,formState:{errors:w,isSubmitting:A,isValid:C},reset:E}=Ve.useForm({resolver:ro(Rd),defaultValues:{...i,options:i.options||[]}}),k=g(),{fields:B,append:P,remove:T}=Ve.useFieldArray({control:f,name:"options"}),{fields:O,append:M,remove:D}=Ve.useFieldArray({control:f,name:"options1"}),{fields:I,append:K,remove:_}=Ve.useFieldArray({control:f,name:"dataColumns"});x.useEffect(()=>{e||E()},[e,E]);const L=G=>{s(G,i.sectionId),n()},U={headers:{Authorization:`Bearer ${xe("token")}`}},W=x.useCallback(async()=>{var G,H,$;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){Ee.toast.info("Please provide a valid API URL");return}try{u(!0);const{status:F,data:q}=await Xe.get(k.apiUrl,U);if(F!==200||!q){Ee.toast.error("Unexpected response from server.");return}const R=q.data||q.record||q.result;if(!Array.isArray(R)){Ee.toast.error("Expected an array in response (data, record, or result).");return}((G=i.type)==null?void 0:G.toLowerCase())==="datagrid"?N("dataColumns",mo(R)):N("options",co(R))}catch(F){const q=(($=(H=F==null?void 0:F.response)==null?void 0:H.data)==null?void 0:$.message)||(F==null?void 0:F.message)||"Unable to load options";Ee.toast.error(q)}finally{u(!1)}},[i.type,N,k.apiUrl]),Y=["manual","api","sheet"];function J(){m==="api"&&W()}const ie=()=>{var G,H;return t.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[t.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Y==null?void 0:Y.map($=>t.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[t.jsx("input",{type:"radio",name:"optionType",onChange:F=>c(F.target.value),value:$})," ",t.jsxs("span",{children:[$," options"]})]},$))}),m==="api"&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[t.jsx(le,{watch:g,label:"Load Options from Api",name:"apiUrl",errors:w,register:p,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),d&&t.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"})]}),t.jsx("button",{onClick:J,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),t.jsx($d,{})]}),m==="sheet"&&t.jsx("div",{className:"mb-4",children:t.jsx(Zs,{type:i.type,label:"Load options form sheet (csv, xlsx)",setValue:N,name:"options"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((G=i==null?void 0:i.type)==null?void 0:G.toLowerCase())==="matrix"?"Rows Options":"Parent Options"}),B==null?void 0:B.map(($,F)=>t.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Label":"",name:`options.${F}.label`,register:p,errors:w,element:i,placeholder:"Label",onChange:q=>{const X=q.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");N(`options.${F}.value`,X,{shouldValidate:!0,shouldDirty:!0})}})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Value":"",name:`options.${F}.value`,register:p,errors:w,element:i,placeholder:"Value"})}),t.jsx("button",{disabled:B.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>T(F),children:t.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id))," ",t.jsxs("div",{children:[" ",t.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>P({label:"",value:"",id:Ce.v4()}),children:[t.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),["cascadeselect","matrix"].includes(i.type.toLowerCase())&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"my-5"}),t.jsxs("div",{children:[" ",t.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((H=i==null?void 0:i.type)==null?void 0:H.toLowerCase())==="matrix"?"Columns Options":"Child Options"}),O==null?void 0:O.map(($,F)=>t.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Label":"",name:`options1.${F}.label`,register:p,errors:w,element:i,placeholder:"Label",onChange:q=>{const X=q.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");N(`options1.${F}.value`,X,{shouldValidate:!0,shouldDirty:!0})}})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Value":"",name:`options1.${F}.value`,register:p,errors:w,element:i,placeholder:"Value"})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Key":"",name:`options1.${F}.key`,register:p,errors:w,element:i,placeholder:"Key"})}),t.jsx("button",{disabled:O.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>D(F),children:t.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id)),t.jsxs("div",{children:[" ",t.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>M({label:"",value:"",key:"",id:Ce.v4()}),children:[t.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]})},se=()=>t.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[t.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Y==null?void 0:Y.map(G=>t.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[t.jsx("input",{type:"radio",name:"optionType",onChange:H=>c(H.target.value),value:G,checked:G===m})," ",t.jsxs("span",{children:[G," options"]})]},G))}),m==="api"&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[t.jsx(le,{watch:g,label:"Load Columns from Api",name:"apiUrl",errors:w,register:p,className:"!w-full",placeholder:"https://example.com/columns"}),d&&t.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"})]})," ",t.jsx("button",{onClick:J,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),t.jsx(jd,{})]}),m==="sheet"&&t.jsx("div",{className:"mb-4",children:t.jsx(Zs,{type:i.type,label:"Load columns form sheet (csv, xlsx)",setValue:N,name:"dataColumns"})}),t.jsx("div",{className:"grid gap-y-3",children:I==null?void 0:I.map((G,H)=>{var $,F;return t.jsxs("div",{className:"flex flex-col gap-2 border-b border-gray-100 pb-2 mb-2 last:border-0 last:pb-0 last:mb-0",children:[t.jsxs("div",{className:"flex items-center gap-x-4",children:[t.jsx("div",{className:"min-w-[140px]",children:t.jsx(un,{label:H===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"},{label:"Select",value:"select"}],register:p,name:`dataColumns.${H}.type`,setValue:N,trigger:S,value:k.dataColumns[H].type})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:H===0?"Display header":"",name:`dataColumns.${H}.headerName`,register:p,onChange:q=>{const X=q.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");N(`dataColumns.${H}.field`,X,{shouldValidate:!0,shouldDirty:!0})},errors:w,element:i,placeholder:"header"})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:H===0?"Field key":"",name:`dataColumns.${H}.field`,register:p,errors:w,element:i,placeholder:"fieldKey",disabled:!0})}),t.jsx("button",{disabled:I.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>_(H),children:t.jsx(te,{icon:"iconamoon:sign-times-fill"})})]}),((F=($=k.dataColumns)==null?void 0:$[H])==null?void 0:F.type)==="select"&&t.jsx("div",{className:"flex items-center gap-x-4",children:t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Options API URL",name:`dataColumns.${H}.optionsUrl`,register:p,errors:w,element:i,placeholder:"https://api.example.com/options"})})})]},G.id)})}),t.jsxs("div",{children:[" ",t.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>K({headerName:"",field:"",editable:!0,id:Ce.v4(),type:"text",validate:!1}),children:[t.jsx(te,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),Q=x.useCallback(async()=>{const G=xe("token"),{status:H,data:$}=await Xe.get(k.url,{headers:{Authorization:`Bearer ${G}`}});H===200&&N("options",($==null?void 0:$.data)||$)},[N,k.url]);x.useEffect(()=>{i.type==="document"&&k.url&&Q()},[k.url,i.type,Q]);const j=t.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default",onMouseDown:G=>G.stopPropagation(),onPointerDown:G=>G.stopPropagation(),onDragStart:G=>{G.preventDefault(),G.stopPropagation()},children:t.jsxs("div",{className:"w-full lg:w-2/3 xl:w-2/5 bg-white h-screen shadow-xl relative flex flex-col items-center",children:[t.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:t.jsx(te,{icon:"tabler:x",iconClass:"text-xl"})}),t.jsx("div",{className:"w-full pt-4",children:t.jsx(Ed,{tabs:o,setActiveTab:r,activeTab:l,className:"justify-start !text-left",btnClass:" !text-left"})}),t.jsxs("form",{onSubmit:y(L),className:"w-full flex-1 flex flex-col",autoComplete:"off",children:[t.jsxs("div",{className:"flex-1",children:[" ",t.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[l==="basic"&&t.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[uo.includes(i.inputType)&&t.jsx(t.Fragment,{children:t.jsx(le,{watch:g,label:"Value",name:"value",register:p,errors:w,element:i})}),!uo.includes(i.inputType)&&!ti.includes(i.inputType)&&t.jsxs(t.Fragment,{children:[t.jsx(le,{watch:g,label:"Label",name:"inputLabel",register:p,errors:w,element:i})," ",i.type.toLowerCase()==="cascadeselect"&&t.jsx(le,{watch:g,label:"Child Label",name:"childLabel",register:p,errors:w,element:i})]}),Od.includes(i.inputType)&&t.jsx(le,{watch:g,label:"Placeholder",name:"placeholder",register:p,errors:w,element:i}),Dd.includes(i.inputType)&&t.jsx(le,{watch:g,label:"Prefix",name:"prefix",register:p,errors:w,element:i}),Gd.includes(i.inputType)&&t.jsxs("div",{className:"grid gap-y-4",children:[t.jsx(Wd,{}),t.jsx(le,{watch:g,label:"Api Url",name:"url",register:p,errors:w,element:i}),t.jsx(un,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:p,name:"method",setValue:N,trigger:S,value:g("method")}),t.jsx(un,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:p,name:"responseType",setValue:N,trigger:S,value:g("responseType")})]}),Fd.includes(i.inputType)&&t.jsx(zd,{onChange:G=>{N("denominators",G)},value:g("denominators")}),!uo.includes(i.inputType)&&!ti.includes(i.inputType)&&t.jsx(le,{watch:g,label:"Short Description",name:"description",register:p,errors:w,element:i}),i.type.toLowerCase()==="date"&&t.jsxs(t.Fragment,{children:[t.jsx(un,{label:"Date Format",options:Id,register:p,name:"dateFormat",setValue:N,trigger:S,value:g("dateFormat")}),t.jsx(le,{watch:g,label:"Allow Range",name:"canHaveDateRange",register:p,errors:w,element:i,type:"checkbox",value:k.canHaveDateRange}),(k==null?void 0:k.canHaveDateRange)&&t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsx(Ji,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:N,placeholder:"Select min date"}),t.jsx(Ji,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:N,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),t.jsx(le,{watch:g,label:"Allow Year Picker",name:"allowYearPicker",register:p,errors:w,element:i,type:"checkbox",value:k.allowYearPicker})]}),i.type.toLowerCase()==="country"&&t.jsx(le,{watch:g,label:"Allow States",name:"showState",register:p,errors:w,element:i,type:"checkbox",value:k.showState}),i.type.toLowerCase()==="selectfield"&&t.jsx(un,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:p,name:"selectType",setValue:N,trigger:S,value:g("selectType")}),i.type.toLowerCase()==="grid"&&t.jsx(le,{watch:g,label:"Number of columns (max: 4)",name:"columns",register:p,errors:w,element:i,max:4,min:1}),i.type.toLowerCase()==="document"&&t.jsxs("div",{className:"grid gap-y-6",children:[t.jsxs("div",{className:"grid gap-y-1",children:[t.jsx(le,{watch:g,label:"Document Options Url",name:"url",register:p,errors:w,element:i})," ",t.jsx(Ud,{})]}),t.jsxs("div",{className:"grid gap-y-1",children:[t.jsx(le,{watch:g,label:"Document Validation Url",name:"validationUrl",register:p,errors:w,element:i}),t.jsx(qd,{})]}),t.jsx("div",{className:"grid gap-y-1",children:t.jsx(le,{watch:g,label:"Signature Page Url",name:"signatureLink",register:p,errors:w,element:i})})]}),i.type.toLowerCase()==="datagrid"&&se(),i.type.toLowerCase()==="file"&&t.jsxs(t.Fragment,{children:[t.jsx(le,{watch:g,label:"Allow Multiple Uploads",name:"isMultiple",register:p,errors:w,element:i,type:"checkbox",value:k.isMultiple}),t.jsx(lo,{element:{options:Vd,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:p,setValue:N,trigger:S,watch:g},placeholder:"Choose file types"})]}),Hd.includes(i.inputType)&&ie(),t.jsxs("div",{children:[t.jsx("div",{className:"w-[150px] mb-4",children:t.jsx(le,{watch:g,label:"Toggle Visibility",name:"isHidden",register:p,errors:w,element:i,type:"checkbox",value:k.isHidden})})," ",k.isHidden&&t.jsx(Zd,{register:p,setValue:N,trigger:S,watch:g,id:i==null?void 0:i.id})]}),i.type.toLowerCase()==="calculatedfield"&&t.jsxs("div",{className:"grid gap-y-2 mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-[#344054] font-onest",children:"Formula"}),t.jsx(Qd,{value:g("formula")||"",onChange:G=>N("formula",G,{shouldValidate:!0,shouldDirty:!0}),fields:v,placeholder:"Build your formula..."})]}),i.type.toLowerCase()==="polling"&&t.jsxs("div",{className:"grid gap-y-4 mb-4 mt-2",children:[t.jsx(le,{watch:g,label:"Fetch results from external API",name:"fetchExternalResults",register:p,errors:w,element:i,type:"checkbox",value:k.fetchExternalResults}),k.fetchExternalResults&&t.jsx(le,{watch:g,label:"External API URL (returns options results)",name:"externalApiUrl",register:p,errors:w,element:i,placeholder:"https://api.example.com/poll/results"})]})]}),!ti.includes(i.type.toLowerCase())&&l==="validation"&&t.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Required",name:"isRequired",register:p,errors:w,element:i,type:"checkbox",value:k.isRequired})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"requiredMessage",register:p,errors:w,element:i})})]}),_d.includes(i.inputType)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Min Length",name:"minLength",register:p,errors:w,element:i,type:"number"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"minLengthMessage",register:p,errors:w,element:i})})]}),t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Max Length",name:"maxLength",register:p,errors:w,element:i,type:"number"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"maxLengthMessage",register:p,errors:w,element:i})})]})]}),Kd.includes(i.inputType)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Min Amount",name:"minAmount",register:p,errors:w,element:i,type:"amount"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"minAmountMessage",register:p,errors:w,element:i})})]}),t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Max Amount",name:"maxAmount",register:p,errors:w,element:i,type:"amount"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"maxAmountMessage",register:p,errors:w,element:i})})]})]})]})]})]}),t.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[t.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"}),t.jsx("button",{type:"submit",disabled:!C||A,style:{background:(h==null?void 0:h.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!C||A?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!C||A?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:A?"Saving...":"Save"})]})]})]})});return document.body?ur.createPortal(j,document.body):j},vo=x.memo(({state:e,element:n,children:i})=>{var m,c;const[o,s]=x.useState(!1),{removeElement:a,duplicateElement:l,updateElement:r}=x.useContext(Ae),d=x.useMemo(()=>{var b;return(b=n==null?void 0:n.acceptedFiles)==null?void 0:b.map(v=>v.label).join(", ")},[n]),u=x.useCallback(()=>{a(n.id,n.sectionId)},[n.id,n.sectionId,a]);return t.jsxs("div",{className:"w-full min-w-0",children:[o&&t.jsx(nu,{isOpen:o,onClose:()=>s(!1),element:n}),t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("span",{children:[" ",n.inputLabel&&t.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",d&&t.jsxs("span",{className:"text-gray-400 text-xs",children:["(",d==null?void 0:d.toLowerCase(),")"]})]})]}),e==="edit"&&t.jsxs("span",{className:"flex items-center gap-x-3",children:[((m=n.type)==null?void 0:m.toLowerCase())!=="spacer"&&((c=n.type)==null?void 0:c.toLowerCase())!=="divider"&&t.jsxs("label",{className:"flex items-center gap-1 text-xs cursor-pointer text-gray-500 mr-2 hover:text-gray-700 select-none",children:[t.jsx("input",{type:"checkbox",checked:n.isRequired||!1,onChange:b=>r({...n,isRequired:b.target.checked},n.sectionId),className:"cursor-pointer"}),t.jsx("span",{className:"mt-0.5",children:"Required"})]}),t.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1 text-gray-600",onClick:()=>l(n==null?void 0:n.id,n.sectionId),title:"Duplicate",children:t.jsx(te,{icon:"tabler:copy",iconClass:"text-base"})}),t.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:()=>s(!0),title:"Edit",children:t.jsx(te,{icon:"circum:edit",iconClass:"text-base"})}),t.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:u,title:"Remove",children:t.jsx(te,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),i,n.description&&t.jsx("small",{className:"block text-gray-400 mt-1 text-xs",children:n.description})]})});vo.displayName="ElementContainer";function iu({element:e,validationData:n}){const{register:i=()=>({}),trigger:o,setValue:s,watch:a,isReadOnly:l}=n||{};let r;return a&&(r=a()[e.id]),t.jsx(le,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:i,trigger:o,setValue:s,value:r,prefix:e.prefix,disabled:l,watch:a})}function ou(e){if(!e)return!1;const n=/^data:image\/(jpeg|png|gif|bmp|webp);base64,/i,i=/\.(jpeg|jpg|png|gif|bmp|webp)$/i;return n.test(e)||i.test(e)}const su=({imageUrl:e})=>{const[n,i]=x.useState(!1),o=()=>{i(!0)},s=()=>{i(!1)};return t.jsxs("div",{children:[t.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:o,src:e||"/place.png","data-toggle":"tooltip","data-placement":"top",title:"Click to view"}),n&&t.jsx("div",{className:"modal",style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",justifyContent:"center",alignItems:"center"},onClick:s,children:t.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:a=>a.stopPropagation(),children:[t.jsx("span",{className:"close",onClick:s,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),t.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function au({element:e,validationData:n}){var A;const{register:i=()=>({}),setValue:o,watch:s}=n||{},[a,l]=x.useState(),[r,d]=x.useState(!1),[u,m]=x.useState(!1),[c,b]=x.useState(""),v=s&&s(e==null?void 0:e.id);x.useEffect(()=>{l(v)},[v]);const[h,p]=x.useState("");x.useEffect(()=>{i(e.id)},[e.id,i]);const{url:y,method:f,responseType:N}=e||{},S={headers:{Authorization:`Bearer ${xe("token")}`}},w=x.useCallback(async C=>{var E,k,B,P,T,O,M,D,I,K,_;if(!(!y||!f)){d(!0);try{let L;if(f.toLowerCase()==="get"){const z=`${y}?value=${C}`;L=await Xe.get(z,S)}else if(f.toLowerCase()==="post")L=await Xe.post(y,{value:C},S);else throw new Error("Unsupported HTTP method");L.status===200&&((((k=(E=L==null?void 0:L.data)==null?void 0:E.data)==null?void 0:k.status)||((B=L==null?void 0:L.data)==null?void 0:B.status))===!0?(m(!0),N==="string"?b(((T=(P=L==null?void 0:L.data)==null?void 0:P.data)==null?void 0:T.description)||((O=L==null?void 0:L.data)==null?void 0:O.description)||"Validation successful"):p(((D=(M=L==null?void 0:L.data)==null?void 0:M.data)==null?void 0:D.description)||((I=L==null?void 0:L.data)==null?void 0:I.description)||{})):(console.error("Invalid input:",C),b("Unable to validate input"),m(!1)))}catch(L){console.error("Error validating input:",L),b(((_=(K=L==null?void 0:L.response)==null?void 0:K.data)==null?void 0:_.message)||"Unable to validate input"),m(!1)}finally{d(!1)}}},[f,N,y]);return x.useEffect(()=>{if(a){const C=setTimeout(()=>{w(a)},700);return()=>clearTimeout(C)}},[w,a]),t.jsxs("div",{children:[t.jsxs("div",{className:"relative flex items-center",children:[t.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:de("field-control",e==null?void 0:e.customClass),...i(e==null?void 0:e.id),onChange:C=>{l(C.target.value),o(e==null?void 0:e.id,C.target.value)},disabled:n==null?void 0:n.isReadOnly}),t.jsxs("span",{className:"absolute right-0",children:[r&&t.jsxs("span",{children:[" ",t.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:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.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"})]})]}),u&&!r&&t.jsx("span",{className:"block pr-3 text-lg text-green-600",children:t.jsx(te,{icon:"gg:check-o"})})]})]}),c&&N==="string"&&t.jsx("span",{className:`${u?"text-green-600":"text-red-600"} text-sm`,children:c}),N==="object"&&t.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(A=Object.entries(h))==null?void 0:A.map(([C,E])=>t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsxs("span",{className:"font-semibold",children:[C,":"]}),ou(E)?t.jsx(su,{imageUrl:E}):t.jsx("span",{children:String(E)})]},C))})]})}function tu({onGetTotal:e,readOnly:n,defaultValue:i,denominators:o}){const[s,a]=x.useState([...i]);function l(u,m){a(c=>{const b=[...c];return b[m]={...b[m],value:u},b})}function r(u,m){return parseFloat(u)*parseFloat(m)||0}const d=x.useMemo(()=>s.reduce((u,m)=>{const c=r(m.key,m.value);return u+c},0),[s]);return x.useEffect(()=>{e&&e(s)},[s]),x.useEffect(()=>{if(o!=null&&o.length){const u=o==null?void 0:o.map((m,c)=>({key:m.value,value:Array.isArray(i)&&i[c]?i[c].value:""}));a(u)}},[i,o]),t.jsx("div",{className:"mt-2",children:t.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[t.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[t.jsx("div",{className:"border-r px-4 py-2",children:t.jsx("span",{className:"",children:"Denomination"})}),t.jsx("div",{className:"border-r px-4 py-2",children:t.jsx("span",{children:"Quantity"})}),t.jsx("div",{className:"px-4 py-2",children:t.jsx("span",{children:"Sub total"})})]}),s==null?void 0:s.map((u,m)=>{var c,b;return t.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[t.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:t.jsx("span",{className:"",children:(c=parseFloat(u.key))==null?void 0:c.toLocaleString()})}),t.jsx("div",{className:"border-r px-4 py-1",children:t.jsx("span",{children:t.jsx(ei,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:u.value,onValueChange:v=>l(v,m),disabled:n,allowNegativeValue:!1})})}),t.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:t.jsx("span",{children:(b=r(u.key,u.value))==null?void 0:b.toLocaleString()})})]},m+"index")}),t.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[t.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),t.jsx("div",{className:"px-4 py-3",children:d==null?void 0:d.toLocaleString()})]})]})})}function lu({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,getValues:s}=n||{},a=s&&s(e==null?void 0:e.id)||[];return x.useEffect(()=>{i(e.id)},[e.id,i]),t.jsx("div",{children:t.jsx(tu,{onGetTotal:l=>{o&&o(e.id,l)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:a,readOnly:e==null?void 0:e.isReadOnly})})}function ru({element:e}){return t.jsx("div",{className:de("py-6",e==null?void 0:e.customClass)})}function du({element:e}){return t.jsx("div",{children:t.jsx("hr",{className:de("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function uu({element:e,validationData:n}){const{register:i=()=>({})}=n||{};return t.jsx("div",{children:t.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...i(e==null?void 0:e.id)})})}function cu({element:e,state:n}){return t.jsx(t.Fragment,{children:t.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&t.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function mu({row:e,columns:n,isReadOnly:i,handleCellChange:o,getValidationStatus:s,deleteRow:a}){return t.jsxs("tr",{children:[n.map(l=>{var v;const r=e[l.field],d=l.editable&&!i,{isValidating:u,result:m}=s(e.id,l.field);let c="border-gray-300";l.validate&&((m==null?void 0:m.isValid)===!1?c="border-red-500 bg-red-50":(m==null?void 0:m.isValid)===!0&&(c="border-green-500 bg-green-50"));const b=`w-full py-1 rounded outline-none ${c}`;return t.jsx("td",{className:"px-3 py-1 border-b border-r last:border-r-0",children:d?t.jsxs("div",{className:"relative",children:[l.type==="number"?t.jsx(ei,{value:r,decimalsLimit:6,allowNegativeValue:!1,className:b,onValueChange:h=>o(h,e.id,l.field)}):l.type==="checkbox"?t.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(h=>{const p=h==="yes",y=`radio-${e.id}-${String(l.field)}-${h}`;return t.jsxs("label",{htmlFor:y,className:"flex items-center gap-1 cursor-pointer",children:[t.jsx("input",{id:y,type:"radio",name:`boolean-${e.id}-${String(l.field)}`,checked:r===p,onChange:()=>o(p,e.id,l.field)}),t.jsx("span",{className:"text-sm",children:p?"Yes":"No"})]},h)})}):l.type==="select"?t.jsx(Bn,{name:String(l.field),options:l.options||[],apiUrl:l.optionsUrl,value:r,onGetValue:(h,p)=>o((p==null?void 0:p.value)||"",e.id,l.field),customClass:"!border-none !p-0"}):t.jsx("input",{type:"text",value:String(r!=null?r:""),onChange:h=>o(h.target.value,e.id,l.field),className:b}),u&&t.jsx("div",{className:"absolute right-1 top-1",children:t.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):l.validate&&m?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{children:[String(r!=null?r:"")," ",m.data&&`[${m.data}]`]}),m.isValid?t.jsx("span",{className:"text-xs text-green-600",children:"✓"}):t.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(v=m.error)!=null?v:"",children:"✗"})]}):l.type==="select"?t.jsx(Bn,{name:String(l.field),options:l.options||[],apiUrl:l.optionsUrl,value:r,onGetValue:()=>{},readOnly:!0,customClass:"!border-none !bg-transparent !p-0 !text-gray-700 pointer-events-none"}):l.type==="checkbox"?t.jsx("span",{className:"block py-1 text-gray-700",children:r===!0?"Yes":r===!1?"No":""}):t.jsx("span",{className:"block py-1 text-gray-700",children:String(r!=null?r:"")})},String(l.id))}),!i&&t.jsx("td",{className:"px-3 py-1 text-center border sticky right-0 bg-gray-50 z-10",children:t.jsx("button",{type:"button",onClick:()=>a(e.id),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:t.jsx(te,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const bu=x.memo(mu);function vu({value:e=[],onChange:n,isReadOnly:i=!1,columns:o}){const[s,a]=x.useState(e),l=xe("config"),r=x.useRef(s);r.current=s,x.useEffect(()=>{a(b=>JSON.stringify(b)!==JSON.stringify(e)?e:b)},[e]);const d=x.useCallback((b,v,h)=>{const p=r.current.map(y=>y.id===v?{...y,[h]:b}:y);a(p),n==null||n(p)},[n]),u=x.useCallback(()=>{const b=Ce.v4(),v=o.reduce((p,y)=>(p[y.field]=y.field==="id"?b:"",p),{}),h=[...r.current,{id:b,...v}];a(h),n==null||n(h)},[o,n]),m=x.useCallback(b=>{const v=r.current.filter(h=>h.id!==b);a(v),n==null||n(v)},[n]),c=x.useCallback(()=>({isValidating:!1,result:void 0}),[]);return t.jsxs("div",{className:"mt-3 rounded",children:[t.jsx("div",{className:"w-full max-w-full overflow-x-auto border rounded-lg",children:t.jsxs("table",{className:"min-w-max w-full text-sm border-collapse table-auto",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"bg-gray-100",children:[o.map((b,v)=>{var h;return t.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border-b whitespace-nowrap",children:[(h=b.headerName)!=null?h:String(b.field),b.validate&&t.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(b.id)}-${v}`)}),!i&&t.jsx("th",{className:"w-10 px-2 py-2 border sticky right-0 bg-gray-100 z-10"})]})}),t.jsx("tbody",{children:s.length>0?s.map(b=>t.jsx(bu,{row:b,columns:o,isReadOnly:i,handleCellChange:d,getValidationStatus:c,deleteRow:m},b.id)):t.jsx("tr",{children:t.jsx("td",{colSpan:o.length+(i?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})}),!i&&t.jsx("div",{className:"flex justify-center mt-2",children:t.jsx("button",{onClick:u,type:"button",style:{color:(l==null?void 0:l.buttonColor)||"#333"},className:"px-2 py-1 mb-3 text-xs text-gray-600 font-medium",children:"+ Add Row"})})]})}function hu({element:e,validationData:n}){var v;const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:a}=n||{},l=s&&s(e==null?void 0:e.id)||{},r=Array.isArray(l)?l:(v=l==null?void 0:l.rows)!=null?v:[];x.useEffect(()=>{i(e.id)},[e.id,i]);const d=x.useRef(""),u=x.useRef(e==null?void 0:e.id),m=x.useRef(e==null?void 0:e.dataColumns),c=x.useRef(o);u.current=e==null?void 0:e.id,m.current=e==null?void 0:e.dataColumns,c.current=o;const b=x.useCallback(h=>{var y;const p=JSON.stringify(h);p!==d.current&&(d.current=p,(y=c.current)==null||y.call(c,u.current,{rows:h,columns:m.current}))},[]);return t.jsx(vu,{value:r,onChange:b,columns:e==null?void 0:e.dataColumns,isReadOnly:a})}const Rs=({className:e="",options:n=[],placeholder:i="Select",errors:o,register:s,setValue:a,name:l,label:r,value:d,trigger:u,isMultiple:m=!1,isFloatingLabel:c=!1,subText:b,labelClass:v="",loading:h,disabled:p})=>{const[y,f]=x.useState(m?[]:null),N=de("custom-select__control",e),g=x.useMemo(()=>n,[n]);return x.useEffect(()=>{const S=n==null?void 0:n.find(w=>{var A;return typeof w.value=="string"&&typeof d=="string"?w.value.toLowerCase()===d.toLowerCase():typeof w.value=="object"&&typeof d=="object"?((A=w.value)==null?void 0:A.id)===(d==null?void 0:d.id):w.value===d});f(S||null)},[d,n]),x.useEffect(()=>{y&&a&&s&&(a(l,y==null?void 0:y.value),s(l),u==null||u(l))},[l,y]),t.jsxs("div",{className:"custom-select",children:[r&&!c&&t.jsx("label",{className:"custom-select__label",children:r}),c&&r&&t.jsx("label",{className:de("custom-select__floating-label",v),children:r}),t.jsx(re.Listbox,{value:y,onChange:f,multiple:m,disabled:p,children:t.jsxs("div",{className:"custom-select__wrapper",children:[t.jsxs(re.Listbox.Button,{className:N,disabled:p,children:[h?t.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):t.jsx("span",{className:"custom-select__value",children:(y==null?void 0:y.label)||t.jsx("span",{className:"custom-select__placeholder",children:i})}),t.jsx("span",{className:"custom-select__icon",children:t.jsx(te,{icon:"lucide:chevron-down"})})]}),t.jsx(re.Transition,{as:x.Fragment,leave:"custom-select__transition",children:t.jsx(re.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:g==null?void 0:g.map((S,w)=>t.jsx(re.Listbox.Option,{value:S,className:({active:A})=>de("custom-select__option",A&&"custom-select__option--active"),children:({selected:A})=>t.jsx("span",{className:de("custom-select__option-label",A&&"custom-select__option--selected"),children:S.label})},w))})})]})}),b&&!o&&t.jsx("p",{className:"custom-select__subtext",children:b}),o&&t.jsx("span",{className:"custom-select__error",children:o.message})]})},fu=({element:e,validationData:n})=>{var p;const{register:i=()=>({}),trigger:o,setValue:s,watch:a,isReadOnly:l}=n||{},r=(p=e==null?void 0:e.id)!=null?p:"cascadeValue",[d,u]=x.useState(""),[m,c]=x.useState(""),b=(y,f)=>{const N=y&&f?`${y}_${f}`:"";s==null||s(r,N),o==null||o(r)},v=(y,f)=>{y==="first"?(u(f),c(""),b(f,"")):(c(f),b(d,f))};x.useEffect(()=>{if(a){const y=a(r);if(y!=null&&y.includes("_")){const[f,N]=y.split("_");u(f),c(N)}}},[a,r]);const h=x.useMemo(()=>{var y;return(y=e.options1)==null?void 0:y.filter(f=>f.key===d)},[e.options1,d]);return!e.options||!e.options1?null:t.jsxs("div",{children:[t.jsx("input",{type:"hidden",...i(r)}),t.jsx("div",{className:"relative",children:t.jsx(Rs,{setValue:(y,f)=>v("first",f),options:e.options,name:`${r}`,register:i,value:d})}),d&&t.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&t.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),t.jsx(Rs,{setValue:(y,f)=>v("second",f),options:h,name:`${r}`,register:i,value:m})]})]})},pu=({value:e=0,max:n=5,readOnly:i=!1,onChange:o,size:s=24,className:a="",element:l,validationData:r})=>{var f;const{register:d=()=>({}),trigger:u,setValue:m,watch:c,isReadOnly:b}=r||{},v=(f=c==null?void 0:c(l.id))!=null?f:0,[h,p]=x.useState(null);x.useEffect(()=>{v==null&&(m==null||m(l.id,e))},[]);const y=N=>{if(!i&&!b){const g=N+1;m==null||m(l.id,g),u==null||u(l.id),o==null||o(g)}};return t.jsxs("div",{className:`flex gap-1 ${a}`,children:[t.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(N,g)=>{const S=h!==null?g<=h:g<v;return t.jsx(Us,{icon:S?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${S?"text-yellow-400":"text-gray-300"}`,width:s,height:s,onMouseEnter:()=>!(i||b)&&p(g),onMouseLeave:()=>!(i||b)&&p(null),onClick:()=>y(g)},g)})]})};function gu({element:e,validationData:n}){const{register:i=()=>({})}=n||{},o=(e==null?void 0:e.options)||[],s=(e==null?void 0:e.options1)||[];return t.jsx("div",{className:de("w-full overflow-x-auto",e.customClass),children:t.jsxs("table",{className:"w-full text-left border-collapse min-w-[600px] mb-2",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{className:"p-3 border-b bg-gray-50/50"}),s.map(a=>t.jsx("th",{className:"p-3 font-medium text-center border-b text-xs text-gray-700 w-[12%]",children:a.label},a.id||a.value))]})}),t.jsx("tbody",{children:o.map(a=>t.jsxs("tr",{className:"border-b last:border-0 hover:bg-gray-50/30",children:[t.jsx("td",{className:"p-3 text-gray-700 min-w-[150px] text-sm",children:a.label}),s.map(l=>t.jsx("td",{className:"p-3 text-center align-middle",children:t.jsx("input",{type:"radio",value:l.value,disabled:e.isDisabled||(n==null?void 0:n.isReadOnly),className:"w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 cursor-pointer disabled:opacity-50",...i(`${e.id}.${a.value}`)})},l.id||l.value))]},a.id||a.value))})]})})}function ea({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,trigger:s,isReadOnly:a,watch:l}=n||{},r=(l==null?void 0:l(e.id))||"",{country:d,state:u}=x.useMemo(()=>{var h;if(typeof r=="string"&&r.includes(",")){const[p,y]=(h=r.split(","))==null?void 0:h.map(f=>f.trim());return{country:y,state:p}}return{country:r,state:""}},[r]),m=x.useRef(r),c=x.useMemo(()=>{var h,p;return d?((p=(h=ai.find(y=>y.name===d))==null?void 0:h.states)==null?void 0:p.map(y=>({label:y.name,value:y.name})))||[]:[]},[d]),b=(h,p)=>{const f=(p==null?void 0:p.value)||"";o&&f!==m.current&&(o(e.id,f),s==null||s(e.id),m.current=f)},v=(h,p)=>{const y=(p==null?void 0:p.value)||"",f=y?`${y}, ${d}`:d;o&&f!==m.current&&(o(e.id,f),s==null||s(e.id),m.current=f)};return x.useEffect(()=>{m.current=r},[r]),t.jsxs("div",{className:"grid gap-y-6",children:[t.jsx("input",{type:"hidden",...i(e.id)}),t.jsx(Bn,{options:e.options,onGetValue:b,name:`${e.id}-country`,readOnly:a,defaultValue:d},`country-${d}`),c.length>0&&e.showState&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),t.jsx(Bn,{options:c,onGetValue:v,name:`${e.id}-state`,readOnly:a,defaultValue:u},`state-${u}`)]})]})}function yu({element:e,validationData:n}){const{register:i=()=>({}),isReadOnly:o}=n||{},{validationUrl:s,documentObj:a,signatureLink:l}=e,r=x.useMemo(()=>xe("config"),[]),[d,u]=x.useState(!1),[m,c]=x.useState(!1),b=x.useCallback(async()=>{var v,h;if(!(!s||!a))try{c(!0);const y={headers:{Authorization:`Bearer ${xe("token")}`}},{data:f}=await Xe.get(`${s}/${a}`,y),N=!!((h=(v=f==null?void 0:f.data)==null?void 0:v.isSigned)!=null?h:f!=null&&f.isSigned);return u(N),N}catch(p){console.error("Failed to check sign status",p)}finally{c(!1)}},[s,a]);return x.useEffect(()=>{let v=null;return!d&&a&&s&&(async()=>{await b()||(v=setInterval(async()=>{await b()&&v&&clearInterval(v)},2e3))})(),()=>{v&&clearInterval(v)}},[b,d,a,s]),t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:de("field-control",e.customClass),...i(e.id),disabled:o}),t.jsx("a",{href:d?"#":l,children:t.jsxs("button",{type:"button",onClick:b,disabled:m||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:de("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":m}),children:[t.jsx(te,{icon:m?"solar:refresh-outline":d?"solar:check-circle-bold":"solar:pen-2-line-duotone",iconClass:m?"animate-spin":""}),m?"Checking...":d?"Signed":"Sign"]})})]})}const ho=[{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 xu({label:e,placeholder:n,classLabel:i,isRequired:o,isOptional:s,name:a,value:l,error:r,disabled:d,readOnly:u,horizontal:m,description:c,validate:b,onChange:v,onError:h}){const[p,y]=x.useState(""),[f,N]=x.useState(null),[g,S]=x.useState(""),w=x.useMemo(()=>{var T;return(T=ho==null?void 0:ho.slice().sort((O,M)=>O.label.localeCompare(M.label)))==null?void 0:T.map(O=>({...O,phone:`+${O.phone}`}))},[]),A=x.useMemo(()=>p?w.filter(T=>`${T.label} ${T.phone}`.toLowerCase().includes(p.toLowerCase())):w,[p,w]),C=(f==null?void 0:f.min)||10,E=(f==null?void 0:f.max)||10,k=()=>g?`${(f==null?void 0:f.phone)||"+234"}-${g}`:"",B=T=>{if(!T)return{code:"+234",number:""};const O=T.split(/[-\s]/);return{code:O[0],number:O.slice(1).join(" ")}};x.useEffect(()=>{if(l){const T=B(l);N(w.find(O=>O.phone===T.code)||w[0]),S(T.number)}},[l,w]);const P=x.useMemo(()=>{if(r)return r;const T=g.length;return o&&T===0?"Phone number is required":T>0&&!/^\d+$/.test(g)?"Phone number must contain only digits":T>0&&T<C?`Minimum length is ${C}`:T>E?`Maximum length is ${E}`:""},[r,g,C,E,o]);return x.useEffect(()=>{v==null||v(k()),h==null||h(P||null)},[g,f,P]),t.jsxs("div",{className:`relative formGroup ${P&&!u?"has-error":""} ${m?"flex":""} ${!P&&g.length>0&&!u?"is-valid":""}`,children:[e&&t.jsxs("label",{htmlFor:a,className:`${i} ${m?"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," ",o&&t.jsx("span",{className:"text-red-500",children:"*"}),s&&t.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),t.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[t.jsx(te,{icon:"lucide:phone-call"}),t.jsx(re.Combobox,{value:f,onChange:N,children:t.jsxs("div",{className:"relative",children:[t.jsx(re.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:T=>(T==null?void 0:T.phone)||"+234",placeholder:"+234",onChange:T=>y(T.target.value)}),t.jsx(re.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:t.jsx(te,{icon:"lucide:chevron-down"})}),t.jsx(re.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:A==null?void 0:A.map((T,O)=>t.jsxs(re.Combobox.Option,{value:T,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[T.phone," - ",T.label]},`${T.code}+ ${O}`))})]})}),t.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[t.jsx("input",{type:"tel",inputMode:"numeric",value:g,disabled:d,readOnly:u,onChange:T=>{const O=T.target.value.replace(/\D/g,"");S(O)},placeholder:n,className:"w-full px-3 outline-none",maxLength:E,minLength:C}),t.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!P&&g.length>0&&!u&&t.jsx("span",{className:"text-green-500",children:t.jsx(te,{icon:"bi:check-lg"})})})]})]}),c&&t.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:c})]})}function Su({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:a,setError:l,clearErrors:r}=n||{};let d;return x.useEffect(()=>{i(e.id)},[e.id,i]),s&&(d=s()[e.id]),t.jsx(xu,{placeholder:e.placeholder,label:"",name:e.id,value:d,readOnly:a,disabled:a,onError:u=>{u?l==null||l(e.id,{type:"manual",message:u}):r==null||r(e.id)},onChange:u=>{u&&(o==null||o(e.id,u))}})}function wu({element:e,validationData:n}){var u;const{register:i=()=>({}),watch:o}=n||{};let s="";o&&(s=(u=o()[e.id])!=null?u:"");const a=s.trim(),l=/^https?:\/\//i.test(a),r=a?l?a:`https://${a}`:"",d=!l;return t.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&t.jsxs("div",{className:"relative",children:[d&&t.jsx("span",{className:"text-sm absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none select-none",children:"https://"}),t.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:de("field-control",d&&"!pl-16",e==null?void 0:e.customClass),...i(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly})]}),a?t.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:t.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:a})}):(n==null?void 0:n.isReadOnly)&&t.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}function Nu({element:e,validationData:n}){var d;const{watch:i,setValue:o}=n||{},s=(e==null?void 0:e.formula)||"",a=x.useMemo(()=>{const m=(s.match(/\{\{([^{}]+)\}\}/g)||[]).map(v=>v.replace(/[{}]/g,"")),b=(s.match(/@\[.*?\]\((.*?)\)/g)||[]).map(v=>{const h=/@\[.*?\]\((.*?)\)/.exec(v);return h?h[1]:""}).filter(Boolean);return Array.from(new Set([...m,...b]))},[s]),l=i?i(a):[],r=x.useMemo(()=>{if(!s)return"";let u=s,m=!1;if(a.forEach((c,b)=>{const v=l[b],h=Number(v);(isNaN(h)||v===void 0||v===null||v==="")&&(m=!0),u=u.replace(new RegExp(`\\{\\{${c}\\}\\}`,"g"),String(h||0)),u=u.replace(new RegExp(`@\\[.*?\\]\\(${c}\\)`,"g"),String(h||0))}),m)return"";try{const c=u.replace(/[^0-9+\-*/().\s]/g,"");if(!c)return"";const b=new Function(`return ${c}`)();return!isNaN(b)&&b!==null?Number.isInteger(b)?b:Number(b.toFixed(2)):""}catch(c){return"Error"}},[s,a,l]);return x.useEffect(()=>{o&&r!=="Error"&&r!==""&&o(e.id,r,{shouldValidate:!0,shouldDirty:!0})},[r,e.id,o]),t.jsx("div",{children:t.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Calculated result",type:"text",className:de("field-control bg-gray-100 cursor-not-allowed",e==null?void 0:e.customClass),value:r,readOnly:!0,disabled:!0,"aria-invalid":!!((d=n==null?void 0:n.errors)!=null&&d[e==null?void 0:e.id])})})}function Au({element:e,validationData:n,state:i}){var v;const{register:o,watch:s,setValue:a}=n||{},[l,r]=x.useState({}),[d,u]=x.useState(0),m=s?s(e.id):null,c=!!(m||i&&i!=="edit");x.useEffect(()=>{if(!e.fetchExternalResults||!e.externalApiUrl)return;const h=async()=>{try{const y=await fetch(e.externalApiUrl);if(!y.ok)return;const f=await y.json();let N={};Array.isArray(f)?f.forEach(S=>{const w=S.value||S.id||S.option,A=S.count||S.votes||S.value||0;w&&(N[w]=Number(A))}):typeof f=="object"&&(N=f),r(N);const g=Object.values(N).reduce((S,w)=>S+Number(w),0);u(g)}catch(y){console.error("Failed to fetch polling results",y)}};h();const p=setInterval(h,1e4);return()=>clearInterval(p)},[e.fetchExternalResults,e.externalApiUrl]),x.useEffect(()=>{e.fetchExternalResults||(m?(r({[m]:1}),u(1)):(r({}),u(0)))},[m,e.fetchExternalResults]);const b=h=>{n!=null&&n.isReadOnly||a&&a(e.id,h,{shouldValidate:!0,shouldDirty:!0})};return t.jsxs("div",{className:"w-full",children:[t.jsx("div",{className:"grid gap-y-3",children:(v=e.options)==null?void 0:v.map(h=>{const p=l[h.value]||0,y=d>0?Math.round(p/d*100):0,f=m===h.value;return t.jsxs("div",{onClick:()=>b(h.value),className:de("relative flex items-center justify-between p-3 border rounded-lg overflow-hidden transition-all duration-200",n!=null&&n.isReadOnly?"cursor-default":"cursor-pointer hover:border-blue-400 hover:bg-blue-50/50",f?"border-blue-500 ring-1 ring-blue-500":"border-gray-200"),children:[c&&t.jsx("div",{className:"absolute top-0 left-0 bottom-0 bg-blue-100/60 transition-all duration-1000 ease-out",style:{width:`${y}%`}}),t.jsxs("div",{className:"relative z-10 flex items-center gap-3",children:[t.jsx("div",{className:de("flex-shrink-0 w-5 h-5 rounded-full border flex items-center justify-center transition-colors",f?"border-blue-500 bg-blue-500":"border-gray-300 bg-white"),children:f&&t.jsx("div",{className:"w-2 h-2 bg-white rounded-full"})}),t.jsx("span",{className:de("font-medium text-sm",f?"text-blue-900":"text-gray-700"),children:h.label||h.name||h.option||h.value||"Unknown Option"})]}),c&&t.jsxs("div",{className:"relative z-10 flex items-center gap-2",children:[t.jsxs("span",{className:"text-sm font-semibold text-gray-700",children:[y,"%"]}),f&&t.jsx(te,{icon:"material-symbols:check-circle",iconClass:"text-blue-500 text-lg"})]}),t.jsx("input",{type:"radio",value:h.value,className:"hidden",...o?o(e.id):{}})]},h.id||h.value)})}),c&&t.jsxs("div",{className:"mt-3 text-xs text-gray-500 text-right flex justify-between items-center",children:[t.jsxs("span",{children:[d," ",d===1?"vote":"votes"," total"]}),e.fetchExternalResults&&e.externalApiUrl&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"})," Live"]})]})]})}const na={textField:Zi,longText:Md,selectField:kd,multiSelect:lo,numberField:Zi,amountField:iu,date:fr,password:wd,checkbox:Cd,radio:Nd,email:Zi,file:Sd,dataGrid:hu,section:Ad,validateInput:au,tableInput:lu,spacer:ru,divider:du,header:uu,basicText:cu,phoneField:Su,cascadeSelect:fu,rating:pu,matrix:gu,country:ea,bank:ea,document:yu,url:wu,calculatedField:Nu,polling:Au},ia="edit",Cu=(e,n)=>{var o;const i=na[e.type];return i?t.jsx(vo,{element:e,state:ia,children:t.jsxs("div",{className:"relative w-full",children:[((o=e.type)==null?void 0:o.toLowerCase())!=="grid"&&t.jsx("div",{className:"absolute top-0 left-0 z-20 w-full h-full"}),t.jsx(i,{element:e,state:ia,sectionId:n})]})}):t.jsx("div",{className:"flex items-center justify-center p-4 text-red-500 bg-red-50 border border-red-200 rounded-md",children:t.jsxs("span",{className:"text-sm font-medium",children:["Unsupported element type: ",e.type]})})},li=({col:e,children:n,customClass:i})=>t.jsx("div",{className:de("w-full bg-white min-w-0",i),style:{gridColumn:e},children:n}),ku=({element:e,sectionId:n,children:i,customClass:o,state:s,draggedElementId:a})=>{const{formData:l,addElement:r,setIsDragging:d,moveElement:u,isDragging:m,removeElement:c}=x.useContext(Ae),b=x.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[v,h]=x.useState(null);x.useEffect(()=>{const S=()=>{h(null),d(!1)};return document.addEventListener("dragend",S),()=>document.removeEventListener("dragend",S)},[d]);const p=x.useCallback((S,w)=>{S.preventDefault(),S.stopPropagation(),S.dataTransfer.dropEffect="move",h(w)},[]),y=x.useCallback((S,w)=>{S.preventDefault(),S.stopPropagation(),h(w)},[]),f=x.useCallback((S,w)=>{const A=S.relatedTarget;A&&S.currentTarget.contains(A)||h(C=>C===w?null:C)},[]),N=x.useCallback((S,w)=>{var E;S.preventDefault(),S.stopPropagation(),d(!1),h(null);const A=w+1,C=S.dataTransfer.getData("elementId");if(C){u({draggedId:C,sectionId:n,targetGridId:e.id,targetCol:A});return}try{const k=S.dataTransfer.getData("properties");if(!k)return;const B=JSON.parse(k);if((B==null?void 0:B.type)==="grid")return;const P=l.find(M=>M.id===n),T=(E=P==null?void 0:P.questionData)==null?void 0:E.find(M=>{var D;return M.gridId===e.id&&((D=M.gridPosition)==null?void 0:D.col)===A});T&&c(T.id,n);const O={...B,id:Ce.v4(),sectionId:n,gridId:e.id,gridPosition:{col:A}};r(O,n)}catch(k){console.error("Drop failed in grid:",k),d(!1)}},[r,e.id,l,n,d,u]),g=(S,w,A)=>{var D,I,K;const C=S+1,E=(I=(D=l.find(_=>_.id===n))==null?void 0:D.questionData)==null?void 0:I.find(_=>{var L;return _.gridId===e.id&&((L=_.gridPosition)==null?void 0:L.col)===C}),k=(K=E==null?void 0:E.id)!=null?K:null,B=Array.isArray(i)&&i.find(_=>{var L;return((L=_==null?void 0:_.props)==null?void 0:L.col)===C}),P=m&&v===S,T=!!B,O=m&&!!a,M=T&&k&&A==="edit"?{draggable:!0,onDragStart:_=>{_.stopPropagation(),_.dataTransfer.setData("elementId",k),_.dataTransfer.setData("properties",k),_.dataTransfer.effectAllowed="move",d(!0)},onDragEnd:()=>{h(null),d(!1)}}:{};return t.jsx("div",{className:"min-w-0",children:t.jsxs("div",{id:`grid-cell-${e.id}-${S}`,...M,onDrop:_=>N(_,S),onDragEnter:_=>y(_,S),onDragOver:_=>p(_,S),onDragLeave:_=>f(_,S),className:de("relative border rounded-lg min-h-[110px] min-w-0","flex items-center justify-center","transition-all duration-200 ease-in-out",A==="edit"?"py-3 ":"",T&&A==="edit"&&"cursor-grab active:cursor-grabbing border-none",w,!O&&!P&&"bg-white border-gray-200 text-gray-300",O&&!P&&!T&&"bg-blue-50 border-blue-200 border-dashed text-blue-300",O&&!P&&T&&"bg-white border-orange-200 border-dashed",P&&!T&&"bg-blue-100 border-blue-400 border-dashed shadow-inner scale-[1.01] text-blue-500",P&&T&&"bg-orange-50 border-orange-400 border-dashed shadow-inner scale-[1.01] text-orange-500"),children:[T&&A==="edit"&&t.jsx("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 flex items-center gap-0.5 px-2 py-0.5 rounded-full bg-gray-100 hover:bg-blue-100 text-gray-400 hover:text-blue-500 cursor-grab active:cursor-grabbing transition-colors z-10 opacity-60 hover:opacity-100 pointer-events-none select-none",children:t.jsx(te,{icon:"ph:dots-six-bold"})}),P&&!T&&t.jsxs("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-blue-400 text-xs font-medium pointer-events-none",children:[t.jsx(te,{icon:"ph:plus-bold"}),"Drop here"]}),P&&T&&t.jsx("span",{className:"absolute top-1 right-1 text-xs text-orange-400 font-medium pointer-events-none px-1 py-0.5 bg-orange-50 rounded",children:"Replace"}),t.jsx("div",{className:de("w-full select-none min-w-0",P&&"opacity-50 pointer-events-none"),children:B||t.jsx("span",{className:"flex items-center justify-center text-gray-300",children:A==="edit"&&t.jsx(te,{icon:"ph:plus-bold"})})})]})},S)};return t.jsx("div",{className:"relative w-full",children:t.jsx("div",{className:"grid w-full gap-3 items-center",style:{gridTemplateColumns:`repeat(${e.columns}, minmax(0, 1fr))`},children:b==null?void 0:b.map((S,w)=>g(w,o,s))})})},ri=x.memo(ku),Mu="edit";function fo({index:e,onDrop:n,onDragEnd:i,isDragging:o}){const[s,a]=x.useState(!1),l=s?52:o?28:4;return t.jsx("div",{onDragEnter:r=>{r.preventDefault(),a(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),a(!0)},onDragLeave:()=>a(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),a(!1),n(r,e)},onDragEnd:()=>{a(!1),i()},style:{height:`${l}px`},className:de("w-full rounded-md flex items-center justify-center","transition-all duration-150 ease-in-out overflow-hidden",s?"bg-blue-50 border-2 border-blue-300 border-dashed":o?"border-2 border-blue-200 border-dashed":"border-2 border-transparent"),children:s&&t.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[t.jsx(te,{icon:"octicon:plus-16"}),"Drop here"]})})}function Eu({elementData:e,sectionId:n}){const{formData:i,isDragging:o,setIsDragging:s,addElementInPosition:a,moveElement:l}=x.useContext(Ae),[r,d]=x.useState(null),u=x.useMemo(()=>{var f;return((f=i.find(N=>N.id===n))==null?void 0:f.questionData)||[]},[i,n]),m=x.useCallback((f,N)=>{f.dataTransfer.setData("elementId",N),f.dataTransfer.setData("properties",N),f.dataTransfer.effectAllowed="move",d(N),s(!0)},[s]),c=x.useCallback(()=>{d(null),s(!1)},[s]);x.useEffect(()=>{!o&&r&&d(null)},[o,r]);const b=x.useCallback(f=>{f.preventDefault(),f.stopPropagation();const N=f.dataTransfer.getData("elementId"),g=f.currentTarget.id;if(!N||!g||N===g){c();return}const S=u.find(A=>A.id===N),w=u.findIndex(A=>A.id===g);S!=null&&S.gridId&&w!==-1?l({draggedId:N,sectionId:n,targetIndex:w}):l({draggedId:N,sectionId:n,targetId:g}),d(null),s(!1)},[n,l,s,c,u]),v=x.useCallback((f,N)=>{f.preventDefault(),f.stopPropagation(),s(!1);const g=f.dataTransfer.getData("elementId");if(g){l({draggedId:g,sectionId:n,targetIndex:N}),d(null);return}try{const S=JSON.parse(f.dataTransfer.getData("properties"));if((S==null?void 0:S.type)==="section")return;const w={...S,id:Ce.v4(),sectionId:n};a(w,n,N),d(null)}catch(S){console.error("Drop error:",S)}},[a,n,s,l]),h=x.useCallback((f,N=!1)=>t.jsx("div",{id:f.id,draggable:!0,onDragStart:g=>m(g,f.id),onDragOver:N?void 0:g=>{g.preventDefault(),g.stopPropagation()},onDrop:N?void 0:b,onDragEnd:c,className:de("cursor-grab active:cursor-grabbing border p-4 w-full rounded-lg","transition-all duration-200 ease-in-out",r===f.id?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-300 shadow-inner":r?"bg-white border-dashed border-blue-200 shadow-sm":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:Cu(f,n)},f.id),[r,b,n,m,c]),p=x.useMemo(()=>(e==null?void 0:e.reduce((f,N)=>(N.gridId&&(f[N.gridId]=f[N.gridId]||[],f[N.gridId].push(N)),f),{}))||{},[e]);if(!(e!=null&&e.length))return t.jsx("div",{onDragOver:f=>f.preventDefault(),onDrop:f=>v(f,0),onDragEnd:c,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 y=e.filter(f=>!f.gridId);return t.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[t.jsx(fo,{index:0,isDragging:o,onDrop:v,onDragEnd:c}),y.map(f=>{const N=u.findIndex(g=>g.id===f.id);if(f.type==="grid"){const g=p[f.id]||[],S=r===f.id,w=!!r&&!S;return t.jsxs("div",{className:"flex flex-col gap-0",children:[t.jsx("div",{id:f.id,draggable:!0,onDragStart:A=>m(A,f.id),onDragOver:A=>{A.preventDefault(),A.stopPropagation()},onDrop:b,onDragEnd:c,className:de("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",S?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":w?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:t.jsx(vo,{element:f,state:"edit",children:t.jsx(ri,{element:f,sectionId:n,state:Mu,draggedElementId:r,children:g==null?void 0:g.map(A=>{var C;return t.jsx(li,{col:(C=A.gridPosition)==null?void 0:C.col,children:h(A,!0)},A.id)})})})}),t.jsx(fo,{index:N+1,isDragging:o,onDrop:v,onDragEnd:c})]},f.id)}return t.jsxs("div",{className:"flex flex-col gap-0",children:[h(f),t.jsx(fo,{index:N+1,isDragging:o,onDrop:v,onDragEnd:c})]},f.id)})]})}const Tu=x.memo(Eu),Pu=ne.object({title:ne.string(),description:ne.string(),disabled:ne.boolean().default(!1),isHidden:ne.boolean().default(!1)}).required(),po=xe("config"),Lu=({isOpen:e,onClose:n,section:i})=>{const{updateSection:o}=x.useContext(Ae),{register:s,handleSubmit:a,watch:l,formState:{errors:r,isSubmitting:d,isValid:u},reset:m}=Ve.useForm({resolver:ro(Pu),defaultValues:i});if(x.useEffect(()=>{e||m()},[e,m]),!e)return null;const c=v=>{o(v,i.id),n()},b=l();return t.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:t.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[t.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 mb-6",children:[t.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Update Section Information"}),t.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:t.jsx(te,{icon:"tabler:x"})})]}),t.jsxs("form",{onSubmit:a(c),className:"w-full",autoComplete:"off",children:[t.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[t.jsx(le,{label:"Title",name:"title",register:s,errors:r,watch:l}),t.jsx(le,{label:"Description",name:"description",register:s,errors:r,watch:l,type:"textarea"}),t.jsx(le,{label:"Disable Section",name:"disabled",register:s,errors:r,watch:l,type:"checkbox",value:b.disabled,description:"Disables all fields in this section"}),t.jsx(le,{label:"Hide Section",name:"isHidden",register:s,errors:r,watch:l,type:"checkbox",value:b.isHidden,description:"Hides this section from the form"})]}),t.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[t.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"}),t.jsx("button",{type:"submit",disabled:!u||d,style:{background:(po==null?void 0:po.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!u||d?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!u||d?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:d?"Saving...":"Save"})]})]})]})})},Bu=({isOpen:e,onClose:n,templates:i,onSelect:o})=>e?t.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:t.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[t.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 border-b",children:[t.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Select a Template"}),t.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:t.jsx(te,{icon:"tabler:x"})})]}),t.jsx("div",{className:"w-full max-h-[60vh] overflow-y-auto px-6 py-4 flex flex-col gap-4",children:i!=null&&i.length?i.map(s=>t.jsxs("div",{className:"p-4 border rounded-lg cursor-pointer hover:border-blue-500 hover:shadow-md transition-all",onClick:()=>{o(s),n()},children:[t.jsx("h3",{className:"font-semibold text-[#344054] mb-1",children:s.name}),s.description&&t.jsx("p",{className:"text-sm text-[#475467]",children:s.description})]},s.id)):t.jsx("p",{className:"text-sm text-gray-500",children:"No templates available."})})]})}):null,Iu=[{id:"tpl-1",name:"Simple Contact Form",description:"A basic form to collect user contact info.",sections:[{id:"sec-contact",title:"Contact Info",description:"Please fill in your details",questionData:[{id:"q-name",type:"textField",label:"Text Field",inputLabel:"Full Name",inputType:"text"},{id:"q-email",type:"textField",label:"Text Field",inputLabel:"Email Address",inputType:"email"},{id:"q-phone",type:"phoneField",label:"Phone Number",inputLabel:"Phone Number"}]}]},{id:"tpl-2",name:"Feedback Form",description:"Collect user feedback.",sections:[{id:"sec-feedback",title:"Your Feedback",questionData:[{id:"q-rating",type:"numberField",label:"Number",inputLabel:"Rating (1-5)",inputType:"number"},{id:"q-comments",type:"longText",label:"Long Text Field",inputLabel:"Additional Comments",inputType:"text"}]}]},{id:"tpl-3",name:"Event Registration",description:"Register attendees for an upcoming event.",sections:[{id:"sec-event-reg",title:"Event Registration",questionData:[{id:"q-fname",type:"textField",label:"Text Field",inputLabel:"First Name",inputType:"text"},{id:"q-lname",type:"textField",label:"Text Field",inputLabel:"Last Name",inputType:"text"},{id:"q-company",type:"textField",label:"Text Field",inputLabel:"Company",inputType:"text"},{id:"q-diet",type:"textField",label:"Text Field",inputLabel:"Dietary Requirements",inputType:"text"}]}]},{id:"tpl-4",name:"Job Application",description:"Standard job application form.",sections:[{id:"sec-job",title:"Job Application",questionData:[{id:"q-applicant",type:"textField",label:"Text Field",inputLabel:"Full Name",inputType:"text"},{id:"q-portfolio",type:"textField",label:"Text Field",inputLabel:"Portfolio URL",inputType:"url"},{id:"q-cover",type:"longText",label:"Long Text Field",inputLabel:"Cover Letter",inputType:"text"},{id:"q-resume",type:"file",label:"File Upload",inputLabel:"Upload Resume"}]}]},{id:"tpl-5",name:"Customer Satisfaction Survey",description:"Measure customer satisfaction (CSAT).",sections:[{id:"sec-csat",title:"CSAT Survey",questionData:[{id:"q-csat-rate",type:"numberField",label:"Number",inputLabel:"How satisfied are you with our service? (1-10)",inputType:"number"},{id:"q-csat-recommend",type:"radio",label:"Radio",inputLabel:"Would you recommend us?",options:[{label:"Yes",value:"yes"},{label:"No",value:"no"}]}]}]},{id:"tpl-6",name:"Maintenance Request",description:"Submit a property or IT maintenance request.",sections:[{id:"sec-maintenance",title:"Maintenance Details",questionData:[{id:"q-maint-loc",type:"textField",label:"Text Field",inputLabel:"Location / Room",inputType:"text"},{id:"q-maint-desc",type:"longText",label:"Long Text Field",inputLabel:"Issue Description",inputType:"text"},{id:"q-maint-urgency",type:"selectField",label:"Select",inputLabel:"Urgency Level",options:[{label:"Low",value:"low"},{label:"Medium",value:"medium"},{label:"High",value:"high"}]}]}]},{id:"tpl-7",name:"Product Order Form",description:"Basic order form for merchandise or products.",sections:[{id:"sec-order-info",title:"Customer Info",questionData:[{id:"q-order-name",type:"textField",label:"Text Field",inputLabel:"Name",inputType:"text"},{id:"q-order-address",type:"longText",label:"Long Text Field",inputLabel:"Shipping Address",inputType:"text"}]},{id:"sec-order-details",title:"Order Details",questionData:[{id:"q-order-item",type:"textField",label:"Text Field",inputLabel:"Item Name",inputType:"text"},{id:"q-order-qty",type:"numberField",label:"Number",inputLabel:"Quantity",inputType:"number"}]}]},{id:"tpl-8",name:"Employee Onboarding",description:"Collect info for new hires.",sections:[{id:"sec-onboard",title:"Employee Details",questionData:[{id:"q-emp-name",type:"textField",label:"Text Field",inputLabel:"Legal Name",inputType:"text"},{id:"q-emp-start",type:"date",label:"Date Picker",inputLabel:"Start Date"},{id:"q-emp-dept",type:"textField",label:"Text Field",inputLabel:"Department",inputType:"text"}]}]},{id:"tpl-9",name:"Support Ticket",description:"IT or customer support ticket form.",sections:[{id:"sec-support",title:"Issue Details",questionData:[{id:"q-sup-subject",type:"textField",label:"Text Field",inputLabel:"Subject",inputType:"text"},{id:"q-sup-body",type:"longText",label:"Long Text Field",inputLabel:"Description",inputType:"text"},{id:"q-sup-file",type:"file",label:"File Upload",inputLabel:"Attach Screenshot"}]}]},{id:"tpl-10",name:"Course Evaluation",description:"Student feedback for a course.",sections:[{id:"sec-course",title:"Course Evaluation",questionData:[{id:"q-course-name",type:"textField",label:"Text Field",inputLabel:"Course Name",inputType:"text"},{id:"q-course-rate",type:"numberField",label:"Number",inputLabel:"Course Rating (1-10)",inputType:"number"},{id:"q-course-improve",type:"longText",label:"Long Text Field",inputLabel:"What could be improved?",inputType:"text"}]}]}],Du=({section:e,index:n,selectedSection:i,setSelectedSection:o,activeSections:s,toggleSection:a,handleSectionEdit:l,removeSection:r,formDataLength:d,onDragOver:u,setIsDragging:m,isDragging:c,onReorderSection:b})=>{var p,y;const v=x.useRef(null),h=x.useRef((p=e==null?void 0:e.questionData)==null?void 0:p.length);return x.useEffect(()=>{var f,N;if(((f=e==null?void 0:e.questionData)==null?void 0:f.length)>h.current&&!c){const g=document.getElementById("section-container");g&&requestAnimationFrame(()=>{g.scrollTo({top:g.scrollHeight,behavior:"smooth"})})}h.current=(N=e==null?void 0:e.questionData)==null?void 0:N.length},[(y=e==null?void 0:e.questionData)==null?void 0:y.length,c]),t.jsx("div",{ref:v,onDragOver:f=>{f.dataTransfer.types.includes("sectionid")&&f.preventDefault()},onDrop:f=>{const N=f.dataTransfer.getData("sectionid");N&&(f.preventDefault(),f.stopPropagation(),b&&b(N,e.id))},className:"bg-white group cursor-pointer rounded-lg shadow-[rgba(149,157,165,0.2)_0px_2px_2px] transition-colors duration-200",children:t.jsxs("div",{className:` border border-gray-200 rounded-lg px-4 transition-colors duration-200
27
- ${i===e.id?" border-blue-200 bg-gray-100":"bg-white"} ${s.includes(n)?"min-h-[300px] pb-6 ":""}`,children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{draggable:!0,onDragStart:f=>{f.dataTransfer.setData("sectionid",e.id),f.dataTransfer.effectAllowed="move",m(!0)},onDragEnd:()=>m(!1),onClick:()=>o(e.id),className:"flex-1 h-full py-4 cursor-grab active:cursor-grabbing flex items-center gap-2",title:"Drag to reorder section",children:[t.jsx(te,{icon:"material-symbols:drag-indicator",iconClass:"text-gray-400 text-lg"}),t.jsx("h2",{className:"font-medium",children:e.title||"Section title"})]}),t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>l(e),children:t.jsx(te,{icon:"fluent:edit-28-regular"})}),d>1&&t.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>r(e.id),children:t.jsx(te,{icon:"lets-icons:trash-duotone-line"})}),t.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>a(n),children:t.jsx(te,{icon:s.includes(n)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(e==null?void 0:e.description)&&s.includes(n)&&t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:e==null?void 0:e.description}),s.includes(n)&&t.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:e.id,onDragOver:u,onDragEnd:()=>m(!1),onClick:()=>o(e.id),children:[t.jsx("hr",{className:"group-last:hidden"}),t.jsx("div",{className:"h-full mt-4 gap-y-6 ",children:t.jsx(Tu,{elementData:e==null?void 0:e.questionData,sectionId:e==null?void 0:e.id})})]})]})},e==null?void 0:e.id)},_u=({onAddTemplate:e,templates:n})=>{const i=[...Iu,...n||[]],[o,s]=x.useState(!1),[a,l]=x.useState(!1),r=x.useRef(null),d=x.useRef(null),{removeSection:u,addSection:m,formData:c,setIsDragging:b,setSelectedSection:v,selectedSection:h,activeSections:p,setActiveSections:y,setFormData:f,isDragging:N}=x.useContext(Ae),g=x.useRef((c==null?void 0:c.length)||0);x.useEffect(()=>{var B;v(((B=c[0])==null?void 0:B.id)||null)},[]),x.useEffect(()=>{(c==null?void 0:c.length)>g.current&&d.current&&requestAnimationFrame(()=>{var B;(B=d.current)==null||B.scrollTo({top:d.current.scrollHeight,behavior:"smooth"})}),g.current=(c==null?void 0:c.length)||0},[c==null?void 0:c.length]);const S=x.useCallback(B=>{B.preventDefault(),B.dataTransfer.dropEffect="move"},[]),w=x.useCallback((B,P)=>{f(T=>{const O=T.findIndex(K=>K.id===B),M=T.findIndex(K=>K.id===P);if(O===-1||M===-1||O===M)return T;const D=[...T],[I]=D.splice(O,1);return D.splice(M,0,I),D})},[f]);function A(B){p.includes(B)?y(P=>P.filter(T=>T!==B)):y(P=>[...P,B])}function C(B){r.current=B,s(!0)}const E=B=>{var T,O,M,D;const P=(I,K={})=>({...JSON.parse(JSON.stringify(I)),...K});if(B.sections&&Array.isArray(B.sections)){const K=B.sections.filter(Boolean).map(L=>{var W;const z=Ce.v4(),U=(W=L.questionData)==null?void 0:W.map(Y=>P(Y,{id:Ce.v4(),sectionId:z}));if(U){const Y=new Map;L.questionData.forEach((J,ie)=>{Y.set(J.id,U[ie].id)}),U.forEach(J=>{J.gridId&&Y.has(J.gridId)&&(J.gridId=Y.get(J.gridId))})}return P(L,{id:z,questionData:U||[]})});c.length===1&&c[0].title===""&&c[0].description===""&&(!((T=c[0])!=null&&T.questionData)||((M=(O=c[0])==null?void 0:O.questionData)==null?void 0:M.length)===0)?(f(K),K.length>0&&v((D=K[0])==null?void 0:D.id)):f(L=>[...L,...K])}},k=xe("config");return t.jsxs("div",{className:"relative flex flex-col h-full pb-5 mx-auto gap-x-4 ",children:[o&&t.jsx(Lu,{isOpen:o,onClose:()=>s(!1),section:r.current}),t.jsxs("div",{id:"section-container",ref:d,className:"relative flex flex-col flex-1 w-full gap-y-3 container overflow-y-auto",children:[c==null?void 0:c.map((B,P)=>t.jsx(Du,{section:B,index:P,selectedSection:h,setSelectedSection:v,activeSections:p,toggleSection:A,handleSectionEdit:C,removeSection:u,formDataLength:c.length,onDragOver:S,setIsDragging:b,isDragging:N,onReorderSection:w},B.id)),t.jsxs("div",{className:"flex justify-center gap-x-4",children:[t.jsxs("button",{type:"button",onClick:()=>m(),style:{color:(k==null?void 0:k.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]}),e||i!=null&&i.length?t.jsx("button",{type:"button",onClick:()=>{i!=null&&i.length?l(!0):e&&e()},style:{color:(k==null?void 0:k.buttonColor)||"#333"},className:"text-sm font-medium",children:"+ Add existing template"}):null]})]}),a&&t.jsx(Bu,{isOpen:a,onClose:()=>l(!1),templates:i,onSelect:E})]})},Ou=()=>{const{formData:e,uploadUrl:n}=x.useContext(Ae),[i,o]=x.useState("multi"),s=xe("config");return t.jsxs("div",{className:"flex flex-col h-full w-full",children:[t.jsx("div",{className:"flex justify-center p-3 border-b border-gray-100 bg-gray-50/50",children:t.jsxs("div",{className:"flex bg-gray-200 p-1 rounded-lg text-sm font-medium",children:[t.jsx("button",{type:"button",className:`px-4 py-1.5 rounded-md transition-all ${i==="multi"?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"}`,onClick:()=>o("multi"),children:"Standard"}),t.jsx("button",{type:"button",className:`px-4 py-1.5 rounded-md transition-all ${i==="conversational"?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"}`,onClick:()=>o("conversational"),children:"Conversational"})]})}),t.jsx("div",{className:"flex-1 overflow-y-auto w-full relative",children:t.jsx(wo,{form_data:e,ignoreValidation:!0,config:s,uploadUrl:n,renderType:i,onGetValues:a=>console.log(a)})})]})},go=({loadingClass:e})=>{const n=de("h-full w-full min-h-[300px] flex justify-center items-center",e);return x.useEffect(()=>{const i=xe("config"),o=(i==null?void 0:i.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",o)},[]),t.jsx("div",{className:n,children:t.jsx("span",{className:"loader"})})},Ku=x.lazy(()=>Promise.resolve().then(()=>yg));function Hu({questionData:e,uploadUrl:n,onAddTemplate:i,templates:o,viewMode:s="canvas"}){const{setFormData:a,addSection:l,setUploadUrl:r,showPreview:d,formData:u}=x.useContext(Ae);x.useEffect(()=>{e&&e.length>0&&a(e)},[e,a]),x.useEffect(()=>{r(n)},[n,r]);const m=x.useCallback(c=>{c.preventDefault();try{const b=JSON.parse(c.dataTransfer.getData("properties"));if((b==null?void 0:b.type)==="section"){l();return}}catch(b){console.error("Drop error:",b)}},[]);return t.jsxs("div",{className:"flex gap-x-6 h-full",children:[t.jsx("div",{onDragOver:c=>c.preventDefault(),onDrop:c=>m(c),className:" h-full overflow-y-auto no-scrollbar max-h-[calc(100vh-80px)] flex-1 form_builder",children:s==="canvas"?t.jsx(_u,{onAddTemplate:i,templates:o}):t.jsx(x.Suspense,{fallback:t.jsx(go,{loadingClass:"!w-full !h-full"}),children:t.jsx(Ku,{formData:u})})}),s==="canvas"&&t.jsx(re.Transition,{show:d,as:"div",enter:"transition-all duration-300 ease-in-out origin-right",enterFrom:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",enterTo:"opacity-100 w-2/5 translate-x-0",leave:"transition-all duration-300 ease-in-out origin-right",leaveFrom:"opacity-100 w-2/5 translate-x-0",leaveTo:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",className:"shrink-0 overflow-y-auto no-scrollbar max-h-[calc(100vh-70px)] form_preview w-2/5 min-w-0",children:t.jsx("div",{className:"px-2 shadow_box min-w-0 bg-white border border-gray-100 rounded-lg container",children:t.jsx(Ou,{})})})]})}const yo=[{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"}],Gu=()=>{const[e,n]=x.useState(""),{setIsDragging:i,addElement:o,selectedSection:s}=x.useContext(Ae),a=x.useCallback((v,h)=>{if(!s){Ee.toast.error("Please select a section to add an element.");return}v.dataTransfer.setData("properties",JSON.stringify(h)),v.dataTransfer.effectAllowed="move",i(!0)},[i,s]);function l(v){if(!s){Ee.toast.error("Please select a section to add an element.");return}const h={...v,id:Ce.v4(),sectionId:s};o(h,s)}const r=xe("config")||{},d=r.elementColor,u=r.elementBgColor,m=r.elementBorderColor,c=Ld.filter(v=>v.label.toLowerCase().includes(e.toLowerCase())),b=yo==null?void 0:yo.map(v=>({title:v.title,elements:c.filter(h=>{var p;return(p=Bd[v.key])==null?void 0:p.includes(h.type)})})).filter(v=>v.elements.length>0);return t.jsxs("div",{className:"pt-4 flex flex-col gap-y-6",children:[t.jsx("div",{className:"px-5",children:t.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:v=>n(v.target.value),name:"search",id:"search",autoComplete:"off"})}),t.jsx("div",{className:"flex-1 overflow-y-auto no-scrollbar max-h-[calc(100vh-100px)]",children:t.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 ",children:b==null?void 0:b.map((v,h)=>{var p;return t.jsxs("li",{children:[t.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:v.title}),t.jsx("ul",{className:"grid grid-cols-2 gap-y-3 gap-x-4 mb-3",children:(p=v.elements)==null?void 0:p.map(y=>t.jsx("li",{onDragStart:f=>a(f,y),onDragEnd:()=>i(!1),onClick:()=>l(y),style:{borderColor:m,backgroundColor:u},className:`cursor-move text-[#475467] flex justify-between items-center \r
26
+ }`})})]})})}),qd=()=>t.jsx("blockquote",{className:"p-4 text-gray-700 bg-gray-100 rounded-md",children:t.jsxs("ul",{children:[t.jsxs("li",{className:"text-xs",children:["Method: GET ",t.jsx("br",{}),"URL format:"," ",t.jsx("code",{children:"https://example.com/validation/{documentId}"})]}),t.jsxs("li",{className:"text-xs",children:[t.jsx("span",{className:"block mb-1",children:" Response example format:"}),t.jsx("pre",{className:"p-2 bg-white rounded-md",children:t.jsxs("code",{children:["{ ",t.jsx("br",{}),'  "data": { ',t.jsx("br",{}),'    "status": true, ',t.jsx("br",{}),'    "isSigned": true ',t.jsx("br",{}),"  } ",t.jsx("br",{}),"}"]})})]})]})});function Yd(e){return e.flatMap(n=>{var i;return(i=n==null?void 0:n.questionData)!=null?i:[]})}const bo=["text","number","boolean"],Xs=["equals","not_equals","contains","not_contains"],Jd=["greater","less"];function Zd({register:e,setValue:n,trigger:i,watch:o,id:s}){const{formData:a}=x.useContext(Ae),l=o("visibilityDependentFields")||[],r=x.useMemo(()=>{var u;return(u=Yd(a).filter(m=>m.id!==s))==null?void 0:u.map(m=>{const c=l.find(b=>b.id===m.id);return{id:m.id,value:m.id,label:m.inputLabel,sectionId:m.sectionId,fieldType:(c==null?void 0:c.fieldType)||"text",operator:(c==null?void 0:c.operator)||"equals",fieldValue:(c==null?void 0:c.fieldValue)!==void 0?c.fieldValue:""}})},[a,l,s]),d=(u,m,c)=>{const b=l==null?void 0:l.map((v,h)=>h===u?{...v,[m]:c}:v);n("visibilityDependentFields",b)};return t.jsxs("div",{className:"visibility-editor",children:[t.jsx("label",{className:"label",children:"Select Dependent Fields"}),t.jsx(lo,{element:{options:r,id:"visibilityDependentFields",value:o("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:i,watch:o}}),l.length>0&&t.jsx("div",{className:"py-1 bg-gray-100 rounded dependent-fields",children:l==null?void 0:l.map((u,m)=>{var c,b;return t.jsxs("div",{className:"dependent-field",children:[t.jsx("input",{type:"text",value:u.label,readOnly:!0,disabled:!0,className:"field-label"}),t.jsx("div",{className:"field-listbox min-w-[100px]",children:t.jsx(re.Listbox,{value:u.fieldType,onChange:v=>d(m,"fieldType",v),children:t.jsxs("div",{className:"listbox-wrapper",children:[t.jsx(re.Listbox.Button,{className:"listbox-button",children:u.fieldType}),t.jsx(re.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t.jsx(re.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:bo==null?void 0:bo.map(v=>t.jsx(re.Listbox.Option,{value:v,className:"listbox-option",children:v},v))})})]})})}),t.jsx("div",{className:"field-listbox min-w-[100px]",children:t.jsx(re.Listbox,{value:u.operator,onChange:v=>d(m,"operator",v),children:t.jsxs("div",{className:"listbox-wrapper",children:[t.jsx(re.Listbox.Button,{className:"listbox-button",children:u.operator.replace("_"," ")}),t.jsx(re.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t.jsx(re.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:(c=u.fieldType==="number"?[...Xs,...Jd]:Xs)==null?void 0:c.map(v=>t.jsx(re.Listbox.Option,{value:v,className:"listbox-option",children:v.replace("_"," ")},v))})})]})})}),u.fieldType!=="boolean"?t.jsx("input",{type:u.fieldType,value:u.fieldValue||"",onChange:v=>d(m,"fieldValue",v.target.value),placeholder:"Value",className:"field-value"}):t.jsx("div",{className:"field-listbox",children:t.jsx(re.Listbox,{value:(b=u.fieldValue)!=null?b:"",onChange:v=>d(m,"fieldValue",v),children:t.jsxs("div",{className:"listbox-wrapper",children:[t.jsx(re.Listbox.Button,{className:"listbox-button",children:u.fieldValue===!0?"True":u.fieldValue===!1?"False":"Select value"}),t.jsx(re.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t.jsxs(re.Listbox.Options,{className:"listbox-options ",anchor:"bottom",children:[t.jsx(re.Listbox.Option,{value:!0,className:"listbox-option",children:"True"}),t.jsx(re.Listbox.Option,{value:!1,className:"listbox-option",children:"False"})]})})]})})})]},u.id)})})]})}function Qs(e){const n=[],i=/@\[([^\]]+)\]\(([^)]+)\)/g;let o=0,s;for(;(s=i.exec(e))!==null;){const l=e.slice(o,s.index);l&&n.push({type:"operator",value:l}),n.push({type:"field",id:s[2],display:s[1]}),o=s.index+s[0].length}const a=e.slice(o);return a&&n.push({type:"operator",value:a}),n}function Xd(e){return e.map(n=>n.type==="field"?`@[${n.display}](${n.id})`:n.value).join("")}function Qd({value:e,onChange:n,fields:i,placeholder:o}){const[s,a]=x.useState(()=>Qs(e)),[l,r]=x.useState(null),[d,u]=x.useState(!1),[m,c]=x.useState(""),[b,v]=x.useState(null),h=x.useRef(null),p=x.useRef(null),y=x.useRef(new Map);x.useEffect(()=>{const k=Qs(e);a(k)},[]);const f=x.useCallback(k=>{n(Xd(k))},[n]),N=(k,B)=>{const P=[...s];P[k]={type:"operator",value:B},a(P),f(P)},g=k=>{const B=s.filter((P,T)=>T!==k);a(B),f(B)},S=k=>{v(k),c(""),u(!0)},w=(k,B)=>{const P=B!==void 0?B:b!=null?b:s.length,T=[...s],O=T.slice(0,P),M=T.slice(P),D=[...O,{type:"field",id:k.id,display:k.display},...M],I=A(D);a(I),f(I),u(!1),v(null)};function A(k){const B=[];if(k.length===0)return[{type:"operator",value:""}];k[0].type==="field"&&B.push({type:"operator",value:""});for(let P=0;P<k.length;P++)B.push(k[P]),k[P].type==="field"&&(P+1>=k.length||k[P+1].type==="field")&&B.push({type:"operator",value:""});return B}const C=i.filter(k=>k.display.toLowerCase().includes(m.toLowerCase())),E=s.every(k=>k.type==="operator"&&k.value.trim()==="");return t.jsxs("div",{className:"relative",ref:p,children:[t.jsxs("div",{className:"field-control flex flex-wrap items-center gap-1 min-h-[44px] cursor-text",style:{padding:"6px 10px"},onClick:()=>{var B;const k=[...s].reverse().findIndex(P=>P.type==="operator");if(k!==-1){const P=s.length-1-k;(B=y.current.get(P))==null||B.focus()}},children:[E&&t.jsx("span",{className:"text-gray-400 text-sm pointer-events-none select-none",children:o||"Build your formula..."}),s.map((k,B)=>k.type==="field"?t.jsxs("span",{className:"inline-flex items-center gap-1 bg-blue-100 text-blue-800 text-sm px-2 py-0.5 rounded-full font-medium select-none",children:[k.display,t.jsx("button",{type:"button",onMouseDown:P=>{P.preventDefault(),g(B)},className:"text-blue-400 hover:text-blue-700 leading-none ml-0.5","aria-label":`Remove ${k.display}`,children:"×"})]},B):t.jsx("input",{ref:P=>{P?y.current.set(B,P):y.current.delete(B)},type:"text",value:k.value,onChange:P=>N(B,P.target.value),onFocus:()=>r(B),onBlur:()=>r(null),className:"border-none outline-none bg-transparent text-sm font-mono p-0 m-0",style:{width:`${Math.max(k.value.length*9+8,l===B?40:14)}px`,minWidth:"14px",maxWidth:"200px"},placeholder:"","aria-label":`Operator at position ${B}`},B)),t.jsx("button",{type:"button",onMouseDown:k=>{k.preventDefault(),S(s.length)},className:"inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800 hover:bg-blue-50 px-1.5 py-0.5 rounded transition-colors",title:"Insert a field",children:t.jsx("span",{className:"text-base leading-none",children:"@"})})]}),!E&&t.jsxs("div",{className:"mt-2 text-xs bg-blue-50 text-blue-800 border border-blue-100 rounded px-2 py-1.5 font-mono break-words",children:[t.jsx("span",{className:"font-sans font-semibold text-blue-500 uppercase tracking-wide mr-1",children:"Preview:"}),s.map(k=>k.type==="field"?`[${k.display}]`:k.value).join("")]}),d&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-40",onMouseDown:()=>u(!1)}),t.jsxs("div",{ref:h,className:"absolute left-0 right-0 z-50 bg-white border border-gray-200 rounded-lg shadow-xl overflow-hidden",style:{top:"calc(100% + 4px)"},children:[t.jsx("div",{className:"p-2 border-b border-gray-100",children:t.jsx("input",{autoFocus:!0,type:"text",placeholder:"Search fields...",value:m,onChange:k=>c(k.target.value),className:"w-full text-sm px-2 py-1 border border-gray-200 rounded outline-none focus:border-blue-300",onKeyDown:k=>{k.key==="Escape"&&u(!1),k.key==="Enter"&&C.length>0&&w(C[0])}})}),t.jsxs("div",{className:"max-h-48 overflow-y-auto",children:[C.length===0&&t.jsx("p",{className:"text-xs text-gray-400 text-center py-3",children:"No matching fields"}),C.map(k=>t.jsxs("div",{onMouseDown:B=>{B.preventDefault(),w(k)},className:"px-3 py-2 text-sm cursor-pointer flex items-center justify-between hover:bg-blue-50 group",children:[t.jsx("span",{className:"font-medium text-gray-800",children:k.display}),t.jsxs("span",{className:"text-xs text-gray-400 font-mono group-hover:text-blue-400",children:[k.id.slice(0,8),"..."]})]},k.id))]})]})]}),i.length>0&&t.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:i.map(k=>t.jsxs("button",{type:"button",onMouseDown:B=>{B.preventDefault(),w(k,s.length)},className:"text-xs bg-gray-100 hover:bg-blue-50 hover:text-blue-700 border text-gray-600 px-2 py-0.5 rounded-full transition-colors",children:["+ ",k.display]},k.id))})]})}const Rd=ne.object().shape({inputLabel:ne.string().nullable(),placeholder:ne.string().nullable(),description:ne.string().nullable(),isReadOnly:ne.boolean(),isDisabled:ne.boolean(),isRequired:ne.boolean(),requiredMessage:ne.string().nullable(),minLengthMessage:ne.string().nullable(),maxLengthMessage:ne.string().nullable(),maxLength:ne.number().typeError("Expecting a number").nullable(),minLength:ne.number().typeError("Expecting a number").nullable(),inputType:ne.string().nullable(),maxAmountMessage:ne.string().nullable(),maxAmount:ne.string().nullable(),options:ne.array().of(ne.object().shape({label:ne.string().nullable(),value:ne.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:ne.array().of(ne.object().shape({label:ne.string().nullable(),value:ne.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:ne.string().nullable(),url:ne.string().nullable(),method:ne.string().nullable(),denominators:ne.mixed().nullable(),responseType:ne.string().nullable(),minAmount:ne.string().nullable(),heading:ne.string().nullable(),minAmountMessage:ne.string().nullable(),columns:ne.number().nullable().max(4).min(2),value:ne.mixed().nullable(),customClass:ne.string().nullable(),elementClass:ne.string().nullable(),apiUrl:ne.string().nullable(),selectType:ne.string().default("list"),dateType:ne.string().default("basic"),validationUrl:ne.string(),signatureLink:ne.string(),minDate:ne.string().nullable(),maxDate:ne.string().nullable(),canHaveDateRange:ne.boolean(),allowYearPicker:ne.boolean(),isHidden:ne.boolean(),visibilityDependentFields:ne.array().nullable(),isMultiple:ne.boolean(),acceptedFiles:ne.array(),showState:ne.boolean(),formula:ne.string().nullable(),fetchExternalResults:ne.boolean(),externalApiUrl:ne.string().nullable()}),eu=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],nu=({isOpen:e,onClose:n,element:i})=>{var V;const o=eu.filter(G=>!ti.includes(i.inputType)||G.key!=="validation"),{updateElement:s,formData:a}=x.useContext(Ae),[l,r]=x.useState("basic"),[d,u]=x.useState(!1),[m,c]=x.useState("manual"),b=((V=a==null?void 0:a.flatMap(G=>(G==null?void 0:G.questionData)||[]))==null?void 0:V.length)||0,v=x.useMemo(()=>(a==null?void 0:a.flatMap(G=>(G==null?void 0:G.questionData)||[]).filter(G=>{var H;return G.id!==(i==null?void 0:i.id)&&!["spacer","divider","section","grid"].includes((H=G.type)==null?void 0:H.toLowerCase())}).map(G=>({id:G.id,display:G.inputLabel||G.label||"Unnamed"})))||[],[b,i==null?void 0:i.id]),h=xe("config"),{register:p,handleSubmit:y,control:f,setValue:N,watch:g,trigger:S,formState:{errors:w,isSubmitting:A,isValid:C},reset:E}=Ve.useForm({resolver:ro(Rd),defaultValues:{...i,options:i.options||[]}}),k=g(),{fields:B,append:P,remove:T}=Ve.useFieldArray({control:f,name:"options"}),{fields:O,append:M,remove:D}=Ve.useFieldArray({control:f,name:"options1"}),{fields:I,append:K,remove:_}=Ve.useFieldArray({control:f,name:"dataColumns"});x.useEffect(()=>{e||E()},[e,E]);const L=G=>{s(G,i.sectionId),n()},U={headers:{Authorization:`Bearer ${xe("token")}`}},W=x.useCallback(async()=>{var G,H,$;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){Ee.toast.info("Please provide a valid API URL");return}try{u(!0);const{status:F,data:q}=await Xe.get(k.apiUrl,U);if(F!==200||!q){Ee.toast.error("Unexpected response from server.");return}const R=q.data||q.record||q.result;if(!Array.isArray(R)){Ee.toast.error("Expected an array in response (data, record, or result).");return}((G=i.type)==null?void 0:G.toLowerCase())==="datagrid"?N("dataColumns",mo(R)):N("options",co(R))}catch(F){const q=(($=(H=F==null?void 0:F.response)==null?void 0:H.data)==null?void 0:$.message)||(F==null?void 0:F.message)||"Unable to load options";Ee.toast.error(q)}finally{u(!1)}},[i.type,N,k.apiUrl]),Y=["manual","api","sheet"];function J(){m==="api"&&W()}const ie=()=>{var G,H;return t.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[t.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Y==null?void 0:Y.map($=>t.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[t.jsx("input",{type:"radio",name:"optionType",onChange:F=>c(F.target.value),value:$})," ",t.jsxs("span",{children:[$," options"]})]},$))}),m==="api"&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[t.jsx(le,{watch:g,label:"Load Options from Api",name:"apiUrl",errors:w,register:p,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),d&&t.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"})]}),t.jsx("button",{onClick:J,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),t.jsx($d,{})]}),m==="sheet"&&t.jsx("div",{className:"mb-4",children:t.jsx(Zs,{type:i.type,label:"Load options form sheet (csv, xlsx)",setValue:N,name:"options"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((G=i==null?void 0:i.type)==null?void 0:G.toLowerCase())==="matrix"?"Rows Options":"Parent Options"}),B==null?void 0:B.map(($,F)=>t.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Label":"",name:`options.${F}.label`,register:p,errors:w,element:i,placeholder:"Label",onChange:q=>{const X=q.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");N(`options.${F}.value`,X,{shouldValidate:!0,shouldDirty:!0})}})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Value":"",name:`options.${F}.value`,register:p,errors:w,element:i,placeholder:"Value"})}),t.jsx("button",{disabled:B.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>T(F),children:t.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id))," ",t.jsxs("div",{children:[" ",t.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>P({label:"",value:"",id:Ce.v4()}),children:[t.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),["cascadeselect","matrix"].includes(i.type.toLowerCase())&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"my-5"}),t.jsxs("div",{children:[" ",t.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((H=i==null?void 0:i.type)==null?void 0:H.toLowerCase())==="matrix"?"Columns Options":"Child Options"}),O==null?void 0:O.map(($,F)=>t.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Label":"",name:`options1.${F}.label`,register:p,errors:w,element:i,placeholder:"Label",onChange:q=>{const X=q.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");N(`options1.${F}.value`,X,{shouldValidate:!0,shouldDirty:!0})}})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Value":"",name:`options1.${F}.value`,register:p,errors:w,element:i,placeholder:"Value"})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:F===0?"Key":"",name:`options1.${F}.key`,register:p,errors:w,element:i,placeholder:"Key"})}),t.jsx("button",{disabled:O.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>D(F),children:t.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id)),t.jsxs("div",{children:[" ",t.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>M({label:"",value:"",key:"",id:Ce.v4()}),children:[t.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]})},se=()=>t.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[t.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Y==null?void 0:Y.map(G=>t.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[t.jsx("input",{type:"radio",name:"optionType",onChange:H=>c(H.target.value),value:G,checked:G===m})," ",t.jsxs("span",{children:[G," options"]})]},G))}),m==="api"&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[t.jsx(le,{watch:g,label:"Load Columns from Api",name:"apiUrl",errors:w,register:p,className:"!w-full",placeholder:"https://example.com/columns"}),d&&t.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"})]})," ",t.jsx("button",{onClick:J,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),t.jsx(jd,{})]}),m==="sheet"&&t.jsx("div",{className:"mb-4",children:t.jsx(Zs,{type:i.type,label:"Load columns form sheet (csv, xlsx)",setValue:N,name:"dataColumns"})}),t.jsx("div",{className:"grid gap-y-3",children:I==null?void 0:I.map((G,H)=>{var $,F;return t.jsxs("div",{className:"flex flex-col gap-2 border-b border-gray-100 pb-2 mb-2 last:border-0 last:pb-0 last:mb-0",children:[t.jsxs("div",{className:"flex items-center gap-x-4",children:[t.jsx("div",{className:"min-w-[140px]",children:t.jsx(un,{label:H===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"},{label:"Select",value:"select"}],register:p,name:`dataColumns.${H}.type`,setValue:N,trigger:S,value:k.dataColumns[H].type})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:H===0?"Display header":"",name:`dataColumns.${H}.headerName`,register:p,onChange:q=>{const X=q.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");N(`dataColumns.${H}.field`,X,{shouldValidate:!0,shouldDirty:!0})},errors:w,element:i,placeholder:"header"})}),t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:H===0?"Field key":"",name:`dataColumns.${H}.field`,register:p,errors:w,element:i,placeholder:"fieldKey",disabled:!0})}),t.jsx("button",{disabled:I.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>_(H),children:t.jsx(te,{icon:"iconamoon:sign-times-fill"})})]}),((F=($=k.dataColumns)==null?void 0:$[H])==null?void 0:F.type)==="select"&&t.jsx("div",{className:"flex items-center gap-x-4",children:t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Options API URL",name:`dataColumns.${H}.optionsUrl`,register:p,errors:w,element:i,placeholder:"https://api.example.com/options"})})})]},G.id)})}),t.jsxs("div",{children:[" ",t.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>K({headerName:"",field:"",editable:!0,id:Ce.v4(),type:"text",validate:!1}),children:[t.jsx(te,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),Q=x.useCallback(async()=>{const G=xe("token"),{status:H,data:$}=await Xe.get(k.url,{headers:{Authorization:`Bearer ${G}`}});H===200&&N("options",($==null?void 0:$.data)||$)},[N,k.url]);x.useEffect(()=>{i.type==="document"&&k.url&&Q()},[k.url,i.type,Q]);const j=t.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default",onMouseDown:G=>G.stopPropagation(),onPointerDown:G=>G.stopPropagation(),onDragStart:G=>{G.preventDefault(),G.stopPropagation()},children:t.jsxs("div",{className:"w-full lg:w-2/3 xl:w-2/5 bg-white h-screen shadow-xl relative flex flex-col items-center",children:[t.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:t.jsx(te,{icon:"tabler:x",iconClass:"text-xl"})}),t.jsx("div",{className:"w-full pt-4",children:t.jsx(Ed,{tabs:o,setActiveTab:r,activeTab:l,className:"justify-start !text-left",btnClass:" !text-left"})}),t.jsxs("form",{onSubmit:y(L),className:"w-full flex-1 flex flex-col",autoComplete:"off",children:[t.jsxs("div",{className:"flex-1",children:[" ",t.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[l==="basic"&&t.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[uo.includes(i.inputType)&&t.jsx(t.Fragment,{children:t.jsx(le,{watch:g,label:"Value",name:"value",register:p,errors:w,element:i})}),!uo.includes(i.inputType)&&!ti.includes(i.inputType)&&t.jsxs(t.Fragment,{children:[t.jsx(le,{watch:g,label:"Label",name:"inputLabel",register:p,errors:w,element:i})," ",i.type.toLowerCase()==="cascadeselect"&&t.jsx(le,{watch:g,label:"Child Label",name:"childLabel",register:p,errors:w,element:i})]}),Od.includes(i.inputType)&&t.jsx(le,{watch:g,label:"Placeholder",name:"placeholder",register:p,errors:w,element:i}),Dd.includes(i.inputType)&&t.jsx(le,{watch:g,label:"Prefix",name:"prefix",register:p,errors:w,element:i}),Gd.includes(i.inputType)&&t.jsxs("div",{className:"grid gap-y-4",children:[t.jsx(Wd,{}),t.jsx(le,{watch:g,label:"Api Url",name:"url",register:p,errors:w,element:i}),t.jsx(un,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:p,name:"method",setValue:N,trigger:S,value:g("method")}),t.jsx(un,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:p,name:"responseType",setValue:N,trigger:S,value:g("responseType")})]}),Fd.includes(i.inputType)&&t.jsx(zd,{onChange:G=>{N("denominators",G)},value:g("denominators")}),!uo.includes(i.inputType)&&!ti.includes(i.inputType)&&t.jsx(le,{watch:g,label:"Short Description",name:"description",register:p,errors:w,element:i}),i.type.toLowerCase()==="date"&&t.jsxs(t.Fragment,{children:[t.jsx(un,{label:"Date Format",options:Id,register:p,name:"dateFormat",setValue:N,trigger:S,value:g("dateFormat")}),t.jsx(le,{watch:g,label:"Allow Range",name:"canHaveDateRange",register:p,errors:w,element:i,type:"checkbox",value:k.canHaveDateRange}),(k==null?void 0:k.canHaveDateRange)&&t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsx(Ji,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:N,placeholder:"Select min date"}),t.jsx(Ji,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:N,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),t.jsx(le,{watch:g,label:"Allow Year Picker",name:"allowYearPicker",register:p,errors:w,element:i,type:"checkbox",value:k.allowYearPicker})]}),i.type.toLowerCase()==="country"&&t.jsx(le,{watch:g,label:"Allow States",name:"showState",register:p,errors:w,element:i,type:"checkbox",value:k.showState}),i.type.toLowerCase()==="selectfield"&&t.jsx(un,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:p,name:"selectType",setValue:N,trigger:S,value:g("selectType")}),i.type.toLowerCase()==="grid"&&t.jsx(le,{watch:g,label:"Number of columns (max: 4)",name:"columns",register:p,errors:w,element:i,max:4,min:1}),i.type.toLowerCase()==="document"&&t.jsxs("div",{className:"grid gap-y-6",children:[t.jsxs("div",{className:"grid gap-y-1",children:[t.jsx(le,{watch:g,label:"Document Options Url",name:"url",register:p,errors:w,element:i})," ",t.jsx(Ud,{})]}),t.jsxs("div",{className:"grid gap-y-1",children:[t.jsx(le,{watch:g,label:"Document Validation Url",name:"validationUrl",register:p,errors:w,element:i}),t.jsx(qd,{})]}),t.jsx("div",{className:"grid gap-y-1",children:t.jsx(le,{watch:g,label:"Signature Page Url",name:"signatureLink",register:p,errors:w,element:i})})]}),i.type.toLowerCase()==="datagrid"&&se(),i.type.toLowerCase()==="file"&&t.jsxs(t.Fragment,{children:[t.jsx(le,{watch:g,label:"Allow Multiple Uploads",name:"isMultiple",register:p,errors:w,element:i,type:"checkbox",value:k.isMultiple}),t.jsx(lo,{element:{options:Vd,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:p,setValue:N,trigger:S,watch:g},placeholder:"Choose file types"})]}),Hd.includes(i.inputType)&&ie(),t.jsxs("div",{children:[t.jsx("div",{className:"w-[150px] mb-4",children:t.jsx(le,{watch:g,label:"Toggle Visibility",name:"isHidden",register:p,errors:w,element:i,type:"checkbox",value:k.isHidden})})," ",k.isHidden&&t.jsx(Zd,{register:p,setValue:N,trigger:S,watch:g,id:i==null?void 0:i.id})]}),i.type.toLowerCase()==="calculatedfield"&&t.jsxs("div",{className:"grid gap-y-2 mb-4",children:[t.jsx("label",{className:"block text-sm font-medium text-[#344054] font-onest",children:"Formula"}),t.jsx(Qd,{value:g("formula")||"",onChange:G=>N("formula",G,{shouldValidate:!0,shouldDirty:!0}),fields:v,placeholder:"Build your formula..."})]}),i.type.toLowerCase()==="polling"&&t.jsxs("div",{className:"grid gap-y-4 mb-4 mt-2",children:[t.jsx(le,{watch:g,label:"Fetch results from external API",name:"fetchExternalResults",register:p,errors:w,element:i,type:"checkbox",value:k.fetchExternalResults}),k.fetchExternalResults&&t.jsx(le,{watch:g,label:"External API URL (returns options results)",name:"externalApiUrl",register:p,errors:w,element:i,placeholder:"https://api.example.com/poll/results"})]})]}),!ti.includes(i.type.toLowerCase())&&l==="validation"&&t.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Required",name:"isRequired",register:p,errors:w,element:i,type:"checkbox",value:k.isRequired})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"requiredMessage",register:p,errors:w,element:i})})]}),_d.includes(i.inputType)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Min Length",name:"minLength",register:p,errors:w,element:i,type:"number"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"minLengthMessage",register:p,errors:w,element:i})})]}),t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Max Length",name:"maxLength",register:p,errors:w,element:i,type:"number"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"maxLengthMessage",register:p,errors:w,element:i})})]})]}),Kd.includes(i.inputType)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Min Amount",name:"minAmount",register:p,errors:w,element:i,type:"amount"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"minAmountMessage",register:p,errors:w,element:i})})]}),t.jsxs("div",{className:"flex items-center gap-x-6",children:[t.jsx("div",{className:"w-[150px]",children:t.jsx(le,{watch:g,label:"Max Amount",name:"maxAmount",register:p,errors:w,element:i,type:"amount"})})," ",t.jsx("div",{className:"flex-1",children:t.jsx(le,{watch:g,label:"Error message text",name:"maxAmountMessage",register:p,errors:w,element:i})})]})]})]})]})]}),t.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[t.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"}),t.jsx("button",{type:"submit",disabled:!C||A,style:{background:(h==null?void 0:h.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!C||A?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!C||A?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50 editor_option__save`,children:A?"Saving...":"Save"})]})]})]})});return document.body?ur.createPortal(j,document.body):j},vo=x.memo(({state:e,element:n,children:i})=>{var m,c;const[o,s]=x.useState(!1),{removeElement:a,duplicateElement:l,updateElement:r}=x.useContext(Ae),d=x.useMemo(()=>{var b;return(b=n==null?void 0:n.acceptedFiles)==null?void 0:b.map(v=>v.label).join(", ")},[n]),u=x.useCallback(()=>{a(n.id,n.sectionId)},[n.id,n.sectionId,a]);return t.jsxs("div",{className:"w-full min-w-0",children:[o&&t.jsx(nu,{isOpen:o,onClose:()=>s(!1),element:n}),t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("span",{children:[" ",n.inputLabel&&t.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",d&&t.jsxs("span",{className:"text-gray-400 text-xs",children:["(",d==null?void 0:d.toLowerCase(),")"]})]})]}),e==="edit"&&t.jsxs("span",{className:"flex items-center gap-x-3",children:[((m=n.type)==null?void 0:m.toLowerCase())!=="spacer"&&((c=n.type)==null?void 0:c.toLowerCase())!=="divider"&&t.jsxs("label",{className:"flex items-center gap-1 text-xs cursor-pointer text-gray-500 mr-2 hover:text-gray-700 select-none",children:[t.jsx("input",{type:"checkbox",checked:n.isRequired||!1,onChange:b=>r({...n,isRequired:b.target.checked},n.sectionId),className:"cursor-pointer"}),t.jsx("span",{className:"mt-0.5",children:"Required"})]}),t.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1 text-gray-600",onClick:()=>l(n==null?void 0:n.id,n.sectionId),title:"Duplicate",children:t.jsx(te,{icon:"tabler:copy",iconClass:"text-base"})}),t.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:()=>s(!0),title:"Edit",children:t.jsx(te,{icon:"circum:edit",iconClass:"text-base"})}),t.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:u,title:"Remove",children:t.jsx(te,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),i,n.description&&t.jsx("small",{className:"block text-gray-400 mt-1 text-xs",children:n.description})]})});vo.displayName="ElementContainer";function iu({element:e,validationData:n}){const{register:i=()=>({}),trigger:o,setValue:s,watch:a,isReadOnly:l}=n||{};let r;return a&&(r=a()[e.id]),t.jsx(le,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:i,trigger:o,setValue:s,value:r,prefix:e.prefix,disabled:l,watch:a})}function ou(e){if(!e)return!1;const n=/^data:image\/(jpeg|png|gif|bmp|webp);base64,/i,i=/\.(jpeg|jpg|png|gif|bmp|webp)$/i;return n.test(e)||i.test(e)}const su=({imageUrl:e})=>{const[n,i]=x.useState(!1),o=()=>{i(!0)},s=()=>{i(!1)};return t.jsxs("div",{children:[t.jsx("img",{alt:"Thumbnail",style:{cursor:"pointer",width:"120px",height:"130px",objectFit:"cover"},onClick:o,src:e||"/place.png","data-toggle":"tooltip","data-placement":"top",title:"Click to view"}),n&&t.jsx("div",{className:"modal",style:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",justifyContent:"center",alignItems:"center"},onClick:s,children:t.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:a=>a.stopPropagation(),children:[t.jsx("span",{className:"close",onClick:s,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),t.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function au({element:e,validationData:n}){var A;const{register:i=()=>({}),setValue:o,watch:s}=n||{},[a,l]=x.useState(),[r,d]=x.useState(!1),[u,m]=x.useState(!1),[c,b]=x.useState(""),v=s&&s(e==null?void 0:e.id);x.useEffect(()=>{l(v)},[v]);const[h,p]=x.useState("");x.useEffect(()=>{i(e.id)},[e.id,i]);const{url:y,method:f,responseType:N}=e||{},S={headers:{Authorization:`Bearer ${xe("token")}`}},w=x.useCallback(async C=>{var E,k,B,P,T,O,M,D,I,K,_;if(!(!y||!f)){d(!0);try{let L;if(f.toLowerCase()==="get"){const z=`${y}?value=${C}`;L=await Xe.get(z,S)}else if(f.toLowerCase()==="post")L=await Xe.post(y,{value:C},S);else throw new Error("Unsupported HTTP method");L.status===200&&((((k=(E=L==null?void 0:L.data)==null?void 0:E.data)==null?void 0:k.status)||((B=L==null?void 0:L.data)==null?void 0:B.status))===!0?(m(!0),N==="string"?b(((T=(P=L==null?void 0:L.data)==null?void 0:P.data)==null?void 0:T.description)||((O=L==null?void 0:L.data)==null?void 0:O.description)||"Validation successful"):p(((D=(M=L==null?void 0:L.data)==null?void 0:M.data)==null?void 0:D.description)||((I=L==null?void 0:L.data)==null?void 0:I.description)||{})):(console.error("Invalid input:",C),b("Unable to validate input"),m(!1)))}catch(L){console.error("Error validating input:",L),b(((_=(K=L==null?void 0:L.response)==null?void 0:K.data)==null?void 0:_.message)||"Unable to validate input"),m(!1)}finally{d(!1)}}},[f,N,y]);return x.useEffect(()=>{if(a){const C=setTimeout(()=>{w(a)},700);return()=>clearTimeout(C)}},[w,a]),t.jsxs("div",{children:[t.jsxs("div",{className:"relative flex items-center",children:[t.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:de("field-control",e==null?void 0:e.customClass),...i(e==null?void 0:e.id),onChange:C=>{l(C.target.value),o(e==null?void 0:e.id,C.target.value)},disabled:n==null?void 0:n.isReadOnly}),t.jsxs("span",{className:"absolute right-0",children:[r&&t.jsxs("span",{children:[" ",t.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:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.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"})]})]}),u&&!r&&t.jsx("span",{className:"block pr-3 text-lg text-green-600",children:t.jsx(te,{icon:"gg:check-o"})})]})]}),c&&N==="string"&&t.jsx("span",{className:`${u?"text-green-600":"text-red-600"} text-sm`,children:c}),N==="object"&&t.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(A=Object.entries(h))==null?void 0:A.map(([C,E])=>t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsxs("span",{className:"font-semibold",children:[C,":"]}),ou(E)?t.jsx(su,{imageUrl:E}):t.jsx("span",{children:String(E)})]},C))})]})}function tu({onGetTotal:e,readOnly:n,defaultValue:i,denominators:o}){const[s,a]=x.useState([...i]);function l(u,m){a(c=>{const b=[...c];return b[m]={...b[m],value:u},b})}function r(u,m){return parseFloat(u)*parseFloat(m)||0}const d=x.useMemo(()=>s.reduce((u,m)=>{const c=r(m.key,m.value);return u+c},0),[s]);return x.useEffect(()=>{e&&e(s)},[s]),x.useEffect(()=>{if(o!=null&&o.length){const u=o==null?void 0:o.map((m,c)=>({key:m.value,value:Array.isArray(i)&&i[c]?i[c].value:""}));a(u)}},[i,o]),t.jsx("div",{className:"mt-2",children:t.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[t.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[t.jsx("div",{className:"border-r px-4 py-2",children:t.jsx("span",{className:"",children:"Denomination"})}),t.jsx("div",{className:"border-r px-4 py-2",children:t.jsx("span",{children:"Quantity"})}),t.jsx("div",{className:"px-4 py-2",children:t.jsx("span",{children:"Sub total"})})]}),s==null?void 0:s.map((u,m)=>{var c,b;return t.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[t.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:t.jsx("span",{className:"",children:(c=parseFloat(u.key))==null?void 0:c.toLocaleString()})}),t.jsx("div",{className:"border-r px-4 py-1",children:t.jsx("span",{children:t.jsx(ei,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:u.value,onValueChange:v=>l(v,m),disabled:n,allowNegativeValue:!1})})}),t.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:t.jsx("span",{children:(b=r(u.key,u.value))==null?void 0:b.toLocaleString()})})]},m+"index")}),t.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[t.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),t.jsx("div",{className:"px-4 py-3",children:d==null?void 0:d.toLocaleString()})]})]})})}function lu({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,getValues:s}=n||{},a=s&&s(e==null?void 0:e.id)||[];return x.useEffect(()=>{i(e.id)},[e.id,i]),t.jsx("div",{children:t.jsx(tu,{onGetTotal:l=>{o&&o(e.id,l)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:a,readOnly:e==null?void 0:e.isReadOnly})})}function ru({element:e}){return t.jsx("div",{className:de("py-6",e==null?void 0:e.customClass)})}function du({element:e}){return t.jsx("div",{children:t.jsx("hr",{className:de("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function uu({element:e,validationData:n}){const{register:i=()=>({})}=n||{};return t.jsx("div",{children:t.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...i(e==null?void 0:e.id)})})}function cu({element:e,state:n}){return t.jsx(t.Fragment,{children:t.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&t.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function mu({row:e,columns:n,isReadOnly:i,handleCellChange:o,getValidationStatus:s,deleteRow:a}){return t.jsxs("tr",{children:[n.map(l=>{var v;const r=e[l.field],d=l.editable&&!i,{isValidating:u,result:m}=s(e.id,l.field);let c="border-gray-300";l.validate&&((m==null?void 0:m.isValid)===!1?c="border-red-500 bg-red-50":(m==null?void 0:m.isValid)===!0&&(c="border-green-500 bg-green-50"));const b=`w-full py-1 rounded outline-none ${c}`;return t.jsx("td",{className:"px-3 py-1 border-b border-r last:border-r-0",children:d?t.jsxs("div",{className:"relative",children:[l.type==="number"?t.jsx(ei,{value:r,decimalsLimit:6,allowNegativeValue:!1,className:b,onValueChange:h=>o(h,e.id,l.field)}):l.type==="checkbox"?t.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(h=>{const p=h==="yes",y=`radio-${e.id}-${String(l.field)}-${h}`;return t.jsxs("label",{htmlFor:y,className:"flex items-center gap-1 cursor-pointer",children:[t.jsx("input",{id:y,type:"radio",name:`boolean-${e.id}-${String(l.field)}`,checked:r===p,onChange:()=>o(p,e.id,l.field)}),t.jsx("span",{className:"text-sm",children:p?"Yes":"No"})]},h)})}):l.type==="select"?t.jsx(Bn,{name:String(l.field),options:l.options||[],apiUrl:l.optionsUrl,value:r,onGetValue:(h,p)=>o((p==null?void 0:p.value)||"",e.id,l.field),customClass:"!border-none !p-0"}):t.jsx("input",{type:"text",value:String(r!=null?r:""),onChange:h=>o(h.target.value,e.id,l.field),className:b}),u&&t.jsx("div",{className:"absolute right-1 top-1",children:t.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):l.validate&&m?t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{children:[String(r!=null?r:"")," ",m.data&&`[${m.data}]`]}),m.isValid?t.jsx("span",{className:"text-xs text-green-600",children:"✓"}):t.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(v=m.error)!=null?v:"",children:"✗"})]}):l.type==="select"?t.jsx(Bn,{name:String(l.field),options:l.options||[],apiUrl:l.optionsUrl,value:r,onGetValue:()=>{},readOnly:!0,customClass:"!border-none !bg-transparent !p-0 !text-gray-700 pointer-events-none"}):l.type==="checkbox"?t.jsx("span",{className:"block py-1 text-gray-700",children:r===!0?"Yes":r===!1?"No":""}):t.jsx("span",{className:"block py-1 text-gray-700",children:String(r!=null?r:"")})},String(l.id))}),!i&&t.jsx("td",{className:"px-3 py-1 text-center border sticky right-0 bg-gray-50 z-10",children:t.jsx("button",{type:"button",onClick:()=>a(e.id),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:t.jsx(te,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const bu=x.memo(mu);function vu({value:e=[],onChange:n,isReadOnly:i=!1,columns:o}){const[s,a]=x.useState(e),l=xe("config"),r=x.useRef(s);r.current=s,x.useEffect(()=>{a(b=>JSON.stringify(b)!==JSON.stringify(e)?e:b)},[e]);const d=x.useCallback((b,v,h)=>{const p=r.current.map(y=>y.id===v?{...y,[h]:b}:y);a(p),n==null||n(p)},[n]),u=x.useCallback(()=>{const b=Ce.v4(),v=o.reduce((p,y)=>(p[y.field]=y.field==="id"?b:"",p),{}),h=[...r.current,{id:b,...v}];a(h),n==null||n(h)},[o,n]),m=x.useCallback(b=>{const v=r.current.filter(h=>h.id!==b);a(v),n==null||n(v)},[n]),c=x.useCallback(()=>({isValidating:!1,result:void 0}),[]);return t.jsxs("div",{className:"mt-3 rounded",children:[t.jsx("div",{className:"w-full max-w-full overflow-x-auto border rounded-lg",children:t.jsxs("table",{className:"min-w-max w-full text-sm border-collapse table-auto",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"bg-gray-100",children:[o.map((b,v)=>{var h;return t.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border-b whitespace-nowrap",children:[(h=b.headerName)!=null?h:String(b.field),b.validate&&t.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(b.id)}-${v}`)}),!i&&t.jsx("th",{className:"w-10 px-2 py-2 border sticky right-0 bg-gray-100 z-10"})]})}),t.jsx("tbody",{children:s.length>0?s.map(b=>t.jsx(bu,{row:b,columns:o,isReadOnly:i,handleCellChange:d,getValidationStatus:c,deleteRow:m},b.id)):t.jsx("tr",{children:t.jsx("td",{colSpan:o.length+(i?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})}),!i&&t.jsx("div",{className:"flex justify-center mt-2",children:t.jsx("button",{onClick:u,type:"button",style:{color:(l==null?void 0:l.buttonColor)||"#333"},className:"px-2 py-1 mb-3 text-xs text-gray-600 font-medium",children:"+ Add Row"})})]})}function hu({element:e,validationData:n}){var v;const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:a}=n||{},l=s&&s(e==null?void 0:e.id)||{},r=Array.isArray(l)?l:(v=l==null?void 0:l.rows)!=null?v:[];x.useEffect(()=>{i(e.id)},[e.id,i]);const d=x.useRef(""),u=x.useRef(e==null?void 0:e.id),m=x.useRef(e==null?void 0:e.dataColumns),c=x.useRef(o);u.current=e==null?void 0:e.id,m.current=e==null?void 0:e.dataColumns,c.current=o;const b=x.useCallback(h=>{var y;const p=JSON.stringify(h);p!==d.current&&(d.current=p,(y=c.current)==null||y.call(c,u.current,{rows:h,columns:m.current}))},[]);return t.jsx(vu,{value:r,onChange:b,columns:e==null?void 0:e.dataColumns,isReadOnly:a})}const Rs=({className:e="",options:n=[],placeholder:i="Select",errors:o,register:s,setValue:a,name:l,label:r,value:d,trigger:u,isMultiple:m=!1,isFloatingLabel:c=!1,subText:b,labelClass:v="",loading:h,disabled:p})=>{const[y,f]=x.useState(m?[]:null),N=de("custom-select__control",e),g=x.useMemo(()=>n,[n]);return x.useEffect(()=>{const S=n==null?void 0:n.find(w=>{var A;return typeof w.value=="string"&&typeof d=="string"?w.value.toLowerCase()===d.toLowerCase():typeof w.value=="object"&&typeof d=="object"?((A=w.value)==null?void 0:A.id)===(d==null?void 0:d.id):w.value===d});f(S||null)},[d,n]),x.useEffect(()=>{y&&a&&s&&(a(l,y==null?void 0:y.value),s(l),u==null||u(l))},[l,y]),t.jsxs("div",{className:"custom-select",children:[r&&!c&&t.jsx("label",{className:"custom-select__label",children:r}),c&&r&&t.jsx("label",{className:de("custom-select__floating-label",v),children:r}),t.jsx(re.Listbox,{value:y,onChange:f,multiple:m,disabled:p,children:t.jsxs("div",{className:"custom-select__wrapper",children:[t.jsxs(re.Listbox.Button,{className:N,disabled:p,children:[h?t.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):t.jsx("span",{className:"custom-select__value",children:(y==null?void 0:y.label)||t.jsx("span",{className:"custom-select__placeholder",children:i})}),t.jsx("span",{className:"custom-select__icon",children:t.jsx(te,{icon:"lucide:chevron-down"})})]}),t.jsx(re.Transition,{as:x.Fragment,leave:"custom-select__transition",children:t.jsx(re.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:g==null?void 0:g.map((S,w)=>t.jsx(re.Listbox.Option,{value:S,className:({active:A})=>de("custom-select__option",A&&"custom-select__option--active"),children:({selected:A})=>t.jsx("span",{className:de("custom-select__option-label",A&&"custom-select__option--selected"),children:S.label})},w))})})]})}),b&&!o&&t.jsx("p",{className:"custom-select__subtext",children:b}),o&&t.jsx("span",{className:"custom-select__error",children:o.message})]})},fu=({element:e,validationData:n})=>{var p;const{register:i=()=>({}),trigger:o,setValue:s,watch:a,isReadOnly:l}=n||{},r=(p=e==null?void 0:e.id)!=null?p:"cascadeValue",[d,u]=x.useState(""),[m,c]=x.useState(""),b=(y,f)=>{const N=y&&f?`${y}_${f}`:"";s==null||s(r,N),o==null||o(r)},v=(y,f)=>{y==="first"?(u(f),c(""),b(f,"")):(c(f),b(d,f))};x.useEffect(()=>{if(a){const y=a(r);if(y!=null&&y.includes("_")){const[f,N]=y.split("_");u(f),c(N)}}},[a,r]);const h=x.useMemo(()=>{var y;return(y=e.options1)==null?void 0:y.filter(f=>f.key===d)},[e.options1,d]);return!e.options||!e.options1?null:t.jsxs("div",{children:[t.jsx("input",{type:"hidden",...i(r)}),t.jsx("div",{className:"relative",children:t.jsx(Rs,{setValue:(y,f)=>v("first",f),options:e.options,name:`${r}`,register:i,value:d})}),d&&t.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&t.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),t.jsx(Rs,{setValue:(y,f)=>v("second",f),options:h,name:`${r}`,register:i,value:m})]})]})},pu=({value:e=0,max:n=5,readOnly:i=!1,onChange:o,size:s=24,className:a="",element:l,validationData:r})=>{var f;const{register:d=()=>({}),trigger:u,setValue:m,watch:c,isReadOnly:b}=r||{},v=(f=c==null?void 0:c(l.id))!=null?f:0,[h,p]=x.useState(null);x.useEffect(()=>{v==null&&(m==null||m(l.id,e))},[]);const y=N=>{if(!i&&!b){const g=N+1;m==null||m(l.id,g),u==null||u(l.id),o==null||o(g)}};return t.jsxs("div",{className:`flex gap-1 ${a}`,children:[t.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(N,g)=>{const S=h!==null?g<=h:g<v;return t.jsx(Us,{icon:S?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${S?"text-yellow-400":"text-gray-300"}`,width:s,height:s,onMouseEnter:()=>!(i||b)&&p(g),onMouseLeave:()=>!(i||b)&&p(null),onClick:()=>y(g)},g)})]})};function gu({element:e,validationData:n}){const{register:i=()=>({})}=n||{},o=(e==null?void 0:e.options)||[],s=(e==null?void 0:e.options1)||[];return t.jsx("div",{className:de("w-full overflow-x-auto",e.customClass),children:t.jsxs("table",{className:"w-full text-left border-collapse min-w-[600px] mb-2",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{className:"p-3 border-b bg-gray-50/50"}),s.map(a=>t.jsx("th",{className:"p-3 font-medium text-center border-b text-xs text-gray-700 w-[12%]",children:a.label},a.id||a.value))]})}),t.jsx("tbody",{children:o.map(a=>t.jsxs("tr",{className:"border-b last:border-0 hover:bg-gray-50/30",children:[t.jsx("td",{className:"p-3 text-gray-700 min-w-[150px] text-sm",children:a.label}),s.map(l=>t.jsx("td",{className:"p-3 text-center align-middle",children:t.jsx("input",{type:"radio",value:l.value,disabled:e.isDisabled||(n==null?void 0:n.isReadOnly),className:"w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 cursor-pointer disabled:opacity-50",...i(`${e.id}.${a.value}`)})},l.id||l.value))]},a.id||a.value))})]})})}function ea({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,trigger:s,isReadOnly:a,watch:l}=n||{},r=(l==null?void 0:l(e.id))||"",{country:d,state:u}=x.useMemo(()=>{var h;if(typeof r=="string"&&r.includes(",")){const[p,y]=(h=r.split(","))==null?void 0:h.map(f=>f.trim());return{country:y,state:p}}return{country:r,state:""}},[r]),m=x.useRef(r),c=x.useMemo(()=>{var h,p;return d?((p=(h=ai.find(y=>y.name===d))==null?void 0:h.states)==null?void 0:p.map(y=>({label:y.name,value:y.name})))||[]:[]},[d]),b=(h,p)=>{const f=(p==null?void 0:p.value)||"";o&&f!==m.current&&(o(e.id,f),s==null||s(e.id),m.current=f)},v=(h,p)=>{const y=(p==null?void 0:p.value)||"",f=y?`${y}, ${d}`:d;o&&f!==m.current&&(o(e.id,f),s==null||s(e.id),m.current=f)};return x.useEffect(()=>{m.current=r},[r]),t.jsxs("div",{className:"grid gap-y-6",children:[t.jsx("input",{type:"hidden",...i(e.id)}),t.jsx(Bn,{options:e.options,onGetValue:b,name:`${e.id}-country`,readOnly:a,defaultValue:d},`country-${d}`),c.length>0&&e.showState&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),t.jsx(Bn,{options:c,onGetValue:v,name:`${e.id}-state`,readOnly:a,defaultValue:u},`state-${u}`)]})]})}function yu({element:e,validationData:n}){const{register:i=()=>({}),isReadOnly:o}=n||{},{validationUrl:s,documentObj:a,signatureLink:l}=e,r=x.useMemo(()=>xe("config"),[]),[d,u]=x.useState(!1),[m,c]=x.useState(!1),b=x.useCallback(async()=>{var v,h;if(!(!s||!a))try{c(!0);const y={headers:{Authorization:`Bearer ${xe("token")}`}},{data:f}=await Xe.get(`${s}/${a}`,y),N=!!((h=(v=f==null?void 0:f.data)==null?void 0:v.isSigned)!=null?h:f!=null&&f.isSigned);return u(N),N}catch(p){console.error("Failed to check sign status",p)}finally{c(!1)}},[s,a]);return x.useEffect(()=>{let v=null;return!d&&a&&s&&(async()=>{await b()||(v=setInterval(async()=>{await b()&&v&&clearInterval(v)},2e3))})(),()=>{v&&clearInterval(v)}},[b,d,a,s]),t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:de("field-control",e.customClass),...i(e.id),disabled:o}),t.jsx("a",{href:d?"#":l,children:t.jsxs("button",{type:"button",onClick:b,disabled:m||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:de("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":m}),children:[t.jsx(te,{icon:m?"solar:refresh-outline":d?"solar:check-circle-bold":"solar:pen-2-line-duotone",iconClass:m?"animate-spin":""}),m?"Checking...":d?"Signed":"Sign"]})})]})}const ho=[{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 xu({label:e,placeholder:n,classLabel:i,isRequired:o,isOptional:s,name:a,value:l,error:r,disabled:d,readOnly:u,horizontal:m,description:c,validate:b,onChange:v,onError:h}){const[p,y]=x.useState(""),[f,N]=x.useState(null),[g,S]=x.useState(""),w=x.useMemo(()=>{var T;return(T=ho==null?void 0:ho.slice().sort((O,M)=>O.label.localeCompare(M.label)))==null?void 0:T.map(O=>({...O,phone:`+${O.phone}`}))},[]),A=x.useMemo(()=>p?w.filter(T=>`${T.label} ${T.phone}`.toLowerCase().includes(p.toLowerCase())):w,[p,w]),C=(f==null?void 0:f.min)||10,E=(f==null?void 0:f.max)||10,k=()=>g?`${(f==null?void 0:f.phone)||"+234"}-${g}`:"",B=T=>{if(!T)return{code:"+234",number:""};const O=T.split(/[-\s]/);return{code:O[0],number:O.slice(1).join(" ")}};x.useEffect(()=>{if(l){const T=B(l);N(w.find(O=>O.phone===T.code)||w[0]),S(T.number)}},[l,w]);const P=x.useMemo(()=>{if(r)return r;const T=g.length;return o&&T===0?"Phone number is required":T>0&&!/^\d+$/.test(g)?"Phone number must contain only digits":T>0&&T<C?`Minimum length is ${C}`:T>E?`Maximum length is ${E}`:""},[r,g,C,E,o]);return x.useEffect(()=>{v==null||v(k()),h==null||h(P||null)},[g,f,P]),t.jsxs("div",{className:`relative formGroup ${P&&!u?"has-error":""} ${m?"flex":""} ${!P&&g.length>0&&!u?"is-valid":""}`,children:[e&&t.jsxs("label",{htmlFor:a,className:`${i} ${m?"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," ",o&&t.jsx("span",{className:"text-red-500",children:"*"}),s&&t.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),t.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[t.jsx(te,{icon:"lucide:phone-call"}),t.jsx(re.Combobox,{value:f,onChange:N,children:t.jsxs("div",{className:"relative",children:[t.jsx(re.Combobox.Input,{className:"pl-3 pr-4 mr-1 text-sm bg-white py-[10px] outline-none whitespace-nowrap max-w-[70px]",displayValue:T=>(T==null?void 0:T.phone)||"+234",placeholder:"+234",onChange:T=>y(T.target.value)}),t.jsx(re.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:t.jsx(te,{icon:"lucide:chevron-down"})}),t.jsx(re.Combobox.Options,{className:"absolute z-10 w-[250px] left-0 bg-white border rounded-md shadow-lg max-h-[400px] overflow-y-auto",children:A==null?void 0:A.map((T,O)=>t.jsxs(re.Combobox.Option,{value:T,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[T.phone," - ",T.label]},`${T.code}+ ${O}`))})]})}),t.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[t.jsx("input",{type:"tel",inputMode:"numeric",value:g,disabled:d,readOnly:u,onChange:T=>{const O=T.target.value.replace(/\D/g,"");S(O)},placeholder:n,className:"w-full px-3 outline-none",maxLength:E,minLength:C}),t.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!P&&g.length>0&&!u&&t.jsx("span",{className:"text-green-500",children:t.jsx(te,{icon:"bi:check-lg"})})})]})]}),c&&t.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:c})]})}function Su({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:a,setError:l,clearErrors:r}=n||{};let d;return x.useEffect(()=>{i(e.id)},[e.id,i]),s&&(d=s()[e.id]),t.jsx(xu,{placeholder:e.placeholder,label:"",name:e.id,value:d,readOnly:a,disabled:a,onError:u=>{u?l==null||l(e.id,{type:"manual",message:u}):r==null||r(e.id)},onChange:u=>{u&&(o==null||o(e.id,u))}})}function wu({element:e,validationData:n}){var u;const{register:i=()=>({}),watch:o}=n||{};let s="";o&&(s=(u=o()[e.id])!=null?u:"");const a=s.trim(),l=/^https?:\/\//i.test(a),r=a?l?a:`https://${a}`:"",d=!l;return t.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&t.jsxs("div",{className:"relative",children:[d&&t.jsx("span",{className:"text-sm absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none select-none",children:"https://"}),t.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:de("field-control",d&&"!pl-16",e==null?void 0:e.customClass),...i(e==null?void 0:e.id),disabled:n==null?void 0:n.isReadOnly})]}),a?t.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:t.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:a})}):(n==null?void 0:n.isReadOnly)&&t.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}function Nu({element:e,validationData:n}){var d;const{watch:i,setValue:o}=n||{},s=(e==null?void 0:e.formula)||"",a=x.useMemo(()=>{const m=(s.match(/\{\{([^{}]+)\}\}/g)||[]).map(v=>v.replace(/[{}]/g,"")),b=(s.match(/@\[.*?\]\((.*?)\)/g)||[]).map(v=>{const h=/@\[.*?\]\((.*?)\)/.exec(v);return h?h[1]:""}).filter(Boolean);return Array.from(new Set([...m,...b]))},[s]),l=i?i(a):[],r=x.useMemo(()=>{if(!s)return"";let u=s,m=!1;if(a.forEach((c,b)=>{const v=l[b],h=Number(v);(isNaN(h)||v===void 0||v===null||v==="")&&(m=!0),u=u.replace(new RegExp(`\\{\\{${c}\\}\\}`,"g"),String(h||0)),u=u.replace(new RegExp(`@\\[.*?\\]\\(${c}\\)`,"g"),String(h||0))}),m)return"";try{const c=u.replace(/[^0-9+\-*/().\s]/g,"");if(!c)return"";const b=new Function(`return ${c}`)();return!isNaN(b)&&b!==null?Number.isInteger(b)?b:Number(b.toFixed(2)):""}catch(c){return"Error"}},[s,a,l]);return x.useEffect(()=>{o&&r!=="Error"&&r!==""&&o(e.id,r,{shouldValidate:!0,shouldDirty:!0})},[r,e.id,o]),t.jsx("div",{children:t.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Calculated result",type:"text",className:de("field-control bg-gray-100 cursor-not-allowed",e==null?void 0:e.customClass),value:r,readOnly:!0,disabled:!0,"aria-invalid":!!((d=n==null?void 0:n.errors)!=null&&d[e==null?void 0:e.id])})})}function Au({element:e,validationData:n,state:i}){var v;const{register:o,watch:s,setValue:a}=n||{},[l,r]=x.useState({}),[d,u]=x.useState(0),m=s?s(e.id):null,c=!!(m||i&&i!=="edit");x.useEffect(()=>{if(!e.fetchExternalResults||!e.externalApiUrl)return;const h=async()=>{try{const y=await fetch(e.externalApiUrl);if(!y.ok)return;const f=await y.json();let N={};Array.isArray(f)?f.forEach(S=>{const w=S.value||S.id||S.option,A=S.count||S.votes||S.value||0;w&&(N[w]=Number(A))}):typeof f=="object"&&(N=f),r(N);const g=Object.values(N).reduce((S,w)=>S+Number(w),0);u(g)}catch(y){console.error("Failed to fetch polling results",y)}};h();const p=setInterval(h,1e4);return()=>clearInterval(p)},[e.fetchExternalResults,e.externalApiUrl]),x.useEffect(()=>{e.fetchExternalResults||(m?(r({[m]:1}),u(1)):(r({}),u(0)))},[m,e.fetchExternalResults]);const b=h=>{n!=null&&n.isReadOnly||a&&a(e.id,h,{shouldValidate:!0,shouldDirty:!0})};return t.jsxs("div",{className:"w-full",children:[t.jsx("div",{className:"grid gap-y-3",children:(v=e.options)==null?void 0:v.map(h=>{const p=l[h.value]||0,y=d>0?Math.round(p/d*100):0,f=m===h.value;return t.jsxs("div",{onClick:()=>b(h.value),className:de("relative flex items-center justify-between p-3 border rounded-lg overflow-hidden transition-all duration-200",n!=null&&n.isReadOnly?"cursor-default":"cursor-pointer hover:border-blue-400 hover:bg-blue-50/50",f?"border-blue-500 ring-1 ring-blue-500":"border-gray-200"),children:[c&&t.jsx("div",{className:"absolute top-0 left-0 bottom-0 bg-blue-100/60 transition-all duration-1000 ease-out",style:{width:`${y}%`}}),t.jsxs("div",{className:"relative z-10 flex items-center gap-3",children:[t.jsx("div",{className:de("flex-shrink-0 w-5 h-5 rounded-full border flex items-center justify-center transition-colors",f?"border-blue-500 bg-blue-500":"border-gray-300 bg-white"),children:f&&t.jsx("div",{className:"w-2 h-2 bg-white rounded-full"})}),t.jsx("span",{className:de("font-medium text-sm",f?"text-blue-900":"text-gray-700"),children:h.label||h.name||h.option||h.value||"Unknown Option"})]}),c&&t.jsxs("div",{className:"relative z-10 flex items-center gap-2",children:[t.jsxs("span",{className:"text-sm font-semibold text-gray-700",children:[y,"%"]}),f&&t.jsx(te,{icon:"material-symbols:check-circle",iconClass:"text-blue-500 text-lg"})]}),t.jsx("input",{type:"radio",value:h.value,className:"hidden",...o?o(e.id):{}})]},h.id||h.value)})}),c&&t.jsxs("div",{className:"mt-3 text-xs text-gray-500 text-right flex justify-between items-center",children:[t.jsxs("span",{children:[d," ",d===1?"vote":"votes"," total"]}),e.fetchExternalResults&&e.externalApiUrl&&t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"})," Live"]})]})]})}const na={textField:Zi,longText:Md,selectField:kd,multiSelect:lo,numberField:Zi,amountField:iu,date:fr,password:wd,checkbox:Cd,radio:Nd,email:Zi,file:Sd,dataGrid:hu,section:Ad,validateInput:au,tableInput:lu,spacer:ru,divider:du,header:uu,basicText:cu,phoneField:Su,cascadeSelect:fu,rating:pu,matrix:gu,country:ea,bank:ea,document:yu,url:wu,calculatedField:Nu,polling:Au},ia="edit",Cu=(e,n)=>{var o;const i=na[e.type];return i?t.jsx(vo,{element:e,state:ia,children:t.jsxs("div",{className:"relative w-full",children:[((o=e.type)==null?void 0:o.toLowerCase())!=="grid"&&t.jsx("div",{className:"absolute top-0 left-0 z-20 w-full h-full"}),t.jsx(i,{element:e,state:ia,sectionId:n})]})}):t.jsx("div",{className:"flex items-center justify-center p-4 text-red-500 bg-red-50 border border-red-200 rounded-md",children:t.jsxs("span",{className:"text-sm font-medium",children:["Unsupported element type: ",e.type]})})},li=({col:e,children:n,customClass:i})=>t.jsx("div",{className:de("w-full bg-white min-w-0",i),style:{gridColumn:e},children:n}),ku=({element:e,sectionId:n,children:i,customClass:o,state:s,draggedElementId:a})=>{const{formData:l,addElement:r,setIsDragging:d,moveElement:u,isDragging:m,removeElement:c}=x.useContext(Ae),b=x.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[v,h]=x.useState(null);x.useEffect(()=>{const S=()=>{h(null),d(!1)};return document.addEventListener("dragend",S),()=>document.removeEventListener("dragend",S)},[d]);const p=x.useCallback((S,w)=>{S.preventDefault(),S.stopPropagation(),S.dataTransfer.dropEffect="move",h(w)},[]),y=x.useCallback((S,w)=>{S.preventDefault(),S.stopPropagation(),h(w)},[]),f=x.useCallback((S,w)=>{const A=S.relatedTarget;A&&S.currentTarget.contains(A)||h(C=>C===w?null:C)},[]),N=x.useCallback((S,w)=>{var E;S.preventDefault(),S.stopPropagation(),d(!1),h(null);const A=w+1,C=S.dataTransfer.getData("elementId");if(C){u({draggedId:C,sectionId:n,targetGridId:e.id,targetCol:A});return}try{const k=S.dataTransfer.getData("properties");if(!k)return;const B=JSON.parse(k);if((B==null?void 0:B.type)==="grid")return;const P=l.find(M=>M.id===n),T=(E=P==null?void 0:P.questionData)==null?void 0:E.find(M=>{var D;return M.gridId===e.id&&((D=M.gridPosition)==null?void 0:D.col)===A});T&&c(T.id,n);const O={...B,id:Ce.v4(),sectionId:n,gridId:e.id,gridPosition:{col:A}};r(O,n)}catch(k){console.error("Drop failed in grid:",k),d(!1)}},[r,e.id,l,n,d,u]),g=(S,w,A)=>{var D,I,K;const C=S+1,E=(I=(D=l.find(_=>_.id===n))==null?void 0:D.questionData)==null?void 0:I.find(_=>{var L;return _.gridId===e.id&&((L=_.gridPosition)==null?void 0:L.col)===C}),k=(K=E==null?void 0:E.id)!=null?K:null,B=Array.isArray(i)&&i.find(_=>{var L;return((L=_==null?void 0:_.props)==null?void 0:L.col)===C}),P=m&&v===S,T=!!B,O=m&&!!a,M=T&&k&&A==="edit"?{draggable:!0,onDragStart:_=>{_.stopPropagation(),_.dataTransfer.setData("elementId",k),_.dataTransfer.setData("properties",k),_.dataTransfer.effectAllowed="move",d(!0)},onDragEnd:()=>{h(null),d(!1)}}:{};return t.jsx("div",{className:"min-w-0",children:t.jsxs("div",{id:`grid-cell-${e.id}-${S}`,...M,onDrop:_=>N(_,S),onDragEnter:_=>y(_,S),onDragOver:_=>p(_,S),onDragLeave:_=>f(_,S),className:de("relative border rounded-lg min-h-[110px] min-w-0","flex items-center justify-center","transition-all duration-200 ease-in-out",A==="edit"?"py-3 ":"",T&&A==="edit"&&"cursor-grab active:cursor-grabbing border-none",w,!O&&!P&&"bg-white border-gray-200 text-gray-300",O&&!P&&!T&&"bg-blue-50 border-blue-200 border-dashed text-blue-300",O&&!P&&T&&"bg-white border-orange-200 border-dashed",P&&!T&&"bg-blue-100 border-blue-400 border-dashed shadow-inner scale-[1.01] text-blue-500",P&&T&&"bg-orange-50 border-orange-400 border-dashed shadow-inner scale-[1.01] text-orange-500"),children:[T&&A==="edit"&&t.jsx("div",{className:"absolute top-1 left-1/2 -translate-x-1/2 flex items-center gap-0.5 px-2 py-0.5 rounded-full bg-gray-100 hover:bg-blue-100 text-gray-400 hover:text-blue-500 cursor-grab active:cursor-grabbing transition-colors z-10 opacity-60 hover:opacity-100 pointer-events-none select-none",children:t.jsx(te,{icon:"ph:dots-six-bold"})}),P&&!T&&t.jsxs("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-blue-400 text-xs font-medium pointer-events-none",children:[t.jsx(te,{icon:"ph:plus-bold"}),"Drop here"]}),P&&T&&t.jsx("span",{className:"absolute top-1 right-1 text-xs text-orange-400 font-medium pointer-events-none px-1 py-0.5 bg-orange-50 rounded",children:"Replace"}),t.jsx("div",{className:de("w-full select-none min-w-0",P&&"opacity-50 pointer-events-none"),children:B||t.jsx("span",{className:"flex items-center justify-center text-gray-300",children:A==="edit"&&t.jsx(te,{icon:"ph:plus-bold"})})})]})},S)};return t.jsx("div",{className:"relative w-full",children:t.jsx("div",{className:"grid w-full gap-3 items-center",style:{gridTemplateColumns:`repeat(${e.columns}, minmax(0, 1fr))`},children:b==null?void 0:b.map((S,w)=>g(w,o,s))})})},ri=x.memo(ku),Mu="edit";function fo({index:e,onDrop:n,onDragEnd:i,isDragging:o}){const[s,a]=x.useState(!1),l=s?52:o?28:4;return t.jsx("div",{onDragEnter:r=>{r.preventDefault(),a(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),a(!0)},onDragLeave:()=>a(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),a(!1),n(r,e)},onDragEnd:()=>{a(!1),i()},style:{height:`${l}px`},className:de("w-full rounded-md flex items-center justify-center","transition-all duration-150 ease-in-out overflow-hidden",s?"bg-blue-50 border-2 border-blue-300 border-dashed":o?"border-2 border-blue-200 border-dashed":"border-2 border-transparent"),children:s&&t.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[t.jsx(te,{icon:"octicon:plus-16"}),"Drop here"]})})}function Eu({elementData:e,sectionId:n}){const{formData:i,isDragging:o,setIsDragging:s,addElementInPosition:a,moveElement:l}=x.useContext(Ae),[r,d]=x.useState(null),u=x.useMemo(()=>{var f;return((f=i.find(N=>N.id===n))==null?void 0:f.questionData)||[]},[i,n]),m=x.useCallback((f,N)=>{f.dataTransfer.setData("elementId",N),f.dataTransfer.setData("properties",N),f.dataTransfer.effectAllowed="move",d(N),s(!0)},[s]),c=x.useCallback(()=>{d(null),s(!1)},[s]);x.useEffect(()=>{!o&&r&&d(null)},[o,r]);const b=x.useCallback(f=>{f.preventDefault(),f.stopPropagation();const N=f.dataTransfer.getData("elementId"),g=f.currentTarget.id;if(!N||!g||N===g){c();return}const S=u.find(A=>A.id===N),w=u.findIndex(A=>A.id===g);S!=null&&S.gridId&&w!==-1?l({draggedId:N,sectionId:n,targetIndex:w}):l({draggedId:N,sectionId:n,targetId:g}),d(null),s(!1)},[n,l,s,c,u]),v=x.useCallback((f,N)=>{f.preventDefault(),f.stopPropagation(),s(!1);const g=f.dataTransfer.getData("elementId");if(g){l({draggedId:g,sectionId:n,targetIndex:N}),d(null);return}try{const S=JSON.parse(f.dataTransfer.getData("properties"));if((S==null?void 0:S.type)==="section")return;const w={...S,id:Ce.v4(),sectionId:n};a(w,n,N),d(null)}catch(S){console.error("Drop error:",S)}},[a,n,s,l]),h=x.useCallback((f,N=!1)=>t.jsx("div",{id:f.id,draggable:!0,onDragStart:g=>m(g,f.id),onDragOver:N?void 0:g=>{g.preventDefault(),g.stopPropagation()},onDrop:N?void 0:b,onDragEnd:c,className:de("cursor-grab active:cursor-grabbing border p-4 w-full rounded-lg","transition-all duration-200 ease-in-out",r===f.id?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-300 shadow-inner":r?"bg-white border-dashed border-blue-200 shadow-sm":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:Cu(f,n)},f.id),[r,b,n,m,c]),p=x.useMemo(()=>(e==null?void 0:e.reduce((f,N)=>(N.gridId&&(f[N.gridId]=f[N.gridId]||[],f[N.gridId].push(N)),f),{}))||{},[e]);if(!(e!=null&&e.length))return t.jsx("div",{onDragOver:f=>f.preventDefault(),onDrop:f=>v(f,0),onDragEnd:c,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 y=e.filter(f=>!f.gridId);return t.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[t.jsx(fo,{index:0,isDragging:o,onDrop:v,onDragEnd:c}),y.map(f=>{const N=u.findIndex(g=>g.id===f.id);if(f.type==="grid"){const g=p[f.id]||[],S=r===f.id,w=!!r&&!S;return t.jsxs("div",{className:"flex flex-col gap-0",children:[t.jsx("div",{id:f.id,draggable:!0,onDragStart:A=>m(A,f.id),onDragOver:A=>{A.preventDefault(),A.stopPropagation()},onDrop:b,onDragEnd:c,className:de("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",S?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":w?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:t.jsx(vo,{element:f,state:"edit",children:t.jsx(ri,{element:f,sectionId:n,state:Mu,draggedElementId:r,children:g==null?void 0:g.map(A=>{var C;return t.jsx(li,{col:(C=A.gridPosition)==null?void 0:C.col,children:h(A,!0)},A.id)})})})}),t.jsx(fo,{index:N+1,isDragging:o,onDrop:v,onDragEnd:c})]},f.id)}return t.jsxs("div",{className:"flex flex-col gap-0",children:[h(f),t.jsx(fo,{index:N+1,isDragging:o,onDrop:v,onDragEnd:c})]},f.id)})]})}const Tu=x.memo(Eu),Pu=ne.object({title:ne.string(),description:ne.string(),disabled:ne.boolean().default(!1),isHidden:ne.boolean().default(!1)}).required(),po=xe("config"),Lu=({isOpen:e,onClose:n,section:i})=>{const{updateSection:o}=x.useContext(Ae),{register:s,handleSubmit:a,watch:l,formState:{errors:r,isSubmitting:d,isValid:u},reset:m}=Ve.useForm({resolver:ro(Pu),defaultValues:i});if(x.useEffect(()=>{e||m()},[e,m]),!e)return null;const c=v=>{o(v,i.id),n()},b=l();return t.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:t.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[t.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 mb-6",children:[t.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Update Section Information"}),t.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:t.jsx(te,{icon:"tabler:x"})})]}),t.jsxs("form",{onSubmit:a(c),className:"w-full",autoComplete:"off",children:[t.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[t.jsx(le,{label:"Title",name:"title",register:s,errors:r,watch:l}),t.jsx(le,{label:"Description",name:"description",register:s,errors:r,watch:l,type:"textarea"}),t.jsx(le,{label:"Disable Section",name:"disabled",register:s,errors:r,watch:l,type:"checkbox",value:b.disabled,description:"Disables all fields in this section"}),t.jsx(le,{label:"Hide Section",name:"isHidden",register:s,errors:r,watch:l,type:"checkbox",value:b.isHidden,description:"Hides this section from the form"})]}),t.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[t.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"}),t.jsx("button",{type:"submit",disabled:!u||d,style:{background:(po==null?void 0:po.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!u||d?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!u||d?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:d?"Saving...":"Save"})]})]})]})})},Bu=({isOpen:e,onClose:n,templates:i,onSelect:o})=>e?t.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:t.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[t.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 border-b",children:[t.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Select a Template"}),t.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:t.jsx(te,{icon:"tabler:x"})})]}),t.jsx("div",{className:"w-full max-h-[60vh] overflow-y-auto px-6 py-4 flex flex-col gap-4",children:i!=null&&i.length?i.map(s=>t.jsxs("div",{className:"p-4 border rounded-lg cursor-pointer hover:border-blue-500 hover:shadow-md transition-all",onClick:()=>{o(s),n()},children:[t.jsx("h3",{className:"font-semibold text-[#344054] mb-1",children:s.name}),s.description&&t.jsx("p",{className:"text-sm text-[#475467]",children:s.description})]},s.id)):t.jsx("p",{className:"text-sm text-gray-500",children:"No templates available."})})]})}):null,Iu=[{id:"tpl-1",name:"Simple Contact Form",description:"A basic form to collect user contact info.",sections:[{id:"sec-contact",title:"Contact Info",description:"Please fill in your details",questionData:[{id:"q-name",type:"textField",label:"Text Field",inputLabel:"Full Name",inputType:"text"},{id:"q-email",type:"textField",label:"Text Field",inputLabel:"Email Address",inputType:"email"},{id:"q-phone",type:"phoneField",label:"Phone Number",inputLabel:"Phone Number"}]}]},{id:"tpl-2",name:"Feedback Form",description:"Collect user feedback.",sections:[{id:"sec-feedback",title:"Your Feedback",questionData:[{id:"q-rating",type:"numberField",label:"Number",inputLabel:"Rating (1-5)",inputType:"number"},{id:"q-comments",type:"longText",label:"Long Text Field",inputLabel:"Additional Comments",inputType:"text"}]}]},{id:"tpl-3",name:"Event Registration",description:"Register attendees for an upcoming event.",sections:[{id:"sec-event-reg",title:"Event Registration",questionData:[{id:"q-fname",type:"textField",label:"Text Field",inputLabel:"First Name",inputType:"text"},{id:"q-lname",type:"textField",label:"Text Field",inputLabel:"Last Name",inputType:"text"},{id:"q-company",type:"textField",label:"Text Field",inputLabel:"Company",inputType:"text"},{id:"q-diet",type:"textField",label:"Text Field",inputLabel:"Dietary Requirements",inputType:"text"}]}]},{id:"tpl-4",name:"Job Application",description:"Standard job application form.",sections:[{id:"sec-job",title:"Job Application",questionData:[{id:"q-applicant",type:"textField",label:"Text Field",inputLabel:"Full Name",inputType:"text"},{id:"q-portfolio",type:"textField",label:"Text Field",inputLabel:"Portfolio URL",inputType:"url"},{id:"q-cover",type:"longText",label:"Long Text Field",inputLabel:"Cover Letter",inputType:"text"},{id:"q-resume",type:"file",label:"File Upload",inputLabel:"Upload Resume"}]}]},{id:"tpl-5",name:"Customer Satisfaction Survey",description:"Measure customer satisfaction (CSAT).",sections:[{id:"sec-csat",title:"CSAT Survey",questionData:[{id:"q-csat-rate",type:"numberField",label:"Number",inputLabel:"How satisfied are you with our service? (1-10)",inputType:"number"},{id:"q-csat-recommend",type:"radio",label:"Radio",inputLabel:"Would you recommend us?",options:[{label:"Yes",value:"yes"},{label:"No",value:"no"}]}]}]},{id:"tpl-6",name:"Maintenance Request",description:"Submit a property or IT maintenance request.",sections:[{id:"sec-maintenance",title:"Maintenance Details",questionData:[{id:"q-maint-loc",type:"textField",label:"Text Field",inputLabel:"Location / Room",inputType:"text"},{id:"q-maint-desc",type:"longText",label:"Long Text Field",inputLabel:"Issue Description",inputType:"text"},{id:"q-maint-urgency",type:"selectField",label:"Select",inputLabel:"Urgency Level",options:[{label:"Low",value:"low"},{label:"Medium",value:"medium"},{label:"High",value:"high"}]}]}]},{id:"tpl-7",name:"Product Order Form",description:"Basic order form for merchandise or products.",sections:[{id:"sec-order-info",title:"Customer Info",questionData:[{id:"q-order-name",type:"textField",label:"Text Field",inputLabel:"Name",inputType:"text"},{id:"q-order-address",type:"longText",label:"Long Text Field",inputLabel:"Shipping Address",inputType:"text"}]},{id:"sec-order-details",title:"Order Details",questionData:[{id:"q-order-item",type:"textField",label:"Text Field",inputLabel:"Item Name",inputType:"text"},{id:"q-order-qty",type:"numberField",label:"Number",inputLabel:"Quantity",inputType:"number"}]}]},{id:"tpl-8",name:"Employee Onboarding",description:"Collect info for new hires.",sections:[{id:"sec-onboard",title:"Employee Details",questionData:[{id:"q-emp-name",type:"textField",label:"Text Field",inputLabel:"Legal Name",inputType:"text"},{id:"q-emp-start",type:"date",label:"Date Picker",inputLabel:"Start Date"},{id:"q-emp-dept",type:"textField",label:"Text Field",inputLabel:"Department",inputType:"text"}]}]},{id:"tpl-9",name:"Support Ticket",description:"IT or customer support ticket form.",sections:[{id:"sec-support",title:"Issue Details",questionData:[{id:"q-sup-subject",type:"textField",label:"Text Field",inputLabel:"Subject",inputType:"text"},{id:"q-sup-body",type:"longText",label:"Long Text Field",inputLabel:"Description",inputType:"text"},{id:"q-sup-file",type:"file",label:"File Upload",inputLabel:"Attach Screenshot"}]}]},{id:"tpl-10",name:"Course Evaluation",description:"Student feedback for a course.",sections:[{id:"sec-course",title:"Course Evaluation",questionData:[{id:"q-course-name",type:"textField",label:"Text Field",inputLabel:"Course Name",inputType:"text"},{id:"q-course-rate",type:"numberField",label:"Number",inputLabel:"Course Rating (1-10)",inputType:"number"},{id:"q-course-improve",type:"longText",label:"Long Text Field",inputLabel:"What could be improved?",inputType:"text"}]}]}],Du=({section:e,index:n,selectedSection:i,setSelectedSection:o,activeSections:s,toggleSection:a,handleSectionEdit:l,removeSection:r,formDataLength:d,onDragOver:u,setIsDragging:m,isDragging:c,onReorderSection:b})=>{var y,f;const v=x.useRef(null),h=x.useRef((y=e==null?void 0:e.questionData)==null?void 0:y.length),p=x.useRef(c);return x.useEffect(()=>{var N,g;if(((N=e==null?void 0:e.questionData)==null?void 0:N.length)>h.current&&!c&&!p.current){const S=document.getElementById("section-container");S&&requestAnimationFrame(()=>{S.scrollTo({top:S.scrollHeight,behavior:"smooth"})})}h.current=(g=e==null?void 0:e.questionData)==null?void 0:g.length},[(f=e==null?void 0:e.questionData)==null?void 0:f.length,c]),x.useEffect(()=>{p.current=c},[c]),t.jsx("div",{ref:v,onDragOver:N=>{N.dataTransfer.types.includes("sectionid")&&N.preventDefault()},onDrop:N=>{const g=N.dataTransfer.getData("sectionid");g&&(N.preventDefault(),N.stopPropagation(),b&&b(g,e.id))},className:"bg-white group cursor-pointer rounded-lg shadow-[rgba(149,157,165,0.2)_0px_2px_2px] transition-colors duration-200",children:t.jsxs("div",{className:` border border-gray-200 rounded-lg px-4 transition-colors duration-200
27
+ ${i===e.id?" border-blue-200 bg-gray-100":"bg-white"} ${s.includes(n)?"min-h-[300px] pb-6 ":""}`,children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{draggable:!0,onDragStart:N=>{N.dataTransfer.setData("sectionid",e.id),N.dataTransfer.effectAllowed="move",m(!0)},onDragEnd:()=>m(!1),onClick:()=>o(e.id),className:"flex-1 h-full py-4 cursor-grab active:cursor-grabbing flex items-center gap-2",title:"Drag to reorder section",children:[t.jsx(te,{icon:"material-symbols:drag-indicator",iconClass:"text-gray-400 text-lg"}),t.jsx("h2",{className:"font-medium",children:e.title||"Section title"})]}),t.jsxs("div",{className:"flex items-center gap-x-2",children:[t.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>l(e),children:t.jsx(te,{icon:"fluent:edit-28-regular"})}),d>1&&t.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>r(e.id),children:t.jsx(te,{icon:"lets-icons:trash-duotone-line"})}),t.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>a(n),children:t.jsx(te,{icon:s.includes(n)?"fa6-solid:chevron-up":"fa6-solid:chevron-down",iconClass:"text-base"})})]})]}),(e==null?void 0:e.description)&&s.includes(n)&&t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:e==null?void 0:e.description}),s.includes(n)&&t.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:e.id,onDragOver:u,onDragEnd:()=>m(!1),onClick:()=>o(e.id),children:[t.jsx("hr",{className:"group-last:hidden"}),t.jsx("div",{className:"h-full mt-4 gap-y-6 ",children:t.jsx(Tu,{elementData:e==null?void 0:e.questionData,sectionId:e==null?void 0:e.id})})]})]})},e==null?void 0:e.id)},_u=({onAddTemplate:e,templates:n})=>{const i=[...Iu,...n||[]],[o,s]=x.useState(!1),[a,l]=x.useState(!1),r=x.useRef(null),d=x.useRef(null),{removeSection:u,addSection:m,formData:c,setIsDragging:b,setSelectedSection:v,selectedSection:h,activeSections:p,setActiveSections:y,setFormData:f,isDragging:N}=x.useContext(Ae),g=x.useRef((c==null?void 0:c.length)||0);x.useEffect(()=>{var B;v(((B=c[0])==null?void 0:B.id)||null)},[]),x.useEffect(()=>{(c==null?void 0:c.length)>g.current&&d.current&&requestAnimationFrame(()=>{var B;(B=d.current)==null||B.scrollTo({top:d.current.scrollHeight,behavior:"smooth"})}),g.current=(c==null?void 0:c.length)||0},[c==null?void 0:c.length]);const S=x.useCallback(B=>{B.preventDefault(),B.dataTransfer.dropEffect="move"},[]),w=x.useCallback((B,P)=>{f(T=>{const O=T.findIndex(K=>K.id===B),M=T.findIndex(K=>K.id===P);if(O===-1||M===-1||O===M)return T;const D=[...T],[I]=D.splice(O,1);return D.splice(M,0,I),D})},[f]);function A(B){p.includes(B)?y(P=>P.filter(T=>T!==B)):y(P=>[...P,B])}function C(B){r.current=B,s(!0)}const E=B=>{var T,O,M,D;const P=(I,K={})=>({...JSON.parse(JSON.stringify(I)),...K});if(B.sections&&Array.isArray(B.sections)){const K=B.sections.filter(Boolean).map(L=>{var W;const z=Ce.v4(),U=(W=L.questionData)==null?void 0:W.map(Y=>P(Y,{id:Ce.v4(),sectionId:z}));if(U){const Y=new Map;L.questionData.forEach((J,ie)=>{Y.set(J.id,U[ie].id)}),U.forEach(J=>{J.gridId&&Y.has(J.gridId)&&(J.gridId=Y.get(J.gridId))})}return P(L,{id:z,questionData:U||[]})});c.length===1&&c[0].title===""&&c[0].description===""&&(!((T=c[0])!=null&&T.questionData)||((M=(O=c[0])==null?void 0:O.questionData)==null?void 0:M.length)===0)?(f(K),K.length>0&&v((D=K[0])==null?void 0:D.id)):f(L=>[...L,...K])}},k=xe("config");return t.jsxs("div",{className:"relative flex flex-col h-full pb-5 mx-auto gap-x-4 ",children:[o&&t.jsx(Lu,{isOpen:o,onClose:()=>s(!1),section:r.current}),t.jsxs("div",{id:"section-container",ref:d,className:"relative flex flex-col flex-1 w-full gap-y-3 container overflow-y-auto",children:[c==null?void 0:c.map((B,P)=>t.jsx(Du,{section:B,index:P,selectedSection:h,setSelectedSection:v,activeSections:p,toggleSection:A,handleSectionEdit:C,removeSection:u,formDataLength:c.length,onDragOver:S,setIsDragging:b,isDragging:N,onReorderSection:w},B.id)),t.jsxs("div",{className:"flex justify-center gap-x-4",children:[t.jsxs("button",{type:"button",onClick:()=>m(),style:{color:(k==null?void 0:k.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]}),e||i!=null&&i.length?t.jsx("button",{type:"button",onClick:()=>{i!=null&&i.length?l(!0):e&&e()},style:{color:(k==null?void 0:k.buttonColor)||"#333"},className:"text-sm font-medium",children:"+ Add existing template"}):null]})]}),a&&t.jsx(Bu,{isOpen:a,onClose:()=>l(!1),templates:i,onSelect:E})]})},Ou=()=>{const{formData:e,uploadUrl:n}=x.useContext(Ae),[i,o]=x.useState("multi"),s=xe("config");return t.jsxs("div",{className:"flex flex-col h-full w-full",children:[t.jsx("div",{className:"flex justify-center p-3 border-b border-gray-100 bg-gray-50/50",children:t.jsxs("div",{className:"flex bg-gray-200 p-1 rounded-lg text-sm font-medium",children:[t.jsx("button",{type:"button",className:`px-4 py-1.5 rounded-md transition-all ${i==="multi"?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"}`,onClick:()=>o("multi"),children:"Standard"}),t.jsx("button",{type:"button",className:`px-4 py-1.5 rounded-md transition-all ${i==="conversational"?"bg-white shadow-sm text-gray-900":"text-gray-500 hover:text-gray-700"}`,onClick:()=>o("conversational"),children:"Conversational"})]})}),t.jsx("div",{className:"flex-1 overflow-y-auto w-full relative",children:t.jsx(wo,{form_data:e,ignoreValidation:!0,config:s,uploadUrl:n,renderType:i,onGetValues:a=>console.log(a)})})]})},go=({loadingClass:e})=>{const n=de("h-full w-full min-h-[300px] flex justify-center items-center",e);return x.useEffect(()=>{const i=xe("config"),o=(i==null?void 0:i.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",o)},[]),t.jsx("div",{className:n,children:t.jsx("span",{className:"loader"})})},Ku=x.lazy(()=>Promise.resolve().then(()=>yg));function Hu({questionData:e,uploadUrl:n,onAddTemplate:i,templates:o,viewMode:s="canvas"}){const{setFormData:a,addSection:l,setUploadUrl:r,showPreview:d,formData:u}=x.useContext(Ae);x.useEffect(()=>{e&&e.length>0&&a(e)},[e,a]),x.useEffect(()=>{r(n)},[n,r]);const m=x.useCallback(c=>{c.preventDefault();try{const b=JSON.parse(c.dataTransfer.getData("properties"));if((b==null?void 0:b.type)==="section"){l();return}}catch(b){console.error("Drop error:",b)}},[]);return t.jsxs("div",{className:"flex gap-x-6 h-full",children:[t.jsx("div",{onDragOver:c=>c.preventDefault(),onDrop:c=>m(c),className:" h-full overflow-y-auto no-scrollbar max-h-[calc(100vh-80px)] flex-1 form_builder",children:s==="canvas"?t.jsx(_u,{onAddTemplate:i,templates:o}):t.jsx(x.Suspense,{fallback:t.jsx(go,{loadingClass:"!w-full !h-full"}),children:t.jsx(Ku,{formData:u})})}),s==="canvas"&&t.jsx(re.Transition,{show:d,as:"div",enter:"transition-all duration-300 ease-in-out origin-right",enterFrom:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",enterTo:"opacity-100 w-2/5 translate-x-0",leave:"transition-all duration-300 ease-in-out origin-right",leaveFrom:"opacity-100 w-2/5 translate-x-0",leaveTo:"opacity-0 w-0 translate-x-10 px-0 overflow-hidden border-transparent shadow-none",className:"shrink-0 overflow-y-auto no-scrollbar max-h-[calc(100vh-70px)] form_preview w-2/5 min-w-0",children:t.jsx("div",{className:"px-2 shadow_box min-w-0 bg-white border border-gray-100 rounded-lg container",children:t.jsx(Ou,{})})})]})}const yo=[{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"}],Gu=()=>{const[e,n]=x.useState(""),{setIsDragging:i,addElement:o,selectedSection:s}=x.useContext(Ae),a=x.useCallback((v,h)=>{if(!s){Ee.toast.error("Please select a section to add an element.");return}v.dataTransfer.setData("properties",JSON.stringify(h)),v.dataTransfer.effectAllowed="move",i(!0)},[i,s]);function l(v){if(!s){Ee.toast.error("Please select a section to add an element.");return}const h={...v,id:Ce.v4(),sectionId:s};o(h,s)}const r=xe("config")||{},d=r.elementColor,u=r.elementBgColor,m=r.elementBorderColor,c=Ld.filter(v=>v.label.toLowerCase().includes(e.toLowerCase())),b=yo==null?void 0:yo.map(v=>({title:v.title,elements:c.filter(h=>{var p;return(p=Bd[v.key])==null?void 0:p.includes(h.type)})})).filter(v=>v.elements.length>0);return t.jsxs("div",{className:"pt-4 flex flex-col gap-y-6",children:[t.jsx("div",{className:"px-5",children:t.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:v=>n(v.target.value),name:"search",id:"search",autoComplete:"off"})}),t.jsx("div",{className:"flex-1 overflow-y-auto no-scrollbar max-h-[calc(100vh-100px)]",children:t.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 ",children:b==null?void 0:b.map((v,h)=>{var p;return t.jsxs("li",{children:[t.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:v.title}),t.jsx("ul",{className:"grid grid-cols-2 gap-y-3 gap-x-4 mb-3",children:(p=v.elements)==null?void 0:p.map(y=>t.jsx("li",{onDragStart:f=>a(f,y),onDragEnd:()=>i(!1),onClick:()=>l(y),style:{borderColor:m,backgroundColor:u},className:`cursor-move text-[#475467] flex justify-between items-center \r
28
28
  border-[1.5px] border-[#98A2B3] rounded-lg py-2 px-2 shadow-custom\r
29
29
  hover:shadow-lg transition-all duration-200\r
30
30
  active:opacity-50 element_class`,draggable:!0,children:t.jsxs("span",{className:"flex flex-col items-center justify-center w-full gap-2",children:[t.jsx("span",{style:{color:d},children:t.jsx(te,{icon:y.icon,iconClass:"w-6 h-6"})}),t.jsx("span",{style:{color:d},className:"text-xs font-medium text-center",children:y.label})]})},y.type))})]},h)})})})]})},Fu=x.memo(Gu),Ke=({text:e="",isDisabled:n=!1,isLoading:i=!1,btnClass:o="bg-primary-500 text-white",icon:s="",iconPosition:a="left",iconClass:l="text-[20px]",loadingClass:r="",link:d="",div:u=!1,type:m="button",style:c,onClick:b})=>{const v=de("btn inline-flex justify-center",{"pointer-events-none":i,"opacity-40 cursor-not-allowed":n},o),h=()=>i?t.jsxs(t.Fragment,{children:[t.jsxs("svg",{className:`animate-spin -ml-1 mr-3 h-5 w-5 ${r}`,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Submitting..."]}):t.jsxs("span",{className:"flex items-center",children:[s&&a==="left"&&t.jsx("span",{className:`mr-[6px] ${l}`,children:t.jsx(te,{icon:s})}),e&&t.jsx("span",{children:e}),s&&a==="right"&&t.jsx("span",{className:`ml-[6px] ${l}`,children:t.jsx(te,{icon:s})})]});return u?t.jsx("div",{className:v,children:h()}):d?t.jsx(vr.Link,{to:d,className:v,children:h()}):t.jsx("button",{disabled:n,type:m,className:v,"data-testid":"btn",onClick:b,style:c,children:h()})};function Vu(){return t.jsx("div",{children:t.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",fill:"#D5D7DA"}),t.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",stroke:"#E9EAEB"}),t.jsx("path",{d:"M22.5 14L14.5 22M14.5 14L22.5 22",stroke:"#414651",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})]})})}const zu=({isOpen:e,onClose:n})=>{const{formData:i,uploadUrl:o}=x.useContext(Ae);if(!e)return null;const s=xe("config");return t.jsxs("div",{className:"fixed inset-0 flex justify-center z-[999] cursor-default no-drag select-none w-screen h-screen pt-20 bg-[#F8F9FC]",children:[t.jsx("button",{type:"button",onClick:n,className:"absolute text-sm top-3 right-4","aria-label":"close",children:t.jsx(Vu,{})})," ",t.jsx("div",{className:"max-h-[80vh] overflow-y-auto h-max w-full max-w-[650px] min-w-0 border border-[#D5D9EB] rounded-lg bg-white form_submit container",children:t.jsx(wo,{form_data:i,ignoreValidation:!0,config:s,uploadUrl:o})})]})};function Wu(){return t.jsx("div",{children:t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.jsx("rect",{width:"24",height:"24",rx:"6",fill:"currentColor"}),t.jsx("path",{d:"M14 16L10 12L14 8",stroke:"white",strokeWidth:"1.39167",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function $u({title:e,goBackUrl:n,onSubmit:i,onPublish:o,previewLoading:s,saveLoading:a,publishLoading:l,onTitleChange:r,viewMode:d,setViewMode:u,onShowVersion:m}){const{formData:c,setShowPreview:b,showPreview:v,undo:h,redo:p,canUndo:y,canRedo:f}=x.useContext(Ae),[N,g]=x.useState(!1),[S,w]=x.useState(!1),[A,C]=x.useState(e||""),E=xe("config");function k(){try{localStorage.setItem("formData",JSON.stringify(c))}catch(T){console.warn("Could not save formData to localStorage",T)}i==null||i(c)}function B(){try{localStorage.setItem("formData",JSON.stringify(c))}catch(T){console.warn("Could not save formData to localStorage",T)}o==null||o(c)}function P(){w(!1),r&&A!==e&&r(A.trim())}return t.jsxs("div",{className:"px-[30px] py-3 flex justify-between items-center bg-[#F9F9FB] top_bar border-b h-full",children:[t.jsxs("span",{className:"flex items-center gap-x-2",children:[n&&t.jsx("button",{type:"button",onClick:()=>n(),style:{color:(E==null?void 0:E.buttonColor)||"#333"},className:"flex items-center gap-x-3",children:t.jsx(Wu,{})})," ",S?t.jsx("input",{type:"text",value:A,onChange:T=>C(T.target.value),onBlur:P,autoFocus:!0,className:"w-48 px-2 py-1 text-sm font-semibold outline-gray-100 input form_title"}):t.jsx("h1",{title:"Click to edit",className:"text-base font-semibold cursor-pointer form_title",onClick:()=>w(!0),children:A||"Untitled"})]}),N&&t.jsx(zu,{isOpen:N,onClose:()=>g(!1),element:void 0}),t.jsxs("div",{className:"flex justify-end text-xs gap-x-3 items-center",children:[u&&t.jsxs("div",{className:"flex border border-gray-300 rounded-lg overflow-hidden h-[36px] text-sm font-medium shadow-sm mr-2",children:[t.jsxs("button",{type:"button",style:{color:(E==null?void 0:E.buttonColor)||"#333"},className:`px-3 flex items-center gap-1.5 transition-colors canvas_view ${d==="canvas"?"bg-white font-medium":"bg-gray-100 text-gray-500 hover:bg-gray-50"}`,onClick:()=>u("canvas"),children:[t.jsx(te,{icon:"mdi:view-dashboard-outline",iconClass:"text-base"})," ","Builder"]}),t.jsxs("button",{type:"button",style:{color:(E==null?void 0:E.buttonColor)||"#333"},className:`px-3 flex items-center gap-1.5 border-l border-gray-300 transition-colors flow_view ${d==="flow"?" bg-white font-medium":"bg-gray-100 text-gray-500 hover:bg-gray-50"}`,onClick:()=>u("flow"),children:[t.jsx(te,{icon:"mdi:sitemap-outline",iconClass:"text-base"})," Flow"]})]}),t.jsx(Ke,{onClick:h,text:"",btnClass:`!px-2 bg-transparent undo ${y?"":"opacity-50"}`,icon:"material-symbols:undo",iconClass:"text-xl !mr-0",style:{color:(E==null?void 0:E.buttonColor)||"#333"},isDisabled:!y}),t.jsx(Ke,{onClick:p,text:"",btnClass:`!px-2 bg-transparent redo ${f?"":"opacity-50"}`,icon:"material-symbols:redo",iconClass:"text-xl !mr-0",style:{color:(E==null?void 0:E.buttonColor)||"#333"},isDisabled:!f}),m&&t.jsx(Ke,{onClick:m,text:"Versions",btnClass:"px-2 bg-transparent font-medium text-sm version_btn",icon:"tabler:history",iconClass:"text-xl",style:{color:(E==null?void 0:E.buttonColor)||"#333"}}),t.jsx(Ke,{onClick:()=>b(T=>!T),text:v?"Hide Preview":"Preview",btnClass:"px-2 bg-transparent font-medium text-sm form_preview",icon:v?"iconamoon:eye-off-duotone":"solar:eye-bold-duotone",iconClass:"text-base",style:{color:(E==null?void 0:E.buttonColor)||"#333"},isDisabled:s,isLoading:s}),t.jsx(Ke,{onClick:k,text:"Save",btnClass:"px-2 bg-transparent font-medium text-sm form_save__btn",icon:"lets-icons:save-duotone",iconClass:"text-base",style:{color:(E==null?void 0:E.buttonColor)||"#333"},isDisabled:a,isLoading:a}),t.jsx(Ke,{onClick:B,text:"Publish",style:{background:(E==null?void 0:E.buttonColor)||"#333"},btnClass:"border-[#98A2B3] font-medium text-sm py-2 px-6 text-white rounded-lg form_publish__btn",isDisabled:l,isLoading:l})]})]})}function ju({onSubmit:e,onChange:n,onLogAction:i,questionData:o,title:s,goBackUrl:a,loading:l,onPublish:r,previewLoading:d,saveLoading:u,publishLoading:m,onTitleChange:c,uploadUrl:b,onAddTemplate:v,templates:h,onShowVersion:p}){const[y,f]=x.useState("canvas");return t.jsxs(xs,{onChange:n,onLogAction:i,children:[t.jsx(Ee.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),t.jsx("div",{className:"w-full h-full bg-[#F8F9FC] flex flex-col",children:t.jsxs("div",{className:"flex flex-1 ",children:[y==="canvas"&&t.jsx("div",{children:t.jsx("div",{className:"w-[250px] h-screen border-r border-[#E4E7EC] bg-white ",children:t.jsx(Fu,{})})}),t.jsxs("div",{className:`flex-1 h-full max-h-full z-[1] ${y==="canvas"?"w-[calc(100%-250px)]":"w-full"}`,children:[t.jsx("div",{className:" h-[70px]",children:t.jsx($u,{title:s,goBackUrl:a,onSubmit:e,onPublish:r,previewLoading:d,saveLoading:u,publishLoading:m,onTitleChange:c,viewMode:y,setViewMode:f,onShowVersion:p})}),t.jsx("div",{className:"p-6 h-[calc(100vh-70px)]",children:l?t.jsx(go,{loadingClass:"!w-full !h-[800px]"}):t.jsx(Hu,{questionData:o,uploadUrl:b,onAddTemplate:v,templates:h,viewMode:y})})]})]})})]})}const Uu=({onSubmit:e,onChange:n,onLogAction:i,questionData:o,isReadOnly:s,config:a={buttonColor:"#333"},title:l,loading:r,goBackUrl:d,onPublish:u,previewLoading:m,saveLoading:c,publishLoading:b,onTitleChange:v,uploadUrl:h,onAddTemplate:p,templates:y,onShowVersion:f})=>(x.useEffect(()=>{a&&Ys("config",a)},[a]),t.jsx(ju,{onSubmit:e,onChange:n,onLogAction:i,onPublish:u,questionData:o,isReadOnly:s,title:l,goBackUrl:d,loading:r,previewLoading:m,saveLoading:c,publishLoading:b,onTitleChange:v,uploadUrl:h,onAddTemplate:p,templates:y,onShowVersion:f})),Ue={required:"This field is required",email:"Invalid email format",url:"Invalid url format",minLength:e=>`Minimum length is ${e}`,maxLength:e=>`Maximum length is ${e}`,minAmount:e=>`Minimum amount is ${e}`,maxAmount:e=>`Maximum amount is ${e}`},qu=(e,n=!1)=>({textField:ne.string().nullable(),longText:ne.string().nullable(),numberField:ne.number().nullable().transform(o=>isNaN(o)?null:o),amountField:ne.number().nullable().transform(o=>isNaN(o)?null:o),selectField:ne.string().nullable(),checkbox:ne.mixed().nullable(),radio:ne.mixed().nullable(),matrix:ne.mixed().nullable(),email:ne.string().nullable().test("email-format",Ue.email,o=>!o||o.trim()===""?!0:/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/.test(o)),date:ne.date().nullable().transform((o,s)=>n&&s===""?null:o).typeError("Invalid date"),url:ne.string().nullable().test("url-format",Ue.url,o=>!o||o.trim()===""?!0:/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/.test(o))})[e]||ne.mixed().nullable(),Yu=(e,n,i)=>n?e.type==="boolean"?e.oneOf([!0],i||Ue.required):e.required(i||Ue.required):e,Ju=(e,{minLength:n,maxLength:i,minLengthMessage:o,maxLengthMessage:s})=>{let a=e;return n&&(a=a.min(n,o||Ue.minLength(n))),i&&(a=a.max(i,s||Ue.maxLength(i))),a},Zu=(e,{minAmount:n,maxAmount:i,minAmountMessage:o,maxAmountMessage:s})=>{let a=e;return n&&(a=a.min(parseFloat(String(n)),o||Ue.minAmount(n))),i&&(a=a.max(parseFloat(String(i)),s||Ue.maxAmount(i))),a},xo=(e,n)=>{if(!e.isHidden)return!0;const i=e.visibilityDependentFields||[];return i.length?i.every(o=>{const s=n==null?void 0:n[o.id],a=o.fieldValue,l=s;switch(o.operator){case"equals":return String(a).toLowerCase()===String(l).toLowerCase();case"not_equals":return String(a).toLowerCase()!==String(l).toLowerCase();case"greater":return Number(l)>Number(a);case"less":return Number(l)<Number(a);case"contains":return String(l).toLowerCase().includes(String(a).toLowerCase());case"not_contains":return!String(l).toLowerCase().includes(String(a).toLowerCase());default:return!0}}):!0};function Xu({formData:e,isReadOnly:n,answerData:i}){const o={};return e.forEach(({questionData:s})=>{s==null||s.forEach(a=>{if(!xo(a,i))return;const{id:l,type:r,isRequired:d,requiredMessage:u,isDisabled:m}=a;let c=qu(r,n);c=Yu(c,m||n?!1:d,u),r==="textField"||r==="longText"||r==="email"||r==="url"?c=Ju(c,a):(r==="numberField"||r==="amountField")&&(c=Zu(c,a)),o[l]=c})}),ne.object().shape(o)}const mn=({element:e,validationData:n})=>{const i=na[e.type],{answerData:o}=x.useContext(Ae),s=x.useMemo(()=>{var l;return(l=e==null?void 0:e.acceptedFiles)==null?void 0:l.map(r=>r.label).join(", ")},[e]),a=x.useMemo(()=>xo(e,o),[o,e]);return i?t.jsxs("div",{className:`${a?"":"hidden"} min-w-0 w-full`,children:[t.jsx("div",{className:"mb-1.5 min-w-0",children:e.inputLabel&&t.jsxs("label",{className:"block text-sm font-medium input_label",children:[e.inputLabel," ",s&&t.jsxs("span",{className:"text-gray-400 text-xs",children:["(",s==null?void 0:s.toLowerCase(),")"]})]})}),t.jsx(i,{element:e,state:"edit",validationData:{...n,isReadOnly:n.isReadOnly||e.isDisabled}}),e.description&&t.jsx("small",{className:"block text-gray-400 mt-0.5 text-xs",children:e.description})]}):null},bn=(e,n)=>e!=null&&e.allowEdit?{...n,isReadOnly:!1}:n;function Qu({form_data:e,options:n}){const i=(s,a)=>t.jsx("div",{className:"min-w-0",children:t.jsx(ri,{element:s,customClass:"p-0 min-h-[60px] border-none",children:a==null?void 0:a.map(l=>{var r,d,u;return t.jsxs(li,{col:(r=l.gridPosition)==null?void 0:r.col,customClass:"p-0",children:[t.jsx(mn,{element:l,validationData:bn(l,n)}),((u=(d=n==null?void 0:n.errors)==null?void 0:d[l.id])==null?void 0:u.message)&&t.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[l.id].message})]},l.id)})})},s.id),o=s=>{var a,l;return t.jsxs("div",{className:de("group relative grid gap-y-[6px] min-w-0",s.elementClass),children:[t.jsx(mn,{element:s,validationData:bn(s,n)}),((l=(a=n==null?void 0:n.errors)==null?void 0:a[s.id])==null?void 0:l.message)&&t.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[s.id].message})]},s.id)};return t.jsx("div",{className:"grid gap-y-10",children:e==null?void 0:e.map(s=>{var l,r;const a=new Map;return(l=s==null?void 0:s.questionData)==null||l.forEach(d=>{d.gridId&&(a.has(d.gridId)||a.set(d.gridId,[]),a.get(d.gridId).push(d))}),t.jsxs("div",{className:"pb-6 section_box min-w-0",children:[(s.title||s.description)&&t.jsxs("div",{className:"py-4 border-b border-gray-100 mb-7 section_box__title",children:[s.title&&t.jsx("h2",{className:"text-lg font-semibold mb-[4px]",children:s.title}),s.description&&t.jsx("p",{className:"text-sm",children:s.description})]}),t.jsx("div",{className:"grid gap-y-6 section_box__content min-w-0",children:(r=s==null?void 0:s.questionData)==null?void 0:r.map(d=>d.gridId?null:d.type==="grid"?i(d,a.get(d.id)||[]):o(d))})]},s.id)})})}function Ru({form_data:e,options:n,current:i}){var o,s;return t.jsx("div",{className:"grid gap-y-3 multi_section__content min-w-0",children:(s=(o=e[i])==null?void 0:o.questionData)==null?void 0:s.map(a=>{var l,r,d,u;if(a.type==="grid"){const m=(r=(l=e[i])==null?void 0:l.questionData)==null?void 0:r.filter(c=>c.gridId===a.id);return t.jsx("div",{className:"min-w-0",children:t.jsx(ri,{element:a,customClass:"p-0 min-h-[60px] border-none",children:m==null?void 0:m.map(c=>{var b,v,h;return t.jsxs(li,{col:(b=c.gridPosition)==null?void 0:b.col,customClass:"p-0",children:[t.jsx(mn,{element:c,validationData:bn(c,n)}),t.jsx("div",{className:"mt-1 text-xs text-red-600",children:(h=(v=n==null?void 0:n.errors)==null?void 0:v[c.id])==null?void 0:h.message})]},c.id)})})},a.id)}return a.gridId?null:t.jsxs("div",{className:de("group relative grid gap-y-[6px] min-w-0",a.elementClass),children:[t.jsx(mn,{element:a,validationData:bn(a,n)}),t.jsx("div",{className:"mt-1 text-xs text-red-600",children:(u=(d=n==null?void 0:n.errors)==null?void 0:d[a.id])==null?void 0:u.message})]},a.id)})})}const So=xe("config");function ec({element:e,options:n,onNext:i,onPrev:o,isFirst:s,isLast:a,isReadOnly:l}){if(!e)return t.jsx("div",{className:"flex items-center justify-center min-h-[500px] text-gray-500",children:"No questions available."});const r=m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),i())},d=m=>{var c;return t.jsx("div",{className:"min-w-0 w-full",children:t.jsx(ri,{element:m,customClass:"p-0 min-h-[60px] border-none w-full",children:(c=m.gridChildren)==null?void 0:c.map(b=>{var v,h,p;return t.jsxs(li,{col:(v=b.gridPosition)==null?void 0:v.col,customClass:"p-0",children:[t.jsx(mn,{element:b,validationData:bn(b,n)}),((p=(h=n==null?void 0:n.errors)==null?void 0:h[b.id])==null?void 0:p.message)&&t.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[b.id].message})]},b.id)})})},m.id)},u=m=>{var c,b;return t.jsxs("div",{className:de("group relative grid gap-y-[6px] min-w-0 w-full",m.elementClass),children:[t.jsx(mn,{element:m,validationData:bn(m,n)}),((b=(c=n==null?void 0:n.errors)==null?void 0:c[m.id])==null?void 0:b.message)&&t.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[m.id].message})]},m.id)};return t.jsx("div",{className:"flex flex-col items-center justify-center min-h-[500px] w-full p-4 sm:p-8 outline-none",onKeyDown:r,tabIndex:0,children:t.jsxs(re.Transition,{as:"div",show:!0,appear:!0,enter:"transition-all duration-500 ease-out",enterFrom:"opacity-0 translate-y-8",enterTo:"opacity-100 translate-y-0",leave:"transition-all duration-300 ease-in",leaveFrom:"opacity-100 translate-y-0",leaveTo:"opacity-0 -translate-y-8",className:"w-full max-w-2xl",children:[t.jsx("div",{className:"text-left w-full mb-8",children:e.type==="grid"?d(e):u(e)}),!l&&t.jsxs("div",{className:"flex items-center gap-4 mt-8",children:[t.jsx(Ke,{type:"button",text:a?n!=null&&n.isSubmitting?"Submitting...":"Submit":"OK",onClick:i,style:{background:(So==null?void 0:So.buttonColor)||"#333"},btnClass:`text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg ${a?"submit_btn":"continue_btn next_btn text-sm"}`,isDisabled:(n==null?void 0:n.apiActivityCount)>0||a&&(n==null?void 0:n.isSubmitting)}),!a&&t.jsx("span",{className:"text-xs text-gray-400 font-medium hidden sm:inline-block",children:"press Enter ↵"}),!s&&t.jsxs("button",{type:"button",onClick:o,className:"text-gray-400 hover:text-gray-600 font-medium text-sm ml-auto flex items-center gap-1 transition-colors",children:[t.jsx(te,{icon:"material-symbols:arrow-upward-rounded",iconClass:"text-lg"}),"Back"]})]})]},e.id)})}function nc(e){return e.reduce((n,i)=>(n[i.id]=i.value,n),{})}const ic=({form_data:e,answerData:n=[],ignoreValidation:i=!1,onSubmitData:o,onGetValues:s,isReadOnly:a=!1,renderType:l="multi",children:r,hideFooter:d=!1,uploadUrl:u})=>{var se,Q,j,V,G,H,$,F,q,R;const{setAnswerData:m,setUploadUrl:c,apiActivityCount:b}=x.useContext(Ae),[v,h]=x.useState(0),[p,y]=x.useState(0),f=x.useMemo(()=>e.filter(X=>!X.isHidden).map(X=>{var ee;return X.isDisabled||X.disabled?{...X,questionData:(ee=X==null?void 0:X.questionData)==null?void 0:ee.map(ae=>({...ae,isDisabled:!0}))}:X}),[e]),N=(se=f==null?void 0:f.length)!=null?se:0,g=xe("config"),S=x.useCallback(async(X,Z,ee)=>{const ae=Xu({formData:f,isReadOnly:a,answerData:X});return ro(ae)(X,Z,ee)},[f,a]),w=Ve.useForm({resolver:S,mode:"onSubmit",defaultValues:{}}),{register:A,setValue:C,control:E,handleSubmit:k,reset:B,getValues:P,watch:T,formState:{errors:O,isSubmitting:M},trigger:D,setError:I,clearErrors:K}=w,_=Ve.useWatch({control:E}),L=x.useMemo(()=>_,[JSON.stringify(_)]),z=x.useMemo(()=>{if(l!=="conversational")return[];const X=[];return f.forEach(Z=>{var ee;(ee=Z==null?void 0:Z.questionData)==null||ee.forEach(ae=>{var ue;if(xo(ae,L))if(ae.type==="grid"){const me=(ue=Z==null?void 0:Z.questionData)==null?void 0:ue.filter(ye=>ye.gridId===ae.id);X.push({...ae,gridChildren:me})}else ae.gridId||X.push(ae)})}),X},[f,L,l]),U=x.useCallback(X=>{s&&s(X)},[s]);x.useEffect(()=>{c(u)},[c,u]),x.useEffect(()=>{if(!(f!=null&&f.length)||!s)return;const X=f.flatMap(Z=>{var ee;return(ee=Z==null?void 0:Z.questionData)==null?void 0:ee.map(ae=>({id:ae.id,value:L[ae.id]||"",sectionId:Z.id,type:ae.type,metaData:{prefix:ae.prefix,dateFormat:ae.dateFormat}}))});U(X),m(L)},[L,f,U,s,m]),x.useEffect(()=>{n!=null&&n.length&&B(nc(n))},[n,B]);const W=x.useCallback(X=>{const Z=f.flatMap(ee=>{var ae;return(ae=ee==null?void 0:ee.questionData)==null?void 0:ae.map(ue=>({id:ue.id,value:X[ue.id]||"",sectionId:ee.id,type:ue.type,metaData:{prefix:ue.prefix,dateFormat:ue.dateFormat}}))});Object.keys(O).length>0||o==null||o(Z)},[O,f,o]),Y=x.useCallback(async()=>{var X,Z;if(l==="conversational"){if(!i){const ee=z[p];if(!ee)return;const ae=ee.gridChildren?ee.gridChildren.map(me=>me.id):[ee.id];if(!await D(ae))return}p<z.length-1?y(ee=>ee+1):k(W)();return}if(!i){const ee=(Z=(X=f==null?void 0:f[v])==null?void 0:X.questionData)==null?void 0:Z.map(ue=>ue.id);if(!await D(ee))return}h(ee=>ee+1)},[v,p,z,f,i,D,l,k,W]),J=x.useCallback(()=>{if(l==="conversational"){y(X=>Math.max(0,X-1));return}h(X=>X-1)},[l]),ie=x.useMemo(()=>({register:A,setValue:C,watch:T,errors:O,trigger:D,isSubmitting:M,isReadOnly:a,getValues:P,setError:I,clearErrors:K,apiActivityCount:b}),[A,C,T,O,D,M,a,P,I,K,b]);return t.jsxs(Ve.FormProvider,{...w,children:[t.jsx(Ee.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),t.jsxs("form",{onSubmit:k(W),className:"container h-full mx-auto",children:[t.jsx("div",{className:"relative flex flex-col w-full min-w-0 py-4 gap-y-12",children:t.jsxs("div",{className:"multi_section__box min-w-0",children:[l==="multi"&&(((Q=f==null?void 0:f[v])==null?void 0:Q.title)||((j=f==null?void 0:f[v])==null?void 0:j.description))&&t.jsxs("div",{className:"py-4 mb-4 border-b border-gray-100 multi_section__title",children:[((V=f[v])==null?void 0:V.title)&&t.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:(G=f[v])==null?void 0:G.title}),((H=f[v])==null?void 0:H.description)&&t.jsx("p",{className:"text-sm",children:($=f[v])==null?void 0:$.description})]}),l==="multi"?t.jsx(Ru,{form_data:f,options:ie,current:v}):l==="conversational"?t.jsx(ec,{element:z[p],options:ie,onNext:Y,onPrev:J,isFirst:p===0,isLast:p===z.length-1,isReadOnly:a}):t.jsx(Qu,{form_data:f,options:ie})]},l==="conversational"?`conv-${p}`:(F=f==null?void 0:f[v])==null?void 0:F.id)}),!d&&l!=="conversational"&&t.jsx("footer",{className:"flex items-center justify-end gap-4 footer flex-wrap",children:l==="multi"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex gap-x-4 justify-between navigation_container w-full",children:[t.jsxs("div",{children:[" ",v>0&&t.jsxs("button",{type:"button",onClick:J,className:"text-gray-400 hover:text-gray-600 font-medium text-sm flex items-center gap-1 transition-colors back_btn",children:[t.jsx(te,{icon:"material-symbols:arrow-upward-rounded",iconClass:"text-lg"}),"Back"]})]}),v<N-1&&t.jsx(Ke,{type:"button",text:"Next",onClick:Y,style:{background:(g==null?void 0:g.buttonColor)||"#333"},btnClass:"text-gray-700 next_btn text-sm border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg continue_btn"})]}),(v===N-1||a)&&!i&&((q=typeof r=="function"?r({isUploading:b>0,isSubmitting:M,hasErrors:Object.keys(O).length>0}):r)!=null?q:t.jsx(Ke,{isDisabled:M||Object.keys(O).length>0||b>0,isLoading:M,type:"submit",text:"Submit",style:{background:(g==null?void 0:g.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] submit_btn !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))]}):!i&&((R=typeof r=="function"?r({isUploading:b>0,isSubmitting:M,hasErrors:Object.keys(O).length>0}):r)!=null?R:t.jsx(Ke,{isDisabled:M||Object.keys(O).length>0||b>0,isLoading:M,type:"submit",text:"Submit",style:{background:(g==null?void 0:g.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] submit_btn !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg submit_btn"}))}),l==="conversational"&&z.length>0&&t.jsx("div",{className:"fixed bottom-0 left-0 w-full h-1.5 bg-gray-200",children:t.jsx("div",{className:"h-full bg-blue-600 transition-all duration-500 ease-out",style:{width:`${(p+1)/z.length*100}%`,background:(g==null?void 0:g.buttonColor)||"#2563EB"}})})]})]})},oc=x.memo(ic);function wo({answerData:e,form_data:n,ignoreValidation:i,onSubmit:o,isReadOnly:s=!1,loading:a=!1,config:l={buttonColor:"#333"},renderType:r,children:d,hideFooter:u,onGetValues:m,uploadUrl:c}){x.useEffect(()=>{l&&Ys("config",l)},[l]);const b=x.useCallback(v=>{m&&m(v)},[m]);return a?t.jsx(go,{}):n?t.jsxs("div",{className:"w-full h-full min-w-0",children:[t.jsx("div",{id:"root-portal"}),t.jsx(xs,{children:t.jsx(oc,{form_data:n,answerData:e,ignoreValidation:i,onSubmitData:o,isReadOnly:s,renderType:r,hideFooter:u,onGetValues:b,uploadUrl:c,children:d})})]}):t.jsx("div",{children:t.jsx("p",{className:"p-6 text-sm text-gray-400",children:"Error: No form data available."})})}function Se(e){if(typeof e=="string"||typeof e=="number")return""+e;let n="";if(Array.isArray(e))for(let i=0,o;i<e.length;i++)(o=Se(e[i]))!==""&&(n+=(n&&" ")+o);else for(let i in e)e[i]&&(n+=(n&&" ")+i);return n}var sc={value:()=>{}};function di(){for(var e=0,n=arguments.length,i={},o;e<n;++e){if(!(o=arguments[e]+"")||o in i||/[\s.]/.test(o))throw new Error("illegal type: "+o);i[o]=[]}return new ui(i)}function ui(e){this._=e}function ac(e,n){return e.trim().split(/^|\s+/).map(function(i){var o="",s=i.indexOf(".");if(s>=0&&(o=i.slice(s+1),i=i.slice(0,s)),i&&!n.hasOwnProperty(i))throw new Error("unknown type: "+i);return{type:i,name:o}})}ui.prototype=di.prototype={constructor:ui,on:function(e,n){var i=this._,o=ac(e+"",i),s,a=-1,l=o.length;if(arguments.length<2){for(;++a<l;)if((s=(e=o[a]).type)&&(s=tc(i[s],e.name)))return s;return}if(n!=null&&typeof n!="function")throw new Error("invalid callback: "+n);for(;++a<l;)if(s=(e=o[a]).type)i[s]=oa(i[s],e.name,n);else if(n==null)for(s in i)i[s]=oa(i[s],e.name,null);return this},copy:function(){var e={},n=this._;for(var i in n)e[i]=n[i].slice();return new ui(e)},call:function(e,n){if((s=arguments.length-2)>0)for(var i=new Array(s),o=0,s,a;o<s;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],o=0,s=a.length;o<s;++o)a[o].value.apply(n,i)},apply:function(e,n,i){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var o=this._[e],s=0,a=o.length;s<a;++s)o[s].value.apply(n,i)}};function tc(e,n){for(var i=0,o=e.length,s;i<o;++i)if((s=e[i]).name===n)return s.value}function oa(e,n,i){for(var o=0,s=e.length;o<s;++o)if(e[o].name===n){e[o]=sc,e=e.slice(0,o).concat(e.slice(o+1));break}return i!=null&&e.push({name:n,value:i}),e}var No="http://www.w3.org/1999/xhtml";const sa={svg:"http://www.w3.org/2000/svg",xhtml:No,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function ci(e){var n=e+="",i=n.indexOf(":");return i>=0&&(n=e.slice(0,i))!=="xmlns"&&(e=e.slice(i+1)),sa.hasOwnProperty(n)?{space:sa[n],local:e}:e}function lc(e){return function(){var n=this.ownerDocument,i=this.namespaceURI;return i===No&&n.documentElement.namespaceURI===No?n.createElement(e):n.createElementNS(i,e)}}function rc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function aa(e){var n=ci(e);return(n.local?rc:lc)(n)}function dc(){}function Ao(e){return e==null?dc:function(){return this.querySelector(e)}}function uc(e){typeof e!="function"&&(e=Ao(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var a=n[s],l=a.length,r=o[s]=new Array(l),d,u,m=0;m<l;++m)(d=a[m])&&(u=e.call(d,d.__data__,m,a))&&("__data__"in d&&(u.__data__=d.__data__),r[m]=u);return new Te(o,this._parents)}function cc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function mc(){return[]}function ta(e){return e==null?mc:function(){return this.querySelectorAll(e)}}function bc(e){return function(){return cc(e.apply(this,arguments))}}function vc(e){typeof e=="function"?e=bc(e):e=ta(e);for(var n=this._groups,i=n.length,o=[],s=[],a=0;a<i;++a)for(var l=n[a],r=l.length,d,u=0;u<r;++u)(d=l[u])&&(o.push(e.call(d,d.__data__,u,l)),s.push(d));return new Te(o,s)}function la(e){return function(){return this.matches(e)}}function ra(e){return function(n){return n.matches(e)}}var hc=Array.prototype.find;function fc(e){return function(){return hc.call(this.children,e)}}function pc(){return this.firstElementChild}function gc(e){return this.select(e==null?pc:fc(typeof e=="function"?e:ra(e)))}var yc=Array.prototype.filter;function xc(){return Array.from(this.children)}function Sc(e){return function(){return yc.call(this.children,e)}}function wc(e){return this.selectAll(e==null?xc:Sc(typeof e=="function"?e:ra(e)))}function Nc(e){typeof e!="function"&&(e=la(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var a=n[s],l=a.length,r=o[s]=[],d,u=0;u<l;++u)(d=a[u])&&e.call(d,d.__data__,u,a)&&r.push(d);return new Te(o,this._parents)}function da(e){return new Array(e.length)}function Ac(){return new Te(this._enter||this._groups.map(da),this._parents)}function mi(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}mi.prototype={constructor:mi,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,n){return this._parent.insertBefore(e,n)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Cc(e){return function(){return e}}function kc(e,n,i,o,s,a){for(var l=0,r,d=n.length,u=a.length;l<u;++l)(r=n[l])?(r.__data__=a[l],o[l]=r):i[l]=new mi(e,a[l]);for(;l<d;++l)(r=n[l])&&(s[l]=r)}function Mc(e,n,i,o,s,a,l){var r,d,u=new Map,m=n.length,c=a.length,b=new Array(m),v;for(r=0;r<m;++r)(d=n[r])&&(b[r]=v=l.call(d,d.__data__,r,n)+"",u.has(v)?s[r]=d:u.set(v,d));for(r=0;r<c;++r)v=l.call(e,a[r],r,a)+"",(d=u.get(v))?(o[r]=d,d.__data__=a[r],u.delete(v)):i[r]=new mi(e,a[r]);for(r=0;r<m;++r)(d=n[r])&&u.get(b[r])===d&&(s[r]=d)}function Ec(e){return e.__data__}function Tc(e,n){if(!arguments.length)return Array.from(this,Ec);var i=n?Mc:kc,o=this._parents,s=this._groups;typeof e!="function"&&(e=Cc(e));for(var a=s.length,l=new Array(a),r=new Array(a),d=new Array(a),u=0;u<a;++u){var m=o[u],c=s[u],b=c.length,v=Pc(e.call(m,m&&m.__data__,u,o)),h=v.length,p=r[u]=new Array(h),y=l[u]=new Array(h),f=d[u]=new Array(b);i(m,c,p,y,f,v,n);for(var N=0,g=0,S,w;N<h;++N)if(S=p[N]){for(N>=g&&(g=N+1);!(w=y[g])&&++g<h;);S._next=w||null}}return l=new Te(l,o),l._enter=r,l._exit=d,l}function Pc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Lc(){return new Te(this._exit||this._groups.map(da),this._parents)}function Bc(e,n,i){var o=this.enter(),s=this,a=this.exit();return typeof e=="function"?(o=e(o),o&&(o=o.selection())):o=o.append(e+""),n!=null&&(s=n(s),s&&(s=s.selection())),i==null?a.remove():i(a),o&&s?o.merge(s).order():s}function Ic(e){for(var n=e.selection?e.selection():e,i=this._groups,o=n._groups,s=i.length,a=o.length,l=Math.min(s,a),r=new Array(s),d=0;d<l;++d)for(var u=i[d],m=o[d],c=u.length,b=r[d]=new Array(c),v,h=0;h<c;++h)(v=u[h]||m[h])&&(b[h]=v);for(;d<s;++d)r[d]=i[d];return new Te(r,this._parents)}function Dc(){for(var e=this._groups,n=-1,i=e.length;++n<i;)for(var o=e[n],s=o.length-1,a=o[s],l;--s>=0;)(l=o[s])&&(a&&l.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(l,a),a=l);return this}function _c(e){e||(e=Oc);function n(c,b){return c&&b?e(c.__data__,b.__data__):!c-!b}for(var i=this._groups,o=i.length,s=new Array(o),a=0;a<o;++a){for(var l=i[a],r=l.length,d=s[a]=new Array(r),u,m=0;m<r;++m)(u=l[m])&&(d[m]=u);d.sort(n)}return new Te(s,this._parents).order()}function Oc(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function Kc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Hc(){return Array.from(this)}function Gc(){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var o=e[n],s=0,a=o.length;s<a;++s){var l=o[s];if(l)return l}return null}function Fc(){let e=0;for(const n of this)++e;return e}function Vc(){return!this.node()}function zc(e){for(var n=this._groups,i=0,o=n.length;i<o;++i)for(var s=n[i],a=0,l=s.length,r;a<l;++a)(r=s[a])&&e.call(r,r.__data__,a,s);return this}function Wc(e){return function(){this.removeAttribute(e)}}function $c(e){return function(){this.removeAttributeNS(e.space,e.local)}}function jc(e,n){return function(){this.setAttribute(e,n)}}function Uc(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function qc(e,n){return function(){var i=n.apply(this,arguments);i==null?this.removeAttribute(e):this.setAttribute(e,i)}}function Yc(e,n){return function(){var i=n.apply(this,arguments);i==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,i)}}function Jc(e,n){var i=ci(e);if(arguments.length<2){var o=this.node();return i.local?o.getAttributeNS(i.space,i.local):o.getAttribute(i)}return this.each((n==null?i.local?$c:Wc:typeof n=="function"?i.local?Yc:qc:i.local?Uc:jc)(i,n))}function ua(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Zc(e){return function(){this.style.removeProperty(e)}}function Xc(e,n,i){return function(){this.style.setProperty(e,n,i)}}function Qc(e,n,i){return function(){var o=n.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,i)}}function Rc(e,n,i){return arguments.length>1?this.each((n==null?Zc:typeof n=="function"?Qc:Xc)(e,n,i==null?"":i)):vn(this.node(),e)}function vn(e,n){return e.style.getPropertyValue(n)||ua(e).getComputedStyle(e,null).getPropertyValue(n)}function em(e){return function(){delete this[e]}}function nm(e,n){return function(){this[e]=n}}function im(e,n){return function(){var i=n.apply(this,arguments);i==null?delete this[e]:this[e]=i}}function om(e,n){return arguments.length>1?this.each((n==null?em:typeof n=="function"?im:nm)(e,n)):this.node()[e]}function ca(e){return e.trim().split(/^|\s+/)}function Co(e){return e.classList||new ma(e)}function ma(e){this._node=e,this._names=ca(e.getAttribute("class")||"")}ma.prototype={add:function(e){var n=this._names.indexOf(e);n<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var n=this._names.indexOf(e);n>=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function ba(e,n){for(var i=Co(e),o=-1,s=n.length;++o<s;)i.add(n[o])}function va(e,n){for(var i=Co(e),o=-1,s=n.length;++o<s;)i.remove(n[o])}function sm(e){return function(){ba(this,e)}}function am(e){return function(){va(this,e)}}function tm(e,n){return function(){(n.apply(this,arguments)?ba:va)(this,e)}}function lm(e,n){var i=ca(e+"");if(arguments.length<2){for(var o=Co(this.node()),s=-1,a=i.length;++s<a;)if(!o.contains(i[s]))return!1;return!0}return this.each((typeof n=="function"?tm:n?sm:am)(i,n))}function rm(){this.textContent=""}function dm(e){return function(){this.textContent=e}}function um(e){return function(){var n=e.apply(this,arguments);this.textContent=n==null?"":n}}function cm(e){return arguments.length?this.each(e==null?rm:(typeof e=="function"?um:dm)(e)):this.node().textContent}function mm(){this.innerHTML=""}function bm(e){return function(){this.innerHTML=e}}function vm(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n==null?"":n}}function hm(e){return arguments.length?this.each(e==null?mm:(typeof e=="function"?vm:bm)(e)):this.node().innerHTML}function fm(){this.nextSibling&&this.parentNode.appendChild(this)}function pm(){return this.each(fm)}function gm(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function ym(){return this.each(gm)}function xm(e){var n=typeof e=="function"?e:aa(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function Sm(){return null}function wm(e,n){var i=typeof e=="function"?e:aa(e),o=n==null?Sm:typeof n=="function"?n:Ao(n);return this.select(function(){return this.insertBefore(i.apply(this,arguments),o.apply(this,arguments)||null)})}function Nm(){var e=this.parentNode;e&&e.removeChild(this)}function Am(){return this.each(Nm)}function Cm(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function km(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Mm(e){return this.select(e?km:Cm)}function Em(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Tm(e){return function(n){e.call(this,n,this.__data__)}}function Pm(e){return e.trim().split(/^|\s+/).map(function(n){var i="",o=n.indexOf(".");return o>=0&&(i=n.slice(o+1),n=n.slice(0,o)),{type:n,name:i}})}function Lm(e){return function(){var n=this.__on;if(n){for(var i=0,o=-1,s=n.length,a;i<s;++i)a=n[i],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):n[++o]=a;++o?n.length=o:delete this.__on}}}function Bm(e,n,i){return function(){var o=this.__on,s,a=Tm(n);if(o){for(var l=0,r=o.length;l<r;++l)if((s=o[l]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=a,s.options=i),s.value=n;return}}this.addEventListener(e.type,a,i),s={type:e.type,name:e.name,value:n,listener:a,options:i},o?o.push(s):this.__on=[s]}}function Im(e,n,i){var o=Pm(e+""),s,a=o.length,l;if(arguments.length<2){var r=this.node().__on;if(r){for(var d=0,u=r.length,m;d<u;++d)for(s=0,m=r[d];s<a;++s)if((l=o[s]).type===m.type&&l.name===m.name)return m.value}return}for(r=n?Bm:Lm,s=0;s<a;++s)this.each(r(o[s],n,i));return this}function ha(e,n,i){var o=ua(e),s=o.CustomEvent;typeof s=="function"?s=new s(n,i):(s=o.document.createEvent("Event"),i?(s.initEvent(n,i.bubbles,i.cancelable),s.detail=i.detail):s.initEvent(n,!1,!1)),e.dispatchEvent(s)}function Dm(e,n){return function(){return ha(this,e,n)}}function _m(e,n){return function(){return ha(this,e,n.apply(this,arguments))}}function Om(e,n){return this.each((typeof n=="function"?_m:Dm)(e,n))}function*Km(){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var o=e[n],s=0,a=o.length,l;s<a;++s)(l=o[s])&&(yield l)}var fa=[null];function Te(e,n){this._groups=e,this._parents=n}function In(){return new Te([[document.documentElement]],fa)}function Hm(){return this}Te.prototype=In.prototype={constructor:Te,select:uc,selectAll:vc,selectChild:gc,selectChildren:wc,filter:Nc,data:Tc,enter:Ac,exit:Lc,join:Bc,merge:Ic,selection:Hm,order:Dc,sort:_c,call:Kc,nodes:Hc,node:Gc,size:Fc,empty:Vc,each:zc,attr:Jc,style:Rc,property:om,classed:lm,text:cm,html:hm,raise:pm,lower:ym,append:xm,insert:wm,remove:Am,clone:Mm,datum:Em,on:Im,dispatch:Om,[Symbol.iterator]:Km};function Pe(e){return typeof e=="string"?new Te([[document.querySelector(e)]],[document.documentElement]):new Te([[e]],fa)}function Gm(e){let n;for(;n=e.sourceEvent;)e=n;return e}function Be(e,n){if(e=Gm(e),n===void 0&&(n=e.currentTarget),n){var i=n.ownerSVGElement||n;if(i.createSVGPoint){var o=i.createSVGPoint();return o.x=e.clientX,o.y=e.clientY,o=o.matrixTransform(n.getScreenCTM().inverse()),[o.x,o.y]}if(n.getBoundingClientRect){var s=n.getBoundingClientRect();return[e.clientX-s.left-n.clientLeft,e.clientY-s.top-n.clientTop]}}return[e.pageX,e.pageY]}const Fm={passive:!1},Dn={capture:!0,passive:!1};function ko(e){e.stopImmediatePropagation()}function hn(e){e.preventDefault(),e.stopImmediatePropagation()}function pa(e){var n=e.document.documentElement,i=Pe(e).on("dragstart.drag",hn,Dn);"onselectstart"in n?i.on("selectstart.drag",hn,Dn):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function ga(e,n){var i=e.document.documentElement,o=Pe(e).on("dragstart.drag",null);n&&(o.on("click.drag",hn,Dn),setTimeout(function(){o.on("click.drag",null)},0)),"onselectstart"in i?o.on("selectstart.drag",null):(i.style.MozUserSelect=i.__noselect,delete i.__noselect)}const bi=e=>()=>e;function Mo(e,{sourceEvent:n,subject:i,target:o,identifier:s,active:a,x:l,y:r,dx:d,dy:u,dispatch:m}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:i,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:l,enumerable:!0,configurable:!0},y:{value:r,enumerable:!0,configurable:!0},dx:{value:d,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:m}})}Mo.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Vm(e){return!e.ctrlKey&&!e.button}function zm(){return this.parentNode}function Wm(e,n){return n==null?{x:e.x,y:e.y}:n}function $m(){return navigator.maxTouchPoints||"ontouchstart"in this}function ya(){var e=Vm,n=zm,i=Wm,o=$m,s={},a=di("start","drag","end"),l=0,r,d,u,m,c=0;function b(S){S.on("mousedown.drag",v).filter(o).on("touchstart.drag",y).on("touchmove.drag",f,Fm).on("touchend.drag touchcancel.drag",N).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function v(S,w){if(!(m||!e.call(this,S,w))){var A=g(this,n.call(this,S,w),S,w,"mouse");A&&(Pe(S.view).on("mousemove.drag",h,Dn).on("mouseup.drag",p,Dn),pa(S.view),ko(S),u=!1,r=S.clientX,d=S.clientY,A("start",S))}}function h(S){if(hn(S),!u){var w=S.clientX-r,A=S.clientY-d;u=w*w+A*A>c}s.mouse("drag",S)}function p(S){Pe(S.view).on("mousemove.drag mouseup.drag",null),ga(S.view,u),hn(S),s.mouse("end",S)}function y(S,w){if(e.call(this,S,w)){var A=S.changedTouches,C=n.call(this,S,w),E=A.length,k,B;for(k=0;k<E;++k)(B=g(this,C,S,w,A[k].identifier,A[k]))&&(ko(S),B("start",S,A[k]))}}function f(S){var w=S.changedTouches,A=w.length,C,E;for(C=0;C<A;++C)(E=s[w[C].identifier])&&(hn(S),E("drag",S,w[C]))}function N(S){var w=S.changedTouches,A=w.length,C,E;for(m&&clearTimeout(m),m=setTimeout(function(){m=null},500),C=0;C<A;++C)(E=s[w[C].identifier])&&(ko(S),E("end",S,w[C]))}function g(S,w,A,C,E,k){var B=a.copy(),P=Be(k||A,w),T,O,M;if((M=i.call(S,new Mo("beforestart",{sourceEvent:A,target:b,identifier:E,active:l,x:P[0],y:P[1],dx:0,dy:0,dispatch:B}),C))!=null)return T=M.x-P[0]||0,O=M.y-P[1]||0,function D(I,K,_){var L=P,z;switch(I){case"start":s[E]=D,z=l++;break;case"end":delete s[E],--l;case"drag":P=Be(_||K,w),z=l;break}B.call(I,S,new Mo(I,{sourceEvent:K,subject:M,target:b,identifier:E,active:z,x:P[0]+T,y:P[1]+O,dx:P[0]-L[0],dy:P[1]-L[1],dispatch:B}),C)}}return b.filter=function(S){return arguments.length?(e=typeof S=="function"?S:bi(!!S),b):e},b.container=function(S){return arguments.length?(n=typeof S=="function"?S:bi(S),b):n},b.subject=function(S){return arguments.length?(i=typeof S=="function"?S:bi(S),b):i},b.touchable=function(S){return arguments.length?(o=typeof S=="function"?S:bi(!!S),b):o},b.on=function(){var S=a.on.apply(a,arguments);return S===a?b:S},b.clickDistance=function(S){return arguments.length?(c=(S=+S)*S,b):Math.sqrt(c)},b}function Eo(e,n,i){e.prototype=n.prototype=i,i.constructor=e}function xa(e,n){var i=Object.create(e.prototype);for(var o in n)i[o]=n[o];return i}function _n(){}var On=.7,vi=1/On,fn="\\s*([+-]?\\d+)\\s*",Kn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",He="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",jm=/^#([0-9a-f]{3,8})$/,Um=new RegExp(`^rgb\\(${fn},${fn},${fn}\\)$`),qm=new RegExp(`^rgb\\(${He},${He},${He}\\)$`),Ym=new RegExp(`^rgba\\(${fn},${fn},${fn},${Kn}\\)$`),Jm=new RegExp(`^rgba\\(${He},${He},${He},${Kn}\\)$`),Zm=new RegExp(`^hsl\\(${Kn},${He},${He}\\)$`),Xm=new RegExp(`^hsla\\(${Kn},${He},${He},${Kn}\\)$`),Sa={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Eo(_n,Qe,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:wa,formatHex:wa,formatHex8:Qm,formatHsl:Rm,formatRgb:Na,toString:Na});function wa(){return this.rgb().formatHex()}function Qm(){return this.rgb().formatHex8()}function Rm(){return Ea(this).formatHsl()}function Na(){return this.rgb().formatRgb()}function Qe(e){var n,i;return e=(e+"").trim().toLowerCase(),(n=jm.exec(e))?(i=n[1].length,n=parseInt(n[1],16),i===6?Aa(n):i===3?new ke(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):i===8?hi(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):i===4?hi(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|n&240,((n&15)<<4|n&15)/255):null):(n=Um.exec(e))?new ke(n[1],n[2],n[3],1):(n=qm.exec(e))?new ke(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=Ym.exec(e))?hi(n[1],n[2],n[3],n[4]):(n=Jm.exec(e))?hi(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=Zm.exec(e))?Ma(n[1],n[2]/100,n[3]/100,1):(n=Xm.exec(e))?Ma(n[1],n[2]/100,n[3]/100,n[4]):Sa.hasOwnProperty(e)?Aa(Sa[e]):e==="transparent"?new ke(NaN,NaN,NaN,0):null}function Aa(e){return new ke(e>>16&255,e>>8&255,e&255,1)}function hi(e,n,i,o){return o<=0&&(e=n=i=NaN),new ke(e,n,i,o)}function eb(e){return e instanceof _n||(e=Qe(e)),e?(e=e.rgb(),new ke(e.r,e.g,e.b,e.opacity)):new ke}function To(e,n,i,o){return arguments.length===1?eb(e):new ke(e,n,i,o==null?1:o)}function ke(e,n,i,o){this.r=+e,this.g=+n,this.b=+i,this.opacity=+o}Eo(ke,To,xa(_n,{brighter(e){return e=e==null?vi:Math.pow(vi,e),new ke(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?On:Math.pow(On,e),new ke(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new ke(Re(this.r),Re(this.g),Re(this.b),fi(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ca,formatHex:Ca,formatHex8:nb,formatRgb:ka,toString:ka}));function Ca(){return`#${en(this.r)}${en(this.g)}${en(this.b)}`}function nb(){return`#${en(this.r)}${en(this.g)}${en(this.b)}${en((isNaN(this.opacity)?1:this.opacity)*255)}`}function ka(){const e=fi(this.opacity);return`${e===1?"rgb(":"rgba("}${Re(this.r)}, ${Re(this.g)}, ${Re(this.b)}${e===1?")":`, ${e})`}`}function fi(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Re(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function en(e){return e=Re(e),(e<16?"0":"")+e.toString(16)}function Ma(e,n,i,o){return o<=0?e=n=i=NaN:i<=0||i>=1?e=n=NaN:n<=0&&(e=NaN),new Ie(e,n,i,o)}function Ea(e){if(e instanceof Ie)return new Ie(e.h,e.s,e.l,e.opacity);if(e instanceof _n||(e=Qe(e)),!e)return new Ie;if(e instanceof Ie)return e;e=e.rgb();var n=e.r/255,i=e.g/255,o=e.b/255,s=Math.min(n,i,o),a=Math.max(n,i,o),l=NaN,r=a-s,d=(a+s)/2;return r?(n===a?l=(i-o)/r+(i<o)*6:i===a?l=(o-n)/r+2:l=(n-i)/r+4,r/=d<.5?a+s:2-a-s,l*=60):r=d>0&&d<1?0:l,new Ie(l,r,d,e.opacity)}function ib(e,n,i,o){return arguments.length===1?Ea(e):new Ie(e,n,i,o==null?1:o)}function Ie(e,n,i,o){this.h=+e,this.s=+n,this.l=+i,this.opacity=+o}Eo(Ie,ib,xa(_n,{brighter(e){return e=e==null?vi:Math.pow(vi,e),new Ie(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?On:Math.pow(On,e),new Ie(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,n=isNaN(e)||isNaN(this.s)?0:this.s,i=this.l,o=i+(i<.5?i:1-i)*n,s=2*i-o;return new ke(Po(e>=240?e-240:e+120,s,o),Po(e,s,o),Po(e<120?e+240:e-120,s,o),this.opacity)},clamp(){return new Ie(Ta(this.h),pi(this.s),pi(this.l),fi(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=fi(this.opacity);return`${e===1?"hsl(":"hsla("}${Ta(this.h)}, ${pi(this.s)*100}%, ${pi(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Ta(e){return e=(e||0)%360,e<0?e+360:e}function pi(e){return Math.max(0,Math.min(1,e||0))}function Po(e,n,i){return(e<60?n+(i-n)*e/60:e<180?i:e<240?n+(i-n)*(240-e)/60:n)*255}const Lo=e=>()=>e;function ob(e,n){return function(i){return e+i*n}}function sb(e,n,i){return e=Math.pow(e,i),n=Math.pow(n,i)-e,i=1/i,function(o){return Math.pow(e+o*n,i)}}function ab(e){return(e=+e)==1?Pa:function(n,i){return i-n?sb(n,i,e):Lo(isNaN(n)?i:n)}}function Pa(e,n){var i=n-e;return i?ob(e,i):Lo(isNaN(e)?n:e)}const gi=function e(n){var i=ab(n);function o(s,a){var l=i((s=To(s)).r,(a=To(a)).r),r=i(s.g,a.g),d=i(s.b,a.b),u=Pa(s.opacity,a.opacity);return function(m){return s.r=l(m),s.g=r(m),s.b=d(m),s.opacity=u(m),s+""}}return o.gamma=e,o}(1);function tb(e,n){n||(n=[]);var i=e?Math.min(n.length,e.length):0,o=n.slice(),s;return function(a){for(s=0;s<i;++s)o[s]=e[s]*(1-a)+n[s]*a;return o}}function lb(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function rb(e,n){var i=n?n.length:0,o=e?Math.min(i,e.length):0,s=new Array(o),a=new Array(i),l;for(l=0;l<o;++l)s[l]=Hn(e[l],n[l]);for(;l<i;++l)a[l]=n[l];return function(r){for(l=0;l<o;++l)a[l]=s[l](r);return a}}function db(e,n){var i=new Date;return e=+e,n=+n,function(o){return i.setTime(e*(1-o)+n*o),i}}function Ge(e,n){return e=+e,n=+n,function(i){return e*(1-i)+n*i}}function ub(e,n){var i={},o={},s;(e===null||typeof e!="object")&&(e={}),(n===null||typeof n!="object")&&(n={});for(s in n)s in e?i[s]=Hn(e[s],n[s]):o[s]=n[s];return function(a){for(s in i)o[s]=i[s](a);return o}}var Bo=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Io=new RegExp(Bo.source,"g");function cb(e){return function(){return e}}function mb(e){return function(n){return e(n)+""}}function La(e,n){var i=Bo.lastIndex=Io.lastIndex=0,o,s,a,l=-1,r=[],d=[];for(e=e+"",n=n+"";(o=Bo.exec(e))&&(s=Io.exec(n));)(a=s.index)>i&&(a=n.slice(i,a),r[l]?r[l]+=a:r[++l]=a),(o=o[0])===(s=s[0])?r[l]?r[l]+=s:r[++l]=s:(r[++l]=null,d.push({i:l,x:Ge(o,s)})),i=Io.lastIndex;return i<n.length&&(a=n.slice(i),r[l]?r[l]+=a:r[++l]=a),r.length<2?d[0]?mb(d[0].x):cb(n):(n=d.length,function(u){for(var m=0,c;m<n;++m)r[(c=d[m]).i]=c.x(u);return r.join("")})}function Hn(e,n){var i=typeof n,o;return n==null||i==="boolean"?Lo(n):(i==="number"?Ge:i==="string"?(o=Qe(n))?(n=o,gi):La:n instanceof Qe?gi:n instanceof Date?db:lb(n)?tb:Array.isArray(n)?rb:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?ub:Ge)(e,n)}var Ba=180/Math.PI,Do={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ia(e,n,i,o,s,a){var l,r,d;return(l=Math.sqrt(e*e+n*n))&&(e/=l,n/=l),(d=e*i+n*o)&&(i-=e*d,o-=n*d),(r=Math.sqrt(i*i+o*o))&&(i/=r,o/=r,d/=r),e*o<n*i&&(e=-e,n=-n,d=-d,l=-l),{translateX:s,translateY:a,rotate:Math.atan2(n,e)*Ba,skewX:Math.atan(d)*Ba,scaleX:l,scaleY:r}}var yi;function bb(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?Do:Ia(n.a,n.b,n.c,n.d,n.e,n.f)}function vb(e){return e==null||(yi||(yi=document.createElementNS("http://www.w3.org/2000/svg","g")),yi.setAttribute("transform",e),!(e=yi.transform.baseVal.consolidate()))?Do:(e=e.matrix,Ia(e.a,e.b,e.c,e.d,e.e,e.f))}function Da(e,n,i,o){function s(u){return u.length?u.pop()+" ":""}function a(u,m,c,b,v,h){if(u!==c||m!==b){var p=v.push("translate(",null,n,null,i);h.push({i:p-4,x:Ge(u,c)},{i:p-2,x:Ge(m,b)})}else(c||b)&&v.push("translate("+c+n+b+i)}function l(u,m,c,b){u!==m?(u-m>180?m+=360:m-u>180&&(u+=360),b.push({i:c.push(s(c)+"rotate(",null,o)-2,x:Ge(u,m)})):m&&c.push(s(c)+"rotate("+m+o)}function r(u,m,c,b){u!==m?b.push({i:c.push(s(c)+"skewX(",null,o)-2,x:Ge(u,m)}):m&&c.push(s(c)+"skewX("+m+o)}function d(u,m,c,b,v,h){if(u!==c||m!==b){var p=v.push(s(v)+"scale(",null,",",null,")");h.push({i:p-4,x:Ge(u,c)},{i:p-2,x:Ge(m,b)})}else(c!==1||b!==1)&&v.push(s(v)+"scale("+c+","+b+")")}return function(u,m){var c=[],b=[];return u=e(u),m=e(m),a(u.translateX,u.translateY,m.translateX,m.translateY,c,b),l(u.rotate,m.rotate,c,b),r(u.skewX,m.skewX,c,b),d(u.scaleX,u.scaleY,m.scaleX,m.scaleY,c,b),u=m=null,function(v){for(var h=-1,p=b.length,y;++h<p;)c[(y=b[h]).i]=y.x(v);return c.join("")}}}var hb=Da(bb,"px, ","px)","deg)"),fb=Da(vb,", ",")",")"),pb=1e-12;function _a(e){return((e=Math.exp(e))+1/e)/2}function gb(e){return((e=Math.exp(e))-1/e)/2}function yb(e){return((e=Math.exp(2*e))-1)/(e+1)}const xi=function e(n,i,o){function s(a,l){var r=a[0],d=a[1],u=a[2],m=l[0],c=l[1],b=l[2],v=m-r,h=c-d,p=v*v+h*h,y,f;if(p<pb)f=Math.log(b/u)/n,y=function(C){return[r+C*v,d+C*h,u*Math.exp(n*C*f)]};else{var N=Math.sqrt(p),g=(b*b-u*u+o*p)/(2*u*i*N),S=(b*b-u*u-o*p)/(2*b*i*N),w=Math.log(Math.sqrt(g*g+1)-g),A=Math.log(Math.sqrt(S*S+1)-S);f=(A-w)/n,y=function(C){var E=C*f,k=_a(w),B=u/(i*N)*(k*yb(n*E+w)-gb(w));return[r+B*v,d+B*h,u*k/_a(n*E+w)]}}return y.duration=f*1e3*n/Math.SQRT2,y}return s.rho=function(a){var l=Math.max(.001,+a),r=l*l,d=r*r;return e(l,r,d)},s}(Math.SQRT2,2,4);var pn=0,Gn=0,Fn=0,Oa=1e3,Si,Vn,wi=0,nn=0,Ni=0,zn=typeof performance=="object"&&performance.now?performance:Date,Ka=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function _o(){return nn||(Ka(xb),nn=zn.now()+Ni)}function xb(){nn=0}function Ai(){this._call=this._time=this._next=null}Ai.prototype=Ha.prototype={constructor:Ai,restart:function(e,n,i){if(typeof e!="function")throw new TypeError("callback is not a function");i=(i==null?_o():+i)+(n==null?0:+n),!this._next&&Vn!==this&&(Vn?Vn._next=this:Si=this,Vn=this),this._call=e,this._time=i,Oo()},stop:function(){this._call&&(this._call=null,this._time=1/0,Oo())}};function Ha(e,n,i){var o=new Ai;return o.restart(e,n,i),o}function Sb(){_o(),++pn;for(var e=Si,n;e;)(n=nn-e._time)>=0&&e._call.call(void 0,n),e=e._next;--pn}function Ga(){nn=(wi=zn.now())+Ni,pn=Gn=0;try{Sb()}finally{pn=0,Nb(),nn=0}}function wb(){var e=zn.now(),n=e-wi;n>Oa&&(Ni-=n,wi=e)}function Nb(){for(var e,n=Si,i,o=1/0;n;)n._call?(o>n._time&&(o=n._time),e=n,n=n._next):(i=n._next,n._next=null,n=e?e._next=i:Si=i);Vn=e,Oo(o)}function Oo(e){if(!pn){Gn&&(Gn=clearTimeout(Gn));var n=e-nn;n>24?(e<1/0&&(Gn=setTimeout(Ga,e-zn.now()-Ni)),Fn&&(Fn=clearInterval(Fn))):(Fn||(wi=zn.now(),Fn=setInterval(wb,Oa)),pn=1,Ka(Ga))}}function Fa(e,n,i){var o=new Ai;return n=n==null?0:+n,o.restart(s=>{o.stop(),e(s+n)},n,i),o}var Ab=di("start","end","cancel","interrupt"),Cb=[],Va=0,za=1,Ko=2,Ci=3,Wa=4,Ho=5,ki=6;function Mi(e,n,i,o,s,a){var l=e.__transition;if(!l)e.__transition={};else if(i in l)return;kb(e,i,{name:n,index:o,group:s,on:Ab,tween:Cb,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:Va})}function Go(e,n){var i=De(e,n);if(i.state>Va)throw new Error("too late; already scheduled");return i}function Fe(e,n){var i=De(e,n);if(i.state>Ci)throw new Error("too late; already running");return i}function De(e,n){var i=e.__transition;if(!i||!(i=i[n]))throw new Error("transition not found");return i}function kb(e,n,i){var o=e.__transition,s;o[n]=i,i.timer=Ha(a,0,i.time);function a(u){i.state=za,i.timer.restart(l,i.delay,i.time),i.delay<=u&&l(u-i.delay)}function l(u){var m,c,b,v;if(i.state!==za)return d();for(m in o)if(v=o[m],v.name===i.name){if(v.state===Ci)return Fa(l);v.state===Wa?(v.state=ki,v.timer.stop(),v.on.call("interrupt",e,e.__data__,v.index,v.group),delete o[m]):+m<n&&(v.state=ki,v.timer.stop(),v.on.call("cancel",e,e.__data__,v.index,v.group),delete o[m])}if(Fa(function(){i.state===Ci&&(i.state=Wa,i.timer.restart(r,i.delay,i.time),r(u))}),i.state=Ko,i.on.call("start",e,e.__data__,i.index,i.group),i.state===Ko){for(i.state=Ci,s=new Array(b=i.tween.length),m=0,c=-1;m<b;++m)(v=i.tween[m].value.call(e,e.__data__,i.index,i.group))&&(s[++c]=v);s.length=c+1}}function r(u){for(var m=u<i.duration?i.ease.call(null,u/i.duration):(i.timer.restart(d),i.state=Ho,1),c=-1,b=s.length;++c<b;)s[c].call(e,m);i.state===Ho&&(i.on.call("end",e,e.__data__,i.index,i.group),d())}function d(){i.state=ki,i.timer.stop(),delete o[n];for(var u in o)return;delete e.__transition}}function Ei(e,n){var i=e.__transition,o,s,a=!0,l;if(i){n=n==null?null:n+"";for(l in i){if((o=i[l]).name!==n){a=!1;continue}s=o.state>Ko&&o.state<Ho,o.state=ki,o.timer.stop(),o.on.call(s?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete i[l]}a&&delete e.__transition}}function Mb(e){return this.each(function(){Ei(this,e)})}function Eb(e,n){var i,o;return function(){var s=Fe(this,e),a=s.tween;if(a!==i){o=i=a;for(var l=0,r=o.length;l<r;++l)if(o[l].name===n){o=o.slice(),o.splice(l,1);break}}s.tween=o}}function Tb(e,n,i){var o,s;if(typeof i!="function")throw new Error;return function(){var a=Fe(this,e),l=a.tween;if(l!==o){s=(o=l).slice();for(var r={name:n,value:i},d=0,u=s.length;d<u;++d)if(s[d].name===n){s[d]=r;break}d===u&&s.push(r)}a.tween=s}}function Pb(e,n){var i=this._id;if(e+="",arguments.length<2){for(var o=De(this.node(),i).tween,s=0,a=o.length,l;s<a;++s)if((l=o[s]).name===e)return l.value;return null}return this.each((n==null?Eb:Tb)(i,e,n))}function Fo(e,n,i){var o=e._id;return e.each(function(){var s=Fe(this,o);(s.value||(s.value={}))[n]=i.apply(this,arguments)}),function(s){return De(s,o).value[n]}}function $a(e,n){var i;return(typeof n=="number"?Ge:n instanceof Qe?gi:(i=Qe(n))?(n=i,gi):La)(e,n)}function Lb(e){return function(){this.removeAttribute(e)}}function Bb(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ib(e,n,i){var o,s=i+"",a;return function(){var l=this.getAttribute(e);return l===s?null:l===o?a:a=n(o=l,i)}}function Db(e,n,i){var o,s=i+"",a;return function(){var l=this.getAttributeNS(e.space,e.local);return l===s?null:l===o?a:a=n(o=l,i)}}function _b(e,n,i){var o,s,a;return function(){var l,r=i(this),d;return r==null?void this.removeAttribute(e):(l=this.getAttribute(e),d=r+"",l===d?null:l===o&&d===s?a:(s=d,a=n(o=l,r)))}}function Ob(e,n,i){var o,s,a;return function(){var l,r=i(this),d;return r==null?void this.removeAttributeNS(e.space,e.local):(l=this.getAttributeNS(e.space,e.local),d=r+"",l===d?null:l===o&&d===s?a:(s=d,a=n(o=l,r)))}}function Kb(e,n){var i=ci(e),o=i==="transform"?fb:$a;return this.attrTween(e,typeof n=="function"?(i.local?Ob:_b)(i,o,Fo(this,"attr."+e,n)):n==null?(i.local?Bb:Lb)(i):(i.local?Db:Ib)(i,o,n))}function Hb(e,n){return function(i){this.setAttribute(e,n.call(this,i))}}function Gb(e,n){return function(i){this.setAttributeNS(e.space,e.local,n.call(this,i))}}function Fb(e,n){var i,o;function s(){var a=n.apply(this,arguments);return a!==o&&(i=(o=a)&&Gb(e,a)),i}return s._value=n,s}function Vb(e,n){var i,o;function s(){var a=n.apply(this,arguments);return a!==o&&(i=(o=a)&&Hb(e,a)),i}return s._value=n,s}function zb(e,n){var i="attr."+e;if(arguments.length<2)return(i=this.tween(i))&&i._value;if(n==null)return this.tween(i,null);if(typeof n!="function")throw new Error;var o=ci(e);return this.tween(i,(o.local?Fb:Vb)(o,n))}function Wb(e,n){return function(){Go(this,e).delay=+n.apply(this,arguments)}}function $b(e,n){return n=+n,function(){Go(this,e).delay=n}}function jb(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?Wb:$b)(n,e)):De(this.node(),n).delay}function Ub(e,n){return function(){Fe(this,e).duration=+n.apply(this,arguments)}}function qb(e,n){return n=+n,function(){Fe(this,e).duration=n}}function Yb(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?Ub:qb)(n,e)):De(this.node(),n).duration}function Jb(e,n){if(typeof n!="function")throw new Error;return function(){Fe(this,e).ease=n}}function Zb(e){var n=this._id;return arguments.length?this.each(Jb(n,e)):De(this.node(),n).ease}function Xb(e,n){return function(){var i=n.apply(this,arguments);if(typeof i!="function")throw new Error;Fe(this,e).ease=i}}function Qb(e){if(typeof e!="function")throw new Error;return this.each(Xb(this._id,e))}function Rb(e){typeof e!="function"&&(e=la(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var a=n[s],l=a.length,r=o[s]=[],d,u=0;u<l;++u)(d=a[u])&&e.call(d,d.__data__,u,a)&&r.push(d);return new ze(o,this._parents,this._name,this._id)}function ev(e){if(e._id!==this._id)throw new Error;for(var n=this._groups,i=e._groups,o=n.length,s=i.length,a=Math.min(o,s),l=new Array(o),r=0;r<a;++r)for(var d=n[r],u=i[r],m=d.length,c=l[r]=new Array(m),b,v=0;v<m;++v)(b=d[v]||u[v])&&(c[v]=b);for(;r<o;++r)l[r]=n[r];return new ze(l,this._parents,this._name,this._id)}function nv(e){return(e+"").trim().split(/^|\s+/).every(function(n){var i=n.indexOf(".");return i>=0&&(n=n.slice(0,i)),!n||n==="start"})}function iv(e,n,i){var o,s,a=nv(n)?Go:Fe;return function(){var l=a(this,e),r=l.on;r!==o&&(s=(o=r).copy()).on(n,i),l.on=s}}function ov(e,n){var i=this._id;return arguments.length<2?De(this.node(),i).on.on(e):this.each(iv(i,e,n))}function sv(e){return function(){var n=this.parentNode;for(var i in this.__transition)if(+i!==e)return;n&&n.removeChild(this)}}function av(){return this.on("end.remove",sv(this._id))}function tv(e){var n=this._name,i=this._id;typeof e!="function"&&(e=Ao(e));for(var o=this._groups,s=o.length,a=new Array(s),l=0;l<s;++l)for(var r=o[l],d=r.length,u=a[l]=new Array(d),m,c,b=0;b<d;++b)(m=r[b])&&(c=e.call(m,m.__data__,b,r))&&("__data__"in m&&(c.__data__=m.__data__),u[b]=c,Mi(u[b],n,i,b,u,De(m,i)));return new ze(a,this._parents,n,i)}function lv(e){var n=this._name,i=this._id;typeof e!="function"&&(e=ta(e));for(var o=this._groups,s=o.length,a=[],l=[],r=0;r<s;++r)for(var d=o[r],u=d.length,m,c=0;c<u;++c)if(m=d[c]){for(var b=e.call(m,m.__data__,c,d),v,h=De(m,i),p=0,y=b.length;p<y;++p)(v=b[p])&&Mi(v,n,i,p,b,h);a.push(b),l.push(m)}return new ze(a,l,n,i)}var rv=In.prototype.constructor;function dv(){return new rv(this._groups,this._parents)}function uv(e,n){var i,o,s;return function(){var a=vn(this,e),l=(this.style.removeProperty(e),vn(this,e));return a===l?null:a===i&&l===o?s:s=n(i=a,o=l)}}function ja(e){return function(){this.style.removeProperty(e)}}function cv(e,n,i){var o,s=i+"",a;return function(){var l=vn(this,e);return l===s?null:l===o?a:a=n(o=l,i)}}function mv(e,n,i){var o,s,a;return function(){var l=vn(this,e),r=i(this),d=r+"";return r==null&&(d=r=(this.style.removeProperty(e),vn(this,e))),l===d?null:l===o&&d===s?a:(s=d,a=n(o=l,r))}}function bv(e,n){var i,o,s,a="style."+n,l="end."+a,r;return function(){var d=Fe(this,e),u=d.on,m=d.value[a]==null?r||(r=ja(n)):void 0;(u!==i||s!==m)&&(o=(i=u).copy()).on(l,s=m),d.on=o}}function vv(e,n,i){var o=(e+="")=="transform"?hb:$a;return n==null?this.styleTween(e,uv(e,o)).on("end.style."+e,ja(e)):typeof n=="function"?this.styleTween(e,mv(e,o,Fo(this,"style."+e,n))).each(bv(this._id,e)):this.styleTween(e,cv(e,o,n),i).on("end.style."+e,null)}function hv(e,n,i){return function(o){this.style.setProperty(e,n.call(this,o),i)}}function fv(e,n,i){var o,s;function a(){var l=n.apply(this,arguments);return l!==s&&(o=(s=l)&&hv(e,l,i)),o}return a._value=n,a}function pv(e,n,i){var o="style."+(e+="");if(arguments.length<2)return(o=this.tween(o))&&o._value;if(n==null)return this.tween(o,null);if(typeof n!="function")throw new Error;return this.tween(o,fv(e,n,i==null?"":i))}function gv(e){return function(){this.textContent=e}}function yv(e){return function(){var n=e(this);this.textContent=n==null?"":n}}function xv(e){return this.tween("text",typeof e=="function"?yv(Fo(this,"text",e)):gv(e==null?"":e+""))}function Sv(e){return function(n){this.textContent=e.call(this,n)}}function wv(e){var n,i;function o(){var s=e.apply(this,arguments);return s!==i&&(n=(i=s)&&Sv(s)),n}return o._value=e,o}function Nv(e){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(e==null)return this.tween(n,null);if(typeof e!="function")throw new Error;return this.tween(n,wv(e))}function Av(){for(var e=this._name,n=this._id,i=Ua(),o=this._groups,s=o.length,a=0;a<s;++a)for(var l=o[a],r=l.length,d,u=0;u<r;++u)if(d=l[u]){var m=De(d,n);Mi(d,e,i,u,l,{time:m.time+m.delay+m.duration,delay:0,duration:m.duration,ease:m.ease})}return new ze(o,this._parents,e,i)}function Cv(){var e,n,i=this,o=i._id,s=i.size();return new Promise(function(a,l){var r={value:l},d={value:function(){--s===0&&a()}};i.each(function(){var u=Fe(this,o),m=u.on;m!==e&&(n=(e=m).copy(),n._.cancel.push(r),n._.interrupt.push(r),n._.end.push(d)),u.on=n}),s===0&&a()})}var kv=0;function ze(e,n,i,o){this._groups=e,this._parents=n,this._name=i,this._id=o}function Ua(){return++kv}var We=In.prototype;ze.prototype={constructor:ze,select:tv,selectAll:lv,selectChild:We.selectChild,selectChildren:We.selectChildren,filter:Rb,merge:ev,selection:dv,transition:Av,call:We.call,nodes:We.nodes,node:We.node,size:We.size,empty:We.empty,each:We.each,on:ov,attr:Kb,attrTween:zb,style:vv,styleTween:pv,text:xv,textTween:Nv,remove:av,tween:Pb,delay:jb,duration:Yb,ease:Zb,easeVarying:Qb,end:Cv,[Symbol.iterator]:We[Symbol.iterator]};function Mv(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Ev={time:null,delay:0,duration:250,ease:Mv};function Tv(e,n){for(var i;!(i=e.__transition)||!(i=i[n]);)if(!(e=e.parentNode))throw new Error(`transition ${n} not found`);return i}function Pv(e){var n,i;e instanceof ze?(n=e._id,e=e._name):(n=Ua(),(i=Ev).time=_o(),e=e==null?null:e+"");for(var o=this._groups,s=o.length,a=0;a<s;++a)for(var l=o[a],r=l.length,d,u=0;u<r;++u)(d=l[u])&&Mi(d,e,n,u,l,i||Tv(d,n));return new ze(o,this._parents,e,n)}In.prototype.interrupt=Mb,In.prototype.transition=Pv;const Ti=e=>()=>e;function Lv(e,{sourceEvent:n,target:i,transform:o,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},transform:{value:o,enumerable:!0,configurable:!0},_:{value:s}})}function $e(e,n,i){this.k=e,this.x=n,this.y=i}$e.prototype={constructor:$e,scale:function(e){return e===1?this:new $e(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new $e(this.k,this.x+this.k*e,this.y+this.k*n)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Pi=new $e(1,0,0);qa.prototype=$e.prototype;function qa(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Pi;return e.__zoom}function Vo(e){e.stopImmediatePropagation()}function Wn(e){e.preventDefault(),e.stopImmediatePropagation()}function Bv(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Iv(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Ya(){return this.__zoom||Pi}function Dv(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function _v(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ov(e,n,i){var o=e.invertX(n[0][0])-i[0][0],s=e.invertX(n[1][0])-i[1][0],a=e.invertY(n[0][1])-i[0][1],l=e.invertY(n[1][1])-i[1][1];return e.translate(s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s),l>a?(a+l)/2:Math.min(0,a)||Math.max(0,l))}function Ja(){var e=Bv,n=Iv,i=Ov,o=Dv,s=_v,a=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],r=250,d=xi,u=di("start","zoom","end"),m,c,b,v=500,h=150,p=0,y=10;function f(M){M.property("__zoom",Ya).on("wheel.zoom",E,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",B).filter(s).on("touchstart.zoom",P).on("touchmove.zoom",T).on("touchend.zoom touchcancel.zoom",O).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}f.transform=function(M,D,I,K){var _=M.selection?M.selection():M;_.property("__zoom",Ya),M!==_?w(M,D,I,K):_.interrupt().each(function(){A(this,arguments).event(K).start().zoom(null,typeof D=="function"?D.apply(this,arguments):D).end()})},f.scaleBy=function(M,D,I,K){f.scaleTo(M,function(){var _=this.__zoom.k,L=typeof D=="function"?D.apply(this,arguments):D;return _*L},I,K)},f.scaleTo=function(M,D,I,K){f.transform(M,function(){var _=n.apply(this,arguments),L=this.__zoom,z=I==null?S(_):typeof I=="function"?I.apply(this,arguments):I,U=L.invert(z),W=typeof D=="function"?D.apply(this,arguments):D;return i(g(N(L,W),z,U),_,l)},I,K)},f.translateBy=function(M,D,I,K){f.transform(M,function(){return i(this.__zoom.translate(typeof D=="function"?D.apply(this,arguments):D,typeof I=="function"?I.apply(this,arguments):I),n.apply(this,arguments),l)},null,K)},f.translateTo=function(M,D,I,K,_){f.transform(M,function(){var L=n.apply(this,arguments),z=this.__zoom,U=K==null?S(L):typeof K=="function"?K.apply(this,arguments):K;return i(Pi.translate(U[0],U[1]).scale(z.k).translate(typeof D=="function"?-D.apply(this,arguments):-D,typeof I=="function"?-I.apply(this,arguments):-I),L,l)},K,_)};function N(M,D){return D=Math.max(a[0],Math.min(a[1],D)),D===M.k?M:new $e(D,M.x,M.y)}function g(M,D,I){var K=D[0]-I[0]*M.k,_=D[1]-I[1]*M.k;return K===M.x&&_===M.y?M:new $e(M.k,K,_)}function S(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function w(M,D,I,K){M.on("start.zoom",function(){A(this,arguments).event(K).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(K).end()}).tween("zoom",function(){var _=this,L=arguments,z=A(_,L).event(K),U=n.apply(_,L),W=I==null?S(U):typeof I=="function"?I.apply(_,L):I,Y=Math.max(U[1][0]-U[0][0],U[1][1]-U[0][1]),J=_.__zoom,ie=typeof D=="function"?D.apply(_,L):D,se=d(J.invert(W).concat(Y/J.k),ie.invert(W).concat(Y/ie.k));return function(Q){if(Q===1)Q=ie;else{var j=se(Q),V=Y/j[2];Q=new $e(V,W[0]-j[0]*V,W[1]-j[1]*V)}z.zoom(null,Q)}})}function A(M,D,I){return!I&&M.__zooming||new C(M,D)}function C(M,D){this.that=M,this.args=D,this.active=0,this.sourceEvent=null,this.extent=n.apply(M,D),this.taps=0}C.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,D){return this.mouse&&M!=="mouse"&&(this.mouse[1]=D.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=D.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=D.invert(this.touch1[0])),this.that.__zoom=D,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var D=Pe(this.that).datum();u.call(M,this.that,new Lv(M,{sourceEvent:this.sourceEvent,target:f,transform:this.that.__zoom,dispatch:u}),D)}};function E(M,...D){if(!e.apply(this,arguments))return;var I=A(this,D).event(M),K=this.__zoom,_=Math.max(a[0],Math.min(a[1],K.k*Math.pow(2,o.apply(this,arguments)))),L=Be(M);if(I.wheel)(I.mouse[0][0]!==L[0]||I.mouse[0][1]!==L[1])&&(I.mouse[1]=K.invert(I.mouse[0]=L)),clearTimeout(I.wheel);else{if(K.k===_)return;I.mouse=[L,K.invert(L)],Ei(this),I.start()}Wn(M),I.wheel=setTimeout(z,h),I.zoom("mouse",i(g(N(K,_),I.mouse[0],I.mouse[1]),I.extent,l));function z(){I.wheel=null,I.end()}}function k(M,...D){if(b||!e.apply(this,arguments))return;var I=M.currentTarget,K=A(this,D,!0).event(M),_=Pe(M.view).on("mousemove.zoom",W,!0).on("mouseup.zoom",Y,!0),L=Be(M,I),z=M.clientX,U=M.clientY;pa(M.view),Vo(M),K.mouse=[L,this.__zoom.invert(L)],Ei(this),K.start();function W(J){if(Wn(J),!K.moved){var ie=J.clientX-z,se=J.clientY-U;K.moved=ie*ie+se*se>p}K.event(J).zoom("mouse",i(g(K.that.__zoom,K.mouse[0]=Be(J,I),K.mouse[1]),K.extent,l))}function Y(J){_.on("mousemove.zoom mouseup.zoom",null),ga(J.view,K.moved),Wn(J),K.event(J).end()}}function B(M,...D){if(e.apply(this,arguments)){var I=this.__zoom,K=Be(M.changedTouches?M.changedTouches[0]:M,this),_=I.invert(K),L=I.k*(M.shiftKey?.5:2),z=i(g(N(I,L),K,_),n.apply(this,D),l);Wn(M),r>0?Pe(this).transition().duration(r).call(w,z,K,M):Pe(this).call(f.transform,z,K,M)}}function P(M,...D){if(e.apply(this,arguments)){var I=M.touches,K=I.length,_=A(this,D,M.changedTouches.length===K).event(M),L,z,U,W;for(Vo(M),z=0;z<K;++z)U=I[z],W=Be(U,this),W=[W,this.__zoom.invert(W),U.identifier],_.touch0?!_.touch1&&_.touch0[2]!==W[2]&&(_.touch1=W,_.taps=0):(_.touch0=W,L=!0,_.taps=1+!!m);m&&(m=clearTimeout(m)),L&&(_.taps<2&&(c=W[0],m=setTimeout(function(){m=null},v)),Ei(this),_.start())}}function T(M,...D){if(this.__zooming){var I=A(this,D).event(M),K=M.changedTouches,_=K.length,L,z,U,W;for(Wn(M),L=0;L<_;++L)z=K[L],U=Be(z,this),I.touch0&&I.touch0[2]===z.identifier?I.touch0[0]=U:I.touch1&&I.touch1[2]===z.identifier&&(I.touch1[0]=U);if(z=I.that.__zoom,I.touch1){var Y=I.touch0[0],J=I.touch0[1],ie=I.touch1[0],se=I.touch1[1],Q=(Q=ie[0]-Y[0])*Q+(Q=ie[1]-Y[1])*Q,j=(j=se[0]-J[0])*j+(j=se[1]-J[1])*j;z=N(z,Math.sqrt(Q/j)),U=[(Y[0]+ie[0])/2,(Y[1]+ie[1])/2],W=[(J[0]+se[0])/2,(J[1]+se[1])/2]}else if(I.touch0)U=I.touch0[0],W=I.touch0[1];else return;I.zoom("touch",i(g(z,U,W),I.extent,l))}}function O(M,...D){if(this.__zooming){var I=A(this,D).event(M),K=M.changedTouches,_=K.length,L,z;for(Vo(M),b&&clearTimeout(b),b=setTimeout(function(){b=null},v),L=0;L<_;++L)z=K[L],I.touch0&&I.touch0[2]===z.identifier?delete I.touch0:I.touch1&&I.touch1[2]===z.identifier&&delete I.touch1;if(I.touch1&&!I.touch0&&(I.touch0=I.touch1,delete I.touch1),I.touch0)I.touch0[1]=this.__zoom.invert(I.touch0[0]);else if(I.end(),I.taps===2&&(z=Be(z,this),Math.hypot(c[0]-z[0],c[1]-z[1])<y)){var U=Pe(this).on("dblclick.zoom");U&&U.apply(this,arguments)}}}return f.wheelDelta=function(M){return arguments.length?(o=typeof M=="function"?M:Ti(+M),f):o},f.filter=function(M){return arguments.length?(e=typeof M=="function"?M:Ti(!!M),f):e},f.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:Ti(!!M),f):s},f.extent=function(M){return arguments.length?(n=typeof M=="function"?M:Ti([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),f):n},f.scaleExtent=function(M){return arguments.length?(a[0]=+M[0],a[1]=+M[1],f):[a[0],a[1]]},f.translateExtent=function(M){return arguments.length?(l[0][0]=+M[0][0],l[1][0]=+M[1][0],l[0][1]=+M[0][1],l[1][1]=+M[1][1],f):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},f.constrain=function(M){return arguments.length?(i=M,f):i},f.duration=function(M){return arguments.length?(r=+M,f):r},f.interpolate=function(M){return arguments.length?(d=M,f):d},f.on=function(){var M=u.on.apply(u,arguments);return M===u?f:M},f.clickDistance=function(M){return arguments.length?(p=(M=+M)*M,f):Math.sqrt(p)},f.tapDistance=function(M){return arguments.length?(y=+M,f):y},f}const Le={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:n,sourceHandle:i,targetHandle:o})=>`Couldn't create edge for ${e} handle id: "${e==="source"?i:o}", edge id: ${n}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},$n=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Za=["Enter"," ","Escape"],Xa={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:n,y:i})=>`Moved selected node ${e}. New position, x: ${n}, y: ${i}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var gn;(function(e){e.Strict="strict",e.Loose="loose"})(gn||(gn={}));var on;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(on||(on={}));var jn;(function(e){e.Partial="partial",e.Full="full"})(jn||(jn={}));const Qa={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var qe;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(qe||(qe={}));var yn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(yn||(yn={}));var oe;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(oe||(oe={}));const Ra={[oe.Left]:oe.Right,[oe.Right]:oe.Left,[oe.Top]:oe.Bottom,[oe.Bottom]:oe.Top};function et(e){return e===null?null:e?"valid":"invalid"}const nt=e=>"id"in e&&"source"in e&&"target"in e,Kv=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),zo=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Un=(e,n=[0,0])=>{var r;const{width:i,height:o}=je(e),s=(r=e.origin)!=null?r:n,a=i*s[0],l=o*s[1];return{x:e.position.x-a,y:e.position.y-l}},Hv=(e,n={nodeOrigin:[0,0]})=>{if(process.env.NODE_ENV==="development"&&!n.nodeLookup&&console.warn("Please use `getNodesBounds` from `useReactFlow`/`useSvelteFlow` hook to ensure correct values for sub flows. If not possible, you have to provide a nodeLookup to support sub flows."),e.length===0)return{x:0,y:0,width:0,height:0};const i=e.reduce((o,s)=>{const a=typeof s=="string";let l=!n.nodeLookup&&!a?s:void 0;n.nodeLookup&&(l=a?n.nodeLookup.get(s):zo(s)?s:n.nodeLookup.get(s.id));const r=l?Ii(l,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Li(o,r)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Bi(i)},qn=(e,n={})=>{let i={x:1/0,y:1/0,x2:-1/0,y2:-1/0},o=!1;return e.forEach(s=>{(n.filter===void 0||n.filter(s))&&(i=Li(i,Ii(s)),o=!0)}),o?Bi(i):{x:0,y:0,width:0,height:0}},Wo=(e,n,[i,o,s]=[0,0,1],a=!1,l=!1)=>{var b,v,h,p,y,f;const r=(n.x-i)/s,d=(n.y-o)/s,u=n.width/s,m=n.height/s,c=[];for(const N of e.values()){const{measured:g,selectable:S=!0,hidden:w=!1}=N;if(l&&!S||w)continue;const A=(h=(v=(b=g.width)!=null?b:N.width)!=null?v:N.initialWidth)!=null?h:0,C=(f=(y=(p=g.height)!=null?p:N.height)!=null?y:N.initialHeight)!=null?f:0,{x:E,y:k}=N.internals.positionAbsolute,B=tt(r,d,u,m,E,k,A,C),P=A*C,T=a&&B>0;(!N.internals.handleBounds||T||B>=P||N.dragging)&&c.push(N)}return c},Gv=(e,n)=>{const i=new Set;return e.forEach(o=>{i.add(o.id)}),n.filter(o=>i.has(o.source)||i.has(o.target))};function Fv(e,n){const i=new Map,o=n!=null&&n.nodes?new Set(n.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((n==null?void 0:n.includeHiddenNodes)||!s.hidden)&&(!o||o.has(s.id))&&i.set(s.id,s)}),i}async function Vv({nodes:e,width:n,height:i,panZoom:o,minZoom:s,maxZoom:a},l){var m,c,b;if(e.size===0)return!0;const r=Fv(e,l),d=qn(r),u=Uo(d,n,i,(m=l==null?void 0:l.minZoom)!=null?m:s,(c=l==null?void 0:l.maxZoom)!=null?c:a,(b=l==null?void 0:l.padding)!=null?b:.1);return await o.setViewport(u,{duration:l==null?void 0:l.duration,ease:l==null?void 0:l.ease,interpolate:l==null?void 0:l.interpolate}),!0}function it({nodeId:e,nextPosition:n,nodeLookup:i,nodeOrigin:o=[0,0],nodeExtent:s,onError:a}){var v,h,p;const l=i.get(e),r=l.parentId?i.get(l.parentId):void 0,{x:d,y:u}=r?r.internals.positionAbsolute:{x:0,y:0},m=(v=l.origin)!=null?v:o;let c=l.extent||s;if(l.extent==="parent"&&!l.expandParent)if(!r)a==null||a("005",Le.error005());else{const y=r.measured.width,f=r.measured.height;y&&f&&(c=[[d,u],[d+y,u+f]])}else r&&an(l.extent)&&(c=[[l.extent[0][0]+d,l.extent[0][1]+u],[l.extent[1][0]+d,l.extent[1][1]+u]]);const b=an(c)?sn(n,c,l.measured):n;return(l.measured.width===void 0||l.measured.height===void 0)&&(a==null||a("015",Le.error015())),{position:{x:b.x-d+((h=l.measured.width)!=null?h:0)*m[0],y:b.y-u+((p=l.measured.height)!=null?p:0)*m[1]},positionAbsolute:b}}async function zv({nodesToRemove:e=[],edgesToRemove:n=[],nodes:i,edges:o,onBeforeDelete:s}){const a=new Set(e.map(b=>b.id)),l=[];for(const b of i){if(b.deletable===!1)continue;const v=a.has(b.id),h=!v&&b.parentId&&l.find(p=>p.id===b.parentId);(v||h)&&l.push(b)}const r=new Set(n.map(b=>b.id)),d=o.filter(b=>b.deletable!==!1),m=Gv(l,d);for(const b of d)r.has(b.id)&&!m.find(h=>h.id===b.id)&&m.push(b);if(!s)return{edges:m,nodes:l};const c=await s({nodes:l,edges:m});return typeof c=="boolean"?c?{edges:m,nodes:l}:{edges:[],nodes:[]}:c}const xn=(e,n=0,i=1)=>Math.min(Math.max(e,n),i),sn=(e={x:0,y:0},n,i)=>{var o,s;return{x:xn(e.x,n[0][0],n[1][0]-((o=i==null?void 0:i.width)!=null?o:0)),y:xn(e.y,n[0][1],n[1][1]-((s=i==null?void 0:i.height)!=null?s:0))}};function ot(e,n,i){const{width:o,height:s}=je(i),{x:a,y:l}=i.internals.positionAbsolute;return sn(e,[[a,l],[a+o,l+s]],n)}const st=(e,n,i)=>e<n?xn(Math.abs(e-n),1,n)/n:e>i?-xn(Math.abs(e-i),1,n)/n:0,$o=(e,n,i=15,o=40)=>{const s=st(e.x,o,n.width-o)*i,a=st(e.y,o,n.height-o)*i;return[s,a]},Li=(e,n)=>({x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x2,n.x2),y2:Math.max(e.y2,n.y2)}),jo=({x:e,y:n,width:i,height:o})=>({x:e,y:n,x2:e+i,y2:n+o}),Bi=({x:e,y:n,x2:i,y2:o})=>({x:e,y:n,width:i-e,height:o-n}),Yn=(e,n=[0,0])=>{var s,a,l,r,d,u,m,c;const{x:i,y:o}=zo(e)?e.internals.positionAbsolute:Un(e,n);return{x:i,y:o,width:(r=(l=(a=(s=e.measured)==null?void 0:s.width)!=null?a:e.width)!=null?l:e.initialWidth)!=null?r:0,height:(c=(m=(u=(d=e.measured)==null?void 0:d.height)!=null?u:e.height)!=null?m:e.initialHeight)!=null?c:0}},Ii=(e,n=[0,0])=>{var s,a,l,r,d,u,m,c;const{x:i,y:o}=zo(e)?e.internals.positionAbsolute:Un(e,n);return{x:i,y:o,x2:i+((r=(l=(a=(s=e.measured)==null?void 0:s.width)!=null?a:e.width)!=null?l:e.initialWidth)!=null?r:0),y2:o+((c=(m=(u=(d=e.measured)==null?void 0:d.height)!=null?u:e.height)!=null?m:e.initialHeight)!=null?c:0)}},at=(e,n)=>Bi(Li(jo(e),jo(n))),tt=(e,n,i,o,s,a,l,r)=>{const d=Math.max(0,Math.min(e+i,s+l)-Math.max(e,s)),u=Math.max(0,Math.min(n+o,a+r)-Math.max(n,a));return Math.ceil(d*u)},Di=(e,n)=>tt(e.x,e.y,e.width,e.height,n.x,n.y,n.width,n.height),lt=e=>_e(e.width)&&_e(e.height)&&_e(e.x)&&_e(e.y),_e=e=>!isNaN(e)&&isFinite(e),rt=(e,n)=>(i,o)=>{process.env.NODE_ENV==="development"&&console.warn(`[${e}]: ${o} Help: ${n}error#${i}`)},Jn=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Zn=({x:e,y:n},[i,o,s],a=!1,l=[1,1])=>{const r={x:(e-i)/s,y:(n-o)/s};return a?Jn(r,l):r},Sn=({x:e,y:n},[i,o,s])=>({x:e*s+i,y:n*s+o});function wn(e,n){if(typeof e=="number")return Math.floor((n-n/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const i=parseFloat(e);if(!Number.isNaN(i))return Math.floor(i)}if(typeof e=="string"&&e.endsWith("%")){const i=parseFloat(e);if(!Number.isNaN(i))return Math.floor(n*i*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Wv(e,n,i){var o,s,a,l,r,d,u,m;if(typeof e=="string"||typeof e=="number"){const c=wn(e,i),b=wn(e,n);return{top:c,right:b,bottom:c,left:b,x:b*2,y:c*2}}if(typeof e=="object"){const c=wn((s=(o=e.top)!=null?o:e.y)!=null?s:0,i),b=wn((l=(a=e.bottom)!=null?a:e.y)!=null?l:0,i),v=wn((d=(r=e.left)!=null?r:e.x)!=null?d:0,n),h=wn((m=(u=e.right)!=null?u:e.x)!=null?m:0,n);return{top:c,right:h,bottom:b,left:v,x:v+h,y:c+b}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function $v(e,n,i,o,s,a){const{x:l,y:r}=Sn(e,[n,i,o]),{x:d,y:u}=Sn({x:e.x+e.width,y:e.y+e.height},[n,i,o]),m=s-d,c=a-u;return{left:Math.floor(l),top:Math.floor(r),right:Math.floor(m),bottom:Math.floor(c)}}const Uo=(e,n,i,o,s,a)=>{const l=Wv(a,n,i),r=(n-l.x)/e.width,d=(i-l.y)/e.height,u=Math.min(r,d),m=xn(u,o,s),c=e.x+e.width/2,b=e.y+e.height/2,v=n/2-c*m,h=i/2-b*m,p=$v(e,v,h,m,n,i),y={left:Math.min(p.left-l.left,0),top:Math.min(p.top-l.top,0),right:Math.min(p.right-l.right,0),bottom:Math.min(p.bottom-l.bottom,0)};return{x:v-y.left+y.right,y:h-y.top+y.bottom,zoom:m}},Xn=()=>{var e;return typeof navigator!="undefined"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function an(e){return e!=null&&e!=="parent"}function je(e){var n,i,o,s,a,l,r,d;return{width:(s=(o=(i=(n=e.measured)==null?void 0:n.width)!=null?i:e.width)!=null?o:e.initialWidth)!=null?s:0,height:(d=(r=(l=(a=e.measured)==null?void 0:a.height)!=null?l:e.height)!=null?r:e.initialHeight)!=null?d:0}}function dt(e){var n,i,o,s,a,l;return((o=(i=(n=e.measured)==null?void 0:n.width)!=null?i:e.width)!=null?o:e.initialWidth)!==void 0&&((l=(a=(s=e.measured)==null?void 0:s.height)!=null?a:e.height)!=null?l:e.initialHeight)!==void 0}function ut(e,n={width:0,height:0},i,o,s){var r,d;const a={...e},l=o.get(i);if(l){const u=l.origin||s;a.x+=l.internals.positionAbsolute.x-((r=n.width)!=null?r:0)*u[0],a.y+=l.internals.positionAbsolute.y-((d=n.height)!=null?d:0)*u[1]}return a}function ct(e,n){if(e.size!==n.size)return!1;for(const i of e)if(!n.has(i))return!1;return!0}function jv(){let e,n;return{promise:new Promise((o,s)=>{e=o,n=s}),resolve:e,reject:n}}function Uv(e){return{...Xa,...e||{}}}function Qn(e,{snapGrid:n=[0,0],snapToGrid:i=!1,transform:o,containerBounds:s}){var m,c;const{x:a,y:l}=Oe(e),r=Zn({x:a-((m=s==null?void 0:s.left)!=null?m:0),y:l-((c=s==null?void 0:s.top)!=null?c:0)},o),{x:d,y:u}=i?Jn(r,n):r;return{xSnapped:d,ySnapped:u,...r}}const qo=e=>({width:e.offsetWidth,height:e.offsetHeight}),mt=e=>{var n;return((n=e==null?void 0:e.getRootNode)==null?void 0:n.call(e))||(window==null?void 0:window.document)},qv=["INPUT","SELECT","TEXTAREA"];function bt(e){var o,s;const n=((s=(o=e.composedPath)==null?void 0:o.call(e))==null?void 0:s[0])||e.target;return(n==null?void 0:n.nodeType)!==1?!1:qv.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const vt=e=>"clientX"in e,Oe=(e,n)=>{var a,l,r,d;const i=vt(e),o=i?e.clientX:(a=e.touches)==null?void 0:a[0].clientX,s=i?e.clientY:(l=e.touches)==null?void 0:l[0].clientY;return{x:o-((r=n==null?void 0:n.left)!=null?r:0),y:s-((d=n==null?void 0:n.top)!=null?d:0)}},ht=(e,n,i,o,s)=>{const a=n.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(l=>{const r=l.getBoundingClientRect();return{id:l.getAttribute("data-handleid"),type:e,nodeId:s,position:l.getAttribute("data-handlepos"),x:(r.left-i.left)/o,y:(r.top-i.top)/o,...qo(l)}})};function ft({sourceX:e,sourceY:n,targetX:i,targetY:o,sourceControlX:s,sourceControlY:a,targetControlX:l,targetControlY:r}){const d=e*.125+s*.375+l*.375+i*.125,u=n*.125+a*.375+r*.375+o*.125,m=Math.abs(d-e),c=Math.abs(u-n);return[d,u,m,c]}function _i(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function pt({pos:e,x1:n,y1:i,x2:o,y2:s,c:a}){switch(e){case oe.Left:return[n-_i(n-o,a),i];case oe.Right:return[n+_i(o-n,a),i];case oe.Top:return[n,i-_i(i-s,a)];case oe.Bottom:return[n,i+_i(s-i,a)]}}function gt({sourceX:e,sourceY:n,sourcePosition:i=oe.Bottom,targetX:o,targetY:s,targetPosition:a=oe.Top,curvature:l=.25}){const[r,d]=pt({pos:i,x1:e,y1:n,x2:o,y2:s,c:l}),[u,m]=pt({pos:a,x1:o,y1:s,x2:e,y2:n,c:l}),[c,b,v,h]=ft({sourceX:e,sourceY:n,targetX:o,targetY:s,sourceControlX:r,sourceControlY:d,targetControlX:u,targetControlY:m});return[`M${e},${n} C${r},${d} ${u},${m} ${o},${s}`,c,b,v,h]}function yt({sourceX:e,sourceY:n,targetX:i,targetY:o}){const s=Math.abs(i-e)/2,a=i<e?i+s:i-s,l=Math.abs(o-n)/2,r=o<n?o+l:o-l;return[a,r,s,l]}function Yv({sourceNode:e,targetNode:n,selected:i=!1,zIndex:o=0,elevateOnSelect:s=!1,zIndexMode:a="basic"}){if(a==="manual")return o;const l=s&&i?o+1e3:o,r=Math.max(e.parentId||s&&e.selected?e.internals.z:0,n.parentId||s&&n.selected?n.internals.z:0);return l+r}function Jv({sourceNode:e,targetNode:n,width:i,height:o,transform:s}){const a=Li(Ii(e),Ii(n));a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1);const l={x:-s[0]/s[2],y:-s[1]/s[2],width:i/s[2],height:o/s[2]};return Di(l,Bi(a))>0}const Zv=({source:e,sourceHandle:n,target:i,targetHandle:o})=>`xy-edge__${e}${n||""}-${i}${o||""}`,Xv=(e,n)=>n.some(i=>i.source===e.source&&i.target===e.target&&(i.sourceHandle===e.sourceHandle||!i.sourceHandle&&!e.sourceHandle)&&(i.targetHandle===e.targetHandle||!i.targetHandle&&!e.targetHandle)),Qv=(e,n,i={})=>{var a;if(!e.source||!e.target)return(a=i.onError)==null||a.call(i,"006",Le.error006()),n;const o=i.getEdgeId||Zv;let s;return nt(e)?s={...e}:s={...e,id:o(e)},Xv(s,n)?n:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,n.concat(s))};function xt({sourceX:e,sourceY:n,targetX:i,targetY:o}){const[s,a,l,r]=yt({sourceX:e,sourceY:n,targetX:i,targetY:o});return[`M ${e},${n}L ${i},${o}`,s,a,l,r]}const St={[oe.Left]:{x:-1,y:0},[oe.Right]:{x:1,y:0},[oe.Top]:{x:0,y:-1},[oe.Bottom]:{x:0,y:1}},Rv=({source:e,sourcePosition:n=oe.Bottom,target:i})=>n===oe.Left||n===oe.Right?e.x<i.x?{x:1,y:0}:{x:-1,y:0}:e.y<i.y?{x:0,y:1}:{x:0,y:-1},wt=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function eh({source:e,sourcePosition:n=oe.Bottom,target:i,targetPosition:o=oe.Top,center:s,offset:a,stepPosition:l}){var E,k,B,P;const r=St[n],d=St[o],u={x:e.x+r.x*a,y:e.y+r.y*a},m={x:i.x+d.x*a,y:i.y+d.y*a},c=Rv({source:u,sourcePosition:n,target:m}),b=c.x!==0?"x":"y",v=c[b];let h=[],p,y;const f={x:0,y:0},N={x:0,y:0},[,,g,S]=yt({sourceX:e.x,sourceY:e.y,targetX:i.x,targetY:i.y});if(r[b]*d[b]===-1){b==="x"?(p=(E=s.x)!=null?E:u.x+(m.x-u.x)*l,y=(k=s.y)!=null?k:(u.y+m.y)/2):(p=(B=s.x)!=null?B:(u.x+m.x)/2,y=(P=s.y)!=null?P:u.y+(m.y-u.y)*l);const T=[{x:p,y:u.y},{x:p,y:m.y}],O=[{x:u.x,y},{x:m.x,y}];r[b]===v?h=b==="x"?T:O:h=b==="x"?O:T}else{const T=[{x:u.x,y:m.y}],O=[{x:m.x,y:u.y}];if(b==="x"?h=r.x===v?O:T:h=r.y===v?T:O,n===o){const _=Math.abs(e[b]-i[b]);if(_<=a){const L=Math.min(a-1,a-_);r[b]===v?f[b]=(u[b]>e[b]?-1:1)*L:N[b]=(m[b]>i[b]?-1:1)*L}}if(n!==o){const _=b==="x"?"y":"x",L=r[b]===d[_],z=u[_]>m[_],U=u[_]<m[_];(r[b]===1&&(!L&&z||L&&U)||r[b]!==1&&(!L&&U||L&&z))&&(h=b==="x"?T:O)}const M={x:u.x+f.x,y:u.y+f.y},D={x:m.x+N.x,y:m.y+N.y},I=Math.max(Math.abs(M.x-h[0].x),Math.abs(D.x-h[0].x)),K=Math.max(Math.abs(M.y-h[0].y),Math.abs(D.y-h[0].y));I>=K?(p=(M.x+D.x)/2,y=h[0].y):(p=h[0].x,y=(M.y+D.y)/2)}const w={x:u.x+f.x,y:u.y+f.y},A={x:m.x+N.x,y:m.y+N.y};return[[e,...w.x!==h[0].x||w.y!==h[0].y?[w]:[],...h,...A.x!==h[h.length-1].x||A.y!==h[h.length-1].y?[A]:[],i],p,y,g,S]}function nh(e,n,i,o){const s=Math.min(wt(e,n)/2,wt(n,i)/2,o),{x:a,y:l}=n;if(e.x===a&&a===i.x||e.y===l&&l===i.y)return`L${a} ${l}`;if(e.y===l){const u=e.x<i.x?-1:1,m=e.y<i.y?1:-1;return`L ${a+s*u},${l}Q ${a},${l} ${a},${l+s*m}`}const r=e.x<i.x?1:-1,d=e.y<i.y?-1:1;return`L ${a},${l+s*d}Q ${a},${l} ${a+s*r},${l}`}function Yo({sourceX:e,sourceY:n,sourcePosition:i=oe.Bottom,targetX:o,targetY:s,targetPosition:a=oe.Top,borderRadius:l=5,centerX:r,centerY:d,offset:u=20,stepPosition:m=.5}){const[c,b,v,h,p]=eh({source:{x:e,y:n},sourcePosition:i,target:{x:o,y:s},targetPosition:a,center:{x:r,y:d},offset:u,stepPosition:m});let y=`M${c[0].x} ${c[0].y}`;for(let f=1;f<c.length-1;f++)y+=nh(c[f-1],c[f],c[f+1],l);return y+=`L${c[c.length-1].x} ${c[c.length-1].y}`,[y,b,v,h,p]}function Nt(e){var n;return e&&!!(e.internals.handleBounds||(n=e.handles)!=null&&n.length)&&!!(e.measured.width||e.width||e.initialWidth)}function ih(e){var c,b,v,h,p;const{sourceNode:n,targetNode:i}=e;if(!Nt(n)||!Nt(i))return null;const o=n.internals.handleBounds||At(n.handles),s=i.internals.handleBounds||At(i.handles),a=Ct((c=o==null?void 0:o.source)!=null?c:[],e.sourceHandle),l=Ct(e.connectionMode===gn.Strict?(b=s==null?void 0:s.target)!=null?b:[]:((v=s==null?void 0:s.target)!=null?v:[]).concat((h=s==null?void 0:s.source)!=null?h:[]),e.targetHandle);if(!a||!l)return(p=e.onError)==null||p.call(e,"008",Le.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const r=(a==null?void 0:a.position)||oe.Bottom,d=(l==null?void 0:l.position)||oe.Top,u=tn(n,a,r),m=tn(i,l,d);return{sourceX:u.x,sourceY:u.y,targetX:m.x,targetY:m.y,sourcePosition:r,targetPosition:d}}function At(e){var o,s;if(!e)return null;const n=[],i=[];for(const a of e)a.width=(o=a.width)!=null?o:1,a.height=(s=a.height)!=null?s:1,a.type==="source"?n.push(a):a.type==="target"&&i.push(a);return{source:n,target:i}}function tn(e,n,i=oe.Left,o=!1){var u,m,c;const s=((u=n==null?void 0:n.x)!=null?u:0)+e.internals.positionAbsolute.x,a=((m=n==null?void 0:n.y)!=null?m:0)+e.internals.positionAbsolute.y,{width:l,height:r}=n!=null?n:je(e);if(o)return{x:s+l/2,y:a+r/2};switch((c=n==null?void 0:n.position)!=null?c:i){case oe.Top:return{x:s+l/2,y:a};case oe.Right:return{x:s+l,y:a+r/2};case oe.Bottom:return{x:s+l/2,y:a+r};case oe.Left:return{x:s,y:a+r/2}}}function Ct(e,n){return e&&(n?e.find(i=>i.id===n):e[0])||null}function Jo(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function oh(e,{id:n,defaultColor:i,defaultMarkerStart:o,defaultMarkerEnd:s}){const a=new Set;return e.reduce((l,r)=>([r.markerStart||o,r.markerEnd||s].forEach(d=>{if(d&&typeof d=="object"){const u=Jo(d,n);a.has(u)||(l.push({id:u,color:d.color||i,...d}),a.add(u))}}),l),[]).sort((l,r)=>l.id.localeCompare(r.id))}const kt=1e3,sh=10,Zo={nodeOrigin:[0,0],nodeExtent:$n,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},ah={...Zo,checkEquality:!0};function Xo(e,n){const i={...e};for(const o in n)n[o]!==void 0&&(i[o]=n[o]);return i}function th(e,n,i){const o=Xo(Zo,i);for(const s of e.values())if(s.parentId)es(s,e,n,o);else{const a=Un(s,o.nodeOrigin),l=an(s.extent)?s.extent:o.nodeExtent,r=sn(a,l,je(s));s.internals.positionAbsolute=r}}function lh(e,n){var s,a;if(!e.handles)return e.measured?n==null?void 0:n.internals.handleBounds:void 0;const i=[],o=[];for(const l of e.handles){const r={id:l.id,width:(s=l.width)!=null?s:1,height:(a=l.height)!=null?a:1,nodeId:e.id,x:l.x,y:l.y,position:l.position,type:l.type};l.type==="source"?i.push(r):l.type==="target"&&o.push(r)}return{source:i,target:o}}function Qo(e){return e==="manual"}function Ro(e,n,i,o={}){var m,c,b;const s=Xo(ah,o),a={i:0},l=new Map(n),r=s!=null&&s.elevateNodesOnSelect&&!Qo(s.zIndexMode)?kt:0;let d=e.length>0,u=!1;n.clear(),i.clear();for(const v of e){let h=l.get(v.id);if(s.checkEquality&&v===(h==null?void 0:h.internals.userNode))n.set(v.id,h);else{const p=Un(v,s.nodeOrigin),y=an(v.extent)?v.extent:s.nodeExtent,f=sn(p,y,je(v));h={...s.defaults,...v,measured:{width:(m=v.measured)==null?void 0:m.width,height:(c=v.measured)==null?void 0:c.height},internals:{positionAbsolute:f,handleBounds:lh(v,h),z:Mt(v,r,s.zIndexMode),userNode:v}},n.set(v.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(d=!1),v.parentId&&es(h,n,i,o,a),u||(u=(b=v.selected)!=null?b:!1)}return{nodesInitialized:d,hasSelectedNodes:u}}function rh(e,n){if(!e.parentId)return;const i=n.get(e.parentId);i?i.set(e.id,e):n.set(e.parentId,new Map([[e.id,e]]))}function es(e,n,i,o,s){const{elevateNodesOnSelect:a,nodeOrigin:l,nodeExtent:r,zIndexMode:d}=Xo(Zo,o),u=e.parentId,m=n.get(u);if(!m){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}rh(e,i),s&&!m.parentId&&m.internals.rootParentIndex===void 0&&d==="auto"&&(m.internals.rootParentIndex=++s.i,m.internals.z=m.internals.z+s.i*sh),s&&m.internals.rootParentIndex!==void 0&&(s.i=m.internals.rootParentIndex);const c=a&&!Qo(d)?kt:0,{x:b,y:v,z:h}=dh(e,m,l,r,c,d),{positionAbsolute:p}=e.internals,y=b!==p.x||v!==p.y;(y||h!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:y?{x:b,y:v}:p,z:h}})}function Mt(e,n,i){const o=_e(e.zIndex)?e.zIndex:0;return Qo(i)?o:o+(e.selected?n:0)}function dh(e,n,i,o,s,a){var h;const{x:l,y:r}=n.internals.positionAbsolute,d=je(e),u=Un(e,i),m=an(e.extent)?sn(u,e.extent,d):u;let c=sn({x:l+m.x,y:r+m.y},o,d);e.extent==="parent"&&(c=ot(c,d,n));const b=Mt(e,s,a),v=(h=n.internals.z)!=null?h:0;return{x:c.x,y:c.y,z:v>=b?v+1:b}}function ns(e,n,i,o=[0,0]){var l,r;const s=[],a=new Map;for(const d of e){const u=n.get(d.parentId);if(!u)continue;const m=(r=(l=a.get(d.parentId))==null?void 0:l.expandedRect)!=null?r:Yn(u),c=at(m,d.rect);a.set(d.parentId,{expandedRect:c,parent:u})}return a.size>0&&a.forEach(({expandedRect:d,parent:u},m)=>{var S,w;const c=u.internals.positionAbsolute,b=je(u),v=(S=u.origin)!=null?S:o,h=d.x<c.x?Math.round(Math.abs(c.x-d.x)):0,p=d.y<c.y?Math.round(Math.abs(c.y-d.y)):0,y=Math.max(b.width,Math.round(d.width)),f=Math.max(b.height,Math.round(d.height)),N=(y-b.width)*v[0],g=(f-b.height)*v[1];(h>0||p>0||N||g)&&(s.push({id:m,type:"position",position:{x:u.position.x-h+N,y:u.position.y-p+g}}),(w=i.get(m))==null||w.forEach(A=>{e.some(C=>C.id===A.id)||s.push({id:A.id,type:"position",position:{x:A.position.x+h,y:A.position.y+p}})})),(b.width<d.width||b.height<d.height||h||p)&&s.push({id:m,type:"dimensions",setAttributes:!0,dimensions:{width:y+(h?v[0]*h-N:0),height:f+(p?v[1]*p-g:0)}})}),s}function uh(e,n,i,o,s,a,l){const r=o==null?void 0:o.querySelector(".xyflow__viewport");let d=!1;if(!r)return{changes:[],updatedInternals:d};const u=[],m=window.getComputedStyle(r),{m22:c}=new window.DOMMatrixReadOnly(m.transform),b=[];for(const v of e.values()){const h=n.get(v.id);if(!h)continue;if(h.hidden){n.set(h.id,{...h,internals:{...h.internals,handleBounds:void 0}}),d=!0;continue}const p=qo(v.nodeElement),y=h.measured.width!==p.width||h.measured.height!==p.height;if(!!(p.width&&p.height&&(y||!h.internals.handleBounds||v.force))){const N=v.nodeElement.getBoundingClientRect(),g=an(h.extent)?h.extent:a;let{positionAbsolute:S}=h.internals;h.parentId&&h.extent==="parent"?S=ot(S,p,n.get(h.parentId)):g&&(S=sn(S,g,p));const w={...h,measured:p,internals:{...h.internals,positionAbsolute:S,handleBounds:{source:ht("source",v.nodeElement,N,c,h.id),target:ht("target",v.nodeElement,N,c,h.id)}}};n.set(h.id,w),h.parentId&&es(w,n,i,{nodeOrigin:s,zIndexMode:l}),d=!0,y&&(u.push({id:h.id,type:"dimensions",dimensions:p}),h.expandParent&&h.parentId&&b.push({id:h.id,parentId:h.parentId,rect:Yn(w,s)}))}}if(b.length>0){const v=ns(b,n,i,s);u.push(...v)}return{changes:u,updatedInternals:d}}async function ch({delta:e,panZoom:n,transform:i,translateExtent:o,width:s,height:a}){if(!n||!e.x&&!e.y)return!1;const l=await n.setViewportConstrained({x:i[0]+e.x,y:i[1]+e.y,zoom:i[2]},[[0,0],[s,a]],o);return!!l&&(l.x!==i[0]||l.y!==i[1]||l.k!==i[2])}function Et(e,n,i,o,s,a){let l=s;const r=o.get(l)||new Map;o.set(l,r.set(i,n)),l=`${s}-${e}`;const d=o.get(l)||new Map;if(o.set(l,d.set(i,n)),a){l=`${s}-${e}-${a}`;const u=o.get(l)||new Map;o.set(l,u.set(i,n))}}function Tt(e,n,i){e.clear(),n.clear();for(const o of i){const{source:s,target:a,sourceHandle:l=null,targetHandle:r=null}=o,d={edgeId:o.id,source:s,target:a,sourceHandle:l,targetHandle:r},u=`${s}-${l}--${a}-${r}`,m=`${a}-${r}--${s}-${l}`;Et("source",d,m,e,s,l),Et("target",d,u,e,a,r),n.set(o.id,o)}}function Pt(e,n){if(!e.parentId)return!1;const i=n.get(e.parentId);return i?i.selected?!0:Pt(i,n):!1}function Lt(e,n,i){var s;let o=e;do{if((s=o==null?void 0:o.matches)!=null&&s.call(o,n))return!0;if(o===i)return!1;o=o==null?void 0:o.parentElement}while(o);return!1}function mh(e,n,i,o){var a,l;const s=new Map;for(const[r,d]of e)if((d.selected||d.id===o)&&(!d.parentId||!Pt(d,e))&&(d.draggable||n&&typeof d.draggable=="undefined")){const u=e.get(r);u&&s.set(r,{id:r,position:u.position||{x:0,y:0},distance:{x:i.x-u.internals.positionAbsolute.x,y:i.y-u.internals.positionAbsolute.y},extent:u.extent,parentId:u.parentId,origin:u.origin,expandParent:u.expandParent,internals:{positionAbsolute:u.internals.positionAbsolute||{x:0,y:0}},measured:{width:(a=u.measured.width)!=null?a:0,height:(l=u.measured.height)!=null?l:0}})}return s}function is({nodeId:e,dragItems:n,nodeLookup:i,dragging:o=!0}){var l,r,d;const s=[];for(const[u,m]of n){const c=(l=i.get(u))==null?void 0:l.internals.userNode;c&&s.push({...c,position:m.position,dragging:o})}if(!e)return[s[0],s];const a=(r=i.get(e))==null?void 0:r.internals.userNode;return[a?{...a,position:((d=n.get(e))==null?void 0:d.position)||a.position,dragging:o}:s[0],s]}function bh({dragItems:e,snapGrid:n,x:i,y:o}){const s=e.values().next().value;if(!s)return null;const a={x:i-s.distance.x,y:o-s.distance.y},l=Jn(a,n);return{x:l.x-a.x,y:l.y-a.y}}function vh({onNodeMouseDown:e,getStoreItems:n,onDragStart:i,onDrag:o,onDragStop:s}){let a={x:null,y:null},l=0,r=new Map,d=!1,u={x:0,y:0},m=null,c=!1,b=null,v=!1,h=!1,p=null;function y({noDragClassName:N,handleSelector:g,domNode:S,isSelectable:w,nodeId:A,nodeClickDistance:C=0}){b=Pe(S);function E({x:T,y:O}){const{nodeLookup:M,nodeExtent:D,snapGrid:I,snapToGrid:K,nodeOrigin:_,onNodeDrag:L,onSelectionDrag:z,onError:U,updateNodePositions:W}=n();a={x:T,y:O};let Y=!1;const J=r.size>1,ie=J&&D?jo(qn(r)):null,se=J&&K?bh({dragItems:r,snapGrid:I,x:T,y:O}):null;for(const[Q,j]of r){if(!M.has(Q))continue;let V={x:T-j.distance.x,y:O-j.distance.y};K&&(V=se?{x:Math.round(V.x+se.x),y:Math.round(V.y+se.y)}:Jn(V,I));let G=null;if(J&&D&&!j.extent&&ie){const{positionAbsolute:F}=j.internals,q=F.x-ie.x+D[0][0],R=F.x+j.measured.width-ie.x2+D[1][0],X=F.y-ie.y+D[0][1],Z=F.y+j.measured.height-ie.y2+D[1][1];G=[[q,X],[R,Z]]}const{position:H,positionAbsolute:$}=it({nodeId:Q,nextPosition:V,nodeLookup:M,nodeExtent:G||D,nodeOrigin:_,onError:U});Y=Y||j.position.x!==H.x||j.position.y!==H.y,j.position=H,j.internals.positionAbsolute=$}if(h=h||Y,!!Y&&(W(r,!0),p&&(o||L||!A&&z))){const[Q,j]=is({nodeId:A,dragItems:r,nodeLookup:M});o==null||o(p,r,Q,j),L==null||L(p,Q,j),A||z==null||z(p,j)}}async function k(){var _,L;if(!m)return;const{transform:T,panBy:O,autoPanSpeed:M,autoPanOnNodeDrag:D}=n();if(!D){d=!1,cancelAnimationFrame(l);return}const[I,K]=$o(u,m,M);(I!==0||K!==0)&&(a.x=((_=a.x)!=null?_:0)-I/T[2],a.y=((L=a.y)!=null?L:0)-K/T[2],await O({x:I,y:K})&&E(a)),l=requestAnimationFrame(k)}function B(T){var J;const{nodeLookup:O,multiSelectionActive:M,nodesDraggable:D,transform:I,snapGrid:K,snapToGrid:_,selectNodesOnDrag:L,onNodeDragStart:z,onSelectionDragStart:U,unselectNodesAndEdges:W}=n();c=!0,(!L||!w)&&!M&&A&&((J=O.get(A))!=null&&J.selected||W()),w&&L&&A&&(e==null||e(A));const Y=Qn(T.sourceEvent,{transform:I,snapGrid:K,snapToGrid:_,containerBounds:m});if(a=Y,r=mh(O,D,Y,A),r.size>0&&(i||z||!A&&U)){const[ie,se]=is({nodeId:A,dragItems:r,nodeLookup:O});i==null||i(T.sourceEvent,r,ie,se),z==null||z(T.sourceEvent,ie,se),A||U==null||U(T.sourceEvent,se)}}const P=ya().clickDistance(C).on("start",T=>{const{domNode:O,nodeDragThreshold:M,transform:D,snapGrid:I,snapToGrid:K}=n();m=(O==null?void 0:O.getBoundingClientRect())||null,v=!1,h=!1,p=T.sourceEvent,M===0&&B(T),a=Qn(T.sourceEvent,{transform:D,snapGrid:I,snapToGrid:K,containerBounds:m}),u=Oe(T.sourceEvent,m)}).on("drag",T=>{const{autoPanOnNodeDrag:O,transform:M,snapGrid:D,snapToGrid:I,nodeDragThreshold:K,nodeLookup:_}=n(),L=Qn(T.sourceEvent,{transform:M,snapGrid:D,snapToGrid:I,containerBounds:m});if(p=T.sourceEvent,(T.sourceEvent.type==="touchmove"&&T.sourceEvent.touches.length>1||A&&!_.has(A))&&(v=!0),!v){if(!d&&O&&c&&(d=!0,k()),!c){const z=Oe(T.sourceEvent,m),U=z.x-u.x,W=z.y-u.y;Math.sqrt(U*U+W*W)>K&&B(T)}(a.x!==L.xSnapped||a.y!==L.ySnapped)&&r&&c&&(u=Oe(T.sourceEvent,m),E(L))}}).on("end",T=>{if(!c||v){v&&r.size>0&&n().updateNodePositions(r,!1);return}if(d=!1,c=!1,cancelAnimationFrame(l),r.size>0){const{nodeLookup:O,updateNodePositions:M,onNodeDragStop:D,onSelectionDragStop:I}=n();if(h&&(M(r,!1),h=!1),s||D||!A&&I){const[K,_]=is({nodeId:A,dragItems:r,nodeLookup:O,dragging:!1});s==null||s(T.sourceEvent,r,K,_),D==null||D(T.sourceEvent,K,_),A||I==null||I(T.sourceEvent,_)}}}).filter(T=>{const O=T.target;return!T.button&&(!N||!Lt(O,`.${N}`,S))&&(!g||Lt(O,g,S))});b.call(P)}function f(){b==null||b.on(".drag",null)}return{update:y,destroy:f}}function hh(e,n,i){const o=[],s={x:e.x-i,y:e.y-i,width:i*2,height:i*2};for(const a of n.values())Di(s,Yn(a))>0&&o.push(a);return o}const fh=250;function ph(e,n,i,o){var r,d,u,m,c;let s=[],a=1/0;const l=hh(e,i,n+fh);for(const b of l){const v=[...(d=(r=b.internals.handleBounds)==null?void 0:r.source)!=null?d:[],...(m=(u=b.internals.handleBounds)==null?void 0:u.target)!=null?m:[]];for(const h of v){if(o.nodeId===h.nodeId&&o.type===h.type&&o.id===h.id)continue;const{x:p,y}=tn(b,h,h.position,!0),f=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(y-e.y,2));f>n||(f<a?(s=[{...h,x:p,y}],a=f):f===a&&s.push({...h,x:p,y}))}}if(!s.length)return null;if(s.length>1){const b=o.type==="source"?"target":"source";return(c=s.find(v=>v.type===b))!=null?c:s[0]}return s[0]}function Bt(e,n,i,o,s,a=!1){var u,m,c,b,v,h;const l=o.get(e);if(!l)return null;const r=s==="strict"?(u=l.internals.handleBounds)==null?void 0:u[n]:[...(c=(m=l.internals.handleBounds)==null?void 0:m.source)!=null?c:[],...(v=(b=l.internals.handleBounds)==null?void 0:b.target)!=null?v:[]],d=(h=i?r==null?void 0:r.find(p=>p.id===i):r==null?void 0:r[0])!=null?h:null;return d&&a?{...d,...tn(l,d,d.position,!0)}:d}function It(e,n){return e||(n!=null&&n.classList.contains("target")?"target":n!=null&&n.classList.contains("source")?"source":null)}function gh(e,n){let i=null;return n?i=!0:e&&!n&&(i=!1),i}const Dt=()=>!0;function yh(e,{connectionMode:n,connectionRadius:i,handleId:o,nodeId:s,edgeUpdaterType:a,isTarget:l,domNode:r,nodeLookup:d,lib:u,autoPanOnConnect:m,flowId:c,panBy:b,cancelConnection:v,onConnectStart:h,onConnect:p,onConnectEnd:y,isValidConnection:f=Dt,onReconnectEnd:N,updateConnection:g,getTransform:S,getFromHandle:w,autoPanSpeed:A,dragThreshold:C=1,handleDomNode:E}){const k=mt(e.target);let B=0,P;const{x:T,y:O}=Oe(e),M=It(a,E),D=r==null?void 0:r.getBoundingClientRect();let I=!1;if(!D||!M)return;const K=Bt(s,M,o,d,n);if(!K)return;let _=Oe(e,D),L=!1,z=null,U=!1,W=null;function Y(){if(!m||!D)return;const[H,$]=$o(_,D,A);b({x:H,y:$}),B=requestAnimationFrame(Y)}const J={...K,nodeId:s,type:M,position:K.position},ie=d.get(s);let Q={inProgress:!0,isValid:null,from:tn(ie,J,oe.Left,!0),fromHandle:J,fromPosition:J.position,fromNode:ie,to:_,toHandle:null,toPosition:Ra[J.position],toNode:null,pointer:_};function j(){I=!0,g(Q),h==null||h(e,{nodeId:s,handleId:o,handleType:M})}C===0&&j();function V(H){if(!I){const{x:Z,y:ee}=Oe(H),ae=Z-T,ue=ee-O;if(!(ae*ae+ue*ue>C*C))return;j()}if(!w()||!J){G(H);return}const $=S();_=Oe(H,D),P=ph(Zn(_,$,!1,[1,1]),i,d,J),L||(Y(),L=!0);const F=_t(H,{handle:P,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:l?"target":"source",isValidConnection:f,doc:k,lib:u,flowId:c,nodeLookup:d});W=F.handleDomNode,z=F.connection,U=gh(!!P,F.isValid);const q=d.get(s),R=q?tn(q,J,oe.Left,!0):Q.from,X={...Q,from:R,isValid:U,to:F.toHandle&&U?Sn({x:F.toHandle.x,y:F.toHandle.y},$):_,toHandle:F.toHandle,toPosition:U&&F.toHandle?F.toHandle.position:Ra[J.position],toNode:F.toHandle?d.get(F.toHandle.nodeId):null,pointer:_};g(X),Q=X}function G(H){if(!("touches"in H&&H.touches.length>0)){if(I){(P||W)&&z&&U&&(p==null||p(z));const{inProgress:$,...F}=Q,q={...F,toPosition:Q.toHandle?Q.toPosition:null};y==null||y(H,q),a&&(N==null||N(H,q))}v(),cancelAnimationFrame(B),L=!1,U=!1,z=null,W=null,k.removeEventListener("mousemove",V),k.removeEventListener("mouseup",G),k.removeEventListener("touchmove",V),k.removeEventListener("touchend",G)}}k.addEventListener("mousemove",V),k.addEventListener("mouseup",G),k.addEventListener("touchmove",V),k.addEventListener("touchend",G)}function _t(e,{handle:n,connectionMode:i,fromNodeId:o,fromHandleId:s,fromType:a,doc:l,lib:r,flowId:d,isValidConnection:u=Dt,nodeLookup:m}){const c=a==="target",b=n?l.querySelector(`.${r}-flow__handle[data-id="${d}-${n==null?void 0:n.nodeId}-${n==null?void 0:n.id}-${n==null?void 0:n.type}"]`):null,{x:v,y:h}=Oe(e),p=l.elementFromPoint(v,h),y=p!=null&&p.classList.contains(`${r}-flow__handle`)?p:b,f={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){const N=It(void 0,y),g=y.getAttribute("data-nodeid"),S=y.getAttribute("data-handleid"),w=y.classList.contains("connectable"),A=y.classList.contains("connectableend");if(!g||!N)return f;const C={source:c?g:o,sourceHandle:c?S:s,target:c?o:g,targetHandle:c?s:S};f.connection=C;const k=w&&A&&(i===gn.Strict?c&&N==="source"||!c&&N==="target":g!==o||S!==s);f.isValid=k&&u(C),f.toHandle=Bt(g,N,S,m,i,!0)}return f}const os={onPointerDown:yh,isValid:_t};function xh({domNode:e,panZoom:n,getTransform:i,getViewScale:o}){const s=Pe(e);function a({translateExtent:r,width:d,height:u,zoomStep:m=1,pannable:c=!0,zoomable:b=!0,inversePan:v=!1}){const h=g=>{if(g.sourceEvent.type!=="wheel"||!n)return;const S=i(),w=g.sourceEvent.ctrlKey&&Xn()?10:1,A=-g.sourceEvent.deltaY*(g.sourceEvent.deltaMode===1?.05:g.sourceEvent.deltaMode?1:.002)*m,C=S[2]*Math.pow(2,A*w);n.scaleTo(C)};let p=[0,0];const y=g=>{var S,w;(g.sourceEvent.type==="mousedown"||g.sourceEvent.type==="touchstart")&&(p=[(S=g.sourceEvent.clientX)!=null?S:g.sourceEvent.touches[0].clientX,(w=g.sourceEvent.clientY)!=null?w:g.sourceEvent.touches[0].clientY])},f=g=>{var B,P;const S=i();if(g.sourceEvent.type!=="mousemove"&&g.sourceEvent.type!=="touchmove"||!n)return;const w=[(B=g.sourceEvent.clientX)!=null?B:g.sourceEvent.touches[0].clientX,(P=g.sourceEvent.clientY)!=null?P:g.sourceEvent.touches[0].clientY],A=[w[0]-p[0],w[1]-p[1]];p=w;const C=o()*Math.max(S[2],Math.log(S[2]))*(v?-1:1),E={x:S[0]-A[0]*C,y:S[1]-A[1]*C},k=[[0,0],[d,u]];n.setViewportConstrained({x:E.x,y:E.y,zoom:S[2]},k,r)},N=Ja().on("start",y).on("zoom",c?f:null).on("zoom.wheel",b?h:null);s.call(N,{})}function l(){s.on("zoom",null)}return{update:a,destroy:l,pointer:Be}}const Oi=e=>({x:e.x,y:e.y,zoom:e.k}),ss=({x:e,y:n,zoom:i})=>Pi.translate(e,n).scale(i),Nn=(e,n)=>e.target.closest(`.${n}`),Ot=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),Sh=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,as=(e,n=0,i=Sh,o=()=>{})=>{const s=typeof n=="number"&&n>0;return s||o(),s?e.transition().duration(n).ease(i).on("end",o):e},Kt=e=>{const n=e.ctrlKey&&Xn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function wh({zoomPanValues:e,noWheelClassName:n,d3Selection:i,d3Zoom:o,panOnScrollMode:s,panOnScrollSpeed:a,zoomOnPinch:l,onPanZoomStart:r,onPanZoom:d,onPanZoomEnd:u}){return m=>{if(Nn(m,n))return m.ctrlKey&&m.preventDefault(),!1;m.preventDefault(),m.stopImmediatePropagation();const c=i.property("__zoom").k||1;if(m.ctrlKey&&l){const y=Be(m),f=Kt(m),N=c*Math.pow(2,f);o.scaleTo(i,N,y,m);return}const b=m.deltaMode===1?20:1;let v=s===on.Vertical?0:m.deltaX*b,h=s===on.Horizontal?0:m.deltaY*b;!Xn()&&m.shiftKey&&s!==on.Vertical&&(v=m.deltaY*b,h=0),o.translateBy(i,-(v/c)*a,-(h/c)*a,{internal:!0});const p=Oi(i.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d==null||d(m,p),e.panScrollTimeout=setTimeout(()=>{u==null||u(m,p),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,r==null||r(m,p))}}function Nh({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:i}){return function(o,s){const a=o.type==="wheel",l=!n&&a&&!o.ctrlKey,r=Nn(o,e);if(o.ctrlKey&&a&&r&&o.preventDefault(),l||r)return null;o.preventDefault(),i.call(this,o,s)}}function Ah({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:i}){return o=>{var a,l,r;if((a=o.sourceEvent)!=null&&a.internal)return;const s=Oi(o.transform);e.mouseButton=((l=o.sourceEvent)==null?void 0:l.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((r=o.sourceEvent)==null?void 0:r.type)==="mousedown"&&n(!0),i&&(i==null||i(o.sourceEvent,s))}}function Ch({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:i,onTransformChange:o,onPanZoom:s}){return a=>{var l,r,d;e.usedRightMouseButton=!!(i&&Ot(n,(l=e.mouseButton)!=null?l:0)),(r=a.sourceEvent)!=null&&r.sync||o([a.transform.x,a.transform.y,a.transform.k]),s&&!((d=a.sourceEvent)!=null&&d.internal)&&(s==null||s(a.sourceEvent,Oi(a.transform)))}}function kh({zoomPanValues:e,panOnDrag:n,panOnScroll:i,onDraggingChange:o,onPanZoomEnd:s,onPaneContextMenu:a}){return l=>{var r,d;if(!((r=l.sourceEvent)!=null&&r.internal)&&(e.isZoomingOrPanning=!1,a&&Ot(n,(d=e.mouseButton)!=null?d:0)&&!e.usedRightMouseButton&&l.sourceEvent&&a(l.sourceEvent),e.usedRightMouseButton=!1,o(!1),s)){const u=Oi(l.transform);e.prevViewport=u,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(l.sourceEvent,u)},i?150:0)}}}function Mh({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:i,panOnDrag:o,panOnScroll:s,zoomOnDoubleClick:a,userSelectionActive:l,noWheelClassName:r,noPanClassName:d,lib:u,connectionInProgress:m}){return c=>{var y;const b=e||n,v=i&&c.ctrlKey,h=c.type==="wheel";if(c.button===1&&c.type==="mousedown"&&(Nn(c,`${u}-flow__node`)||Nn(c,`${u}-flow__edge`)))return!0;if(!o&&!b&&!s&&!a&&!i||l||m&&!h||Nn(c,r)&&h||Nn(c,d)&&(!h||s&&h&&!e)||!i&&c.ctrlKey&&h)return!1;if(!i&&c.type==="touchstart"&&((y=c.touches)==null?void 0:y.length)>1)return c.preventDefault(),!1;if(!b&&!s&&!v&&h||!o&&(c.type==="mousedown"||c.type==="touchstart")||Array.isArray(o)&&!o.includes(c.button)&&c.type==="mousedown")return!1;const p=Array.isArray(o)&&o.includes(c.button)||!c.button||c.button<=1;return(!c.ctrlKey||h)&&p}}function Eh({domNode:e,minZoom:n,maxZoom:i,translateExtent:o,viewport:s,onPanZoom:a,onPanZoomStart:l,onPanZoomEnd:r,onDraggingChange:d}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},m=e.getBoundingClientRect(),c=Ja().scaleExtent([n,i]).translateExtent(o),b=Pe(e).call(c);N({x:s.x,y:s.y,zoom:xn(s.zoom,n,i)},[[0,0],[m.width,m.height]],o);const v=b.on("wheel.zoom"),h=b.on("dblclick.zoom");c.wheelDelta(Kt);async function p(P,T){return b?new Promise(O=>{c==null||c.interpolate((T==null?void 0:T.interpolate)==="linear"?Hn:xi).transform(as(b,T==null?void 0:T.duration,T==null?void 0:T.ease,()=>O(!0)),P)}):!1}function y({noWheelClassName:P,noPanClassName:T,onPaneContextMenu:O,userSelectionActive:M,panOnScroll:D,panOnDrag:I,panOnScrollMode:K,panOnScrollSpeed:_,preventScrolling:L,zoomOnPinch:z,zoomOnScroll:U,zoomOnDoubleClick:W,zoomActivationKeyPressed:Y,lib:J,onTransformChange:ie,connectionInProgress:se,paneClickDistance:Q,selectionOnDrag:j}){M&&!u.isZoomingOrPanning&&f();const V=D&&!Y&&!M;c.clickDistance(j?1/0:!_e(Q)||Q<0?0:Q);const G=V?wh({zoomPanValues:u,noWheelClassName:P,d3Selection:b,d3Zoom:c,panOnScrollMode:K,panOnScrollSpeed:_,zoomOnPinch:z,onPanZoomStart:l,onPanZoom:a,onPanZoomEnd:r}):Nh({noWheelClassName:P,preventScrolling:L,d3ZoomHandler:v});b.on("wheel.zoom",G,{passive:!1});const H=Ah({zoomPanValues:u,onDraggingChange:d,onPanZoomStart:l});c.on("start",H);const $=Ch({zoomPanValues:u,panOnDrag:I,onPaneContextMenu:!!O,onPanZoom:a,onTransformChange:ie});c.on("zoom",$);const F=kh({zoomPanValues:u,panOnDrag:I,panOnScroll:D,onPaneContextMenu:O,onPanZoomEnd:r,onDraggingChange:d});c.on("end",F);const q=Mh({zoomActivationKeyPressed:Y,panOnDrag:I,zoomOnScroll:U,panOnScroll:D,zoomOnDoubleClick:W,zoomOnPinch:z,userSelectionActive:M,noPanClassName:T,noWheelClassName:P,lib:J,connectionInProgress:se});c.filter(q),W?b.on("dblclick.zoom",h):b.on("dblclick.zoom",null)}function f(){c.on("zoom",null)}async function N(P,T,O){const M=ss(P),D=c==null?void 0:c.constrain()(M,T,O);return D&&await p(D),D}async function g(P,T){const O=ss(P);return await p(O,T),O}function S(P){if(b){const T=ss(P),O=b.property("__zoom");(O.k!==P.zoom||O.x!==P.x||O.y!==P.y)&&(c==null||c.transform(b,T,null,{sync:!0}))}}function w(){const P=b?qa(b.node()):{x:0,y:0,k:1};return{x:P.x,y:P.y,zoom:P.k}}async function A(P,T){return b?new Promise(O=>{c==null||c.interpolate((T==null?void 0:T.interpolate)==="linear"?Hn:xi).scaleTo(as(b,T==null?void 0:T.duration,T==null?void 0:T.ease,()=>O(!0)),P)}):!1}async function C(P,T){return b?new Promise(O=>{c==null||c.interpolate((T==null?void 0:T.interpolate)==="linear"?Hn:xi).scaleBy(as(b,T==null?void 0:T.duration,T==null?void 0:T.ease,()=>O(!0)),P)}):!1}function E(P){c==null||c.scaleExtent(P)}function k(P){c==null||c.translateExtent(P)}function B(P){const T=!_e(P)||P<0?0:P;c==null||c.clickDistance(T)}return{update:y,destroy:f,setViewport:g,setViewportConstrained:N,getViewport:w,scaleTo:A,scaleBy:C,setScaleExtent:E,setTranslateExtent:k,syncViewport:S,setClickDistance:B}}var An;(function(e){e.Line="line",e.Handle="handle"})(An||(An={}));function Th({width:e,prevWidth:n,height:i,prevHeight:o,affectsX:s,affectsY:a}){const l=e-n,r=i-o,d=[l>0?1:l<0?-1:0,r>0?1:r<0?-1:0];return l&&s&&(d[0]=d[0]*-1),r&&a&&(d[1]=d[1]*-1),d}function Ht(e){const n=e.includes("right")||e.includes("left"),i=e.includes("bottom")||e.includes("top"),o=e.includes("left"),s=e.includes("top");return{isHorizontal:n,isVertical:i,affectsX:o,affectsY:s}}function Ye(e,n){return Math.max(0,n-e)}function Je(e,n){return Math.max(0,e-n)}function Ki(e,n,i){return Math.max(0,n-e,e-i)}function Gt(e,n){return e?!n:n}function Ph(e,n,i,o,s,a,l,r){let{affectsX:d,affectsY:u}=n;const{isHorizontal:m,isVertical:c}=n,b=m&&c,{xSnapped:v,ySnapped:h}=i,{minWidth:p,maxWidth:y,minHeight:f,maxHeight:N}=o,{x:g,y:S,width:w,height:A,aspectRatio:C}=e;let E=Math.floor(m?v-e.pointerX:0),k=Math.floor(c?h-e.pointerY:0);const B=w+(d?-E:E),P=A+(u?-k:k),T=-a[0]*w,O=-a[1]*A;let M=Ki(B,p,y),D=Ki(P,f,N);if(l){let _=0,L=0;d&&E<0?_=Ye(g+E+T,l[0][0]):!d&&E>0&&(_=Je(g+B+T,l[1][0])),u&&k<0?L=Ye(S+k+O,l[0][1]):!u&&k>0&&(L=Je(S+P+O,l[1][1])),M=Math.max(M,_),D=Math.max(D,L)}if(r){let _=0,L=0;d&&E>0?_=Je(g+E,r[0][0]):!d&&E<0&&(_=Ye(g+B,r[1][0])),u&&k>0?L=Je(S+k,r[0][1]):!u&&k<0&&(L=Ye(S+P,r[1][1])),M=Math.max(M,_),D=Math.max(D,L)}if(s){if(m){const _=Ki(B/C,f,N)*C;if(M=Math.max(M,_),l){let L=0;!d&&!u||d&&!u&&b?L=Je(S+O+B/C,l[1][1])*C:L=Ye(S+O+(d?E:-E)/C,l[0][1])*C,M=Math.max(M,L)}if(r){let L=0;!d&&!u||d&&!u&&b?L=Ye(S+B/C,r[1][1])*C:L=Je(S+(d?E:-E)/C,r[0][1])*C,M=Math.max(M,L)}}if(c){const _=Ki(P*C,p,y)/C;if(D=Math.max(D,_),l){let L=0;!d&&!u||u&&!d&&b?L=Je(g+P*C+T,l[1][0])/C:L=Ye(g+(u?k:-k)*C+T,l[0][0])/C,D=Math.max(D,L)}if(r){let L=0;!d&&!u||u&&!d&&b?L=Ye(g+P*C,r[1][0])/C:L=Je(g+(u?k:-k)*C,r[0][0])/C,D=Math.max(D,L)}}}k=k+(k<0?D:-D),E=E+(E<0?M:-M),s&&(b?B>P*C?k=(Gt(d,u)?-E:E)/C:E=(Gt(d,u)?-k:k)*C:m?(k=E/C,u=d):(E=k*C,d=u));const I=d?g+E:g,K=u?S+k:S;return{width:w+(d?-E:E),height:A+(u?-k:k),x:a[0]*E*(d?-1:1)+I,y:a[1]*k*(u?-1:1)+K}}const Ft={width:0,height:0,x:0,y:0},Lh={...Ft,pointerX:0,pointerY:0,aspectRatio:1};function Bh(e,n,i){var u,m;const o=n.position.x+e.position.x,s=n.position.y+e.position.y,a=(u=e.measured.width)!=null?u:0,l=(m=e.measured.height)!=null?m:0,r=i[0]*a,d=i[1]*l;return[[o-r,s-d],[o+a-r,s+l-d]]}function Ih({domNode:e,nodeId:n,getStoreItems:i,onChange:o,onEnd:s}){const a=Pe(e);let l={controlDirection:Ht("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function r({controlPosition:u,boundaries:m,keepAspectRatio:c,resizeDirection:b,onResizeStart:v,onResize:h,onResizeEnd:p,shouldResize:y}){let f={...Ft},N={...Lh};l={boundaries:m,resizeDirection:b,keepAspectRatio:c,controlDirection:Ht(u)};let g,S=null,w=[],A,C,E,k=!1;const B=ya().on("start",P=>{var z,U,W,Y,J,ie;const{nodeLookup:T,transform:O,snapGrid:M,snapToGrid:D,nodeOrigin:I,paneDomNode:K}=i();if(g=T.get(n),!g)return;S=(z=K==null?void 0:K.getBoundingClientRect())!=null?z:null;const{xSnapped:_,ySnapped:L}=Qn(P.sourceEvent,{transform:O,snapGrid:M,snapToGrid:D,containerBounds:S});f={width:(U=g.measured.width)!=null?U:0,height:(W=g.measured.height)!=null?W:0,x:(Y=g.position.x)!=null?Y:0,y:(J=g.position.y)!=null?J:0},N={...f,pointerX:_,pointerY:L,aspectRatio:f.width/f.height},A=void 0,C=an(g.extent)?g.extent:void 0,g.parentId&&(g.extent==="parent"||g.expandParent)&&(A=T.get(g.parentId)),A&&g.extent==="parent"&&(C=[[0,0],[A.measured.width,A.measured.height]]),w=[],E=void 0;for(const[se,Q]of T)if(Q.parentId===n&&(w.push({id:se,position:{...Q.position},extent:Q.extent}),Q.extent==="parent"||Q.expandParent)){const j=Bh(Q,g,(ie=Q.origin)!=null?ie:I);E?E=[[Math.min(j[0][0],E[0][0]),Math.min(j[0][1],E[0][1])],[Math.max(j[1][0],E[1][0]),Math.max(j[1][1],E[1][1])]]:E=j}v==null||v(P,{...f})}).on("drag",P=>{var R,X,Z;const{transform:T,snapGrid:O,snapToGrid:M,nodeOrigin:D}=i(),I=Qn(P.sourceEvent,{transform:T,snapGrid:O,snapToGrid:M,containerBounds:S}),K=[];if(!g)return;const{x:_,y:L,width:z,height:U}=f,W={},Y=(R=g.origin)!=null?R:D,{width:J,height:ie,x:se,y:Q}=Ph(N,l.controlDirection,I,l.boundaries,l.keepAspectRatio,Y,C,E),j=J!==z,V=ie!==U,G=se!==_&&j,H=Q!==L&&V;if(!G&&!H&&!j&&!V)return;if((G||H||Y[0]===1||Y[1]===1)&&(W.x=G?se:f.x,W.y=H?Q:f.y,f.x=W.x,f.y=W.y,w.length>0)){const ee=se-_,ae=Q-L;for(const ue of w)ue.position={x:ue.position.x-ee+Y[0]*(J-z),y:ue.position.y-ae+Y[1]*(ie-U)},K.push(ue)}if((j||V)&&(W.width=j&&(!l.resizeDirection||l.resizeDirection==="horizontal")?J:f.width,W.height=V&&(!l.resizeDirection||l.resizeDirection==="vertical")?ie:f.height,f.width=W.width,f.height=W.height),A&&g.expandParent){const ee=Y[0]*((X=W.width)!=null?X:0);W.x&&W.x<ee&&(f.x=ee,N.x=N.x-(W.x-ee));const ae=Y[1]*((Z=W.height)!=null?Z:0);W.y&&W.y<ae&&(f.y=ae,N.y=N.y-(W.y-ae))}const $=Th({width:f.width,prevWidth:z,height:f.height,prevHeight:U,affectsX:l.controlDirection.affectsX,affectsY:l.controlDirection.affectsY}),F={...f,direction:$};(y==null?void 0:y(P,F))!==!1&&(k=!0,h==null||h(P,F),o(W,K))}).on("end",P=>{k&&(p==null||p(P,{...f}),s==null||s({...f}),k=!1)});a.call(B)}function d(){a.on(".drag",null)}return{update:r,destroy:d}}function Dh(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Hi={exports:{}},ts={},Gi={exports:{}},ls={};/**