@overmap-ai/forms 2.1.1 → 2.1.2

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.
@@ -1 +1 @@
1
- (function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("class-variance-authority"),require("react"),require("@xyflow/react/dist/style.css"),require("@xyflow/react"),require("graphology-dag"),require("react-hook-form"),require("uuid"),require("@hello-pangea/dnd"),require("file-saver"),require("@overmap-ai/hooks"),require("react-zxing"),require("@dagrejs/dagre"),require("@adrekic/zod-fieldsjson"),require("graphology"),require("graphology-traversal"),require("lodash.get"),require("lodash.set")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","class-variance-authority","react","@xyflow/react/dist/style.css","@xyflow/react","graphology-dag","react-hook-form","uuid","@hello-pangea/dnd","file-saver","@overmap-ai/hooks","react-zxing","@dagrejs/dagre","@adrekic/zod-fieldsjson","graphology","graphology-traversal","lodash.get","lodash.set"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.forms={},d.jsxRuntime,d.blocks,d.classVarianceAuthority,d.react,null,d.react$1,d.graphologyDag,d.reactHookForm,d.uuid,d.dnd,d.fileSaver,d.hooks,d.reactZxing,d.Dagre,d.zodFieldsjson,d.graphology,d.graphologyTraversal,d.get,d.set))})(this,(function(d,i,a,Y,o,sr,E,Yt,Q,b,Yn,Qn,He,is,Qt,Rt,ts,ls,el,as){"use strict";const ss=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),rs=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,n,l)=>l?l.toUpperCase():n.toLowerCase()),nl=t=>{const e=rs(t);return e.charAt(0).toUpperCase()+e.slice(1)},il=(...t)=>t.filter((e,n,l)=>!!e&&e.trim()!==""&&l.indexOf(e)===n).join(" ").trim(),os=t=>{for(const e in t)if(e.startsWith("aria-")||e==="role"||e==="title")return!0};var ds={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const cs=o.forwardRef(({color:t="currentColor",size:e=24,strokeWidth:n=2,absoluteStrokeWidth:l,className:s="",children:r,iconNode:c,...f},h)=>o.createElement("svg",{ref:h,...ds,width:e,height:e,stroke:t,strokeWidth:l?Number(n)*24/Number(e):n,className:il("lucide",s),...!r&&!os(f)&&{"aria-hidden":"true"},...f},[...c.map(([u,p])=>o.createElement(u,p)),...Array.isArray(r)?r:[r]]));const z=(t,e)=>{const n=o.forwardRef(({className:l,...s},r)=>o.createElement(cs,{ref:r,iconNode:e,className:il(`lucide-${ss(nl(t))}`,`lucide-${t}`,l),...s}));return n.displayName=nl(t),n};const us=z("align-justify",[["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 18h18",key:"1h113x"}],["path",{d:"M3 6h18",key:"d0wm0j"}]]);const hs=z("arrow-down-up",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"m21 8-4-4-4 4",key:"1c9v7m"}],["path",{d:"M17 4v16",key:"7dpous"}]]);const fs=z("arrow-left-right",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);const tl=z("camera",[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);const ps=z("calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);const H=z("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const Ae=z("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const We=z("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);const gs=z("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ms=z("circle-dot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);const Cs=z("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const ys=z("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);const ll=z("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const al=z("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]);const vs=z("clipboard-list",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);const sl=z("clipboard-paste",[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]);const Fs=z("copy-check",[["path",{d:"m12 15 2 2 4-4",key:"2c609p"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const Rn=z("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const ei=z("download",[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]);const rl=z("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);const Vs=z("external-link",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);const ws=z("file",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);const Ss=z("git-branch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);const bs=z("hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);const ol=z("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);const dl=z("layout-panel-top",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}]]);const zs=z("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]);const Ns=z("list-checks",[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const xs=z("list-todo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const Is=z("list",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);const Ms=z("maximize",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]);const Ke=z("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const cl=z("move-down",[["path",{d:"M8 18L12 22L16 18",key:"cskvfv"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const Ze=z("move-up",[["path",{d:"M8 6L12 2L16 6",key:"1yvkyx"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const ul=z("paperclip",[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]);const K=z("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);const qs=z("rectangle-ellipsis",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M17 12h.01",key:"1m0b6t"}],["path",{d:"M7 12h.01",key:"eqddd0"}]]);const Os=z("scan",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]]);const Ts=z("settings",[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Es=z("square-check",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Ls=z("square-dashed",[["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M21 19a2 2 0 0 1-2 2",key:"1j7049"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h1",key:"15o7lz"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M14 21h1",key:"v9vybs"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v1",key:"mxsmne"}],["path",{d:"M3 14v1",key:"vnatye"}],["path",{d:"M21 14v1",key:"169vum"}]]);const hl=z("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);const As=z("text-cursor-input",[["path",{d:"M12 20h-1a2 2 0 0 1-2-2 2 2 0 0 1-2 2H6",key:"1528k5"}],["path",{d:"M13 8h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7",key:"13ksps"}],["path",{d:"M5 16H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1",key:"1n9rhb"}],["path",{d:"M6 4h1a2 2 0 0 1 2 2 2 2 0 0 1 2-2h1",key:"1mj8rg"}],["path",{d:"M9 6v12",key:"velyjx"}]]);const Bs=z("timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);const se=z("trash",[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]);const ni=z("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);const _s=z("video",[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]]);const R=z("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),ii=o.memo(t=>{const{ref:e,file:n,className:l,error:s,rightSlot:r,size:c,...f}=t,h=()=>s?i.jsxs(i.Fragment,{children:[i.jsx(a.LuIcon,{icon:We,color:"var(--base-a11)"}),i.jsx(a.Text,{accentColor:"base",className:"truncate",size:c,children:s})]}):n?i.jsxs(i.Fragment,{children:[i.jsx(a.LuIcon,{icon:ws,color:"var(--base-a11)"}),i.jsx(a.Text,{className:"truncate",size:c,children:n.name})]}):i.jsx(i.Fragment,{children:i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(a.Spinner,{size:c})})});return i.jsxs(a.Card,{className:Y.cx(l,"flex w-full items-center gap-2"),ref:e,size:"xs",...f,children:[h(),r]})});ii.displayName="FileCard";function Be(t){return Array.isArray(t)?t.every(e=>typeof e=="string"):!1}class _e{observers=new Set;notify(e){for(const n of this.observers)n(e)}observe(e){return this.observers.add(e),()=>{this.observers.delete(e)}}}class Se extends _e{id;constructor(e){const{id:n}=e;super(),this.id=n}getOptions(){return{id:this.id}}setOptions(e){"id"in e&&e.id!==void 0&&(this.id=e.id),this.notify(this)}serialize(){return{type:this.type,id:this.id}}config(){return{type:this.type,id:this.id}}static _deserializeConfig(e){const{id:n,type:l}=e;return{id:n,type:l}}static _serializeConfig(e){const{id:n,type:l}=e;return{id:n,type:l}}}class I extends Se{label;description;required;image;constructor(e){const{label:n,description:l,required:s,image:r,...c}=e;super(c),this.label=n,this.description=l,this.required=s,this.image=r}getError(e){if(!(!this.required&&this.isValueBlank(e))){if(this.required&&this.isValueBlank(e))return"This field is required.";for(const n of this.getFieldValidators()){const l=n(e);if(l)return l}}}serialize(){return{...super.serialize(),label:this.label,description:this.description,required:this.required}}config(){return{...super.config(),label:this.label,description:this.description,required:this.required,image:this.image}}static _deserializeConfig(e){const{label:n,description:l,required:s,...r}=e;return{...Se._deserializeConfig(r),label:n,description:l??void 0,required:s}}static _serializeConfig(e){const{label:n,description:l,required:s,...r}=e;return{...Se._serializeConfig(r),label:n,description:l,required:s}}getOptions(){return{...super.getOptions(),label:this.label,description:this.description,required:this.required,image:this.image}}setOptions(e){"label"in e&&e.label!==void 0&&(this.label=e.label),"description"in e&&(this.description=e.description),"required"in e&&e.required!==void 0&&(this.required=e.required),"image"in e&&(this.image=e.image),super.setOptions(e)}isValueBlank(e){return this.areValuesEqual(e,this.blankValue())}cleanValue(e){return e}isValueClean(e){return this.areValuesEqual(e,this.cleanValue(e))}cleanSerializedValue(e){return e}isSerializedValueClean(e){return this.areSerializedValuesEqual(e,this.cleanSerializedValue(e))}isSerializedValueBlank(e){return this.areSerializedValuesEqual(e,this.blankSerializedValue())}getFieldValidators(){return[]}}const B=o.createContext({}),ti=t=>{const[e,n]=o.useState(null);return o.useLayoutEffect(()=>{const l=URL.createObjectURL(t);return n(l),()=>{URL.revokeObjectURL(l)}},[t]),e},be=o.memo(t=>{const{file:e,...n}=t,l=ti(e);return i.jsx("img",{src:l??void 0,alt:e.name,...n})});be.displayName="ImageFile";const fl=o.createContext(()=>{throw new Error("No ImageViewerProvider found")}),Xe=()=>o.useContext(fl),li=o.memo(t=>{const{file:e,onClose:n}=t,l=o.useCallback(()=>{Qn.saveAs(e,e.name)},[e]);return i.jsx(a.Overlay.Root,{open:!0,onOpenChange:n,children:i.jsxs(a.Overlay.Content,{onOpenAutoFocus:a.preventDefault,children:[i.jsxs(a.ButtonGroup,{className:"absolute right-0 top-0 flex items-center gap-2 p-2",accentColor:"base",variant:"soft",children:[i.jsx(a.IconButton,{onClick:l,"aria-label":"download",children:i.jsx(a.LuIcon,{icon:ei})}),i.jsx(a.Separator,{orientation:"vertical",size:"sm"}),i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{onClick:n,"aria-label":"close",children:i.jsx(a.LuIcon,{icon:R})})})]}),i.jsx("div",{className:"flex size-full items-center justify-center overflow-hidden p-4",children:i.jsx(be,{className:"max-h-full max-w-full",file:e})})]})})});li.displayName="ImageViewer";const pl=o.memo(t=>{const{children:e}=t,[n,l]=o.useState(null),s=o.useCallback(()=>{l(null)},[]),r=o.useCallback(f=>{l(f(s))},[s]),c=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),s())},[s,n]);return i.jsxs(fl.Provider,{value:r,children:[e,n&&i.jsx(li,{file:n.file,onClose:c})]})});pl.displayName="FileViewerProvider";const D=o.memo(t=>{const{label:e,error:n,description:l,required:s,children:r,inputId:c,image:f,size:h}=t,[u,p]=o.useState(void 0),m=Xe();o.useEffect(()=>{f instanceof Promise?f.then(p).catch(console.error):p(f)},[f]);const C=o.useCallback(()=>{u&&m(()=>({file:u}))},[m,u]),g=s?`${e??"Unlabelled"} *`:e??"Unlabelled";return i.jsxs("div",{className:"flex flex-col gap-1",children:[u&&i.jsx(be,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:u,onClick:C}),(!!e||!!l)&&i.jsxs("div",{className:"flex flex-col",children:[i.jsx("label",{className:"w-max max-w-full",htmlFor:c,children:i.jsx(a.Text,{size:h,className:"text-wrap",children:g})}),!!l&&i.jsx(a.Text,{accentColor:"base",size:h,children:l})]}),r,!!n&&i.jsx(a.Text,{accentColor:"danger",size:h,children:n})]})});D.displayName="InputWithLabel";const gl=t=>t.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),Ye=t=>t.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),$=t=>{const{field:e}=t,{field:{value:n,name:l,onChange:s,onBlur:r,disabled:c},fieldState:{isTouched:f,error:h}}=Q.useController({name:e.id});return{value:n,name:l,disabled:c,isTouched:f,error:h?.message??"",onChange:s,onBlur:r}},ml=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),[u,p]=o.useState(""),[m,C]=o.useState(""),g=o.useCallback(S=>{c(S),r()},[c,r]),y=o.useCallback(S=>{l&&l.findIndex(q=>q===S.target.value.trim())>=0?C("All options must be unique"):S.target.value?C(""):C("Option cannot be empty"),p(S.target.value)},[p,l]),F=o.useCallback(()=>{if(m)return;if(!u.trim()){C("Option cannot be empty");return}const S=u.trim();g([...l,S]),p("")},[u,m,g,l]),V=o.useCallback(S=>{S.key==="Enter"&&(S.preventDefault(),F())},[F]),w=o.useCallback(S=>{const q=Array.from(l);q.splice(S,1),g(q)},[l,g]),M=o.useCallback(S=>{if(!S.destination)return;const q=S.source.index,x=S.destination.index,T=Array.from(l),[_]=T.splice(q,1);T.splice(x,0,_),g(T)},[g,l]),N=o.useCallback(()=>{r()},[r]);return i.jsx(Yn.DragDropContext,{onDragEnd:M,children:i.jsxs(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:m||f,image:e.image,children:[(!h||l.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx(a.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{value:u,onChange:y,onKeyDown:V,id:e.id,placeholder:e.placeholder??"Press enter to add a new option",onBlur:N,name:s,disabled:h})}),i.jsx(a.IconButton,{size:n,accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!m||h,onClick:F,children:i.jsx(a.LuIcon,{icon:K})})]}),l.length!==0&&i.jsx(Yn.Droppable,{droppableId:`${e.id}-droppable`,children:S=>i.jsxs("div",{className:"flex flex-col gap-1",...S.droppableProps,ref:S.innerRef,children:[l.map((q,x)=>i.jsx(Yn.Draggable,{draggableId:`${q}-draggable`,index:x,isDragDisabled:h,children:({draggableProps:T,dragHandleProps:_,innerRef:X})=>i.jsxs(a.Badge,{..._,...T,ref:X,className:"flex items-center justify-between gap-2",accentColor:"base",size:n,variant:"soft",children:[i.jsx(a.Text,{className:"truncate",highContrast:!0,children:ai(q).label}),i.jsx(a.IconButton,{className:"bg-transparent!",size:n,variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:h,onClick:()=>{w(x)},children:i.jsx(a.LuIcon,{icon:R})})]})},`${e.id}-${q}-${x}`)),S.placeholder]})})]})})});ml.displayName="MultiStringFieldInput";class re extends I{type="multi-string";minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;super(r),this.minLength=n,this.maxLength=l,this.placeholder=s}render(){return i.jsx(ml,{field:this})}serialize(){return{...super.serialize(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}config(){return{...super.config(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}duplicate(e){return new re({...this.getOptions(),id:e})}setOptions(e){"minLength"in e&&(this.minLength=e.minLength),"maxLength"in e&&(this.maxLength=e.maxLength),"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}getFieldValidators(){const e=super.getFieldValidators();return e.push(n=>{if(this.minLength!==void 0&&n.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(n=>{if(this.maxLength!==void 0&&n.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){return new re(e)}static fromConfig(e){return new re(e)}static deserializeConfig(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;return{...I._deserializeConfig(r),minLength:n,maxLength:l,placeholder:s}}static serializeConfig(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;return{...I._serializeConfig(r),minLength:n,maxLength:l,placeholder:s}}isSerializedValue(e){return Be(e)}isValue(e){return Be(e)}blankValue(){return[]}areValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}}function ai(t){return typeof t=="string"&&(t={label:t,value:t}),t}function oe(t){return t.map(ai)}class ee extends I{options;constructor(e){const{options:n,...l}=e;super(l),this.options=oe(n)}serialize(){return{...super.serialize(),options:this.options}}config(){return{...super.config(),options:this.options}}static _deserializeConfig(e){const{options:n,...l}=e;return{...I._deserializeConfig(l),options:n}}static _serializeConfig(e){const{options:n,...l}=e;return{...I._serializeConfig(l),options:oe(n)}}getOptions(){return{...super.getOptions(),options:this.options}}setOptions(e){"options"in e&&e.options!==void 0&&(this.options=oe(e.options)),super.setOptions(e)}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new re({label:"Options",description:"List possible options for the user to select from.",required:!0,id:`${n}options`,minLength:2}),showDirectly:!0}]}}const si=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{c(!!m),r()},[r,c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,error:f,image:e.image,required:e.required,children:i.jsx(a.Checkbox.Root,{id:e.id,name:s,checked:l??!1,onCheckedChange:u,onBlur:p,size:n,accentColor:"base",variant:"surface",disabled:h,children:i.jsx(a.Checkbox.Indicator,{children:i.jsx(a.LuIcon,{icon:H})})})})});si.displayName="BooleanFieldInput";class de extends I{type="boolean";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}setOptions(e){super.setOptions(e)}duplicate(e){return new de({...this.getOptions(),id:e})}static deserialize(e){return new de(e)}static fromConfig(e){return new de(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(si,{field:this})}isSerializedValue(e){return typeof e=="boolean"}isValue(e){return typeof e=="boolean"}blankValue(){return!1}blankSerializedValue(){return!1}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const Cl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{const g=C.target.valueAsNumber,y=isNaN(g)?null:g;c(y)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(C=>{C.key==="Enter"&&C.preventDefault()},[]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.Input.Root,{accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{id:e.id,name:s,onChange:u,onBlur:p,value:l??"",type:"number",min:e.minimum??Number.MIN_SAFE_INTEGER,max:e.maximum??Number.MAX_SAFE_INTEGER,step:e.integers?1:"any",placeholder:e.placeholder??"Enter a number",disabled:h,onKeyDown:m})})})});Cl.displayName="NumberFieldInput";class G extends I{type="number";minimum;maximum;integers;placeholder;constructor(e){const{minimum:n,maximum:l,integers:s,placeholder:r,...c}=e;super(c),this.minimum=n,this.maximum=l,this.integers=s,this.placeholder=r}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Minimum",description:"Minimum value",integers:!0,required:!1,id:`${n}minimum`}),showDirectly:!1},{field:new G({label:"Maximum",description:"Maximum value",integers:!0,required:!1,id:`${n}maximum`}),showDirectly:!1},{field:new de({label:"Integers",description:"Whole numbers only",required:!1,id:`${n}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.minimum,l=this.maximum;return typeof n=="number"&&e.push(s=>{if(typeof s=="number"&&s<n)return`Must be at least ${this.minimum}.`}),e.push(s=>{if(typeof s=="number"&&s<Number.MIN_SAFE_INTEGER)return"Cant be less than MIN_SAFE_INTEGER."}),typeof l=="number"&&e.push(s=>{if(typeof s=="number"&&s>l)return`Must be at most ${l}.`}),e.push(s=>{if(typeof s=="number"&&s>Number.MAX_SAFE_INTEGER)return"Cant be greater than MAX_SAFE_INTEGER."}),this.integers&&e.push(s=>{if(typeof s=="number"&&!Number.isInteger(s))return"Must be a whole number."}),e}serialize(){return{...super.serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}config(){return{...super.config(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}duplicate(e){return new G({...this.getOptions(),id:e})}setOptions(e){"minimum"in e&&(this.minimum=e.minimum),"maximum"in e&&(this.maximum=e.maximum),"integers"in e&&(this.integers=e.integers),"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new G(e)}static fromConfig(e){return new G(e)}static deserializeConfig(e){const{minimum:n,maximum:l,integers:s,placeholder:r,...c}=e;return{...I._deserializeConfig(c),minimum:n,maximum:l,integers:s,placeholder:r}}static serializeConfig(e){const{minimum:n,maximum:l,integers:s,placeholder:r,...c}=e;return{...I._serializeConfig(c),minimum:n,maximum:l,integers:s,placeholder:r}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Cl,{field:this})}isSerializedValue(e){return this.isValue(e)}isValue(e){return typeof e=="number"&&!isNaN(e)||e===null}areValuesEqual(e,n){return e===n}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}class ze extends I{minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;super(r),this.minLength=n,this.maxLength=l,this.placeholder=s}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Minimum length",description:"Minimum number of characters",required:!1,id:`${n}minLength`,minimum:0,integers:!0}),showDirectly:!1},{field:new G({label:"Maximum length",description:"Maximum number of characters",required:!1,id:`${n}maxLength`,minimum:1,integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.minLength,l=this.maxLength;return typeof n=="number"&&e.push(s=>{if(s.length<n)return`Minimum ${n} character(s).`}),typeof l=="number"&&e.push(s=>{if(s.length>l)return`Maximum ${l} character(s).`}),e}serialize(){return{...super.serialize(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}config(){return{...super.config(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}static _deserializeConfig(e){const{maxLength:n,minLength:l,placeholder:s,...r}=e;return{...I._deserializeConfig(r),minLength:l,maxLength:n,placeholder:s}}static _serializeConfig(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;return{...I._serializeConfig(r),minLength:n,maxLength:l,placeholder:s}}getOptions(){return{...super.getOptions(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}setOptions(e){"minLength"in e&&(this.minLength=e.minLength),"maxLength"in e&&(this.maxLength=e.maxLength),"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}isSerializedValue(e){return typeof e=="string"}isValue(e){return typeof e=="string"}blankValue(){return""}blankSerializedValue(){return""}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const yl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{c(m),r()},[r,c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.CheckboxGroup.Root,{id:e.id,name:s,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:n,values:l,onValuesChange:u,disabled:h,children:e.options.map((m,C)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.CheckboxGroup.Item,{value:m.value,onBlur:p,children:i.jsx(a.CheckboxGroup.ItemIndicator,{children:i.jsx(a.LuIcon,{icon:H})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:m.label})]},`${e.id}-${m.value}-${C}`))})})});yl.displayName="CheckboxListFieldInput";class ie extends ee{type="checkbox-list";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new ie({...this.getOptions(),id:e})}static deserialize(e){return new ie(e)}static fromConfig(e){return new ie(e)}static deserializeConfig(e){return ie._deserializeConfig(e)}static serializeConfig(e){return ie._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(yl,{field:this})}isSerializedValue(e){if(!Be(e))return!1;const n=new Set(this.options.map(({value:l})=>l));return e.every(l=>n.has(l))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}areValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}}const ri=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),[u,p]=o.useState(!1),m=o.useCallback(g=>{c(g??null),r(),p(!1)},[c,r]),C=o.useCallback(g=>{p(g),g||r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.Popover.Root,{open:u,onOpenChange:C,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:i.jsxs(a.Button,{id:e.id,name:s,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:n,disabled:h,children:[i.jsx(a.Text,{className:"truncate",highContrast:!!l,children:l?l.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd"}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Popover.Content,{align:"start",size:n,children:i.jsx(a.DayPicker,{size:n,required:!1,mode:"single",variant:"solid",selected:l??void 0,onSelect:m})})]})})});ri.displayName="DateFieldInput";class Ne extends I{type="date";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ne({...this.getOptions(),id:e})}static deserialize(e){return new Ne(e)}static fromConfig(e){return new Ne(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}setOptions(e){super.setOptions(e)}serializeValue(e){return e?e.toISOString():null}deserializeValue(e){return e?new Date(e):null}render(){return i.jsx(ri,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:this.isValue(this.deserializeValue(e))}isValue(e){return!(!(e instanceof Date)&&e!==null||e instanceof Date&&isNaN(e.getTime()))}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return!e&&!n?!0:!e||!n?!1:e.getTime()===n.getTime()}}var O=(t=>(t.Text="text",t.Selection="selection",t.Numeric="numeric",t.Temporal="temporal",t.Capture="capture",t.Assessment="assessment",t.Verification="verification",t))(O||{});const vl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{c(m),r()},[r,c]),p=o.useCallback(m=>{m||r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.Menu.Root,{onOpenChange:p,align:"start",children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{id:e.id,name:s,className:"!justify-between",variant:"surface",type:"button",size:n,accentColor:"base",disabled:h,children:[i.jsx(a.Text,{className:"truncate",highContrast:l&&l.length>0,children:l&&l.length>0?l.join(", "):e.placeholder??"Select one or more..."}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:n,children:i.jsx(a.Menu.Scroll,{children:i.jsxs(a.Menu.MultiSelectGroup,{values:l,onValuesChange:u,children:[i.jsxs(a.Menu.SelectAllItem,{children:[i.jsx(a.Menu.CheckboxItemIndicator,{children:m=>m?i.jsx(a.LuIcon,{icon:Ke}):i.jsx(a.LuIcon,{icon:H})}),"Select all"]}),e.options.map((m,C)=>i.jsxs(a.Menu.MultiSelectItem,{value:m.value,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),m.label]},`${e.id}-${m.value}-${C}`))]})})})]})})});vl.displayName="MultiSelectFieldInput";class te extends ee{type="multi-select";placeholder;constructor(e){const{placeholder:n,...l}=e;super(l),this.placeholder=n}serialize(){return{...super.serialize(),placeholder:this.placeholder}}config(){return{...super.config(),placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),placeholder:this.placeholder}}duplicate(e){return new te({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new te(e)}static fromConfig(e){return new te(e)}static deserializeConfig(e){const{placeholder:n,...l}=e;return{...ee._deserializeConfig(l),placeholder:n}}static serializeConfig(e){const{placeholder:n,...l}=e;return{...ee._serializeConfig(l),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(vl,{field:this})}isSerializedValue(e){if(!Be(e))return!1;const n=new Set(this.options.map(({value:l})=>l));return e.every(l=>n.has(l))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}areValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}}const Fl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useMemo(()=>Array.from({length:e.length},()=>b.v4()),[e.length]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.OneTimePasswordField.Root,{id:e.id,name:s,value:l,onValueChange:u,validationType:"none",disabled:h,orientation:"horizontal",dir:"ltr",type:"text",autoComplete:"off",autoFocus:!1,autoSubmit:!1,className:"p-0.25 flex h-max w-full gap-1 overflow-x-auto",accentColor:"base",variant:"surface",size:n,onBlur:p,children:[m.map(C=>i.jsx(a.OneTimePasswordField.Input,{id:C},C)),i.jsx(a.OneTimePasswordField.HiddenInput,{})]})})});Fl.displayName="OTPFieldInput";class ce extends I{type="otp";length;constructor(e){const{length:n,...l}=e;super(l),this.length=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Length",integers:!0,required:!1,minimum:1,maximum:16,id:`${n}length`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.length;return e.push(l=>{if(l.length!=n)return`Must be ${n} characters.`}),e}serialize(){return{...super.serialize(),length:this.length}}config(){return{...super.config(),length:this.length}}getOptions(){return{...super.getOptions(),length:this.length}}duplicate(e){return new ce({...this.getOptions(),id:e})}setOptions(e){"length"in e&&e.length!==void 0&&(this.length=e.length),super.setOptions(e)}static deserialize(e){return new ce(e)}static fromConfig(e){return new ce(e)}static deserializeConfig(e){const{length:n,...l}=e;return{...I._deserializeConfig(l),length:n}}static serializeConfig(e){const{length:n,...l}=e;return{...I._serializeConfig(l),length:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Fl,{field:this})}isSerializedValue(e){return typeof e=="string"}isValue(e){return typeof e=="string"}blankValue(){return""}areValuesEqual(e,n){return e===n}blankSerializedValue(){return""}areSerializedValuesEqual(e,n){return e===n}}const ue={pass:{label:"Pass",icon:gs},fail:{label:"Fail",icon:ys},na:{label:"N/A",icon:Cs}},Te=Object.keys(ue);class le extends File{uuid;constructor(e,...n){super(...n),this.uuid=e}static from(e,n){return new le(e,[n],n.name,{lastModified:n.lastModified,type:n.type})}}class xe extends Promise{_uuid;constructor(e,n){super(e),this._uuid=n}get uuid(){return this._uuid}set uuid(e){this._uuid=e}static from(e,n){return new xe((l,s)=>{Promise.resolve(e).then(l).catch(s)},n)}then(e,n){const l=super.then(e,n);return l.uuid=this.uuid,l}catch(e){const n=super.catch(e);return n.uuid=this.uuid,n}finally(e){const n=super.finally(e);return n.uuid=this.uuid,n}}function Vl(t){return Array.isArray(t)?t.every(e=>e instanceof xe||e instanceof le):!1}function Qe(t,e){const n=new Set(t.map(({uuid:s})=>s)),l=new Set(e.map(({uuid:s})=>s));return n.size===l.size&&n.isSubsetOf(l)}const wl=o.createContext(()=>{throw new Error("No ImageCapturerProvider found")}),oi=()=>o.useContext(wl),Sl=o.memo(t=>{const{onCapture:e}=t,[n,l]=o.useState("idle"),[s,r]=o.useState(!1),c=o.useRef(null),f=o.useRef(null),h=o.useRef(null),u=o.useCallback(()=>{h.current&&(h.current.getTracks().forEach(g=>g.stop()),h.current=null),c.current&&(c.current.srcObject=null),l("idle")},[]),p=He.useActiveCallback(async g=>{if(c.current){u(),l("loading");try{const y=await navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:{ideal:"environment"},width:{ideal:1920},height:{ideal:1080}}});if(!g()){u();return}h.current=y,c.current.srcObject=y,await c.current.play(),l("ready")}catch{l("errored")}}},[u]),m=o.useCallback(()=>{const g=c.current,y=f.current;if(!g||!y||g.videoWidth<=0||g.videoHeight<=0)return;const F=Math.min(g.clientWidth/g.videoWidth,g.clientHeight/g.videoHeight);y.style.width=`${g.videoWidth*F}px`,y.style.height=`${g.videoHeight*F}px`,y.getAnimations().forEach(V=>V.cancel()),y.animate([{opacity:.8},{opacity:0}],{duration:250,easing:"ease-out"})},[]),C=He.useActiveCallback(async g=>{if(c.current)try{r(!0);const y=c.current,F=y.videoHeight,V=y.videoWidth,w=Math.max(V,F),M=Math.min(1,1920/w),N=document.createElement("canvas");N.width=Math.round(V*M),N.height=Math.round(F*M);const S=N.getContext("2d");if(!S)throw new Error("Could not setup canvas context.");S.drawImage(y,0,0,N.width,N.height),m();const q=await new Promise((X,A)=>{N.toBlob(J=>J?X(J):A(new Error("Could not convert canvas to blob.")),"image/jpeg",.92)});if(!g())return;const x=new Date,T=`${x.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"short"}).replaceAll(":","-").replaceAll("/","-").replaceAll(",","")}.jpg`,_=new File([q],T,{type:q.type,lastModified:x.getTime()});e?.(_)}catch(y){a.toast.error({title:"Photo not captured",description:y instanceof Error?y.message:"The photo could not be captured."})}finally{r(!1)}},[e,m],{deactivateOnCall:!1});return o.useEffect(()=>(p(),()=>{u()}),[p,u]),i.jsxs("div",{className:"flex max-h-full max-w-full shrink grow flex-col gap-4 overflow-hidden",children:[i.jsxs("div",{className:Y.cx("relative flex shrink grow flex-col items-center justify-center overflow-hidden",{"bg-black":!n}),children:[i.jsx("video",{ref:c,className:"max-h-full max-w-full object-contain",muted:!0,playsInline:!0}),i.jsx("div",{ref:f,"aria-hidden":"true",className:"-translate-1/2 pointer-events-none absolute left-1/2 top-1/2 bg-white opacity-0"}),n==="loading"?i.jsx(a.Spinner,{size:"xl",className:"-translate-1/2 absolute left-1/2 top-1/2"}):null,n==="errored"?i.jsx(a.LuIcon,{icon:We,size:24,className:"-translate-1/2 absolute left-1/2 top-1/2"}):null]}),i.jsx("div",{className:"flex h-max shrink-0 justify-center",children:i.jsx("button",{className:"bg-(--base-1) border-(--base-12) size-16 rounded-full border-[5px] outline-offset-4 transition-transform active:scale-95 active:brightness-110",type:"button",onClick:C,disabled:s})})]})});Sl.displayName="Camera";const bl=o.memo(t=>{const{files:e,onDelete:n,children:l,open:s,onOpenChange:r,defaultOpen:c,modal:f}=t,[h,u]=o.useState(null);o.useEffect(()=>{u(e.length>0?e[0]:null)},[e]);const p=o.useCallback(()=>{h&&Qn.saveAs(h,h.name)},[h]),m=o.useCallback(()=>{if(!h)return;const y=e.indexOf(h);u(y!==0?e[y-1]:e[e.length-1])},[h,e]),C=o.useCallback(()=>{if(!h)return;const y=e.indexOf(h);u(y!==e.length-1?e[y+1]:e[0])},[h,e]),g=o.useCallback(()=>{h&&n?.(h)},[h,n]);return i.jsxs(a.Overlay.Root,{open:s,onOpenChange:r,defaultOpen:c,modal:f,children:[!!l&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:l}),i.jsx(a.Overlay.Content,{onOpenAutoFocus:a.preventDefault,children:i.jsxs("div",{className:"flex size-full flex-col gap-4 p-4",children:[i.jsx(a.ButtonGroup,{className:"flex w-full shrink-0 items-center justify-end gap-2",accentColor:"base",variant:"soft",children:i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{"aria-label":"close",type:"button",children:i.jsx(a.LuIcon,{icon:R})})})}),i.jsx("div",{className:"flex grow items-center justify-center overflow-hidden",children:h?i.jsx(be,{className:"max-h-full max-w-full",file:h}):null}),i.jsxs(a.ButtonGroup,{className:"flex w-full shrink-0 items-center gap-2",accentColor:"base",variant:"soft",children:[i.jsx(a.IconButton,{onClick:p,"aria-label":"download",type:"button",children:i.jsx(a.LuIcon,{icon:ei})}),i.jsxs("div",{className:"flex grow items-center justify-center gap-2 overflow-hidden",children:[i.jsx(a.IconButton,{"aria-label":"previous",onClick:m,type:"button",children:i.jsx(a.LuIcon,{icon:Ze,className:"-rotate-90 rounded-r-none"})}),i.jsx(a.IconButton,{"aria-label":"next",onClick:C,type:"button",children:i.jsx(a.LuIcon,{icon:Ze,className:"rotate-90 rounded-l-none"})})]}),i.jsx(a.IconButton,{"aria-label":"delete",onClick:g,type:"button",children:i.jsx(a.LuIcon,{icon:se})})]})]})})]})});bl.displayName="ImagesViewer";const di=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,onConfirm:c}=t,[f,h]=o.useState([]),u=o.useCallback(g=>{g||h([]),l?.(g)},[l]),p=o.useCallback(g=>{h(y=>[...y,g])},[]),m=o.useCallback(g=>{h(y=>y.filter(F=>F!==g))},[]),C=o.useCallback(()=>{c?.(f)},[f,c]);return i.jsxs(a.Overlay.Root,{open:n,onOpenChange:u,defaultOpen:s,modal:r,children:[!!e&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:e}),i.jsxs(a.Overlay.Content,{onOpenAutoFocus:a.preventDefault,children:[i.jsx(a.Overlay.Title,{className:"sr-only",children:"Image capturer"}),i.jsx(a.Overlay.Description,{className:"sr-only",children:"Capture one or more images."}),i.jsxs("div",{className:"bg-(--color-background) flex size-full flex-col gap-4 overflow-hidden py-4",children:[i.jsxs("div",{className:"flex h-max items-center justify-between gap-4 px-4",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{size:"md",variant:"surface",onClick:C,children:i.jsx(a.LuIcon,{icon:H})})}),f.length>0?i.jsx(bl,{files:f,onDelete:m,children:i.jsxs(a.Button,{variant:"soft",accentColor:"base",children:[f.length," ",f.length>1?"images":"image"]})}):null]}),i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{size:"md",variant:"soft",accentColor:"base",children:i.jsx(a.LuIcon,{icon:R})})})]}),i.jsx(Sl,{onCapture:p})]})]})]})});di.displayName="ImageCapturer";const zl=o.memo(t=>{const{children:e}=t,[n,l]=o.useState(null),s=o.useCallback(()=>{l(null)},[]),r=o.useCallback(f=>{l(f(s))},[s]),c=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),s())},[s,n]);return i.jsxs(wl.Provider,{value:r,children:[e,n&&i.jsx(di,{open:!0,onOpenChange:c,onConfirm:n.onConfirm,modal:n.modal})]})});zl.displayName="ImageCapturerProvider";const ci=o.memo(t=>{const{ref:e,file:n,error:l,rightSlot:s,className:r,size:c,...f}=t;return i.jsxs(a.Card,{className:Y.cx(r,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!l&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(a.Spinner,{size:c})}),!!n&&!l&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(be,{className:"block size-full max-w-full object-cover",file:n})}),!!l&&i.jsx("div",{className:"grow"}),(!!n||!!l)&&i.jsxs(i.Fragment,{children:[i.jsx(a.Separator,{size:"full"}),i.jsxs("div",{className:"flex w-full shrink-0 items-center gap-2 self-end p-3",children:[l?i.jsx(a.LuIcon,{color:"var(--base-11)",icon:We}):n&&i.jsx(a.LuIcon,{color:"var(--base-11)",icon:ol}),i.jsx(a.Text,{className:"truncate",size:c,children:l??n?.name}),s]})]})]})});ci.displayName="ImageCard";const ui=o.memo(t=>{const{file:e,...n}=t,l=ti(e);return i.jsx("video",{src:l??void 0,...n})});ui.displayName="VideoFile";const hi=o.memo(t=>{const{ref:e,file:n,className:l,error:s,rightSlot:r,size:c,...f}=t;return i.jsxs(a.Card,{className:Y.cx(l,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!s&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(a.Spinner,{size:c})}),!!n&&!s&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(ui,{className:"block size-full max-w-full object-cover",file:n,controls:!0})}),!!s&&i.jsx("div",{className:"grow"}),(!!n||!!s)&&i.jsxs(i.Fragment,{children:[i.jsx(a.Separator,{size:"full"}),i.jsxs("div",{className:"flex w-full shrink-0 items-center gap-2 self-end p-3",children:[s?i.jsx(a.LuIcon,{color:"var(--danger-11)",icon:We}):n&&i.jsx(a.LuIcon,{color:"var(--base-11)",icon:_s}),i.jsx(a.Text,{className:"truncate",size:c,children:s??n?.name}),r]})]})]})});hi.displayName="VideoCard";const fi=o.memo(t=>{const{fileOrPromise:e,onRemove:n,disabled:l,size:s}=t,[r,c]=o.useState(e instanceof xe?null:e),[f,h]=o.useState(null),u=Xe();He.useActiveEffect(w=>{if(h(null),!(e instanceof xe)){c(e);return}c(null),e.then(M=>{w()&&c(M)}).catch(M=>{w()&&h(M instanceof Error?M.message:"Unknown error")})},[e]);const p=o.useCallback(()=>{if(!r)return;const w=new Blob([r]);Qn.saveAs(w,r.name)},[r]),m=o.useCallback(()=>{n(e)},[n,e]),C=o.useCallback(()=>{if(!r)return;const w=URL.createObjectURL(r);window.open(w,"_blank"),URL.revokeObjectURL(w)},[r]),g=o.useCallback(()=>{r&&u(w=>({file:r,onDelete:l?void 0:()=>{m(),w()}}))},[l,m,u,r]),y=o.useMemo(()=>i.jsx("div",{className:"flex grow justify-end",children:i.jsxs(a.Menu.Root,{modal:!0,children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.IconButton,{onClick:a.stopPropagation,type:"button",variant:"ghost",accentColor:"base",size:s,children:i.jsx(a.LuIcon,{icon:rl})})}),i.jsxs(a.Menu.Content,{size:s,children:[i.jsxs(a.Menu.Item,{onSelect:p,disabled:!r,children:[i.jsx(a.LuIcon,{icon:ei})," Download"]}),l?null:i.jsxs(i.Fragment,{children:[i.jsx(a.Menu.Separator,{}),i.jsxs(a.Menu.Item,{onSelect:m,children:[i.jsx(a.LuIcon,{icon:se})," Delete"]})]})]})]})}),[l,m,p,r,s]),F=!!r?.type.startsWith("image/"),V=!!r?.type.startsWith("video/");return F?i.jsx(ci,{className:"cursor-pointer",onClick:g,file:r,error:f??void 0,rightSlot:y,size:s}):V?i.jsx(hi,{className:"cursor-pointer",onClick:g,file:r,error:f??void 0,rightSlot:y,size:s}):i.jsx(ii,{className:"cursor-pointer",file:r,error:f??void 0,onClick:C,rightSlot:y,size:s})});fi.displayName="DisplayFile";const Nl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=oi(),p=o.useRef(null),m=o.useCallback(x=>{const T=e.cleanValue({...l,status:x});c(T),r()},[e,r,c,l]),C=o.useCallback(x=>{const T=x.target.value,_={...l,notes:T};c(_)},[l,c]),g=o.useCallback(()=>{r()},[r]),y=o.useCallback(x=>{const T=l.files.filter(({uuid:_})=>_!==x.uuid);c({...l,files:T}),r()},[c,r,l]),F=o.useCallback(()=>{u(x=>({onConfirm:T=>{const _=T.map(X=>le.from(b.v4(),X));c({...l,files:[...l.files,..._]}),r()},onClose:()=>{r(),x()}}))},[r,c,l,u]),V=o.useCallback(()=>{p.current?.click()},[]),w=o.useCallback(x=>{const T=Array.from(x.target.files??[]).map(X=>le.from(b.v4(),X)),_={...l,files:[...l.files,...T]};c(_),r()},[r,c,l]);o.useEffect(()=>{if(!p.current)return;const x=new AbortController;return p.current.addEventListener("cancel",()=>{r()},{signal:x.signal}),()=>{x.abort()}},[r,l]);const M=l.status&&e.showNotesAndFilesOn.includes(l.status),N=`${e.id}-status`,S=`${e.id}-notes`,q=`${e.id}-files`;return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(a.RadioGroup.Root,{id:N,className:"flex gap-2",name:s,value:l.status,disabled:h,accentColor:"base",variant:"surface",size:n,onValueChange:m,children:Te.map(x=>{const{label:T}=ue[x];return i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.RadioGroup.Item,{value:x,children:i.jsx(a.RadioGroup.Indicator,{children:i.jsx(a.LuIcon,{icon:ll,className:"fill-current"})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:T})]},`${e.id}-${x}`)})}),M&&i.jsxs(i.Fragment,{children:[i.jsx("div",{children:i.jsx(a.TextArea,{id:S,value:l.notes??"",name:s,onChange:C,onBlur:g,className:"field-sizing-content min-h-12 w-full",placeholder:"Notes",resize:"vertical",accentColor:"base",variant:"surface",size:n,disabled:h})}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{className:"w-max",size:n,variant:"surface",accentColor:"base",type:"button",disabled:h,children:[i.jsx(a.LuIcon,{icon:ni}),"Select files"]})}),i.jsxs(a.Menu.Content,{size:n,children:[i.jsxs(a.Menu.Item,{onSelect:F,children:[i.jsx(a.LuIcon,{icon:tl}),"Take photos"]}),i.jsxs(a.Menu.Item,{onSelect:V,children:[i.jsx(a.LuIcon,{icon:ul}),"Attach files"]})]})]}),i.jsx("input",{id:q,name:s,type:"file",ref:p,multiple:!0,className:"hidden",onChange:w,value:""}),l.files.length>0&&i.jsx("div",{className:"flex h-max flex-wrap gap-2",children:l.files.map(x=>i.jsx(fi,{size:n,fileOrPromise:x,onRemove:y,disabled:h},x.uuid))})]})]})]})})});Nl.displayName="PassFailFieldInput";const pi=t=>typeof t=="string"&&Te.includes(t),xl=t=>!(t===null||typeof t!="object"||!("status"in t)||!pi(t.status)||!("notes"in t)||typeof t.notes!="string"||!("files"in t)||!(Array.isArray(t.files)&&t.files.length===0)),Il=t=>!(t===null||typeof t!="object"||!("status"in t)||!pi(t.status)||!("notes"in t)||typeof t.notes!="string"||!("files"in t)||!Vl(t.files)),Ml=t=>({status:t.status,notes:t.notes,files:[]}),ql=t=>({status:t.status,notes:t.notes,files:[]}),Ol=(t,e)=>!(t.status!==e.status||t.notes!==e.notes||!Qe(t.files,e.files)),Tl=(t,e)=>!(t.status!==e.status||t.notes!==e.notes||t.files.length!==e.files.length);class he extends I{type="pass-fail";showNotesAndFilesOn;constructor(e){const{showNotesAndFilesOn:n,...l}=e;super(l),this.showNotesAndFilesOn=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new te({id:`${n}showNotesAndFilesOn`,label:"Show notes and files on",description:"Show the notes and files on desired statuses.",options:Te.map(l=>{const{label:s}=ue[l];return{value:l,label:s}}),required:!1}),showDirectly:!1}]}serialize(){return{...super.serialize(),showNotesAndFilesOn:this.showNotesAndFilesOn}}config(){return{...super.config(),showNotesAndFilesOn:this.showNotesAndFilesOn}}getOptions(){return{...super.getOptions(),showNotesAndFilesOn:this.showNotesAndFilesOn}}duplicate(e){return new he({...this.getOptions(),id:e})}setOptions(e){"showNotesAndFilesOn"in e&&e.showNotesAndFilesOn!==void 0&&(this.showNotesAndFilesOn=e.showNotesAndFilesOn),super.setOptions(e)}getFieldValidators(){const e=super.getFieldValidators(),n=this.showNotesAndFilesOn,l=this.blankValue();return n.length>0&&(e.push(s=>{if(!(!s.status||!n.includes(s.status))&&l.notes===s.notes)return"Notes is required."}),e.push(s=>{if(!(!s.status||!n.includes(s.status))&&Qe(l.files,s.files))return"Files is required."})),e}static deserialize(e){const{showNotesAndFilesOn:n,...l}=e;return new he({...l,showNotesAndFilesOn:n})}static fromConfig(e){return new he(e)}static deserializeConfig(e){const{showNotesAndFilesOn:n,...l}=e;return{...I._deserializeConfig(l),showNotesAndFilesOn:n}}static serializeConfig(e){const{showNotesAndFilesOn:n,...l}=e;return{...I._serializeConfig(l),showNotesAndFilesOn:n}}serializeValue(e){return Ml(e)}deserializeValue(e){return ql(e)}render(){return i.jsx(Nl,{field:this})}isSerializedValue(e){return xl(e)}isValue(e){return Il(e)}areValuesEqual(e,n){return Ol(e,n)}blankValue(){return{status:null,notes:"",files:[]}}cleanValue(e){return e.status&&this.showNotesAndFilesOn.includes(e.status)?e:{status:e.status,notes:"",files:[]}}cleanSerializedValue(e){return super.cleanSerializedValue(e)}blankSerializedValue(){return{status:null,notes:"",files:[]}}areSerializedValuesEqual(e,n){return Tl(e,n)}}const El=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C),r()},[r,c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(()=>{c(null),r()},[r,c]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.RadioGroup.Root,{id:e.id,name:s,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:n,value:l??"",onValueChange:u,disabled:h,children:[e.options.map((C,g)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.RadioGroup.Item,{value:C.value,onBlur:p,children:i.jsx(a.RadioGroup.Indicator,{children:i.jsx(a.LuIcon,{icon:ll,className:"fill-current"})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:C.label})]},`${e.id}-${C.value}-${g}`)),!!l&&i.jsxs(a.Button,{onClick:m,className:"-mx-2 w-max",type:"button",variant:"ghost",accentColor:"base",size:n,children:[i.jsx(a.LuIcon,{icon:R}),"Clear"]})]})})});El.displayName="RadioFieldInput";class fe extends ee{type="radio";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new fe({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new fe(e)}static fromConfig(e){return new fe(e)}static deserializeConfig(e){return ee._deserializeConfig(e)}static serializeConfig(e){return ee._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(El,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:l})=>l)]).has(e)}isValue(e){return this.isSerializedValue(e)}blankValue(){return null}areValuesEqual(e,n){return e===n}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}const Ds=Y.cva(["group flex cursor-pointer items-center justify-center text-yellow-500 transition-colors disabled:pointer-events-none disabled:opacity-50"],{variants:{size:{xs:["size-5"],sm:["size-6"],md:["size-7"],lg:["size-8"],xl:["size-9"]}}}),Ll=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C),r()},[r,c]),p=o.useCallback(()=>{c(null),r()},[r,c]),m=Array.from({length:e.maxRating},(C,g)=>g+1);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs("div",{className:"flex flex-row items-center gap-1",children:[i.jsx(a.Rating.Root,{id:e.id,name:s,className:"flex items-center gap-0.5",value:l,onValueChange:u,disabled:h,children:m.map(C=>i.jsx(a.Rating.Item,{value:C,className:Ds({size:n}),children:i.jsx(a.LuIcon,{icon:hl,className:"size-full group-data-[active=true]:fill-current"})},`${e.id}-${C}`))}),!h&&l!==null&&i.jsx(a.IconButton,{onClick:p,type:"button",variant:"ghost",accentColor:"base",size:n,children:i.jsx(a.LuIcon,{icon:R})})]})})});Ll.displayName="RatingFieldInput";class pe extends I{type="rating";maxRating;constructor(e){const{maxRating:n,...l}=e;super(l),this.maxRating=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Max Rating",description:"Maximum rating value",integers:!0,required:!1,minimum:1,maximum:10,id:`${n}maxRating`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.maxRating;return e.push(l=>{if(typeof l=="number"&&(l<1||l>n))return`Rating must be between 1 and ${n}.`}),e}serialize(){return{...super.serialize(),maxRating:this.maxRating}}config(){return{...super.config(),maxRating:this.maxRating}}getOptions(){return{...super.getOptions(),maxRating:this.maxRating}}duplicate(e){return new pe({...this.getOptions(),id:e})}setOptions(e){"maxRating"in e&&e.maxRating!==void 0&&(this.maxRating=e.maxRating),super.setOptions(e)}static deserialize(e){return new pe(e)}static fromConfig(e){return new pe(e)}static deserializeConfig(e){const{maxRating:n,...l}=e;return{...I._deserializeConfig(l),maxRating:n}}static serializeConfig(e){const{maxRating:n,...l}=e;return{...I._serializeConfig(l),maxRating:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Ll,{field:this})}isSerializedValue(e){return this.isValue(e)}isValue(e){return typeof e=="number"&&!isNaN(e)||e===null}areValuesEqual(e,n){return e===n}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}const gi=o.createContext(null),Al=()=>{const t=o.use(gi);if(!t)throw new Error("useScannerContext must be used within a component tree wrapped by ScannerProvider.");return t},Ps=()=>{const t=o.use(gi);if(!t)throw new Error("useScanner must be used within a component tree wrapped by ScannerProvider.");return t.openScanner},Re=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,...c}=t;return i.jsxs(a.Overlay.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[!!e&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:e}),i.jsxs(a.Overlay.Content,{children:[i.jsx(a.Overlay.Title,{className:"sr-only",children:"Scanner"}),i.jsx(a.Overlay.Description,{className:"sr-only",children:"Scan a barcode or a qr code."}),i.jsx(Bl,{...c})]})]})});Re.displayName="Scanner";const Bl=o.memo(t=>{const{paused:e,formats:n,timeBetweenDecodingAttempts:l,trySkew:s,onDecodeResult:r,onDecodeError:c,onError:f}=t,{wasmUrl:h}=Al(),{ref:u}=is.useZxing({wasmUrl:h,paused:e,formats:n,timeBetweenDecodingAttempts:l,trySkew:s,onDecodeResult:r,onDecodeError:c,onError:f,constraints:{video:{width:{ideal:1920,min:1280},height:{ideal:1080,min:720},aspectRatio:{ideal:16/9},facingMode:"environment"}}});return i.jsxs("div",{className:"bg-(--color-background) flex size-full flex-col justify-center overflow-hidden",children:[i.jsx("div",{className:"flex w-full justify-end p-4",children:i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:i.jsx(a.LuIcon,{icon:R})})})}),i.jsx("div",{className:"max-h-full w-full grow overflow-hidden p-4",children:i.jsx("video",{className:"size-full",ref:u,muted:!0,playsInline:!0})})]})});Bl.displayName="ScannerInternal";const _l=o.memo(t=>{const{children:e,wasmUrl:n}=t,[l,s]=o.useState(null),r=o.useCallback(()=>{s(null)},[]),c=o.useCallback(u=>{s(u(r))},[r]),f=o.useCallback(()=>{l&&(l.onClose&&l.onClose(),r())},[r,l]),h=o.useMemo(()=>({wasmUrl:n,openScanner:c}),[n,c]);return i.jsxs(gi,{value:h,children:[e,l&&i.jsx(Re,{open:!0,onOpenChange:f,...l})]})});_l.displayName="ScannerProvider";const Dl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),[u,p]=o.useState(!1),m=o.useCallback(V=>{const w=V.target.value;c(w)},[c]),C=o.useCallback(()=>{r()},[r]),g=o.useCallback(V=>{c(V.rawValue.trim()),r(),p(!1)},[c,r]),y=o.useCallback(()=>{p(!0)},[]),F=o.useCallback(()=>{p(!1),r()},[r]);return i.jsxs(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:[i.jsx(a.TextArea,{className:"field-sizing-content w-full",accentColor:"base",variant:"surface",size:n,id:e.id,name:s,value:l??"",placeholder:"Enter a qr or barcode",onChange:m,onBlur:C,disabled:h}),i.jsxs(a.Button,{onClick:y,className:"w-max",type:"button",variant:"soft",size:n,accentColor:"base",disabled:h,children:[i.jsx(a.LuIcon,{icon:Ms}),"Scan"]}),i.jsx(Re,{open:u,onDecodeResult:g,onOpenChange:F})]})});Dl.displayName="ScanFieldInput";class Ie extends I{type="qr";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ie({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new Ie(e)}static fromConfig(e){return new Ie(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Dl,{field:this})}isSerializedValue(e){return typeof e=="string"}isValue(e){return typeof e=="string"}blankValue(){return""}areValuesEqual(e,n){return e===n}blankSerializedValue(){return""}areSerializedValuesEqual(e,n){return e===n}}const Pl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C??null),r()},[r,c]),p=o.useCallback(C=>{C||r()},[r]),m=o.useMemo(()=>e.options.find(C=>C.value===l),[e.options,l]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.Menu.Root,{onOpenChange:p,align:"start",children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{id:e.id,name:s,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:n,disabled:h,children:[i.jsx(a.Text,{className:"truncate",highContrast:!!m,children:m?m.label:e.placeholder??"Select one..."}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:n,children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!1,value:l??void 0,onValueChange:u,children:e.options.map((C,g)=>i.jsxs(a.Menu.SelectItem,{value:C.value,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),C.label]},`${e.id}-${C.value}-${g}`))})})})]})})});Pl.displayName="SelectFieldInput";class ge extends ee{type="select";placeholder;constructor(e){const{placeholder:n,...l}=e;super(l),this.placeholder=n}serialize(){return{...super.serialize(),placeholder:this.placeholder}}config(){return{...super.config(),placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),placeholder:this.placeholder}}duplicate(e){return new ge({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new ge(e)}static fromConfig(e){return new ge(e)}static deserializeConfig(e){const{placeholder:n,...l}=e;return{...ee._deserializeConfig(l),placeholder:n}}static serializeConfig(e){const{placeholder:n,...l}=e;return{...ee._serializeConfig(l),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Pl,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:l})=>l)]).has(e)}isValue(e){return this.isSerializedValue(e)}blankValue(){return null}areValuesEqual(e,n){return e===n}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}const $l=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{const g=C.target.value;c(g)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(C=>{C.key==="Enter"&&C.preventDefault()},[]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.Input.Root,{accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{id:e.id,className:"truncate",name:s,value:l??"",type:"text",placeholder:e.placeholder??"Enter a short description",onChange:u,onBlur:p,disabled:h,onKeyDown:m})})})});$l.displayName="StringFieldInput";class me extends ze{type="string";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new me({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new me(e)}static fromConfig(e){return new me(e)}static deserializeConfig(e){return ze._deserializeConfig(e)}static serializeConfig(e){return ze._serializeConfig(e)}render(){return i.jsx($l,{field:this})}}const kl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{const C=m.target.value;c(C)},[c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.TextArea,{id:e.id,value:l??"",name:s,onChange:u,onBlur:p,className:"field-sizing-content min-h-12",placeholder:e.placeholder??"Enter a description",resize:"vertical",accentColor:"base",variant:"surface",size:n,disabled:h})})});kl.displayName="TextFieldInput";class Ce extends ze{type="text";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ce({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new Ce(e)}static fromConfig(e){return new Ce(e)}static deserializeConfig(e){return ze._deserializeConfig(e)}static serializeConfig(e){return ze._serializeConfig(e)}render(){return i.jsx(kl,{field:this})}}const mi=$s(),jl=new Set(mi);function $s(t=!0){const e=new Set;for(let n=-12;n<=14;n++){const l=n>=0?"+":"-",s=Math.abs(n).toString().padStart(2,"0");e.add(`${l}${s}:00`)}if(t){const n=[-12.5,-9.5,-3.5,3.5,4.5,5.5,6.5,9.5,10.5,12.5];for(const l of n){const s=l>=0?"+":"-",r=Math.floor(Math.abs(l)).toString().padStart(2,"0");e.add(`${s}${r}:30`)}}return Array.from(e).sort((n,l)=>Ul(n)-Ul(l))}function Ul(t){const e=t[0]==="+"?1:-1,n=Number(t.slice(1,3)),l=Number(t.slice(4,6));return e*(n*60+l)}const ks="+00:00",js=/^T([01]\d|2[0-3]):([0-5]\d):00([+-]\d{2}:\d{2})$/,en=t=>typeof t=="string"&&jl.has(t),Gl=()=>{const t=-new Date().getTimezoneOffset(),e=t>=0?"+":"-",n=Math.abs(t),l=Math.floor(n/60),s=n%60,r=`${e}${l.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`;return en(r)?r:ks};function Jl(t){const e=/^([+-])(\d{2}):(\d{2})$/.exec(t);if(!e)throw new Error(`Invalid UTC offset: ${t}`);return(e[1]==="+"?1:-1)*(Number(e[2])*60+Number(e[3]))}const De=t=>{const e=js.exec(t);if(!e)return null;const n=e[3];return en(n)?{hours:Number(e[1]),minutes:Number(e[2]),utcOffset:n}:null},ne=t=>typeof t=="string"&&De(t)!==null,ye=(t,e,n=Gl())=>{if(!Number.isInteger(t)||t<0||t>23)throw new Error(`Invalid hour: ${t}`);if(!Number.isInteger(e)||e<0||e>59)throw new Error(`Invalid minute: ${e}`);if(!en(n))throw new Error("Unsupported UTC offset");const l=t.toString().padStart(2,"0"),s=e.toString().padStart(2,"0");return`T${l}:${s}:00${n}`},nn=t=>`UTC${t}`,ve=t=>{const e=De(t);if(!e)throw new Error(`Invalid time value: ${t}`);return(e.hours*60+e.minutes-Jl(e.utcOffset)+1440)%1440},tn=(t,e=!0)=>{const n=De(t);if(!n)throw new Error(`Invalid time value: ${t}`);const l=(n.hours%12||12).toString().padStart(2,"0"),s=n.minutes.toString().padStart(2,"0"),r=n.hours>=12?"PM":"AM",c=`${l}:${s} ${r}`;return e?`${c} ${nn(n.utcOffset)}`:c},Us=t=>typeof t=="object"&&(ne(t.from)||ne(t.to)),Ci=(t,e)=>{const n=ve(t),l=e.from?ve(e.from):null,s=e.to?ve(e.to):null;return l===null&&s===null?!0:l===null?n<=s:s===null?n>=l:l<=s?n>=l&&n<=s:n>=l||n<=s},ln=o.memo(t=>{const{value:e,onChange:n,onBlur:l,disabled:s,size:r="md",id:c,name:f,compact:h=!1}=t,u=e?De(e):null,p=u?`${u.hours.toString().padStart(2,"0")}:${u.minutes.toString().padStart(2,"0")}`:"",m=o.useCallback(y=>{const F=y.target.value;if(!F){n(null);return}const[V,w]=F.split(":").map(Number);n(ye(V,w,u?.utcOffset))},[n,u?.utcOffset]),C=o.useCallback(y=>{u&&(n(ye(u.hours,u.minutes,y)),l?.())},[l,n,u]),g=o.useCallback(y=>{y||l?.()},[l]);return i.jsxs("div",{className:"flex min-w-0 gap-2",children:[i.jsx(a.Input.Root,{className:"min-w-0 grow",accentColor:"base",variant:"surface",size:r,children:i.jsx(a.Input.Field,{id:c,name:f,className:Y.cx("[&::-webkit-calendar-picker-indicator]:invert-40 dark:[&::-webkit-calendar-picker-indicator]:invert-60",{"[&::-webkit-datetime-edit]:opacity-60":!e}),type:"time",step:60,value:p,onChange:m,onBlur:l,disabled:s})}),i.jsxs(a.Menu.Root,{align:"end",onOpenChange:g,children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",className:h?"!justify-between":"min-w-32 !justify-between",accentColor:"base",variant:"surface",size:r,disabled:s||!u,children:[i.jsx(a.Text,{className:"truncate",highContrast:!!u,children:u?nn(u.utcOffset):"UTC offset"}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:r,children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!0,value:u?.utcOffset,onValueChange:C,children:mi.map(y=>i.jsxs(a.Menu.SelectItem,{value:y,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),nn(y)]},y))})})})]})]})});ln.displayName="TimeFieldControl";const yi=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e});return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(ln,{id:e.id,name:s,size:n,value:l,onChange:c,onBlur:r,disabled:h})})});yi.displayName="TimeFieldInput";class Me extends I{type="time";constructor(e){super(e)}static deserialize(e){return new Me(e)}static fromConfig(e){return new Me(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Me({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(yi,{field:this})}isSerializedValue(e){return e===null||ne(e)}isValue(e){return e===null||ne(e)}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const Hl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=oi(),p=o.useRef(null),m=o.useCallback(()=>{u(N=>({onConfirm:S=>{const q=Array.from(S).map(T=>le.from(b.v4(),T)),x=[...l,...q];c(x),r()},onClose:()=>{r(),N()}}))},[r,c,l,u]),C=o.useCallback(()=>{p.current?.click()},[]),g=o.useCallback(()=>{if(!p.current)return;const N=p.current.files;if(!N){r();return}const S=Array.from(N).map(x=>le.from(b.v4(),x)),q=[...l,...S];c(q),r()},[r,c,l]),y=o.useCallback(N=>{const S=l.filter(({uuid:q})=>q!==N.uuid);c(S),r()},[l,c,r]);o.useEffect(()=>{if(!p.current)return;const N=new AbortController;return p.current.addEventListener("cancel",()=>{r()},{signal:N.signal}),()=>{N.abort()}},[r,l]);const F=e.maxFiles!==1,M=F?"Select files":"Select a file";return i.jsxs(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:[i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{className:"w-max",size:n,variant:"surface",accentColor:"base",type:"button",disabled:h,children:[i.jsx(a.LuIcon,{icon:ni}),M]})}),i.jsxs(a.Menu.Content,{size:n,children:[i.jsxs(a.Menu.Item,{onSelect:m,children:[i.jsx(a.LuIcon,{icon:tl}),"Take photos"]}),i.jsxs(a.Menu.Item,{onSelect:C,children:[i.jsx(a.LuIcon,{icon:ul}),"Attach files"]})]})]}),i.jsx("input",{id:e.id,name:s,type:"file",ref:p,accept:e.extensions?.join(","),multiple:F,className:"hidden",onChange:g,value:""}),l.length>0&&i.jsx("div",{className:"mt-1 flex h-max flex-col gap-2",children:l.map(N=>i.jsx(fi,{size:n,fileOrPromise:N,onRemove:y,disabled:h},N.uuid))})]})});Hl.displayName="UploadFieldInput";class Fe extends I{type="upload";extensions;maxSize;maxFiles;constructor(e){const{extensions:n,maxFiles:l,maxSize:s,...r}=e;super(r),this.maxSize=s,this.maxFiles=l,this.extensions=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:0,id:`${n}maxFiles`,integers:!0}),showDirectly:!1},{field:new G({label:"What is the maximum size of each file?",description:"Maximum file size in MB.",required:!1,id:`${n}maxSize`,minimum:0,integers:!0}),showDirectly:!1},{field:new te({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,id:`${n}extensions`,options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.maxSize,l=n&&n*1e3*1e3,s=this.maxFiles;return typeof n=="number"&&typeof l=="number"&&e.push(r=>{if(r.some(c=>c instanceof le&&c.size>l))return`Files must be at most ${n}MB.`}),typeof s=="number"&&e.push(r=>{if(r.length>s)return`You can only upload ${s} files.`}),e}serialize(){return{...super.serialize(),extensions:this.extensions,maxSize:this.maxSize,maxFiles:this.maxFiles}}config(){return{...super.config(),extensions:this.extensions,maxSize:this.maxSize,maxFiles:this.maxFiles}}getOptions(){return{...super.getOptions(),extensions:this.extensions,maxSize:this.maxSize,maxFiles:this.maxFiles}}duplicate(e){return new Fe({...this.getOptions(),id:e})}setOptions(e){"maxSize"in e&&(this.maxSize=e.maxSize),"maxFiles"in e&&(this.maxFiles=e.maxFiles),"extensions"in e&&(this.extensions=e.extensions),super.setOptions(e)}static deserialize(e){return new Fe(e)}static fromConfig(e){return new Fe(e)}static deserializeConfig(e){const{extensions:n,maxSize:l,maxFiles:s,...r}=e;return{...I._deserializeConfig(r),extensions:n,maxSize:l,maxFiles:s}}static serializeConfig(e){const{extensions:n,maxSize:l,maxFiles:s,...r}=e;return{...I._serializeConfig(r),extensions:n,maxSize:l,maxFiles:s}}serializeValue(e){return[]}deserializeValue(e){return[]}render(){return i.jsx(Hl,{field:this})}isSerializedValue(e){return Array.isArray(e)&&e.length===0}isValue(e){return Array.isArray(e)?e.every(n=>n instanceof xe||n instanceof le):!1}areValuesEqual(e,n){return Qe(e,n)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){return e.length===n.length}}const Wl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(g=>{const y=g.target.value;y!==""&&!URL.canParse(y)||c(y!==""?new URL(y):null)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(g=>{g.key==="Enter"&&g.preventDefault()},[]),C=o.useCallback(()=>{l!==null&&window.open(l,"_blank","noopener,noreferrer")},[l]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs("div",{className:"flex w-full gap-2",children:[i.jsx(a.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{id:e.id,className:"truncate",name:s,value:l?l.toString():"",type:"url",inputMode:"url",placeholder:e.placeholder??"https://example.com",onChange:u,onBlur:p,disabled:h,onKeyDown:m})}),i.jsx(a.IconButton,{size:n,variant:"soft",accentColor:"base",type:"button",disabled:l===null,onClick:C,children:i.jsx(a.LuIcon,{icon:Vs})})]})})});Wl.displayName="URLFieldInput";class qe extends I{type="url";placeholder;constructor(e){const{placeholder:n,...l}=e;super(l),this.placeholder=n}serialize(){return{...super.serialize(),placeholder:this.placeholder}}config(){return{...super.config(),placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),placeholder:this.placeholder}}duplicate(e){return new qe({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new qe(e)}static fromConfig(e){return new qe(e)}static deserializeConfig(e){const{placeholder:n,...l}=e;return{...I._deserializeConfig(l),placeholder:n}}static serializeConfig(e){const{placeholder:n,...l}=e;return{...I._serializeConfig(l),placeholder:n}}serializeValue(e){return e?.toString()??null}deserializeValue(e){return e===null?null:new URL(e)}isSerializedValue(e){return e===null?!0:typeof e!="string"?!1:URL.canParse(e)}isValue(e){return e===null||e instanceof URL}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e?.toString()===n?.toString()}render(){return i.jsx(Wl,{field:this})}}const Ee={date:Ne,time:Me,number:G,boolean:de,select:ge,string:me,url:qe,text:Ce,upload:Fe,qr:Ie,"multi-string":re,"multi-select":te,radio:fe,"checkbox-list":ie,"pass-fail":he,otp:ce,rating:pe},Kl=Object.keys(Ee),L={"checkbox-list":{description:"Allows the user to select a multiple options from a list.",group:O.Selection,icon:Fs,name:"Checkbox list"},"multi-select":{description:"Allows the user to select a multiple options from a list of options.",group:O.Selection,icon:Ns,name:"Multi-select"},"multi-string":{description:"Allows the user to provide multiple unique strings.",group:O.Text,icon:Is,name:"Multi-string"},"pass-fail":{description:"Track pass, fail, or N/A outcome.",group:O.Assessment,icon:vs,name:"Pass - Fail"},boolean:{description:"Perfect for both optional and required yes/no questions.",group:O.Selection,icon:Es,name:"Checkbox"},date:{description:"Allows specifying a date.",group:O.Temporal,icon:ps,name:"Date"},time:{description:"Allows specifying a time and UTC offset.",group:O.Temporal,icon:Bs,name:"Time"},number:{description:"Allows specifying a number within a given range.",group:O.Numeric,icon:bs,name:"Number"},otp:{description:"Allows specifying a number within a given range.",group:O.Verification,icon:qs,name:"OTP"},qr:{description:"Used for scanning/reading QR and barcodes.",group:O.Capture,icon:Os,name:"Scan"},radio:{description:"Allows the user to select a single option from a list of options.",group:O.Selection,icon:ms,name:"Option list"},rating:{description:"Allows users to select a rating value.",group:O.Assessment,icon:hl,name:"Rating"},select:{description:"Allows the user to select a single option from a list of options.",group:O.Selection,icon:xs,name:"Dropdown"},string:{description:"Short text fields can hold up to 500 characters on a single line.",group:O.Text,icon:As,name:"Short Text"},text:{description:"Paragraph fields can hold up to 10000 characters and can have multiple lines.",group:O.Text,icon:us,name:"Paragraph"},upload:{description:"Allows a file to be uploaded.",group:O.Capture,icon:ni,name:"Upload"},url:{description:"Allows users to enter a URL.",group:O.Text,icon:zs,name:"URL"}},Zl={[O.Assessment]:{name:"Assessment"},[O.Capture]:{name:"Capture"},[O.Numeric]:{name:"Numeric"},[O.Selection]:{name:"Selection"},[O.Temporal]:{name:"Temporal"},[O.Text]:{name:"Text"},[O.Verification]:{name:"Verification"}},P="Unlabelled",an="Unlabelled";class vi extends _e{id;constructor(e){const{id:n}=e;super(),this.id=n}serialize(){return{id:this.id,type:this.type}}}class v extends vi{value;field;constructor(e){const{field:n,value:l,...s}=e;super(s),this.value=l,this.field=n}serialize(){return{...super.serialize(),value:this.serializeValue(),modifier:this.modifier,field:this.field.id}}getValue=()=>this.value;setValue=e=>{this.value=e,this.notify(this)};getApplyFn(){const e=this.getValueApplyFn();return n=>{const l=this.accessorFn(n);return this.isApplicable(l)?e(l):!1}}isApplicable=e=>this.field.isValue(e);accessorFn=e=>e[this.field.id]}class sn extends v{type="boolean";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class Fi extends v{type="boolean";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}const rn={equals:{klass:sn,label:"is",isTransferable:t=>!0,defaultValue:()=>!0},notEquals:{klass:Fi,label:"is not",isTransferable:t=>!0,defaultValue:()=>!0}};class on extends v{type="checkbox-list";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size===s.size&&s.isSubsetOf(l)}}}class Vi extends v{type="checkbox-list";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size!==s.size||!s.isSubsetOf(l)}}}class wi extends v{type="checkbox-list";modifier="every";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isSubsetOf(s)}}}class Si extends v{type="checkbox-list";modifier="some";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return!l.isDisjointFrom(s)}}}class bi extends v{type="checkbox-list";modifier="none";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isDisjointFrom(s)}}}const dn={equals:{klass:on,label:"is",isTransferable:t=>!0,defaultValue:()=>[]},notEquals:{klass:Vi,label:"is not",isTransferable:t=>!0,defaultValue:()=>[]},every:{klass:wi,label:"has all of",isTransferable:t=>!0,defaultValue:()=>[]},some:{klass:Si,label:"has any of",isTransferable:t=>!0,defaultValue:()=>[]},none:{klass:bi,label:"has none of",isTransferable:t=>!0,defaultValue:()=>[]}};class Pe extends vi{type="compound";conditions;constructor(e){const{conditions:n,...l}=e;super(l),this.conditions=this.initConditions(n)}conditionObserver=()=>{this.conditions=[...this.conditions],this.notify(this)};initConditions=e=>{for(const n of e)n.observe(this.conditionObserver);return e};serialize(){return{...super.serialize(),operator:this.operator,conditions:this.conditions.map(e=>e.serialize())}}isEmpty(){return this.conditions.length===0?!0:this.conditions.every(e=>e.type==="compound"&&e.isEmpty())}addCondition(e){this.conditions=this.initConditions([...this.conditions,e]),this.notify(this)}addConditions(e){this.conditions=this.initConditions([...this.conditions,...e]),this.notify(this)}replaceCondition(e,n){this.conditions=this.initConditions(this.conditions.map(l=>l.id===e.id?n:l)),this.notify(this)}removeCondition(e){this.conditions=this.initConditions(this.conditions.filter(n=>n.id!==e.id)),this.notify(this)}}class $e extends Pe{operator="and";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:e.every(s=>s(l))}}class zi extends Pe{operator="or";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:e.some(s=>s(l))}}class Ni extends Pe{operator="nand";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:!e.every(s=>s(l))}}class xi extends Pe{operator="nor";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:!e.some(s=>s(l))}}const ke={and:{label:"AND",blurb:"All conditions match",klass:$e},or:{label:"OR",blurb:"At least one condition matches",klass:zi},nand:{label:"NAND",blurb:"At least one condition does not match",klass:Ni},nor:{label:"NOR",blurb:"No conditions match",klass:xi}};class cn extends v{type="date";modifier="equals";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()===e.getTime()}}class Ii extends v{type="date";modifier="notEquals";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()!==e.getTime()}}class Mi extends v{type="date";modifier="before";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()<e.getTime()}}class qi extends v{type="date";modifier="after";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()>e.getTime()}}class Oi extends v{type="date";modifier="in";serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getValueApplyFn(){const e=this.value;return n=>!(n===null||e.from&&e.from.getTime()>n.getTime()||e.to&&e.to.getTime()<n.getTime())}}class Ti extends v{type="date";modifier="notIn";serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getValueApplyFn(){const e=this.value;return n=>n===null?!1:!!(e.from&&e.from.getTime()>n.getTime()||e.to&&e.to.getTime()<n.getTime())}}const un={equals:{klass:cn,label:"is",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},notEquals:{klass:Ii,label:"is not",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},before:{klass:Mi,label:"before",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},after:{klass:qi,label:"after",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},in:{klass:Oi,label:"in between",isTransferable:t=>!(t instanceof Date),defaultValue:()=>({from:void 0,to:void 0})},notIn:{klass:Ti,label:"not in between",isTransferable:t=>!(t instanceof Date),defaultValue:()=>({from:void 0,to:void 0})}};class hn extends v{type="multi-select";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size===s.size&&s.isSubsetOf(l)}}}class Ei extends v{type="multi-select";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size!==s.size||!s.isSubsetOf(l)}}}class Li extends v{type="multi-select";modifier="every";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isSubsetOf(s)}}}class Ai extends v{type="multi-select";modifier="some";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return!l.isDisjointFrom(s)}}}class Bi extends v{type="multi-select";modifier="none";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isDisjointFrom(s)}}}const fn={equals:{klass:hn,label:"is",isTransferable:t=>!0,defaultValue:()=>[]},notEquals:{klass:Ei,label:"is not",isTransferable:t=>!0,defaultValue:()=>[]},every:{klass:Li,label:"has all of",isTransferable:t=>!0,defaultValue:()=>[]},some:{klass:Ai,label:"has any of",isTransferable:t=>!0,defaultValue:()=>[]},none:{klass:Bi,label:"has none of",isTransferable:t=>!0,defaultValue:()=>[]}};class pn extends v{type="multi-string";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size===s.size&&s.isSubsetOf(l)}}}class _i extends v{type="multi-string";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size!==s.size||!s.isSubsetOf(l)}}}class Di extends v{type="multi-string";modifier="every";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isSubsetOf(s)}}}class Pi extends v{type="multi-string";modifier="some";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return!l.isDisjointFrom(s)}}}class $i extends v{type="multi-string";modifier="none";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isDisjointFrom(s)}}}const gn={equals:{klass:pn,label:"is",isTransferable:t=>!0,defaultValue:()=>[]},notEquals:{klass:_i,label:"is not",isTransferable:t=>!0,defaultValue:()=>[]},every:{klass:Di,label:"has all of",isTransferable:t=>!0,defaultValue:()=>[]},some:{klass:Pi,label:"has any of",isTransferable:t=>!0,defaultValue:()=>[]},none:{klass:$i,label:"has none of",isTransferable:t=>!0,defaultValue:()=>[]}};class mn extends v{type="number";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class ki extends v{type="number";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class ji extends v{type="number";modifier="lessThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<e}}class Ui extends v{type="number";modifier="lessThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<=e}}class Gi extends v{type="number";modifier="greaterThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>e}}class Ji extends v{type="number";modifier="greaterThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>=e}}class Hi extends v{type="number";modifier="inRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!(n===null||e.to!==null&&n>e.to||e.from!==null&&n<e.from)}}class Wi extends v{type="number";modifier="notInRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.to!==null&&n>e.to||e.from!==null&&n<e.from}}const Cn={equals:{klass:mn,label:"is",isTransferable:t=>typeof t=="number",defaultValue:()=>0},notEquals:{klass:ki,label:"is not",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThan:{klass:ji,label:"is less than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThanOrEquals:{klass:Ui,label:"is less than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThan:{klass:Gi,label:"is greater than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:Ji,label:"is greater than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},inRange:{klass:Hi,label:"is between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:Wi,label:"is not between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})}};class yn extends v{type="otp";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class Ki extends v{type="otp";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class Zi extends v{type="otp";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class Xi extends v{type="otp";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const vn={equals:{klass:yn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:Ki,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Zi,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:Xi,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class Fn extends v{type="pass-fail";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:n.status===e}}class Yi extends v{type="pass-fail";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:n.status!==e}}class Qi extends v{type="pass-fail";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:e.includes(n.status)}}class Ri extends v{type="pass-fail";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:!e.includes(n.status)}}const Vn={equals:{klass:Fn,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>"pass"},notEquals:{klass:Yi,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>"pass"},includes:{klass:Qi,label:"is any of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]},excludes:{klass:Ri,label:"is none of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]}};class wn extends v{type="radio";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class et extends v{type="radio";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class nt extends v{type="radio";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.includes(n)}}class it extends v{type="radio";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:!e.includes(n)}}const Sn={equals:{klass:wn,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>""},notEquals:{klass:et,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>""},includes:{klass:nt,label:"is any of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]},excludes:{klass:it,label:"is none of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]}};class bn extends v{type="rating";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class tt extends v{type="rating";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class lt extends v{type="rating";modifier="lessThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<e}}class at extends v{type="rating";modifier="lessThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<=e}}class st extends v{type="rating";modifier="greaterThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>e}}class rt extends v{type="rating";modifier="greaterThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>=e}}class ot extends v{type="rating";modifier="inRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!(n===null||e.to!==null&&n>e.to||e.from!==null&&n<e.from)}}class dt extends v{type="rating";modifier="notInRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.to!==null&&n>e.to||e.from!==null&&n<e.from}}const zn={equals:{klass:bn,label:"is",isTransferable:t=>typeof t=="number",defaultValue:()=>0},notEquals:{klass:tt,label:"is not",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThan:{klass:lt,label:"is less than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThanOrEquals:{klass:at,label:"is less than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThan:{klass:st,label:"is greater than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:rt,label:"is greater than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},inRange:{klass:ot,label:"is between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:dt,label:"is not between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})}};class Nn extends v{type="qr";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class ct extends v{type="qr";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class ut extends v{type="qr";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class ht extends v{type="qr";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const xn={equals:{klass:Nn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:ct,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:ut,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:ht,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class In extends v{type="select";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class ft extends v{type="select";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class pt extends v{type="select";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.includes(n)}}class gt extends v{type="select";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:!e.includes(n)}}const Mn={equals:{klass:In,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>""},notEquals:{klass:ft,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>""},includes:{klass:pt,label:"is any of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]},excludes:{klass:gt,label:"is none of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]}};class qn extends v{type="string";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class mt extends v{type="string";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class Ct extends v{type="string";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class yt extends v{type="string";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const On={equals:{klass:qn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:mt,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Ct,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:yt,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class Tn extends v{type="text";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class vt extends v{type="text";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class Ft extends v{type="text";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class Vt extends v{type="text";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const En={equals:{klass:Tn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:vt,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Ft,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:Vt,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class Ln extends v{type="time";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?n===e:!1}}class wt extends v{type="time";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?n!==e:!1}}class St extends v{type="time";modifier="before";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?ve(n)<ve(e):!1}}class bt extends v{type="time";modifier="after";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?ve(n)>ve(e):!1}}class zt extends v{type="time";modifier="in";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?Ci(n,e):!1}}class Nt extends v{type="time";modifier="notIn";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?!Ci(n,e):!1}}const An={equals:{klass:Ln,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},notEquals:{klass:wt,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},before:{klass:St,label:"before",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},after:{klass:bt,label:"after",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},in:{klass:zt,label:"in between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})},notIn:{klass:Nt,label:"not in between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})}};class Bn extends v{type="upload";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){return e=>e.length>0}}class xt extends v{type="upload";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){return e=>e.length===0}}const _n={equals:{klass:Bn,label:"is",isTransferable:t=>!0,defaultValue:()=>!0},notEquals:{klass:xt,label:"is not",isTransferable:t=>!0,defaultValue:()=>!0}};class Dn extends v{type="url";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>(n?.toString()??"")===e}}class It extends v{type="url";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>(n?.toString()??"")!==e}}class Mt extends v{type="url";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>(n?.toString()??"").includes(e)}}class qt extends v{type="url";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!(n?.toString()??"").includes(e)}}const Pn={equals:{klass:Dn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:It,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Mt,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:qt,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}},Gs={date:{equals:(t,e)=>new cn({...t,field:e,value:new Date(t.value)}),notEquals:(t,e)=>new Ii({...t,field:e,value:new Date(t.value)}),before:(t,e)=>new Mi({...t,field:e,value:new Date(t.value)}),after:(t,e)=>new qi({...t,field:e,value:new Date(t.value)}),in:(t,e)=>new Oi({...t,field:e,value:{from:t.value.from?new Date(t.value.from):void 0,to:t.value.to?new Date(t.value.to):void 0}}),notIn:(t,e)=>new Ti({...t,field:e,value:{from:t.value.from?new Date(t.value.from):void 0,to:t.value.to?new Date(t.value.to):void 0}})},boolean:{equals:(t,e)=>new sn({...t,field:e}),notEquals:(t,e)=>new Fi({...t,field:e})},"checkbox-list":{equals:(t,e)=>new on({...t,field:e}),notEquals:(t,e)=>new Vi({...t,field:e}),every:(t,e)=>new wi({...t,field:e}),none:(t,e)=>new bi({...t,field:e}),some:(t,e)=>new Si({...t,field:e})},"multi-select":{equals:(t,e)=>new hn({...t,field:e}),notEquals:(t,e)=>new Ei({...t,field:e}),every:(t,e)=>new Li({...t,field:e}),none:(t,e)=>new Bi({...t,field:e}),some:(t,e)=>new Ai({...t,field:e})},"multi-string":{equals:(t,e)=>new pn({...t,field:e}),notEquals:(t,e)=>new _i({...t,field:e}),every:(t,e)=>new Di({...t,field:e}),none:(t,e)=>new $i({...t,field:e}),some:(t,e)=>new Pi({...t,field:e})},number:{equals:(t,e)=>new mn({...t,field:e}),notEquals:(t,e)=>new ki({...t,field:e}),greaterThan:(t,e)=>new Gi({...t,field:e}),greaterThanOrEquals:(t,e)=>new Ji({...t,field:e}),inRange:(t,e)=>new Hi({...t,field:e}),lessThan:(t,e)=>new ji({...t,field:e}),lessThanOrEquals:(t,e)=>new Ui({...t,field:e}),notInRange:(t,e)=>new Wi({...t,field:e})},otp:{equals:(t,e)=>new yn({...t,field:e}),notEquals:(t,e)=>new Ki({...t,field:e}),excludes:(t,e)=>new Xi({...t,field:e}),includes:(t,e)=>new Zi({...t,field:e})},"pass-fail":{equals:(t,e)=>new Fn({...t,field:e}),notEquals:(t,e)=>new Yi({...t,field:e}),excludes:(t,e)=>new Ri({...t,field:e}),includes:(t,e)=>new Qi({...t,field:e})},radio:{equals:(t,e)=>new wn({...t,field:e}),notEquals:(t,e)=>new et({...t,field:e}),excludes:(t,e)=>new it({...t,field:e}),includes:(t,e)=>new nt({...t,field:e})},rating:{equals:(t,e)=>new bn({...t,field:e}),notEquals:(t,e)=>new tt({...t,field:e}),greaterThan:(t,e)=>new st({...t,field:e}),greaterThanOrEquals:(t,e)=>new rt({...t,field:e}),inRange:(t,e)=>new ot({...t,field:e}),lessThan:(t,e)=>new lt({...t,field:e}),lessThanOrEquals:(t,e)=>new at({...t,field:e}),notInRange:(t,e)=>new dt({...t,field:e})},qr:{equals:(t,e)=>new Nn({...t,field:e}),notEquals:(t,e)=>new ct({...t,field:e}),excludes:(t,e)=>new ht({...t,field:e}),includes:(t,e)=>new ut({...t,field:e})},select:{equals:(t,e)=>new In({...t,field:e}),notEquals:(t,e)=>new ft({...t,field:e}),excludes:(t,e)=>new gt({...t,field:e}),includes:(t,e)=>new pt({...t,field:e})},string:{equals:(t,e)=>new qn({...t,field:e}),notEquals:(t,e)=>new mt({...t,field:e}),excludes:(t,e)=>new yt({...t,field:e}),includes:(t,e)=>new Ct({...t,field:e})},text:{equals:(t,e)=>new Tn({...t,field:e}),notEquals:(t,e)=>new vt({...t,field:e}),excludes:(t,e)=>new Vt({...t,field:e}),includes:(t,e)=>new Ft({...t,field:e})},time:{equals:(t,e)=>new Ln({...t,field:e}),notEquals:(t,e)=>new wt({...t,field:e}),after:(t,e)=>new bt({...t,field:e}),before:(t,e)=>new St({...t,field:e}),in:(t,e)=>new zt({...t,field:e}),notIn:(t,e)=>new Nt({...t,field:e})},url:{equals:(t,e)=>new Dn({...t,field:e}),notEquals:(t,e)=>new It({...t,field:e}),excludes:(t,e)=>new qt({...t,field:e}),includes:(t,e)=>new Mt({...t,field:e})},upload:{equals:(t,e)=>new Bn({...t,field:e}),notEquals:(t,e)=>new xt({...t,field:e})}},Js={and:(t,e)=>new $e({...t,conditions:e}),nand:(t,e)=>new Ni({...t,conditions:e}),nor:(t,e)=>new xi({...t,conditions:e}),or:(t,e)=>new zi({...t,conditions:e})},$n=(t,e)=>t.every(n=>n.getApplyFn()(e)),Ot=(t,e)=>{if(!Un(t,e))return null;if(e.type==="compound"){const n=je(t,e.conditions);return Js[e.operator](e,n)}else{const n=t.find(l=>l.id===e.field);return Gs[e.type][e.modifier](e,n)}},je=(t,e)=>e.map(n=>Ot(t,n)).filter(n=>!!n),Tt=(t,e)=>kn(t,e)?e.serialize():null,Et=(t,e)=>e.map(n=>Tt(t,n)).filter(n=>!!n),kn=(t,e)=>e.type==="compound"?(e.conditions=jn(t,e.conditions),e):new Set(t.map(l=>l.id)).has(e.field.id)?e:null,jn=(t,e)=>e.map(n=>kn(t,n)).filter(n=>!!n),Un=(t,e)=>e.type==="compound"?{...e,conditions:Lt(t,e.conditions)}:new Set(t.map(l=>l.id)).has(e.field)?e:null,Lt=(t,e)=>e.map(n=>Un(t,n)).filter(n=>!!n);class Xl extends _e{conditions;constructor(e){super(),this.conditions=this.initConditions(e)}conditionObserver=()=>{this.conditions=[...this.conditions],this.notify(this)};initConditions=e=>{for(const n of e)n.observe(this.conditionObserver);return e};getConditions(){return this.conditions}setConditions(e){this.conditions=this.initConditions(e),this.notify(this)}addCondition(e){this.conditions=this.initConditions([...this.conditions,e]),this.notify(this)}addConditions(e){this.conditions=this.initConditions([...this.conditions,...e]),this.notify(this)}replaceCondition(e,n){this.conditions=this.initConditions(this.conditions.map(l=>l.id===e.id?n:l)),this.notify(this)}removeCondition(e){this.conditions=this.initConditions(this.conditions.filter(n=>n.id!==e.id)),this.notify(this)}removeConditions(e){const n=new Set(e.map(l=>l.id));this.conditions=this.initConditions(this.conditions.filter(l=>!n.has(l.id))),this.notify(this)}applyConditions(e){return $n(this.conditions,e)}}const Hs=(t,e)=>o.useMemo(()=>{const n=new Xl(t);return n.observe(l=>e(l.getConditions())),n},[t,e]),Gn=t=>Ee[t.type].deserialize(t);function Ws(t){return t.map(Gn)}function Yl(t){return t.type==="section"?W.deserialize(t):Gn(t)}const Jn=t=>t.map(Yl),At=t=>Ee[t.type].fromConfig(t),Ql=t=>t.map(e=>At(e)),Rl=t=>t.type==="section"?W.fromConfig(t):At(t),ea=t=>t.map(Rl),Bt=t=>Ee[t.type].deserializeConfig(t),na=t=>t.map(Bt),ia=t=>t.type==="section"?W.deserializeConfig(t):Bt(t),ta=t=>t.map(ia),_t=t=>Ee[t.type].serializeConfig(t),la=t=>t.map(_t),aa=t=>t.type==="section"?W.serializeConfig(t):_t(t),sa=t=>t.map(aa);function Ks(t){const e={};for(const n of t)e[n.id]=n;return e}function ra(t,e,n=!0){const l=n?Hn(t,e):e,s={};for(const r of t){if(!(r.id in l))continue;const c=l[r.id];s[r.id]=r.serializeValue(c)}return s}function oa(t,e,n=!0){const l=n?Dt(t,e):e,s={};for(const r of t){if(!(r.id in l))continue;const c=l[r.id];s[r.id]=r.deserializeValue(c)}return s}function Hn(t,e){const n={};for(const l of t){if(!(l.id in e))continue;const s=e[l.id];l.isValue(s)&&(n[l.id]=l.cleanValue(s))}return n}function Dt(t,e){const n={};for(const l of t){if(!(l.id in e))continue;const s=e[l.id];l.isSerializedValue(s)&&(n[l.id]=l.cleanSerializedValue(s))}return n}function da(t,e){const n=Hn(t,e),l={},s={};for(const r of t){if(!(r.id in n))continue;const c=n[r.id];switch(r.type){case"upload":if(!r.isValue(c))break;s[r.id]=c,l[r.id]=[];break;case"pass-fail":if(!r.isValue(c))break;s[r.id]=c.files,l[r.id]={...c,files:[]};break;default:l[r.id]=e[r.id]}}return[l,s]}function ca(t,e,n){const l={};for(const s of t){if(!(s.id in e))continue;const r=e[s.id];switch(s.type){case"upload":if(!s.isValue(r))break;l[s.id]=n[s.id]??[];break;case"pass-fail":if(!s.isValue(r))break;l[s.id]={...r,files:n[s.id]??[]};break;default:if(!s.isValue(r))break;l[s.id]=r}}return l}const ua=(t,e)=>{const n={};for(const l of t){const s=e[l.id];n[l.id]=s!==void 0?s:l.blankValue()}return n},ha=(t,e,n)=>{const l={};for(const s of t){if(!(s.id in e)&&!(s.id in n))continue;if(!(s.id in e)){l[s.id]=n[s.id];continue}if(!(s.id in n))continue;const r=e[s.id],c=n[s.id];s.areValuesEqual(r,c)||(l[s.id]=c)}return l},fa=(t,e,n)=>{const l={};for(const s of t){if(!(s.id in e)&&!(s.id in n)||!(s.id in e)||!(s.id in n))continue;const r=e[s.id],c=n[s.id];s.areValuesEqual(r,c)&&(l[s.id]=c)}return l},Pt=(t,e,n)=>t.every(l=>{if(!(l.id in e)&&!(l.id in n))return!0;if(!(l.id in e)||!(l.id in n))return!1;const s=e[l.id],r=n[l.id];return l.areValuesEqual(s,r)}),$t=t=>{const e={};for(const n of t)e[n.id]=n.blankValue();return e},pa=(t,e)=>Pt(t,e,$t(t)),Zs=Y.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),Wn=Y.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),ga=o.memo(t=>{const{fieldSection:e}=t,{label:n,description:l}=e,s=Q.useWatch(),{fieldSchema:r,size:c}=o.use(B),f=o.useMemo(()=>r.getFieldSections(),[r]),h=o.useMemo(()=>f.findIndex(({id:C})=>C===e.id),[f,e.id]),u=o.useMemo(()=>f.filter(C=>e.id in C.conditions),[f,e.id]),p=o.useMemo(()=>u.length===0?!0:u.some(C=>{const g=C.getConditions(e.id);return $n(g,s)}),[u,e,s]),m=Ye(e.fields);return p?i.jsxs(i.Fragment,{children:[h!==0?i.jsx(a.Separator,{size:"full"}):null,i.jsxs("div",{className:"flex flex-col gap-4",children:[(n||l)&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx(a.Heading,{size:c,children:n}),l&&i.jsx(a.Text,{accentColor:"base",size:c,children:l})]})}),i.jsx("div",{className:Wn({size:c}),children:m})]})]}):null});ga.displayName="FieldSectionLayout";class W extends Se{type="section";label;description;conditions;fields=[];constructor(e){const{label:n,description:l,fields:s,conditions:r={},...c}=e;super(c),this.label=n,this.description=l,this.fields=this.initFields(s),this.conditions=this.initConditions(r)}serialize(){return{...super.serialize(),label:this.label,description:this.description,fields:this.fields.map(e=>e.serialize()),conditions:this.serializeConditions()}}static deserialize=e=>{const n=e.fields.map(Gn),l={};for(const[s,r]of Object.entries(e.conditions??{}))l[s]=je(n,r);return new W({...e,fields:n,conditions:l})};static fromConfig=e=>{const n=Ql(e.fields),l={};for(const[s,r]of Object.entries(e.conditions??{}))l[s]=je(n,r);return new W({...e,fields:n,conditions:l})};static deserializeConfig(e){const{label:n,description:l,fields:s,conditions:r,...c}=e;return{...Se._deserializeConfig(c),label:n,description:l,fields:na(s),conditions:r}}static serializeConfig(e){const{label:n,description:l,fields:s,conditions:r,...c}=e;return{...Se._serializeConfig(c),label:n,description:l,fields:la(s),conditions:r}}serializeConditions(){const e={};for(const[n,l]of Object.entries(this.conditions??{}))e[n]=Et(this.fields,l);return e}config(){return{...super.config(),label:this.label,description:this.description,fields:this.fields.map(e=>e.config()),conditions:this.serializeConditions()}}getOptions(){return{...super.getOptions(),label:this.label,description:this.description,fields:this.fields,conditions:this.conditions}}duplicate(e){return new W({...this.getOptions(),id:e,fields:this.fields.map(n=>n.duplicate(b.v4()))})}setOptions(e){"label"in e&&(this.label=e.label),"description"in e&&(this.description=e.description),"fields"in e&&e.fields!==void 0&&(this.fields=this.initFields(e.fields)),"conditions"in e&&(this.conditions=this.initConditions(e.conditions??{})),super.setOptions(e)}getErrors(e){const n={};for(const l of this.fields){const s=l.getError(e[l.id]);s&&(n[l.id]=s)}return n}fieldObserver=()=>{this.notify(this)};initFields=e=>{for(const n of e)n.observe(this.fieldObserver);return e};getFields(){return this.fields}addField(e,n){const l=[...this.fields];l.splice(n??this.fields.length,0,e),this.fields=this.initFields(l),this.notify(this)}moveField(e,n){if(!Number.isInteger(e)||!Number.isInteger(n)||e<0||e>=this.fields.length||n<0||n>=this.fields.length||e===n)return;const l=[...this.fields],[s]=l.splice(e,1);l.splice(n,0,s),this.fields=l,this.notify(this)}removeField(e){this.fields=this.initFields(this.fields.filter(({id:l})=>l!==e.id));const n={};for(const[l,s]of Object.entries(this.conditions))n[l]=jn(this.fields,s);this.conditions=n,this.notify(this)}conditionObserver=()=>{this.notify(this)};initConditions=e=>{for(const n of Object.values(e).flat())n.observe(this.conditionObserver);return e};getConditions(e){return this.conditions[e]}addCondition(e,n){this.conditions=this.initConditions({...this.conditions,[e]:[...this.conditions[e]??[],n]}),this.notify(this)}addConditions(e,n){this.conditions=this.initConditions({...this.conditions,[e]:[...this.conditions[e]??[],...n]}),this.notify(this)}replaceCondition(e,n,l){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).map(s=>s.id===n.id?l:s)}),this.notify(this)}removeCondition(e,n){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(l=>l.id!==n.id)}),this.notify(this)}removeConditions(e,n){const l=new Set(n.map(s=>s.id));this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(s=>!l.has(s.id))}),this.notify(this)}getConditionals(){return new Set(Object.keys(this.conditions))}addConditional(e){this.conditions=this.initConditions({...this.conditions,[e]:[]}),this.notify(this)}removeConditional(e){const n={...this.conditions};delete n[e],this.conditions=this.initConditions(n),this.notify(this)}render(){return i.jsx(ga,{fieldSection:this})}}const ae=o.createContext({}),j=(t,e,n)=>o.useCallback(l=>{const{klass:s,isTransferable:r,defaultValue:c}=e[l],f=t.getValue(),h=new s({id:t.id,value:r(f)?f:c(),field:t.field});n(t,h)},[t,e,n]),ma=o.memo,Ve=ma(function(t){const{ref:e,children:n,...l}=t,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.SelectedIndicator,{className:"ml-[auto]",children:i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.SelectedIndicator,{className:"ml-[auto]",children:i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.SelectItem,{ref:e,...l,children:s})}),Ca=ma(function(t){const{ref:e,children:n,...l}=t,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.SelectedIndicator,{className:"ml-auto",children:i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.SelectedIndicator,{className:"ml-auto",children:i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.MultiSelectItem,{ref:e,...l,children:s})}),kt=o.memo(t=>{const{ref:e,children:n,...l}=t,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:c=>c==="indeterminate"?i.jsx(a.LuIcon,{icon:Ke}):i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:c=>c==="indeterminate"?i.jsx(a.LuIcon,{icon:Ke}):i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.SelectAllItem,{ref:e,...l,children:s})});kt.displayName="SelectAllItemTemplate";const jt=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,align:f,accentColor:h="base",...u}=t;return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,align:f,children:i.jsx(a.DayPicker,{size:c,accentColor:h,...u})})]})});jt.displayName="DayPickerPopover";const ya=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,accentColor:f="base",values:h,onValuesChange:u,placeholder:p="Enter text",...m}=t,[C,g]=o.useState(""),y=o.useCallback(M=>{g(M.target.value)},[]),F=o.useCallback(M=>{M.key==="Enter"&&(M.preventDefault(),M.stopPropagation(),u([...h,C]),g(""))},[C,u,h]),V=o.useCallback(()=>{u([...h,C]),g("")},[C,u,h]),w=o.useCallback(M=>{const N=[...h];N.splice(M,1),u(N)},[u,h]);return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,accentColor:f,...m,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx(a.Input.Root,{className:"grow",accentColor:"base",variant:"outline",size:"sm",children:i.jsx(a.Input.Field,{value:C,onChange:y,onKeyDown:F,placeholder:p,...m})}),i.jsx(a.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button",onClick:V,children:i.jsx(a.LuIcon,{icon:K})})]}),h.length>0&&i.jsx("div",{className:"flex flex-col gap-1",children:h.map((M,N)=>i.jsxs(a.Badge,{className:"flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[i.jsx("span",{className:"truncate",children:M}),i.jsx(a.IconButton,{size:"xs",variant:"ghost",type:"button",accentColor:"base",onClick:()=>{w(N)},children:i.jsx(a.LuIcon,{icon:R})})]},`${M}-${N}`))})]})})]})});ya.displayName="NumberInputPopover";const Oe=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter a number",...m}=t,[C,g]=o.useState(null);o.useEffect(()=>{h!==void 0&&g(h)},[h]);const y=o.useCallback(V=>{const w=V.target.valueAsNumber;g(isNaN(w)?null:w)},[]),F=o.useCallback(V=>{const w=V.target.valueAsNumber;u?.(isNaN(w)?null:w)},[u]);return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,...m,children:i.jsx(a.Input.Root,{size:c,accentColor:f,children:i.jsx(a.Input.Field,{placeholder:p,type:"number",value:C??"",onChange:y,onBlur:F})})})]})});Oe.displayName="NumberInputPopover";const k=t=>{const{condition:e,onClick:n,...l}=t,s=o.useCallback(()=>{n(e)},[e,n]);return i.jsx(a.IconButton,{onClick:s,...l,children:i.jsx(a.LuIcon,{icon:R})})};k.displayName="RemoveConditionButton";const Ue=o.memo(t=>{const{ref:e,selectFieldOptions:n,...l}=t,s=o.useMemo(()=>oe(n),[n]);return i.jsxs(a.Menu.MultiSelectGroup,{ref:e,...l,children:[i.jsx(kt,{children:"Select all"}),s.map(r=>i.jsx(Ca,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))]})});Ue.displayName="SelectFieldOptionMultiSelectGroup";const Ut=o.memo(t=>{const{ref:e,selectFieldOptions:n,...l}=t,s=o.useMemo(()=>oe(n),[n]);return i.jsx(a.Menu.SelectGroup,{ref:e,...l,children:s.map(r=>i.jsx(Ve,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))})});Ut.displayName="SelectFieldOptionSelectGroup";const Le=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter text",...m}=t,[C,g]=o.useState(""),y=o.useCallback(V=>{g(V.target.value)},[]),F=o.useCallback(V=>{const w=V.target.value;u?.(w)},[u]);return o.useEffect(()=>{h&&g(h)},[h]),i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,...m,children:i.jsx(a.Input.Root,{size:c,accentColor:f,children:i.jsx(a.Input.Field,{placeholder:p,type:"text",value:C,onChange:y,onBlur:F})})})]})});Le.displayName="TextInputPopover";const Kn=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c="sm",accentColor:f="base",value:h,onValueChange:u,...p}=t;return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,accentColor:f,...p,children:i.jsx(ln,{compact:!0,size:c,value:h,onChange:u})})]})});Kn.displayName="TimeInputPopover";const U=t=>{const{children:e,required:n,value:l,defaultValue:s,onValueChange:r,modifierConfig:c,size:f="sm",variant:h,accentColor:u,radius:p}=t;return i.jsxs(a.Menu.Root,{align:"start",children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{size:f,variant:h,radius:p,accentColor:u,children:i.jsx(a.Menu.SelectGroup,{required:n,defaultValue:s,value:l,onValueChange:r,children:Object.keys(c).map(m=>{const{label:C}=c[m];return i.jsx(Ve,{value:m,children:C},m)})})})]})},va=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=e.getValue(),r=e.modifier,c=()=>{switch(s){case!0:return"true";case!1:return"false"}},f=j(e,rn,n);return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:r,onValueChange:f,modifierConfig:rn,children:i.jsx(a.Button,{type:"button",children:rn[r].label})}),i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:c()})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.SelectGroup,{required:!0,value:s,onValueChange:e.setValue,children:[i.jsx(Ve,{value:!0,children:"true"}),i.jsx(Ve,{value:!1,children:"false"})]})})]}),i.jsx(k,{condition:e,onClick:l})]})},Fa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,dn,n),r=()=>i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:dn,children:i.jsx(a.Button,{type:"button",children:dn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Zn=o.memo(t=>{const{children:e,variant:n,size:l,accentColor:s,onSelectFieldType:r,...c}=t,f=o.useMemo(()=>{const h={[O.Assessment]:[],[O.Capture]:[],[O.Numeric]:[],[O.Selection]:[],[O.Temporal]:[],[O.Text]:[],[O.Verification]:[]};for(const u of Kl){const{group:p}=L[u];h[p].push(u)}return h},[]);return i.jsxs(a.Menu.Root,{...c,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:l,accentColor:s,children:i.jsx(a.Menu.Scroll,{children:Object.entries(f).map(([h,u])=>{const{name:p}=Zl[h];return u.length===0?null:i.jsxs(a.Menu.Group,{children:[i.jsx(a.Menu.Label,{children:p}),u.map(m=>i.jsx(Va,{fieldType:m,onSelectFieldType:r},m))]},h)})})})]})});Zn.displayName="CreateFieldDropdownMenu";const Va=o.memo(t=>{const{fieldType:e,onSelectFieldType:n}=t,l=o.useCallback(()=>{n(e)},[e,n]),{icon:s,name:r}=L[e];return i.jsxs(a.Menu.Item,{onSelect:l,children:[i.jsx(a.LuIcon,{icon:s}),i.jsx(a.Text,{className:"truncate",children:r})]})});Va.displayName="CreateFieldDropdownMenuItem";const Xn=t=>{switch(t){case"text":return new Ce({label:"",required:!1,id:b.v4()});case"boolean":return new de({label:"",required:!1,id:b.v4()});case"number":return new G({label:"",required:!1,id:b.v4()});case"date":return new Ne({label:"",required:!1,id:b.v4()});case"time":return new Me({label:"",required:!1,id:b.v4()});case"string":return new me({label:"",required:!1,id:b.v4()});case"url":return new qe({label:"",required:!1,id:b.v4()});case"select":return new ge({label:"",options:[],required:!1,id:b.v4()});case"multi-string":return new re({label:"",required:!1,id:b.v4()});case"multi-select":return new te({label:"",options:[],required:!1,id:b.v4()});case"upload":return new Fe({label:"",required:!1,id:b.v4()});case"qr":return new Ie({label:"",required:!1,id:b.v4()});case"radio":return new fe({label:"",options:[],required:!1,id:b.v4()});case"checkbox-list":return new ie({label:"",options:[],required:!1,id:b.v4()});case"pass-fail":return new he({label:"",required:!1,id:b.v4(),showNotesAndFilesOn:["fail"]});case"otp":return new ce({label:"",required:!1,id:b.v4(),length:6});case"rating":return new pe({label:"",required:!1,id:b.v4(),maxRating:5})}},Ge=t=>{switch(t.type){case"text":return new Tn({id:b.v4(),value:"",field:t});case"boolean":return new sn({id:b.v4(),value:!0,field:t});case"number":return new mn({id:b.v4(),value:0,field:t});case"date":return new cn({id:b.v4(),value:new Date,field:t});case"time":return new Ln({id:b.v4(),value:ye(0,0),field:t});case"string":return new qn({id:b.v4(),value:"",field:t});case"url":return new Dn({id:b.v4(),value:"",field:t});case"select":return new In({id:b.v4(),value:"",field:t});case"multi-string":return new pn({id:b.v4(),value:[],field:t});case"multi-select":return new hn({id:b.v4(),value:[],field:t});case"upload":return new Bn({id:b.v4(),value:!0,field:t});case"qr":return new Nn({id:b.v4(),value:"",field:t});case"radio":return new wn({id:b.v4(),value:"",field:t});case"checkbox-list":return new on({id:b.v4(),value:[],field:t});case"pass-fail":return new Fn({id:b.v4(),value:"pass",field:t});case"otp":return new yn({id:b.v4(),value:"",field:t});case"rating":return new bn({id:b.v4(),value:0,field:t})}},wa=(t,e)=>{switch(t){case"checkbox-list":return ie.getFieldCreationSchema(e);case"multi-select":return te.getFieldCreationSchema(e);case"number":return G.getFieldCreationSchema(e);case"radio":return fe.getFieldCreationSchema(e);case"select":return ge.getFieldCreationSchema(e);case"string":return me.getFieldCreationSchema(e);case"text":return Ce.getFieldCreationSchema(e);case"upload":return Fe.getFieldCreationSchema(e);case"pass-fail":return he.getFieldCreationSchema(e);case"otp":return ce.getFieldCreationSchema(e);case"rating":return pe.getFieldCreationSchema(e);default:return}},Sa=o.memo(t=>{const{popoverInputs:e,...n}=t;return i.jsxs(a.Popover.Root,{children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:i.jsxs(a.Button,{variant:"soft",type:"button",size:"sm",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:Ts}),"Settings"]})}),i.jsx(a.Popover.Content,{size:"sm",...n,children:i.jsx("div",{className:Y.cx("flex w-full max-w-[350px] flex-col",Wn({size:"sm"})),children:e})})]})});Sa.displayName="FieldSettingsPopover";const ba=o.memo(t=>{const{parentPath:e,fieldIndex:n,field:l}=t,s=Xe(),{disableRequiredFields:r}=o.use(ae),[c,f]=o.useState(void 0);He.useActiveEffect(S=>{f(void 0);const q=l.image;if(q){if(!(q instanceof Promise)){f(q);return}q.then(x=>{S()&&f(x)})}},[l.image]);const h=o.useCallback(()=>{l.setOptions({image:void 0})},[l]),[u,p]=o.useMemo(()=>{const S=[],q=[],x=wa(l.type,`${e}.${n}`)??[];for(const T of x)T.showDirectly?S.push(T.field):q.push(T.field);return[S,q]},[l,e,n]),m=Ye(u),C=Ye(p),g=p.length>0,y=o.useCallback(()=>{c&&s(()=>({file:c}))},[s,c]),F=o.useCallback(S=>{l.setOptions({required:!!S})},[l]),V=o.useCallback(S=>{l.setOptions({label:S.target.value})},[l]),w=o.useCallback(S=>{l.setOptions({description:S.target.value})},[l]),{icon:M,name:N}=L[l.type];return i.jsxs("div",{className:"flex w-full grow flex-col gap-4",children:[i.jsxs("div",{className:"flex w-full justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(a.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:M}),N]}),!r&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Checkbox.Root,{checked:l.required,onCheckedChange:F,size:"sm",children:i.jsx(a.Checkbox.Indicator,{children:i.jsx(a.LuIcon,{icon:H})})}),i.jsx(a.Text,{size:"sm",accentColor:"base",children:"Required"})]})]}),g&&i.jsx(Sa,{popoverInputs:C,align:"end"})]}),c&&i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx(be,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:c,onClick:y}),i.jsx(a.IconButton,{type:"button",className:"group-hover:not-disabled:flex absolute right-2 top-2 hidden",variant:"solid",accentColor:"base","aria-label":"delete",onClick:h,size:"sm",children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(a.Input.Root,{variant:"outline",size:"md",children:i.jsx(a.Input.Field,{placeholder:"Enter your question",value:l.label??"",onChange:V,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a field description (optional)",value:l.description??"",onChange:w,maxLength:1e3,resize:"vertical",size:"md"})]}),u.length>0&&i.jsx("div",{className:Y.cx("w-full",Wn({size:"sm"})),children:m})]})});ba.displayName="FieldBuilder";const Gt=o.memo(t=>{const{field:e,fieldSection:n,fieldIndex:l,sectionIndex:s}=t,r=o.useRef(null),c=`fields.${s}.fields`,f=o.useCallback(F=>{n.addField(Xn(F),l+1)},[l,n]),h=o.useCallback(()=>{n.addField(e.duplicate(b.v4()))},[e,n]),u=o.useCallback(F=>{const V=F==="up"?l-1:l+1;n.moveField(l,V)},[n,l]),p=o.useCallback(F=>{const{files:V}=F.target;if(!V||V.length!==1)return;const w=V.item(0);w&&e.setOptions({image:w})},[e]),m=o.useCallback(()=>{u("up")},[u]),C=o.useCallback(()=>{u("down")},[u]),g=o.useCallback(()=>{r.current?.click()},[]),y=o.useCallback(()=>{n.removeField(e)},[e,n]);return i.jsxs(a.Card,{className:"flex w-full items-center justify-between gap-4",size:"sm",children:[i.jsx(ba,{fieldIndex:l,field:e,parentPath:c}),i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(Zn,{onSelectFieldType:f,size:"sm",children:i.jsx(a.IconButton,{type:"button",children:i.jsx(a.LuIcon,{icon:K})})}),i.jsx(a.IconButton,{type:"button",onClick:m,disabled:l===0,"aria-label":"Move field up",children:i.jsx(a.LuIcon,{icon:Ze})}),i.jsx(a.IconButton,{type:"button",onClick:C,disabled:l===n.fields.length-1,"aria-label":"Move field down",children:i.jsx(a.LuIcon,{icon:cl})}),i.jsx(a.IconButton,{type:"button",onClick:h,children:i.jsx(a.LuIcon,{icon:Rn})}),i.jsx(a.IconButton,{type:"button",onClick:g,children:i.jsx(a.LuIcon,{icon:ol})}),i.jsx(a.IconButton,{type:"button",onClick:y,children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsx("input",{className:"hidden",ref:r,type:"file",accept:"image/*",onChange:p})]})});Gt.displayName="FieldBuilderWithActions";const Jt=o.memo(t=>{const{children:e,variant:n,size:l,accentColor:s,fields:r,onSelectField:c,onSelectAllFields:f,...h}=t,u=o.useCallback(()=>{f?.(r)},[f,r]);return i.jsxs(a.Menu.Root,{...h,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:l,accentColor:s,children:i.jsxs(a.Menu.Scroll,{children:[f?i.jsx(a.Menu.Item,{onSelect:u,children:"Select all"}):null,r.map(p=>i.jsx(za,{field:p,onSelectField:c},p.id))]})})]})});Jt.displayName="FieldDropdownMenu";const za=o.memo(t=>{const{field:e,onSelectField:n}=t,l=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(a.Menu.Item,{onSelect:l,children:[i.jsx(a.LuIcon,{icon:L[e.type].icon}),e.label||P]})});za.displayName="FieldDropdownMenuItem";const Na=o.memo(t=>{const{children:e,variant:n,size:l,accentColor:s,fieldSections:r,onSelectFieldSection:c,...f}=t;return i.jsxs(a.Menu.Root,{...f,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:l,accentColor:s,children:r.map(h=>i.jsx(xa,{fieldSection:h,onSelectFieldSection:c},h.id))})]})});Na.displayName="FieldSectionDropdownMenu";const xa=o.memo(t=>{const{fieldSection:e,onSelectFieldSection:n}=t,l=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(a.Menu.Item,{onSelect:l,children:[i.jsx(a.LuIcon,{icon:dl}),e.label||an]})});xa.displayName="FieldSectionDropdownMenuItem";const Ia=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,un,n),r=()=>{switch(e.modifier){case"in":case"notIn":{const c=e.getValue();return i.jsx(jt,{required:!0,mode:"range",size:"sm",selected:c,onSelect:e.setValue,children:i.jsxs(a.Button,{type:"button",className:"truncate",children:[c.from?.toLocaleDateString()??"..."," - ",c.to?.toLocaleDateString()??"..."]})})}default:return i.jsx(jt,{required:!0,mode:"single",size:"sm",selected:e.getValue(),onSelect:e.setValue,children:i.jsx(a.Button,{type:"button",className:"truncate",children:e.getValue().toLocaleDateString()})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:un,children:i.jsx(a.Button,{type:"button",children:un[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ma=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,fn,n),r=()=>i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:fn,children:i.jsx(a.Button,{type:"button",children:fn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},qa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,gn,n),r=()=>{const c=e.getValue();return i.jsx(ya,{values:c,onValuesChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:c.length===1?c[0]:`${c.length} values`})})};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:gn,children:i.jsx(a.Button,{type:"button",children:gn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Oa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Cn,n),r=o.useCallback(u=>{u===null||e.modifier==="inRange"||e.modifier==="notInRange"||e.setValue(u)},[e]),c=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),from:u})},[e]),f=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),to:u})},[e]),h=()=>{switch(e.modifier){case"inRange":case"notInRange":{const u=e.getValue();return i.jsxs(i.Fragment,{children:[i.jsx(Oe,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from??"..."})}),i.jsx(Oe,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to??"..."})})]})}default:return i.jsx(Oe,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:e.getValue()})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Cn,children:i.jsx(a.Button,{type:"button",children:Cn[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:l})]})},Ta=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,vn,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:vn,children:i.jsx(a.Button,{type:"button",children:vn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ea=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Vn,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",children:ue[e.getValue()].label})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(a.Menu.SelectGroup,{required:!0,value:e.getValue(),onValueChange:e.setValue,children:Te.map(c=>i.jsx(Ve,{value:c,children:ue[c].label},c))})})]});case"includes":case"excludes":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," statuses"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.MultiSelectGroup,{values:e.getValue(),onValuesChange:e.setValue,children:[i.jsx(kt,{children:"Select all"}),Te.map(c=>i.jsxs(Ca,{value:c,children:[i.jsx(a.LuIcon,{icon:ue[c].icon}),ue[c].label]},c))]})})]})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Vn,children:i.jsx(a.Button,{type:"button",children:Vn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},La=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Sn,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const c=e.getValue(),f=oe(e.field.options).find(h=>h.value===c)?.label;return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"truncate",children:f??(c||"...")})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ut,{required:!0,selectFieldOptions:e.field.options,value:c,onValueChange:e.setValue})})]})}case"includes":case"excludes":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Sn,children:i.jsx(a.Button,{type:"button",children:Sn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Aa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,zn,n),r=o.useCallback(u=>{u===null||e.modifier==="inRange"||e.modifier==="notInRange"||e.setValue(u)},[e]),c=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),from:u})},[e]),f=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),to:u})},[e]),h=()=>{switch(e.modifier){case"inRange":case"notInRange":{const u=e.getValue();return i.jsxs(i.Fragment,{children:[i.jsx(Oe,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from??"..."})}),i.jsx(Oe,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to??"..."})})]})}default:return i.jsx(Oe,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:e.getValue()})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:zn,children:i.jsx(a.Button,{type:"button",children:zn[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:l})]})},Ba=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,xn,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:xn,children:i.jsx(a.Button,{type:"button",children:xn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},_a=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Mn,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const c=e.getValue(),f=oe(e.field.options).find(h=>h.value===c)?.label;return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"truncate",children:f??(c||"...")})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ut,{required:!0,selectFieldOptions:e.field.options,value:c,onValueChange:e.setValue})})]})}case"includes":case"excludes":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Mn,children:i.jsx(a.Button,{type:"button",children:Mn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Da=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,On,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:On,children:i.jsx(a.Button,{type:"button",children:On[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Pa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,En,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:En,children:i.jsx(a.Button,{type:"button",children:En[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},$a=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,An,n),r=o.useCallback(u=>{u===null||e.modifier==="in"||e.modifier==="notIn"||e.setValue(u)},[e]),c=o.useCallback(u=>{e.modifier!=="in"&&e.modifier!=="notIn"||e.setValue({...e.getValue(),from:u})},[e]),f=o.useCallback(u=>{e.modifier!=="in"&&e.modifier!=="notIn"||e.setValue({...e.getValue(),to:u})},[e]),h=()=>{switch(e.modifier){case"in":case"notIn":{const u=e.getValue();return i.jsxs(i.Fragment,{children:[i.jsx(Kn,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from?tn(u.from):"..."})}),i.jsx(Kn,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to?tn(u.to):"..."})})]})}default:return i.jsx(Kn,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:tn(e.getValue())})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:An,children:i.jsx(a.Button,{type:"button",children:An[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:l})]})},ka=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,_n,n),r=()=>i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",children:e.getValue()?"empty":"not empty"})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.SelectGroup,{required:!0,value:e.getValue(),onValueChange:e.setValue,children:[i.jsx(Ve,{value:!0,children:"empty"}),i.jsx(Ve,{value:!1,children:"not empty"})]})})]});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:_n,children:i.jsx(a.Button,{type:"button",children:_n[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},ja=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Pn,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Pn,children:i.jsx(a.Button,{type:"button",children:Pn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ht=t=>{const{condition:e,...n}=t;switch(e.type){case"string":return i.jsx(Da,{condition:e,...n});case"text":return i.jsx(Pa,{condition:e,...n});case"otp":return i.jsx(Ta,{condition:e,...n});case"qr":return i.jsx(Ba,{condition:e,...n});case"url":return i.jsx(ja,{condition:e,...n});case"select":return i.jsx(_a,{condition:e,...n});case"radio":return i.jsx(La,{condition:e,...n});case"checkbox-list":return i.jsx(Fa,{condition:e,...n});case"multi-select":return i.jsx(Ma,{condition:e,...n});case"multi-string":return i.jsx(qa,{condition:e,...n});case"number":return i.jsx(Oa,{condition:e,...n});case"rating":return i.jsx(Aa,{condition:e,...n});case"date":return i.jsx(Ia,{condition:e,...n});case"time":return i.jsx($a,{condition:e,...n});case"pass-fail":return i.jsx(Ea,{condition:e,...n});case"upload":return i.jsx(ka,{condition:e,...n});case"boolean":return i.jsx(va,{condition:e,...n});case"compound":return i.jsx(Ga,{condition:e,...n})}},Wt=o.createContext(null),Ua=()=>{const t=o.useContext(Wt);if(!t)throw new Error("useFieldConditionBuilderContext requires a FieldConditionBuilder");return t},Kt=t=>{const{fields:e,conditions:n,onAdd:l,onReplace:s,onRemove:r}=t,c=o.useMemo(()=>({fields:e}),[e]),f=o.useCallback(p=>l([Ge(p)]),[l]),h=o.useCallback(p=>l(p.map(Ge)),[l]),u=o.useCallback(()=>l([new $e({id:b.v4(),conditions:[]})]),[l]);return i.jsx(Wt.Provider,{value:c,children:i.jsxs("div",{className:"flex flex-col gap-4",children:[n.map(p=>i.jsx(Ht,{condition:p,onReplace:s,onRemove:r},p.id)),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Jt,{fields:e,onSelectField:f,onSelectAllFields:h,align:"start",size:"sm",children:i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",children:[i.jsx(a.LuIcon,{icon:K}),"Add condition"]})}),i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",onClick:u,children:[i.jsx(a.LuIcon,{icon:K}),"Add group"]})]})]})})},Ga=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=e.conditions,{fields:r}=Ua(),c=o.useCallback(g=>{const{klass:y}=ke[g],F=new y({id:e.id,conditions:e.conditions});n(e,F)},[e,n]),f=o.useCallback(()=>{l(e)},[e,l]),h=o.useCallback(()=>{e.addCondition(new $e({id:b.v4(),conditions:[]}))},[e]),u=o.useCallback(g=>{e.addCondition(Ge(g))},[e]),p=o.useCallback(g=>{e.addConditions(g.map(y=>Ge(y)))},[e]),m=o.useCallback((g,y)=>{e.replaceCondition(g,y)},[e]),C=o.useCallback(g=>{e.removeCondition(g)},[e]);return i.jsxs(a.Card,{className:"p-0! flex grow flex-col",variant:"outline",size:"sm",children:[i.jsxs("div",{className:"bg-(--base-a2) flex h-max shrink-0 grow-0 items-center gap-3 rounded-t-[inherit] px-4 py-2",children:[i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{size:"sm",variant:"surface",accentColor:"base",children:[ke[e.operator].label,i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!0,value:e.operator,onValueChange:c,children:Object.entries(ke).map(([g,{label:y,blurb:F}])=>i.jsx(Ve,{value:g,children:i.jsxs("div",{className:"flex flex-col",children:[y,i.jsx(a.Text,{size:"xs",accentColor:"base",children:F})]})},g))})})})]}),i.jsx(a.Text,{size:"sm",accentColor:"base",className:"min-w-0 grow",children:ke[e.operator].blurb}),i.jsx(a.IconButton,{onClick:f,accentColor:"base",size:"sm",variant:"ghost",type:"button",children:i.jsx(a.LuIcon,{icon:R})})]}),i.jsx(a.Separator,{size:"full"}),s.length>0?i.jsx("div",{className:"flex shrink grow flex-col gap-4 p-4",children:s.map(g=>i.jsx(Ht,{condition:g,onRemove:C,onReplace:m},g.id))}):null,i.jsxs("div",{className:"h-max shrink-0 grow-0 rounded-b-[inherit] px-4 py-2",children:[i.jsx(Jt,{fields:r,onSelectField:u,onSelectAllFields:p,align:"start",size:"sm",children:i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",children:[i.jsx(a.LuIcon,{icon:K}),"Condition"]})}),i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",onClick:h,children:[i.jsx(a.LuIcon,{icon:K}),"Group"]})]})]})},Ja=o.memo(t=>{const{id:e,sourceX:n,sourceY:l,targetX:s,targetY:r,style:c,markerEnd:f,data:h}=t,{targetSection:u,sourceSection:p,layoutDirection:m}=h,C=p.getConditions(u.id),g=o.useCallback((S,q)=>{p.replaceCondition(u.id,S,q)},[p,u.id]),y=o.useCallback(S=>{p.addConditions(u.id,S)},[p,u.id]),F=o.useCallback(S=>{p.removeCondition(u.id,S)},[p,u.id]),V=o.useCallback(()=>{p.removeConditional(u.id)},[p,u.id]),[w,M,N]=E.getBezierPath({sourceX:n,sourceY:l,sourcePosition:m==="LR"?E.Position.Right:E.Position.Bottom,targetX:s,targetY:r,targetPosition:m==="LR"?E.Position.Left:E.Position.Top});return i.jsxs(i.Fragment,{children:[i.jsx(E.BaseEdge,{id:e,path:w,style:c,markerEnd:f,labelX:M,labelY:N}),i.jsx(E.EdgeLabelRenderer,{children:i.jsxs(a.Card,{size:"xs",variant:"surface",className:"nodrag dark:bg-(--base-2)! nopan pointer-events-auto absolute inline-flex flex-col gap-2",onMouseDown:a.stopPropagation,onClick:a.stopPropagation,"data-floating-content":"",style:{transform:`translate(-50%, -50%) translate(${M}px, ${N}px)`},children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Text,{size:"xs",className:"max-w-[280px] truncate",children:p.label||an}),i.jsx(a.IconButton,{type:"button","aria-label":"Delete relationship",size:"sm",variant:"ghost",accentColor:"base",onClick:V,children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsx(Kt,{fields:p.fields,conditions:C,onRemove:F,onReplace:g,onAdd:y})]})})]})});Ja.displayName="FieldSectionConditionEdgeComponent";const Ha=o.memo(t=>{const{data:e,selected:n}=t,{fieldSection:l,index:s,layoutDirection:r}=e,{fieldSchema:c}=o.use(ae),f=o.useCallback(()=>{c.removeFieldSection(l)},[c,l]),h=o.useCallback(g=>{l.addField(Xn(g))},[l]),u=o.useCallback(()=>{const g=new W({id:b.v4(),fields:[]});c.addFieldSection(g),l.addConditional(g.id)},[c,l]),p=o.useCallback(()=>{c.addFieldSection(l.duplicate(b.v4()))},[c,l]),m=o.useCallback(g=>{l.setOptions({label:g.target.value})},[l]),C=o.useCallback(g=>{l.setOptions({description:g.target.value})},[l]);return i.jsxs(a.Card,{variant:"surface",className:"dark:bg-(--base-2)! relative cursor-pointer",size:"sm","data-selected":n?"true":void 0,children:[i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(a.Input.Root,{variant:"outline",size:"md",accentColor:"base",children:i.jsx(a.Input.Field,{placeholder:"Enter a section label (optional)",value:l.label??"",onChange:m,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:l.description??"",onChange:C,maxLength:1e3,resize:"vertical",size:"md"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(a.Text,{weight:"bold",children:"Fields"}),i.jsx(Zn,{onSelectFieldType:h,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:K})," Add field"]})})]}),i.jsx("div",{className:"flex flex-col gap-3",children:l.fields.map((g,y)=>i.jsx(Gt,{field:g,fieldSection:l,fieldIndex:y,sectionIndex:s},g.id))})]}),i.jsx(E.NodeToolbar,{isVisible:!0,position:E.Position.Right,align:"start",offset:8,onMouseDown:a.stopPropagation,children:i.jsx(a.Card,{variant:"surface",className:"dark:bg-(--color-background)! p-0! flex flex-col items-center gap-0",size:"sm",onClick:a.stopPropagation,children:i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0",variant:"soft",size:"xs",accentColor:"base",children:[i.jsx(a.IconButton,{className:"rounded-b-none",type:"button",onClick:u,children:i.jsx(a.LuIcon,{icon:Ss})}),i.jsx(a.IconButton,{className:"rounded-none",type:"button",onClick:p,children:i.jsx(a.LuIcon,{icon:Rn})}),i.jsx(a.IconButton,{className:"rounded-t-none",type:"button",onClick:f,children:i.jsx(a.LuIcon,{icon:se})})]})})}),i.jsx(E.Handle,{type:"target",className:"size-4! bg-(--base-3)! border-(--base-7)!",position:r==="LR"?E.Position.Left:E.Position.Top}),i.jsx(E.Handle,{type:"source",className:"size-4! bg-(--base-3)! border-(--base-7)!",position:r==="LR"?E.Position.Right:E.Position.Bottom})]})});Ha.displayName="CustomNode";const Xs={fieldSection:Ha},Ys={fieldSectionCondition:Ja},Qs=(t,e,n)=>{const l=new Qt.graphlib.Graph().setDefaultEdgeLabel(()=>({}));return l.setGraph({rankdir:n,nodesep:200,edgesep:500,ranksep:500}),e.forEach(s=>l.setEdge(s.source,s.target,{width:500,height:200,labelpos:"c"})),t.forEach(s=>l.setNode(s.id,{...s,width:s.measured?.width??0,height:s.measured?.height??0})),Qt.layout(l),[t.map(s=>{const r=l.node(s.id),c=r.x-(s.measured?.width??0)/2,f=r.y-(s.measured?.height??0)/2;return{...s,position:{x:c,y:f}}}),e]},Rs={hideAttribution:!0},Wa=o.memo(()=>{const{errors:t}=Q.useFormState(),{handleSubmit:e}=Q.useFormContext(),{onSave:n,onCancel:l}=o.use(ae),{fieldSchema:s}=o.use(ae),r=o.useRef(null),[c,f]=o.useState(),[h,u]=o.useState("TB");o.useLayoutEffect(()=>{r.current&&r.current.classList.remove("light")},[]);const p=o.useMemo(()=>s.fieldSections.map((A,J)=>({id:A.id,position:{x:0,y:0},data:{index:J,fieldSection:A,layoutDirection:h},draggable:!0,type:"fieldSection"})),[s.fieldSections,h]),m=o.useMemo(()=>{const A=[],J={};for(const Z of s.fieldSections)J[Z.id]=Z;for(const Z of s.fieldSections){const Xt=Z.conditions;for(const[Je,ar]of Object.entries(Xt))A.push({id:`${Z.id}-${Je}`,source:Z.id,target:Je,data:{targetSection:J[Je],sourceSection:Z,layoutDirection:h},animated:ar.length>0,markerEnd:E.MarkerType.Arrow,style:{strokeWidth:2,stroke:"var(--base-a8)"},type:"fieldSectionCondition"})}return A},[s.fieldSections,h]),[C,g,y]=E.useNodesState(p),[F,V,w]=E.useEdgesState(m);o.useEffect(()=>{g(p)},[p,g]),o.useEffect(()=>{V(m)},[m,V]);const[M,N]=o.useMemo(()=>Qs(C,F,h),[F,h,C]),S=o.useCallback(()=>{s.addFieldSection(new W({id:b.v4(),fields:[]}))},[s]),q=o.useCallback(A=>{const{source:J,target:Z}=A;s.fieldSections.find(({id:Je})=>Je===J).addConditional(Z)},[s.fieldSections]),x=o.useCallback(A=>{const J=s.getSectionDependencyGraph();return!Yt.willCreateCycle(J,A.source,A.target)},[s]),T=o.useCallback(()=>{c?.zoomOut()},[c]),_=o.useCallback(()=>{c?.zoomIn()},[c]),X=o.useCallback(()=>{c?.fitView()},[c]);return i.jsxs("form",{className:"flex size-full flex-col gap-4",onSubmit:e(n),children:[i.jsxs(a.Card,{className:"relative size-full",variant:"outline",children:[i.jsx(E.ReactFlow,{ref:r,onInit:f,nodes:M,onNodesChange:y,edges:N,onEdgesChange:w,nodeTypes:Xs,edgeTypes:Ys,onConnect:q,attributionPosition:"bottom-left",fitView:!0,minZoom:0,isValidConnection:x,proOptions:Rs}),i.jsx(E.Panel,{position:"top-left",children:i.jsx(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"surface",onClick:S,children:[i.jsx(a.LuIcon,{icon:K})," Add section"]})})}),i.jsxs(E.Panel,{position:"top-right",className:"flex flex-col items-center gap-2",children:[i.jsxs(a.ToggleGroup.Root,{className:"flex flex-col",type:"single",accentColor:"base",size:"sm",value:h,onValueChange:u,children:[i.jsx(a.ToggleGroup.IconItem,{className:"rounded-b-none",value:"LR",type:"button",children:i.jsx(a.LuIcon,{icon:fs})}),i.jsx(a.ToggleGroup.IconItem,{className:"rounded-t-none",value:"TB",type:"button",children:i.jsx(a.LuIcon,{icon:hs})})]}),i.jsx(a.Separator,{size:"sm"}),i.jsxs(a.ButtonGroup,{className:"flex flex-col",size:"sm",accentColor:"base",variant:"soft",children:[i.jsx(a.IconButton,{className:"rounded-b-none",onClick:_,type:"button",children:i.jsx(a.LuIcon,{icon:K})}),i.jsx(a.IconButton,{onClick:T,radius:"none",type:"button",children:i.jsx(a.LuIcon,{icon:Ke})}),i.jsx(a.IconButton,{className:"rounded-t-none",onClick:X,type:"button",children:i.jsx(a.LuIcon,{icon:Ls})})]})]}),i.jsx(E.Panel,{position:"bottom-right",children:i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[l&&i.jsx(a.Button,{type:"button",variant:"soft",accentColor:"base",onClick:l,children:"Cancel"}),i.jsx(a.Button,{type:"submit",variant:"surface",children:"Save"})]})})]}),!!t.fields?.message&&i.jsx(a.Text,{size:"xs",accentColor:"danger",children:t.fields.message})]})});Wa.displayName="FormBuilderFlowBuilder";const er=(t,e,n={})=>{const{conditions:l=!1}=n,s=t.get(e.id);if(!s)throw new Error(`Attempting to reseed serialized section with id ${e.id} which is not present in the reseeded id map`);const r=new Map,c=e.fields.map(h=>{const u=b.v4();return r.set(h.id,u),{...h,id:u}}),f={};if(l){const h=u=>{switch(u.type){case"compound":return{...u,conditions:u.conditions.map(h)};default:{const p=r.get(u.field);if(!p)throw new Error(`Serialized condition referencing undefined field with id: ${u.field}`);return{...u,field:p}}}};for(const[u,p]of Object.entries(e.conditions??{})){const m=t.get(u);m&&(f[m]=p.map(h))}}return{...e,id:s,conditions:f,fields:c}},nr=(t,e={})=>{const n=new Map(t.map(l=>[l.id,b.v4()]));return t.map(l=>er(n,l,e))},Zt=(t,e)=>{const n={},l=t.filter(s=>s instanceof W);for(const s of t)if(s instanceof W){const r=l.filter(f=>s.id in f.conditions);if(r.length>0&&!r.some(f=>{const h=f.getConditions(s.id);return $n(h,e)}))continue;const c=s.getErrors(e);Object.assign(n,c)}else{if(!(s instanceof I))throw new Error("Invalid field type");const r=s.id,c=s.getError(el(e,r));c&&as(n,r,c)}return n},ir=async t=>{const e={};for(const n of t){const{fields:l}=n;for(const s of l)if(s.image)if(s.image instanceof Promise)try{e[s.id]=await s.image}catch(r){console.error("Failed to get image from promise",r)}else e[s.id]=s.image}return e};async function tr(t){const e={};for(const[n,l]of Object.entries(t))e[n]=await Promise.all(l);return e}class we extends _e{fieldSections;constructor(e){super(),this.fieldSections=this.initFields(e)}serialize(){return this.fieldSections.map(e=>e.serialize())}config(){return this.fieldSections.map(e=>e.config())}static deserialize(e){return new we(Jn(e))}static fromConfig(e){return new we(ea(e))}static serializeConfig(e){return sa(e)}static deserializeConfig(e){return ta(e)}static reseedFieldSections(e,n){return nr(e,n)}fieldObserver=()=>{this.notify(this)};initFields=e=>{for(const n of e)n.observe(this.fieldObserver);return e};getFields(){return this.fieldSections.flatMap(e=>e.getFields())}getFieldSections(){return this.fieldSections}addFieldSection(e,n){const l=[...this.fieldSections];l.splice(n??this.fieldSections.length,0,e),this.fieldSections=this.initFields(l),this.notify(this)}removeFieldSection(e){const n=this.fieldSections.filter(l=>l.id!==e.id);for(const l of n)l.removeConditional(e.id);this.fieldSections=this.initFields(n),this.notify(this)}moveFieldSection(e,n){if(!Number.isInteger(e)||!Number.isInteger(n)||e<0||e>=this.fieldSections.length||n<0||n>=this.fieldSections.length||e===n)return;const l=[...this.fieldSections],[s]=l.splice(e,1);l.splice(n,0,s),this.fieldSections=this.initFields(l),this.notify(this)}getSectionDependencyGraph(){const e=new ts.DirectedGraph({type:"directed"});for(const n of this.fieldSections)for(const l of Object.keys(n.conditions))e.mergeEdge(n.id,l);return e}getDependenciesOfSection(e){const n=this.getSectionDependencyGraph(),l=new Map(this.fieldSections.map(r=>[r.id,r])),s=[];return ls.bfsFromNode(n,e,(r,c,f)=>{s.push(l.get(r))},{mode:"in"}),s}cleanValues(e){return Hn(this.getFields(),e)}cleanSerializedValues(e){return Dt(this.getFields(),e)}deserializeValues(e,n){return oa(this.getFields(),e,n)}serializeValues(e,n){return ra(this.getFields(),e,n)}initializeValues(e){return ua(this.getFields(),e)}validateValues(e){return Zt(this.getFieldSections(),e)}areValuesValid(e){return Object.keys(this.validateValues(e)).length===0}deserializeCondition(e){return Ot(this.getFields(),e)}cleanCondition(e){return kn(this.getFields(),e)}serializeCondition(e){return Tt(this.getFields(),e)}cleanSerializedCondition(e){return Un(this.getFields(),e)}cleanConditions(e){return jn(this.getFields(),e)}cleanSerializedConditions(e){return Lt(this.getFields(),e)}deserializeConditions(e){return je(this.getFields(),e)}serializeConditions(e){return Et(this.getFields(),e)}changedFieldValues(e,n){return ha(this.getFields(),e,n)}unchangedFieldValues(e,n){return fa(this.getFields(),e,n)}areValuesEqual(e,n){return Pt(this.getFields(),e,n)}areValuesBlank(e){return pa(this.getFields(),e)}blankValues(){return $t(this.getFields())}extractFilesAndPromisesFromFieldValues(e){return da(this.getFields(),e)}insertFilesAndPromisesToFieldValues(e,n){return ca(this.getFields(),e,n)}}const Ka=o.memo(t=>{const{sourceFieldSection:e,targetFieldSection:n}=t,l=e.getConditions(n.id),s=o.useCallback((h,u)=>{e.replaceCondition(n.id,h,u)},[e,n.id]),r=o.useCallback(h=>{e.addConditions(n.id,h)},[e,n.id]),c=o.useCallback(h=>{e.removeCondition(n.id,h)},[e,n.id]),f=o.useCallback(()=>{e.removeConditional(n.id)},[e,n.id]);return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs(a.ButtonGroup,{className:"flex justify-between gap-2",size:"sm",accentColor:"base",variant:"soft",children:[i.jsxs(a.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:dl}),e.label??an]}),i.jsx(a.IconButton,{type:"button","aria-label":"Delete relationship",size:"sm",variant:"ghost",accentColor:"base",onClick:f,children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsx(Kt,{fields:e.fields,conditions:l,onRemove:c,onReplace:s,onAdd:r})]})});Ka.displayName="FieldSectionConditionalItem";const Za=o.memo(t=>{const{fieldSection:e}=t,{fieldSchema:n}=o.use(ae),l=o.useMemo(()=>n.fieldSections.filter(h=>e.id in h.conditions),[n.fieldSections,e.id]),s=o.useCallback(h=>{h.addConditional(e.id)},[e.id]),r=o.useCallback(h=>{e.setOptions({label:h.target.value})},[e]),c=o.useCallback(h=>{e.setOptions({description:h.target.value})},[e]),f=o.useMemo(()=>{const h=n.getSectionDependencyGraph();return n.fieldSections.filter(u=>!Yt.willCreateCycle(h,u.id,e.id))},[e.id,n]);return i.jsxs("div",{className:"flex w-full grow flex-col gap-4",children:[i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(a.Input.Root,{variant:"outline",size:"md",children:i.jsx(a.Input.Field,{placeholder:"Enter a section label (optional)",value:e.label??"",onChange:r,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:e.description??"",onChange:c,maxLength:1e3,resize:"vertical",size:"md"})]}),i.jsx(a.Separator,{size:"full"}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex justify-between gap-2",children:[i.jsx(a.Text,{accentColor:"base",children:"Conditions"}),i.jsx(Na,{fieldSections:f,onSelectFieldSection:s,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",className:"w-max",children:[i.jsx(a.LuIcon,{icon:K}),"Add condition"]})})]}),i.jsx("div",{className:"flex flex-col gap-4",children:l.map((h,u)=>i.jsxs(o.Fragment,{children:[i.jsx(Ka,{sourceFieldSection:h,targetFieldSection:e}),u!==l.length-1?i.jsx(a.Separator,{size:"full"}):null]},h.id))})]}),i.jsx(a.Separator,{size:"full"})]})});Za.displayName="FieldSectionBuilder";const Xa=o.memo(t=>{const{fieldSection:e,sectionIndex:n}=t,{fieldSchema:l}=o.use(ae),s=a.useAlertDialog(),r=o.useCallback(()=>{l.removeFieldSection(e)},[l,e]),c=o.useCallback(F=>{const V=F==="up"?n-1:n+1;l.moveFieldSection(n,V)},[l,n]),f=o.useCallback(()=>{l.addFieldSection(e.duplicate(b.v4()))},[l,e]),h=o.useCallback(F=>{e.addField(Xn(F))},[e]),u=o.useCallback(()=>{c("up")},[c]),p=o.useCallback(()=>{c("down")},[c]),m=o.useCallback(async()=>{const F=[e.serialize()],V=we.reseedFieldSections(F,{conditions:!1}),w=JSON.stringify(V);await navigator.clipboard.writeText(w),a.toast.success({title:"Section copied"})},[e]),C=o.useCallback(async()=>{const V=l.getDependenciesOfSection(e.id).map(N=>N.serialize()),w=we.reseedFieldSections(V,{conditions:!0}),M=JSON.stringify(w);await navigator.clipboard.writeText(M),a.toast.success({title:"Section copied"})},[e,l]),g=o.useCallback(async()=>{const F=l.getDependenciesOfSection(e.id),V=F.length>1,w=F.length-1;V?s({title:"Copy section dependencies?",description:`This section has ${w} dependent section${w>1?"s":""} that will also be copied to maintain the conditions. Do you want to include these dependencies?`,action:"Include",onAction:C,cancel:"Dont include",onCancel:m}):m()},[e,l,s,C,m]),y=o.useCallback(async()=>{let F="";try{F=await navigator.clipboard.readText()}catch{a.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const V=F.trim();if(!V){a.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const w=JSON.parse(V),M=Rt.JSONFieldSectionSchema.array().parse(w),N=Jn(M);if(N.length===0){a.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[S,q]of N.entries())l.addFieldSection(q,n+1+S);a.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(w){console.error(w),a.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[l,n]);return i.jsxs(a.Card,{variant:"outline",className:"flex w-full items-center justify-between gap-4",size:"sm",children:[i.jsxs("div",{className:"flex w-full grow flex-col gap-4",children:[i.jsx(Za,{fieldSection:e}),i.jsxs("div",{className:"flex w-full flex-col gap-2",children:[i.jsxs("div",{className:"flex justify-between gap-2",children:[i.jsx(a.Text,{accentColor:"base",size:"md",children:"Fields"}),i.jsx(Zn,{onSelectFieldType:h,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:K})," Add field"]})})]}),e.fields.map((F,V)=>i.jsx(Gt,{field:F,fieldSection:e,fieldIndex:V,sectionIndex:n},F.id))]})]}),i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(a.IconButton,{type:"button",onClick:u,disabled:n===0,"aria-label":"Move section up",children:i.jsx(a.LuIcon,{icon:Ze})}),i.jsx(a.IconButton,{type:"button",onClick:p,disabled:n===l.fieldSections.length-1,"aria-label":"Move section down",children:i.jsx(a.LuIcon,{icon:cl})}),i.jsxs(a.Menu.Root,{align:"end",children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.IconButton,{type:"button",children:i.jsx(a.LuIcon,{icon:rl})})}),i.jsxs(a.Menu.Content,{size:"sm",children:[i.jsxs(a.Menu.Item,{onSelect:f,children:[i.jsx(a.LuIcon,{icon:Rn}),"Duplicate section"]}),i.jsxs(a.Menu.Item,{onSelect:g,children:[i.jsx(a.LuIcon,{icon:al}),"Copy JSON"]}),i.jsxs(a.Menu.Item,{onSelect:y,children:[i.jsx(a.LuIcon,{icon:sl}),"Paste JSON"]}),i.jsxs(a.Menu.Item,{onSelect:r,children:[i.jsx(a.LuIcon,{icon:se}),"Delete section"]})]})]})]})]})});Xa.displayName="FieldSectionWithActions";const Ya=o.memo(()=>{const{handleSubmit:t}=Q.useFormContext(),{errors:e}=Q.useFormState(),{onSave:n,onCancel:l}=o.use(ae),{fieldSchema:s}=o.use(ae),r=o.useCallback(()=>{s.addFieldSection(new W({id:b.v4(),fields:[]}))},[s]),c=o.useCallback(async()=>{try{const h=s.serialize(),u=we.reseedFieldSections(h,{conditions:!0}),p=JSON.stringify(u);await navigator.clipboard.writeText(p),a.toast.success({title:"Sections copied",description:"All sections JSON copied to clipboard."})}catch{a.toast.error({title:"Copy failed",description:"Unable to copy the sections JSON."})}},[s]),f=o.useCallback(async()=>{let h="";try{h=await navigator.clipboard.readText()}catch{a.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const u=h.trim();if(!u){a.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const p=JSON.parse(u),m=Rt.JSONFieldSectionSchema.array().parse(p),C=Jn(m);if(C.length===0){a.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[g,y]of C.entries())s.addFieldSection(y,s.fieldSections.length+g);a.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(p){console.error(p),a.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[s]);return i.jsxs("form",{className:"flex flex-col gap-4",onSubmit:t(n),children:[i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",onClick:c,children:[i.jsx(a.LuIcon,{icon:al})," Copy JSON"]}),i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",onClick:f,children:[i.jsx(a.LuIcon,{icon:sl})," Paste JSON"]})]}),s.fieldSections.map((h,u)=>i.jsx(Xa,{fieldSection:h,sectionIndex:u},h.id)),i.jsxs(a.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:r,children:[i.jsx(a.LuIcon,{icon:K})," Add section"]})]}),!!e.fields?.message&&i.jsx(a.Text,{size:"xs",accentColor:"danger",children:e.fields.message}),i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[l&&i.jsx(a.Button,{type:"button",variant:"soft",accentColor:"base",onClick:l,children:"Cancel"}),i.jsx(a.Button,{type:"submit",variant:"surface",children:"Save"})]})]})});Ya.displayName="FormBuilderListBuilder";function Qa(t){const e=n=>{const l={};for(const[s,r]of Object.entries(n))typeof r=="string"?l[s]={type:"validate",message:r}:l[s]=e(r);return l};return e(t)}const Ra=o.memo(o.forwardRef((t,e)=>{const{disabled:n=!1,fieldSchema:l,values:s={},onValuesChange:r,onSubmit:c,submitText:f="Submit",hideSubmit:h=!1,cancelText:u,onCancel:p,hideCancel:m=!1,className:C,submitButtonProps:g,cancelButtonProps:y,cancelIcon:F,submitIcon:V,size:w="md"}=t,M=o.useMemo(()=>l.initializeValues(s),[l,s]),N=o.useCallback(A=>{c?.(A)},[c]),S=Q.useForm({values:M,mode:"onBlur",criteriaMode:"all",disabled:n,resolver:A=>{const J=l.validateValues(A),Z=Qa(J);return Object.keys(J).length>0?{values:{},errors:Z}:{values:A,errors:{}}}}),q=o.useCallback(A=>{r?.(A)},[r]);o.useEffect(()=>{const{unsubscribe:A}=S.watch((J,{type:Z})=>{Z==="change"&&q(J)});return()=>{A()}},[S,q]);const x=gl(l.getFieldSections()),T=o.useMemo(()=>({fieldSchema:l,size:w}),[l,w]),_=!m&&!!p,X=!h;return i.jsx(Q.FormProvider,{...S,children:i.jsx(B,{value:T,children:i.jsxs("form",{ref:e,className:Y.cx(C,"flex flex-col gap-4"),onSubmit:S.handleSubmit(N),children:[i.jsx("div",{className:Zs({size:w}),children:x}),!n&&(_||X)?i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:w,children:[_?i.jsxs(a.Button,{accentColor:"base",type:"button",variant:"soft",onClick:p,...y,children:[i.jsx(a.LuIcon,{icon:F??R}),u]}):null,X?i.jsxs(a.Button,{type:"submit",accentColor:"primary",variant:"surface",...g,children:[i.jsx(a.LuIcon,{icon:V??H}),f]}):null]}):null]})})})})),es=o.memo(()=>{const{fieldSchema:t}=o.use(ae);return i.jsx(Ra,{fieldSchema:t,disabled:!1})});es.displayName="FormBuilderPreview";const ns=o.memo(t=>{const{children:e,initialFields:n,onSave:l,onCancel:s,disableRequiredFields:r=!1}=t,c=o.useCallback(y=>{const F={};(!y.fields||y.fields.length===0)&&(F.fields="At least one field is required.");const V=[];for(const[N,S]of y.fields.entries())for(const[q,x]of S.fields.entries()){const T=wa(x.type,`fields.${N}.fields.${q}`)?.map(({field:_})=>_)??[];V.push(...T)}const w={};for(const N of V)w[N.id]=el(y,N.id);const M=Zt(V,w);return Object.keys(M).length>0&&(F.fields=M.fields),Object.keys(F).length>0&&a.toast.error({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),F},[]),f=o.useMemo(()=>({fields:n??[]}),[n]),h=Q.useForm({values:f,mode:"onSubmit",criteriaMode:"all",reValidateMode:"onSubmit",resolver:y=>{const F=c(y),V=Qa(F);return Object.keys(F).length>0?{values:{},errors:V}:{values:y,errors:{}}}}),u=o.useCallback(y=>{h.setValue("fields",y.config())},[h]),p=Q.useWatch({control:h.control,compute:y=>y.fields}),m=o.useMemo(()=>{const y=we.fromConfig(p);return y.observe(u),y},[p,u]),C=o.useMemo(()=>({fieldSchema:m,disableRequiredFields:r,onSave:l,onCancel:s}),[r,l,s,m]),g=o.useMemo(()=>({fieldSchema:m,size:"sm"}),[m]);return i.jsx(ae,{value:C,children:i.jsx(B,{value:g,children:i.jsx(Q.FormProvider,{...h,children:e})})})});ns.displayName="FormBuilderRoot";const lr={Root:ns,FlowBuilder:Wa,ListBuilder:Ya,Preview:es};d.AndFieldCondition=$e,d.BaseAtomicFieldCondition=v,d.BaseCompoundFieldCondition=Pe,d.BaseField=I,d.BaseFieldCondition=vi,d.BaseFormElement=Se,d.BaseOptionsField=ee,d.BaseStringField=ze,d.BooleanField=de,d.BooleanFieldConditionCell=va,d.BooleanFieldEqualsCondition=sn,d.BooleanFieldInput=si,d.BooleanFieldNotEqualsCondition=Fi,d.CheckboxListField=ie,d.CheckboxListFieldConditionCell=Fa,d.CheckboxListFieldEqualsCondition=on,d.CheckboxListFieldEveryCondition=wi,d.CheckboxListFieldNoneCondition=bi,d.CheckboxListFieldNotEqualsCondition=Vi,d.CheckboxListFieldSomeCondition=Si,d.CompoundFieldConditionCell=Ga,d.ConditionManager=Xl,d.DateField=Ne,d.DateFieldAfterCondition=qi,d.DateFieldBeforeCondition=Mi,d.DateFieldConditionCell=Ia,d.DateFieldEqualsCondition=cn,d.DateFieldInCondition=Oi,d.DateFieldInput=ri,d.DateFieldNotEqualsCondition=Ii,d.DateFieldNotInCondition=Ti,d.FIELD_TYPES=Kl,d.FieldConditionBuilder=Kt,d.FieldConditionBuilderContext=Wt,d.FieldConditionCell=Ht,d.FieldSchema=we,d.FieldSection=W,d.FieldTypeGroup=O,d.FieldTypeToClsMapping=Ee,d.FieldsRenderer=Ra,d.FileCard=ii,d.FormBuilder=lr,d.ImageCapturer=di,d.ImageCapturerProvider=zl,d.ImageCard=ci,d.ImageFile=be,d.ImageViewer=li,d.ImageViewerProvider=pl,d.InputWithLabel=D,d.MultiSelectField=te,d.MultiSelectFieldConditionCell=Ma,d.MultiSelectFieldEqualsCondition=hn,d.MultiSelectFieldEveryCondition=Li,d.MultiSelectFieldNoneCondition=Bi,d.MultiSelectFieldNotEqualsCondition=Ei,d.MultiSelectFieldSomeCondition=Ai,d.MultiStringField=re,d.MultiStringFieldConditionCell=qa,d.MultiStringFieldEqualsCondition=pn,d.MultiStringFieldEveryCondition=Di,d.MultiStringFieldNoneCondition=$i,d.MultiStringFieldNotEqualsCondition=_i,d.MultiStringFieldSomeCondition=Pi,d.NandFieldCondition=Ni,d.NorFieldCondition=xi,d.NumberField=G,d.NumberFieldConditionCell=Oa,d.NumberFieldEqualsCondition=mn,d.NumberFieldGreaterThanCondition=Gi,d.NumberFieldGreaterThanOrEqualsCondition=Ji,d.NumberFieldInRangeCondition=Hi,d.NumberFieldLessThanCondition=ji,d.NumberFieldLessThanOrEqualsCondition=Ui,d.NumberFieldNotEqualsCondition=ki,d.NumberFieldNotInRangeCondition=Wi,d.OTPField=ce,d.OTPFieldConditionCell=Ta,d.OTPFieldEqualsCondition=yn,d.OTPFieldExcludesCondition=Xi,d.OTPFieldIncludesCondition=Zi,d.OTPFieldNotEqualsCondition=Ki,d.Observable=_e,d.OrFieldCondition=zi,d.PassFailField=he,d.PassFailFieldConditionCell=Ea,d.PassFailFieldEqualsCondition=Fn,d.PassFailFieldExcludesCondition=Ri,d.PassFailFieldIncludesCondition=Qi,d.PassFailFieldNotEqualsCondition=Yi,d.RadioField=fe,d.RadioFieldConditionCell=La,d.RadioFieldEqualsCondition=wn,d.RadioFieldExcludesCondition=it,d.RadioFieldIncludesCondition=nt,d.RadioFieldNotEqualsCondition=et,d.RatingField=pe,d.RatingFieldConditionCell=Aa,d.RatingFieldEqualsCondition=bn,d.RatingFieldGreaterThanCondition=st,d.RatingFieldGreaterThanOrEqualsCondition=rt,d.RatingFieldInRangeCondition=ot,d.RatingFieldLessThanCondition=lt,d.RatingFieldLessThanOrEqualsCondition=at,d.RatingFieldNotEqualsCondition=tt,d.RatingFieldNotInRangeCondition=dt,d.ScanField=Ie,d.ScanFieldConditionCell=Ba,d.ScanFieldEqualsCondition=Nn,d.ScanFieldExcludesCondition=ht,d.ScanFieldIncludesCondition=ut,d.ScanFieldNotEqualsCondition=ct,d.Scanner=Re,d.ScannerProvider=_l,d.SelectField=ge,d.SelectFieldConditionCell=_a,d.SelectFieldEqualsCondition=In,d.SelectFieldExcludesCondition=gt,d.SelectFieldIncludesCondition=pt,d.SelectFieldNotEqualsCondition=ft,d.StringField=me,d.StringFieldConditionCell=Da,d.StringFieldEqualsCondition=qn,d.StringFieldExcludesCondition=yt,d.StringFieldIncludesCondition=Ct,d.StringFieldNotEqualsCondition=mt,d.TextField=Ce,d.TextFieldConditionCell=Pa,d.TextFieldEqualsCondition=Tn,d.TextFieldExcludesCondition=Vt,d.TextFieldIncludesCondition=Ft,d.TextFieldNotEqualsCondition=vt,d.TimeField=Me,d.TimeFieldAfterCondition=bt,d.TimeFieldBeforeCondition=St,d.TimeFieldConditionCell=$a,d.TimeFieldControl=ln,d.TimeFieldEqualsCondition=Ln,d.TimeFieldInCondition=zt,d.TimeFieldInput=yi,d.TimeFieldNotEqualsCondition=wt,d.TimeFieldNotInCondition=Nt,d.UNLABELLED_FIELD_LABEL=P,d.UNLABELLED_SECTION_LABEL=an,d.URLField=qe,d.URLFieldConditionCell=ja,d.URLFieldEqualsCondition=Dn,d.URLFieldExcludesCondition=qt,d.URLFieldIncludesCondition=Mt,d.URLFieldNotEqualsCondition=It,d.UTC_OFFSETS=mi,d.UTC_OFFSETS_SET=jl,d.UUIDFile=le,d.UUIDPromise=xe,d.UploadField=Fe,d.UploadFieldConditionCell=ka,d.UploadFieldEqualsCondition=Bn,d.UploadFieldNotEqualsCondition=xt,d.VideoCard=hi,d.VideoFile=ui,d.applyConditions=$n,d.areFieldValuesBlank=pa,d.areFieldValuesEqual=Pt,d.areFileAndPromiseArraysEqual=Qe,d.areJSONPassFailFieldValuesEqual=Tl,d.arePassFieldValuesEqual=Ol,d.awaitFilesAndPromises=tr,d.blankFieldValues=$t,d.booleanFieldConditionModifierConfig=rn,d.changedFieldValues=ha,d.checkboxListFieldConditionModifierConfig=dn,d.cleanCondition=kn,d.cleanConditions=jn,d.cleanFieldValues=Hn,d.cleanSerializedCondition=Un,d.cleanSerializedConditions=Lt,d.cleanSerializedFieldValues=Dt,d.compoundFieldConditionOperatorConfig=ke,d.createAtomicCondition=Ge,d.createField=Xn,d.createTime=ye,d.dateFieldConditionModifierConfig=un,d.deserializeCondition=Ot,d.deserializeConditions=je,d.deserializeField=Gn,d.deserializeFieldConfig=Bt,d.deserializeFieldConfigs=na,d.deserializeFieldElement=Yl,d.deserializeFieldElementConfig=ia,d.deserializeFieldElementConfigs=ta,d.deserializeFieldElements=Jn,d.deserializeFieldValues=oa,d.deserializeFields=Ws,d.deserializePassFailFieldValue=ql,d.extractFilesAndPromisesFromFieldValues=da,d.fieldDataMapping=L,d.fieldElementFromConfig=Rl,d.fieldElementsFromConfigs=ea,d.fieldFromConfig=At,d.fieldSpacingCva=Wn,d.fieldTypeGroupDataMapping=Zl,d.fieldsFromConfigs=Ql,d.formatTime=tn,d.formatUTCOffset=nn,d.getCurrentUTCOffset=Gl,d.getFieldsMapping=Ks,d.getImagesFromFields=ir,d.getUTCMinuteOfDay=ve,d.getUTCOffsetMinutes=Jl,d.initializeFieldValues=ua,d.insertFilesAndPromisesToFieldValues=ca,d.isFileAndPromiseArray=Vl,d.isJSONPassFailFieldValue=xl,d.isPassFailFieldStatus=pi,d.isPassFailFieldValue=Il,d.isStringArray=Be,d.isTime=ne,d.isTimeInRange=Ci,d.isTimeRange=Us,d.isUTCOffset=en,d.multiSelectFieldConditionModifierConfig=fn,d.multiStringFieldConditionModifierConfig=gn,d.normalizeFieldOption=ai,d.normalizeFieldOptions=oe,d.numberFieldConditionModifierConfig=Cn,d.otpFieldConditionModifierConfig=vn,d.parseTime=De,d.passFailFieldConditionModifierConfig=Vn,d.passFailFieldStatusMapping=ue,d.passFailFieldStatuses=Te,d.radioFieldConditionModifierConfig=Sn,d.ratingFieldConditionModifierConfig=zn,d.scanFieldConditionModifierConfig=xn,d.selectFieldConditionModifierConfig=Mn,d.serializeCondition=Tt,d.serializeConditions=Et,d.serializeFieldConfig=_t,d.serializeFieldConfigs=la,d.serializeFieldElementConfig=aa,d.serializeFieldElementConfigs=sa,d.serializeFieldValues=ra,d.serializePassFailFieldValue=Ml,d.stringFieldConditionModifierConfig=On,d.textFieldConditionModifierConfig=En,d.timeFieldConditionModifierConfig=An,d.unchangedFieldValues=fa,d.uploadFieldConditionModifierConfig=_n,d.urlFieldConditionModifierConfig=Pn,d.useConditionManager=Hs,d.useFieldConditionBuilderContext=Ua,d.useFieldInput=$,d.useFieldInputs=Ye,d.useFieldSectionInputs=gl,d.useImageCapturer=oi,d.useImageViewer=Xe,d.useObjectUrl=ti,d.useScanner=Ps,d.useScannerContext=Al,d.validateFieldValues=Zt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("class-variance-authority"),require("react"),require("@xyflow/react/dist/style.css"),require("@xyflow/react"),require("graphology-dag"),require("react-hook-form"),require("uuid"),require("@hello-pangea/dnd"),require("file-saver"),require("@overmap-ai/hooks"),require("react-zxing"),require("@dagrejs/dagre"),require("@adrekic/zod-fieldsjson"),require("graphology"),require("graphology-traversal"),require("lodash.get"),require("lodash.set")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","class-variance-authority","react","@xyflow/react/dist/style.css","@xyflow/react","graphology-dag","react-hook-form","uuid","@hello-pangea/dnd","file-saver","@overmap-ai/hooks","react-zxing","@dagrejs/dagre","@adrekic/zod-fieldsjson","graphology","graphology-traversal","lodash.get","lodash.set"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.forms={},d.jsxRuntime,d.blocks,d.classVarianceAuthority,d.react,null,d.react$1,d.graphologyDag,d.reactHookForm,d.uuid,d.dnd,d.fileSaver,d.hooks,d.reactZxing,d.Dagre,d.zodFieldsjson,d.graphology,d.graphologyTraversal,d.get,d.set))})(this,(function(d,i,a,Y,o,or,E,Zt,Q,b,Yn,Qn,He,ls,Xt,Yt,as,ss,Qt,rs){"use strict";const os=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),ds=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,n,l)=>l?l.toUpperCase():n.toLowerCase()),Rt=t=>{const e=ds(t);return e.charAt(0).toUpperCase()+e.slice(1)},el=(...t)=>t.filter((e,n,l)=>!!e&&e.trim()!==""&&l.indexOf(e)===n).join(" ").trim(),cs=t=>{for(const e in t)if(e.startsWith("aria-")||e==="role"||e==="title")return!0};var us={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const hs=o.forwardRef(({color:t="currentColor",size:e=24,strokeWidth:n=2,absoluteStrokeWidth:l,className:s="",children:r,iconNode:c,...f},h)=>o.createElement("svg",{ref:h,...us,width:e,height:e,stroke:t,strokeWidth:l?Number(n)*24/Number(e):n,className:el("lucide",s),...!r&&!cs(f)&&{"aria-hidden":"true"},...f},[...c.map(([u,p])=>o.createElement(u,p)),...Array.isArray(r)?r:[r]]));const z=(t,e)=>{const n=o.forwardRef(({className:l,...s},r)=>o.createElement(hs,{ref:r,iconNode:e,className:el(`lucide-${os(Rt(t))}`,`lucide-${t}`,l),...s}));return n.displayName=Rt(t),n};const fs=z("align-justify",[["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 18h18",key:"1h113x"}],["path",{d:"M3 6h18",key:"d0wm0j"}]]);const ps=z("arrow-down-up",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"m21 8-4-4-4 4",key:"1c9v7m"}],["path",{d:"M17 4v16",key:"7dpous"}]]);const gs=z("arrow-left-right",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);const nl=z("camera",[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);const ms=z("calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);const H=z("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const Ae=z("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const We=z("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);const Cs=z("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const ys=z("circle-dot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);const vs=z("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const Fs=z("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);const il=z("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const tl=z("clipboard-copy",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]);const Vs=z("clipboard-list",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);const ll=z("clipboard-paste",[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]);const ws=z("copy-check",[["path",{d:"m12 15 2 2 4-4",key:"2c609p"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const Rn=z("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const ei=z("download",[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]);const al=z("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);const Ss=z("external-link",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);const bs=z("file",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);const zs=z("git-branch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);const Ns=z("hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);const sl=z("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);const rl=z("layout-panel-top",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}]]);const xs=z("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]);const Is=z("list-checks",[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const Ms=z("list-todo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const qs=z("list",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);const Os=z("maximize",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]);const Ke=z("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const ol=z("move-down",[["path",{d:"M8 18L12 22L16 18",key:"cskvfv"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const Ze=z("move-up",[["path",{d:"M8 6L12 2L16 6",key:"1yvkyx"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const dl=z("paperclip",[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]);const K=z("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);const Ts=z("rectangle-ellipsis",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M17 12h.01",key:"1m0b6t"}],["path",{d:"M7 12h.01",key:"eqddd0"}]]);const Es=z("scan",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]]);const Ls=z("settings",[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const As=z("square-check",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Bs=z("square-dashed",[["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M21 19a2 2 0 0 1-2 2",key:"1j7049"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h1",key:"15o7lz"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M14 21h1",key:"v9vybs"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v1",key:"mxsmne"}],["path",{d:"M3 14v1",key:"vnatye"}],["path",{d:"M21 14v1",key:"169vum"}]]);const cl=z("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);const _s=z("text-cursor-input",[["path",{d:"M12 20h-1a2 2 0 0 1-2-2 2 2 0 0 1-2 2H6",key:"1528k5"}],["path",{d:"M13 8h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7",key:"13ksps"}],["path",{d:"M5 16H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1",key:"1n9rhb"}],["path",{d:"M6 4h1a2 2 0 0 1 2 2 2 2 0 0 1 2-2h1",key:"1mj8rg"}],["path",{d:"M9 6v12",key:"velyjx"}]]);const Ds=z("timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);const se=z("trash",[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]);const ni=z("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);const Ps=z("video",[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]]);const R=z("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),ii=o.memo(t=>{const{ref:e,file:n,className:l,error:s,rightSlot:r,size:c,...f}=t,h=()=>s?i.jsxs(i.Fragment,{children:[i.jsx(a.LuIcon,{icon:We,color:"var(--base-a11)"}),i.jsx(a.Text,{accentColor:"base",className:"truncate",size:c,children:s})]}):n?i.jsxs(i.Fragment,{children:[i.jsx(a.LuIcon,{icon:bs,color:"var(--base-a11)"}),i.jsx(a.Text,{className:"truncate",size:c,children:n.name})]}):i.jsx(i.Fragment,{children:i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(a.Spinner,{size:c})})});return i.jsxs(a.Card,{className:Y.cx(l,"flex w-full items-center gap-2"),ref:e,size:"xs",...f,children:[h(),r]})});ii.displayName="FileCard";function Be(t){return Array.isArray(t)?t.every(e=>typeof e=="string"):!1}class _e{observers=new Set;notify(e){for(const n of this.observers)n(e)}observe(e){return this.observers.add(e),()=>{this.observers.delete(e)}}}class Se extends _e{id;constructor(e){const{id:n}=e;super(),this.id=n}getOptions(){return{id:this.id}}setOptions(e){"id"in e&&e.id!==void 0&&(this.id=e.id),this.notify(this)}serialize(){return{type:this.type,id:this.id}}config(){return{type:this.type,id:this.id}}static _deserializeConfig(e){const{id:n,type:l}=e;return{id:n,type:l}}static _serializeConfig(e){const{id:n,type:l}=e;return{id:n,type:l}}}class I extends Se{label;description;required;image;constructor(e){const{label:n,description:l,required:s,image:r,...c}=e;super(c),this.label=n,this.description=l,this.required=s,this.image=r}getError(e){if(!(!this.required&&this.isValueBlank(e))){if(this.required&&this.isValueBlank(e))return"This field is required.";for(const n of this.getFieldValidators()){const l=n(e);if(l)return l}}}serialize(){return{...super.serialize(),label:this.label,description:this.description,required:this.required}}config(){return{...super.config(),label:this.label,description:this.description,required:this.required,image:this.image}}static _deserializeConfig(e){const{label:n,description:l,required:s,...r}=e;return{...Se._deserializeConfig(r),label:n,description:l??void 0,required:s}}static _serializeConfig(e){const{label:n,description:l,required:s,...r}=e;return{...Se._serializeConfig(r),label:n,description:l,required:s}}getOptions(){return{...super.getOptions(),label:this.label,description:this.description,required:this.required,image:this.image}}setOptions(e){"label"in e&&e.label!==void 0&&(this.label=e.label),"description"in e&&(this.description=e.description),"required"in e&&e.required!==void 0&&(this.required=e.required),"image"in e&&(this.image=e.image),super.setOptions(e)}isValueBlank(e){return this.areValuesEqual(e,this.blankValue())}cleanValue(e){return e}isValueClean(e){return this.areValuesEqual(e,this.cleanValue(e))}cleanSerializedValue(e){return e}isSerializedValueClean(e){return this.areSerializedValuesEqual(e,this.cleanSerializedValue(e))}isSerializedValueBlank(e){return this.areSerializedValuesEqual(e,this.blankSerializedValue())}getFieldValidators(){return[]}}const B=o.createContext({}),ti=t=>{const[e,n]=o.useState(null);return o.useLayoutEffect(()=>{const l=URL.createObjectURL(t);return n(l),()=>{URL.revokeObjectURL(l)}},[t]),e},be=o.memo(t=>{const{file:e,...n}=t,l=ti(e);return i.jsx("img",{src:l??void 0,alt:e.name,...n})});be.displayName="ImageFile";const ul=o.createContext(()=>{throw new Error("No ImageViewerProvider found")}),Xe=()=>o.useContext(ul),li=o.memo(t=>{const{file:e,onClose:n}=t,l=o.useCallback(()=>{Qn.saveAs(e,e.name)},[e]);return i.jsx(a.Overlay.Root,{open:!0,onOpenChange:n,children:i.jsxs(a.Overlay.Content,{onOpenAutoFocus:a.preventDefault,children:[i.jsxs(a.ButtonGroup,{className:"absolute right-0 top-0 flex items-center gap-2 p-2",accentColor:"base",variant:"soft",children:[i.jsx(a.IconButton,{onClick:l,"aria-label":"download",children:i.jsx(a.LuIcon,{icon:ei})}),i.jsx(a.Separator,{orientation:"vertical",size:"sm"}),i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{onClick:n,"aria-label":"close",children:i.jsx(a.LuIcon,{icon:R})})})]}),i.jsx("div",{className:"flex size-full items-center justify-center overflow-hidden p-4",children:i.jsx(be,{className:"max-h-full max-w-full",file:e})})]})})});li.displayName="ImageViewer";const hl=o.memo(t=>{const{children:e}=t,[n,l]=o.useState(null),s=o.useCallback(()=>{l(null)},[]),r=o.useCallback(f=>{l(f(s))},[s]),c=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),s())},[s,n]);return i.jsxs(ul.Provider,{value:r,children:[e,n&&i.jsx(li,{file:n.file,onClose:c})]})});hl.displayName="FileViewerProvider";const D=o.memo(t=>{const{label:e,error:n,description:l,required:s,children:r,inputId:c,image:f,size:h}=t,[u,p]=o.useState(void 0),m=Xe();o.useEffect(()=>{f instanceof Promise?f.then(p).catch(console.error):p(f)},[f]);const C=o.useCallback(()=>{u&&m(()=>({file:u}))},[m,u]),g=s?`${e??"Unlabelled"} *`:e??"Unlabelled";return i.jsxs("div",{className:"flex flex-col gap-1",children:[u&&i.jsx(be,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:u,onClick:C}),(!!e||!!l)&&i.jsxs("div",{className:"flex flex-col",children:[i.jsx("label",{className:"w-max max-w-full",htmlFor:c,children:i.jsx(a.Text,{size:h,className:"text-wrap",children:g})}),!!l&&i.jsx(a.Text,{accentColor:"base",size:h,children:l})]}),r,!!n&&i.jsx(a.Text,{accentColor:"danger",size:h,children:n})]})});D.displayName="InputWithLabel";const fl=t=>t.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),Ye=t=>t.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),$=t=>{const{field:e}=t,{field:{value:n,name:l,onChange:s,onBlur:r,disabled:c},fieldState:{isTouched:f,error:h}}=Q.useController({name:e.id});return{value:n,name:l,disabled:c,isTouched:f,error:h?.message??"",onChange:s,onBlur:r}},pl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),[u,p]=o.useState(""),[m,C]=o.useState(""),g=o.useCallback(S=>{c(S),r()},[c,r]),y=o.useCallback(S=>{l&&l.findIndex(q=>q===S.target.value.trim())>=0?C("All options must be unique"):S.target.value?C(""):C("Option cannot be empty"),p(S.target.value)},[p,l]),F=o.useCallback(()=>{if(m)return;if(!u.trim()){C("Option cannot be empty");return}const S=u.trim();g([...l,S]),p("")},[u,m,g,l]),V=o.useCallback(S=>{S.key==="Enter"&&(S.preventDefault(),F())},[F]),w=o.useCallback(S=>{const q=Array.from(l);q.splice(S,1),g(q)},[l,g]),M=o.useCallback(S=>{if(!S.destination)return;const q=S.source.index,x=S.destination.index,T=Array.from(l),[_]=T.splice(q,1);T.splice(x,0,_),g(T)},[g,l]),N=o.useCallback(()=>{r()},[r]);return i.jsx(Yn.DragDropContext,{onDragEnd:M,children:i.jsxs(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:m||f,image:e.image,children:[(!h||l.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx(a.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{value:u,onChange:y,onKeyDown:V,id:e.id,placeholder:e.placeholder??"Press enter to add a new option",onBlur:N,name:s,disabled:h})}),i.jsx(a.IconButton,{size:n,accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!m||h,onClick:F,children:i.jsx(a.LuIcon,{icon:K})})]}),l.length!==0&&i.jsx(Yn.Droppable,{droppableId:`${e.id}-droppable`,children:S=>i.jsxs("div",{className:"flex flex-col gap-1",...S.droppableProps,ref:S.innerRef,children:[l.map((q,x)=>i.jsx(Yn.Draggable,{draggableId:`${q}-draggable`,index:x,isDragDisabled:h,children:({draggableProps:T,dragHandleProps:_,innerRef:X})=>i.jsxs(a.Badge,{..._,...T,ref:X,className:"flex items-center justify-between gap-2",accentColor:"base",size:n,variant:"soft",children:[i.jsx(a.Text,{className:"truncate",highContrast:!0,children:ai(q).label}),i.jsx(a.IconButton,{className:"bg-transparent!",size:n,variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:h,onClick:()=>{w(x)},children:i.jsx(a.LuIcon,{icon:R})})]})},`${e.id}-${q}-${x}`)),S.placeholder]})})]})})});pl.displayName="MultiStringFieldInput";class re extends I{type="multi-string";minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;super(r),this.minLength=n,this.maxLength=l,this.placeholder=s}render(){return i.jsx(pl,{field:this})}serialize(){return{...super.serialize(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}config(){return{...super.config(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}duplicate(e){return new re({...this.getOptions(),id:e})}setOptions(e){"minLength"in e&&(this.minLength=e.minLength),"maxLength"in e&&(this.maxLength=e.maxLength),"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}getFieldValidators(){const e=super.getFieldValidators();return e.push(n=>{if(this.minLength!==void 0&&n.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(n=>{if(this.maxLength!==void 0&&n.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){return new re(e)}static fromConfig(e){return new re(e)}static deserializeConfig(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;return{...I._deserializeConfig(r),minLength:n,maxLength:l,placeholder:s}}static serializeConfig(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;return{...I._serializeConfig(r),minLength:n,maxLength:l,placeholder:s}}isSerializedValue(e){return Be(e)}isValue(e){return Be(e)}blankValue(){return[]}areValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}}function ai(t){return typeof t=="string"&&(t={label:t,value:t}),t}function oe(t){return t.map(ai)}class ee extends I{options;constructor(e){const{options:n,...l}=e;super(l),this.options=oe(n)}serialize(){return{...super.serialize(),options:this.options}}config(){return{...super.config(),options:this.options}}static _deserializeConfig(e){const{options:n,...l}=e;return{...I._deserializeConfig(l),options:n}}static _serializeConfig(e){const{options:n,...l}=e;return{...I._serializeConfig(l),options:oe(n)}}getOptions(){return{...super.getOptions(),options:this.options}}setOptions(e){"options"in e&&e.options!==void 0&&(this.options=oe(e.options)),super.setOptions(e)}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new re({label:"Options",description:"List possible options for the user to select from.",required:!0,id:`${n}options`,minLength:2}),showDirectly:!0}]}}const si=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{c(!!m),r()},[r,c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,error:f,image:e.image,required:e.required,children:i.jsx(a.Checkbox.Root,{id:e.id,name:s,checked:l??!1,onCheckedChange:u,onBlur:p,size:n,accentColor:"base",variant:"surface",disabled:h,children:i.jsx(a.Checkbox.Indicator,{children:i.jsx(a.LuIcon,{icon:H})})})})});si.displayName="BooleanFieldInput";class de extends I{type="boolean";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}setOptions(e){super.setOptions(e)}duplicate(e){return new de({...this.getOptions(),id:e})}static deserialize(e){return new de(e)}static fromConfig(e){return new de(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(si,{field:this})}isSerializedValue(e){return typeof e=="boolean"}isValue(e){return typeof e=="boolean"}blankValue(){return!1}blankSerializedValue(){return!1}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const gl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{const g=C.target.valueAsNumber,y=isNaN(g)?null:g;c(y)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(C=>{C.key==="Enter"&&C.preventDefault()},[]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.Input.Root,{accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{id:e.id,name:s,onChange:u,onBlur:p,value:l??"",type:"number",min:e.minimum??Number.MIN_SAFE_INTEGER,max:e.maximum??Number.MAX_SAFE_INTEGER,step:e.integers?1:"any",placeholder:e.placeholder??"Enter a number",disabled:h,onKeyDown:m})})})});gl.displayName="NumberFieldInput";class G extends I{type="number";minimum;maximum;integers;placeholder;constructor(e){const{minimum:n,maximum:l,integers:s,placeholder:r,...c}=e;super(c),this.minimum=n,this.maximum=l,this.integers=s,this.placeholder=r}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Minimum",description:"Minimum value",integers:!0,required:!1,id:`${n}minimum`}),showDirectly:!1},{field:new G({label:"Maximum",description:"Maximum value",integers:!0,required:!1,id:`${n}maximum`}),showDirectly:!1},{field:new de({label:"Integers",description:"Whole numbers only",required:!1,id:`${n}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.minimum,l=this.maximum;return typeof n=="number"&&e.push(s=>{if(typeof s=="number"&&s<n)return`Must be at least ${this.minimum}.`}),e.push(s=>{if(typeof s=="number"&&s<Number.MIN_SAFE_INTEGER)return"Cant be less than MIN_SAFE_INTEGER."}),typeof l=="number"&&e.push(s=>{if(typeof s=="number"&&s>l)return`Must be at most ${l}.`}),e.push(s=>{if(typeof s=="number"&&s>Number.MAX_SAFE_INTEGER)return"Cant be greater than MAX_SAFE_INTEGER."}),this.integers&&e.push(s=>{if(typeof s=="number"&&!Number.isInteger(s))return"Must be a whole number."}),e}serialize(){return{...super.serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}config(){return{...super.config(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}duplicate(e){return new G({...this.getOptions(),id:e})}setOptions(e){"minimum"in e&&(this.minimum=e.minimum),"maximum"in e&&(this.maximum=e.maximum),"integers"in e&&(this.integers=e.integers),"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new G(e)}static fromConfig(e){return new G(e)}static deserializeConfig(e){const{minimum:n,maximum:l,integers:s,placeholder:r,...c}=e;return{...I._deserializeConfig(c),minimum:n,maximum:l,integers:s,placeholder:r}}static serializeConfig(e){const{minimum:n,maximum:l,integers:s,placeholder:r,...c}=e;return{...I._serializeConfig(c),minimum:n,maximum:l,integers:s,placeholder:r}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(gl,{field:this})}isSerializedValue(e){return this.isValue(e)}isValue(e){return typeof e=="number"&&!isNaN(e)||e===null}areValuesEqual(e,n){return e===n}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}class ze extends I{minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;super(r),this.minLength=n,this.maxLength=l,this.placeholder=s}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Minimum length",description:"Minimum number of characters",required:!1,id:`${n}minLength`,minimum:0,integers:!0}),showDirectly:!1},{field:new G({label:"Maximum length",description:"Maximum number of characters",required:!1,id:`${n}maxLength`,minimum:1,integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.minLength,l=this.maxLength;return typeof n=="number"&&e.push(s=>{if(s.length<n)return`Minimum ${n} character(s).`}),typeof l=="number"&&e.push(s=>{if(s.length>l)return`Maximum ${l} character(s).`}),e}serialize(){return{...super.serialize(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}config(){return{...super.config(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}static _deserializeConfig(e){const{maxLength:n,minLength:l,placeholder:s,...r}=e;return{...I._deserializeConfig(r),minLength:l,maxLength:n,placeholder:s}}static _serializeConfig(e){const{minLength:n,maxLength:l,placeholder:s,...r}=e;return{...I._serializeConfig(r),minLength:n,maxLength:l,placeholder:s}}getOptions(){return{...super.getOptions(),minLength:this.minLength,maxLength:this.maxLength,placeholder:this.placeholder}}setOptions(e){"minLength"in e&&(this.minLength=e.minLength),"maxLength"in e&&(this.maxLength=e.maxLength),"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}isSerializedValue(e){return typeof e=="string"}isValue(e){return typeof e=="string"}blankValue(){return""}blankSerializedValue(){return""}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const ml=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{c(m),r()},[r,c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.CheckboxGroup.Root,{id:e.id,name:s,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:n,values:l,onValuesChange:u,disabled:h,children:e.options.map((m,C)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.CheckboxGroup.Item,{value:m.value,onBlur:p,children:i.jsx(a.CheckboxGroup.ItemIndicator,{children:i.jsx(a.LuIcon,{icon:H})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:m.label})]},`${e.id}-${m.value}-${C}`))})})});ml.displayName="CheckboxListFieldInput";class ie extends ee{type="checkbox-list";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new ie({...this.getOptions(),id:e})}static deserialize(e){return new ie(e)}static fromConfig(e){return new ie(e)}static deserializeConfig(e){return ie._deserializeConfig(e)}static serializeConfig(e){return ie._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(ml,{field:this})}isSerializedValue(e){if(!Be(e))return!1;const n=new Set(this.options.map(({value:l})=>l));return e.every(l=>n.has(l))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}areValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}}const ri=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),[u,p]=o.useState(!1),m=o.useCallback(g=>{c(g??null),r(),p(!1)},[c,r]),C=o.useCallback(g=>{p(g),g||r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.Popover.Root,{open:u,onOpenChange:C,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:i.jsxs(a.Button,{id:e.id,name:s,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:n,disabled:h,children:[i.jsx(a.Text,{className:"truncate",highContrast:!!l,children:l?l.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd"}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Popover.Content,{align:"start",size:n,children:i.jsx(a.DayPicker,{size:n,required:!1,mode:"single",variant:"solid",selected:l??void 0,onSelect:m})})]})})});ri.displayName="DateFieldInput";class Ne extends I{type="date";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ne({...this.getOptions(),id:e})}static deserialize(e){return new Ne(e)}static fromConfig(e){return new Ne(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}setOptions(e){super.setOptions(e)}serializeValue(e){return e?e.toISOString():null}deserializeValue(e){return e?new Date(e):null}render(){return i.jsx(ri,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:this.isValue(this.deserializeValue(e))}isValue(e){return!(!(e instanceof Date)&&e!==null||e instanceof Date&&isNaN(e.getTime()))}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return!e&&!n?!0:!e||!n?!1:e.getTime()===n.getTime()}}var O=(t=>(t.Text="text",t.Selection="selection",t.Numeric="numeric",t.Temporal="temporal",t.Capture="capture",t.Assessment="assessment",t.Verification="verification",t))(O||{});const Cl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{c(m),r()},[r,c]),p=o.useCallback(m=>{m||r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.Menu.Root,{onOpenChange:p,align:"start",children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{id:e.id,name:s,className:"!justify-between",variant:"surface",type:"button",size:n,accentColor:"base",disabled:h,children:[i.jsx(a.Text,{className:"truncate",highContrast:l&&l.length>0,children:l&&l.length>0?l.join(", "):e.placeholder??"Select one or more..."}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:n,children:i.jsx(a.Menu.Scroll,{children:i.jsxs(a.Menu.MultiSelectGroup,{values:l,onValuesChange:u,children:[i.jsxs(a.Menu.SelectAllItem,{children:[i.jsx(a.Menu.CheckboxItemIndicator,{children:m=>m?i.jsx(a.LuIcon,{icon:Ke}):i.jsx(a.LuIcon,{icon:H})}),"Select all"]}),e.options.map((m,C)=>i.jsxs(a.Menu.MultiSelectItem,{value:m.value,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),m.label]},`${e.id}-${m.value}-${C}`))]})})})]})})});Cl.displayName="MultiSelectFieldInput";class te extends ee{type="multi-select";placeholder;constructor(e){const{placeholder:n,...l}=e;super(l),this.placeholder=n}serialize(){return{...super.serialize(),placeholder:this.placeholder}}config(){return{...super.config(),placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),placeholder:this.placeholder}}duplicate(e){return new te({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new te(e)}static fromConfig(e){return new te(e)}static deserializeConfig(e){const{placeholder:n,...l}=e;return{...ee._deserializeConfig(l),placeholder:n}}static serializeConfig(e){const{placeholder:n,...l}=e;return{...ee._serializeConfig(l),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Cl,{field:this})}isSerializedValue(e){if(!Be(e))return!1;const n=new Set(this.options.map(({value:l})=>l));return e.every(l=>n.has(l))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}areValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const l=new Set(e),s=new Set(n);return l.size===s.size&&l.isSubsetOf(s)}}const yl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useMemo(()=>Array.from({length:e.length},()=>b.v4()),[e.length]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.OneTimePasswordField.Root,{id:e.id,name:s,value:l,onValueChange:u,validationType:"none",disabled:h,orientation:"horizontal",dir:"ltr",type:"text",autoComplete:"off",autoFocus:!1,autoSubmit:!1,className:"p-0.25 flex h-max w-full gap-1 overflow-x-auto",accentColor:"base",variant:"surface",size:n,onBlur:p,children:[m.map(C=>i.jsx(a.OneTimePasswordField.Input,{id:C},C)),i.jsx(a.OneTimePasswordField.HiddenInput,{})]})})});yl.displayName="OTPFieldInput";class ce extends I{type="otp";length;constructor(e){const{length:n,...l}=e;super(l),this.length=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Length",integers:!0,required:!1,minimum:1,maximum:16,id:`${n}length`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.length;return e.push(l=>{if(l.length!=n)return`Must be ${n} characters.`}),e}serialize(){return{...super.serialize(),length:this.length}}config(){return{...super.config(),length:this.length}}getOptions(){return{...super.getOptions(),length:this.length}}duplicate(e){return new ce({...this.getOptions(),id:e})}setOptions(e){"length"in e&&e.length!==void 0&&(this.length=e.length),super.setOptions(e)}static deserialize(e){return new ce(e)}static fromConfig(e){return new ce(e)}static deserializeConfig(e){const{length:n,...l}=e;return{...I._deserializeConfig(l),length:n}}static serializeConfig(e){const{length:n,...l}=e;return{...I._serializeConfig(l),length:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(yl,{field:this})}isSerializedValue(e){return typeof e=="string"}isValue(e){return typeof e=="string"}blankValue(){return""}areValuesEqual(e,n){return e===n}blankSerializedValue(){return""}areSerializedValuesEqual(e,n){return e===n}}const ue={pass:{label:"Pass",icon:Cs},fail:{label:"Fail",icon:Fs},na:{label:"N/A",icon:vs}},Te=Object.keys(ue);class le extends File{uuid;constructor(e,...n){super(...n),this.uuid=e}static from(e,n){return new le(e,[n],n.name,{lastModified:n.lastModified,type:n.type})}}class xe extends Promise{_uuid;constructor(e,n){super(e),this._uuid=n}get uuid(){return this._uuid}set uuid(e){this._uuid=e}static from(e,n){return new xe((l,s)=>{Promise.resolve(e).then(l).catch(s)},n)}then(e,n){const l=super.then(e,n);return l.uuid=this.uuid,l}catch(e){const n=super.catch(e);return n.uuid=this.uuid,n}finally(e){const n=super.finally(e);return n.uuid=this.uuid,n}}function vl(t){return Array.isArray(t)?t.every(e=>e instanceof xe||e instanceof le):!1}function Qe(t,e){const n=new Set(t.map(({uuid:s})=>s)),l=new Set(e.map(({uuid:s})=>s));return n.size===l.size&&n.isSubsetOf(l)}const Fl=o.createContext(()=>{throw new Error("No ImageCapturerProvider found")}),oi=()=>o.useContext(Fl),Vl=o.memo(t=>{const{onCapture:e}=t,[n,l]=o.useState("idle"),[s,r]=o.useState(!1),c=o.useRef(null),f=o.useRef(null),h=o.useRef(null),u=o.useCallback(()=>{h.current&&(h.current.getTracks().forEach(g=>g.stop()),h.current=null),c.current&&(c.current.srcObject=null),l("idle")},[]),p=He.useActiveCallback(async g=>{if(c.current){u(),l("loading");try{const y=await navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:{ideal:"environment"},width:{ideal:1920},height:{ideal:1080}}});if(!g()){u();return}h.current=y,c.current.srcObject=y,await c.current.play(),l("ready")}catch{l("errored")}}},[u]),m=o.useCallback(()=>{const g=c.current,y=f.current;if(!g||!y||g.videoWidth<=0||g.videoHeight<=0)return;const F=Math.min(g.clientWidth/g.videoWidth,g.clientHeight/g.videoHeight);y.style.width=`${g.videoWidth*F}px`,y.style.height=`${g.videoHeight*F}px`,y.getAnimations().forEach(V=>V.cancel()),y.animate([{opacity:.8},{opacity:0}],{duration:250,easing:"ease-out"})},[]),C=He.useActiveCallback(async g=>{if(c.current)try{r(!0);const y=c.current,F=y.videoHeight,V=y.videoWidth,w=Math.max(V,F),M=Math.min(1,1920/w),N=document.createElement("canvas");N.width=Math.round(V*M),N.height=Math.round(F*M);const S=N.getContext("2d");if(!S)throw new Error("Could not setup canvas context.");S.drawImage(y,0,0,N.width,N.height),m();const q=await new Promise((X,A)=>{N.toBlob(J=>J?X(J):A(new Error("Could not convert canvas to blob.")),"image/jpeg",.92)});if(!g())return;const x=new Date,T=`${x.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"short"}).replaceAll(":","-").replaceAll("/","-").replaceAll(",","")}.jpg`,_=new File([q],T,{type:q.type,lastModified:x.getTime()});e?.(_)}catch(y){a.toast.error({title:"Photo not captured",description:y instanceof Error?y.message:"The photo could not be captured."})}finally{r(!1)}},[e,m],{deactivateOnCall:!1});return o.useEffect(()=>(p(),()=>{u()}),[p,u]),i.jsxs("div",{className:"flex max-h-full max-w-full shrink grow flex-col gap-4 overflow-hidden",children:[i.jsxs("div",{className:Y.cx("relative flex shrink grow flex-col items-center justify-center overflow-hidden",{"bg-black":!n}),children:[i.jsx("video",{ref:c,className:"max-h-full max-w-full object-contain",muted:!0,playsInline:!0}),i.jsx("div",{ref:f,"aria-hidden":"true",className:"-translate-1/2 pointer-events-none absolute left-1/2 top-1/2 bg-white opacity-0"}),n==="loading"?i.jsx(a.Spinner,{size:"xl",className:"-translate-1/2 absolute left-1/2 top-1/2"}):null,n==="errored"?i.jsx(a.LuIcon,{icon:We,size:24,className:"-translate-1/2 absolute left-1/2 top-1/2"}):null]}),i.jsx("div",{className:"flex h-max shrink-0 justify-center",children:i.jsx("button",{className:"bg-(--base-1) border-(--base-12) size-16 rounded-full border-[5px] outline-offset-4 transition-transform active:scale-95 active:brightness-110",type:"button",onClick:C,disabled:s})})]})});Vl.displayName="Camera";const wl=o.memo(t=>{const{files:e,onDelete:n,children:l,open:s,onOpenChange:r,defaultOpen:c,modal:f}=t,[h,u]=o.useState(null);o.useEffect(()=>{u(e.length>0?e[0]:null)},[e]);const p=o.useCallback(()=>{h&&Qn.saveAs(h,h.name)},[h]),m=o.useCallback(()=>{if(!h)return;const y=e.indexOf(h);u(y!==0?e[y-1]:e[e.length-1])},[h,e]),C=o.useCallback(()=>{if(!h)return;const y=e.indexOf(h);u(y!==e.length-1?e[y+1]:e[0])},[h,e]),g=o.useCallback(()=>{h&&n?.(h)},[h,n]);return i.jsxs(a.Overlay.Root,{open:s,onOpenChange:r,defaultOpen:c,modal:f,children:[!!l&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:l}),i.jsx(a.Overlay.Content,{onOpenAutoFocus:a.preventDefault,children:i.jsxs("div",{className:"flex size-full flex-col gap-4 p-4",children:[i.jsx(a.ButtonGroup,{className:"flex w-full shrink-0 items-center justify-end gap-2",accentColor:"base",variant:"soft",children:i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{"aria-label":"close",type:"button",children:i.jsx(a.LuIcon,{icon:R})})})}),i.jsx("div",{className:"flex grow items-center justify-center overflow-hidden",children:h?i.jsx(be,{className:"max-h-full max-w-full",file:h}):null}),i.jsxs(a.ButtonGroup,{className:"flex w-full shrink-0 items-center gap-2",accentColor:"base",variant:"soft",children:[i.jsx(a.IconButton,{onClick:p,"aria-label":"download",type:"button",children:i.jsx(a.LuIcon,{icon:ei})}),i.jsxs("div",{className:"flex grow items-center justify-center gap-2 overflow-hidden",children:[i.jsx(a.IconButton,{"aria-label":"previous",onClick:m,type:"button",children:i.jsx(a.LuIcon,{icon:Ze,className:"-rotate-90 rounded-r-none"})}),i.jsx(a.IconButton,{"aria-label":"next",onClick:C,type:"button",children:i.jsx(a.LuIcon,{icon:Ze,className:"rotate-90 rounded-l-none"})})]}),i.jsx(a.IconButton,{"aria-label":"delete",onClick:g,type:"button",children:i.jsx(a.LuIcon,{icon:se})})]})]})})]})});wl.displayName="ImagesViewer";const di=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,onConfirm:c}=t,[f,h]=o.useState([]),u=o.useCallback(g=>{g||h([]),l?.(g)},[l]),p=o.useCallback(g=>{h(y=>[...y,g])},[]),m=o.useCallback(g=>{h(y=>y.filter(F=>F!==g))},[]),C=o.useCallback(()=>{c?.(f)},[f,c]);return i.jsxs(a.Overlay.Root,{open:n,onOpenChange:u,defaultOpen:s,modal:r,children:[!!e&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:e}),i.jsxs(a.Overlay.Content,{onOpenAutoFocus:a.preventDefault,children:[i.jsx(a.Overlay.Title,{className:"sr-only",children:"Image capturer"}),i.jsx(a.Overlay.Description,{className:"sr-only",children:"Capture one or more images."}),i.jsxs("div",{className:"bg-(--color-background) flex size-full flex-col gap-4 overflow-hidden py-4",children:[i.jsxs("div",{className:"flex h-max items-center justify-between gap-4 px-4",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{size:"md",variant:"surface",onClick:C,children:i.jsx(a.LuIcon,{icon:H})})}),f.length>0?i.jsx(wl,{files:f,onDelete:m,children:i.jsxs(a.Button,{variant:"soft",accentColor:"base",children:[f.length," ",f.length>1?"images":"image"]})}):null]}),i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{size:"md",variant:"soft",accentColor:"base",children:i.jsx(a.LuIcon,{icon:R})})})]}),i.jsx(Vl,{onCapture:p})]})]})]})});di.displayName="ImageCapturer";const Sl=o.memo(t=>{const{children:e}=t,[n,l]=o.useState(null),s=o.useCallback(()=>{l(null)},[]),r=o.useCallback(f=>{l(f(s))},[s]),c=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),s())},[s,n]);return i.jsxs(Fl.Provider,{value:r,children:[e,n&&i.jsx(di,{open:!0,onOpenChange:c,onConfirm:n.onConfirm,modal:n.modal})]})});Sl.displayName="ImageCapturerProvider";const ci=o.memo(t=>{const{ref:e,file:n,error:l,rightSlot:s,className:r,size:c,...f}=t;return i.jsxs(a.Card,{className:Y.cx(r,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!l&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(a.Spinner,{size:c})}),!!n&&!l&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(be,{className:"block size-full max-w-full object-cover",file:n})}),!!l&&i.jsx("div",{className:"grow"}),(!!n||!!l)&&i.jsxs(i.Fragment,{children:[i.jsx(a.Separator,{size:"full"}),i.jsxs("div",{className:"flex w-full shrink-0 items-center gap-2 self-end p-3",children:[l?i.jsx(a.LuIcon,{color:"var(--base-11)",icon:We}):n&&i.jsx(a.LuIcon,{color:"var(--base-11)",icon:sl}),i.jsx(a.Text,{className:"truncate",size:c,children:l??n?.name}),s]})]})]})});ci.displayName="ImageCard";const ui=o.memo(t=>{const{file:e,...n}=t,l=ti(e);return i.jsx("video",{src:l??void 0,...n})});ui.displayName="VideoFile";const hi=o.memo(t=>{const{ref:e,file:n,className:l,error:s,rightSlot:r,size:c,...f}=t;return i.jsxs(a.Card,{className:Y.cx(l,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!s&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(a.Spinner,{size:c})}),!!n&&!s&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(ui,{className:"block size-full max-w-full object-cover",file:n,controls:!0})}),!!s&&i.jsx("div",{className:"grow"}),(!!n||!!s)&&i.jsxs(i.Fragment,{children:[i.jsx(a.Separator,{size:"full"}),i.jsxs("div",{className:"flex w-full shrink-0 items-center gap-2 self-end p-3",children:[s?i.jsx(a.LuIcon,{color:"var(--danger-11)",icon:We}):n&&i.jsx(a.LuIcon,{color:"var(--base-11)",icon:Ps}),i.jsx(a.Text,{className:"truncate",size:c,children:s??n?.name}),r]})]})]})});hi.displayName="VideoCard";const fi=o.memo(t=>{const{fileOrPromise:e,onRemove:n,disabled:l,size:s}=t,[r,c]=o.useState(e instanceof xe?null:e),[f,h]=o.useState(null),u=Xe();He.useActiveEffect(w=>{if(h(null),!(e instanceof xe)){c(e);return}c(null),e.then(M=>{w()&&c(M)}).catch(M=>{w()&&h(M instanceof Error?M.message:"Unknown error")})},[e]);const p=o.useCallback(()=>{if(!r)return;const w=new Blob([r]);Qn.saveAs(w,r.name)},[r]),m=o.useCallback(()=>{n(e)},[n,e]),C=o.useCallback(()=>{if(!r)return;const w=URL.createObjectURL(r);window.open(w,"_blank"),URL.revokeObjectURL(w)},[r]),g=o.useCallback(()=>{r&&u(w=>({file:r,onDelete:l?void 0:()=>{m(),w()}}))},[l,m,u,r]),y=o.useMemo(()=>i.jsx("div",{className:"flex grow justify-end",children:i.jsxs(a.Menu.Root,{modal:!0,children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.IconButton,{onClick:a.stopPropagation,type:"button",variant:"ghost",accentColor:"base",size:s,children:i.jsx(a.LuIcon,{icon:al})})}),i.jsxs(a.Menu.Content,{size:s,children:[i.jsxs(a.Menu.Item,{onSelect:p,disabled:!r,children:[i.jsx(a.LuIcon,{icon:ei})," Download"]}),l?null:i.jsxs(i.Fragment,{children:[i.jsx(a.Menu.Separator,{}),i.jsxs(a.Menu.Item,{onSelect:m,children:[i.jsx(a.LuIcon,{icon:se})," Delete"]})]})]})]})}),[l,m,p,r,s]),F=!!r?.type.startsWith("image/"),V=!!r?.type.startsWith("video/");return F?i.jsx(ci,{className:"cursor-pointer",onClick:g,file:r,error:f??void 0,rightSlot:y,size:s}):V?i.jsx(hi,{className:"cursor-pointer",onClick:g,file:r,error:f??void 0,rightSlot:y,size:s}):i.jsx(ii,{className:"cursor-pointer",file:r,error:f??void 0,onClick:C,rightSlot:y,size:s})});fi.displayName="DisplayFile";const bl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=oi(),p=o.useRef(null),m=o.useCallback(x=>{const T=e.cleanValue({...l,status:x});c(T),r()},[e,r,c,l]),C=o.useCallback(x=>{const T=x.target.value,_={...l,notes:T};c(_)},[l,c]),g=o.useCallback(()=>{r()},[r]),y=o.useCallback(x=>{const T=l.files.filter(({uuid:_})=>_!==x.uuid);c({...l,files:T}),r()},[c,r,l]),F=o.useCallback(()=>{u(x=>({onConfirm:T=>{const _=T.map(X=>le.from(b.v4(),X));c({...l,files:[...l.files,..._]}),r()},onClose:()=>{r(),x()}}))},[r,c,l,u]),V=o.useCallback(()=>{p.current?.click()},[]),w=o.useCallback(x=>{const T=Array.from(x.target.files??[]).map(X=>le.from(b.v4(),X)),_={...l,files:[...l.files,...T]};c(_),r()},[r,c,l]);o.useEffect(()=>{if(!p.current)return;const x=new AbortController;return p.current.addEventListener("cancel",()=>{r()},{signal:x.signal}),()=>{x.abort()}},[r,l]);const M=l.status&&e.showNotesAndFilesOn.includes(l.status),N=`${e.id}-status`,S=`${e.id}-notes`,q=`${e.id}-files`;return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(a.RadioGroup.Root,{id:N,className:"flex gap-2",name:s,value:l.status,disabled:h,accentColor:"base",variant:"surface",size:n,onValueChange:m,children:Te.map(x=>{const{label:T}=ue[x];return i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.RadioGroup.Item,{value:x,children:i.jsx(a.RadioGroup.Indicator,{children:i.jsx(a.LuIcon,{icon:il,className:"fill-current"})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:T})]},`${e.id}-${x}`)})}),M&&i.jsxs(i.Fragment,{children:[i.jsx("div",{children:i.jsx(a.TextArea,{id:S,value:l.notes??"",name:s,onChange:C,onBlur:g,className:"field-sizing-content min-h-12 w-full",placeholder:"Notes",resize:"vertical",accentColor:"base",variant:"surface",size:n,disabled:h})}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{className:"w-max",size:n,variant:"surface",accentColor:"base",type:"button",disabled:h,children:[i.jsx(a.LuIcon,{icon:ni}),"Select files"]})}),i.jsxs(a.Menu.Content,{size:n,children:[i.jsxs(a.Menu.Item,{onSelect:F,children:[i.jsx(a.LuIcon,{icon:nl}),"Take photos"]}),i.jsxs(a.Menu.Item,{onSelect:V,children:[i.jsx(a.LuIcon,{icon:dl}),"Attach files"]})]})]}),i.jsx("input",{id:q,name:s,type:"file",ref:p,multiple:!0,className:"hidden",onChange:w,value:""}),l.files.length>0&&i.jsx("div",{className:"flex h-max flex-wrap gap-2",children:l.files.map(x=>i.jsx(fi,{size:n,fileOrPromise:x,onRemove:y,disabled:h},x.uuid))})]})]})]})})});bl.displayName="PassFailFieldInput";const pi=t=>typeof t=="string"&&Te.includes(t),zl=t=>!(t===null||typeof t!="object"||!("status"in t)||!pi(t.status)||!("notes"in t)||typeof t.notes!="string"||!("files"in t)||!(Array.isArray(t.files)&&t.files.length===0)),Nl=t=>!(t===null||typeof t!="object"||!("status"in t)||!pi(t.status)||!("notes"in t)||typeof t.notes!="string"||!("files"in t)||!vl(t.files)),xl=t=>({status:t.status,notes:t.notes,files:[]}),Il=t=>({status:t.status,notes:t.notes,files:[]}),Ml=(t,e)=>!(t.status!==e.status||t.notes!==e.notes||!Qe(t.files,e.files)),ql=(t,e)=>!(t.status!==e.status||t.notes!==e.notes||t.files.length!==e.files.length);class he extends I{type="pass-fail";showNotesAndFilesOn;constructor(e){const{showNotesAndFilesOn:n,...l}=e;super(l),this.showNotesAndFilesOn=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new te({id:`${n}showNotesAndFilesOn`,label:"Show notes and files on",description:"Show the notes and files on desired statuses.",options:Te.map(l=>{const{label:s}=ue[l];return{value:l,label:s}}),required:!1}),showDirectly:!1}]}serialize(){return{...super.serialize(),showNotesAndFilesOn:this.showNotesAndFilesOn}}config(){return{...super.config(),showNotesAndFilesOn:this.showNotesAndFilesOn}}getOptions(){return{...super.getOptions(),showNotesAndFilesOn:this.showNotesAndFilesOn}}duplicate(e){return new he({...this.getOptions(),id:e})}setOptions(e){"showNotesAndFilesOn"in e&&e.showNotesAndFilesOn!==void 0&&(this.showNotesAndFilesOn=e.showNotesAndFilesOn),super.setOptions(e)}getFieldValidators(){const e=super.getFieldValidators(),n=this.showNotesAndFilesOn,l=this.blankValue();return n.length>0&&(e.push(s=>{if(!(!s.status||!n.includes(s.status))&&l.notes===s.notes)return"Notes is required."}),e.push(s=>{if(!(!s.status||!n.includes(s.status))&&Qe(l.files,s.files))return"Files is required."})),e}static deserialize(e){const{showNotesAndFilesOn:n,...l}=e;return new he({...l,showNotesAndFilesOn:n})}static fromConfig(e){return new he(e)}static deserializeConfig(e){const{showNotesAndFilesOn:n,...l}=e;return{...I._deserializeConfig(l),showNotesAndFilesOn:n}}static serializeConfig(e){const{showNotesAndFilesOn:n,...l}=e;return{...I._serializeConfig(l),showNotesAndFilesOn:n}}serializeValue(e){return xl(e)}deserializeValue(e){return Il(e)}render(){return i.jsx(bl,{field:this})}isSerializedValue(e){return zl(e)}isValue(e){return Nl(e)}areValuesEqual(e,n){return Ml(e,n)}blankValue(){return{status:null,notes:"",files:[]}}cleanValue(e){return e.status&&this.showNotesAndFilesOn.includes(e.status)?e:{status:e.status,notes:"",files:[]}}cleanSerializedValue(e){return super.cleanSerializedValue(e)}blankSerializedValue(){return{status:null,notes:"",files:[]}}areSerializedValuesEqual(e,n){return ql(e,n)}}const Ol=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C),r()},[r,c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(()=>{c(null),r()},[r,c]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.RadioGroup.Root,{id:e.id,name:s,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:n,value:l??"",onValueChange:u,disabled:h,children:[e.options.map((C,g)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.RadioGroup.Item,{value:C.value,onBlur:p,children:i.jsx(a.RadioGroup.Indicator,{children:i.jsx(a.LuIcon,{icon:il,className:"fill-current"})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:C.label})]},`${e.id}-${C.value}-${g}`)),!!l&&i.jsxs(a.Button,{onClick:m,className:"-mx-2 w-max",type:"button",variant:"ghost",accentColor:"base",size:n,children:[i.jsx(a.LuIcon,{icon:R}),"Clear"]})]})})});Ol.displayName="RadioFieldInput";class fe extends ee{type="radio";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new fe({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new fe(e)}static fromConfig(e){return new fe(e)}static deserializeConfig(e){return ee._deserializeConfig(e)}static serializeConfig(e){return ee._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Ol,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:l})=>l)]).has(e)}isValue(e){return this.isSerializedValue(e)}blankValue(){return null}areValuesEqual(e,n){return e===n}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}const $s=Y.cva(["group flex cursor-pointer items-center justify-center text-yellow-500 transition-colors disabled:pointer-events-none disabled:opacity-50"],{variants:{size:{xs:["size-5"],sm:["size-6"],md:["size-7"],lg:["size-8"],xl:["size-9"]}}}),Tl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C),r()},[r,c]),p=o.useCallback(()=>{c(null),r()},[r,c]),m=Array.from({length:e.maxRating},(C,g)=>g+1);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs("div",{className:"flex flex-row items-center gap-1",children:[i.jsx(a.Rating.Root,{id:e.id,name:s,className:"flex items-center gap-0.5",value:l,onValueChange:u,disabled:h,children:m.map(C=>i.jsx(a.Rating.Item,{value:C,className:$s({size:n}),children:i.jsx(a.LuIcon,{icon:cl,className:"size-full group-data-[active=true]:fill-current"})},`${e.id}-${C}`))}),!h&&l!==null&&i.jsx(a.IconButton,{onClick:p,type:"button",variant:"ghost",accentColor:"base",size:n,children:i.jsx(a.LuIcon,{icon:R})})]})})});Tl.displayName="RatingFieldInput";class pe extends I{type="rating";maxRating;constructor(e){const{maxRating:n,...l}=e;super(l),this.maxRating=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"Max Rating",description:"Maximum rating value",integers:!0,required:!1,minimum:1,maximum:10,id:`${n}maxRating`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.maxRating;return e.push(l=>{if(typeof l=="number"&&(l<1||l>n))return`Rating must be between 1 and ${n}.`}),e}serialize(){return{...super.serialize(),maxRating:this.maxRating}}config(){return{...super.config(),maxRating:this.maxRating}}getOptions(){return{...super.getOptions(),maxRating:this.maxRating}}duplicate(e){return new pe({...this.getOptions(),id:e})}setOptions(e){"maxRating"in e&&e.maxRating!==void 0&&(this.maxRating=e.maxRating),super.setOptions(e)}static deserialize(e){return new pe(e)}static fromConfig(e){return new pe(e)}static deserializeConfig(e){const{maxRating:n,...l}=e;return{...I._deserializeConfig(l),maxRating:n}}static serializeConfig(e){const{maxRating:n,...l}=e;return{...I._serializeConfig(l),maxRating:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Tl,{field:this})}isSerializedValue(e){return this.isValue(e)}isValue(e){return typeof e=="number"&&!isNaN(e)||e===null}areValuesEqual(e,n){return e===n}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}const gi=o.createContext(null),El=()=>{const t=o.use(gi);if(!t)throw new Error("useScannerContext must be used within a component tree wrapped by ScannerProvider.");return t},ks=()=>{const t=o.use(gi);if(!t)throw new Error("useScanner must be used within a component tree wrapped by ScannerProvider.");return t.openScanner},Re=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,...c}=t;return i.jsxs(a.Overlay.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[!!e&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:e}),i.jsxs(a.Overlay.Content,{children:[i.jsx(a.Overlay.Title,{className:"sr-only",children:"Scanner"}),i.jsx(a.Overlay.Description,{className:"sr-only",children:"Scan a barcode or a qr code."}),i.jsx(Ll,{...c})]})]})});Re.displayName="Scanner";const Ll=o.memo(t=>{const{paused:e,formats:n,timeBetweenDecodingAttempts:l,trySkew:s,onDecodeResult:r,onDecodeError:c,onError:f}=t,{wasmUrl:h}=El(),{ref:u}=ls.useZxing({wasmUrl:h,paused:e,formats:n,timeBetweenDecodingAttempts:l,trySkew:s,onDecodeResult:r,onDecodeError:c,onError:f,constraints:{video:{width:{ideal:1920,min:1280},height:{ideal:1080,min:720},aspectRatio:{ideal:16/9},facingMode:"environment"}}});return i.jsxs("div",{className:"bg-(--color-background) flex size-full flex-col justify-center overflow-hidden",children:[i.jsx("div",{className:"flex w-full justify-end p-4",children:i.jsx(a.Overlay.Close,{asChild:!0,children:i.jsx(a.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:i.jsx(a.LuIcon,{icon:R})})})}),i.jsx("div",{className:"max-h-full w-full grow overflow-hidden p-4",children:i.jsx("video",{className:"size-full",ref:u,muted:!0,playsInline:!0})})]})});Ll.displayName="ScannerInternal";const Al=o.memo(t=>{const{children:e,wasmUrl:n}=t,[l,s]=o.useState(null),r=o.useCallback(()=>{s(null)},[]),c=o.useCallback(u=>{s(u(r))},[r]),f=o.useCallback(()=>{l&&(l.onClose&&l.onClose(),r())},[r,l]),h=o.useMemo(()=>({wasmUrl:n,openScanner:c}),[n,c]);return i.jsxs(gi,{value:h,children:[e,l&&i.jsx(Re,{open:!0,onOpenChange:f,...l})]})});Al.displayName="ScannerProvider";const Bl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),[u,p]=o.useState(!1),m=o.useCallback(V=>{const w=V.target.value;c(w)},[c]),C=o.useCallback(()=>{r()},[r]),g=o.useCallback(V=>{c(V.rawValue.trim()),r(),p(!1)},[c,r]),y=o.useCallback(()=>{p(!0)},[]),F=o.useCallback(()=>{p(!1),r()},[r]);return i.jsxs(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:[i.jsx(a.TextArea,{className:"field-sizing-content w-full",accentColor:"base",variant:"surface",size:n,id:e.id,name:s,value:l??"",placeholder:"Enter a qr or barcode",onChange:m,onBlur:C,disabled:h}),i.jsxs(a.Button,{onClick:y,className:"w-max",type:"button",variant:"soft",size:n,accentColor:"base",disabled:h,children:[i.jsx(a.LuIcon,{icon:Os}),"Scan"]}),i.jsx(Re,{open:u,onDecodeResult:g,onOpenChange:F})]})});Bl.displayName="ScanFieldInput";class Ie extends I{type="qr";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ie({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new Ie(e)}static fromConfig(e){return new Ie(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Bl,{field:this})}isSerializedValue(e){return typeof e=="string"}isValue(e){return typeof e=="string"}blankValue(){return""}areValuesEqual(e,n){return e===n}blankSerializedValue(){return""}areSerializedValuesEqual(e,n){return e===n}}const _l=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{c(C??null),r()},[r,c]),p=o.useCallback(C=>{C||r()},[r]),m=o.useMemo(()=>e.options.find(C=>C.value===l),[e.options,l]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(a.Menu.Root,{onOpenChange:p,align:"start",children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{id:e.id,name:s,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:n,disabled:h,children:[i.jsx(a.Text,{className:"truncate",highContrast:!!m,children:m?m.label:e.placeholder??"Select one..."}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:n,children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!1,value:l??void 0,onValueChange:u,children:e.options.map((C,g)=>i.jsxs(a.Menu.SelectItem,{value:C.value,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),C.label]},`${e.id}-${C.value}-${g}`))})})})]})})});_l.displayName="SelectFieldInput";class ge extends ee{type="select";placeholder;constructor(e){const{placeholder:n,...l}=e;super(l),this.placeholder=n}serialize(){return{...super.serialize(),placeholder:this.placeholder}}config(){return{...super.config(),placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),placeholder:this.placeholder}}duplicate(e){return new ge({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new ge(e)}static fromConfig(e){return new ge(e)}static deserializeConfig(e){const{placeholder:n,...l}=e;return{...ee._deserializeConfig(l),placeholder:n}}static serializeConfig(e){const{placeholder:n,...l}=e;return{...ee._serializeConfig(l),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(_l,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:l})=>l)]).has(e)}isValue(e){return this.isSerializedValue(e)}blankValue(){return null}areValuesEqual(e,n){return e===n}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}}const Dl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(C=>{const g=C.target.value;c(g)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(C=>{C.key==="Enter"&&C.preventDefault()},[]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.Input.Root,{accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{id:e.id,className:"truncate",name:s,value:l??"",type:"text",placeholder:e.placeholder??"Enter a short description",onChange:u,onBlur:p,disabled:h,onKeyDown:m})})})});Dl.displayName="StringFieldInput";class me extends ze{type="string";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new me({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new me(e)}static fromConfig(e){return new me(e)}static deserializeConfig(e){return ze._deserializeConfig(e)}static serializeConfig(e){return ze._serializeConfig(e)}render(){return i.jsx(Dl,{field:this})}}const Pl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(m=>{const C=m.target.value;c(C)},[c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(a.TextArea,{id:e.id,value:l??"",name:s,onChange:u,onBlur:p,className:"field-sizing-content min-h-12",placeholder:e.placeholder??"Enter a description",resize:"vertical",accentColor:"base",variant:"surface",size:n,disabled:h})})});Pl.displayName="TextFieldInput";class Ce extends ze{type="text";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ce({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new Ce(e)}static fromConfig(e){return new Ce(e)}static deserializeConfig(e){return ze._deserializeConfig(e)}static serializeConfig(e){return ze._serializeConfig(e)}render(){return i.jsx(Pl,{field:this})}}const mi=js(),$l=new Set(mi);function js(t=!0){const e=new Set;for(let n=-12;n<=14;n++){const l=n>=0?"+":"-",s=Math.abs(n).toString().padStart(2,"0");e.add(`${l}${s}:00`)}if(t){const n=[-12.5,-9.5,-3.5,3.5,4.5,5.5,6.5,9.5,10.5,12.5];for(const l of n){const s=l>=0?"+":"-",r=Math.floor(Math.abs(l)).toString().padStart(2,"0");e.add(`${s}${r}:30`)}}return Array.from(e).sort((n,l)=>kl(n)-kl(l))}function kl(t){const e=t[0]==="+"?1:-1,n=Number(t.slice(1,3)),l=Number(t.slice(4,6));return e*(n*60+l)}const Us="+00:00",Gs=/^T([01]\d|2[0-3]):([0-5]\d):00([+-]\d{2}:\d{2})$/,en=t=>typeof t=="string"&&$l.has(t),jl=()=>{const t=-new Date().getTimezoneOffset(),e=t>=0?"+":"-",n=Math.abs(t),l=Math.floor(n/60),s=n%60,r=`${e}${l.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`;return en(r)?r:Us};function Ul(t){const e=/^([+-])(\d{2}):(\d{2})$/.exec(t);if(!e)throw new Error(`Invalid UTC offset: ${t}`);return(e[1]==="+"?1:-1)*(Number(e[2])*60+Number(e[3]))}const De=t=>{const e=Gs.exec(t);if(!e)return null;const n=e[3];return en(n)?{hours:Number(e[1]),minutes:Number(e[2]),utcOffset:n}:null},ne=t=>typeof t=="string"&&De(t)!==null,ye=(t,e,n=jl())=>{if(!Number.isInteger(t)||t<0||t>23)throw new Error(`Invalid hour: ${t}`);if(!Number.isInteger(e)||e<0||e>59)throw new Error(`Invalid minute: ${e}`);if(!en(n))throw new Error("Unsupported UTC offset");const l=t.toString().padStart(2,"0"),s=e.toString().padStart(2,"0");return`T${l}:${s}:00${n}`},nn=t=>`UTC${t}`,ve=t=>{const e=De(t);if(!e)throw new Error(`Invalid time value: ${t}`);return(e.hours*60+e.minutes-Ul(e.utcOffset)+1440)%1440},tn=(t,e=!0)=>{const n=De(t);if(!n)throw new Error(`Invalid time value: ${t}`);const l=(n.hours%12||12).toString().padStart(2,"0"),s=n.minutes.toString().padStart(2,"0"),r=n.hours>=12?"PM":"AM",c=`${l}:${s} ${r}`;return e?`${c} ${nn(n.utcOffset)}`:c},Js=t=>typeof t=="object"&&(ne(t.from)||ne(t.to)),Ci=(t,e)=>{const n=ve(t),l=e.from?ve(e.from):null,s=e.to?ve(e.to):null;return l===null&&s===null?!0:l===null?n<=s:s===null?n>=l:l<=s?n>=l&&n<=s:n>=l||n<=s},ln=o.memo(t=>{const{value:e,onChange:n,onBlur:l,disabled:s,size:r="md",id:c,name:f,compact:h=!1}=t,u=e?De(e):null,p=u?`${u.hours.toString().padStart(2,"0")}:${u.minutes.toString().padStart(2,"0")}`:"",m=o.useCallback(y=>{const F=y.target.value;if(!F){n(null);return}const[V,w]=F.split(":").map(Number);n(ye(V,w,u?.utcOffset))},[n,u?.utcOffset]),C=o.useCallback(y=>{u&&(n(ye(u.hours,u.minutes,y)),l?.())},[l,n,u]),g=o.useCallback(y=>{y||l?.()},[l]);return i.jsxs("div",{className:"flex min-w-0 gap-2",children:[i.jsx(a.Input.Root,{className:"min-w-0 grow",accentColor:"base",variant:"surface",size:r,children:i.jsx(a.Input.Field,{id:c,name:f,className:Y.cx("[&::-webkit-calendar-picker-indicator]:invert-40 dark:[&::-webkit-calendar-picker-indicator]:invert-60",{"[&::-webkit-datetime-edit]:opacity-60":!e}),type:"time",step:60,value:p,onChange:m,onBlur:l,disabled:s})}),i.jsxs(a.Menu.Root,{align:"end",onOpenChange:g,children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",className:h?"!justify-between":"min-w-32 !justify-between",accentColor:"base",variant:"surface",size:r,disabled:s||!u,children:[i.jsx(a.Text,{className:"truncate",highContrast:!!u,children:u?nn(u.utcOffset):"UTC offset"}),i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:r,children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!0,value:u?.utcOffset,onValueChange:C,children:mi.map(y=>i.jsxs(a.Menu.SelectItem,{value:y,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),nn(y)]},y))})})})]})]})});ln.displayName="TimeFieldControl";const yi=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e});return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(ln,{id:e.id,name:s,size:n,value:l,onChange:c,onBlur:r,disabled:h})})});yi.displayName="TimeFieldInput";class Me extends I{type="time";constructor(e){super(e)}static deserialize(e){return new Me(e)}static fromConfig(e){return new Me(e)}static deserializeConfig(e){return I._deserializeConfig(e)}static serializeConfig(e){return I._serializeConfig(e)}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Me({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(yi,{field:this})}isSerializedValue(e){return e===null||ne(e)}isValue(e){return e===null||ne(e)}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const Gl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=oi(),p=o.useRef(null),m=o.useCallback(()=>{u(N=>({onConfirm:S=>{const q=Array.from(S).map(T=>le.from(b.v4(),T)),x=[...l,...q];c(x),r()},onClose:()=>{r(),N()}}))},[r,c,l,u]),C=o.useCallback(()=>{p.current?.click()},[]),g=o.useCallback(()=>{if(!p.current)return;const N=p.current.files;if(!N){r();return}const S=Array.from(N).map(x=>le.from(b.v4(),x)),q=[...l,...S];c(q),r()},[r,c,l]),y=o.useCallback(N=>{const S=l.filter(({uuid:q})=>q!==N.uuid);c(S),r()},[l,c,r]);o.useEffect(()=>{if(!p.current)return;const N=new AbortController;return p.current.addEventListener("cancel",()=>{r()},{signal:N.signal}),()=>{N.abort()}},[r,l]);const F=e.maxFiles!==1,M=F?"Select files":"Select a file";return i.jsxs(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:[i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{className:"w-max",size:n,variant:"surface",accentColor:"base",type:"button",disabled:h,children:[i.jsx(a.LuIcon,{icon:ni}),M]})}),i.jsxs(a.Menu.Content,{size:n,children:[i.jsxs(a.Menu.Item,{onSelect:m,children:[i.jsx(a.LuIcon,{icon:nl}),"Take photos"]}),i.jsxs(a.Menu.Item,{onSelect:C,children:[i.jsx(a.LuIcon,{icon:dl}),"Attach files"]})]})]}),i.jsx("input",{id:e.id,name:s,type:"file",ref:p,accept:e.extensions?.join(","),multiple:F,className:"hidden",onChange:g,value:""}),l.length>0&&i.jsx("div",{className:"mt-1 flex h-max flex-col gap-2",children:l.map(N=>i.jsx(fi,{size:n,fileOrPromise:N,onRemove:y,disabled:h},N.uuid))})]})});Gl.displayName="UploadFieldInput";class Fe extends I{type="upload";extensions;maxSize;maxFiles;constructor(e){const{extensions:n,maxFiles:l,maxSize:s,...r}=e;super(r),this.maxSize=s,this.maxFiles=l,this.extensions=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new G({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:0,id:`${n}maxFiles`,integers:!0}),showDirectly:!1},{field:new G({label:"What is the maximum size of each file?",description:"Maximum file size in MB.",required:!1,id:`${n}maxSize`,minimum:0,integers:!0}),showDirectly:!1},{field:new te({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,id:`${n}extensions`,options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.maxSize,l=n&&n*1e3*1e3,s=this.maxFiles;return typeof n=="number"&&typeof l=="number"&&e.push(r=>{if(r.some(c=>c instanceof le&&c.size>l))return`Files must be at most ${n}MB.`}),typeof s=="number"&&e.push(r=>{if(r.length>s)return`You can only upload ${s} files.`}),e}serialize(){return{...super.serialize(),extensions:this.extensions,maxSize:this.maxSize,maxFiles:this.maxFiles}}config(){return{...super.config(),extensions:this.extensions,maxSize:this.maxSize,maxFiles:this.maxFiles}}getOptions(){return{...super.getOptions(),extensions:this.extensions,maxSize:this.maxSize,maxFiles:this.maxFiles}}duplicate(e){return new Fe({...this.getOptions(),id:e})}setOptions(e){"maxSize"in e&&(this.maxSize=e.maxSize),"maxFiles"in e&&(this.maxFiles=e.maxFiles),"extensions"in e&&(this.extensions=e.extensions),super.setOptions(e)}static deserialize(e){return new Fe(e)}static fromConfig(e){return new Fe(e)}static deserializeConfig(e){const{extensions:n,maxSize:l,maxFiles:s,...r}=e;return{...I._deserializeConfig(r),extensions:n,maxSize:l,maxFiles:s}}static serializeConfig(e){const{extensions:n,maxSize:l,maxFiles:s,...r}=e;return{...I._serializeConfig(r),extensions:n,maxSize:l,maxFiles:s}}serializeValue(e){return[]}deserializeValue(e){return[]}render(){return i.jsx(Gl,{field:this})}isSerializedValue(e){return Array.isArray(e)&&e.length===0}isValue(e){return Array.isArray(e)?e.every(n=>n instanceof xe||n instanceof le):!1}areValuesEqual(e,n){return Qe(e,n)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){return e.length===n.length}}const Jl=o.memo(t=>{const{field:e}=t,{size:n}=o.use(B),{value:l,name:s,onBlur:r,onChange:c,error:f,disabled:h}=$({field:e}),u=o.useCallback(g=>{const y=g.target.value;y!==""&&!URL.canParse(y)||c(y!==""?new URL(y):null)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(g=>{g.key==="Enter"&&g.preventDefault()},[]),C=o.useCallback(()=>{l!==null&&window.open(l,"_blank","noopener,noreferrer")},[l]);return i.jsx(D,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs("div",{className:"flex w-full gap-2",children:[i.jsx(a.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:n,children:i.jsx(a.Input.Field,{id:e.id,className:"truncate",name:s,value:l?l.toString():"",type:"url",inputMode:"url",placeholder:e.placeholder??"https://example.com",onChange:u,onBlur:p,disabled:h,onKeyDown:m})}),i.jsx(a.IconButton,{size:n,variant:"soft",accentColor:"base",type:"button",disabled:l===null,onClick:C,children:i.jsx(a.LuIcon,{icon:Ss})})]})})});Jl.displayName="URLFieldInput";class qe extends I{type="url";placeholder;constructor(e){const{placeholder:n,...l}=e;super(l),this.placeholder=n}serialize(){return{...super.serialize(),placeholder:this.placeholder}}config(){return{...super.config(),placeholder:this.placeholder}}getOptions(){return{...super.getOptions(),placeholder:this.placeholder}}duplicate(e){return new qe({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new qe(e)}static fromConfig(e){return new qe(e)}static deserializeConfig(e){const{placeholder:n,...l}=e;return{...I._deserializeConfig(l),placeholder:n}}static serializeConfig(e){const{placeholder:n,...l}=e;return{...I._serializeConfig(l),placeholder:n}}serializeValue(e){return e?.toString()??null}deserializeValue(e){return e===null?null:new URL(e)}isSerializedValue(e){return e===null?!0:typeof e!="string"?!1:URL.canParse(e)}isValue(e){return e===null||e instanceof URL}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e?.toString()===n?.toString()}render(){return i.jsx(Jl,{field:this})}}const Ee={date:Ne,time:Me,number:G,boolean:de,select:ge,string:me,url:qe,text:Ce,upload:Fe,qr:Ie,"multi-string":re,"multi-select":te,radio:fe,"checkbox-list":ie,"pass-fail":he,otp:ce,rating:pe},Hl=Object.keys(Ee),L={"checkbox-list":{description:"Allows the user to select a multiple options from a list.",group:O.Selection,icon:ws,name:"Checkbox list"},"multi-select":{description:"Allows the user to select a multiple options from a list of options.",group:O.Selection,icon:Is,name:"Multi-select"},"multi-string":{description:"Allows the user to provide multiple unique strings.",group:O.Text,icon:qs,name:"Multi-string"},"pass-fail":{description:"Track pass, fail, or N/A outcome.",group:O.Assessment,icon:Vs,name:"Pass - Fail"},boolean:{description:"Perfect for both optional and required yes/no questions.",group:O.Selection,icon:As,name:"Checkbox"},date:{description:"Allows specifying a date.",group:O.Temporal,icon:ms,name:"Date"},time:{description:"Allows specifying a time and UTC offset.",group:O.Temporal,icon:Ds,name:"Time"},number:{description:"Allows specifying a number within a given range.",group:O.Numeric,icon:Ns,name:"Number"},otp:{description:"Allows specifying a number within a given range.",group:O.Verification,icon:Ts,name:"OTP"},qr:{description:"Used for scanning/reading QR and barcodes.",group:O.Capture,icon:Es,name:"Scan"},radio:{description:"Allows the user to select a single option from a list of options.",group:O.Selection,icon:ys,name:"Option list"},rating:{description:"Allows users to select a rating value.",group:O.Assessment,icon:cl,name:"Rating"},select:{description:"Allows the user to select a single option from a list of options.",group:O.Selection,icon:Ms,name:"Dropdown"},string:{description:"Short text fields can hold up to 500 characters on a single line.",group:O.Text,icon:_s,name:"Short Text"},text:{description:"Paragraph fields can hold up to 10000 characters and can have multiple lines.",group:O.Text,icon:fs,name:"Paragraph"},upload:{description:"Allows a file to be uploaded.",group:O.Capture,icon:ni,name:"Upload"},url:{description:"Allows users to enter a URL.",group:O.Text,icon:xs,name:"URL"}},Wl={[O.Assessment]:{name:"Assessment"},[O.Capture]:{name:"Capture"},[O.Numeric]:{name:"Numeric"},[O.Selection]:{name:"Selection"},[O.Temporal]:{name:"Temporal"},[O.Text]:{name:"Text"},[O.Verification]:{name:"Verification"}},P="Unlabelled",an="Unlabelled";class vi extends _e{id;constructor(e){const{id:n}=e;super(),this.id=n}serialize(){return{id:this.id,type:this.type}}}class v extends vi{value;field;constructor(e){const{field:n,value:l,...s}=e;super(s),this.value=l,this.field=n}serialize(){return{...super.serialize(),value:this.serializeValue(),modifier:this.modifier,field:this.field.id}}getValue=()=>this.value;setValue=e=>{this.value=e,this.notify(this)};getApplyFn(){const e=this.getValueApplyFn();return n=>{const l=this.accessorFn(n);return this.isApplicable(l)?e(l):!1}}isApplicable=e=>this.field.isValue(e);accessorFn=e=>e[this.field.id]}class sn extends v{type="boolean";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class Fi extends v{type="boolean";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}const rn={equals:{klass:sn,label:"is",isTransferable:t=>!0,defaultValue:()=>!0},notEquals:{klass:Fi,label:"is not",isTransferable:t=>!0,defaultValue:()=>!0}};class on extends v{type="checkbox-list";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size===s.size&&s.isSubsetOf(l)}}}class Vi extends v{type="checkbox-list";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size!==s.size||!s.isSubsetOf(l)}}}class wi extends v{type="checkbox-list";modifier="every";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isSubsetOf(s)}}}class Si extends v{type="checkbox-list";modifier="some";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return!l.isDisjointFrom(s)}}}class bi extends v{type="checkbox-list";modifier="none";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isDisjointFrom(s)}}}const dn={equals:{klass:on,label:"is",isTransferable:t=>!0,defaultValue:()=>[]},notEquals:{klass:Vi,label:"is not",isTransferable:t=>!0,defaultValue:()=>[]},every:{klass:wi,label:"has all of",isTransferable:t=>!0,defaultValue:()=>[]},some:{klass:Si,label:"has any of",isTransferable:t=>!0,defaultValue:()=>[]},none:{klass:bi,label:"has none of",isTransferable:t=>!0,defaultValue:()=>[]}};class Pe extends vi{type="compound";conditions;constructor(e){const{conditions:n,...l}=e;super(l),this.conditions=this.initConditions(n)}conditionObserver=()=>{this.conditions=[...this.conditions],this.notify(this)};initConditions=e=>{for(const n of e)n.observe(this.conditionObserver);return e};serialize(){return{...super.serialize(),operator:this.operator,conditions:this.conditions.map(e=>e.serialize())}}isEmpty(){return this.conditions.length===0?!0:this.conditions.every(e=>e.type==="compound"&&e.isEmpty())}addCondition(e){this.conditions=this.initConditions([...this.conditions,e]),this.notify(this)}addConditions(e){this.conditions=this.initConditions([...this.conditions,...e]),this.notify(this)}replaceCondition(e,n){this.conditions=this.initConditions(this.conditions.map(l=>l.id===e.id?n:l)),this.notify(this)}removeCondition(e){this.conditions=this.initConditions(this.conditions.filter(n=>n.id!==e.id)),this.notify(this)}}class $e extends Pe{operator="and";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:e.every(s=>s(l))}}class zi extends Pe{operator="or";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:e.some(s=>s(l))}}class Ni extends Pe{operator="nand";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:!e.every(s=>s(l))}}class xi extends Pe{operator="nor";getApplyFn(){const e=this.conditions.map(l=>l.getApplyFn()),n=this.isEmpty();return l=>n?!0:!e.some(s=>s(l))}}const ke={and:{label:"AND",blurb:"All conditions match",klass:$e},or:{label:"OR",blurb:"At least one condition matches",klass:zi},nand:{label:"NAND",blurb:"At least one condition does not match",klass:Ni},nor:{label:"NOR",blurb:"No conditions match",klass:xi}};class cn extends v{type="date";modifier="equals";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()===e.getTime()}}class Ii extends v{type="date";modifier="notEquals";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()!==e.getTime()}}class Mi extends v{type="date";modifier="before";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()<e.getTime()}}class qi extends v{type="date";modifier="after";serializeValue(){return this.value.toISOString()}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()>e.getTime()}}class Oi extends v{type="date";modifier="in";serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getValueApplyFn(){const e=this.value;return n=>!(n===null||e.from&&e.from.getTime()>n.getTime()||e.to&&e.to.getTime()<n.getTime())}}class Ti extends v{type="date";modifier="notIn";serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getValueApplyFn(){const e=this.value;return n=>n===null?!1:!!(e.from&&e.from.getTime()>n.getTime()||e.to&&e.to.getTime()<n.getTime())}}const un={equals:{klass:cn,label:"is",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},notEquals:{klass:Ii,label:"is not",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},before:{klass:Mi,label:"before",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},after:{klass:qi,label:"after",isTransferable:t=>t instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},in:{klass:Oi,label:"in between",isTransferable:t=>!(t instanceof Date),defaultValue:()=>({from:void 0,to:void 0})},notIn:{klass:Ti,label:"not in between",isTransferable:t=>!(t instanceof Date),defaultValue:()=>({from:void 0,to:void 0})}};class hn extends v{type="multi-select";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size===s.size&&s.isSubsetOf(l)}}}class Ei extends v{type="multi-select";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size!==s.size||!s.isSubsetOf(l)}}}class Li extends v{type="multi-select";modifier="every";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isSubsetOf(s)}}}class Ai extends v{type="multi-select";modifier="some";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return!l.isDisjointFrom(s)}}}class Bi extends v{type="multi-select";modifier="none";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isDisjointFrom(s)}}}const fn={equals:{klass:hn,label:"is",isTransferable:t=>!0,defaultValue:()=>[]},notEquals:{klass:Ei,label:"is not",isTransferable:t=>!0,defaultValue:()=>[]},every:{klass:Li,label:"has all of",isTransferable:t=>!0,defaultValue:()=>[]},some:{klass:Ai,label:"has any of",isTransferable:t=>!0,defaultValue:()=>[]},none:{klass:Bi,label:"has none of",isTransferable:t=>!0,defaultValue:()=>[]}};class pn extends v{type="multi-string";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size===s.size&&s.isSubsetOf(l)}}}class _i extends v{type="multi-string";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.size!==s.size||!s.isSubsetOf(l)}}}class Di extends v{type="multi-string";modifier="every";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isSubsetOf(s)}}}class Pi extends v{type="multi-string";modifier="some";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return!l.isDisjointFrom(s)}}}class $i extends v{type="multi-string";modifier="none";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>{const l=new Set(e),s=new Set(n);return l.isDisjointFrom(s)}}}const gn={equals:{klass:pn,label:"is",isTransferable:t=>!0,defaultValue:()=>[]},notEquals:{klass:_i,label:"is not",isTransferable:t=>!0,defaultValue:()=>[]},every:{klass:Di,label:"has all of",isTransferable:t=>!0,defaultValue:()=>[]},some:{klass:Pi,label:"has any of",isTransferable:t=>!0,defaultValue:()=>[]},none:{klass:$i,label:"has none of",isTransferable:t=>!0,defaultValue:()=>[]}};class mn extends v{type="number";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class ki extends v{type="number";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class ji extends v{type="number";modifier="lessThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<e}}class Ui extends v{type="number";modifier="lessThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<=e}}class Gi extends v{type="number";modifier="greaterThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>e}}class Ji extends v{type="number";modifier="greaterThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>=e}}class Hi extends v{type="number";modifier="inRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!(n===null||e.to!==null&&n>e.to||e.from!==null&&n<e.from)}}class Wi extends v{type="number";modifier="notInRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.to!==null&&n>e.to||e.from!==null&&n<e.from}}const Cn={equals:{klass:mn,label:"is",isTransferable:t=>typeof t=="number",defaultValue:()=>0},notEquals:{klass:ki,label:"is not",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThan:{klass:ji,label:"is less than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThanOrEquals:{klass:Ui,label:"is less than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThan:{klass:Gi,label:"is greater than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:Ji,label:"is greater than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},inRange:{klass:Hi,label:"is between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:Wi,label:"is not between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})}};class yn extends v{type="otp";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class Ki extends v{type="otp";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class Zi extends v{type="otp";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class Xi extends v{type="otp";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const vn={equals:{klass:yn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:Ki,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Zi,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:Xi,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class Fn extends v{type="pass-fail";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:n.status===e}}class Yi extends v{type="pass-fail";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:n.status!==e}}class Qi extends v{type="pass-fail";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:e.includes(n.status)}}class Ri extends v{type="pass-fail";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.status===null?!1:!e.includes(n.status)}}const Vn={equals:{klass:Fn,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>"pass"},notEquals:{klass:Yi,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>"pass"},includes:{klass:Qi,label:"is any of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]},excludes:{klass:Ri,label:"is none of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]}};class wn extends v{type="radio";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class et extends v{type="radio";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class nt extends v{type="radio";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.includes(n)}}class it extends v{type="radio";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:!e.includes(n)}}const Sn={equals:{klass:wn,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>""},notEquals:{klass:et,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>""},includes:{klass:nt,label:"is any of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]},excludes:{klass:it,label:"is none of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]}};class bn extends v{type="rating";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class tt extends v{type="rating";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class lt extends v{type="rating";modifier="lessThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<e}}class at extends v{type="rating";modifier="lessThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n<=e}}class st extends v{type="rating";modifier="greaterThan";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>e}}class rt extends v{type="rating";modifier="greaterThanOrEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n>=e}}class ot extends v{type="rating";modifier="inRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!(n===null||e.to!==null&&n>e.to||e.from!==null&&n<e.from)}}class dt extends v{type="rating";modifier="notInRange";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.to!==null&&n>e.to||e.from!==null&&n<e.from}}const zn={equals:{klass:bn,label:"is",isTransferable:t=>typeof t=="number",defaultValue:()=>0},notEquals:{klass:tt,label:"is not",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThan:{klass:lt,label:"is less than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},lessThanOrEquals:{klass:at,label:"is less than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThan:{klass:st,label:"is greater than",isTransferable:t=>typeof t=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:rt,label:"is greater than or equal to",isTransferable:t=>typeof t=="number",defaultValue:()=>0},inRange:{klass:ot,label:"is between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:dt,label:"is not between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})}};class Nn extends v{type="qr";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class ct extends v{type="qr";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class ut extends v{type="qr";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class ht extends v{type="qr";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const xn={equals:{klass:Nn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:ct,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:ut,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:ht,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class In extends v{type="select";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class ft extends v{type="select";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class pt extends v{type="select";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:e.includes(n)}}class gt extends v{type="select";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===null?!1:!e.includes(n)}}const Mn={equals:{klass:In,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>""},notEquals:{klass:ft,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>""},includes:{klass:pt,label:"is any of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]},excludes:{klass:gt,label:"is none of",isTransferable:t=>Array.isArray(t),defaultValue:()=>[]}};class qn extends v{type="string";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class mt extends v{type="string";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class Ct extends v{type="string";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class yt extends v{type="string";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const On={equals:{klass:qn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:mt,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Ct,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:yt,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class Tn extends v{type="text";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n===e}}class vt extends v{type="text";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n!==e}}class Ft extends v{type="text";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>n.includes(e)}}class Vt extends v{type="text";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!n.includes(e)}}const En={equals:{klass:Tn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:vt,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Ft,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:Vt,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}};class Ln extends v{type="time";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?n===e:!1}}class wt extends v{type="time";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?n!==e:!1}}class St extends v{type="time";modifier="before";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?ve(n)<ve(e):!1}}class bt extends v{type="time";modifier="after";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?ve(n)>ve(e):!1}}class zt extends v{type="time";modifier="in";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?Ci(n,e):!1}}class Nt extends v{type="time";modifier="notIn";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>ne(n)?!Ci(n,e):!1}}const An={equals:{klass:Ln,label:"is",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},notEquals:{klass:wt,label:"is not",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},before:{klass:St,label:"before",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},after:{klass:bt,label:"after",isTransferable:t=>typeof t=="string",defaultValue:()=>ye(0,0)},in:{klass:zt,label:"in between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})},notIn:{klass:Nt,label:"not in between",isTransferable:t=>typeof t=="object",defaultValue:()=>({from:null,to:null})}};class Bn extends v{type="upload";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){return e=>e.length>0}}class xt extends v{type="upload";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){return e=>e.length===0}}const _n={equals:{klass:Bn,label:"is",isTransferable:t=>!0,defaultValue:()=>!0},notEquals:{klass:xt,label:"is not",isTransferable:t=>!0,defaultValue:()=>!0}};class Dn extends v{type="url";modifier="equals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>(n?.toString()??"")===e}}class It extends v{type="url";modifier="notEquals";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>(n?.toString()??"")!==e}}class Mt extends v{type="url";modifier="includes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>(n?.toString()??"").includes(e)}}class qt extends v{type="url";modifier="excludes";serializeValue(){return this.value}getValueApplyFn(){const e=this.value;return n=>!(n?.toString()??"").includes(e)}}const Pn={equals:{klass:Dn,label:"is",isTransferable:t=>!0,defaultValue:()=>""},notEquals:{klass:It,label:"is not",isTransferable:t=>!0,defaultValue:()=>""},includes:{klass:Mt,label:"includes",isTransferable:t=>!0,defaultValue:()=>""},excludes:{klass:qt,label:"does not include",isTransferable:t=>!0,defaultValue:()=>""}},Hs={date:{equals:(t,e)=>new cn({...t,field:e,value:new Date(t.value)}),notEquals:(t,e)=>new Ii({...t,field:e,value:new Date(t.value)}),before:(t,e)=>new Mi({...t,field:e,value:new Date(t.value)}),after:(t,e)=>new qi({...t,field:e,value:new Date(t.value)}),in:(t,e)=>new Oi({...t,field:e,value:{from:t.value.from?new Date(t.value.from):void 0,to:t.value.to?new Date(t.value.to):void 0}}),notIn:(t,e)=>new Ti({...t,field:e,value:{from:t.value.from?new Date(t.value.from):void 0,to:t.value.to?new Date(t.value.to):void 0}})},boolean:{equals:(t,e)=>new sn({...t,field:e}),notEquals:(t,e)=>new Fi({...t,field:e})},"checkbox-list":{equals:(t,e)=>new on({...t,field:e}),notEquals:(t,e)=>new Vi({...t,field:e}),every:(t,e)=>new wi({...t,field:e}),none:(t,e)=>new bi({...t,field:e}),some:(t,e)=>new Si({...t,field:e})},"multi-select":{equals:(t,e)=>new hn({...t,field:e}),notEquals:(t,e)=>new Ei({...t,field:e}),every:(t,e)=>new Li({...t,field:e}),none:(t,e)=>new Bi({...t,field:e}),some:(t,e)=>new Ai({...t,field:e})},"multi-string":{equals:(t,e)=>new pn({...t,field:e}),notEquals:(t,e)=>new _i({...t,field:e}),every:(t,e)=>new Di({...t,field:e}),none:(t,e)=>new $i({...t,field:e}),some:(t,e)=>new Pi({...t,field:e})},number:{equals:(t,e)=>new mn({...t,field:e}),notEquals:(t,e)=>new ki({...t,field:e}),greaterThan:(t,e)=>new Gi({...t,field:e}),greaterThanOrEquals:(t,e)=>new Ji({...t,field:e}),inRange:(t,e)=>new Hi({...t,field:e}),lessThan:(t,e)=>new ji({...t,field:e}),lessThanOrEquals:(t,e)=>new Ui({...t,field:e}),notInRange:(t,e)=>new Wi({...t,field:e})},otp:{equals:(t,e)=>new yn({...t,field:e}),notEquals:(t,e)=>new Ki({...t,field:e}),excludes:(t,e)=>new Xi({...t,field:e}),includes:(t,e)=>new Zi({...t,field:e})},"pass-fail":{equals:(t,e)=>new Fn({...t,field:e}),notEquals:(t,e)=>new Yi({...t,field:e}),excludes:(t,e)=>new Ri({...t,field:e}),includes:(t,e)=>new Qi({...t,field:e})},radio:{equals:(t,e)=>new wn({...t,field:e}),notEquals:(t,e)=>new et({...t,field:e}),excludes:(t,e)=>new it({...t,field:e}),includes:(t,e)=>new nt({...t,field:e})},rating:{equals:(t,e)=>new bn({...t,field:e}),notEquals:(t,e)=>new tt({...t,field:e}),greaterThan:(t,e)=>new st({...t,field:e}),greaterThanOrEquals:(t,e)=>new rt({...t,field:e}),inRange:(t,e)=>new ot({...t,field:e}),lessThan:(t,e)=>new lt({...t,field:e}),lessThanOrEquals:(t,e)=>new at({...t,field:e}),notInRange:(t,e)=>new dt({...t,field:e})},qr:{equals:(t,e)=>new Nn({...t,field:e}),notEquals:(t,e)=>new ct({...t,field:e}),excludes:(t,e)=>new ht({...t,field:e}),includes:(t,e)=>new ut({...t,field:e})},select:{equals:(t,e)=>new In({...t,field:e}),notEquals:(t,e)=>new ft({...t,field:e}),excludes:(t,e)=>new gt({...t,field:e}),includes:(t,e)=>new pt({...t,field:e})},string:{equals:(t,e)=>new qn({...t,field:e}),notEquals:(t,e)=>new mt({...t,field:e}),excludes:(t,e)=>new yt({...t,field:e}),includes:(t,e)=>new Ct({...t,field:e})},text:{equals:(t,e)=>new Tn({...t,field:e}),notEquals:(t,e)=>new vt({...t,field:e}),excludes:(t,e)=>new Vt({...t,field:e}),includes:(t,e)=>new Ft({...t,field:e})},time:{equals:(t,e)=>new Ln({...t,field:e}),notEquals:(t,e)=>new wt({...t,field:e}),after:(t,e)=>new bt({...t,field:e}),before:(t,e)=>new St({...t,field:e}),in:(t,e)=>new zt({...t,field:e}),notIn:(t,e)=>new Nt({...t,field:e})},url:{equals:(t,e)=>new Dn({...t,field:e}),notEquals:(t,e)=>new It({...t,field:e}),excludes:(t,e)=>new qt({...t,field:e}),includes:(t,e)=>new Mt({...t,field:e})},upload:{equals:(t,e)=>new Bn({...t,field:e}),notEquals:(t,e)=>new xt({...t,field:e})}},Ws={and:(t,e)=>new $e({...t,conditions:e}),nand:(t,e)=>new Ni({...t,conditions:e}),nor:(t,e)=>new xi({...t,conditions:e}),or:(t,e)=>new zi({...t,conditions:e})},$n=(t,e)=>t.every(n=>n.getApplyFn()(e)),Ot=(t,e)=>{if(!Un(t,e))return null;if(e.type==="compound"){const n=je(t,e.conditions);return Ws[e.operator](e,n)}else{const n=t.find(l=>l.id===e.field);return Hs[e.type][e.modifier](e,n)}},je=(t,e)=>e.map(n=>Ot(t,n)).filter(n=>!!n),Tt=(t,e)=>kn(t,e)?e.serialize():null,Et=(t,e)=>e.map(n=>Tt(t,n)).filter(n=>!!n),kn=(t,e)=>e.type==="compound"?(e.conditions=jn(t,e.conditions),e):new Set(t.map(l=>l.id)).has(e.field.id)?e:null,jn=(t,e)=>e.map(n=>kn(t,n)).filter(n=>!!n),Un=(t,e)=>e.type==="compound"?{...e,conditions:Lt(t,e.conditions)}:new Set(t.map(l=>l.id)).has(e.field)?e:null,Lt=(t,e)=>e.map(n=>Un(t,n)).filter(n=>!!n);class Kl extends _e{conditions;constructor(e){super(),this.conditions=this.initConditions(e)}conditionObserver=()=>{this.conditions=[...this.conditions],this.notify(this)};initConditions=e=>{for(const n of e)n.observe(this.conditionObserver);return e};getConditions(){return this.conditions}setConditions(e){this.conditions=this.initConditions(e),this.notify(this)}addCondition(e){this.conditions=this.initConditions([...this.conditions,e]),this.notify(this)}addConditions(e){this.conditions=this.initConditions([...this.conditions,...e]),this.notify(this)}replaceCondition(e,n){this.conditions=this.initConditions(this.conditions.map(l=>l.id===e.id?n:l)),this.notify(this)}removeCondition(e){this.conditions=this.initConditions(this.conditions.filter(n=>n.id!==e.id)),this.notify(this)}removeConditions(e){const n=new Set(e.map(l=>l.id));this.conditions=this.initConditions(this.conditions.filter(l=>!n.has(l.id))),this.notify(this)}applyConditions(e){return $n(this.conditions,e)}}const Ks=(t,e)=>o.useMemo(()=>{const n=new Kl(t);return n.observe(l=>e(l.getConditions())),n},[t,e]),Gn=t=>Ee[t.type].deserialize(t);function Zs(t){return t.map(Gn)}function Zl(t){return t.type==="section"?W.deserialize(t):Gn(t)}const Jn=t=>t.map(Zl),At=t=>Ee[t.type].fromConfig(t),Xl=t=>t.map(e=>At(e)),Yl=t=>t.type==="section"?W.fromConfig(t):At(t),Ql=t=>t.map(Yl),Bt=t=>Ee[t.type].deserializeConfig(t),Rl=t=>t.map(Bt),ea=t=>t.type==="section"?W.deserializeConfig(t):Bt(t),na=t=>t.map(ea),_t=t=>Ee[t.type].serializeConfig(t),ia=t=>t.map(_t),ta=t=>t.type==="section"?W.serializeConfig(t):_t(t),la=t=>t.map(ta);function Xs(t){const e={};for(const n of t)e[n.id]=n;return e}function aa(t,e,n=!0){const l=n?Hn(t,e):e,s={};for(const r of t){if(!(r.id in l))continue;const c=l[r.id];s[r.id]=r.serializeValue(c)}return s}function sa(t,e,n=!0){const l=n?Dt(t,e):e,s={};for(const r of t){if(!(r.id in l))continue;const c=l[r.id];s[r.id]=r.deserializeValue(c)}return s}function Hn(t,e){const n={};for(const l of t){if(!(l.id in e))continue;const s=e[l.id];l.isValue(s)&&(n[l.id]=l.cleanValue(s))}return n}function Dt(t,e){const n={};for(const l of t){if(!(l.id in e))continue;const s=e[l.id];l.isSerializedValue(s)&&(n[l.id]=l.cleanSerializedValue(s))}return n}function ra(t,e){const n=Hn(t,e),l={},s={};for(const r of t){if(!(r.id in n))continue;const c=n[r.id];switch(r.type){case"upload":if(!r.isValue(c))break;s[r.id]=c,l[r.id]=[];break;case"pass-fail":if(!r.isValue(c))break;s[r.id]=c.files,l[r.id]={...c,files:[]};break;default:l[r.id]=e[r.id]}}return[l,s]}function oa(t,e,n){const l={};for(const s of t){if(!(s.id in e))continue;const r=e[s.id];switch(s.type){case"upload":if(!s.isValue(r))break;l[s.id]=n[s.id]??[];break;case"pass-fail":if(!s.isValue(r))break;l[s.id]={...r,files:n[s.id]??[]};break;default:if(!s.isValue(r))break;l[s.id]=r}}return l}const da=(t,e)=>{const n={};for(const l of t){const s=e[l.id];n[l.id]=s!==void 0?s:l.blankValue()}return n},ca=(t,e,n)=>{const l={};for(const s of t){if(!(s.id in e)&&!(s.id in n))continue;if(!(s.id in e)){l[s.id]=n[s.id];continue}if(!(s.id in n))continue;const r=e[s.id],c=n[s.id];s.areValuesEqual(r,c)||(l[s.id]=c)}return l},ua=(t,e,n)=>{const l={};for(const s of t){if(!(s.id in e)&&!(s.id in n)||!(s.id in e)||!(s.id in n))continue;const r=e[s.id],c=n[s.id];s.areValuesEqual(r,c)&&(l[s.id]=c)}return l},ha=(t,e,n)=>t.every(l=>{if(!(l.id in e)&&!(l.id in n))return!0;if(!(l.id in e)||!(l.id in n))return!1;const s=e[l.id],r=n[l.id];return l.areValuesEqual(s,r)}),fa=t=>{const e={};for(const n of t)e[n.id]=n.blankValue();return e},pa=(t,e)=>t.every(n=>{if(!(n.id in e))return!0;const l=e[n.id];return n.isValueBlank(l)}),ga=(t,e)=>t.some(n=>!(n.id in e)),ma=(t,e)=>t.every(n=>n.id in e),Ys=Y.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),Wn=Y.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),Ca=o.memo(t=>{const{fieldSection:e}=t,{label:n,description:l}=e,s=Q.useWatch(),{fieldSchema:r,size:c}=o.use(B),f=o.useMemo(()=>r.getFieldSections(),[r]),h=o.useMemo(()=>f.findIndex(({id:C})=>C===e.id),[f,e.id]),u=o.useMemo(()=>f.filter(C=>e.id in C.conditions),[f,e.id]),p=o.useMemo(()=>u.length===0?!0:u.some(C=>{const g=C.getConditions(e.id);return $n(g,s)}),[u,e,s]),m=Ye(e.fields);return p?i.jsxs(i.Fragment,{children:[h!==0?i.jsx(a.Separator,{size:"full"}):null,i.jsxs("div",{className:"flex flex-col gap-4",children:[(n||l)&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx(a.Heading,{size:c,children:n}),l&&i.jsx(a.Text,{accentColor:"base",size:c,children:l})]})}),i.jsx("div",{className:Wn({size:c}),children:m})]})]}):null});Ca.displayName="FieldSectionLayout";class W extends Se{type="section";label;description;conditions;fields=[];constructor(e){const{label:n,description:l,fields:s,conditions:r={},...c}=e;super(c),this.label=n,this.description=l,this.fields=this.initFields(s),this.conditions=this.initConditions(r)}serialize(){return{...super.serialize(),label:this.label,description:this.description,fields:this.fields.map(e=>e.serialize()),conditions:this.serializeConditions()}}static deserialize=e=>{const n=e.fields.map(Gn),l={};for(const[s,r]of Object.entries(e.conditions??{}))l[s]=je(n,r);return new W({...e,fields:n,conditions:l})};static fromConfig=e=>{const n=Xl(e.fields),l={};for(const[s,r]of Object.entries(e.conditions??{}))l[s]=je(n,r);return new W({...e,fields:n,conditions:l})};static deserializeConfig(e){const{label:n,description:l,fields:s,conditions:r,...c}=e;return{...Se._deserializeConfig(c),label:n,description:l,fields:Rl(s),conditions:r}}static serializeConfig(e){const{label:n,description:l,fields:s,conditions:r,...c}=e;return{...Se._serializeConfig(c),label:n,description:l,fields:ia(s),conditions:r}}serializeConditions(){const e={};for(const[n,l]of Object.entries(this.conditions??{}))e[n]=Et(this.fields,l);return e}config(){return{...super.config(),label:this.label,description:this.description,fields:this.fields.map(e=>e.config()),conditions:this.serializeConditions()}}getOptions(){return{...super.getOptions(),label:this.label,description:this.description,fields:this.fields,conditions:this.conditions}}duplicate(e){return new W({...this.getOptions(),id:e,fields:this.fields.map(n=>n.duplicate(b.v4()))})}setOptions(e){"label"in e&&(this.label=e.label),"description"in e&&(this.description=e.description),"fields"in e&&e.fields!==void 0&&(this.fields=this.initFields(e.fields)),"conditions"in e&&(this.conditions=this.initConditions(e.conditions??{})),super.setOptions(e)}getErrors(e){const n={};for(const l of this.fields){const s=l.getError(e[l.id]);s&&(n[l.id]=s)}return n}fieldObserver=()=>{this.notify(this)};initFields=e=>{for(const n of e)n.observe(this.fieldObserver);return e};getFields(){return this.fields}addField(e,n){const l=[...this.fields];l.splice(n??this.fields.length,0,e),this.fields=this.initFields(l),this.notify(this)}moveField(e,n){if(!Number.isInteger(e)||!Number.isInteger(n)||e<0||e>=this.fields.length||n<0||n>=this.fields.length||e===n)return;const l=[...this.fields],[s]=l.splice(e,1);l.splice(n,0,s),this.fields=l,this.notify(this)}removeField(e){this.fields=this.initFields(this.fields.filter(({id:l})=>l!==e.id));const n={};for(const[l,s]of Object.entries(this.conditions))n[l]=jn(this.fields,s);this.conditions=n,this.notify(this)}conditionObserver=()=>{this.notify(this)};initConditions=e=>{for(const n of Object.values(e).flat())n.observe(this.conditionObserver);return e};getConditions(e){return this.conditions[e]}addCondition(e,n){this.conditions=this.initConditions({...this.conditions,[e]:[...this.conditions[e]??[],n]}),this.notify(this)}addConditions(e,n){this.conditions=this.initConditions({...this.conditions,[e]:[...this.conditions[e]??[],...n]}),this.notify(this)}replaceCondition(e,n,l){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).map(s=>s.id===n.id?l:s)}),this.notify(this)}removeCondition(e,n){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(l=>l.id!==n.id)}),this.notify(this)}removeConditions(e,n){const l=new Set(n.map(s=>s.id));this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(s=>!l.has(s.id))}),this.notify(this)}getConditionals(){return new Set(Object.keys(this.conditions))}addConditional(e){this.conditions=this.initConditions({...this.conditions,[e]:[]}),this.notify(this)}removeConditional(e){const n={...this.conditions};delete n[e],this.conditions=this.initConditions(n),this.notify(this)}render(){return i.jsx(Ca,{fieldSection:this})}}const ae=o.createContext({}),j=(t,e,n)=>o.useCallback(l=>{const{klass:s,isTransferable:r,defaultValue:c}=e[l],f=t.getValue(),h=new s({id:t.id,value:r(f)?f:c(),field:t.field});n(t,h)},[t,e,n]),ya=o.memo,Ve=ya(function(t){const{ref:e,children:n,...l}=t,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.SelectedIndicator,{className:"ml-[auto]",children:i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.SelectedIndicator,{className:"ml-[auto]",children:i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.SelectItem,{ref:e,...l,children:s})}),va=ya(function(t){const{ref:e,children:n,...l}=t,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.SelectedIndicator,{className:"ml-auto",children:i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.SelectedIndicator,{className:"ml-auto",children:i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.MultiSelectItem,{ref:e,...l,children:s})}),Pt=o.memo(t=>{const{ref:e,children:n,...l}=t,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:c=>c==="indeterminate"?i.jsx(a.LuIcon,{icon:Ke}):i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:c=>c==="indeterminate"?i.jsx(a.LuIcon,{icon:Ke}):i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.SelectAllItem,{ref:e,...l,children:s})});Pt.displayName="SelectAllItemTemplate";const $t=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,align:f,accentColor:h="base",...u}=t;return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,align:f,children:i.jsx(a.DayPicker,{size:c,accentColor:h,...u})})]})});$t.displayName="DayPickerPopover";const Fa=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,accentColor:f="base",values:h,onValuesChange:u,placeholder:p="Enter text",...m}=t,[C,g]=o.useState(""),y=o.useCallback(M=>{g(M.target.value)},[]),F=o.useCallback(M=>{M.key==="Enter"&&(M.preventDefault(),M.stopPropagation(),u([...h,C]),g(""))},[C,u,h]),V=o.useCallback(()=>{u([...h,C]),g("")},[C,u,h]),w=o.useCallback(M=>{const N=[...h];N.splice(M,1),u(N)},[u,h]);return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,accentColor:f,...m,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx(a.Input.Root,{className:"grow",accentColor:"base",variant:"outline",size:"sm",children:i.jsx(a.Input.Field,{value:C,onChange:y,onKeyDown:F,placeholder:p,...m})}),i.jsx(a.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button",onClick:V,children:i.jsx(a.LuIcon,{icon:K})})]}),h.length>0&&i.jsx("div",{className:"flex flex-col gap-1",children:h.map((M,N)=>i.jsxs(a.Badge,{className:"flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[i.jsx("span",{className:"truncate",children:M}),i.jsx(a.IconButton,{size:"xs",variant:"ghost",type:"button",accentColor:"base",onClick:()=>{w(N)},children:i.jsx(a.LuIcon,{icon:R})})]},`${M}-${N}`))})]})})]})});Fa.displayName="NumberInputPopover";const Oe=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter a number",...m}=t,[C,g]=o.useState(null);o.useEffect(()=>{h!==void 0&&g(h)},[h]);const y=o.useCallback(V=>{const w=V.target.valueAsNumber;g(isNaN(w)?null:w)},[]),F=o.useCallback(V=>{const w=V.target.valueAsNumber;u?.(isNaN(w)?null:w)},[u]);return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,...m,children:i.jsx(a.Input.Root,{size:c,accentColor:f,children:i.jsx(a.Input.Field,{placeholder:p,type:"number",value:C??"",onChange:y,onBlur:F})})})]})});Oe.displayName="NumberInputPopover";const k=t=>{const{condition:e,onClick:n,...l}=t,s=o.useCallback(()=>{n(e)},[e,n]);return i.jsx(a.IconButton,{onClick:s,...l,children:i.jsx(a.LuIcon,{icon:R})})};k.displayName="RemoveConditionButton";const Ue=o.memo(t=>{const{ref:e,selectFieldOptions:n,...l}=t,s=o.useMemo(()=>oe(n),[n]);return i.jsxs(a.Menu.MultiSelectGroup,{ref:e,...l,children:[i.jsx(Pt,{children:"Select all"}),s.map(r=>i.jsx(va,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))]})});Ue.displayName="SelectFieldOptionMultiSelectGroup";const kt=o.memo(t=>{const{ref:e,selectFieldOptions:n,...l}=t,s=o.useMemo(()=>oe(n),[n]);return i.jsx(a.Menu.SelectGroup,{ref:e,...l,children:s.map(r=>i.jsx(Ve,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))})});kt.displayName="SelectFieldOptionSelectGroup";const Le=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter text",...m}=t,[C,g]=o.useState(""),y=o.useCallback(V=>{g(V.target.value)},[]),F=o.useCallback(V=>{const w=V.target.value;u?.(w)},[u]);return o.useEffect(()=>{h&&g(h)},[h]),i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,...m,children:i.jsx(a.Input.Root,{size:c,accentColor:f,children:i.jsx(a.Input.Field,{placeholder:p,type:"text",value:C,onChange:y,onBlur:F})})})]})});Le.displayName="TextInputPopover";const Kn=o.memo(t=>{const{children:e,open:n,onOpenChange:l,defaultOpen:s,modal:r,size:c="sm",accentColor:f="base",value:h,onValueChange:u,...p}=t;return i.jsxs(a.Popover.Root,{open:n,onOpenChange:l,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:c,onClick:a.stopPropagation,accentColor:f,...p,children:i.jsx(ln,{compact:!0,size:c,value:h,onChange:u})})]})});Kn.displayName="TimeInputPopover";const U=t=>{const{children:e,required:n,value:l,defaultValue:s,onValueChange:r,modifierConfig:c,size:f="sm",variant:h,accentColor:u,radius:p}=t;return i.jsxs(a.Menu.Root,{align:"start",children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{size:f,variant:h,radius:p,accentColor:u,children:i.jsx(a.Menu.SelectGroup,{required:n,defaultValue:s,value:l,onValueChange:r,children:Object.keys(c).map(m=>{const{label:C}=c[m];return i.jsx(Ve,{value:m,children:C},m)})})})]})},Va=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=e.getValue(),r=e.modifier,c=()=>{switch(s){case!0:return"true";case!1:return"false"}},f=j(e,rn,n);return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:r,onValueChange:f,modifierConfig:rn,children:i.jsx(a.Button,{type:"button",children:rn[r].label})}),i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:c()})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.SelectGroup,{required:!0,value:s,onValueChange:e.setValue,children:[i.jsx(Ve,{value:!0,children:"true"}),i.jsx(Ve,{value:!1,children:"false"})]})})]}),i.jsx(k,{condition:e,onClick:l})]})},wa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,dn,n),r=()=>i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:dn,children:i.jsx(a.Button,{type:"button",children:dn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Zn=o.memo(t=>{const{children:e,variant:n,size:l,accentColor:s,onSelectFieldType:r,...c}=t,f=o.useMemo(()=>{const h={[O.Assessment]:[],[O.Capture]:[],[O.Numeric]:[],[O.Selection]:[],[O.Temporal]:[],[O.Text]:[],[O.Verification]:[]};for(const u of Hl){const{group:p}=L[u];h[p].push(u)}return h},[]);return i.jsxs(a.Menu.Root,{...c,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:l,accentColor:s,children:i.jsx(a.Menu.Scroll,{children:Object.entries(f).map(([h,u])=>{const{name:p}=Wl[h];return u.length===0?null:i.jsxs(a.Menu.Group,{children:[i.jsx(a.Menu.Label,{children:p}),u.map(m=>i.jsx(Sa,{fieldType:m,onSelectFieldType:r},m))]},h)})})})]})});Zn.displayName="CreateFieldDropdownMenu";const Sa=o.memo(t=>{const{fieldType:e,onSelectFieldType:n}=t,l=o.useCallback(()=>{n(e)},[e,n]),{icon:s,name:r}=L[e];return i.jsxs(a.Menu.Item,{onSelect:l,children:[i.jsx(a.LuIcon,{icon:s}),i.jsx(a.Text,{className:"truncate",children:r})]})});Sa.displayName="CreateFieldDropdownMenuItem";const Xn=t=>{switch(t){case"text":return new Ce({label:"",required:!1,id:b.v4()});case"boolean":return new de({label:"",required:!1,id:b.v4()});case"number":return new G({label:"",required:!1,id:b.v4()});case"date":return new Ne({label:"",required:!1,id:b.v4()});case"time":return new Me({label:"",required:!1,id:b.v4()});case"string":return new me({label:"",required:!1,id:b.v4()});case"url":return new qe({label:"",required:!1,id:b.v4()});case"select":return new ge({label:"",options:[],required:!1,id:b.v4()});case"multi-string":return new re({label:"",required:!1,id:b.v4()});case"multi-select":return new te({label:"",options:[],required:!1,id:b.v4()});case"upload":return new Fe({label:"",required:!1,id:b.v4()});case"qr":return new Ie({label:"",required:!1,id:b.v4()});case"radio":return new fe({label:"",options:[],required:!1,id:b.v4()});case"checkbox-list":return new ie({label:"",options:[],required:!1,id:b.v4()});case"pass-fail":return new he({label:"",required:!1,id:b.v4(),showNotesAndFilesOn:["fail"]});case"otp":return new ce({label:"",required:!1,id:b.v4(),length:6});case"rating":return new pe({label:"",required:!1,id:b.v4(),maxRating:5})}},Ge=t=>{switch(t.type){case"text":return new Tn({id:b.v4(),value:"",field:t});case"boolean":return new sn({id:b.v4(),value:!0,field:t});case"number":return new mn({id:b.v4(),value:0,field:t});case"date":return new cn({id:b.v4(),value:new Date,field:t});case"time":return new Ln({id:b.v4(),value:ye(0,0),field:t});case"string":return new qn({id:b.v4(),value:"",field:t});case"url":return new Dn({id:b.v4(),value:"",field:t});case"select":return new In({id:b.v4(),value:"",field:t});case"multi-string":return new pn({id:b.v4(),value:[],field:t});case"multi-select":return new hn({id:b.v4(),value:[],field:t});case"upload":return new Bn({id:b.v4(),value:!0,field:t});case"qr":return new Nn({id:b.v4(),value:"",field:t});case"radio":return new wn({id:b.v4(),value:"",field:t});case"checkbox-list":return new on({id:b.v4(),value:[],field:t});case"pass-fail":return new Fn({id:b.v4(),value:"pass",field:t});case"otp":return new yn({id:b.v4(),value:"",field:t});case"rating":return new bn({id:b.v4(),value:0,field:t})}},ba=(t,e)=>{switch(t){case"checkbox-list":return ie.getFieldCreationSchema(e);case"multi-select":return te.getFieldCreationSchema(e);case"number":return G.getFieldCreationSchema(e);case"radio":return fe.getFieldCreationSchema(e);case"select":return ge.getFieldCreationSchema(e);case"string":return me.getFieldCreationSchema(e);case"text":return Ce.getFieldCreationSchema(e);case"upload":return Fe.getFieldCreationSchema(e);case"pass-fail":return he.getFieldCreationSchema(e);case"otp":return ce.getFieldCreationSchema(e);case"rating":return pe.getFieldCreationSchema(e);default:return}},za=o.memo(t=>{const{popoverInputs:e,...n}=t;return i.jsxs(a.Popover.Root,{children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:i.jsxs(a.Button,{variant:"soft",type:"button",size:"sm",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:Ls}),"Settings"]})}),i.jsx(a.Popover.Content,{size:"sm",...n,children:i.jsx("div",{className:Y.cx("flex w-full max-w-[350px] flex-col",Wn({size:"sm"})),children:e})})]})});za.displayName="FieldSettingsPopover";const Na=o.memo(t=>{const{parentPath:e,fieldIndex:n,field:l}=t,s=Xe(),{disableRequiredFields:r}=o.use(ae),[c,f]=o.useState(void 0);He.useActiveEffect(S=>{f(void 0);const q=l.image;if(q){if(!(q instanceof Promise)){f(q);return}q.then(x=>{S()&&f(x)})}},[l.image]);const h=o.useCallback(()=>{l.setOptions({image:void 0})},[l]),[u,p]=o.useMemo(()=>{const S=[],q=[],x=ba(l.type,`${e}.${n}`)??[];for(const T of x)T.showDirectly?S.push(T.field):q.push(T.field);return[S,q]},[l,e,n]),m=Ye(u),C=Ye(p),g=p.length>0,y=o.useCallback(()=>{c&&s(()=>({file:c}))},[s,c]),F=o.useCallback(S=>{l.setOptions({required:!!S})},[l]),V=o.useCallback(S=>{l.setOptions({label:S.target.value})},[l]),w=o.useCallback(S=>{l.setOptions({description:S.target.value})},[l]),{icon:M,name:N}=L[l.type];return i.jsxs("div",{className:"flex w-full grow flex-col gap-4",children:[i.jsxs("div",{className:"flex w-full justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(a.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:M}),N]}),!r&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Checkbox.Root,{checked:l.required,onCheckedChange:F,size:"sm",children:i.jsx(a.Checkbox.Indicator,{children:i.jsx(a.LuIcon,{icon:H})})}),i.jsx(a.Text,{size:"sm",accentColor:"base",children:"Required"})]})]}),g&&i.jsx(za,{popoverInputs:C,align:"end"})]}),c&&i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx(be,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:c,onClick:y}),i.jsx(a.IconButton,{type:"button",className:"group-hover:not-disabled:flex absolute right-2 top-2 hidden",variant:"solid",accentColor:"base","aria-label":"delete",onClick:h,size:"sm",children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(a.Input.Root,{variant:"outline",size:"md",children:i.jsx(a.Input.Field,{placeholder:"Enter your question",value:l.label??"",onChange:V,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a field description (optional)",value:l.description??"",onChange:w,maxLength:1e3,resize:"vertical",size:"md"})]}),u.length>0&&i.jsx("div",{className:Y.cx("w-full",Wn({size:"sm"})),children:m})]})});Na.displayName="FieldBuilder";const jt=o.memo(t=>{const{field:e,fieldSection:n,fieldIndex:l,sectionIndex:s}=t,r=o.useRef(null),c=`fields.${s}.fields`,f=o.useCallback(F=>{n.addField(Xn(F),l+1)},[l,n]),h=o.useCallback(()=>{n.addField(e.duplicate(b.v4()))},[e,n]),u=o.useCallback(F=>{const V=F==="up"?l-1:l+1;n.moveField(l,V)},[n,l]),p=o.useCallback(F=>{const{files:V}=F.target;if(!V||V.length!==1)return;const w=V.item(0);w&&e.setOptions({image:w})},[e]),m=o.useCallback(()=>{u("up")},[u]),C=o.useCallback(()=>{u("down")},[u]),g=o.useCallback(()=>{r.current?.click()},[]),y=o.useCallback(()=>{n.removeField(e)},[e,n]);return i.jsxs(a.Card,{className:"flex w-full items-center justify-between gap-4",size:"sm",children:[i.jsx(Na,{fieldIndex:l,field:e,parentPath:c}),i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(Zn,{onSelectFieldType:f,size:"sm",children:i.jsx(a.IconButton,{type:"button",children:i.jsx(a.LuIcon,{icon:K})})}),i.jsx(a.IconButton,{type:"button",onClick:m,disabled:l===0,"aria-label":"Move field up",children:i.jsx(a.LuIcon,{icon:Ze})}),i.jsx(a.IconButton,{type:"button",onClick:C,disabled:l===n.fields.length-1,"aria-label":"Move field down",children:i.jsx(a.LuIcon,{icon:ol})}),i.jsx(a.IconButton,{type:"button",onClick:h,children:i.jsx(a.LuIcon,{icon:Rn})}),i.jsx(a.IconButton,{type:"button",onClick:g,children:i.jsx(a.LuIcon,{icon:sl})}),i.jsx(a.IconButton,{type:"button",onClick:y,children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsx("input",{className:"hidden",ref:r,type:"file",accept:"image/*",onChange:p})]})});jt.displayName="FieldBuilderWithActions";const Ut=o.memo(t=>{const{children:e,variant:n,size:l,accentColor:s,fields:r,onSelectField:c,onSelectAllFields:f,...h}=t,u=o.useCallback(()=>{f?.(r)},[f,r]);return i.jsxs(a.Menu.Root,{...h,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:l,accentColor:s,children:i.jsxs(a.Menu.Scroll,{children:[f?i.jsx(a.Menu.Item,{onSelect:u,children:"Select all"}):null,r.map(p=>i.jsx(xa,{field:p,onSelectField:c},p.id))]})})]})});Ut.displayName="FieldDropdownMenu";const xa=o.memo(t=>{const{field:e,onSelectField:n}=t,l=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(a.Menu.Item,{onSelect:l,children:[i.jsx(a.LuIcon,{icon:L[e.type].icon}),e.label||P]})});xa.displayName="FieldDropdownMenuItem";const Ia=o.memo(t=>{const{children:e,variant:n,size:l,accentColor:s,fieldSections:r,onSelectFieldSection:c,...f}=t;return i.jsxs(a.Menu.Root,{...f,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:l,accentColor:s,children:r.map(h=>i.jsx(Ma,{fieldSection:h,onSelectFieldSection:c},h.id))})]})});Ia.displayName="FieldSectionDropdownMenu";const Ma=o.memo(t=>{const{fieldSection:e,onSelectFieldSection:n}=t,l=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(a.Menu.Item,{onSelect:l,children:[i.jsx(a.LuIcon,{icon:rl}),e.label||an]})});Ma.displayName="FieldSectionDropdownMenuItem";const qa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,un,n),r=()=>{switch(e.modifier){case"in":case"notIn":{const c=e.getValue();return i.jsx($t,{required:!0,mode:"range",size:"sm",selected:c,onSelect:e.setValue,children:i.jsxs(a.Button,{type:"button",className:"truncate",children:[c.from?.toLocaleDateString()??"..."," - ",c.to?.toLocaleDateString()??"..."]})})}default:return i.jsx($t,{required:!0,mode:"single",size:"sm",selected:e.getValue(),onSelect:e.setValue,children:i.jsx(a.Button,{type:"button",className:"truncate",children:e.getValue().toLocaleDateString()})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:un,children:i.jsx(a.Button,{type:"button",children:un[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Oa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,fn,n),r=()=>i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:fn,children:i.jsx(a.Button,{type:"button",children:fn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ta=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,gn,n),r=()=>{const c=e.getValue();return i.jsx(Fa,{values:c,onValuesChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:c.length===1?c[0]:`${c.length} values`})})};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:gn,children:i.jsx(a.Button,{type:"button",children:gn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ea=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Cn,n),r=o.useCallback(u=>{u===null||e.modifier==="inRange"||e.modifier==="notInRange"||e.setValue(u)},[e]),c=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),from:u})},[e]),f=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),to:u})},[e]),h=()=>{switch(e.modifier){case"inRange":case"notInRange":{const u=e.getValue();return i.jsxs(i.Fragment,{children:[i.jsx(Oe,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from??"..."})}),i.jsx(Oe,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to??"..."})})]})}default:return i.jsx(Oe,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:e.getValue()})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Cn,children:i.jsx(a.Button,{type:"button",children:Cn[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:l})]})},La=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,vn,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:vn,children:i.jsx(a.Button,{type:"button",children:vn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Aa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Vn,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",children:ue[e.getValue()].label})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(a.Menu.SelectGroup,{required:!0,value:e.getValue(),onValueChange:e.setValue,children:Te.map(c=>i.jsx(Ve,{value:c,children:ue[c].label},c))})})]});case"includes":case"excludes":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," statuses"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.MultiSelectGroup,{values:e.getValue(),onValuesChange:e.setValue,children:[i.jsx(Pt,{children:"Select all"}),Te.map(c=>i.jsxs(va,{value:c,children:[i.jsx(a.LuIcon,{icon:ue[c].icon}),ue[c].label]},c))]})})]})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Vn,children:i.jsx(a.Button,{type:"button",children:Vn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ba=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Sn,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const c=e.getValue(),f=oe(e.field.options).find(h=>h.value===c)?.label;return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"truncate",children:f??(c||"...")})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(kt,{required:!0,selectFieldOptions:e.field.options,value:c,onValueChange:e.setValue})})]})}case"includes":case"excludes":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Sn,children:i.jsx(a.Button,{type:"button",children:Sn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},_a=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,zn,n),r=o.useCallback(u=>{u===null||e.modifier==="inRange"||e.modifier==="notInRange"||e.setValue(u)},[e]),c=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),from:u})},[e]),f=o.useCallback(u=>{e.modifier!=="inRange"&&e.modifier!=="notInRange"||e.setValue({...e.getValue(),to:u})},[e]),h=()=>{switch(e.modifier){case"inRange":case"notInRange":{const u=e.getValue();return i.jsxs(i.Fragment,{children:[i.jsx(Oe,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from??"..."})}),i.jsx(Oe,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to??"..."})})]})}default:return i.jsx(Oe,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:e.getValue()})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:zn,children:i.jsx(a.Button,{type:"button",children:zn[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:l})]})},Da=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,xn,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:xn,children:i.jsx(a.Button,{type:"button",children:xn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Pa=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Mn,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const c=e.getValue(),f=oe(e.field.options).find(h=>h.value===c)?.label;return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"truncate",children:f??(c||"...")})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(kt,{required:!0,selectFieldOptions:e.field.options,value:c,onValueChange:e.setValue})})]})}case"includes":case"excludes":return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(Ue,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Mn,children:i.jsx(a.Button,{type:"button",children:Mn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},$a=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,On,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:On,children:i.jsx(a.Button,{type:"button",children:On[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},ka=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,En,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:En,children:i.jsx(a.Button,{type:"button",children:En[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},ja=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,An,n),r=o.useCallback(u=>{u===null||e.modifier==="in"||e.modifier==="notIn"||e.setValue(u)},[e]),c=o.useCallback(u=>{e.modifier!=="in"&&e.modifier!=="notIn"||e.setValue({...e.getValue(),from:u})},[e]),f=o.useCallback(u=>{e.modifier!=="in"&&e.modifier!=="notIn"||e.setValue({...e.getValue(),to:u})},[e]),h=()=>{switch(e.modifier){case"in":case"notIn":{const u=e.getValue();return i.jsxs(i.Fragment,{children:[i.jsx(Kn,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from?tn(u.from):"..."})}),i.jsx(Kn,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to?tn(u.to):"..."})})]})}default:return i.jsx(Kn,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:tn(e.getValue())})})}};return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:An,children:i.jsx(a.Button,{type:"button",children:An[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:l})]})},Ua=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,_n,n),r=()=>i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",children:e.getValue()?"empty":"not empty"})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.SelectGroup,{required:!0,value:e.getValue(),onValueChange:e.setValue,children:[i.jsx(Ve,{value:!0,children:"empty"}),i.jsx(Ve,{value:!1,children:"not empty"})]})})]});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:_n,children:i.jsx(a.Button,{type:"button",children:_n[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Ga=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=j(e,Pn,n),r=()=>i.jsx(Le,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(a.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(a.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:L[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||P})]}),i.jsx(U,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Pn,children:i.jsx(a.Button,{type:"button",children:Pn[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:l})]})},Gt=t=>{const{condition:e,...n}=t;switch(e.type){case"string":return i.jsx($a,{condition:e,...n});case"text":return i.jsx(ka,{condition:e,...n});case"otp":return i.jsx(La,{condition:e,...n});case"qr":return i.jsx(Da,{condition:e,...n});case"url":return i.jsx(Ga,{condition:e,...n});case"select":return i.jsx(Pa,{condition:e,...n});case"radio":return i.jsx(Ba,{condition:e,...n});case"checkbox-list":return i.jsx(wa,{condition:e,...n});case"multi-select":return i.jsx(Oa,{condition:e,...n});case"multi-string":return i.jsx(Ta,{condition:e,...n});case"number":return i.jsx(Ea,{condition:e,...n});case"rating":return i.jsx(_a,{condition:e,...n});case"date":return i.jsx(qa,{condition:e,...n});case"time":return i.jsx(ja,{condition:e,...n});case"pass-fail":return i.jsx(Aa,{condition:e,...n});case"upload":return i.jsx(Ua,{condition:e,...n});case"boolean":return i.jsx(Va,{condition:e,...n});case"compound":return i.jsx(Ha,{condition:e,...n})}},Jt=o.createContext(null),Ja=()=>{const t=o.useContext(Jt);if(!t)throw new Error("useFieldConditionBuilderContext requires a FieldConditionBuilder");return t},Ht=t=>{const{fields:e,conditions:n,onAdd:l,onReplace:s,onRemove:r}=t,c=o.useMemo(()=>({fields:e}),[e]),f=o.useCallback(p=>l([Ge(p)]),[l]),h=o.useCallback(p=>l(p.map(Ge)),[l]),u=o.useCallback(()=>l([new $e({id:b.v4(),conditions:[]})]),[l]);return i.jsx(Jt.Provider,{value:c,children:i.jsxs("div",{className:"flex flex-col gap-4",children:[n.map(p=>i.jsx(Gt,{condition:p,onReplace:s,onRemove:r},p.id)),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ut,{fields:e,onSelectField:f,onSelectAllFields:h,align:"start",size:"sm",children:i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",children:[i.jsx(a.LuIcon,{icon:K}),"Add condition"]})}),i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",onClick:u,children:[i.jsx(a.LuIcon,{icon:K}),"Add group"]})]})]})})},Ha=t=>{const{condition:e,onReplace:n,onRemove:l}=t,s=e.conditions,{fields:r}=Ja(),c=o.useCallback(g=>{const{klass:y}=ke[g],F=new y({id:e.id,conditions:e.conditions});n(e,F)},[e,n]),f=o.useCallback(()=>{l(e)},[e,l]),h=o.useCallback(()=>{e.addCondition(new $e({id:b.v4(),conditions:[]}))},[e]),u=o.useCallback(g=>{e.addCondition(Ge(g))},[e]),p=o.useCallback(g=>{e.addConditions(g.map(y=>Ge(y)))},[e]),m=o.useCallback((g,y)=>{e.replaceCondition(g,y)},[e]),C=o.useCallback(g=>{e.removeCondition(g)},[e]);return i.jsxs(a.Card,{className:"p-0! flex grow flex-col",variant:"outline",size:"sm",children:[i.jsxs("div",{className:"bg-(--base-a2) flex h-max shrink-0 grow-0 items-center gap-3 rounded-t-[inherit] px-4 py-2",children:[i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsxs(a.Button,{size:"sm",variant:"surface",accentColor:"base",children:[ke[e.operator].label,i.jsx(a.LuIcon,{icon:Ae})]})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!0,value:e.operator,onValueChange:c,children:Object.entries(ke).map(([g,{label:y,blurb:F}])=>i.jsx(Ve,{value:g,children:i.jsxs("div",{className:"flex flex-col",children:[y,i.jsx(a.Text,{size:"xs",accentColor:"base",children:F})]})},g))})})})]}),i.jsx(a.Text,{size:"sm",accentColor:"base",className:"min-w-0 grow",children:ke[e.operator].blurb}),i.jsx(a.IconButton,{onClick:f,accentColor:"base",size:"sm",variant:"ghost",type:"button",children:i.jsx(a.LuIcon,{icon:R})})]}),i.jsx(a.Separator,{size:"full"}),s.length>0?i.jsx("div",{className:"flex shrink grow flex-col gap-4 p-4",children:s.map(g=>i.jsx(Gt,{condition:g,onRemove:C,onReplace:m},g.id))}):null,i.jsxs("div",{className:"h-max shrink-0 grow-0 rounded-b-[inherit] px-4 py-2",children:[i.jsx(Ut,{fields:r,onSelectField:u,onSelectAllFields:p,align:"start",size:"sm",children:i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",children:[i.jsx(a.LuIcon,{icon:K}),"Condition"]})}),i.jsxs(a.Button,{variant:"ghost",size:"sm",accentColor:"base",type:"button",onClick:h,children:[i.jsx(a.LuIcon,{icon:K}),"Group"]})]})]})},Wa=o.memo(t=>{const{id:e,sourceX:n,sourceY:l,targetX:s,targetY:r,style:c,markerEnd:f,data:h}=t,{targetSection:u,sourceSection:p,layoutDirection:m}=h,C=p.getConditions(u.id),g=o.useCallback((S,q)=>{p.replaceCondition(u.id,S,q)},[p,u.id]),y=o.useCallback(S=>{p.addConditions(u.id,S)},[p,u.id]),F=o.useCallback(S=>{p.removeCondition(u.id,S)},[p,u.id]),V=o.useCallback(()=>{p.removeConditional(u.id)},[p,u.id]),[w,M,N]=E.getBezierPath({sourceX:n,sourceY:l,sourcePosition:m==="LR"?E.Position.Right:E.Position.Bottom,targetX:s,targetY:r,targetPosition:m==="LR"?E.Position.Left:E.Position.Top});return i.jsxs(i.Fragment,{children:[i.jsx(E.BaseEdge,{id:e,path:w,style:c,markerEnd:f,labelX:M,labelY:N}),i.jsx(E.EdgeLabelRenderer,{children:i.jsxs(a.Card,{size:"xs",variant:"surface",className:"nodrag dark:bg-(--base-2)! nopan pointer-events-auto absolute inline-flex flex-col gap-2",onMouseDown:a.stopPropagation,onClick:a.stopPropagation,"data-floating-content":"",style:{transform:`translate(-50%, -50%) translate(${M}px, ${N}px)`},children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Text,{size:"xs",className:"max-w-[280px] truncate",children:p.label||an}),i.jsx(a.IconButton,{type:"button","aria-label":"Delete relationship",size:"sm",variant:"ghost",accentColor:"base",onClick:V,children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsx(Ht,{fields:p.fields,conditions:C,onRemove:F,onReplace:g,onAdd:y})]})})]})});Wa.displayName="FieldSectionConditionEdgeComponent";const Ka=o.memo(t=>{const{data:e,selected:n}=t,{fieldSection:l,index:s,layoutDirection:r}=e,{fieldSchema:c}=o.use(ae),f=o.useCallback(()=>{c.removeFieldSection(l)},[c,l]),h=o.useCallback(g=>{l.addField(Xn(g))},[l]),u=o.useCallback(()=>{const g=new W({id:b.v4(),fields:[]});c.addFieldSection(g),l.addConditional(g.id)},[c,l]),p=o.useCallback(()=>{c.addFieldSection(l.duplicate(b.v4()))},[c,l]),m=o.useCallback(g=>{l.setOptions({label:g.target.value})},[l]),C=o.useCallback(g=>{l.setOptions({description:g.target.value})},[l]);return i.jsxs(a.Card,{variant:"surface",className:"dark:bg-(--base-2)! relative cursor-pointer",size:"sm","data-selected":n?"true":void 0,children:[i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(a.Input.Root,{variant:"outline",size:"md",accentColor:"base",children:i.jsx(a.Input.Field,{placeholder:"Enter a section label (optional)",value:l.label??"",onChange:m,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:l.description??"",onChange:C,maxLength:1e3,resize:"vertical",size:"md"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(a.Text,{weight:"bold",children:"Fields"}),i.jsx(Zn,{onSelectFieldType:h,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:K})," Add field"]})})]}),i.jsx("div",{className:"flex flex-col gap-3",children:l.fields.map((g,y)=>i.jsx(jt,{field:g,fieldSection:l,fieldIndex:y,sectionIndex:s},g.id))})]}),i.jsx(E.NodeToolbar,{isVisible:!0,position:E.Position.Right,align:"start",offset:8,onMouseDown:a.stopPropagation,children:i.jsx(a.Card,{variant:"surface",className:"dark:bg-(--color-background)! p-0! flex flex-col items-center gap-0",size:"sm",onClick:a.stopPropagation,children:i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0",variant:"soft",size:"xs",accentColor:"base",children:[i.jsx(a.IconButton,{className:"rounded-b-none",type:"button",onClick:u,children:i.jsx(a.LuIcon,{icon:zs})}),i.jsx(a.IconButton,{className:"rounded-none",type:"button",onClick:p,children:i.jsx(a.LuIcon,{icon:Rn})}),i.jsx(a.IconButton,{className:"rounded-t-none",type:"button",onClick:f,children:i.jsx(a.LuIcon,{icon:se})})]})})}),i.jsx(E.Handle,{type:"target",className:"size-4! bg-(--base-3)! border-(--base-7)!",position:r==="LR"?E.Position.Left:E.Position.Top}),i.jsx(E.Handle,{type:"source",className:"size-4! bg-(--base-3)! border-(--base-7)!",position:r==="LR"?E.Position.Right:E.Position.Bottom})]})});Ka.displayName="CustomNode";const Qs={fieldSection:Ka},Rs={fieldSectionCondition:Wa},er=(t,e,n)=>{const l=new Xt.graphlib.Graph().setDefaultEdgeLabel(()=>({}));return l.setGraph({rankdir:n,nodesep:200,edgesep:500,ranksep:500}),e.forEach(s=>l.setEdge(s.source,s.target,{width:500,height:200,labelpos:"c"})),t.forEach(s=>l.setNode(s.id,{...s,width:s.measured?.width??0,height:s.measured?.height??0})),Xt.layout(l),[t.map(s=>{const r=l.node(s.id),c=r.x-(s.measured?.width??0)/2,f=r.y-(s.measured?.height??0)/2;return{...s,position:{x:c,y:f}}}),e]},nr={hideAttribution:!0},Za=o.memo(()=>{const{errors:t}=Q.useFormState(),{handleSubmit:e}=Q.useFormContext(),{onSave:n,onCancel:l}=o.use(ae),{fieldSchema:s}=o.use(ae),r=o.useRef(null),[c,f]=o.useState(),[h,u]=o.useState("TB");o.useLayoutEffect(()=>{r.current&&r.current.classList.remove("light")},[]);const p=o.useMemo(()=>s.fieldSections.map((A,J)=>({id:A.id,position:{x:0,y:0},data:{index:J,fieldSection:A,layoutDirection:h},draggable:!0,type:"fieldSection"})),[s.fieldSections,h]),m=o.useMemo(()=>{const A=[],J={};for(const Z of s.fieldSections)J[Z.id]=Z;for(const Z of s.fieldSections){const Kt=Z.conditions;for(const[Je,rr]of Object.entries(Kt))A.push({id:`${Z.id}-${Je}`,source:Z.id,target:Je,data:{targetSection:J[Je],sourceSection:Z,layoutDirection:h},animated:rr.length>0,markerEnd:E.MarkerType.Arrow,style:{strokeWidth:2,stroke:"var(--base-a8)"},type:"fieldSectionCondition"})}return A},[s.fieldSections,h]),[C,g,y]=E.useNodesState(p),[F,V,w]=E.useEdgesState(m);o.useEffect(()=>{g(p)},[p,g]),o.useEffect(()=>{V(m)},[m,V]);const[M,N]=o.useMemo(()=>er(C,F,h),[F,h,C]),S=o.useCallback(()=>{s.addFieldSection(new W({id:b.v4(),fields:[]}))},[s]),q=o.useCallback(A=>{const{source:J,target:Z}=A;s.fieldSections.find(({id:Je})=>Je===J).addConditional(Z)},[s.fieldSections]),x=o.useCallback(A=>{const J=s.getSectionDependencyGraph();return!Zt.willCreateCycle(J,A.source,A.target)},[s]),T=o.useCallback(()=>{c?.zoomOut()},[c]),_=o.useCallback(()=>{c?.zoomIn()},[c]),X=o.useCallback(()=>{c?.fitView()},[c]);return i.jsxs("form",{className:"flex size-full flex-col gap-4",onSubmit:e(n),children:[i.jsxs(a.Card,{className:"relative size-full",variant:"outline",children:[i.jsx(E.ReactFlow,{ref:r,onInit:f,nodes:M,onNodesChange:y,edges:N,onEdgesChange:w,nodeTypes:Qs,edgeTypes:Rs,onConnect:q,attributionPosition:"bottom-left",fitView:!0,minZoom:0,isValidConnection:x,proOptions:nr}),i.jsx(E.Panel,{position:"top-left",children:i.jsx(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"surface",onClick:S,children:[i.jsx(a.LuIcon,{icon:K})," Add section"]})})}),i.jsxs(E.Panel,{position:"top-right",className:"flex flex-col items-center gap-2",children:[i.jsxs(a.ToggleGroup.Root,{className:"flex flex-col",type:"single",accentColor:"base",size:"sm",value:h,onValueChange:u,children:[i.jsx(a.ToggleGroup.IconItem,{className:"rounded-b-none",value:"LR",type:"button",children:i.jsx(a.LuIcon,{icon:gs})}),i.jsx(a.ToggleGroup.IconItem,{className:"rounded-t-none",value:"TB",type:"button",children:i.jsx(a.LuIcon,{icon:ps})})]}),i.jsx(a.Separator,{size:"sm"}),i.jsxs(a.ButtonGroup,{className:"flex flex-col",size:"sm",accentColor:"base",variant:"soft",children:[i.jsx(a.IconButton,{className:"rounded-b-none",onClick:_,type:"button",children:i.jsx(a.LuIcon,{icon:K})}),i.jsx(a.IconButton,{onClick:T,radius:"none",type:"button",children:i.jsx(a.LuIcon,{icon:Ke})}),i.jsx(a.IconButton,{className:"rounded-t-none",onClick:X,type:"button",children:i.jsx(a.LuIcon,{icon:Bs})})]})]}),i.jsx(E.Panel,{position:"bottom-right",children:i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[l&&i.jsx(a.Button,{type:"button",variant:"soft",accentColor:"base",onClick:l,children:"Cancel"}),i.jsx(a.Button,{type:"submit",variant:"surface",children:"Save"})]})})]}),!!t.fields?.message&&i.jsx(a.Text,{size:"xs",accentColor:"danger",children:t.fields.message})]})});Za.displayName="FormBuilderFlowBuilder";const ir=(t,e,n={})=>{const{conditions:l=!1}=n,s=t.get(e.id);if(!s)throw new Error(`Attempting to reseed serialized section with id ${e.id} which is not present in the reseeded id map`);const r=new Map,c=e.fields.map(h=>{const u=b.v4();return r.set(h.id,u),{...h,id:u}}),f={};if(l){const h=u=>{switch(u.type){case"compound":return{...u,conditions:u.conditions.map(h)};default:{const p=r.get(u.field);if(!p)throw new Error(`Serialized condition referencing undefined field with id: ${u.field}`);return{...u,field:p}}}};for(const[u,p]of Object.entries(e.conditions??{})){const m=t.get(u);m&&(f[m]=p.map(h))}}return{...e,id:s,conditions:f,fields:c}},tr=(t,e={})=>{const n=new Map(t.map(l=>[l.id,b.v4()]));return t.map(l=>ir(n,l,e))},Wt=(t,e)=>{const n={},l=t.filter(s=>s instanceof W);for(const s of t)if(s instanceof W){const r=l.filter(f=>s.id in f.conditions);if(r.length>0&&!r.some(f=>{const h=f.getConditions(s.id);return $n(h,e)}))continue;const c=s.getErrors(e);Object.assign(n,c)}else{if(!(s instanceof I))throw new Error("Invalid field type");const r=s.id,c=s.getError(Qt(e,r));c&&rs(n,r,c)}return n},lr=async t=>{const e={};for(const n of t){const{fields:l}=n;for(const s of l)if(s.image)if(s.image instanceof Promise)try{e[s.id]=await s.image}catch(r){console.error("Failed to get image from promise",r)}else e[s.id]=s.image}return e};async function ar(t){const e={};for(const[n,l]of Object.entries(t))e[n]=await Promise.all(l);return e}class we extends _e{fieldSections;constructor(e){super(),this.fieldSections=this.initFields(e)}serialize(){return this.fieldSections.map(e=>e.serialize())}config(){return this.fieldSections.map(e=>e.config())}static deserialize(e){return new we(Jn(e))}static fromConfig(e){return new we(Ql(e))}static serializeConfig(e){return la(e)}static deserializeConfig(e){return na(e)}static reseedFieldSections(e,n){return tr(e,n)}fieldObserver=()=>{this.notify(this)};initFields=e=>{for(const n of e)n.observe(this.fieldObserver);return e};getFields(){return this.fieldSections.flatMap(e=>e.getFields())}getFieldSections(){return this.fieldSections}addFieldSection(e,n){const l=[...this.fieldSections];l.splice(n??this.fieldSections.length,0,e),this.fieldSections=this.initFields(l),this.notify(this)}removeFieldSection(e){const n=this.fieldSections.filter(l=>l.id!==e.id);for(const l of n)l.removeConditional(e.id);this.fieldSections=this.initFields(n),this.notify(this)}moveFieldSection(e,n){if(!Number.isInteger(e)||!Number.isInteger(n)||e<0||e>=this.fieldSections.length||n<0||n>=this.fieldSections.length||e===n)return;const l=[...this.fieldSections],[s]=l.splice(e,1);l.splice(n,0,s),this.fieldSections=this.initFields(l),this.notify(this)}getSectionDependencyGraph(){const e=new as.DirectedGraph({type:"directed"});for(const n of this.fieldSections)for(const l of Object.keys(n.conditions))e.mergeEdge(n.id,l);return e}getDependenciesOfSection(e){const n=this.getSectionDependencyGraph(),l=new Map(this.fieldSections.map(r=>[r.id,r])),s=[];return ss.bfsFromNode(n,e,(r,c,f)=>{s.push(l.get(r))},{mode:"in"}),s}cleanValues(e){return Hn(this.getFields(),e)}cleanSerializedValues(e){return Dt(this.getFields(),e)}deserializeValues(e,n){return sa(this.getFields(),e,n)}serializeValues(e,n){return aa(this.getFields(),e,n)}initializeValues(e){return da(this.getFields(),e)}validateValues(e){return Wt(this.getFieldSections(),e)}areValuesValid(e){return Object.keys(this.validateValues(e)).length===0}deserializeCondition(e){return Ot(this.getFields(),e)}cleanCondition(e){return kn(this.getFields(),e)}serializeCondition(e){return Tt(this.getFields(),e)}cleanSerializedCondition(e){return Un(this.getFields(),e)}cleanConditions(e){return jn(this.getFields(),e)}cleanSerializedConditions(e){return Lt(this.getFields(),e)}deserializeConditions(e){return je(this.getFields(),e)}serializeConditions(e){return Et(this.getFields(),e)}changedFieldValues(e,n){return ca(this.getFields(),e,n)}unchangedFieldValues(e,n){return ua(this.getFields(),e,n)}areValuesEqual(e,n){return ha(this.getFields(),e,n)}areValuesBlank(e){return pa(this.getFields(),e)}areValuesPartial(e){return ga(this.getFields(),e)}areValuesComplete(e){return ma(this.getFields(),e)}blankValues(){return fa(this.getFields())}extractFilesAndPromisesFromFieldValues(e){return ra(this.getFields(),e)}insertFilesAndPromisesToFieldValues(e,n){return oa(this.getFields(),e,n)}}const Xa=o.memo(t=>{const{sourceFieldSection:e,targetFieldSection:n}=t,l=e.getConditions(n.id),s=o.useCallback((h,u)=>{e.replaceCondition(n.id,h,u)},[e,n.id]),r=o.useCallback(h=>{e.addConditions(n.id,h)},[e,n.id]),c=o.useCallback(h=>{e.removeCondition(n.id,h)},[e,n.id]),f=o.useCallback(()=>{e.removeConditional(n.id)},[e,n.id]);return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs(a.ButtonGroup,{className:"flex justify-between gap-2",size:"sm",accentColor:"base",variant:"soft",children:[i.jsxs(a.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:rl}),e.label??an]}),i.jsx(a.IconButton,{type:"button","aria-label":"Delete relationship",size:"sm",variant:"ghost",accentColor:"base",onClick:f,children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsx(Ht,{fields:e.fields,conditions:l,onRemove:c,onReplace:s,onAdd:r})]})});Xa.displayName="FieldSectionConditionalItem";const Ya=o.memo(t=>{const{fieldSection:e}=t,{fieldSchema:n}=o.use(ae),l=o.useMemo(()=>n.fieldSections.filter(h=>e.id in h.conditions),[n.fieldSections,e.id]),s=o.useCallback(h=>{h.addConditional(e.id)},[e.id]),r=o.useCallback(h=>{e.setOptions({label:h.target.value})},[e]),c=o.useCallback(h=>{e.setOptions({description:h.target.value})},[e]),f=o.useMemo(()=>{const h=n.getSectionDependencyGraph();return n.fieldSections.filter(u=>!Zt.willCreateCycle(h,u.id,e.id))},[e.id,n]);return i.jsxs("div",{className:"flex w-full grow flex-col gap-4",children:[i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(a.Input.Root,{variant:"outline",size:"md",children:i.jsx(a.Input.Field,{placeholder:"Enter a section label (optional)",value:e.label??"",onChange:r,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:e.description??"",onChange:c,maxLength:1e3,resize:"vertical",size:"md"})]}),i.jsx(a.Separator,{size:"full"}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex justify-between gap-2",children:[i.jsx(a.Text,{accentColor:"base",children:"Conditions"}),i.jsx(Ia,{fieldSections:f,onSelectFieldSection:s,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",className:"w-max",children:[i.jsx(a.LuIcon,{icon:K}),"Add condition"]})})]}),i.jsx("div",{className:"flex flex-col gap-4",children:l.map((h,u)=>i.jsxs(o.Fragment,{children:[i.jsx(Xa,{sourceFieldSection:h,targetFieldSection:e}),u!==l.length-1?i.jsx(a.Separator,{size:"full"}):null]},h.id))})]}),i.jsx(a.Separator,{size:"full"})]})});Ya.displayName="FieldSectionBuilder";const Qa=o.memo(t=>{const{fieldSection:e,sectionIndex:n}=t,{fieldSchema:l}=o.use(ae),s=a.useAlertDialog(),r=o.useCallback(()=>{l.removeFieldSection(e)},[l,e]),c=o.useCallback(F=>{const V=F==="up"?n-1:n+1;l.moveFieldSection(n,V)},[l,n]),f=o.useCallback(()=>{l.addFieldSection(e.duplicate(b.v4()))},[l,e]),h=o.useCallback(F=>{e.addField(Xn(F))},[e]),u=o.useCallback(()=>{c("up")},[c]),p=o.useCallback(()=>{c("down")},[c]),m=o.useCallback(async()=>{const F=[e.serialize()],V=we.reseedFieldSections(F,{conditions:!1}),w=JSON.stringify(V);await navigator.clipboard.writeText(w),a.toast.success({title:"Section copied"})},[e]),C=o.useCallback(async()=>{const V=l.getDependenciesOfSection(e.id).map(N=>N.serialize()),w=we.reseedFieldSections(V,{conditions:!0}),M=JSON.stringify(w);await navigator.clipboard.writeText(M),a.toast.success({title:"Section copied"})},[e,l]),g=o.useCallback(async()=>{const F=l.getDependenciesOfSection(e.id),V=F.length>1,w=F.length-1;V?s({title:"Copy section dependencies?",description:`This section has ${w} dependent section${w>1?"s":""} that will also be copied to maintain the conditions. Do you want to include these dependencies?`,action:"Include",onAction:C,cancel:"Dont include",onCancel:m}):m()},[e,l,s,C,m]),y=o.useCallback(async()=>{let F="";try{F=await navigator.clipboard.readText()}catch{a.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const V=F.trim();if(!V){a.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const w=JSON.parse(V),M=Yt.JSONFieldSectionSchema.array().parse(w),N=Jn(M);if(N.length===0){a.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[S,q]of N.entries())l.addFieldSection(q,n+1+S);a.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(w){console.error(w),a.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[l,n]);return i.jsxs(a.Card,{variant:"outline",className:"flex w-full items-center justify-between gap-4",size:"sm",children:[i.jsxs("div",{className:"flex w-full grow flex-col gap-4",children:[i.jsx(Ya,{fieldSection:e}),i.jsxs("div",{className:"flex w-full flex-col gap-2",children:[i.jsxs("div",{className:"flex justify-between gap-2",children:[i.jsx(a.Text,{accentColor:"base",size:"md",children:"Fields"}),i.jsx(Zn,{onSelectFieldType:h,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:K})," Add field"]})})]}),e.fields.map((F,V)=>i.jsx(jt,{field:F,fieldSection:e,fieldIndex:V,sectionIndex:n},F.id))]})]}),i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(a.IconButton,{type:"button",onClick:u,disabled:n===0,"aria-label":"Move section up",children:i.jsx(a.LuIcon,{icon:Ze})}),i.jsx(a.IconButton,{type:"button",onClick:p,disabled:n===l.fieldSections.length-1,"aria-label":"Move section down",children:i.jsx(a.LuIcon,{icon:ol})}),i.jsxs(a.Menu.Root,{align:"end",children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.IconButton,{type:"button",children:i.jsx(a.LuIcon,{icon:al})})}),i.jsxs(a.Menu.Content,{size:"sm",children:[i.jsxs(a.Menu.Item,{onSelect:f,children:[i.jsx(a.LuIcon,{icon:Rn}),"Duplicate section"]}),i.jsxs(a.Menu.Item,{onSelect:g,children:[i.jsx(a.LuIcon,{icon:tl}),"Copy JSON"]}),i.jsxs(a.Menu.Item,{onSelect:y,children:[i.jsx(a.LuIcon,{icon:ll}),"Paste JSON"]}),i.jsxs(a.Menu.Item,{onSelect:r,children:[i.jsx(a.LuIcon,{icon:se}),"Delete section"]})]})]})]})]})});Qa.displayName="FieldSectionWithActions";const Ra=o.memo(()=>{const{handleSubmit:t}=Q.useFormContext(),{errors:e}=Q.useFormState(),{onSave:n,onCancel:l}=o.use(ae),{fieldSchema:s}=o.use(ae),r=o.useCallback(()=>{s.addFieldSection(new W({id:b.v4(),fields:[]}))},[s]),c=o.useCallback(async()=>{try{const h=s.serialize(),u=we.reseedFieldSections(h,{conditions:!0}),p=JSON.stringify(u);await navigator.clipboard.writeText(p),a.toast.success({title:"Sections copied",description:"All sections JSON copied to clipboard."})}catch{a.toast.error({title:"Copy failed",description:"Unable to copy the sections JSON."})}},[s]),f=o.useCallback(async()=>{let h="";try{h=await navigator.clipboard.readText()}catch{a.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const u=h.trim();if(!u){a.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const p=JSON.parse(u),m=Yt.JSONFieldSectionSchema.array().parse(p),C=Jn(m);if(C.length===0){a.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[g,y]of C.entries())s.addFieldSection(y,s.fieldSections.length+g);a.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(p){console.error(p),a.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[s]);return i.jsxs("form",{className:"flex flex-col gap-4",onSubmit:t(n),children:[i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",onClick:c,children:[i.jsx(a.LuIcon,{icon:tl})," Copy JSON"]}),i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",onClick:f,children:[i.jsx(a.LuIcon,{icon:ll})," Paste JSON"]})]}),s.fieldSections.map((h,u)=>i.jsx(Qa,{fieldSection:h,sectionIndex:u},h.id)),i.jsxs(a.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:r,children:[i.jsx(a.LuIcon,{icon:K})," Add section"]})]}),!!e.fields?.message&&i.jsx(a.Text,{size:"xs",accentColor:"danger",children:e.fields.message}),i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[l&&i.jsx(a.Button,{type:"button",variant:"soft",accentColor:"base",onClick:l,children:"Cancel"}),i.jsx(a.Button,{type:"submit",variant:"surface",children:"Save"})]})]})});Ra.displayName="FormBuilderListBuilder";function es(t){const e=n=>{const l={};for(const[s,r]of Object.entries(n))typeof r=="string"?l[s]={type:"validate",message:r}:l[s]=e(r);return l};return e(t)}const ns=o.memo(o.forwardRef((t,e)=>{const{disabled:n=!1,fieldSchema:l,values:s={},onValuesChange:r,onSubmit:c,submitText:f="Submit",hideSubmit:h=!1,cancelText:u,onCancel:p,hideCancel:m=!1,className:C,submitButtonProps:g,cancelButtonProps:y,cancelIcon:F,submitIcon:V,size:w="md"}=t,M=o.useMemo(()=>l.initializeValues(s),[l,s]),N=o.useCallback(A=>{c?.(A)},[c]),S=Q.useForm({values:M,mode:"onBlur",criteriaMode:"all",disabled:n,resolver:A=>{const J=l.validateValues(A),Z=es(J);return Object.keys(J).length>0?{values:{},errors:Z}:{values:A,errors:{}}}}),q=o.useCallback(A=>{r?.(A)},[r]);o.useEffect(()=>{const{unsubscribe:A}=S.watch((J,{type:Z})=>{Z==="change"&&q(J)});return()=>{A()}},[S,q]);const x=fl(l.getFieldSections()),T=o.useMemo(()=>({fieldSchema:l,size:w}),[l,w]),_=!m&&!!p,X=!h;return i.jsx(Q.FormProvider,{...S,children:i.jsx(B,{value:T,children:i.jsxs("form",{ref:e,className:Y.cx(C,"flex flex-col gap-4"),onSubmit:S.handleSubmit(N),children:[i.jsx("div",{className:Ys({size:w}),children:x}),!n&&(_||X)?i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:w,children:[_?i.jsxs(a.Button,{accentColor:"base",type:"button",variant:"soft",onClick:p,...y,children:[i.jsx(a.LuIcon,{icon:F??R}),u]}):null,X?i.jsxs(a.Button,{type:"submit",accentColor:"primary",variant:"surface",...g,children:[i.jsx(a.LuIcon,{icon:V??H}),f]}):null]}):null]})})})})),is=o.memo(()=>{const{fieldSchema:t}=o.use(ae);return i.jsx(ns,{fieldSchema:t,disabled:!1})});is.displayName="FormBuilderPreview";const ts=o.memo(t=>{const{children:e,initialFields:n,onSave:l,onCancel:s,disableRequiredFields:r=!1}=t,c=o.useCallback(y=>{const F={};(!y.fields||y.fields.length===0)&&(F.fields="At least one field is required.");const V=[];for(const[N,S]of y.fields.entries())for(const[q,x]of S.fields.entries()){const T=ba(x.type,`fields.${N}.fields.${q}`)?.map(({field:_})=>_)??[];V.push(...T)}const w={};for(const N of V)w[N.id]=Qt(y,N.id);const M=Wt(V,w);return Object.keys(M).length>0&&(F.fields=M.fields),Object.keys(F).length>0&&a.toast.error({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),F},[]),f=o.useMemo(()=>({fields:n??[]}),[n]),h=Q.useForm({values:f,mode:"onSubmit",criteriaMode:"all",reValidateMode:"onSubmit",resolver:y=>{const F=c(y),V=es(F);return Object.keys(F).length>0?{values:{},errors:V}:{values:y,errors:{}}}}),u=o.useCallback(y=>{h.setValue("fields",y.config())},[h]),p=Q.useWatch({control:h.control,compute:y=>y.fields}),m=o.useMemo(()=>{const y=we.fromConfig(p);return y.observe(u),y},[p,u]),C=o.useMemo(()=>({fieldSchema:m,disableRequiredFields:r,onSave:l,onCancel:s}),[r,l,s,m]),g=o.useMemo(()=>({fieldSchema:m,size:"sm"}),[m]);return i.jsx(ae,{value:C,children:i.jsx(B,{value:g,children:i.jsx(Q.FormProvider,{...h,children:e})})})});ts.displayName="FormBuilderRoot";const sr={Root:ts,FlowBuilder:Za,ListBuilder:Ra,Preview:is};d.AndFieldCondition=$e,d.BaseAtomicFieldCondition=v,d.BaseCompoundFieldCondition=Pe,d.BaseField=I,d.BaseFieldCondition=vi,d.BaseFormElement=Se,d.BaseOptionsField=ee,d.BaseStringField=ze,d.BooleanField=de,d.BooleanFieldConditionCell=Va,d.BooleanFieldEqualsCondition=sn,d.BooleanFieldInput=si,d.BooleanFieldNotEqualsCondition=Fi,d.CheckboxListField=ie,d.CheckboxListFieldConditionCell=wa,d.CheckboxListFieldEqualsCondition=on,d.CheckboxListFieldEveryCondition=wi,d.CheckboxListFieldNoneCondition=bi,d.CheckboxListFieldNotEqualsCondition=Vi,d.CheckboxListFieldSomeCondition=Si,d.CompoundFieldConditionCell=Ha,d.ConditionManager=Kl,d.DateField=Ne,d.DateFieldAfterCondition=qi,d.DateFieldBeforeCondition=Mi,d.DateFieldConditionCell=qa,d.DateFieldEqualsCondition=cn,d.DateFieldInCondition=Oi,d.DateFieldInput=ri,d.DateFieldNotEqualsCondition=Ii,d.DateFieldNotInCondition=Ti,d.FIELD_TYPES=Hl,d.FieldConditionBuilder=Ht,d.FieldConditionBuilderContext=Jt,d.FieldConditionCell=Gt,d.FieldSchema=we,d.FieldSection=W,d.FieldTypeGroup=O,d.FieldTypeToClsMapping=Ee,d.FieldsRenderer=ns,d.FileCard=ii,d.FormBuilder=sr,d.ImageCapturer=di,d.ImageCapturerProvider=Sl,d.ImageCard=ci,d.ImageFile=be,d.ImageViewer=li,d.ImageViewerProvider=hl,d.InputWithLabel=D,d.MultiSelectField=te,d.MultiSelectFieldConditionCell=Oa,d.MultiSelectFieldEqualsCondition=hn,d.MultiSelectFieldEveryCondition=Li,d.MultiSelectFieldNoneCondition=Bi,d.MultiSelectFieldNotEqualsCondition=Ei,d.MultiSelectFieldSomeCondition=Ai,d.MultiStringField=re,d.MultiStringFieldConditionCell=Ta,d.MultiStringFieldEqualsCondition=pn,d.MultiStringFieldEveryCondition=Di,d.MultiStringFieldNoneCondition=$i,d.MultiStringFieldNotEqualsCondition=_i,d.MultiStringFieldSomeCondition=Pi,d.NandFieldCondition=Ni,d.NorFieldCondition=xi,d.NumberField=G,d.NumberFieldConditionCell=Ea,d.NumberFieldEqualsCondition=mn,d.NumberFieldGreaterThanCondition=Gi,d.NumberFieldGreaterThanOrEqualsCondition=Ji,d.NumberFieldInRangeCondition=Hi,d.NumberFieldLessThanCondition=ji,d.NumberFieldLessThanOrEqualsCondition=Ui,d.NumberFieldNotEqualsCondition=ki,d.NumberFieldNotInRangeCondition=Wi,d.OTPField=ce,d.OTPFieldConditionCell=La,d.OTPFieldEqualsCondition=yn,d.OTPFieldExcludesCondition=Xi,d.OTPFieldIncludesCondition=Zi,d.OTPFieldNotEqualsCondition=Ki,d.Observable=_e,d.OrFieldCondition=zi,d.PassFailField=he,d.PassFailFieldConditionCell=Aa,d.PassFailFieldEqualsCondition=Fn,d.PassFailFieldExcludesCondition=Ri,d.PassFailFieldIncludesCondition=Qi,d.PassFailFieldNotEqualsCondition=Yi,d.RadioField=fe,d.RadioFieldConditionCell=Ba,d.RadioFieldEqualsCondition=wn,d.RadioFieldExcludesCondition=it,d.RadioFieldIncludesCondition=nt,d.RadioFieldNotEqualsCondition=et,d.RatingField=pe,d.RatingFieldConditionCell=_a,d.RatingFieldEqualsCondition=bn,d.RatingFieldGreaterThanCondition=st,d.RatingFieldGreaterThanOrEqualsCondition=rt,d.RatingFieldInRangeCondition=ot,d.RatingFieldLessThanCondition=lt,d.RatingFieldLessThanOrEqualsCondition=at,d.RatingFieldNotEqualsCondition=tt,d.RatingFieldNotInRangeCondition=dt,d.ScanField=Ie,d.ScanFieldConditionCell=Da,d.ScanFieldEqualsCondition=Nn,d.ScanFieldExcludesCondition=ht,d.ScanFieldIncludesCondition=ut,d.ScanFieldNotEqualsCondition=ct,d.Scanner=Re,d.ScannerProvider=Al,d.SelectField=ge,d.SelectFieldConditionCell=Pa,d.SelectFieldEqualsCondition=In,d.SelectFieldExcludesCondition=gt,d.SelectFieldIncludesCondition=pt,d.SelectFieldNotEqualsCondition=ft,d.StringField=me,d.StringFieldConditionCell=$a,d.StringFieldEqualsCondition=qn,d.StringFieldExcludesCondition=yt,d.StringFieldIncludesCondition=Ct,d.StringFieldNotEqualsCondition=mt,d.TextField=Ce,d.TextFieldConditionCell=ka,d.TextFieldEqualsCondition=Tn,d.TextFieldExcludesCondition=Vt,d.TextFieldIncludesCondition=Ft,d.TextFieldNotEqualsCondition=vt,d.TimeField=Me,d.TimeFieldAfterCondition=bt,d.TimeFieldBeforeCondition=St,d.TimeFieldConditionCell=ja,d.TimeFieldControl=ln,d.TimeFieldEqualsCondition=Ln,d.TimeFieldInCondition=zt,d.TimeFieldInput=yi,d.TimeFieldNotEqualsCondition=wt,d.TimeFieldNotInCondition=Nt,d.UNLABELLED_FIELD_LABEL=P,d.UNLABELLED_SECTION_LABEL=an,d.URLField=qe,d.URLFieldConditionCell=Ga,d.URLFieldEqualsCondition=Dn,d.URLFieldExcludesCondition=qt,d.URLFieldIncludesCondition=Mt,d.URLFieldNotEqualsCondition=It,d.UTC_OFFSETS=mi,d.UTC_OFFSETS_SET=$l,d.UUIDFile=le,d.UUIDPromise=xe,d.UploadField=Fe,d.UploadFieldConditionCell=Ua,d.UploadFieldEqualsCondition=Bn,d.UploadFieldNotEqualsCondition=xt,d.VideoCard=hi,d.VideoFile=ui,d.applyConditions=$n,d.areFieldValuesBlank=pa,d.areFieldValuesComplete=ma,d.areFieldValuesEqual=ha,d.areFieldValuesPartial=ga,d.areFileAndPromiseArraysEqual=Qe,d.areJSONPassFailFieldValuesEqual=ql,d.arePassFieldValuesEqual=Ml,d.awaitFilesAndPromises=ar,d.blankFieldValues=fa,d.booleanFieldConditionModifierConfig=rn,d.changedFieldValues=ca,d.checkboxListFieldConditionModifierConfig=dn,d.cleanCondition=kn,d.cleanConditions=jn,d.cleanFieldValues=Hn,d.cleanSerializedCondition=Un,d.cleanSerializedConditions=Lt,d.cleanSerializedFieldValues=Dt,d.compoundFieldConditionOperatorConfig=ke,d.createAtomicCondition=Ge,d.createField=Xn,d.createTime=ye,d.dateFieldConditionModifierConfig=un,d.deserializeCondition=Ot,d.deserializeConditions=je,d.deserializeField=Gn,d.deserializeFieldConfig=Bt,d.deserializeFieldConfigs=Rl,d.deserializeFieldElement=Zl,d.deserializeFieldElementConfig=ea,d.deserializeFieldElementConfigs=na,d.deserializeFieldElements=Jn,d.deserializeFieldValues=sa,d.deserializeFields=Zs,d.deserializePassFailFieldValue=Il,d.extractFilesAndPromisesFromFieldValues=ra,d.fieldDataMapping=L,d.fieldElementFromConfig=Yl,d.fieldElementsFromConfigs=Ql,d.fieldFromConfig=At,d.fieldSpacingCva=Wn,d.fieldTypeGroupDataMapping=Wl,d.fieldsFromConfigs=Xl,d.formatTime=tn,d.formatUTCOffset=nn,d.getCurrentUTCOffset=jl,d.getFieldsMapping=Xs,d.getImagesFromFields=lr,d.getUTCMinuteOfDay=ve,d.getUTCOffsetMinutes=Ul,d.initializeFieldValues=da,d.insertFilesAndPromisesToFieldValues=oa,d.isFileAndPromiseArray=vl,d.isJSONPassFailFieldValue=zl,d.isPassFailFieldStatus=pi,d.isPassFailFieldValue=Nl,d.isStringArray=Be,d.isTime=ne,d.isTimeInRange=Ci,d.isTimeRange=Js,d.isUTCOffset=en,d.multiSelectFieldConditionModifierConfig=fn,d.multiStringFieldConditionModifierConfig=gn,d.normalizeFieldOption=ai,d.normalizeFieldOptions=oe,d.numberFieldConditionModifierConfig=Cn,d.otpFieldConditionModifierConfig=vn,d.parseTime=De,d.passFailFieldConditionModifierConfig=Vn,d.passFailFieldStatusMapping=ue,d.passFailFieldStatuses=Te,d.radioFieldConditionModifierConfig=Sn,d.ratingFieldConditionModifierConfig=zn,d.scanFieldConditionModifierConfig=xn,d.selectFieldConditionModifierConfig=Mn,d.serializeCondition=Tt,d.serializeConditions=Et,d.serializeFieldConfig=_t,d.serializeFieldConfigs=ia,d.serializeFieldElementConfig=ta,d.serializeFieldElementConfigs=la,d.serializeFieldValues=aa,d.serializePassFailFieldValue=xl,d.stringFieldConditionModifierConfig=On,d.textFieldConditionModifierConfig=En,d.timeFieldConditionModifierConfig=An,d.unchangedFieldValues=ua,d.uploadFieldConditionModifierConfig=_n,d.urlFieldConditionModifierConfig=Pn,d.useConditionManager=Ks,d.useFieldConditionBuilderContext=Ja,d.useFieldInput=$,d.useFieldInputs=Ye,d.useFieldSectionInputs=fl,d.useImageCapturer=oi,d.useImageViewer=Xe,d.useObjectUrl=ti,d.useScanner=ks,d.useScannerContext=El,d.validateFieldValues=Wt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));