ynotsoft-dynamic-form 1.0.10 → 1.0.12

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/index.cjs CHANGED
@@ -1,21 +1,21 @@
1
- var tt=Object.create;var J=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var nt=(e,r)=>{for(var c in r)J(e,c,{get:r[c],enumerable:!0})},de=(e,r,c,h)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of rt(r))!st.call(e,d)&&d!==c&&J(e,d,{get:()=>r[d],enumerable:!(h=ot(r,d))||h.enumerable});return e};var I=(e,r,c)=>(c=e!=null?tt(at(e)):{},de(r||!e||!e.__esModule?J(c,"default",{value:e,enumerable:!0}):c,e)),lt=e=>de(J({},"__esModule",{value:!0}),e);var Ft={};nt(Ft,{DynamicForm:()=>et,MyButton:()=>ae});module.exports=lt(Ft);var me=require("react/jsx-runtime");function ae({children:e,onClick:r}){return(0,me.jsx)("button",{onClick:r,children:e})}var M=require("react"),Qe=require("react-hot-toast"),ce=I(require("dayjs"),1),No=require("dayjs/locale/de");var pe=I(require("axios"),1),Q=I(require("react-hot-toast"),1);var ue={REACT_API_URL:"http://localhost:5000/"};var be=pe.default.create({baseURL:ue.REACT_API_URL,headers:{"Content-Type":"application/json"}});be.interceptors.response.use(e=>e.data,e=>{var r;if(e.response&&e.response.status===403)return Q.default.error("You are not authorized to access this resource."),Promise.reject("You are not authorized to access this resource.");if(e.response)return Q.default.error("An error occurred"),Promise.reject(((r=e.response.data)==null?void 0:r.message)||"An error occurred");Q.default.error(e.message)});var ge=be;var xe=require("react/jsx-runtime");function it(e){return(0,xe.jsx)("input",{type:"hidden",name:e.name,value:e.value},e.name)}var he=it;var fe=I(require("react-select"),1),ye=I(require("react-select/animated"),1),we=require("react/jsx-runtime");function ct({field:e,formValues:r,handleChange:c,touched:h,errors:d,handleBlur:a}){let l=e.disabled&&e.disabled(r),p=e.options||[],s=(0,ye.default)(),b=r[e.name]||[];return(0,we.jsx)(fe.default,{components:s,isMulti:!0,isDisabled:l,name:e.label,value:b,onChange:v=>c(e.name,v),options:p,placeholder:e.placeholder,closeMenuOnSelect:!1})}var ve=ct;var g=I(require("@radix-ui/react-select"),1),Bt=require("react"),Ne=require("@heroicons/react/20/solid"),w=require("react/jsx-runtime");function dt({field:e,formValues:r,handleChange:c,handleBlur:h}){var p;let d=r[e.name]||"",a=typeof e.disabled=="function"?e.disabled(r):e.disabled,l=e.options||[];return(0,w.jsxs)(g.Root,{value:d,onValueChange:s=>c(e.name,s),disabled:a,children:[(0,w.jsxs)(g.Trigger,{id:e.name,onBlur:()=>h(e.name),className:`inline-flex items-center justify-between w-full px-3 py-2 border rounded-md text-sm transition-all
1
+ var Qe=Object.create;var Q=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var rt=(e,r)=>{for(var c in r)Q(e,c,{get:r[c],enumerable:!0})},me=(e,r,c,g)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of et(r))!ot.call(e,d)&&d!==c&&Q(e,d,{get:()=>r[d],enumerable:!(g=Ze(r,d))||g.enumerable});return e};var I=(e,r,c)=>(c=e!=null?Qe(tt(e)):{},me(r||!e||!e.__esModule?Q(c,"default",{value:e,enumerable:!0}):c,e)),at=e=>me(Q({},"__esModule",{value:!0}),e);var Ct={};rt(Ct,{DynamicForm:()=>ae,DynamicFormComponent:()=>ae,MyButton:()=>Z,MyButtonComponent:()=>Z,default:()=>kt});module.exports=at(Ct);var ue=require("react/jsx-runtime");function Z({children:e,onClick:r}){return(0,ue.jsx)("button",{onClick:r,children:e})}var M=require("react"),Xe=require("react-hot-toast"),de=I(require("dayjs"),1);var be=I(require("axios"),1),ee=I(require("react-hot-toast"),1);var pe={REACT_API_URL:"http://localhost:5000/"};var ge=be.default.create({baseURL:pe.REACT_API_URL,headers:{"Content-Type":"application/json"}});ge.interceptors.response.use(e=>e.data,e=>{var r;if(e.response&&e.response.status===403)return ee.default.error("You are not authorized to access this resource."),Promise.reject("You are not authorized to access this resource.");if(e.response)return ee.default.error("An error occurred"),Promise.reject(((r=e.response.data)==null?void 0:r.message)||"An error occurred");ee.default.error(e.message)});var he=ge;var ye=require("react/jsx-runtime");function st(e){return(0,ye.jsx)("input",{type:"hidden",name:e.name,value:e.value},e.name)}var xe=st;var fe=I(require("react-select"),1),ve=I(require("react-select/animated"),1),Ne=require("react/jsx-runtime");function nt({field:e,formValues:r,handleChange:c,touched:g,errors:d,handleBlur:a}){let l=e.disabled&&e.disabled(r),p=e.options||[],s=(0,ve.default)(),b=r[e.name]||[];return(0,Ne.jsx)(fe.default,{components:s,isMulti:!0,isDisabled:l,name:e.label,value:b,onChange:v=>c(e.name,v),options:p,placeholder:e.placeholder,closeMenuOnSelect:!1})}var we=nt;var h=I(require("@radix-ui/react-select"),1),Et=require("react"),ke=require("@heroicons/react/20/solid"),w=require("react/jsx-runtime");function lt({field:e,formValues:r,handleChange:c,handleBlur:g}){var p;let d=r[e.name]||"",a=typeof e.disabled=="function"?e.disabled(r):e.disabled,l=e.options||[];return(0,w.jsxs)(h.Root,{value:d,onValueChange:s=>c(e.name,s),disabled:a,children:[(0,w.jsxs)(h.Trigger,{id:e.name,onBlur:()=>g(e.name),className:`inline-flex items-center justify-between w-full px-3 py-2 border rounded-md text-sm transition-all
2
2
  ${a?"bg-gray-100 text-gray-500 cursor-not-allowed":"border-gray-300 hover:border-gray-400 focus:ring-2 focus:ring-blue-500"}
3
- `,children:[(0,w.jsx)(g.Value,{placeholder:e.placeholder||`Select ${((p=e.label)==null?void 0:p.toLowerCase())||""}`}),(0,w.jsx)(g.Icon,{className:"ml-2 text-gray-500",children:(0,w.jsx)(Ne.ChevronDownIcon,{className:"w-4 h-4"})})]}),(0,w.jsx)(g.Portal,{children:(0,w.jsxs)(g.Content,{className:"bg-white border border-gray-200 rounded-md shadow-lg z-50 min-w-[var(--radix-select-trigger-width)]",position:"popper",sideOffset:5,children:[(0,w.jsx)(g.ScrollUpButton,{className:"flex items-center justify-center h-6 text-gray-500 bg-gray-50",children:(0,w.jsx)(g.Arrow,{className:"fill-white stroke-gray-200"})}),(0,w.jsxs)(g.Viewport,{className:"p-1",children:[e.groupLabel&&(0,w.jsx)(g.Group,{children:(0,w.jsx)(g.Label,{className:"px-2 py-1 text-xs text-gray-500 uppercase tracking-wide",children:e.groupLabel})}),l.map(s=>(0,w.jsx)(g.Item,{value:s.value,className:`relative flex items-center px-3 py-2 text-sm rounded cursor-pointer select-none
3
+ `,children:[(0,w.jsx)(h.Value,{placeholder:e.placeholder||`Select ${((p=e.label)==null?void 0:p.toLowerCase())||""}`}),(0,w.jsx)(h.Icon,{className:"ml-2 text-gray-500",children:(0,w.jsx)(ke.ChevronDownIcon,{className:"w-4 h-4"})})]}),(0,w.jsx)(h.Portal,{children:(0,w.jsxs)(h.Content,{className:"bg-white border border-gray-200 rounded-md shadow-lg z-50 min-w-[var(--radix-select-trigger-width)]",position:"popper",sideOffset:5,children:[(0,w.jsx)(h.ScrollUpButton,{className:"flex items-center justify-center h-6 text-gray-500 bg-gray-50",children:(0,w.jsx)(h.Arrow,{className:"fill-white stroke-gray-200"})}),(0,w.jsxs)(h.Viewport,{className:"p-1",children:[e.groupLabel&&(0,w.jsx)(h.Group,{children:(0,w.jsx)(h.Label,{className:"px-2 py-1 text-xs text-gray-500 uppercase tracking-wide",children:e.groupLabel})}),l.map(s=>(0,w.jsx)(h.Item,{value:s.value,className:`relative flex items-center px-3 py-2 text-sm rounded cursor-pointer select-none
4
4
  data-[state=checked]:bg-blue-50
5
5
  data-[state=checked]:text-blue-600
6
- `,children:(0,w.jsx)(g.ItemText,{children:s.label})},s.value)),e.separator&&(0,w.jsx)(g.Separator,{className:"my-1 h-px bg-gray-200"})]}),(0,w.jsx)(g.Arrow,{className:"fill-white stroke-gray-200"})]})})]})}var ke=dt;var Tt=require("react"),Se=require("react/jsx-runtime");function mt({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){let l=e.readOnly&&e.disabled;return(0,Se.jsx)("input",{...e.props,type:"email",value:r[e.name]||"",onChange:s=>c(e.name,s.target.value),onBlur:()=>h(e.name),disabled:l,name:e.name,placeholder:e.placeholder,className:`w-full px-3 py-2 border rounded-md ${!1?"border-red-500":"border-gray-300"} ${l?"bg-gray-100 text-gray-500 cursor-not-allowed":""}`})}var Ce=mt;var Ut=require("react"),Fe=require("react/jsx-runtime");function ut({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){console.log("Rendering InputField for",e);let l=e.readOnly||e.disabled;return(0,Fe.jsx)("input",{...e.props,id:e.name,type:e.type||"text",value:r[e.name]||"",onChange:s=>c(e.name,s.target.value),onBlur:()=>h(e.name),disabled:l,name:e.name,placeholder:e.placeholder,min:e.minLength,max:e.maxLength,className:`flex h-10 w-full rounded-md border px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 ${!1?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${l?"bg-gray-50 text-gray-500":"bg-background"}`})}var se=ut;var Ht=require("react"),ne=require("react/jsx-runtime");function pt({field:e,formValues:r}){let c=r[e.name]||e.content||"";return(0,ne.jsx)("div",{className:`mb-4 ${e.fieldClass?e.fieldClass:"col-span-full"}`,id:e.name.toLowerCase()+"_id",children:(0,ne.jsx)("div",{className:"w-full px-3 py-2 border rounded-md overflow-y-auto max-h-40 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:c}})},e.name)}var Re=pt;var D=require("react/jsx-runtime");function bt({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){let l=e.disabled&&e.disabled(r),p=!1;return(0,D.jsxs)("div",{className:"mt-1 space-x-2",children:[(0,D.jsx)("input",{...e.props,id:"id_"+e.name,type:"checkbox",checked:r[e.name]||!1,onChange:s=>c(e.name,s.target.checked),onBlur:()=>h(e.name),disabled:l,className:`rounded border-gray-300 ${l?"opacity-50 cursor-not-allowed":""}`}),(0,D.jsxs)("label",{className:"",htmlFor:"id_"+e.name,children:[e.label,e.required&&(0,D.jsx)("span",{className:"text-red-500",children:"*"})]}),p&&(0,D.jsx)("p",{className:"mt-1 text-sm text-red-500",children:p})]})}var Pe=bt;var _=I(require("@radix-ui/react-popover"),1),Le=require("react"),$e=require("react-day-picker"),Yt=require("react-day-picker/dist/style.css"),S=require("react/jsx-runtime");function gt({field:e,formValues:r,handleChange:c,handleBlur:h}){let[d,a]=(0,Le.useState)(!1),l=r[e.name]??{from:null,to:null},p=b=>c(e.name,b),s=()=>c(e.name,{from:null,to:null});return(0,S.jsx)("div",{children:(0,S.jsxs)(_.Root,{open:d,onOpenChange:a,children:[(0,S.jsx)(_.Trigger,{asChild:!0,children:(0,S.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),onKeyDown:b=>b.key==="Enter"&&a(!0),className:`
6
+ `,children:(0,w.jsx)(h.ItemText,{children:s.label})},s.value)),e.separator&&(0,w.jsx)(h.Separator,{className:"my-1 h-px bg-gray-200"})]}),(0,w.jsx)(h.Arrow,{className:"fill-white stroke-gray-200"})]})})]})}var Ce=lt;var At=require("react"),Fe=require("react/jsx-runtime");function it({field:e,formValues:r,handleChange:c,handleBlur:g,touched:d,errors:a}){let l=e.readOnly&&e.disabled;return(0,Fe.jsx)("input",{...e.props,type:"email",value:r[e.name]||"",onChange:s=>c(e.name,s.target.value),onBlur:()=>g(e.name),disabled:l,name:e.name,placeholder:e.placeholder,className:`w-full px-3 py-2 border rounded-md ${!1?"border-red-500":"border-gray-300"} ${l?"bg-gray-100 text-gray-500 cursor-not-allowed":""}`})}var Se=it;var zt=require("react"),Re=require("react/jsx-runtime");function ct({field:e,formValues:r,handleChange:c,handleBlur:g,touched:d,errors:a}){console.log("Rendering InputField for",e);let l=e.readOnly||e.disabled;return(0,Re.jsx)("input",{...e.props,id:e.name,type:e.type||"text",value:r[e.name]||"",onChange:s=>c(e.name,s.target.value),onBlur:()=>g(e.name),disabled:l,name:e.name,placeholder:e.placeholder,min:e.minLength,max:e.maxLength,className:`flex h-10 w-full rounded-md border px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 ${!1?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${l?"bg-gray-50 text-gray-500":"bg-background"}`})}var ne=ct;var _t=require("react"),le=require("react/jsx-runtime");function dt({field:e,formValues:r}){let c=r[e.name]||e.content||"";return(0,le.jsx)("div",{className:`mb-4 ${e.fieldClass?e.fieldClass:"col-span-full"}`,id:e.name.toLowerCase()+"_id",children:(0,le.jsx)("div",{className:"w-full px-3 py-2 border rounded-md overflow-y-auto max-h-40 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:c}})},e.name)}var $e=dt;var D=require("react/jsx-runtime");function mt({field:e,formValues:r,handleChange:c,handleBlur:g,touched:d,errors:a}){let l=e.disabled&&e.disabled(r),p=!1;return(0,D.jsxs)("div",{className:"mt-1 space-x-2",children:[(0,D.jsx)("input",{...e.props,id:"id_"+e.name,type:"checkbox",checked:r[e.name]||!1,onChange:s=>c(e.name,s.target.checked),onBlur:()=>g(e.name),disabled:l,className:`rounded border-gray-300 ${l?"opacity-50 cursor-not-allowed":""}`}),(0,D.jsxs)("label",{className:"",htmlFor:"id_"+e.name,children:[e.label,e.required&&(0,D.jsx)("span",{className:"text-red-500",children:"*"})]}),p&&(0,D.jsx)("p",{className:"mt-1 text-sm text-red-500",children:p})]})}var Pe=mt;var _=I(require("@radix-ui/react-popover"),1),Le=require("react"),Ie=require("react-day-picker"),Wt=require("react-day-picker/dist/style.css"),S=require("react/jsx-runtime");function ut({field:e,formValues:r,handleChange:c,handleBlur:g}){let[d,a]=(0,Le.useState)(!1),l=r[e.name]??{from:null,to:null},p=b=>c(e.name,b),s=()=>c(e.name,{from:null,to:null});return(0,S.jsx)("div",{children:(0,S.jsxs)(_.Root,{open:d,onOpenChange:a,children:[(0,S.jsx)(_.Trigger,{asChild:!0,children:(0,S.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),onKeyDown:b=>b.key==="Enter"&&a(!0),className:`
7
7
  inline-flex items-center justify-between gap-2
8
8
  w-full h-9 rounded-md border border-gray-300 bg-white
9
9
  px-3 py-2 text-sm font-normal shadow-sm
10
10
  hover:bg-gray-50 hover:text-gray-900
11
11
  focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
12
12
  disabled:cursor-not-allowed disabled:opacity-50
13
- `,children:[l.from?l.to?(0,S.jsxs)("span",{children:[l.from.toLocaleDateString()," \u2013 ",l.to.toLocaleDateString()]}):(0,S.jsx)("span",{children:l.from.toLocaleDateString()}):(0,S.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date range"}),(0,S.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,S.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,S.jsxs)(_.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,S.jsx)($e.DayPicker,{mode:"range",selected:l,onSelect:p,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[(0,S.jsx)("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,S.jsx)("button",{type:"button",onClick:()=>a(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var Ie=gt;var Xt=require("react"),le=require("react-hot-toast");var Ee={apiBaseUrl:process.env.API_BASE_URL||""};var x=require("react/jsx-runtime");function ht({field:e,formValues:r,touched:c,errors:h,fileUploads:d,setFileUploads:a,fileInputRefs:l,handleChange:p,onFieldsChange:s}){let b=c[e.name]&&h[e.name],v=e.type==="multifile",P=d[e.name]||{},C=r[e.name],B=v?C||[]:[C].filter(Boolean),L=e.disabled&&e.disabled(r),O=`px-4 py-2 bg-gray-100 border rounded hover:bg-gray-200 ${L?"cursor-not-allowed":""}`,V=`${Ee.REACT_API_URL}uploads`,A=i=>{if(i===0)return"0 Bytes";let t=1024,o=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(i)/Math.log(t));return parseFloat((i/Math.pow(t,n)).toFixed(2))+" "+o[n]},U=async(i,t)=>{let o=new FormData;o.append("file",i);let n=await fetch(`${V}`,{method:"POST",body:o});if(!n.ok)throw le.toast.error("Upload failed"),new Error("Upload failed");return await n.json()},f=async(i,t)=>{if(!t)return;if(i.maxSize&&t.size>i.maxSize)throw new Error(`File size must not exceed ${A(i.maxSize)}`);let o=await U(t,i.name),n={...r,[i.name]:o};p(i.name,o),s(n)},$=async(i,t)=>{let o=r[i.name]||[];if(o.length+t.length>i.maxFiles)throw new Error(`Maximum ${i.maxFiles} files allowed`);t.forEach(k=>{if(i.maxSize&&k.size>i.maxSize)throw new Error(`Each file must not exceed ${A(i.maxSize)}`)});let n=await Promise.all(t.map(k=>U(k,i.name))),m=[...o,...n];p(i.name,m),s({...r,[i.name]:m})},X=async(i,t)=>{let o=Array.from(t);try{e.type==="file"?await f(e,o[0]):e.type==="multifile"&&await $(e,o),l.current[i]&&(l.current[i].value="")}catch(n){le.toast.error(`Upload failed: ${n.message}`)}},re=async(i,t)=>{let o;e.type==="file"?o="":o=(r[i]||[]).filter(m=>m!==t),p(i,o),s({...r,[i]:o}),l.current[i]&&(l.current[i].value="")};return(0,x.jsxs)("div",{className:`mb-4 ${e.fieldClass||"col-span-full"}`,children:[(0,x.jsxs)("label",{className:"block font-medium mb-1",children:[e.label,e.required&&(0,x.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,x.jsxs)("div",{className:"space-y-2",children:[(0,x.jsxs)("div",{className:"items-center space-x-2",children:[(0,x.jsxs)("button",{type:"button",disabled:L,onClick:()=>l.current[e.name].click(),className:O,children:["Choose ",v?"Files":"File"]}),v&&B.length>0&&(0,x.jsxs)("span",{className:"text-sm text-gray-600",children:[B.length," of ",e.maxFiles," files uploaded"]})]}),(0,x.jsx)("input",{ref:i=>l.current[e.name]=i,type:"file",accept:e.accept,multiple:v,className:"hidden",onChange:i=>X(e.name,i.target.files)}),(0,x.jsx)("div",{className:"space-y-2",children:B.map((i,t)=>{let o=Object.values(P).find(n=>n.file===i);return(0,x.jsxs)("div",{className:"flex items-center justify-between p-2 bg-gray-50 rounded",children:[(0,x.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("span",{className:"text-sm",children:o.fileName}),(0,x.jsxs)("span",{className:"text-xs text-gray-500",children:["(",A(o.fileSize),")"]})]}),!o&&(0,x.jsx)("span",{className:"text-sm",children:i.original_name})]}),(0,x.jsx)("button",{type:"button",onClick:()=>re(e.name,i),className:"text-red-500 hover:text-red-700 ml-3",children:"Remove"})]},i)})}),Object.entries(P).map(([i,t])=>t.status==="uploading"?(0,x.jsxs)("div",{className:"relative pt-1",children:[(0,x.jsxs)("div",{className:"flex items-center justify-between",children:[(0,x.jsxs)("span",{className:"text-xs font-semibold inline-block text-blue-600",children:["Uploading ",i]}),(0,x.jsxs)("span",{className:"text-xs font-semibold inline-block text-blue-600",children:[t.progress,"%"]})]}),(0,x.jsx)("div",{className:"overflow-hidden h-2 mt-1 text-xs flex rounded bg-blue-200",children:(0,x.jsx)("div",{className:"shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-blue-500",style:{width:`${t.progress}%`}})})]},i):null)]}),b&&(0,x.jsx)("p",{className:"mt-1 text-sm text-red-500",children:b})]},e.name)}var ie=ht;var Z=require("react"),j=require("react/jsx-runtime");function xt({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a,charCount:l,setCharCounts:p}){let s=(0,Z.useRef)(null),b=r[e.name]||"",v=typeof e.disabled=="function"?e.disabled(r):e.disabled||e.readOnly,P=d!=null&&d[e.name]&&(a!=null&&a[e.name])?a[e.name]:null,C=()=>{let L=s.current;L&&(L.style.height="auto",L.style.height=`${L.scrollHeight+2}px`)};(0,Z.useEffect)(()=>{C()},[b]);let B=L=>{c(e.name,L.target.value),C(),p&&p(O=>({...O,[e.name]:L.target.value.length}))};return(0,j.jsxs)("div",{className:"space-y-2",children:[(0,j.jsx)("textarea",{...e.props,ref:s,id:e.name,name:e.name,placeholder:e.placeholder||"",value:b,onChange:B,onBlur:()=>h(e.name),disabled:v,maxLength:e.maxLength,rows:e.rows||3,className:`flex w-full rounded-md border px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none overflow-y-auto ${P?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${v?"bg-gray-50 text-gray-500":"bg-background"}`,style:{minHeight:"80px",maxHeight:"400px"}}),(0,j.jsx)("div",{className:"flex justify-between items-center",children:e.maxLength&&!e.readOnly&&(0,j.jsxs)("span",{className:"text-xs text-gray-500",children:[l||0,"/",e.maxLength," characters"]})})]})}var Me=xt;var Be=require("@mui/x-date-pickers"),oo=require("react"),Ae=require("@mui/x-date-pickers/AdapterDayjs"),De=require("@mui/x-date-pickers/DateTimeField"),ee=require("react/jsx-runtime");function ft({field:e,formValues:r,handleChange:c,handleBlur:h,touched:d,errors:a}){return(0,ee.jsx)("div",{children:(0,ee.jsx)(Be.LocalizationProvider,{dateAdapter:Ae.AdapterDayjs,adapterLocale:"aus",children:(0,ee.jsx)(De.DateTimeField,{value:e.value,onChange:l=>c(e.name,l)})})})}var Te=ft;var te=require("@radix-ui/react-separator"),T=require("react/jsx-runtime");function yt({field:e}){return e!=null&&e.label?(0,T.jsxs)("div",{className:"relative flex items-center py-4",children:[(0,T.jsx)(te.Separator,{className:"flex-1 h-px bg-gray-300"}),(0,T.jsx)("span",{className:"px-3 font-medium text-gray-600 bg-white",children:e.label}),(0,T.jsx)(te.Separator,{className:"flex-1 h-px bg-gray-300"})]}):(0,T.jsx)(te.Separator,{className:"my-4 h-px bg-gray-300"})}var ze=yt;var no=require("react"),H=I(require("@radix-ui/react-radio-group"),1),E=require("react/jsx-runtime");function vt({field:e,formValues:r,handleChange:c,handleBlur:h}){let d=r[e.name]||"",a=typeof e.disabled=="function"?e.disabled(r):e.disabled,l=e.options||[],p=e.inline||!1;return(0,E.jsx)(H.Root,{value:d,onValueChange:s=>c(e.name,s),onBlur:()=>h(e.name),disabled:a,className:p?"flex flex-wrap gap-4":"space-y-3","aria-label":e.label||e.name,children:l.map(s=>{let b=typeof s=="object"?s.value:s,v=typeof s=="object"?s.label:s,P=typeof s=="object"?s.description:null,C=`${e.name}-${b}`;return(0,E.jsxs)("div",{className:"relative flex items-start",children:[(0,E.jsx)("div",{className:"flex h-6 items-center",children:(0,E.jsx)(H.Item,{value:b,id:C,disabled:a,className:`
13
+ `,children:[l.from?l.to?(0,S.jsxs)("span",{children:[l.from.toLocaleDateString()," \u2013 ",l.to.toLocaleDateString()]}):(0,S.jsx)("span",{children:l.from.toLocaleDateString()}):(0,S.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date range"}),(0,S.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,S.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,S.jsxs)(_.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,S.jsx)(Ie.DayPicker,{mode:"range",selected:l,onSelect:p,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[(0,S.jsx)("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,S.jsx)("button",{type:"button",onClick:()=>a(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var Ee=ut;var qt=require("react"),ie=require("react-hot-toast");var Me={apiBaseUrl:process.env.API_BASE_URL||""};var x=require("react/jsx-runtime");function pt({field:e,formValues:r,touched:c,errors:g,fileUploads:d,setFileUploads:a,fileInputRefs:l,handleChange:p,onFieldsChange:s}){let b=c[e.name]&&g[e.name],v=e.type==="multifile",$=d[e.name]||{},C=r[e.name],B=v?C||[]:[C].filter(Boolean),P=e.disabled&&e.disabled(r),O=`px-4 py-2 bg-gray-100 border rounded hover:bg-gray-200 ${P?"cursor-not-allowed":""}`,V=`${Me.REACT_API_URL}uploads`,A=i=>{if(i===0)return"0 Bytes";let t=1024,o=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(i)/Math.log(t));return parseFloat((i/Math.pow(t,n)).toFixed(2))+" "+o[n]},U=async(i,t)=>{let o=new FormData;o.append("file",i);let n=await fetch(`${V}`,{method:"POST",body:o});if(!n.ok)throw ie.toast.error("Upload failed"),new Error("Upload failed");return await n.json()},y=async(i,t)=>{if(!t)return;if(i.maxSize&&t.size>i.maxSize)throw new Error(`File size must not exceed ${A(i.maxSize)}`);let o=await U(t,i.name),n={...r,[i.name]:o};p(i.name,o),s(n)},L=async(i,t)=>{let o=r[i.name]||[];if(o.length+t.length>i.maxFiles)throw new Error(`Maximum ${i.maxFiles} files allowed`);t.forEach(k=>{if(i.maxSize&&k.size>i.maxSize)throw new Error(`Each file must not exceed ${A(i.maxSize)}`)});let n=await Promise.all(t.map(k=>U(k,i.name))),m=[...o,...n];p(i.name,m),s({...r,[i.name]:m})},J=async(i,t)=>{let o=Array.from(t);try{e.type==="file"?await y(e,o[0]):e.type==="multifile"&&await L(e,o),l.current[i]&&(l.current[i].value="")}catch(n){ie.toast.error(`Upload failed: ${n.message}`)}},se=async(i,t)=>{let o;e.type==="file"?o="":o=(r[i]||[]).filter(m=>m!==t),p(i,o),s({...r,[i]:o}),l.current[i]&&(l.current[i].value="")};return(0,x.jsxs)("div",{className:`mb-4 ${e.fieldClass||"col-span-full"}`,children:[(0,x.jsxs)("label",{className:"block font-medium mb-1",children:[e.label,e.required&&(0,x.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,x.jsxs)("div",{className:"space-y-2",children:[(0,x.jsxs)("div",{className:"items-center space-x-2",children:[(0,x.jsxs)("button",{type:"button",disabled:P,onClick:()=>l.current[e.name].click(),className:O,children:["Choose ",v?"Files":"File"]}),v&&B.length>0&&(0,x.jsxs)("span",{className:"text-sm text-gray-600",children:[B.length," of ",e.maxFiles," files uploaded"]})]}),(0,x.jsx)("input",{ref:i=>l.current[e.name]=i,type:"file",accept:e.accept,multiple:v,className:"hidden",onChange:i=>J(e.name,i.target.files)}),(0,x.jsx)("div",{className:"space-y-2",children:B.map((i,t)=>{let o=Object.values($).find(n=>n.file===i);return(0,x.jsxs)("div",{className:"flex items-center justify-between p-2 bg-gray-50 rounded",children:[(0,x.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("span",{className:"text-sm",children:o.fileName}),(0,x.jsxs)("span",{className:"text-xs text-gray-500",children:["(",A(o.fileSize),")"]})]}),!o&&(0,x.jsx)("span",{className:"text-sm",children:i.original_name})]}),(0,x.jsx)("button",{type:"button",onClick:()=>se(e.name,i),className:"text-red-500 hover:text-red-700 ml-3",children:"Remove"})]},i)})}),Object.entries($).map(([i,t])=>t.status==="uploading"?(0,x.jsxs)("div",{className:"relative pt-1",children:[(0,x.jsxs)("div",{className:"flex items-center justify-between",children:[(0,x.jsxs)("span",{className:"text-xs font-semibold inline-block text-blue-600",children:["Uploading ",i]}),(0,x.jsxs)("span",{className:"text-xs font-semibold inline-block text-blue-600",children:[t.progress,"%"]})]}),(0,x.jsx)("div",{className:"overflow-hidden h-2 mt-1 text-xs flex rounded bg-blue-200",children:(0,x.jsx)("div",{className:"shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-blue-500",style:{width:`${t.progress}%`}})})]},i):null)]}),b&&(0,x.jsx)("p",{className:"mt-1 text-sm text-red-500",children:b})]},e.name)}var ce=pt;var te=require("react"),H=require("react/jsx-runtime");function bt({field:e,formValues:r,handleChange:c,handleBlur:g,touched:d,errors:a,charCount:l,setCharCounts:p}){let s=(0,te.useRef)(null),b=r[e.name]||"",v=typeof e.disabled=="function"?e.disabled(r):e.disabled||e.readOnly,$=d!=null&&d[e.name]&&(a!=null&&a[e.name])?a[e.name]:null,C=()=>{let P=s.current;P&&(P.style.height="auto",P.style.height=`${P.scrollHeight+2}px`)};(0,te.useEffect)(()=>{C()},[b]);let B=P=>{c(e.name,P.target.value),C(),p&&p(O=>({...O,[e.name]:P.target.value.length}))};return(0,H.jsxs)("div",{className:"space-y-2",children:[(0,H.jsx)("textarea",{...e.props,ref:s,id:e.name,name:e.name,placeholder:e.placeholder||"",value:b,onChange:B,onBlur:()=>g(e.name),disabled:v,maxLength:e.maxLength,rows:e.rows||3,className:`flex w-full rounded-md border px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none overflow-y-auto ${$?"border-red-500 focus-visible:ring-red-500":"border-input focus-visible:ring-blue-500"} ${v?"bg-gray-50 text-gray-500":"bg-background"}`,style:{minHeight:"80px",maxHeight:"400px"}}),(0,H.jsx)("div",{className:"flex justify-between items-center",children:e.maxLength&&!e.readOnly&&(0,H.jsxs)("span",{className:"text-xs text-gray-500",children:[l||0,"/",e.maxLength," characters"]})})]})}var Be=bt;var eo=require("react"),q=require("react/jsx-runtime");function gt({field:e,formValues:r,handleChange:c,handleBlur:g,touched:d,errors:a}){return(0,q.jsxs)("div",{children:[(0,q.jsx)("input",{type:"datetime-local",value:e.value||"",onChange:l=>c(e.name,l.target.value),onBlur:g,className:"border rounded px-3 py-2 w-full",placeholder:"Select date and time"}),(0,q.jsx)("p",{className:"text-sm text-gray-500 mt-1",children:"Note: Install @mui/x-date-pickers for enhanced date picker functionality"})]})}var Ae=gt;var oe=require("@radix-ui/react-separator"),T=require("react/jsx-runtime");function ht({field:e}){return e!=null&&e.label?(0,T.jsxs)("div",{className:"relative flex items-center py-4",children:[(0,T.jsx)(oe.Separator,{className:"flex-1 h-px bg-gray-300"}),(0,T.jsx)("span",{className:"px-3 font-medium text-gray-600 bg-white",children:e.label}),(0,T.jsx)(oe.Separator,{className:"flex-1 h-px bg-gray-300"})]}):(0,T.jsx)(oe.Separator,{className:"my-4 h-px bg-gray-300"})}var De=ht;var ao=require("react"),j=I(require("@radix-ui/react-radio-group"),1),E=require("react/jsx-runtime");function xt({field:e,formValues:r,handleChange:c,handleBlur:g}){let d=r[e.name]||"",a=typeof e.disabled=="function"?e.disabled(r):e.disabled,l=e.options||[],p=e.inline||!1;return(0,E.jsx)(j.Root,{value:d,onValueChange:s=>c(e.name,s),onBlur:()=>g(e.name),disabled:a,className:p?"flex flex-wrap gap-4":"space-y-3","aria-label":e.label||e.name,children:l.map(s=>{let b=typeof s=="object"?s.value:s,v=typeof s=="object"?s.label:s,$=typeof s=="object"?s.description:null,C=`${e.name}-${b}`;return(0,E.jsxs)("div",{className:"relative flex items-start",children:[(0,E.jsx)("div",{className:"flex h-6 items-center",children:(0,E.jsx)(j.Item,{value:b,id:C,disabled:a,className:`
14
14
  relative size-4 rounded-full border transition-all
15
15
  ${a?"border-gray-300 bg-gray-100 cursor-not-allowed":"border-gray-300 bg-white hover:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"}
16
16
  data-[state=checked]:border-blue-600 data-[state=checked]:bg-blue-600
17
- `,children:(0,E.jsx)(H.Indicator,{className:"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-1.5 after:h-1.5 after:rounded-full after:bg-white"})})}),(0,E.jsxs)("div",{className:"ml-3 text-sm",children:[(0,E.jsx)("label",{htmlFor:C,className:`font-medium ${a?"text-gray-500":"text-gray-900 cursor-pointer"}`,children:v}),P&&!p&&(0,E.jsx)("p",{className:`text-sm ${a?"text-gray-400":"text-gray-500"}`,children:P})]})]},b)})})}var Oe=vt;var co=require("react"),q=require("react/jsx-runtime");function wt({field:e}){let r=e.text||e.label||"",c=e.description||"",h=e.size||"lg",d=e.underline||!1,a=e.align||"left",l=e.className||"",p={sm:"text-base font-semibold",md:"text-lg font-semibold",lg:"text-xl font-bold",xl:"text-2xl font-bold","2xl":"text-3xl font-bold","3xl":"text-4xl font-bold","4xl":"text-5xl font-bold"},s={left:"text-left",center:"text-center",right:"text-right"},b=`
18
- ${p[h]||p.lg}
17
+ `,children:(0,E.jsx)(j.Indicator,{className:"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-1.5 after:h-1.5 after:rounded-full after:bg-white"})})}),(0,E.jsxs)("div",{className:"ml-3 text-sm",children:[(0,E.jsx)("label",{htmlFor:C,className:`font-medium ${a?"text-gray-500":"text-gray-900 cursor-pointer"}`,children:v}),$&&!p&&(0,E.jsx)("p",{className:`text-sm ${a?"text-gray-400":"text-gray-500"}`,children:$})]})]},b)})})}var Te=xt;var lo=require("react"),K=require("react/jsx-runtime");function yt({field:e}){let r=e.text||e.label||"",c=e.description||"",g=e.size||"lg",d=e.underline||!1,a=e.align||"left",l=e.className||"",p={sm:"text-base font-semibold",md:"text-lg font-semibold",lg:"text-xl font-bold",xl:"text-2xl font-bold","2xl":"text-3xl font-bold","3xl":"text-4xl font-bold","4xl":"text-5xl font-bold"},s={left:"text-left",center:"text-center",right:"text-right"},b=`
18
+ ${p[g]||p.lg}
19
19
  ${s[a]||s.left}
20
20
  ${d?"border-b-2 border-gray-300 pb-2":""}
21
21
  ${l}
@@ -23,25 +23,25 @@ var tt=Object.create;var J=Object.defineProperty;var ot=Object.getOwnPropertyDes
23
23
  `.trim(),v=`
24
24
  mt-1 text-sm text-gray-600
25
25
  ${s[a]||s.left}
26
- `.trim();return(0,q.jsxs)("div",{className:"my-4",children:[(0,q.jsx)("h2",{className:b,children:r}),c&&(0,q.jsx)("p",{className:v,children:c})]})}var Ue=wt;var G=I(require("@radix-ui/react-popover"),1),_e=require("react"),je=require("react-day-picker"),po=require("react-day-picker/dist/style.css"),F=require("react/jsx-runtime");function Nt({field:e,formValues:r,handleChange:c,handleBlur:h}){let[d,a]=(0,_e.useState)(!1),l=r[e.name]??null,p=b=>c(e.name,b),s=()=>c(e.name,null);return(0,F.jsx)("div",{children:(0,F.jsxs)(G.Root,{open:d,onOpenChange:a,children:[(0,F.jsx)(G.Trigger,{asChild:!0,children:(0,F.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),onKeyDown:b=>b.key==="Enter"&&a(!0),className:`
26
+ `.trim();return(0,K.jsxs)("div",{className:"my-4",children:[(0,K.jsx)("h2",{className:b,children:r}),c&&(0,K.jsx)("p",{className:v,children:c})]})}var ze=yt;var G=I(require("@radix-ui/react-popover"),1),Oe=require("react"),Ue=require("react-day-picker"),mo=require("react-day-picker/dist/style.css"),F=require("react/jsx-runtime");function ft({field:e,formValues:r,handleChange:c,handleBlur:g}){let[d,a]=(0,Oe.useState)(!1),l=r[e.name]??null,p=b=>c(e.name,b),s=()=>c(e.name,null);return(0,F.jsx)("div",{children:(0,F.jsxs)(G.Root,{open:d,onOpenChange:a,children:[(0,F.jsx)(G.Trigger,{asChild:!0,children:(0,F.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),onKeyDown:b=>b.key==="Enter"&&a(!0),className:`
27
27
  inline-flex items-center justify-between gap-2
28
28
  w-full h-9 rounded-md border border-gray-300 bg-white
29
29
  px-3 py-2 text-sm font-normal shadow-sm
30
30
  hover:bg-gray-50 hover:text-gray-900
31
31
  focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
32
32
  disabled:cursor-not-allowed disabled:opacity-50
33
- `,children:[l?(0,F.jsx)("span",{children:l.toLocaleDateString()}):(0,F.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date"}),(0,F.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,F.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,F.jsxs)(G.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,F.jsx)(je.DayPicker,{mode:"single",selected:l,onSelect:p,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),(0,F.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[(0,F.jsx)("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,F.jsx)("button",{type:"button",onClick:()=>a(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var He=Nt;var z=I(require("react"),1),W=I(require("@radix-ui/react-popover"),1),u=require("react/jsx-runtime");function kt({field:e,formValues:r,handleChange:c,handleBlur:h}){let[d,a]=(0,z.useState)(!1),[l,p]=(0,z.useState)("12"),[s,b]=(0,z.useState)("00"),[v,P]=(0,z.useState)("PM"),C=r[e.name]||"";z.default.useEffect(()=>{if(C){let f=C.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);f&&(p(f[1].padStart(2,"0")),b(f[2]),P(f[3].toUpperCase()))}},[C]);let B=()=>{let f=`${l}:${s} ${v}`;c(e.name,f),a(!1)},L=()=>{c(e.name,""),p("12"),b("00"),P("PM")},O=()=>{let f=parseInt(l);p((f%12+1).toString().padStart(2,"0"))},V=()=>{let f=parseInt(l);p((f===1?12:f-1).toString().padStart(2,"0"))},A=()=>{let f=parseInt(s);b(((f+5)%60).toString().padStart(2,"0"))},U=()=>{let f=parseInt(s);b((f===0?55:f-5).toString().padStart(2,"0"))};return(0,u.jsx)("div",{children:(0,u.jsxs)(W.Root,{open:d,onOpenChange:a,children:[(0,u.jsx)(W.Trigger,{asChild:!0,children:(0,u.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),className:`
33
+ `,children:[l?(0,F.jsx)("span",{children:l.toLocaleDateString()}):(0,F.jsx)("span",{className:"text-muted-foreground",children:e.placeholder||"Select date"}),(0,F.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down opacity-70",children:(0,F.jsx)("path",{d:"m6 9 6 6 6-6"})})]})}),(0,F.jsxs)(G.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-0 shadow-md w-auto",children:[(0,F.jsx)(Ue.DayPicker,{mode:"single",selected:l,onSelect:p,showOutsideDays:!0,className:"rounded-md bg-white p-3 text-xs"}),(0,F.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 p-3",children:[(0,F.jsx)("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,F.jsx)("button",{type:"button",onClick:()=>a(!1),className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})]})})}var _e=ft;var z=I(require("react"),1),W=I(require("@radix-ui/react-popover"),1),u=require("react/jsx-runtime");function vt({field:e,formValues:r,handleChange:c,handleBlur:g}){let[d,a]=(0,z.useState)(!1),[l,p]=(0,z.useState)("12"),[s,b]=(0,z.useState)("00"),[v,$]=(0,z.useState)("PM"),C=r[e.name]||"";z.default.useEffect(()=>{if(C){let y=C.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);y&&(p(y[1].padStart(2,"0")),b(y[2]),$(y[3].toUpperCase()))}},[C]);let B=()=>{let y=`${l}:${s} ${v}`;c(e.name,y),a(!1)},P=()=>{c(e.name,""),p("12"),b("00"),$("PM")},O=()=>{let y=parseInt(l);p((y%12+1).toString().padStart(2,"0"))},V=()=>{let y=parseInt(l);p((y===1?12:y-1).toString().padStart(2,"0"))},A=()=>{let y=parseInt(s);b(((y+5)%60).toString().padStart(2,"0"))},U=()=>{let y=parseInt(s);b((y===0?55:y-5).toString().padStart(2,"0"))};return(0,u.jsx)("div",{children:(0,u.jsxs)(W.Root,{open:d,onOpenChange:a,children:[(0,u.jsx)(W.Trigger,{asChild:!0,children:(0,u.jsxs)("button",{type:"button",id:e.name,"aria-haspopup":"dialog","aria-expanded":d,onClick:()=>a(!0),className:`
34
34
  inline-flex items-center justify-between gap-2
35
35
  w-full h-9 rounded-md border border-gray-300 bg-white
36
36
  px-3 py-2 text-sm font-normal shadow-sm
37
37
  hover:bg-gray-50 hover:text-gray-900
38
38
  focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2
39
39
  disabled:cursor-not-allowed disabled:opacity-50
40
- `,children:[C?(0,u.jsx)("span",{children:C}):(0,u.jsx)("span",{className:"text-gray-400",children:e.placeholder||"Select time"}),(0,u.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-clock opacity-70",children:[(0,u.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,u.jsx)("polyline",{points:"12 6 12 12 16 14"})]})]})}),(0,u.jsx)(W.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-4 shadow-md w-64",children:(0,u.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,u.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,u.jsxs)("div",{className:"flex flex-col items-center",children:[(0,u.jsx)("button",{type:"button",onClick:O,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"18 15 12 9 6 15"})})}),(0,u.jsx)("input",{type:"text",value:l,onChange:f=>{let $=f.target.value.replace(/\D/g,"");($===""||parseInt($)>=1&&parseInt($)<=12)&&p($.padStart(2,"0"))},className:"w-14 text-center text-2xl font-semibold border-0 focus:outline-none focus:ring-2 focus:ring-blue-500 rounded py-2",maxLength:"2"}),(0,u.jsx)("button",{type:"button",onClick:V,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),(0,u.jsx)("span",{className:"text-2xl font-semibold",children:":"}),(0,u.jsxs)("div",{className:"flex flex-col items-center",children:[(0,u.jsx)("button",{type:"button",onClick:A,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"18 15 12 9 6 15"})})}),(0,u.jsx)("input",{type:"text",value:s,onChange:f=>{let $=f.target.value.replace(/\D/g,"");($===""||parseInt($)>=0&&parseInt($)<=59)&&b($.padStart(2,"0"))},className:"w-14 text-center text-2xl font-semibold border-0 focus:outline-none focus:ring-2 focus:ring-blue-500 rounded py-2",maxLength:"2"}),(0,u.jsx)("button",{type:"button",onClick:U,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),(0,u.jsxs)("div",{className:"flex flex-col gap-1 ml-2",children:[(0,u.jsx)("button",{type:"button",onClick:()=>P("AM"),className:`
40
+ `,children:[C?(0,u.jsx)("span",{children:C}):(0,u.jsx)("span",{className:"text-gray-400",children:e.placeholder||"Select time"}),(0,u.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-clock opacity-70",children:[(0,u.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,u.jsx)("polyline",{points:"12 6 12 12 16 14"})]})]})}),(0,u.jsx)(W.Content,{align:"start",sideOffset:2,className:"z-50 rounded-md border border-gray-200 bg-white p-4 shadow-md w-64",children:(0,u.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,u.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,u.jsxs)("div",{className:"flex flex-col items-center",children:[(0,u.jsx)("button",{type:"button",onClick:O,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"18 15 12 9 6 15"})})}),(0,u.jsx)("input",{type:"text",value:l,onChange:y=>{let L=y.target.value.replace(/\D/g,"");(L===""||parseInt(L)>=1&&parseInt(L)<=12)&&p(L.padStart(2,"0"))},className:"w-14 text-center text-2xl font-semibold border-0 focus:outline-none focus:ring-2 focus:ring-blue-500 rounded py-2",maxLength:"2"}),(0,u.jsx)("button",{type:"button",onClick:V,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),(0,u.jsx)("span",{className:"text-2xl font-semibold",children:":"}),(0,u.jsxs)("div",{className:"flex flex-col items-center",children:[(0,u.jsx)("button",{type:"button",onClick:A,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"18 15 12 9 6 15"})})}),(0,u.jsx)("input",{type:"text",value:s,onChange:y=>{let L=y.target.value.replace(/\D/g,"");(L===""||parseInt(L)>=0&&parseInt(L)<=59)&&b(L.padStart(2,"0"))},className:"w-14 text-center text-2xl font-semibold border-0 focus:outline-none focus:ring-2 focus:ring-blue-500 rounded py-2",maxLength:"2"}),(0,u.jsx)("button",{type:"button",onClick:U,className:"p-1 hover:bg-gray-100 rounded",children:(0,u.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,u.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),(0,u.jsxs)("div",{className:"flex flex-col gap-1 ml-2",children:[(0,u.jsx)("button",{type:"button",onClick:()=>$("AM"),className:`
41
41
  px-3 py-1 text-sm font-medium rounded
42
42
  ${v==="AM"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}
43
- `,children:"AM"}),(0,u.jsx)("button",{type:"button",onClick:()=>P("PM"),className:`
43
+ `,children:"AM"}),(0,u.jsx)("button",{type:"button",onClick:()=>$("PM"),className:`
44
44
  px-3 py-1 text-sm font-medium rounded
45
45
  ${v==="PM"?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}
46
- `,children:"PM"})]})]}),(0,u.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 pt-3",children:[(0,u.jsx)("button",{type:"button",onClick:L,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,u.jsx)("button",{type:"button",onClick:B,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})})]})})}var Ge=kt;var xo=require("react");var oe=require("@heroicons/react/20/solid"),We=require("@heroicons/react/20/solid"),Ve=require("@heroicons/react/24/outline");var N=require("react/jsx-runtime");function Ye({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-red-50 border border-red-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(oe.XCircleIcon,{"aria-hidden":"true",className:"size-5 text-red-500 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-red-900",children:e})]})})}function qe({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-amber-50 border border-amber-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(Ve.ExclamationCircleIcon,{"aria-hidden":"true",className:"size-5 text-amber-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-amber-900",children:e})]})})}function Ke({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-green-50 border border-green-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(We.CheckCircleIcon,{"aria-hidden":"true",className:"size-5 text-green-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-green-900",children:e})]})})}function Xe({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-blue-50 border border-blue-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(oe.InformationCircleIcon,{"aria-hidden":"true",className:"size-5 text-blue-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-blue-900",children:e})]})})}var K=require("react/jsx-runtime");function Ct({field:e}){let{variant:r="info",message:c,content:h}=e,d=c||h||"";switch(r.toLowerCase()){case"error":case"danger":return(0,K.jsx)(Ye,{message:d});case"success":return(0,K.jsx)(Ke,{message:d});case"warning":case"warn":return(0,K.jsx)(qe,{message:d});case"info":case"information":default:return(0,K.jsx)(Xe,{message:d})}}var Je=Ct;var Ze=require("@radix-ui/react-label"),R=require("react/jsx-runtime"),St=({formDefinition:e,sendFormValues:r,children:c,defaultValues:h={},onFieldsChange:d=()=>{}})=>{let[a,l]=(0,M.useState)({...h}),[p,s]=(0,M.useState)({}),[b,v]=(0,M.useState)({}),[P,C]=(0,M.useState)({}),B=["hidden","html","linebreak","header","alert"],L=(0,M.useMemo)(()=>({file:ie,multifile:ie,dateRange:Ie,date:He,dayTimePicker:Te,time:Ge,hidden:he,multiselect:ve,select:ke,email:Ce,litertext:Re,checkbox:Pe,radiogroup:Oe,input:se,textarea:Me,header:Ue,alert:Je,linebreak:ze}),[]),O={},V=async(t,o=null)=>{try{let n=await ge(`/${t.optionsUrl}`);console.log(n);let m=[];t.type==="select"?m=[{value:"",label:`Select ${t.label.toLowerCase()}`},...n.data]:m=[...n.data.map(k=>({value:k.value,label:k.label}))],e.fields.forEach(k=>{k.name===t.name&&(k.options=m)})}catch(n){console.error(`Failed to load options for ${t.name}:`,n)}finally{}};(0,M.useEffect)(()=>{if(e!=null&&e.fields&&e.fields.length>0){if(!e.fields.some(n=>n.value))return;e.fields.forEach(n=>{n.optionsUrl&&V(n)});let o={};e.fields.forEach(n=>{o[n.name]=h[n.name]??n.value??(n.type==="multiselect"?[]:"")}),l(o)}},[e]);let A=(t,o,n)=>{if(t.disabled&&t.disabled(n))return null;if(t.required){if(!o)return`${t.label} is required`;if(Array.isArray(o)&&o.length===0)return`Please select at least one ${t.label.toLowerCase()}`}if(t.validate){let m=t.validate(o,n);if(m)return m}if(t.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o))return"Please enter a valid email address";if(t.type==="number"){if(t.min!==void 0&&o<t.min)return`${t.label} must be at least ${t.min}`;if(t.max!==void 0&&o>t.max)return`${t.label} must be no more than ${t.max}`}return t.type==="date"&&!(0,ce.default)(o).isValid()?`${t.label} must be a valid date`:t.maxLength&&o&&o.length>t.maxLength?`${t.label} must not exceed ${t.maxLength} characters`:null},U=(t,o)=>{let n=e.fields.find(y=>y.name===t);if(!n)return;let m={...a};console.log(o),n.type==="multiselect"?m[t]=Array.isArray(o)?o:Array.from(o.target.selectedOptions).map(y=>y.value):n.type==="dateRange"?(console.log(o),m[t]=[{startDate:o[0].from,endDate:o[0].to,key:"selection"}]):n.type==="dayTimePicker"?m[t]=o?(0,ce.default)(o).format("YYYY-MM-DD HH:mm:ss"):"":m[t]=o,n.type==="select"&&e.fields.forEach(y=>{y.showIf&&!y.showIf(m)&&(m[y.name]=y.type==="multiselect"?[]:"")}),e.fields.forEach(y=>{y.disabled&&y.disabled(m)&&(m[y.name]=y.type==="multiselect"?[]:"")}),l(m);let k={};e.fields.forEach(y=>{if(!y.showIf||y.showIf(m)){let Y=A(y,m[y.name],m);Y&&(k[y.name]=Y)}}),s(k)},f=t=>{v({...b,[t]:!0})},$=t=>{t.preventDefault();let o={};e.fields.forEach(m=>{o[m.name]=!0}),v(o);let n={};e.fields.forEach(m=>{if((!m.showIf||m.showIf(a))&&(!m.disabled||!m.disabled(a))){let k=A(m,a[m.name],a);k&&(n[m.name]=k)}}),s(n),Object.keys(n).length===0?r(a):Qe.toast.error("Please correct the errors in the form")};(0,M.useEffect)(()=>{d(a)},[a,d]);let X={green:"border-green-500 bg-green-50",blue:"border-blue-500 bg-blue-50",red:"border-red-500 bg-red-50",yellow:"border-yellow-500 bg-yellow-50",purple:"border-purple-500 bg-purple-50",indigo:"border-indigo-500 bg-indigo-50",gray:"border-gray-500 bg-gray-50",pink:"border-pink-500 bg-pink-50",orange:"border-orange-500 bg-orange-50"};function re(t,o,n){if(B.includes(o.type))return(0,R.jsx)("div",{className:o.fieldClass||"col-span-8",children:t});let m=o.containerStyle,k=o.color||"blue",y=m==="card"?`rounded-lg border text-card-foreground shadow-sm p-4 ${o.containerClassName||X[k]||X.blue}`:"",Y=(0,R.jsxs)(R.Fragment,{children:[o.label&&(0,R.jsxs)(Ze.Label,{htmlFor:o.name,className:"block text-sm font-medium mb-1",children:[o.label,o.required&&(0,R.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),(0,R.jsx)("div",{children:t}),n&&(0,R.jsx)("p",{className:"mt-1 text-sm text-red-500",children:n})]});return(0,R.jsx)("div",{className:`mb-4 ${o.fieldClass||"col-span-8"}`,children:m==="card"?(0,R.jsx)("div",{className:y,children:Y}):Y})}let i=t=>{if(t.showIf&&!t.showIf(a))return null;let o=L[t.type]||se;a[t.name]===void 0&&(a[t.name]=t.value!==void 0?t.value:t.type==="multiselect"?[]:"");let n=b[t.name]&&p[t.name]?p[t.name]:null;return re((0,R.jsx)(o,{field:t,formValues:a,handleChange:U,handleBlur:()=>f(t.name),setCharCounts:C,charCount:P[t.name]||0}),t)};return(0,R.jsxs)("form",{onSubmit:$,className:"grid grid-cols-12 gap-x-4 mx-auto",children:[e?e.fields.map(i):(0,R.jsx)("div",{children:"Loading..."}),c]})},et=St;0&&(module.exports={DynamicForm,MyButton});
46
+ `,children:"PM"})]})]}),(0,u.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-gray-200 pt-3",children:[(0,u.jsx)("button",{type:"button",onClick:P,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-white hover:bg-gray-100 hover:text-gray-900 h-9 px-4 py-2",children:"Clear"}),(0,u.jsx)("button",{type:"button",onClick:B,className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-blue-600 text-white hover:bg-blue-700 h-9 px-4 py-2",children:"Done"})]})]})})]})})}var He=vt;var go=require("react");var re=require("@heroicons/react/20/solid"),je=require("@heroicons/react/20/solid"),Ge=require("@heroicons/react/24/outline");var N=require("react/jsx-runtime");function We({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-red-50 border border-red-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(re.XCircleIcon,{"aria-hidden":"true",className:"size-5 text-red-500 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-red-900",children:e})]})})}function Ve({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-amber-50 border border-amber-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(Ge.ExclamationCircleIcon,{"aria-hidden":"true",className:"size-5 text-amber-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-amber-900",children:e})]})})}function Ye({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-green-50 border border-green-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(je.CheckCircleIcon,{"aria-hidden":"true",className:"size-5 text-green-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-green-900",children:e})]})})}function qe({message:e}){return(0,N.jsx)("div",{className:"rounded-lg bg-blue-50 border border-blue-100 p-4 shadow-sm",children:(0,N.jsxs)("div",{className:"flex items-center gap-3",children:[(0,N.jsx)(re.InformationCircleIcon,{"aria-hidden":"true",className:"size-5 text-blue-600 shrink-0"}),(0,N.jsx)("span",{className:"text-sm font-medium text-blue-900",children:e})]})})}var X=require("react/jsx-runtime");function wt({field:e}){let{variant:r="info",message:c,content:g}=e,d=c||g||"";switch(r.toLowerCase()){case"error":case"danger":return(0,X.jsx)(We,{message:d});case"success":return(0,X.jsx)(Ye,{message:d});case"warning":case"warn":return(0,X.jsx)(Ve,{message:d});case"info":case"information":default:return(0,X.jsx)(qe,{message:d})}}var Ke=wt;var Je=require("@radix-ui/react-label"),R=require("react/jsx-runtime"),Nt=({formDefinition:e,sendFormValues:r,children:c,defaultValues:g={},onFieldsChange:d=()=>{}})=>{let[a,l]=(0,M.useState)({...g}),[p,s]=(0,M.useState)({}),[b,v]=(0,M.useState)({}),[$,C]=(0,M.useState)({}),B=["hidden","html","linebreak","header","alert"],P=(0,M.useMemo)(()=>({file:ce,multifile:ce,dateRange:Ee,date:_e,dayTimePicker:Ae,time:He,hidden:xe,multiselect:we,select:Ce,email:Se,litertext:$e,checkbox:Pe,radiogroup:Te,input:ne,textarea:Be,header:ze,alert:Ke,linebreak:De}),[]),O={},V=async(t,o=null)=>{try{let n=await he(`/${t.optionsUrl}`);console.log(n);let m=[];t.type==="select"?m=[{value:"",label:`Select ${t.label.toLowerCase()}`},...n.data]:m=[...n.data.map(k=>({value:k.value,label:k.label}))],e.fields.forEach(k=>{k.name===t.name&&(k.options=m)})}catch(n){console.error(`Failed to load options for ${t.name}:`,n)}finally{}};(0,M.useEffect)(()=>{if(e!=null&&e.fields&&e.fields.length>0){if(!e.fields.some(n=>n.value))return;e.fields.forEach(n=>{n.optionsUrl&&V(n)});let o={};e.fields.forEach(n=>{o[n.name]=g[n.name]??n.value??(n.type==="multiselect"?[]:"")}),l(o)}},[e]);let A=(t,o,n)=>{if(t.disabled&&t.disabled(n))return null;if(t.required){if(!o)return`${t.label} is required`;if(Array.isArray(o)&&o.length===0)return`Please select at least one ${t.label.toLowerCase()}`}if(t.validate){let m=t.validate(o,n);if(m)return m}if(t.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o))return"Please enter a valid email address";if(t.type==="number"){if(t.min!==void 0&&o<t.min)return`${t.label} must be at least ${t.min}`;if(t.max!==void 0&&o>t.max)return`${t.label} must be no more than ${t.max}`}return t.type==="date"&&!(0,de.default)(o).isValid()?`${t.label} must be a valid date`:t.maxLength&&o&&o.length>t.maxLength?`${t.label} must not exceed ${t.maxLength} characters`:null},U=(t,o)=>{let n=e.fields.find(f=>f.name===t);if(!n)return;let m={...a};console.log(o),n.type==="multiselect"?m[t]=Array.isArray(o)?o:Array.from(o.target.selectedOptions).map(f=>f.value):n.type==="dateRange"?(console.log(o),m[t]=[{startDate:o[0].from,endDate:o[0].to,key:"selection"}]):n.type==="dayTimePicker"?m[t]=o?(0,de.default)(o).format("YYYY-MM-DD HH:mm:ss"):"":m[t]=o,n.type==="select"&&e.fields.forEach(f=>{f.showIf&&!f.showIf(m)&&(m[f.name]=f.type==="multiselect"?[]:"")}),e.fields.forEach(f=>{f.disabled&&f.disabled(m)&&(m[f.name]=f.type==="multiselect"?[]:"")}),l(m);let k={};e.fields.forEach(f=>{if(!f.showIf||f.showIf(m)){let Y=A(f,m[f.name],m);Y&&(k[f.name]=Y)}}),s(k)},y=t=>{v({...b,[t]:!0})},L=t=>{t.preventDefault();let o={};e.fields.forEach(m=>{o[m.name]=!0}),v(o);let n={};e.fields.forEach(m=>{if((!m.showIf||m.showIf(a))&&(!m.disabled||!m.disabled(a))){let k=A(m,a[m.name],a);k&&(n[m.name]=k)}}),s(n),Object.keys(n).length===0?r(a):Xe.toast.error("Please correct the errors in the form")};(0,M.useEffect)(()=>{d(a)},[a,d]);let J={green:"border-green-500 bg-green-50",blue:"border-blue-500 bg-blue-50",red:"border-red-500 bg-red-50",yellow:"border-yellow-500 bg-yellow-50",purple:"border-purple-500 bg-purple-50",indigo:"border-indigo-500 bg-indigo-50",gray:"border-gray-500 bg-gray-50",pink:"border-pink-500 bg-pink-50",orange:"border-orange-500 bg-orange-50"};function se(t,o,n){if(B.includes(o.type))return(0,R.jsx)("div",{className:o.fieldClass||"col-span-8",children:t});let m=o.containerStyle,k=o.color||"blue",f=m==="card"?`rounded-lg border text-card-foreground shadow-sm p-4 ${o.containerClassName||J[k]||J.blue}`:"",Y=(0,R.jsxs)(R.Fragment,{children:[o.label&&(0,R.jsxs)(Je.Label,{htmlFor:o.name,className:"block text-sm font-medium mb-1",children:[o.label,o.required&&(0,R.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),(0,R.jsx)("div",{children:t}),n&&(0,R.jsx)("p",{className:"mt-1 text-sm text-red-500",children:n})]});return(0,R.jsx)("div",{className:`mb-4 ${o.fieldClass||"col-span-8"}`,children:m==="card"?(0,R.jsx)("div",{className:f,children:Y}):Y})}let i=t=>{if(t.showIf&&!t.showIf(a))return null;let o=P[t.type]||ne;a[t.name]===void 0&&(a[t.name]=t.value!==void 0?t.value:t.type==="multiselect"?[]:"");let n=b[t.name]&&p[t.name]?p[t.name]:null;return se((0,R.jsx)(o,{field:t,formValues:a,handleChange:U,handleBlur:()=>y(t.name),setCharCounts:C,charCount:$[t.name]||0}),t)};return(0,R.jsxs)("form",{onSubmit:L,className:"grid grid-cols-12 gap-x-4 mx-auto",children:[e?e.fields.map(i):(0,R.jsx)("div",{children:"Loading..."}),c]})},ae=Nt;var kt=ae;0&&(module.exports={DynamicForm,DynamicFormComponent,MyButton,MyButtonComponent});
47
47
  //# sourceMappingURL=index.cjs.map