@overmap-ai/forms 2.0.0 → 2.0.1-camera.1
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.
- package/dist/ImageCapturer/Camera.d.ts +4 -0
- package/dist/ImageCapturer/ImageCapturer.d.ts +7 -0
- package/dist/ImageCapturer/ImageCapturerProvider.d.ts +2 -0
- package/dist/ImageCapturer/ImagesViewer.d.ts +8 -0
- package/dist/ImageCapturer/context.d.ts +3 -0
- package/dist/ImageCapturer/hooks.d.ts +1 -0
- package/dist/ImageCapturer/index.d.ts +4 -0
- package/dist/ImageCapturer/typings.d.ts +4 -0
- package/dist/forms.js +3069 -2706
- package/dist/forms.umd.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
package/dist/forms.umd.cjs
CHANGED
|
@@ -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,s,Q,o,Da,O,Tt,K,V,Yi,Ot,Et,Ls,Lt,Bt,Bs,As,At,Ds){"use strict";const _s=l=>l.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),$s=l=>l.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,n,t)=>t?t.toUpperCase():n.toLowerCase()),Dt=l=>{const e=$s(l);return e.charAt(0).toUpperCase()+e.slice(1)},_t=(...l)=>l.filter((e,n,t)=>!!e&&e.trim()!==""&&t.indexOf(e)===n).join(" ").trim(),ks=l=>{for(const e in l)if(e.startsWith("aria-")||e==="role"||e==="title")return!0};var Ps={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 js=o.forwardRef(({color:l="currentColor",size:e=24,strokeWidth:n=2,absoluteStrokeWidth:t,className:a="",children:r,iconNode:c,...f},h)=>o.createElement("svg",{ref:h,...Ps,width:e,height:e,stroke:l,strokeWidth:t?Number(n)*24/Number(e):n,className:_t("lucide",a),...!r&&!ks(f)&&{"aria-hidden":"true"},...f},[...c.map(([u,p])=>o.createElement(u,p)),...Array.isArray(r)?r:[r]]));const N=(l,e)=>{const n=o.forwardRef(({className:t,...a},r)=>o.createElement(js,{ref:r,iconNode:e,className:_t(`lucide-${_s(Dt(l))}`,`lucide-${l}`,t),...a}));return n.displayName=Dt(l),n};const Us=N("align-justify",[["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 18h18",key:"1h113x"}],["path",{d:"M3 6h18",key:"d0wm0j"}]]);const Gs=N("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 Js=N("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 Hs=N("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 G=N("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const pi=N("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const Qi=N("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 Ws=N("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Ks=N("circle-dot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);const Xs=N("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 Zs=N("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 $t=N("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const kt=N("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 Ys=N("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 Pt=N("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 Qs=N("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 Ri=N("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 jt=N("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 Ut=N("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 Rs=N("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 ea=N("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 na=N("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 ia=N("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 Gt=N("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 Jt=N("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 ta=N("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 la=N("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 sa=N("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 aa=N("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 ra=N("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 gi=N("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Ht=N("move-down",[["path",{d:"M8 18L12 22L16 18",key:"cskvfv"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const Wt=N("move-up",[["path",{d:"M8 6L12 2L16 6",key:"1yvkyx"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const X=N("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);const oa=N("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 da=N("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 ca=N("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 ua=N("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 ha=N("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 Kt=N("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 fa=N("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 pa=N("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 Fe=N("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 et=N("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 ga=N("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 te=N("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),nt=o.memo(l=>{const{ref:e,file:n,className:t,error:a,rightSlot:r,size:c,...f}=l,h=()=>a?i.jsxs(i.Fragment,{children:[i.jsx(s.LuIcon,{icon:Qi,color:"var(--base-a11)"}),i.jsx(s.Text,{accentColor:"base",className:"truncate",size:c,children:a})]}):n?i.jsxs(i.Fragment,{children:[i.jsx(s.LuIcon,{icon:ea,color:"var(--base-a11)"}),i.jsx(s.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(s.Spinner,{size:c})})});return i.jsxs(s.Card,{className:Q.cx(t,"flex w-full items-center gap-2"),ref:e,size:"xs",...f,children:[h(),r]})});nt.displayName="FileCard";function Qe(l){return Array.isArray(l)?l.every(e=>typeof e=="string"):!1}class Re{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 ze extends Re{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:t}=e;return{id:n,type:t}}static _serializeConfig(e){const{id:n,type:t}=e;return{id:n,type:t}}}class x extends ze{label;description;required;image;constructor(e){const{label:n,description:t,required:a,image:r,...c}=e;super(c),this.label=n,this.description=t,this.required=a,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 t=n(e);if(t)return t}}}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:t,required:a,...r}=e;return{...ze._deserializeConfig(r),label:n,description:t??void 0,required:a}}static _serializeConfig(e){const{label:n,description:t,required:a,...r}=e;return{...ze._serializeConfig(r),label:n,description:t,required:a}}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 L=o.createContext({}),it=l=>{const[e,n]=o.useState(null);return o.useLayoutEffect(()=>{const t=URL.createObjectURL(l);return n(t),()=>{URL.revokeObjectURL(t)}},[l]),e},qe=o.memo(l=>{const{file:e,...n}=l,t=it(e);return i.jsx("img",{src:t??void 0,alt:e.name,...n})});qe.displayName="ImageFile";const Xt=o.createContext(()=>{throw new Error("No ImageViewerProvider found")}),mi=()=>o.useContext(Xt),tt=o.memo(l=>{const{file:e,onClose:n}=l,t=o.useCallback(()=>{Ot.saveAs(e,e.name)},[e]);return i.jsx(s.Overlay.Root,{open:!0,onOpenChange:n,children:i.jsxs(s.Overlay.Content,{onOpenAutoFocus:s.preventDefault,children:[i.jsxs(s.ButtonGroup,{className:"absolute right-0 top-0 flex items-center gap-2 p-2",accentColor:"base",variant:"ghost",children:[i.jsxs(s.Tooltip.Root,{children:[i.jsx(s.Tooltip.Trigger,{asChild:!0,children:i.jsx(s.IconButton,{onClick:t,"aria-label":"download",children:i.jsx(s.LuIcon,{icon:jt})})}),i.jsx(s.Tooltip.Content,{size:"sm",children:"Download"})]}),i.jsx(s.Separator,{orientation:"vertical",size:"sm"}),i.jsx(s.Overlay.Close,{asChild:!0,children:i.jsx(s.IconButton,{onClick:n,"aria-label":"close",children:i.jsx(s.LuIcon,{icon:te})})})]}),i.jsx("figure",{className:"flex size-full items-center justify-center overflow-hidden p-4",children:i.jsx(qe,{className:"max-h-full max-w-full",file:e})})]})})});tt.displayName="ImageViewer";const Zt=o.memo(l=>{const{children:e}=l,[n,t]=o.useState(null),a=o.useCallback(()=>{t(null)},[]),r=o.useCallback(f=>{t(f(a))},[a]),c=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),a())},[a,n]);return i.jsxs(Xt.Provider,{value:r,children:[e,n&&i.jsx(tt,{file:n.file,onClose:c})]})});Zt.displayName="FileViewerProvider";const B=o.memo(l=>{const{label:e,error:n,description:t,required:a,children:r,inputId:c,image:f,size:h}=l,[u,p]=o.useState(void 0),m=mi();o.useEffect(()=>{f instanceof Promise?f.then(p).catch(console.error):p(f)},[f]);const g=o.useCallback(()=>{u&&m(()=>({file:u}))},[m,u]),C=a?`${e??"Unlabelled"} *`:e??"Unlabelled";return i.jsxs("div",{className:"flex flex-col gap-1",children:[u&&i.jsx(qe,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:u,onClick:g}),(!!e||!!t)&&i.jsxs("div",{className:"flex flex-col",children:[i.jsx("label",{className:"w-max max-w-full",htmlFor:c,children:i.jsx(s.Text,{size:h,className:"text-wrap",children:C})}),!!t&&i.jsx(s.Text,{accentColor:"base",size:h,children:t})]}),r,!!n&&i.jsx(s.Text,{accentColor:"danger",size:h,children:n})]})});B.displayName="InputWithLabel";const Yt=l=>l.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),Ci=l=>l.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),_=l=>{const{field:e}=l,{field:{value:n,name:t,onChange:a,onBlur:r,disabled:c},fieldState:{isTouched:f,error:h}}=K.useController({name:e.id});return{value:n,name:t,disabled:c,isTouched:f,error:h?.message??"",onChange:a,onBlur:r}},Qt=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),[u,p]=o.useState(""),[m,g]=o.useState(""),C=o.useCallback(z=>{c(z),r()},[c,r]),F=o.useCallback(z=>{t&&t.findIndex(b=>b===z.target.value.trim())>=0?g("All options must be unique"):z.target.value?g(""):g("Option cannot be empty"),p(z.target.value)},[p,t]),w=o.useCallback(()=>{if(m)return;if(!u.trim()){g("Option cannot be empty");return}const z=u.trim();C([...t,z]),p("")},[u,m,C,t]),S=o.useCallback(z=>{z.key==="Enter"&&(z.preventDefault(),w())},[w]),v=o.useCallback(z=>{const b=Array.from(t);b.splice(z,1),C(b)},[t,C]),I=o.useCallback(z=>{if(!z.destination)return;const b=z.source.index,T=z.destination.index,j=Array.from(t),[ie]=j.splice(b,1);j.splice(T,0,ie),C(j)},[C,t]),q=o.useCallback(()=>{r()},[r]);return i.jsx(Yi.DragDropContext,{onDragEnd:I,children:i.jsxs(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:m||f,image:e.image,children:[(!h||t.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx(s.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:n,children:i.jsx(s.Input.Field,{value:u,onChange:F,onKeyDown:S,id:e.id,placeholder:e.placeholder??"Press enter to add a new option",onBlur:q,name:a,disabled:h})}),i.jsx(s.IconButton,{size:n,accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!m||h,onClick:w,children:i.jsx(s.LuIcon,{icon:X})})]}),t.length!==0&&i.jsx(Yi.Droppable,{droppableId:`${e.id}-droppable`,children:z=>i.jsxs("div",{className:"flex flex-col gap-1",...z.droppableProps,ref:z.innerRef,children:[t.map((b,T)=>i.jsx(Yi.Draggable,{draggableId:`${b}-draggable`,index:T,isDragDisabled:h,children:({draggableProps:j,dragHandleProps:ie,innerRef:Ye})=>i.jsxs(s.Badge,{...ie,...j,ref:Ye,className:"flex items-center justify-between gap-2",accentColor:"base",size:n,variant:"soft",children:[i.jsx(s.Text,{className:"truncate",highContrast:!0,children:lt(b).label}),i.jsx(s.IconButton,{className:"bg-transparent!",size:n,variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:h,onClick:()=>{v(T)},children:i.jsx(s.LuIcon,{icon:te})})]})},`${e.id}-${b}-${T}`)),z.placeholder]})})]})})});Qt.displayName="MultiStringFieldInput";class le extends x{type="multi-string";minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:t,placeholder:a,...r}=e;super(r),this.minLength=n,this.maxLength=t,this.placeholder=a}render(){return i.jsx(Qt,{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 le({...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 le(e)}static fromConfig(e){return new le(e)}static deserializeConfig(e){const{minLength:n,maxLength:t,placeholder:a,...r}=e;return{...x._deserializeConfig(r),minLength:n,maxLength:t,placeholder:a}}static serializeConfig(e){const{minLength:n,maxLength:t,placeholder:a,...r}=e;return{...x._serializeConfig(r),minLength:n,maxLength:t,placeholder:a}}isSerializedValue(e){return Qe(e)}isValue(e){return Qe(e)}blankValue(){return[]}areValuesEqual(e,n){const t=new Set(e),a=new Set(n);return t.size===a.size&&t.isSubsetOf(a)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const t=new Set(e),a=new Set(n);return t.size===a.size&&t.isSubsetOf(a)}}function lt(l){return typeof l=="string"&&(l={label:l,value:l}),l}function se(l){return l.map(lt)}class Z extends x{options;constructor(e){const{options:n,...t}=e;super(t),this.options=se(n)}serialize(){return{...super.serialize(),options:this.options}}config(){return{...super.config(),options:this.options}}static _deserializeConfig(e){const{options:n,...t}=e;return{...x._deserializeConfig(t),options:n}}static _serializeConfig(e){const{options:n,...t}=e;return{...x._serializeConfig(t),options:se(n)}}getOptions(){return{...super.getOptions(),options:this.options}}setOptions(e){"options"in e&&e.options!==void 0&&(this.options=se(e.options)),super.setOptions(e)}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new le({label:"Options",description:"List possible options for the user to select from.",required:!0,id:`${n}options`,minLength:2}),showDirectly:!0}]}}const st=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,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(B,{size:n,inputId:e.id,label:e.label,description:e.description,error:f,image:e.image,required:e.required,children:i.jsx(s.Checkbox.Root,{id:e.id,name:a,checked:t??!1,onCheckedChange:u,onBlur:p,size:n,accentColor:"base",variant:"surface",disabled:h,children:i.jsx(s.Checkbox.Indicator,{children:i.jsx(s.LuIcon,{icon:G})})})})});st.displayName="BooleanFieldInput";class ae extends x{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 ae({...this.getOptions(),id:e})}static deserialize(e){return new ae(e)}static fromConfig(e){return new ae(e)}static deserializeConfig(e){return x._deserializeConfig(e)}static serializeConfig(e){return x._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(st,{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 Rt=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(g=>{const C=g.target.valueAsNumber,F=isNaN(C)?null:C;c(F)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(g=>{g.key==="Enter"&&g.preventDefault()},[]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(s.Input.Root,{accentColor:"base",variant:"surface",size:n,children:i.jsx(s.Input.Field,{id:e.id,name:a,onChange:u,onBlur:p,value:t??"",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})})})});Rt.displayName="NumberFieldInput";class U extends x{type="number";minimum;maximum;integers;placeholder;constructor(e){const{minimum:n,maximum:t,integers:a,placeholder:r,...c}=e;super(c),this.minimum=n,this.maximum=t,this.integers=a,this.placeholder=r}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new U({label:"Minimum",description:"Minimum value",integers:!0,required:!1,id:`${n}minimum`}),showDirectly:!1},{field:new U({label:"Maximum",description:"Maximum value",integers:!0,required:!1,id:`${n}maximum`}),showDirectly:!1},{field:new ae({label:"Integers",description:"Whole numbers only",required:!1,id:`${n}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),n=this.minimum,t=this.maximum;return typeof n=="number"&&e.push(a=>{if(typeof a=="number"&&a<n)return`Must be at least ${this.minimum}.`}),e.push(a=>{if(typeof a=="number"&&a<Number.MIN_SAFE_INTEGER)return"Cant be less than MIN_SAFE_INTEGER."}),typeof t=="number"&&e.push(a=>{if(typeof a=="number"&&a>t)return`Must be at most ${t}.`}),e.push(a=>{if(typeof a=="number"&&a>Number.MAX_SAFE_INTEGER)return"Cant be greater than MAX_SAFE_INTEGER."}),this.integers&&e.push(a=>{if(typeof a=="number"&&!Number.isInteger(a))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 U({...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 U(e)}static fromConfig(e){return new U(e)}static deserializeConfig(e){const{minimum:n,maximum:t,integers:a,placeholder:r,...c}=e;return{...x._deserializeConfig(c),minimum:n,maximum:t,integers:a,placeholder:r}}static serializeConfig(e){const{minimum:n,maximum:t,integers:a,placeholder:r,...c}=e;return{...x._serializeConfig(c),minimum:n,maximum:t,integers:a,placeholder:r}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Rt,{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 we extends x{minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:t,placeholder:a,...r}=e;super(r),this.minLength=n,this.maxLength=t,this.placeholder=a}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new U({label:"Minimum length",description:"Minimum number of characters",required:!1,id:`${n}minLength`,minimum:0,integers:!0}),showDirectly:!1},{field:new U({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,t=this.maxLength;return typeof n=="number"&&e.push(a=>{if(a.length<n)return`Minimum ${n} character(s).`}),typeof t=="number"&&e.push(a=>{if(a.length>t)return`Maximum ${t} 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:t,placeholder:a,...r}=e;return{...x._deserializeConfig(r),minLength:t,maxLength:n,placeholder:a}}static _serializeConfig(e){const{minLength:n,maxLength:t,placeholder:a,...r}=e;return{...x._serializeConfig(r),minLength:n,maxLength:t,placeholder:a}}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 el=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,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(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(s.CheckboxGroup.Root,{id:e.id,name:a,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:n,values:t,onValuesChange:u,disabled:h,children:e.options.map((m,g)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(s.CheckboxGroup.Item,{value:m.value,onBlur:p,children:i.jsx(s.CheckboxGroup.ItemIndicator,{children:i.jsx(s.LuIcon,{icon:G})})}),i.jsx(s.Text,{size:n,accentColor:"base",className:"truncate",children:m.label})]},`${e.id}-${m.value}-${g}`))})})});el.displayName="CheckboxListFieldInput";class R extends Z{type="checkbox-list";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new R({...this.getOptions(),id:e})}static deserialize(e){return new R(e)}static fromConfig(e){return new R(e)}static deserializeConfig(e){return R._deserializeConfig(e)}static serializeConfig(e){return R._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(el,{field:this})}isSerializedValue(e){if(!Qe(e))return!1;const n=new Set(this.options.map(({value:t})=>t));return e.every(t=>n.has(t))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const t=new Set(e),a=new Set(n);return t.size===a.size&&t.isSubsetOf(a)}areValuesEqual(e,n){const t=new Set(e),a=new Set(n);return t.size===a.size&&t.isSubsetOf(a)}}const at=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),[u,p]=o.useState(!1),m=o.useCallback(C=>{c(C??null),r(),p(!1)},[c,r]),g=o.useCallback(C=>{p(C),C||r()},[r]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(s.Popover.Root,{open:u,onOpenChange:g,children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:i.jsxs(s.Button,{id:e.id,name:a,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:n,disabled:h,children:[i.jsx(s.Text,{className:"truncate",highContrast:!!t,children:t?t.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd"}),i.jsx(s.LuIcon,{icon:pi})]})}),i.jsx(s.Popover.Content,{align:"start",size:n,children:i.jsx(s.DayPicker,{size:n,required:!1,mode:"single",variant:"solid",selected:t??void 0,onSelect:m})})]})})});at.displayName="DateFieldInput";class Se extends x{type="date";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Se({...this.getOptions(),id:e})}static deserialize(e){return new Se(e)}static fromConfig(e){return new Se(e)}static deserializeConfig(e){return x._deserializeConfig(e)}static serializeConfig(e){return x._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(at,{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 M=(l=>(l.Text="text",l.Selection="selection",l.Numeric="numeric",l.Temporal="temporal",l.Capture="capture",l.Assessment="assessment",l.Verification="verification",l))(M||{});const nl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,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(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(s.Menu.Root,{onOpenChange:p,align:"start",children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{id:e.id,name:a,className:"!justify-between",variant:"surface",type:"button",size:n,accentColor:"base",disabled:h,children:[i.jsx(s.Text,{className:"truncate",highContrast:t&&t.length>0,children:t&&t.length>0?t.join(", "):e.placeholder??"Select one or more..."}),i.jsx(s.LuIcon,{icon:pi})]})}),i.jsx(s.Menu.Content,{size:n,children:i.jsx(s.Menu.Scroll,{children:i.jsxs(s.Menu.MultiSelectGroup,{values:t,onValuesChange:u,children:[i.jsxs(s.Menu.SelectAllItem,{children:[i.jsx(s.Menu.CheckboxItemIndicator,{children:m=>m?i.jsx(s.LuIcon,{icon:gi}):i.jsx(s.LuIcon,{icon:G})}),"Select all"]}),e.options.map((m,g)=>i.jsxs(s.Menu.MultiSelectItem,{value:m.value,children:[i.jsx(s.Menu.SelectedIndicator,{children:i.jsx(s.LuIcon,{icon:G})}),m.label]},`${e.id}-${m.value}-${g}`))]})})})]})})});nl.displayName="MultiSelectFieldInput";class ee extends Z{type="multi-select";placeholder;constructor(e){const{placeholder:n,...t}=e;super(t),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 ee({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new ee(e)}static fromConfig(e){return new ee(e)}static deserializeConfig(e){const{placeholder:n,...t}=e;return{...Z._deserializeConfig(t),placeholder:n}}static serializeConfig(e){const{placeholder:n,...t}=e;return{...Z._serializeConfig(t),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(nl,{field:this})}isSerializedValue(e){if(!Qe(e))return!1;const n=new Set(this.options.map(({value:t})=>t));return e.every(t=>n.has(t))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}areValuesEqual(e,n){const t=new Set(e),a=new Set(n);return t.size===a.size&&t.isSubsetOf(a)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const t=new Set(e),a=new Set(n);return t.size===a.size&&t.isSubsetOf(a)}}const il=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(g=>{c(g)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useMemo(()=>Array.from({length:e.length},()=>V.v4()),[e.length]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(s.OneTimePasswordField.Root,{id:e.id,name:a,value:t,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(g=>i.jsx(s.OneTimePasswordField.Input,{id:g},g)),i.jsx(s.OneTimePasswordField.HiddenInput,{})]})})});il.displayName="OTPFieldInput";class re extends x{type="otp";length;constructor(e){const{length:n,...t}=e;super(t),this.length=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new U({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(t=>{if(t.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 re({...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 re(e)}static fromConfig(e){return new re(e)}static deserializeConfig(e){const{length:n,...t}=e;return{...x._deserializeConfig(t),length:n}}static serializeConfig(e){const{length:n,...t}=e;return{...x._serializeConfig(t),length:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(il,{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 oe={pass:{label:"Pass",icon:Ws},fail:{label:"Fail",icon:Zs},na:{label:"N/A",icon:Xs}},Te=Object.keys(oe);class de extends File{uuid;constructor(e,...n){super(...n),this.uuid=e}static from(e,n){return new de(e,[n],n.name,{lastModified:n.lastModified,type:n.type})}}class be 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 be((t,a)=>{Promise.resolve(e).then(t).catch(a)},n)}then(e,n){const t=super.then(e,n);return t.uuid=this.uuid,t}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 tl(l){return Array.isArray(l)?l.every(e=>e instanceof be||e instanceof de):!1}function yi(l,e){const n=new Set(l.map(({uuid:a})=>a)),t=new Set(e.map(({uuid:a})=>a));return n.size===t.size&&n.isSubsetOf(t)}const rt=o.memo(l=>{const{ref:e,file:n,error:t,rightSlot:a,className:r,size:c,...f}=l;return i.jsxs(s.Card,{className:Q.cx(r,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!t&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(s.Spinner,{size:c})}),!!n&&!t&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(qe,{className:"block size-full max-w-full object-cover",file:n})}),!!t&&i.jsx("div",{className:"grow"}),(!!n||!!t)&&i.jsxs(i.Fragment,{children:[i.jsx(s.Separator,{size:"full"}),i.jsxs("div",{className:"flex w-full shrink-0 items-center gap-2 self-end p-3",children:[t?i.jsx(s.LuIcon,{color:"var(--base-11)",icon:Qi}):n&&i.jsx(s.LuIcon,{color:"var(--base-11)",icon:Gt}),i.jsx(s.Text,{className:"truncate",size:c,children:t??n?.name}),a]})]})]})});rt.displayName="ImageCard";const ot=o.memo(l=>{const{file:e,...n}=l,t=it(e);return i.jsx("video",{src:t??void 0,...n})});ot.displayName="VideoFile";const dt=o.memo(l=>{const{ref:e,file:n,className:t,error:a,rightSlot:r,size:c,...f}=l;return i.jsxs(s.Card,{className:Q.cx(t,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!a&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(s.Spinner,{size:c})}),!!n&&!a&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(ot,{className:"block size-full max-w-full object-cover",file:n,controls:!0})}),!!a&&i.jsx("div",{className:"grow"}),(!!n||!!a)&&i.jsxs(i.Fragment,{children:[i.jsx(s.Separator,{size:"full"}),i.jsxs("div",{className:"flex w-full shrink-0 items-center gap-2 self-end p-3",children:[a?i.jsx(s.LuIcon,{color:"var(--danger-11)",icon:Qi}):n&&i.jsx(s.LuIcon,{color:"var(--base-11)",icon:ga}),i.jsx(s.Text,{className:"truncate",size:c,children:a??n?.name}),r]})]})]})});dt.displayName="VideoCard";const ct=o.memo(l=>{const{fileOrPromise:e,onRemove:n,disabled:t,size:a}=l,[r,c]=o.useState(e instanceof be?null:e),[f,h]=o.useState(null),u=mi();Et.useActiveEffect(v=>{if(h(null),!(e instanceof be)){c(e);return}c(null),e.then(I=>{v()&&c(I)}).catch(I=>{v()&&h(I instanceof Error?I.message:"Unknown error")})},[e]);const p=o.useCallback(()=>{if(!r)return;const v=new Blob([r]);Ot.saveAs(v,r.name)},[r]),m=o.useCallback(()=>{n(e)},[n,e]),g=o.useCallback(()=>{if(!r)return;const v=URL.createObjectURL(r);window.open(v,"_blank"),URL.revokeObjectURL(v)},[r]),C=o.useCallback(()=>{r&&u(v=>({file:r,onDelete:t?void 0:()=>{m(),v()}}))},[t,m,u,r]),F=o.useMemo(()=>i.jsx("div",{className:"flex grow justify-end",children:i.jsxs(s.Menu.Root,{modal:!0,children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.IconButton,{onClick:s.stopPropagation,type:"button",variant:"ghost",accentColor:"base",size:a,children:i.jsx(s.LuIcon,{icon:Ut})})}),i.jsxs(s.Menu.Content,{size:a,children:[i.jsxs(s.Menu.Item,{onSelect:p,disabled:!r,children:[i.jsx(s.LuIcon,{icon:jt})," Download"]}),t?null:i.jsxs(i.Fragment,{children:[i.jsx(s.Menu.Separator,{}),i.jsxs(s.Menu.Item,{onSelect:m,children:[i.jsx(s.LuIcon,{icon:Fe})," Delete"]})]})]})]})}),[t,m,p,r,a]),w=!!r?.type.startsWith("image/"),S=!!r?.type.startsWith("video/");return w?i.jsx(rt,{className:"cursor-pointer",onClick:C,file:r,error:f??void 0,rightSlot:F,size:a}):S?i.jsx(dt,{className:"cursor-pointer",onClick:C,file:r,error:f??void 0,rightSlot:F,size:a}):i.jsx(nt,{className:"cursor-pointer",file:r,error:f??void 0,onClick:g,rightSlot:F,size:a})});ct.displayName="DisplayFile";const ll=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useRef(null),p=o.useCallback(z=>{const b=e.cleanValue({...t,status:z});c(b),r()},[e,r,c,t]),m=o.useCallback(z=>{const b=z.target.value,T={...t,notes:b};c(T)},[t,c]),g=o.useCallback(()=>{r()},[r]),C=o.useCallback(z=>{const b=t.files.filter(({uuid:T})=>T!==z.uuid);c({...t,files:b}),r()},[c,r,t]),F=o.useCallback(()=>{u.current?.click()},[]),w=o.useCallback(z=>{const b=Array.from(z.target.files??[]).map(j=>de.from(V.v4(),j)),T={...t,files:[...t.files,...b]};c(T),r()},[r,c,t]);o.useEffect(()=>{if(!u.current)return;const z=new AbortController;return u.current.addEventListener("cancel",()=>{r()},{signal:z.signal}),()=>{z.abort()}},[r,t]);const S=t.status&&e.showNotesAndFilesOn.includes(t.status),v=`${e.id}-status`,I=`${e.id}-notes`,q=`${e.id}-files`;return i.jsx(B,{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(s.RadioGroup.Root,{id:v,className:"flex gap-2",name:a,value:t.status,disabled:h,accentColor:"base",variant:"surface",size:n,onValueChange:p,children:Te.map(z=>{const{label:b}=oe[z];return i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(s.RadioGroup.Item,{value:z,children:i.jsx(s.RadioGroup.Indicator,{children:i.jsx(s.LuIcon,{icon:$t,className:"fill-current"})})}),i.jsx(s.Text,{size:n,accentColor:"base",className:"truncate",children:b})]},`${e.id}-${z}`)})}),S&&i.jsxs(i.Fragment,{children:[i.jsx("div",{children:i.jsx(s.TextArea,{id:I,value:t.notes??"",name:a,onChange:m,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(s.Button,{className:"w-max",size:n,variant:"surface",accentColor:"base",onClick:F,type:"button",disabled:h,children:[i.jsx(s.LuIcon,{icon:et}),"Select files"]}),i.jsx("input",{id:q,name:a,type:"file",ref:u,multiple:!0,className:"hidden",onChange:w,value:""}),t.files.length>0&&i.jsx("div",{className:"flex h-max flex-wrap gap-2",children:t.files.map(z=>i.jsx(ct,{size:n,fileOrPromise:z,onRemove:C,disabled:h},z.uuid))})]})]})]})})});ll.displayName="PassFailFieldInput";const ut=l=>typeof l=="string"&&Te.includes(l),sl=l=>!(l===null||typeof l!="object"||!("status"in l)||!ut(l.status)||!("notes"in l)||typeof l.notes!="string"||!("files"in l)||!(Array.isArray(l.files)&&l.files.length===0)),al=l=>!(l===null||typeof l!="object"||!("status"in l)||!ut(l.status)||!("notes"in l)||typeof l.notes!="string"||!("files"in l)||!tl(l.files)),rl=l=>({status:l.status,notes:l.notes,files:[]}),ol=l=>({status:l.status,notes:l.notes,files:[]}),dl=(l,e)=>!(l.status!==e.status||l.notes!==e.notes||!yi(l.files,e.files)),cl=(l,e)=>!(l.status!==e.status||l.notes!==e.notes||l.files.length!==e.files.length);class ce extends x{type="pass-fail";showNotesAndFilesOn;constructor(e){const{showNotesAndFilesOn:n,...t}=e;super(t),this.showNotesAndFilesOn=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new ee({id:`${n}showNotesAndFilesOn`,label:"Show notes and files on",description:"Show the notes and files on desired statuses.",options:Te.map(t=>{const{label:a}=oe[t];return{value:t,label:a}}),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 ce({...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,t=this.blankValue();return n.length>0&&(e.push(a=>{if(!(!a.status||!n.includes(a.status))&&t.notes===a.notes)return"Notes is required."}),e.push(a=>{if(!(!a.status||!n.includes(a.status))&&yi(t.files,a.files))return"Files is required."})),e}static deserialize(e){const{showNotesAndFilesOn:n,...t}=e;return new ce({...t,showNotesAndFilesOn:n})}static fromConfig(e){return new ce(e)}static deserializeConfig(e){const{showNotesAndFilesOn:n,...t}=e;return{...x._deserializeConfig(t),showNotesAndFilesOn:n}}static serializeConfig(e){const{showNotesAndFilesOn:n,...t}=e;return{...x._serializeConfig(t),showNotesAndFilesOn:n}}serializeValue(e){return rl(e)}deserializeValue(e){return ol(e)}render(){return i.jsx(ll,{field:this})}isSerializedValue(e){return sl(e)}isValue(e){return al(e)}areValuesEqual(e,n){return dl(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 cl(e,n)}}const ul=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(g=>{c(g),r()},[r,c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(()=>{c(null),r()},[r,c]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(s.RadioGroup.Root,{id:e.id,name:a,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:n,value:t??"",onValueChange:u,disabled:h,children:[e.options.map((g,C)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(s.RadioGroup.Item,{value:g.value,onBlur:p,children:i.jsx(s.RadioGroup.Indicator,{children:i.jsx(s.LuIcon,{icon:$t,className:"fill-current"})})}),i.jsx(s.Text,{size:n,accentColor:"base",className:"truncate",children:g.label})]},`${e.id}-${g.value}-${C}`)),!!t&&i.jsxs(s.Button,{onClick:m,className:"-mx-2 w-max",type:"button",variant:"ghost",accentColor:"base",size:n,children:[i.jsx(s.LuIcon,{icon:te}),"Clear"]})]})})});ul.displayName="RadioFieldInput";class ue extends Z{type="radio";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new ue({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new ue(e)}static fromConfig(e){return new ue(e)}static deserializeConfig(e){return Z._deserializeConfig(e)}static serializeConfig(e){return Z._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(ul,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:t})=>t)]).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 ma=Q.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"]}}}),hl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(g=>{c(g),r()},[r,c]),p=o.useCallback(()=>{c(null),r()},[r,c]),m=Array.from({length:e.maxRating},(g,C)=>C+1);return i.jsx(B,{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(s.Rating.Root,{id:e.id,name:a,className:"flex items-center gap-0.5",value:t,onValueChange:u,disabled:h,children:m.map(g=>i.jsx(s.Rating.Item,{value:g,className:ma({size:n}),children:i.jsx(s.LuIcon,{icon:Kt,className:"size-full group-data-[active=true]:fill-current"})},`${e.id}-${g}`))}),!h&&t!==null&&i.jsx(s.IconButton,{onClick:p,type:"button",variant:"ghost",accentColor:"base",size:n,children:i.jsx(s.LuIcon,{icon:te})})]})})});hl.displayName="RatingFieldInput";class he extends x{type="rating";maxRating;constructor(e){const{maxRating:n,...t}=e;super(t),this.maxRating=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new U({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(t=>{if(typeof t=="number"&&(t<1||t>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 he({...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 he(e)}static fromConfig(e){return new he(e)}static deserializeConfig(e){const{maxRating:n,...t}=e;return{...x._deserializeConfig(t),maxRating:n}}static serializeConfig(e){const{maxRating:n,...t}=e;return{...x._serializeConfig(t),maxRating:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(hl,{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 ht=o.createContext(null),fl=()=>{const l=o.use(ht);if(!l)throw new Error("useScannerContext must be used within a component tree wrapped by ScannerProvider.");return l},Ca=()=>{const l=o.use(ht);if(!l)throw new Error("useScanner must be used within a component tree wrapped by ScannerProvider.");return l.openScanner},vi=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:a,modal:r,...c}=l;return i.jsxs(s.Overlay.Root,{open:n,onOpenChange:t,defaultOpen:a,modal:r,children:[!!e&&i.jsx(s.Overlay.Trigger,{asChild:!0,children:e}),i.jsxs(s.Overlay.Content,{children:[i.jsx(s.Overlay.Title,{className:"sr-only",children:"Scanner"}),i.jsx(s.Overlay.Description,{className:"sr-only",children:"Scan a barcode or a qr code."}),i.jsx(pl,{...c})]})]})});vi.displayName="Scanner";const pl=o.memo(l=>{const{paused:e,formats:n,timeBetweenDecodingAttempts:t,trySkew:a,onDecodeResult:r,onDecodeError:c,onError:f}=l,{wasmUrl:h}=fl(),{ref:u}=Ls.useZxing({wasmUrl:h,paused:e,formats:n,timeBetweenDecodingAttempts:t,trySkew:a,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(s.Overlay.Close,{asChild:!0,children:i.jsx(s.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:i.jsx(s.LuIcon,{icon:te})})})}),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})})]})});pl.displayName="ScannerInternal";const gl=o.memo(l=>{const{children:e,wasmUrl:n}=l,[t,a]=o.useState(null),r=o.useCallback(()=>{a(null)},[]),c=o.useCallback(u=>{a(u(r))},[r]),f=o.useCallback(()=>{t&&(t.onClose&&t.onClose(),r())},[r,t]),h=o.useMemo(()=>({wasmUrl:n,openScanner:c}),[n,c]);return i.jsxs(ht,{value:h,children:[e,t&&i.jsx(vi,{open:!0,onOpenChange:f,...t})]})});gl.displayName="ScannerProvider";const ml=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),[u,p]=o.useState(!1),m=o.useCallback(S=>{const v=S.target.value;c(v)},[c]),g=o.useCallback(()=>{r()},[r]),C=o.useCallback(S=>{c(S.rawValue.trim()),r(),p(!1)},[c,r]),F=o.useCallback(()=>{p(!0)},[]),w=o.useCallback(()=>{p(!1),r()},[r]);return i.jsxs(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:[i.jsx(s.TextArea,{className:"field-sizing-content w-full",accentColor:"base",variant:"surface",size:n,id:e.id,name:a,value:t??"",placeholder:"Enter a qr or barcode",onChange:m,onBlur:g,disabled:h}),i.jsxs(s.Button,{onClick:F,className:"w-max",type:"button",variant:"soft",size:n,accentColor:"base",disabled:h,children:[i.jsx(s.LuIcon,{icon:ra}),"Scan"]}),i.jsx(vi,{open:u,onDecodeResult:C,onOpenChange:w})]})});ml.displayName="ScanFieldInput";class Ve extends x{type="qr";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ve({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new Ve(e)}static fromConfig(e){return new Ve(e)}static deserializeConfig(e){return x._deserializeConfig(e)}static serializeConfig(e){return x._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(ml,{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 Cl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(g=>{c(g??null),r()},[r,c]),p=o.useCallback(g=>{g||r()},[r]),m=o.useMemo(()=>e.options.find(g=>g.value===t),[e.options,t]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsxs(s.Menu.Root,{onOpenChange:p,align:"start",children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{id:e.id,name:a,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:n,disabled:h,children:[i.jsx(s.Text,{className:"truncate",highContrast:!!m,children:m?m.label:e.placeholder??"Select one..."}),i.jsx(s.LuIcon,{icon:pi})]})}),i.jsx(s.Menu.Content,{size:n,children:i.jsx(s.Menu.Scroll,{children:i.jsx(s.Menu.SelectGroup,{required:!1,value:t??void 0,onValueChange:u,children:e.options.map((g,C)=>i.jsxs(s.Menu.SelectItem,{value:g.value,children:[i.jsx(s.Menu.SelectedIndicator,{children:i.jsx(s.LuIcon,{icon:G})}),g.label]},`${e.id}-${g.value}-${C}`))})})})]})})});Cl.displayName="SelectFieldInput";class fe extends Z{type="select";placeholder;constructor(e){const{placeholder:n,...t}=e;super(t),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 fe({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new fe(e)}static fromConfig(e){return new fe(e)}static deserializeConfig(e){const{placeholder:n,...t}=e;return{...Z._deserializeConfig(t),placeholder:n}}static serializeConfig(e){const{placeholder:n,...t}=e;return{...Z._serializeConfig(t),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Cl,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:t})=>t)]).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 yl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(g=>{const C=g.target.value;c(C)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(g=>{g.key==="Enter"&&g.preventDefault()},[]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(s.Input.Root,{accentColor:"base",variant:"surface",size:n,children:i.jsx(s.Input.Field,{id:e.id,className:"truncate",name:a,value:t??"",type:"text",placeholder:e.placeholder??"Enter a short description",onChange:u,onBlur:p,disabled:h,onKeyDown:m})})})});yl.displayName="StringFieldInput";class pe extends we{type="string";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new pe({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new pe(e)}static fromConfig(e){return new pe(e)}static deserializeConfig(e){return we._deserializeConfig(e)}static serializeConfig(e){return we._serializeConfig(e)}render(){return i.jsx(yl,{field:this})}}const vl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(m=>{const g=m.target.value;c(g)},[c]),p=o.useCallback(()=>{r()},[r]);return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(s.TextArea,{id:e.id,value:t??"",name:a,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})})});vl.displayName="TextFieldInput";class ge extends we{type="text";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new ge({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new ge(e)}static fromConfig(e){return new ge(e)}static deserializeConfig(e){return we._deserializeConfig(e)}static serializeConfig(e){return we._serializeConfig(e)}render(){return i.jsx(vl,{field:this})}}const ft=ya(),Fl=new Set(ft);function ya(l=!0){const e=new Set;for(let n=-12;n<=14;n++){const t=n>=0?"+":"-",a=Math.abs(n).toString().padStart(2,"0");e.add(`${t}${a}:00`)}if(l){const n=[-12.5,-9.5,-3.5,3.5,4.5,5.5,6.5,9.5,10.5,12.5];for(const t of n){const a=t>=0?"+":"-",r=Math.floor(Math.abs(t)).toString().padStart(2,"0");e.add(`${a}${r}:30`)}}return Array.from(e).sort((n,t)=>zl(n)-zl(t))}function zl(l){const e=l[0]==="+"?1:-1,n=Number(l.slice(1,3)),t=Number(l.slice(4,6));return e*(n*60+t)}const va="+00:00",Fa=/^T([01]\d|2[0-3]):([0-5]\d):00([+-]\d{2}:\d{2})$/,Fi=l=>typeof l=="string"&&Fl.has(l),wl=()=>{const l=-new Date().getTimezoneOffset(),e=l>=0?"+":"-",n=Math.abs(l),t=Math.floor(n/60),a=n%60,r=`${e}${t.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`;return Fi(r)?r:va};function Sl(l){const e=/^([+-])(\d{2}):(\d{2})$/.exec(l);if(!e)throw new Error(`Invalid UTC offset: ${l}`);return(e[1]==="+"?1:-1)*(Number(e[2])*60+Number(e[3]))}const en=l=>{const e=Fa.exec(l);if(!e)return null;const n=e[3];return Fi(n)?{hours:Number(e[1]),minutes:Number(e[2]),utcOffset:n}:null},Y=l=>typeof l=="string"&&en(l)!==null,me=(l,e,n=wl())=>{if(!Number.isInteger(l)||l<0||l>23)throw new Error(`Invalid hour: ${l}`);if(!Number.isInteger(e)||e<0||e>59)throw new Error(`Invalid minute: ${e}`);if(!Fi(n))throw new Error("Unsupported UTC offset");const t=l.toString().padStart(2,"0"),a=e.toString().padStart(2,"0");return`T${t}:${a}:00${n}`},zi=l=>`UTC${l}`,Ce=l=>{const e=en(l);if(!e)throw new Error(`Invalid time value: ${l}`);return(e.hours*60+e.minutes-Sl(e.utcOffset)+1440)%1440},wi=(l,e=!0)=>{const n=en(l);if(!n)throw new Error(`Invalid time value: ${l}`);const t=(n.hours%12||12).toString().padStart(2,"0"),a=n.minutes.toString().padStart(2,"0"),r=n.hours>=12?"PM":"AM",c=`${t}:${a} ${r}`;return e?`${c} ${zi(n.utcOffset)}`:c},za=l=>typeof l=="object"&&(Y(l.from)||Y(l.to)),pt=(l,e)=>{const n=Ce(l),t=e.from?Ce(e.from):null,a=e.to?Ce(e.to):null;return t===null&&a===null?!0:t===null?n<=a:a===null?n>=t:t<=a?n>=t&&n<=a:n>=t||n<=a},Si=o.memo(l=>{const{value:e,onChange:n,onBlur:t,disabled:a,size:r="md",id:c,name:f,compact:h=!1}=l,u=e?en(e):null,p=u?`${u.hours.toString().padStart(2,"0")}:${u.minutes.toString().padStart(2,"0")}`:"",m=o.useCallback(F=>{const w=F.target.value;if(!w){n(null);return}const[S,v]=w.split(":").map(Number);n(me(S,v,u?.utcOffset))},[n,u?.utcOffset]),g=o.useCallback(F=>{u&&(n(me(u.hours,u.minutes,F)),t?.())},[t,n,u]),C=o.useCallback(F=>{F||t?.()},[t]);return i.jsxs("div",{className:"flex min-w-0 gap-2",children:[i.jsx(s.Input.Root,{className:"min-w-0 grow",accentColor:"base",variant:"surface",size:r,children:i.jsx(s.Input.Field,{id:c,name:f,className:Q.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:t,disabled:a})}),i.jsxs(s.Menu.Root,{align:"end",onOpenChange:C,children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{type:"button",className:h?"!justify-between":"min-w-32 !justify-between",accentColor:"base",variant:"surface",size:r,disabled:a||!u,children:[i.jsx(s.Text,{className:"truncate",highContrast:!!u,children:u?zi(u.utcOffset):"UTC offset"}),i.jsx(s.LuIcon,{icon:pi})]})}),i.jsx(s.Menu.Content,{size:r,children:i.jsx(s.Menu.Scroll,{children:i.jsx(s.Menu.SelectGroup,{required:!0,value:u?.utcOffset,onValueChange:g,children:ft.map(F=>i.jsxs(s.Menu.SelectItem,{value:F,children:[i.jsx(s.Menu.SelectedIndicator,{children:i.jsx(s.LuIcon,{icon:G})}),zi(F)]},F))})})})]})]})});Si.displayName="TimeFieldControl";const gt=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e});return i.jsx(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(Si,{id:e.id,name:a,size:n,value:t,onChange:c,onBlur:r,disabled:h})})});gt.displayName="TimeFieldInput";class Ne extends x{type="time";constructor(e){super(e)}static deserialize(e){return new Ne(e)}static fromConfig(e){return new Ne(e)}static deserializeConfig(e){return x._deserializeConfig(e)}static serializeConfig(e){return x._serializeConfig(e)}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ne({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(gt,{field:this})}isSerializedValue(e){return e===null||Y(e)}isValue(e){return e===null||Y(e)}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const bl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useRef(null),p=o.useCallback(()=>{u.current?.click()},[]),m=o.useCallback(()=>{if(!u.current)return;const v=u.current.files;if(!v){r();return}const I=Array.from(v).map(z=>de.from(V.v4(),z)),q=[...t,...I];c(q),r()},[r,c,t]),g=o.useCallback(v=>{const I=t.filter(({uuid:q})=>q!==v.uuid);c(I),r()},[t,c,r]);o.useEffect(()=>{if(!u.current)return;const v=new AbortController;return u.current.addEventListener("cancel",()=>{r()},{signal:v.signal}),()=>{v.abort()}},[r,t]);const C=e.maxFiles!==1,S=C?"Select files":"Select a file";return i.jsxs(B,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:[i.jsxs(s.Button,{className:"w-max",size:n,variant:"surface",accentColor:"base",onClick:p,type:"button",disabled:h,children:[i.jsx(s.LuIcon,{icon:et}),S]}),i.jsx("input",{id:e.id,name:a,type:"file",ref:u,accept:e.extensions?.join(","),multiple:C,className:"hidden",onChange:m,value:""}),t.length>0&&i.jsx("div",{className:"mt-1 flex h-max flex-col gap-2",children:t.map(v=>i.jsx(ct,{size:n,fileOrPromise:v,onRemove:g,disabled:h},v.uuid))})]})});bl.displayName="UploadFieldInput";class ye extends x{type="upload";extensions;maxSize;maxFiles;constructor(e){const{extensions:n,maxFiles:t,maxSize:a,...r}=e;super(r),this.maxSize=a,this.maxFiles=t,this.extensions=n}static getFieldCreationSchema(e=""){const n=e&&`${e}.`;return[{field:new U({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 U({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 ee({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,t=n&&n*1e3*1e3,a=this.maxFiles;return typeof n=="number"&&typeof t=="number"&&e.push(r=>{if(r.some(c=>c instanceof de&&c.size>t))return`Files must be at most ${n}MB.`}),typeof a=="number"&&e.push(r=>{if(r.length>a)return`You can only upload ${a} 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 ye({...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 ye(e)}static fromConfig(e){return new ye(e)}static deserializeConfig(e){const{extensions:n,maxSize:t,maxFiles:a,...r}=e;return{...x._deserializeConfig(r),extensions:n,maxSize:t,maxFiles:a}}static serializeConfig(e){const{extensions:n,maxSize:t,maxFiles:a,...r}=e;return{...x._serializeConfig(r),extensions:n,maxSize:t,maxFiles:a}}serializeValue(e){return[]}deserializeValue(e){return[]}render(){return i.jsx(bl,{field:this})}isSerializedValue(e){return Array.isArray(e)&&e.length===0}isValue(e){return Array.isArray(e)?e.every(n=>n instanceof be||n instanceof de):!1}areValuesEqual(e,n){return yi(e,n)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){return e.length===n.length}}const Vl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(L),{value:t,name:a,onBlur:r,onChange:c,error:f,disabled:h}=_({field:e}),u=o.useCallback(C=>{const F=C.target.value;F!==""&&!URL.canParse(F)||c(F!==""?new URL(F):null)},[c]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(C=>{C.key==="Enter"&&C.preventDefault()},[]),g=o.useCallback(()=>{t!==null&&window.open(t,"_blank","noopener,noreferrer")},[t]);return i.jsx(B,{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(s.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:n,children:i.jsx(s.Input.Field,{id:e.id,className:"truncate",name:a,value:t?t.toString():"",type:"url",inputMode:"url",placeholder:e.placeholder??"https://example.com",onChange:u,onBlur:p,disabled:h,onKeyDown:m})}),i.jsx(s.IconButton,{size:n,variant:"soft",accentColor:"base",type:"button",disabled:t===null,onClick:g,children:i.jsx(s.LuIcon,{icon:Rs})})]})})});Vl.displayName="URLFieldInput";class xe extends x{type="url";placeholder;constructor(e){const{placeholder:n,...t}=e;super(t),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 xe({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new xe(e)}static fromConfig(e){return new xe(e)}static deserializeConfig(e){const{placeholder:n,...t}=e;return{...x._deserializeConfig(t),placeholder:n}}static serializeConfig(e){const{placeholder:n,...t}=e;return{...x._serializeConfig(t),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(Vl,{field:this})}}const Oe={date:Se,time:Ne,number:U,boolean:ae,select:fe,string:pe,url:xe,text:ge,upload:ye,qr:Ve,"multi-string":le,"multi-select":ee,radio:ue,"checkbox-list":R,"pass-fail":ce,otp:re,rating:he},Nl=Object.keys(Oe),E={"checkbox-list":{description:"Allows the user to select a multiple options from a list.",group:M.Selection,icon:Qs,name:"Checkbox list"},"multi-select":{description:"Allows the user to select a multiple options from a list of options.",group:M.Selection,icon:la,name:"Multi-select"},"multi-string":{description:"Allows the user to provide multiple unique strings.",group:M.Text,icon:aa,name:"Multi-string"},"pass-fail":{description:"Track pass, fail, or N/A outcome.",group:M.Assessment,icon:Ys,name:"Pass - Fail"},boolean:{description:"Perfect for both optional and required yes/no questions.",group:M.Selection,icon:ua,name:"Checkbox"},date:{description:"Allows specifying a date.",group:M.Temporal,icon:Hs,name:"Date"},time:{description:"Allows specifying a time and UTC offset.",group:M.Temporal,icon:pa,name:"Time"},number:{description:"Allows specifying a number within a given range.",group:M.Numeric,icon:ia,name:"Number"},otp:{description:"Allows specifying a number within a given range.",group:M.Verification,icon:oa,name:"OTP"},qr:{description:"Used for scanning/reading QR and barcodes.",group:M.Capture,icon:da,name:"Scan"},radio:{description:"Allows the user to select a single option from a list of options.",group:M.Selection,icon:Ks,name:"Option list"},rating:{description:"Allows users to select a rating value.",group:M.Assessment,icon:Kt,name:"Rating"},select:{description:"Allows the user to select a single option from a list of options.",group:M.Selection,icon:sa,name:"Dropdown"},string:{description:"Short text fields can hold up to 500 characters on a single line.",group:M.Text,icon:fa,name:"Short Text"},text:{description:"Paragraph fields can hold up to 10000 characters and can have multiple lines.",group:M.Text,icon:Us,name:"Paragraph"},upload:{description:"Allows a file to be uploaded.",group:M.Capture,icon:et,name:"Upload"},url:{description:"Allows users to enter a URL.",group:M.Text,icon:ta,name:"URL"}},xl={[M.Assessment]:{name:"Assessment"},[M.Capture]:{name:"Capture"},[M.Numeric]:{name:"Numeric"},[M.Selection]:{name:"Selection"},[M.Temporal]:{name:"Temporal"},[M.Text]:{name:"Text"},[M.Verification]:{name:"Verification"}},A="Unlabelled",bi="Unlabelled";class Il extends Re{id;value;constructor(e){const{id:n,value:t}=e;super(),this.id=n,this.value=t}serialize(){return{id:this.id,type:this.type,value:this.serializeValue(),modifier:this.modifier}}getValue=()=>this.value;setValue=e=>{this.value=e,this.notify(this)}}class y extends Il{field;constructor(e){const{field:n,...t}=e;super(t),this.field=n}serialize(){return{...super.serialize(),field:this.field.id}}isApplicable=e=>this.field.isValue(e);accessorFn=e=>e[this.field.id]}const Ml=o.memo,Ie=Ml(function(l){const{ref:e,children:n,...t}=l,a=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(s.Menu.SelectedIndicator,{className:"ml-[auto]",children:i.jsx(s.LuIcon,{icon:G})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(s.Menu.SelectedIndicator,{className:"ml-[auto]",children:i.jsx(s.LuIcon,{icon:G})})]}),[n]);return i.jsx(s.Menu.SelectItem,{ref:e,...t,children:a})}),ql=Ml(function(l){const{ref:e,children:n,...t}=l,a=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(s.Menu.SelectedIndicator,{className:"ml-auto",children:i.jsx(s.LuIcon,{icon:G})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(s.Menu.SelectedIndicator,{className:"ml-auto",children:i.jsx(s.LuIcon,{icon:G})})]}),[n]);return i.jsx(s.Menu.MultiSelectItem,{ref:e,...t,children:a})}),mt=o.memo(l=>{const{ref:e,children:n,...t}=l,a=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(s.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:c=>c==="indeterminate"?i.jsx(s.LuIcon,{icon:gi}):i.jsx(s.LuIcon,{icon:G})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(s.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:c=>c==="indeterminate"?i.jsx(s.LuIcon,{icon:gi}):i.jsx(s.LuIcon,{icon:G})})]}),[n]);return i.jsx(s.Menu.SelectAllItem,{ref:e,...t,children:a})});mt.displayName="SelectAllItemTemplate";const Ct=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:a,modal:r,size:c,align:f,accentColor:h="base",...u}=l;return i.jsxs(s.Popover.Root,{open:n,onOpenChange:t,defaultOpen:a,modal:r,children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:e}),i.jsx(s.Popover.Content,{size:c,align:f,children:i.jsx(s.DayPicker,{size:c,accentColor:h,...u})})]})});Ct.displayName="DayPickerPopover";const Tl=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:a,modal:r,size:c,accentColor:f="base",values:h,onValuesChange:u,placeholder:p="Enter text",...m}=l,[g,C]=o.useState(""),F=o.useCallback(I=>{C(I.target.value)},[]),w=o.useCallback(I=>{I.key==="Enter"&&(I.preventDefault(),I.stopPropagation(),u([...h,g]),C(""))},[g,u,h]),S=o.useCallback(()=>{u([...h,g]),C("")},[g,u,h]),v=o.useCallback(I=>{const q=[...h];q.splice(I,1),u(q)},[u,h]);return i.jsxs(s.Popover.Root,{open:n,onOpenChange:t,defaultOpen:a,modal:r,children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:e}),i.jsx(s.Popover.Content,{size:c,onClick:s.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(s.Input.Root,{className:"grow",accentColor:"base",variant:"outline",size:"sm",children:i.jsx(s.Input.Field,{value:g,onChange:F,onKeyDown:w,placeholder:p,...m})}),i.jsx(s.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button",onClick:S,children:i.jsx(s.LuIcon,{icon:X})})]}),h.length>0&&i.jsx("div",{className:"flex flex-col gap-1",children:h.map((I,q)=>i.jsxs(s.Badge,{className:"flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[i.jsx("span",{className:"truncate",children:I}),i.jsx(s.IconButton,{size:"xs",variant:"ghost",type:"button",accentColor:"base",onClick:()=>{v(q)},children:i.jsx(s.LuIcon,{icon:te})})]},`${I}-${q}`))})]})})]})});Tl.displayName="NumberInputPopover";const Me=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:a,modal:r,size:c,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter a number",...m}=l,[g,C]=o.useState(null);o.useEffect(()=>{h!==void 0&&C(h)},[h]);const F=o.useCallback(S=>{const v=S.target.valueAsNumber;C(isNaN(v)?null:v)},[]),w=o.useCallback(S=>{const v=S.target.valueAsNumber;u?.(isNaN(v)?null:v)},[u]);return i.jsxs(s.Popover.Root,{open:n,onOpenChange:t,defaultOpen:a,modal:r,children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:e}),i.jsx(s.Popover.Content,{size:c,onClick:s.stopPropagation,...m,children:i.jsx(s.Input.Root,{size:c,accentColor:f,children:i.jsx(s.Input.Field,{placeholder:p,type:"number",value:g??"",onChange:F,onBlur:w})})})]})});Me.displayName="NumberInputPopover";const $=l=>{const{condition:e,onClick:n,...t}=l,a=o.useCallback(()=>{n(e)},[e,n]);return i.jsx(s.IconButton,{onClick:a,...t,children:i.jsx(s.LuIcon,{icon:te})})};$.displayName="RemoveConditionButton";const nn=o.memo(l=>{const{ref:e,selectFieldOptions:n,...t}=l,a=o.useMemo(()=>se(n),[n]);return i.jsxs(s.Menu.MultiSelectGroup,{ref:e,...t,children:[i.jsx(mt,{children:"Select all"}),a.map(r=>i.jsx(ql,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))]})});nn.displayName="SelectFieldOptionMultiSelectGroup";const yt=o.memo(l=>{const{ref:e,selectFieldOptions:n,...t}=l,a=o.useMemo(()=>se(n),[n]);return i.jsx(s.Menu.SelectGroup,{ref:e,...t,children:a.map(r=>i.jsx(Ie,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))})});yt.displayName="SelectFieldOptionSelectGroup";const Ee=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:a,modal:r,size:c,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter text",...m}=l,[g,C]=o.useState(""),F=o.useCallback(S=>{C(S.target.value)},[]),w=o.useCallback(S=>{const v=S.target.value;u?.(v)},[u]);return o.useEffect(()=>{h&&C(h)},[h]),i.jsxs(s.Popover.Root,{open:n,onOpenChange:t,defaultOpen:a,modal:r,children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:e}),i.jsx(s.Popover.Content,{size:c,onClick:s.stopPropagation,...m,children:i.jsx(s.Input.Root,{size:c,accentColor:f,children:i.jsx(s.Input.Field,{placeholder:p,type:"text",value:g,onChange:F,onBlur:w})})})]})});Ee.displayName="TextInputPopover";const Vi=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:a,modal:r,size:c="sm",accentColor:f="base",value:h,onValueChange:u,...p}=l;return i.jsxs(s.Popover.Root,{open:n,onOpenChange:t,defaultOpen:a,modal:r,children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:e}),i.jsx(s.Popover.Content,{size:c,onClick:s.stopPropagation,accentColor:f,...p,children:i.jsx(Si,{compact:!0,size:c,value:h,onChange:u})})]})});Vi.displayName="TimeInputPopover";const k=l=>{const{children:e,required:n,value:t,defaultValue:a,onValueChange:r,modifierConfig:c,size:f="sm",variant:h,accentColor:u,radius:p}=l;return i.jsxs(s.Menu.Root,{align:"start",children:[i.jsx(s.Menu.ClickTrigger,{children:e}),i.jsx(s.Menu.Content,{size:f,variant:h,radius:p,accentColor:u,children:i.jsx(s.Menu.SelectGroup,{required:n,defaultValue:a,value:t,onValueChange:r,children:Object.keys(c).map(m=>{const{label:g}=c[m];return i.jsx(Ie,{value:m,children:g},m)})})})]})},P=(l,e,n)=>o.useCallback(t=>{const{klass:a,isTransferable:r,defaultValue:c}=e[t],f=l.getValue(),h=new a({id:l.id,value:r(f)?f:c(),field:l.field});n(l,h)},[l,e,n]);class Le extends y{type="boolean";modifier="equals";static deserialize(e,n){return new Le({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===this.value}}class tn extends y{type="boolean";modifier="notEquals";static deserialize(e,n){return new tn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e!==this.value}}const Ni={equals:{klass:Le,label:"is",isTransferable:l=>!0,defaultValue:()=>!0},notEquals:{klass:tn,label:"is not",isTransferable:l=>!0,defaultValue:()=>!0}},Ol=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=e.getValue(),r=e.modifier,c=()=>{switch(a){case!0:return"true";case!1:return"false"}},f=P(e,Ni,n);return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:r,onValueChange:f,modifierConfig:Ni,children:i.jsx(s.Button,{type:"button",children:Ni[r].label})}),i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:c()})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsxs(s.Menu.SelectGroup,{required:!0,value:a,onValueChange:e.setValue,children:[i.jsx(Ie,{value:!0,children:"true"}),i.jsx(Ie,{value:!1,children:"false"})]})})]}),i.jsx($,{condition:e,onClick:t})]})};class Be extends y{type="checkbox-list";modifier="equals";static deserialize(e,n){return new Be({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.size===t.size&&t.isSubsetOf(n)}}}class ln extends y{type="checkbox-list";modifier="notEquals";static deserialize(e,n){return new ln({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.size!==t.size||!t.isSubsetOf(n)}}}class sn extends y{type="checkbox-list";modifier="every";static deserialize(e,n){return new sn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.isSubsetOf(t)}}}class an extends y{type="checkbox-list";modifier="some";static deserialize(e,n){return new an({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return!n.isDisjointFrom(t)}}}class rn extends y{type="checkbox-list";modifier="none";static deserialize(e,n){return new rn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.isDisjointFrom(t)}}}const xi={equals:{klass:Be,label:"is",isTransferable:l=>!0,defaultValue:()=>[]},notEquals:{klass:ln,label:"is not",isTransferable:l=>!0,defaultValue:()=>[]},every:{klass:sn,label:"has all of",isTransferable:l=>!0,defaultValue:()=>[]},some:{klass:an,label:"has any of",isTransferable:l=>!0,defaultValue:()=>[]},none:{klass:rn,label:"has none of",isTransferable:l=>!0,defaultValue:()=>[]}},El=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,xi,n),r=()=>i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(nn,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:xi,children:i.jsx(s.Button,{type:"button",children:xi[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class Ii extends Re{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}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(t=>t.id===e.id?n:t)),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(t=>t.id));this.conditions=this.initConditions(this.conditions.filter(t=>!n.has(t.id))),this.notify(this)}applyConditions(e){return this.conditions.length===0?!0:this.conditions.map(t=>[t.getApplyFn(),t.isApplicable,t.accessorFn]).every(([t,a,r])=>{const c=r(e);return a(c)?t(c):!1})}}const wa=(l,e)=>o.useMemo(()=>{const n=new Ii(l);return n.observe(t=>e(t.getConditions())),n},[l,e]);class Ae extends y{type="date";modifier="equals";static deserialize(e,n){return new Ae({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){return e=>e===null?!1:e.getTime()===this.value.getTime()}}class on extends y{type="date";modifier="notEquals";static deserialize(e,n){return new on({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){return e=>e===null?!1:e.getTime()!==this.value.getTime()}}class dn extends y{type="date";modifier="before";static deserialize(e,n){return new dn({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){return e=>e===null?!1:e.getTime()<this.value.getTime()}}class cn extends y{type="date";modifier="after";static deserialize(e,n){return new cn({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){return e=>e===null?!1:e.getTime()>this.value.getTime()}}class un extends y{type="date";modifier="in";static deserialize(e,n){return new un({...e,value:{from:e.value.from?new Date(e.value.from):void 0,to:e.value.to?new Date(e.value.to):void 0},field:n})}serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getApplyFn(){return e=>!(e===null||this.value.from&&this.value.from.getTime()>e.getTime()||this.value.to&&this.value.to.getTime()<e.getTime())}}class hn extends y{type="date";modifier="notIn";static deserialize(e,n){return new hn({...e,value:{from:e.value.from?new Date(e.value.from):void 0,to:e.value.to?new Date(e.value.to):void 0},field:n})}serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getApplyFn(){return e=>e===null?!1:!!(this.value.from&&this.value.from.getTime()>e.getTime()||this.value.to&&this.value.to.getTime()<e.getTime())}}const Mi={equals:{klass:Ae,label:"is",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},notEquals:{klass:on,label:"is not",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},before:{klass:dn,label:"before",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},after:{klass:cn,label:"after",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},in:{klass:un,label:"in between",isTransferable:l=>!(l instanceof Date),defaultValue:()=>({from:void 0,to:void 0})},notIn:{klass:hn,label:"not in between",isTransferable:l=>!(l instanceof Date),defaultValue:()=>({from:void 0,to:void 0})}},Ll=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Mi,n),r=()=>{switch(e.modifier){case"in":case"notIn":{const c=e.getValue();return i.jsx(Ct,{required:!0,mode:"range",size:"sm",selected:c,onSelect:e.setValue,children:i.jsxs(s.Button,{type:"button",className:"truncate",children:[c.from?.toLocaleDateString()??"..."," - ",c.to?.toLocaleDateString()??"..."]})})}default:return i.jsx(Ct,{required:!0,mode:"single",size:"sm",selected:e.getValue(),onSelect:e.setValue,children:i.jsx(s.Button,{type:"button",className:"truncate",children:e.getValue().toLocaleDateString()})})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Mi,children:i.jsx(s.Button,{type:"button",children:Mi[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class De extends y{type="multi-select";modifier="equals";static deserialize(e,n){return new De({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.size===t.size&&t.isSubsetOf(n)}}}class fn extends y{type="multi-select";modifier="notEquals";static deserialize(e,n){return new fn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.size!==t.size||!t.isSubsetOf(n)}}}class pn extends y{type="multi-select";modifier="every";static deserialize(e,n){return new pn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.isSubsetOf(t)}}}class gn extends y{type="multi-select";modifier="some";static deserialize(e,n){return new gn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return!n.isDisjointFrom(t)}}}class mn extends y{type="multi-select";modifier="none";static deserialize(e,n){return new mn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.isDisjointFrom(t)}}}const qi={equals:{klass:De,label:"is",isTransferable:l=>!0,defaultValue:()=>[]},notEquals:{klass:fn,label:"is not",isTransferable:l=>!0,defaultValue:()=>[]},every:{klass:pn,label:"has all of",isTransferable:l=>!0,defaultValue:()=>[]},some:{klass:gn,label:"has any of",isTransferable:l=>!0,defaultValue:()=>[]},none:{klass:mn,label:"has none of",isTransferable:l=>!0,defaultValue:()=>[]}},Bl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,qi,n),r=()=>i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(nn,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:qi,children:i.jsx(s.Button,{type:"button",children:qi[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class _e extends y{type="multi-string";modifier="equals";static deserialize(e,n){return new _e({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.size===t.size&&t.isSubsetOf(n)}}}class Cn extends y{type="multi-string";modifier="notEquals";static deserialize(e,n){return new Cn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.size!==t.size||!t.isSubsetOf(n)}}}class yn extends y{type="multi-string";modifier="every";static deserialize(e,n){return new yn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.isSubsetOf(t)}}}class vn extends y{type="multi-string";modifier="some";static deserialize(e,n){return new vn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return!n.isDisjointFrom(t)}}}class Fn extends y{type="multi-string";modifier="none";static deserialize(e,n){return new Fn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>{const n=new Set(this.value),t=new Set(e);return n.isDisjointFrom(t)}}}const Ti={equals:{klass:_e,label:"is",isTransferable:l=>!0,defaultValue:()=>[]},notEquals:{klass:Cn,label:"is not",isTransferable:l=>!0,defaultValue:()=>[]},every:{klass:yn,label:"has all of",isTransferable:l=>!0,defaultValue:()=>[]},some:{klass:vn,label:"has any of",isTransferable:l=>!0,defaultValue:()=>[]},none:{klass:Fn,label:"has none of",isTransferable:l=>!0,defaultValue:()=>[]}},Al=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Ti,n),r=()=>{const c=e.getValue();return i.jsx(Tl,{values:c,onValuesChange:e.setValue,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:c.length===1?c[0]:`${c.length} values`})})};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Ti,children:i.jsx(s.Button,{type:"button",children:Ti[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class $e extends y{type="number";modifier="equals";static deserialize(e,n){return new $e({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e===this.value}}class zn extends y{type="number";modifier="notEquals";static deserialize(e,n){return new zn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e!==this.value}}class wn extends y{type="number";modifier="lessThan";static deserialize(e,n){return new wn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e<this.value}}class Sn extends y{type="number";modifier="lessThanOrEquals";static deserialize(e,n){return new Sn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e<=this.value}}class bn extends y{type="number";modifier="greaterThan";static deserialize(e,n){return new bn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e>this.value}}class Vn extends y{type="number";modifier="greaterThanOrEquals";static deserialize(e,n){return new Vn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e>=this.value}}class Nn extends y{type="number";modifier="inRange";static deserialize(e,n){return new Nn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!(e===null||this.value.to!==null&&e>this.value.to||this.value.from!==null&&e<this.value.from)}}class xn extends y{type="number";modifier="notInRange";static deserialize(e,n){return new xn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:this.value.to!==null&&e>this.value.to||this.value.from!==null&&e<this.value.from}}const Oi={equals:{klass:$e,label:"is",isTransferable:l=>typeof l=="number",defaultValue:()=>0},notEquals:{klass:zn,label:"is not",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThan:{klass:wn,label:"is less than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThanOrEquals:{klass:Sn,label:"is less than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThan:{klass:bn,label:"is greater than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:Vn,label:"is greater than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},inRange:{klass:Nn,label:"is between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:xn,label:"is not between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})}},Dl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Oi,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(Me,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:u.from??"..."})}),i.jsx(Me,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:u.to??"..."})})]})}default:return i.jsx(Me,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:e.getValue()})})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Oi,children:i.jsx(s.Button,{type:"button",children:Oi[e.modifier].label})}),h(),i.jsx($,{condition:e,onClick:t})]})};class ke extends y{type="otp";modifier="equals";static deserialize(e,n){return new ke({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===this.value}}class In extends y{type="otp";modifier="notEquals";static deserialize(e,n){return new In({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e!==this.value}}class Mn extends y{type="otp";modifier="includes";static deserialize(e,n){return new Mn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.includes(this.value)}}class qn extends y{type="otp";modifier="excludes";static deserialize(e,n){return new qn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!e.includes(this.value)}}const Ei={equals:{klass:ke,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:In,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:Mn,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:qn,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},_l=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Ei,n),r=()=>i.jsx(Ee,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(s.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Ei,children:i.jsx(s.Button,{type:"button",children:Ei[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class Pe extends y{type="pass-fail";modifier="equals";static deserialize(e,n){return new Pe({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.status===null?!1:e.status===this.value}}class Tn extends y{type="pass-fail";modifier="notEquals";static deserialize(e,n){return new Tn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.status===null?!1:e.status!==this.value}}class On extends y{type="pass-fail";modifier="includes";static deserialize(e,n){return new On({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.status===null?!1:this.value.includes(e.status)}}class En extends y{type="pass-fail";modifier="excludes";static deserialize(e,n){return new En({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.status===null?!1:!this.value.includes(e.status)}}const Li={equals:{klass:Pe,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>"pass"},notEquals:{klass:Tn,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>"pass"},includes:{klass:On,label:"is any of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]},excludes:{klass:En,label:"is none of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]}},$l=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Li,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":return i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.Button,{type:"button",children:oe[e.getValue()].label})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(s.Menu.SelectGroup,{required:!0,value:e.getValue(),onValueChange:e.setValue,children:Te.map(c=>i.jsx(Ie,{value:c,children:oe[c].label},c))})})]});case"includes":case"excludes":return i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{type:"button",children:[e.getValue().length," statuses"]})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsxs(s.Menu.MultiSelectGroup,{values:e.getValue(),onValuesChange:e.setValue,children:[i.jsx(mt,{children:"Select all"}),Te.map(c=>i.jsxs(ql,{value:c,children:[i.jsx(s.LuIcon,{icon:oe[c].icon}),oe[c].label]},c))]})})]})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Li,children:i.jsx(s.Button,{type:"button",children:Li[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class je extends y{type="radio";modifier="equals";static deserialize(e,n){return new je({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e===this.value}}class Ln extends y{type="radio";modifier="notEquals";static deserialize(e,n){return new Ln({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e!==this.value}}class Bn extends y{type="radio";modifier="includes";static deserialize(e,n){return new Bn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:this.value.includes(e)}}class An extends y{type="radio";modifier="excludes";static deserialize(e,n){return new An({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:!this.value.includes(e)}}const Bi={equals:{klass:je,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>""},notEquals:{klass:Ln,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>""},includes:{klass:Bn,label:"is any of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]},excludes:{klass:An,label:"is none of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]}},kl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Bi,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const c=e.getValue(),f=se(e.field.options).find(h=>h.value===c)?.label;return i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.Button,{type:"button",className:"truncate",children:f??(c||"...")})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(yt,{required:!0,selectFieldOptions:e.field.options,value:c,onValueChange:e.setValue})})]})}case"includes":case"excludes":return i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(nn,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Bi,children:i.jsx(s.Button,{type:"button",children:Bi[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class Ue extends y{type="rating";modifier="equals";static deserialize(e,n){return new Ue({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e===this.value}}class Dn extends y{type="rating";modifier="notEquals";static deserialize(e,n){return new Dn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e!==this.value}}class _n extends y{type="rating";modifier="lessThan";static deserialize(e,n){return new _n({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e<this.value}}class $n extends y{type="rating";modifier="lessThanOrEquals";static deserialize(e,n){return new $n({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e<=this.value}}class kn extends y{type="rating";modifier="greaterThan";static deserialize(e,n){return new kn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e>this.value}}class Pn extends y{type="rating";modifier="greaterThanOrEquals";static deserialize(e,n){return new Pn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e>=this.value}}class jn extends y{type="rating";modifier="inRange";static deserialize(e,n){return new jn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!(e===null||this.value.to!==null&&e>this.value.to||this.value.from!==null&&e<this.value.from)}}class Un extends y{type="rating";modifier="notInRange";static deserialize(e,n){return new Un({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:this.value.to!==null&&e>this.value.to||this.value.from!==null&&e<this.value.from}}const Ai={equals:{klass:Ue,label:"is",isTransferable:l=>typeof l=="number",defaultValue:()=>0},notEquals:{klass:Dn,label:"is not",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThan:{klass:_n,label:"is less than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThanOrEquals:{klass:$n,label:"is less than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThan:{klass:kn,label:"is greater than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:Pn,label:"is greater than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},inRange:{klass:jn,label:"is between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:Un,label:"is not between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})}},Pl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Ai,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(Me,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:u.from??"..."})}),i.jsx(Me,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:u.to??"..."})})]})}default:return i.jsx(Me,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:e.getValue()})})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Ai,children:i.jsx(s.Button,{type:"button",children:Ai[e.modifier].label})}),h(),i.jsx($,{condition:e,onClick:t})]})};class Ge extends y{type="qr";modifier="equals";static deserialize(e,n){return new Ge({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===this.value}}class Gn extends y{type="qr";modifier="notEquals";static deserialize(e,n){return new Gn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e!==this.value}}class Jn extends y{type="qr";modifier="includes";static deserialize(e,n){return new Jn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.includes(this.value)}}class Hn extends y{type="qr";modifier="excludes";static deserialize(e,n){return new Hn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!e.includes(this.value)}}const Di={equals:{klass:Ge,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:Gn,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:Jn,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:Hn,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},jl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Di,n),r=()=>i.jsx(Ee,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(s.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Di,children:i.jsx(s.Button,{type:"button",children:Di[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class Je extends y{type="select";modifier="equals";static deserialize(e,n){return new Je({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e===this.value}}class Wn extends y{type="select";modifier="notEquals";static deserialize(e,n){return new Wn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:e!==this.value}}class Kn extends y{type="select";modifier="includes";static deserialize(e,n){return new Kn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:this.value.includes(e)}}class Xn extends y{type="select";modifier="excludes";static deserialize(e,n){return new Xn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===null?!1:!this.value.includes(e)}}const _i={equals:{klass:Je,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>""},notEquals:{klass:Wn,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>""},includes:{klass:Kn,label:"is any of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]},excludes:{klass:Xn,label:"is none of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]}},Ul=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,_i,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const c=e.getValue(),f=se(e.field.options).find(h=>h.value===c)?.label;return i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.Button,{type:"button",className:"truncate",children:f??(c||"...")})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(yt,{required:!0,selectFieldOptions:e.field.options,value:c,onValueChange:e.setValue})})]})}case"includes":case"excludes":return i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsxs(s.Button,{type:"button",children:[e.getValue().length," options"]})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsx(nn,{selectFieldOptions:e.field.options,values:e.getValue(),onValuesChange:e.setValue})})]})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:_i,children:i.jsx(s.Button,{type:"button",children:_i[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class He extends y{type="string";modifier="equals";static deserialize(e,n){return new He({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===this.value}}class Zn extends y{type="string";modifier="notEquals";static deserialize(e,n){return new Zn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e!==this.value}}class Yn extends y{type="string";modifier="includes";static deserialize(e,n){return new Yn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.includes(this.value)}}class Qn extends y{type="string";modifier="excludes";static deserialize(e,n){return new Qn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!e.includes(this.value)}}const $i={equals:{klass:He,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:Zn,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:Yn,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:Qn,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Gl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,$i,n),r=()=>i.jsx(Ee,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(s.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:$i,children:i.jsx(s.Button,{type:"button",children:$i[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class We extends y{type="text";modifier="equals";static deserialize(e,n){return new We({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e===this.value}}class Rn extends y{type="text";modifier="notEquals";static deserialize(e,n){return new Rn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e!==this.value}}class ei extends y{type="text";modifier="includes";static deserialize(e,n){return new ei({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.includes(this.value)}}class ni extends y{type="text";modifier="excludes";static deserialize(e,n){return new ni({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!e.includes(this.value)}}const ki={equals:{klass:We,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:Rn,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:ei,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:ni,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Jl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,ki,n),r=()=>i.jsx(Ee,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(s.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:ki,children:i.jsx(s.Button,{type:"button",children:ki[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class Ke extends y{type="time";modifier="equals";static deserialize(e,n){return new Ke({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>Y(e)?e===this.value:!1}}class ii extends y{type="time";modifier="notEquals";static deserialize(e,n){return new ii({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>Y(e)?e!==this.value:!1}}class ti extends y{type="time";modifier="before";static deserialize(e,n){return new ti({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>Y(e)?Ce(e)<Ce(this.value):!1}}class li extends y{type="time";modifier="after";static deserialize(e,n){return new li({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>Y(e)?Ce(e)>Ce(this.value):!1}}class si extends y{type="time";modifier="in";static deserialize(e,n){return new si({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>Y(e)?pt(e,this.value):!1}}class ai extends y{type="time";modifier="notIn";static deserialize(e,n){return new ai({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>Y(e)?!pt(e,this.value):!1}}const Pi={equals:{klass:Ke,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>me(0,0)},notEquals:{klass:ii,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>me(0,0)},before:{klass:ti,label:"before",isTransferable:l=>typeof l=="string",defaultValue:()=>me(0,0)},after:{klass:li,label:"after",isTransferable:l=>typeof l=="string",defaultValue:()=>me(0,0)},in:{klass:si,label:"in between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})},notIn:{klass:ai,label:"not in between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})}},Hl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Pi,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(Vi,{value:u.from,onValueChange:c,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:u.from?wi(u.from):"..."})}),i.jsx(Vi,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:u.to?wi(u.to):"..."})})]})}default:return i.jsx(Vi,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(s.Button,{type:"button",className:"truncate",children:wi(e.getValue())})})}};return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Pi,children:i.jsx(s.Button,{type:"button",children:Pi[e.modifier].label})}),h(),i.jsx($,{condition:e,onClick:t})]})};class Xe extends y{type="upload";modifier="equals";static deserialize(e,n){return new Xe({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.length>0}}class ri extends y{type="upload";modifier="notEquals";static deserialize(e,n){return new ri({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.length===0}}const ji={equals:{klass:Xe,label:"is",isTransferable:l=>!0,defaultValue:()=>!0},notEquals:{klass:ri,label:"is not",isTransferable:l=>!0,defaultValue:()=>!0}},Wl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,ji,n),r=()=>i.jsxs(s.Menu.Root,{children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.Button,{type:"button",children:e.getValue()?"empty":"not empty"})}),i.jsx(s.Menu.Content,{size:"sm",children:i.jsxs(s.Menu.SelectGroup,{required:!0,value:e.getValue(),onValueChange:e.setValue,children:[i.jsx(Ie,{value:!0,children:"empty"}),i.jsx(Ie,{value:!1,children:"not empty"})]})})]});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:ji,children:i.jsx(s.Button,{type:"button",children:ji[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})};class Ze extends y{type="url";modifier="equals";static deserialize(e,n){return new Ze({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>(e?.toString()??"")===this.value}}class oi extends y{type="url";modifier="notEquals";static deserialize(e,n){return new oi({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>(e?.toString()??"")!==this.value}}class di extends y{type="url";modifier="includes";static deserialize(e,n){return new di({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>(e?.toString()??"").includes(this.value)}}class ci extends y{type="url";modifier="excludes";static deserialize(e,n){return new ci({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>!(e?.toString()??"").includes(this.value)}}const Ui={equals:{klass:Ze,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:oi,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:di,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:ci,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Kl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,a=P(e,Ui,n),r=()=>i.jsx(Ee,{value:e.getValue(),onValueChange:e.setValue,size:"sm",children:i.jsx(s.Button,{type:"button",className:"shrink-1 min-w-0 grow",children:i.jsx("span",{className:"truncate",children:e.getValue()||"..."})})});return i.jsxs(s.ButtonGroup,{className:"flex w-max min-w-0 max-w-full gap-0.5",size:"sm",variant:"fill",accentColor:"base",children:[i.jsxs(s.Badge,{className:"shrink-1 min-w-0",size:"sm",variant:"fill",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:E[e.field.type].icon}),i.jsx("span",{className:"truncate",children:e.field.label||A})]}),i.jsx(k,{required:!0,value:e.modifier,onValueChange:a,modifierConfig:Ui,children:i.jsx(s.Button,{type:"button",children:Ui[e.modifier].label})}),r(),i.jsx($,{condition:e,onClick:t})]})},Sa={date:{equals:Ae,notEquals:on,before:dn,after:cn,in:un,notIn:hn},boolean:{equals:Le,notEquals:tn},"checkbox-list":{equals:Be,notEquals:ln,every:sn,none:rn,some:an},"multi-select":{equals:De,notEquals:fn,every:pn,none:mn,some:gn},"multi-string":{equals:_e,notEquals:Cn,every:yn,none:Fn,some:vn},number:{equals:$e,notEquals:zn,greaterThan:bn,greaterThanOrEquals:Vn,inRange:Nn,lessThan:wn,lessThanOrEquals:Sn,notInRange:xn},otp:{equals:ke,notEquals:In,excludes:qn,includes:Mn},"pass-fail":{equals:Pe,notEquals:Tn,excludes:En,includes:On},radio:{equals:je,notEquals:Ln,excludes:An,includes:Bn},rating:{equals:Ue,notEquals:Dn,greaterThan:kn,greaterThanOrEquals:Pn,inRange:jn,lessThan:_n,lessThanOrEquals:$n,notInRange:Un},qr:{equals:Ge,notEquals:Gn,excludes:Hn,includes:Jn},select:{equals:Je,notEquals:Wn,excludes:Xn,includes:Kn},string:{equals:He,notEquals:Zn,excludes:Qn,includes:Yn},text:{equals:We,notEquals:Rn,excludes:ni,includes:ei},time:{equals:Ke,notEquals:ii,after:li,before:ti,in:si,notIn:ai},url:{equals:Ze,notEquals:oi,excludes:ci,includes:di},upload:{equals:Xe,notEquals:ri}},Xl=(l,e)=>{if(l.type!==e.type)throw new Error(`field and condition type mismatch ${l.type} !== ${e.type}`);return Sa[e.type][e.modifier].deserialize(e,l)},Gi=(l,e)=>{const n=vt(l,e),t={};for(const a of l)t[a.id]=a;return n.map(a=>Xl(t[a.field],a))},Zl=(l,e)=>Ft(l,e).map(t=>t.serialize()),vt=(l,e)=>{const n=new Set(l.map(t=>t.id));return e.filter(t=>n.has(t.field))},Ft=(l,e)=>{const n=new Set(l.map(t=>t.id));return e.filter(t=>n.has(t.field.id))},zt=l=>{const{condition:e,...n}=l;switch(e.type){case"string":return i.jsx(Gl,{condition:e,...n});case"text":return i.jsx(Jl,{condition:e,...n});case"otp":return i.jsx(_l,{condition:e,...n});case"qr":return i.jsx(jl,{condition:e,...n});case"url":return i.jsx(Kl,{condition:e,...n});case"select":return i.jsx(Ul,{condition:e,...n});case"radio":return i.jsx(kl,{condition:e,...n});case"checkbox-list":return i.jsx(El,{condition:e,...n});case"multi-select":return i.jsx(Bl,{condition:e,...n});case"multi-string":return i.jsx(Al,{condition:e,...n});case"number":return i.jsx(Dl,{condition:e,...n});case"rating":return i.jsx(Pl,{condition:e,...n});case"date":return i.jsx(Ll,{condition:e,...n});case"time":return i.jsx(Hl,{condition:e,...n});case"pass-fail":return i.jsx($l,{condition:e,...n});case"upload":return i.jsx(Wl,{condition:e,...n});case"boolean":return i.jsx(Ol,{condition:e,...n})}},Ji=l=>Oe[l.type].deserialize(l);function ba(l){return l.map(Ji)}function Yl(l){return l.type==="section"?J.deserialize(l):Ji(l)}const Hi=l=>l.map(Yl),wt=l=>Oe[l.type].fromConfig(l),Ql=l=>l.map(e=>wt(e)),Rl=l=>l.type==="section"?J.fromConfig(l):wt(l),es=l=>l.map(Rl),St=l=>Oe[l.type].deserializeConfig(l),ns=l=>l.map(St),is=l=>l.type==="section"?J.deserializeConfig(l):St(l),ts=l=>l.map(is),bt=l=>Oe[l.type].serializeConfig(l),ls=l=>l.map(bt),ss=l=>l.type==="section"?J.serializeConfig(l):bt(l),as=l=>l.map(ss);function Va(l){const e={};for(const n of l)e[n.id]=n;return e}function rs(l,e,n=!0){const t=n?Wi(l,e):e,a={};for(const r of l){if(!(r.id in t))continue;const c=t[r.id];a[r.id]=r.serializeValue(c)}return a}function os(l,e,n=!0){const t=n?Vt(l,e):e,a={};for(const r of l){if(!(r.id in t))continue;const c=t[r.id];a[r.id]=r.deserializeValue(c)}return a}function Wi(l,e){const n={};for(const t of l){if(!(t.id in e))continue;const a=e[t.id];t.isValue(a)&&(n[t.id]=t.cleanValue(a))}return n}function Vt(l,e){const n={};for(const t of l){if(!(t.id in e))continue;const a=e[t.id];t.isSerializedValue(a)&&(n[t.id]=t.cleanSerializedValue(a))}return n}function ds(l,e){const n=Wi(l,e),t={},a={};for(const r of l){if(!(r.id in n))continue;const c=n[r.id];switch(r.type){case"upload":if(!r.isValue(c))break;a[r.id]=c,t[r.id]=[];break;case"pass-fail":if(!r.isValue(c))break;a[r.id]=c.files,t[r.id]={...c,files:[]};break;default:t[r.id]=e[r.id]}}return[t,a]}function cs(l,e,n){const t={};for(const a of l){if(!(a.id in e))continue;const r=e[a.id];switch(a.type){case"upload":if(!a.isValue(r))break;t[a.id]=n[a.id]??[];break;case"pass-fail":if(!a.isValue(r))break;t[a.id]={...r,files:n[a.id]??[]};break;default:if(!a.isValue(r))break;t[a.id]=r}}return t}const us=(l,e)=>{const n={};for(const t of l){const a=e[t.id];n[t.id]=a!==void 0?a:t.blankValue()}return n},hs=(l,e,n)=>{const t={};for(const a of l){const r=e[a.id],c=n[a.id];a.areValuesEqual(r,c)||(t[a.id]=c)}return t},fs=(l,e,n)=>{const t={};for(const a of l){const r=e[a.id],c=n[a.id];a.areValuesEqual(r,c)&&(t[a.id]=c)}return t},Nt=(l,e,n)=>l.every(t=>{const a=e[t.id],r=n[t.id];return t.areValuesEqual(a,r)}),xt=l=>{const e={};for(const n of l)e[n.id]=n.blankValue();return e},ps=(l,e)=>Nt(l,e,xt(l)),Na=Q.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),Ki=Q.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),gs=o.memo(l=>{const{fieldSection:e}=l,{label:n,description:t}=e,a=K.useWatch(),{fieldSchema:r,size:c}=o.use(L),f=o.useMemo(()=>r.getFieldSections(),[r]),h=o.useMemo(()=>f.findIndex(({id:g})=>g===e.id),[f,e.id]),u=o.useMemo(()=>f.filter(g=>e.id in g.conditions),[f,e.id]),p=o.useMemo(()=>u.length===0?!0:u.some(g=>{const C=g.getConditions(e.id);return new Ii(C).applyConditions(a)}),[u,e,a]),m=Ci(e.fields);return p?i.jsxs(i.Fragment,{children:[h!==0?i.jsx(s.Separator,{size:"full"}):null,i.jsxs("div",{className:"flex flex-col gap-4",children:[(n||t)&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx(s.Heading,{size:c,children:n}),t&&i.jsx(s.Text,{accentColor:"base",size:c,children:t})]})}),i.jsx("div",{className:Ki({size:c}),children:m})]})]}):null});gs.displayName="FieldSectionLayout";class J extends ze{type="section";label;description;conditions;fields=[];constructor(e){const{label:n,description:t,fields:a,conditions:r={},...c}=e;super(c),this.label=n,this.description=t,this.fields=this.initFields(a),this.conditions=this.initConditions(r)}serialize(){return{...super.serialize(),label:this.label,description:this.description,fields:this.fields.map(e=>e.serialize()),conditions:Object.fromEntries(Object.entries(this.conditions).map(([e,n])=>[e,n.map(t=>t.serialize())]))}}static deserialize=e=>{const n=e.fields.map(Ji),t={};for(const[a,r]of Object.entries(e.conditions??{}))t[a]=Gi(n,r);return new J({...e,fields:n,conditions:t})};static fromConfig=e=>{const n=Ql(e.fields),t={};for(const[a,r]of Object.entries(e.conditions??{}))t[a]=Gi(n,r);return new J({...e,fields:n,conditions:t})};static deserializeConfig(e){const{label:n,description:t,fields:a,conditions:r,...c}=e;return{...ze._deserializeConfig(c),label:n,description:t,fields:ns(a),conditions:r}}static serializeConfig(e){const{label:n,description:t,fields:a,conditions:r,...c}=e;return{...ze._serializeConfig(c),label:n,description:t,fields:ls(a),conditions:r}}config(){return{...super.config(),label:this.label,description:this.description,fields:this.fields.map(e=>e.config()),conditions:Object.fromEntries(Object.entries(this.conditions).map(([e,n])=>[e,n.map(t=>t.serialize())]))}}getOptions(){return{...super.getOptions(),label:this.label,description:this.description,fields:this.fields,conditions:this.conditions}}duplicate(e){return new J({...this.getOptions(),id:e,fields:this.fields.map(n=>n.duplicate(V.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 t of this.fields){const a=t.getError(e[t.id]);a&&(n[t.id]=a)}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 t=[...this.fields];t.splice(n??this.fields.length,0,e),this.fields=this.initFields(t),this.notify(this)}moveField(e,n){const t=[...this.fields],[a]=t.splice(e,1);t.splice(n,0,a),this.fields=t,this.notify(this)}removeField(e){this.fields=this.initFields(this.fields.filter(({id:t})=>t!==e.id));const n={};for(const[t,a]of Object.entries(this.conditions))n[t]=a.filter(r=>r.field.id!==e.id);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,t){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).map(a=>a.id===n.id?t:a)}),this.notify(this)}removeCondition(e,n){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(t=>t.id!==n.id)}),this.notify(this)}removeConditions(e,n){const t=new Set(n.map(a=>a.id));this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(a=>!t.has(a.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(gs,{fieldSection:this})}}const ne=o.createContext({}),Xi=o.memo(l=>{const{children:e,variant:n,size:t,accentColor:a,onSelectFieldType:r,...c}=l,f=o.useMemo(()=>{const h={[M.Assessment]:[],[M.Capture]:[],[M.Numeric]:[],[M.Selection]:[],[M.Temporal]:[],[M.Text]:[],[M.Verification]:[]};for(const u of Nl){const{group:p}=E[u];h[p].push(u)}return h},[]);return i.jsxs(s.Menu.Root,{...c,children:[i.jsx(s.Menu.ClickTrigger,{children:e}),i.jsx(s.Menu.Content,{variant:n,size:t,accentColor:a,children:i.jsx(s.Menu.Scroll,{children:Object.entries(f).map(([h,u])=>{const{name:p}=xl[h];return u.length===0?null:i.jsxs(s.Menu.Group,{children:[i.jsx(s.Menu.Label,{children:p}),u.map(m=>i.jsx(ms,{fieldType:m,onSelectFieldType:r},m))]},h)})})})]})});Xi.displayName="CreateFieldDropdownMenu";const ms=o.memo(l=>{const{fieldType:e,onSelectFieldType:n}=l,t=o.useCallback(()=>{n(e)},[e,n]),{icon:a,name:r}=E[e];return i.jsxs(s.Menu.Item,{onSelect:t,children:[i.jsx(s.LuIcon,{icon:a}),i.jsx(s.Text,{className:"truncate",children:r})]})});ms.displayName="CreateFieldDropdownMenuItem";const Zi=l=>{switch(l){case"text":return new ge({label:"",required:!1,id:V.v4()});case"boolean":return new ae({label:"",required:!1,id:V.v4()});case"number":return new U({label:"",required:!1,id:V.v4()});case"date":return new Se({label:"",required:!1,id:V.v4()});case"time":return new Ne({label:"",required:!1,id:V.v4()});case"string":return new pe({label:"",required:!1,id:V.v4()});case"url":return new xe({label:"",required:!1,id:V.v4()});case"select":return new fe({label:"",options:[],required:!1,id:V.v4()});case"multi-string":return new le({label:"",required:!1,id:V.v4()});case"multi-select":return new ee({label:"",options:[],required:!1,id:V.v4()});case"upload":return new ye({label:"",required:!1,id:V.v4()});case"qr":return new Ve({label:"",required:!1,id:V.v4()});case"radio":return new ue({label:"",options:[],required:!1,id:V.v4()});case"checkbox-list":return new R({label:"",options:[],required:!1,id:V.v4()});case"pass-fail":return new ce({label:"",required:!1,id:V.v4(),showNotesAndFilesOn:["fail"]});case"otp":return new re({label:"",required:!1,id:V.v4(),length:6});case"rating":return new he({label:"",required:!1,id:V.v4(),maxRating:5})}},ui=l=>{switch(l.type){case"text":return new We({id:V.v4(),value:"",field:l});case"boolean":return new Le({id:V.v4(),value:!0,field:l});case"number":return new $e({id:V.v4(),value:0,field:l});case"date":return new Ae({id:V.v4(),value:new Date,field:l});case"time":return new Ke({id:V.v4(),value:me(0,0),field:l});case"string":return new He({id:V.v4(),value:"",field:l});case"url":return new Ze({id:V.v4(),value:"",field:l});case"select":return new Je({id:V.v4(),value:"",field:l});case"multi-string":return new _e({id:V.v4(),value:[],field:l});case"multi-select":return new De({id:V.v4(),value:[],field:l});case"upload":return new Xe({id:V.v4(),value:!0,field:l});case"qr":return new Ge({id:V.v4(),value:"",field:l});case"radio":return new je({id:V.v4(),value:"",field:l});case"checkbox-list":return new Be({id:V.v4(),value:[],field:l});case"pass-fail":return new Pe({id:V.v4(),value:"pass",field:l});case"otp":return new ke({id:V.v4(),value:"",field:l});case"rating":return new Ue({id:V.v4(),value:0,field:l})}},Cs=(l,e)=>{switch(l){case"checkbox-list":return R.getFieldCreationSchema(e);case"multi-select":return ee.getFieldCreationSchema(e);case"number":return U.getFieldCreationSchema(e);case"radio":return ue.getFieldCreationSchema(e);case"select":return fe.getFieldCreationSchema(e);case"string":return pe.getFieldCreationSchema(e);case"text":return ge.getFieldCreationSchema(e);case"upload":return ye.getFieldCreationSchema(e);case"pass-fail":return ce.getFieldCreationSchema(e);case"otp":return re.getFieldCreationSchema(e);case"rating":return he.getFieldCreationSchema(e);default:return}},ys=o.memo(l=>{const{popoverInputs:e,...n}=l;return i.jsxs(s.Popover.Root,{children:[i.jsx(s.Popover.Trigger,{asChild:!0,children:i.jsxs(s.Button,{variant:"soft",type:"button",size:"sm",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:ca}),"Settings"]})}),i.jsx(s.Popover.Content,{size:"sm",...n,children:i.jsx("div",{className:Q.cx("flex w-full max-w-[350px] flex-col",Ki({size:"sm"})),children:e})})]})});ys.displayName="FieldSettingsPopover";const vs=o.memo(l=>{const{parentPath:e,fieldIndex:n,field:t}=l,a=mi(),{disableRequiredFields:r}=o.use(ne),[c,f]=o.useState(void 0);Et.useActiveEffect(z=>{f(void 0);const b=t.image;if(b){if(!(b instanceof Promise)){f(b);return}b.then(T=>{z()&&f(T)})}},[t.image]);const h=o.useCallback(()=>{t.setOptions({image:void 0})},[t]),[u,p]=o.useMemo(()=>{const z=[],b=[],T=Cs(t.type,`${e}.${n}`)??[];for(const j of T)j.showDirectly?z.push(j.field):b.push(j.field);return[z,b]},[t,e,n]),m=Ci(u),g=Ci(p),C=p.length>0,F=o.useCallback(()=>{c&&a(()=>({file:c}))},[a,c]),w=o.useCallback(z=>{t.setOptions({required:!!z})},[t]),S=o.useCallback(z=>{t.setOptions({label:z.target.value})},[t]),v=o.useCallback(z=>{t.setOptions({description:z.target.value})},[t]),{icon:I,name:q}=E[t.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(s.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[i.jsx(s.LuIcon,{icon:I}),q]}),!r&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(s.Checkbox.Root,{checked:t.required,onCheckedChange:w,size:"sm",children:i.jsx(s.Checkbox.Indicator,{children:i.jsx(s.LuIcon,{icon:G})})}),i.jsx(s.Text,{size:"sm",accentColor:"base",children:"Required"})]})]}),C&&i.jsx(ys,{popoverInputs:g,align:"end"})]}),c&&i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx(qe,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:c,onClick:F}),i.jsx(s.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(s.LuIcon,{icon:Fe})})]}),i.jsxs("div",{className:"flex w-full flex-col gap-2 overflow-hidden",children:[i.jsx(s.Input.Root,{variant:"outline",size:"md",children:i.jsx(s.Input.Field,{placeholder:"Enter your question",value:t.label??"",onChange:S,maxLength:200})}),i.jsx(s.TextArea,{className:"field-sizing-content",placeholder:"Enter a field description (optional)",value:t.description??"",onChange:v,maxLength:1e3,resize:"vertical",size:"md"})]}),u.length>0&&i.jsx("div",{className:Q.cx("w-full",Ki({size:"sm"})),children:m})]})});vs.displayName="FieldBuilder";const It=o.memo(l=>{const{field:e,fieldSection:n,fieldIndex:t,sectionIndex:a}=l,r=o.useRef(null),c=`fields.${a}.fields`,f=o.useCallback(w=>{n.addField(Zi(w),t+1)},[t,n]),h=o.useCallback(()=>{n.addField(e.duplicate(V.v4()))},[e,n]),u=o.useCallback(w=>{const S=w==="up"?a-1:a+1;n.moveField(t,S)},[n,t,a]),p=o.useCallback(w=>{const{files:S}=w.target;if(!S||S.length!==1)return;const v=S.item(0);v&&e.setOptions({image:v})},[e]),m=o.useCallback(()=>{u("up")},[u]),g=o.useCallback(()=>{u("down")},[u]),C=o.useCallback(()=>{r.current?.click()},[]),F=o.useCallback(()=>{n.removeField(e)},[e,n]);return i.jsxs(s.Card,{className:"flex w-full items-center justify-between gap-4",size:"sm",children:[i.jsx(vs,{fieldIndex:t,field:e,parentPath:c}),i.jsxs(s.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(Xi,{onSelectFieldType:f,size:"sm",children:i.jsx(s.IconButton,{type:"button",children:i.jsx(s.LuIcon,{icon:X})})}),i.jsx(s.IconButton,{type:"button",onClick:m,children:i.jsx(s.LuIcon,{icon:Wt})}),i.jsx(s.IconButton,{type:"button",onClick:g,children:i.jsx(s.LuIcon,{icon:Ht})}),i.jsx(s.IconButton,{type:"button",onClick:h,children:i.jsx(s.LuIcon,{icon:Ri})}),i.jsx(s.IconButton,{type:"button",onClick:C,children:i.jsx(s.LuIcon,{icon:Gt})}),i.jsx(s.IconButton,{type:"button",onClick:F,children:i.jsx(s.LuIcon,{icon:Fe})})]}),i.jsx("input",{className:"hidden",ref:r,type:"file",accept:"image/*",onChange:p})]})});It.displayName="FieldBuilderWithActions";const Mt=o.memo(l=>{const{children:e,variant:n,size:t,accentColor:a,fields:r,onSelectField:c,onSelectAllFields:f,...h}=l,u=o.useCallback(()=>{f?.(r)},[f,r]);return i.jsxs(s.Menu.Root,{...h,children:[i.jsx(s.Menu.ClickTrigger,{children:e}),i.jsx(s.Menu.Content,{variant:n,size:t,accentColor:a,children:i.jsxs(s.Menu.Scroll,{children:[f?i.jsx(s.Menu.Item,{onSelect:u,children:"Select all"}):null,r.map(p=>i.jsx(Fs,{field:p,onSelectField:c},p.id))]})})]})});Mt.displayName="FieldDropdownMenu";const Fs=o.memo(l=>{const{field:e,onSelectField:n}=l,t=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(s.Menu.Item,{onSelect:t,children:[i.jsx(s.LuIcon,{icon:E[e.type].icon}),e.label||A]})});Fs.displayName="FieldDropdownMenuItem";const zs=o.memo(l=>{const{children:e,variant:n,size:t,accentColor:a,fieldSections:r,onSelectFieldSection:c,...f}=l;return i.jsxs(s.Menu.Root,{...f,children:[i.jsx(s.Menu.ClickTrigger,{children:e}),i.jsx(s.Menu.Content,{variant:n,size:t,accentColor:a,children:r.map(h=>i.jsx(ws,{fieldSection:h,onSelectFieldSection:c},h.id))})]})});zs.displayName="FieldSectionDropdownMenu";const ws=o.memo(l=>{const{fieldSection:e,onSelectFieldSection:n}=l,t=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(s.Menu.Item,{onSelect:t,children:[i.jsx(s.LuIcon,{icon:Jt}),e.label||bi]})});ws.displayName="FieldSectionDropdownMenuItem";const Ss=o.memo(l=>{const{id:e,sourceX:n,sourceY:t,targetX:a,targetY:r,style:c,markerEnd:f,data:h}=l,{targetSection:u,sourceSection:p,layoutDirection:m}=h,g=o.useMemo(()=>p.getConditions(u.id),[p,u.id]),C=o.useCallback(()=>{p.removeConditional(u.id)},[p,u.id]),F=o.useCallback(b=>{p.addCondition(u.id,ui(b))},[p,u.id]),w=o.useCallback(b=>{p.addConditions(u.id,b.map(ui))},[p,u.id]),S=o.useCallback((b,T)=>{p.replaceCondition(u.id,b,T)},[p,u.id]),v=o.useCallback(b=>{p.removeCondition(u.id,b)},[p,u.id]),[I,q,z]=O.getBezierPath({sourceX:n,sourceY:t,sourcePosition:m==="LR"?O.Position.Right:O.Position.Bottom,targetX:a,targetY:r,targetPosition:m==="LR"?O.Position.Left:O.Position.Top});return i.jsxs(i.Fragment,{children:[i.jsx(O.BaseEdge,{id:e,path:I,style:c,markerEnd:f,labelX:q,labelY:z}),i.jsx(O.EdgeLabelRenderer,{children:i.jsxs(s.Card,{size:"xs",variant:"surface",className:"nodrag nopan bg-(--base-2)! pointer-events-auto absolute inline-flex flex-col gap-2",onMouseDown:s.stopPropagation,onClick:s.stopPropagation,"data-floating-content":"",style:{transform:`translate(-50%, -50%) translate(${q}px, ${z}px)`},children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(s.Text,{size:"xs",className:"max-w-[280px] truncate",children:p.label||bi}),i.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[i.jsx(Mt,{size:"sm",fields:p.fields,onSelectField:F,onSelectAllFields:w,children:i.jsx(s.IconButton,{"aria-label":"Add condition",type:"button",variant:"surface",size:"xs",accentColor:"base",children:i.jsx(s.LuIcon,{icon:X})})}),i.jsxs(s.Tooltip.Root,{children:[i.jsx(s.Tooltip.Trigger,{asChild:!0,children:i.jsx(s.IconButton,{"aria-label":"Remove conditional logic",type:"button",variant:"surface",size:"xs",accentColor:"base",color:"danger",onClick:C,children:i.jsx(s.LuIcon,{icon:Fe})})}),i.jsx(s.Tooltip.Content,{size:"sm",children:"Remove conditional logic"})]})]})]}),g.length>0&&i.jsx("div",{className:"flex h-max w-full flex-col flex-wrap gap-1",children:g.map(b=>i.jsx(zt,{condition:b,onRemove:v,onReplace:S},b.id))})]})})]})});Ss.displayName="FieldSectionConditionEdgeComponent";const bs=o.memo(l=>{const{data:e,selected:n}=l,{fieldSection:t,index:a,layoutDirection:r}=e,{fieldSchema:c}=o.use(ne),f=o.useCallback(()=>{c.removeFieldSection(t)},[c,t]),h=o.useCallback(C=>{t.addField(Zi(C))},[t]),u=o.useCallback(()=>{const C=new J({id:V.v4(),fields:[]});c.addFieldSection(C),t.addConditional(C.id)},[c,t]),p=o.useCallback(()=>{c.addFieldSection(t.duplicate(V.v4()))},[c,t]),m=o.useCallback(C=>{t.setOptions({label:C.target.value})},[t]),g=o.useCallback(C=>{t.setOptions({description:C.target.value})},[t]);return i.jsxs(s.Card,{variant:"surface",className:"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(s.Input.Root,{variant:"outline",size:"md",accentColor:"base",children:i.jsx(s.Input.Field,{placeholder:"Enter a section label (optional)",value:t.label??"",onChange:m,maxLength:200})}),i.jsx(s.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:t.description??"",onChange:g,maxLength:1e3,resize:"vertical",size:"md"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(s.Text,{weight:"bold",children:"Fields"}),i.jsx(Xi,{onSelectFieldType:h,size:"sm",children:i.jsxs(s.Button,{type:"button",variant:"soft",size:"sm",accentColor:"base",children:[i.jsx(s.LuIcon,{icon:X})," Add field"]})})]}),i.jsx("div",{className:"flex flex-col gap-3",children:t.fields.map((C,F)=>i.jsx(It,{field:C,fieldSection:t,fieldIndex:F,sectionIndex:a},C.id))})]}),i.jsx(O.NodeToolbar,{isVisible:!0,position:O.Position.Right,align:"start",offset:8,onMouseDown:s.stopPropagation,children:i.jsx(s.Card,{variant:"surface",className:"bg-(--base-2) flex flex-col items-center gap-1 p-1",size:"xs",onClick:s.stopPropagation,children:i.jsxs(s.ButtonGroup,{className:"flex flex-col gap-2",variant:"surface",size:"xs",accentColor:"base",children:[i.jsx(s.IconButton,{type:"button",onClick:u,children:i.jsx(s.LuIcon,{icon:na})}),i.jsx(s.IconButton,{type:"button",onClick:p,children:i.jsx(s.LuIcon,{icon:Ri})}),i.jsx(s.IconButton,{type:"button",onClick:f,children:i.jsx(s.LuIcon,{icon:Fe})})]})})}),i.jsx(O.Handle,{type:"target",className:"size-4! bg-(--base-3)! border-(--base-7)!",position:r==="LR"?O.Position.Left:O.Position.Top}),i.jsx(O.Handle,{type:"source",className:"size-4! bg-(--base-3)! border-(--base-7)!",position:r==="LR"?O.Position.Right:O.Position.Bottom})]})});bs.displayName="CustomNode";const xa={fieldSection:bs},Ia={fieldSectionCondition:Ss},Ma=(l,e,n)=>{const t=new Lt.graphlib.Graph().setDefaultEdgeLabel(()=>({}));return t.setGraph({rankdir:n,nodesep:200,edgesep:500,ranksep:500}),e.forEach(a=>t.setEdge(a.source,a.target,{width:500,height:200,labelpos:"c"})),l.forEach(a=>t.setNode(a.id,{...a,width:a.measured?.width??0,height:a.measured?.height??0})),Lt.layout(t),[l.map(a=>{const r=t.node(a.id),c=r.x-(a.measured?.width??0)/2,f=r.y-(a.measured?.height??0)/2;return{...a,position:{x:c,y:f}}}),e]},qa={hideAttribution:!0},Vs=o.memo(()=>{const{errors:l}=K.useFormState(),{handleSubmit:e}=K.useFormContext(),{onSave:n,onCancel:t}=o.use(ne),{fieldSchema:a}=o.use(ne),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(()=>a.fieldSections.map((D,H)=>({id:D.id,position:{x:0,y:0},data:{index:H,fieldSection:D,layoutDirection:h},draggable:!0,type:"fieldSection"})),[a.fieldSections,h]),m=o.useMemo(()=>{const D=[],H={};for(const W of a.fieldSections)H[W.id]=W;for(const W of a.fieldSections){const hi=W.conditions;for(const[fi,Aa]of Object.entries(hi))D.push({id:`${W.id}-${fi}`,source:W.id,target:fi,data:{targetSection:H[fi],sourceSection:W,layoutDirection:h},animated:Aa.length>0,markerEnd:O.MarkerType.Arrow,style:{strokeWidth:2,stroke:"var(--base-a8)"},type:"fieldSectionCondition"})}return D},[a.fieldSections,h]),[g,C,F]=O.useNodesState(p),[w,S,v]=O.useEdgesState(m);o.useEffect(()=>{C(p)},[p,C]),o.useEffect(()=>{S(m)},[m,S]);const[I,q]=o.useMemo(()=>Ma(g,w,h),[w,h,g]),z=o.useCallback(()=>{a.addFieldSection(new J({id:V.v4(),fields:[]}))},[a]),b=o.useCallback(D=>{const{source:H,target:W}=D,hi=a.fieldSections.find(({id:fi})=>fi===H);hi.setOptions({conditions:{...hi.conditions,[W]:[]}})},[a.fieldSections]),T=o.useCallback(D=>{const H=a.getSectionDependencyGraph();return!Tt.willCreateCycle(H,D.source,D.target)},[a]),j=o.useCallback(()=>{c?.zoomOut()},[c]),ie=o.useCallback(()=>{c?.zoomIn()},[c]),Ye=o.useCallback(()=>{c?.fitView()},[c]);return i.jsxs("form",{className:"flex size-full flex-col gap-4",onSubmit:e(n),children:[i.jsxs(s.Card,{className:"relative size-full",variant:"outline",children:[i.jsx(O.ReactFlow,{ref:r,onInit:f,nodes:I,onNodesChange:F,edges:q,onEdgesChange:v,nodeTypes:xa,edgeTypes:Ia,onConnect:b,attributionPosition:"bottom-left",fitView:!0,minZoom:0,isValidConnection:T,proOptions:qa}),i.jsx(O.Panel,{position:"top-left",children:i.jsx(s.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:i.jsxs(s.Button,{type:"button",variant:"surface",onClick:z,children:[i.jsx(s.LuIcon,{icon:X})," Add section"]})})}),i.jsxs(O.Panel,{position:"top-right",className:"flex flex-col items-center gap-2",children:[i.jsxs(s.ToggleGroup.Root,{className:"flex flex-col",type:"single",accentColor:"base",size:"sm",value:h,onValueChange:u,children:[i.jsx(s.ToggleGroup.IconItem,{className:"rounded-b-none",value:"LR",type:"button",children:i.jsx(s.LuIcon,{icon:Js})}),i.jsx(s.ToggleGroup.IconItem,{className:"rounded-t-none",value:"TB",type:"button",children:i.jsx(s.LuIcon,{icon:Gs})})]}),i.jsx(s.Separator,{size:"sm"}),i.jsxs(s.ButtonGroup,{className:"flex flex-col",size:"sm",accentColor:"base",variant:"soft",children:[i.jsx(s.IconButton,{className:"rounded-b-none",onClick:ie,type:"button",children:i.jsx(s.LuIcon,{icon:X})}),i.jsx(s.IconButton,{onClick:j,radius:"none",type:"button",children:i.jsx(s.LuIcon,{icon:gi})}),i.jsx(s.IconButton,{className:"rounded-t-none",onClick:Ye,type:"button",children:i.jsx(s.LuIcon,{icon:ha})})]})]}),i.jsx(O.Panel,{position:"bottom-right",children:i.jsxs(s.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[t&&i.jsx(s.Button,{type:"button",variant:"soft",accentColor:"base",onClick:t,children:"Cancel"}),i.jsx(s.Button,{type:"submit",variant:"surface",children:"Save"})]})})]}),!!l.fields?.message&&i.jsx(s.Text,{size:"xs",accentColor:"danger",children:l.fields.message})]})});Vs.displayName="FormBuilderFlowBuilder";const Ta=(l,e,n={})=>{const{conditions:t=!1}=n,a=l.get(e.id);if(!a)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=V.v4();return r.set(h.id,u),{...h,id:u}}),f={};if(t)for(const[h,u]of Object.entries(e.conditions??{})){const p=l.get(h);if(!p)continue;const m=u.map(g=>{const C=r.get(g.field);if(!C)throw new Error(`Serialized condition referencing undefined field with id: ${g.field}`);return{...g,field:C}});f[p]=m}return{...e,id:a,conditions:f,fields:c}},Oa=(l,e={})=>{const n=new Map(l.map(t=>[t.id,V.v4()]));return l.map(t=>Ta(n,t,e))},qt=(l,e)=>{const n={},t=l.filter(a=>a instanceof J);for(const a of l)if(a instanceof J){const r=t.filter(f=>a.id in f.conditions);if(r.length>0&&!r.some(f=>{const h=f.getConditions(a.id);return new Ii(h).applyConditions(e)}))continue;const c=a.getErrors(e);Object.assign(n,c)}else{if(!(a instanceof x))throw new Error("Invalid field type");const r=a.id,c=a.getError(At(e,r));c&&Ds(n,r,c)}return n},Ea=async l=>{const e={};for(const n of l){const{fields:t}=n;for(const a of t)if(a.image)if(a.image instanceof Promise)try{e[a.id]=await a.image}catch(r){console.error("Failed to get image from promise",r)}else e[a.id]=a.image}return e};async function La(l){const e={};for(const[n,t]of Object.entries(l))e[n]=await Promise.all(t);return e}class ve extends Re{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 ve(Hi(e))}static fromConfig(e){return new ve(es(e))}static serializeConfig(e){return as(e)}static deserializeConfig(e){return ts(e)}static reseedFieldSections(e,n){return Oa(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 t=[...this.fieldSections];t.splice(n??this.fieldSections.length,0,e),this.fieldSections=this.initFields(t),this.notify(this)}removeFieldSection(e){const n=this.fieldSections.filter(t=>t.id!==e.id);for(const t of n)t.removeConditional(e.id);this.fieldSections=this.initFields(n),this.notify(this)}moveFieldSection(e,n){const t=[...this.fieldSections],[a]=t.splice(e,1);t.splice(n,0,a),this.fieldSections=this.initFields(t),this.notify(this)}getSectionDependencyGraph(){const e=new Bs.DirectedGraph({type:"directed"});for(const n of this.fieldSections)for(const t of Object.keys(n.conditions))e.mergeEdge(n.id,t);return e}getDependenciesOfSection(e){const n=this.getSectionDependencyGraph(),t=new Map(this.fieldSections.map(r=>[r.id,r])),a=[];return As.bfsFromNode(n,e,(r,c,f)=>{a.push(t.get(r))},{mode:"in"}),a}cleanValues(e){return Wi(this.getFields(),e)}cleanSerializedValues(e){return Vt(this.getFields(),e)}deserializeValues(e,n){return os(this.getFields(),e,n)}serializeValues(e,n){return rs(this.getFields(),e,n)}initializeValues(e){return us(this.getFields(),e)}validateValues(e){return qt(this.getFieldSections(),e)}areValuesValid(e){return Object.keys(this.validateValues(e)).length===0}deserializeConditions(e){return Gi(this.getFields(),e)}cleanConditions(e){return Ft(this.getFields(),e)}serializeConditions(e){return Zl(this.getFields(),e)}cleanSerializedConditions(e){return vt(this.getFields(),e)}changedFieldValues(e,n){return hs(this.getFields(),e,n)}unchangedFieldValues(e,n){return fs(this.getFields(),e,n)}areValuesEqual(e,n){return Nt(this.getFields(),e,n)}areValuesBlank(e){return ps(this.getFields(),e)}blankValues(){return xt(this.getFields())}extractFilesAndPromisesFromFieldValues(e){return ds(this.getFields(),e)}insertFilesAndPromisesToFieldValues(e,n){return cs(this.getFields(),e,n)}}const Ns=o.memo(l=>{const{sourceFieldSection:e,targetFieldSection:n}=l,t=o.useMemo(()=>e.getConditions(n.id),[e,n.id]),a=o.useCallback(()=>{e.removeConditional(n.id)},[e,n.id]),r=o.useCallback(u=>{e.addCondition(n.id,ui(u))},[e,n.id]),c=o.useCallback(u=>{e.addConditions(n.id,u.map(ui))},[e,n.id]),f=o.useCallback((u,p)=>{e.replaceCondition(n.id,u,p)},[e,n.id]),h=o.useCallback(u=>{e.removeCondition(n.id,u)},[e,n.id]);return i.jsxs(s.Card,{className:"flex flex-col gap-2",size:"sm",children:[i.jsxs(s.ButtonGroup,{className:"flex justify-between gap-2",size:"sm",accentColor:"base",variant:"soft",children:[i.jsxs(s.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[i.jsx(s.LuIcon,{icon:Jt}),e.label??bi]}),i.jsx(s.IconButton,{type:"button",onClick:a,variant:"ghost",children:i.jsx(s.LuIcon,{icon:Fe})})]}),i.jsxs("div",{className:"flex h-max w-full flex-wrap gap-2",children:[t.map(u=>i.jsx(zt,{condition:u,onRemove:h,onReplace:f},u.id)),i.jsx(Mt,{fields:e.fields,onSelectField:r,onSelectAllFields:c,align:"start",size:"sm",children:i.jsx(s.IconButton,{type:"button",size:"sm",variant:"soft",accentColor:"base",children:i.jsx(s.LuIcon,{icon:X})})})]})]})});Ns.displayName="FieldSectionConditionalItem";const xs=o.memo(l=>{const{fieldSection:e}=l,{fieldSchema:n}=o.use(ne),t=o.useMemo(()=>n.fieldSections.filter(h=>e.id in h.conditions),[n.fieldSections,e.id]),a=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=>!Tt.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(s.Input.Root,{variant:"outline",size:"md",children:i.jsx(s.Input.Field,{placeholder:"Enter a section label (optional)",value:e.label??"",onChange:r,maxLength:200})}),i.jsx(s.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:e.description??"",onChange:c,maxLength:1e3,resize:"vertical",size:"md"})]}),i.jsx(s.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(s.Text,{accentColor:"base",children:"Conditions"}),i.jsx(zs,{fieldSections:f,onSelectFieldSection:a,size:"sm",children:i.jsxs(s.Button,{type:"button",variant:"soft",size:"sm",className:"w-max",children:[i.jsx(s.LuIcon,{icon:X}),"Add condition"]})})]}),t.map(h=>i.jsx(Ns,{sourceFieldSection:h,targetFieldSection:e},h.id))]}),i.jsx(s.Separator,{size:"full"})]})});xs.displayName="FieldSectionBuilder";const Is=o.memo(l=>{const{fieldSection:e,sectionIndex:n}=l,{fieldSchema:t}=o.use(ne),a=s.useAlertDialog(),r=o.useCallback(()=>{t.removeFieldSection(e)},[t,e]),c=o.useCallback(w=>{const S=w==="up"?n-1:n+1;t.moveFieldSection(n,S)},[t,n]),f=o.useCallback(()=>{t.addFieldSection(e.duplicate(V.v4()))},[t,e]),h=o.useCallback(w=>{e.addField(Zi(w))},[e]),u=o.useCallback(()=>{c("up")},[c]),p=o.useCallback(()=>{c("down")},[c]),m=o.useCallback(async()=>{const w=[e.serialize()],S=ve.reseedFieldSections(w,{conditions:!1}),v=JSON.stringify(S);await navigator.clipboard.writeText(v),s.toast.success({title:"Section copied"})},[e]),g=o.useCallback(async()=>{const S=t.getDependenciesOfSection(e.id).map(q=>q.serialize()),v=ve.reseedFieldSections(S,{conditions:!0}),I=JSON.stringify(v);await navigator.clipboard.writeText(I),s.toast.success({title:"Section copied"})},[e,t]),C=o.useCallback(async()=>{const w=t.getDependenciesOfSection(e.id),S=w.length>1,v=w.length-1;S?a({title:"Copy section dependencies?",description:`This section has ${v} dependent section${v>1?"s":""} that will also be copied to maintain the conditions. Do you want to include these dependencies?`,action:"Include",onAction:g,cancel:"Dont include",onCancel:m}):m()},[e,t,a,g,m]),F=o.useCallback(async()=>{let w="";try{w=await navigator.clipboard.readText()}catch{s.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const S=w.trim();if(!S){s.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const v=JSON.parse(S),I=Bt.JSONFieldSectionSchema.array().parse(v),q=Hi(I);if(q.length===0){s.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[z,b]of q.entries())t.addFieldSection(b,n+1+z);s.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(v){console.error(v),s.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[t,n]);return i.jsxs(s.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(xs,{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(s.Text,{accentColor:"base",size:"md",children:"Fields"}),i.jsx(Xi,{onSelectFieldType:h,size:"sm",children:i.jsxs(s.Button,{type:"button",variant:"soft",size:"sm",children:[i.jsx(s.LuIcon,{icon:X})," Add field"]})})]}),e.fields.map((w,S)=>i.jsx(It,{field:w,fieldSection:e,fieldIndex:S,sectionIndex:n},w.id))]})]}),i.jsxs(s.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(s.IconButton,{type:"button",onClick:u,children:i.jsx(s.LuIcon,{icon:Wt})}),i.jsx(s.IconButton,{type:"button",onClick:p,children:i.jsx(s.LuIcon,{icon:Ht})}),i.jsxs(s.Menu.Root,{align:"end",children:[i.jsx(s.Menu.ClickTrigger,{children:i.jsx(s.IconButton,{type:"button",children:i.jsx(s.LuIcon,{icon:Ut})})}),i.jsxs(s.Menu.Content,{size:"sm",children:[i.jsxs(s.Menu.Item,{onSelect:f,children:[i.jsx(s.LuIcon,{icon:Ri}),"Duplicate section"]}),i.jsxs(s.Menu.Item,{onSelect:C,children:[i.jsx(s.LuIcon,{icon:kt}),"Copy JSON"]}),i.jsxs(s.Menu.Item,{onSelect:F,children:[i.jsx(s.LuIcon,{icon:Pt}),"Paste JSON"]}),i.jsxs(s.Menu.Item,{onSelect:r,children:[i.jsx(s.LuIcon,{icon:Fe}),"Delete section"]})]})]})]})]})});Is.displayName="FieldSectionWithActions";const Ms=o.memo(()=>{const{handleSubmit:l}=K.useFormContext(),{errors:e}=K.useFormState(),{onSave:n,onCancel:t}=o.use(ne),{fieldSchema:a}=o.use(ne),r=o.useCallback(()=>{a.addFieldSection(new J({id:V.v4(),fields:[]}))},[a]),c=o.useCallback(async()=>{try{const h=a.serialize(),u=ve.reseedFieldSections(h,{conditions:!0}),p=JSON.stringify(u);await navigator.clipboard.writeText(p),s.toast.success({title:"Sections copied",description:"All sections JSON copied to clipboard."})}catch{s.toast.error({title:"Copy failed",description:"Unable to copy the sections JSON."})}},[a]),f=o.useCallback(async()=>{let h="";try{h=await navigator.clipboard.readText()}catch{s.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const u=h.trim();if(!u){s.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const p=JSON.parse(u),m=Bt.JSONFieldSectionSchema.array().parse(p),g=Hi(m);if(g.length===0){s.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[C,F]of g.entries())a.addFieldSection(F,a.fieldSections.length+C);s.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(p){console.error(p),s.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[a]);return i.jsxs("form",{className:"flex flex-col gap-4",onSubmit:l(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(s.Button,{type:"button",variant:"soft",size:"sm",onClick:c,children:[i.jsx(s.LuIcon,{icon:kt})," Copy JSON"]}),i.jsxs(s.Button,{type:"button",variant:"soft",size:"sm",onClick:f,children:[i.jsx(s.LuIcon,{icon:Pt})," Paste JSON"]})]}),a.fieldSections.map((h,u)=>i.jsx(Is,{fieldSection:h,sectionIndex:u},h.id)),i.jsxs(s.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:r,children:[i.jsx(s.LuIcon,{icon:X})," Add section"]})]}),!!e.fields?.message&&i.jsx(s.Text,{size:"xs",accentColor:"danger",children:e.fields.message}),i.jsxs(s.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[t&&i.jsx(s.Button,{type:"button",variant:"soft",accentColor:"base",onClick:t,children:"Cancel"}),i.jsx(s.Button,{type:"submit",variant:"surface",children:"Save"})]})]})});Ms.displayName="FormBuilderListBuilder";function qs(l){const e=n=>{const t={};for(const[a,r]of Object.entries(n))typeof r=="string"?t[a]={type:"validate",message:r}:t[a]=e(r);return t};return e(l)}const Ts=o.memo(o.forwardRef((l,e)=>{const{disabled:n=!1,fieldSchema:t,values:a={},onValuesChange:r,onSubmit:c,submitText:f="Submit",hideSubmit:h=!1,cancelText:u,onCancel:p,hideCancel:m=!1,className:g,submitButtonProps:C,cancelButtonProps:F,cancelIcon:w,submitIcon:S,size:v="md"}=l,I=o.useMemo(()=>t.initializeValues(a),[t,a]),q=o.useCallback(D=>{c?.(D)},[c]),z=K.useForm({values:I,mode:"onBlur",criteriaMode:"all",disabled:n,resolver:D=>{const H=t.validateValues(D),W=qs(H);return Object.keys(H).length>0?{values:{},errors:W}:{values:D,errors:{}}}}),b=o.useCallback(D=>{r?.(D)},[r]);o.useEffect(()=>{const{unsubscribe:D}=z.watch((H,{type:W})=>{W==="change"&&b(H)});return()=>{D()}},[z,b]);const T=Yt(t.getFieldSections()),j=o.useMemo(()=>({fieldSchema:t,size:v}),[t,v]),ie=!m&&!!p,Ye=!h;return i.jsx(K.FormProvider,{...z,children:i.jsx(L,{value:j,children:i.jsxs("form",{ref:e,className:Q.cx(g,"flex flex-col gap-4"),onSubmit:z.handleSubmit(q),children:[i.jsx("div",{className:Na({size:v}),children:T}),!n&&(ie||Ye)?i.jsxs(s.ButtonGroup,{className:"flex items-center justify-end gap-2",size:v,children:[ie?i.jsxs(s.Button,{accentColor:"base",type:"button",variant:"soft",onClick:p,...F,children:[i.jsx(s.LuIcon,{icon:w??te}),u]}):null,Ye?i.jsxs(s.Button,{type:"submit",accentColor:"primary",variant:"surface",...C,children:[i.jsx(s.LuIcon,{icon:S??G}),f]}):null]}):null]})})})})),Os=o.memo(()=>{const{fieldSchema:l}=o.use(ne);return i.jsx(Ts,{fieldSchema:l,disabled:!1})});Os.displayName="FormBuilderPreview";const Es=o.memo(l=>{const{children:e,initialFields:n,onSave:t,onCancel:a,disableRequiredFields:r=!1}=l,c=o.useCallback(F=>{const w={};(!F.fields||F.fields.length===0)&&(w.fields="At least one field is required.");const S=[];for(const[q,z]of F.fields.entries())for(const[b,T]of z.fields.entries()){const j=Cs(T.type,`fields.${q}.fields.${b}`)?.map(({field:ie})=>ie)??[];S.push(...j)}const v={};for(const q of S)v[q.id]=At(F,q.id);const I=qt(S,v);return Object.keys(I).length>0&&(w.fields=I.fields),Object.keys(w).length>0&&s.toast.error({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),w},[]),f=o.useMemo(()=>({fields:n??[]}),[n]),h=K.useForm({values:f,mode:"onSubmit",criteriaMode:"all",reValidateMode:"onSubmit",resolver:F=>{const w=c(F),S=qs(w);return Object.keys(w).length>0?{values:{},errors:S}:{values:F,errors:{}}}}),u=o.useCallback(F=>{h.setValue("fields",F.config())},[h]),p=K.useWatch({control:h.control,compute:F=>F.fields}),m=o.useMemo(()=>{const F=ve.fromConfig(p);return F.observe(u),F},[p,u]),g=o.useMemo(()=>({fieldSchema:m,disableRequiredFields:r,onSave:t,onCancel:a}),[r,t,a,m]),C=o.useMemo(()=>({fieldSchema:m,size:"sm"}),[m]);return i.jsx(ne,{value:g,children:i.jsx(L,{value:C,children:i.jsx(K.FormProvider,{...h,children:e})})})});Es.displayName="FormBuilderRoot";const Ba={Root:Es,FlowBuilder:Vs,ListBuilder:Ms,Preview:Os};d.BaseCondition=Il,d.BaseField=x,d.BaseFieldCondition=y,d.BaseFormElement=ze,d.BaseOptionsField=Z,d.BaseStringField=we,d.BooleanField=ae,d.BooleanFieldConditionCell=Ol,d.BooleanFieldEqualsCondition=Le,d.BooleanFieldInput=st,d.BooleanFieldNotEqualsCondition=tn,d.CheckboxListField=R,d.CheckboxListFieldConditionCell=El,d.CheckboxListFieldEqualsCondition=Be,d.CheckboxListFieldEveryCondition=sn,d.CheckboxListFieldNoneCondition=rn,d.CheckboxListFieldNotEqualsCondition=ln,d.CheckboxListFieldSomeCondition=an,d.ConditionManager=Ii,d.DateField=Se,d.DateFieldAfterCondition=cn,d.DateFieldBeforeCondition=dn,d.DateFieldConditionCell=Ll,d.DateFieldEqualsCondition=Ae,d.DateFieldInCondition=un,d.DateFieldInput=at,d.DateFieldNotEqualsCondition=on,d.DateFieldNotInCondition=hn,d.FIELD_TYPES=Nl,d.FieldConditionCell=zt,d.FieldSchema=ve,d.FieldSection=J,d.FieldTypeGroup=M,d.FieldTypeToClsMapping=Oe,d.FieldsRenderer=Ts,d.FileCard=nt,d.FormBuilder=Ba,d.ImageCard=rt,d.ImageFile=qe,d.ImageViewer=tt,d.ImageViewerProvider=Zt,d.InputWithLabel=B,d.MultiSelectField=ee,d.MultiSelectFieldConditionCell=Bl,d.MultiSelectFieldEqualsCondition=De,d.MultiSelectFieldEveryCondition=pn,d.MultiSelectFieldNoneCondition=mn,d.MultiSelectFieldNotEqualsCondition=fn,d.MultiSelectFieldSomeCondition=gn,d.MultiStringField=le,d.MultiStringFieldConditionCell=Al,d.MultiStringFieldEqualsCondition=_e,d.MultiStringFieldEveryCondition=yn,d.MultiStringFieldNoneCondition=Fn,d.MultiStringFieldNotEqualsCondition=Cn,d.MultiStringFieldSomeCondition=vn,d.NumberField=U,d.NumberFieldConditionCell=Dl,d.NumberFieldEqualsCondition=$e,d.NumberFieldGreaterThanCondition=bn,d.NumberFieldGreaterThanOrEqualsCondition=Vn,d.NumberFieldInRangeCondition=Nn,d.NumberFieldLessThanCondition=wn,d.NumberFieldLessThanOrEqualsCondition=Sn,d.NumberFieldNotEqualsCondition=zn,d.NumberFieldNotInRangeCondition=xn,d.OTPField=re,d.OTPFieldConditionCell=_l,d.OTPFieldEqualsCondition=ke,d.OTPFieldExcludesCondition=qn,d.OTPFieldIncludesCondition=Mn,d.OTPFieldNotEqualsCondition=In,d.Observable=Re,d.PassFailField=ce,d.PassFailFieldConditionCell=$l,d.PassFailFieldEqualsCondition=Pe,d.PassFailFieldExcludesCondition=En,d.PassFailFieldIncludesCondition=On,d.PassFailFieldNotEqualsCondition=Tn,d.RadioField=ue,d.RadioFieldConditionCell=kl,d.RadioFieldEqualsCondition=je,d.RadioFieldExcludesCondition=An,d.RadioFieldIncludesCondition=Bn,d.RadioFieldNotEqualsCondition=Ln,d.RatingField=he,d.RatingFieldConditionCell=Pl,d.RatingFieldEqualsCondition=Ue,d.RatingFieldGreaterThanCondition=kn,d.RatingFieldGreaterThanOrEqualsCondition=Pn,d.RatingFieldInRangeCondition=jn,d.RatingFieldLessThanCondition=_n,d.RatingFieldLessThanOrEqualsCondition=$n,d.RatingFieldNotEqualsCondition=Dn,d.RatingFieldNotInRangeCondition=Un,d.ScanField=Ve,d.ScanFieldConditionCell=jl,d.ScanFieldEqualsCondition=Ge,d.ScanFieldExcludesCondition=Hn,d.ScanFieldIncludesCondition=Jn,d.ScanFieldNotEqualsCondition=Gn,d.Scanner=vi,d.ScannerProvider=gl,d.SelectField=fe,d.SelectFieldConditionCell=Ul,d.SelectFieldEqualsCondition=Je,d.SelectFieldExcludesCondition=Xn,d.SelectFieldIncludesCondition=Kn,d.SelectFieldNotEqualsCondition=Wn,d.StringField=pe,d.StringFieldConditionCell=Gl,d.StringFieldEqualsCondition=He,d.StringFieldExcludesCondition=Qn,d.StringFieldIncludesCondition=Yn,d.StringFieldNotEqualsCondition=Zn,d.TextField=ge,d.TextFieldConditionCell=Jl,d.TextFieldEqualsCondition=We,d.TextFieldExcludesCondition=ni,d.TextFieldIncludesCondition=ei,d.TextFieldNotEqualsCondition=Rn,d.TimeField=Ne,d.TimeFieldAfterCondition=li,d.TimeFieldBeforeCondition=ti,d.TimeFieldConditionCell=Hl,d.TimeFieldControl=Si,d.TimeFieldEqualsCondition=Ke,d.TimeFieldInCondition=si,d.TimeFieldInput=gt,d.TimeFieldNotEqualsCondition=ii,d.TimeFieldNotInCondition=ai,d.UNLABELLED_FIELD_LABEL=A,d.UNLABELLED_SECTION_LABEL=bi,d.URLField=xe,d.URLFieldConditionCell=Kl,d.URLFieldEqualsCondition=Ze,d.URLFieldExcludesCondition=ci,d.URLFieldIncludesCondition=di,d.URLFieldNotEqualsCondition=oi,d.UTC_OFFSETS=ft,d.UTC_OFFSETS_SET=Fl,d.UUIDFile=de,d.UUIDPromise=be,d.UploadField=ye,d.UploadFieldConditionCell=Wl,d.UploadFieldEqualsCondition=Xe,d.UploadFieldNotEqualsCondition=ri,d.VideoCard=dt,d.VideoFile=ot,d.areFieldValuesBlank=ps,d.areFieldValuesEqual=Nt,d.areFileAndPromiseArraysEqual=yi,d.areJSONPassFailFieldValuesEqual=cl,d.arePassFieldValuesEqual=dl,d.awaitFilesAndPromises=La,d.blankFieldValues=xt,d.booleanFieldConditionModifierConfig=Ni,d.changedFieldValues=hs,d.checkboxListFieldConditionModifierConfig=xi,d.cleanConditions=Ft,d.cleanFieldValues=Wi,d.cleanSerializedConditions=vt,d.cleanSerializedFieldValues=Vt,d.createCondition=ui,d.createField=Zi,d.createTime=me,d.dateFieldConditionModifierConfig=Mi,d.deserializeCondition=Xl,d.deserializeConditions=Gi,d.deserializeField=Ji,d.deserializeFieldConfig=St,d.deserializeFieldConfigs=ns,d.deserializeFieldElement=Yl,d.deserializeFieldElementConfig=is,d.deserializeFieldElementConfigs=ts,d.deserializeFieldElements=Hi,d.deserializeFieldValues=os,d.deserializeFields=ba,d.deserializePassFailFieldValue=ol,d.extractFilesAndPromisesFromFieldValues=ds,d.fieldDataMapping=E,d.fieldElementFromConfig=Rl,d.fieldElementsFromConfigs=es,d.fieldFromConfig=wt,d.fieldSpacingCva=Ki,d.fieldTypeGroupDataMapping=xl,d.fieldsFromConfigs=Ql,d.formatTime=wi,d.formatUTCOffset=zi,d.getCurrentUTCOffset=wl,d.getFieldsMapping=Va,d.getImagesFromFields=Ea,d.getUTCMinuteOfDay=Ce,d.getUTCOffsetMinutes=Sl,d.initializeFieldValues=us,d.insertFilesAndPromisesToFieldValues=cs,d.isFileAndPromiseArray=tl,d.isJSONPassFailFieldValue=sl,d.isPassFailFieldStatus=ut,d.isPassFailFieldValue=al,d.isStringArray=Qe,d.isTime=Y,d.isTimeInRange=pt,d.isTimeRange=za,d.isUTCOffset=Fi,d.multiSelectFieldConditionModifierConfig=qi,d.multiStringFieldConditionModifierConfig=Ti,d.normalizeFieldOption=lt,d.normalizeFieldOptions=se,d.numberFieldConditionModifierConfig=Oi,d.otpFieldConditionModifierConfig=Ei,d.parseTime=en,d.passFailFieldConditionModifierConfig=Li,d.passFailFieldStatusMapping=oe,d.passFailFieldStatuses=Te,d.radioFieldConditionModifierConfig=Bi,d.ratingFieldConditionModifierConfig=Ai,d.scanFieldConditionModifierConfig=Di,d.selectFieldConditionModifierConfig=_i,d.serializeConditions=Zl,d.serializeFieldConfig=bt,d.serializeFieldConfigs=ls,d.serializeFieldElementConfig=ss,d.serializeFieldElementConfigs=as,d.serializeFieldValues=rs,d.serializePassFailFieldValue=rl,d.stringFieldConditionModifierConfig=$i,d.textFieldConditionModifierConfig=ki,d.timeFieldConditionModifierConfig=Pi,d.unchangedFieldValues=fs,d.uploadFieldConditionModifierConfig=ji,d.urlFieldConditionModifierConfig=Ui,d.useConditionManager=wa,d.useFieldInput=_,d.useFieldInputs=Ci,d.useFieldSectionInputs=Yt,d.useImageViewer=mi,d.useObjectUrl=it,d.useScanner=Ca,d.useScannerContext=fl,d.validateFieldValues=qt,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(c,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):(c=typeof globalThis<"u"?globalThis:c||self,i(c.forms={},c.jsxRuntime,c.blocks,c.classVarianceAuthority,c.react,null,c.react$1,c.graphologyDag,c.reactHookForm,c.uuid,c.dnd,c.fileSaver,c.hooks,c.reactZxing,c.Dagre,c.zodFieldsjson,c.graphology,c.graphologyTraversal,c.get,c.set))})(this,(function(c,i,a,X,o,Js,E,Dt,Y,b,et,nt,pi,ja,_t,$t,Ua,Ga,Pt,Ja){"use strict";const Ha=l=>l.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Wa=l=>l.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,n,t)=>t?t.toUpperCase():n.toLowerCase()),kt=l=>{const e=Wa(l);return e.charAt(0).toUpperCase()+e.slice(1)},jt=(...l)=>l.filter((e,n,t)=>!!e&&e.trim()!==""&&t.indexOf(e)===n).join(" ").trim(),Ka=l=>{for(const e in l)if(e.startsWith("aria-")||e==="role"||e==="title")return!0};var Za={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 Xa=o.forwardRef(({color:l="currentColor",size:e=24,strokeWidth:n=2,absoluteStrokeWidth:t,className:s="",children:r,iconNode:d,...f},h)=>o.createElement("svg",{ref:h,...Za,width:e,height:e,stroke:l,strokeWidth:t?Number(n)*24/Number(e):n,className:jt("lucide",s),...!r&&!Ka(f)&&{"aria-hidden":"true"},...f},[...d.map(([u,p])=>o.createElement(u,p)),...Array.isArray(r)?r:[r]]));const N=(l,e)=>{const n=o.forwardRef(({className:t,...s},r)=>o.createElement(Xa,{ref:r,iconNode:e,className:jt(`lucide-${Ha(kt(l))}`,`lucide-${l}`,t),...s}));return n.displayName=kt(l),n};const Ya=N("align-justify",[["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 18h18",key:"1h113x"}],["path",{d:"M3 6h18",key:"d0wm0j"}]]);const Qa=N("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 Ra=N("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 Ut=N("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 es=N("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=N("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const gi=N("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const mi=N("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 ns=N("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const is=N("circle-dot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);const ts=N("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 ls=N("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 Gt=N("circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const Jt=N("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 as=N("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 Ht=N("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 ss=N("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 it=N("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 tt=N("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 Wt=N("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 rs=N("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 os=N("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 ds=N("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 cs=N("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 Kt=N("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 Zt=N("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 us=N("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 hs=N("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 fs=N("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 ps=N("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 gs=N("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 Ci=N("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);const Xt=N("move-down",[["path",{d:"M8 18L12 22L16 18",key:"cskvfv"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const yi=N("move-up",[["path",{d:"M8 6L12 2L16 6",key:"1yvkyx"}],["path",{d:"M12 2V22",key:"r89rzk"}]]);const Yt=N("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 Q=N("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);const ms=N("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 Cs=N("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 ys=N("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 vs=N("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 ws=N("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 Qt=N("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 Fs=N("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 zs=N("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=N("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 lt=N("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 Vs=N("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 ne=N("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),at=o.memo(l=>{const{ref:e,file:n,className:t,error:s,rightSlot:r,size:d,...f}=l,h=()=>s?i.jsxs(i.Fragment,{children:[i.jsx(a.LuIcon,{icon:mi,color:"var(--base-a11)"}),i.jsx(a.Text,{accentColor:"base",className:"truncate",size:d,children:s})]}):n?i.jsxs(i.Fragment,{children:[i.jsx(a.LuIcon,{icon:os,color:"var(--base-a11)"}),i.jsx(a.Text,{className:"truncate",size:d,children:n.name})]}):i.jsx(i.Fragment,{children:i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(a.Spinner,{size:d})})});return i.jsxs(a.Card,{className:X.cx(t,"flex w-full items-center gap-2"),ref:e,size:"xs",...f,children:[h(),r]})});at.displayName="FileCard";function Qe(l){return Array.isArray(l)?l.every(e=>typeof e=="string"):!1}class Re{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 ze extends Re{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:t}=e;return{id:n,type:t}}static _serializeConfig(e){const{id:n,type:t}=e;return{id:n,type:t}}}class M extends ze{label;description;required;image;constructor(e){const{label:n,description:t,required:s,image:r,...d}=e;super(d),this.label=n,this.description=t,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 t=n(e);if(t)return t}}}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:t,required:s,...r}=e;return{...ze._deserializeConfig(r),label:n,description:t??void 0,required:s}}static _serializeConfig(e){const{label:n,description:t,required:s,...r}=e;return{...ze._serializeConfig(r),label:n,description:t,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 A=o.createContext({}),st=l=>{const[e,n]=o.useState(null);return o.useLayoutEffect(()=>{const t=URL.createObjectURL(l);return n(t),()=>{URL.revokeObjectURL(t)}},[l]),e},Ve=o.memo(l=>{const{file:e,...n}=l,t=st(e);return i.jsx("img",{src:t??void 0,alt:e.name,...n})});Ve.displayName="ImageFile";const Rt=o.createContext(()=>{throw new Error("No ImageViewerProvider found")}),vi=()=>o.useContext(Rt),rt=o.memo(l=>{const{file:e,onClose:n}=l,t=o.useCallback(()=>{nt.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:t,"aria-label":"download",children:i.jsx(a.LuIcon,{icon:tt})}),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:ne})})})]}),i.jsx("div",{className:"flex size-full items-center justify-center overflow-hidden p-4",children:i.jsx(Ve,{className:"max-h-full max-w-full",file:e})})]})})});rt.displayName="ImageViewer";const el=o.memo(l=>{const{children:e}=l,[n,t]=o.useState(null),s=o.useCallback(()=>{t(null)},[]),r=o.useCallback(f=>{t(f(s))},[s]),d=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),s())},[s,n]);return i.jsxs(Rt.Provider,{value:r,children:[e,n&&i.jsx(rt,{file:n.file,onClose:d})]})});el.displayName="FileViewerProvider";const _=o.memo(l=>{const{label:e,error:n,description:t,required:s,children:r,inputId:d,image:f,size:h}=l,[u,p]=o.useState(void 0),m=vi();o.useEffect(()=>{f instanceof Promise?f.then(p).catch(console.error):p(f)},[f]);const g=o.useCallback(()=>{u&&m(()=>({file:u}))},[m,u]),C=s?`${e??"Unlabelled"} *`:e??"Unlabelled";return i.jsxs("div",{className:"flex flex-col gap-1",children:[u&&i.jsx(Ve,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:u,onClick:g}),(!!e||!!t)&&i.jsxs("div",{className:"flex flex-col",children:[i.jsx("label",{className:"w-max max-w-full",htmlFor:d,children:i.jsx(a.Text,{size:h,className:"text-wrap",children:C})}),!!t&&i.jsx(a.Text,{accentColor:"base",size:h,children:t})]}),r,!!n&&i.jsx(a.Text,{accentColor:"danger",size:h,children:n})]})});_.displayName="InputWithLabel";const nl=l=>l.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),wi=l=>l.map(e=>i.jsx(o.Fragment,{children:e.render()},e.id)),P=l=>{const{field:e}=l,{field:{value:n,name:t,onChange:s,onBlur:r,disabled:d},fieldState:{isTouched:f,error:h}}=Y.useController({name:e.id});return{value:n,name:t,disabled:d,isTouched:f,error:h?.message??"",onChange:s,onBlur:r}},il=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),[u,p]=o.useState(""),[m,g]=o.useState(""),C=o.useCallback(V=>{d(V),r()},[d,r]),y=o.useCallback(V=>{t&&t.findIndex(S=>S===V.target.value.trim())>=0?g("All options must be unique"):V.target.value?g(""):g("Option cannot be empty"),p(V.target.value)},[p,t]),w=o.useCallback(()=>{if(m)return;if(!u.trim()){g("Option cannot be empty");return}const V=u.trim();C([...t,V]),p("")},[u,m,C,t]),F=o.useCallback(V=>{V.key==="Enter"&&(V.preventDefault(),w())},[w]),z=o.useCallback(V=>{const S=Array.from(t);S.splice(V,1),C(S)},[t,C]),q=o.useCallback(V=>{if(!V.destination)return;const S=V.source.index,I=V.destination.index,T=Array.from(t),[D]=T.splice(S,1);T.splice(I,0,D),C(T)},[C,t]),x=o.useCallback(()=>{r()},[r]);return i.jsx(et.DragDropContext,{onDragEnd:q,children:i.jsxs(_,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:m||f,image:e.image,children:[(!h||t.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:F,id:e.id,placeholder:e.placeholder??"Press enter to add a new option",onBlur:x,name:s,disabled:h})}),i.jsx(a.IconButton,{size:n,accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!m||h,onClick:w,children:i.jsx(a.LuIcon,{icon:Q})})]}),t.length!==0&&i.jsx(et.Droppable,{droppableId:`${e.id}-droppable`,children:V=>i.jsxs("div",{className:"flex flex-col gap-1",...V.droppableProps,ref:V.innerRef,children:[t.map((S,I)=>i.jsx(et.Draggable,{draggableId:`${S}-draggable`,index:I,isDragDisabled:h,children:({draggableProps:T,dragHandleProps:D,innerRef:Z})=>i.jsxs(a.Badge,{...D,...T,ref:Z,className:"flex items-center justify-between gap-2",accentColor:"base",size:n,variant:"soft",children:[i.jsx(a.Text,{className:"truncate",highContrast:!0,children:ot(S).label}),i.jsx(a.IconButton,{className:"bg-transparent!",size:n,variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:h,onClick:()=>{z(I)},children:i.jsx(a.LuIcon,{icon:ne})})]})},`${e.id}-${S}-${I}`)),V.placeholder]})})]})})});il.displayName="MultiStringFieldInput";class re extends M{type="multi-string";minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:t,placeholder:s,...r}=e;super(r),this.minLength=n,this.maxLength=t,this.placeholder=s}render(){return i.jsx(il,{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:t,placeholder:s,...r}=e;return{...M._deserializeConfig(r),minLength:n,maxLength:t,placeholder:s}}static serializeConfig(e){const{minLength:n,maxLength:t,placeholder:s,...r}=e;return{...M._serializeConfig(r),minLength:n,maxLength:t,placeholder:s}}isSerializedValue(e){return Qe(e)}isValue(e){return Qe(e)}blankValue(){return[]}areValuesEqual(e,n){const t=new Set(e),s=new Set(n);return t.size===s.size&&t.isSubsetOf(s)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const t=new Set(e),s=new Set(n);return t.size===s.size&&t.isSubsetOf(s)}}function ot(l){return typeof l=="string"&&(l={label:l,value:l}),l}function oe(l){return l.map(ot)}class R extends M{options;constructor(e){const{options:n,...t}=e;super(t),this.options=oe(n)}serialize(){return{...super.serialize(),options:this.options}}config(){return{...super.config(),options:this.options}}static _deserializeConfig(e){const{options:n,...t}=e;return{...M._deserializeConfig(t),options:n}}static _serializeConfig(e){const{options:n,...t}=e;return{...M._serializeConfig(t),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 dt=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(m=>{d(!!m),r()},[r,d]),p=o.useCallback(()=>{r()},[r]);return i.jsx(_,{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:t??!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})})})})});dt.displayName="BooleanFieldInput";class de extends M{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 M._deserializeConfig(e)}static serializeConfig(e){return M._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(dt,{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 tl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(g=>{const C=g.target.valueAsNumber,y=isNaN(C)?null:C;d(y)},[d]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(g=>{g.key==="Enter"&&g.preventDefault()},[]);return i.jsx(_,{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:t??"",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})})})});tl.displayName="NumberFieldInput";class G extends M{type="number";minimum;maximum;integers;placeholder;constructor(e){const{minimum:n,maximum:t,integers:s,placeholder:r,...d}=e;super(d),this.minimum=n,this.maximum=t,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,t=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 t=="number"&&e.push(s=>{if(typeof s=="number"&&s>t)return`Must be at most ${t}.`}),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:t,integers:s,placeholder:r,...d}=e;return{...M._deserializeConfig(d),minimum:n,maximum:t,integers:s,placeholder:r}}static serializeConfig(e){const{minimum:n,maximum:t,integers:s,placeholder:r,...d}=e;return{...M._serializeConfig(d),minimum:n,maximum:t,integers:s,placeholder:r}}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}}class Se extends M{minLength;maxLength;placeholder;constructor(e){const{minLength:n,maxLength:t,placeholder:s,...r}=e;super(r),this.minLength=n,this.maxLength=t,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,t=this.maxLength;return typeof n=="number"&&e.push(s=>{if(s.length<n)return`Minimum ${n} character(s).`}),typeof t=="number"&&e.push(s=>{if(s.length>t)return`Maximum ${t} 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:t,placeholder:s,...r}=e;return{...M._deserializeConfig(r),minLength:t,maxLength:n,placeholder:s}}static _serializeConfig(e){const{minLength:n,maxLength:t,placeholder:s,...r}=e;return{...M._serializeConfig(r),minLength:n,maxLength:t,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 ll=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(m=>{d(m),r()},[r,d]),p=o.useCallback(()=>{r()},[r]);return i.jsx(_,{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:t,onValuesChange:u,disabled:h,children:e.options.map((m,g)=>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}-${g}`))})})});ll.displayName="CheckboxListFieldInput";class ie extends R{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(ll,{field:this})}isSerializedValue(e){if(!Qe(e))return!1;const n=new Set(this.options.map(({value:t})=>t));return e.every(t=>n.has(t))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const t=new Set(e),s=new Set(n);return t.size===s.size&&t.isSubsetOf(s)}areValuesEqual(e,n){const t=new Set(e),s=new Set(n);return t.size===s.size&&t.isSubsetOf(s)}}const ct=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),[u,p]=o.useState(!1),m=o.useCallback(C=>{d(C??null),r(),p(!1)},[d,r]),g=o.useCallback(C=>{p(C),C||r()},[r]);return i.jsx(_,{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:g,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:!!t,children:t?t.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd"}),i.jsx(a.LuIcon,{icon:gi})]})}),i.jsx(a.Popover.Content,{align:"start",size:n,children:i.jsx(a.DayPicker,{size:n,required:!1,mode:"single",variant:"solid",selected:t??void 0,onSelect:m})})]})})});ct.displayName="DateFieldInput";class be extends M{type="date";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new be({...this.getOptions(),id:e})}static deserialize(e){return new be(e)}static fromConfig(e){return new be(e)}static deserializeConfig(e){return M._deserializeConfig(e)}static serializeConfig(e){return M._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(ct,{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=(l=>(l.Text="text",l.Selection="selection",l.Numeric="numeric",l.Temporal="temporal",l.Capture="capture",l.Assessment="assessment",l.Verification="verification",l))(O||{});const al=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(m=>{d(m),r()},[r,d]),p=o.useCallback(m=>{m||r()},[r]);return i.jsx(_,{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:t&&t.length>0,children:t&&t.length>0?t.join(", "):e.placeholder??"Select one or more..."}),i.jsx(a.LuIcon,{icon:gi})]})}),i.jsx(a.Menu.Content,{size:n,children:i.jsx(a.Menu.Scroll,{children:i.jsxs(a.Menu.MultiSelectGroup,{values:t,onValuesChange:u,children:[i.jsxs(a.Menu.SelectAllItem,{children:[i.jsx(a.Menu.CheckboxItemIndicator,{children:m=>m?i.jsx(a.LuIcon,{icon:Ci}):i.jsx(a.LuIcon,{icon:H})}),"Select all"]}),e.options.map((m,g)=>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}-${g}`))]})})})]})})});al.displayName="MultiSelectFieldInput";class te extends R{type="multi-select";placeholder;constructor(e){const{placeholder:n,...t}=e;super(t),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,...t}=e;return{...R._deserializeConfig(t),placeholder:n}}static serializeConfig(e){const{placeholder:n,...t}=e;return{...R._serializeConfig(t),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(al,{field:this})}isSerializedValue(e){if(!Qe(e))return!1;const n=new Set(this.options.map(({value:t})=>t));return e.every(t=>n.has(t))}isValue(e){return this.isSerializedValue(e)}blankValue(){return[]}areValuesEqual(e,n){const t=new Set(e),s=new Set(n);return t.size===s.size&&t.isSubsetOf(s)}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){const t=new Set(e),s=new Set(n);return t.size===s.size&&t.isSubsetOf(s)}}const sl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(g=>{d(g)},[d]),p=o.useCallback(()=>{r()},[r]),m=o.useMemo(()=>Array.from({length:e.length},()=>b.v4()),[e.length]);return i.jsx(_,{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:t,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(g=>i.jsx(a.OneTimePasswordField.Input,{id:g},g)),i.jsx(a.OneTimePasswordField.HiddenInput,{})]})})});sl.displayName="OTPFieldInput";class ce extends M{type="otp";length;constructor(e){const{length:n,...t}=e;super(t),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(t=>{if(t.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,...t}=e;return{...M._deserializeConfig(t),length:n}}static serializeConfig(e){const{length:n,...t}=e;return{...M._serializeConfig(t),length:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(sl,{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:ns},fail:{label:"Fail",icon:ls},na:{label:"N/A",icon:ts}},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 Ne 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 Ne((t,s)=>{Promise.resolve(e).then(t).catch(s)},n)}then(e,n){const t=super.then(e,n);return t.uuid=this.uuid,t}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 rl(l){return Array.isArray(l)?l.every(e=>e instanceof Ne||e instanceof le):!1}function Fi(l,e){const n=new Set(l.map(({uuid:s})=>s)),t=new Set(e.map(({uuid:s})=>s));return n.size===t.size&&n.isSubsetOf(t)}const ol=o.createContext(()=>{throw new Error("No ImageCapturerProvider found")}),ut=()=>o.useContext(ol),dl=o.memo(l=>{const{onCapture:e}=l,[n,t]=o.useState("idle"),[s,r]=o.useState(!1),d=o.useRef(null),f=o.useRef(null),h=o.useRef(null),u=o.useCallback(()=>{h.current&&(h.current.getTracks().forEach(C=>C.stop()),h.current=null),d.current&&(d.current.srcObject=null),t("idle")},[]),p=pi.useActiveCallback(async C=>{if(d.current){u(),t("loading");try{const y=await navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:{ideal:"environment"},width:{ideal:1920},height:{ideal:1080}}});if(!C()){u();return}h.current=y,d.current.srcObject=y,await d.current.play(),t("ready")}catch{t("errored")}}},[u]),m=o.useCallback(()=>{const C=d.current,y=f.current;if(!C||!y||C.videoWidth<=0||C.videoHeight<=0)return;const w=Math.min(C.clientWidth/C.videoWidth,C.clientHeight/C.videoHeight);y.style.width=`${C.videoWidth*w}px`,y.style.height=`${C.videoHeight*w}px`,y.getAnimations().forEach(F=>F.cancel()),y.animate([{opacity:.8},{opacity:0}],{duration:250,easing:"ease-out"})},[]),g=pi.useActiveCallback(async C=>{if(d.current)try{r(!0);const y=d.current,w=y.videoHeight,F=y.videoWidth,z=Math.max(F,w),q=Math.min(1,1920/z),x=document.createElement("canvas");x.width=Math.round(F*q),x.height=Math.round(w*q);const V=x.getContext("2d");if(!V)throw new Error("Could not setup canvas context.");V.drawImage(y,0,0,x.width,x.height),m();const S=await new Promise((Z,B)=>{x.toBlob(J=>J?Z(J):B(new Error("Could not convert canvas to blob.")),"image/jpeg",.92)});if(!C())return;const I=new Date,T=`${I.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`,D=new File([S],T,{type:S.type,lastModified:I.getTime()});e?.(D)}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:X.cx("relative flex shrink grow flex-col items-center justify-center overflow-hidden",{"bg-black":!n}),children:[i.jsx("video",{ref:d,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:mi,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:g,disabled:s})})]})});dl.displayName="Camera";const cl=o.memo(l=>{const{files:e,onDelete:n,children:t,open:s,onOpenChange:r,defaultOpen:d,modal:f}=l,[h,u]=o.useState(null);o.useEffect(()=>{u(e.length>0?e[0]:null)},[e]);const p=o.useCallback(()=>{h&&nt.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]),g=o.useCallback(()=>{if(!h)return;const y=e.indexOf(h);u(y!==e.length-1?e[y+1]:e[0])},[h,e]),C=o.useCallback(()=>{h&&n?.(h)},[h,n]);return i.jsxs(a.Overlay.Root,{open:s,onOpenChange:r,defaultOpen:d,modal:f,children:[!!t&&i.jsx(a.Overlay.Trigger,{asChild:!0,children:t}),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:ne})})})}),i.jsx("div",{className:"flex grow items-center justify-center overflow-hidden",children:h?i.jsx(Ve,{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:tt})}),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:yi,className:"-rotate-90 rounded-r-none"})}),i.jsx(a.IconButton,{"aria-label":"next",onClick:g,type:"button",children:i.jsx(a.LuIcon,{icon:yi,className:"rotate-90 rounded-l-none"})})]}),i.jsx(a.IconButton,{"aria-label":"delete",onClick:C,type:"button",children:i.jsx(a.LuIcon,{icon:se})})]})]})})]})});cl.displayName="ImagesViewer";const ht=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,onConfirm:d}=l,[f,h]=o.useState([]),u=o.useCallback(C=>{C||h([]),t?.(C)},[t]),p=o.useCallback(C=>{h(y=>[...y,C])},[]),m=o.useCallback(C=>{h(y=>y.filter(w=>w!==C))},[]),g=o.useCallback(()=>{d?.(f)},[f,d]);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:g,children:i.jsx(a.LuIcon,{icon:H})})}),f.length>0?i.jsx(cl,{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:ne})})})]}),i.jsx(dl,{onCapture:p})]})]})]})});ht.displayName="ImageCapturer";const ul=o.memo(l=>{const{children:e}=l,[n,t]=o.useState(null),s=o.useCallback(()=>{t(null)},[]),r=o.useCallback(f=>{t(f(s))},[s]),d=o.useCallback(()=>{n&&(n.onClose&&n.onClose(),s())},[s,n]);return i.jsxs(ol.Provider,{value:r,children:[e,n&&i.jsx(ht,{open:!0,onOpenChange:d,onConfirm:n.onConfirm,modal:n.modal})]})});ul.displayName="ImageCapturerProvider";const ft=o.memo(l=>{const{ref:e,file:n,error:t,rightSlot:s,className:r,size:d,...f}=l;return i.jsxs(a.Card,{className:X.cx(r,"p-0! relative flex h-48 w-full flex-col overflow-hidden"),ref:e,size:"xs",...f,children:[!n&&!t&&i.jsx("div",{className:"absolute inset-0 flex grow items-center justify-center",children:i.jsx(a.Spinner,{size:d})}),!!n&&!t&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(Ve,{className:"block size-full max-w-full object-cover",file:n})}),!!t&&i.jsx("div",{className:"grow"}),(!!n||!!t)&&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:[t?i.jsx(a.LuIcon,{color:"var(--base-11)",icon:mi}):n&&i.jsx(a.LuIcon,{color:"var(--base-11)",icon:Kt}),i.jsx(a.Text,{className:"truncate",size:d,children:t??n?.name}),s]})]})]})});ft.displayName="ImageCard";const pt=o.memo(l=>{const{file:e,...n}=l,t=st(e);return i.jsx("video",{src:t??void 0,...n})});pt.displayName="VideoFile";const gt=o.memo(l=>{const{ref:e,file:n,className:t,error:s,rightSlot:r,size:d,...f}=l;return i.jsxs(a.Card,{className:X.cx(t,"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:d})}),!!n&&!s&&i.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden p-3",children:i.jsx(pt,{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:mi}):n&&i.jsx(a.LuIcon,{color:"var(--base-11)",icon:Vs}),i.jsx(a.Text,{className:"truncate",size:d,children:s??n?.name}),r]})]})]})});gt.displayName="VideoCard";const mt=o.memo(l=>{const{fileOrPromise:e,onRemove:n,disabled:t,size:s}=l,[r,d]=o.useState(e instanceof Ne?null:e),[f,h]=o.useState(null),u=vi();pi.useActiveEffect(z=>{if(h(null),!(e instanceof Ne)){d(e);return}d(null),e.then(q=>{z()&&d(q)}).catch(q=>{z()&&h(q instanceof Error?q.message:"Unknown error")})},[e]);const p=o.useCallback(()=>{if(!r)return;const z=new Blob([r]);nt.saveAs(z,r.name)},[r]),m=o.useCallback(()=>{n(e)},[n,e]),g=o.useCallback(()=>{if(!r)return;const z=URL.createObjectURL(r);window.open(z,"_blank"),URL.revokeObjectURL(z)},[r]),C=o.useCallback(()=>{r&&u(z=>({file:r,onDelete:t?void 0:()=>{m(),z()}}))},[t,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:Wt})})}),i.jsxs(a.Menu.Content,{size:s,children:[i.jsxs(a.Menu.Item,{onSelect:p,disabled:!r,children:[i.jsx(a.LuIcon,{icon:tt})," Download"]}),t?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"]})]})]})]})}),[t,m,p,r,s]),w=!!r?.type.startsWith("image/"),F=!!r?.type.startsWith("video/");return w?i.jsx(ft,{className:"cursor-pointer",onClick:C,file:r,error:f??void 0,rightSlot:y,size:s}):F?i.jsx(gt,{className:"cursor-pointer",onClick:C,file:r,error:f??void 0,rightSlot:y,size:s}):i.jsx(at,{className:"cursor-pointer",file:r,error:f??void 0,onClick:g,rightSlot:y,size:s})});mt.displayName="DisplayFile";const hl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=ut(),p=o.useRef(null),m=o.useCallback(I=>{const T=e.cleanValue({...t,status:I});d(T),r()},[e,r,d,t]),g=o.useCallback(I=>{const T=I.target.value,D={...t,notes:T};d(D)},[t,d]),C=o.useCallback(()=>{r()},[r]),y=o.useCallback(I=>{const T=t.files.filter(({uuid:D})=>D!==I.uuid);d({...t,files:T}),r()},[d,r,t]),w=o.useCallback(()=>{u(I=>({onConfirm:T=>{const D=T.map(Z=>le.from(b.v4(),Z));d({...t,files:[...t.files,...D]}),r()},onClose:()=>{r(),I()}}))},[r,d,t,u]),F=o.useCallback(()=>{p.current?.click()},[]),z=o.useCallback(I=>{const T=Array.from(I.target.files??[]).map(Z=>le.from(b.v4(),Z)),D={...t,files:[...t.files,...T]};d(D),r()},[r,d,t]);o.useEffect(()=>{if(!p.current)return;const I=new AbortController;return p.current.addEventListener("cancel",()=>{r()},{signal:I.signal}),()=>{I.abort()}},[r,t]);const q=t.status&&e.showNotesAndFilesOn.includes(t.status),x=`${e.id}-status`,V=`${e.id}-notes`,S=`${e.id}-files`;return i.jsx(_,{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:x,className:"flex gap-2",name:s,value:t.status,disabled:h,accentColor:"base",variant:"surface",size:n,onValueChange:m,children:Te.map(I=>{const{label:T}=ue[I];return i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.RadioGroup.Item,{value:I,children:i.jsx(a.RadioGroup.Indicator,{children:i.jsx(a.LuIcon,{icon:Gt,className:"fill-current"})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:T})]},`${e.id}-${I}`)})}),q&&i.jsxs(i.Fragment,{children:[i.jsx("div",{children:i.jsx(a.TextArea,{id:V,value:t.notes??"",name:s,onChange:g,onBlur:C,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:lt}),"Select files"]})}),i.jsxs(a.Menu.Content,{size:n,children:[i.jsxs(a.Menu.Item,{onSelect:w,children:[i.jsx(a.LuIcon,{icon:Ut}),"Take photos"]}),i.jsxs(a.Menu.Item,{onSelect:F,children:[i.jsx(a.LuIcon,{icon:Yt}),"Attach files"]})]})]}),i.jsx("input",{id:S,name:s,type:"file",ref:p,multiple:!0,className:"hidden",onChange:z,value:""}),t.files.length>0&&i.jsx("div",{className:"flex h-max flex-wrap gap-2",children:t.files.map(I=>i.jsx(mt,{size:n,fileOrPromise:I,onRemove:y,disabled:h},I.uuid))})]})]})]})})});hl.displayName="PassFailFieldInput";const Ct=l=>typeof l=="string"&&Te.includes(l),fl=l=>!(l===null||typeof l!="object"||!("status"in l)||!Ct(l.status)||!("notes"in l)||typeof l.notes!="string"||!("files"in l)||!(Array.isArray(l.files)&&l.files.length===0)),pl=l=>!(l===null||typeof l!="object"||!("status"in l)||!Ct(l.status)||!("notes"in l)||typeof l.notes!="string"||!("files"in l)||!rl(l.files)),gl=l=>({status:l.status,notes:l.notes,files:[]}),ml=l=>({status:l.status,notes:l.notes,files:[]}),Cl=(l,e)=>!(l.status!==e.status||l.notes!==e.notes||!Fi(l.files,e.files)),yl=(l,e)=>!(l.status!==e.status||l.notes!==e.notes||l.files.length!==e.files.length);class he extends M{type="pass-fail";showNotesAndFilesOn;constructor(e){const{showNotesAndFilesOn:n,...t}=e;super(t),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(t=>{const{label:s}=ue[t];return{value:t,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,t=this.blankValue();return n.length>0&&(e.push(s=>{if(!(!s.status||!n.includes(s.status))&&t.notes===s.notes)return"Notes is required."}),e.push(s=>{if(!(!s.status||!n.includes(s.status))&&Fi(t.files,s.files))return"Files is required."})),e}static deserialize(e){const{showNotesAndFilesOn:n,...t}=e;return new he({...t,showNotesAndFilesOn:n})}static fromConfig(e){return new he(e)}static deserializeConfig(e){const{showNotesAndFilesOn:n,...t}=e;return{...M._deserializeConfig(t),showNotesAndFilesOn:n}}static serializeConfig(e){const{showNotesAndFilesOn:n,...t}=e;return{...M._serializeConfig(t),showNotesAndFilesOn:n}}serializeValue(e){return gl(e)}deserializeValue(e){return ml(e)}render(){return i.jsx(hl,{field:this})}isSerializedValue(e){return fl(e)}isValue(e){return pl(e)}areValuesEqual(e,n){return Cl(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 yl(e,n)}}const vl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(g=>{d(g),r()},[r,d]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(()=>{d(null),r()},[r,d]);return i.jsx(_,{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:t??"",onValueChange:u,disabled:h,children:[e.options.map((g,C)=>i.jsxs("label",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(a.RadioGroup.Item,{value:g.value,onBlur:p,children:i.jsx(a.RadioGroup.Indicator,{children:i.jsx(a.LuIcon,{icon:Gt,className:"fill-current"})})}),i.jsx(a.Text,{size:n,accentColor:"base",className:"truncate",children:g.label})]},`${e.id}-${g.value}-${C}`)),!!t&&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:ne}),"Clear"]})]})})});vl.displayName="RadioFieldInput";class fe extends R{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 R._deserializeConfig(e)}static serializeConfig(e){return R._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(vl,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:t})=>t)]).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 Ss=X.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"]}}}),wl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(g=>{d(g),r()},[r,d]),p=o.useCallback(()=>{d(null),r()},[r,d]),m=Array.from({length:e.maxRating},(g,C)=>C+1);return i.jsx(_,{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:t,onValueChange:u,disabled:h,children:m.map(g=>i.jsx(a.Rating.Item,{value:g,className:Ss({size:n}),children:i.jsx(a.LuIcon,{icon:Qt,className:"size-full group-data-[active=true]:fill-current"})},`${e.id}-${g}`))}),!h&&t!==null&&i.jsx(a.IconButton,{onClick:p,type:"button",variant:"ghost",accentColor:"base",size:n,children:i.jsx(a.LuIcon,{icon:ne})})]})})});wl.displayName="RatingFieldInput";class pe extends M{type="rating";maxRating;constructor(e){const{maxRating:n,...t}=e;super(t),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(t=>{if(typeof t=="number"&&(t<1||t>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,...t}=e;return{...M._deserializeConfig(t),maxRating:n}}static serializeConfig(e){const{maxRating:n,...t}=e;return{...M._serializeConfig(t),maxRating:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(wl,{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 yt=o.createContext(null),Fl=()=>{const l=o.use(yt);if(!l)throw new Error("useScannerContext must be used within a component tree wrapped by ScannerProvider.");return l},bs=()=>{const l=o.use(yt);if(!l)throw new Error("useScanner must be used within a component tree wrapped by ScannerProvider.");return l.openScanner},zi=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,...d}=l;return i.jsxs(a.Overlay.Root,{open:n,onOpenChange:t,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(zl,{...d})]})]})});zi.displayName="Scanner";const zl=o.memo(l=>{const{paused:e,formats:n,timeBetweenDecodingAttempts:t,trySkew:s,onDecodeResult:r,onDecodeError:d,onError:f}=l,{wasmUrl:h}=Fl(),{ref:u}=ja.useZxing({wasmUrl:h,paused:e,formats:n,timeBetweenDecodingAttempts:t,trySkew:s,onDecodeResult:r,onDecodeError:d,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:ne})})})}),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})})]})});zl.displayName="ScannerInternal";const Vl=o.memo(l=>{const{children:e,wasmUrl:n}=l,[t,s]=o.useState(null),r=o.useCallback(()=>{s(null)},[]),d=o.useCallback(u=>{s(u(r))},[r]),f=o.useCallback(()=>{t&&(t.onClose&&t.onClose(),r())},[r,t]),h=o.useMemo(()=>({wasmUrl:n,openScanner:d}),[n,d]);return i.jsxs(yt,{value:h,children:[e,t&&i.jsx(zi,{open:!0,onOpenChange:f,...t})]})});Vl.displayName="ScannerProvider";const Sl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),[u,p]=o.useState(!1),m=o.useCallback(F=>{const z=F.target.value;d(z)},[d]),g=o.useCallback(()=>{r()},[r]),C=o.useCallback(F=>{d(F.rawValue.trim()),r(),p(!1)},[d,r]),y=o.useCallback(()=>{p(!0)},[]),w=o.useCallback(()=>{p(!1),r()},[r]);return i.jsxs(_,{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:t??"",placeholder:"Enter a qr or barcode",onChange:m,onBlur:g,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:gs}),"Scan"]}),i.jsx(zi,{open:u,onDecodeResult:C,onOpenChange:w})]})});Sl.displayName="ScanFieldInput";class xe extends M{type="qr";constructor(e){super(e)}serialize(){return super.serialize()}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new xe({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}static deserialize(e){return new xe(e)}static fromConfig(e){return new xe(e)}static deserializeConfig(e){return M._deserializeConfig(e)}static serializeConfig(e){return M._serializeConfig(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Sl,{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 bl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(g=>{d(g??null),r()},[r,d]),p=o.useCallback(g=>{g||r()},[r]),m=o.useMemo(()=>e.options.find(g=>g.value===t),[e.options,t]);return i.jsx(_,{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:gi})]})}),i.jsx(a.Menu.Content,{size:n,children:i.jsx(a.Menu.Scroll,{children:i.jsx(a.Menu.SelectGroup,{required:!1,value:t??void 0,onValueChange:u,children:e.options.map((g,C)=>i.jsxs(a.Menu.SelectItem,{value:g.value,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),g.label]},`${e.id}-${g.value}-${C}`))})})})]})})});bl.displayName="SelectFieldInput";class ge extends R{type="select";placeholder;constructor(e){const{placeholder:n,...t}=e;super(t),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,...t}=e;return{...R._deserializeConfig(t),placeholder:n}}static serializeConfig(e){const{placeholder:n,...t}=e;return{...R._serializeConfig(t),placeholder:n}}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(bl,{field:this})}isSerializedValue(e){return typeof e!="string"&&e!==null?!1:new Set([null,...this.options.map(({value:t})=>t)]).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 Nl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(g=>{const C=g.target.value;d(C)},[d]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(g=>{g.key==="Enter"&&g.preventDefault()},[]);return i.jsx(_,{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:t??"",type:"text",placeholder:e.placeholder??"Enter a short description",onChange:u,onBlur:p,disabled:h,onKeyDown:m})})})});Nl.displayName="StringFieldInput";class me extends Se{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 Se._deserializeConfig(e)}static serializeConfig(e){return Se._serializeConfig(e)}render(){return i.jsx(Nl,{field:this})}}const xl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(m=>{const g=m.target.value;d(g)},[d]),p=o.useCallback(()=>{r()},[r]);return i.jsx(_,{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:t??"",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})})});xl.displayName="TextFieldInput";class Ce extends Se{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 Se._deserializeConfig(e)}static serializeConfig(e){return Se._serializeConfig(e)}render(){return i.jsx(xl,{field:this})}}const vt=Ns(),Il=new Set(vt);function Ns(l=!0){const e=new Set;for(let n=-12;n<=14;n++){const t=n>=0?"+":"-",s=Math.abs(n).toString().padStart(2,"0");e.add(`${t}${s}:00`)}if(l){const n=[-12.5,-9.5,-3.5,3.5,4.5,5.5,6.5,9.5,10.5,12.5];for(const t of n){const s=t>=0?"+":"-",r=Math.floor(Math.abs(t)).toString().padStart(2,"0");e.add(`${s}${r}:30`)}}return Array.from(e).sort((n,t)=>Ml(n)-Ml(t))}function Ml(l){const e=l[0]==="+"?1:-1,n=Number(l.slice(1,3)),t=Number(l.slice(4,6));return e*(n*60+t)}const xs="+00:00",Is=/^T([01]\d|2[0-3]):([0-5]\d):00([+-]\d{2}:\d{2})$/,Vi=l=>typeof l=="string"&&Il.has(l),ql=()=>{const l=-new Date().getTimezoneOffset(),e=l>=0?"+":"-",n=Math.abs(l),t=Math.floor(n/60),s=n%60,r=`${e}${t.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`;return Vi(r)?r:xs};function Ol(l){const e=/^([+-])(\d{2}):(\d{2})$/.exec(l);if(!e)throw new Error(`Invalid UTC offset: ${l}`);return(e[1]==="+"?1:-1)*(Number(e[2])*60+Number(e[3]))}const en=l=>{const e=Is.exec(l);if(!e)return null;const n=e[3];return Vi(n)?{hours:Number(e[1]),minutes:Number(e[2]),utcOffset:n}:null},ee=l=>typeof l=="string"&&en(l)!==null,ye=(l,e,n=ql())=>{if(!Number.isInteger(l)||l<0||l>23)throw new Error(`Invalid hour: ${l}`);if(!Number.isInteger(e)||e<0||e>59)throw new Error(`Invalid minute: ${e}`);if(!Vi(n))throw new Error("Unsupported UTC offset");const t=l.toString().padStart(2,"0"),s=e.toString().padStart(2,"0");return`T${t}:${s}:00${n}`},Si=l=>`UTC${l}`,ve=l=>{const e=en(l);if(!e)throw new Error(`Invalid time value: ${l}`);return(e.hours*60+e.minutes-Ol(e.utcOffset)+1440)%1440},bi=(l,e=!0)=>{const n=en(l);if(!n)throw new Error(`Invalid time value: ${l}`);const t=(n.hours%12||12).toString().padStart(2,"0"),s=n.minutes.toString().padStart(2,"0"),r=n.hours>=12?"PM":"AM",d=`${t}:${s} ${r}`;return e?`${d} ${Si(n.utcOffset)}`:d},Ms=l=>typeof l=="object"&&(ee(l.from)||ee(l.to)),wt=(l,e)=>{const n=ve(l),t=e.from?ve(e.from):null,s=e.to?ve(e.to):null;return t===null&&s===null?!0:t===null?n<=s:s===null?n>=t:t<=s?n>=t&&n<=s:n>=t||n<=s},Ni=o.memo(l=>{const{value:e,onChange:n,onBlur:t,disabled:s,size:r="md",id:d,name:f,compact:h=!1}=l,u=e?en(e):null,p=u?`${u.hours.toString().padStart(2,"0")}:${u.minutes.toString().padStart(2,"0")}`:"",m=o.useCallback(y=>{const w=y.target.value;if(!w){n(null);return}const[F,z]=w.split(":").map(Number);n(ye(F,z,u?.utcOffset))},[n,u?.utcOffset]),g=o.useCallback(y=>{u&&(n(ye(u.hours,u.minutes,y)),t?.())},[t,n,u]),C=o.useCallback(y=>{y||t?.()},[t]);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:d,name:f,className:X.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:t,disabled:s})}),i.jsxs(a.Menu.Root,{align:"end",onOpenChange:C,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?Si(u.utcOffset):"UTC offset"}),i.jsx(a.LuIcon,{icon:gi})]})}),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:g,children:vt.map(y=>i.jsxs(a.Menu.SelectItem,{value:y,children:[i.jsx(a.Menu.SelectedIndicator,{children:i.jsx(a.LuIcon,{icon:H})}),Si(y)]},y))})})})]})]})});Ni.displayName="TimeFieldControl";const Ft=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e});return i.jsx(_,{size:n,inputId:e.id,label:e.label,description:e.description,required:e.required,error:f,image:e.image,children:i.jsx(Ni,{id:e.id,name:s,size:n,value:t,onChange:d,onBlur:r,disabled:h})})});Ft.displayName="TimeFieldInput";class Ie extends M{type="time";constructor(e){super(e)}static deserialize(e){return new Ie(e)}static fromConfig(e){return new Ie(e)}static deserializeConfig(e){return M._deserializeConfig(e)}static serializeConfig(e){return M._serializeConfig(e)}config(){return super.config()}getOptions(){return super.getOptions()}duplicate(e){return new Ie({...this.getOptions(),id:e})}setOptions(e){super.setOptions(e)}serializeValue(e){return e}deserializeValue(e){return e}render(){return i.jsx(Ft,{field:this})}isSerializedValue(e){return e===null||ee(e)}isValue(e){return e===null||ee(e)}blankValue(){return null}blankSerializedValue(){return null}areSerializedValuesEqual(e,n){return e===n}areValuesEqual(e,n){return e===n}}const Tl=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=ut(),p=o.useRef(null),m=o.useCallback(()=>{u(x=>({onConfirm:V=>{const S=Array.from(V).map(T=>le.from(b.v4(),T)),I=[...t,...S];d(I),r()},onClose:()=>{r(),x()}}))},[r,d,t,u]),g=o.useCallback(()=>{p.current?.click()},[]),C=o.useCallback(()=>{if(!p.current)return;const x=p.current.files;if(!x){r();return}const V=Array.from(x).map(I=>le.from(b.v4(),I)),S=[...t,...V];d(S),r()},[r,d,t]),y=o.useCallback(x=>{const V=t.filter(({uuid:S})=>S!==x.uuid);d(V),r()},[t,d,r]);o.useEffect(()=>{if(!p.current)return;const x=new AbortController;return p.current.addEventListener("cancel",()=>{r()},{signal:x.signal}),()=>{x.abort()}},[r,t]);const w=e.maxFiles!==1,q=w?"Select files":"Select a file";return i.jsxs(_,{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:lt}),q]})}),i.jsxs(a.Menu.Content,{size:n,children:[i.jsxs(a.Menu.Item,{onSelect:m,children:[i.jsx(a.LuIcon,{icon:Ut}),"Take photos"]}),i.jsxs(a.Menu.Item,{onSelect:g,children:[i.jsx(a.LuIcon,{icon:Yt}),"Attach files"]})]})]}),i.jsx("input",{id:e.id,name:s,type:"file",ref:p,accept:e.extensions?.join(","),multiple:w,className:"hidden",onChange:C,value:""}),t.length>0&&i.jsx("div",{className:"mt-1 flex h-max flex-col gap-2",children:t.map(x=>i.jsx(mt,{size:n,fileOrPromise:x,onRemove:y,disabled:h},x.uuid))})]})});Tl.displayName="UploadFieldInput";class we extends M{type="upload";extensions;maxSize;maxFiles;constructor(e){const{extensions:n,maxFiles:t,maxSize:s,...r}=e;super(r),this.maxSize=s,this.maxFiles=t,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,t=n&&n*1e3*1e3,s=this.maxFiles;return typeof n=="number"&&typeof t=="number"&&e.push(r=>{if(r.some(d=>d instanceof le&&d.size>t))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 we({...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 we(e)}static fromConfig(e){return new we(e)}static deserializeConfig(e){const{extensions:n,maxSize:t,maxFiles:s,...r}=e;return{...M._deserializeConfig(r),extensions:n,maxSize:t,maxFiles:s}}static serializeConfig(e){const{extensions:n,maxSize:t,maxFiles:s,...r}=e;return{...M._serializeConfig(r),extensions:n,maxSize:t,maxFiles:s}}serializeValue(e){return[]}deserializeValue(e){return[]}render(){return i.jsx(Tl,{field:this})}isSerializedValue(e){return Array.isArray(e)&&e.length===0}isValue(e){return Array.isArray(e)?e.every(n=>n instanceof Ne||n instanceof le):!1}areValuesEqual(e,n){return Fi(e,n)}blankValue(){return[]}blankSerializedValue(){return[]}areSerializedValuesEqual(e,n){return e.length===n.length}}const El=o.memo(l=>{const{field:e}=l,{size:n}=o.use(A),{value:t,name:s,onBlur:r,onChange:d,error:f,disabled:h}=P({field:e}),u=o.useCallback(C=>{const y=C.target.value;y!==""&&!URL.canParse(y)||d(y!==""?new URL(y):null)},[d]),p=o.useCallback(()=>{r()},[r]),m=o.useCallback(C=>{C.key==="Enter"&&C.preventDefault()},[]),g=o.useCallback(()=>{t!==null&&window.open(t,"_blank","noopener,noreferrer")},[t]);return i.jsx(_,{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:t?t.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:t===null,onClick:g,children:i.jsx(a.LuIcon,{icon:rs})})]})})});El.displayName="URLFieldInput";class Me extends M{type="url";placeholder;constructor(e){const{placeholder:n,...t}=e;super(t),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 Me({...this.getOptions(),id:e})}setOptions(e){"placeholder"in e&&(this.placeholder=e.placeholder),super.setOptions(e)}static deserialize(e){return new Me(e)}static fromConfig(e){return new Me(e)}static deserializeConfig(e){const{placeholder:n,...t}=e;return{...M._deserializeConfig(t),placeholder:n}}static serializeConfig(e){const{placeholder:n,...t}=e;return{...M._serializeConfig(t),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(El,{field:this})}}const Ee={date:be,time:Ie,number:G,boolean:de,select:ge,string:me,url:Me,text:Ce,upload:we,qr:xe,"multi-string":re,"multi-select":te,radio:fe,"checkbox-list":ie,"pass-fail":he,otp:ce,rating:pe},Ll=Object.keys(Ee),L={"checkbox-list":{description:"Allows the user to select a multiple options from a list.",group:O.Selection,icon:ss,name:"Checkbox list"},"multi-select":{description:"Allows the user to select a multiple options from a list of options.",group:O.Selection,icon:hs,name:"Multi-select"},"multi-string":{description:"Allows the user to provide multiple unique strings.",group:O.Text,icon:ps,name:"Multi-string"},"pass-fail":{description:"Track pass, fail, or N/A outcome.",group:O.Assessment,icon:as,name:"Pass - Fail"},boolean:{description:"Perfect for both optional and required yes/no questions.",group:O.Selection,icon:vs,name:"Checkbox"},date:{description:"Allows specifying a date.",group:O.Temporal,icon:es,name:"Date"},time:{description:"Allows specifying a time and UTC offset.",group:O.Temporal,icon:zs,name:"Time"},number:{description:"Allows specifying a number within a given range.",group:O.Numeric,icon:cs,name:"Number"},otp:{description:"Allows specifying a number within a given range.",group:O.Verification,icon:ms,name:"OTP"},qr:{description:"Used for scanning/reading QR and barcodes.",group:O.Capture,icon:Cs,name:"Scan"},radio:{description:"Allows the user to select a single option from a list of options.",group:O.Selection,icon:is,name:"Option list"},rating:{description:"Allows users to select a rating value.",group:O.Assessment,icon:Qt,name:"Rating"},select:{description:"Allows the user to select a single option from a list of options.",group:O.Selection,icon:fs,name:"Dropdown"},string:{description:"Short text fields can hold up to 500 characters on a single line.",group:O.Text,icon:Fs,name:"Short Text"},text:{description:"Paragraph fields can hold up to 10000 characters and can have multiple lines.",group:O.Text,icon:Ya,name:"Paragraph"},upload:{description:"Allows a file to be uploaded.",group:O.Capture,icon:lt,name:"Upload"},url:{description:"Allows users to enter a URL.",group:O.Text,icon:us,name:"URL"}},Bl={[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"}},$="Unlabelled",xi="Unlabelled";class Al extends Re{id;value;constructor(e){const{id:n,value:t}=e;super(),this.id=n,this.value=t}serialize(){return{id:this.id,type:this.type,value:this.serializeValue(),modifier:this.modifier}}getValue=()=>this.value;setValue=e=>{this.value=e,this.notify(this)}}class v extends Al{field;constructor(e){const{field:n,...t}=e;super(t),this.field=n}serialize(){return{...super.serialize(),field:this.field.id}}isApplicable=e=>this.field.isValue(e);accessorFn=e=>e[this.field.id]}const Dl=o.memo,qe=Dl(function(l){const{ref:e,children:n,...t}=l,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,...t,children:s})}),_l=Dl(function(l){const{ref:e,children:n,...t}=l,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,...t,children:s})}),zt=o.memo(l=>{const{ref:e,children:n,...t}=l,s=o.useCallback(r=>typeof n=="function"?i.jsxs(i.Fragment,{children:[n(r),i.jsx(a.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:d=>d==="indeterminate"?i.jsx(a.LuIcon,{icon:Ci}):i.jsx(a.LuIcon,{icon:H})})]}):i.jsxs(i.Fragment,{children:[n,i.jsx(a.Menu.CheckboxItemIndicator,{className:"ml-[auto]",children:d=>d==="indeterminate"?i.jsx(a.LuIcon,{icon:Ci}):i.jsx(a.LuIcon,{icon:H})})]}),[n]);return i.jsx(a.Menu.SelectAllItem,{ref:e,...t,children:s})});zt.displayName="SelectAllItemTemplate";const Vt=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,size:d,align:f,accentColor:h="base",...u}=l;return i.jsxs(a.Popover.Root,{open:n,onOpenChange:t,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:d,align:f,children:i.jsx(a.DayPicker,{size:d,accentColor:h,...u})})]})});Vt.displayName="DayPickerPopover";const $l=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,size:d,accentColor:f="base",values:h,onValuesChange:u,placeholder:p="Enter text",...m}=l,[g,C]=o.useState(""),y=o.useCallback(q=>{C(q.target.value)},[]),w=o.useCallback(q=>{q.key==="Enter"&&(q.preventDefault(),q.stopPropagation(),u([...h,g]),C(""))},[g,u,h]),F=o.useCallback(()=>{u([...h,g]),C("")},[g,u,h]),z=o.useCallback(q=>{const x=[...h];x.splice(q,1),u(x)},[u,h]);return i.jsxs(a.Popover.Root,{open:n,onOpenChange:t,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:d,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:g,onChange:y,onKeyDown:w,placeholder:p,...m})}),i.jsx(a.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button",onClick:F,children:i.jsx(a.LuIcon,{icon:Q})})]}),h.length>0&&i.jsx("div",{className:"flex flex-col gap-1",children:h.map((q,x)=>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:q}),i.jsx(a.IconButton,{size:"xs",variant:"ghost",type:"button",accentColor:"base",onClick:()=>{z(x)},children:i.jsx(a.LuIcon,{icon:ne})})]},`${q}-${x}`))})]})})]})});$l.displayName="NumberInputPopover";const Oe=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,size:d,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter a number",...m}=l,[g,C]=o.useState(null);o.useEffect(()=>{h!==void 0&&C(h)},[h]);const y=o.useCallback(F=>{const z=F.target.valueAsNumber;C(isNaN(z)?null:z)},[]),w=o.useCallback(F=>{const z=F.target.valueAsNumber;u?.(isNaN(z)?null:z)},[u]);return i.jsxs(a.Popover.Root,{open:n,onOpenChange:t,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:d,onClick:a.stopPropagation,...m,children:i.jsx(a.Input.Root,{size:d,accentColor:f,children:i.jsx(a.Input.Field,{placeholder:p,type:"number",value:g??"",onChange:y,onBlur:w})})})]})});Oe.displayName="NumberInputPopover";const k=l=>{const{condition:e,onClick:n,...t}=l,s=o.useCallback(()=>{n(e)},[e,n]);return i.jsx(a.IconButton,{onClick:s,...t,children:i.jsx(a.LuIcon,{icon:ne})})};k.displayName="RemoveConditionButton";const nn=o.memo(l=>{const{ref:e,selectFieldOptions:n,...t}=l,s=o.useMemo(()=>oe(n),[n]);return i.jsxs(a.Menu.MultiSelectGroup,{ref:e,...t,children:[i.jsx(zt,{children:"Select all"}),s.map(r=>i.jsx(_l,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))]})});nn.displayName="SelectFieldOptionMultiSelectGroup";const St=o.memo(l=>{const{ref:e,selectFieldOptions:n,...t}=l,s=o.useMemo(()=>oe(n),[n]);return i.jsx(a.Menu.SelectGroup,{ref:e,...t,children:s.map(r=>i.jsx(qe,{value:r.value,children:i.jsx("span",{className:"truncate",children:r.label})},r.value))})});St.displayName="SelectFieldOptionSelectGroup";const Le=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,size:d,accentColor:f="base",value:h,onValueChange:u,placeholder:p="Enter text",...m}=l,[g,C]=o.useState(""),y=o.useCallback(F=>{C(F.target.value)},[]),w=o.useCallback(F=>{const z=F.target.value;u?.(z)},[u]);return o.useEffect(()=>{h&&C(h)},[h]),i.jsxs(a.Popover.Root,{open:n,onOpenChange:t,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:d,onClick:a.stopPropagation,...m,children:i.jsx(a.Input.Root,{size:d,accentColor:f,children:i.jsx(a.Input.Field,{placeholder:p,type:"text",value:g,onChange:y,onBlur:w})})})]})});Le.displayName="TextInputPopover";const Ii=o.memo(l=>{const{children:e,open:n,onOpenChange:t,defaultOpen:s,modal:r,size:d="sm",accentColor:f="base",value:h,onValueChange:u,...p}=l;return i.jsxs(a.Popover.Root,{open:n,onOpenChange:t,defaultOpen:s,modal:r,children:[i.jsx(a.Popover.Trigger,{asChild:!0,children:e}),i.jsx(a.Popover.Content,{size:d,onClick:a.stopPropagation,accentColor:f,...p,children:i.jsx(Ni,{compact:!0,size:d,value:h,onChange:u})})]})});Ii.displayName="TimeInputPopover";const j=l=>{const{children:e,required:n,value:t,defaultValue:s,onValueChange:r,modifierConfig:d,size:f="sm",variant:h,accentColor:u,radius:p}=l;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:t,onValueChange:r,children:Object.keys(d).map(m=>{const{label:g}=d[m];return i.jsx(qe,{value:m,children:g},m)})})})]})},U=(l,e,n)=>o.useCallback(t=>{const{klass:s,isTransferable:r,defaultValue:d}=e[t],f=l.getValue(),h=new s({id:l.id,value:r(f)?f:d(),field:l.field});n(l,h)},[l,e,n]);class Be extends v{type="boolean";modifier="equals";static deserialize(e,n){return new Be({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===e}}class tn extends v{type="boolean";modifier="notEquals";static deserialize(e,n){return new tn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n!==e}}const Mi={equals:{klass:Be,label:"is",isTransferable:l=>!0,defaultValue:()=>!0},notEquals:{klass:tn,label:"is not",isTransferable:l=>!0,defaultValue:()=>!0}},Pl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=e.getValue(),r=e.modifier,d=()=>{switch(s){case!0:return"true";case!1:return"false"}},f=U(e,Mi,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||$})]}),i.jsx(j,{required:!0,value:r,onValueChange:f,modifierConfig:Mi,children:i.jsx(a.Button,{type:"button",children:Mi[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:d()})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsxs(a.Menu.SelectGroup,{required:!0,value:s,onValueChange:e.setValue,children:[i.jsx(qe,{value:!0,children:"true"}),i.jsx(qe,{value:!1,children:"false"})]})})]}),i.jsx(k,{condition:e,onClick:t})]})};class Ae extends v{type="checkbox-list";modifier="equals";static deserialize(e,n){return new Ae({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.size===s.size&&s.isSubsetOf(t)}}}class ln extends v{type="checkbox-list";modifier="notEquals";static deserialize(e,n){return new ln({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.size!==s.size||!s.isSubsetOf(t)}}}class an extends v{type="checkbox-list";modifier="every";static deserialize(e,n){return new an({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.isSubsetOf(s)}}}class sn extends v{type="checkbox-list";modifier="some";static deserialize(e,n){return new sn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return!t.isDisjointFrom(s)}}}class rn extends v{type="checkbox-list";modifier="none";static deserialize(e,n){return new rn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.isDisjointFrom(s)}}}const qi={equals:{klass:Ae,label:"is",isTransferable:l=>!0,defaultValue:()=>[]},notEquals:{klass:ln,label:"is not",isTransferable:l=>!0,defaultValue:()=>[]},every:{klass:an,label:"has all of",isTransferable:l=>!0,defaultValue:()=>[]},some:{klass:sn,label:"has any of",isTransferable:l=>!0,defaultValue:()=>[]},none:{klass:rn,label:"has none of",isTransferable:l=>!0,defaultValue:()=>[]}},kl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,qi,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(nn,{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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:qi,children:i.jsx(a.Button,{type:"button",children:qi[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Oi extends Re{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}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(t=>t.id===e.id?n:t)),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(t=>t.id));this.conditions=this.initConditions(this.conditions.filter(t=>!n.has(t.id))),this.notify(this)}applyConditions(e){return this.conditions.length===0?!0:this.conditions.map(t=>[t.getApplyFn(),t.isApplicable,t.accessorFn]).every(([t,s,r])=>{const d=r(e);return s(d)?t(d):!1})}}const qs=(l,e)=>o.useMemo(()=>{const n=new Oi(l);return n.observe(t=>e(t.getConditions())),n},[l,e]);class De extends v{type="date";modifier="equals";static deserialize(e,n){return new De({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()===e.getTime()}}class on extends v{type="date";modifier="notEquals";static deserialize(e,n){return new on({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()!==e.getTime()}}class dn extends v{type="date";modifier="before";static deserialize(e,n){return new dn({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()<e.getTime()}}class cn extends v{type="date";modifier="after";static deserialize(e,n){return new cn({...e,value:new Date(e.value),field:n})}serializeValue(){return this.value.toISOString()}getApplyFn(){const e=this.value;return n=>n===null?!1:n.getTime()>e.getTime()}}class un extends v{type="date";modifier="in";static deserialize(e,n){return new un({...e,value:{from:e.value.from?new Date(e.value.from):void 0,to:e.value.to?new Date(e.value.to):void 0},field:n})}serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getApplyFn(){const e=this.value;return n=>!(n===null||e.from&&e.from.getTime()>n.getTime()||e.to&&e.to.getTime()<n.getTime())}}class hn extends v{type="date";modifier="notIn";static deserialize(e,n){return new hn({...e,value:{from:e.value.from?new Date(e.value.from):void 0,to:e.value.to?new Date(e.value.to):void 0},field:n})}serializeValue(){return{from:this.value.from?.toISOString()??null,to:this.value.to?.toISOString()??null}}getApplyFn(){const e=this.value;return n=>n===null?!1:!!(e.from&&e.from.getTime()>n.getTime()||e.to&&e.to.getTime()<n.getTime())}}const Ti={equals:{klass:De,label:"is",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},notEquals:{klass:on,label:"is not",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},before:{klass:dn,label:"before",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},after:{klass:cn,label:"after",isTransferable:l=>l instanceof Date,defaultValue:()=>new Date(new Date().setHours(0,0,0,0))},in:{klass:un,label:"in between",isTransferable:l=>!(l instanceof Date),defaultValue:()=>({from:void 0,to:void 0})},notIn:{klass:hn,label:"not in between",isTransferable:l=>!(l instanceof Date),defaultValue:()=>({from:void 0,to:void 0})}},jl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Ti,n),r=()=>{switch(e.modifier){case"in":case"notIn":{const d=e.getValue();return i.jsx(Vt,{required:!0,mode:"range",size:"sm",selected:d,onSelect:e.setValue,children:i.jsxs(a.Button,{type:"button",className:"truncate",children:[d.from?.toLocaleDateString()??"..."," - ",d.to?.toLocaleDateString()??"..."]})})}default:return i.jsx(Vt,{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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Ti,children:i.jsx(a.Button,{type:"button",children:Ti[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class _e extends v{type="multi-select";modifier="equals";static deserialize(e,n){return new _e({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.size===s.size&&s.isSubsetOf(t)}}}class fn extends v{type="multi-select";modifier="notEquals";static deserialize(e,n){return new fn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.size!==s.size||!s.isSubsetOf(t)}}}class pn extends v{type="multi-select";modifier="every";static deserialize(e,n){return new pn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.isSubsetOf(s)}}}class gn extends v{type="multi-select";modifier="some";static deserialize(e,n){return new gn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return!t.isDisjointFrom(s)}}}class mn extends v{type="multi-select";modifier="none";static deserialize(e,n){return new mn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.isDisjointFrom(s)}}}const Ei={equals:{klass:_e,label:"is",isTransferable:l=>!0,defaultValue:()=>[]},notEquals:{klass:fn,label:"is not",isTransferable:l=>!0,defaultValue:()=>[]},every:{klass:pn,label:"has all of",isTransferable:l=>!0,defaultValue:()=>[]},some:{klass:gn,label:"has any of",isTransferable:l=>!0,defaultValue:()=>[]},none:{klass:mn,label:"has none of",isTransferable:l=>!0,defaultValue:()=>[]}},Ul=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Ei,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(nn,{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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Ei,children:i.jsx(a.Button,{type:"button",children:Ei[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class $e extends v{type="multi-string";modifier="equals";static deserialize(e,n){return new $e({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.size===s.size&&s.isSubsetOf(t)}}}class Cn extends v{type="multi-string";modifier="notEquals";static deserialize(e,n){return new Cn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.size!==s.size||!s.isSubsetOf(t)}}}class yn extends v{type="multi-string";modifier="every";static deserialize(e,n){return new yn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.isSubsetOf(s)}}}class vn extends v{type="multi-string";modifier="some";static deserialize(e,n){return new vn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return!t.isDisjointFrom(s)}}}class wn extends v{type="multi-string";modifier="none";static deserialize(e,n){return new wn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>{const t=new Set(e),s=new Set(n);return t.isDisjointFrom(s)}}}const Li={equals:{klass:$e,label:"is",isTransferable:l=>!0,defaultValue:()=>[]},notEquals:{klass:Cn,label:"is not",isTransferable:l=>!0,defaultValue:()=>[]},every:{klass:yn,label:"has all of",isTransferable:l=>!0,defaultValue:()=>[]},some:{klass:vn,label:"has any of",isTransferable:l=>!0,defaultValue:()=>[]},none:{klass:wn,label:"has none of",isTransferable:l=>!0,defaultValue:()=>[]}},Gl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Li,n),r=()=>{const d=e.getValue();return i.jsx($l,{values:d,onValuesChange:e.setValue,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:d.length===1?d[0]:`${d.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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Li,children:i.jsx(a.Button,{type:"button",children:Li[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Pe extends v{type="number";modifier="equals";static deserialize(e,n){return new Pe({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class Fn extends v{type="number";modifier="notEquals";static deserialize(e,n){return new Fn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class zn extends v{type="number";modifier="lessThan";static deserialize(e,n){return new zn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n<e}}class Vn extends v{type="number";modifier="lessThanOrEquals";static deserialize(e,n){return new Vn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n<=e}}class Sn extends v{type="number";modifier="greaterThan";static deserialize(e,n){return new Sn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n>e}}class bn extends v{type="number";modifier="greaterThanOrEquals";static deserialize(e,n){return new bn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n>=e}}class Nn extends v{type="number";modifier="inRange";static deserialize(e,n){return new Nn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!(n===null||e.to!==null&&n>e.to||e.from!==null&&n<e.from)}}class xn extends v{type="number";modifier="notInRange";static deserialize(e,n){return new xn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:e.to!==null&&n>e.to||e.from!==null&&n<e.from}}const Bi={equals:{klass:Pe,label:"is",isTransferable:l=>typeof l=="number",defaultValue:()=>0},notEquals:{klass:Fn,label:"is not",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThan:{klass:zn,label:"is less than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThanOrEquals:{klass:Vn,label:"is less than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThan:{klass:Sn,label:"is greater than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:bn,label:"is greater than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},inRange:{klass:Nn,label:"is between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:xn,label:"is not between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})}},Jl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Bi,n),r=o.useCallback(u=>{u===null||e.modifier==="inRange"||e.modifier==="notInRange"||e.setValue(u)},[e]),d=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:d,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Bi,children:i.jsx(a.Button,{type:"button",children:Bi[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:t})]})};class ke extends v{type="otp";modifier="equals";static deserialize(e,n){return new ke({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===e}}class In extends v{type="otp";modifier="notEquals";static deserialize(e,n){return new In({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n!==e}}class Mn extends v{type="otp";modifier="includes";static deserialize(e,n){return new Mn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.includes(e)}}class qn extends v{type="otp";modifier="excludes";static deserialize(e,n){return new qn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!n.includes(e)}}const Ai={equals:{klass:ke,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:In,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:Mn,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:qn,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Hl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Ai,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Ai,children:i.jsx(a.Button,{type:"button",children:Ai[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class je extends v{type="pass-fail";modifier="equals";static deserialize(e,n){return new je({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.status===null?!1:n.status===e}}class On extends v{type="pass-fail";modifier="notEquals";static deserialize(e,n){return new On({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.status===null?!1:n.status!==e}}class Tn extends v{type="pass-fail";modifier="includes";static deserialize(e,n){return new Tn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.status===null?!1:e.includes(n.status)}}class En extends v{type="pass-fail";modifier="excludes";static deserialize(e,n){return new En({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.status===null?!1:!e.includes(n.status)}}const Di={equals:{klass:je,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>"pass"},notEquals:{klass:On,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>"pass"},includes:{klass:Tn,label:"is any of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]},excludes:{klass:En,label:"is none of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]}},Wl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Di,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(d=>i.jsx(qe,{value:d,children:ue[d].label},d))})})]});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(zt,{children:"Select all"}),Te.map(d=>i.jsxs(_l,{value:d,children:[i.jsx(a.LuIcon,{icon:ue[d].icon}),ue[d].label]},d))]})})]})}};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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Di,children:i.jsx(a.Button,{type:"button",children:Di[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Ue extends v{type="radio";modifier="equals";static deserialize(e,n){return new Ue({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class Ln extends v{type="radio";modifier="notEquals";static deserialize(e,n){return new Ln({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class Bn extends v{type="radio";modifier="includes";static deserialize(e,n){return new Bn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:e.includes(n)}}class An extends v{type="radio";modifier="excludes";static deserialize(e,n){return new An({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:!e.includes(n)}}const _i={equals:{klass:Ue,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>""},notEquals:{klass:Ln,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>""},includes:{klass:Bn,label:"is any of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]},excludes:{klass:An,label:"is none of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]}},Kl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,_i,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const d=e.getValue(),f=oe(e.field.options).find(h=>h.value===d)?.label;return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"truncate",children:f??(d||"...")})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(St,{required:!0,selectFieldOptions:e.field.options,value:d,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(nn,{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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:_i,children:i.jsx(a.Button,{type:"button",children:_i[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Ge extends v{type="rating";modifier="equals";static deserialize(e,n){return new Ge({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class Dn extends v{type="rating";modifier="notEquals";static deserialize(e,n){return new Dn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class _n extends v{type="rating";modifier="lessThan";static deserialize(e,n){return new _n({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n<e}}class $n extends v{type="rating";modifier="lessThanOrEquals";static deserialize(e,n){return new $n({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n<=e}}class Pn extends v{type="rating";modifier="greaterThan";static deserialize(e,n){return new Pn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n>e}}class kn extends v{type="rating";modifier="greaterThanOrEquals";static deserialize(e,n){return new kn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n>=e}}class jn extends v{type="rating";modifier="inRange";static deserialize(e,n){return new jn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!(n===null||e.to!==null&&n>e.to||e.from!==null&&n<e.from)}}class Un extends v{type="rating";modifier="notInRange";static deserialize(e,n){return new Un({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:e.to!==null&&n>e.to||e.from!==null&&n<e.from}}const $i={equals:{klass:Ge,label:"is",isTransferable:l=>typeof l=="number",defaultValue:()=>0},notEquals:{klass:Dn,label:"is not",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThan:{klass:_n,label:"is less than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},lessThanOrEquals:{klass:$n,label:"is less than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThan:{klass:Pn,label:"is greater than",isTransferable:l=>typeof l=="number",defaultValue:()=>0},greaterThanOrEquals:{klass:kn,label:"is greater than or equal to",isTransferable:l=>typeof l=="number",defaultValue:()=>0},inRange:{klass:jn,label:"is between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})},notInRange:{klass:Un,label:"is not between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})}},Zl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,$i,n),r=o.useCallback(u=>{u===null||e.modifier==="inRange"||e.modifier==="notInRange"||e.setValue(u)},[e]),d=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:d,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:$i,children:i.jsx(a.Button,{type:"button",children:$i[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:t})]})};class Je extends v{type="qr";modifier="equals";static deserialize(e,n){return new Je({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===e}}class Gn extends v{type="qr";modifier="notEquals";static deserialize(e,n){return new Gn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n!==e}}class Jn extends v{type="qr";modifier="includes";static deserialize(e,n){return new Jn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.includes(e)}}class Hn extends v{type="qr";modifier="excludes";static deserialize(e,n){return new Hn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!n.includes(e)}}const Pi={equals:{klass:Je,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:Gn,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:Jn,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:Hn,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Xl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Pi,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Pi,children:i.jsx(a.Button,{type:"button",children:Pi[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class He extends v{type="select";modifier="equals";static deserialize(e,n){return new He({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n===e}}class Wn extends v{type="select";modifier="notEquals";static deserialize(e,n){return new Wn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:n!==e}}class Kn extends v{type="select";modifier="includes";static deserialize(e,n){return new Kn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:e.includes(n)}}class Zn extends v{type="select";modifier="excludes";static deserialize(e,n){return new Zn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===null?!1:!e.includes(n)}}const ki={equals:{klass:He,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>""},notEquals:{klass:Wn,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>""},includes:{klass:Kn,label:"is any of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]},excludes:{klass:Zn,label:"is none of",isTransferable:l=>Array.isArray(l),defaultValue:()=>[]}},Yl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,ki,n),r=()=>{switch(e.modifier){case"equals":case"notEquals":{const d=e.getValue(),f=oe(e.field.options).find(h=>h.value===d)?.label;return i.jsxs(a.Menu.Root,{children:[i.jsx(a.Menu.ClickTrigger,{children:i.jsx(a.Button,{type:"button",className:"truncate",children:f??(d||"...")})}),i.jsx(a.Menu.Content,{size:"sm",children:i.jsx(St,{required:!0,selectFieldOptions:e.field.options,value:d,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(nn,{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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:ki,children:i.jsx(a.Button,{type:"button",children:ki[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class We extends v{type="string";modifier="equals";static deserialize(e,n){return new We({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===e}}class Xn extends v{type="string";modifier="notEquals";static deserialize(e,n){return new Xn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n!==e}}class Yn extends v{type="string";modifier="includes";static deserialize(e,n){return new Yn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.includes(e)}}class Qn extends v{type="string";modifier="excludes";static deserialize(e,n){return new Qn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!n.includes(e)}}const ji={equals:{klass:We,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:Xn,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:Yn,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:Qn,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Ql=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,ji,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:ji,children:i.jsx(a.Button,{type:"button",children:ji[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Ke extends v{type="text";modifier="equals";static deserialize(e,n){return new Ke({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n===e}}class Rn extends v{type="text";modifier="notEquals";static deserialize(e,n){return new Rn({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n!==e}}class ei extends v{type="text";modifier="includes";static deserialize(e,n){return new ei({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>n.includes(e)}}class ni extends v{type="text";modifier="excludes";static deserialize(e,n){return new ni({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!n.includes(e)}}const Ui={equals:{klass:Ke,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:Rn,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:ei,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:ni,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},Rl=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Ui,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Ui,children:i.jsx(a.Button,{type:"button",children:Ui[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Ze extends v{type="time";modifier="equals";static deserialize(e,n){return new Ze({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>ee(n)?n===e:!1}}class ii extends v{type="time";modifier="notEquals";static deserialize(e,n){return new ii({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>ee(n)?n!==e:!1}}class ti extends v{type="time";modifier="before";static deserialize(e,n){return new ti({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>ee(n)?ve(n)<ve(e):!1}}class li extends v{type="time";modifier="after";static deserialize(e,n){return new li({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>ee(n)?ve(n)>ve(e):!1}}class ai extends v{type="time";modifier="in";static deserialize(e,n){return new ai({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>ee(n)?wt(n,e):!1}}class si extends v{type="time";modifier="notIn";static deserialize(e,n){return new si({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>ee(n)?!wt(n,e):!1}}const Gi={equals:{klass:Ze,label:"is",isTransferable:l=>typeof l=="string",defaultValue:()=>ye(0,0)},notEquals:{klass:ii,label:"is not",isTransferable:l=>typeof l=="string",defaultValue:()=>ye(0,0)},before:{klass:ti,label:"before",isTransferable:l=>typeof l=="string",defaultValue:()=>ye(0,0)},after:{klass:li,label:"after",isTransferable:l=>typeof l=="string",defaultValue:()=>ye(0,0)},in:{klass:ai,label:"in between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})},notIn:{klass:si,label:"not in between",isTransferable:l=>typeof l=="object",defaultValue:()=>({from:null,to:null})}},ea=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Gi,n),r=o.useCallback(u=>{u===null||e.modifier==="in"||e.modifier==="notIn"||e.setValue(u)},[e]),d=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(Ii,{value:u.from,onValueChange:d,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.from?bi(u.from):"..."})}),i.jsx(Ii,{value:u.to,onValueChange:f,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:u.to?bi(u.to):"..."})})]})}default:return i.jsx(Ii,{value:e.getValue(),onValueChange:r,size:"sm",children:i.jsx(a.Button,{type:"button",className:"truncate",children:bi(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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Gi,children:i.jsx(a.Button,{type:"button",children:Gi[e.modifier].label})}),h(),i.jsx(k,{condition:e,onClick:t})]})};class Xe extends v{type="upload";modifier="equals";static deserialize(e,n){return new Xe({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.length>0}}class ri extends v{type="upload";modifier="notEquals";static deserialize(e,n){return new ri({...e,field:n})}serializeValue(){return this.value}getApplyFn(){return e=>e.length===0}}const Ji={equals:{klass:Xe,label:"is",isTransferable:l=>!0,defaultValue:()=>!0},notEquals:{klass:ri,label:"is not",isTransferable:l=>!0,defaultValue:()=>!0}},na=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Ji,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(qe,{value:!0,children:"empty"}),i.jsx(qe,{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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Ji,children:i.jsx(a.Button,{type:"button",children:Ji[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})};class Ye extends v{type="url";modifier="equals";static deserialize(e,n){return new Ye({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>(n?.toString()??"")===e}}class oi extends v{type="url";modifier="notEquals";static deserialize(e,n){return new oi({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>(n?.toString()??"")!==e}}class di extends v{type="url";modifier="includes";static deserialize(e,n){return new di({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>(n?.toString()??"").includes(e)}}class ci extends v{type="url";modifier="excludes";static deserialize(e,n){return new ci({...e,field:n})}serializeValue(){return this.value}getApplyFn(){const e=this.value;return n=>!(n?.toString()??"").includes(e)}}const Hi={equals:{klass:Ye,label:"is",isTransferable:l=>!0,defaultValue:()=>""},notEquals:{klass:oi,label:"is not",isTransferable:l=>!0,defaultValue:()=>""},includes:{klass:di,label:"includes",isTransferable:l=>!0,defaultValue:()=>""},excludes:{klass:ci,label:"does not include",isTransferable:l=>!0,defaultValue:()=>""}},ia=l=>{const{condition:e,onReplace:n,onRemove:t}=l,s=U(e,Hi,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||$})]}),i.jsx(j,{required:!0,value:e.modifier,onValueChange:s,modifierConfig:Hi,children:i.jsx(a.Button,{type:"button",children:Hi[e.modifier].label})}),r(),i.jsx(k,{condition:e,onClick:t})]})},Os={date:{equals:De,notEquals:on,before:dn,after:cn,in:un,notIn:hn},boolean:{equals:Be,notEquals:tn},"checkbox-list":{equals:Ae,notEquals:ln,every:an,none:rn,some:sn},"multi-select":{equals:_e,notEquals:fn,every:pn,none:mn,some:gn},"multi-string":{equals:$e,notEquals:Cn,every:yn,none:wn,some:vn},number:{equals:Pe,notEquals:Fn,greaterThan:Sn,greaterThanOrEquals:bn,inRange:Nn,lessThan:zn,lessThanOrEquals:Vn,notInRange:xn},otp:{equals:ke,notEquals:In,excludes:qn,includes:Mn},"pass-fail":{equals:je,notEquals:On,excludes:En,includes:Tn},radio:{equals:Ue,notEquals:Ln,excludes:An,includes:Bn},rating:{equals:Ge,notEquals:Dn,greaterThan:Pn,greaterThanOrEquals:kn,inRange:jn,lessThan:_n,lessThanOrEquals:$n,notInRange:Un},qr:{equals:Je,notEquals:Gn,excludes:Hn,includes:Jn},select:{equals:He,notEquals:Wn,excludes:Zn,includes:Kn},string:{equals:We,notEquals:Xn,excludes:Qn,includes:Yn},text:{equals:Ke,notEquals:Rn,excludes:ni,includes:ei},time:{equals:Ze,notEquals:ii,after:li,before:ti,in:ai,notIn:si},url:{equals:Ye,notEquals:oi,excludes:ci,includes:di},upload:{equals:Xe,notEquals:ri}},ta=(l,e)=>{if(l.type!==e.type)throw new Error(`field and condition type mismatch ${l.type} !== ${e.type}`);return Os[e.type][e.modifier].deserialize(e,l)},Wi=(l,e)=>{const n=bt(l,e),t={};for(const s of l)t[s.id]=s;return n.map(s=>ta(t[s.field],s))},la=(l,e)=>Nt(l,e).map(t=>t.serialize()),bt=(l,e)=>{const n=new Set(l.map(t=>t.id));return e.filter(t=>n.has(t.field))},Nt=(l,e)=>{const n=new Set(l.map(t=>t.id));return e.filter(t=>n.has(t.field.id))},xt=l=>{const{condition:e,...n}=l;switch(e.type){case"string":return i.jsx(Ql,{condition:e,...n});case"text":return i.jsx(Rl,{condition:e,...n});case"otp":return i.jsx(Hl,{condition:e,...n});case"qr":return i.jsx(Xl,{condition:e,...n});case"url":return i.jsx(ia,{condition:e,...n});case"select":return i.jsx(Yl,{condition:e,...n});case"radio":return i.jsx(Kl,{condition:e,...n});case"checkbox-list":return i.jsx(kl,{condition:e,...n});case"multi-select":return i.jsx(Ul,{condition:e,...n});case"multi-string":return i.jsx(Gl,{condition:e,...n});case"number":return i.jsx(Jl,{condition:e,...n});case"rating":return i.jsx(Zl,{condition:e,...n});case"date":return i.jsx(jl,{condition:e,...n});case"time":return i.jsx(ea,{condition:e,...n});case"pass-fail":return i.jsx(Wl,{condition:e,...n});case"upload":return i.jsx(na,{condition:e,...n});case"boolean":return i.jsx(Pl,{condition:e,...n})}},Ki=l=>Ee[l.type].deserialize(l);function Ts(l){return l.map(Ki)}function aa(l){return l.type==="section"?W.deserialize(l):Ki(l)}const Zi=l=>l.map(aa),It=l=>Ee[l.type].fromConfig(l),sa=l=>l.map(e=>It(e)),ra=l=>l.type==="section"?W.fromConfig(l):It(l),oa=l=>l.map(ra),Mt=l=>Ee[l.type].deserializeConfig(l),da=l=>l.map(Mt),ca=l=>l.type==="section"?W.deserializeConfig(l):Mt(l),ua=l=>l.map(ca),qt=l=>Ee[l.type].serializeConfig(l),ha=l=>l.map(qt),fa=l=>l.type==="section"?W.serializeConfig(l):qt(l),pa=l=>l.map(fa);function Es(l){const e={};for(const n of l)e[n.id]=n;return e}function ga(l,e,n=!0){const t=n?Xi(l,e):e,s={};for(const r of l){if(!(r.id in t))continue;const d=t[r.id];s[r.id]=r.serializeValue(d)}return s}function ma(l,e,n=!0){const t=n?Ot(l,e):e,s={};for(const r of l){if(!(r.id in t))continue;const d=t[r.id];s[r.id]=r.deserializeValue(d)}return s}function Xi(l,e){const n={};for(const t of l){if(!(t.id in e))continue;const s=e[t.id];t.isValue(s)&&(n[t.id]=t.cleanValue(s))}return n}function Ot(l,e){const n={};for(const t of l){if(!(t.id in e))continue;const s=e[t.id];t.isSerializedValue(s)&&(n[t.id]=t.cleanSerializedValue(s))}return n}function Ca(l,e){const n=Xi(l,e),t={},s={};for(const r of l){if(!(r.id in n))continue;const d=n[r.id];switch(r.type){case"upload":if(!r.isValue(d))break;s[r.id]=d,t[r.id]=[];break;case"pass-fail":if(!r.isValue(d))break;s[r.id]=d.files,t[r.id]={...d,files:[]};break;default:t[r.id]=e[r.id]}}return[t,s]}function ya(l,e,n){const t={};for(const s of l){if(!(s.id in e))continue;const r=e[s.id];switch(s.type){case"upload":if(!s.isValue(r))break;t[s.id]=n[s.id]??[];break;case"pass-fail":if(!s.isValue(r))break;t[s.id]={...r,files:n[s.id]??[]};break;default:if(!s.isValue(r))break;t[s.id]=r}}return t}const va=(l,e)=>{const n={};for(const t of l){const s=e[t.id];n[t.id]=s!==void 0?s:t.blankValue()}return n},wa=(l,e,n)=>{const t={};for(const s of l){const r=e[s.id],d=n[s.id];s.areValuesEqual(r,d)||(t[s.id]=d)}return t},Fa=(l,e,n)=>{const t={};for(const s of l){const r=e[s.id],d=n[s.id];s.areValuesEqual(r,d)&&(t[s.id]=d)}return t},Tt=(l,e,n)=>l.every(t=>{const s=e[t.id],r=n[t.id];return t.areValuesEqual(s,r)}),Et=l=>{const e={};for(const n of l)e[n.id]=n.blankValue();return e},za=(l,e)=>Tt(l,e,Et(l)),Ls=X.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),Yi=X.cva(["flex","flex-col"],{variants:{size:{xs:["gap-2"],sm:["gap-4"],md:["gap-6"],lg:["gap-8"],xl:["gap-10"]}}}),Va=o.memo(l=>{const{fieldSection:e}=l,{label:n,description:t}=e,s=Y.useWatch(),{fieldSchema:r,size:d}=o.use(A),f=o.useMemo(()=>r.getFieldSections(),[r]),h=o.useMemo(()=>f.findIndex(({id:g})=>g===e.id),[f,e.id]),u=o.useMemo(()=>f.filter(g=>e.id in g.conditions),[f,e.id]),p=o.useMemo(()=>u.length===0?!0:u.some(g=>{const C=g.getConditions(e.id);return new Oi(C).applyConditions(s)}),[u,e,s]),m=wi(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||t)&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx(a.Heading,{size:d,children:n}),t&&i.jsx(a.Text,{accentColor:"base",size:d,children:t})]})}),i.jsx("div",{className:Yi({size:d}),children:m})]})]}):null});Va.displayName="FieldSectionLayout";class W extends ze{type="section";label;description;conditions;fields=[];constructor(e){const{label:n,description:t,fields:s,conditions:r={},...d}=e;super(d),this.label=n,this.description=t,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:Object.fromEntries(Object.entries(this.conditions).map(([e,n])=>[e,n.map(t=>t.serialize())]))}}static deserialize=e=>{const n=e.fields.map(Ki),t={};for(const[s,r]of Object.entries(e.conditions??{}))t[s]=Wi(n,r);return new W({...e,fields:n,conditions:t})};static fromConfig=e=>{const n=sa(e.fields),t={};for(const[s,r]of Object.entries(e.conditions??{}))t[s]=Wi(n,r);return new W({...e,fields:n,conditions:t})};static deserializeConfig(e){const{label:n,description:t,fields:s,conditions:r,...d}=e;return{...ze._deserializeConfig(d),label:n,description:t,fields:da(s),conditions:r}}static serializeConfig(e){const{label:n,description:t,fields:s,conditions:r,...d}=e;return{...ze._serializeConfig(d),label:n,description:t,fields:ha(s),conditions:r}}config(){return{...super.config(),label:this.label,description:this.description,fields:this.fields.map(e=>e.config()),conditions:Object.fromEntries(Object.entries(this.conditions).map(([e,n])=>[e,n.map(t=>t.serialize())]))}}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 t of this.fields){const s=t.getError(e[t.id]);s&&(n[t.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 t=[...this.fields];t.splice(n??this.fields.length,0,e),this.fields=this.initFields(t),this.notify(this)}moveField(e,n){const t=[...this.fields],[s]=t.splice(e,1);t.splice(n,0,s),this.fields=t,this.notify(this)}removeField(e){this.fields=this.initFields(this.fields.filter(({id:t})=>t!==e.id));const n={};for(const[t,s]of Object.entries(this.conditions))n[t]=s.filter(r=>r.field.id!==e.id);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,t){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).map(s=>s.id===n.id?t:s)}),this.notify(this)}removeCondition(e,n){this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(t=>t.id!==n.id)}),this.notify(this)}removeConditions(e,n){const t=new Set(n.map(s=>s.id));this.conditions=this.initConditions({...this.conditions,[e]:(this.conditions[e]??[]).filter(s=>!t.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(Va,{fieldSection:this})}}const ae=o.createContext({}),Qi=o.memo(l=>{const{children:e,variant:n,size:t,accentColor:s,onSelectFieldType:r,...d}=l,f=o.useMemo(()=>{const h={[O.Assessment]:[],[O.Capture]:[],[O.Numeric]:[],[O.Selection]:[],[O.Temporal]:[],[O.Text]:[],[O.Verification]:[]};for(const u of Ll){const{group:p}=L[u];h[p].push(u)}return h},[]);return i.jsxs(a.Menu.Root,{...d,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:t,accentColor:s,children:i.jsx(a.Menu.Scroll,{children:Object.entries(f).map(([h,u])=>{const{name:p}=Bl[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)})})})]})});Qi.displayName="CreateFieldDropdownMenu";const Sa=o.memo(l=>{const{fieldType:e,onSelectFieldType:n}=l,t=o.useCallback(()=>{n(e)},[e,n]),{icon:s,name:r}=L[e];return i.jsxs(a.Menu.Item,{onSelect:t,children:[i.jsx(a.LuIcon,{icon:s}),i.jsx(a.Text,{className:"truncate",children:r})]})});Sa.displayName="CreateFieldDropdownMenuItem";const Ri=l=>{switch(l){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 be({label:"",required:!1,id:b.v4()});case"time":return new Ie({label:"",required:!1,id:b.v4()});case"string":return new me({label:"",required:!1,id:b.v4()});case"url":return new Me({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 we({label:"",required:!1,id:b.v4()});case"qr":return new xe({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})}},ui=l=>{switch(l.type){case"text":return new Ke({id:b.v4(),value:"",field:l});case"boolean":return new Be({id:b.v4(),value:!0,field:l});case"number":return new Pe({id:b.v4(),value:0,field:l});case"date":return new De({id:b.v4(),value:new Date,field:l});case"time":return new Ze({id:b.v4(),value:ye(0,0),field:l});case"string":return new We({id:b.v4(),value:"",field:l});case"url":return new Ye({id:b.v4(),value:"",field:l});case"select":return new He({id:b.v4(),value:"",field:l});case"multi-string":return new $e({id:b.v4(),value:[],field:l});case"multi-select":return new _e({id:b.v4(),value:[],field:l});case"upload":return new Xe({id:b.v4(),value:!0,field:l});case"qr":return new Je({id:b.v4(),value:"",field:l});case"radio":return new Ue({id:b.v4(),value:"",field:l});case"checkbox-list":return new Ae({id:b.v4(),value:[],field:l});case"pass-fail":return new je({id:b.v4(),value:"pass",field:l});case"otp":return new ke({id:b.v4(),value:"",field:l});case"rating":return new Ge({id:b.v4(),value:0,field:l})}},ba=(l,e)=>{switch(l){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 we.getFieldCreationSchema(e);case"pass-fail":return he.getFieldCreationSchema(e);case"otp":return ce.getFieldCreationSchema(e);case"rating":return pe.getFieldCreationSchema(e);default:return}},Na=o.memo(l=>{const{popoverInputs:e,...n}=l;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:ys}),"Settings"]})}),i.jsx(a.Popover.Content,{size:"sm",...n,children:i.jsx("div",{className:X.cx("flex w-full max-w-[350px] flex-col",Yi({size:"sm"})),children:e})})]})});Na.displayName="FieldSettingsPopover";const xa=o.memo(l=>{const{parentPath:e,fieldIndex:n,field:t}=l,s=vi(),{disableRequiredFields:r}=o.use(ae),[d,f]=o.useState(void 0);pi.useActiveEffect(V=>{f(void 0);const S=t.image;if(S){if(!(S instanceof Promise)){f(S);return}S.then(I=>{V()&&f(I)})}},[t.image]);const h=o.useCallback(()=>{t.setOptions({image:void 0})},[t]),[u,p]=o.useMemo(()=>{const V=[],S=[],I=ba(t.type,`${e}.${n}`)??[];for(const T of I)T.showDirectly?V.push(T.field):S.push(T.field);return[V,S]},[t,e,n]),m=wi(u),g=wi(p),C=p.length>0,y=o.useCallback(()=>{d&&s(()=>({file:d}))},[s,d]),w=o.useCallback(V=>{t.setOptions({required:!!V})},[t]),F=o.useCallback(V=>{t.setOptions({label:V.target.value})},[t]),z=o.useCallback(V=>{t.setOptions({description:V.target.value})},[t]),{icon:q,name:x}=L[t.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:q}),x]}),!r&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(a.Checkbox.Root,{checked:t.required,onCheckedChange:w,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"})]})]}),C&&i.jsx(Na,{popoverInputs:g,align:"end"})]}),d&&i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx(Ve,{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",file:d,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:t.label??"",onChange:F,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a field description (optional)",value:t.description??"",onChange:z,maxLength:1e3,resize:"vertical",size:"md"})]}),u.length>0&&i.jsx("div",{className:X.cx("w-full",Yi({size:"sm"})),children:m})]})});xa.displayName="FieldBuilder";const Lt=o.memo(l=>{const{field:e,fieldSection:n,fieldIndex:t,sectionIndex:s}=l,r=o.useRef(null),d=`fields.${s}.fields`,f=o.useCallback(w=>{n.addField(Ri(w),t+1)},[t,n]),h=o.useCallback(()=>{n.addField(e.duplicate(b.v4()))},[e,n]),u=o.useCallback(w=>{const F=w==="up"?s-1:s+1;n.moveField(t,F)},[n,t,s]),p=o.useCallback(w=>{const{files:F}=w.target;if(!F||F.length!==1)return;const z=F.item(0);z&&e.setOptions({image:z})},[e]),m=o.useCallback(()=>{u("up")},[u]),g=o.useCallback(()=>{u("down")},[u]),C=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(xa,{fieldIndex:t,field:e,parentPath:d}),i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-0.5",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(Qi,{onSelectFieldType:f,size:"sm",children:i.jsx(a.IconButton,{type:"button",children:i.jsx(a.LuIcon,{icon:Q})})}),i.jsx(a.IconButton,{type:"button",onClick:m,children:i.jsx(a.LuIcon,{icon:yi})}),i.jsx(a.IconButton,{type:"button",onClick:g,children:i.jsx(a.LuIcon,{icon:Xt})}),i.jsx(a.IconButton,{type:"button",onClick:h,children:i.jsx(a.LuIcon,{icon:it})}),i.jsx(a.IconButton,{type:"button",onClick:C,children:i.jsx(a.LuIcon,{icon:Kt})}),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})]})});Lt.displayName="FieldBuilderWithActions";const Bt=o.memo(l=>{const{children:e,variant:n,size:t,accentColor:s,fields:r,onSelectField:d,onSelectAllFields:f,...h}=l,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:t,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(Ia,{field:p,onSelectField:d},p.id))]})})]})});Bt.displayName="FieldDropdownMenu";const Ia=o.memo(l=>{const{field:e,onSelectField:n}=l,t=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(a.Menu.Item,{onSelect:t,children:[i.jsx(a.LuIcon,{icon:L[e.type].icon}),e.label||$]})});Ia.displayName="FieldDropdownMenuItem";const Ma=o.memo(l=>{const{children:e,variant:n,size:t,accentColor:s,fieldSections:r,onSelectFieldSection:d,...f}=l;return i.jsxs(a.Menu.Root,{...f,children:[i.jsx(a.Menu.ClickTrigger,{children:e}),i.jsx(a.Menu.Content,{variant:n,size:t,accentColor:s,children:r.map(h=>i.jsx(qa,{fieldSection:h,onSelectFieldSection:d},h.id))})]})});Ma.displayName="FieldSectionDropdownMenu";const qa=o.memo(l=>{const{fieldSection:e,onSelectFieldSection:n}=l,t=o.useCallback(()=>{n(e)},[e,n]);return i.jsxs(a.Menu.Item,{onSelect:t,children:[i.jsx(a.LuIcon,{icon:Zt}),e.label||xi]})});qa.displayName="FieldSectionDropdownMenuItem";const Oa=o.memo(l=>{const{id:e,sourceX:n,sourceY:t,targetX:s,targetY:r,style:d,markerEnd:f,data:h}=l,{targetSection:u,sourceSection:p,layoutDirection:m}=h,g=o.useMemo(()=>p.getConditions(u.id),[p,u.id]),C=o.useCallback(()=>{p.removeConditional(u.id)},[p,u.id]),y=o.useCallback(S=>{p.addCondition(u.id,ui(S))},[p,u.id]),w=o.useCallback(S=>{p.addConditions(u.id,S.map(ui))},[p,u.id]),F=o.useCallback((S,I)=>{p.replaceCondition(u.id,S,I)},[p,u.id]),z=o.useCallback(S=>{p.removeCondition(u.id,S)},[p,u.id]),[q,x,V]=E.getBezierPath({sourceX:n,sourceY:t,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:q,style:d,markerEnd:f,labelX:x,labelY:V}),i.jsx(E.EdgeLabelRenderer,{children:i.jsxs(a.Card,{size:"xs",variant:"surface",className:"nodrag nopan bg-(--base-2)! 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(${x}px, ${V}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||xi}),i.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[i.jsx(Bt,{size:"sm",fields:p.fields,onSelectField:y,onSelectAllFields:w,children:i.jsx(a.IconButton,{"aria-label":"Add condition",type:"button",variant:"surface",size:"xs",accentColor:"base",children:i.jsx(a.LuIcon,{icon:Q})})}),i.jsxs(a.Tooltip.Root,{children:[i.jsx(a.Tooltip.Trigger,{asChild:!0,children:i.jsx(a.IconButton,{"aria-label":"Remove conditional logic",type:"button",variant:"surface",size:"xs",accentColor:"base",color:"danger",onClick:C,children:i.jsx(a.LuIcon,{icon:se})})}),i.jsx(a.Tooltip.Content,{size:"sm",children:"Remove conditional logic"})]})]})]}),g.length>0&&i.jsx("div",{className:"flex h-max w-full flex-col flex-wrap gap-1",children:g.map(S=>i.jsx(xt,{condition:S,onRemove:z,onReplace:F},S.id))})]})})]})});Oa.displayName="FieldSectionConditionEdgeComponent";const Ta=o.memo(l=>{const{data:e,selected:n}=l,{fieldSection:t,index:s,layoutDirection:r}=e,{fieldSchema:d}=o.use(ae),f=o.useCallback(()=>{d.removeFieldSection(t)},[d,t]),h=o.useCallback(C=>{t.addField(Ri(C))},[t]),u=o.useCallback(()=>{const C=new W({id:b.v4(),fields:[]});d.addFieldSection(C),t.addConditional(C.id)},[d,t]),p=o.useCallback(()=>{d.addFieldSection(t.duplicate(b.v4()))},[d,t]),m=o.useCallback(C=>{t.setOptions({label:C.target.value})},[t]),g=o.useCallback(C=>{t.setOptions({description:C.target.value})},[t]);return i.jsxs(a.Card,{variant:"surface",className:"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:t.label??"",onChange:m,maxLength:200})}),i.jsx(a.TextArea,{className:"field-sizing-content",placeholder:"Enter a section description (optional)",value:t.description??"",onChange:g,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(Qi,{onSelectFieldType:h,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",accentColor:"base",children:[i.jsx(a.LuIcon,{icon:Q})," Add field"]})})]}),i.jsx("div",{className:"flex flex-col gap-3",children:t.fields.map((C,y)=>i.jsx(Lt,{field:C,fieldSection:t,fieldIndex:y,sectionIndex:s},C.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:"bg-(--base-2) flex flex-col items-center gap-1 p-1",size:"xs",onClick:a.stopPropagation,children:i.jsxs(a.ButtonGroup,{className:"flex flex-col gap-2",variant:"surface",size:"xs",accentColor:"base",children:[i.jsx(a.IconButton,{type:"button",onClick:u,children:i.jsx(a.LuIcon,{icon:ds})}),i.jsx(a.IconButton,{type:"button",onClick:p,children:i.jsx(a.LuIcon,{icon:it})}),i.jsx(a.IconButton,{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})]})});Ta.displayName="CustomNode";const Bs={fieldSection:Ta},As={fieldSectionCondition:Oa},Ds=(l,e,n)=>{const t=new _t.graphlib.Graph().setDefaultEdgeLabel(()=>({}));return t.setGraph({rankdir:n,nodesep:200,edgesep:500,ranksep:500}),e.forEach(s=>t.setEdge(s.source,s.target,{width:500,height:200,labelpos:"c"})),l.forEach(s=>t.setNode(s.id,{...s,width:s.measured?.width??0,height:s.measured?.height??0})),_t.layout(t),[l.map(s=>{const r=t.node(s.id),d=r.x-(s.measured?.width??0)/2,f=r.y-(s.measured?.height??0)/2;return{...s,position:{x:d,y:f}}}),e]},_s={hideAttribution:!0},Ea=o.memo(()=>{const{errors:l}=Y.useFormState(),{handleSubmit:e}=Y.useFormContext(),{onSave:n,onCancel:t}=o.use(ae),{fieldSchema:s}=o.use(ae),r=o.useRef(null),[d,f]=o.useState(),[h,u]=o.useState("TB");o.useLayoutEffect(()=>{r.current&&r.current.classList.remove("light")},[]);const p=o.useMemo(()=>s.fieldSections.map((B,J)=>({id:B.id,position:{x:0,y:0},data:{index:J,fieldSection:B,layoutDirection:h},draggable:!0,type:"fieldSection"})),[s.fieldSections,h]),m=o.useMemo(()=>{const B=[],J={};for(const K of s.fieldSections)J[K.id]=K;for(const K of s.fieldSections){const hi=K.conditions;for(const[fi,Gs]of Object.entries(hi))B.push({id:`${K.id}-${fi}`,source:K.id,target:fi,data:{targetSection:J[fi],sourceSection:K,layoutDirection:h},animated:Gs.length>0,markerEnd:E.MarkerType.Arrow,style:{strokeWidth:2,stroke:"var(--base-a8)"},type:"fieldSectionCondition"})}return B},[s.fieldSections,h]),[g,C,y]=E.useNodesState(p),[w,F,z]=E.useEdgesState(m);o.useEffect(()=>{C(p)},[p,C]),o.useEffect(()=>{F(m)},[m,F]);const[q,x]=o.useMemo(()=>Ds(g,w,h),[w,h,g]),V=o.useCallback(()=>{s.addFieldSection(new W({id:b.v4(),fields:[]}))},[s]),S=o.useCallback(B=>{const{source:J,target:K}=B,hi=s.fieldSections.find(({id:fi})=>fi===J);hi.setOptions({conditions:{...hi.conditions,[K]:[]}})},[s.fieldSections]),I=o.useCallback(B=>{const J=s.getSectionDependencyGraph();return!Dt.willCreateCycle(J,B.source,B.target)},[s]),T=o.useCallback(()=>{d?.zoomOut()},[d]),D=o.useCallback(()=>{d?.zoomIn()},[d]),Z=o.useCallback(()=>{d?.fitView()},[d]);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:q,onNodesChange:y,edges:x,onEdgesChange:z,nodeTypes:Bs,edgeTypes:As,onConnect:S,attributionPosition:"bottom-left",fitView:!0,minZoom:0,isValidConnection:I,proOptions:_s}),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:V,children:[i.jsx(a.LuIcon,{icon:Q})," 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:Ra})}),i.jsx(a.ToggleGroup.IconItem,{className:"rounded-t-none",value:"TB",type:"button",children:i.jsx(a.LuIcon,{icon:Qa})})]}),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:D,type:"button",children:i.jsx(a.LuIcon,{icon:Q})}),i.jsx(a.IconButton,{onClick:T,radius:"none",type:"button",children:i.jsx(a.LuIcon,{icon:Ci})}),i.jsx(a.IconButton,{className:"rounded-t-none",onClick:Z,type:"button",children:i.jsx(a.LuIcon,{icon:ws})})]})]}),i.jsx(E.Panel,{position:"bottom-right",children:i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:"sm",children:[t&&i.jsx(a.Button,{type:"button",variant:"soft",accentColor:"base",onClick:t,children:"Cancel"}),i.jsx(a.Button,{type:"submit",variant:"surface",children:"Save"})]})})]}),!!l.fields?.message&&i.jsx(a.Text,{size:"xs",accentColor:"danger",children:l.fields.message})]})});Ea.displayName="FormBuilderFlowBuilder";const $s=(l,e,n={})=>{const{conditions:t=!1}=n,s=l.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,d=e.fields.map(h=>{const u=b.v4();return r.set(h.id,u),{...h,id:u}}),f={};if(t)for(const[h,u]of Object.entries(e.conditions??{})){const p=l.get(h);if(!p)continue;const m=u.map(g=>{const C=r.get(g.field);if(!C)throw new Error(`Serialized condition referencing undefined field with id: ${g.field}`);return{...g,field:C}});f[p]=m}return{...e,id:s,conditions:f,fields:d}},Ps=(l,e={})=>{const n=new Map(l.map(t=>[t.id,b.v4()]));return l.map(t=>$s(n,t,e))},At=(l,e)=>{const n={},t=l.filter(s=>s instanceof W);for(const s of l)if(s instanceof W){const r=t.filter(f=>s.id in f.conditions);if(r.length>0&&!r.some(f=>{const h=f.getConditions(s.id);return new Oi(h).applyConditions(e)}))continue;const d=s.getErrors(e);Object.assign(n,d)}else{if(!(s instanceof M))throw new Error("Invalid field type");const r=s.id,d=s.getError(Pt(e,r));d&&Ja(n,r,d)}return n},ks=async l=>{const e={};for(const n of l){const{fields:t}=n;for(const s of t)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 js(l){const e={};for(const[n,t]of Object.entries(l))e[n]=await Promise.all(t);return e}class Fe extends Re{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 Fe(Zi(e))}static fromConfig(e){return new Fe(oa(e))}static serializeConfig(e){return pa(e)}static deserializeConfig(e){return ua(e)}static reseedFieldSections(e,n){return Ps(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 t=[...this.fieldSections];t.splice(n??this.fieldSections.length,0,e),this.fieldSections=this.initFields(t),this.notify(this)}removeFieldSection(e){const n=this.fieldSections.filter(t=>t.id!==e.id);for(const t of n)t.removeConditional(e.id);this.fieldSections=this.initFields(n),this.notify(this)}moveFieldSection(e,n){const t=[...this.fieldSections],[s]=t.splice(e,1);t.splice(n,0,s),this.fieldSections=this.initFields(t),this.notify(this)}getSectionDependencyGraph(){const e=new Ua.DirectedGraph({type:"directed"});for(const n of this.fieldSections)for(const t of Object.keys(n.conditions))e.mergeEdge(n.id,t);return e}getDependenciesOfSection(e){const n=this.getSectionDependencyGraph(),t=new Map(this.fieldSections.map(r=>[r.id,r])),s=[];return Ga.bfsFromNode(n,e,(r,d,f)=>{s.push(t.get(r))},{mode:"in"}),s}cleanValues(e){return Xi(this.getFields(),e)}cleanSerializedValues(e){return Ot(this.getFields(),e)}deserializeValues(e,n){return ma(this.getFields(),e,n)}serializeValues(e,n){return ga(this.getFields(),e,n)}initializeValues(e){return va(this.getFields(),e)}validateValues(e){return At(this.getFieldSections(),e)}areValuesValid(e){return Object.keys(this.validateValues(e)).length===0}deserializeConditions(e){return Wi(this.getFields(),e)}cleanConditions(e){return Nt(this.getFields(),e)}serializeConditions(e){return la(this.getFields(),e)}cleanSerializedConditions(e){return bt(this.getFields(),e)}changedFieldValues(e,n){return wa(this.getFields(),e,n)}unchangedFieldValues(e,n){return Fa(this.getFields(),e,n)}areValuesEqual(e,n){return Tt(this.getFields(),e,n)}areValuesBlank(e){return za(this.getFields(),e)}blankValues(){return Et(this.getFields())}extractFilesAndPromisesFromFieldValues(e){return Ca(this.getFields(),e)}insertFilesAndPromisesToFieldValues(e,n){return ya(this.getFields(),e,n)}}const La=o.memo(l=>{const{sourceFieldSection:e,targetFieldSection:n}=l,t=o.useMemo(()=>e.getConditions(n.id),[e,n.id]),s=o.useCallback(()=>{e.removeConditional(n.id)},[e,n.id]),r=o.useCallback(u=>{e.addCondition(n.id,ui(u))},[e,n.id]),d=o.useCallback(u=>{e.addConditions(n.id,u.map(ui))},[e,n.id]),f=o.useCallback((u,p)=>{e.replaceCondition(n.id,u,p)},[e,n.id]),h=o.useCallback(u=>{e.removeCondition(n.id,u)},[e,n.id]);return i.jsxs(a.Card,{className:"flex flex-col gap-2",size:"sm",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:Zt}),e.label??xi]}),i.jsx(a.IconButton,{type:"button",onClick:s,variant:"ghost",children:i.jsx(a.LuIcon,{icon:se})})]}),i.jsxs("div",{className:"flex h-max w-full flex-wrap gap-2",children:[t.map(u=>i.jsx(xt,{condition:u,onRemove:h,onReplace:f},u.id)),i.jsx(Bt,{fields:e.fields,onSelectField:r,onSelectAllFields:d,align:"start",size:"sm",children:i.jsx(a.IconButton,{type:"button",size:"sm",variant:"soft",accentColor:"base",children:i.jsx(a.LuIcon,{icon:Q})})})]})]})});La.displayName="FieldSectionConditionalItem";const Ba=o.memo(l=>{const{fieldSection:e}=l,{fieldSchema:n}=o.use(ae),t=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]),d=o.useCallback(h=>{e.setOptions({description:h.target.value})},[e]),f=o.useMemo(()=>{const h=n.getSectionDependencyGraph();return n.fieldSections.filter(u=>!Dt.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:d,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(Ma,{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:Q}),"Add condition"]})})]}),t.map(h=>i.jsx(La,{sourceFieldSection:h,targetFieldSection:e},h.id))]}),i.jsx(a.Separator,{size:"full"})]})});Ba.displayName="FieldSectionBuilder";const Aa=o.memo(l=>{const{fieldSection:e,sectionIndex:n}=l,{fieldSchema:t}=o.use(ae),s=a.useAlertDialog(),r=o.useCallback(()=>{t.removeFieldSection(e)},[t,e]),d=o.useCallback(w=>{const F=w==="up"?n-1:n+1;t.moveFieldSection(n,F)},[t,n]),f=o.useCallback(()=>{t.addFieldSection(e.duplicate(b.v4()))},[t,e]),h=o.useCallback(w=>{e.addField(Ri(w))},[e]),u=o.useCallback(()=>{d("up")},[d]),p=o.useCallback(()=>{d("down")},[d]),m=o.useCallback(async()=>{const w=[e.serialize()],F=Fe.reseedFieldSections(w,{conditions:!1}),z=JSON.stringify(F);await navigator.clipboard.writeText(z),a.toast.success({title:"Section copied"})},[e]),g=o.useCallback(async()=>{const F=t.getDependenciesOfSection(e.id).map(x=>x.serialize()),z=Fe.reseedFieldSections(F,{conditions:!0}),q=JSON.stringify(z);await navigator.clipboard.writeText(q),a.toast.success({title:"Section copied"})},[e,t]),C=o.useCallback(async()=>{const w=t.getDependenciesOfSection(e.id),F=w.length>1,z=w.length-1;F?s({title:"Copy section dependencies?",description:`This section has ${z} dependent section${z>1?"s":""} that will also be copied to maintain the conditions. Do you want to include these dependencies?`,action:"Include",onAction:g,cancel:"Dont include",onCancel:m}):m()},[e,t,s,g,m]),y=o.useCallback(async()=>{let w="";try{w=await navigator.clipboard.readText()}catch{a.toast.error({title:"Paste failed",description:"Unable to read clipboard contents."});return}const F=w.trim();if(!F){a.toast.error({title:"Paste failed",description:"Clipboard is empty."});return}try{const z=JSON.parse(F),q=$t.JSONFieldSectionSchema.array().parse(z),x=Zi(q);if(x.length===0){a.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[V,S]of x.entries())t.addFieldSection(S,n+1+V);a.toast.success({title:"Sections pasted",description:"Serialized JSON imported successfully."})}catch(z){console.error(z),a.toast.error({title:"Invalid JSON",description:"Check the JSON and try again."})}},[t,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(Ba,{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(Qi,{onSelectFieldType:h,size:"sm",children:i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",children:[i.jsx(a.LuIcon,{icon:Q})," Add field"]})})]}),e.fields.map((w,F)=>i.jsx(Lt,{field:w,fieldSection:e,fieldIndex:F,sectionIndex:n},w.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,children:i.jsx(a.LuIcon,{icon:yi})}),i.jsx(a.IconButton,{type:"button",onClick:p,children:i.jsx(a.LuIcon,{icon:Xt})}),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:Wt})})}),i.jsxs(a.Menu.Content,{size:"sm",children:[i.jsxs(a.Menu.Item,{onSelect:f,children:[i.jsx(a.LuIcon,{icon:it}),"Duplicate section"]}),i.jsxs(a.Menu.Item,{onSelect:C,children:[i.jsx(a.LuIcon,{icon:Jt}),"Copy JSON"]}),i.jsxs(a.Menu.Item,{onSelect:y,children:[i.jsx(a.LuIcon,{icon:Ht}),"Paste JSON"]}),i.jsxs(a.Menu.Item,{onSelect:r,children:[i.jsx(a.LuIcon,{icon:se}),"Delete section"]})]})]})]})]})});Aa.displayName="FieldSectionWithActions";const Da=o.memo(()=>{const{handleSubmit:l}=Y.useFormContext(),{errors:e}=Y.useFormState(),{onSave:n,onCancel:t}=o.use(ae),{fieldSchema:s}=o.use(ae),r=o.useCallback(()=>{s.addFieldSection(new W({id:b.v4(),fields:[]}))},[s]),d=o.useCallback(async()=>{try{const h=s.serialize(),u=Fe.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=$t.JSONFieldSectionSchema.array().parse(p),g=Zi(m);if(g.length===0){a.toast.error({title:"Paste failed",description:"No valid sections found in the JSON."});return}for(const[C,y]of g.entries())s.addFieldSection(y,s.fieldSections.length+C);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:l(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:d,children:[i.jsx(a.LuIcon,{icon:Jt})," Copy JSON"]}),i.jsxs(a.Button,{type:"button",variant:"soft",size:"sm",onClick:f,children:[i.jsx(a.LuIcon,{icon:Ht})," Paste JSON"]})]}),s.fieldSections.map((h,u)=>i.jsx(Aa,{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:Q})," 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:[t&&i.jsx(a.Button,{type:"button",variant:"soft",accentColor:"base",onClick:t,children:"Cancel"}),i.jsx(a.Button,{type:"submit",variant:"surface",children:"Save"})]})]})});Da.displayName="FormBuilderListBuilder";function _a(l){const e=n=>{const t={};for(const[s,r]of Object.entries(n))typeof r=="string"?t[s]={type:"validate",message:r}:t[s]=e(r);return t};return e(l)}const $a=o.memo(o.forwardRef((l,e)=>{const{disabled:n=!1,fieldSchema:t,values:s={},onValuesChange:r,onSubmit:d,submitText:f="Submit",hideSubmit:h=!1,cancelText:u,onCancel:p,hideCancel:m=!1,className:g,submitButtonProps:C,cancelButtonProps:y,cancelIcon:w,submitIcon:F,size:z="md"}=l,q=o.useMemo(()=>t.initializeValues(s),[t,s]),x=o.useCallback(B=>{d?.(B)},[d]),V=Y.useForm({values:q,mode:"onBlur",criteriaMode:"all",disabled:n,resolver:B=>{const J=t.validateValues(B),K=_a(J);return Object.keys(J).length>0?{values:{},errors:K}:{values:B,errors:{}}}}),S=o.useCallback(B=>{r?.(B)},[r]);o.useEffect(()=>{const{unsubscribe:B}=V.watch((J,{type:K})=>{K==="change"&&S(J)});return()=>{B()}},[V,S]);const I=nl(t.getFieldSections()),T=o.useMemo(()=>({fieldSchema:t,size:z}),[t,z]),D=!m&&!!p,Z=!h;return i.jsx(Y.FormProvider,{...V,children:i.jsx(A,{value:T,children:i.jsxs("form",{ref:e,className:X.cx(g,"flex flex-col gap-4"),onSubmit:V.handleSubmit(x),children:[i.jsx("div",{className:Ls({size:z}),children:I}),!n&&(D||Z)?i.jsxs(a.ButtonGroup,{className:"flex items-center justify-end gap-2",size:z,children:[D?i.jsxs(a.Button,{accentColor:"base",type:"button",variant:"soft",onClick:p,...y,children:[i.jsx(a.LuIcon,{icon:w??ne}),u]}):null,Z?i.jsxs(a.Button,{type:"submit",accentColor:"primary",variant:"surface",...C,children:[i.jsx(a.LuIcon,{icon:F??H}),f]}):null]}):null]})})})})),Pa=o.memo(()=>{const{fieldSchema:l}=o.use(ae);return i.jsx($a,{fieldSchema:l,disabled:!1})});Pa.displayName="FormBuilderPreview";const ka=o.memo(l=>{const{children:e,initialFields:n,onSave:t,onCancel:s,disableRequiredFields:r=!1}=l,d=o.useCallback(y=>{const w={};(!y.fields||y.fields.length===0)&&(w.fields="At least one field is required.");const F=[];for(const[x,V]of y.fields.entries())for(const[S,I]of V.fields.entries()){const T=ba(I.type,`fields.${x}.fields.${S}`)?.map(({field:D})=>D)??[];F.push(...T)}const z={};for(const x of F)z[x.id]=Pt(y,x.id);const q=At(F,z);return Object.keys(q).length>0&&(w.fields=q.fields),Object.keys(w).length>0&&a.toast.error({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),w},[]),f=o.useMemo(()=>({fields:n??[]}),[n]),h=Y.useForm({values:f,mode:"onSubmit",criteriaMode:"all",reValidateMode:"onSubmit",resolver:y=>{const w=d(y),F=_a(w);return Object.keys(w).length>0?{values:{},errors:F}:{values:y,errors:{}}}}),u=o.useCallback(y=>{h.setValue("fields",y.config())},[h]),p=Y.useWatch({control:h.control,compute:y=>y.fields}),m=o.useMemo(()=>{const y=Fe.fromConfig(p);return y.observe(u),y},[p,u]),g=o.useMemo(()=>({fieldSchema:m,disableRequiredFields:r,onSave:t,onCancel:s}),[r,t,s,m]),C=o.useMemo(()=>({fieldSchema:m,size:"sm"}),[m]);return i.jsx(ae,{value:g,children:i.jsx(A,{value:C,children:i.jsx(Y.FormProvider,{...h,children:e})})})});ka.displayName="FormBuilderRoot";const Us={Root:ka,FlowBuilder:Ea,ListBuilder:Da,Preview:Pa};c.BaseCondition=Al,c.BaseField=M,c.BaseFieldCondition=v,c.BaseFormElement=ze,c.BaseOptionsField=R,c.BaseStringField=Se,c.BooleanField=de,c.BooleanFieldConditionCell=Pl,c.BooleanFieldEqualsCondition=Be,c.BooleanFieldInput=dt,c.BooleanFieldNotEqualsCondition=tn,c.CheckboxListField=ie,c.CheckboxListFieldConditionCell=kl,c.CheckboxListFieldEqualsCondition=Ae,c.CheckboxListFieldEveryCondition=an,c.CheckboxListFieldNoneCondition=rn,c.CheckboxListFieldNotEqualsCondition=ln,c.CheckboxListFieldSomeCondition=sn,c.ConditionManager=Oi,c.DateField=be,c.DateFieldAfterCondition=cn,c.DateFieldBeforeCondition=dn,c.DateFieldConditionCell=jl,c.DateFieldEqualsCondition=De,c.DateFieldInCondition=un,c.DateFieldInput=ct,c.DateFieldNotEqualsCondition=on,c.DateFieldNotInCondition=hn,c.FIELD_TYPES=Ll,c.FieldConditionCell=xt,c.FieldSchema=Fe,c.FieldSection=W,c.FieldTypeGroup=O,c.FieldTypeToClsMapping=Ee,c.FieldsRenderer=$a,c.FileCard=at,c.FormBuilder=Us,c.ImageCapturer=ht,c.ImageCapturerProvider=ul,c.ImageCard=ft,c.ImageFile=Ve,c.ImageViewer=rt,c.ImageViewerProvider=el,c.InputWithLabel=_,c.MultiSelectField=te,c.MultiSelectFieldConditionCell=Ul,c.MultiSelectFieldEqualsCondition=_e,c.MultiSelectFieldEveryCondition=pn,c.MultiSelectFieldNoneCondition=mn,c.MultiSelectFieldNotEqualsCondition=fn,c.MultiSelectFieldSomeCondition=gn,c.MultiStringField=re,c.MultiStringFieldConditionCell=Gl,c.MultiStringFieldEqualsCondition=$e,c.MultiStringFieldEveryCondition=yn,c.MultiStringFieldNoneCondition=wn,c.MultiStringFieldNotEqualsCondition=Cn,c.MultiStringFieldSomeCondition=vn,c.NumberField=G,c.NumberFieldConditionCell=Jl,c.NumberFieldEqualsCondition=Pe,c.NumberFieldGreaterThanCondition=Sn,c.NumberFieldGreaterThanOrEqualsCondition=bn,c.NumberFieldInRangeCondition=Nn,c.NumberFieldLessThanCondition=zn,c.NumberFieldLessThanOrEqualsCondition=Vn,c.NumberFieldNotEqualsCondition=Fn,c.NumberFieldNotInRangeCondition=xn,c.OTPField=ce,c.OTPFieldConditionCell=Hl,c.OTPFieldEqualsCondition=ke,c.OTPFieldExcludesCondition=qn,c.OTPFieldIncludesCondition=Mn,c.OTPFieldNotEqualsCondition=In,c.Observable=Re,c.PassFailField=he,c.PassFailFieldConditionCell=Wl,c.PassFailFieldEqualsCondition=je,c.PassFailFieldExcludesCondition=En,c.PassFailFieldIncludesCondition=Tn,c.PassFailFieldNotEqualsCondition=On,c.RadioField=fe,c.RadioFieldConditionCell=Kl,c.RadioFieldEqualsCondition=Ue,c.RadioFieldExcludesCondition=An,c.RadioFieldIncludesCondition=Bn,c.RadioFieldNotEqualsCondition=Ln,c.RatingField=pe,c.RatingFieldConditionCell=Zl,c.RatingFieldEqualsCondition=Ge,c.RatingFieldGreaterThanCondition=Pn,c.RatingFieldGreaterThanOrEqualsCondition=kn,c.RatingFieldInRangeCondition=jn,c.RatingFieldLessThanCondition=_n,c.RatingFieldLessThanOrEqualsCondition=$n,c.RatingFieldNotEqualsCondition=Dn,c.RatingFieldNotInRangeCondition=Un,c.ScanField=xe,c.ScanFieldConditionCell=Xl,c.ScanFieldEqualsCondition=Je,c.ScanFieldExcludesCondition=Hn,c.ScanFieldIncludesCondition=Jn,c.ScanFieldNotEqualsCondition=Gn,c.Scanner=zi,c.ScannerProvider=Vl,c.SelectField=ge,c.SelectFieldConditionCell=Yl,c.SelectFieldEqualsCondition=He,c.SelectFieldExcludesCondition=Zn,c.SelectFieldIncludesCondition=Kn,c.SelectFieldNotEqualsCondition=Wn,c.StringField=me,c.StringFieldConditionCell=Ql,c.StringFieldEqualsCondition=We,c.StringFieldExcludesCondition=Qn,c.StringFieldIncludesCondition=Yn,c.StringFieldNotEqualsCondition=Xn,c.TextField=Ce,c.TextFieldConditionCell=Rl,c.TextFieldEqualsCondition=Ke,c.TextFieldExcludesCondition=ni,c.TextFieldIncludesCondition=ei,c.TextFieldNotEqualsCondition=Rn,c.TimeField=Ie,c.TimeFieldAfterCondition=li,c.TimeFieldBeforeCondition=ti,c.TimeFieldConditionCell=ea,c.TimeFieldControl=Ni,c.TimeFieldEqualsCondition=Ze,c.TimeFieldInCondition=ai,c.TimeFieldInput=Ft,c.TimeFieldNotEqualsCondition=ii,c.TimeFieldNotInCondition=si,c.UNLABELLED_FIELD_LABEL=$,c.UNLABELLED_SECTION_LABEL=xi,c.URLField=Me,c.URLFieldConditionCell=ia,c.URLFieldEqualsCondition=Ye,c.URLFieldExcludesCondition=ci,c.URLFieldIncludesCondition=di,c.URLFieldNotEqualsCondition=oi,c.UTC_OFFSETS=vt,c.UTC_OFFSETS_SET=Il,c.UUIDFile=le,c.UUIDPromise=Ne,c.UploadField=we,c.UploadFieldConditionCell=na,c.UploadFieldEqualsCondition=Xe,c.UploadFieldNotEqualsCondition=ri,c.VideoCard=gt,c.VideoFile=pt,c.areFieldValuesBlank=za,c.areFieldValuesEqual=Tt,c.areFileAndPromiseArraysEqual=Fi,c.areJSONPassFailFieldValuesEqual=yl,c.arePassFieldValuesEqual=Cl,c.awaitFilesAndPromises=js,c.blankFieldValues=Et,c.booleanFieldConditionModifierConfig=Mi,c.changedFieldValues=wa,c.checkboxListFieldConditionModifierConfig=qi,c.cleanConditions=Nt,c.cleanFieldValues=Xi,c.cleanSerializedConditions=bt,c.cleanSerializedFieldValues=Ot,c.createCondition=ui,c.createField=Ri,c.createTime=ye,c.dateFieldConditionModifierConfig=Ti,c.deserializeCondition=ta,c.deserializeConditions=Wi,c.deserializeField=Ki,c.deserializeFieldConfig=Mt,c.deserializeFieldConfigs=da,c.deserializeFieldElement=aa,c.deserializeFieldElementConfig=ca,c.deserializeFieldElementConfigs=ua,c.deserializeFieldElements=Zi,c.deserializeFieldValues=ma,c.deserializeFields=Ts,c.deserializePassFailFieldValue=ml,c.extractFilesAndPromisesFromFieldValues=Ca,c.fieldDataMapping=L,c.fieldElementFromConfig=ra,c.fieldElementsFromConfigs=oa,c.fieldFromConfig=It,c.fieldSpacingCva=Yi,c.fieldTypeGroupDataMapping=Bl,c.fieldsFromConfigs=sa,c.formatTime=bi,c.formatUTCOffset=Si,c.getCurrentUTCOffset=ql,c.getFieldsMapping=Es,c.getImagesFromFields=ks,c.getUTCMinuteOfDay=ve,c.getUTCOffsetMinutes=Ol,c.initializeFieldValues=va,c.insertFilesAndPromisesToFieldValues=ya,c.isFileAndPromiseArray=rl,c.isJSONPassFailFieldValue=fl,c.isPassFailFieldStatus=Ct,c.isPassFailFieldValue=pl,c.isStringArray=Qe,c.isTime=ee,c.isTimeInRange=wt,c.isTimeRange=Ms,c.isUTCOffset=Vi,c.multiSelectFieldConditionModifierConfig=Ei,c.multiStringFieldConditionModifierConfig=Li,c.normalizeFieldOption=ot,c.normalizeFieldOptions=oe,c.numberFieldConditionModifierConfig=Bi,c.otpFieldConditionModifierConfig=Ai,c.parseTime=en,c.passFailFieldConditionModifierConfig=Di,c.passFailFieldStatusMapping=ue,c.passFailFieldStatuses=Te,c.radioFieldConditionModifierConfig=_i,c.ratingFieldConditionModifierConfig=$i,c.scanFieldConditionModifierConfig=Pi,c.selectFieldConditionModifierConfig=ki,c.serializeConditions=la,c.serializeFieldConfig=qt,c.serializeFieldConfigs=ha,c.serializeFieldElementConfig=fa,c.serializeFieldElementConfigs=pa,c.serializeFieldValues=ga,c.serializePassFailFieldValue=gl,c.stringFieldConditionModifierConfig=ji,c.textFieldConditionModifierConfig=Ui,c.timeFieldConditionModifierConfig=Gi,c.unchangedFieldValues=Fa,c.uploadFieldConditionModifierConfig=Ji,c.urlFieldConditionModifierConfig=Hi,c.useConditionManager=qs,c.useFieldInput=P,c.useFieldInputs=wi,c.useFieldSectionInputs=nl,c.useImageCapturer=ut,c.useImageViewer=vi,c.useObjectUrl=st,c.useScanner=bs,c.useScannerContext=Fl,c.validateFieldValues=At,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|