@flowcsolutions/react-form-builder
Version:
A powerful, responsive form builder built with React, TypeScript, HeroUI, and TailwindCSS
10 lines (9 loc) • 126 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),A=require("react"),se=require("uuid"),Y=require("@dnd-kit/core"),H=require("@dnd-kit/sortable"),t=require("@heroui/react"),x=require("lucide-react"),he=require("@dnd-kit/utilities");function je(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const o in s)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(s,o);Object.defineProperty(a,o,l.get?l:{enumerable:!0,get:()=>s[o]})}}return a.default=s,Object.freeze(a)}const ee=je(x);function be(s,a){if(s.name&&s.name.trim())return s.name;const o=s.type.replace(/[-_]/g,"_").toLowerCase(),l=a.map(j=>j.name).filter(Boolean);if(!l.includes(o))return o;let i=2,n=`${o}${i}`;for(;l.includes(n);)i++,n=`${o}${i}`;return n}const ge={currentForm:{id:se.v4(),title:"New Form",description:"",fields:[],settings:{submitButtonText:"Submit",allowMultipleSubmissions:!0,requireAuth:!1,captchaEnabled:!1,theme:"auto"}},selectedFieldId:null,previewMode:!1,deviceView:"desktop"};function ye(s,a){switch(a.type){case"SET_FORM":return{...s,currentForm:a.payload,selectedFieldId:null};case"ADD_FIELD":const o={...a.payload,name:be(a.payload,s.currentForm.fields)};return{...s,currentForm:{...s.currentForm,fields:[...s.currentForm.fields,o]},selectedFieldId:a.payload.id};case"UPDATE_FIELD":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,...a.payload.updates,properties:a.payload.updates.properties?{...n.properties,...a.payload.updates.properties}:n.properties,advanced:a.payload.updates.advanced?{...n.advanced,...a.payload.updates.advanced}:n.advanced,custom:a.payload.updates.custom?{...n.custom,...a.payload.updates.custom}:n.custom,events:a.payload.updates.events?{...n.events,...a.payload.updates.events}:n.events,schema:a.payload.updates.schema?{...n.schema,...a.payload.updates.schema}:n.schema,layout:a.payload.updates.layout?{...n.layout,...a.payload.updates.layout}:n.layout}:n)}};case"UPDATE_FIELD_PROPERTIES":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,properties:{...n.properties,...a.payload.properties}}:n)}};case"UPDATE_FIELD_ADVANCED":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,advanced:{...n.advanced,...a.payload.advanced}}:n)}};case"UPDATE_FIELD_CUSTOM":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,custom:{...n.custom,...a.payload.custom}}:n)}};case"UPDATE_FIELD_EVENTS":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,events:{...n.events,...a.payload.events}}:n)}};case"UPDATE_FIELD_SCHEMA":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,schema:{...n.schema,...a.payload.schema}}:n)}};case"UPDATE_FIELD_LAYOUT":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.map(n=>n.id===a.payload.id?{...n,layout:{...n.layout,...a.payload.layout}}:n)}};case"DELETE_FIELD":return{...s,currentForm:{...s.currentForm,fields:s.currentForm.fields.filter(n=>n.id!==a.payload)},selectedFieldId:s.selectedFieldId===a.payload?null:s.selectedFieldId};case"REORDER_FIELDS":const l=[...s.currentForm.fields],[i]=l.splice(a.payload.oldIndex,1);return l.splice(a.payload.newIndex,0,i),{...s,currentForm:{...s.currentForm,fields:l}};case"SELECT_FIELD":return{...s,selectedFieldId:a.payload};case"SET_PREVIEW_MODE":return{...s,previewMode:a.payload,selectedFieldId:a.payload?null:s.selectedFieldId};case"SET_DEVICE_VIEW":return{...s,deviceView:a.payload};case"UPDATE_FORM_SETTINGS":return{...s,currentForm:{...s.currentForm,settings:{...s.currentForm.settings,...a.payload}}};case"UPDATE_FORM_META":return{...s,currentForm:{...s.currentForm,title:a.payload.title??s.currentForm.title,description:a.payload.description??s.currentForm.description}};default:return s}}const te=A.createContext(void 0);function re({children:s}){const[a,o]=A.useReducer(ye,ge),l={setForm:i=>o({type:"SET_FORM",payload:i}),addField:i=>o({type:"ADD_FIELD",payload:i}),updateField:(i,n)=>o({type:"UPDATE_FIELD",payload:{id:i,updates:n}}),updateFieldProperties:(i,n)=>o({type:"UPDATE_FIELD_PROPERTIES",payload:{id:i,properties:n}}),updateFieldAdvanced:(i,n)=>o({type:"UPDATE_FIELD_ADVANCED",payload:{id:i,advanced:n}}),updateFieldCustom:(i,n)=>o({type:"UPDATE_FIELD_CUSTOM",payload:{id:i,custom:n}}),updateFieldEvents:(i,n)=>o({type:"UPDATE_FIELD_EVENTS",payload:{id:i,events:n}}),updateFieldSchema:(i,n)=>o({type:"UPDATE_FIELD_SCHEMA",payload:{id:i,schema:n}}),updateFieldLayout:(i,n)=>o({type:"UPDATE_FIELD_LAYOUT",payload:{id:i,layout:n}}),deleteField:i=>o({type:"DELETE_FIELD",payload:i}),reorderFields:(i,n)=>o({type:"REORDER_FIELDS",payload:{oldIndex:i,newIndex:n}}),selectField:i=>o({type:"SELECT_FIELD",payload:i}),setPreviewMode:i=>o({type:"SET_PREVIEW_MODE",payload:i}),setDeviceView:i=>o({type:"SET_DEVICE_VIEW",payload:i}),updateFormSettings:i=>o({type:"UPDATE_FORM_SETTINGS",payload:i}),updateFormMeta:i=>o({type:"UPDATE_FORM_META",payload:i})};return e.jsx(te.Provider,{value:{state:a,dispatch:o,actions:l},children:s})}function z(){const s=A.useContext(te);if(s===void 0)throw new Error("useFormBuilder must be used within a FormBuilderProvider");return s}function w(s){const a={id:se.v4(),type:s,label:Ne(s),required:!1,properties:{},advanced:{valued:!0,valueType:"string",dataBindingType:"twoWay",calculable:!1,localizable:!1,readOnly:!1,disabled:!1,asyncValidation:!1,deferFieldCalculation:!1},layout:{columnSpan:12,gridClass:"col-span-12"},custom:{cssClasses:[],dataAttributes:{}},events:{},schema:{componentKind:"component",category:fe(s),typeName:s,icon:ve(s),nestingLevel:0,builderOnly:!1}};switch(s){case"text":case"email":case"password":case"phone":case"url":return{...a,placeholder:`Enter ${a.label.toLowerCase()}`,properties:{...a.properties,width:"full",maxLength:255,colorVariant:"default",size:"md",borderRadius:"md"}};case"textarea":return{...a,placeholder:`Enter ${a.label.toLowerCase()}`,properties:{...a.properties,width:"full",rows:4,maxLength:1e3,colorVariant:"default",size:"md",borderRadius:"md"}};case"number":case"number-format":return{...a,placeholder:"Enter number",properties:{...a.properties,width:"full"},advanced:{...a.advanced,valueType:"number"}};case"select":case"radio":case"checkbox":case"multiselect":case"autocomplete":return{...a,options:[{label:"Option 1",value:"option1"},{label:"Option 2",value:"option2"}],properties:{...a.properties,width:"full",colorVariant:"default",size:"md",borderRadius:"md",orientation:s==="radio"||s==="checkbox"?"vertical":void 0,componentAlignment:s==="radio"||s==="checkbox"?"left":void 0},advanced:{...a.advanced,valueType:s==="multiselect"||s==="checkbox"?"array":"string"}};case"date":case"datetime":case"time":case"calendar":return{...a,properties:{...a.properties,width:"full"},advanced:{...a.advanced,valueType:"date"}};case"file":return{...a,properties:{...a.properties,width:"full",accept:"",multiple:!1},advanced:{...a.advanced,valueType:"array"}};case"rating":case"range":return{...a,properties:{...a.properties,width:"full",max:5,componentAlignment:s==="rating"?"left":void 0},advanced:{...a.advanced,valueType:"number"}};case"switch":return{...a,properties:{...a.properties,width:"full",size:"md",componentAlignment:"left"},advanced:{...a.advanced,valueType:"boolean"}};case"signature":return{...a,properties:{...a.properties,width:"full"},advanced:{...a.advanced,valueType:"string"}};case"header":return{...a,label:"Header",properties:{...a.properties,width:"full"},advanced:{...a.advanced,valued:!1}};case"paragraph":case"label":case"message":return{...a,label:"Paragraph",properties:{...a.properties,width:"full"},advanced:{...a.advanced,valued:!1}};case"image":return{...a,label:"Image",properties:{...a.properties,width:"full"},advanced:{...a.advanced,valued:!1}};case"button":return{...a,label:"Button",properties:{...a.properties,width:"full",colorVariant:"primary",size:"md",borderRadius:"md",variant:"solid"},advanced:{...a.advanced,valued:!1}};case"section":case"pagebreak":return{...a,label:"Section",properties:{...a.properties,width:"full"},advanced:{...a.advanced,valued:!1}};case"container":case"card":return{...a,label:"Container",properties:{...a.properties,width:"full"},advanced:{...a.advanced,valued:!1}};default:return a}}function Ne(s){return{text:"Text Input",email:"Email",password:"Password",number:"Number",phone:"Phone",url:"URL",textarea:"Text Area",select:"Select",multiselect:"Multi Select",radio:"Radio Group",checkbox:"Checkbox Group",switch:"Switch",autocomplete:"Auto Complete",search:"Search",date:"Date",datetime:"Date Time",time:"Time",calendar:"Calendar",file:"File Upload",rating:"Rating",signature:"Signature",range:"Range Slider","rich-text":"Rich Text","number-format":"Formatted Number","pattern-format":"Pattern Format",button:"Button",label:"Label",header:"Header",paragraph:"Paragraph",image:"Image",message:"Message","progress-line":"Progress Line","progress-circle":"Progress Circle",tooltip:"Tooltip","qr-code":"QR Code",html:"HTML",container:"Container",card:"Card",tab:"Tab",breadcrumb:"Breadcrumb",section:"Section",pagebreak:"Page Break",repeater:"Repeater",slot:"Slot",template:"Template","error-message":"Error Message"}[s]||"Field"}function fe(s){return{text:"fields",email:"fields",password:"fields",number:"fields",phone:"fields",url:"fields",textarea:"fields",select:"fields",multiselect:"fields",radio:"fields",checkbox:"fields",switch:"fields",autocomplete:"fields",search:"fields",date:"fields",datetime:"fields",time:"fields",calendar:"fields",file:"fields",rating:"fields",signature:"fields",range:"fields","rich-text":"fields","number-format":"fields","pattern-format":"fields",button:"static",label:"static",header:"static",paragraph:"static",image:"static",message:"static","progress-line":"static","progress-circle":"static",tooltip:"static","qr-code":"static",html:"static",container:"structure",card:"structure",tab:"structure",breadcrumb:"structure",section:"structure",pagebreak:"structure",repeater:"structure",slot:"templates",template:"templates","error-message":"error"}[s]||"fields"}function ve(s){return{text:"Type",email:"Mail",password:"Key",number:"Hash",phone:"Phone",url:"Link",textarea:"FileText",select:"ChevronDown",multiselect:"List",radio:"Circle",checkbox:"Square",switch:"ToggleLeft",autocomplete:"Search",search:"Search",date:"Calendar",datetime:"Clock",time:"Clock",calendar:"Calendar",file:"Upload",rating:"Star",signature:"PenTool",range:"Sliders","rich-text":"FileText","number-format":"Hash","pattern-format":"Hash",button:"MousePointer",label:"Tag",header:"Heading",paragraph:"Type",image:"Image",message:"MessageSquare","progress-line":"TrendingUp","progress-circle":"Circle",tooltip:"Info","qr-code":"QrCode",html:"Code",container:"Box",card:"Square",tab:"Tabs",breadcrumb:"ChevronRight",section:"Layout",pagebreak:"Scissors",repeater:"Copy",slot:"Grid",template:"FileTemplate","error-message":"AlertCircle"}[s]||"Square"}const we={text:w("text"),email:w("email"),password:w("password"),number:w("number"),phone:w("phone"),url:w("url"),textarea:w("textarea"),select:w("select"),multiselect:w("multiselect"),radio:w("radio"),checkbox:w("checkbox"),switch:w("switch"),autocomplete:w("autocomplete"),search:w("search"),date:w("date"),datetime:w("datetime"),time:w("time"),calendar:w("calendar"),file:w("file"),rating:w("rating"),signature:w("signature"),range:w("range"),"rich-text":w("rich-text"),"number-format":w("number-format"),"pattern-format":w("pattern-format"),button:w("button"),label:w("label"),header:w("header"),paragraph:w("paragraph"),image:w("image"),message:w("message"),"progress-line":w("progress-line"),"progress-circle":w("progress-circle"),tooltip:w("tooltip"),"qr-code":w("qr-code"),html:w("html"),container:w("container"),card:w("card"),tab:w("tab"),breadcrumb:w("breadcrumb"),section:w("section"),pagebreak:w("pagebreak"),repeater:w("repeater"),slot:w("slot"),template:w("template"),"error-message":w("error-message")},ae=[{id:"text",type:"text",label:"Text Input",icon:"Type",category:"fields"},{id:"email",type:"email",label:"Email",icon:"Mail",category:"fields"},{id:"password",type:"password",label:"Password",icon:"Key",category:"fields"},{id:"number",type:"number",label:"Number",icon:"Hash",category:"fields"},{id:"phone",type:"phone",label:"Phone",icon:"Phone",category:"fields"},{id:"textarea",type:"textarea",label:"Text Area",icon:"FileText",category:"fields"},{id:"select",type:"select",label:"Select",icon:"ChevronDown",category:"fields"},{id:"autocomplete",type:"autocomplete",label:"Auto Complete",icon:"Search",category:"fields"},{id:"radio",type:"radio",label:"Radio Group",icon:"Circle",category:"fields"},{id:"checkbox",type:"checkbox",label:"Checkbox Group",icon:"Square",category:"fields"},{id:"switch",type:"switch",label:"Switch",icon:"ToggleLeft",category:"fields"},{id:"date",type:"date",label:"Date",icon:"Calendar",category:"fields"},{id:"time",type:"time",label:"Time",icon:"Clock",category:"fields"},{id:"file",type:"file",label:"File Upload",icon:"Upload",category:"fields"},{id:"rating",type:"rating",label:"Rating",icon:"Star",category:"fields"},{id:"header",type:"header",label:"Header",icon:"Heading",category:"static"},{id:"paragraph",type:"paragraph",label:"Paragraph",icon:"Type",category:"static"},{id:"image",type:"image",label:"Image",icon:"Image",category:"static"},{id:"button",type:"button",label:"Button",icon:"MousePointer",category:"static"},{id:"section",type:"section",label:"Section",icon:"Layout",category:"structure"},{id:"container",type:"container",label:"Container",icon:"Box",category:"structure"},{id:"card",type:"card",label:"Card",icon:"Square",category:"structure"}],ne=[{id:"fields",label:"Form Fields",description:"Input and selection fields"},{id:"static",label:"Static Content",description:"Text, images, and layout elements"},{id:"structure",label:"Structure",description:"Containers and layout components"},{id:"templates",label:"Templates",description:"Pre-built field combinations"},{id:"error",label:"Error Handling",description:"Error display components"}];function W(s,a=!1){const o=Se(s.properties?.borderRadius),l=Fe(s),i=le(s,a),n=s.properties?.customClasses||"",j=s.custom?.cssClasses?.join(" ")||"",m=[n,j].filter(Boolean).join(" "),C=Ce(m),c=s.properties?.classNames||{},p=d=>d?(d.includes("text-")||d.includes("bg-")||d.includes("border-"),d):"";return{base:[l.margin,l.padding,a?"":i.visibility,C.wrapper,c.base||""].filter(Boolean).join(" "),label:["text-left",C.label,p(c.label||"")].filter(Boolean).join(" "),inputWrapper:[o,C.inputWrapper,p(c.inputWrapper||"")].filter(Boolean).join(" "),innerWrapper:[p(c.innerWrapper||"")].filter(Boolean).join(" "),mainWrapper:[p(c.mainWrapper||"")].filter(Boolean).join(" "),input:[s.properties?.alignment||"",C.input,p(c.input||"")].filter(Boolean).join(" "),clearButton:[p(c.clearButton||"")].filter(Boolean).join(" "),helperWrapper:[p(c.helperWrapper||"")].filter(Boolean).join(" "),description:["text-left",C.description,p(c.description||"")].filter(Boolean).join(" "),errorMessage:[p(c.errorMessage||"")].filter(Boolean).join(" ")}}function Ce(s){if(!s.trim())return{wrapper:"",inputWrapper:"",input:"",label:"",description:""};const a=s.trim().split(/\s+/),o={wrapper:[],inputWrapper:[],input:[],label:[],description:[]};return a.forEach(l=>{l.match(/^(border|shadow|bg-|rounded|ring)/)?o.inputWrapper.push(l):l.match(/^(text-|font-|placeholder|italic|underline)/)?o.input.push(l):l.match(/^(m[tlrb]?-|p[tlrb]?-|w-|h-|max-|min-|flex|grid|col-|row-|gap-|space-|justify-|items-|self-)/)?o.wrapper.push(l):o.inputWrapper.push(l)}),{wrapper:o.wrapper.join(" "),inputWrapper:o.inputWrapper.join(" "),input:o.input.join(" "),label:o.label.join(" "),description:o.description.join(" ")}}function Se(s){switch(s){case"none":return"rounded-none";case"small":return"rounded-sm";case"default":return"rounded-md";case"large":return"rounded-lg";case"full":return"rounded-full";default:return""}}function Fe(s){const a=s.properties?.marginTop,o=s.properties?.marginBottom,l=s.properties?.padding;return{margin:[a||"",o||""].filter(Boolean).join(" "),padding:l||""}}function le(s,a=!1){const o=[];return a||(s.properties?.hideOnMobile&&o.push("hidden sm:block"),s.properties?.hideOnTablet&&o.push("sm:hidden lg:block"),s.properties?.hideOnDesktop&&o.push("lg:hidden")),{visibility:o.join(" ")}}function Ie(s){return W(s).base}function _(s,a=!1){const o=[];s.layout?.gridClass&&o.push(s.layout.gridClass);const l=le(s,a);return l.visibility&&o.push(l.visibility),o.join(" ")}function ie({value:s,onChange:a,width:o=400,height:l=200,disabled:i=!1,className:n=""}){const j=A.useRef(null),[m,C]=A.useState(!1),[c,p]=A.useState(!0),[r,d]=A.useState({x:0,y:0});A.useEffect(()=>{const g=j.current;if(!g)return;const b=g.getContext("2d");if(b&&(g.width=o,g.height=l,b.lineCap="round",b.lineJoin="round",b.strokeStyle="#000000",b.lineWidth=2,b.fillStyle="#ffffff",b.fillRect(0,0,o,l),s&&s.startsWith("data:image"))){const S=new Image;S.onload=()=>{b.clearRect(0,0,o,l),b.fillStyle="#ffffff",b.fillRect(0,0,o,l),b.drawImage(S,0,0,o,l),p(!1)},S.src=s}},[o,l,s]);const u=g=>{const b=j.current;if(!b)return{x:0,y:0};const S=b.getBoundingClientRect(),T=b.width/S.width,O=b.height/S.height;if("touches"in g){const B=g.touches[0];return{x:(B.clientX-S.left)*T,y:(B.clientY-S.top)*O}}else return{x:(g.clientX-S.left)*T,y:(g.clientY-S.top)*O}},f=g=>{if(i)return;g.preventDefault();const b=u(g);C(!0),d(b),p(!1)},h=g=>{if(!m||i)return;g.preventDefault();const b=j.current,S=b?.getContext("2d");if(!b||!S)return;const T=u(g);S.beginPath(),S.moveTo(r.x,r.y),S.lineTo(T.x,T.y),S.stroke(),d(T)},v=()=>{m&&(C(!1),I())},I=()=>{const g=j.current;if(!g)return;const b=g.toDataURL("image/png");a?.(b)},E=()=>{const g=j.current,b=g?.getContext("2d");!g||!b||(b.fillStyle="#ffffff",b.fillRect(0,0,o,l),p(!0),a?.(""))};return e.jsxs("div",{className:`signature-pad ${n}`,children:[e.jsx("div",{className:"border-2 border-default-300 rounded-lg overflow-hidden bg-white",children:e.jsx("canvas",{ref:j,className:"block cursor-crosshair touch-none",style:{width:"100%",height:"auto",maxWidth:`${o}px`},onMouseDown:f,onMouseMove:h,onMouseUp:v,onMouseLeave:v,onTouchStart:f,onTouchMove:h,onTouchEnd:v})}),e.jsxs("div",{className:"flex justify-between items-center mt-3",children:[e.jsx("div",{className:"text-xs text-default-500",children:c?"Sign above":"Signature captured"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(t.Button,{size:"sm",variant:"flat",color:"warning",startContent:e.jsx(x.RotateCcw,{size:16}),onPress:E,isDisabled:i||c,children:"Clear"}),!c&&e.jsx(t.Button,{size:"sm",color:"success",variant:"flat",startContent:e.jsx(x.Check,{size:16}),onPress:I,isDisabled:i,children:"Save"})]})]})]})}function q({field:s,value:a,onChange:o}){const l=h=>{o&&o(h)};if(s.advanced?.hidden||s.properties?.hidden)return null;const i=W(s,!0),n=i.base,m=(()=>{const h=[];return s.properties?.hideOnMobile&&h.push("Hidden on Mobile"),s.properties?.hideOnTablet&&h.push("Hidden on Tablet"),s.properties?.hideOnDesktop&&h.push("Hidden on Desktop"),h})(),C=({children:h})=>m.length===0?e.jsx(e.Fragment,{children:h}):e.jsxs("div",{className:"relative",children:[h,e.jsx("div",{className:"absolute top-0 right-0 flex items-center gap-1 -mt-2 -mr-2 z-10",children:m.map(v=>e.jsx("span",{className:"text-danger-700 text-xs px-1.5 py-0.5 rounded-full ",title:v,children:v.includes("Mobile")?e.jsx(x.Smartphone,{size:15}):v.includes("Tablet")?e.jsx(x.Tablet,{size:15}):e.jsx(x.Monitor,{size:15})},v))})]}),c=h=>e.jsx(C,{children:h}),p={label:s.label,placeholder:s.placeholder,isRequired:s.required,description:s.properties?.description,isDisabled:s.advanced?.disabled||s.properties?.disabled,isReadOnly:s.advanced?.readOnly||s.properties?.readonly,size:s.properties?.size,color:s.properties?.colorVariant,variant:s.properties?.variant,radius:s.properties?.borderRadius,classNames:{base:i.base,label:i.label,inputWrapper:i.inputWrapper,innerWrapper:i.innerWrapper,mainWrapper:i.mainWrapper,input:i.input,clearButton:i.clearButton,helperWrapper:i.helperWrapper,description:i.description,errorMessage:i.errorMessage}},d=(()=>{const h={},v=s.custom?.dataAttributes||{};return Object.entries(v).forEach(([I,E])=>{h[`data-${I}`]=E}),s.custom?.role&&(h.role=s.custom.role),s.custom?.tabIndex!==void 0&&(h.tabIndex=s.custom.tabIndex),s.properties?.ariaLabel&&(h["aria-label"]=s.properties.ariaLabel),s.type==="number"&&(s.properties?.min!==void 0&&(h.min=s.properties.min),s.properties?.max!==void 0&&(h.max=s.properties.max),s.properties?.step!==void 0&&(h.step=s.properties.step)),h})(),f=(()=>{if(s.properties?.showCharacterCount&&(s.type==="text"||s.type==="textarea")){const h=a?a.length:0,v=s.properties?.maxLength;return v?`${h}/${v}`:`${h}`}return null})();switch(s.type){case"text":return e.jsxs(C,{children:[e.jsx(t.Input,{...p,...d,type:"text",value:a||"",onValueChange:y=>l(y),maxLength:s.properties?.maxLength},`text-${s.id}`),f&&e.jsx("div",{className:"text-xs text-default-500 mt-1 text-right",children:f})]});case"email":return e.jsx(C,{children:e.jsx(t.Input,{...p,...d,type:"email",value:a||"",onValueChange:y=>l(y)},`email-${s.id}`)});case"password":return e.jsx(C,{children:e.jsx(t.Input,{...p,...d,type:"password",value:a||"",onValueChange:y=>l(y)},`password-${s.id}`)});case"number":return c(e.jsx(t.Input,{...p,...d,type:"number",value:a||"",onValueChange:y=>{const D=parseFloat(y);!isNaN(D)&&(s.properties?.min!==void 0&&D<s.properties.min||s.properties?.max!==void 0&&D>s.properties.max)||l(y)}},`number-${s.id}`));case"date":return c(e.jsx(t.DateInput,{...p,value:a||null,onChange:y=>{l(y?y.toString():"")}},`date-${s.id}`));case"datetime":return e.jsx(t.DateInput,{...p,granularity:"second",value:a||null,onChange:y=>{l(y?y.toString():"")}},`datetime-${s.id}`);case"time":return e.jsx(t.TimeInput,{...p,value:a||null,onChange:y=>{l(y?y.toString():"")}},`time-${s.id}`);case"textarea":return c(e.jsxs(e.Fragment,{children:[e.jsx(t.Textarea,{...p,...d,value:a||"",onValueChange:y=>l(y),rows:s.properties?.rows||4,maxLength:s.properties?.maxLength},`textarea-${s.id}`),f&&e.jsx("div",{className:"text-xs text-default-500 mt-1 text-right",children:f})]}));case"select":return c(e.jsx(t.Select,{...p,...d,selectedKeys:a?[a]:[],onSelectionChange:y=>{const D=Array.from(y)[0];l(D)},children:s.options?.map(y=>e.jsx(t.SelectItem,{children:y.label},y.value))||[]}));case"autocomplete":return c(e.jsx(t.Autocomplete,{...p,...d,selectedKey:a||"",onSelectionChange:y=>{l(y)},allowsCustomValue:!0,children:s.options?.map(y=>e.jsx(t.AutocompleteItem,{children:y.label},y.value))||[]}));case"multiselect":return e.jsx(t.Select,{...p,selectionMode:"multiple",selectedKeys:a||[],onSelectionChange:y=>{l(Array.from(y))},children:s.options?.map(y=>e.jsx(t.SelectItem,{children:y.label},y.value))||[]});case"radio":const h=s.properties?.orientation||"vertical",v=s.properties?.componentAlignment||"left",I=h==="horizontal"?v==="center"?"justify-center":v==="right"?"justify-end":"justify-start":v==="center"?"items-center":v==="right"?"items-end":"items-start",E=v==="center"?"text-center":v==="right"?"text-right":"text-left",g=v==="center"?"flex flex-col items-center":v==="right"?"flex flex-col items-end":"flex flex-col items-start";return e.jsx("div",{className:g,children:e.jsx(t.RadioGroup,{label:s.label,description:s.properties?.description,isRequired:s.required,value:a||"",onValueChange:l,size:s.properties?.size,color:s.properties?.colorVariant,isDisabled:s.advanced?.disabled||s.properties?.disabled,isReadOnly:s.advanced?.readOnly||s.properties?.readonly,orientation:h,classNames:{base:i.base,label:`${i.label} ${E}`,wrapper:`${i.inputWrapper} ${I}`,description:`${i.description} ${E}`},children:s.options?.map(y=>e.jsx(t.Radio,{value:y.value,children:y.label},y.value))||[]})});case"checkbox":if(s.options&&s.options.length>1){const y=s.properties?.orientation||"vertical",D=s.properties?.componentAlignment||"left",P=y==="horizontal"?"flex flex-wrap gap-4":"flex flex-col space-y-2",N=y==="horizontal"?D==="center"?"justify-center":D==="right"?"justify-end":"justify-start":D==="center"?"items-center":D==="right"?"items-end":"items-start",F=D==="center"?"text-center":D==="right"?"text-right":"text-left",k=D==="center"?"flex flex-col items-center":D==="right"?"flex flex-col items-end":"flex flex-col items-start";return e.jsxs("div",{className:`space-y-2 ${n} ${k}`,children:[e.jsxs("label",{className:`text-sm font-medium ${F}`,children:[s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),s.properties?.description&&e.jsx("p",{className:`text-xs text-default-500 ${F}`,children:s.properties?.description}),e.jsx("div",{className:`${P} ${N}`,children:s.options.map(R=>e.jsx(t.Checkbox,{value:R.value,isSelected:a?.includes?.(R.value)||!1,onValueChange:M=>{const V=a||[];l(M?[...V,R.value]:V.filter(L=>L!==R.value))},size:s.properties?.size,color:s.properties?.colorVariant,radius:s.properties?.borderRadius,isDisabled:s.advanced?.disabled||s.properties?.disabled,isReadOnly:s.advanced?.readOnly||s.properties?.readonly,children:R.label},R.value))})]})}else{const y=s.properties?.componentAlignment||"left",D=y==="center"?"flex justify-center":y==="right"?"flex justify-end":"flex justify-start",P=y==="center"?"text-center":y==="right"?"text-right":"text-left";return e.jsxs("div",{className:`${n} ${D} flex-col items-start`,children:[e.jsxs("label",{className:`text-sm font-medium ${P} block mb-2`,children:[s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),s.properties?.description&&e.jsx("p",{className:`text-xs text-default-500 mb-2 ${P}`,children:s.properties?.description}),e.jsx(t.Checkbox,{isSelected:a||!1,onValueChange:l,size:s.properties?.size,color:s.properties?.colorVariant,radius:s.properties?.borderRadius,isDisabled:s.advanced?.disabled||s.properties?.disabled,isReadOnly:s.advanced?.readOnly||s.properties?.readonly,children:"Check to confirm"})]})}case"switch":const b=s.properties?.componentAlignment||"left",S=b==="center"?"flex justify-center":b==="right"?"flex justify-end":"flex justify-start";return e.jsxs("div",{className:`space-y-2 ${n}`,children:[e.jsx("div",{className:S,children:e.jsxs(t.Switch,{isSelected:a||!1,onValueChange:l,size:s.properties?.size,color:s.properties?.colorVariant,isDisabled:s.advanced?.disabled||s.properties?.disabled,isReadOnly:s.advanced?.readOnly||s.properties?.readonly,children:[s.label,s.required&&e.jsx("span",{className:"text-danger ml-1",children:"*"})]})}),s.properties?.description&&e.jsx("div",{className:S,children:e.jsx("p",{className:"text-xs text-default-500",children:s.properties?.description})})]});case"file":return e.jsxs("div",{className:`space-y-2 ${n}`,children:[e.jsxs("label",{className:"text-sm font-medium",children:[s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),s.properties?.description&&e.jsx("p",{className:"text-xs text-default-500",children:s.properties?.description}),e.jsxs("div",{className:"border-2 border-dashed border-default-300 rounded-lg p-6 text-center hover:border-default-400 transition-colors relative",children:[e.jsx(x.Upload,{className:"mx-auto text-default-400 mb-2",size:32}),e.jsx("p",{className:"text-sm text-default-600 mb-2",children:"Click to upload or drag and drop"}),e.jsx("p",{className:"text-xs text-default-500",children:s.properties?.accept||"All file types"}),e.jsx("input",{type:"file",accept:s.properties?.accept,multiple:s.properties?.multiple,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",onChange:y=>{const D=Array.from(y.target.files||[]);l(s.properties?.multiple?D:D[0])}})]})]});case"rating":const T=s.properties?.max||5,O=s.properties?.componentAlignment||"left",B=O==="center"?"flex justify-center":O==="right"?"flex justify-end":"flex justify-start";return e.jsxs("div",{className:`space-y-2 ${n}`,children:[e.jsx("div",{className:B,children:e.jsxs("label",{className:"text-sm font-medium",children:[s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]})}),s.properties?.description&&e.jsx("div",{className:B,children:e.jsx("p",{className:"text-xs text-default-500",children:s.properties?.description})}),e.jsx("div",{className:B,children:e.jsx("div",{className:"flex gap-1",children:Array.from({length:T},(y,D)=>D+1).map(y=>e.jsx("button",{type:"button",onClick:()=>l(y),className:"focus:outline-none",children:e.jsx(x.Star,{className:`w-6 h-6 ${y<=(a||0)?"text-warning fill-current":"text-default-300"}`})},y))})})]});case"signature":return e.jsxs("div",{className:`space-y-2 ${n}`,children:[e.jsxs("label",{className:"text-sm font-medium",children:[s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),s.properties?.description&&e.jsx("p",{className:"text-xs text-default-500",children:s.properties?.description}),e.jsx(ie,{value:a,onChange:l,width:380,height:150,className:"w-full"})]});case"section":return e.jsx("div",{className:n,children:e.jsx(t.Card,{children:e.jsxs(t.CardBody,{className:"py-4",children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:s.label}),s.properties?.description&&e.jsx("p",{className:"text-default-600",children:s.properties?.description})]})})});case"paragraph":return e.jsxs("div",{className:`py-2 ${n}`,children:[e.jsx("h4",{className:"text-md font-medium mb-1",children:s.label}),s.properties?.description&&e.jsx("p",{className:"text-default-600",children:s.properties?.description})]});case"pagebreak":return e.jsxs("div",{className:`my-8 ${n}`,children:[e.jsx(t.Divider,{className:"my-4"}),e.jsx("div",{className:"text-center text-sm text-default-500",children:"Page Break"}),e.jsx(t.Divider,{className:"my-4"})]});case"html":return e.jsx("div",{className:`prose prose-sm max-w-none ${n}`,dangerouslySetInnerHTML:{__html:s.properties?.description||s.label}});case"range":return e.jsxs("div",{className:`space-y-2 ${n}`,children:[e.jsxs("label",{className:"text-sm font-medium",children:[s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),s.properties?.description&&e.jsx("p",{className:"text-xs text-default-500",children:s.properties?.description}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("input",{type:"range",min:s.properties?.min||0,max:s.properties?.max||100,step:s.properties?.step||1,value:a||s.properties?.min||0,onChange:y=>l(Number(y.target.value)),className:"flex-1 h-2 bg-default-200 rounded-lg appearance-none cursor-pointer"}),e.jsx("span",{className:"text-sm text-default-600 min-w-[3rem] text-right",children:a||s.properties?.min||0})]})]});case"phone":return e.jsx(t.Input,{...p,type:"tel",value:a||"",onValueChange:y=>l(y)});case"url":return e.jsx(t.Input,{...p,type:"url",value:a||"",onValueChange:y=>l(y)});case"button":return c(e.jsx(t.Button,{color:s.properties?.colorVariant,size:s.properties?.size,variant:s.properties?.variant,radius:s.properties?.borderRadius,isDisabled:s.advanced?.disabled||s.properties?.disabled,className:i.base,onPress:()=>{l("clicked")},...d,children:s.label},`button-${s.id}`));default:return e.jsx("div",{className:`p-4 border border-dashed border-default-300 rounded-lg text-center ${n}`,children:e.jsxs("p",{className:"text-default-500",children:["Unsupported field type: ",s.type]})})}}A.memo(q);function J({field:s,isPreview:a}){const{state:o,actions:l}=z(),{selectedFieldId:i}=o,{attributes:n,listeners:j,setNodeRef:m,transform:C,transition:c,isDragging:p}=H.useSortable({id:s.id}),r={transform:he.CSS.Transform.toString(C),transition:c},d=i===s.id,u=()=>{a||l.selectField(s.id)},f=()=>{const E={...s,id:crypto.randomUUID(),label:`${s.label} (Copy)`};l.addField(E)},h=()=>{l.deleteField(s.id)},v=()=>{l.selectField(s.id)},I=_(s,!a);return a?e.jsx("div",{className:`w-full ${I}`,children:e.jsx(q,{field:s})}):e.jsx("div",{ref:m,style:r,className:`
relative group
${p?"opacity-50 z-50":""}
${I}
`,onClick:p?void 0:u,children:e.jsx("div",{className:`
border transition-all duration-200 cursor-pointer
${d?"border-primary shadow-lg":"border-default-200 hover:border-default-300"}
${p?"shadow-2xl":""}
`,children:e.jsxs("div",{className:"p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 ",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...n,...j,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-default-100 rounded",children:e.jsx(x.GripVertical,{className:"text-default-400",size:14})}),e.jsx("span",{className:"text-xs text-default-600 font-medium",children:s.type.charAt(0).toUpperCase()+s.type.slice(1)})]}),e.jsxs(t.ButtonGroup,{size:"sm",variant:"flat",children:[e.jsx(t.Button,{isIconOnly:!0,onPress:v,color:d?"primary":"default",children:e.jsx(x.Edit,{size:16})}),e.jsx(t.Button,{isIconOnly:!0,onPress:f,children:e.jsx(x.Copy,{size:16})}),e.jsx(t.Button,{isIconOnly:!0,color:"danger",onPress:h,children:e.jsx(x.Trash2,{size:16})})]})]}),e.jsx("div",{className:"pointer-events-none",children:e.jsx(q,{field:s})}),e.jsx("div",{className:"mt-2 pt-2 border-t border-default-200",children:e.jsxs("div",{className:"flex items-center justify-between text-xs text-default-500",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Req: ",s.required?"Yes":"No"]}),s.validation&&s.validation.length>0&&e.jsxs("span",{children:["Val: ",s.validation.length]})]}),e.jsxs("span",{children:["ID: ",s.id.slice(0,6),"..."]})]})})]})})})}function Q(s){const a=[];let o=[],l=0;return s.forEach((i,n)=>{const j=$(i);i.properties?.startNewRow||!1||l+j>12||o.length===0?(o.length>0&&a.push({id:`row-${a.length}`,fields:[...o]}),o=[i],l=j):(o.push(i),l+=j),n===s.length-1&&o.length>0&&a.push({id:`row-${a.length}`,fields:[...o]})}),a}function $(s){const a=s.layout?.columnSpan||s.columnSpan;if(a)return Math.min(12,Math.max(1,a));switch(s.properties?.width){case"quarter":return 3;case"third":return 4;case"half":return 6;case"full":default:return 12}}function oe(s){return{1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4",5:"col-span-5",6:"col-span-6",7:"col-span-7",8:"col-span-8",9:"col-span-9",10:"col-span-10",11:"col-span-11",12:"col-span-12"}[s]||"col-span-12"}function ce({row:s,isPreview:a}){const{fields:o}=s;if(o.length===1&&$(o[0])===12){const l=_(o[0],!a);return e.jsx("div",{className:l,children:e.jsx(J,{field:o[0],isPreview:a},o[0].id)})}return e.jsx("div",{className:"grid grid-cols-12 gap-3",children:o.map(l=>{const i=$(l),n=oe(i),j=_(l,!a),m=[n,j].filter(Boolean).join(" ");return e.jsx("div",{className:m,children:e.jsx(J,{field:l,isPreview:a})},l.id)})})}function Z({formConfig:s,onSubmit:a,className:o=""}){const[l,i]=A.useState({}),[n,j]=A.useState({}),m=A.useCallback((r,d)=>{i(u=>({...u,[r]:d})),j(u=>{if(u[r]){const f={...u};return delete f[r],f}return u})},[]),C=()=>{const r={};return s.validation.requiredFields.forEach(d=>{const u=s.fieldMap[d],f=l[d];(!f||typeof f=="string"&&f.trim()==="")&&(r[d]=`${u.label} is required`)}),s.validation.fieldsWithValidation.forEach(d=>{const u=s.fieldMap[d],f=l[d];u.validation&&f&&u.validation.forEach(h=>{switch(h.type){case"email":/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f)||(r[d]=h.message);break;case"minLength":f.length<h.value&&(r[d]=h.message);break;case"maxLength":f.length>h.value&&(r[d]=h.message);break;case"min":parseFloat(f)<h.value&&(r[d]=h.message);break;case"max":parseFloat(f)>h.value&&(r[d]=h.message);break;case"pattern":new RegExp(h.value).test(f)||(r[d]=h.message);break}})}),j(r),Object.keys(r).length===0},c=r=>{if(r.preventDefault(),C()){const d=new Map,u=new Set;Object.keys(l).forEach(h=>{const v=s.fieldMap[h];let I=v.name;if(!I||!I.trim()){const E=v.type.replace(/[-_]/g,"_").toLowerCase();if(I=E,u.has(I)){let g=2;for(I=`${E}${g}`;u.has(I);)g++,I=`${E}${g}`}}u.add(I),d.set(h,I)});const f={};Object.entries(l).forEach(([h,v])=>{const I=d.get(h);f[I]=v}),a?.(f)}},p=r=>{const d=l[r.id]||r.defaultValue||"",u=n[r.id],f=!!u,h=W(r,!1),v={label:r.label,placeholder:r.placeholder,isRequired:r.required,description:r.properties?.description,classNames:{base:h.base,label:h.label,inputWrapper:h.inputWrapper,innerWrapper:h.innerWrapper,mainWrapper:h.mainWrapper,input:h.input,clearButton:h.clearButton,helperWrapper:h.helperWrapper,description:h.description,errorMessage:h.errorMessage},errorMessage:u,size:r.properties.size||"md",isDisabled:r.properties.disabled,isReadOnly:r.properties.readonly,color:r.properties.colorVariant,radius:r.properties.borderRadius,variant:r.properties.variant};if(r.properties.hidden)return null;const E=(()=>{const g={};return r.properties.ariaLabel&&(g["aria-label"]=r.properties.ariaLabel),r.properties.tabIndex!==void 0&&(g.tabIndex=r.properties.tabIndex),r.properties.dataAttributes&&r.properties.dataAttributes.split(",").forEach(S=>{const[T,O]=S.split("=");T&&O&&(g[T.trim()]=O.trim())}),g})();switch(r.type){case"text":return e.jsx(t.Input,{...v,type:"text",value:d,onValueChange:N=>m(r.id,N),minLength:r.properties.minLength,maxLength:r.properties.maxLength},`text-${r.id}`);case"email":return e.jsx(t.Input,{...v,type:"email",value:d,onValueChange:N=>m(r.id,N),minLength:r.properties.minLength,maxLength:r.properties.maxLength},`email-${r.id}`);case"password":return e.jsx(t.Input,{...v,type:"password",value:d,onValueChange:N=>m(r.id,N),minLength:r.properties.minLength,maxLength:r.properties.maxLength},`password-${r.id}`);case"number":return e.jsx(t.Input,{...v,type:"number",value:d,onValueChange:N=>{const F=parseFloat(N);!isNaN(F)&&(r.properties.min!==void 0&&F<r.properties.min||r.properties.max!==void 0&&F>r.properties.max)||m(r.id,N)},min:r.properties.min,max:r.properties.max,step:r.properties.step},`number-${r.id}`);case"textarea":return e.jsx(t.Textarea,{...v,value:d,onValueChange:N=>m(r.id,N),rows:r.properties.rows||4,minLength:r.properties.minLength,maxLength:r.properties.maxLength},`textarea-${r.id}`);case"select":return e.jsx(t.Select,{...v,selectedKeys:d?[d]:[],onSelectionChange:N=>{const F=Array.from(N)[0];m(r.id,F)},selectionMode:r.properties.multiple?"multiple":"single",children:r.options?.map(N=>e.jsx(t.SelectItem,{children:N.label},N.value))||[]});case"autocomplete":return e.jsx(t.Autocomplete,{...v,selectedKey:d||"",onSelectionChange:N=>{m(r.id,N)},allowsCustomValue:!0,children:r.options?.map(N=>e.jsx(t.AutocompleteItem,{children:N.label},N.value))||[]});case"radio":const g=r.properties?.orientation||"vertical",b=r.properties?.componentAlignment||"left",S=g==="horizontal"?b==="center"?"justify-center":b==="right"?"justify-end":"justify-start":b==="center"?"items-center":b==="right"?"items-end":"items-start",T=b==="center"?"text-center":b==="right"?"text-right":"text-left",O=b==="center"?"flex flex-col items-center":b==="right"?"flex flex-col items-end":"flex flex-col items-start";return e.jsx("div",{className:O,children:e.jsx(t.RadioGroup,{label:r.label,description:r.properties?.description,isRequired:r.required,value:d,onValueChange:N=>m(r.id,N),isInvalid:f,errorMessage:u,size:r.properties.size||"md",isDisabled:r.properties.disabled,color:r.properties.colorVariant,orientation:g,classNames:{base:[r.properties.marginTop,r.properties.marginBottom,r.properties.padding].filter(Boolean).join(" "),wrapper:`${r.properties.alignment||""} ${S}`,label:T,description:T},className:r.properties.customClasses,children:r.options?.map(N=>e.jsx(t.Radio,{value:N.value,children:N.label},N.value))||[]})});case"checkbox":if(r.options&&r.options.length>1){const N=r.properties?.orientation||"vertical",F=r.properties?.componentAlignment||"left",k=N==="horizontal"?"flex flex-wrap gap-4":"flex flex-col space-y-2",R=N==="horizontal"?F==="center"?"justify-center":F==="right"?"justify-end":"justify-start":F==="center"?"items-center":F==="right"?"items-end":"items-start",M=F==="center"?"text-center":F==="right"?"text-right":"text-left",V=F==="center"?"flex flex-col items-center":F==="right"?"flex flex-col items-end":"flex flex-col items-start";return e.jsxs("div",{className:`space-y-2 ${r.properties.customClasses||""} ${V}`,children:[e.jsxs("label",{className:`text-sm font-medium ${M}`,children:[r.label,r.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),r.properties?.description&&e.jsx("p",{className:`text-xs text-default-500 ${M}`,children:r.properties?.description}),e.jsx("div",{className:`${k} ${R}`,children:r.options.map(L=>e.jsx(t.Checkbox,{isSelected:d?.includes?.(L.value)||!1,onValueChange:ue=>{const X=d||[];ue?m(r.id,[...X,L.value]):m(r.id,X.filter(xe=>xe!==L.value))},size:r.properties.size||"md",isDisabled:r.properties.disabled,color:r.properties.colorVariant,radius:r.properties.borderRadius,children:L.label},L.value))}),f&&e.jsx("p",{className:"text-danger text-xs",children:u})]})}else{const N=r.properties?.componentAlignment||"left",F=N==="center"?"justify-center":N==="right"?"justify-end":"justify-start",k=N==="center"?"text-center":N==="right"?"text-right":"text-left";return e.jsxs("div",{className:`${r.properties.customClasses} ${F}`,children:[e.jsxs("label",{className:`text-sm font-medium block mb-2 ${k}`,children:[r.label,r.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),r.properties?.description&&e.jsx("p",{className:`text-xs text-default-500 mb-2 ${k}`,children:r.properties?.description}),e.jsx(t.Checkbox,{isSelected:d||!1,onValueChange:R=>m(r.id,R),size:r.properties.size||"md",isDisabled:r.properties.disabled,color:r.properties.colorVariant,radius:r.properties.borderRadius,children:"Check to confirm"}),f&&e.jsx("p",{className:`text-danger text-xs mt-1 ${k}`,children:u})]})}case"switch":const B=r.properties?.componentAlignment||"left",y=B==="center"?"flex justify-center":B==="right"?"flex justify-end":"flex justify-start";return e.jsxs("div",{className:`space-y-2 ${r.properties.customClasses||""}`,children:[e.jsx("div",{className:y,children:e.jsxs(t.Switch,{isSelected:d||!1,onValueChange:N=>m(r.id,N),size:r.properties.size||"sm",isDisabled:r.properties.disabled,color:r.properties.colorVariant,children:[r.label,r.required&&e.jsx("span",{className:"text-danger ml-1",children:"*"})]})}),r.properties?.description&&e.jsx("div",{className:y,children:e.jsx("p",{className:"text-xs text-default-500",children:r.properties?.description})}),f&&e.jsx("div",{className:y,children:e.jsx("p",{className:"text-danger text-xs",children:u})})]});case"section":return e.jsx(t.Card,{radius:r.properties.borderRadius||"sm",className:r.properties.customClasses,children:e.jsxs(t.CardBody,{className:"py-4",children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:r.label}),r.properties?.description&&e.jsx("p",{className:"text-default-600",children:r.properties?.description})]})});case"paragraph":return e.jsxs("div",{className:`py-2 ${r.properties.customClasses||""}`,children:[e.jsx("h4",{className:"text-md font-medium mb-1",children:r.label}),r.properties?.description&&e.jsx("p",{className:"text-default-600",children:r.properties?.description})]});case"phone":return e.jsx(t.Input,{...v,type:"tel",value:d,onValueChange:N=>m(r.id,N),minLength:r.properties.minLength,maxLength:r.properties.maxLength},`phone-${r.id}`);case"url":return e.jsx(t.Input,{...v,type:"url",value:d,onValueChange:N=>m(r.id,N),minLength:r.properties.minLength,maxLength:r.properties.maxLength},`url-${r.id}`);case"date":return e.jsx(t.Input,{...v,type:"date",value:d,onValueChange:N=>m(r.id,N)},`date-${r.id}`);case"time":return e.jsx(t.Input,{...v,type:"time",value:d,onValueChange:N=>m(r.id,N)},`time-${r.id}`);case"datetime":return e.jsx(t.Input,{...v,type:"datetime-local",value:d,onValueChange:N=>m(r.id,N)},`datetime-${r.id}`);case"multiselect":return e.jsx(t.Select,{...v,selectionMode:"multiple",selectedKeys:d||[],onSelectionChange:N=>{const F=Array.from(N);m(r.id,F)},children:r.options?.map(N=>e.jsx(t.SelectItem,{children:N.label},N.value))||[]});case"range":return e.jsxs("div",{className:`space-y-2 ${r.properties.customClasses||""}`,children:[e.jsxs("label",{className:"text-sm font-medium",children:[r.label,r.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),r.properties?.description&&e.jsx("p",{className:"text-xs text-default-500",children:r.properties?.description}),e.jsx(t.Slider,{value:d||r.properties.min||0,onChange:N=>{const F=Array.isArray(N)?N[0]:N;m(r.id,F)},minValue:r.properties.min||0,maxValue:r.properties.max||100,step:r.properties.step||1,className:"max-w-md",size:r.properties.size||"sm",isDisabled:r.properties.disabled,color:r.properties.colorVariant}),e.jsxs("div",{className:"text-xs text-default-500",children:["Value: ",d||r.properties.min||0]}),f&&e.jsx("p",{className:"text-danger text-xs",children:u})]});case"file":return e.jsxs("div",{className:`space-y-2 ${r.properties.customClasses||""}`,children:[e.jsxs("label",{className:"text-sm font-medium",children:[r.label,r.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),r.properties?.description&&e.jsx("p",{className:"text-xs text-default-500",children:r.properties?.description}),e.jsxs("div",{className:`border-2 border-dashed border-default-300 rounded-lg p-4 text-center hover:border-default-400 transition-colors ${r.properties.disabled?"opacity-50 cursor-not-allowed":""}`,children:[e.jsx(x.Upload,{className:"mx-auto h-8 w-8 text-default-400 mb-2"}),e.jsx("input",{type:"file",accept:r.properties.accept||"*",multiple:r.properties.multiple,disabled:r.properties.disabled,onChange:N=>{const F=r.properties.multiple?Array.from(N.target.files||[]):N.target.files?.[0];m(r.id,F)},className:"hidden",id:`file-${r.id}`}),e.jsxs("label",{htmlFor:`file-${r.id}`,className:`cursor-pointer ${r.properties.disabled?"cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"text-sm text-default-600",children:["Click to upload ",r.properties.multiple?"files":"a file"]}),d&&e.jsx("div",{className:"mt-2",children:Array.isArray(d)?e.jsx("div",{className:"flex flex-wrap gap-1",children:d.map((N,F)=>e.jsx(t.Chip,{color:"primary",size:"sm",children:N.name||`File ${F+1}`},F))}):e.jsx(t.Chip,{color:"primary",size:"sm",children:d.name||"File selected"})})]})]}),f&&e.jsx("p",{className:"text-danger text-xs",children:u})]});case"rating":const D=r.properties?.componentAlignment||"left",P=D==="center"?"flex justify-center":D==="right"?"flex justify-end":"flex justify-start";return e.jsxs("div",{className:`space-y-2 ${r.properties.customClasses||""}`,children:[e.jsx("div",{className:P,children:e.jsxs("label",{className:"text-sm font-medium",children:[r.label,r.required&&e.jsx("span",{className:"text-danger",children:"*"})]})}),r.properties?.description&&e.jsx("div",{className:P,children:e.jsx("p",{className:"text-xs text-default-500",children:r.properties?.description})}),e.jsx("div",{className:P,children:e.jsx("div",{className:"flex space-x-1",children:Array.from({length:r.properties.max||5},(N,F)=>e.jsx("button",{type:"button",disabled:r.properties.disabled,onClick:()=>m(r.id,F+1),className:`p-1 hover:scale-110 transition-transform ${r.properties.disabled?"opacity-50 cursor-not-allowed":""}`,children:e.jsx(x.Star,{className:`h-6 w-6 ${(d||0)>F?"text-yellow-400 fill-yellow-400":"text-default-300"}`})},F))})}),d&&e.jsx("div",{className:P,children:e.jsxs("div",{className:"text-sm text-default-600",children:[d," out of ",r.properties.max||5," stars"]})}),f&&e.jsx("div",{className:P,children:e.jsx("p",{className:"text-danger text-xs",children:u})})]});case"signature":return e.jsxs("div",{className:`space-y-2 ${r.properties.customClasses||""}`,children:[e.jsxs("label",{className:"text-sm font-medium",children:[r.label,r.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),r.properties?.description&&e.jsx("p",{className:"text-xs text-default-500",children:r.properties?.description}),e.jsx(ie,{value:d,onChange:N=>m(r.id,N),width:400,height:200,className:"w-full",disabled:r.properties.disabled}),f&&e.jsx("p",{className:"text-danger text-xs",children:u})]});case"pagebreak":return e.jsx("div",{className:"py-4",children:e.jsx(t.Divider,{})});case"html":return e.jsx("div",{className:"py-2",children:e.jsx("div",{dangerouslySetInnerHTML:{__html:r.defaultValue||"<div>HTML content</div>"},className:"prose prose-sm max-w-none"})});case"button":return e.jsx(t.Button,{color:r.properties.colorVariant,size:r.properties.size,variant:r.properties.variant,radius:r.properties.borderRadius,isDisabled:r.properties.disabled,className:r.properties.customClasses,onPress:()=>{console.log("Button clicked:",r.label),m(r.id,"clicked")},...E,children:r.label},`button-${r.id}`);default:return e.jsx("div",{className:"p-4 border border-dashed border-default-300 rounded-lg text-center",children:e.jsxs("p",{className:"text-default-500",children:["Unsupported field type: ",r.type]})})}};return e.jsx("div",{className:`max-w-4xl mx-auto p-6 ${o}`,children:e.jsxs(t.Card,{radius:"sm",className:"p-1",children:[e.jsx(t.CardHeader,{children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:s.metadata.title}),s.metadata.description&&e.jsx("p",{className:"text-default-600 mt-2",children:s.metadata.description})]})}),e.jsx(t.CardBody,{children:e.jsxs("form",{onSubmit:c,className:"space-y-6",children:[s.layout.rows.map(r=>e.jsx("div",{className:"grid grid-cols-12 gap-4",children:r.fields.map(d=>{const u=s.fieldMap[d],h=(()=>{const v=[];return u.properties.hideOnMobile&&v.push("hidden sm:block"),u.properties.hideOnTablet&&v.push("md:hidden lg:block"),u.properties.hideOnDesktop&&v.push("lg:hidden"),v.join(" ")})();return e.jsx("div",{className:`${u.layout.gridClass} ${h}`,children:p(u)},d)})},r.id)),e.jsx("div",{className:"flex justify-end pt-6 border-t border-divider",children:e.jsx(t.Button,{radius:"sm",type:"submit",color:"primary",size:"md",className:"w-full sm:w-auto",children:s.settings.submitButtonText})})]})})]})})}function U(s)