@arudovwen/form-builder-react 1.8.6 → 1.8.7

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,11 +23,11 @@
23
23
  "data": [
24
24
  { "name": "Document Name", "id": "documentMainId", ...restObject },
25
25
  ]
26
- }`})})]})})}),Jd=()=>a.jsx("blockquote",{className:"p-4 text-gray-700 bg-gray-100 rounded-md",children:a.jsxs("ul",{children:[a.jsxs("li",{className:"text-xs",children:["Method: GET ",a.jsx("br",{}),"URL format:"," ",a.jsx("code",{children:"https://example.com/validation/{documentId}"})]}),a.jsxs("li",{className:"text-xs",children:[a.jsx("span",{className:"block mb-1",children:" Response example format:"}),a.jsx("pre",{className:"p-2 bg-white rounded-md",children:a.jsxs("code",{children:["{ ",a.jsx("br",{}),'  "data": { ',a.jsx("br",{}),'    "status": true, ',a.jsx("br",{}),'    "isSigned": true ',a.jsx("br",{}),"  } ",a.jsx("br",{}),"}"]})})]})]})});function Qs(e){return e.flatMap(n=>{var i;return(i=n==null?void 0:n.questionData)!=null?i:[]})}const vo=["text","number","boolean"],Rs=["equals","not_equals","contains","not_contains"],Zd=["greater","less"];function Xd({register:e,setValue:n,trigger:i,watch:o,id:s}){const{formData:t}=x.useContext(Te),l=o("visibilityDependentFields")||[],r=x.useMemo(()=>{var c;return(c=Qs(t).filter(m=>m.id!==s))==null?void 0:c.map(m=>{const u=l.find(b=>b.id===m.id);return{id:m.id,value:m.id,label:m.inputLabel,sectionId:m.sectionId,fieldType:(u==null?void 0:u.fieldType)||"text",operator:(u==null?void 0:u.operator)||"equals",fieldValue:(u==null?void 0:u.fieldValue)!==void 0?u.fieldValue:""}})},[t,l,s]),d=(c,m,u)=>{const b=l==null?void 0:l.map((h,v)=>v===c?{...h,[m]:u}:h);n("visibilityDependentFields",b)};return a.jsxs("div",{className:"flex flex-col gap-4 w-full",children:[a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsx("label",{className:"text-sm font-semibold text-slate-800",children:"Dependent Fields"}),a.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"Choose which fields this element's visibility should depend on."}),a.jsx(ro,{element:{options:r,id:"visibilityDependentFields",value:o("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:i,watch:o}})]}),l.length>0&&a.jsxs("div",{className:"flex flex-col gap-3 mt-2",children:[a.jsxs("div",{className:"hidden sm:flex flex-wrap items-center gap-3 px-4 pt-2 pb-1",children:[a.jsx("div",{className:"flex-1 min-w-[120px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Field"})}),a.jsx("div",{className:"w-[110px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Type"})}),a.jsx("div",{className:"w-[140px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Operator"})}),a.jsx("div",{className:"flex-1 min-w-[140px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Value"})})]}),l==null?void 0:l.map((c,m)=>{var v,p,y,f;const u=Qs(t).find(S=>S.id===c.id),b=["selectField","radio","checkbox","multiSelect","cascadeSelect"].includes(u==null?void 0:u.type),h=(u==null?void 0:u.options)||[];return a.jsxs("div",{className:"group relative flex flex-wrap items-center gap-2 p-2 bg-white/70 backdrop-blur-md border border-slate-200/80 rounded-lg shadow-[0_2px_10px_-4px_rgba(0,0,0,0.1)] hover:border-gray-300/60 transition-all duration-300 ease-out",children:[a.jsx("div",{className:"flex-1 min-w-[120px]",children:a.jsx("input",{type:"text",id:c.label,value:c.label,readOnly:!0,disabled:!0,className:"w-full px-3 py-2.5 bg-slate-100/50 border border-slate-200/80 rounded-lg text-sm text-slate-600 font-medium truncate cursor-not-allowed focus:outline-none"})}),a.jsx("div",{className:"w-[110px]",children:a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:c.fieldType,onChange:S=>d(m,"fieldType",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate capitalize",children:c.fieldType}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsx(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[120px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:vo==null?void 0:vo.map(S=>a.jsx(le.Listbox.Option,{value:S,className:({active:g})=>`px-4 py-2 text-sm cursor-pointer capitalize transition-colors ${g?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:S},S))})})]})})}),a.jsx("div",{className:"w-[140px]",children:a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:c.operator,onChange:S=>d(m,"operator",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate capitalize",children:c.operator.replace("_"," ")}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsx(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[150px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:(v=c.fieldType==="number"?[...Rs,...Zd]:Rs)==null?void 0:v.map(S=>a.jsx(le.Listbox.Option,{value:S,className:({active:g})=>`px-4 py-2 text-sm cursor-pointer capitalize transition-colors ${g?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:S.replace("_"," ")},S))})})]})})}),a.jsx("div",{className:"flex-1 min-w-[140px]",children:b&&h.length>0?a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:(p=c.fieldValue)!=null?p:"",onChange:S=>d(m,"fieldValue",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate pr-2",children:((y=h.find(S=>S.value===c.fieldValue))==null?void 0:y.label)||"Select value"}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 flex-shrink-0 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsx(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[160px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:h.map((S,g)=>a.jsx(le.Listbox.Option,{value:S.value,className:({active:w})=>`px-4 py-2 text-sm cursor-pointer transition-colors ${w?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:S.label},g))})})]})}):c.fieldType!=="boolean"?a.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:S=>d(m,"fieldValue",S.target.value),placeholder:"Enter value...",className:"w-full px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 transition-colors shadow-sm placeholder-slate-400"}):a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:(f=c.fieldValue)!=null?f:"",onChange:S=>d(m,"fieldValue",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsxs(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[150px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:[a.jsx(le.Listbox.Option,{value:!0,className:({active:S})=>`px-4 py-2 text-sm cursor-pointer transition-colors ${S?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:"True"}),a.jsx(le.Listbox.Option,{value:!1,className:({active:S})=>`px-4 py-2 text-sm cursor-pointer transition-colors ${S?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:"False"})]})})]})})})]},c.id)})]})]})}function ea(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 t=e.slice(o);return t&&n.push({type:"operator",value:t}),n}function Qd(e){return e.map(n=>n.type==="field"?`@[${n.display}](${n.id})`:n.value).join("")}function Rd({value:e,onChange:n,fields:i,placeholder:o}){const[s,t]=x.useState(()=>ea(e)),[l,r]=x.useState(null),[d,c]=x.useState(!1),[m,u]=x.useState(""),[b,h]=x.useState(null),v=x.useRef(null),p=x.useRef(null),y=x.useRef(new Map);x.useEffect(()=>{const k=ea(e);t(k)},[]);const f=x.useCallback(k=>{n(Qd(k))},[n]),S=(k,I)=>{const P=[...s];P[k]={type:"operator",value:I},t(P),f(P)},g=k=>{const I=s.filter((P,T)=>T!==k);t(I),f(I)},w=k=>{h(k),u(""),c(!0)},N=(k,I)=>{const P=I!==void 0?I:b!=null?b:s.length,T=[...s],O=T.slice(0,P),M=T.slice(P),_=[...O,{type:"field",id:k.id,display:k.display},...M],B=A(_);t(B),f(B),c(!1),h(null)};function A(k){const I=[];if(k.length===0)return[{type:"operator",value:""}];k[0].type==="field"&&I.push({type:"operator",value:""});for(let P=0;P<k.length;P++)I.push(k[P]),k[P].type==="field"&&(P+1>=k.length||k[P+1].type==="field")&&I.push({type:"operator",value:""});return I}const C=i.filter(k=>k.display.toLowerCase().includes(m.toLowerCase())),E=s.every(k=>k.type==="operator"&&k.value.trim()==="");return a.jsxs("div",{className:"relative",ref:p,children:[a.jsxs("div",{className:"field-control flex flex-wrap items-center gap-1 min-h-[44px] cursor-text",style:{padding:"6px 10px"},onClick:()=>{var I;const k=[...s].reverse().findIndex(P=>P.type==="operator");if(k!==-1){const P=s.length-1-k;(I=y.current.get(P))==null||I.focus()}},children:[E&&a.jsx("span",{className:"text-gray-400 text-sm pointer-events-none select-none",children:o||"Build your formula..."}),s.map((k,I)=>k.type==="field"?a.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,a.jsx("button",{type:"button",onMouseDown:P=>{P.preventDefault(),g(I)},className:"text-blue-400 hover:text-blue-700 leading-none ml-0.5","aria-label":`Remove ${k.display}`,children:"×"})]},I):a.jsx("input",{ref:P=>{P?y.current.set(I,P):y.current.delete(I)},type:"text",value:k.value,onChange:P=>S(I,P.target.value),onFocus:()=>r(I),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===I?40:14)}px`,minWidth:"14px",maxWidth:"200px"},placeholder:"","aria-label":`Operator at position ${I}`},I)),a.jsx("button",{type:"button",onMouseDown:k=>{k.preventDefault(),w(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:a.jsx("span",{className:"text-base leading-none",children:"@"})})]}),!E&&a.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:[a.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&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onMouseDown:()=>c(!1)}),a.jsxs("div",{ref:v,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:[a.jsx("div",{className:"p-2 border-b border-gray-100",children:a.jsx("input",{autoFocus:!0,type:"text",placeholder:"Search fields...",value:m,onChange:k=>u(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"&&c(!1),k.key==="Enter"&&C.length>0&&N(C[0])}})}),a.jsxs("div",{className:"max-h-48 overflow-y-auto",children:[C.length===0&&a.jsx("p",{className:"text-xs text-gray-400 text-center py-3",children:"No matching fields"}),C.map(k=>a.jsxs("div",{onMouseDown:I=>{I.preventDefault(),N(k)},className:"px-3 py-2 text-sm cursor-pointer flex items-center justify-between hover:bg-blue-50 group",children:[a.jsx("span",{className:"font-medium text-gray-800",children:k.display}),a.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&&a.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:i.map(k=>a.jsxs("button",{type:"button",onMouseDown:I=>{I.preventDefault(),N(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 eu=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(),minChecked:ne.number().typeError("Expecting a number").nullable().default(1),requireAllChecked:ne.boolean(),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()}),nu=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],iu=({isOpen:e,onClose:n,element:i})=>{var ee;const o=nu.filter(J=>!ri.includes(i.inputType)||J.key!=="validation"),{updateElement:s,formData:t}=x.useContext(Te),[l,r]=x.useState("basic"),[d,c]=x.useState(!1),[m,u]=x.useState("manual"),b=((ee=t==null?void 0:t.flatMap(J=>(J==null?void 0:J.questionData)||[]))==null?void 0:ee.length)||0,h=x.useMemo(()=>(t==null?void 0:t.flatMap(J=>(J==null?void 0:J.questionData)||[]).filter(J=>{var K;return J.id!==(i==null?void 0:i.id)&&!["spacer","divider","section","grid"].includes((K=J.type)==null?void 0:K.toLowerCase())}).map(J=>({id:J.id,display:J.inputLabel||J.label||"Unnamed"})))||[],[b,i==null?void 0:i.id]),v=Ce("config"),{register:p,handleSubmit:y,control:f,setValue:S,watch:g,trigger:w,formState:{errors:N,isSubmitting:A,isValid:C},reset:E}=$e.useForm({resolver:uo(eu),defaultValues:{...i,options:i.options||[]}}),k=g(),{fields:I,append:P,remove:T}=$e.useFieldArray({control:f,name:"options"}),{fields:O,append:M,remove:_}=$e.useFieldArray({control:f,name:"options1"}),{fields:B,append:H,remove:D}=$e.useFieldArray({control:f,name:"dataColumns"});x.useEffect(()=>{e||E()},[e,E]);const L=J=>{s(J,i.sectionId),n()},q={headers:{Authorization:`Bearer ${Ce("token")}`}},W=x.useCallback(async()=>{var J,K,$;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){Ae.toast.info("Please provide a valid API URL");return}try{c(!0);const{status:G,data:F}=await en.get(k.apiUrl,q);if(G!==200||!F){Ae.toast.error("Unexpected response from server.");return}const V=F.data||F.record||F.result;if(!Array.isArray(V)){Ae.toast.error("Expected an array in response (data, record, or result).");return}((J=i.type)==null?void 0:J.toLowerCase())==="datagrid"?S("dataColumns",bo(V)):S("options",mo(V))}catch(G){const F=(($=(K=G==null?void 0:G.response)==null?void 0:K.data)==null?void 0:$.message)||(G==null?void 0:G.message)||"Unable to load options";Ae.toast.error(F)}finally{c(!1)}},[i.type,S,k.apiUrl]),Z=["manual","api","sheet"];function X(){m==="api"&&W()}const ie=()=>{var J,K;return a.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[a.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Z==null?void 0:Z.map($=>a.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[a.jsx("input",{type:"radio",name:"optionType",onChange:G=>u(G.target.value),value:$})," ",a.jsxs("span",{children:[$," options"]})]},$))}),m==="api"&&a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[a.jsx(re,{watch:g,label:"Load Options from Api",name:"apiUrl",errors:N,register:p,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),d&&a.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"})]}),a.jsx("button",{onClick:X,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),a.jsx(Ud,{})]}),m==="sheet"&&a.jsx("div",{className:"mb-4",children:a.jsx(Xs,{type:i.type,label:"Load options form sheet (csv, xlsx)",setValue:S,name:"options"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((J=i==null?void 0:i.type)==null?void 0:J.toLowerCase())==="matrix"?"Rows Options":"Parent Options"}),I==null?void 0:I.map(($,G)=>a.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Label":"",name:`options.${G}.label`,register:p,errors:N,element:i,placeholder:"Label",onChange:F=>{const U=F.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");S(`options.${G}.value`,U,{shouldValidate:!0,shouldDirty:!0})}})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Value":"",name:`options.${G}.value`,register:p,errors:N,element:i,placeholder:"Value"})}),a.jsx("button",{disabled:I.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>T(G),children:a.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id))," ",a.jsxs("div",{children:[" ",a.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:Ee.v4()}),children:[a.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),["cascadeselect","matrix"].includes(i.type.toLowerCase())&&a.jsxs(a.Fragment,{children:[a.jsx("hr",{className:"my-5"}),a.jsxs("div",{children:[" ",a.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((K=i==null?void 0:i.type)==null?void 0:K.toLowerCase())==="matrix"?"Columns Options":"Child Options"}),O==null?void 0:O.map(($,G)=>a.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Label":"",name:`options1.${G}.label`,register:p,errors:N,element:i,placeholder:"Label",onChange:F=>{const U=F.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");S(`options1.${G}.value`,U,{shouldValidate:!0,shouldDirty:!0})}})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Value":"",name:`options1.${G}.value`,register:p,errors:N,element:i,placeholder:"Value"})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Key":"",name:`options1.${G}.key`,register:p,errors:N,element:i,placeholder:"Key"})}),a.jsx("button",{disabled:O.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>_(G),children:a.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id)),a.jsxs("div",{children:[" ",a.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:Ee.v4()}),children:[a.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]})},ae=()=>a.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[a.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Z==null?void 0:Z.map(J=>a.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[a.jsx("input",{type:"radio",name:"optionType",onChange:K=>u(K.target.value),value:J,checked:J===m})," ",a.jsxs("span",{children:[J," options"]})]},J))}),m==="api"&&a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[a.jsx(re,{watch:g,label:"Load Columns from Api",name:"apiUrl",errors:N,register:p,className:"!w-full",placeholder:"https://example.com/columns"}),d&&a.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"})]})," ",a.jsx("button",{onClick:X,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),a.jsx(qd,{})]}),m==="sheet"&&a.jsx("div",{className:"mb-4",children:a.jsx(Xs,{type:i.type,label:"Load columns form sheet (csv, xlsx)",setValue:S,name:"dataColumns"})}),a.jsx("div",{className:"grid gap-y-3",children:B==null?void 0:B.map((J,K)=>{var $,G;return a.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:[a.jsxs("div",{className:"flex items-center gap-x-4",children:[a.jsx("div",{className:"min-w-[140px]",children:a.jsx(mn,{label:K===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"},{label:"Select",value:"select"}],register:p,name:`dataColumns.${K}.type`,setValue:S,trigger:w,value:k.dataColumns[K].type})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:K===0?"Display header":"",name:`dataColumns.${K}.headerName`,register:p,onChange:F=>{const U=F.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");S(`dataColumns.${K}.field`,U,{shouldValidate:!0,shouldDirty:!0})},errors:N,element:i,placeholder:"header"})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:K===0?"Field key":"",name:`dataColumns.${K}.field`,register:p,errors:N,element:i,placeholder:"fieldKey",disabled:!0})}),a.jsx("button",{disabled:B.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>D(K),children:a.jsx(te,{icon:"iconamoon:sign-times-fill"})})]}),((G=($=k.dataColumns)==null?void 0:$[K])==null?void 0:G.type)==="select"&&a.jsx("div",{className:"flex items-center gap-x-4",children:a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Options API URL",name:`dataColumns.${K}.optionsUrl`,register:p,errors:N,element:i,placeholder:"https://api.example.com/options"})})})]},J.id)})}),a.jsxs("div",{children:[" ",a.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>H({headerName:"",field:"",editable:!0,id:Ee.v4(),type:"text",validate:!1}),children:[a.jsx(te,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),R=x.useCallback(async()=>{const J=Ce("token"),{status:K,data:$}=await en.get(k.url,{headers:{Authorization:`Bearer ${J}`}});K===200&&S("options",($==null?void 0:$.data)||$)},[S,k.url]);x.useEffect(()=>{i.type==="document"&&k.url&&R()},[k.url,i.type,R]);const j=a.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default",onMouseDown:J=>J.stopPropagation(),onPointerDown:J=>J.stopPropagation(),onDragStart:J=>{J.preventDefault(),J.stopPropagation()},children:a.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:[a.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:a.jsx(te,{icon:"tabler:x",iconClass:"text-xl"})}),a.jsx("div",{className:"w-full pt-4",children:a.jsx(Pd,{tabs:o,setActiveTab:r,activeTab:l,className:"justify-start !text-left",btnClass:" !text-left"})}),a.jsxs("form",{onSubmit:y(L),className:"w-full flex-1 flex flex-col",autoComplete:"off",children:[a.jsxs("div",{className:"flex-1",children:[" ",a.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[l==="basic"&&a.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[co.includes(i.inputType)&&a.jsx(a.Fragment,{children:a.jsx(re,{watch:g,label:"Value",name:"value",register:p,errors:N,element:i})}),!co.includes(i.inputType)&&!ri.includes(i.inputType)&&a.jsxs(a.Fragment,{children:[a.jsx(re,{watch:g,label:"Label",name:"inputLabel",register:p,errors:N,element:i})," ",i.type.toLowerCase()==="cascadeselect"&&a.jsx(re,{watch:g,label:"Child Label",name:"childLabel",register:p,errors:N,element:i})]}),Hd.includes(i.inputType)&&a.jsx(re,{watch:g,label:"Placeholder",name:"placeholder",register:p,errors:N,element:i}),Od.includes(i.inputType)&&a.jsx(re,{watch:g,label:"Prefix",name:"prefix",register:p,errors:N,element:i}),Vd.includes(i.inputType)&&a.jsxs("div",{className:"grid gap-y-4",children:[a.jsx(jd,{}),a.jsx(re,{watch:g,label:"Api Url",name:"url",register:p,errors:N,element:i}),a.jsx(mn,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:p,name:"method",setValue:S,trigger:w,value:g("method")}),a.jsx(mn,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:p,name:"responseType",setValue:S,trigger:w,value:g("responseType")})]}),zd.includes(i.inputType)&&a.jsx($d,{onChange:J=>{S("denominators",J)},value:g("denominators")}),!co.includes(i.inputType)&&!ri.includes(i.inputType)&&a.jsx(re,{watch:g,label:"Short Description",name:"description",register:p,errors:N,element:i}),i.type.toLowerCase()==="date"&&a.jsxs(a.Fragment,{children:[a.jsx(mn,{label:"Date Format",options:_d,register:p,name:"dateFormat",setValue:S,trigger:w,value:g("dateFormat")}),a.jsx(re,{watch:g,label:"Allow Range",name:"canHaveDateRange",register:p,errors:N,element:i,type:"checkbox",value:k.canHaveDateRange}),(k==null?void 0:k.canHaveDateRange)&&a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsx(Zi,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:S,placeholder:"Select min date"}),a.jsx(Zi,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:S,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),a.jsx(re,{watch:g,label:"Allow Year Picker",name:"allowYearPicker",register:p,errors:N,element:i,type:"checkbox",value:k.allowYearPicker})]}),i.type.toLowerCase()==="country"&&a.jsx(re,{watch:g,label:"Allow States",name:"showState",register:p,errors:N,element:i,type:"checkbox",value:k.showState}),i.type.toLowerCase()==="selectfield"&&a.jsx(mn,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:p,name:"selectType",setValue:S,trigger:w,value:g("selectType")}),["multiselect","checkbox"].includes(i.type.toLowerCase())&&a.jsxs(a.Fragment,{children:[a.jsx(re,{watch:g,label:"Minimum Options Checked",name:"minChecked",register:p,errors:N,element:i,type:"number"}),a.jsx("div",{className:"w-[250px]",children:a.jsx(re,{watch:g,label:"Require All Checked",name:"requireAllChecked",register:p,errors:N,element:i,type:"checkbox",value:k.requireAllChecked})})]}),i.type.toLowerCase()==="grid"&&a.jsx(re,{watch:g,label:"Number of columns (max: 4)",name:"columns",register:p,errors:N,element:i,max:4,min:1}),i.type.toLowerCase()==="document"&&a.jsxs("div",{className:"grid gap-y-6",children:[a.jsxs("div",{className:"grid gap-y-1",children:[a.jsx(re,{watch:g,label:"Document Options Url",name:"url",register:p,errors:N,element:i})," ",a.jsx(Yd,{})]}),a.jsxs("div",{className:"grid gap-y-1",children:[a.jsx(re,{watch:g,label:"Document Validation Url",name:"validationUrl",register:p,errors:N,element:i}),a.jsx(Jd,{})]}),a.jsx("div",{className:"grid gap-y-1",children:a.jsx(re,{watch:g,label:"Signature Page Url",name:"signatureLink",register:p,errors:N,element:i})})]}),i.type.toLowerCase()==="datagrid"&&ae(),i.type.toLowerCase()==="file"&&a.jsxs(a.Fragment,{children:[a.jsx(re,{watch:g,label:"Allow Multiple Uploads",name:"isMultiple",register:p,errors:N,element:i,type:"checkbox",value:k.isMultiple}),a.jsx(ro,{element:{options:Wd,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:p,setValue:S,trigger:w,watch:g},placeholder:"Choose file types"})]}),Fd.includes(i.inputType)&&ie(),a.jsxs("div",{children:[a.jsx("div",{className:"w-[150px] mb-4",children:a.jsx(re,{watch:g,label:"Toggle Visibility",name:"isHidden",register:p,errors:N,element:i,type:"checkbox",value:k.isHidden})})," ",k.isHidden&&a.jsx(Xd,{register:p,setValue:S,trigger:w,watch:g,id:i==null?void 0:i.id})]}),i.type.toLowerCase()==="calculatedfield"&&a.jsxs("div",{className:"grid gap-y-2 mb-4",children:[a.jsx("label",{className:"block text-sm font-medium text-[#344054] font-onest",children:"Formula"}),a.jsx(Rd,{value:g("formula")||"",onChange:J=>S("formula",J,{shouldValidate:!0,shouldDirty:!0}),fields:h,placeholder:"Build your formula..."})]}),i.type.toLowerCase()==="polling"&&a.jsxs("div",{className:"grid gap-y-4 mb-4 mt-2",children:[a.jsx(re,{watch:g,label:"Fetch results from external API",name:"fetchExternalResults",register:p,errors:N,element:i,type:"checkbox",value:k.fetchExternalResults}),k.fetchExternalResults&&a.jsx(re,{watch:g,label:"External API URL (returns options results)",name:"externalApiUrl",register:p,errors:N,element:i,placeholder:"https://api.example.com/poll/results"})]})]}),!ri.includes(i.type.toLowerCase())&&l==="validation"&&a.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Required",name:"isRequired",register:p,errors:N,element:i,type:"checkbox",value:k.isRequired})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"requiredMessage",register:p,errors:N,element:i})})]}),Kd.includes(i.inputType)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Min Length",name:"minLength",register:p,errors:N,element:i,type:"number"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"minLengthMessage",register:p,errors:N,element:i})})]}),a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Max Length",name:"maxLength",register:p,errors:N,element:i,type:"number"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"maxLengthMessage",register:p,errors:N,element:i})})]})]}),Gd.includes(i.inputType)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Min Amount",name:"minAmount",register:p,errors:N,element:i,type:"amount"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"minAmountMessage",register:p,errors:N,element:i})})]}),a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Max Amount",name:"maxAmount",register:p,errors:N,element:i,type:"amount"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"maxAmountMessage",register:p,errors:N,element:i})})]})]})]})]})]}),a.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[a.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"}),a.jsx("button",{type:"submit",disabled:!C||A,style:{background:(v==null?void 0:v.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?mr.createPortal(j,document.body):j},ho=x.memo(({state:e,element:n,children:i})=>{var u,b;const[o,s]=x.useState(!1),{removeElement:t,duplicateElement:l,updateElement:r,copyElement:d}=x.useContext(Te),c=x.useMemo(()=>{var h;return(h=n==null?void 0:n.acceptedFiles)==null?void 0:h.map(v=>v.label).join(", ")},[n]),m=x.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return a.jsxs("div",{className:"w-full min-w-0",children:[o&&a.jsx(iu,{isOpen:o,onClose:()=>s(!1),element:n}),a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("span",{children:[" ",n.inputLabel&&a.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",c&&a.jsxs("span",{className:"text-gray-400 text-xs",children:["(",c==null?void 0:c.toLowerCase(),")"]})]})]}),e==="edit"&&a.jsxs("span",{className:"flex items-center gap-x-3",children:[((u=n.type)==null?void 0:u.toLowerCase())!=="spacer"&&((b=n.type)==null?void 0:b.toLowerCase())!=="divider"&&a.jsxs("label",{className:"flex items-center gap-1 text-xs cursor-pointer text-gray-500 mr-2 hover:text-gray-700 select-none",children:[a.jsx("input",{type:"checkbox",checked:n.isRequired||!1,onChange:h=>r({...n,isRequired:h.target.checked},n.sectionId),className:"cursor-pointer"}),a.jsx("span",{className:"mt-0.5",children:"Required"})]}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1 text-gray-600",onClick:()=>{typeof d=="function"&&d(n==null?void 0:n.id,n.sectionId)},title:"Copy to Clipboard",children:a.jsx(te,{icon:"lucide:clipboard-copy",iconClass:"text-base"})}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:()=>s(!0),title:"Edit",children:a.jsx(te,{icon:"circum:edit",iconClass:"text-base"})}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:m,title:"Remove",children:a.jsx(te,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),i,n.description&&a.jsx("small",{className:"block text-gray-400 mt-1 text-xs",children:n.description})]})});ho.displayName="ElementContainer";function ou({element:e,validationData:n}){const{register:i=()=>({}),trigger:o,setValue:s,watch:t,isReadOnly:l}=n||{};let r;return t&&(r=t()[e.id]),a.jsx(re,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:i,trigger:o,setValue:s,value:r,prefix:e.prefix,disabled:l,watch:t})}function su(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 au=({imageUrl:e})=>{const[n,i]=x.useState(!1),o=()=>{i(!0)},s=()=>{i(!1)};return a.jsxs("div",{children:[a.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&&a.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:a.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:t=>t.stopPropagation(),children:[a.jsx("span",{className:"close",onClick:s,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),a.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function tu({element:e,validationData:n}){var A;const{register:i=()=>({}),setValue:o,watch:s}=n||{},[t,l]=x.useState(),[r,d]=x.useState(!1),[c,m]=x.useState(!1),[u,b]=x.useState(""),h=s&&s(e==null?void 0:e.id);x.useEffect(()=>{l(h)},[h]);const[v,p]=x.useState("");x.useEffect(()=>{i(e.id)},[e.id,i]);const{url:y,method:f,responseType:S}=e||{},w={headers:{Authorization:`Bearer ${Ce("token")}`}},N=x.useCallback(async C=>{var E,k,I,P,T,O,M,_,B,H,D;if(!(!y||!f)){d(!0);try{let L;if(f.toLowerCase()==="get"){const z=`${y}?value=${C}`;L=await en.get(z,w)}else if(f.toLowerCase()==="post")L=await en.post(y,{value:C},w);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)||((I=L==null?void 0:L.data)==null?void 0:I.status))===!0?(m(!0),S==="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(((_=(M=L==null?void 0:L.data)==null?void 0:M.data)==null?void 0:_.description)||((B=L==null?void 0:L.data)==null?void 0:B.description)||{})):(console.error("Invalid input:",C),b("Unable to validate input"),m(!1)))}catch(L){console.error("Error validating input:",L),b(((D=(H=L==null?void 0:L.response)==null?void 0:H.data)==null?void 0:D.message)||"Unable to validate input"),m(!1)}finally{d(!1)}}},[f,S,y]);return x.useEffect(()=>{if(t){const C=setTimeout(()=>{N(t)},700);return()=>clearTimeout(C)}},[N,t]),a.jsxs("div",{children:[a.jsxs("div",{className:"relative flex items-center",children:[a.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:me("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}),a.jsxs("span",{className:"absolute right-0",children:[r&&a.jsxs("span",{children:[" ",a.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:[a.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),a.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})]}),c&&!r&&a.jsx("span",{className:"block pr-3 text-lg text-green-600",children:a.jsx(te,{icon:"gg:check-o"})})]})]}),u&&S==="string"&&a.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:u}),S==="object"&&a.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(A=Object.entries(v))==null?void 0:A.map(([C,E])=>a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsxs("span",{className:"font-semibold",children:[C,":"]}),su(E)?a.jsx(au,{imageUrl:E}):a.jsx("span",{children:String(E)})]},C))})]})}function lu({onGetTotal:e,readOnly:n,defaultValue:i,denominators:o}){const[s,t]=x.useState([...i]);function l(c,m){t(u=>{const b=[...u];return b[m]={...b[m],value:c},b})}function r(c,m){return parseFloat(c)*parseFloat(m)||0}const d=x.useMemo(()=>s.reduce((c,m)=>{const u=r(m.key,m.value);return c+u},0),[s]);return x.useEffect(()=>{e&&e(s)},[s]),x.useEffect(()=>{if(o!=null&&o.length){const c=o==null?void 0:o.map((m,u)=>({key:m.value,value:Array.isArray(i)&&i[u]?i[u].value:""}));t(c)}},[i,o]),a.jsx("div",{className:"mt-2",children:a.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[a.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[a.jsx("div",{className:"border-r px-4 py-2",children:a.jsx("span",{className:"",children:"Denomination"})}),a.jsx("div",{className:"border-r px-4 py-2",children:a.jsx("span",{children:"Quantity"})}),a.jsx("div",{className:"px-4 py-2",children:a.jsx("span",{children:"Sub total"})})]}),s==null?void 0:s.map((c,m)=>{var u,b;return a.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[a.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:a.jsx("span",{className:"",children:(u=parseFloat(c.key))==null?void 0:u.toLocaleString()})}),a.jsx("div",{className:"border-r px-4 py-1",children:a.jsx("span",{children:a.jsx(ii,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:h=>l(h,m),disabled:n,allowNegativeValue:!1})})}),a.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:a.jsx("span",{children:(b=r(c.key,c.value))==null?void 0:b.toLocaleString()})})]},m+"index")}),a.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[a.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),a.jsx("div",{className:"px-4 py-3",children:d==null?void 0:d.toLocaleString()})]})]})})}function ru({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,getValues:s}=n||{},t=s&&s(e==null?void 0:e.id)||[];return x.useEffect(()=>{i(e.id)},[e.id,i]),a.jsx("div",{children:a.jsx(lu,{onGetTotal:l=>{o&&o(e.id,l)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:t,readOnly:e==null?void 0:e.isReadOnly})})}function du({element:e}){return a.jsx("div",{className:me("py-6",e==null?void 0:e.customClass)})}function uu({element:e}){return a.jsx("div",{children:a.jsx("hr",{className:me("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function cu({element:e,validationData:n}){const{register:i=()=>({})}=n||{};return a.jsx("div",{children:a.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...i(e==null?void 0:e.id)})})}function mu({element:e,state:n}){return a.jsx(a.Fragment,{children:a.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&a.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function bu({row:e,columns:n,isReadOnly:i,handleCellChange:o,getValidationStatus:s,deleteRow:t}){return a.jsxs("tr",{children:[n.map(l=>{var h;const r=e[l.field],d=l.editable&&!i,{isValidating:c,result:m}=s(e.id,l.field);let u="border-gray-300";l.validate&&((m==null?void 0:m.isValid)===!1?u="border-red-500 bg-red-50":(m==null?void 0:m.isValid)===!0&&(u="border-green-500 bg-green-50"));const b=`w-full py-1 rounded outline-none ${u}`;return a.jsx("td",{className:"px-3 py-1 border-b border-r last:border-r-0",children:d?a.jsxs("div",{className:"relative",children:[l.type==="number"?a.jsx(ii,{value:r,decimalsLimit:6,allowNegativeValue:!1,className:b,onValueChange:v=>o(v,e.id,l.field)}):l.type==="checkbox"?a.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(v=>{const p=v==="yes",y=`radio-${e.id}-${String(l.field)}-${v}`;return a.jsxs("label",{htmlFor:y,className:"flex items-center gap-1 cursor-pointer",children:[a.jsx("input",{id:y,type:"radio",name:`boolean-${e.id}-${String(l.field)}`,checked:r===p,onChange:()=>o(p,e.id,l.field)}),a.jsx("span",{className:"text-sm",children:p?"Yes":"No"})]},v)})}):l.type==="select"?a.jsx(In,{name:String(l.field),options:l.options||[],apiUrl:l.optionsUrl,value:r,onGetValue:(v,p)=>o((p==null?void 0:p.value)||"",e.id,l.field),customClass:"!border-none !p-0"}):a.jsx("input",{type:"text",value:String(r!=null?r:""),onChange:v=>o(v.target.value,e.id,l.field),className:b}),c&&a.jsx("div",{className:"absolute right-1 top-1",children:a.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):l.validate&&m?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("span",{children:[String(r!=null?r:"")," ",m.data&&`[${m.data}]`]}),m.isValid?a.jsx("span",{className:"text-xs text-green-600",children:"✓"}):a.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(h=m.error)!=null?h:"",children:"✗"})]}):l.type==="select"?a.jsx(In,{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"?a.jsx("span",{className:"block py-1 text-gray-700",children:r===!0?"Yes":r===!1?"No":""}):a.jsx("span",{className:"block py-1 text-gray-700",children:String(r!=null?r:"")})},String(l.id))}),!i&&a.jsx("td",{className:"px-3 py-1 text-center border sticky right-0 bg-gray-50 z-10",children:a.jsx("button",{type:"button",onClick:()=>t(e.id),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:a.jsx(te,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const vu=x.memo(bu);function hu({value:e=[],onChange:n,isReadOnly:i=!1,columns:o}){const[s,t]=x.useState(e),l=Ce("config"),r=x.useRef(s);r.current=s,x.useEffect(()=>{t(b=>JSON.stringify(b)!==JSON.stringify(e)?e:b)},[e]);const d=x.useCallback((b,h,v)=>{const p=r.current.map(y=>y.id===h?{...y,[v]:b}:y);t(p),n==null||n(p)},[n]),c=x.useCallback(()=>{const b=Ee.v4(),h=o.reduce((p,y)=>(p[y.field]=y.field==="id"?b:"",p),{}),v=[...r.current,{id:b,...h}];t(v),n==null||n(v)},[o,n]),m=x.useCallback(b=>{const h=r.current.filter(v=>v.id!==b);t(h),n==null||n(h)},[n]),u=x.useCallback(()=>({isValidating:!1,result:void 0}),[]);return a.jsxs("div",{className:"mt-3 rounded",children:[a.jsx("div",{className:"w-full max-w-full overflow-x-auto border rounded-lg",children:a.jsxs("table",{className:"min-w-max w-full text-sm border-collapse table-auto",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"bg-gray-100",children:[o.map((b,h)=>{var v;return a.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border-b whitespace-nowrap",children:[(v=b.headerName)!=null?v:String(b.field),b.validate&&a.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(b.id)}-${h}`)}),!i&&a.jsx("th",{className:"w-10 px-2 py-2 border sticky right-0 bg-gray-100 z-10"})]})}),a.jsx("tbody",{children:s.length>0?s.map(b=>a.jsx(vu,{row:b,columns:o,isReadOnly:i,handleCellChange:d,getValidationStatus:u,deleteRow:m},b.id)):a.jsx("tr",{children:a.jsx("td",{colSpan:o.length+(i?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})}),!i&&a.jsx("div",{className:"flex justify-center mt-2",children:a.jsx("button",{onClick:c,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 fu({element:e,validationData:n}){var h;const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:t}=n||{},l=s&&s(e==null?void 0:e.id)||{},r=Array.isArray(l)?l:(h=l==null?void 0:l.rows)!=null?h:[];x.useEffect(()=>{i(e.id)},[e.id,i]);const d=x.useRef(""),c=x.useRef(e==null?void 0:e.id),m=x.useRef(e==null?void 0:e.dataColumns),u=x.useRef(o);c.current=e==null?void 0:e.id,m.current=e==null?void 0:e.dataColumns,u.current=o;const b=x.useCallback(v=>{var y;const p=JSON.stringify(v);p!==d.current&&(d.current=p,(y=u.current)==null||y.call(u,c.current,{rows:v,columns:m.current}))},[]);return a.jsx(hu,{value:r,onChange:b,columns:e==null?void 0:e.dataColumns,isReadOnly:t})}const na=({className:e="",options:n=[],placeholder:i="Select",errors:o,register:s,setValue:t,name:l,label:r,value:d,trigger:c,isMultiple:m=!1,isFloatingLabel:u=!1,subText:b,labelClass:h="",loading:v,disabled:p})=>{const[y,f]=x.useState(m?[]:null),S=me("custom-select__control",e),g=x.useMemo(()=>n,[n]);return x.useEffect(()=>{const w=n==null?void 0:n.find(N=>{var A;return typeof N.value=="string"&&typeof d=="string"?N.value.toLowerCase()===d.toLowerCase():typeof N.value=="object"&&typeof d=="object"?((A=N.value)==null?void 0:A.id)===(d==null?void 0:d.id):N.value===d});f(w||null)},[d,n]),x.useEffect(()=>{y&&t&&s&&(t(l,y==null?void 0:y.value),s(l),c==null||c(l))},[l,y]),a.jsxs("div",{className:"custom-select",children:[r&&!u&&a.jsx("label",{className:"custom-select__label",children:r}),u&&r&&a.jsx("label",{className:me("custom-select__floating-label",h),children:r}),a.jsx(le.Listbox,{value:y,onChange:f,multiple:m,disabled:p,children:a.jsxs("div",{className:"custom-select__wrapper",children:[a.jsxs(le.Listbox.Button,{className:S,disabled:p,children:[v?a.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):a.jsx("span",{className:"custom-select__value",children:(y==null?void 0:y.label)||a.jsx("span",{className:"custom-select__placeholder",children:i})}),a.jsx("span",{className:"custom-select__icon",children:a.jsx(te,{icon:"lucide:chevron-down"})})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"custom-select__transition",children:a.jsx(le.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:g==null?void 0:g.map((w,N)=>a.jsx(le.Listbox.Option,{value:w,className:({active:A})=>me("custom-select__option",A&&"custom-select__option--active"),children:({selected:A})=>a.jsx("span",{className:me("custom-select__option-label",A&&"custom-select__option--selected"),children:w.label})},N))})})]})}),b&&!o&&a.jsx("p",{className:"custom-select__subtext",children:b}),o&&a.jsx("span",{className:"custom-select__error",children:o.message})]})},pu=({element:e,validationData:n})=>{var p;const{register:i=()=>({}),trigger:o,setValue:s,watch:t,isReadOnly:l}=n||{},r=(p=e==null?void 0:e.id)!=null?p:"cascadeValue",[d,c]=x.useState(""),[m,u]=x.useState(""),b=(y,f)=>{const S=y&&f?`${y}_${f}`:"";s==null||s(r,S),o==null||o(r)},h=(y,f)=>{y==="first"?(c(f),u(""),b(f,"")):(u(f),b(d,f))};x.useEffect(()=>{if(t){const y=t(r);if(y!=null&&y.includes("_")){const[f,S]=y.split("_");c(f),u(S)}}},[t,r]);const v=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:a.jsxs("div",{children:[a.jsx("input",{type:"hidden",...i(r)}),a.jsx("div",{className:"relative",children:a.jsx(na,{setValue:(y,f)=>h("first",f),options:e.options,name:`${r}`,register:i,value:d})}),d&&a.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&a.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),a.jsx(na,{setValue:(y,f)=>h("second",f),options:v,name:`${r}`,register:i,value:m})]})]})},gu=({value:e=0,max:n=5,readOnly:i=!1,onChange:o,size:s=24,className:t="",element:l,validationData:r})=>{var f;const{register:d=()=>({}),trigger:c,setValue:m,watch:u,isReadOnly:b}=r||{},h=(f=u==null?void 0:u(l.id))!=null?f:0,[v,p]=x.useState(null);x.useEffect(()=>{h==null&&(m==null||m(l.id,e))},[]);const y=S=>{if(!i&&!b){const g=S+1;m==null||m(l.id,g),c==null||c(l.id),o==null||o(g)}};return a.jsxs("div",{className:`flex gap-1 ${t}`,children:[a.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(S,g)=>{const w=v!==null?g<=v:g<h;return a.jsx(qs,{icon:w?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${w?"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 yu({element:e,validationData:n}){const{register:i=()=>({})}=n||{},o=(e==null?void 0:e.options)||[],s=(e==null?void 0:e.options1)||[];return a.jsx("div",{className:me("w-full overflow-x-auto",e.customClass),children:a.jsxs("table",{className:"w-full text-left border-collapse min-w-[600px] mb-2",children:[a.jsx("thead",{children:a.jsxs("tr",{children:[a.jsx("th",{className:"p-3 border-b bg-gray-50/50"}),s.map(t=>a.jsx("th",{className:"p-3 font-medium text-center border-b text-xs text-gray-700 w-[12%]",children:t.label},t.id||t.value))]})}),a.jsx("tbody",{children:o.map(t=>a.jsxs("tr",{className:"border-b last:border-0 hover:bg-gray-50/30",children:[a.jsx("td",{className:"p-3 text-gray-700 min-w-[150px] text-sm",children:t.label}),s.map(l=>a.jsx("td",{className:"p-3 text-center align-middle",children:a.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}.${t.value}`)})},l.id||l.value))]},t.id||t.value))})]})})}function ia({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,trigger:s,isReadOnly:t,watch:l}=n||{},r=(l==null?void 0:l(e.id))||"",{country:d,state:c}=x.useMemo(()=>{var v;if(typeof r=="string"&&r.includes(",")){const[p,y]=(v=r.split(","))==null?void 0:v.map(f=>f.trim());return{country:y,state:p}}return{country:r,state:""}},[r]),m=x.useRef(r),u=x.useMemo(()=>{var v,p;return d?((p=(v=li.find(y=>y.name===d))==null?void 0:v.states)==null?void 0:p.map(y=>({label:y.name,value:y.name})))||[]:[]},[d]),b=(v,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)},h=(v,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]),a.jsxs("div",{className:"grid gap-y-6",children:[a.jsx("input",{type:"hidden",...i(e.id)}),a.jsx(In,{options:e.options,onGetValue:b,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),u.length>0&&e.showState&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),a.jsx(In,{options:u,onGetValue:h,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function xu({element:e,validationData:n}){const{register:i=()=>({}),isReadOnly:o}=n||{},{validationUrl:s,documentObj:t,signatureLink:l}=e,r=x.useMemo(()=>Ce("config"),[]),[d,c]=x.useState(!1),[m,u]=x.useState(!1),b=x.useCallback(async()=>{var h,v;if(!(!s||!t))try{u(!0);const y={headers:{Authorization:`Bearer ${Ce("token")}`}},{data:f}=await en.get(`${s}/${t}`,y),S=!!((v=(h=f==null?void 0:f.data)==null?void 0:h.isSigned)!=null?v:f!=null&&f.isSigned);return c(S),S}catch(p){console.error("Failed to check sign status",p)}finally{u(!1)}},[s,t]);return x.useEffect(()=>{let h=null;return!d&&t&&s&&(async()=>{await b()||(h=setInterval(async()=>{await b()&&h&&clearInterval(h)},2e3))})(),()=>{h&&clearInterval(h)}},[b,d,t,s]),a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:me("field-control",e.customClass),...i(e.id),disabled:o}),a.jsx("a",{href:d?"#":l,children:a.jsxs("button",{type:"button",onClick:b,disabled:m||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:me("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:[a.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 fo=[{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 Su({label:e,placeholder:n,classLabel:i,isRequired:o,isOptional:s,name:t,value:l,error:r,disabled:d,readOnly:c,horizontal:m,description:u,validate:b,onChange:h,onError:v}){const[p,y]=x.useState(""),[f,S]=x.useState(null),[g,w]=x.useState(""),N=x.useMemo(()=>{var T;return(T=fo==null?void 0:fo.slice().sort((O,M)=>O.label.localeCompare(M.label)))==null?void 0:T.map(O=>({...O,phone:`+${O.phone}`}))},[]),A=x.useMemo(()=>p?N.filter(T=>`${T.label} ${T.phone}`.toLowerCase().includes(p.toLowerCase())):N,[p,N]),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}`:"",I=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=I(l);S(N.find(O=>O.phone===T.code)||N[0]),w(T.number)}},[l,N]);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(()=>{h==null||h(k()),v==null||v(P||null)},[g,f,P]),a.jsxs("div",{className:`relative formGroup ${P&&!c?"has-error":""} ${m?"flex":""} ${!P&&g.length>0&&!c?"is-valid":""}`,children:[e&&a.jsxs("label",{htmlFor:t,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&&a.jsx("span",{className:"text-red-500",children:"*"}),s&&a.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),a.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[a.jsx(te,{icon:"lucide:phone-call"}),a.jsx(le.Combobox,{value:f,onChange:S,children:a.jsxs("div",{className:"relative",children:[a.jsx(le.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)}),a.jsx(le.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:a.jsx(te,{icon:"lucide:chevron-down"})}),a.jsx(le.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)=>a.jsxs(le.Combobox.Option,{value:T,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[T.phone," - ",T.label]},`${T.code}+ ${O}`))})]})}),a.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[a.jsx("input",{type:"tel",inputMode:"numeric",value:g,disabled:d,readOnly:c,onChange:T=>{const O=T.target.value.replace(/\D/g,"");w(O)},placeholder:n,className:"w-full px-3 outline-none",maxLength:E,minLength:C}),a.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!P&&g.length>0&&!c&&a.jsx("span",{className:"text-green-500",children:a.jsx(te,{icon:"bi:check-lg"})})})]})]}),u&&a.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:u})]})}function wu({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:t,setError:l,clearErrors:r}=n||{};let d;return x.useEffect(()=>{i(e.id)},[e.id,i]),s&&(d=s()[e.id]),a.jsx(Su,{placeholder:e.placeholder,label:"",name:e.id,value:d,readOnly:t,disabled:t,onError:c=>{c?l==null||l(e.id,{type:"manual",message:c}):r==null||r(e.id)},onChange:c=>{c&&(o==null||o(e.id,c))}})}function Nu({element:e,validationData:n}){var c;const{register:i=()=>({}),watch:o}=n||{};let s="";o&&(s=(c=o()[e.id])!=null?c:"");const t=s.trim(),l=/^https?:\/\//i.test(t),r=t?l?t:`https://${t}`:"",d=!l;return a.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&a.jsxs("div",{className:"relative",children:[d&&a.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://"}),a.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:me("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})]}),t?a.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:a.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:t})}):(n==null?void 0:n.isReadOnly)&&a.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}function Au({element:e,validationData:n}){var d;const{watch:i,setValue:o}=n||{},s=(e==null?void 0:e.formula)||"",t=x.useMemo(()=>{const m=(s.match(/\{\{([^{}]+)\}\}/g)||[]).map(h=>h.replace(/[{}]/g,"")),b=(s.match(/@\[.*?\]\((.*?)\)/g)||[]).map(h=>{const v=/@\[.*?\]\((.*?)\)/.exec(h);return v?v[1]:""}).filter(Boolean);return Array.from(new Set([...m,...b]))},[s]),l=i?i(t):[],r=x.useMemo(()=>{if(!s)return"";let c=s,m=!1;if(t.forEach((u,b)=>{const h=l[b],v=Number(h);(isNaN(v)||h===void 0||h===null||h==="")&&(m=!0),c=c.replace(new RegExp(`\\{\\{${u}\\}\\}`,"g"),String(v||0)),c=c.replace(new RegExp(`@\\[.*?\\]\\(${u}\\)`,"g"),String(v||0))}),m)return"";try{const u=c.replace(/[^0-9+\-*/().\s]/g,"");if(!u)return"";const b=new Function(`return ${u}`)();return!isNaN(b)&&b!==null?Number.isInteger(b)?b:Number(b.toFixed(2)):""}catch(u){return"Error"}},[s,t,l]);return x.useEffect(()=>{o&&r!=="Error"&&r!==""&&o(e.id,r,{shouldValidate:!0,shouldDirty:!0})},[r,e.id,o]),a.jsx("div",{children:a.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Calculated result",type:"text",className:me("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 Cu({element:e,validationData:n,state:i}){var h;const{register:o,watch:s,setValue:t}=n||{},[l,r]=x.useState({}),[d,c]=x.useState(0),m=s?s(e.id):null,u=!!(m||i&&i!=="edit");x.useEffect(()=>{if(!e.fetchExternalResults||!e.externalApiUrl)return;const v=async()=>{try{const y=await fetch(e.externalApiUrl);if(!y.ok)return;const f=await y.json();let S={};Array.isArray(f)?f.forEach(w=>{const N=w.value||w.id||w.option,A=w.count||w.votes||w.value||0;N&&(S[N]=Number(A))}):typeof f=="object"&&(S=f),r(S);const g=Object.values(S).reduce((w,N)=>w+Number(N),0);c(g)}catch(y){console.error("Failed to fetch polling results",y)}};v();const p=setInterval(v,1e4);return()=>clearInterval(p)},[e.fetchExternalResults,e.externalApiUrl]),x.useEffect(()=>{e.fetchExternalResults||(m?(r({[m]:1}),c(1)):(r({}),c(0)))},[m,e.fetchExternalResults]);const b=v=>{n!=null&&n.isReadOnly||t&&t(e.id,v,{shouldValidate:!0,shouldDirty:!0})};return a.jsxs("div",{className:"w-full",children:[a.jsx("div",{className:"grid gap-y-3",children:(h=e.options)==null?void 0:h.map(v=>{const p=l[v.value]||0,y=d>0?Math.round(p/d*100):0,f=m===v.value;return a.jsxs("div",{onClick:()=>b(v.value),className:me("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:[u&&a.jsx("div",{className:"absolute top-0 left-0 bottom-0 bg-blue-100/60 transition-all duration-1000 ease-out",style:{width:`${y}%`}}),a.jsxs("div",{className:"relative z-10 flex items-center gap-3",children:[a.jsx("div",{className:me("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&&a.jsx("div",{className:"w-2 h-2 bg-white rounded-full"})}),a.jsx("span",{className:me("font-medium text-sm",f?"text-blue-900":"text-gray-700"),children:v.label||v.name||v.option||v.value||"Unknown Option"})]}),u&&a.jsxs("div",{className:"relative z-10 flex items-center gap-2",children:[a.jsxs("span",{className:"text-sm font-semibold text-gray-700",children:[y,"%"]}),f&&a.jsx(te,{icon:"material-symbols:check-circle",iconClass:"text-blue-500 text-lg"})]}),a.jsx("input",{type:"radio",value:v.value,className:"hidden",...o?o(e.id):{}})]},v.id||v.value)})}),u&&a.jsxs("div",{className:"mt-3 text-xs text-gray-500 text-right flex justify-between items-center",children:[a.jsxs("span",{children:[d," ",d===1?"vote":"votes"," total"]}),e.fetchExternalResults&&e.externalApiUrl&&a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"})," Live"]})]})]})}const oa={textField:Xi,longText:Td,selectField:Ed,multiSelect:ro,numberField:Xi,amountField:ou,date:gr,password:Ad,checkbox:Md,radio:Cd,email:Xi,file:Nd,dataGrid:fu,section:kd,validateInput:tu,tableInput:ru,spacer:du,divider:uu,header:cu,basicText:mu,phoneField:wu,cascadeSelect:pu,rating:gu,matrix:yu,country:ia,bank:ia,document:xu,url:Nu,calculatedField:Au,polling:Cu},sa="edit",ku=(e,n)=>{var o;const i=oa[e.type];return i?a.jsx(ho,{element:e,state:sa,children:a.jsxs("div",{className:"relative w-full",children:[((o=e.type)==null?void 0:o.toLowerCase())!=="grid"&&a.jsx("div",{className:"absolute top-0 left-0 z-20 w-full h-full"}),a.jsx(i,{element:e,state:sa,sectionId:n})]})}):a.jsx("div",{className:"flex items-center justify-center p-4 text-red-500 bg-red-50 border border-red-200 rounded-md",children:a.jsxs("span",{className:"text-sm font-medium",children:["Unsupported element type: ",e.type]})})},di=({col:e,children:n,customClass:i})=>a.jsx("div",{className:me("w-full bg-white min-w-0",i),style:{gridColumn:e},children:n}),Mu=({element:e,sectionId:n,children:i,customClass:o,state:s,draggedElementId:t})=>{const{formData:l,addElement:r,setIsDragging:d,moveElement:c,isDragging:m,removeElement:u}=x.useContext(Te),b=x.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[h,v]=x.useState(null);x.useEffect(()=>{const w=()=>{v(null),d(!1)};return document.addEventListener("dragend",w),()=>document.removeEventListener("dragend",w)},[d]);const p=x.useCallback((w,N)=>{w.preventDefault(),w.stopPropagation(),w.dataTransfer.dropEffect="move",v(N)},[]),y=x.useCallback((w,N)=>{w.preventDefault(),w.stopPropagation(),v(N)},[]),f=x.useCallback((w,N)=>{const A=w.relatedTarget;A&&w.currentTarget.contains(A)||v(C=>C===N?null:C)},[]),S=x.useCallback((w,N)=>{var E;w.preventDefault(),w.stopPropagation(),d(!1),v(null);const A=N+1,C=w.dataTransfer.getData("elementId");if(C){c({draggedId:C,sectionId:n,targetGridId:e.id,targetCol:A});return}try{const k=w.dataTransfer.getData("properties");if(!k)return;const I=JSON.parse(k);if((I==null?void 0:I.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 _;return M.gridId===e.id&&((_=M.gridPosition)==null?void 0:_.col)===A});T&&u(T.id,n);const O={...I,id:Ee.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,c]),g=(w,N,A)=>{var _,B,H;const C=w+1,E=(B=(_=l.find(D=>D.id===n))==null?void 0:_.questionData)==null?void 0:B.find(D=>{var L;return D.gridId===e.id&&((L=D.gridPosition)==null?void 0:L.col)===C}),k=(H=E==null?void 0:E.id)!=null?H:null,I=Array.isArray(i)&&i.find(D=>{var L;return((L=D==null?void 0:D.props)==null?void 0:L.col)===C}),P=m&&h===w,T=!!I,O=m&&!!t,M=T&&k&&A==="edit"?{draggable:!0,onDragStart:D=>{D.stopPropagation(),D.dataTransfer.setData("elementId",k),D.dataTransfer.setData("properties",k),D.dataTransfer.effectAllowed="move",d(!0)},onDragEnd:()=>{v(null),d(!1)}}:{};return a.jsx("div",{className:"min-w-0",children:a.jsxs("div",{id:`grid-cell-${e.id}-${w}`,...M,onDrop:D=>S(D,w),onDragEnter:D=>y(D,w),onDragOver:D=>p(D,w),onDragLeave:D=>f(D,w),className:me("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",N,!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"&&a.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:a.jsx(te,{icon:"ph:dots-six-bold"})}),P&&!T&&a.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:[a.jsx(te,{icon:"ph:plus-bold"}),"Drop here"]}),P&&T&&a.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"}),a.jsx("div",{className:me("w-full select-none min-w-0",P&&"opacity-50 pointer-events-none"),children:I||a.jsx("span",{className:"flex items-center justify-center text-gray-300",children:A==="edit"&&a.jsx(te,{icon:"ph:plus-bold"})})})]})},w)};return a.jsx("div",{className:"relative w-full",children:a.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((w,N)=>g(N,o,s))})})},ui=x.memo(Mu),Eu="edit";function po({index:e,onDrop:n,onDragEnd:i,isDragging:o}){const[s,t]=x.useState(!1),l=s?52:o?28:4;return a.jsx("div",{onDragEnter:r=>{r.preventDefault(),t(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),t(!0)},onDragLeave:()=>t(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),t(!1),n(r,e)},onDragEnd:()=>{t(!1),i()},style:{height:`${l}px`},className:me("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&&a.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[a.jsx(te,{icon:"octicon:plus-16"}),"Drop here"]})})}function Tu({elementData:e,sectionId:n}){const{formData:i,isDragging:o,setIsDragging:s,addElementInPosition:t,moveElement:l}=x.useContext(Te),[r,d]=x.useState(null),c=x.useMemo(()=>{var f;return((f=i.find(S=>S.id===n))==null?void 0:f.questionData)||[]},[i,n]),m=x.useCallback((f,S)=>{f.dataTransfer.setData("elementId",S),f.dataTransfer.setData("properties",S),f.dataTransfer.effectAllowed="move",d(S),s(!0)},[s]),u=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 S=f.dataTransfer.getData("elementId"),g=f.currentTarget.id;if(!S||!g||S===g){u();return}const w=c.find(A=>A.id===S),N=c.findIndex(A=>A.id===g);w!=null&&w.gridId&&N!==-1?l({draggedId:S,sectionId:n,targetIndex:N}):l({draggedId:S,sectionId:n,targetId:g}),d(null),s(!1)},[n,l,s,u,c]),h=x.useCallback((f,S)=>{f.preventDefault(),f.stopPropagation(),s(!1);const g=f.dataTransfer.getData("elementId");if(g){l({draggedId:g,sectionId:n,targetIndex:S}),d(null);return}try{const w=JSON.parse(f.dataTransfer.getData("properties"));if((w==null?void 0:w.type)==="section")return;const N={...w,id:Ee.v4(),sectionId:n};t(N,n,S),d(null)}catch(w){console.error("Drop error:",w)}},[t,n,s,l]),v=x.useCallback((f,S=!1)=>a.jsx("div",{id:f.id,draggable:!0,onDragStart:g=>m(g,f.id),onDragOver:S?void 0:g=>{g.preventDefault(),g.stopPropagation()},onDrop:S?void 0:b,onDragEnd:u,className:me("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:ku(f,n)},f.id),[r,b,n,m,u]),p=x.useMemo(()=>(e==null?void 0:e.reduce((f,S)=>(S.gridId&&(f[S.gridId]=f[S.gridId]||[],f[S.gridId].push(S)),f),{}))||{},[e]);if(!(e!=null&&e.length))return a.jsx("div",{onDragOver:f=>f.preventDefault(),onDrop:f=>h(f,0),onDragEnd:u,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 a.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[a.jsx(po,{index:0,isDragging:o,onDrop:h,onDragEnd:u}),y.map(f=>{const S=c.findIndex(g=>g.id===f.id);if(f.type==="grid"){const g=p[f.id]||[],w=r===f.id,N=!!r&&!w;return a.jsxs("div",{className:"flex flex-col gap-0",children:[a.jsx("div",{id:f.id,draggable:!0,onDragStart:A=>m(A,f.id),onDragOver:A=>{A.preventDefault(),A.stopPropagation()},onDrop:b,onDragEnd:u,className:me("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",w?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":N?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:a.jsx(ho,{element:f,state:"edit",children:a.jsx(ui,{element:f,sectionId:n,state:Eu,draggedElementId:r,children:g==null?void 0:g.map(A=>{var C;return a.jsx(di,{col:(C=A.gridPosition)==null?void 0:C.col,children:v(A,!0)},A.id)})})})}),a.jsx(po,{index:S+1,isDragging:o,onDrop:h,onDragEnd:u})]},f.id)}return a.jsxs("div",{className:"flex flex-col gap-0",children:[v(f),a.jsx(po,{index:S+1,isDragging:o,onDrop:h,onDragEnd:u})]},f.id)})]})}const Pu=x.memo(Tu),Lu=ne.object({title:ne.string(),description:ne.string(),disabled:ne.boolean().default(!1),isHidden:ne.boolean().default(!1)}).required(),go=Ce("config"),Bu=({isOpen:e,onClose:n,section:i})=>{const{updateSection:o}=x.useContext(Te),{register:s,handleSubmit:t,watch:l,formState:{errors:r,isSubmitting:d,isValid:c},reset:m}=$e.useForm({resolver:uo(Lu),defaultValues:i});if(x.useEffect(()=>{e||m()},[e,m]),!e)return null;const u=h=>{o(h,i.id),n()},b=l();return a.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:a.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[a.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 mb-6",children:[a.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Update Section Information"}),a.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:a.jsx(te,{icon:"tabler:x"})})]}),a.jsxs("form",{onSubmit:t(u),className:"w-full",autoComplete:"off",children:[a.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[a.jsx(re,{label:"Title",name:"title",register:s,errors:r,watch:l}),a.jsx(re,{label:"Description",name:"description",register:s,errors:r,watch:l,type:"textarea"}),a.jsx(re,{label:"Disable Section",name:"disabled",register:s,errors:r,watch:l,type:"checkbox",value:b.disabled,description:"Disables all fields in this section"}),a.jsx(re,{label:"Hide Section",name:"isHidden",register:s,errors:r,watch:l,type:"checkbox",value:b.isHidden,description:"Hides this section from the form"})]}),a.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[a.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"}),a.jsx("button",{type:"submit",disabled:!c||d,style:{background:(go==null?void 0:go.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!c||d?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!c||d?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:d?"Saving...":"Save"})]})]})]})})},Iu=({isOpen:e,onClose:n,templates:i,onSelect:o})=>e?a.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:a.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[a.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 border-b",children:[a.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Select a Template"}),a.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:a.jsx(te,{icon:"tabler:x"})})]}),a.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=>a.jsxs("div",{className:"p-4 border rounded-lg cursor-pointer hover:border-blue-500 hover:shadow-md transition-all",onClick:()=>{o(s),n()},children:[a.jsx("h3",{className:"font-semibold text-[#344054] mb-1",children:s.name}),s.description&&a.jsx("p",{className:"text-sm text-[#475467]",children:s.description})]},s.id)):a.jsx("p",{className:"text-sm text-gray-500",children:"No templates available."})})]})}):null,Du=[{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"}]}]}],_u=({section:e,index:n,selectedSection:i,setSelectedSection:o,activeSections:s,toggleSection:t,handleSectionEdit:l,removeSection:r,formDataLength:d,onDragOver:c,setIsDragging:m,isDragging:u,onReorderSection:b})=>{var y,f;const h=x.useRef(null),v=x.useRef((y=e==null?void 0:e.questionData)==null?void 0:y.length),p=x.useRef(u);return x.useEffect(()=>{var S,g;if(((S=e==null?void 0:e.questionData)==null?void 0:S.length)>v.current&&!u&&!p.current){const w=document.getElementById("section-container");w&&requestAnimationFrame(()=>{w.scrollTo({top:w.scrollHeight,behavior:"smooth"})})}v.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,u]),x.useEffect(()=>{p.current=u},[u]),a.jsx("div",{ref:h,onDragOver:S=>{S.dataTransfer.types.includes("sectionid")&&S.preventDefault()},onDrop:S=>{const g=S.dataTransfer.getData("sectionid");g&&(S.preventDefault(),S.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:a.jsxs("div",{className:` border border-gray-200 rounded-lg px-4 transition-colors duration-200
26
+ }`})})]})})}),Jd=()=>a.jsx("blockquote",{className:"p-4 text-gray-700 bg-gray-100 rounded-md",children:a.jsxs("ul",{children:[a.jsxs("li",{className:"text-xs",children:["Method: GET ",a.jsx("br",{}),"URL format:"," ",a.jsx("code",{children:"https://example.com/validation/{documentId}"})]}),a.jsxs("li",{className:"text-xs",children:[a.jsx("span",{className:"block mb-1",children:" Response example format:"}),a.jsx("pre",{className:"p-2 bg-white rounded-md",children:a.jsxs("code",{children:["{ ",a.jsx("br",{}),'  "data": { ',a.jsx("br",{}),'    "status": true, ',a.jsx("br",{}),'    "isSigned": true ',a.jsx("br",{}),"  } ",a.jsx("br",{}),"}"]})})]})]})});function Qs(e){return e.flatMap(n=>{var i;return(i=n==null?void 0:n.questionData)!=null?i:[]})}const vo=["text","number","boolean"],Rs=["equals","not_equals","contains","not_contains"],Zd=["greater","less"];function Xd({register:e,setValue:n,trigger:i,watch:o,id:s}){const{formData:t}=x.useContext(Te),l=o("visibilityDependentFields")||[],r=x.useMemo(()=>{var c;return(c=Qs(t).filter(m=>m.id!==s))==null?void 0:c.map(m=>{const u=l.find(b=>b.id===m.id);return{id:m.id,value:m.id,label:m.inputLabel,sectionId:m.sectionId,fieldType:(u==null?void 0:u.fieldType)||"text",operator:(u==null?void 0:u.operator)||"equals",fieldValue:(u==null?void 0:u.fieldValue)!==void 0?u.fieldValue:""}})},[t,l,s]),d=(c,m,u)=>{const b=l==null?void 0:l.map((h,v)=>v===c?{...h,[m]:u}:h);n("visibilityDependentFields",b)};return a.jsxs("div",{className:"flex flex-col gap-4 w-full",children:[a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsx("label",{className:"text-sm font-semibold text-slate-800",children:"Dependent Fields"}),a.jsx("p",{className:"text-xs text-slate-500 mb-1",children:"Choose which fields this element's visibility should depend on."}),a.jsx(ro,{element:{options:r,id:"visibilityDependentFields",value:o("visibilityDependentFields")},validationData:{register:e,setValue:n,trigger:i,watch:o}})]}),l.length>0&&a.jsxs("div",{className:"flex flex-col gap-3 mt-2",children:[a.jsxs("div",{className:"hidden sm:flex flex-wrap items-center gap-3 px-4 pt-2 pb-1",children:[a.jsx("div",{className:"flex-1 min-w-[120px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Field"})}),a.jsx("div",{className:"w-[110px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Type"})}),a.jsx("div",{className:"w-[140px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Operator"})}),a.jsx("div",{className:"flex-1 min-w-[140px]",children:a.jsx("span",{className:"block text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Value"})})]}),l==null?void 0:l.map((c,m)=>{var v,p,y,f;const u=Qs(t).find(S=>S.id===c.id),b=["selectField","radio","checkbox","multiSelect","cascadeSelect"].includes(u==null?void 0:u.type),h=(u==null?void 0:u.options)||[];return a.jsxs("div",{className:"group relative flex flex-wrap items-center gap-2 p-2 bg-white/70 backdrop-blur-md border border-slate-200/80 rounded-lg shadow-[0_2px_10px_-4px_rgba(0,0,0,0.1)] hover:border-gray-300/60 transition-all duration-300 ease-out",children:[a.jsx("div",{className:"flex-1 min-w-[120px]",children:a.jsx("input",{type:"text",id:c.label,value:c.label,readOnly:!0,disabled:!0,className:"w-full px-3 py-2.5 bg-slate-100/50 border border-slate-200/80 rounded-lg text-sm text-slate-600 font-medium truncate cursor-not-allowed focus:outline-none"})}),a.jsx("div",{className:"w-[110px]",children:a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:c.fieldType,onChange:S=>d(m,"fieldType",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate capitalize",children:c.fieldType}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsx(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[120px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:vo==null?void 0:vo.map(S=>a.jsx(le.Listbox.Option,{value:S,className:({active:g})=>`px-4 py-2 text-sm cursor-pointer capitalize transition-colors ${g?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:S},S))})})]})})}),a.jsx("div",{className:"w-[140px]",children:a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:c.operator,onChange:S=>d(m,"operator",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate capitalize",children:c.operator.replace("_"," ")}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsx(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[150px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:(v=c.fieldType==="number"?[...Rs,...Zd]:Rs)==null?void 0:v.map(S=>a.jsx(le.Listbox.Option,{value:S,className:({active:g})=>`px-4 py-2 text-sm cursor-pointer capitalize transition-colors ${g?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:S.replace("_"," ")},S))})})]})})}),a.jsx("div",{className:"flex-1 min-w-[140px]",children:b&&h.length>0?a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:(p=c.fieldValue)!=null?p:"",onChange:S=>d(m,"fieldValue",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate pr-2",children:((y=h.find(S=>S.value===c.fieldValue))==null?void 0:y.label)||"Select value"}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 flex-shrink-0 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsx(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[160px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:h.map((S,g)=>a.jsx(le.Listbox.Option,{value:S.value,className:({active:w})=>`px-4 py-2 text-sm cursor-pointer transition-colors ${w?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:S.label},g))})})]})}):c.fieldType!=="boolean"?a.jsx("input",{type:c.fieldType,value:c.fieldValue||"",onChange:S=>d(m,"fieldValue",S.target.value),placeholder:"Enter value...",className:"w-full px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 transition-colors shadow-sm placeholder-slate-400"}):a.jsx("div",{className:"relative",children:a.jsxs(le.Listbox,{value:(f=c.fieldValue)!=null?f:"",onChange:S=>d(m,"fieldValue",S),children:[a.jsxs(le.Listbox.Button,{className:"w-full flex items-center justify-between px-3 py-2 bg-white border border-slate-200/80 rounded-lg text-sm text-slate-700 font-medium hover:bg-slate-50 hover:border-slate-300 transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500/20 focus:border-gray-500 shadow-sm",children:[a.jsx("span",{className:"block truncate",children:c.fieldValue===!0?"True":c.fieldValue===!1?"False":"Select value"}),a.jsx(te,{icon:"lucide:chevron-down",iconClass:"w-4 h-4 text-slate-400"})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"transition ease-in duration-100",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:a.jsxs(le.Listbox.Options,{className:"absolute z-[9999] w-[var(--button-width)] min-w-[150px] mt-2 bg-white/95 backdrop-blur-xl border border-slate-200/80 rounded-lg shadow-lg max-h-60 overflow-auto focus:outline-none py-1",anchor:"bottom start",children:[a.jsx(le.Listbox.Option,{value:!0,className:({active:S})=>`px-4 py-2 text-sm cursor-pointer transition-colors ${S?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:"True"}),a.jsx(le.Listbox.Option,{value:!1,className:({active:S})=>`px-4 py-2 text-sm cursor-pointer transition-colors ${S?"bg-gray-50/80 text-gray-700 font-medium":"text-slate-700 hover:bg-slate-50"}`,children:"False"})]})})]})})})]},c.id)})]})]})}function ea(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 t=e.slice(o);return t&&n.push({type:"operator",value:t}),n}function Qd(e){return e.map(n=>n.type==="field"?`@[${n.display}](${n.id})`:n.value).join("")}function Rd({value:e,onChange:n,fields:i,placeholder:o}){const[s,t]=x.useState(()=>ea(e)),[l,r]=x.useState(null),[d,c]=x.useState(!1),[m,u]=x.useState(""),[b,h]=x.useState(null),v=x.useRef(null),p=x.useRef(null),y=x.useRef(new Map);x.useEffect(()=>{const k=ea(e);t(k)},[]);const f=x.useCallback(k=>{n(Qd(k))},[n]),S=(k,I)=>{const P=[...s];P[k]={type:"operator",value:I},t(P),f(P)},g=k=>{const I=s.filter((P,T)=>T!==k);t(I),f(I)},w=k=>{h(k),u(""),c(!0)},N=(k,I)=>{const P=I!==void 0?I:b!=null?b:s.length,T=[...s],O=T.slice(0,P),M=T.slice(P),_=[...O,{type:"field",id:k.id,display:k.display},...M],B=A(_);t(B),f(B),c(!1),h(null)};function A(k){const I=[];if(k.length===0)return[{type:"operator",value:""}];k[0].type==="field"&&I.push({type:"operator",value:""});for(let P=0;P<k.length;P++)I.push(k[P]),k[P].type==="field"&&(P+1>=k.length||k[P+1].type==="field")&&I.push({type:"operator",value:""});return I}const C=i.filter(k=>k.display.toLowerCase().includes(m.toLowerCase())),E=s.every(k=>k.type==="operator"&&k.value.trim()==="");return a.jsxs("div",{className:"relative",ref:p,children:[a.jsxs("div",{className:"field-control flex flex-wrap items-center gap-1 min-h-[44px] cursor-text",style:{padding:"6px 10px"},onClick:()=>{var I;const k=[...s].reverse().findIndex(P=>P.type==="operator");if(k!==-1){const P=s.length-1-k;(I=y.current.get(P))==null||I.focus()}},children:[E&&a.jsx("span",{className:"text-gray-400 text-sm pointer-events-none select-none",children:o||"Build your formula..."}),s.map((k,I)=>k.type==="field"?a.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,a.jsx("button",{type:"button",onMouseDown:P=>{P.preventDefault(),g(I)},className:"text-blue-400 hover:text-blue-700 leading-none ml-0.5","aria-label":`Remove ${k.display}`,children:"×"})]},I):a.jsx("input",{ref:P=>{P?y.current.set(I,P):y.current.delete(I)},type:"text",value:k.value,onChange:P=>S(I,P.target.value),onFocus:()=>r(I),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===I?40:14)}px`,minWidth:"14px",maxWidth:"200px"},placeholder:"","aria-label":`Operator at position ${I}`},I)),a.jsx("button",{type:"button",onMouseDown:k=>{k.preventDefault(),w(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:a.jsx("span",{className:"text-base leading-none",children:"@"})})]}),!E&&a.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:[a.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&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40",onMouseDown:()=>c(!1)}),a.jsxs("div",{ref:v,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:[a.jsx("div",{className:"p-2 border-b border-gray-100",children:a.jsx("input",{autoFocus:!0,type:"text",placeholder:"Search fields...",value:m,onChange:k=>u(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"&&c(!1),k.key==="Enter"&&C.length>0&&N(C[0])}})}),a.jsxs("div",{className:"max-h-48 overflow-y-auto",children:[C.length===0&&a.jsx("p",{className:"text-xs text-gray-400 text-center py-3",children:"No matching fields"}),C.map(k=>a.jsxs("div",{onMouseDown:I=>{I.preventDefault(),N(k)},className:"px-3 py-2 text-sm cursor-pointer flex items-center justify-between hover:bg-blue-50 group",children:[a.jsx("span",{className:"font-medium text-gray-800",children:k.display}),a.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&&a.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:i.map(k=>a.jsxs("button",{type:"button",onMouseDown:I=>{I.preventDefault(),N(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 eu=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().transform((e,n)=>String(n).trim()===""?null:e).typeError("Expecting a number").nullable(),minLength:ne.number().transform((e,n)=>String(n).trim()===""?null:e).typeError("Expecting a number").nullable(),minChecked:ne.number().transform((e,n)=>String(n).trim()===""?null:e).typeError("Expecting a number").nullable(),requireAllChecked:ne.boolean(),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()}),nu=[{title:"Configurations",key:"basic"},{title:"Validations",key:"validation"}],iu=({isOpen:e,onClose:n,element:i})=>{var ee;const o=nu.filter(J=>!ri.includes(i.inputType)||J.key!=="validation"),{updateElement:s,formData:t}=x.useContext(Te),[l,r]=x.useState("basic"),[d,c]=x.useState(!1),[m,u]=x.useState("manual"),b=((ee=t==null?void 0:t.flatMap(J=>(J==null?void 0:J.questionData)||[]))==null?void 0:ee.length)||0,h=x.useMemo(()=>(t==null?void 0:t.flatMap(J=>(J==null?void 0:J.questionData)||[]).filter(J=>{var K;return J.id!==(i==null?void 0:i.id)&&!["spacer","divider","section","grid"].includes((K=J.type)==null?void 0:K.toLowerCase())}).map(J=>({id:J.id,display:J.inputLabel||J.label||"Unnamed"})))||[],[b,i==null?void 0:i.id]),v=Ce("config"),{register:p,handleSubmit:y,control:f,setValue:S,watch:g,trigger:w,formState:{errors:N,isSubmitting:A,isValid:C},reset:E}=$e.useForm({resolver:uo(eu),defaultValues:{...i,options:i.options||[]}}),k=g(),{fields:I,append:P,remove:T}=$e.useFieldArray({control:f,name:"options"}),{fields:O,append:M,remove:_}=$e.useFieldArray({control:f,name:"options1"}),{fields:B,append:H,remove:D}=$e.useFieldArray({control:f,name:"dataColumns"});x.useEffect(()=>{e||E()},[e,E]);const L=J=>{s(J,i.sectionId),n()},q={headers:{Authorization:`Bearer ${Ce("token")}`}},W=x.useCallback(async()=>{var J,K,$;if(!k.apiUrl||!/^https?:\/\//.test(k.apiUrl)){Ae.toast.info("Please provide a valid API URL");return}try{c(!0);const{status:G,data:F}=await en.get(k.apiUrl,q);if(G!==200||!F){Ae.toast.error("Unexpected response from server.");return}const V=F.data||F.record||F.result;if(!Array.isArray(V)){Ae.toast.error("Expected an array in response (data, record, or result).");return}((J=i.type)==null?void 0:J.toLowerCase())==="datagrid"?S("dataColumns",bo(V)):S("options",mo(V))}catch(G){const F=(($=(K=G==null?void 0:G.response)==null?void 0:K.data)==null?void 0:$.message)||(G==null?void 0:G.message)||"Unable to load options";Ae.toast.error(F)}finally{c(!1)}},[i.type,S,k.apiUrl]),Z=["manual","api","sheet"];function X(){m==="api"&&W()}const ie=()=>{var J,K;return a.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[a.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Z==null?void 0:Z.map($=>a.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[a.jsx("input",{type:"radio",name:"optionType",onChange:G=>u(G.target.value),value:$})," ",a.jsxs("span",{children:[$," options"]})]},$))}),m==="api"&&a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[a.jsx(re,{watch:g,label:"Load Options from Api",name:"apiUrl",errors:N,register:p,className:"!w-full",placeholder:"https://example.com/options",isFloating:!0}),d&&a.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"})]}),a.jsx("button",{onClick:X,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),a.jsx(Ud,{})]}),m==="sheet"&&a.jsx("div",{className:"mb-4",children:a.jsx(Xs,{type:i.type,label:"Load options form sheet (csv, xlsx)",setValue:S,name:"options"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((J=i==null?void 0:i.type)==null?void 0:J.toLowerCase())==="matrix"?"Rows Options":"Parent Options"}),I==null?void 0:I.map(($,G)=>a.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Label":"",name:`options.${G}.label`,register:p,errors:N,element:i,placeholder:"Label",onChange:F=>{const U=F.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");S(`options.${G}.value`,U,{shouldValidate:!0,shouldDirty:!0})}})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Value":"",name:`options.${G}.value`,register:p,errors:N,element:i,placeholder:"Value"})}),a.jsx("button",{disabled:I.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>T(G),children:a.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id))," ",a.jsxs("div",{children:[" ",a.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:Ee.v4()}),children:[a.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]}),["cascadeselect","matrix"].includes(i.type.toLowerCase())&&a.jsxs(a.Fragment,{children:[a.jsx("hr",{className:"my-5"}),a.jsxs("div",{children:[" ",a.jsx("h3",{className:"mb-4 text-sm text-gray-500 font-semibold",children:((K=i==null?void 0:i.type)==null?void 0:K.toLowerCase())==="matrix"?"Columns Options":"Child Options"}),O==null?void 0:O.map(($,G)=>a.jsxs("div",{className:"flex items-center mb-1 gap-x-4 last:mb-0",children:[a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Label":"",name:`options1.${G}.label`,register:p,errors:N,element:i,placeholder:"Label",onChange:F=>{const U=F.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");S(`options1.${G}.value`,U,{shouldValidate:!0,shouldDirty:!0})}})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Value":"",name:`options1.${G}.value`,register:p,errors:N,element:i,placeholder:"Value"})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:G===0?"Key":"",name:`options1.${G}.key`,register:p,errors:N,element:i,placeholder:"Key"})}),a.jsx("button",{disabled:O.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>_(G),children:a.jsx(te,{icon:"iconamoon:sign-times-fill"})})]},$.id)),a.jsxs("div",{children:[" ",a.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:Ee.v4()}),children:[a.jsx(te,{icon:"qlementine-icons:plus-16"})," Add Option"]})]})]})]})]})},ae=()=>a.jsxs("div",{className:"flex flex-col justify-start gap-y-1",children:[a.jsx("div",{className:"flex items-center mb-4 gap-x-5",children:Z==null?void 0:Z.map(J=>a.jsxs("label",{className:"items-center text-base capitalize gap-x-3",children:[a.jsx("input",{type:"radio",name:"optionType",onChange:K=>u(K.target.value),value:J,checked:J===m})," ",a.jsxs("span",{children:[J," options"]})]},J))}),m==="api"&&a.jsxs("div",{className:"mb-4",children:[a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsxs("div",{className:"relative flex items-center w-full mb-2",children:[a.jsx(re,{watch:g,label:"Load Columns from Api",name:"apiUrl",errors:N,register:p,className:"!w-full",placeholder:"https://example.com/columns"}),d&&a.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"})]})," ",a.jsx("button",{onClick:X,className:"px-3 py-1 text-xs text-white bg-gray-600 rounded",type:"button",children:"Load"})]}),a.jsx(qd,{})]}),m==="sheet"&&a.jsx("div",{className:"mb-4",children:a.jsx(Xs,{type:i.type,label:"Load columns form sheet (csv, xlsx)",setValue:S,name:"dataColumns"})}),a.jsx("div",{className:"grid gap-y-3",children:B==null?void 0:B.map((J,K)=>{var $,G;return a.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:[a.jsxs("div",{className:"flex items-center gap-x-4",children:[a.jsx("div",{className:"min-w-[140px]",children:a.jsx(mn,{label:K===0?"Type":"",options:[{label:"Text",value:"text"},{label:"Number",value:"number"},{label:"Checkbox",value:"checkbox"},{label:"Select",value:"select"}],register:p,name:`dataColumns.${K}.type`,setValue:S,trigger:w,value:k.dataColumns[K].type})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:K===0?"Display header":"",name:`dataColumns.${K}.headerName`,register:p,onChange:F=>{const U=F.target.value.toLowerCase().trim().replace(/[\s-]+/g,"_").replace(/[^a-z0-9_]/g,"");S(`dataColumns.${K}.field`,U,{shouldValidate:!0,shouldDirty:!0})},errors:N,element:i,placeholder:"header"})}),a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:K===0?"Field key":"",name:`dataColumns.${K}.field`,register:p,errors:N,element:i,placeholder:"fieldKey",disabled:!0})}),a.jsx("button",{disabled:B.length===1,type:"button",className:"outline-none hover:opacity-80 disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>D(K),children:a.jsx(te,{icon:"iconamoon:sign-times-fill"})})]}),((G=($=k.dataColumns)==null?void 0:$[K])==null?void 0:G.type)==="select"&&a.jsx("div",{className:"flex items-center gap-x-4",children:a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Options API URL",name:`dataColumns.${K}.optionsUrl`,register:p,errors:N,element:i,placeholder:"https://api.example.com/options"})})})]},J.id)})}),a.jsxs("div",{children:[" ",a.jsxs("button",{type:"button",className:"flex items-center mt-2 text-sm font-medium text-gray-700 gap-x-1",onClick:()=>H({headerName:"",field:"",editable:!0,id:Ee.v4(),type:"text",validate:!1}),children:[a.jsx(te,{icon:"qlementine-icons:plus-16"})," Add column"]})]})]}),R=x.useCallback(async()=>{const J=Ce("token"),{status:K,data:$}=await en.get(k.url,{headers:{Authorization:`Bearer ${J}`}});K===200&&S("options",($==null?void 0:$.data)||$)},[S,k.url]);x.useEffect(()=>{i.type==="document"&&k.url&&R()},[k.url,i.type,R]);const j=a.jsx("div",{className:"fixed inset-0 bg-gray-800/40 backdrop-blur-sm flex items-center justify-end z-[999] cursor-default",onMouseDown:J=>J.stopPropagation(),onPointerDown:J=>J.stopPropagation(),onDragStart:J=>{J.preventDefault(),J.stopPropagation()},children:a.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:[a.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:a.jsx(te,{icon:"tabler:x",iconClass:"text-xl"})}),a.jsx("div",{className:"w-full pt-4",children:a.jsx(Pd,{tabs:o,setActiveTab:r,activeTab:l,className:"justify-start !text-left",btnClass:" !text-left"})}),a.jsxs("form",{onSubmit:y(L),className:"w-full flex-1 flex flex-col",autoComplete:"off",children:[a.jsxs("div",{className:"flex-1",children:[" ",a.jsxs("div",{className:" max-h-[70vh] overflow-y-auto flex-1",children:[l==="basic"&&a.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[co.includes(i.inputType)&&a.jsx(a.Fragment,{children:a.jsx(re,{watch:g,label:"Value",name:"value",register:p,errors:N,element:i})}),!co.includes(i.inputType)&&!ri.includes(i.inputType)&&a.jsxs(a.Fragment,{children:[a.jsx(re,{watch:g,label:"Label",name:"inputLabel",register:p,errors:N,element:i})," ",i.type.toLowerCase()==="cascadeselect"&&a.jsx(re,{watch:g,label:"Child Label",name:"childLabel",register:p,errors:N,element:i})]}),Hd.includes(i.inputType)&&a.jsx(re,{watch:g,label:"Placeholder",name:"placeholder",register:p,errors:N,element:i}),Od.includes(i.inputType)&&a.jsx(re,{watch:g,label:"Prefix",name:"prefix",register:p,errors:N,element:i}),Vd.includes(i.inputType)&&a.jsxs("div",{className:"grid gap-y-4",children:[a.jsx(jd,{}),a.jsx(re,{watch:g,label:"Api Url",name:"url",register:p,errors:N,element:i}),a.jsx(mn,{label:"Api Method",options:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],register:p,name:"method",setValue:S,trigger:w,value:g("method")}),a.jsx(mn,{label:"Api Response type",options:[{label:"String",value:"string"},{label:"Object",value:"object"}],register:p,name:"responseType",setValue:S,trigger:w,value:g("responseType")})]}),zd.includes(i.inputType)&&a.jsx($d,{onChange:J=>{S("denominators",J)},value:g("denominators")}),!co.includes(i.inputType)&&!ri.includes(i.inputType)&&a.jsx(re,{watch:g,label:"Short Description",name:"description",register:p,errors:N,element:i}),i.type.toLowerCase()==="date"&&a.jsxs(a.Fragment,{children:[a.jsx(mn,{label:"Date Format",options:_d,register:p,name:"dateFormat",setValue:S,trigger:w,value:g("dateFormat")}),a.jsx(re,{watch:g,label:"Allow Range",name:"canHaveDateRange",register:p,errors:N,element:i,type:"checkbox",value:k.canHaveDateRange}),(k==null?void 0:k.canHaveDateRange)&&a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsx(Zi,{name:"minDate",value:k==null?void 0:k.minDate,onGetValue:S,placeholder:"Select min date"}),a.jsx(Zi,{name:"maxDate",value:k==null?void 0:k.minDate,onGetValue:S,placeholder:"Select max date",minDate:k==null?void 0:k.minDate})]}),a.jsx(re,{watch:g,label:"Allow Year Picker",name:"allowYearPicker",register:p,errors:N,element:i,type:"checkbox",value:k.allowYearPicker})]}),i.type.toLowerCase()==="country"&&a.jsx(re,{watch:g,label:"Allow States",name:"showState",register:p,errors:N,element:i,type:"checkbox",value:k.showState}),i.type.toLowerCase()==="selectfield"&&a.jsx(mn,{label:"Select Type",options:[{label:"List",value:"list"},{label:"Combobox",value:"Combobox"}],register:p,name:"selectType",setValue:S,trigger:w,value:g("selectType")}),["multiselect","checkbox"].includes(i.type.toLowerCase())&&a.jsxs(a.Fragment,{children:[a.jsx(re,{watch:g,label:"Minimum Options Checked",name:"minChecked",register:p,errors:N,element:i,type:"number"}),a.jsx("div",{className:"w-[250px]",children:a.jsx(re,{watch:g,label:"Require All Checked",name:"requireAllChecked",register:p,errors:N,element:i,type:"checkbox",value:k.requireAllChecked})})]}),i.type.toLowerCase()==="grid"&&a.jsx(re,{watch:g,label:"Number of columns (max: 4)",name:"columns",register:p,errors:N,element:i,max:4,min:1}),i.type.toLowerCase()==="document"&&a.jsxs("div",{className:"grid gap-y-6",children:[a.jsxs("div",{className:"grid gap-y-1",children:[a.jsx(re,{watch:g,label:"Document Options Url",name:"url",register:p,errors:N,element:i})," ",a.jsx(Yd,{})]}),a.jsxs("div",{className:"grid gap-y-1",children:[a.jsx(re,{watch:g,label:"Document Validation Url",name:"validationUrl",register:p,errors:N,element:i}),a.jsx(Jd,{})]}),a.jsx("div",{className:"grid gap-y-1",children:a.jsx(re,{watch:g,label:"Signature Page Url",name:"signatureLink",register:p,errors:N,element:i})})]}),i.type.toLowerCase()==="datagrid"&&ae(),i.type.toLowerCase()==="file"&&a.jsxs(a.Fragment,{children:[a.jsx(re,{watch:g,label:"Allow Multiple Uploads",name:"isMultiple",register:p,errors:N,element:i,type:"checkbox",value:k.isMultiple}),a.jsx(ro,{element:{options:Wd,id:"acceptedFiles",value:k==null?void 0:k.acceptedFiles},validationData:{register:p,setValue:S,trigger:w,watch:g},placeholder:"Choose file types"})]}),Fd.includes(i.inputType)&&ie(),a.jsxs("div",{children:[a.jsx("div",{className:"w-[150px] mb-4",children:a.jsx(re,{watch:g,label:"Toggle Visibility",name:"isHidden",register:p,errors:N,element:i,type:"checkbox",value:k.isHidden})})," ",k.isHidden&&a.jsx(Xd,{register:p,setValue:S,trigger:w,watch:g,id:i==null?void 0:i.id})]}),i.type.toLowerCase()==="calculatedfield"&&a.jsxs("div",{className:"grid gap-y-2 mb-4",children:[a.jsx("label",{className:"block text-sm font-medium text-[#344054] font-onest",children:"Formula"}),a.jsx(Rd,{value:g("formula")||"",onChange:J=>S("formula",J,{shouldValidate:!0,shouldDirty:!0}),fields:h,placeholder:"Build your formula..."})]}),i.type.toLowerCase()==="polling"&&a.jsxs("div",{className:"grid gap-y-4 mb-4 mt-2",children:[a.jsx(re,{watch:g,label:"Fetch results from external API",name:"fetchExternalResults",register:p,errors:N,element:i,type:"checkbox",value:k.fetchExternalResults}),k.fetchExternalResults&&a.jsx(re,{watch:g,label:"External API URL (returns options results)",name:"externalApiUrl",register:p,errors:N,element:i,placeholder:"https://api.example.com/poll/results"})]})]}),!ri.includes(i.type.toLowerCase())&&l==="validation"&&a.jsxs("div",{className:"z-10 flex flex-col w-full gap-5 px-6",children:[a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Required",name:"isRequired",register:p,errors:N,element:i,type:"checkbox",value:k.isRequired})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"requiredMessage",register:p,errors:N,element:i})})]}),Kd.includes(i.inputType)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Min Length",name:"minLength",register:p,errors:N,element:i,type:"number"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"minLengthMessage",register:p,errors:N,element:i})})]}),a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Max Length",name:"maxLength",register:p,errors:N,element:i,type:"number"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"maxLengthMessage",register:p,errors:N,element:i})})]})]}),Gd.includes(i.inputType)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Min Amount",name:"minAmount",register:p,errors:N,element:i,type:"amount"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"minAmountMessage",register:p,errors:N,element:i})})]}),a.jsxs("div",{className:"flex items-center gap-x-6",children:[a.jsx("div",{className:"w-[150px]",children:a.jsx(re,{watch:g,label:"Max Amount",name:"maxAmount",register:p,errors:N,element:i,type:"amount"})})," ",a.jsx("div",{className:"flex-1",children:a.jsx(re,{watch:g,label:"Error message text",name:"maxAmountMessage",register:p,errors:N,element:i})})]})]})]})]})]}),a.jsxs("div",{className:"sticky flex w-full gap-3 px-6 pt-8 pb-10 mt-10 border-t",children:[a.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"}),a.jsx("button",{type:"submit",disabled:!C||A,style:{background:(v==null?void 0:v.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?mr.createPortal(j,document.body):j},ho=x.memo(({state:e,element:n,children:i})=>{var u,b;const[o,s]=x.useState(!1),{removeElement:t,duplicateElement:l,updateElement:r,copyElement:d}=x.useContext(Te),c=x.useMemo(()=>{var h;return(h=n==null?void 0:n.acceptedFiles)==null?void 0:h.map(v=>v.label).join(", ")},[n]),m=x.useCallback(()=>{t(n.id,n.sectionId)},[n.id,n.sectionId,t]);return a.jsxs("div",{className:"w-full min-w-0",children:[o&&a.jsx(iu,{isOpen:o,onClose:()=>s(!1),element:n}),a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("span",{children:[" ",n.inputLabel&&a.jsxs("label",{className:"text-sm font-medium input_label",children:[n.inputLabel," ",c&&a.jsxs("span",{className:"text-gray-400 text-xs",children:["(",c==null?void 0:c.toLowerCase(),")"]})]})]}),e==="edit"&&a.jsxs("span",{className:"flex items-center gap-x-3",children:[((u=n.type)==null?void 0:u.toLowerCase())!=="spacer"&&((b=n.type)==null?void 0:b.toLowerCase())!=="divider"&&a.jsxs("label",{className:"flex items-center gap-1 text-xs cursor-pointer text-gray-500 mr-2 hover:text-gray-700 select-none",children:[a.jsx("input",{type:"checkbox",checked:n.isRequired||!1,onChange:h=>r({...n,isRequired:h.target.checked},n.sectionId),className:"cursor-pointer"}),a.jsx("span",{className:"mt-0.5",children:"Required"})]}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1 text-gray-600",onClick:()=>{typeof l=="function"&&l(n==null?void 0:n.id,n.sectionId)},title:"Duplicate",children:a.jsx(te,{icon:"solar:copy-outline",iconClass:"text-base"})}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 py-1 text-gray-600",onClick:()=>{typeof d=="function"&&d(n==null?void 0:n.id,n.sectionId)},title:"Copy to Clipboard",children:a.jsx(te,{icon:"lucide:clipboard-copy",iconClass:"text-base"})}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:()=>s(!0),title:"Edit",children:a.jsx(te,{icon:"circum:edit",iconClass:"text-base"})}),a.jsx("button",{type:"button",className:"text-sm outline-none hover:opacity-80 text-gray-600 py-1",onClick:m,title:"Remove",children:a.jsx(te,{icon:"iconamoon:trash",iconClass:"text-base"})})]})]}),i,n.description&&a.jsx("small",{className:"block text-gray-400 mt-1 text-xs",children:n.description})]})});ho.displayName="ElementContainer";function ou({element:e,validationData:n}){const{register:i=()=>({}),trigger:o,setValue:s,watch:t,isReadOnly:l}=n||{};let r;return t&&(r=t()[e.id]),a.jsx(re,{placeholder:e.placeholder,type:e.inputType,label:"",name:e.id,register:i,trigger:o,setValue:s,value:r,prefix:e.prefix,disabled:l,watch:t})}function su(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 au=({imageUrl:e})=>{const[n,i]=x.useState(!1),o=()=>{i(!0)},s=()=>{i(!1)};return a.jsxs("div",{children:[a.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&&a.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:a.jsxs("div",{className:"modal-content",style:{position:"relative",backgroundColor:"white",padding:"20px",borderRadius:"8px",width:"90vw"},onClick:t=>t.stopPropagation(),children:[a.jsx("span",{className:"close",onClick:s,style:{position:"absolute",top:"10px",right:"10px",fontSize:"24px",cursor:"pointer"},children:"×"}),a.jsx("img",{src:e||"/place.png",alt:"Full Image",style:{maxWidth:"90%",maxHeight:"90vh",objectFit:"contain"}})]})})]})};function tu({element:e,validationData:n}){var A;const{register:i=()=>({}),setValue:o,watch:s}=n||{},[t,l]=x.useState(),[r,d]=x.useState(!1),[c,m]=x.useState(!1),[u,b]=x.useState(""),h=s&&s(e==null?void 0:e.id);x.useEffect(()=>{l(h)},[h]);const[v,p]=x.useState("");x.useEffect(()=>{i(e.id)},[e.id,i]);const{url:y,method:f,responseType:S}=e||{},w={headers:{Authorization:`Bearer ${Ce("token")}`}},N=x.useCallback(async C=>{var E,k,I,P,T,O,M,_,B,H,D;if(!(!y||!f)){d(!0);try{let L;if(f.toLowerCase()==="get"){const z=`${y}?value=${C}`;L=await en.get(z,w)}else if(f.toLowerCase()==="post")L=await en.post(y,{value:C},w);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)||((I=L==null?void 0:L.data)==null?void 0:I.status))===!0?(m(!0),S==="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(((_=(M=L==null?void 0:L.data)==null?void 0:M.data)==null?void 0:_.description)||((B=L==null?void 0:L.data)==null?void 0:B.description)||{})):(console.error("Invalid input:",C),b("Unable to validate input"),m(!1)))}catch(L){console.error("Error validating input:",L),b(((D=(H=L==null?void 0:L.response)==null?void 0:H.data)==null?void 0:D.message)||"Unable to validate input"),m(!1)}finally{d(!1)}}},[f,S,y]);return x.useEffect(()=>{if(t){const C=setTimeout(()=>{N(t)},700);return()=>clearTimeout(C)}},[N,t]),a.jsxs("div",{children:[a.jsxs("div",{className:"relative flex items-center",children:[a.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"",type:(e==null?void 0:e.inputType)||"text",className:me("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}),a.jsxs("span",{className:"absolute right-0",children:[r&&a.jsxs("span",{children:[" ",a.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:[a.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),a.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})]}),c&&!r&&a.jsx("span",{className:"block pr-3 text-lg text-green-600",children:a.jsx(te,{icon:"gg:check-o"})})]})]}),u&&S==="string"&&a.jsx("span",{className:`${c?"text-green-600":"text-red-600"} text-sm`,children:u}),S==="object"&&a.jsx("div",{className:"grid grid-cols-2 gap-6 mt-2 text-sm text-gray-600",children:(A=Object.entries(v))==null?void 0:A.map(([C,E])=>a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsxs("span",{className:"font-semibold",children:[C,":"]}),su(E)?a.jsx(au,{imageUrl:E}):a.jsx("span",{children:String(E)})]},C))})]})}function lu({onGetTotal:e,readOnly:n,defaultValue:i,denominators:o}){const[s,t]=x.useState([...i]);function l(c,m){t(u=>{const b=[...u];return b[m]={...b[m],value:c},b})}function r(c,m){return parseFloat(c)*parseFloat(m)||0}const d=x.useMemo(()=>s.reduce((c,m)=>{const u=r(m.key,m.value);return c+u},0),[s]);return x.useEffect(()=>{e&&e(s)},[s]),x.useEffect(()=>{if(o!=null&&o.length){const c=o==null?void 0:o.map((m,u)=>({key:m.value,value:Array.isArray(i)&&i[u]?i[u].value:""}));t(c)}},[i,o]),a.jsx("div",{className:"mt-2",children:a.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden text-gray-700",children:[a.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold border-b border-gray-100 bg-gray-50",children:[a.jsx("div",{className:"border-r px-4 py-2",children:a.jsx("span",{className:"",children:"Denomination"})}),a.jsx("div",{className:"border-r px-4 py-2",children:a.jsx("span",{children:"Quantity"})}),a.jsx("div",{className:"px-4 py-2",children:a.jsx("span",{children:"Sub total"})})]}),s==null?void 0:s.map((c,m)=>{var u,b;return a.jsxs("div",{className:"grid grid-cols-3 text-sm border-b border-gray-100",children:[a.jsx("div",{className:"border-r px-4 py-2 flex items-center",children:a.jsx("span",{className:"",children:(u=parseFloat(c.key))==null?void 0:u.toLocaleString()})}),a.jsx("div",{className:"border-r px-4 py-1",children:a.jsx("span",{children:a.jsx(ii,{id:"input-example",className:"border border-gray-100 rounded w-full px-3 py-1 outline-none",decimalsLimit:6,value:c.value,onValueChange:h=>l(h,m),disabled:n,allowNegativeValue:!1})})}),a.jsx("div",{className:"px-4 py-2 flex justify-between items-center",children:a.jsx("span",{children:(b=r(c.key,c.value))==null?void 0:b.toLocaleString()})})]},m+"index")}),a.jsxs("div",{className:"grid grid-cols-3 text-sm font-bold bg-gray-50",children:[a.jsx("div",{className:"border-r px-4 py-3 col-span-2 text-right",children:"Total"}),a.jsx("div",{className:"px-4 py-3",children:d==null?void 0:d.toLocaleString()})]})]})})}function ru({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,getValues:s}=n||{},t=s&&s(e==null?void 0:e.id)||[];return x.useEffect(()=>{i(e.id)},[e.id,i]),a.jsx("div",{children:a.jsx(lu,{onGetTotal:l=>{o&&o(e.id,l)},denominators:(e==null?void 0:e.denominators)||[],defaultValue:t,readOnly:e==null?void 0:e.isReadOnly})})}function du({element:e}){return a.jsx("div",{className:me("py-6",e==null?void 0:e.customClass)})}function uu({element:e}){return a.jsx("div",{children:a.jsx("hr",{className:me("border-gray-200 my-4",e==null?void 0:e.customClass)})})}function cu({element:e,validationData:n}){const{register:i=()=>({})}=n||{};return a.jsx("div",{children:a.jsx("input",{placeholder:"Enter text",type:"text",className:"field-control",...i(e==null?void 0:e.id)})})}function mu({element:e,state:n}){return a.jsx(a.Fragment,{children:a.jsx("div",{className:e==null?void 0:e.customClass,children:(e==null?void 0:e.value)||n==="edit"&&a.jsx("span",{className:"text-gray-400",children:"Provide text"})})})}function bu({row:e,columns:n,isReadOnly:i,handleCellChange:o,getValidationStatus:s,deleteRow:t}){return a.jsxs("tr",{children:[n.map(l=>{var h;const r=e[l.field],d=l.editable&&!i,{isValidating:c,result:m}=s(e.id,l.field);let u="border-gray-300";l.validate&&((m==null?void 0:m.isValid)===!1?u="border-red-500 bg-red-50":(m==null?void 0:m.isValid)===!0&&(u="border-green-500 bg-green-50"));const b=`w-full py-1 rounded outline-none ${u}`;return a.jsx("td",{className:"px-3 py-1 border-b border-r last:border-r-0",children:d?a.jsxs("div",{className:"relative",children:[l.type==="number"?a.jsx(ii,{value:r,decimalsLimit:6,allowNegativeValue:!1,className:b,onValueChange:v=>o(v,e.id,l.field)}):l.type==="checkbox"?a.jsx("div",{className:"flex items-center gap-x-4",children:["yes","no"].map(v=>{const p=v==="yes",y=`radio-${e.id}-${String(l.field)}-${v}`;return a.jsxs("label",{htmlFor:y,className:"flex items-center gap-1 cursor-pointer",children:[a.jsx("input",{id:y,type:"radio",name:`boolean-${e.id}-${String(l.field)}`,checked:r===p,onChange:()=>o(p,e.id,l.field)}),a.jsx("span",{className:"text-sm",children:p?"Yes":"No"})]},v)})}):l.type==="select"?a.jsx(In,{name:String(l.field),options:l.options||[],apiUrl:l.optionsUrl,value:r,onGetValue:(v,p)=>o((p==null?void 0:p.value)||"",e.id,l.field),customClass:"!border-none !p-0"}):a.jsx("input",{type:"text",value:String(r!=null?r:""),onChange:v=>o(v.target.value,e.id,l.field),className:b}),c&&a.jsx("div",{className:"absolute right-1 top-1",children:a.jsx("div",{className:"w-4 h-4 border-2 border-blue-500 rounded-full border-t-transparent animate-spin"})})]}):l.validate&&m?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("span",{children:[String(r!=null?r:"")," ",m.data&&`[${m.data}]`]}),m.isValid?a.jsx("span",{className:"text-xs text-green-600",children:"✓"}):a.jsx("span",{className:"text-xs text-red-600 cursor-help",title:(h=m.error)!=null?h:"",children:"✗"})]}):l.type==="select"?a.jsx(In,{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"?a.jsx("span",{className:"block py-1 text-gray-700",children:r===!0?"Yes":r===!1?"No":""}):a.jsx("span",{className:"block py-1 text-gray-700",children:String(r!=null?r:"")})},String(l.id))}),!i&&a.jsx("td",{className:"px-3 py-1 text-center border sticky right-0 bg-gray-50 z-10",children:a.jsx("button",{type:"button",onClick:()=>t(e.id),className:"text-red-500 hover:text-red-700","aria-label":"Delete row",children:a.jsx(te,{icon:"lets-icons:trash-duotone",iconClass:"text-xl"})})})]})}const vu=x.memo(bu);function hu({value:e=[],onChange:n,isReadOnly:i=!1,columns:o}){const[s,t]=x.useState(e),l=Ce("config"),r=x.useRef(s);r.current=s,x.useEffect(()=>{t(b=>JSON.stringify(b)!==JSON.stringify(e)?e:b)},[e]);const d=x.useCallback((b,h,v)=>{const p=r.current.map(y=>y.id===h?{...y,[v]:b}:y);t(p),n==null||n(p)},[n]),c=x.useCallback(()=>{const b=Ee.v4(),h=o.reduce((p,y)=>(p[y.field]=y.field==="id"?b:"",p),{}),v=[...r.current,{id:b,...h}];t(v),n==null||n(v)},[o,n]),m=x.useCallback(b=>{const h=r.current.filter(v=>v.id!==b);t(h),n==null||n(h)},[n]),u=x.useCallback(()=>({isValidating:!1,result:void 0}),[]);return a.jsxs("div",{className:"mt-3 rounded",children:[a.jsx("div",{className:"w-full max-w-full overflow-x-auto border rounded-lg",children:a.jsxs("table",{className:"min-w-max w-full text-sm border-collapse table-auto",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"bg-gray-100",children:[o.map((b,h)=>{var v;return a.jsxs("th",{className:"px-3 py-2 text-xs font-semibold text-left text-gray-600 border-b whitespace-nowrap",children:[(v=b.headerName)!=null?v:String(b.field),b.validate&&a.jsx("span",{className:"ml-1 text-blue-600",children:"*"})]},`${String(b.id)}-${h}`)}),!i&&a.jsx("th",{className:"w-10 px-2 py-2 border sticky right-0 bg-gray-100 z-10"})]})}),a.jsx("tbody",{children:s.length>0?s.map(b=>a.jsx(vu,{row:b,columns:o,isReadOnly:i,handleCellChange:d,getValidationStatus:u,deleteRow:m},b.id)):a.jsx("tr",{children:a.jsx("td",{colSpan:o.length+(i?0:1),className:"p-2 text-xs text-center text-gray-400",children:"No data available"})})})]})}),!i&&a.jsx("div",{className:"flex justify-center mt-2",children:a.jsx("button",{onClick:c,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 fu({element:e,validationData:n}){var h;const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:t}=n||{},l=s&&s(e==null?void 0:e.id)||{},r=Array.isArray(l)?l:(h=l==null?void 0:l.rows)!=null?h:[];x.useEffect(()=>{i(e.id)},[e.id,i]);const d=x.useRef(""),c=x.useRef(e==null?void 0:e.id),m=x.useRef(e==null?void 0:e.dataColumns),u=x.useRef(o);c.current=e==null?void 0:e.id,m.current=e==null?void 0:e.dataColumns,u.current=o;const b=x.useCallback(v=>{var y;const p=JSON.stringify(v);p!==d.current&&(d.current=p,(y=u.current)==null||y.call(u,c.current,{rows:v,columns:m.current}))},[]);return a.jsx(hu,{value:r,onChange:b,columns:e==null?void 0:e.dataColumns,isReadOnly:t})}const na=({className:e="",options:n=[],placeholder:i="Select",errors:o,register:s,setValue:t,name:l,label:r,value:d,trigger:c,isMultiple:m=!1,isFloatingLabel:u=!1,subText:b,labelClass:h="",loading:v,disabled:p})=>{const[y,f]=x.useState(m?[]:null),S=me("custom-select__control",e),g=x.useMemo(()=>n,[n]);return x.useEffect(()=>{const w=n==null?void 0:n.find(N=>{var A;return typeof N.value=="string"&&typeof d=="string"?N.value.toLowerCase()===d.toLowerCase():typeof N.value=="object"&&typeof d=="object"?((A=N.value)==null?void 0:A.id)===(d==null?void 0:d.id):N.value===d});f(w||null)},[d,n]),x.useEffect(()=>{y&&t&&s&&(t(l,y==null?void 0:y.value),s(l),c==null||c(l))},[l,y]),a.jsxs("div",{className:"custom-select",children:[r&&!u&&a.jsx("label",{className:"custom-select__label",children:r}),u&&r&&a.jsx("label",{className:me("custom-select__floating-label",h),children:r}),a.jsx(le.Listbox,{value:y,onChange:f,multiple:m,disabled:p,children:a.jsxs("div",{className:"custom-select__wrapper",children:[a.jsxs(le.Listbox.Button,{className:S,disabled:p,children:[v?a.jsx("span",{className:"custom-select__loading",children:"Fetching data..."}):a.jsx("span",{className:"custom-select__value",children:(y==null?void 0:y.label)||a.jsx("span",{className:"custom-select__placeholder",children:i})}),a.jsx("span",{className:"custom-select__icon",children:a.jsx(te,{icon:"lucide:chevron-down"})})]}),a.jsx(le.Transition,{as:x.Fragment,leave:"custom-select__transition",children:a.jsx(le.Listbox.Options,{className:"custom-select__options",anchor:"bottom",children:g==null?void 0:g.map((w,N)=>a.jsx(le.Listbox.Option,{value:w,className:({active:A})=>me("custom-select__option",A&&"custom-select__option--active"),children:({selected:A})=>a.jsx("span",{className:me("custom-select__option-label",A&&"custom-select__option--selected"),children:w.label})},N))})})]})}),b&&!o&&a.jsx("p",{className:"custom-select__subtext",children:b}),o&&a.jsx("span",{className:"custom-select__error",children:o.message})]})},pu=({element:e,validationData:n})=>{var p;const{register:i=()=>({}),trigger:o,setValue:s,watch:t,isReadOnly:l}=n||{},r=(p=e==null?void 0:e.id)!=null?p:"cascadeValue",[d,c]=x.useState(""),[m,u]=x.useState(""),b=(y,f)=>{const S=y&&f?`${y}_${f}`:"";s==null||s(r,S),o==null||o(r)},h=(y,f)=>{y==="first"?(c(f),u(""),b(f,"")):(u(f),b(d,f))};x.useEffect(()=>{if(t){const y=t(r);if(y!=null&&y.includes("_")){const[f,S]=y.split("_");c(f),u(S)}}},[t,r]);const v=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:a.jsxs("div",{children:[a.jsx("input",{type:"hidden",...i(r)}),a.jsx("div",{className:"relative",children:a.jsx(na,{setValue:(y,f)=>h("first",f),options:e.options,name:`${r}`,register:i,value:d})}),d&&a.jsxs("div",{className:"mt-4",children:[(e==null?void 0:e.childLabel)&&a.jsx("label",{className:"block text-sm text-[#686878] darks:!text-white/70 mb-2",children:e==null?void 0:e.childLabel}),a.jsx(na,{setValue:(y,f)=>h("second",f),options:v,name:`${r}`,register:i,value:m})]})]})},gu=({value:e=0,max:n=5,readOnly:i=!1,onChange:o,size:s=24,className:t="",element:l,validationData:r})=>{var f;const{register:d=()=>({}),trigger:c,setValue:m,watch:u,isReadOnly:b}=r||{},h=(f=u==null?void 0:u(l.id))!=null?f:0,[v,p]=x.useState(null);x.useEffect(()=>{h==null&&(m==null||m(l.id,e))},[]);const y=S=>{if(!i&&!b){const g=S+1;m==null||m(l.id,g),c==null||c(l.id),o==null||o(g)}};return a.jsxs("div",{className:`flex gap-1 ${t}`,children:[a.jsx("input",{type:"hidden",...d(l.id)}),Array.from({length:n},(S,g)=>{const w=v!==null?g<=v:g<h;return a.jsx(qs,{icon:w?"mdi:star":"mdi:star-outline",className:`cursor-pointer transition-colors ${w?"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 yu({element:e,validationData:n}){const{register:i=()=>({})}=n||{},o=(e==null?void 0:e.options)||[],s=(e==null?void 0:e.options1)||[];return a.jsx("div",{className:me("w-full overflow-x-auto",e.customClass),children:a.jsxs("table",{className:"w-full text-left border-collapse min-w-[600px] mb-2",children:[a.jsx("thead",{children:a.jsxs("tr",{children:[a.jsx("th",{className:"p-3 border-b bg-gray-50/50"}),s.map(t=>a.jsx("th",{className:"p-3 font-medium text-center border-b text-xs text-gray-700 w-[12%]",children:t.label},t.id||t.value))]})}),a.jsx("tbody",{children:o.map(t=>a.jsxs("tr",{className:"border-b last:border-0 hover:bg-gray-50/30",children:[a.jsx("td",{className:"p-3 text-gray-700 min-w-[150px] text-sm",children:t.label}),s.map(l=>a.jsx("td",{className:"p-3 text-center align-middle",children:a.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}.${t.value}`)})},l.id||l.value))]},t.id||t.value))})]})})}function ia({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,trigger:s,isReadOnly:t,watch:l}=n||{},r=(l==null?void 0:l(e.id))||"",{country:d,state:c}=x.useMemo(()=>{var v;if(typeof r=="string"&&r.includes(",")){const[p,y]=(v=r.split(","))==null?void 0:v.map(f=>f.trim());return{country:y,state:p}}return{country:r,state:""}},[r]),m=x.useRef(r),u=x.useMemo(()=>{var v,p;return d?((p=(v=li.find(y=>y.name===d))==null?void 0:v.states)==null?void 0:p.map(y=>({label:y.name,value:y.name})))||[]:[]},[d]),b=(v,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)},h=(v,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]),a.jsxs("div",{className:"grid gap-y-6",children:[a.jsx("input",{type:"hidden",...i(e.id)}),a.jsx(In,{options:e.options,onGetValue:b,name:`${e.id}-country`,readOnly:t,defaultValue:d},`country-${d}`),u.length>0&&e.showState&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium mb-1.5 input_label",children:"State"}),a.jsx(In,{options:u,onGetValue:h,name:`${e.id}-state`,readOnly:t,defaultValue:c},`state-${c}`)]})]})}function xu({element:e,validationData:n}){const{register:i=()=>({}),isReadOnly:o}=n||{},{validationUrl:s,documentObj:t,signatureLink:l}=e,r=x.useMemo(()=>Ce("config"),[]),[d,c]=x.useState(!1),[m,u]=x.useState(!1),b=x.useCallback(async()=>{var h,v;if(!(!s||!t))try{u(!0);const y={headers:{Authorization:`Bearer ${Ce("token")}`}},{data:f}=await en.get(`${s}/${t}`,y),S=!!((v=(h=f==null?void 0:f.data)==null?void 0:h.isSigned)!=null?v:f!=null&&f.isSigned);return c(S),S}catch(p){console.error("Failed to check sign status",p)}finally{u(!1)}},[s,t]);return x.useEffect(()=>{let h=null;return!d&&t&&s&&(async()=>{await b()||(h=setInterval(async()=>{await b()&&h&&clearInterval(h)},2e3))})(),()=>{h&&clearInterval(h)}},[b,d,t,s]),a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsx("input",{placeholder:e.placeholder,type:e.inputType,className:me("field-control",e.customClass),...i(e.id),disabled:o}),a.jsx("a",{href:d?"#":l,children:a.jsxs("button",{type:"button",onClick:b,disabled:m||d,style:{background:(r==null?void 0:r.buttonColor)||"#333"},className:me("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:[a.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 fo=[{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 Su({label:e,placeholder:n,classLabel:i,isRequired:o,isOptional:s,name:t,value:l,error:r,disabled:d,readOnly:c,horizontal:m,description:u,validate:b,onChange:h,onError:v}){const[p,y]=x.useState(""),[f,S]=x.useState(null),[g,w]=x.useState(""),N=x.useMemo(()=>{var T;return(T=fo==null?void 0:fo.slice().sort((O,M)=>O.label.localeCompare(M.label)))==null?void 0:T.map(O=>({...O,phone:`+${O.phone}`}))},[]),A=x.useMemo(()=>p?N.filter(T=>`${T.label} ${T.phone}`.toLowerCase().includes(p.toLowerCase())):N,[p,N]),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}`:"",I=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=I(l);S(N.find(O=>O.phone===T.code)||N[0]),w(T.number)}},[l,N]);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(()=>{h==null||h(k()),v==null||v(P||null)},[g,f,P]),a.jsxs("div",{className:`relative formGroup ${P&&!c?"has-error":""} ${m?"flex":""} ${!P&&g.length>0&&!c?"is-valid":""}`,children:[e&&a.jsxs("label",{htmlFor:t,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&&a.jsx("span",{className:"text-red-500",children:"*"}),s&&a.jsx("span",{className:"text-[#98A2B3]",children:"(Optional)"})]}),a.jsxs("div",{className:"relative !flex items-center input-control text-[#667085] !py-0 field-control",children:[a.jsx(te,{icon:"lucide:phone-call"}),a.jsx(le.Combobox,{value:f,onChange:S,children:a.jsxs("div",{className:"relative",children:[a.jsx(le.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)}),a.jsx(le.Combobox.Button,{className:"absolute inset-y-0 right-0 flex items-center pr-2",children:a.jsx(te,{icon:"lucide:chevron-down"})}),a.jsx(le.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)=>a.jsxs(le.Combobox.Option,{value:T,className:"px-4 py-2 cursor-pointer hover:bg-gray-100",children:[T.phone," - ",T.label]},`${T.code}+ ${O}`))})]})}),a.jsxs("div",{className:"relative flex items-center flex-1 z-[1]",children:[a.jsx("input",{type:"tel",inputMode:"numeric",value:g,disabled:d,readOnly:c,onChange:T=>{const O=T.target.value.replace(/\D/g,"");w(O)},placeholder:n,className:"w-full px-3 outline-none",maxLength:E,minLength:C}),a.jsx("div",{className:"absolute flex text-xl -translate-y-1/2 top-1/2 right-4",children:!P&&g.length>0&&!c&&a.jsx("span",{className:"text-green-500",children:a.jsx(te,{icon:"bi:check-lg"})})})]})]}),u&&a.jsx("span",{className:"block text-[#475467] font-light leading-4 text-xs mt-2",children:u})]})}function wu({element:e,validationData:n}){const{register:i=()=>({}),setValue:o,watch:s,isReadOnly:t,setError:l,clearErrors:r}=n||{};let d;return x.useEffect(()=>{i(e.id)},[e.id,i]),s&&(d=s()[e.id]),a.jsx(Su,{placeholder:e.placeholder,label:"",name:e.id,value:d,readOnly:t,disabled:t,onError:c=>{c?l==null||l(e.id,{type:"manual",message:c}):r==null||r(e.id)},onChange:c=>{c&&(o==null||o(e.id,c))}})}function Nu({element:e,validationData:n}){var c;const{register:i=()=>({}),watch:o}=n||{};let s="";o&&(s=(c=o()[e.id])!=null?c:"");const t=s.trim(),l=/^https?:\/\//i.test(t),r=t?l?t:`https://${t}`:"",d=!l;return a.jsxs("div",{children:[!(n!=null&&n.isReadOnly)&&a.jsxs("div",{className:"relative",children:[d&&a.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://"}),a.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Enter Url link",type:"text",className:me("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})]}),t?a.jsx("div",{className:n!=null&&n.isReadOnly?"field-control !bg-gray-50 mt-1":"mt-1 text-xs",children:a.jsx("a",{title:"Visit link",target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-blue-700 break-all",href:r,children:t})}):(n==null?void 0:n.isReadOnly)&&a.jsx("div",{className:"field-control !bg-gray-50 mt-1 text-gray-400 text-sm",children:"No link provided"})]})}function Au({element:e,validationData:n}){var d;const{watch:i,setValue:o}=n||{},s=(e==null?void 0:e.formula)||"",t=x.useMemo(()=>{const m=(s.match(/\{\{([^{}]+)\}\}/g)||[]).map(h=>h.replace(/[{}]/g,"")),b=(s.match(/@\[.*?\]\((.*?)\)/g)||[]).map(h=>{const v=/@\[.*?\]\((.*?)\)/.exec(h);return v?v[1]:""}).filter(Boolean);return Array.from(new Set([...m,...b]))},[s]),l=i?i(t):[],r=x.useMemo(()=>{if(!s)return"";let c=s,m=!1;if(t.forEach((u,b)=>{const h=l[b],v=Number(h);(isNaN(v)||h===void 0||h===null||h==="")&&(m=!0),c=c.replace(new RegExp(`\\{\\{${u}\\}\\}`,"g"),String(v||0)),c=c.replace(new RegExp(`@\\[.*?\\]\\(${u}\\)`,"g"),String(v||0))}),m)return"";try{const u=c.replace(/[^0-9+\-*/().\s]/g,"");if(!u)return"";const b=new Function(`return ${u}`)();return!isNaN(b)&&b!==null?Number.isInteger(b)?b:Number(b.toFixed(2)):""}catch(u){return"Error"}},[s,t,l]);return x.useEffect(()=>{o&&r!=="Error"&&r!==""&&o(e.id,r,{shouldValidate:!0,shouldDirty:!0})},[r,e.id,o]),a.jsx("div",{children:a.jsx("input",{placeholder:(e==null?void 0:e.placeholder)||"Calculated result",type:"text",className:me("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 Cu({element:e,validationData:n,state:i}){var h;const{register:o,watch:s,setValue:t}=n||{},[l,r]=x.useState({}),[d,c]=x.useState(0),m=s?s(e.id):null,u=!!(m||i&&i!=="edit");x.useEffect(()=>{if(!e.fetchExternalResults||!e.externalApiUrl)return;const v=async()=>{try{const y=await fetch(e.externalApiUrl);if(!y.ok)return;const f=await y.json();let S={};Array.isArray(f)?f.forEach(w=>{const N=w.value||w.id||w.option,A=w.count||w.votes||w.value||0;N&&(S[N]=Number(A))}):typeof f=="object"&&(S=f),r(S);const g=Object.values(S).reduce((w,N)=>w+Number(N),0);c(g)}catch(y){console.error("Failed to fetch polling results",y)}};v();const p=setInterval(v,1e4);return()=>clearInterval(p)},[e.fetchExternalResults,e.externalApiUrl]),x.useEffect(()=>{e.fetchExternalResults||(m?(r({[m]:1}),c(1)):(r({}),c(0)))},[m,e.fetchExternalResults]);const b=v=>{n!=null&&n.isReadOnly||t&&t(e.id,v,{shouldValidate:!0,shouldDirty:!0})};return a.jsxs("div",{className:"w-full",children:[a.jsx("div",{className:"grid gap-y-3",children:(h=e.options)==null?void 0:h.map(v=>{const p=l[v.value]||0,y=d>0?Math.round(p/d*100):0,f=m===v.value;return a.jsxs("div",{onClick:()=>b(v.value),className:me("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:[u&&a.jsx("div",{className:"absolute top-0 left-0 bottom-0 bg-blue-100/60 transition-all duration-1000 ease-out",style:{width:`${y}%`}}),a.jsxs("div",{className:"relative z-10 flex items-center gap-3",children:[a.jsx("div",{className:me("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&&a.jsx("div",{className:"w-2 h-2 bg-white rounded-full"})}),a.jsx("span",{className:me("font-medium text-sm",f?"text-blue-900":"text-gray-700"),children:v.label||v.name||v.option||v.value||"Unknown Option"})]}),u&&a.jsxs("div",{className:"relative z-10 flex items-center gap-2",children:[a.jsxs("span",{className:"text-sm font-semibold text-gray-700",children:[y,"%"]}),f&&a.jsx(te,{icon:"material-symbols:check-circle",iconClass:"text-blue-500 text-lg"})]}),a.jsx("input",{type:"radio",value:v.value,className:"hidden",...o?o(e.id):{}})]},v.id||v.value)})}),u&&a.jsxs("div",{className:"mt-3 text-xs text-gray-500 text-right flex justify-between items-center",children:[a.jsxs("span",{children:[d," ",d===1?"vote":"votes"," total"]}),e.fetchExternalResults&&e.externalApiUrl&&a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"})," Live"]})]})]})}const oa={textField:Xi,longText:Td,selectField:Ed,multiSelect:ro,numberField:Xi,amountField:ou,date:gr,password:Ad,checkbox:Md,radio:Cd,email:Xi,file:Nd,dataGrid:fu,section:kd,validateInput:tu,tableInput:ru,spacer:du,divider:uu,header:cu,basicText:mu,phoneField:wu,cascadeSelect:pu,rating:gu,matrix:yu,country:ia,bank:ia,document:xu,url:Nu,calculatedField:Au,polling:Cu},sa="edit",ku=(e,n)=>{var o;const i=oa[e.type];return i?a.jsx(ho,{element:e,state:sa,children:a.jsxs("div",{className:"relative w-full",children:[((o=e.type)==null?void 0:o.toLowerCase())!=="grid"&&a.jsx("div",{className:"absolute top-0 left-0 z-20 w-full h-full"}),a.jsx(i,{element:e,state:sa,sectionId:n})]})}):a.jsx("div",{className:"flex items-center justify-center p-4 text-red-500 bg-red-50 border border-red-200 rounded-md",children:a.jsxs("span",{className:"text-sm font-medium",children:["Unsupported element type: ",e.type]})})},di=({col:e,children:n,customClass:i})=>a.jsx("div",{className:me("w-full bg-white min-w-0",i),style:{gridColumn:e},children:n}),Mu=({element:e,sectionId:n,children:i,customClass:o,state:s,draggedElementId:t})=>{const{formData:l,addElement:r,setIsDragging:d,moveElement:c,isDragging:m,removeElement:u}=x.useContext(Te),b=x.useMemo(()=>Array.from({length:e.columns}),[e.columns]),[h,v]=x.useState(null);x.useEffect(()=>{const w=()=>{v(null),d(!1)};return document.addEventListener("dragend",w),()=>document.removeEventListener("dragend",w)},[d]);const p=x.useCallback((w,N)=>{w.preventDefault(),w.stopPropagation(),w.dataTransfer.dropEffect="move",v(N)},[]),y=x.useCallback((w,N)=>{w.preventDefault(),w.stopPropagation(),v(N)},[]),f=x.useCallback((w,N)=>{const A=w.relatedTarget;A&&w.currentTarget.contains(A)||v(C=>C===N?null:C)},[]),S=x.useCallback((w,N)=>{var E;w.preventDefault(),w.stopPropagation(),d(!1),v(null);const A=N+1,C=w.dataTransfer.getData("elementId");if(C){c({draggedId:C,sectionId:n,targetGridId:e.id,targetCol:A});return}try{const k=w.dataTransfer.getData("properties");if(!k)return;const I=JSON.parse(k);if((I==null?void 0:I.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 _;return M.gridId===e.id&&((_=M.gridPosition)==null?void 0:_.col)===A});T&&u(T.id,n);const O={...I,id:Ee.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,c]),g=(w,N,A)=>{var _,B,H;const C=w+1,E=(B=(_=l.find(D=>D.id===n))==null?void 0:_.questionData)==null?void 0:B.find(D=>{var L;return D.gridId===e.id&&((L=D.gridPosition)==null?void 0:L.col)===C}),k=(H=E==null?void 0:E.id)!=null?H:null,I=Array.isArray(i)&&i.find(D=>{var L;return((L=D==null?void 0:D.props)==null?void 0:L.col)===C}),P=m&&h===w,T=!!I,O=m&&!!t,M=T&&k&&A==="edit"?{draggable:!0,onDragStart:D=>{D.stopPropagation(),D.dataTransfer.setData("elementId",k),D.dataTransfer.setData("properties",k),D.dataTransfer.effectAllowed="move",d(!0)},onDragEnd:()=>{v(null),d(!1)}}:{};return a.jsx("div",{className:"min-w-0",children:a.jsxs("div",{id:`grid-cell-${e.id}-${w}`,...M,onDrop:D=>S(D,w),onDragEnter:D=>y(D,w),onDragOver:D=>p(D,w),onDragLeave:D=>f(D,w),className:me("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",N,!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"&&a.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:a.jsx(te,{icon:"ph:dots-six-bold"})}),P&&!T&&a.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:[a.jsx(te,{icon:"ph:plus-bold"}),"Drop here"]}),P&&T&&a.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"}),a.jsx("div",{className:me("w-full select-none min-w-0",P&&"opacity-50 pointer-events-none"),children:I||a.jsx("span",{className:"flex items-center justify-center text-gray-300",children:A==="edit"&&a.jsx(te,{icon:"ph:plus-bold"})})})]})},w)};return a.jsx("div",{className:"relative w-full",children:a.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((w,N)=>g(N,o,s))})})},ui=x.memo(Mu),Eu="edit";function po({index:e,onDrop:n,onDragEnd:i,isDragging:o}){const[s,t]=x.useState(!1),l=s?52:o?28:4;return a.jsx("div",{onDragEnter:r=>{r.preventDefault(),t(!0)},onDragOver:r=>{r.preventDefault(),r.stopPropagation(),t(!0)},onDragLeave:()=>t(!1),onDrop:r=>{r.preventDefault(),r.stopPropagation(),t(!1),n(r,e)},onDragEnd:()=>{t(!1),i()},style:{height:`${l}px`},className:me("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&&a.jsxs("span",{className:"flex items-center gap-1 text-blue-500 text-xs font-medium select-none pointer-events-none",children:[a.jsx(te,{icon:"octicon:plus-16"}),"Drop here"]})})}function Tu({elementData:e,sectionId:n}){const{formData:i,isDragging:o,setIsDragging:s,addElementInPosition:t,moveElement:l}=x.useContext(Te),[r,d]=x.useState(null),c=x.useMemo(()=>{var f;return((f=i.find(S=>S.id===n))==null?void 0:f.questionData)||[]},[i,n]),m=x.useCallback((f,S)=>{f.dataTransfer.setData("elementId",S),f.dataTransfer.setData("properties",S),f.dataTransfer.effectAllowed="move",d(S),s(!0)},[s]),u=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 S=f.dataTransfer.getData("elementId"),g=f.currentTarget.id;if(!S||!g||S===g){u();return}const w=c.find(A=>A.id===S),N=c.findIndex(A=>A.id===g);w!=null&&w.gridId&&N!==-1?l({draggedId:S,sectionId:n,targetIndex:N}):l({draggedId:S,sectionId:n,targetId:g}),d(null),s(!1)},[n,l,s,u,c]),h=x.useCallback((f,S)=>{f.preventDefault(),f.stopPropagation(),s(!1);const g=f.dataTransfer.getData("elementId");if(g){l({draggedId:g,sectionId:n,targetIndex:S}),d(null);return}try{const w=JSON.parse(f.dataTransfer.getData("properties"));if((w==null?void 0:w.type)==="section")return;const N={...w,id:Ee.v4(),sectionId:n};t(N,n,S),d(null)}catch(w){console.error("Drop error:",w)}},[t,n,s,l]),v=x.useCallback((f,S=!1)=>a.jsx("div",{id:f.id,draggable:!0,onDragStart:g=>m(g,f.id),onDragOver:S?void 0:g=>{g.preventDefault(),g.stopPropagation()},onDrop:S?void 0:b,onDragEnd:u,className:me("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:ku(f,n)},f.id),[r,b,n,m,u]),p=x.useMemo(()=>(e==null?void 0:e.reduce((f,S)=>(S.gridId&&(f[S.gridId]=f[S.gridId]||[],f[S.gridId].push(S)),f),{}))||{},[e]);if(!(e!=null&&e.length))return a.jsx("div",{onDragOver:f=>f.preventDefault(),onDrop:f=>h(f,0),onDragEnd:u,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 a.jsxs("div",{className:"relative flex flex-col w-full h-full gap-2",children:[a.jsx(po,{index:0,isDragging:o,onDrop:h,onDragEnd:u}),y.map(f=>{const S=c.findIndex(g=>g.id===f.id);if(f.type==="grid"){const g=p[f.id]||[],w=r===f.id,N=!!r&&!w;return a.jsxs("div",{className:"flex flex-col gap-0",children:[a.jsx("div",{id:f.id,draggable:!0,onDragStart:A=>m(A,f.id),onDragOver:A=>{A.preventDefault(),A.stopPropagation()},onDrop:b,onDragEnd:u,className:me("w-full p-4 border rounded-lg cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out",w?"opacity-40 scale-[0.98] bg-gray-100 border-dashed border-blue-400 shadow-inner":N?"bg-white border-dashed border-blue-200":"bg-white border-gray-200 shadow-sm hover:border-blue-300 hover:shadow-md"),children:a.jsx(ho,{element:f,state:"edit",children:a.jsx(ui,{element:f,sectionId:n,state:Eu,draggedElementId:r,children:g==null?void 0:g.map(A=>{var C;return a.jsx(di,{col:(C=A.gridPosition)==null?void 0:C.col,children:v(A,!0)},A.id)})})})}),a.jsx(po,{index:S+1,isDragging:o,onDrop:h,onDragEnd:u})]},f.id)}return a.jsxs("div",{className:"flex flex-col gap-0",children:[v(f),a.jsx(po,{index:S+1,isDragging:o,onDrop:h,onDragEnd:u})]},f.id)})]})}const Pu=x.memo(Tu),Lu=ne.object({title:ne.string(),description:ne.string(),disabled:ne.boolean().default(!1),isHidden:ne.boolean().default(!1)}).required(),go=Ce("config"),Bu=({isOpen:e,onClose:n,section:i})=>{const{updateSection:o}=x.useContext(Te),{register:s,handleSubmit:t,watch:l,formState:{errors:r,isSubmitting:d,isValid:c},reset:m}=$e.useForm({resolver:uo(Lu),defaultValues:i});if(x.useEffect(()=>{e||m()},[e,m]),!e)return null;const u=h=>{o(h,i.id),n()},b=l();return a.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:a.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[a.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 mb-6",children:[a.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Update Section Information"}),a.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:a.jsx(te,{icon:"tabler:x"})})]}),a.jsxs("form",{onSubmit:t(u),className:"w-full",autoComplete:"off",children:[a.jsxs("div",{className:"w-full px-6 flex flex-col gap-5 z-10",children:[a.jsx(re,{label:"Title",name:"title",register:s,errors:r,watch:l}),a.jsx(re,{label:"Description",name:"description",register:s,errors:r,watch:l,type:"textarea"}),a.jsx(re,{label:"Disable Section",name:"disabled",register:s,errors:r,watch:l,type:"checkbox",value:b.disabled,description:"Disables all fields in this section"}),a.jsx(re,{label:"Hide Section",name:"isHidden",register:s,errors:r,watch:l,type:"checkbox",value:b.isHidden,description:"Hides this section from the form"})]}),a.jsxs("div",{className:"w-full px-6 pt-8 pb-6 flex gap-3 mt-4",children:[a.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"}),a.jsx("button",{type:"submit",disabled:!c||d,style:{background:(go==null?void 0:go.buttonColor)||"#333"},className:`flex-1 px-4 py-2.5 ${!c||d?"bg-[#F2F4F7]":"bg-[#2563EB]"} ${!c||d?"text-[#98A2B3]":"text-white"} rounded-lg shadow-xs font-semibold font-onest disabled:opacity-50`,children:d?"Saving...":"Save"})]})]})]})})},Iu=({isOpen:e,onClose:n,templates:i,onSelect:o})=>e?a.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:a.jsxs("div",{className:"min-w-[600px] bg-white rounded-xl shadow-xl relative flex flex-col items-center",children:[a.jsxs("div",{className:"w-full px-6 pt-6 pb-5 flex flex-col items-start gap-4 z-10 border-b",children:[a.jsx("h2",{className:"text-lg font-semibold text-[#475467] font-onest",children:"Select a Template"}),a.jsx("button",{onClick:n,className:"absolute right-4 top-4 p-2 text-[#98A2B3] hover:bg-gray-50 rounded-lg",children:a.jsx(te,{icon:"tabler:x"})})]}),a.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=>a.jsxs("div",{className:"p-4 border rounded-lg cursor-pointer hover:border-blue-500 hover:shadow-md transition-all",onClick:()=>{o(s),n()},children:[a.jsx("h3",{className:"font-semibold text-[#344054] mb-1",children:s.name}),s.description&&a.jsx("p",{className:"text-sm text-[#475467]",children:s.description})]},s.id)):a.jsx("p",{className:"text-sm text-gray-500",children:"No templates available."})})]})}):null,Du=[{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"}]}]}],_u=({section:e,index:n,selectedSection:i,setSelectedSection:o,activeSections:s,toggleSection:t,handleSectionEdit:l,removeSection:r,formDataLength:d,onDragOver:c,setIsDragging:m,isDragging:u,onReorderSection:b})=>{var y,f;const h=x.useRef(null),v=x.useRef((y=e==null?void 0:e.questionData)==null?void 0:y.length),p=x.useRef(u);return x.useEffect(()=>{var S,g;if(((S=e==null?void 0:e.questionData)==null?void 0:S.length)>v.current&&!u&&!p.current){const w=document.getElementById("section-container");w&&requestAnimationFrame(()=>{w.scrollTo({top:w.scrollHeight,behavior:"smooth"})})}v.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,u]),x.useEffect(()=>{p.current=u},[u]),a.jsx("div",{ref:h,onDragOver:S=>{S.dataTransfer.types.includes("sectionid")&&S.preventDefault()},onDrop:S=>{const g=S.dataTransfer.getData("sectionid");g&&(S.preventDefault(),S.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:a.jsxs("div",{className:` border border-gray-200 rounded-lg px-4 transition-colors duration-200
27
27
  ${i===e.id?" border-blue-200 bg-gray-100":"bg-white"} ${s.includes(n)?"min-h-[300px] pb-6 ":""}`,children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{draggable:!0,onDragStart:S=>{S.dataTransfer.setData("sectionid",e.id),S.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:[a.jsx(te,{icon:"material-symbols:drag-indicator",iconClass:"text-gray-400 text-lg"}),a.jsx("h2",{className:"font-medium",children:e.title||"Section title"})]}),a.jsxs("div",{className:"flex items-center gap-x-2",children:[a.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>l(e),children:a.jsx(te,{icon:"fluent:edit-28-regular"})}),d>1&&a.jsx("button",{type:"button",className:"p-1 text-xs border rounded-lg",onClick:()=>r(e.id),children:a.jsx(te,{icon:"lets-icons:trash-duotone-line"})}),a.jsx("button",{type:"button",className:"p-1 text-xs rounded-lg",onClick:()=>t(n),children:a.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)&&a.jsx("p",{className:"mt-2 text-sm text-gray-600",children:e==null?void 0:e.description}),s.includes(n)&&a.jsxs("div",{className:"h-full mt-4 transition-all duration-200",id:e.id,onDragOver:c,onDragEnd:()=>m(!1),onClick:()=>o(e.id),children:[a.jsx("hr",{className:"group-last:hidden"}),a.jsx("div",{className:"h-full mt-4 gap-y-6 ",children:a.jsx(Pu,{elementData:e==null?void 0:e.questionData,sectionId:e==null?void 0:e.id})})]})]})},e==null?void 0:e.id)},Ou=({onAddTemplate:e,templates:n})=>{const i=[...Du,...n||[]],[o,s]=x.useState(!1),[t,l]=x.useState(!1),r=x.useRef(null),d=x.useRef(null),{removeSection:c,addSection:m,formData:u,setIsDragging:b,setSelectedSection:h,selectedSection:v,activeSections:p,setActiveSections:y,setFormData:f,isDragging:S,pasteElement:g}=x.useContext(Te);x.useEffect(()=>{const P=T=>{var M;const O=T.target;if(!(O.tagName==="INPUT"||O.tagName==="TEXTAREA"||O.isContentEditable)&&v){const _=((M=T.clipboardData)==null?void 0:M.getData("text"))||"";g(v,void 0,_)}};return window.addEventListener("paste",P),()=>{window.removeEventListener("paste",P)}},[v,g]);const w=x.useRef((u==null?void 0:u.length)||0);x.useEffect(()=>{var P;h(((P=u[0])==null?void 0:P.id)||null)},[]),x.useEffect(()=>{(u==null?void 0:u.length)>w.current&&d.current&&requestAnimationFrame(()=>{var P;(P=d.current)==null||P.scrollTo({top:d.current.scrollHeight,behavior:"smooth"})}),w.current=(u==null?void 0:u.length)||0},[u==null?void 0:u.length]);const N=x.useCallback(P=>{P.preventDefault(),P.dataTransfer.dropEffect="move"},[]),A=x.useCallback((P,T)=>{f(O=>{const M=O.findIndex(D=>D.id===P),_=O.findIndex(D=>D.id===T);if(M===-1||_===-1||M===_)return O;const B=[...O],[H]=B.splice(M,1);return B.splice(_,0,H),B})},[f]);function C(P){p.includes(P)?y(T=>T.filter(O=>O!==P)):y(T=>[...T,P])}function E(P){r.current=P,s(!0)}const k=P=>{var O,M,_,B;const T=(H,D={})=>({...JSON.parse(JSON.stringify(H)),...D});if(P.sections&&Array.isArray(P.sections)){const D=P.sections.filter(Boolean).map(z=>{var Z;const q=Ee.v4(),W=(Z=z.questionData)==null?void 0:Z.map(X=>T(X,{id:Ee.v4(),sectionId:q}));if(W){const X=new Map;z.questionData.forEach((ie,ae)=>{X.set(ie.id,W[ae].id)}),W.forEach(ie=>{ie.gridId&&X.has(ie.gridId)&&(ie.gridId=X.get(ie.gridId))})}return T(z,{id:q,questionData:W||[]})});u.length===1&&u[0].title===""&&u[0].description===""&&(!((O=u[0])!=null&&O.questionData)||((_=(M=u[0])==null?void 0:M.questionData)==null?void 0:_.length)===0)?(f(D),D.length>0&&h((B=D[0])==null?void 0:B.id)):f(z=>[...z,...D])}},I=Ce("config");return a.jsxs("div",{className:"relative flex flex-col h-full pb-5 mx-auto gap-x-4 ",children:[o&&a.jsx(Bu,{isOpen:o,onClose:()=>s(!1),section:r.current}),a.jsxs("div",{id:"section-container",ref:d,className:"relative flex flex-col flex-1 w-full gap-y-3 container overflow-y-auto",children:[u==null?void 0:u.map((P,T)=>a.jsx(_u,{section:P,index:T,selectedSection:v,setSelectedSection:h,activeSections:p,toggleSection:C,handleSectionEdit:E,removeSection:c,formDataLength:u.length,onDragOver:N,setIsDragging:b,isDragging:S,onReorderSection:A},P.id)),a.jsxs("div",{className:"flex justify-center gap-x-4",children:[a.jsxs("button",{type:"button",onClick:()=>m(),style:{color:(I==null?void 0:I.buttonColor)||"#333"},className:"text-sm font-medium",children:["+ Add section"," "]}),e||i!=null&&i.length?a.jsx("button",{type:"button",onClick:()=>{i!=null&&i.length?l(!0):e&&e()},style:{color:(I==null?void 0:I.buttonColor)||"#333"},className:"text-sm font-medium",children:"+ Add existing template"}):null]})]}),t&&a.jsx(Iu,{isOpen:t,onClose:()=>l(!1),templates:i,onSelect:k})]})},Ku=()=>{const{formData:e,uploadUrl:n}=x.useContext(Te),[i,o]=x.useState("multi"),s=Ce("config");return a.jsxs("div",{className:"flex flex-col h-full w-full",children:[a.jsx("div",{className:"flex justify-center p-3 border-b border-gray-100 bg-gray-50/50",children:a.jsxs("div",{className:"flex bg-gray-200 p-1 rounded-lg text-sm font-medium",children:[a.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"}),a.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"})]})}),a.jsx("div",{className:"flex-1 overflow-y-auto w-full relative",children:a.jsx(No,{form_data:e,ignoreValidation:!0,config:s,uploadUrl:n,renderType:i,onGetValues:t=>console.log(t)})})]})},yo=({loadingClass:e})=>{const n=me("h-full w-full min-h-[300px] flex justify-center items-center",e);return x.useEffect(()=>{const i=Ce("config"),o=(i==null?void 0:i.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",o)},[]),a.jsx("div",{className:n,children:a.jsx("span",{className:"loader"})})},Hu=x.lazy(()=>Promise.resolve().then(()=>xg));function Gu({questionData:e,uploadUrl:n,onAddTemplate:i,templates:o,viewMode:s="canvas"}){const{setFormData:t,addSection:l,setUploadUrl:r,showPreview:d,formData:c}=x.useContext(Te);x.useEffect(()=>{e&&e.length>0&&t(e)},[e,t]),x.useEffect(()=>{r(n)},[n,r]);const m=x.useCallback(u=>{u.preventDefault();try{const b=JSON.parse(u.dataTransfer.getData("properties"));if((b==null?void 0:b.type)==="section"){l();return}}catch(b){console.error("Drop error:",b)}},[]);return a.jsxs("div",{className:"flex gap-x-6 h-full",children:[a.jsx("div",{onDragOver:u=>u.preventDefault(),onDrop:u=>m(u),className:" h-full overflow-y-auto no-scrollbar max-h-[calc(100vh-80px)] flex-1 form_builder",children:s==="canvas"?a.jsx(Ou,{onAddTemplate:i,templates:o}):a.jsx(x.Suspense,{fallback:a.jsx(yo,{loadingClass:"!w-full !h-full"}),children:a.jsx(Hu,{formData:c})})}),s==="canvas"&&a.jsx(le.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:a.jsx("div",{className:"px-2 shadow_box min-w-0 bg-white border border-gray-100 rounded-lg container",children:a.jsx(Ku,{})})})]})}const xo=[{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"}],Fu=()=>{const[e,n]=x.useState(""),[i,o]=x.useState(!1),{setIsDragging:s,addElement:t,selectedSection:l,pasteElement:r}=x.useContext(Te);x.useEffect(()=>{const y=()=>{try{const S=localStorage.getItem("form_builder_clipboard");if(S){const g=JSON.parse(S);(g==null?void 0:g.type)==="FORM_BUILDER_CLIPBOARD"&&(g!=null&&g.timestamp)?Date.now()-g.timestamp>6e4?(localStorage.removeItem("form_builder_clipboard"),o(!1)):o(!0):o(!1)}else o(!1)}catch(S){o(!1)}};y();const f=setInterval(y,1e3);return()=>clearInterval(f)},[]);const d=x.useCallback((y,f)=>{if(!l){Ae.toast.error("Please select a section to add an element.");return}y.dataTransfer.setData("properties",JSON.stringify(f)),y.dataTransfer.effectAllowed="move",s(!0)},[s,l]);function c(y){if(!l){Ae.toast.error("Please select a section to add an element.");return}const f={...y,id:Ee.v4(),sectionId:l};t(f,l)}const m=Ce("config")||{},u=m.elementColor,b=m.elementBgColor,h=m.elementBorderColor,v=Id.filter(y=>y.label.toLowerCase().includes(e.toLowerCase())),p=xo==null?void 0:xo.map(y=>({title:y.title,elements:v.filter(f=>{var S;return(S=Dd[y.key])==null?void 0:S.includes(f.type)})})).filter(y=>y.elements.length>0);return a.jsxs("div",{className:"pt-4 flex flex-col gap-y-6",children:[a.jsxs("div",{className:"px-5",children:[a.jsx("input",{className:"field-control",placeholder:"Search",value:e,onChange:y=>n(y.target.value),name:"search",id:"search",autoComplete:"off"}),i&&a.jsxs("button",{className:"w-full mt-3 flex items-center justify-center gap-2 py-2 px-3 bg-blue-50 text-blue-600 hover:bg-blue-100 rounded-lg text-sm font-medium transition-colors",onClick:()=>{if(!l){Ae.toast.error("Please select a section to paste the element.");return}typeof r=="function"&&r(l)},title:"Paste copied element",children:[a.jsx(te,{icon:"lucide:clipboard-paste"}),"Paste Element (Ctrl+V)"]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto no-scrollbar max-h-[calc(100vh-100px)]",children:a.jsx("ul",{className:"grid gap-y-5 mt-3 px-5 ",children:p==null?void 0:p.map((y,f)=>{var S;return a.jsxs("li",{children:[a.jsx("h4",{className:"mb-2 text-[11px] font-bold text-gray-500 uppercase",children:y.title}),a.jsx("ul",{className:"grid grid-cols-2 gap-y-3 gap-x-4 mb-3",children:(S=y.elements)==null?void 0:S.map(g=>a.jsx("li",{onDragStart:w=>d(w,g),onDragEnd:()=>s(!1),onClick:()=>c(g),style:{borderColor:h,backgroundColor:b},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
- active:opacity-50 element_class`,draggable:!0,children:a.jsxs("span",{className:"flex flex-col items-center justify-center w-full gap-2",children:[a.jsx("span",{style:{color:u},children:a.jsx(te,{icon:g.icon,iconClass:"w-6 h-6"})}),a.jsx("span",{style:{color:u},className:"text-xs font-medium text-center",children:g.label})]})},g.type))})]},f)})})})]})},Vu=x.memo(Fu),Fe=({text:e="",isDisabled:n=!1,isLoading:i=!1,btnClass:o="bg-primary-500 text-white",icon:s="",iconPosition:t="left",iconClass:l="text-[20px]",loadingClass:r="",link:d="",div:c=!1,type:m="button",style:u,onClick:b})=>{const h=me("btn inline-flex justify-center",{"pointer-events-none":i,"opacity-40 cursor-not-allowed":n},o),v=()=>i?a.jsxs(a.Fragment,{children:[a.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:[a.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),a.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..."]}):a.jsxs("span",{className:"flex items-center",children:[s&&t==="left"&&a.jsx("span",{className:`mr-[6px] ${l}`,children:a.jsx(te,{icon:s})}),e&&a.jsx("span",{children:e}),s&&t==="right"&&a.jsx("span",{className:`ml-[6px] ${l}`,children:a.jsx(te,{icon:s})})]});return c?a.jsx("div",{className:h,children:v()}):d?a.jsx(fr.Link,{to:d,className:h,children:v()}):a.jsx("button",{disabled:n,type:m,className:h,"data-testid":"btn",onClick:b,style:u,children:v()})};function zu(){return a.jsx("div",{children:a.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",fill:"#D5D7DA"}),a.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",stroke:"#E9EAEB"}),a.jsx("path",{d:"M22.5 14L14.5 22M14.5 14L22.5 22",stroke:"#414651",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})]})})}const Wu=({isOpen:e,onClose:n})=>{const{formData:i,uploadUrl:o}=x.useContext(Te);if(!e)return null;const s=Ce("config");return a.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:[a.jsx("button",{type:"button",onClick:n,className:"absolute text-sm top-3 right-4","aria-label":"close",children:a.jsx(zu,{})})," ",a.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:a.jsx(No,{form_data:i,ignoreValidation:!0,config:s,uploadUrl:o})})]})};function $u(){return a.jsx("div",{children:a.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("rect",{width:"24",height:"24",rx:"6",fill:"currentColor"}),a.jsx("path",{d:"M14 16L10 12L14 8",stroke:"white",strokeWidth:"1.39167",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function ju({title:e,goBackUrl:n,onSubmit:i,onPublish:o,previewLoading:s,saveLoading:t,publishLoading:l,onTitleChange:r,viewMode:d,setViewMode:c,onShowVersion:m}){const{formData:u,setShowPreview:b,showPreview:h,undo:v,redo:p,canUndo:y,canRedo:f}=x.useContext(Te),[S,g]=x.useState(!1),[w,N]=x.useState(!1),[A,C]=x.useState(e||""),E=Ce("config");function k(){try{localStorage.setItem("formData",JSON.stringify(u))}catch(T){console.warn("Could not save formData to localStorage",T)}i==null||i(u)}function I(){try{localStorage.setItem("formData",JSON.stringify(u))}catch(T){console.warn("Could not save formData to localStorage",T)}o==null||o(u)}function P(){N(!1),r&&A!==e&&r(A.trim())}return a.jsxs("div",{className:"px-[30px] py-3 flex justify-between items-center bg-[#F9F9FB] top_bar border-b h-full",children:[a.jsxs("span",{className:"flex items-center gap-x-2",children:[n&&a.jsx("button",{type:"button",onClick:()=>n(),style:{color:(E==null?void 0:E.buttonColor)||"#333"},className:"flex items-center gap-x-3",children:a.jsx($u,{})})," ",w?a.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"}):a.jsx("h1",{title:"Click to edit",className:"text-base font-semibold cursor-pointer form_title",onClick:()=>N(!0),children:A||"Untitled"})]}),S&&a.jsx(Wu,{isOpen:S,onClose:()=>g(!1),element:void 0}),a.jsxs("div",{className:"flex justify-end text-xs gap-x-3 items-center",children:[c&&a.jsxs("div",{className:"flex border border-gray-300 rounded-lg overflow-hidden h-[36px] text-sm font-medium shadow-sm mr-2",children:[a.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:()=>c("canvas"),children:[a.jsx(te,{icon:"mdi:view-dashboard-outline",iconClass:"text-base"})," ","Builder"]}),a.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:()=>c("flow"),children:[a.jsx(te,{icon:"mdi:sitemap-outline",iconClass:"text-base"})," Flow"]})]}),a.jsx(Fe,{onClick:v,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}),a.jsx(Fe,{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&&a.jsx(Fe,{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"}}),a.jsx(Fe,{onClick:()=>b(T=>!T),text:h?"Hide Preview":"Preview",btnClass:"px-2 bg-transparent font-medium text-sm form_preview",icon:h?"iconamoon:eye-off-duotone":"solar:eye-bold-duotone",iconClass:"text-base",style:{color:(E==null?void 0:E.buttonColor)||"#333"},isDisabled:s,isLoading:s}),a.jsx(Fe,{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:t,isLoading:t}),a.jsx(Fe,{onClick:I,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 Uu({onSubmit:e,onChange:n,onLogAction:i,questionData:o,title:s,goBackUrl:t,loading:l,onPublish:r,previewLoading:d,saveLoading:c,publishLoading:m,onTitleChange:u,uploadUrl:b,onAddTemplate:h,templates:v,onShowVersion:p}){const[y,f]=x.useState("canvas");return a.jsxs(Ss,{onChange:n,onLogAction:i,children:[a.jsx(Ae.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),a.jsx("div",{className:"w-full h-full bg-[#F8F9FC] flex flex-col",children:a.jsxs("div",{className:"flex flex-1 ",children:[y==="canvas"&&a.jsx("div",{children:a.jsx("div",{className:"w-[250px] h-screen border-r border-[#E4E7EC] bg-white ",children:a.jsx(Vu,{})})}),a.jsxs("div",{className:`flex-1 h-full max-h-full z-[1] ${y==="canvas"?"w-[calc(100%-250px)]":"w-full"}`,children:[a.jsx("div",{className:" h-[70px]",children:a.jsx(ju,{title:s,goBackUrl:t,onSubmit:e,onPublish:r,previewLoading:d,saveLoading:c,publishLoading:m,onTitleChange:u,viewMode:y,setViewMode:f,onShowVersion:p})}),a.jsx("div",{className:"p-6 h-[calc(100vh-70px)]",children:l?a.jsx(yo,{loadingClass:"!w-full !h-[800px]"}):a.jsx(Gu,{questionData:o,uploadUrl:b,onAddTemplate:h,templates:v,viewMode:y})})]})]})})]})}const qu=({onSubmit:e,onChange:n,onLogAction:i,questionData:o,isReadOnly:s,config:t={buttonColor:"#333"},title:l,loading:r,goBackUrl:d,onPublish:c,previewLoading:m,saveLoading:u,publishLoading:b,onTitleChange:h,uploadUrl:v,onAddTemplate:p,templates:y,onShowVersion:f})=>(x.useEffect(()=>{t&&Js("config",t)},[t]),a.jsx(Uu,{onSubmit:e,onChange:n,onLogAction:i,onPublish:c,questionData:o,isReadOnly:s,title:l,goBackUrl:d,loading:r,previewLoading:m,saveLoading:u,publishLoading:b,onTitleChange:h,uploadUrl:v,onAddTemplate:p,templates:y,onShowVersion:f})),Je={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}`},Yu=(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",Je.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",Je.url,o=>!o||o.trim()===""?!0:/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/.test(o))})[e]||ne.mixed().nullable(),Ju=(e,n,i)=>n?e.type==="boolean"?e.oneOf([!0],i||Je.required):e.required(i||Je.required):e,Zu=(e,{minLength:n,maxLength:i,minLengthMessage:o,maxLengthMessage:s})=>{let t=e;return n&&(t=t.min(n,o||Je.minLength(n))),i&&(t=t.max(i,s||Je.maxLength(i))),t},Xu=(e,{minAmount:n,maxAmount:i,minAmountMessage:o,maxAmountMessage:s})=>{let t=e;return n&&(t=t.min(parseFloat(String(n)),o||Je.minAmount(n))),i&&(t=t.max(parseFloat(String(i)),s||Je.maxAmount(i))),t},So=(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],t=o.fieldValue,l=s;switch(o.operator){case"equals":return String(t).toLowerCase()===String(l).toLowerCase();case"not_equals":return String(t).toLowerCase()!==String(l).toLowerCase();case"greater":return Number(l)>Number(t);case"less":return Number(l)<Number(t);case"contains":return String(l).toLowerCase().includes(String(t).toLowerCase());case"not_contains":return!String(l).toLowerCase().includes(String(t).toLowerCase());default:return!0}}):!0};function Qu({formData:e,isReadOnly:n,answerData:i}){const o={};return e.forEach(({questionData:s})=>{s==null||s.forEach(t=>{if(!So(t,i))return;const{id:l,type:r,isRequired:d,requiredMessage:c,isDisabled:m}=t;let u=Yu(r,n);u=Ju(u,m||n?!1:d,c),r==="textField"||r==="longText"||r==="email"||r==="url"?u=Zu(u,t):(r==="numberField"||r==="amountField")&&(u=Xu(u,t)),t.requireAllChecked?u=u.test("require-all-checked","All options must be selected",b=>{var v;if(b==null||b==="")return!1;const h=((v=t.options)==null?void 0:v.length)||0;return Array.isArray(b)?b.length>=h:h<=1}):t.minChecked&&(u=u.test("min-checked",`Please select at least ${t.minChecked} option(s)`,b=>b==null||b===""?!1:Array.isArray(b)?b.length>=t.minChecked:1>=t.minChecked)),o[l]=u})}),ne.object().shape(o)}const vn=({element:e,validationData:n})=>{const i=oa[e.type],{answerData:o}=x.useContext(Te),s=x.useMemo(()=>{var l;return(l=e==null?void 0:e.acceptedFiles)==null?void 0:l.map(r=>r.label).join(", ")},[e]),t=x.useMemo(()=>So(e,o),[o,e]);return i?a.jsxs("div",{className:`${t?"":"hidden"} min-w-0 w-full`,children:[a.jsx("div",{className:"mb-1.5 min-w-0",children:e.inputLabel&&a.jsxs("label",{className:"block text-sm font-medium input_label",children:[e.inputLabel," ",s&&a.jsxs("span",{className:"text-gray-400 text-xs",children:["(",s==null?void 0:s.toLowerCase(),")"]})]})}),a.jsx(i,{element:e,state:"edit",validationData:{...n,isReadOnly:n.isReadOnly||e.isDisabled}}),e.description&&a.jsx("small",{className:"block text-gray-400 mt-0.5 text-xs",children:e.description})]}):null},hn=(e,n)=>e!=null&&e.allowEdit?{...n,isReadOnly:!1}:n;function Ru({form_data:e,options:n}){const i=(s,t)=>a.jsx("div",{className:"min-w-0",children:a.jsx(ui,{element:s,customClass:"p-0 min-h-[60px] border-none",children:t==null?void 0:t.map(l=>{var r,d,c;return a.jsxs(di,{col:(r=l.gridPosition)==null?void 0:r.col,customClass:"p-0",children:[a.jsx(vn,{element:l,validationData:hn(l,n)}),((c=(d=n==null?void 0:n.errors)==null?void 0:d[l.id])==null?void 0:c.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[l.id].message})]},l.id)})})},s.id),o=s=>{var t,l;return a.jsxs("div",{className:me("group relative grid gap-y-[6px] min-w-0",s.elementClass),children:[a.jsx(vn,{element:s,validationData:hn(s,n)}),((l=(t=n==null?void 0:n.errors)==null?void 0:t[s.id])==null?void 0:l.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[s.id].message})]},s.id)};return a.jsx("div",{className:"grid gap-y-10",children:e==null?void 0:e.map(s=>{var l,r;const t=new Map;return(l=s==null?void 0:s.questionData)==null||l.forEach(d=>{d.gridId&&(t.has(d.gridId)||t.set(d.gridId,[]),t.get(d.gridId).push(d))}),a.jsxs("div",{className:"pb-6 section_box min-w-0",children:[(s.title||s.description)&&a.jsxs("div",{className:"py-4 border-b border-gray-100 mb-7 section_box__title",children:[s.title&&a.jsx("h2",{className:"text-lg font-semibold mb-[4px]",children:s.title}),s.description&&a.jsx("p",{className:"text-sm",children:s.description})]}),a.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,t.get(d.id)||[]):o(d))})]},s.id)})})}function ec({form_data:e,options:n,current:i}){var o,s;return a.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(t=>{var l,r,d,c;if(t.type==="grid"){const m=(r=(l=e[i])==null?void 0:l.questionData)==null?void 0:r.filter(u=>u.gridId===t.id);return a.jsx("div",{className:"min-w-0",children:a.jsx(ui,{element:t,customClass:"p-0 min-h-[60px] border-none",children:m==null?void 0:m.map(u=>{var b,h,v;return a.jsxs(di,{col:(b=u.gridPosition)==null?void 0:b.col,customClass:"p-0",children:[a.jsx(vn,{element:u,validationData:hn(u,n)}),a.jsx("div",{className:"mt-1 text-xs text-red-600",children:(v=(h=n==null?void 0:n.errors)==null?void 0:h[u.id])==null?void 0:v.message})]},u.id)})})},t.id)}return t.gridId?null:a.jsxs("div",{className:me("group relative grid gap-y-[6px] min-w-0",t.elementClass),children:[a.jsx(vn,{element:t,validationData:hn(t,n)}),a.jsx("div",{className:"mt-1 text-xs text-red-600",children:(c=(d=n==null?void 0:n.errors)==null?void 0:d[t.id])==null?void 0:c.message})]},t.id)})})}const wo=Ce("config");function nc({element:e,options:n,onNext:i,onPrev:o,isFirst:s,isLast:t,isReadOnly:l}){if(!e)return a.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 u;return a.jsx("div",{className:"min-w-0 w-full",children:a.jsx(ui,{element:m,customClass:"p-0 min-h-[60px] border-none w-full",children:(u=m.gridChildren)==null?void 0:u.map(b=>{var h,v,p;return a.jsxs(di,{col:(h=b.gridPosition)==null?void 0:h.col,customClass:"p-0",children:[a.jsx(vn,{element:b,validationData:hn(b,n)}),((p=(v=n==null?void 0:n.errors)==null?void 0:v[b.id])==null?void 0:p.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[b.id].message})]},b.id)})})},m.id)},c=m=>{var u,b;return a.jsxs("div",{className:me("group relative grid gap-y-[6px] min-w-0 w-full",m.elementClass),children:[a.jsx(vn,{element:m,validationData:hn(m,n)}),((b=(u=n==null?void 0:n.errors)==null?void 0:u[m.id])==null?void 0:b.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[m.id].message})]},m.id)};return a.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:a.jsxs(le.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:[a.jsx("div",{className:"text-left w-full mb-8",children:e.type==="grid"?d(e):c(e)}),!l&&a.jsxs("div",{className:"flex items-center gap-4 mt-8",children:[a.jsx(Fe,{type:"button",text:t?n!=null&&n.isSubmitting?"Submitting...":"Submit":"OK",onClick:i,style:{background:(wo==null?void 0:wo.buttonColor)||"#333"},btnClass:`text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg ${t?"submit_btn":"continue_btn next_btn text-sm"}`,isDisabled:(n==null?void 0:n.apiActivityCount)>0||t&&(n==null?void 0:n.isSubmitting)}),!t&&a.jsx("span",{className:"text-xs text-gray-400 font-medium hidden sm:inline-block",children:"press Enter ↵"}),!s&&a.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:[a.jsx(te,{icon:"material-symbols:arrow-upward-rounded",iconClass:"text-lg"}),"Back"]})]})]},e.id)})}function ic(e){return e.reduce((n,i)=>(n[i.id]=i.value,n),{})}const oc=({form_data:e,answerData:n=[],ignoreValidation:i=!1,onSubmitData:o,onGetValues:s,isReadOnly:t=!1,renderType:l="multi",children:r,hideFooter:d=!1,uploadUrl:c})=>{var ae,R,j,ee,J,K,$,G,F,V;const{setAnswerData:m,setUploadUrl:u,apiActivityCount:b}=x.useContext(Te),[h,v]=x.useState(0),[p,y]=x.useState(0),f=x.useMemo(()=>e.filter(U=>!U.isHidden).map(U=>{var Q;return U.isDisabled||U.disabled?{...U,questionData:(Q=U==null?void 0:U.questionData)==null?void 0:Q.map(oe=>({...oe,isDisabled:!0}))}:U}),[e]),S=(ae=f==null?void 0:f.length)!=null?ae:0,g=Ce("config"),w=x.useCallback(async(U,Y,Q)=>{const oe=Qu({formData:f,isReadOnly:t,answerData:U});return uo(oe)(U,Y,Q)},[f,t]),N=$e.useForm({resolver:w,mode:"onSubmit",defaultValues:{}}),{register:A,setValue:C,control:E,handleSubmit:k,reset:I,getValues:P,watch:T,formState:{errors:O,isSubmitting:M},trigger:_,setError:B,clearErrors:H}=N,D=$e.useWatch({control:E}),L=x.useMemo(()=>D,[JSON.stringify(D)]),z=x.useMemo(()=>{if(l!=="conversational")return[];const U=[];return f.forEach(Y=>{var Q;(Q=Y==null?void 0:Y.questionData)==null||Q.forEach(oe=>{var ue;if(So(oe,L))if(oe.type==="grid"){const fe=(ue=Y==null?void 0:Y.questionData)==null?void 0:ue.filter(ge=>ge.gridId===oe.id);U.push({...oe,gridChildren:fe})}else oe.gridId||U.push(oe)})}),U},[f,L,l]),q=x.useCallback(U=>{s&&s(U)},[s]);x.useEffect(()=>{u(c)},[u,c]),x.useEffect(()=>{if(!(f!=null&&f.length)||!s)return;const U=f.flatMap(Y=>{var Q;return(Q=Y==null?void 0:Y.questionData)==null?void 0:Q.map(oe=>({id:oe.id,value:L[oe.id]||"",sectionId:Y.id,type:oe.type,metaData:{prefix:oe.prefix,dateFormat:oe.dateFormat}}))});q(U),m(L)},[L,f,q,s,m]),x.useEffect(()=>{n!=null&&n.length&&I(ic(n))},[n,I]);const W=x.useCallback(U=>{const Y=f.flatMap(Q=>{var oe;return(oe=Q==null?void 0:Q.questionData)==null?void 0:oe.map(ue=>({id:ue.id,value:U[ue.id]||"",sectionId:Q.id,type:ue.type,metaData:{prefix:ue.prefix,dateFormat:ue.dateFormat}}))});Object.keys(O).length>0||o==null||o(Y)},[O,f,o]),Z=x.useCallback(async()=>{var U,Y;if(l==="conversational"){if(!i){const Q=z[p];if(!Q)return;const oe=Q.gridChildren?Q.gridChildren.map(fe=>fe.id):[Q.id];if(!await _(oe))return}p<z.length-1?y(Q=>Q+1):k(W)();return}if(!i){const Q=(Y=(U=f==null?void 0:f[h])==null?void 0:U.questionData)==null?void 0:Y.map(ue=>ue.id);if(!await _(Q))return}v(Q=>Q+1)},[h,p,z,f,i,_,l,k,W]),X=x.useCallback(()=>{if(l==="conversational"){y(U=>Math.max(0,U-1));return}v(U=>U-1)},[l]),ie=x.useMemo(()=>({register:A,setValue:C,watch:T,errors:O,trigger:_,isSubmitting:M,isReadOnly:t,getValues:P,setError:B,clearErrors:H,apiActivityCount:b}),[A,C,T,O,_,M,t,P,B,H,b]);return a.jsxs($e.FormProvider,{...N,children:[a.jsx(Ae.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),a.jsxs("form",{onSubmit:k(W),className:"container h-full mx-auto",children:[a.jsx("div",{className:"relative flex flex-col w-full min-w-0 py-4 gap-y-12",children:a.jsxs("div",{className:"multi_section__box min-w-0",children:[l==="multi"&&(((R=f==null?void 0:f[h])==null?void 0:R.title)||((j=f==null?void 0:f[h])==null?void 0:j.description))&&a.jsxs("div",{className:"py-4 mb-4 border-b border-gray-100 multi_section__title",children:[((ee=f[h])==null?void 0:ee.title)&&a.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:(J=f[h])==null?void 0:J.title}),((K=f[h])==null?void 0:K.description)&&a.jsx("p",{className:"text-sm",children:($=f[h])==null?void 0:$.description})]}),l==="multi"?a.jsx(ec,{form_data:f,options:ie,current:h}):l==="conversational"?a.jsx(nc,{element:z[p],options:ie,onNext:Z,onPrev:X,isFirst:p===0,isLast:p===z.length-1,isReadOnly:t}):a.jsx(Ru,{form_data:f,options:ie})]},l==="conversational"?`conv-${p}`:(G=f==null?void 0:f[h])==null?void 0:G.id)}),!d&&l!=="conversational"&&a.jsx("footer",{className:"flex items-center justify-end gap-4 footer flex-wrap",children:l==="multi"?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex gap-x-4 justify-between navigation_container w-full",children:[a.jsxs("div",{children:[" ",h>0&&a.jsxs("button",{type:"button",onClick:X,className:"text-gray-400 hover:text-gray-600 font-medium text-sm flex items-center gap-1 transition-colors back_btn",children:[a.jsx(te,{icon:"material-symbols:arrow-upward-rounded",iconClass:"text-lg"}),"Back"]})]}),h<S-1&&a.jsx(Fe,{type:"button",text:"Next",onClick:Z,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"})]}),(h===S-1||t)&&!i&&((F=typeof r=="function"?r({isUploading:b>0,isSubmitting:M,hasErrors:Object.keys(O).length>0}):r)!=null?F:a.jsx(Fe,{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&&((V=typeof r=="function"?r({isUploading:b>0,isSubmitting:M,hasErrors:Object.keys(O).length>0}):r)!=null?V:a.jsx(Fe,{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&&a.jsx("div",{className:"fixed bottom-0 left-0 w-full h-1.5 bg-gray-200",children:a.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"}})})]})]})},sc=x.memo(oc);function No({answerData:e,form_data:n,ignoreValidation:i,onSubmit:o,isReadOnly:s=!1,loading:t=!1,config:l={buttonColor:"#333"},renderType:r,children:d,hideFooter:c,onGetValues:m,uploadUrl:u}){x.useEffect(()=>{l&&Js("config",l)},[l]);const b=x.useCallback(h=>{m&&m(h)},[m]);return t?a.jsx(yo,{}):n?a.jsxs("div",{className:"w-full h-full min-w-0",children:[a.jsx("div",{id:"root-portal"}),a.jsx(Ss,{children:a.jsx(sc,{form_data:n,answerData:e,ignoreValidation:i,onSubmitData:o,isReadOnly:s,renderType:r,hideFooter:c,onGetValues:b,uploadUrl:u,children:d})})]}):a.jsx("div",{children:a.jsx("p",{className:"p-6 text-sm text-gray-400",children:"Error: No form data available."})})}function ke(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=ke(e[i]))!==""&&(n+=(n&&" ")+o);else for(let i in e)e[i]&&(n+=(n&&" ")+i);return n}var ac={value:()=>{}};function ci(){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 mi(i)}function mi(e){this._=e}function tc(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}})}mi.prototype=ci.prototype={constructor:mi,on:function(e,n){var i=this._,o=tc(e+"",i),s,t=-1,l=o.length;if(arguments.length<2){for(;++t<l;)if((s=(e=o[t]).type)&&(s=lc(i[s],e.name)))return s;return}if(n!=null&&typeof n!="function")throw new Error("invalid callback: "+n);for(;++t<l;)if(s=(e=o[t]).type)i[s]=aa(i[s],e.name,n);else if(n==null)for(s in i)i[s]=aa(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 mi(e)},call:function(e,n){if((s=arguments.length-2)>0)for(var i=new Array(s),o=0,s,t;o<s;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(t=this._[e],o=0,s=t.length;o<s;++o)t[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,t=o.length;s<t;++s)o[s].value.apply(n,i)}};function lc(e,n){for(var i=0,o=e.length,s;i<o;++i)if((s=e[i]).name===n)return s.value}function aa(e,n,i){for(var o=0,s=e.length;o<s;++o)if(e[o].name===n){e[o]=ac,e=e.slice(0,o).concat(e.slice(o+1));break}return i!=null&&e.push({name:n,value:i}),e}var Ao="http://www.w3.org/1999/xhtml";const ta={svg:"http://www.w3.org/2000/svg",xhtml:Ao,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function bi(e){var n=e+="",i=n.indexOf(":");return i>=0&&(n=e.slice(0,i))!=="xmlns"&&(e=e.slice(i+1)),ta.hasOwnProperty(n)?{space:ta[n],local:e}:e}function rc(e){return function(){var n=this.ownerDocument,i=this.namespaceURI;return i===Ao&&n.documentElement.namespaceURI===Ao?n.createElement(e):n.createElementNS(i,e)}}function dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function la(e){var n=bi(e);return(n.local?dc:rc)(n)}function uc(){}function Co(e){return e==null?uc:function(){return this.querySelector(e)}}function cc(e){typeof e!="function"&&(e=Co(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var t=n[s],l=t.length,r=o[s]=new Array(l),d,c,m=0;m<l;++m)(d=t[m])&&(c=e.call(d,d.__data__,m,t))&&("__data__"in d&&(c.__data__=d.__data__),r[m]=c);return new Be(o,this._parents)}function mc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function bc(){return[]}function ra(e){return e==null?bc:function(){return this.querySelectorAll(e)}}function vc(e){return function(){return mc(e.apply(this,arguments))}}function hc(e){typeof e=="function"?e=vc(e):e=ra(e);for(var n=this._groups,i=n.length,o=[],s=[],t=0;t<i;++t)for(var l=n[t],r=l.length,d,c=0;c<r;++c)(d=l[c])&&(o.push(e.call(d,d.__data__,c,l)),s.push(d));return new Be(o,s)}function da(e){return function(){return this.matches(e)}}function ua(e){return function(n){return n.matches(e)}}var fc=Array.prototype.find;function pc(e){return function(){return fc.call(this.children,e)}}function gc(){return this.firstElementChild}function yc(e){return this.select(e==null?gc:pc(typeof e=="function"?e:ua(e)))}var xc=Array.prototype.filter;function Sc(){return Array.from(this.children)}function wc(e){return function(){return xc.call(this.children,e)}}function Nc(e){return this.selectAll(e==null?Sc:wc(typeof e=="function"?e:ua(e)))}function Ac(e){typeof e!="function"&&(e=da(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var t=n[s],l=t.length,r=o[s]=[],d,c=0;c<l;++c)(d=t[c])&&e.call(d,d.__data__,c,t)&&r.push(d);return new Be(o,this._parents)}function ca(e){return new Array(e.length)}function Cc(){return new Be(this._enter||this._groups.map(ca),this._parents)}function vi(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}vi.prototype={constructor:vi,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 kc(e){return function(){return e}}function Mc(e,n,i,o,s,t){for(var l=0,r,d=n.length,c=t.length;l<c;++l)(r=n[l])?(r.__data__=t[l],o[l]=r):i[l]=new vi(e,t[l]);for(;l<d;++l)(r=n[l])&&(s[l]=r)}function Ec(e,n,i,o,s,t,l){var r,d,c=new Map,m=n.length,u=t.length,b=new Array(m),h;for(r=0;r<m;++r)(d=n[r])&&(b[r]=h=l.call(d,d.__data__,r,n)+"",c.has(h)?s[r]=d:c.set(h,d));for(r=0;r<u;++r)h=l.call(e,t[r],r,t)+"",(d=c.get(h))?(o[r]=d,d.__data__=t[r],c.delete(h)):i[r]=new vi(e,t[r]);for(r=0;r<m;++r)(d=n[r])&&c.get(b[r])===d&&(s[r]=d)}function Tc(e){return e.__data__}function Pc(e,n){if(!arguments.length)return Array.from(this,Tc);var i=n?Ec:Mc,o=this._parents,s=this._groups;typeof e!="function"&&(e=kc(e));for(var t=s.length,l=new Array(t),r=new Array(t),d=new Array(t),c=0;c<t;++c){var m=o[c],u=s[c],b=u.length,h=Lc(e.call(m,m&&m.__data__,c,o)),v=h.length,p=r[c]=new Array(v),y=l[c]=new Array(v),f=d[c]=new Array(b);i(m,u,p,y,f,h,n);for(var S=0,g=0,w,N;S<v;++S)if(w=p[S]){for(S>=g&&(g=S+1);!(N=y[g])&&++g<v;);w._next=N||null}}return l=new Be(l,o),l._enter=r,l._exit=d,l}function Lc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Bc(){return new Be(this._exit||this._groups.map(ca),this._parents)}function Ic(e,n,i){var o=this.enter(),s=this,t=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?t.remove():i(t),o&&s?o.merge(s).order():s}function Dc(e){for(var n=e.selection?e.selection():e,i=this._groups,o=n._groups,s=i.length,t=o.length,l=Math.min(s,t),r=new Array(s),d=0;d<l;++d)for(var c=i[d],m=o[d],u=c.length,b=r[d]=new Array(u),h,v=0;v<u;++v)(h=c[v]||m[v])&&(b[v]=h);for(;d<s;++d)r[d]=i[d];return new Be(r,this._parents)}function _c(){for(var e=this._groups,n=-1,i=e.length;++n<i;)for(var o=e[n],s=o.length-1,t=o[s],l;--s>=0;)(l=o[s])&&(t&&l.compareDocumentPosition(t)^4&&t.parentNode.insertBefore(l,t),t=l);return this}function Oc(e){e||(e=Kc);function n(u,b){return u&&b?e(u.__data__,b.__data__):!u-!b}for(var i=this._groups,o=i.length,s=new Array(o),t=0;t<o;++t){for(var l=i[t],r=l.length,d=s[t]=new Array(r),c,m=0;m<r;++m)(c=l[m])&&(d[m]=c);d.sort(n)}return new Be(s,this._parents).order()}function Kc(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function Hc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Gc(){return Array.from(this)}function Fc(){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var o=e[n],s=0,t=o.length;s<t;++s){var l=o[s];if(l)return l}return null}function Vc(){let e=0;for(const n of this)++e;return e}function zc(){return!this.node()}function Wc(e){for(var n=this._groups,i=0,o=n.length;i<o;++i)for(var s=n[i],t=0,l=s.length,r;t<l;++t)(r=s[t])&&e.call(r,r.__data__,t,s);return this}function $c(e){return function(){this.removeAttribute(e)}}function jc(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Uc(e,n){return function(){this.setAttribute(e,n)}}function qc(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function Yc(e,n){return function(){var i=n.apply(this,arguments);i==null?this.removeAttribute(e):this.setAttribute(e,i)}}function Jc(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 Zc(e,n){var i=bi(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?jc:$c:typeof n=="function"?i.local?Jc:Yc:i.local?qc:Uc)(i,n))}function ma(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Xc(e){return function(){this.style.removeProperty(e)}}function Qc(e,n,i){return function(){this.style.setProperty(e,n,i)}}function Rc(e,n,i){return function(){var o=n.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,i)}}function em(e,n,i){return arguments.length>1?this.each((n==null?Xc:typeof n=="function"?Rc:Qc)(e,n,i==null?"":i)):fn(this.node(),e)}function fn(e,n){return e.style.getPropertyValue(n)||ma(e).getComputedStyle(e,null).getPropertyValue(n)}function nm(e){return function(){delete this[e]}}function im(e,n){return function(){this[e]=n}}function om(e,n){return function(){var i=n.apply(this,arguments);i==null?delete this[e]:this[e]=i}}function sm(e,n){return arguments.length>1?this.each((n==null?nm:typeof n=="function"?om:im)(e,n)):this.node()[e]}function ba(e){return e.trim().split(/^|\s+/)}function ko(e){return e.classList||new va(e)}function va(e){this._node=e,this._names=ba(e.getAttribute("class")||"")}va.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 ha(e,n){for(var i=ko(e),o=-1,s=n.length;++o<s;)i.add(n[o])}function fa(e,n){for(var i=ko(e),o=-1,s=n.length;++o<s;)i.remove(n[o])}function am(e){return function(){ha(this,e)}}function tm(e){return function(){fa(this,e)}}function lm(e,n){return function(){(n.apply(this,arguments)?ha:fa)(this,e)}}function rm(e,n){var i=ba(e+"");if(arguments.length<2){for(var o=ko(this.node()),s=-1,t=i.length;++s<t;)if(!o.contains(i[s]))return!1;return!0}return this.each((typeof n=="function"?lm:n?am:tm)(i,n))}function dm(){this.textContent=""}function um(e){return function(){this.textContent=e}}function cm(e){return function(){var n=e.apply(this,arguments);this.textContent=n==null?"":n}}function mm(e){return arguments.length?this.each(e==null?dm:(typeof e=="function"?cm:um)(e)):this.node().textContent}function bm(){this.innerHTML=""}function vm(e){return function(){this.innerHTML=e}}function hm(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n==null?"":n}}function fm(e){return arguments.length?this.each(e==null?bm:(typeof e=="function"?hm:vm)(e)):this.node().innerHTML}function pm(){this.nextSibling&&this.parentNode.appendChild(this)}function gm(){return this.each(pm)}function ym(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function xm(){return this.each(ym)}function Sm(e){var n=typeof e=="function"?e:la(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function wm(){return null}function Nm(e,n){var i=typeof e=="function"?e:la(e),o=n==null?wm:typeof n=="function"?n:Co(n);return this.select(function(){return this.insertBefore(i.apply(this,arguments),o.apply(this,arguments)||null)})}function Am(){var e=this.parentNode;e&&e.removeChild(this)}function Cm(){return this.each(Am)}function km(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Mm(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Em(e){return this.select(e?Mm:km)}function Tm(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Pm(e){return function(n){e.call(this,n,this.__data__)}}function Lm(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 Bm(e){return function(){var n=this.__on;if(n){for(var i=0,o=-1,s=n.length,t;i<s;++i)t=n[i],(!e.type||t.type===e.type)&&t.name===e.name?this.removeEventListener(t.type,t.listener,t.options):n[++o]=t;++o?n.length=o:delete this.__on}}}function Im(e,n,i){return function(){var o=this.__on,s,t=Pm(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=t,s.options=i),s.value=n;return}}this.addEventListener(e.type,t,i),s={type:e.type,name:e.name,value:n,listener:t,options:i},o?o.push(s):this.__on=[s]}}function Dm(e,n,i){var o=Lm(e+""),s,t=o.length,l;if(arguments.length<2){var r=this.node().__on;if(r){for(var d=0,c=r.length,m;d<c;++d)for(s=0,m=r[d];s<t;++s)if((l=o[s]).type===m.type&&l.name===m.name)return m.value}return}for(r=n?Im:Bm,s=0;s<t;++s)this.each(r(o[s],n,i));return this}function pa(e,n,i){var o=ma(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 _m(e,n){return function(){return pa(this,e,n)}}function Om(e,n){return function(){return pa(this,e,n.apply(this,arguments))}}function Km(e,n){return this.each((typeof n=="function"?Om:_m)(e,n))}function*Hm(){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var o=e[n],s=0,t=o.length,l;s<t;++s)(l=o[s])&&(yield l)}var ga=[null];function Be(e,n){this._groups=e,this._parents=n}function Dn(){return new Be([[document.documentElement]],ga)}function Gm(){return this}Be.prototype=Dn.prototype={constructor:Be,select:cc,selectAll:hc,selectChild:yc,selectChildren:Nc,filter:Ac,data:Pc,enter:Cc,exit:Bc,join:Ic,merge:Dc,selection:Gm,order:_c,sort:Oc,call:Hc,nodes:Gc,node:Fc,size:Vc,empty:zc,each:Wc,attr:Zc,style:em,property:sm,classed:rm,text:mm,html:fm,raise:gm,lower:xm,append:Sm,insert:Nm,remove:Cm,clone:Em,datum:Tm,on:Dm,dispatch:Km,[Symbol.iterator]:Hm};function Ie(e){return typeof e=="string"?new Be([[document.querySelector(e)]],[document.documentElement]):new Be([[e]],ga)}function Fm(e){let n;for(;n=e.sourceEvent;)e=n;return e}function _e(e,n){if(e=Fm(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 Vm={passive:!1},_n={capture:!0,passive:!1};function Mo(e){e.stopImmediatePropagation()}function pn(e){e.preventDefault(),e.stopImmediatePropagation()}function ya(e){var n=e.document.documentElement,i=Ie(e).on("dragstart.drag",pn,_n);"onselectstart"in n?i.on("selectstart.drag",pn,_n):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function xa(e,n){var i=e.document.documentElement,o=Ie(e).on("dragstart.drag",null);n&&(o.on("click.drag",pn,_n),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 hi=e=>()=>e;function Eo(e,{sourceEvent:n,subject:i,target:o,identifier:s,active:t,x:l,y:r,dx:d,dy:c,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:t,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:c,enumerable:!0,configurable:!0},_:{value:m}})}Eo.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function zm(e){return!e.ctrlKey&&!e.button}function Wm(){return this.parentNode}function $m(e,n){return n==null?{x:e.x,y:e.y}:n}function jm(){return navigator.maxTouchPoints||"ontouchstart"in this}function Sa(){var e=zm,n=Wm,i=$m,o=jm,s={},t=ci("start","drag","end"),l=0,r,d,c,m,u=0;function b(w){w.on("mousedown.drag",h).filter(o).on("touchstart.drag",y).on("touchmove.drag",f,Vm).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(w,N){if(!(m||!e.call(this,w,N))){var A=g(this,n.call(this,w,N),w,N,"mouse");A&&(Ie(w.view).on("mousemove.drag",v,_n).on("mouseup.drag",p,_n),ya(w.view),Mo(w),c=!1,r=w.clientX,d=w.clientY,A("start",w))}}function v(w){if(pn(w),!c){var N=w.clientX-r,A=w.clientY-d;c=N*N+A*A>u}s.mouse("drag",w)}function p(w){Ie(w.view).on("mousemove.drag mouseup.drag",null),xa(w.view,c),pn(w),s.mouse("end",w)}function y(w,N){if(e.call(this,w,N)){var A=w.changedTouches,C=n.call(this,w,N),E=A.length,k,I;for(k=0;k<E;++k)(I=g(this,C,w,N,A[k].identifier,A[k]))&&(Mo(w),I("start",w,A[k]))}}function f(w){var N=w.changedTouches,A=N.length,C,E;for(C=0;C<A;++C)(E=s[N[C].identifier])&&(pn(w),E("drag",w,N[C]))}function S(w){var N=w.changedTouches,A=N.length,C,E;for(m&&clearTimeout(m),m=setTimeout(function(){m=null},500),C=0;C<A;++C)(E=s[N[C].identifier])&&(Mo(w),E("end",w,N[C]))}function g(w,N,A,C,E,k){var I=t.copy(),P=_e(k||A,N),T,O,M;if((M=i.call(w,new Eo("beforestart",{sourceEvent:A,target:b,identifier:E,active:l,x:P[0],y:P[1],dx:0,dy:0,dispatch:I}),C))!=null)return T=M.x-P[0]||0,O=M.y-P[1]||0,function _(B,H,D){var L=P,z;switch(B){case"start":s[E]=_,z=l++;break;case"end":delete s[E],--l;case"drag":P=_e(D||H,N),z=l;break}I.call(B,w,new Eo(B,{sourceEvent:H,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:I}),C)}}return b.filter=function(w){return arguments.length?(e=typeof w=="function"?w:hi(!!w),b):e},b.container=function(w){return arguments.length?(n=typeof w=="function"?w:hi(w),b):n},b.subject=function(w){return arguments.length?(i=typeof w=="function"?w:hi(w),b):i},b.touchable=function(w){return arguments.length?(o=typeof w=="function"?w:hi(!!w),b):o},b.on=function(){var w=t.on.apply(t,arguments);return w===t?b:w},b.clickDistance=function(w){return arguments.length?(u=(w=+w)*w,b):Math.sqrt(u)},b}function To(e,n,i){e.prototype=n.prototype=i,i.constructor=e}function wa(e,n){var i=Object.create(e.prototype);for(var o in n)i[o]=n[o];return i}function On(){}var Kn=.7,fi=1/Kn,gn="\\s*([+-]?\\d+)\\s*",Hn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ve="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Um=/^#([0-9a-f]{3,8})$/,qm=new RegExp(`^rgb\\(${gn},${gn},${gn}\\)$`),Ym=new RegExp(`^rgb\\(${Ve},${Ve},${Ve}\\)$`),Jm=new RegExp(`^rgba\\(${gn},${gn},${gn},${Hn}\\)$`),Zm=new RegExp(`^rgba\\(${Ve},${Ve},${Ve},${Hn}\\)$`),Xm=new RegExp(`^hsl\\(${Hn},${Ve},${Ve}\\)$`),Qm=new RegExp(`^hsla\\(${Hn},${Ve},${Ve},${Hn}\\)$`),Na={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};To(On,nn,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Aa,formatHex:Aa,formatHex8:Rm,formatHsl:eb,formatRgb:Ca,toString:Ca});function Aa(){return this.rgb().formatHex()}function Rm(){return this.rgb().formatHex8()}function eb(){return Pa(this).formatHsl()}function Ca(){return this.rgb().formatRgb()}function nn(e){var n,i;return e=(e+"").trim().toLowerCase(),(n=Um.exec(e))?(i=n[1].length,n=parseInt(n[1],16),i===6?ka(n):i===3?new Le(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):i===8?pi(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):i===4?pi(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=qm.exec(e))?new Le(n[1],n[2],n[3],1):(n=Ym.exec(e))?new Le(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=Jm.exec(e))?pi(n[1],n[2],n[3],n[4]):(n=Zm.exec(e))?pi(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=Xm.exec(e))?Ta(n[1],n[2]/100,n[3]/100,1):(n=Qm.exec(e))?Ta(n[1],n[2]/100,n[3]/100,n[4]):Na.hasOwnProperty(e)?ka(Na[e]):e==="transparent"?new Le(NaN,NaN,NaN,0):null}function ka(e){return new Le(e>>16&255,e>>8&255,e&255,1)}function pi(e,n,i,o){return o<=0&&(e=n=i=NaN),new Le(e,n,i,o)}function nb(e){return e instanceof On||(e=nn(e)),e?(e=e.rgb(),new Le(e.r,e.g,e.b,e.opacity)):new Le}function Po(e,n,i,o){return arguments.length===1?nb(e):new Le(e,n,i,o==null?1:o)}function Le(e,n,i,o){this.r=+e,this.g=+n,this.b=+i,this.opacity=+o}To(Le,Po,wa(On,{brighter(e){return e=e==null?fi:Math.pow(fi,e),new Le(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kn:Math.pow(Kn,e),new Le(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Le(on(this.r),on(this.g),on(this.b),gi(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:Ma,formatHex:Ma,formatHex8:ib,formatRgb:Ea,toString:Ea}));function Ma(){return`#${sn(this.r)}${sn(this.g)}${sn(this.b)}`}function ib(){return`#${sn(this.r)}${sn(this.g)}${sn(this.b)}${sn((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ea(){const e=gi(this.opacity);return`${e===1?"rgb(":"rgba("}${on(this.r)}, ${on(this.g)}, ${on(this.b)}${e===1?")":`, ${e})`}`}function gi(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function on(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function sn(e){return e=on(e),(e<16?"0":"")+e.toString(16)}function Ta(e,n,i,o){return o<=0?e=n=i=NaN:i<=0||i>=1?e=n=NaN:n<=0&&(e=NaN),new Oe(e,n,i,o)}function Pa(e){if(e instanceof Oe)return new Oe(e.h,e.s,e.l,e.opacity);if(e instanceof On||(e=nn(e)),!e)return new Oe;if(e instanceof Oe)return e;e=e.rgb();var n=e.r/255,i=e.g/255,o=e.b/255,s=Math.min(n,i,o),t=Math.max(n,i,o),l=NaN,r=t-s,d=(t+s)/2;return r?(n===t?l=(i-o)/r+(i<o)*6:i===t?l=(o-n)/r+2:l=(n-i)/r+4,r/=d<.5?t+s:2-t-s,l*=60):r=d>0&&d<1?0:l,new Oe(l,r,d,e.opacity)}function ob(e,n,i,o){return arguments.length===1?Pa(e):new Oe(e,n,i,o==null?1:o)}function Oe(e,n,i,o){this.h=+e,this.s=+n,this.l=+i,this.opacity=+o}To(Oe,ob,wa(On,{brighter(e){return e=e==null?fi:Math.pow(fi,e),new Oe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kn:Math.pow(Kn,e),new Oe(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 Le(Lo(e>=240?e-240:e+120,s,o),Lo(e,s,o),Lo(e<120?e+240:e-120,s,o),this.opacity)},clamp(){return new Oe(La(this.h),yi(this.s),yi(this.l),gi(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=gi(this.opacity);return`${e===1?"hsl(":"hsla("}${La(this.h)}, ${yi(this.s)*100}%, ${yi(this.l)*100}%${e===1?")":`, ${e})`}`}}));function La(e){return e=(e||0)%360,e<0?e+360:e}function yi(e){return Math.max(0,Math.min(1,e||0))}function Lo(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 Bo=e=>()=>e;function sb(e,n){return function(i){return e+i*n}}function ab(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 tb(e){return(e=+e)==1?Ba:function(n,i){return i-n?ab(n,i,e):Bo(isNaN(n)?i:n)}}function Ba(e,n){var i=n-e;return i?sb(e,i):Bo(isNaN(e)?n:e)}const xi=function e(n){var i=tb(n);function o(s,t){var l=i((s=Po(s)).r,(t=Po(t)).r),r=i(s.g,t.g),d=i(s.b,t.b),c=Ba(s.opacity,t.opacity);return function(m){return s.r=l(m),s.g=r(m),s.b=d(m),s.opacity=c(m),s+""}}return o.gamma=e,o}(1);function lb(e,n){n||(n=[]);var i=e?Math.min(n.length,e.length):0,o=n.slice(),s;return function(t){for(s=0;s<i;++s)o[s]=e[s]*(1-t)+n[s]*t;return o}}function rb(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function db(e,n){var i=n?n.length:0,o=e?Math.min(i,e.length):0,s=new Array(o),t=new Array(i),l;for(l=0;l<o;++l)s[l]=Gn(e[l],n[l]);for(;l<i;++l)t[l]=n[l];return function(r){for(l=0;l<o;++l)t[l]=s[l](r);return t}}function ub(e,n){var i=new Date;return e=+e,n=+n,function(o){return i.setTime(e*(1-o)+n*o),i}}function ze(e,n){return e=+e,n=+n,function(i){return e*(1-i)+n*i}}function cb(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]=Gn(e[s],n[s]):o[s]=n[s];return function(t){for(s in i)o[s]=i[s](t);return o}}var Io=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Do=new RegExp(Io.source,"g");function mb(e){return function(){return e}}function bb(e){return function(n){return e(n)+""}}function Ia(e,n){var i=Io.lastIndex=Do.lastIndex=0,o,s,t,l=-1,r=[],d=[];for(e=e+"",n=n+"";(o=Io.exec(e))&&(s=Do.exec(n));)(t=s.index)>i&&(t=n.slice(i,t),r[l]?r[l]+=t:r[++l]=t),(o=o[0])===(s=s[0])?r[l]?r[l]+=s:r[++l]=s:(r[++l]=null,d.push({i:l,x:ze(o,s)})),i=Do.lastIndex;return i<n.length&&(t=n.slice(i),r[l]?r[l]+=t:r[++l]=t),r.length<2?d[0]?bb(d[0].x):mb(n):(n=d.length,function(c){for(var m=0,u;m<n;++m)r[(u=d[m]).i]=u.x(c);return r.join("")})}function Gn(e,n){var i=typeof n,o;return n==null||i==="boolean"?Bo(n):(i==="number"?ze:i==="string"?(o=nn(n))?(n=o,xi):Ia:n instanceof nn?xi:n instanceof Date?ub:rb(n)?lb:Array.isArray(n)?db:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?cb:ze)(e,n)}var Da=180/Math.PI,_o={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function _a(e,n,i,o,s,t){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:t,rotate:Math.atan2(n,e)*Da,skewX:Math.atan(d)*Da,scaleX:l,scaleY:r}}var Si;function vb(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?_o:_a(n.a,n.b,n.c,n.d,n.e,n.f)}function hb(e){return e==null||(Si||(Si=document.createElementNS("http://www.w3.org/2000/svg","g")),Si.setAttribute("transform",e),!(e=Si.transform.baseVal.consolidate()))?_o:(e=e.matrix,_a(e.a,e.b,e.c,e.d,e.e,e.f))}function Oa(e,n,i,o){function s(c){return c.length?c.pop()+" ":""}function t(c,m,u,b,h,v){if(c!==u||m!==b){var p=h.push("translate(",null,n,null,i);v.push({i:p-4,x:ze(c,u)},{i:p-2,x:ze(m,b)})}else(u||b)&&h.push("translate("+u+n+b+i)}function l(c,m,u,b){c!==m?(c-m>180?m+=360:m-c>180&&(c+=360),b.push({i:u.push(s(u)+"rotate(",null,o)-2,x:ze(c,m)})):m&&u.push(s(u)+"rotate("+m+o)}function r(c,m,u,b){c!==m?b.push({i:u.push(s(u)+"skewX(",null,o)-2,x:ze(c,m)}):m&&u.push(s(u)+"skewX("+m+o)}function d(c,m,u,b,h,v){if(c!==u||m!==b){var p=h.push(s(h)+"scale(",null,",",null,")");v.push({i:p-4,x:ze(c,u)},{i:p-2,x:ze(m,b)})}else(u!==1||b!==1)&&h.push(s(h)+"scale("+u+","+b+")")}return function(c,m){var u=[],b=[];return c=e(c),m=e(m),t(c.translateX,c.translateY,m.translateX,m.translateY,u,b),l(c.rotate,m.rotate,u,b),r(c.skewX,m.skewX,u,b),d(c.scaleX,c.scaleY,m.scaleX,m.scaleY,u,b),c=m=null,function(h){for(var v=-1,p=b.length,y;++v<p;)u[(y=b[v]).i]=y.x(h);return u.join("")}}}var fb=Oa(vb,"px, ","px)","deg)"),pb=Oa(hb,", ",")",")"),gb=1e-12;function Ka(e){return((e=Math.exp(e))+1/e)/2}function yb(e){return((e=Math.exp(e))-1/e)/2}function xb(e){return((e=Math.exp(2*e))-1)/(e+1)}const wi=function e(n,i,o){function s(t,l){var r=t[0],d=t[1],c=t[2],m=l[0],u=l[1],b=l[2],h=m-r,v=u-d,p=h*h+v*v,y,f;if(p<gb)f=Math.log(b/c)/n,y=function(C){return[r+C*h,d+C*v,c*Math.exp(n*C*f)]};else{var S=Math.sqrt(p),g=(b*b-c*c+o*p)/(2*c*i*S),w=(b*b-c*c-o*p)/(2*b*i*S),N=Math.log(Math.sqrt(g*g+1)-g),A=Math.log(Math.sqrt(w*w+1)-w);f=(A-N)/n,y=function(C){var E=C*f,k=Ka(N),I=c/(i*S)*(k*xb(n*E+N)-yb(N));return[r+I*h,d+I*v,c*k/Ka(n*E+N)]}}return y.duration=f*1e3*n/Math.SQRT2,y}return s.rho=function(t){var l=Math.max(.001,+t),r=l*l,d=r*r;return e(l,r,d)},s}(Math.SQRT2,2,4);var yn=0,Fn=0,Vn=0,Ha=1e3,Ni,zn,Ai=0,an=0,Ci=0,Wn=typeof performance=="object"&&performance.now?performance:Date,Ga=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Oo(){return an||(Ga(Sb),an=Wn.now()+Ci)}function Sb(){an=0}function ki(){this._call=this._time=this._next=null}ki.prototype=Fa.prototype={constructor:ki,restart:function(e,n,i){if(typeof e!="function")throw new TypeError("callback is not a function");i=(i==null?Oo():+i)+(n==null?0:+n),!this._next&&zn!==this&&(zn?zn._next=this:Ni=this,zn=this),this._call=e,this._time=i,Ko()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ko())}};function Fa(e,n,i){var o=new ki;return o.restart(e,n,i),o}function wb(){Oo(),++yn;for(var e=Ni,n;e;)(n=an-e._time)>=0&&e._call.call(void 0,n),e=e._next;--yn}function Va(){an=(Ai=Wn.now())+Ci,yn=Fn=0;try{wb()}finally{yn=0,Ab(),an=0}}function Nb(){var e=Wn.now(),n=e-Ai;n>Ha&&(Ci-=n,Ai=e)}function Ab(){for(var e,n=Ni,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:Ni=i);zn=e,Ko(o)}function Ko(e){if(!yn){Fn&&(Fn=clearTimeout(Fn));var n=e-an;n>24?(e<1/0&&(Fn=setTimeout(Va,e-Wn.now()-Ci)),Vn&&(Vn=clearInterval(Vn))):(Vn||(Ai=Wn.now(),Vn=setInterval(Nb,Ha)),yn=1,Ga(Va))}}function za(e,n,i){var o=new ki;return n=n==null?0:+n,o.restart(s=>{o.stop(),e(s+n)},n,i),o}var Cb=ci("start","end","cancel","interrupt"),kb=[],Wa=0,$a=1,Ho=2,Mi=3,ja=4,Go=5,Ei=6;function Ti(e,n,i,o,s,t){var l=e.__transition;if(!l)e.__transition={};else if(i in l)return;Mb(e,i,{name:n,index:o,group:s,on:Cb,tween:kb,time:t.time,delay:t.delay,duration:t.duration,ease:t.ease,timer:null,state:Wa})}function Fo(e,n){var i=Ke(e,n);if(i.state>Wa)throw new Error("too late; already scheduled");return i}function We(e,n){var i=Ke(e,n);if(i.state>Mi)throw new Error("too late; already running");return i}function Ke(e,n){var i=e.__transition;if(!i||!(i=i[n]))throw new Error("transition not found");return i}function Mb(e,n,i){var o=e.__transition,s;o[n]=i,i.timer=Fa(t,0,i.time);function t(c){i.state=$a,i.timer.restart(l,i.delay,i.time),i.delay<=c&&l(c-i.delay)}function l(c){var m,u,b,h;if(i.state!==$a)return d();for(m in o)if(h=o[m],h.name===i.name){if(h.state===Mi)return za(l);h.state===ja?(h.state=Ei,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete o[m]):+m<n&&(h.state=Ei,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete o[m])}if(za(function(){i.state===Mi&&(i.state=ja,i.timer.restart(r,i.delay,i.time),r(c))}),i.state=Ho,i.on.call("start",e,e.__data__,i.index,i.group),i.state===Ho){for(i.state=Mi,s=new Array(b=i.tween.length),m=0,u=-1;m<b;++m)(h=i.tween[m].value.call(e,e.__data__,i.index,i.group))&&(s[++u]=h);s.length=u+1}}function r(c){for(var m=c<i.duration?i.ease.call(null,c/i.duration):(i.timer.restart(d),i.state=Go,1),u=-1,b=s.length;++u<b;)s[u].call(e,m);i.state===Go&&(i.on.call("end",e,e.__data__,i.index,i.group),d())}function d(){i.state=Ei,i.timer.stop(),delete o[n];for(var c in o)return;delete e.__transition}}function Pi(e,n){var i=e.__transition,o,s,t=!0,l;if(i){n=n==null?null:n+"";for(l in i){if((o=i[l]).name!==n){t=!1;continue}s=o.state>Ho&&o.state<Go,o.state=Ei,o.timer.stop(),o.on.call(s?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete i[l]}t&&delete e.__transition}}function Eb(e){return this.each(function(){Pi(this,e)})}function Tb(e,n){var i,o;return function(){var s=We(this,e),t=s.tween;if(t!==i){o=i=t;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 Pb(e,n,i){var o,s;if(typeof i!="function")throw new Error;return function(){var t=We(this,e),l=t.tween;if(l!==o){s=(o=l).slice();for(var r={name:n,value:i},d=0,c=s.length;d<c;++d)if(s[d].name===n){s[d]=r;break}d===c&&s.push(r)}t.tween=s}}function Lb(e,n){var i=this._id;if(e+="",arguments.length<2){for(var o=Ke(this.node(),i).tween,s=0,t=o.length,l;s<t;++s)if((l=o[s]).name===e)return l.value;return null}return this.each((n==null?Tb:Pb)(i,e,n))}function Vo(e,n,i){var o=e._id;return e.each(function(){var s=We(this,o);(s.value||(s.value={}))[n]=i.apply(this,arguments)}),function(s){return Ke(s,o).value[n]}}function Ua(e,n){var i;return(typeof n=="number"?ze:n instanceof nn?xi:(i=nn(n))?(n=i,xi):Ia)(e,n)}function Bb(e){return function(){this.removeAttribute(e)}}function Ib(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Db(e,n,i){var o,s=i+"",t;return function(){var l=this.getAttribute(e);return l===s?null:l===o?t:t=n(o=l,i)}}function _b(e,n,i){var o,s=i+"",t;return function(){var l=this.getAttributeNS(e.space,e.local);return l===s?null:l===o?t:t=n(o=l,i)}}function Ob(e,n,i){var o,s,t;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?t:(s=d,t=n(o=l,r)))}}function Kb(e,n,i){var o,s,t;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?t:(s=d,t=n(o=l,r)))}}function Hb(e,n){var i=bi(e),o=i==="transform"?pb:Ua;return this.attrTween(e,typeof n=="function"?(i.local?Kb:Ob)(i,o,Vo(this,"attr."+e,n)):n==null?(i.local?Ib:Bb)(i):(i.local?_b:Db)(i,o,n))}function Gb(e,n){return function(i){this.setAttribute(e,n.call(this,i))}}function Fb(e,n){return function(i){this.setAttributeNS(e.space,e.local,n.call(this,i))}}function Vb(e,n){var i,o;function s(){var t=n.apply(this,arguments);return t!==o&&(i=(o=t)&&Fb(e,t)),i}return s._value=n,s}function zb(e,n){var i,o;function s(){var t=n.apply(this,arguments);return t!==o&&(i=(o=t)&&Gb(e,t)),i}return s._value=n,s}function Wb(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=bi(e);return this.tween(i,(o.local?Vb:zb)(o,n))}function $b(e,n){return function(){Fo(this,e).delay=+n.apply(this,arguments)}}function jb(e,n){return n=+n,function(){Fo(this,e).delay=n}}function Ub(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?$b:jb)(n,e)):Ke(this.node(),n).delay}function qb(e,n){return function(){We(this,e).duration=+n.apply(this,arguments)}}function Yb(e,n){return n=+n,function(){We(this,e).duration=n}}function Jb(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?qb:Yb)(n,e)):Ke(this.node(),n).duration}function Zb(e,n){if(typeof n!="function")throw new Error;return function(){We(this,e).ease=n}}function Xb(e){var n=this._id;return arguments.length?this.each(Zb(n,e)):Ke(this.node(),n).ease}function Qb(e,n){return function(){var i=n.apply(this,arguments);if(typeof i!="function")throw new Error;We(this,e).ease=i}}function Rb(e){if(typeof e!="function")throw new Error;return this.each(Qb(this._id,e))}function ev(e){typeof e!="function"&&(e=da(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var t=n[s],l=t.length,r=o[s]=[],d,c=0;c<l;++c)(d=t[c])&&e.call(d,d.__data__,c,t)&&r.push(d);return new je(o,this._parents,this._name,this._id)}function nv(e){if(e._id!==this._id)throw new Error;for(var n=this._groups,i=e._groups,o=n.length,s=i.length,t=Math.min(o,s),l=new Array(o),r=0;r<t;++r)for(var d=n[r],c=i[r],m=d.length,u=l[r]=new Array(m),b,h=0;h<m;++h)(b=d[h]||c[h])&&(u[h]=b);for(;r<o;++r)l[r]=n[r];return new je(l,this._parents,this._name,this._id)}function iv(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 ov(e,n,i){var o,s,t=iv(n)?Fo:We;return function(){var l=t(this,e),r=l.on;r!==o&&(s=(o=r).copy()).on(n,i),l.on=s}}function sv(e,n){var i=this._id;return arguments.length<2?Ke(this.node(),i).on.on(e):this.each(ov(i,e,n))}function av(e){return function(){var n=this.parentNode;for(var i in this.__transition)if(+i!==e)return;n&&n.removeChild(this)}}function tv(){return this.on("end.remove",av(this._id))}function lv(e){var n=this._name,i=this._id;typeof e!="function"&&(e=Co(e));for(var o=this._groups,s=o.length,t=new Array(s),l=0;l<s;++l)for(var r=o[l],d=r.length,c=t[l]=new Array(d),m,u,b=0;b<d;++b)(m=r[b])&&(u=e.call(m,m.__data__,b,r))&&("__data__"in m&&(u.__data__=m.__data__),c[b]=u,Ti(c[b],n,i,b,c,Ke(m,i)));return new je(t,this._parents,n,i)}function rv(e){var n=this._name,i=this._id;typeof e!="function"&&(e=ra(e));for(var o=this._groups,s=o.length,t=[],l=[],r=0;r<s;++r)for(var d=o[r],c=d.length,m,u=0;u<c;++u)if(m=d[u]){for(var b=e.call(m,m.__data__,u,d),h,v=Ke(m,i),p=0,y=b.length;p<y;++p)(h=b[p])&&Ti(h,n,i,p,b,v);t.push(b),l.push(m)}return new je(t,l,n,i)}var dv=Dn.prototype.constructor;function uv(){return new dv(this._groups,this._parents)}function cv(e,n){var i,o,s;return function(){var t=fn(this,e),l=(this.style.removeProperty(e),fn(this,e));return t===l?null:t===i&&l===o?s:s=n(i=t,o=l)}}function qa(e){return function(){this.style.removeProperty(e)}}function mv(e,n,i){var o,s=i+"",t;return function(){var l=fn(this,e);return l===s?null:l===o?t:t=n(o=l,i)}}function bv(e,n,i){var o,s,t;return function(){var l=fn(this,e),r=i(this),d=r+"";return r==null&&(d=r=(this.style.removeProperty(e),fn(this,e))),l===d?null:l===o&&d===s?t:(s=d,t=n(o=l,r))}}function vv(e,n){var i,o,s,t="style."+n,l="end."+t,r;return function(){var d=We(this,e),c=d.on,m=d.value[t]==null?r||(r=qa(n)):void 0;(c!==i||s!==m)&&(o=(i=c).copy()).on(l,s=m),d.on=o}}function hv(e,n,i){var o=(e+="")=="transform"?fb:Ua;return n==null?this.styleTween(e,cv(e,o)).on("end.style."+e,qa(e)):typeof n=="function"?this.styleTween(e,bv(e,o,Vo(this,"style."+e,n))).each(vv(this._id,e)):this.styleTween(e,mv(e,o,n),i).on("end.style."+e,null)}function fv(e,n,i){return function(o){this.style.setProperty(e,n.call(this,o),i)}}function pv(e,n,i){var o,s;function t(){var l=n.apply(this,arguments);return l!==s&&(o=(s=l)&&fv(e,l,i)),o}return t._value=n,t}function gv(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,pv(e,n,i==null?"":i))}function yv(e){return function(){this.textContent=e}}function xv(e){return function(){var n=e(this);this.textContent=n==null?"":n}}function Sv(e){return this.tween("text",typeof e=="function"?xv(Vo(this,"text",e)):yv(e==null?"":e+""))}function wv(e){return function(n){this.textContent=e.call(this,n)}}function Nv(e){var n,i;function o(){var s=e.apply(this,arguments);return s!==i&&(n=(i=s)&&wv(s)),n}return o._value=e,o}function Av(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,Nv(e))}function Cv(){for(var e=this._name,n=this._id,i=Ya(),o=this._groups,s=o.length,t=0;t<s;++t)for(var l=o[t],r=l.length,d,c=0;c<r;++c)if(d=l[c]){var m=Ke(d,n);Ti(d,e,i,c,l,{time:m.time+m.delay+m.duration,delay:0,duration:m.duration,ease:m.ease})}return new je(o,this._parents,e,i)}function kv(){var e,n,i=this,o=i._id,s=i.size();return new Promise(function(t,l){var r={value:l},d={value:function(){--s===0&&t()}};i.each(function(){var c=We(this,o),m=c.on;m!==e&&(n=(e=m).copy(),n._.cancel.push(r),n._.interrupt.push(r),n._.end.push(d)),c.on=n}),s===0&&t()})}var Mv=0;function je(e,n,i,o){this._groups=e,this._parents=n,this._name=i,this._id=o}function Ya(){return++Mv}var Ue=Dn.prototype;je.prototype={constructor:je,select:lv,selectAll:rv,selectChild:Ue.selectChild,selectChildren:Ue.selectChildren,filter:ev,merge:nv,selection:uv,transition:Cv,call:Ue.call,nodes:Ue.nodes,node:Ue.node,size:Ue.size,empty:Ue.empty,each:Ue.each,on:sv,attr:Hb,attrTween:Wb,style:hv,styleTween:gv,text:Sv,textTween:Av,remove:tv,tween:Lb,delay:Ub,duration:Jb,ease:Xb,easeVarying:Rb,end:kv,[Symbol.iterator]:Ue[Symbol.iterator]};function Ev(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Tv={time:null,delay:0,duration:250,ease:Ev};function Pv(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 Lv(e){var n,i;e instanceof je?(n=e._id,e=e._name):(n=Ya(),(i=Tv).time=Oo(),e=e==null?null:e+"");for(var o=this._groups,s=o.length,t=0;t<s;++t)for(var l=o[t],r=l.length,d,c=0;c<r;++c)(d=l[c])&&Ti(d,e,n,c,l,i||Pv(d,n));return new je(o,this._parents,e,n)}Dn.prototype.interrupt=Eb,Dn.prototype.transition=Lv;const Li=e=>()=>e;function Bv(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 qe(e,n,i){this.k=e,this.x=n,this.y=i}qe.prototype={constructor:qe,scale:function(e){return e===1?this:new qe(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new qe(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 Bi=new qe(1,0,0);Ja.prototype=qe.prototype;function Ja(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Bi;return e.__zoom}function zo(e){e.stopImmediatePropagation()}function $n(e){e.preventDefault(),e.stopImmediatePropagation()}function Iv(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Dv(){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 Za(){return this.__zoom||Bi}function _v(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Ov(){return navigator.maxTouchPoints||"ontouchstart"in this}function Kv(e,n,i){var o=e.invertX(n[0][0])-i[0][0],s=e.invertX(n[1][0])-i[1][0],t=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>t?(t+l)/2:Math.min(0,t)||Math.max(0,l))}function Xa(){var e=Iv,n=Dv,i=Kv,o=_v,s=Ov,t=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],r=250,d=wi,c=ci("start","zoom","end"),m,u,b,h=500,v=150,p=0,y=10;function f(M){M.property("__zoom",Za).on("wheel.zoom",E,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",I).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,_,B,H){var D=M.selection?M.selection():M;D.property("__zoom",Za),M!==D?N(M,_,B,H):D.interrupt().each(function(){A(this,arguments).event(H).start().zoom(null,typeof _=="function"?_.apply(this,arguments):_).end()})},f.scaleBy=function(M,_,B,H){f.scaleTo(M,function(){var D=this.__zoom.k,L=typeof _=="function"?_.apply(this,arguments):_;return D*L},B,H)},f.scaleTo=function(M,_,B,H){f.transform(M,function(){var D=n.apply(this,arguments),L=this.__zoom,z=B==null?w(D):typeof B=="function"?B.apply(this,arguments):B,q=L.invert(z),W=typeof _=="function"?_.apply(this,arguments):_;return i(g(S(L,W),z,q),D,l)},B,H)},f.translateBy=function(M,_,B,H){f.transform(M,function(){return i(this.__zoom.translate(typeof _=="function"?_.apply(this,arguments):_,typeof B=="function"?B.apply(this,arguments):B),n.apply(this,arguments),l)},null,H)},f.translateTo=function(M,_,B,H,D){f.transform(M,function(){var L=n.apply(this,arguments),z=this.__zoom,q=H==null?w(L):typeof H=="function"?H.apply(this,arguments):H;return i(Bi.translate(q[0],q[1]).scale(z.k).translate(typeof _=="function"?-_.apply(this,arguments):-_,typeof B=="function"?-B.apply(this,arguments):-B),L,l)},H,D)};function S(M,_){return _=Math.max(t[0],Math.min(t[1],_)),_===M.k?M:new qe(_,M.x,M.y)}function g(M,_,B){var H=_[0]-B[0]*M.k,D=_[1]-B[1]*M.k;return H===M.x&&D===M.y?M:new qe(M.k,H,D)}function w(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function N(M,_,B,H){M.on("start.zoom",function(){A(this,arguments).event(H).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(H).end()}).tween("zoom",function(){var D=this,L=arguments,z=A(D,L).event(H),q=n.apply(D,L),W=B==null?w(q):typeof B=="function"?B.apply(D,L):B,Z=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),X=D.__zoom,ie=typeof _=="function"?_.apply(D,L):_,ae=d(X.invert(W).concat(Z/X.k),ie.invert(W).concat(Z/ie.k));return function(R){if(R===1)R=ie;else{var j=ae(R),ee=Z/j[2];R=new qe(ee,W[0]-j[0]*ee,W[1]-j[1]*ee)}z.zoom(null,R)}})}function A(M,_,B){return!B&&M.__zooming||new C(M,_)}function C(M,_){this.that=M,this.args=_,this.active=0,this.sourceEvent=null,this.extent=n.apply(M,_),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,_){return this.mouse&&M!=="mouse"&&(this.mouse[1]=_.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=_.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=_.invert(this.touch1[0])),this.that.__zoom=_,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var _=Ie(this.that).datum();c.call(M,this.that,new Bv(M,{sourceEvent:this.sourceEvent,target:f,transform:this.that.__zoom,dispatch:c}),_)}};function E(M,..._){if(!e.apply(this,arguments))return;var B=A(this,_).event(M),H=this.__zoom,D=Math.max(t[0],Math.min(t[1],H.k*Math.pow(2,o.apply(this,arguments)))),L=_e(M);if(B.wheel)(B.mouse[0][0]!==L[0]||B.mouse[0][1]!==L[1])&&(B.mouse[1]=H.invert(B.mouse[0]=L)),clearTimeout(B.wheel);else{if(H.k===D)return;B.mouse=[L,H.invert(L)],Pi(this),B.start()}$n(M),B.wheel=setTimeout(z,v),B.zoom("mouse",i(g(S(H,D),B.mouse[0],B.mouse[1]),B.extent,l));function z(){B.wheel=null,B.end()}}function k(M,..._){if(b||!e.apply(this,arguments))return;var B=M.currentTarget,H=A(this,_,!0).event(M),D=Ie(M.view).on("mousemove.zoom",W,!0).on("mouseup.zoom",Z,!0),L=_e(M,B),z=M.clientX,q=M.clientY;ya(M.view),zo(M),H.mouse=[L,this.__zoom.invert(L)],Pi(this),H.start();function W(X){if($n(X),!H.moved){var ie=X.clientX-z,ae=X.clientY-q;H.moved=ie*ie+ae*ae>p}H.event(X).zoom("mouse",i(g(H.that.__zoom,H.mouse[0]=_e(X,B),H.mouse[1]),H.extent,l))}function Z(X){D.on("mousemove.zoom mouseup.zoom",null),xa(X.view,H.moved),$n(X),H.event(X).end()}}function I(M,..._){if(e.apply(this,arguments)){var B=this.__zoom,H=_e(M.changedTouches?M.changedTouches[0]:M,this),D=B.invert(H),L=B.k*(M.shiftKey?.5:2),z=i(g(S(B,L),H,D),n.apply(this,_),l);$n(M),r>0?Ie(this).transition().duration(r).call(N,z,H,M):Ie(this).call(f.transform,z,H,M)}}function P(M,..._){if(e.apply(this,arguments)){var B=M.touches,H=B.length,D=A(this,_,M.changedTouches.length===H).event(M),L,z,q,W;for(zo(M),z=0;z<H;++z)q=B[z],W=_e(q,this),W=[W,this.__zoom.invert(W),q.identifier],D.touch0?!D.touch1&&D.touch0[2]!==W[2]&&(D.touch1=W,D.taps=0):(D.touch0=W,L=!0,D.taps=1+!!m);m&&(m=clearTimeout(m)),L&&(D.taps<2&&(u=W[0],m=setTimeout(function(){m=null},h)),Pi(this),D.start())}}function T(M,..._){if(this.__zooming){var B=A(this,_).event(M),H=M.changedTouches,D=H.length,L,z,q,W;for($n(M),L=0;L<D;++L)z=H[L],q=_e(z,this),B.touch0&&B.touch0[2]===z.identifier?B.touch0[0]=q:B.touch1&&B.touch1[2]===z.identifier&&(B.touch1[0]=q);if(z=B.that.__zoom,B.touch1){var Z=B.touch0[0],X=B.touch0[1],ie=B.touch1[0],ae=B.touch1[1],R=(R=ie[0]-Z[0])*R+(R=ie[1]-Z[1])*R,j=(j=ae[0]-X[0])*j+(j=ae[1]-X[1])*j;z=S(z,Math.sqrt(R/j)),q=[(Z[0]+ie[0])/2,(Z[1]+ie[1])/2],W=[(X[0]+ae[0])/2,(X[1]+ae[1])/2]}else if(B.touch0)q=B.touch0[0],W=B.touch0[1];else return;B.zoom("touch",i(g(z,q,W),B.extent,l))}}function O(M,..._){if(this.__zooming){var B=A(this,_).event(M),H=M.changedTouches,D=H.length,L,z;for(zo(M),b&&clearTimeout(b),b=setTimeout(function(){b=null},h),L=0;L<D;++L)z=H[L],B.touch0&&B.touch0[2]===z.identifier?delete B.touch0:B.touch1&&B.touch1[2]===z.identifier&&delete B.touch1;if(B.touch1&&!B.touch0&&(B.touch0=B.touch1,delete B.touch1),B.touch0)B.touch0[1]=this.__zoom.invert(B.touch0[0]);else if(B.end(),B.taps===2&&(z=_e(z,this),Math.hypot(u[0]-z[0],u[1]-z[1])<y)){var q=Ie(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return f.wheelDelta=function(M){return arguments.length?(o=typeof M=="function"?M:Li(+M),f):o},f.filter=function(M){return arguments.length?(e=typeof M=="function"?M:Li(!!M),f):e},f.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:Li(!!M),f):s},f.extent=function(M){return arguments.length?(n=typeof M=="function"?M:Li([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),f):n},f.scaleExtent=function(M){return arguments.length?(t[0]=+M[0],t[1]=+M[1],f):[t[0],t[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=c.on.apply(c,arguments);return M===c?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 De={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.`},jn=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Qa=["Enter"," ","Escape"],Ra={"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 xn;(function(e){e.Strict="strict",e.Loose="loose"})(xn||(xn={}));var tn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(tn||(tn={}));var Un;(function(e){e.Partial="partial",e.Full="full"})(Un||(Un={}));const et={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Ze;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Ze||(Ze={}));var Sn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Sn||(Sn={}));var se;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(se||(se={}));const nt={[se.Left]:se.Right,[se.Right]:se.Left,[se.Top]:se.Bottom,[se.Bottom]:se.Top};function it(e){return e===null?null:e?"valid":"invalid"}const ot=e=>"id"in e&&"source"in e&&"target"in e,Hv=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Wo=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),qn=(e,n=[0,0])=>{var r;const{width:i,height:o}=Ye(e),s=(r=e.origin)!=null?r:n,t=i*s[0],l=o*s[1];return{x:e.position.x-t,y:e.position.y-l}},Gv=(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 t=typeof s=="string";let l=!n.nodeLookup&&!t?s:void 0;n.nodeLookup&&(l=t?n.nodeLookup.get(s):Wo(s)?s:n.nodeLookup.get(s.id));const r=l?_i(l,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Ii(o,r)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Di(i)},Yn=(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=Ii(i,_i(s)),o=!0)}),o?Di(i):{x:0,y:0,width:0,height:0}},$o=(e,n,[i,o,s]=[0,0,1],t=!1,l=!1)=>{var b,h,v,p,y,f;const r=(n.x-i)/s,d=(n.y-o)/s,c=n.width/s,m=n.height/s,u=[];for(const S of e.values()){const{measured:g,selectable:w=!0,hidden:N=!1}=S;if(l&&!w||N)continue;const A=(v=(h=(b=g.width)!=null?b:S.width)!=null?h:S.initialWidth)!=null?v:0,C=(f=(y=(p=g.height)!=null?p:S.height)!=null?y:S.initialHeight)!=null?f:0,{x:E,y:k}=S.internals.positionAbsolute,I=rt(r,d,c,m,E,k,A,C),P=A*C,T=t&&I>0;(!S.internals.handleBounds||T||I>=P||S.dragging)&&u.push(S)}return u},Fv=(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 Vv(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 zv({nodes:e,width:n,height:i,panZoom:o,minZoom:s,maxZoom:t},l){var m,u,b;if(e.size===0)return!0;const r=Vv(e,l),d=Yn(r),c=qo(d,n,i,(m=l==null?void 0:l.minZoom)!=null?m:s,(u=l==null?void 0:l.maxZoom)!=null?u:t,(b=l==null?void 0:l.padding)!=null?b:.1);return await o.setViewport(c,{duration:l==null?void 0:l.duration,ease:l==null?void 0:l.ease,interpolate:l==null?void 0:l.interpolate}),!0}function st({nodeId:e,nextPosition:n,nodeLookup:i,nodeOrigin:o=[0,0],nodeExtent:s,onError:t}){var h,v,p;const l=i.get(e),r=l.parentId?i.get(l.parentId):void 0,{x:d,y:c}=r?r.internals.positionAbsolute:{x:0,y:0},m=(h=l.origin)!=null?h:o;let u=l.extent||s;if(l.extent==="parent"&&!l.expandParent)if(!r)t==null||t("005",De.error005());else{const y=r.measured.width,f=r.measured.height;y&&f&&(u=[[d,c],[d+y,c+f]])}else r&&rn(l.extent)&&(u=[[l.extent[0][0]+d,l.extent[0][1]+c],[l.extent[1][0]+d,l.extent[1][1]+c]]);const b=rn(u)?ln(n,u,l.measured):n;return(l.measured.width===void 0||l.measured.height===void 0)&&(t==null||t("015",De.error015())),{position:{x:b.x-d+((v=l.measured.width)!=null?v:0)*m[0],y:b.y-c+((p=l.measured.height)!=null?p:0)*m[1]},positionAbsolute:b}}async function Wv({nodesToRemove:e=[],edgesToRemove:n=[],nodes:i,edges:o,onBeforeDelete:s}){const t=new Set(e.map(b=>b.id)),l=[];for(const b of i){if(b.deletable===!1)continue;const h=t.has(b.id),v=!h&&b.parentId&&l.find(p=>p.id===b.parentId);(h||v)&&l.push(b)}const r=new Set(n.map(b=>b.id)),d=o.filter(b=>b.deletable!==!1),m=Fv(l,d);for(const b of d)r.has(b.id)&&!m.find(v=>v.id===b.id)&&m.push(b);if(!s)return{edges:m,nodes:l};const u=await s({nodes:l,edges:m});return typeof u=="boolean"?u?{edges:m,nodes:l}:{edges:[],nodes:[]}:u}const wn=(e,n=0,i=1)=>Math.min(Math.max(e,n),i),ln=(e={x:0,y:0},n,i)=>{var o,s;return{x:wn(e.x,n[0][0],n[1][0]-((o=i==null?void 0:i.width)!=null?o:0)),y:wn(e.y,n[0][1],n[1][1]-((s=i==null?void 0:i.height)!=null?s:0))}};function at(e,n,i){const{width:o,height:s}=Ye(i),{x:t,y:l}=i.internals.positionAbsolute;return ln(e,[[t,l],[t+o,l+s]],n)}const tt=(e,n,i)=>e<n?wn(Math.abs(e-n),1,n)/n:e>i?-wn(Math.abs(e-i),1,n)/n:0,jo=(e,n,i=15,o=40)=>{const s=tt(e.x,o,n.width-o)*i,t=tt(e.y,o,n.height-o)*i;return[s,t]},Ii=(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)}),Uo=({x:e,y:n,width:i,height:o})=>({x:e,y:n,x2:e+i,y2:n+o}),Di=({x:e,y:n,x2:i,y2:o})=>({x:e,y:n,width:i-e,height:o-n}),Jn=(e,n=[0,0])=>{var s,t,l,r,d,c,m,u;const{x:i,y:o}=Wo(e)?e.internals.positionAbsolute:qn(e,n);return{x:i,y:o,width:(r=(l=(t=(s=e.measured)==null?void 0:s.width)!=null?t:e.width)!=null?l:e.initialWidth)!=null?r:0,height:(u=(m=(c=(d=e.measured)==null?void 0:d.height)!=null?c:e.height)!=null?m:e.initialHeight)!=null?u:0}},_i=(e,n=[0,0])=>{var s,t,l,r,d,c,m,u;const{x:i,y:o}=Wo(e)?e.internals.positionAbsolute:qn(e,n);return{x:i,y:o,x2:i+((r=(l=(t=(s=e.measured)==null?void 0:s.width)!=null?t:e.width)!=null?l:e.initialWidth)!=null?r:0),y2:o+((u=(m=(c=(d=e.measured)==null?void 0:d.height)!=null?c:e.height)!=null?m:e.initialHeight)!=null?u:0)}},lt=(e,n)=>Di(Ii(Uo(e),Uo(n))),rt=(e,n,i,o,s,t,l,r)=>{const d=Math.max(0,Math.min(e+i,s+l)-Math.max(e,s)),c=Math.max(0,Math.min(n+o,t+r)-Math.max(n,t));return Math.ceil(d*c)},Oi=(e,n)=>rt(e.x,e.y,e.width,e.height,n.x,n.y,n.width,n.height),dt=e=>He(e.width)&&He(e.height)&&He(e.x)&&He(e.y),He=e=>!isNaN(e)&&isFinite(e),ut=(e,n)=>(i,o)=>{process.env.NODE_ENV==="development"&&console.warn(`[${e}]: ${o} Help: ${n}error#${i}`)},Zn=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Xn=({x:e,y:n},[i,o,s],t=!1,l=[1,1])=>{const r={x:(e-i)/s,y:(n-o)/s};return t?Zn(r,l):r},Nn=({x:e,y:n},[i,o,s])=>({x:e*s+i,y:n*s+o});function An(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 $v(e,n,i){var o,s,t,l,r,d,c,m;if(typeof e=="string"||typeof e=="number"){const u=An(e,i),b=An(e,n);return{top:u,right:b,bottom:u,left:b,x:b*2,y:u*2}}if(typeof e=="object"){const u=An((s=(o=e.top)!=null?o:e.y)!=null?s:0,i),b=An((l=(t=e.bottom)!=null?t:e.y)!=null?l:0,i),h=An((d=(r=e.left)!=null?r:e.x)!=null?d:0,n),v=An((m=(c=e.right)!=null?c:e.x)!=null?m:0,n);return{top:u,right:v,bottom:b,left:h,x:h+v,y:u+b}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function jv(e,n,i,o,s,t){const{x:l,y:r}=Nn(e,[n,i,o]),{x:d,y:c}=Nn({x:e.x+e.width,y:e.y+e.height},[n,i,o]),m=s-d,u=t-c;return{left:Math.floor(l),top:Math.floor(r),right:Math.floor(m),bottom:Math.floor(u)}}const qo=(e,n,i,o,s,t)=>{const l=$v(t,n,i),r=(n-l.x)/e.width,d=(i-l.y)/e.height,c=Math.min(r,d),m=wn(c,o,s),u=e.x+e.width/2,b=e.y+e.height/2,h=n/2-u*m,v=i/2-b*m,p=jv(e,h,v,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:h-y.left+y.right,y:v-y.top+y.bottom,zoom:m}},Qn=()=>{var e;return typeof navigator!="undefined"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function rn(e){return e!=null&&e!=="parent"}function Ye(e){var n,i,o,s,t,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=(t=e.measured)==null?void 0:t.height)!=null?l:e.height)!=null?r:e.initialHeight)!=null?d:0}}function ct(e){var n,i,o,s,t,l;return((o=(i=(n=e.measured)==null?void 0:n.width)!=null?i:e.width)!=null?o:e.initialWidth)!==void 0&&((l=(t=(s=e.measured)==null?void 0:s.height)!=null?t:e.height)!=null?l:e.initialHeight)!==void 0}function mt(e,n={width:0,height:0},i,o,s){var r,d;const t={...e},l=o.get(i);if(l){const c=l.origin||s;t.x+=l.internals.positionAbsolute.x-((r=n.width)!=null?r:0)*c[0],t.y+=l.internals.positionAbsolute.y-((d=n.height)!=null?d:0)*c[1]}return t}function bt(e,n){if(e.size!==n.size)return!1;for(const i of e)if(!n.has(i))return!1;return!0}function Uv(){let e,n;return{promise:new Promise((o,s)=>{e=o,n=s}),resolve:e,reject:n}}function qv(e){return{...Ra,...e||{}}}function Rn(e,{snapGrid:n=[0,0],snapToGrid:i=!1,transform:o,containerBounds:s}){var m,u;const{x:t,y:l}=Ge(e),r=Xn({x:t-((m=s==null?void 0:s.left)!=null?m:0),y:l-((u=s==null?void 0:s.top)!=null?u:0)},o),{x:d,y:c}=i?Zn(r,n):r;return{xSnapped:d,ySnapped:c,...r}}const Yo=e=>({width:e.offsetWidth,height:e.offsetHeight}),vt=e=>{var n;return((n=e==null?void 0:e.getRootNode)==null?void 0:n.call(e))||(window==null?void 0:window.document)},Yv=["INPUT","SELECT","TEXTAREA"];function ht(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:Yv.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const ft=e=>"clientX"in e,Ge=(e,n)=>{var t,l,r,d;const i=ft(e),o=i?e.clientX:(t=e.touches)==null?void 0:t[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)}},pt=(e,n,i,o,s)=>{const t=n.querySelectorAll(`.${e}`);return!t||!t.length?null:Array.from(t).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,...Yo(l)}})};function gt({sourceX:e,sourceY:n,targetX:i,targetY:o,sourceControlX:s,sourceControlY:t,targetControlX:l,targetControlY:r}){const d=e*.125+s*.375+l*.375+i*.125,c=n*.125+t*.375+r*.375+o*.125,m=Math.abs(d-e),u=Math.abs(c-n);return[d,c,m,u]}function Ki(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function yt({pos:e,x1:n,y1:i,x2:o,y2:s,c:t}){switch(e){case se.Left:return[n-Ki(n-o,t),i];case se.Right:return[n+Ki(o-n,t),i];case se.Top:return[n,i-Ki(i-s,t)];case se.Bottom:return[n,i+Ki(s-i,t)]}}function xt({sourceX:e,sourceY:n,sourcePosition:i=se.Bottom,targetX:o,targetY:s,targetPosition:t=se.Top,curvature:l=.25}){const[r,d]=yt({pos:i,x1:e,y1:n,x2:o,y2:s,c:l}),[c,m]=yt({pos:t,x1:o,y1:s,x2:e,y2:n,c:l}),[u,b,h,v]=gt({sourceX:e,sourceY:n,targetX:o,targetY:s,sourceControlX:r,sourceControlY:d,targetControlX:c,targetControlY:m});return[`M${e},${n} C${r},${d} ${c},${m} ${o},${s}`,u,b,h,v]}function St({sourceX:e,sourceY:n,targetX:i,targetY:o}){const s=Math.abs(i-e)/2,t=i<e?i+s:i-s,l=Math.abs(o-n)/2,r=o<n?o+l:o-l;return[t,r,s,l]}function Jv({sourceNode:e,targetNode:n,selected:i=!1,zIndex:o=0,elevateOnSelect:s=!1,zIndexMode:t="basic"}){if(t==="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 Zv({sourceNode:e,targetNode:n,width:i,height:o,transform:s}){const t=Ii(_i(e),_i(n));t.x===t.x2&&(t.x2+=1),t.y===t.y2&&(t.y2+=1);const l={x:-s[0]/s[2],y:-s[1]/s[2],width:i/s[2],height:o/s[2]};return Oi(l,Di(t))>0}const Xv=({source:e,sourceHandle:n,target:i,targetHandle:o})=>`xy-edge__${e}${n||""}-${i}${o||""}`,Qv=(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)),Rv=(e,n,i={})=>{var t;if(!e.source||!e.target)return(t=i.onError)==null||t.call(i,"006",De.error006()),n;const o=i.getEdgeId||Xv;let s;return ot(e)?s={...e}:s={...e,id:o(e)},Qv(s,n)?n:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,n.concat(s))};function wt({sourceX:e,sourceY:n,targetX:i,targetY:o}){const[s,t,l,r]=St({sourceX:e,sourceY:n,targetX:i,targetY:o});return[`M ${e},${n}L ${i},${o}`,s,t,l,r]}const Nt={[se.Left]:{x:-1,y:0},[se.Right]:{x:1,y:0},[se.Top]:{x:0,y:-1},[se.Bottom]:{x:0,y:1}},eh=({source:e,sourcePosition:n=se.Bottom,target:i})=>n===se.Left||n===se.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},At=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function nh({source:e,sourcePosition:n=se.Bottom,target:i,targetPosition:o=se.Top,center:s,offset:t,stepPosition:l}){var E,k,I,P;const r=Nt[n],d=Nt[o],c={x:e.x+r.x*t,y:e.y+r.y*t},m={x:i.x+d.x*t,y:i.y+d.y*t},u=eh({source:c,sourcePosition:n,target:m}),b=u.x!==0?"x":"y",h=u[b];let v=[],p,y;const f={x:0,y:0},S={x:0,y:0},[,,g,w]=St({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:c.x+(m.x-c.x)*l,y=(k=s.y)!=null?k:(c.y+m.y)/2):(p=(I=s.x)!=null?I:(c.x+m.x)/2,y=(P=s.y)!=null?P:c.y+(m.y-c.y)*l);const T=[{x:p,y:c.y},{x:p,y:m.y}],O=[{x:c.x,y},{x:m.x,y}];r[b]===h?v=b==="x"?T:O:v=b==="x"?O:T}else{const T=[{x:c.x,y:m.y}],O=[{x:m.x,y:c.y}];if(b==="x"?v=r.x===h?O:T:v=r.y===h?T:O,n===o){const D=Math.abs(e[b]-i[b]);if(D<=t){const L=Math.min(t-1,t-D);r[b]===h?f[b]=(c[b]>e[b]?-1:1)*L:S[b]=(m[b]>i[b]?-1:1)*L}}if(n!==o){const D=b==="x"?"y":"x",L=r[b]===d[D],z=c[D]>m[D],q=c[D]<m[D];(r[b]===1&&(!L&&z||L&&q)||r[b]!==1&&(!L&&q||L&&z))&&(v=b==="x"?T:O)}const M={x:c.x+f.x,y:c.y+f.y},_={x:m.x+S.x,y:m.y+S.y},B=Math.max(Math.abs(M.x-v[0].x),Math.abs(_.x-v[0].x)),H=Math.max(Math.abs(M.y-v[0].y),Math.abs(_.y-v[0].y));B>=H?(p=(M.x+_.x)/2,y=v[0].y):(p=v[0].x,y=(M.y+_.y)/2)}const N={x:c.x+f.x,y:c.y+f.y},A={x:m.x+S.x,y:m.y+S.y};return[[e,...N.x!==v[0].x||N.y!==v[0].y?[N]:[],...v,...A.x!==v[v.length-1].x||A.y!==v[v.length-1].y?[A]:[],i],p,y,g,w]}function ih(e,n,i,o){const s=Math.min(At(e,n)/2,At(n,i)/2,o),{x:t,y:l}=n;if(e.x===t&&t===i.x||e.y===l&&l===i.y)return`L${t} ${l}`;if(e.y===l){const c=e.x<i.x?-1:1,m=e.y<i.y?1:-1;return`L ${t+s*c},${l}Q ${t},${l} ${t},${l+s*m}`}const r=e.x<i.x?1:-1,d=e.y<i.y?-1:1;return`L ${t},${l+s*d}Q ${t},${l} ${t+s*r},${l}`}function Jo({sourceX:e,sourceY:n,sourcePosition:i=se.Bottom,targetX:o,targetY:s,targetPosition:t=se.Top,borderRadius:l=5,centerX:r,centerY:d,offset:c=20,stepPosition:m=.5}){const[u,b,h,v,p]=nh({source:{x:e,y:n},sourcePosition:i,target:{x:o,y:s},targetPosition:t,center:{x:r,y:d},offset:c,stepPosition:m});let y=`M${u[0].x} ${u[0].y}`;for(let f=1;f<u.length-1;f++)y+=ih(u[f-1],u[f],u[f+1],l);return y+=`L${u[u.length-1].x} ${u[u.length-1].y}`,[y,b,h,v,p]}function Ct(e){var n;return e&&!!(e.internals.handleBounds||(n=e.handles)!=null&&n.length)&&!!(e.measured.width||e.width||e.initialWidth)}function oh(e){var u,b,h,v,p;const{sourceNode:n,targetNode:i}=e;if(!Ct(n)||!Ct(i))return null;const o=n.internals.handleBounds||kt(n.handles),s=i.internals.handleBounds||kt(i.handles),t=Mt((u=o==null?void 0:o.source)!=null?u:[],e.sourceHandle),l=Mt(e.connectionMode===xn.Strict?(b=s==null?void 0:s.target)!=null?b:[]:((h=s==null?void 0:s.target)!=null?h:[]).concat((v=s==null?void 0:s.source)!=null?v:[]),e.targetHandle);if(!t||!l)return(p=e.onError)==null||p.call(e,"008",De.error008(t?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const r=(t==null?void 0:t.position)||se.Bottom,d=(l==null?void 0:l.position)||se.Top,c=dn(n,t,r),m=dn(i,l,d);return{sourceX:c.x,sourceY:c.y,targetX:m.x,targetY:m.y,sourcePosition:r,targetPosition:d}}function kt(e){var o,s;if(!e)return null;const n=[],i=[];for(const t of e)t.width=(o=t.width)!=null?o:1,t.height=(s=t.height)!=null?s:1,t.type==="source"?n.push(t):t.type==="target"&&i.push(t);return{source:n,target:i}}function dn(e,n,i=se.Left,o=!1){var c,m,u;const s=((c=n==null?void 0:n.x)!=null?c:0)+e.internals.positionAbsolute.x,t=((m=n==null?void 0:n.y)!=null?m:0)+e.internals.positionAbsolute.y,{width:l,height:r}=n!=null?n:Ye(e);if(o)return{x:s+l/2,y:t+r/2};switch((u=n==null?void 0:n.position)!=null?u:i){case se.Top:return{x:s+l/2,y:t};case se.Right:return{x:s+l,y:t+r/2};case se.Bottom:return{x:s+l/2,y:t+r};case se.Left:return{x:s,y:t+r/2}}}function Mt(e,n){return e&&(n?e.find(i=>i.id===n):e[0])||null}function Zo(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function sh(e,{id:n,defaultColor:i,defaultMarkerStart:o,defaultMarkerEnd:s}){const t=new Set;return e.reduce((l,r)=>([r.markerStart||o,r.markerEnd||s].forEach(d=>{if(d&&typeof d=="object"){const c=Zo(d,n);t.has(c)||(l.push({id:c,color:d.color||i,...d}),t.add(c))}}),l),[]).sort((l,r)=>l.id.localeCompare(r.id))}const Et=1e3,ah=10,Xo={nodeOrigin:[0,0],nodeExtent:jn,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},th={...Xo,checkEquality:!0};function Qo(e,n){const i={...e};for(const o in n)n[o]!==void 0&&(i[o]=n[o]);return i}function lh(e,n,i){const o=Qo(Xo,i);for(const s of e.values())if(s.parentId)ns(s,e,n,o);else{const t=qn(s,o.nodeOrigin),l=rn(s.extent)?s.extent:o.nodeExtent,r=ln(t,l,Ye(s));s.internals.positionAbsolute=r}}function rh(e,n){var s,t;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:(t=l.height)!=null?t: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 Ro(e){return e==="manual"}function es(e,n,i,o={}){var m,u,b;const s=Qo(th,o),t={i:0},l=new Map(n),r=s!=null&&s.elevateNodesOnSelect&&!Ro(s.zIndexMode)?Et:0;let d=e.length>0,c=!1;n.clear(),i.clear();for(const h of e){let v=l.get(h.id);if(s.checkEquality&&h===(v==null?void 0:v.internals.userNode))n.set(h.id,v);else{const p=qn(h,s.nodeOrigin),y=rn(h.extent)?h.extent:s.nodeExtent,f=ln(p,y,Ye(h));v={...s.defaults,...h,measured:{width:(m=h.measured)==null?void 0:m.width,height:(u=h.measured)==null?void 0:u.height},internals:{positionAbsolute:f,handleBounds:rh(h,v),z:Tt(h,r,s.zIndexMode),userNode:h}},n.set(h.id,v)}(v.measured===void 0||v.measured.width===void 0||v.measured.height===void 0)&&!v.hidden&&(d=!1),h.parentId&&ns(v,n,i,o,t),c||(c=(b=h.selected)!=null?b:!1)}return{nodesInitialized:d,hasSelectedNodes:c}}function dh(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 ns(e,n,i,o,s){const{elevateNodesOnSelect:t,nodeOrigin:l,nodeExtent:r,zIndexMode:d}=Qo(Xo,o),c=e.parentId,m=n.get(c);if(!m){console.warn(`Parent node ${c} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}dh(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*ah),s&&m.internals.rootParentIndex!==void 0&&(s.i=m.internals.rootParentIndex);const u=t&&!Ro(d)?Et:0,{x:b,y:h,z:v}=uh(e,m,l,r,u,d),{positionAbsolute:p}=e.internals,y=b!==p.x||h!==p.y;(y||v!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:y?{x:b,y:h}:p,z:v}})}function Tt(e,n,i){const o=He(e.zIndex)?e.zIndex:0;return Ro(i)?o:o+(e.selected?n:0)}function uh(e,n,i,o,s,t){var v;const{x:l,y:r}=n.internals.positionAbsolute,d=Ye(e),c=qn(e,i),m=rn(e.extent)?ln(c,e.extent,d):c;let u=ln({x:l+m.x,y:r+m.y},o,d);e.extent==="parent"&&(u=at(u,d,n));const b=Tt(e,s,t),h=(v=n.internals.z)!=null?v:0;return{x:u.x,y:u.y,z:h>=b?h+1:b}}function is(e,n,i,o=[0,0]){var l,r;const s=[],t=new Map;for(const d of e){const c=n.get(d.parentId);if(!c)continue;const m=(r=(l=t.get(d.parentId))==null?void 0:l.expandedRect)!=null?r:Jn(c),u=lt(m,d.rect);t.set(d.parentId,{expandedRect:u,parent:c})}return t.size>0&&t.forEach(({expandedRect:d,parent:c},m)=>{var w,N;const u=c.internals.positionAbsolute,b=Ye(c),h=(w=c.origin)!=null?w:o,v=d.x<u.x?Math.round(Math.abs(u.x-d.x)):0,p=d.y<u.y?Math.round(Math.abs(u.y-d.y)):0,y=Math.max(b.width,Math.round(d.width)),f=Math.max(b.height,Math.round(d.height)),S=(y-b.width)*h[0],g=(f-b.height)*h[1];(v>0||p>0||S||g)&&(s.push({id:m,type:"position",position:{x:c.position.x-v+S,y:c.position.y-p+g}}),(N=i.get(m))==null||N.forEach(A=>{e.some(C=>C.id===A.id)||s.push({id:A.id,type:"position",position:{x:A.position.x+v,y:A.position.y+p}})})),(b.width<d.width||b.height<d.height||v||p)&&s.push({id:m,type:"dimensions",setAttributes:!0,dimensions:{width:y+(v?h[0]*v-S:0),height:f+(p?h[1]*p-g:0)}})}),s}function ch(e,n,i,o,s,t,l){const r=o==null?void 0:o.querySelector(".xyflow__viewport");let d=!1;if(!r)return{changes:[],updatedInternals:d};const c=[],m=window.getComputedStyle(r),{m22:u}=new window.DOMMatrixReadOnly(m.transform),b=[];for(const h of e.values()){const v=n.get(h.id);if(!v)continue;if(v.hidden){n.set(v.id,{...v,internals:{...v.internals,handleBounds:void 0}}),d=!0;continue}const p=Yo(h.nodeElement),y=v.measured.width!==p.width||v.measured.height!==p.height;if(!!(p.width&&p.height&&(y||!v.internals.handleBounds||h.force))){const S=h.nodeElement.getBoundingClientRect(),g=rn(v.extent)?v.extent:t;let{positionAbsolute:w}=v.internals;v.parentId&&v.extent==="parent"?w=at(w,p,n.get(v.parentId)):g&&(w=ln(w,g,p));const N={...v,measured:p,internals:{...v.internals,positionAbsolute:w,handleBounds:{source:pt("source",h.nodeElement,S,u,v.id),target:pt("target",h.nodeElement,S,u,v.id)}}};n.set(v.id,N),v.parentId&&ns(N,n,i,{nodeOrigin:s,zIndexMode:l}),d=!0,y&&(c.push({id:v.id,type:"dimensions",dimensions:p}),v.expandParent&&v.parentId&&b.push({id:v.id,parentId:v.parentId,rect:Jn(N,s)}))}}if(b.length>0){const h=is(b,n,i,s);c.push(...h)}return{changes:c,updatedInternals:d}}async function mh({delta:e,panZoom:n,transform:i,translateExtent:o,width:s,height:t}){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,t]],o);return!!l&&(l.x!==i[0]||l.y!==i[1]||l.k!==i[2])}function Pt(e,n,i,o,s,t){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)),t){l=`${s}-${e}-${t}`;const c=o.get(l)||new Map;o.set(l,c.set(i,n))}}function Lt(e,n,i){e.clear(),n.clear();for(const o of i){const{source:s,target:t,sourceHandle:l=null,targetHandle:r=null}=o,d={edgeId:o.id,source:s,target:t,sourceHandle:l,targetHandle:r},c=`${s}-${l}--${t}-${r}`,m=`${t}-${r}--${s}-${l}`;Pt("source",d,m,e,s,l),Pt("target",d,c,e,t,r),n.set(o.id,o)}}function Bt(e,n){if(!e.parentId)return!1;const i=n.get(e.parentId);return i?i.selected?!0:Bt(i,n):!1}function It(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 bh(e,n,i,o){var t,l;const s=new Map;for(const[r,d]of e)if((d.selected||d.id===o)&&(!d.parentId||!Bt(d,e))&&(d.draggable||n&&typeof d.draggable=="undefined")){const c=e.get(r);c&&s.set(r,{id:r,position:c.position||{x:0,y:0},distance:{x:i.x-c.internals.positionAbsolute.x,y:i.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:(t=c.measured.width)!=null?t:0,height:(l=c.measured.height)!=null?l:0}})}return s}function os({nodeId:e,dragItems:n,nodeLookup:i,dragging:o=!0}){var l,r,d;const s=[];for(const[c,m]of n){const u=(l=i.get(c))==null?void 0:l.internals.userNode;u&&s.push({...u,position:m.position,dragging:o})}if(!e)return[s[0],s];const t=(r=i.get(e))==null?void 0:r.internals.userNode;return[t?{...t,position:((d=n.get(e))==null?void 0:d.position)||t.position,dragging:o}:s[0],s]}function vh({dragItems:e,snapGrid:n,x:i,y:o}){const s=e.values().next().value;if(!s)return null;const t={x:i-s.distance.x,y:o-s.distance.y},l=Zn(t,n);return{x:l.x-t.x,y:l.y-t.y}}function hh({onNodeMouseDown:e,getStoreItems:n,onDragStart:i,onDrag:o,onDragStop:s}){let t={x:null,y:null},l=0,r=new Map,d=!1,c={x:0,y:0},m=null,u=!1,b=null,h=!1,v=!1,p=null;function y({noDragClassName:S,handleSelector:g,domNode:w,isSelectable:N,nodeId:A,nodeClickDistance:C=0}){b=Ie(w);function E({x:T,y:O}){const{nodeLookup:M,nodeExtent:_,snapGrid:B,snapToGrid:H,nodeOrigin:D,onNodeDrag:L,onSelectionDrag:z,onError:q,updateNodePositions:W}=n();t={x:T,y:O};let Z=!1;const X=r.size>1,ie=X&&_?Uo(Yn(r)):null,ae=X&&H?vh({dragItems:r,snapGrid:B,x:T,y:O}):null;for(const[R,j]of r){if(!M.has(R))continue;let ee={x:T-j.distance.x,y:O-j.distance.y};H&&(ee=ae?{x:Math.round(ee.x+ae.x),y:Math.round(ee.y+ae.y)}:Zn(ee,B));let J=null;if(X&&_&&!j.extent&&ie){const{positionAbsolute:G}=j.internals,F=G.x-ie.x+_[0][0],V=G.x+j.measured.width-ie.x2+_[1][0],U=G.y-ie.y+_[0][1],Y=G.y+j.measured.height-ie.y2+_[1][1];J=[[F,U],[V,Y]]}const{position:K,positionAbsolute:$}=st({nodeId:R,nextPosition:ee,nodeLookup:M,nodeExtent:J||_,nodeOrigin:D,onError:q});Z=Z||j.position.x!==K.x||j.position.y!==K.y,j.position=K,j.internals.positionAbsolute=$}if(v=v||Z,!!Z&&(W(r,!0),p&&(o||L||!A&&z))){const[R,j]=os({nodeId:A,dragItems:r,nodeLookup:M});o==null||o(p,r,R,j),L==null||L(p,R,j),A||z==null||z(p,j)}}async function k(){var D,L;if(!m)return;const{transform:T,panBy:O,autoPanSpeed:M,autoPanOnNodeDrag:_}=n();if(!_){d=!1,cancelAnimationFrame(l);return}const[B,H]=jo(c,m,M);(B!==0||H!==0)&&(t.x=((D=t.x)!=null?D:0)-B/T[2],t.y=((L=t.y)!=null?L:0)-H/T[2],await O({x:B,y:H})&&E(t)),l=requestAnimationFrame(k)}function I(T){var X;const{nodeLookup:O,multiSelectionActive:M,nodesDraggable:_,transform:B,snapGrid:H,snapToGrid:D,selectNodesOnDrag:L,onNodeDragStart:z,onSelectionDragStart:q,unselectNodesAndEdges:W}=n();u=!0,(!L||!N)&&!M&&A&&((X=O.get(A))!=null&&X.selected||W()),N&&L&&A&&(e==null||e(A));const Z=Rn(T.sourceEvent,{transform:B,snapGrid:H,snapToGrid:D,containerBounds:m});if(t=Z,r=bh(O,_,Z,A),r.size>0&&(i||z||!A&&q)){const[ie,ae]=os({nodeId:A,dragItems:r,nodeLookup:O});i==null||i(T.sourceEvent,r,ie,ae),z==null||z(T.sourceEvent,ie,ae),A||q==null||q(T.sourceEvent,ae)}}const P=Sa().clickDistance(C).on("start",T=>{const{domNode:O,nodeDragThreshold:M,transform:_,snapGrid:B,snapToGrid:H}=n();m=(O==null?void 0:O.getBoundingClientRect())||null,h=!1,v=!1,p=T.sourceEvent,M===0&&I(T),t=Rn(T.sourceEvent,{transform:_,snapGrid:B,snapToGrid:H,containerBounds:m}),c=Ge(T.sourceEvent,m)}).on("drag",T=>{const{autoPanOnNodeDrag:O,transform:M,snapGrid:_,snapToGrid:B,nodeDragThreshold:H,nodeLookup:D}=n(),L=Rn(T.sourceEvent,{transform:M,snapGrid:_,snapToGrid:B,containerBounds:m});if(p=T.sourceEvent,(T.sourceEvent.type==="touchmove"&&T.sourceEvent.touches.length>1||A&&!D.has(A))&&(h=!0),!h){if(!d&&O&&u&&(d=!0,k()),!u){const z=Ge(T.sourceEvent,m),q=z.x-c.x,W=z.y-c.y;Math.sqrt(q*q+W*W)>H&&I(T)}(t.x!==L.xSnapped||t.y!==L.ySnapped)&&r&&u&&(c=Ge(T.sourceEvent,m),E(L))}}).on("end",T=>{if(!u||h){h&&r.size>0&&n().updateNodePositions(r,!1);return}if(d=!1,u=!1,cancelAnimationFrame(l),r.size>0){const{nodeLookup:O,updateNodePositions:M,onNodeDragStop:_,onSelectionDragStop:B}=n();if(v&&(M(r,!1),v=!1),s||_||!A&&B){const[H,D]=os({nodeId:A,dragItems:r,nodeLookup:O,dragging:!1});s==null||s(T.sourceEvent,r,H,D),_==null||_(T.sourceEvent,H,D),A||B==null||B(T.sourceEvent,D)}}}).filter(T=>{const O=T.target;return!T.button&&(!S||!It(O,`.${S}`,w))&&(!g||It(O,g,w))});b.call(P)}function f(){b==null||b.on(".drag",null)}return{update:y,destroy:f}}function fh(e,n,i){const o=[],s={x:e.x-i,y:e.y-i,width:i*2,height:i*2};for(const t of n.values())Oi(s,Jn(t))>0&&o.push(t);return o}const ph=250;function gh(e,n,i,o){var r,d,c,m,u;let s=[],t=1/0;const l=fh(e,i,n+ph);for(const b of l){const h=[...(d=(r=b.internals.handleBounds)==null?void 0:r.source)!=null?d:[],...(m=(c=b.internals.handleBounds)==null?void 0:c.target)!=null?m:[]];for(const v of h){if(o.nodeId===v.nodeId&&o.type===v.type&&o.id===v.id)continue;const{x:p,y}=dn(b,v,v.position,!0),f=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(y-e.y,2));f>n||(f<t?(s=[{...v,x:p,y}],t=f):f===t&&s.push({...v,x:p,y}))}}if(!s.length)return null;if(s.length>1){const b=o.type==="source"?"target":"source";return(u=s.find(h=>h.type===b))!=null?u:s[0]}return s[0]}function Dt(e,n,i,o,s,t=!1){var c,m,u,b,h,v;const l=o.get(e);if(!l)return null;const r=s==="strict"?(c=l.internals.handleBounds)==null?void 0:c[n]:[...(u=(m=l.internals.handleBounds)==null?void 0:m.source)!=null?u:[],...(h=(b=l.internals.handleBounds)==null?void 0:b.target)!=null?h:[]],d=(v=i?r==null?void 0:r.find(p=>p.id===i):r==null?void 0:r[0])!=null?v:null;return d&&t?{...d,...dn(l,d,d.position,!0)}:d}function _t(e,n){return e||(n!=null&&n.classList.contains("target")?"target":n!=null&&n.classList.contains("source")?"source":null)}function yh(e,n){let i=null;return n?i=!0:e&&!n&&(i=!1),i}const Ot=()=>!0;function xh(e,{connectionMode:n,connectionRadius:i,handleId:o,nodeId:s,edgeUpdaterType:t,isTarget:l,domNode:r,nodeLookup:d,lib:c,autoPanOnConnect:m,flowId:u,panBy:b,cancelConnection:h,onConnectStart:v,onConnect:p,onConnectEnd:y,isValidConnection:f=Ot,onReconnectEnd:S,updateConnection:g,getTransform:w,getFromHandle:N,autoPanSpeed:A,dragThreshold:C=1,handleDomNode:E}){const k=vt(e.target);let I=0,P;const{x:T,y:O}=Ge(e),M=_t(t,E),_=r==null?void 0:r.getBoundingClientRect();let B=!1;if(!_||!M)return;const H=Dt(s,M,o,d,n);if(!H)return;let D=Ge(e,_),L=!1,z=null,q=!1,W=null;function Z(){if(!m||!_)return;const[K,$]=jo(D,_,A);b({x:K,y:$}),I=requestAnimationFrame(Z)}const X={...H,nodeId:s,type:M,position:H.position},ie=d.get(s);let R={inProgress:!0,isValid:null,from:dn(ie,X,se.Left,!0),fromHandle:X,fromPosition:X.position,fromNode:ie,to:D,toHandle:null,toPosition:nt[X.position],toNode:null,pointer:D};function j(){B=!0,g(R),v==null||v(e,{nodeId:s,handleId:o,handleType:M})}C===0&&j();function ee(K){if(!B){const{x:Y,y:Q}=Ge(K),oe=Y-T,ue=Q-O;if(!(oe*oe+ue*ue>C*C))return;j()}if(!N()||!X){J(K);return}const $=w();D=Ge(K,_),P=gh(Xn(D,$,!1,[1,1]),i,d,X),L||(Z(),L=!0);const G=Kt(K,{handle:P,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:l?"target":"source",isValidConnection:f,doc:k,lib:c,flowId:u,nodeLookup:d});W=G.handleDomNode,z=G.connection,q=yh(!!P,G.isValid);const F=d.get(s),V=F?dn(F,X,se.Left,!0):R.from,U={...R,from:V,isValid:q,to:G.toHandle&&q?Nn({x:G.toHandle.x,y:G.toHandle.y},$):D,toHandle:G.toHandle,toPosition:q&&G.toHandle?G.toHandle.position:nt[X.position],toNode:G.toHandle?d.get(G.toHandle.nodeId):null,pointer:D};g(U),R=U}function J(K){if(!("touches"in K&&K.touches.length>0)){if(B){(P||W)&&z&&q&&(p==null||p(z));const{inProgress:$,...G}=R,F={...G,toPosition:R.toHandle?R.toPosition:null};y==null||y(K,F),t&&(S==null||S(K,F))}h(),cancelAnimationFrame(I),L=!1,q=!1,z=null,W=null,k.removeEventListener("mousemove",ee),k.removeEventListener("mouseup",J),k.removeEventListener("touchmove",ee),k.removeEventListener("touchend",J)}}k.addEventListener("mousemove",ee),k.addEventListener("mouseup",J),k.addEventListener("touchmove",ee),k.addEventListener("touchend",J)}function Kt(e,{handle:n,connectionMode:i,fromNodeId:o,fromHandleId:s,fromType:t,doc:l,lib:r,flowId:d,isValidConnection:c=Ot,nodeLookup:m}){const u=t==="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:h,y:v}=Ge(e),p=l.elementFromPoint(h,v),y=p!=null&&p.classList.contains(`${r}-flow__handle`)?p:b,f={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){const S=_t(void 0,y),g=y.getAttribute("data-nodeid"),w=y.getAttribute("data-handleid"),N=y.classList.contains("connectable"),A=y.classList.contains("connectableend");if(!g||!S)return f;const C={source:u?g:o,sourceHandle:u?w:s,target:u?o:g,targetHandle:u?s:w};f.connection=C;const k=N&&A&&(i===xn.Strict?u&&S==="source"||!u&&S==="target":g!==o||w!==s);f.isValid=k&&c(C),f.toHandle=Dt(g,S,w,m,i,!0)}return f}const ss={onPointerDown:xh,isValid:Kt};function Sh({domNode:e,panZoom:n,getTransform:i,getViewScale:o}){const s=Ie(e);function t({translateExtent:r,width:d,height:c,zoomStep:m=1,pannable:u=!0,zoomable:b=!0,inversePan:h=!1}){const v=g=>{if(g.sourceEvent.type!=="wheel"||!n)return;const w=i(),N=g.sourceEvent.ctrlKey&&Qn()?10:1,A=-g.sourceEvent.deltaY*(g.sourceEvent.deltaMode===1?.05:g.sourceEvent.deltaMode?1:.002)*m,C=w[2]*Math.pow(2,A*N);n.scaleTo(C)};let p=[0,0];const y=g=>{var w,N;(g.sourceEvent.type==="mousedown"||g.sourceEvent.type==="touchstart")&&(p=[(w=g.sourceEvent.clientX)!=null?w:g.sourceEvent.touches[0].clientX,(N=g.sourceEvent.clientY)!=null?N:g.sourceEvent.touches[0].clientY])},f=g=>{var I,P;const w=i();if(g.sourceEvent.type!=="mousemove"&&g.sourceEvent.type!=="touchmove"||!n)return;const N=[(I=g.sourceEvent.clientX)!=null?I:g.sourceEvent.touches[0].clientX,(P=g.sourceEvent.clientY)!=null?P:g.sourceEvent.touches[0].clientY],A=[N[0]-p[0],N[1]-p[1]];p=N;const C=o()*Math.max(w[2],Math.log(w[2]))*(h?-1:1),E={x:w[0]-A[0]*C,y:w[1]-A[1]*C},k=[[0,0],[d,c]];n.setViewportConstrained({x:E.x,y:E.y,zoom:w[2]},k,r)},S=Xa().on("start",y).on("zoom",u?f:null).on("zoom.wheel",b?v:null);s.call(S,{})}function l(){s.on("zoom",null)}return{update:t,destroy:l,pointer:_e}}const Hi=e=>({x:e.x,y:e.y,zoom:e.k}),as=({x:e,y:n,zoom:i})=>Bi.translate(e,n).scale(i),Cn=(e,n)=>e.target.closest(`.${n}`),Ht=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),wh=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,ts=(e,n=0,i=wh,o=()=>{})=>{const s=typeof n=="number"&&n>0;return s||o(),s?e.transition().duration(n).ease(i).on("end",o):e},Gt=e=>{const n=e.ctrlKey&&Qn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function Nh({zoomPanValues:e,noWheelClassName:n,d3Selection:i,d3Zoom:o,panOnScrollMode:s,panOnScrollSpeed:t,zoomOnPinch:l,onPanZoomStart:r,onPanZoom:d,onPanZoomEnd:c}){return m=>{if(Cn(m,n))return m.ctrlKey&&m.preventDefault(),!1;m.preventDefault(),m.stopImmediatePropagation();const u=i.property("__zoom").k||1;if(m.ctrlKey&&l){const y=_e(m),f=Gt(m),S=u*Math.pow(2,f);o.scaleTo(i,S,y,m);return}const b=m.deltaMode===1?20:1;let h=s===tn.Vertical?0:m.deltaX*b,v=s===tn.Horizontal?0:m.deltaY*b;!Qn()&&m.shiftKey&&s!==tn.Vertical&&(h=m.deltaY*b,v=0),o.translateBy(i,-(h/u)*t,-(v/u)*t,{internal:!0});const p=Hi(i.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d==null||d(m,p),e.panScrollTimeout=setTimeout(()=>{c==null||c(m,p),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,r==null||r(m,p))}}function Ah({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:i}){return function(o,s){const t=o.type==="wheel",l=!n&&t&&!o.ctrlKey,r=Cn(o,e);if(o.ctrlKey&&t&&r&&o.preventDefault(),l||r)return null;o.preventDefault(),i.call(this,o,s)}}function Ch({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:i}){return o=>{var t,l,r;if((t=o.sourceEvent)!=null&&t.internal)return;const s=Hi(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 kh({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:i,onTransformChange:o,onPanZoom:s}){return t=>{var l,r,d;e.usedRightMouseButton=!!(i&&Ht(n,(l=e.mouseButton)!=null?l:0)),(r=t.sourceEvent)!=null&&r.sync||o([t.transform.x,t.transform.y,t.transform.k]),s&&!((d=t.sourceEvent)!=null&&d.internal)&&(s==null||s(t.sourceEvent,Hi(t.transform)))}}function Mh({zoomPanValues:e,panOnDrag:n,panOnScroll:i,onDraggingChange:o,onPanZoomEnd:s,onPaneContextMenu:t}){return l=>{var r,d;if(!((r=l.sourceEvent)!=null&&r.internal)&&(e.isZoomingOrPanning=!1,t&&Ht(n,(d=e.mouseButton)!=null?d:0)&&!e.usedRightMouseButton&&l.sourceEvent&&t(l.sourceEvent),e.usedRightMouseButton=!1,o(!1),s)){const c=Hi(l.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(l.sourceEvent,c)},i?150:0)}}}function Eh({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:i,panOnDrag:o,panOnScroll:s,zoomOnDoubleClick:t,userSelectionActive:l,noWheelClassName:r,noPanClassName:d,lib:c,connectionInProgress:m}){return u=>{var y;const b=e||n,h=i&&u.ctrlKey,v=u.type==="wheel";if(u.button===1&&u.type==="mousedown"&&(Cn(u,`${c}-flow__node`)||Cn(u,`${c}-flow__edge`)))return!0;if(!o&&!b&&!s&&!t&&!i||l||m&&!v||Cn(u,r)&&v||Cn(u,d)&&(!v||s&&v&&!e)||!i&&u.ctrlKey&&v)return!1;if(!i&&u.type==="touchstart"&&((y=u.touches)==null?void 0:y.length)>1)return u.preventDefault(),!1;if(!b&&!s&&!h&&v||!o&&(u.type==="mousedown"||u.type==="touchstart")||Array.isArray(o)&&!o.includes(u.button)&&u.type==="mousedown")return!1;const p=Array.isArray(o)&&o.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||v)&&p}}function Th({domNode:e,minZoom:n,maxZoom:i,translateExtent:o,viewport:s,onPanZoom:t,onPanZoomStart:l,onPanZoomEnd:r,onDraggingChange:d}){const c={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},m=e.getBoundingClientRect(),u=Xa().scaleExtent([n,i]).translateExtent(o),b=Ie(e).call(u);S({x:s.x,y:s.y,zoom:wn(s.zoom,n,i)},[[0,0],[m.width,m.height]],o);const h=b.on("wheel.zoom"),v=b.on("dblclick.zoom");u.wheelDelta(Gt);async function p(P,T){return b?new Promise(O=>{u==null||u.interpolate((T==null?void 0:T.interpolate)==="linear"?Gn:wi).transform(ts(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:_,panOnDrag:B,panOnScrollMode:H,panOnScrollSpeed:D,preventScrolling:L,zoomOnPinch:z,zoomOnScroll:q,zoomOnDoubleClick:W,zoomActivationKeyPressed:Z,lib:X,onTransformChange:ie,connectionInProgress:ae,paneClickDistance:R,selectionOnDrag:j}){M&&!c.isZoomingOrPanning&&f();const ee=_&&!Z&&!M;u.clickDistance(j?1/0:!He(R)||R<0?0:R);const J=ee?Nh({zoomPanValues:c,noWheelClassName:P,d3Selection:b,d3Zoom:u,panOnScrollMode:H,panOnScrollSpeed:D,zoomOnPinch:z,onPanZoomStart:l,onPanZoom:t,onPanZoomEnd:r}):Ah({noWheelClassName:P,preventScrolling:L,d3ZoomHandler:h});b.on("wheel.zoom",J,{passive:!1});const K=Ch({zoomPanValues:c,onDraggingChange:d,onPanZoomStart:l});u.on("start",K);const $=kh({zoomPanValues:c,panOnDrag:B,onPaneContextMenu:!!O,onPanZoom:t,onTransformChange:ie});u.on("zoom",$);const G=Mh({zoomPanValues:c,panOnDrag:B,panOnScroll:_,onPaneContextMenu:O,onPanZoomEnd:r,onDraggingChange:d});u.on("end",G);const F=Eh({zoomActivationKeyPressed:Z,panOnDrag:B,zoomOnScroll:q,panOnScroll:_,zoomOnDoubleClick:W,zoomOnPinch:z,userSelectionActive:M,noPanClassName:T,noWheelClassName:P,lib:X,connectionInProgress:ae});u.filter(F),W?b.on("dblclick.zoom",v):b.on("dblclick.zoom",null)}function f(){u.on("zoom",null)}async function S(P,T,O){const M=as(P),_=u==null?void 0:u.constrain()(M,T,O);return _&&await p(_),_}async function g(P,T){const O=as(P);return await p(O,T),O}function w(P){if(b){const T=as(P),O=b.property("__zoom");(O.k!==P.zoom||O.x!==P.x||O.y!==P.y)&&(u==null||u.transform(b,T,null,{sync:!0}))}}function N(){const P=b?Ja(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=>{u==null||u.interpolate((T==null?void 0:T.interpolate)==="linear"?Gn:wi).scaleTo(ts(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=>{u==null||u.interpolate((T==null?void 0:T.interpolate)==="linear"?Gn:wi).scaleBy(ts(b,T==null?void 0:T.duration,T==null?void 0:T.ease,()=>O(!0)),P)}):!1}function E(P){u==null||u.scaleExtent(P)}function k(P){u==null||u.translateExtent(P)}function I(P){const T=!He(P)||P<0?0:P;u==null||u.clickDistance(T)}return{update:y,destroy:f,setViewport:g,setViewportConstrained:S,getViewport:N,scaleTo:A,scaleBy:C,setScaleExtent:E,setTranslateExtent:k,syncViewport:w,setClickDistance:I}}var kn;(function(e){e.Line="line",e.Handle="handle"})(kn||(kn={}));function Ph({width:e,prevWidth:n,height:i,prevHeight:o,affectsX:s,affectsY:t}){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&&t&&(d[1]=d[1]*-1),d}function Ft(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 Xe(e,n){return Math.max(0,n-e)}function Qe(e,n){return Math.max(0,e-n)}function Gi(e,n,i){return Math.max(0,n-e,e-i)}function Vt(e,n){return e?!n:n}function Lh(e,n,i,o,s,t,l,r){let{affectsX:d,affectsY:c}=n;const{isHorizontal:m,isVertical:u}=n,b=m&&u,{xSnapped:h,ySnapped:v}=i,{minWidth:p,maxWidth:y,minHeight:f,maxHeight:S}=o,{x:g,y:w,width:N,height:A,aspectRatio:C}=e;let E=Math.floor(m?h-e.pointerX:0),k=Math.floor(u?v-e.pointerY:0);const I=N+(d?-E:E),P=A+(c?-k:k),T=-t[0]*N,O=-t[1]*A;let M=Gi(I,p,y),_=Gi(P,f,S);if(l){let D=0,L=0;d&&E<0?D=Xe(g+E+T,l[0][0]):!d&&E>0&&(D=Qe(g+I+T,l[1][0])),c&&k<0?L=Xe(w+k+O,l[0][1]):!c&&k>0&&(L=Qe(w+P+O,l[1][1])),M=Math.max(M,D),_=Math.max(_,L)}if(r){let D=0,L=0;d&&E>0?D=Qe(g+E,r[0][0]):!d&&E<0&&(D=Xe(g+I,r[1][0])),c&&k>0?L=Qe(w+k,r[0][1]):!c&&k<0&&(L=Xe(w+P,r[1][1])),M=Math.max(M,D),_=Math.max(_,L)}if(s){if(m){const D=Gi(I/C,f,S)*C;if(M=Math.max(M,D),l){let L=0;!d&&!c||d&&!c&&b?L=Qe(w+O+I/C,l[1][1])*C:L=Xe(w+O+(d?E:-E)/C,l[0][1])*C,M=Math.max(M,L)}if(r){let L=0;!d&&!c||d&&!c&&b?L=Xe(w+I/C,r[1][1])*C:L=Qe(w+(d?E:-E)/C,r[0][1])*C,M=Math.max(M,L)}}if(u){const D=Gi(P*C,p,y)/C;if(_=Math.max(_,D),l){let L=0;!d&&!c||c&&!d&&b?L=Qe(g+P*C+T,l[1][0])/C:L=Xe(g+(c?k:-k)*C+T,l[0][0])/C,_=Math.max(_,L)}if(r){let L=0;!d&&!c||c&&!d&&b?L=Xe(g+P*C,r[1][0])/C:L=Qe(g+(c?k:-k)*C,r[0][0])/C,_=Math.max(_,L)}}}k=k+(k<0?_:-_),E=E+(E<0?M:-M),s&&(b?I>P*C?k=(Vt(d,c)?-E:E)/C:E=(Vt(d,c)?-k:k)*C:m?(k=E/C,c=d):(E=k*C,d=c));const B=d?g+E:g,H=c?w+k:w;return{width:N+(d?-E:E),height:A+(c?-k:k),x:t[0]*E*(d?-1:1)+B,y:t[1]*k*(c?-1:1)+H}}const zt={width:0,height:0,x:0,y:0},Bh={...zt,pointerX:0,pointerY:0,aspectRatio:1};function Ih(e,n,i){var c,m;const o=n.position.x+e.position.x,s=n.position.y+e.position.y,t=(c=e.measured.width)!=null?c:0,l=(m=e.measured.height)!=null?m:0,r=i[0]*t,d=i[1]*l;return[[o-r,s-d],[o+t-r,s+l-d]]}function Dh({domNode:e,nodeId:n,getStoreItems:i,onChange:o,onEnd:s}){const t=Ie(e);let l={controlDirection:Ft("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function r({controlPosition:c,boundaries:m,keepAspectRatio:u,resizeDirection:b,onResizeStart:h,onResize:v,onResizeEnd:p,shouldResize:y}){let f={...zt},S={...Bh};l={boundaries:m,resizeDirection:b,keepAspectRatio:u,controlDirection:Ft(c)};let g,w=null,N=[],A,C,E,k=!1;const I=Sa().on("start",P=>{var z,q,W,Z,X,ie;const{nodeLookup:T,transform:O,snapGrid:M,snapToGrid:_,nodeOrigin:B,paneDomNode:H}=i();if(g=T.get(n),!g)return;w=(z=H==null?void 0:H.getBoundingClientRect())!=null?z:null;const{xSnapped:D,ySnapped:L}=Rn(P.sourceEvent,{transform:O,snapGrid:M,snapToGrid:_,containerBounds:w});f={width:(q=g.measured.width)!=null?q:0,height:(W=g.measured.height)!=null?W:0,x:(Z=g.position.x)!=null?Z:0,y:(X=g.position.y)!=null?X:0},S={...f,pointerX:D,pointerY:L,aspectRatio:f.width/f.height},A=void 0,C=rn(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]]),N=[],E=void 0;for(const[ae,R]of T)if(R.parentId===n&&(N.push({id:ae,position:{...R.position},extent:R.extent}),R.extent==="parent"||R.expandParent)){const j=Ih(R,g,(ie=R.origin)!=null?ie:B);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}h==null||h(P,{...f})}).on("drag",P=>{var V,U,Y;const{transform:T,snapGrid:O,snapToGrid:M,nodeOrigin:_}=i(),B=Rn(P.sourceEvent,{transform:T,snapGrid:O,snapToGrid:M,containerBounds:w}),H=[];if(!g)return;const{x:D,y:L,width:z,height:q}=f,W={},Z=(V=g.origin)!=null?V:_,{width:X,height:ie,x:ae,y:R}=Lh(S,l.controlDirection,B,l.boundaries,l.keepAspectRatio,Z,C,E),j=X!==z,ee=ie!==q,J=ae!==D&&j,K=R!==L&&ee;if(!J&&!K&&!j&&!ee)return;if((J||K||Z[0]===1||Z[1]===1)&&(W.x=J?ae:f.x,W.y=K?R:f.y,f.x=W.x,f.y=W.y,N.length>0)){const Q=ae-D,oe=R-L;for(const ue of N)ue.position={x:ue.position.x-Q+Z[0]*(X-z),y:ue.position.y-oe+Z[1]*(ie-q)},H.push(ue)}if((j||ee)&&(W.width=j&&(!l.resizeDirection||l.resizeDirection==="horizontal")?X:f.width,W.height=ee&&(!l.resizeDirection||l.resizeDirection==="vertical")?ie:f.height,f.width=W.width,f.height=W.height),A&&g.expandParent){const Q=Z[0]*((U=W.width)!=null?U:0);W.x&&W.x<Q&&(f.x=Q,S.x=S.x-(W.x-Q));const oe=Z[1]*((Y=W.height)!=null?Y:0);W.y&&W.y<oe&&(f.y=oe,S.y=S.y-(W.y-oe))}const $=Ph({width:f.width,prevWidth:z,height:f.height,prevHeight:q,affectsX:l.controlDirection.affectsX,affectsY:l.controlDirection.affectsY}),G={...f,direction:$};(y==null?void 0:y(P,G))!==!1&&(k=!0,v==null||v(P,G),o(W,H))}).on("end",P=>{k&&(p==null||p(P,{...f}),s==null||s({...f}),k=!1)});t.call(I)}function d(){t.on(".drag",null)}return{update:r,destroy:d}}function _h(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fi={exports:{}},ls={},Vi={exports:{}},rs={};/**
30
+ active:opacity-50 element_class`,draggable:!0,children:a.jsxs("span",{className:"flex flex-col items-center justify-center w-full gap-2",children:[a.jsx("span",{style:{color:u},children:a.jsx(te,{icon:g.icon,iconClass:"w-6 h-6"})}),a.jsx("span",{style:{color:u},className:"text-xs font-medium text-center",children:g.label})]})},g.type))})]},f)})})})]})},Vu=x.memo(Fu),Fe=({text:e="",isDisabled:n=!1,isLoading:i=!1,btnClass:o="bg-primary-500 text-white",icon:s="",iconPosition:t="left",iconClass:l="text-[20px]",loadingClass:r="",link:d="",div:c=!1,type:m="button",style:u,onClick:b})=>{const h=me("btn inline-flex justify-center",{"pointer-events-none":i,"opacity-40 cursor-not-allowed":n},o),v=()=>i?a.jsxs(a.Fragment,{children:[a.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:[a.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),a.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..."]}):a.jsxs("span",{className:"flex items-center",children:[s&&t==="left"&&a.jsx("span",{className:`mr-[6px] ${l}`,children:a.jsx(te,{icon:s})}),e&&a.jsx("span",{children:e}),s&&t==="right"&&a.jsx("span",{className:`ml-[6px] ${l}`,children:a.jsx(te,{icon:s})})]});return c?a.jsx("div",{className:h,children:v()}):d?a.jsx(fr.Link,{to:d,className:h,children:v()}):a.jsx("button",{disabled:n,type:m,className:h,"data-testid":"btn",onClick:b,style:u,children:v()})};function zu(){return a.jsx("div",{children:a.jsxs("svg",{width:"36",height:"36",viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",fill:"#D5D7DA"}),a.jsx("rect",{x:"0.5",y:"0.5",width:"35",height:"35",rx:"7.5",stroke:"#E9EAEB"}),a.jsx("path",{d:"M22.5 14L14.5 22M14.5 14L22.5 22",stroke:"#414651",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"})]})})}const Wu=({isOpen:e,onClose:n})=>{const{formData:i,uploadUrl:o}=x.useContext(Te);if(!e)return null;const s=Ce("config");return a.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:[a.jsx("button",{type:"button",onClick:n,className:"absolute text-sm top-3 right-4","aria-label":"close",children:a.jsx(zu,{})})," ",a.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:a.jsx(No,{form_data:i,ignoreValidation:!0,config:s,uploadUrl:o})})]})};function $u(){return a.jsx("div",{children:a.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[a.jsx("rect",{width:"24",height:"24",rx:"6",fill:"currentColor"}),a.jsx("path",{d:"M14 16L10 12L14 8",stroke:"white",strokeWidth:"1.39167",strokeLinecap:"round",strokeLinejoin:"round"})]})})}function ju({title:e,goBackUrl:n,onSubmit:i,onPublish:o,previewLoading:s,saveLoading:t,publishLoading:l,onTitleChange:r,viewMode:d,setViewMode:c,onShowVersion:m}){const{formData:u,setShowPreview:b,showPreview:h,undo:v,redo:p,canUndo:y,canRedo:f}=x.useContext(Te),[S,g]=x.useState(!1),[w,N]=x.useState(!1),[A,C]=x.useState(e||""),E=Ce("config");function k(){try{localStorage.setItem("formData",JSON.stringify(u))}catch(T){console.warn("Could not save formData to localStorage",T)}i==null||i(u)}function I(){try{localStorage.setItem("formData",JSON.stringify(u))}catch(T){console.warn("Could not save formData to localStorage",T)}o==null||o(u)}function P(){N(!1),r&&A!==e&&r(A.trim())}return a.jsxs("div",{className:"px-[30px] py-3 flex justify-between items-center bg-[#F9F9FB] top_bar border-b h-full",children:[a.jsxs("span",{className:"flex items-center gap-x-2",children:[n&&a.jsx("button",{type:"button",onClick:()=>n(),style:{color:(E==null?void 0:E.buttonColor)||"#333"},className:"flex items-center gap-x-3",children:a.jsx($u,{})})," ",w?a.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"}):a.jsx("h1",{title:"Click to edit",className:"text-base font-semibold cursor-pointer form_title",onClick:()=>N(!0),children:A||"Untitled"})]}),S&&a.jsx(Wu,{isOpen:S,onClose:()=>g(!1),element:void 0}),a.jsxs("div",{className:"flex justify-end text-xs gap-x-3 items-center",children:[c&&a.jsxs("div",{className:"flex border border-gray-300 rounded-lg overflow-hidden h-[36px] text-sm font-medium shadow-sm mr-2",children:[a.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:()=>c("canvas"),children:[a.jsx(te,{icon:"mdi:view-dashboard-outline",iconClass:"text-base"})," ","Builder"]}),a.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:()=>c("flow"),children:[a.jsx(te,{icon:"mdi:sitemap-outline",iconClass:"text-base"})," Flow"]})]}),a.jsx(Fe,{onClick:v,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}),a.jsx(Fe,{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&&a.jsx(Fe,{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"}}),a.jsx(Fe,{onClick:()=>b(T=>!T),text:h?"Hide Preview":"Preview",btnClass:"px-2 bg-transparent font-medium text-sm form_preview",icon:h?"iconamoon:eye-off-duotone":"solar:eye-bold-duotone",iconClass:"text-base",style:{color:(E==null?void 0:E.buttonColor)||"#333"},isDisabled:s,isLoading:s}),a.jsx(Fe,{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:t,isLoading:t}),a.jsx(Fe,{onClick:I,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 Uu({onSubmit:e,onChange:n,onLogAction:i,questionData:o,title:s,goBackUrl:t,loading:l,onPublish:r,previewLoading:d,saveLoading:c,publishLoading:m,onTitleChange:u,uploadUrl:b,onAddTemplate:h,templates:v,onShowVersion:p}){const[y,f]=x.useState("canvas");return a.jsxs(Ss,{onChange:n,onLogAction:i,children:[a.jsx(Ae.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),a.jsx("div",{className:"w-full h-full bg-[#F8F9FC] flex flex-col",children:a.jsxs("div",{className:"flex flex-1 ",children:[y==="canvas"&&a.jsx("div",{children:a.jsx("div",{className:"w-[250px] h-screen border-r border-[#E4E7EC] bg-white ",children:a.jsx(Vu,{})})}),a.jsxs("div",{className:`flex-1 h-full max-h-full z-[1] ${y==="canvas"?"w-[calc(100%-250px)]":"w-full"}`,children:[a.jsx("div",{className:" h-[70px]",children:a.jsx(ju,{title:s,goBackUrl:t,onSubmit:e,onPublish:r,previewLoading:d,saveLoading:c,publishLoading:m,onTitleChange:u,viewMode:y,setViewMode:f,onShowVersion:p})}),a.jsx("div",{className:"p-6 h-[calc(100vh-70px)]",children:l?a.jsx(yo,{loadingClass:"!w-full !h-[800px]"}):a.jsx(Gu,{questionData:o,uploadUrl:b,onAddTemplate:h,templates:v,viewMode:y})})]})]})})]})}const qu=({onSubmit:e,onChange:n,onLogAction:i,questionData:o,isReadOnly:s,config:t={buttonColor:"#333"},title:l,loading:r,goBackUrl:d,onPublish:c,previewLoading:m,saveLoading:u,publishLoading:b,onTitleChange:h,uploadUrl:v,onAddTemplate:p,templates:y,onShowVersion:f})=>(x.useEffect(()=>{t&&Js("config",t)},[t]),a.jsx(Uu,{onSubmit:e,onChange:n,onLogAction:i,onPublish:c,questionData:o,isReadOnly:s,title:l,goBackUrl:d,loading:r,previewLoading:m,saveLoading:u,publishLoading:b,onTitleChange:h,uploadUrl:v,onAddTemplate:p,templates:y,onShowVersion:f})),Je={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}`},Yu=(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",Je.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",Je.url,o=>!o||o.trim()===""?!0:/^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/.*)?$/.test(o))})[e]||ne.mixed().nullable(),Ju=(e,n,i)=>n?e.type==="boolean"?e.oneOf([!0],i||Je.required):e.required(i||Je.required):e,Zu=(e,{minLength:n,maxLength:i,minLengthMessage:o,maxLengthMessage:s})=>{let t=e;return n&&(t=t.min(n,o||Je.minLength(n))),i&&(t=t.max(i,s||Je.maxLength(i))),t},Xu=(e,{minAmount:n,maxAmount:i,minAmountMessage:o,maxAmountMessage:s})=>{let t=e;return n&&(t=t.min(parseFloat(String(n)),o||Je.minAmount(n))),i&&(t=t.max(parseFloat(String(i)),s||Je.maxAmount(i))),t},So=(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],t=o.fieldValue,l=s;switch(o.operator){case"equals":return String(t).toLowerCase()===String(l).toLowerCase();case"not_equals":return String(t).toLowerCase()!==String(l).toLowerCase();case"greater":return Number(l)>Number(t);case"less":return Number(l)<Number(t);case"contains":return String(l).toLowerCase().includes(String(t).toLowerCase());case"not_contains":return!String(l).toLowerCase().includes(String(t).toLowerCase());default:return!0}}):!0};function Qu({formData:e,isReadOnly:n,answerData:i}){const o={};return e.forEach(({questionData:s})=>{s==null||s.forEach(t=>{if(!So(t,i))return;const{id:l,type:r,isRequired:d,requiredMessage:c,isDisabled:m}=t;let u=Yu(r,n);u=Ju(u,m||n?!1:d,c),r==="textField"||r==="longText"||r==="email"||r==="url"?u=Zu(u,t):(r==="numberField"||r==="amountField")&&(u=Xu(u,t)),t.requireAllChecked?u=u.test("require-all-checked","All options must be selected",b=>{var p;if(b==null||b===""||Array.isArray(b)&&b.length===0)return!d;const v=((p=t.options)==null?void 0:p.length)||0;return Array.isArray(b)?b.length>=v:v<=1}):t.minChecked&&(u=u.test("min-checked",`Please select at least ${t.minChecked} option(s)`,b=>b==null||b===""||Array.isArray(b)&&b.length===0?!d:Array.isArray(b)?b.length>=t.minChecked:1>=t.minChecked)),o[l]=u})}),ne.object().shape(o)}const vn=({element:e,validationData:n})=>{const i=oa[e.type],{answerData:o}=x.useContext(Te),s=x.useMemo(()=>{var l;return(l=e==null?void 0:e.acceptedFiles)==null?void 0:l.map(r=>r.label).join(", ")},[e]),t=x.useMemo(()=>So(e,o),[o,e]);return i?a.jsxs("div",{className:`${t?"":"hidden"} min-w-0 w-full`,children:[a.jsx("div",{className:"mb-1.5 min-w-0",children:e.inputLabel&&a.jsxs("label",{className:"block text-sm font-medium input_label",children:[e.inputLabel," ",s&&a.jsxs("span",{className:"text-gray-400 text-xs",children:["(",s==null?void 0:s.toLowerCase(),")"]})]})}),a.jsx(i,{element:e,state:"edit",validationData:{...n,isReadOnly:n.isReadOnly||e.isDisabled}}),e.description&&a.jsx("small",{className:"block text-gray-400 mt-0.5 text-xs",children:e.description})]}):null},hn=(e,n)=>e!=null&&e.allowEdit?{...n,isReadOnly:!1}:n;function Ru({form_data:e,options:n}){const i=(s,t)=>a.jsx("div",{className:"min-w-0",children:a.jsx(ui,{element:s,customClass:"p-0 min-h-[60px] border-none",children:t==null?void 0:t.map(l=>{var r,d,c;return a.jsxs(di,{col:(r=l.gridPosition)==null?void 0:r.col,customClass:"p-0",children:[a.jsx(vn,{element:l,validationData:hn(l,n)}),((c=(d=n==null?void 0:n.errors)==null?void 0:d[l.id])==null?void 0:c.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[l.id].message})]},l.id)})})},s.id),o=s=>{var t,l;return a.jsxs("div",{className:me("group relative grid gap-y-[6px] min-w-0",s.elementClass),children:[a.jsx(vn,{element:s,validationData:hn(s,n)}),((l=(t=n==null?void 0:n.errors)==null?void 0:t[s.id])==null?void 0:l.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[s.id].message})]},s.id)};return a.jsx("div",{className:"grid gap-y-10",children:e==null?void 0:e.map(s=>{var l,r;const t=new Map;return(l=s==null?void 0:s.questionData)==null||l.forEach(d=>{d.gridId&&(t.has(d.gridId)||t.set(d.gridId,[]),t.get(d.gridId).push(d))}),a.jsxs("div",{className:"pb-6 section_box min-w-0",children:[(s.title||s.description)&&a.jsxs("div",{className:"py-4 border-b border-gray-100 mb-7 section_box__title",children:[s.title&&a.jsx("h2",{className:"text-lg font-semibold mb-[4px]",children:s.title}),s.description&&a.jsx("p",{className:"text-sm",children:s.description})]}),a.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,t.get(d.id)||[]):o(d))})]},s.id)})})}function ec({form_data:e,options:n,current:i}){var o,s;return a.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(t=>{var l,r,d,c;if(t.type==="grid"){const m=(r=(l=e[i])==null?void 0:l.questionData)==null?void 0:r.filter(u=>u.gridId===t.id);return a.jsx("div",{className:"min-w-0",children:a.jsx(ui,{element:t,customClass:"p-0 min-h-[60px] border-none",children:m==null?void 0:m.map(u=>{var b,h,v;return a.jsxs(di,{col:(b=u.gridPosition)==null?void 0:b.col,customClass:"p-0",children:[a.jsx(vn,{element:u,validationData:hn(u,n)}),a.jsx("div",{className:"mt-1 text-xs text-red-600",children:(v=(h=n==null?void 0:n.errors)==null?void 0:h[u.id])==null?void 0:v.message})]},u.id)})})},t.id)}return t.gridId?null:a.jsxs("div",{className:me("group relative grid gap-y-[6px] min-w-0",t.elementClass),children:[a.jsx(vn,{element:t,validationData:hn(t,n)}),a.jsx("div",{className:"mt-1 text-xs text-red-600",children:(c=(d=n==null?void 0:n.errors)==null?void 0:d[t.id])==null?void 0:c.message})]},t.id)})})}const wo=Ce("config");function nc({element:e,options:n,onNext:i,onPrev:o,isFirst:s,isLast:t,isReadOnly:l}){if(!e)return a.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 u;return a.jsx("div",{className:"min-w-0 w-full",children:a.jsx(ui,{element:m,customClass:"p-0 min-h-[60px] border-none w-full",children:(u=m.gridChildren)==null?void 0:u.map(b=>{var h,v,p;return a.jsxs(di,{col:(h=b.gridPosition)==null?void 0:h.col,customClass:"p-0",children:[a.jsx(vn,{element:b,validationData:hn(b,n)}),((p=(v=n==null?void 0:n.errors)==null?void 0:v[b.id])==null?void 0:p.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[b.id].message})]},b.id)})})},m.id)},c=m=>{var u,b;return a.jsxs("div",{className:me("group relative grid gap-y-[6px] min-w-0 w-full",m.elementClass),children:[a.jsx(vn,{element:m,validationData:hn(m,n)}),((b=(u=n==null?void 0:n.errors)==null?void 0:u[m.id])==null?void 0:b.message)&&a.jsx("div",{className:"mt-1 text-xs text-red-600",children:n.errors[m.id].message})]},m.id)};return a.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:a.jsxs(le.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:[a.jsx("div",{className:"text-left w-full mb-8",children:e.type==="grid"?d(e):c(e)}),!l&&a.jsxs("div",{className:"flex items-center gap-4 mt-8",children:[a.jsx(Fe,{type:"button",text:t?n!=null&&n.isSubmitting?"Submitting...":"Submit":"OK",onClick:i,style:{background:(wo==null?void 0:wo.buttonColor)||"#333"},btnClass:`text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg ${t?"submit_btn":"continue_btn next_btn text-sm"}`,isDisabled:(n==null?void 0:n.apiActivityCount)>0||t&&(n==null?void 0:n.isSubmitting)}),!t&&a.jsx("span",{className:"text-xs text-gray-400 font-medium hidden sm:inline-block",children:"press Enter ↵"}),!s&&a.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:[a.jsx(te,{icon:"material-symbols:arrow-upward-rounded",iconClass:"text-lg"}),"Back"]})]})]},e.id)})}function ic(e){return e.reduce((n,i)=>(n[i.id]=i.value,n),{})}const oc=({form_data:e,answerData:n=[],ignoreValidation:i=!1,onSubmitData:o,onGetValues:s,isReadOnly:t=!1,renderType:l="multi",children:r,hideFooter:d=!1,uploadUrl:c})=>{var ae,R,j,ee,J,K,$,G,F,V;const{setAnswerData:m,setUploadUrl:u,apiActivityCount:b}=x.useContext(Te),[h,v]=x.useState(0),[p,y]=x.useState(0),f=x.useMemo(()=>e.filter(U=>!U.isHidden).map(U=>{var Q;return U.isDisabled||U.disabled?{...U,questionData:(Q=U==null?void 0:U.questionData)==null?void 0:Q.map(oe=>({...oe,isDisabled:!0}))}:U}),[e]),S=(ae=f==null?void 0:f.length)!=null?ae:0,g=Ce("config"),w=x.useCallback(async(U,Y,Q)=>{const oe=Qu({formData:f,isReadOnly:t,answerData:U});return uo(oe)(U,Y,Q)},[f,t]),N=$e.useForm({resolver:w,mode:"onSubmit",defaultValues:{}}),{register:A,setValue:C,control:E,handleSubmit:k,reset:I,getValues:P,watch:T,formState:{errors:O,isSubmitting:M},trigger:_,setError:B,clearErrors:H}=N,D=$e.useWatch({control:E}),L=x.useMemo(()=>D,[JSON.stringify(D)]),z=x.useMemo(()=>{if(l!=="conversational")return[];const U=[];return f.forEach(Y=>{var Q;(Q=Y==null?void 0:Y.questionData)==null||Q.forEach(oe=>{var ue;if(So(oe,L))if(oe.type==="grid"){const fe=(ue=Y==null?void 0:Y.questionData)==null?void 0:ue.filter(ge=>ge.gridId===oe.id);U.push({...oe,gridChildren:fe})}else oe.gridId||U.push(oe)})}),U},[f,L,l]),q=x.useCallback(U=>{s&&s(U)},[s]);x.useEffect(()=>{u(c)},[u,c]),x.useEffect(()=>{if(!(f!=null&&f.length)||!s)return;const U=f.flatMap(Y=>{var Q;return(Q=Y==null?void 0:Y.questionData)==null?void 0:Q.map(oe=>({id:oe.id,value:L[oe.id]||"",sectionId:Y.id,type:oe.type,metaData:{prefix:oe.prefix,dateFormat:oe.dateFormat}}))});q(U),m(L)},[L,f,q,s,m]),x.useEffect(()=>{n!=null&&n.length&&I(ic(n))},[n,I]);const W=x.useCallback(U=>{const Y=f.flatMap(Q=>{var oe;return(oe=Q==null?void 0:Q.questionData)==null?void 0:oe.map(ue=>({id:ue.id,value:U[ue.id]||"",sectionId:Q.id,type:ue.type,metaData:{prefix:ue.prefix,dateFormat:ue.dateFormat}}))});Object.keys(O).length>0||o==null||o(Y)},[O,f,o]),Z=x.useCallback(async()=>{var U,Y;if(l==="conversational"){if(!i){const Q=z[p];if(!Q)return;const oe=Q.gridChildren?Q.gridChildren.map(fe=>fe.id):[Q.id];if(!await _(oe))return}p<z.length-1?y(Q=>Q+1):k(W)();return}if(!i){const Q=(Y=(U=f==null?void 0:f[h])==null?void 0:U.questionData)==null?void 0:Y.map(ue=>ue.id);if(!await _(Q))return}v(Q=>Q+1)},[h,p,z,f,i,_,l,k,W]),X=x.useCallback(()=>{if(l==="conversational"){y(U=>Math.max(0,U-1));return}v(U=>U-1)},[l]),ie=x.useMemo(()=>({register:A,setValue:C,watch:T,errors:O,trigger:_,isSubmitting:M,isReadOnly:t,getValues:P,setError:B,clearErrors:H,apiActivityCount:b}),[A,C,T,O,_,M,t,P,B,H,b]);return a.jsxs($e.FormProvider,{...N,children:[a.jsx(Ae.Toaster,{position:"top-right",richColors:!0,closeButton:!0}),a.jsxs("form",{onSubmit:k(W),className:"container h-full mx-auto",children:[a.jsx("div",{className:"relative flex flex-col w-full min-w-0 py-4 gap-y-12",children:a.jsxs("div",{className:"multi_section__box min-w-0",children:[l==="multi"&&(((R=f==null?void 0:f[h])==null?void 0:R.title)||((j=f==null?void 0:f[h])==null?void 0:j.description))&&a.jsxs("div",{className:"py-4 mb-4 border-b border-gray-100 multi_section__title",children:[((ee=f[h])==null?void 0:ee.title)&&a.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:(J=f[h])==null?void 0:J.title}),((K=f[h])==null?void 0:K.description)&&a.jsx("p",{className:"text-sm",children:($=f[h])==null?void 0:$.description})]}),l==="multi"?a.jsx(ec,{form_data:f,options:ie,current:h}):l==="conversational"?a.jsx(nc,{element:z[p],options:ie,onNext:Z,onPrev:X,isFirst:p===0,isLast:p===z.length-1,isReadOnly:t}):a.jsx(Ru,{form_data:f,options:ie})]},l==="conversational"?`conv-${p}`:(G=f==null?void 0:f[h])==null?void 0:G.id)}),!d&&l!=="conversational"&&a.jsx("footer",{className:"flex items-center justify-end gap-4 footer flex-wrap",children:l==="multi"?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex gap-x-4 justify-between navigation_container w-full",children:[a.jsxs("div",{children:[" ",h>0&&a.jsxs("button",{type:"button",onClick:X,className:"text-gray-400 hover:text-gray-600 font-medium text-sm flex items-center gap-1 transition-colors back_btn",children:[a.jsx(te,{icon:"material-symbols:arrow-upward-rounded",iconClass:"text-lg"}),"Back"]})]}),h<S-1&&a.jsx(Fe,{type:"button",text:"Next",onClick:Z,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"})]}),(h===S-1||t)&&!i&&((F=typeof r=="function"?r({isUploading:b>0,isSubmitting:M,hasErrors:Object.keys(O).length>0}):r)!=null?F:a.jsx(Fe,{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&&((V=typeof r=="function"?r({isUploading:b>0,isSubmitting:M,hasErrors:Object.keys(O).length>0}):r)!=null?V:a.jsx(Fe,{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&&a.jsx("div",{className:"fixed bottom-0 left-0 w-full h-1.5 bg-gray-200",children:a.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"}})})]})]})},sc=x.memo(oc);function No({answerData:e,form_data:n,ignoreValidation:i,onSubmit:o,isReadOnly:s=!1,loading:t=!1,config:l={buttonColor:"#333"},renderType:r,children:d,hideFooter:c,onGetValues:m,uploadUrl:u}){x.useEffect(()=>{l&&Js("config",l)},[l]);const b=x.useCallback(h=>{m&&m(h)},[m]);return t?a.jsx(yo,{}):n?a.jsxs("div",{className:"w-full h-full min-w-0",children:[a.jsx("div",{id:"root-portal"}),a.jsx(Ss,{children:a.jsx(sc,{form_data:n,answerData:e,ignoreValidation:i,onSubmitData:o,isReadOnly:s,renderType:r,hideFooter:c,onGetValues:b,uploadUrl:u,children:d})})]}):a.jsx("div",{children:a.jsx("p",{className:"p-6 text-sm text-gray-400",children:"Error: No form data available."})})}function ke(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=ke(e[i]))!==""&&(n+=(n&&" ")+o);else for(let i in e)e[i]&&(n+=(n&&" ")+i);return n}var ac={value:()=>{}};function ci(){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 mi(i)}function mi(e){this._=e}function tc(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}})}mi.prototype=ci.prototype={constructor:mi,on:function(e,n){var i=this._,o=tc(e+"",i),s,t=-1,l=o.length;if(arguments.length<2){for(;++t<l;)if((s=(e=o[t]).type)&&(s=lc(i[s],e.name)))return s;return}if(n!=null&&typeof n!="function")throw new Error("invalid callback: "+n);for(;++t<l;)if(s=(e=o[t]).type)i[s]=aa(i[s],e.name,n);else if(n==null)for(s in i)i[s]=aa(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 mi(e)},call:function(e,n){if((s=arguments.length-2)>0)for(var i=new Array(s),o=0,s,t;o<s;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(t=this._[e],o=0,s=t.length;o<s;++o)t[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,t=o.length;s<t;++s)o[s].value.apply(n,i)}};function lc(e,n){for(var i=0,o=e.length,s;i<o;++i)if((s=e[i]).name===n)return s.value}function aa(e,n,i){for(var o=0,s=e.length;o<s;++o)if(e[o].name===n){e[o]=ac,e=e.slice(0,o).concat(e.slice(o+1));break}return i!=null&&e.push({name:n,value:i}),e}var Ao="http://www.w3.org/1999/xhtml";const ta={svg:"http://www.w3.org/2000/svg",xhtml:Ao,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function bi(e){var n=e+="",i=n.indexOf(":");return i>=0&&(n=e.slice(0,i))!=="xmlns"&&(e=e.slice(i+1)),ta.hasOwnProperty(n)?{space:ta[n],local:e}:e}function rc(e){return function(){var n=this.ownerDocument,i=this.namespaceURI;return i===Ao&&n.documentElement.namespaceURI===Ao?n.createElement(e):n.createElementNS(i,e)}}function dc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function la(e){var n=bi(e);return(n.local?dc:rc)(n)}function uc(){}function Co(e){return e==null?uc:function(){return this.querySelector(e)}}function cc(e){typeof e!="function"&&(e=Co(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var t=n[s],l=t.length,r=o[s]=new Array(l),d,c,m=0;m<l;++m)(d=t[m])&&(c=e.call(d,d.__data__,m,t))&&("__data__"in d&&(c.__data__=d.__data__),r[m]=c);return new Be(o,this._parents)}function mc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function bc(){return[]}function ra(e){return e==null?bc:function(){return this.querySelectorAll(e)}}function vc(e){return function(){return mc(e.apply(this,arguments))}}function hc(e){typeof e=="function"?e=vc(e):e=ra(e);for(var n=this._groups,i=n.length,o=[],s=[],t=0;t<i;++t)for(var l=n[t],r=l.length,d,c=0;c<r;++c)(d=l[c])&&(o.push(e.call(d,d.__data__,c,l)),s.push(d));return new Be(o,s)}function da(e){return function(){return this.matches(e)}}function ua(e){return function(n){return n.matches(e)}}var fc=Array.prototype.find;function pc(e){return function(){return fc.call(this.children,e)}}function gc(){return this.firstElementChild}function yc(e){return this.select(e==null?gc:pc(typeof e=="function"?e:ua(e)))}var xc=Array.prototype.filter;function Sc(){return Array.from(this.children)}function wc(e){return function(){return xc.call(this.children,e)}}function Nc(e){return this.selectAll(e==null?Sc:wc(typeof e=="function"?e:ua(e)))}function Ac(e){typeof e!="function"&&(e=da(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var t=n[s],l=t.length,r=o[s]=[],d,c=0;c<l;++c)(d=t[c])&&e.call(d,d.__data__,c,t)&&r.push(d);return new Be(o,this._parents)}function ca(e){return new Array(e.length)}function Cc(){return new Be(this._enter||this._groups.map(ca),this._parents)}function vi(e,n){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=n}vi.prototype={constructor:vi,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 kc(e){return function(){return e}}function Mc(e,n,i,o,s,t){for(var l=0,r,d=n.length,c=t.length;l<c;++l)(r=n[l])?(r.__data__=t[l],o[l]=r):i[l]=new vi(e,t[l]);for(;l<d;++l)(r=n[l])&&(s[l]=r)}function Ec(e,n,i,o,s,t,l){var r,d,c=new Map,m=n.length,u=t.length,b=new Array(m),h;for(r=0;r<m;++r)(d=n[r])&&(b[r]=h=l.call(d,d.__data__,r,n)+"",c.has(h)?s[r]=d:c.set(h,d));for(r=0;r<u;++r)h=l.call(e,t[r],r,t)+"",(d=c.get(h))?(o[r]=d,d.__data__=t[r],c.delete(h)):i[r]=new vi(e,t[r]);for(r=0;r<m;++r)(d=n[r])&&c.get(b[r])===d&&(s[r]=d)}function Tc(e){return e.__data__}function Pc(e,n){if(!arguments.length)return Array.from(this,Tc);var i=n?Ec:Mc,o=this._parents,s=this._groups;typeof e!="function"&&(e=kc(e));for(var t=s.length,l=new Array(t),r=new Array(t),d=new Array(t),c=0;c<t;++c){var m=o[c],u=s[c],b=u.length,h=Lc(e.call(m,m&&m.__data__,c,o)),v=h.length,p=r[c]=new Array(v),y=l[c]=new Array(v),f=d[c]=new Array(b);i(m,u,p,y,f,h,n);for(var S=0,g=0,w,N;S<v;++S)if(w=p[S]){for(S>=g&&(g=S+1);!(N=y[g])&&++g<v;);w._next=N||null}}return l=new Be(l,o),l._enter=r,l._exit=d,l}function Lc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Bc(){return new Be(this._exit||this._groups.map(ca),this._parents)}function Ic(e,n,i){var o=this.enter(),s=this,t=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?t.remove():i(t),o&&s?o.merge(s).order():s}function Dc(e){for(var n=e.selection?e.selection():e,i=this._groups,o=n._groups,s=i.length,t=o.length,l=Math.min(s,t),r=new Array(s),d=0;d<l;++d)for(var c=i[d],m=o[d],u=c.length,b=r[d]=new Array(u),h,v=0;v<u;++v)(h=c[v]||m[v])&&(b[v]=h);for(;d<s;++d)r[d]=i[d];return new Be(r,this._parents)}function _c(){for(var e=this._groups,n=-1,i=e.length;++n<i;)for(var o=e[n],s=o.length-1,t=o[s],l;--s>=0;)(l=o[s])&&(t&&l.compareDocumentPosition(t)^4&&t.parentNode.insertBefore(l,t),t=l);return this}function Oc(e){e||(e=Kc);function n(u,b){return u&&b?e(u.__data__,b.__data__):!u-!b}for(var i=this._groups,o=i.length,s=new Array(o),t=0;t<o;++t){for(var l=i[t],r=l.length,d=s[t]=new Array(r),c,m=0;m<r;++m)(c=l[m])&&(d[m]=c);d.sort(n)}return new Be(s,this._parents).order()}function Kc(e,n){return e<n?-1:e>n?1:e>=n?0:NaN}function Hc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Gc(){return Array.from(this)}function Fc(){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var o=e[n],s=0,t=o.length;s<t;++s){var l=o[s];if(l)return l}return null}function Vc(){let e=0;for(const n of this)++e;return e}function zc(){return!this.node()}function Wc(e){for(var n=this._groups,i=0,o=n.length;i<o;++i)for(var s=n[i],t=0,l=s.length,r;t<l;++t)(r=s[t])&&e.call(r,r.__data__,t,s);return this}function $c(e){return function(){this.removeAttribute(e)}}function jc(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Uc(e,n){return function(){this.setAttribute(e,n)}}function qc(e,n){return function(){this.setAttributeNS(e.space,e.local,n)}}function Yc(e,n){return function(){var i=n.apply(this,arguments);i==null?this.removeAttribute(e):this.setAttribute(e,i)}}function Jc(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 Zc(e,n){var i=bi(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?jc:$c:typeof n=="function"?i.local?Jc:Yc:i.local?qc:Uc)(i,n))}function ma(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Xc(e){return function(){this.style.removeProperty(e)}}function Qc(e,n,i){return function(){this.style.setProperty(e,n,i)}}function Rc(e,n,i){return function(){var o=n.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,i)}}function em(e,n,i){return arguments.length>1?this.each((n==null?Xc:typeof n=="function"?Rc:Qc)(e,n,i==null?"":i)):fn(this.node(),e)}function fn(e,n){return e.style.getPropertyValue(n)||ma(e).getComputedStyle(e,null).getPropertyValue(n)}function nm(e){return function(){delete this[e]}}function im(e,n){return function(){this[e]=n}}function om(e,n){return function(){var i=n.apply(this,arguments);i==null?delete this[e]:this[e]=i}}function sm(e,n){return arguments.length>1?this.each((n==null?nm:typeof n=="function"?om:im)(e,n)):this.node()[e]}function ba(e){return e.trim().split(/^|\s+/)}function ko(e){return e.classList||new va(e)}function va(e){this._node=e,this._names=ba(e.getAttribute("class")||"")}va.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 ha(e,n){for(var i=ko(e),o=-1,s=n.length;++o<s;)i.add(n[o])}function fa(e,n){for(var i=ko(e),o=-1,s=n.length;++o<s;)i.remove(n[o])}function am(e){return function(){ha(this,e)}}function tm(e){return function(){fa(this,e)}}function lm(e,n){return function(){(n.apply(this,arguments)?ha:fa)(this,e)}}function rm(e,n){var i=ba(e+"");if(arguments.length<2){for(var o=ko(this.node()),s=-1,t=i.length;++s<t;)if(!o.contains(i[s]))return!1;return!0}return this.each((typeof n=="function"?lm:n?am:tm)(i,n))}function dm(){this.textContent=""}function um(e){return function(){this.textContent=e}}function cm(e){return function(){var n=e.apply(this,arguments);this.textContent=n==null?"":n}}function mm(e){return arguments.length?this.each(e==null?dm:(typeof e=="function"?cm:um)(e)):this.node().textContent}function bm(){this.innerHTML=""}function vm(e){return function(){this.innerHTML=e}}function hm(e){return function(){var n=e.apply(this,arguments);this.innerHTML=n==null?"":n}}function fm(e){return arguments.length?this.each(e==null?bm:(typeof e=="function"?hm:vm)(e)):this.node().innerHTML}function pm(){this.nextSibling&&this.parentNode.appendChild(this)}function gm(){return this.each(pm)}function ym(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function xm(){return this.each(ym)}function Sm(e){var n=typeof e=="function"?e:la(e);return this.select(function(){return this.appendChild(n.apply(this,arguments))})}function wm(){return null}function Nm(e,n){var i=typeof e=="function"?e:la(e),o=n==null?wm:typeof n=="function"?n:Co(n);return this.select(function(){return this.insertBefore(i.apply(this,arguments),o.apply(this,arguments)||null)})}function Am(){var e=this.parentNode;e&&e.removeChild(this)}function Cm(){return this.each(Am)}function km(){var e=this.cloneNode(!1),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Mm(){var e=this.cloneNode(!0),n=this.parentNode;return n?n.insertBefore(e,this.nextSibling):e}function Em(e){return this.select(e?Mm:km)}function Tm(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Pm(e){return function(n){e.call(this,n,this.__data__)}}function Lm(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 Bm(e){return function(){var n=this.__on;if(n){for(var i=0,o=-1,s=n.length,t;i<s;++i)t=n[i],(!e.type||t.type===e.type)&&t.name===e.name?this.removeEventListener(t.type,t.listener,t.options):n[++o]=t;++o?n.length=o:delete this.__on}}}function Im(e,n,i){return function(){var o=this.__on,s,t=Pm(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=t,s.options=i),s.value=n;return}}this.addEventListener(e.type,t,i),s={type:e.type,name:e.name,value:n,listener:t,options:i},o?o.push(s):this.__on=[s]}}function Dm(e,n,i){var o=Lm(e+""),s,t=o.length,l;if(arguments.length<2){var r=this.node().__on;if(r){for(var d=0,c=r.length,m;d<c;++d)for(s=0,m=r[d];s<t;++s)if((l=o[s]).type===m.type&&l.name===m.name)return m.value}return}for(r=n?Im:Bm,s=0;s<t;++s)this.each(r(o[s],n,i));return this}function pa(e,n,i){var o=ma(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 _m(e,n){return function(){return pa(this,e,n)}}function Om(e,n){return function(){return pa(this,e,n.apply(this,arguments))}}function Km(e,n){return this.each((typeof n=="function"?Om:_m)(e,n))}function*Hm(){for(var e=this._groups,n=0,i=e.length;n<i;++n)for(var o=e[n],s=0,t=o.length,l;s<t;++s)(l=o[s])&&(yield l)}var ga=[null];function Be(e,n){this._groups=e,this._parents=n}function Dn(){return new Be([[document.documentElement]],ga)}function Gm(){return this}Be.prototype=Dn.prototype={constructor:Be,select:cc,selectAll:hc,selectChild:yc,selectChildren:Nc,filter:Ac,data:Pc,enter:Cc,exit:Bc,join:Ic,merge:Dc,selection:Gm,order:_c,sort:Oc,call:Hc,nodes:Gc,node:Fc,size:Vc,empty:zc,each:Wc,attr:Zc,style:em,property:sm,classed:rm,text:mm,html:fm,raise:gm,lower:xm,append:Sm,insert:Nm,remove:Cm,clone:Em,datum:Tm,on:Dm,dispatch:Km,[Symbol.iterator]:Hm};function Ie(e){return typeof e=="string"?new Be([[document.querySelector(e)]],[document.documentElement]):new Be([[e]],ga)}function Fm(e){let n;for(;n=e.sourceEvent;)e=n;return e}function _e(e,n){if(e=Fm(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 Vm={passive:!1},_n={capture:!0,passive:!1};function Mo(e){e.stopImmediatePropagation()}function pn(e){e.preventDefault(),e.stopImmediatePropagation()}function ya(e){var n=e.document.documentElement,i=Ie(e).on("dragstart.drag",pn,_n);"onselectstart"in n?i.on("selectstart.drag",pn,_n):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function xa(e,n){var i=e.document.documentElement,o=Ie(e).on("dragstart.drag",null);n&&(o.on("click.drag",pn,_n),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 hi=e=>()=>e;function Eo(e,{sourceEvent:n,subject:i,target:o,identifier:s,active:t,x:l,y:r,dx:d,dy:c,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:t,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:c,enumerable:!0,configurable:!0},_:{value:m}})}Eo.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function zm(e){return!e.ctrlKey&&!e.button}function Wm(){return this.parentNode}function $m(e,n){return n==null?{x:e.x,y:e.y}:n}function jm(){return navigator.maxTouchPoints||"ontouchstart"in this}function Sa(){var e=zm,n=Wm,i=$m,o=jm,s={},t=ci("start","drag","end"),l=0,r,d,c,m,u=0;function b(w){w.on("mousedown.drag",h).filter(o).on("touchstart.drag",y).on("touchmove.drag",f,Vm).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(w,N){if(!(m||!e.call(this,w,N))){var A=g(this,n.call(this,w,N),w,N,"mouse");A&&(Ie(w.view).on("mousemove.drag",v,_n).on("mouseup.drag",p,_n),ya(w.view),Mo(w),c=!1,r=w.clientX,d=w.clientY,A("start",w))}}function v(w){if(pn(w),!c){var N=w.clientX-r,A=w.clientY-d;c=N*N+A*A>u}s.mouse("drag",w)}function p(w){Ie(w.view).on("mousemove.drag mouseup.drag",null),xa(w.view,c),pn(w),s.mouse("end",w)}function y(w,N){if(e.call(this,w,N)){var A=w.changedTouches,C=n.call(this,w,N),E=A.length,k,I;for(k=0;k<E;++k)(I=g(this,C,w,N,A[k].identifier,A[k]))&&(Mo(w),I("start",w,A[k]))}}function f(w){var N=w.changedTouches,A=N.length,C,E;for(C=0;C<A;++C)(E=s[N[C].identifier])&&(pn(w),E("drag",w,N[C]))}function S(w){var N=w.changedTouches,A=N.length,C,E;for(m&&clearTimeout(m),m=setTimeout(function(){m=null},500),C=0;C<A;++C)(E=s[N[C].identifier])&&(Mo(w),E("end",w,N[C]))}function g(w,N,A,C,E,k){var I=t.copy(),P=_e(k||A,N),T,O,M;if((M=i.call(w,new Eo("beforestart",{sourceEvent:A,target:b,identifier:E,active:l,x:P[0],y:P[1],dx:0,dy:0,dispatch:I}),C))!=null)return T=M.x-P[0]||0,O=M.y-P[1]||0,function _(B,H,D){var L=P,z;switch(B){case"start":s[E]=_,z=l++;break;case"end":delete s[E],--l;case"drag":P=_e(D||H,N),z=l;break}I.call(B,w,new Eo(B,{sourceEvent:H,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:I}),C)}}return b.filter=function(w){return arguments.length?(e=typeof w=="function"?w:hi(!!w),b):e},b.container=function(w){return arguments.length?(n=typeof w=="function"?w:hi(w),b):n},b.subject=function(w){return arguments.length?(i=typeof w=="function"?w:hi(w),b):i},b.touchable=function(w){return arguments.length?(o=typeof w=="function"?w:hi(!!w),b):o},b.on=function(){var w=t.on.apply(t,arguments);return w===t?b:w},b.clickDistance=function(w){return arguments.length?(u=(w=+w)*w,b):Math.sqrt(u)},b}function To(e,n,i){e.prototype=n.prototype=i,i.constructor=e}function wa(e,n){var i=Object.create(e.prototype);for(var o in n)i[o]=n[o];return i}function On(){}var Kn=.7,fi=1/Kn,gn="\\s*([+-]?\\d+)\\s*",Hn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ve="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Um=/^#([0-9a-f]{3,8})$/,qm=new RegExp(`^rgb\\(${gn},${gn},${gn}\\)$`),Ym=new RegExp(`^rgb\\(${Ve},${Ve},${Ve}\\)$`),Jm=new RegExp(`^rgba\\(${gn},${gn},${gn},${Hn}\\)$`),Zm=new RegExp(`^rgba\\(${Ve},${Ve},${Ve},${Hn}\\)$`),Xm=new RegExp(`^hsl\\(${Hn},${Ve},${Ve}\\)$`),Qm=new RegExp(`^hsla\\(${Hn},${Ve},${Ve},${Hn}\\)$`),Na={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};To(On,nn,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Aa,formatHex:Aa,formatHex8:Rm,formatHsl:eb,formatRgb:Ca,toString:Ca});function Aa(){return this.rgb().formatHex()}function Rm(){return this.rgb().formatHex8()}function eb(){return Pa(this).formatHsl()}function Ca(){return this.rgb().formatRgb()}function nn(e){var n,i;return e=(e+"").trim().toLowerCase(),(n=Um.exec(e))?(i=n[1].length,n=parseInt(n[1],16),i===6?ka(n):i===3?new Le(n>>8&15|n>>4&240,n>>4&15|n&240,(n&15)<<4|n&15,1):i===8?pi(n>>24&255,n>>16&255,n>>8&255,(n&255)/255):i===4?pi(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=qm.exec(e))?new Le(n[1],n[2],n[3],1):(n=Ym.exec(e))?new Le(n[1]*255/100,n[2]*255/100,n[3]*255/100,1):(n=Jm.exec(e))?pi(n[1],n[2],n[3],n[4]):(n=Zm.exec(e))?pi(n[1]*255/100,n[2]*255/100,n[3]*255/100,n[4]):(n=Xm.exec(e))?Ta(n[1],n[2]/100,n[3]/100,1):(n=Qm.exec(e))?Ta(n[1],n[2]/100,n[3]/100,n[4]):Na.hasOwnProperty(e)?ka(Na[e]):e==="transparent"?new Le(NaN,NaN,NaN,0):null}function ka(e){return new Le(e>>16&255,e>>8&255,e&255,1)}function pi(e,n,i,o){return o<=0&&(e=n=i=NaN),new Le(e,n,i,o)}function nb(e){return e instanceof On||(e=nn(e)),e?(e=e.rgb(),new Le(e.r,e.g,e.b,e.opacity)):new Le}function Po(e,n,i,o){return arguments.length===1?nb(e):new Le(e,n,i,o==null?1:o)}function Le(e,n,i,o){this.r=+e,this.g=+n,this.b=+i,this.opacity=+o}To(Le,Po,wa(On,{brighter(e){return e=e==null?fi:Math.pow(fi,e),new Le(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kn:Math.pow(Kn,e),new Le(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Le(on(this.r),on(this.g),on(this.b),gi(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:Ma,formatHex:Ma,formatHex8:ib,formatRgb:Ea,toString:Ea}));function Ma(){return`#${sn(this.r)}${sn(this.g)}${sn(this.b)}`}function ib(){return`#${sn(this.r)}${sn(this.g)}${sn(this.b)}${sn((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ea(){const e=gi(this.opacity);return`${e===1?"rgb(":"rgba("}${on(this.r)}, ${on(this.g)}, ${on(this.b)}${e===1?")":`, ${e})`}`}function gi(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function on(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function sn(e){return e=on(e),(e<16?"0":"")+e.toString(16)}function Ta(e,n,i,o){return o<=0?e=n=i=NaN:i<=0||i>=1?e=n=NaN:n<=0&&(e=NaN),new Oe(e,n,i,o)}function Pa(e){if(e instanceof Oe)return new Oe(e.h,e.s,e.l,e.opacity);if(e instanceof On||(e=nn(e)),!e)return new Oe;if(e instanceof Oe)return e;e=e.rgb();var n=e.r/255,i=e.g/255,o=e.b/255,s=Math.min(n,i,o),t=Math.max(n,i,o),l=NaN,r=t-s,d=(t+s)/2;return r?(n===t?l=(i-o)/r+(i<o)*6:i===t?l=(o-n)/r+2:l=(n-i)/r+4,r/=d<.5?t+s:2-t-s,l*=60):r=d>0&&d<1?0:l,new Oe(l,r,d,e.opacity)}function ob(e,n,i,o){return arguments.length===1?Pa(e):new Oe(e,n,i,o==null?1:o)}function Oe(e,n,i,o){this.h=+e,this.s=+n,this.l=+i,this.opacity=+o}To(Oe,ob,wa(On,{brighter(e){return e=e==null?fi:Math.pow(fi,e),new Oe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kn:Math.pow(Kn,e),new Oe(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 Le(Lo(e>=240?e-240:e+120,s,o),Lo(e,s,o),Lo(e<120?e+240:e-120,s,o),this.opacity)},clamp(){return new Oe(La(this.h),yi(this.s),yi(this.l),gi(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=gi(this.opacity);return`${e===1?"hsl(":"hsla("}${La(this.h)}, ${yi(this.s)*100}%, ${yi(this.l)*100}%${e===1?")":`, ${e})`}`}}));function La(e){return e=(e||0)%360,e<0?e+360:e}function yi(e){return Math.max(0,Math.min(1,e||0))}function Lo(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 Bo=e=>()=>e;function sb(e,n){return function(i){return e+i*n}}function ab(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 tb(e){return(e=+e)==1?Ba:function(n,i){return i-n?ab(n,i,e):Bo(isNaN(n)?i:n)}}function Ba(e,n){var i=n-e;return i?sb(e,i):Bo(isNaN(e)?n:e)}const xi=function e(n){var i=tb(n);function o(s,t){var l=i((s=Po(s)).r,(t=Po(t)).r),r=i(s.g,t.g),d=i(s.b,t.b),c=Ba(s.opacity,t.opacity);return function(m){return s.r=l(m),s.g=r(m),s.b=d(m),s.opacity=c(m),s+""}}return o.gamma=e,o}(1);function lb(e,n){n||(n=[]);var i=e?Math.min(n.length,e.length):0,o=n.slice(),s;return function(t){for(s=0;s<i;++s)o[s]=e[s]*(1-t)+n[s]*t;return o}}function rb(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function db(e,n){var i=n?n.length:0,o=e?Math.min(i,e.length):0,s=new Array(o),t=new Array(i),l;for(l=0;l<o;++l)s[l]=Gn(e[l],n[l]);for(;l<i;++l)t[l]=n[l];return function(r){for(l=0;l<o;++l)t[l]=s[l](r);return t}}function ub(e,n){var i=new Date;return e=+e,n=+n,function(o){return i.setTime(e*(1-o)+n*o),i}}function ze(e,n){return e=+e,n=+n,function(i){return e*(1-i)+n*i}}function cb(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]=Gn(e[s],n[s]):o[s]=n[s];return function(t){for(s in i)o[s]=i[s](t);return o}}var Io=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Do=new RegExp(Io.source,"g");function mb(e){return function(){return e}}function bb(e){return function(n){return e(n)+""}}function Ia(e,n){var i=Io.lastIndex=Do.lastIndex=0,o,s,t,l=-1,r=[],d=[];for(e=e+"",n=n+"";(o=Io.exec(e))&&(s=Do.exec(n));)(t=s.index)>i&&(t=n.slice(i,t),r[l]?r[l]+=t:r[++l]=t),(o=o[0])===(s=s[0])?r[l]?r[l]+=s:r[++l]=s:(r[++l]=null,d.push({i:l,x:ze(o,s)})),i=Do.lastIndex;return i<n.length&&(t=n.slice(i),r[l]?r[l]+=t:r[++l]=t),r.length<2?d[0]?bb(d[0].x):mb(n):(n=d.length,function(c){for(var m=0,u;m<n;++m)r[(u=d[m]).i]=u.x(c);return r.join("")})}function Gn(e,n){var i=typeof n,o;return n==null||i==="boolean"?Bo(n):(i==="number"?ze:i==="string"?(o=nn(n))?(n=o,xi):Ia:n instanceof nn?xi:n instanceof Date?ub:rb(n)?lb:Array.isArray(n)?db:typeof n.valueOf!="function"&&typeof n.toString!="function"||isNaN(n)?cb:ze)(e,n)}var Da=180/Math.PI,_o={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function _a(e,n,i,o,s,t){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:t,rotate:Math.atan2(n,e)*Da,skewX:Math.atan(d)*Da,scaleX:l,scaleY:r}}var Si;function vb(e){const n=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return n.isIdentity?_o:_a(n.a,n.b,n.c,n.d,n.e,n.f)}function hb(e){return e==null||(Si||(Si=document.createElementNS("http://www.w3.org/2000/svg","g")),Si.setAttribute("transform",e),!(e=Si.transform.baseVal.consolidate()))?_o:(e=e.matrix,_a(e.a,e.b,e.c,e.d,e.e,e.f))}function Oa(e,n,i,o){function s(c){return c.length?c.pop()+" ":""}function t(c,m,u,b,h,v){if(c!==u||m!==b){var p=h.push("translate(",null,n,null,i);v.push({i:p-4,x:ze(c,u)},{i:p-2,x:ze(m,b)})}else(u||b)&&h.push("translate("+u+n+b+i)}function l(c,m,u,b){c!==m?(c-m>180?m+=360:m-c>180&&(c+=360),b.push({i:u.push(s(u)+"rotate(",null,o)-2,x:ze(c,m)})):m&&u.push(s(u)+"rotate("+m+o)}function r(c,m,u,b){c!==m?b.push({i:u.push(s(u)+"skewX(",null,o)-2,x:ze(c,m)}):m&&u.push(s(u)+"skewX("+m+o)}function d(c,m,u,b,h,v){if(c!==u||m!==b){var p=h.push(s(h)+"scale(",null,",",null,")");v.push({i:p-4,x:ze(c,u)},{i:p-2,x:ze(m,b)})}else(u!==1||b!==1)&&h.push(s(h)+"scale("+u+","+b+")")}return function(c,m){var u=[],b=[];return c=e(c),m=e(m),t(c.translateX,c.translateY,m.translateX,m.translateY,u,b),l(c.rotate,m.rotate,u,b),r(c.skewX,m.skewX,u,b),d(c.scaleX,c.scaleY,m.scaleX,m.scaleY,u,b),c=m=null,function(h){for(var v=-1,p=b.length,y;++v<p;)u[(y=b[v]).i]=y.x(h);return u.join("")}}}var fb=Oa(vb,"px, ","px)","deg)"),pb=Oa(hb,", ",")",")"),gb=1e-12;function Ka(e){return((e=Math.exp(e))+1/e)/2}function yb(e){return((e=Math.exp(e))-1/e)/2}function xb(e){return((e=Math.exp(2*e))-1)/(e+1)}const wi=function e(n,i,o){function s(t,l){var r=t[0],d=t[1],c=t[2],m=l[0],u=l[1],b=l[2],h=m-r,v=u-d,p=h*h+v*v,y,f;if(p<gb)f=Math.log(b/c)/n,y=function(C){return[r+C*h,d+C*v,c*Math.exp(n*C*f)]};else{var S=Math.sqrt(p),g=(b*b-c*c+o*p)/(2*c*i*S),w=(b*b-c*c-o*p)/(2*b*i*S),N=Math.log(Math.sqrt(g*g+1)-g),A=Math.log(Math.sqrt(w*w+1)-w);f=(A-N)/n,y=function(C){var E=C*f,k=Ka(N),I=c/(i*S)*(k*xb(n*E+N)-yb(N));return[r+I*h,d+I*v,c*k/Ka(n*E+N)]}}return y.duration=f*1e3*n/Math.SQRT2,y}return s.rho=function(t){var l=Math.max(.001,+t),r=l*l,d=r*r;return e(l,r,d)},s}(Math.SQRT2,2,4);var yn=0,Fn=0,Vn=0,Ha=1e3,Ni,zn,Ai=0,an=0,Ci=0,Wn=typeof performance=="object"&&performance.now?performance:Date,Ga=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Oo(){return an||(Ga(Sb),an=Wn.now()+Ci)}function Sb(){an=0}function ki(){this._call=this._time=this._next=null}ki.prototype=Fa.prototype={constructor:ki,restart:function(e,n,i){if(typeof e!="function")throw new TypeError("callback is not a function");i=(i==null?Oo():+i)+(n==null?0:+n),!this._next&&zn!==this&&(zn?zn._next=this:Ni=this,zn=this),this._call=e,this._time=i,Ko()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ko())}};function Fa(e,n,i){var o=new ki;return o.restart(e,n,i),o}function wb(){Oo(),++yn;for(var e=Ni,n;e;)(n=an-e._time)>=0&&e._call.call(void 0,n),e=e._next;--yn}function Va(){an=(Ai=Wn.now())+Ci,yn=Fn=0;try{wb()}finally{yn=0,Ab(),an=0}}function Nb(){var e=Wn.now(),n=e-Ai;n>Ha&&(Ci-=n,Ai=e)}function Ab(){for(var e,n=Ni,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:Ni=i);zn=e,Ko(o)}function Ko(e){if(!yn){Fn&&(Fn=clearTimeout(Fn));var n=e-an;n>24?(e<1/0&&(Fn=setTimeout(Va,e-Wn.now()-Ci)),Vn&&(Vn=clearInterval(Vn))):(Vn||(Ai=Wn.now(),Vn=setInterval(Nb,Ha)),yn=1,Ga(Va))}}function za(e,n,i){var o=new ki;return n=n==null?0:+n,o.restart(s=>{o.stop(),e(s+n)},n,i),o}var Cb=ci("start","end","cancel","interrupt"),kb=[],Wa=0,$a=1,Ho=2,Mi=3,ja=4,Go=5,Ei=6;function Ti(e,n,i,o,s,t){var l=e.__transition;if(!l)e.__transition={};else if(i in l)return;Mb(e,i,{name:n,index:o,group:s,on:Cb,tween:kb,time:t.time,delay:t.delay,duration:t.duration,ease:t.ease,timer:null,state:Wa})}function Fo(e,n){var i=Ke(e,n);if(i.state>Wa)throw new Error("too late; already scheduled");return i}function We(e,n){var i=Ke(e,n);if(i.state>Mi)throw new Error("too late; already running");return i}function Ke(e,n){var i=e.__transition;if(!i||!(i=i[n]))throw new Error("transition not found");return i}function Mb(e,n,i){var o=e.__transition,s;o[n]=i,i.timer=Fa(t,0,i.time);function t(c){i.state=$a,i.timer.restart(l,i.delay,i.time),i.delay<=c&&l(c-i.delay)}function l(c){var m,u,b,h;if(i.state!==$a)return d();for(m in o)if(h=o[m],h.name===i.name){if(h.state===Mi)return za(l);h.state===ja?(h.state=Ei,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete o[m]):+m<n&&(h.state=Ei,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete o[m])}if(za(function(){i.state===Mi&&(i.state=ja,i.timer.restart(r,i.delay,i.time),r(c))}),i.state=Ho,i.on.call("start",e,e.__data__,i.index,i.group),i.state===Ho){for(i.state=Mi,s=new Array(b=i.tween.length),m=0,u=-1;m<b;++m)(h=i.tween[m].value.call(e,e.__data__,i.index,i.group))&&(s[++u]=h);s.length=u+1}}function r(c){for(var m=c<i.duration?i.ease.call(null,c/i.duration):(i.timer.restart(d),i.state=Go,1),u=-1,b=s.length;++u<b;)s[u].call(e,m);i.state===Go&&(i.on.call("end",e,e.__data__,i.index,i.group),d())}function d(){i.state=Ei,i.timer.stop(),delete o[n];for(var c in o)return;delete e.__transition}}function Pi(e,n){var i=e.__transition,o,s,t=!0,l;if(i){n=n==null?null:n+"";for(l in i){if((o=i[l]).name!==n){t=!1;continue}s=o.state>Ho&&o.state<Go,o.state=Ei,o.timer.stop(),o.on.call(s?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete i[l]}t&&delete e.__transition}}function Eb(e){return this.each(function(){Pi(this,e)})}function Tb(e,n){var i,o;return function(){var s=We(this,e),t=s.tween;if(t!==i){o=i=t;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 Pb(e,n,i){var o,s;if(typeof i!="function")throw new Error;return function(){var t=We(this,e),l=t.tween;if(l!==o){s=(o=l).slice();for(var r={name:n,value:i},d=0,c=s.length;d<c;++d)if(s[d].name===n){s[d]=r;break}d===c&&s.push(r)}t.tween=s}}function Lb(e,n){var i=this._id;if(e+="",arguments.length<2){for(var o=Ke(this.node(),i).tween,s=0,t=o.length,l;s<t;++s)if((l=o[s]).name===e)return l.value;return null}return this.each((n==null?Tb:Pb)(i,e,n))}function Vo(e,n,i){var o=e._id;return e.each(function(){var s=We(this,o);(s.value||(s.value={}))[n]=i.apply(this,arguments)}),function(s){return Ke(s,o).value[n]}}function Ua(e,n){var i;return(typeof n=="number"?ze:n instanceof nn?xi:(i=nn(n))?(n=i,xi):Ia)(e,n)}function Bb(e){return function(){this.removeAttribute(e)}}function Ib(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Db(e,n,i){var o,s=i+"",t;return function(){var l=this.getAttribute(e);return l===s?null:l===o?t:t=n(o=l,i)}}function _b(e,n,i){var o,s=i+"",t;return function(){var l=this.getAttributeNS(e.space,e.local);return l===s?null:l===o?t:t=n(o=l,i)}}function Ob(e,n,i){var o,s,t;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?t:(s=d,t=n(o=l,r)))}}function Kb(e,n,i){var o,s,t;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?t:(s=d,t=n(o=l,r)))}}function Hb(e,n){var i=bi(e),o=i==="transform"?pb:Ua;return this.attrTween(e,typeof n=="function"?(i.local?Kb:Ob)(i,o,Vo(this,"attr."+e,n)):n==null?(i.local?Ib:Bb)(i):(i.local?_b:Db)(i,o,n))}function Gb(e,n){return function(i){this.setAttribute(e,n.call(this,i))}}function Fb(e,n){return function(i){this.setAttributeNS(e.space,e.local,n.call(this,i))}}function Vb(e,n){var i,o;function s(){var t=n.apply(this,arguments);return t!==o&&(i=(o=t)&&Fb(e,t)),i}return s._value=n,s}function zb(e,n){var i,o;function s(){var t=n.apply(this,arguments);return t!==o&&(i=(o=t)&&Gb(e,t)),i}return s._value=n,s}function Wb(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=bi(e);return this.tween(i,(o.local?Vb:zb)(o,n))}function $b(e,n){return function(){Fo(this,e).delay=+n.apply(this,arguments)}}function jb(e,n){return n=+n,function(){Fo(this,e).delay=n}}function Ub(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?$b:jb)(n,e)):Ke(this.node(),n).delay}function qb(e,n){return function(){We(this,e).duration=+n.apply(this,arguments)}}function Yb(e,n){return n=+n,function(){We(this,e).duration=n}}function Jb(e){var n=this._id;return arguments.length?this.each((typeof e=="function"?qb:Yb)(n,e)):Ke(this.node(),n).duration}function Zb(e,n){if(typeof n!="function")throw new Error;return function(){We(this,e).ease=n}}function Xb(e){var n=this._id;return arguments.length?this.each(Zb(n,e)):Ke(this.node(),n).ease}function Qb(e,n){return function(){var i=n.apply(this,arguments);if(typeof i!="function")throw new Error;We(this,e).ease=i}}function Rb(e){if(typeof e!="function")throw new Error;return this.each(Qb(this._id,e))}function ev(e){typeof e!="function"&&(e=da(e));for(var n=this._groups,i=n.length,o=new Array(i),s=0;s<i;++s)for(var t=n[s],l=t.length,r=o[s]=[],d,c=0;c<l;++c)(d=t[c])&&e.call(d,d.__data__,c,t)&&r.push(d);return new je(o,this._parents,this._name,this._id)}function nv(e){if(e._id!==this._id)throw new Error;for(var n=this._groups,i=e._groups,o=n.length,s=i.length,t=Math.min(o,s),l=new Array(o),r=0;r<t;++r)for(var d=n[r],c=i[r],m=d.length,u=l[r]=new Array(m),b,h=0;h<m;++h)(b=d[h]||c[h])&&(u[h]=b);for(;r<o;++r)l[r]=n[r];return new je(l,this._parents,this._name,this._id)}function iv(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 ov(e,n,i){var o,s,t=iv(n)?Fo:We;return function(){var l=t(this,e),r=l.on;r!==o&&(s=(o=r).copy()).on(n,i),l.on=s}}function sv(e,n){var i=this._id;return arguments.length<2?Ke(this.node(),i).on.on(e):this.each(ov(i,e,n))}function av(e){return function(){var n=this.parentNode;for(var i in this.__transition)if(+i!==e)return;n&&n.removeChild(this)}}function tv(){return this.on("end.remove",av(this._id))}function lv(e){var n=this._name,i=this._id;typeof e!="function"&&(e=Co(e));for(var o=this._groups,s=o.length,t=new Array(s),l=0;l<s;++l)for(var r=o[l],d=r.length,c=t[l]=new Array(d),m,u,b=0;b<d;++b)(m=r[b])&&(u=e.call(m,m.__data__,b,r))&&("__data__"in m&&(u.__data__=m.__data__),c[b]=u,Ti(c[b],n,i,b,c,Ke(m,i)));return new je(t,this._parents,n,i)}function rv(e){var n=this._name,i=this._id;typeof e!="function"&&(e=ra(e));for(var o=this._groups,s=o.length,t=[],l=[],r=0;r<s;++r)for(var d=o[r],c=d.length,m,u=0;u<c;++u)if(m=d[u]){for(var b=e.call(m,m.__data__,u,d),h,v=Ke(m,i),p=0,y=b.length;p<y;++p)(h=b[p])&&Ti(h,n,i,p,b,v);t.push(b),l.push(m)}return new je(t,l,n,i)}var dv=Dn.prototype.constructor;function uv(){return new dv(this._groups,this._parents)}function cv(e,n){var i,o,s;return function(){var t=fn(this,e),l=(this.style.removeProperty(e),fn(this,e));return t===l?null:t===i&&l===o?s:s=n(i=t,o=l)}}function qa(e){return function(){this.style.removeProperty(e)}}function mv(e,n,i){var o,s=i+"",t;return function(){var l=fn(this,e);return l===s?null:l===o?t:t=n(o=l,i)}}function bv(e,n,i){var o,s,t;return function(){var l=fn(this,e),r=i(this),d=r+"";return r==null&&(d=r=(this.style.removeProperty(e),fn(this,e))),l===d?null:l===o&&d===s?t:(s=d,t=n(o=l,r))}}function vv(e,n){var i,o,s,t="style."+n,l="end."+t,r;return function(){var d=We(this,e),c=d.on,m=d.value[t]==null?r||(r=qa(n)):void 0;(c!==i||s!==m)&&(o=(i=c).copy()).on(l,s=m),d.on=o}}function hv(e,n,i){var o=(e+="")=="transform"?fb:Ua;return n==null?this.styleTween(e,cv(e,o)).on("end.style."+e,qa(e)):typeof n=="function"?this.styleTween(e,bv(e,o,Vo(this,"style."+e,n))).each(vv(this._id,e)):this.styleTween(e,mv(e,o,n),i).on("end.style."+e,null)}function fv(e,n,i){return function(o){this.style.setProperty(e,n.call(this,o),i)}}function pv(e,n,i){var o,s;function t(){var l=n.apply(this,arguments);return l!==s&&(o=(s=l)&&fv(e,l,i)),o}return t._value=n,t}function gv(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,pv(e,n,i==null?"":i))}function yv(e){return function(){this.textContent=e}}function xv(e){return function(){var n=e(this);this.textContent=n==null?"":n}}function Sv(e){return this.tween("text",typeof e=="function"?xv(Vo(this,"text",e)):yv(e==null?"":e+""))}function wv(e){return function(n){this.textContent=e.call(this,n)}}function Nv(e){var n,i;function o(){var s=e.apply(this,arguments);return s!==i&&(n=(i=s)&&wv(s)),n}return o._value=e,o}function Av(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,Nv(e))}function Cv(){for(var e=this._name,n=this._id,i=Ya(),o=this._groups,s=o.length,t=0;t<s;++t)for(var l=o[t],r=l.length,d,c=0;c<r;++c)if(d=l[c]){var m=Ke(d,n);Ti(d,e,i,c,l,{time:m.time+m.delay+m.duration,delay:0,duration:m.duration,ease:m.ease})}return new je(o,this._parents,e,i)}function kv(){var e,n,i=this,o=i._id,s=i.size();return new Promise(function(t,l){var r={value:l},d={value:function(){--s===0&&t()}};i.each(function(){var c=We(this,o),m=c.on;m!==e&&(n=(e=m).copy(),n._.cancel.push(r),n._.interrupt.push(r),n._.end.push(d)),c.on=n}),s===0&&t()})}var Mv=0;function je(e,n,i,o){this._groups=e,this._parents=n,this._name=i,this._id=o}function Ya(){return++Mv}var Ue=Dn.prototype;je.prototype={constructor:je,select:lv,selectAll:rv,selectChild:Ue.selectChild,selectChildren:Ue.selectChildren,filter:ev,merge:nv,selection:uv,transition:Cv,call:Ue.call,nodes:Ue.nodes,node:Ue.node,size:Ue.size,empty:Ue.empty,each:Ue.each,on:sv,attr:Hb,attrTween:Wb,style:hv,styleTween:gv,text:Sv,textTween:Av,remove:tv,tween:Lb,delay:Ub,duration:Jb,ease:Xb,easeVarying:Rb,end:kv,[Symbol.iterator]:Ue[Symbol.iterator]};function Ev(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Tv={time:null,delay:0,duration:250,ease:Ev};function Pv(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 Lv(e){var n,i;e instanceof je?(n=e._id,e=e._name):(n=Ya(),(i=Tv).time=Oo(),e=e==null?null:e+"");for(var o=this._groups,s=o.length,t=0;t<s;++t)for(var l=o[t],r=l.length,d,c=0;c<r;++c)(d=l[c])&&Ti(d,e,n,c,l,i||Pv(d,n));return new je(o,this._parents,e,n)}Dn.prototype.interrupt=Eb,Dn.prototype.transition=Lv;const Li=e=>()=>e;function Bv(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 qe(e,n,i){this.k=e,this.x=n,this.y=i}qe.prototype={constructor:qe,scale:function(e){return e===1?this:new qe(this.k*e,this.x,this.y)},translate:function(e,n){return e===0&n===0?this:new qe(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 Bi=new qe(1,0,0);Ja.prototype=qe.prototype;function Ja(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Bi;return e.__zoom}function zo(e){e.stopImmediatePropagation()}function $n(e){e.preventDefault(),e.stopImmediatePropagation()}function Iv(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Dv(){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 Za(){return this.__zoom||Bi}function _v(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Ov(){return navigator.maxTouchPoints||"ontouchstart"in this}function Kv(e,n,i){var o=e.invertX(n[0][0])-i[0][0],s=e.invertX(n[1][0])-i[1][0],t=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>t?(t+l)/2:Math.min(0,t)||Math.max(0,l))}function Xa(){var e=Iv,n=Dv,i=Kv,o=_v,s=Ov,t=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],r=250,d=wi,c=ci("start","zoom","end"),m,u,b,h=500,v=150,p=0,y=10;function f(M){M.property("__zoom",Za).on("wheel.zoom",E,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",I).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,_,B,H){var D=M.selection?M.selection():M;D.property("__zoom",Za),M!==D?N(M,_,B,H):D.interrupt().each(function(){A(this,arguments).event(H).start().zoom(null,typeof _=="function"?_.apply(this,arguments):_).end()})},f.scaleBy=function(M,_,B,H){f.scaleTo(M,function(){var D=this.__zoom.k,L=typeof _=="function"?_.apply(this,arguments):_;return D*L},B,H)},f.scaleTo=function(M,_,B,H){f.transform(M,function(){var D=n.apply(this,arguments),L=this.__zoom,z=B==null?w(D):typeof B=="function"?B.apply(this,arguments):B,q=L.invert(z),W=typeof _=="function"?_.apply(this,arguments):_;return i(g(S(L,W),z,q),D,l)},B,H)},f.translateBy=function(M,_,B,H){f.transform(M,function(){return i(this.__zoom.translate(typeof _=="function"?_.apply(this,arguments):_,typeof B=="function"?B.apply(this,arguments):B),n.apply(this,arguments),l)},null,H)},f.translateTo=function(M,_,B,H,D){f.transform(M,function(){var L=n.apply(this,arguments),z=this.__zoom,q=H==null?w(L):typeof H=="function"?H.apply(this,arguments):H;return i(Bi.translate(q[0],q[1]).scale(z.k).translate(typeof _=="function"?-_.apply(this,arguments):-_,typeof B=="function"?-B.apply(this,arguments):-B),L,l)},H,D)};function S(M,_){return _=Math.max(t[0],Math.min(t[1],_)),_===M.k?M:new qe(_,M.x,M.y)}function g(M,_,B){var H=_[0]-B[0]*M.k,D=_[1]-B[1]*M.k;return H===M.x&&D===M.y?M:new qe(M.k,H,D)}function w(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function N(M,_,B,H){M.on("start.zoom",function(){A(this,arguments).event(H).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(H).end()}).tween("zoom",function(){var D=this,L=arguments,z=A(D,L).event(H),q=n.apply(D,L),W=B==null?w(q):typeof B=="function"?B.apply(D,L):B,Z=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),X=D.__zoom,ie=typeof _=="function"?_.apply(D,L):_,ae=d(X.invert(W).concat(Z/X.k),ie.invert(W).concat(Z/ie.k));return function(R){if(R===1)R=ie;else{var j=ae(R),ee=Z/j[2];R=new qe(ee,W[0]-j[0]*ee,W[1]-j[1]*ee)}z.zoom(null,R)}})}function A(M,_,B){return!B&&M.__zooming||new C(M,_)}function C(M,_){this.that=M,this.args=_,this.active=0,this.sourceEvent=null,this.extent=n.apply(M,_),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,_){return this.mouse&&M!=="mouse"&&(this.mouse[1]=_.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=_.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=_.invert(this.touch1[0])),this.that.__zoom=_,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var _=Ie(this.that).datum();c.call(M,this.that,new Bv(M,{sourceEvent:this.sourceEvent,target:f,transform:this.that.__zoom,dispatch:c}),_)}};function E(M,..._){if(!e.apply(this,arguments))return;var B=A(this,_).event(M),H=this.__zoom,D=Math.max(t[0],Math.min(t[1],H.k*Math.pow(2,o.apply(this,arguments)))),L=_e(M);if(B.wheel)(B.mouse[0][0]!==L[0]||B.mouse[0][1]!==L[1])&&(B.mouse[1]=H.invert(B.mouse[0]=L)),clearTimeout(B.wheel);else{if(H.k===D)return;B.mouse=[L,H.invert(L)],Pi(this),B.start()}$n(M),B.wheel=setTimeout(z,v),B.zoom("mouse",i(g(S(H,D),B.mouse[0],B.mouse[1]),B.extent,l));function z(){B.wheel=null,B.end()}}function k(M,..._){if(b||!e.apply(this,arguments))return;var B=M.currentTarget,H=A(this,_,!0).event(M),D=Ie(M.view).on("mousemove.zoom",W,!0).on("mouseup.zoom",Z,!0),L=_e(M,B),z=M.clientX,q=M.clientY;ya(M.view),zo(M),H.mouse=[L,this.__zoom.invert(L)],Pi(this),H.start();function W(X){if($n(X),!H.moved){var ie=X.clientX-z,ae=X.clientY-q;H.moved=ie*ie+ae*ae>p}H.event(X).zoom("mouse",i(g(H.that.__zoom,H.mouse[0]=_e(X,B),H.mouse[1]),H.extent,l))}function Z(X){D.on("mousemove.zoom mouseup.zoom",null),xa(X.view,H.moved),$n(X),H.event(X).end()}}function I(M,..._){if(e.apply(this,arguments)){var B=this.__zoom,H=_e(M.changedTouches?M.changedTouches[0]:M,this),D=B.invert(H),L=B.k*(M.shiftKey?.5:2),z=i(g(S(B,L),H,D),n.apply(this,_),l);$n(M),r>0?Ie(this).transition().duration(r).call(N,z,H,M):Ie(this).call(f.transform,z,H,M)}}function P(M,..._){if(e.apply(this,arguments)){var B=M.touches,H=B.length,D=A(this,_,M.changedTouches.length===H).event(M),L,z,q,W;for(zo(M),z=0;z<H;++z)q=B[z],W=_e(q,this),W=[W,this.__zoom.invert(W),q.identifier],D.touch0?!D.touch1&&D.touch0[2]!==W[2]&&(D.touch1=W,D.taps=0):(D.touch0=W,L=!0,D.taps=1+!!m);m&&(m=clearTimeout(m)),L&&(D.taps<2&&(u=W[0],m=setTimeout(function(){m=null},h)),Pi(this),D.start())}}function T(M,..._){if(this.__zooming){var B=A(this,_).event(M),H=M.changedTouches,D=H.length,L,z,q,W;for($n(M),L=0;L<D;++L)z=H[L],q=_e(z,this),B.touch0&&B.touch0[2]===z.identifier?B.touch0[0]=q:B.touch1&&B.touch1[2]===z.identifier&&(B.touch1[0]=q);if(z=B.that.__zoom,B.touch1){var Z=B.touch0[0],X=B.touch0[1],ie=B.touch1[0],ae=B.touch1[1],R=(R=ie[0]-Z[0])*R+(R=ie[1]-Z[1])*R,j=(j=ae[0]-X[0])*j+(j=ae[1]-X[1])*j;z=S(z,Math.sqrt(R/j)),q=[(Z[0]+ie[0])/2,(Z[1]+ie[1])/2],W=[(X[0]+ae[0])/2,(X[1]+ae[1])/2]}else if(B.touch0)q=B.touch0[0],W=B.touch0[1];else return;B.zoom("touch",i(g(z,q,W),B.extent,l))}}function O(M,..._){if(this.__zooming){var B=A(this,_).event(M),H=M.changedTouches,D=H.length,L,z;for(zo(M),b&&clearTimeout(b),b=setTimeout(function(){b=null},h),L=0;L<D;++L)z=H[L],B.touch0&&B.touch0[2]===z.identifier?delete B.touch0:B.touch1&&B.touch1[2]===z.identifier&&delete B.touch1;if(B.touch1&&!B.touch0&&(B.touch0=B.touch1,delete B.touch1),B.touch0)B.touch0[1]=this.__zoom.invert(B.touch0[0]);else if(B.end(),B.taps===2&&(z=_e(z,this),Math.hypot(u[0]-z[0],u[1]-z[1])<y)){var q=Ie(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return f.wheelDelta=function(M){return arguments.length?(o=typeof M=="function"?M:Li(+M),f):o},f.filter=function(M){return arguments.length?(e=typeof M=="function"?M:Li(!!M),f):e},f.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:Li(!!M),f):s},f.extent=function(M){return arguments.length?(n=typeof M=="function"?M:Li([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),f):n},f.scaleExtent=function(M){return arguments.length?(t[0]=+M[0],t[1]=+M[1],f):[t[0],t[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=c.on.apply(c,arguments);return M===c?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 De={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.`},jn=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Qa=["Enter"," ","Escape"],Ra={"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 xn;(function(e){e.Strict="strict",e.Loose="loose"})(xn||(xn={}));var tn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(tn||(tn={}));var Un;(function(e){e.Partial="partial",e.Full="full"})(Un||(Un={}));const et={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Ze;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Ze||(Ze={}));var Sn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Sn||(Sn={}));var se;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(se||(se={}));const nt={[se.Left]:se.Right,[se.Right]:se.Left,[se.Top]:se.Bottom,[se.Bottom]:se.Top};function it(e){return e===null?null:e?"valid":"invalid"}const ot=e=>"id"in e&&"source"in e&&"target"in e,Hv=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Wo=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),qn=(e,n=[0,0])=>{var r;const{width:i,height:o}=Ye(e),s=(r=e.origin)!=null?r:n,t=i*s[0],l=o*s[1];return{x:e.position.x-t,y:e.position.y-l}},Gv=(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 t=typeof s=="string";let l=!n.nodeLookup&&!t?s:void 0;n.nodeLookup&&(l=t?n.nodeLookup.get(s):Wo(s)?s:n.nodeLookup.get(s.id));const r=l?_i(l,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Ii(o,r)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Di(i)},Yn=(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=Ii(i,_i(s)),o=!0)}),o?Di(i):{x:0,y:0,width:0,height:0}},$o=(e,n,[i,o,s]=[0,0,1],t=!1,l=!1)=>{var b,h,v,p,y,f;const r=(n.x-i)/s,d=(n.y-o)/s,c=n.width/s,m=n.height/s,u=[];for(const S of e.values()){const{measured:g,selectable:w=!0,hidden:N=!1}=S;if(l&&!w||N)continue;const A=(v=(h=(b=g.width)!=null?b:S.width)!=null?h:S.initialWidth)!=null?v:0,C=(f=(y=(p=g.height)!=null?p:S.height)!=null?y:S.initialHeight)!=null?f:0,{x:E,y:k}=S.internals.positionAbsolute,I=rt(r,d,c,m,E,k,A,C),P=A*C,T=t&&I>0;(!S.internals.handleBounds||T||I>=P||S.dragging)&&u.push(S)}return u},Fv=(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 Vv(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 zv({nodes:e,width:n,height:i,panZoom:o,minZoom:s,maxZoom:t},l){var m,u,b;if(e.size===0)return!0;const r=Vv(e,l),d=Yn(r),c=qo(d,n,i,(m=l==null?void 0:l.minZoom)!=null?m:s,(u=l==null?void 0:l.maxZoom)!=null?u:t,(b=l==null?void 0:l.padding)!=null?b:.1);return await o.setViewport(c,{duration:l==null?void 0:l.duration,ease:l==null?void 0:l.ease,interpolate:l==null?void 0:l.interpolate}),!0}function st({nodeId:e,nextPosition:n,nodeLookup:i,nodeOrigin:o=[0,0],nodeExtent:s,onError:t}){var h,v,p;const l=i.get(e),r=l.parentId?i.get(l.parentId):void 0,{x:d,y:c}=r?r.internals.positionAbsolute:{x:0,y:0},m=(h=l.origin)!=null?h:o;let u=l.extent||s;if(l.extent==="parent"&&!l.expandParent)if(!r)t==null||t("005",De.error005());else{const y=r.measured.width,f=r.measured.height;y&&f&&(u=[[d,c],[d+y,c+f]])}else r&&rn(l.extent)&&(u=[[l.extent[0][0]+d,l.extent[0][1]+c],[l.extent[1][0]+d,l.extent[1][1]+c]]);const b=rn(u)?ln(n,u,l.measured):n;return(l.measured.width===void 0||l.measured.height===void 0)&&(t==null||t("015",De.error015())),{position:{x:b.x-d+((v=l.measured.width)!=null?v:0)*m[0],y:b.y-c+((p=l.measured.height)!=null?p:0)*m[1]},positionAbsolute:b}}async function Wv({nodesToRemove:e=[],edgesToRemove:n=[],nodes:i,edges:o,onBeforeDelete:s}){const t=new Set(e.map(b=>b.id)),l=[];for(const b of i){if(b.deletable===!1)continue;const h=t.has(b.id),v=!h&&b.parentId&&l.find(p=>p.id===b.parentId);(h||v)&&l.push(b)}const r=new Set(n.map(b=>b.id)),d=o.filter(b=>b.deletable!==!1),m=Fv(l,d);for(const b of d)r.has(b.id)&&!m.find(v=>v.id===b.id)&&m.push(b);if(!s)return{edges:m,nodes:l};const u=await s({nodes:l,edges:m});return typeof u=="boolean"?u?{edges:m,nodes:l}:{edges:[],nodes:[]}:u}const wn=(e,n=0,i=1)=>Math.min(Math.max(e,n),i),ln=(e={x:0,y:0},n,i)=>{var o,s;return{x:wn(e.x,n[0][0],n[1][0]-((o=i==null?void 0:i.width)!=null?o:0)),y:wn(e.y,n[0][1],n[1][1]-((s=i==null?void 0:i.height)!=null?s:0))}};function at(e,n,i){const{width:o,height:s}=Ye(i),{x:t,y:l}=i.internals.positionAbsolute;return ln(e,[[t,l],[t+o,l+s]],n)}const tt=(e,n,i)=>e<n?wn(Math.abs(e-n),1,n)/n:e>i?-wn(Math.abs(e-i),1,n)/n:0,jo=(e,n,i=15,o=40)=>{const s=tt(e.x,o,n.width-o)*i,t=tt(e.y,o,n.height-o)*i;return[s,t]},Ii=(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)}),Uo=({x:e,y:n,width:i,height:o})=>({x:e,y:n,x2:e+i,y2:n+o}),Di=({x:e,y:n,x2:i,y2:o})=>({x:e,y:n,width:i-e,height:o-n}),Jn=(e,n=[0,0])=>{var s,t,l,r,d,c,m,u;const{x:i,y:o}=Wo(e)?e.internals.positionAbsolute:qn(e,n);return{x:i,y:o,width:(r=(l=(t=(s=e.measured)==null?void 0:s.width)!=null?t:e.width)!=null?l:e.initialWidth)!=null?r:0,height:(u=(m=(c=(d=e.measured)==null?void 0:d.height)!=null?c:e.height)!=null?m:e.initialHeight)!=null?u:0}},_i=(e,n=[0,0])=>{var s,t,l,r,d,c,m,u;const{x:i,y:o}=Wo(e)?e.internals.positionAbsolute:qn(e,n);return{x:i,y:o,x2:i+((r=(l=(t=(s=e.measured)==null?void 0:s.width)!=null?t:e.width)!=null?l:e.initialWidth)!=null?r:0),y2:o+((u=(m=(c=(d=e.measured)==null?void 0:d.height)!=null?c:e.height)!=null?m:e.initialHeight)!=null?u:0)}},lt=(e,n)=>Di(Ii(Uo(e),Uo(n))),rt=(e,n,i,o,s,t,l,r)=>{const d=Math.max(0,Math.min(e+i,s+l)-Math.max(e,s)),c=Math.max(0,Math.min(n+o,t+r)-Math.max(n,t));return Math.ceil(d*c)},Oi=(e,n)=>rt(e.x,e.y,e.width,e.height,n.x,n.y,n.width,n.height),dt=e=>He(e.width)&&He(e.height)&&He(e.x)&&He(e.y),He=e=>!isNaN(e)&&isFinite(e),ut=(e,n)=>(i,o)=>{process.env.NODE_ENV==="development"&&console.warn(`[${e}]: ${o} Help: ${n}error#${i}`)},Zn=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),Xn=({x:e,y:n},[i,o,s],t=!1,l=[1,1])=>{const r={x:(e-i)/s,y:(n-o)/s};return t?Zn(r,l):r},Nn=({x:e,y:n},[i,o,s])=>({x:e*s+i,y:n*s+o});function An(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 $v(e,n,i){var o,s,t,l,r,d,c,m;if(typeof e=="string"||typeof e=="number"){const u=An(e,i),b=An(e,n);return{top:u,right:b,bottom:u,left:b,x:b*2,y:u*2}}if(typeof e=="object"){const u=An((s=(o=e.top)!=null?o:e.y)!=null?s:0,i),b=An((l=(t=e.bottom)!=null?t:e.y)!=null?l:0,i),h=An((d=(r=e.left)!=null?r:e.x)!=null?d:0,n),v=An((m=(c=e.right)!=null?c:e.x)!=null?m:0,n);return{top:u,right:v,bottom:b,left:h,x:h+v,y:u+b}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function jv(e,n,i,o,s,t){const{x:l,y:r}=Nn(e,[n,i,o]),{x:d,y:c}=Nn({x:e.x+e.width,y:e.y+e.height},[n,i,o]),m=s-d,u=t-c;return{left:Math.floor(l),top:Math.floor(r),right:Math.floor(m),bottom:Math.floor(u)}}const qo=(e,n,i,o,s,t)=>{const l=$v(t,n,i),r=(n-l.x)/e.width,d=(i-l.y)/e.height,c=Math.min(r,d),m=wn(c,o,s),u=e.x+e.width/2,b=e.y+e.height/2,h=n/2-u*m,v=i/2-b*m,p=jv(e,h,v,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:h-y.left+y.right,y:v-y.top+y.bottom,zoom:m}},Qn=()=>{var e;return typeof navigator!="undefined"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function rn(e){return e!=null&&e!=="parent"}function Ye(e){var n,i,o,s,t,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=(t=e.measured)==null?void 0:t.height)!=null?l:e.height)!=null?r:e.initialHeight)!=null?d:0}}function ct(e){var n,i,o,s,t,l;return((o=(i=(n=e.measured)==null?void 0:n.width)!=null?i:e.width)!=null?o:e.initialWidth)!==void 0&&((l=(t=(s=e.measured)==null?void 0:s.height)!=null?t:e.height)!=null?l:e.initialHeight)!==void 0}function mt(e,n={width:0,height:0},i,o,s){var r,d;const t={...e},l=o.get(i);if(l){const c=l.origin||s;t.x+=l.internals.positionAbsolute.x-((r=n.width)!=null?r:0)*c[0],t.y+=l.internals.positionAbsolute.y-((d=n.height)!=null?d:0)*c[1]}return t}function bt(e,n){if(e.size!==n.size)return!1;for(const i of e)if(!n.has(i))return!1;return!0}function Uv(){let e,n;return{promise:new Promise((o,s)=>{e=o,n=s}),resolve:e,reject:n}}function qv(e){return{...Ra,...e||{}}}function Rn(e,{snapGrid:n=[0,0],snapToGrid:i=!1,transform:o,containerBounds:s}){var m,u;const{x:t,y:l}=Ge(e),r=Xn({x:t-((m=s==null?void 0:s.left)!=null?m:0),y:l-((u=s==null?void 0:s.top)!=null?u:0)},o),{x:d,y:c}=i?Zn(r,n):r;return{xSnapped:d,ySnapped:c,...r}}const Yo=e=>({width:e.offsetWidth,height:e.offsetHeight}),vt=e=>{var n;return((n=e==null?void 0:e.getRootNode)==null?void 0:n.call(e))||(window==null?void 0:window.document)},Yv=["INPUT","SELECT","TEXTAREA"];function ht(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:Yv.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const ft=e=>"clientX"in e,Ge=(e,n)=>{var t,l,r,d;const i=ft(e),o=i?e.clientX:(t=e.touches)==null?void 0:t[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)}},pt=(e,n,i,o,s)=>{const t=n.querySelectorAll(`.${e}`);return!t||!t.length?null:Array.from(t).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,...Yo(l)}})};function gt({sourceX:e,sourceY:n,targetX:i,targetY:o,sourceControlX:s,sourceControlY:t,targetControlX:l,targetControlY:r}){const d=e*.125+s*.375+l*.375+i*.125,c=n*.125+t*.375+r*.375+o*.125,m=Math.abs(d-e),u=Math.abs(c-n);return[d,c,m,u]}function Ki(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function yt({pos:e,x1:n,y1:i,x2:o,y2:s,c:t}){switch(e){case se.Left:return[n-Ki(n-o,t),i];case se.Right:return[n+Ki(o-n,t),i];case se.Top:return[n,i-Ki(i-s,t)];case se.Bottom:return[n,i+Ki(s-i,t)]}}function xt({sourceX:e,sourceY:n,sourcePosition:i=se.Bottom,targetX:o,targetY:s,targetPosition:t=se.Top,curvature:l=.25}){const[r,d]=yt({pos:i,x1:e,y1:n,x2:o,y2:s,c:l}),[c,m]=yt({pos:t,x1:o,y1:s,x2:e,y2:n,c:l}),[u,b,h,v]=gt({sourceX:e,sourceY:n,targetX:o,targetY:s,sourceControlX:r,sourceControlY:d,targetControlX:c,targetControlY:m});return[`M${e},${n} C${r},${d} ${c},${m} ${o},${s}`,u,b,h,v]}function St({sourceX:e,sourceY:n,targetX:i,targetY:o}){const s=Math.abs(i-e)/2,t=i<e?i+s:i-s,l=Math.abs(o-n)/2,r=o<n?o+l:o-l;return[t,r,s,l]}function Jv({sourceNode:e,targetNode:n,selected:i=!1,zIndex:o=0,elevateOnSelect:s=!1,zIndexMode:t="basic"}){if(t==="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 Zv({sourceNode:e,targetNode:n,width:i,height:o,transform:s}){const t=Ii(_i(e),_i(n));t.x===t.x2&&(t.x2+=1),t.y===t.y2&&(t.y2+=1);const l={x:-s[0]/s[2],y:-s[1]/s[2],width:i/s[2],height:o/s[2]};return Oi(l,Di(t))>0}const Xv=({source:e,sourceHandle:n,target:i,targetHandle:o})=>`xy-edge__${e}${n||""}-${i}${o||""}`,Qv=(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)),Rv=(e,n,i={})=>{var t;if(!e.source||!e.target)return(t=i.onError)==null||t.call(i,"006",De.error006()),n;const o=i.getEdgeId||Xv;let s;return ot(e)?s={...e}:s={...e,id:o(e)},Qv(s,n)?n:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,n.concat(s))};function wt({sourceX:e,sourceY:n,targetX:i,targetY:o}){const[s,t,l,r]=St({sourceX:e,sourceY:n,targetX:i,targetY:o});return[`M ${e},${n}L ${i},${o}`,s,t,l,r]}const Nt={[se.Left]:{x:-1,y:0},[se.Right]:{x:1,y:0},[se.Top]:{x:0,y:-1},[se.Bottom]:{x:0,y:1}},eh=({source:e,sourcePosition:n=se.Bottom,target:i})=>n===se.Left||n===se.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},At=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function nh({source:e,sourcePosition:n=se.Bottom,target:i,targetPosition:o=se.Top,center:s,offset:t,stepPosition:l}){var E,k,I,P;const r=Nt[n],d=Nt[o],c={x:e.x+r.x*t,y:e.y+r.y*t},m={x:i.x+d.x*t,y:i.y+d.y*t},u=eh({source:c,sourcePosition:n,target:m}),b=u.x!==0?"x":"y",h=u[b];let v=[],p,y;const f={x:0,y:0},S={x:0,y:0},[,,g,w]=St({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:c.x+(m.x-c.x)*l,y=(k=s.y)!=null?k:(c.y+m.y)/2):(p=(I=s.x)!=null?I:(c.x+m.x)/2,y=(P=s.y)!=null?P:c.y+(m.y-c.y)*l);const T=[{x:p,y:c.y},{x:p,y:m.y}],O=[{x:c.x,y},{x:m.x,y}];r[b]===h?v=b==="x"?T:O:v=b==="x"?O:T}else{const T=[{x:c.x,y:m.y}],O=[{x:m.x,y:c.y}];if(b==="x"?v=r.x===h?O:T:v=r.y===h?T:O,n===o){const D=Math.abs(e[b]-i[b]);if(D<=t){const L=Math.min(t-1,t-D);r[b]===h?f[b]=(c[b]>e[b]?-1:1)*L:S[b]=(m[b]>i[b]?-1:1)*L}}if(n!==o){const D=b==="x"?"y":"x",L=r[b]===d[D],z=c[D]>m[D],q=c[D]<m[D];(r[b]===1&&(!L&&z||L&&q)||r[b]!==1&&(!L&&q||L&&z))&&(v=b==="x"?T:O)}const M={x:c.x+f.x,y:c.y+f.y},_={x:m.x+S.x,y:m.y+S.y},B=Math.max(Math.abs(M.x-v[0].x),Math.abs(_.x-v[0].x)),H=Math.max(Math.abs(M.y-v[0].y),Math.abs(_.y-v[0].y));B>=H?(p=(M.x+_.x)/2,y=v[0].y):(p=v[0].x,y=(M.y+_.y)/2)}const N={x:c.x+f.x,y:c.y+f.y},A={x:m.x+S.x,y:m.y+S.y};return[[e,...N.x!==v[0].x||N.y!==v[0].y?[N]:[],...v,...A.x!==v[v.length-1].x||A.y!==v[v.length-1].y?[A]:[],i],p,y,g,w]}function ih(e,n,i,o){const s=Math.min(At(e,n)/2,At(n,i)/2,o),{x:t,y:l}=n;if(e.x===t&&t===i.x||e.y===l&&l===i.y)return`L${t} ${l}`;if(e.y===l){const c=e.x<i.x?-1:1,m=e.y<i.y?1:-1;return`L ${t+s*c},${l}Q ${t},${l} ${t},${l+s*m}`}const r=e.x<i.x?1:-1,d=e.y<i.y?-1:1;return`L ${t},${l+s*d}Q ${t},${l} ${t+s*r},${l}`}function Jo({sourceX:e,sourceY:n,sourcePosition:i=se.Bottom,targetX:o,targetY:s,targetPosition:t=se.Top,borderRadius:l=5,centerX:r,centerY:d,offset:c=20,stepPosition:m=.5}){const[u,b,h,v,p]=nh({source:{x:e,y:n},sourcePosition:i,target:{x:o,y:s},targetPosition:t,center:{x:r,y:d},offset:c,stepPosition:m});let y=`M${u[0].x} ${u[0].y}`;for(let f=1;f<u.length-1;f++)y+=ih(u[f-1],u[f],u[f+1],l);return y+=`L${u[u.length-1].x} ${u[u.length-1].y}`,[y,b,h,v,p]}function Ct(e){var n;return e&&!!(e.internals.handleBounds||(n=e.handles)!=null&&n.length)&&!!(e.measured.width||e.width||e.initialWidth)}function oh(e){var u,b,h,v,p;const{sourceNode:n,targetNode:i}=e;if(!Ct(n)||!Ct(i))return null;const o=n.internals.handleBounds||kt(n.handles),s=i.internals.handleBounds||kt(i.handles),t=Mt((u=o==null?void 0:o.source)!=null?u:[],e.sourceHandle),l=Mt(e.connectionMode===xn.Strict?(b=s==null?void 0:s.target)!=null?b:[]:((h=s==null?void 0:s.target)!=null?h:[]).concat((v=s==null?void 0:s.source)!=null?v:[]),e.targetHandle);if(!t||!l)return(p=e.onError)==null||p.call(e,"008",De.error008(t?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const r=(t==null?void 0:t.position)||se.Bottom,d=(l==null?void 0:l.position)||se.Top,c=dn(n,t,r),m=dn(i,l,d);return{sourceX:c.x,sourceY:c.y,targetX:m.x,targetY:m.y,sourcePosition:r,targetPosition:d}}function kt(e){var o,s;if(!e)return null;const n=[],i=[];for(const t of e)t.width=(o=t.width)!=null?o:1,t.height=(s=t.height)!=null?s:1,t.type==="source"?n.push(t):t.type==="target"&&i.push(t);return{source:n,target:i}}function dn(e,n,i=se.Left,o=!1){var c,m,u;const s=((c=n==null?void 0:n.x)!=null?c:0)+e.internals.positionAbsolute.x,t=((m=n==null?void 0:n.y)!=null?m:0)+e.internals.positionAbsolute.y,{width:l,height:r}=n!=null?n:Ye(e);if(o)return{x:s+l/2,y:t+r/2};switch((u=n==null?void 0:n.position)!=null?u:i){case se.Top:return{x:s+l/2,y:t};case se.Right:return{x:s+l,y:t+r/2};case se.Bottom:return{x:s+l/2,y:t+r};case se.Left:return{x:s,y:t+r/2}}}function Mt(e,n){return e&&(n?e.find(i=>i.id===n):e[0])||null}function Zo(e,n){return e?typeof e=="string"?e:`${n?`${n}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function sh(e,{id:n,defaultColor:i,defaultMarkerStart:o,defaultMarkerEnd:s}){const t=new Set;return e.reduce((l,r)=>([r.markerStart||o,r.markerEnd||s].forEach(d=>{if(d&&typeof d=="object"){const c=Zo(d,n);t.has(c)||(l.push({id:c,color:d.color||i,...d}),t.add(c))}}),l),[]).sort((l,r)=>l.id.localeCompare(r.id))}const Et=1e3,ah=10,Xo={nodeOrigin:[0,0],nodeExtent:jn,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},th={...Xo,checkEquality:!0};function Qo(e,n){const i={...e};for(const o in n)n[o]!==void 0&&(i[o]=n[o]);return i}function lh(e,n,i){const o=Qo(Xo,i);for(const s of e.values())if(s.parentId)ns(s,e,n,o);else{const t=qn(s,o.nodeOrigin),l=rn(s.extent)?s.extent:o.nodeExtent,r=ln(t,l,Ye(s));s.internals.positionAbsolute=r}}function rh(e,n){var s,t;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:(t=l.height)!=null?t: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 Ro(e){return e==="manual"}function es(e,n,i,o={}){var m,u,b;const s=Qo(th,o),t={i:0},l=new Map(n),r=s!=null&&s.elevateNodesOnSelect&&!Ro(s.zIndexMode)?Et:0;let d=e.length>0,c=!1;n.clear(),i.clear();for(const h of e){let v=l.get(h.id);if(s.checkEquality&&h===(v==null?void 0:v.internals.userNode))n.set(h.id,v);else{const p=qn(h,s.nodeOrigin),y=rn(h.extent)?h.extent:s.nodeExtent,f=ln(p,y,Ye(h));v={...s.defaults,...h,measured:{width:(m=h.measured)==null?void 0:m.width,height:(u=h.measured)==null?void 0:u.height},internals:{positionAbsolute:f,handleBounds:rh(h,v),z:Tt(h,r,s.zIndexMode),userNode:h}},n.set(h.id,v)}(v.measured===void 0||v.measured.width===void 0||v.measured.height===void 0)&&!v.hidden&&(d=!1),h.parentId&&ns(v,n,i,o,t),c||(c=(b=h.selected)!=null?b:!1)}return{nodesInitialized:d,hasSelectedNodes:c}}function dh(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 ns(e,n,i,o,s){const{elevateNodesOnSelect:t,nodeOrigin:l,nodeExtent:r,zIndexMode:d}=Qo(Xo,o),c=e.parentId,m=n.get(c);if(!m){console.warn(`Parent node ${c} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}dh(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*ah),s&&m.internals.rootParentIndex!==void 0&&(s.i=m.internals.rootParentIndex);const u=t&&!Ro(d)?Et:0,{x:b,y:h,z:v}=uh(e,m,l,r,u,d),{positionAbsolute:p}=e.internals,y=b!==p.x||h!==p.y;(y||v!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:y?{x:b,y:h}:p,z:v}})}function Tt(e,n,i){const o=He(e.zIndex)?e.zIndex:0;return Ro(i)?o:o+(e.selected?n:0)}function uh(e,n,i,o,s,t){var v;const{x:l,y:r}=n.internals.positionAbsolute,d=Ye(e),c=qn(e,i),m=rn(e.extent)?ln(c,e.extent,d):c;let u=ln({x:l+m.x,y:r+m.y},o,d);e.extent==="parent"&&(u=at(u,d,n));const b=Tt(e,s,t),h=(v=n.internals.z)!=null?v:0;return{x:u.x,y:u.y,z:h>=b?h+1:b}}function is(e,n,i,o=[0,0]){var l,r;const s=[],t=new Map;for(const d of e){const c=n.get(d.parentId);if(!c)continue;const m=(r=(l=t.get(d.parentId))==null?void 0:l.expandedRect)!=null?r:Jn(c),u=lt(m,d.rect);t.set(d.parentId,{expandedRect:u,parent:c})}return t.size>0&&t.forEach(({expandedRect:d,parent:c},m)=>{var w,N;const u=c.internals.positionAbsolute,b=Ye(c),h=(w=c.origin)!=null?w:o,v=d.x<u.x?Math.round(Math.abs(u.x-d.x)):0,p=d.y<u.y?Math.round(Math.abs(u.y-d.y)):0,y=Math.max(b.width,Math.round(d.width)),f=Math.max(b.height,Math.round(d.height)),S=(y-b.width)*h[0],g=(f-b.height)*h[1];(v>0||p>0||S||g)&&(s.push({id:m,type:"position",position:{x:c.position.x-v+S,y:c.position.y-p+g}}),(N=i.get(m))==null||N.forEach(A=>{e.some(C=>C.id===A.id)||s.push({id:A.id,type:"position",position:{x:A.position.x+v,y:A.position.y+p}})})),(b.width<d.width||b.height<d.height||v||p)&&s.push({id:m,type:"dimensions",setAttributes:!0,dimensions:{width:y+(v?h[0]*v-S:0),height:f+(p?h[1]*p-g:0)}})}),s}function ch(e,n,i,o,s,t,l){const r=o==null?void 0:o.querySelector(".xyflow__viewport");let d=!1;if(!r)return{changes:[],updatedInternals:d};const c=[],m=window.getComputedStyle(r),{m22:u}=new window.DOMMatrixReadOnly(m.transform),b=[];for(const h of e.values()){const v=n.get(h.id);if(!v)continue;if(v.hidden){n.set(v.id,{...v,internals:{...v.internals,handleBounds:void 0}}),d=!0;continue}const p=Yo(h.nodeElement),y=v.measured.width!==p.width||v.measured.height!==p.height;if(!!(p.width&&p.height&&(y||!v.internals.handleBounds||h.force))){const S=h.nodeElement.getBoundingClientRect(),g=rn(v.extent)?v.extent:t;let{positionAbsolute:w}=v.internals;v.parentId&&v.extent==="parent"?w=at(w,p,n.get(v.parentId)):g&&(w=ln(w,g,p));const N={...v,measured:p,internals:{...v.internals,positionAbsolute:w,handleBounds:{source:pt("source",h.nodeElement,S,u,v.id),target:pt("target",h.nodeElement,S,u,v.id)}}};n.set(v.id,N),v.parentId&&ns(N,n,i,{nodeOrigin:s,zIndexMode:l}),d=!0,y&&(c.push({id:v.id,type:"dimensions",dimensions:p}),v.expandParent&&v.parentId&&b.push({id:v.id,parentId:v.parentId,rect:Jn(N,s)}))}}if(b.length>0){const h=is(b,n,i,s);c.push(...h)}return{changes:c,updatedInternals:d}}async function mh({delta:e,panZoom:n,transform:i,translateExtent:o,width:s,height:t}){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,t]],o);return!!l&&(l.x!==i[0]||l.y!==i[1]||l.k!==i[2])}function Pt(e,n,i,o,s,t){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)),t){l=`${s}-${e}-${t}`;const c=o.get(l)||new Map;o.set(l,c.set(i,n))}}function Lt(e,n,i){e.clear(),n.clear();for(const o of i){const{source:s,target:t,sourceHandle:l=null,targetHandle:r=null}=o,d={edgeId:o.id,source:s,target:t,sourceHandle:l,targetHandle:r},c=`${s}-${l}--${t}-${r}`,m=`${t}-${r}--${s}-${l}`;Pt("source",d,m,e,s,l),Pt("target",d,c,e,t,r),n.set(o.id,o)}}function Bt(e,n){if(!e.parentId)return!1;const i=n.get(e.parentId);return i?i.selected?!0:Bt(i,n):!1}function It(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 bh(e,n,i,o){var t,l;const s=new Map;for(const[r,d]of e)if((d.selected||d.id===o)&&(!d.parentId||!Bt(d,e))&&(d.draggable||n&&typeof d.draggable=="undefined")){const c=e.get(r);c&&s.set(r,{id:r,position:c.position||{x:0,y:0},distance:{x:i.x-c.internals.positionAbsolute.x,y:i.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:(t=c.measured.width)!=null?t:0,height:(l=c.measured.height)!=null?l:0}})}return s}function os({nodeId:e,dragItems:n,nodeLookup:i,dragging:o=!0}){var l,r,d;const s=[];for(const[c,m]of n){const u=(l=i.get(c))==null?void 0:l.internals.userNode;u&&s.push({...u,position:m.position,dragging:o})}if(!e)return[s[0],s];const t=(r=i.get(e))==null?void 0:r.internals.userNode;return[t?{...t,position:((d=n.get(e))==null?void 0:d.position)||t.position,dragging:o}:s[0],s]}function vh({dragItems:e,snapGrid:n,x:i,y:o}){const s=e.values().next().value;if(!s)return null;const t={x:i-s.distance.x,y:o-s.distance.y},l=Zn(t,n);return{x:l.x-t.x,y:l.y-t.y}}function hh({onNodeMouseDown:e,getStoreItems:n,onDragStart:i,onDrag:o,onDragStop:s}){let t={x:null,y:null},l=0,r=new Map,d=!1,c={x:0,y:0},m=null,u=!1,b=null,h=!1,v=!1,p=null;function y({noDragClassName:S,handleSelector:g,domNode:w,isSelectable:N,nodeId:A,nodeClickDistance:C=0}){b=Ie(w);function E({x:T,y:O}){const{nodeLookup:M,nodeExtent:_,snapGrid:B,snapToGrid:H,nodeOrigin:D,onNodeDrag:L,onSelectionDrag:z,onError:q,updateNodePositions:W}=n();t={x:T,y:O};let Z=!1;const X=r.size>1,ie=X&&_?Uo(Yn(r)):null,ae=X&&H?vh({dragItems:r,snapGrid:B,x:T,y:O}):null;for(const[R,j]of r){if(!M.has(R))continue;let ee={x:T-j.distance.x,y:O-j.distance.y};H&&(ee=ae?{x:Math.round(ee.x+ae.x),y:Math.round(ee.y+ae.y)}:Zn(ee,B));let J=null;if(X&&_&&!j.extent&&ie){const{positionAbsolute:G}=j.internals,F=G.x-ie.x+_[0][0],V=G.x+j.measured.width-ie.x2+_[1][0],U=G.y-ie.y+_[0][1],Y=G.y+j.measured.height-ie.y2+_[1][1];J=[[F,U],[V,Y]]}const{position:K,positionAbsolute:$}=st({nodeId:R,nextPosition:ee,nodeLookup:M,nodeExtent:J||_,nodeOrigin:D,onError:q});Z=Z||j.position.x!==K.x||j.position.y!==K.y,j.position=K,j.internals.positionAbsolute=$}if(v=v||Z,!!Z&&(W(r,!0),p&&(o||L||!A&&z))){const[R,j]=os({nodeId:A,dragItems:r,nodeLookup:M});o==null||o(p,r,R,j),L==null||L(p,R,j),A||z==null||z(p,j)}}async function k(){var D,L;if(!m)return;const{transform:T,panBy:O,autoPanSpeed:M,autoPanOnNodeDrag:_}=n();if(!_){d=!1,cancelAnimationFrame(l);return}const[B,H]=jo(c,m,M);(B!==0||H!==0)&&(t.x=((D=t.x)!=null?D:0)-B/T[2],t.y=((L=t.y)!=null?L:0)-H/T[2],await O({x:B,y:H})&&E(t)),l=requestAnimationFrame(k)}function I(T){var X;const{nodeLookup:O,multiSelectionActive:M,nodesDraggable:_,transform:B,snapGrid:H,snapToGrid:D,selectNodesOnDrag:L,onNodeDragStart:z,onSelectionDragStart:q,unselectNodesAndEdges:W}=n();u=!0,(!L||!N)&&!M&&A&&((X=O.get(A))!=null&&X.selected||W()),N&&L&&A&&(e==null||e(A));const Z=Rn(T.sourceEvent,{transform:B,snapGrid:H,snapToGrid:D,containerBounds:m});if(t=Z,r=bh(O,_,Z,A),r.size>0&&(i||z||!A&&q)){const[ie,ae]=os({nodeId:A,dragItems:r,nodeLookup:O});i==null||i(T.sourceEvent,r,ie,ae),z==null||z(T.sourceEvent,ie,ae),A||q==null||q(T.sourceEvent,ae)}}const P=Sa().clickDistance(C).on("start",T=>{const{domNode:O,nodeDragThreshold:M,transform:_,snapGrid:B,snapToGrid:H}=n();m=(O==null?void 0:O.getBoundingClientRect())||null,h=!1,v=!1,p=T.sourceEvent,M===0&&I(T),t=Rn(T.sourceEvent,{transform:_,snapGrid:B,snapToGrid:H,containerBounds:m}),c=Ge(T.sourceEvent,m)}).on("drag",T=>{const{autoPanOnNodeDrag:O,transform:M,snapGrid:_,snapToGrid:B,nodeDragThreshold:H,nodeLookup:D}=n(),L=Rn(T.sourceEvent,{transform:M,snapGrid:_,snapToGrid:B,containerBounds:m});if(p=T.sourceEvent,(T.sourceEvent.type==="touchmove"&&T.sourceEvent.touches.length>1||A&&!D.has(A))&&(h=!0),!h){if(!d&&O&&u&&(d=!0,k()),!u){const z=Ge(T.sourceEvent,m),q=z.x-c.x,W=z.y-c.y;Math.sqrt(q*q+W*W)>H&&I(T)}(t.x!==L.xSnapped||t.y!==L.ySnapped)&&r&&u&&(c=Ge(T.sourceEvent,m),E(L))}}).on("end",T=>{if(!u||h){h&&r.size>0&&n().updateNodePositions(r,!1);return}if(d=!1,u=!1,cancelAnimationFrame(l),r.size>0){const{nodeLookup:O,updateNodePositions:M,onNodeDragStop:_,onSelectionDragStop:B}=n();if(v&&(M(r,!1),v=!1),s||_||!A&&B){const[H,D]=os({nodeId:A,dragItems:r,nodeLookup:O,dragging:!1});s==null||s(T.sourceEvent,r,H,D),_==null||_(T.sourceEvent,H,D),A||B==null||B(T.sourceEvent,D)}}}).filter(T=>{const O=T.target;return!T.button&&(!S||!It(O,`.${S}`,w))&&(!g||It(O,g,w))});b.call(P)}function f(){b==null||b.on(".drag",null)}return{update:y,destroy:f}}function fh(e,n,i){const o=[],s={x:e.x-i,y:e.y-i,width:i*2,height:i*2};for(const t of n.values())Oi(s,Jn(t))>0&&o.push(t);return o}const ph=250;function gh(e,n,i,o){var r,d,c,m,u;let s=[],t=1/0;const l=fh(e,i,n+ph);for(const b of l){const h=[...(d=(r=b.internals.handleBounds)==null?void 0:r.source)!=null?d:[],...(m=(c=b.internals.handleBounds)==null?void 0:c.target)!=null?m:[]];for(const v of h){if(o.nodeId===v.nodeId&&o.type===v.type&&o.id===v.id)continue;const{x:p,y}=dn(b,v,v.position,!0),f=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(y-e.y,2));f>n||(f<t?(s=[{...v,x:p,y}],t=f):f===t&&s.push({...v,x:p,y}))}}if(!s.length)return null;if(s.length>1){const b=o.type==="source"?"target":"source";return(u=s.find(h=>h.type===b))!=null?u:s[0]}return s[0]}function Dt(e,n,i,o,s,t=!1){var c,m,u,b,h,v;const l=o.get(e);if(!l)return null;const r=s==="strict"?(c=l.internals.handleBounds)==null?void 0:c[n]:[...(u=(m=l.internals.handleBounds)==null?void 0:m.source)!=null?u:[],...(h=(b=l.internals.handleBounds)==null?void 0:b.target)!=null?h:[]],d=(v=i?r==null?void 0:r.find(p=>p.id===i):r==null?void 0:r[0])!=null?v:null;return d&&t?{...d,...dn(l,d,d.position,!0)}:d}function _t(e,n){return e||(n!=null&&n.classList.contains("target")?"target":n!=null&&n.classList.contains("source")?"source":null)}function yh(e,n){let i=null;return n?i=!0:e&&!n&&(i=!1),i}const Ot=()=>!0;function xh(e,{connectionMode:n,connectionRadius:i,handleId:o,nodeId:s,edgeUpdaterType:t,isTarget:l,domNode:r,nodeLookup:d,lib:c,autoPanOnConnect:m,flowId:u,panBy:b,cancelConnection:h,onConnectStart:v,onConnect:p,onConnectEnd:y,isValidConnection:f=Ot,onReconnectEnd:S,updateConnection:g,getTransform:w,getFromHandle:N,autoPanSpeed:A,dragThreshold:C=1,handleDomNode:E}){const k=vt(e.target);let I=0,P;const{x:T,y:O}=Ge(e),M=_t(t,E),_=r==null?void 0:r.getBoundingClientRect();let B=!1;if(!_||!M)return;const H=Dt(s,M,o,d,n);if(!H)return;let D=Ge(e,_),L=!1,z=null,q=!1,W=null;function Z(){if(!m||!_)return;const[K,$]=jo(D,_,A);b({x:K,y:$}),I=requestAnimationFrame(Z)}const X={...H,nodeId:s,type:M,position:H.position},ie=d.get(s);let R={inProgress:!0,isValid:null,from:dn(ie,X,se.Left,!0),fromHandle:X,fromPosition:X.position,fromNode:ie,to:D,toHandle:null,toPosition:nt[X.position],toNode:null,pointer:D};function j(){B=!0,g(R),v==null||v(e,{nodeId:s,handleId:o,handleType:M})}C===0&&j();function ee(K){if(!B){const{x:Y,y:Q}=Ge(K),oe=Y-T,ue=Q-O;if(!(oe*oe+ue*ue>C*C))return;j()}if(!N()||!X){J(K);return}const $=w();D=Ge(K,_),P=gh(Xn(D,$,!1,[1,1]),i,d,X),L||(Z(),L=!0);const G=Kt(K,{handle:P,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:l?"target":"source",isValidConnection:f,doc:k,lib:c,flowId:u,nodeLookup:d});W=G.handleDomNode,z=G.connection,q=yh(!!P,G.isValid);const F=d.get(s),V=F?dn(F,X,se.Left,!0):R.from,U={...R,from:V,isValid:q,to:G.toHandle&&q?Nn({x:G.toHandle.x,y:G.toHandle.y},$):D,toHandle:G.toHandle,toPosition:q&&G.toHandle?G.toHandle.position:nt[X.position],toNode:G.toHandle?d.get(G.toHandle.nodeId):null,pointer:D};g(U),R=U}function J(K){if(!("touches"in K&&K.touches.length>0)){if(B){(P||W)&&z&&q&&(p==null||p(z));const{inProgress:$,...G}=R,F={...G,toPosition:R.toHandle?R.toPosition:null};y==null||y(K,F),t&&(S==null||S(K,F))}h(),cancelAnimationFrame(I),L=!1,q=!1,z=null,W=null,k.removeEventListener("mousemove",ee),k.removeEventListener("mouseup",J),k.removeEventListener("touchmove",ee),k.removeEventListener("touchend",J)}}k.addEventListener("mousemove",ee),k.addEventListener("mouseup",J),k.addEventListener("touchmove",ee),k.addEventListener("touchend",J)}function Kt(e,{handle:n,connectionMode:i,fromNodeId:o,fromHandleId:s,fromType:t,doc:l,lib:r,flowId:d,isValidConnection:c=Ot,nodeLookup:m}){const u=t==="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:h,y:v}=Ge(e),p=l.elementFromPoint(h,v),y=p!=null&&p.classList.contains(`${r}-flow__handle`)?p:b,f={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){const S=_t(void 0,y),g=y.getAttribute("data-nodeid"),w=y.getAttribute("data-handleid"),N=y.classList.contains("connectable"),A=y.classList.contains("connectableend");if(!g||!S)return f;const C={source:u?g:o,sourceHandle:u?w:s,target:u?o:g,targetHandle:u?s:w};f.connection=C;const k=N&&A&&(i===xn.Strict?u&&S==="source"||!u&&S==="target":g!==o||w!==s);f.isValid=k&&c(C),f.toHandle=Dt(g,S,w,m,i,!0)}return f}const ss={onPointerDown:xh,isValid:Kt};function Sh({domNode:e,panZoom:n,getTransform:i,getViewScale:o}){const s=Ie(e);function t({translateExtent:r,width:d,height:c,zoomStep:m=1,pannable:u=!0,zoomable:b=!0,inversePan:h=!1}){const v=g=>{if(g.sourceEvent.type!=="wheel"||!n)return;const w=i(),N=g.sourceEvent.ctrlKey&&Qn()?10:1,A=-g.sourceEvent.deltaY*(g.sourceEvent.deltaMode===1?.05:g.sourceEvent.deltaMode?1:.002)*m,C=w[2]*Math.pow(2,A*N);n.scaleTo(C)};let p=[0,0];const y=g=>{var w,N;(g.sourceEvent.type==="mousedown"||g.sourceEvent.type==="touchstart")&&(p=[(w=g.sourceEvent.clientX)!=null?w:g.sourceEvent.touches[0].clientX,(N=g.sourceEvent.clientY)!=null?N:g.sourceEvent.touches[0].clientY])},f=g=>{var I,P;const w=i();if(g.sourceEvent.type!=="mousemove"&&g.sourceEvent.type!=="touchmove"||!n)return;const N=[(I=g.sourceEvent.clientX)!=null?I:g.sourceEvent.touches[0].clientX,(P=g.sourceEvent.clientY)!=null?P:g.sourceEvent.touches[0].clientY],A=[N[0]-p[0],N[1]-p[1]];p=N;const C=o()*Math.max(w[2],Math.log(w[2]))*(h?-1:1),E={x:w[0]-A[0]*C,y:w[1]-A[1]*C},k=[[0,0],[d,c]];n.setViewportConstrained({x:E.x,y:E.y,zoom:w[2]},k,r)},S=Xa().on("start",y).on("zoom",u?f:null).on("zoom.wheel",b?v:null);s.call(S,{})}function l(){s.on("zoom",null)}return{update:t,destroy:l,pointer:_e}}const Hi=e=>({x:e.x,y:e.y,zoom:e.k}),as=({x:e,y:n,zoom:i})=>Bi.translate(e,n).scale(i),Cn=(e,n)=>e.target.closest(`.${n}`),Ht=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),wh=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,ts=(e,n=0,i=wh,o=()=>{})=>{const s=typeof n=="number"&&n>0;return s||o(),s?e.transition().duration(n).ease(i).on("end",o):e},Gt=e=>{const n=e.ctrlKey&&Qn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function Nh({zoomPanValues:e,noWheelClassName:n,d3Selection:i,d3Zoom:o,panOnScrollMode:s,panOnScrollSpeed:t,zoomOnPinch:l,onPanZoomStart:r,onPanZoom:d,onPanZoomEnd:c}){return m=>{if(Cn(m,n))return m.ctrlKey&&m.preventDefault(),!1;m.preventDefault(),m.stopImmediatePropagation();const u=i.property("__zoom").k||1;if(m.ctrlKey&&l){const y=_e(m),f=Gt(m),S=u*Math.pow(2,f);o.scaleTo(i,S,y,m);return}const b=m.deltaMode===1?20:1;let h=s===tn.Vertical?0:m.deltaX*b,v=s===tn.Horizontal?0:m.deltaY*b;!Qn()&&m.shiftKey&&s!==tn.Vertical&&(h=m.deltaY*b,v=0),o.translateBy(i,-(h/u)*t,-(v/u)*t,{internal:!0});const p=Hi(i.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d==null||d(m,p),e.panScrollTimeout=setTimeout(()=>{c==null||c(m,p),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,r==null||r(m,p))}}function Ah({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:i}){return function(o,s){const t=o.type==="wheel",l=!n&&t&&!o.ctrlKey,r=Cn(o,e);if(o.ctrlKey&&t&&r&&o.preventDefault(),l||r)return null;o.preventDefault(),i.call(this,o,s)}}function Ch({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:i}){return o=>{var t,l,r;if((t=o.sourceEvent)!=null&&t.internal)return;const s=Hi(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 kh({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:i,onTransformChange:o,onPanZoom:s}){return t=>{var l,r,d;e.usedRightMouseButton=!!(i&&Ht(n,(l=e.mouseButton)!=null?l:0)),(r=t.sourceEvent)!=null&&r.sync||o([t.transform.x,t.transform.y,t.transform.k]),s&&!((d=t.sourceEvent)!=null&&d.internal)&&(s==null||s(t.sourceEvent,Hi(t.transform)))}}function Mh({zoomPanValues:e,panOnDrag:n,panOnScroll:i,onDraggingChange:o,onPanZoomEnd:s,onPaneContextMenu:t}){return l=>{var r,d;if(!((r=l.sourceEvent)!=null&&r.internal)&&(e.isZoomingOrPanning=!1,t&&Ht(n,(d=e.mouseButton)!=null?d:0)&&!e.usedRightMouseButton&&l.sourceEvent&&t(l.sourceEvent),e.usedRightMouseButton=!1,o(!1),s)){const c=Hi(l.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(l.sourceEvent,c)},i?150:0)}}}function Eh({zoomActivationKeyPressed:e,zoomOnScroll:n,zoomOnPinch:i,panOnDrag:o,panOnScroll:s,zoomOnDoubleClick:t,userSelectionActive:l,noWheelClassName:r,noPanClassName:d,lib:c,connectionInProgress:m}){return u=>{var y;const b=e||n,h=i&&u.ctrlKey,v=u.type==="wheel";if(u.button===1&&u.type==="mousedown"&&(Cn(u,`${c}-flow__node`)||Cn(u,`${c}-flow__edge`)))return!0;if(!o&&!b&&!s&&!t&&!i||l||m&&!v||Cn(u,r)&&v||Cn(u,d)&&(!v||s&&v&&!e)||!i&&u.ctrlKey&&v)return!1;if(!i&&u.type==="touchstart"&&((y=u.touches)==null?void 0:y.length)>1)return u.preventDefault(),!1;if(!b&&!s&&!h&&v||!o&&(u.type==="mousedown"||u.type==="touchstart")||Array.isArray(o)&&!o.includes(u.button)&&u.type==="mousedown")return!1;const p=Array.isArray(o)&&o.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||v)&&p}}function Th({domNode:e,minZoom:n,maxZoom:i,translateExtent:o,viewport:s,onPanZoom:t,onPanZoomStart:l,onPanZoomEnd:r,onDraggingChange:d}){const c={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},m=e.getBoundingClientRect(),u=Xa().scaleExtent([n,i]).translateExtent(o),b=Ie(e).call(u);S({x:s.x,y:s.y,zoom:wn(s.zoom,n,i)},[[0,0],[m.width,m.height]],o);const h=b.on("wheel.zoom"),v=b.on("dblclick.zoom");u.wheelDelta(Gt);async function p(P,T){return b?new Promise(O=>{u==null||u.interpolate((T==null?void 0:T.interpolate)==="linear"?Gn:wi).transform(ts(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:_,panOnDrag:B,panOnScrollMode:H,panOnScrollSpeed:D,preventScrolling:L,zoomOnPinch:z,zoomOnScroll:q,zoomOnDoubleClick:W,zoomActivationKeyPressed:Z,lib:X,onTransformChange:ie,connectionInProgress:ae,paneClickDistance:R,selectionOnDrag:j}){M&&!c.isZoomingOrPanning&&f();const ee=_&&!Z&&!M;u.clickDistance(j?1/0:!He(R)||R<0?0:R);const J=ee?Nh({zoomPanValues:c,noWheelClassName:P,d3Selection:b,d3Zoom:u,panOnScrollMode:H,panOnScrollSpeed:D,zoomOnPinch:z,onPanZoomStart:l,onPanZoom:t,onPanZoomEnd:r}):Ah({noWheelClassName:P,preventScrolling:L,d3ZoomHandler:h});b.on("wheel.zoom",J,{passive:!1});const K=Ch({zoomPanValues:c,onDraggingChange:d,onPanZoomStart:l});u.on("start",K);const $=kh({zoomPanValues:c,panOnDrag:B,onPaneContextMenu:!!O,onPanZoom:t,onTransformChange:ie});u.on("zoom",$);const G=Mh({zoomPanValues:c,panOnDrag:B,panOnScroll:_,onPaneContextMenu:O,onPanZoomEnd:r,onDraggingChange:d});u.on("end",G);const F=Eh({zoomActivationKeyPressed:Z,panOnDrag:B,zoomOnScroll:q,panOnScroll:_,zoomOnDoubleClick:W,zoomOnPinch:z,userSelectionActive:M,noPanClassName:T,noWheelClassName:P,lib:X,connectionInProgress:ae});u.filter(F),W?b.on("dblclick.zoom",v):b.on("dblclick.zoom",null)}function f(){u.on("zoom",null)}async function S(P,T,O){const M=as(P),_=u==null?void 0:u.constrain()(M,T,O);return _&&await p(_),_}async function g(P,T){const O=as(P);return await p(O,T),O}function w(P){if(b){const T=as(P),O=b.property("__zoom");(O.k!==P.zoom||O.x!==P.x||O.y!==P.y)&&(u==null||u.transform(b,T,null,{sync:!0}))}}function N(){const P=b?Ja(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=>{u==null||u.interpolate((T==null?void 0:T.interpolate)==="linear"?Gn:wi).scaleTo(ts(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=>{u==null||u.interpolate((T==null?void 0:T.interpolate)==="linear"?Gn:wi).scaleBy(ts(b,T==null?void 0:T.duration,T==null?void 0:T.ease,()=>O(!0)),P)}):!1}function E(P){u==null||u.scaleExtent(P)}function k(P){u==null||u.translateExtent(P)}function I(P){const T=!He(P)||P<0?0:P;u==null||u.clickDistance(T)}return{update:y,destroy:f,setViewport:g,setViewportConstrained:S,getViewport:N,scaleTo:A,scaleBy:C,setScaleExtent:E,setTranslateExtent:k,syncViewport:w,setClickDistance:I}}var kn;(function(e){e.Line="line",e.Handle="handle"})(kn||(kn={}));function Ph({width:e,prevWidth:n,height:i,prevHeight:o,affectsX:s,affectsY:t}){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&&t&&(d[1]=d[1]*-1),d}function Ft(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 Xe(e,n){return Math.max(0,n-e)}function Qe(e,n){return Math.max(0,e-n)}function Gi(e,n,i){return Math.max(0,n-e,e-i)}function Vt(e,n){return e?!n:n}function Lh(e,n,i,o,s,t,l,r){let{affectsX:d,affectsY:c}=n;const{isHorizontal:m,isVertical:u}=n,b=m&&u,{xSnapped:h,ySnapped:v}=i,{minWidth:p,maxWidth:y,minHeight:f,maxHeight:S}=o,{x:g,y:w,width:N,height:A,aspectRatio:C}=e;let E=Math.floor(m?h-e.pointerX:0),k=Math.floor(u?v-e.pointerY:0);const I=N+(d?-E:E),P=A+(c?-k:k),T=-t[0]*N,O=-t[1]*A;let M=Gi(I,p,y),_=Gi(P,f,S);if(l){let D=0,L=0;d&&E<0?D=Xe(g+E+T,l[0][0]):!d&&E>0&&(D=Qe(g+I+T,l[1][0])),c&&k<0?L=Xe(w+k+O,l[0][1]):!c&&k>0&&(L=Qe(w+P+O,l[1][1])),M=Math.max(M,D),_=Math.max(_,L)}if(r){let D=0,L=0;d&&E>0?D=Qe(g+E,r[0][0]):!d&&E<0&&(D=Xe(g+I,r[1][0])),c&&k>0?L=Qe(w+k,r[0][1]):!c&&k<0&&(L=Xe(w+P,r[1][1])),M=Math.max(M,D),_=Math.max(_,L)}if(s){if(m){const D=Gi(I/C,f,S)*C;if(M=Math.max(M,D),l){let L=0;!d&&!c||d&&!c&&b?L=Qe(w+O+I/C,l[1][1])*C:L=Xe(w+O+(d?E:-E)/C,l[0][1])*C,M=Math.max(M,L)}if(r){let L=0;!d&&!c||d&&!c&&b?L=Xe(w+I/C,r[1][1])*C:L=Qe(w+(d?E:-E)/C,r[0][1])*C,M=Math.max(M,L)}}if(u){const D=Gi(P*C,p,y)/C;if(_=Math.max(_,D),l){let L=0;!d&&!c||c&&!d&&b?L=Qe(g+P*C+T,l[1][0])/C:L=Xe(g+(c?k:-k)*C+T,l[0][0])/C,_=Math.max(_,L)}if(r){let L=0;!d&&!c||c&&!d&&b?L=Xe(g+P*C,r[1][0])/C:L=Qe(g+(c?k:-k)*C,r[0][0])/C,_=Math.max(_,L)}}}k=k+(k<0?_:-_),E=E+(E<0?M:-M),s&&(b?I>P*C?k=(Vt(d,c)?-E:E)/C:E=(Vt(d,c)?-k:k)*C:m?(k=E/C,c=d):(E=k*C,d=c));const B=d?g+E:g,H=c?w+k:w;return{width:N+(d?-E:E),height:A+(c?-k:k),x:t[0]*E*(d?-1:1)+B,y:t[1]*k*(c?-1:1)+H}}const zt={width:0,height:0,x:0,y:0},Bh={...zt,pointerX:0,pointerY:0,aspectRatio:1};function Ih(e,n,i){var c,m;const o=n.position.x+e.position.x,s=n.position.y+e.position.y,t=(c=e.measured.width)!=null?c:0,l=(m=e.measured.height)!=null?m:0,r=i[0]*t,d=i[1]*l;return[[o-r,s-d],[o+t-r,s+l-d]]}function Dh({domNode:e,nodeId:n,getStoreItems:i,onChange:o,onEnd:s}){const t=Ie(e);let l={controlDirection:Ft("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function r({controlPosition:c,boundaries:m,keepAspectRatio:u,resizeDirection:b,onResizeStart:h,onResize:v,onResizeEnd:p,shouldResize:y}){let f={...zt},S={...Bh};l={boundaries:m,resizeDirection:b,keepAspectRatio:u,controlDirection:Ft(c)};let g,w=null,N=[],A,C,E,k=!1;const I=Sa().on("start",P=>{var z,q,W,Z,X,ie;const{nodeLookup:T,transform:O,snapGrid:M,snapToGrid:_,nodeOrigin:B,paneDomNode:H}=i();if(g=T.get(n),!g)return;w=(z=H==null?void 0:H.getBoundingClientRect())!=null?z:null;const{xSnapped:D,ySnapped:L}=Rn(P.sourceEvent,{transform:O,snapGrid:M,snapToGrid:_,containerBounds:w});f={width:(q=g.measured.width)!=null?q:0,height:(W=g.measured.height)!=null?W:0,x:(Z=g.position.x)!=null?Z:0,y:(X=g.position.y)!=null?X:0},S={...f,pointerX:D,pointerY:L,aspectRatio:f.width/f.height},A=void 0,C=rn(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]]),N=[],E=void 0;for(const[ae,R]of T)if(R.parentId===n&&(N.push({id:ae,position:{...R.position},extent:R.extent}),R.extent==="parent"||R.expandParent)){const j=Ih(R,g,(ie=R.origin)!=null?ie:B);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}h==null||h(P,{...f})}).on("drag",P=>{var V,U,Y;const{transform:T,snapGrid:O,snapToGrid:M,nodeOrigin:_}=i(),B=Rn(P.sourceEvent,{transform:T,snapGrid:O,snapToGrid:M,containerBounds:w}),H=[];if(!g)return;const{x:D,y:L,width:z,height:q}=f,W={},Z=(V=g.origin)!=null?V:_,{width:X,height:ie,x:ae,y:R}=Lh(S,l.controlDirection,B,l.boundaries,l.keepAspectRatio,Z,C,E),j=X!==z,ee=ie!==q,J=ae!==D&&j,K=R!==L&&ee;if(!J&&!K&&!j&&!ee)return;if((J||K||Z[0]===1||Z[1]===1)&&(W.x=J?ae:f.x,W.y=K?R:f.y,f.x=W.x,f.y=W.y,N.length>0)){const Q=ae-D,oe=R-L;for(const ue of N)ue.position={x:ue.position.x-Q+Z[0]*(X-z),y:ue.position.y-oe+Z[1]*(ie-q)},H.push(ue)}if((j||ee)&&(W.width=j&&(!l.resizeDirection||l.resizeDirection==="horizontal")?X:f.width,W.height=ee&&(!l.resizeDirection||l.resizeDirection==="vertical")?ie:f.height,f.width=W.width,f.height=W.height),A&&g.expandParent){const Q=Z[0]*((U=W.width)!=null?U:0);W.x&&W.x<Q&&(f.x=Q,S.x=S.x-(W.x-Q));const oe=Z[1]*((Y=W.height)!=null?Y:0);W.y&&W.y<oe&&(f.y=oe,S.y=S.y-(W.y-oe))}const $=Ph({width:f.width,prevWidth:z,height:f.height,prevHeight:q,affectsX:l.controlDirection.affectsX,affectsY:l.controlDirection.affectsY}),G={...f,direction:$};(y==null?void 0:y(P,G))!==!1&&(k=!0,v==null||v(P,G),o(W,H))}).on("end",P=>{k&&(p==null||p(P,{...f}),s==null||s({...f}),k=!1)});t.call(I)}function d(){t.on(".drag",null)}return{update:r,destroy:d}}function _h(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fi={exports:{}},ls={},Vi={exports:{}},rs={};/**
31
31
  * @license React
32
32
  * use-sync-external-store-shim.production.js
33
33
  *