PageSourceSearch

https://edgemxtiming.com/assets/FormBuilderPage-Cvkl29l1.js

js edgemxtiming.com collected 2026-09-24 14:42:36 UTC 75,213 bytes, 114 lines download raw bytes

1import{c as xe,j as e,O as ge,a as Pt,b4 as Rt,v as Dt,l as $e,s as _,r as u,D as ke,w as Ne,x as Ce,y as Fe,K as Ve,B as E,m as Lt,Q as lt,a0 as _e,u as Se,M as ot,H as dt,i as ct,P as mt,V as Ot,Y as Bt,Z as Mt,_ as zt,p as ut,b as oe,X as We,I as Ye,E as Ut,L as Kt}from"./index-BCH4IFx8.js";import{B as te}from"./BpSpinner-Bqvfph1h.js";import{C as M,a as z,b as de,c as ce,d as fe}from"./card-DaE3Hwfn.js";import{L as Gt}from"./list-checks-B6tbvk60.js";import{u as Ge,a as Ht,b as Vt,c as Wt,d as Yt,e as It}from"./useBikeMakes-BpqgI2R0.js";import{u as He,a as Qt,b as Xt,c as Zt,d as Jt}from"./useConfirmationFields-DYHTMDkO.js";import{a as pt,u as es}from"./useEvents-Ck6r64Ep.js";import{A as ts,b as ss,c as is,d as as,e as rs,f as ns,g as ls,h as os}from"./alert-dialog-CJdQZTQ5.js";import{u as gt,a as Ee,d as ht,D as ft,c as xt,S as bt,v as yt,s as vt,K as jt,P as wt}from"./sortable.esm-BklNrvu_.js";import{P as Ie}from"./palette-BG3SnNBH.js";import{u as ds,s as cs,S as _t,F as kt,E as Nt,a as Ct}from"./ElementPickerDialog-DkqmGN4L.js";import{S as ms}from"./scroll-area-hNK22iDX.js";import{F as Qe,T as us,a as ps}from"./formTemplates-C2Tiiina.js";import{T as Ft}from"./triangle-alert-m5K6MENR.js";import{F as be}from"./file-text-BuQtBEyd.js";import{B as gs}from"./bike-Dps5BhUi.js";import{T as hs}from"./timer-C6AhmeTR.js";import{T as fs}from"./trophy-vILI8AG3.js";import{H as xs}from"./heart-DlsJc9lx.js";import{A as bs}from"./award-BWT5GFkf.js";import{U as St}from"./users-Cp35uMGZ.js";import{g as ys}from"./baseUrl-1OnSOMcw.js";import{L as vs}from"./lock-By386ZB3.js";import{G as js}from"./globe-U-LYO4AP.js";import{C as ws}from"./copy-CIGjrFWu.js";import{E as _s}from"./external-link-C5SQDLFH.js";import{L as Et}from"./lock-open-C7rbpyt4.js";import{E as Ue}from"./eye-EzNZygao.js";import{R as ks,a as Xe}from"./radio-group-CA2dgSse.js";import{M as Ze}from"./mail-a7kSoD61.js";import{I as Je}from"./image-CG8pJg5g.js";import{U as et}from"./upload-DCg56Dks.js";import{P as Ns}from"./plus-BhX-wvbj.js";import{a as Cs,A as Fs}from"./AIFloatingButton-CaPC8bmX.js";import{a as Ss,C as he,S as Es}from"./SetupWizard-CdXrP2Fa.js";import{S as $s}from"./switch-D8RIYbw7.js";import{S as Ts}from"./sparkles-Bw29Z9hN.js";import{W as As}from"./wand-sparkles-Bw0wz20k.js";import{L as qs}from"./layout-list-w6d1tM00.js";import"./formImageStyles-BX6ecPWb.js";import"./sanitized-html-DPAQvfI8.js";import"./purify.es-C5KSVp3G.js";import"./checkbox-D7mWENF4.js";import"./inline-rich-text-editor-DJmEa-L9.js";import"./index-CNSwMYTP.js";import"./index-7Wu8hD2L.js";import"./index-Dh4i1-J3.js";import"./underline-BSHnBAnM.js";import"./list-ordered-DMG1_MP3.js";import"./link-CRYWBnin.js";import"./unlink-bKKG2pa6.js";import"./EnduranceEntryField-Bi_0cumQ.js";import"./teams-Dc2EtOTA.js";import"./BikeMakeBadge-ogaJPLaU.js";import"./useBikeMakeLogos-B-qqkSzN.js";import"./bikeMakeStyle-RND07Se0.js";import"./TeamSignupSection-CZuvIYhy.js";import"./circle-alert-BU1rIcjn.js";import"./send-CJD-Z0Nl.js";import"./square-pen-DGpFzMTR.js";import"./trash-2-CrxPrdNf.js";import"./facebook-DP4tuXIW.js";import"./linkedin-BydiKwsK.js";import"./youtube-DPBrFqvB.js";import"./textarea-C9Po2OuC.js";import"./accordion-BhWFpyA1.js";import"./index-DKPz-1vL.js";import"./slider-DP7akdCw.js";import"./ImageStudioDialog-cxPRqL8q.js";import"./tabs-eUqQwHgv.js";import"./popover-BVAS7-gK.js";import"./type-B7yme6Ie.js";import"./square-TGQLwe2J.js";import"./minus-DdEXcKKQ.js";import"./star-CILQxhrW.js";import"./eye-off-UCwc6mQx.js";import"./arrow-up-LNTMQ3U2.js";import"./zoom-in-DpdUiuTw.js";import"./maximize-Drdx8_u2.js";import"./eraser-BjlB-yev.js";import"./save-C6KbuPF0.js";import"./layers-CuqFRUiS.js";import"./image-plus-Da7jXNUn.js";import"./arrow-left-CX5CfIFs.js";import"./phone-BoQi_8-c.js";import"./calendar-BcfRHKCP.js";import"./clock-DEKHqbRJ.js";import"./map-pin-Eqsqtagn.js";import"./share-DEkuJuTQ.js";import"./play-CSYR7nMW.js";import"./info-D-iSIGln.js";import"./circle-help-h2AkoHBZ.js";import"./trash-DEmd3ohH.js";import"./video-p_tYJZV_.js";import"./house-c8G1GW9E.js";import"./settings-BTLJRKc5.js";import"./search-GvbQAZxx.js";import"./credit-card-DWFX6dPl.js";import"./shopping-cart-B70C3eZm.js";import"./gift-D6KMZtGY.js";import"./tag-Mk6oilZH.js";import"./flag-CvB2R2ls.js";import"./useTimingEnabled-jfD7nqrK.js";import"./square-check-big-4tdOVlqy.js";import"./hash-Ca99qMeV.js";import"./file-pen-line-CUrpn3Uh.js";import"./shirt-BdRF3pfH.js";import"./file-check-Dv96N6dK.js";import"./square-plus-LeDwvcy1.js";import"./code-CKWNp3Gy.js";import"./shopping-bag-Dkab3ewO.js";import"./receipt-BKYFFUPa.js";import"./user-cog-BIIJsLPt.js";import"./shield-CYKtwov5.js";import"./calendar-days-YI2yIyuJ.js";import"./log-in-BvkXFUoR.js";import"./calendar-range-9Xefpm0m.js";import"./monitor-MHmyhpPu.js";import"./chart-column-CE7gfWWI.js";import"./megaphone-DSpUXlnT.js";import"./share-2-BRqKvXQJ.js";import"./arrow-up-down-B8egXO6U.js";import"./bell-DZvW1LWc.js";import"./ImageLightbox-ey1BtFuB.js";import"./chevron-left-BfsUvDbz.js";import"./bot-BqG0y9ls.js";import"./zap-Cjz0tJy0.js";import"./thumbs-up-lKUbd0LV.js";import"./thumbs-down-Bw1mgNVr.js";import"./crosshair-DfOELHsT.js";import"./progress-CL2A5cKM.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Ps=xe("CircleDot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Rs=xe("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Ds=xe("FileStack",[["path",{d:"M21 7h-3a2 2 0 0 1-2-2V2",key:"9rb54x"}],["path",{d:"M21 6v6.5c0 .8-.7 1.5-1.5 1.5h-7c-.8 0-1.5-.7-1.5-1.5v-9c0-.8.7-1.5 1.5-1.5H17Z",key:"1059l0"}],["path",{d:"M7 8v8.8c0 .3.2.6.4.8.2.2.5.4.8.4H15",key:"16874u"}],["path",{d:"M3 12v8.8c0 .3.2.6.4.8.2.2.5.4.8.4H11",key:"k2ox98"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Ls=xe("GlobeLock",[["path",{d:"M15.686 15A14.5 14.5 0 0 1 12 22a14.5 14.5 0 0 1 0-20 10 10 0 1 0 9.542 13",key:"qkt0x6"}],["path",{d:"M2 12h8.5",key:"ovaggd"}],["path",{d:"M20 6V4a2 2 0 1 0-4 0v2",key:"1of5e8"}
21],["rect",{width:"8",height:"5",x:"14",y:"6",rx:"1",key:"1fmf51"}]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const Ke=xe("PartyPopper",[["path",{d:"M5.8 11.3 2 22l10.7-3.79",key:"gwxi1d"}],["path",{d:"M4 3h.01",key:"1vcuye"}],["path",{d:"M22 8h.01",key:"1mrtc2"}],["path",{d:"M15 2h.01",key:"1cjtqr"}],["path",{d:"M22 20h.01",key:"1mrys2"}],["path",{d:"m22 2-2.24.75a2.9 2.9 0 0 0-1.96 3.12c.1.86-.57 1.63-1.45 1.63h-.38c-.86 0-1.6.6-1.76 1.44L14 10",key:"hbicv8"}],["path",{d:"m22 13-.82-.33c-.86-.34-1.82.2-1.98 1.11c-.11.7-.72 1.22-1.43 1.22H17",key:"1i94pl"}],["path",{d:"m11 2 .33.82c.34.86-.2 1.82-1.11 1.98C9.52 4.9 9 5.52 9 6.23V7",key:"1cofks"}],["path",{d:"M11 13c1.93 1.93 2.83 4.17 2 5-.83.83-3.07-.07-5-2-1.93-1.93-2.83-4.17-2-5 .83-.83 3.07.07 5 2Z",key:"4kbmks"}]]);function Os({items:t,isReadyToPublish:n,onJumpTo:s}){const r=t.filter(m=>m.required),d=t.filter(m=>!m.required),l=r.filter(m=>m.done).length,a=r.length;return e.jsx(M,{className:ge("border",n?"border-green-500/40 bg-green-500/5":"border-primary/30 bg-primary/5"),children:e.jsxs(z,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gt,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"font-display text-base text-foreground tracking-wide",children:"Setup Checklist"})]}),e.jsxs("span",{className:ge("text-xs font-medium px-2 py-1 rounded-full",n?"bg-green-500/15 text-green-700":"bg-primary/10 text-primary"),children:[l,"/",a," required"]})]}),e.jsx("ul",{className:"space-y-1",children:[...r,...d].map(m=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>s(m.id),className:ge("w-full flex items-center gap-3 px-2 py-2 rounded-md text-left transition-colors","hover:bg-muted/60 focus:outline-none focus:ring-2 focus:ring-ring"),children:[m.done?e.jsx(Pt,{className:"h-5 w-5 text-green-600 shrink-0"}):e.jsx(Rt,{className:ge("h-5 w-5 shrink-0",m.required?"text-amber-500":"text-muted-foreground")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:ge("text-sm font-medium",m.done?"text-muted-foreground line-through":"text-foreground"),children:[m.label,!m.required&&e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:m.description})]}),e.jsx(Dt,{className:"h-4 w-4 text-muted-foreground shrink-0"})]})},m.id))})]})})}function Bs(t){return $e({queryKey:["event-class-count",t],queryFn:async()=>{if(!t)return 0;const{count:n,error:s}=await _.from("event_classes").select("id",{count:"exact",head:!0}).eq("event_id",t);if(s)throw s;return n??0},enabled:!!t,staleTime:30*1e3})}const $t=t=>`form-builder-previewed:${t}`;function Ms(t){try{localStorage.setItem($t(t),"1")}catch{}}function zs(t){if(!t)return!1;try{return localStorage.getItem($t(t))==="1"}catch{return!1}}function Us(t){const{data:n}=pt(t),{data:s=[]}=Ge(t),{data:r=[]}=He(t),{data:d=0}=Bs(t),l=!!(n!=null&&n.name&&(n!=null&&n.event_date)&&(n!=null&&n.location)),a=s.length>0,m=d>0,y=r.length>0,v=!!(n!=null&&n.confirmation_icon_url),w=zs(t),i=[{id:"event-details",label:"Event details",description:"Name, date, and location are set",done:l,required:!0},{id:"form-fields",label:"Registration form fields",description:"Add at least one field riders fill out",done:a,required:!0},{id:"classes",label:"Race classes",description:"Add at least one class with capacity",done:m,required:!0},{id:"confirmation-fields",label:"Confirmation page",description:"Customize the thank-you screen riders see",done:y,required:!0},{id:"confirmation-image",label:"Confirmation image",description:"Upload an icon or banner image (recommended)",done:v,required:!1},{id:"preview",label:"Preview registration",description:"Open the form once to see what riders see",done:w,required:!1}],h=i.filter(j=>j.required&&!j.done),g=i.filter(j=>!j.required&&!j.done),c=h.length===0;return{items:i,missingRequired:h,missingOptional:g,isReadyToPublish:c,hasAnyConfirmationFields:y}}const we=[{value:"white",label:"White",class:"bg-white"},{value:"gray-light",label:"Light Gray",class:"bg-gray-300"},{value:"gray-medium",label:"Medium Gray",class:"bg-gray-500"},{value:"gray-dark",label:"Dark Gray",class:"bg-gray-700"},{value:"black",label:"Black",class:"bg-black"},{value:"slate",label:"Slate",class:"bg-slate-900"},{value:"zinc",label:"Zinc",class:"bg-zinc-900"},{value:"stone",label:"Stone",class:"bg-stone-900"},{value:"red",label:"Red",class:"bg-red-900"},{value:"orange",label:"Orange",class:"bg-orange-900"},{value:"amber",label:"Amber",class:"bg-amber-900"},{value:"yellow",label:"Yellow",class:"bg-yellow-900"},{value:"lime",label:"Lime",class:"bg-lime-900"},{value:"green",label:"Green",class:"bg-green-900"},{value:"emerald",label:"Emerald",class:"bg-emerald-900"},{value:"teal",label:"Teal",class:"bg-teal-900"},{value:"cyan",label:"Cyan",class:"bg-cyan-900"},{value:"sky",label:"Sky",class:"bg-sky-900"},{value:"blue",label:"Blue",class:"bg-blue-900"},{value:"indigo",label:"Indigo",class:"bg-indigo-900"},{value:"violet",label:"Violet",class:"bg-violet-900"},{value:"purple",label:"Purple",class:"bg-purple-900"},{value:"fuchsia",label:"Fuchsia",class:"bg-fuchsia-900"},{value:"pink",label:"Pink",class:"bg-pink-900"},{value:"rose",label:"Rose",class:"bg-rose-900"}];function Tt({backgroundColor:t="white",formColor:n="white",onBackgroun
26dColorChange:s,onFormColorChange:r}){const d=we.find(a=>a.value===t),l=we.find(a=>a.value===n);return e.jsxs(M,{className:"bg-card border-border h-fit sticky top-4",children:[e.jsx(de,{className:"pb-3",children:e.jsx(ce,{className:"text-sm font-medium",children:"Design Settings"})}),e.jsxs(z,{className:"space-y-4",children:[s&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ie,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Page Background"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:we.map(a=>e.jsx("button",{type:"button",onClick:()=>s(a.value),className:`w-5 h-5 rounded border-2 ${a.class} ${t===a.value?"border-primary ring-2 ring-primary ring-offset-1 ring-offset-background":"border-border"}`,title:a.label},a.value))})]}),r&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ie,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Form Color"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:we.map(a=>e.jsx("button",{type:"button",onClick:()=>r(a.value),className:`w-5 h-5 rounded border-2 ${a.class} ${n===a.value?"border-primary ring-2 ring-primary ring-offset-1 ring-offset-background":"border-border"}`,title:a.label},a.value))})]}),(s||r)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Preview"}),e.jsx("div",{className:`h-16 rounded-md border border-border flex items-center justify-center p-2 ${(d==null?void 0:d.class)||"bg-background"}`,children:e.jsx("div",{className:`w-full h-full rounded flex items-center justify-center ${(l==null?void 0:l.class)||"bg-card"}`,children:e.jsx("span",{className:`text-[10px] font-medium ${["white","gray-light","amber","yellow","lime"].includes(n)?"text-black":"text-white"}`,children:"Form"})})})]})]})]})}const Ks={Bike:gs,Timer:hs,Trophy:fs,Heart:xs,Award:bs,Users:St,FileText:be};function Gs({isOpen:t,onClose:n,onSelectTemplate:s,hasExistingFields:r,isApplying:d}){const[l,a]=u.useState(null),[m,y]=u.useState(null),v=l?Qe.filter(g=>g.category===l):Qe,w=g=>{r?y(g):s(g)},i=()=>{m&&(s(m),y(null))},h=()=>{y(null),a(null),n()};return m?e.jsx(ke,{open:t,onOpenChange:g=>!g&&h(),children:e.jsxs(Ne,{className:"max-w-md",children:[e.jsxs(Ce,{children:[e.jsxs(Fe,{className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"h-5 w-5 text-amber-500"}),"Replace Existing Fields?"]}),e.jsxs(Ve,{children:['This form already has fields. Applying the "',m.name,'" template will replace all existing fields with the template fields.']})]}),e.jsxs("div",{className:"flex gap-3 justify-end mt-4",children:[e.jsx(E,{variant:"outline",onClick:()=>y(null),disabled:d,children:"Cancel"}),e.jsx(E,{onClick:i,disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"h-4 w-4 mr-2 animate-spin"}),"Applying..."]}):"Replace Fields"})]})]})}):e.jsx(ke,{open:t,onOpenChange:g=>!g&&h(),children:e.jsxs(Ne,{className:"max-w-4xl max-h-[85vh]",children:[e.jsxs(Ce,{children:[e.jsx(Fe,{children:"Choose a Template"}),e.jsx(Ve,{children:"Start with a pre-built form template and customize it for your event"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 py-2",children:[e.jsx(E,{variant:l===null?"default":"outline",size:"sm",onClick:()=>a(null),children:"All"}),us.map(g=>e.jsx(E,{variant:l===g?"default":"outline",size:"sm",onClick:()=>a(g),children:g},g))]}),e.jsx(ms,{className:"h-[500px] pr-4",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:v.map(g=>{const c=Ks[g.icon]||be;return e.jsxs(M,{className:"cursor-pointer hover:border-primary/50 hover:bg-primary/5 transition-colors",onClick:()=>w(g),children:[e.jsxs(de,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(c,{className:"h-5 w-5 text-primary"})}),e.jsx(Lt,{variant:"secondary",className:"text-xs",children:g.category})]}),e.jsx(ce,{className:"text-base mt-2",children:g.name}),e.jsx(fe,{className:"text-xs line-clamp-2",children:g.description})]}),e.jsx(z,{className:"pt-0",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:[g.fields.length," fields included"]})})]},g.id)})})}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsx(E,{variant:"outline",onClick:h,children:"Cancel"})})]})})}function Hs(){const t=lt();return _e({mutationFn:async({eventId:n,template:s,clearExisting:r=!0})=>{if(r){const{error:i}=await _.from("form_fields").delete().eq("event_id",n);if(i)throw i}let d=0;if(!r){const{data:i}=await _.from("form_fields").select("field_order").eq("event_id",n).order("field_order",{ascending:!1}).limit(1);i&&i.length>0&&(d=i[0].field_order+1)}const{data:l}=await _.from("events").select("event_kind, parent_event_id").eq("id",n).maybeSingle(),a=(l==null?void 0:l.event_kind)==="series"||l!=null&&l.parent_event_id?"series":"single",y=ps(s.fields,a).map((i,h)=>({event_id:n,field_type:i.field_type,label:i.label,placeholder:i.placeholder||null,help_text:i.help_text||null,is_required:i.is_required||!1,field_order:d+h,width:i.width||"full",options:i.options?i.options:null})),{data:v,error:w}=await _.from("form_fields").insert(y).select();if(w)throw w;return v},onSuccess:(n,s)=>{t.invalidateQueries({queryKey:["form-fields",s.eventId]})}})}function Vs({eventId:t}){const{data:n}=$e({queryKey:["event-team-classes-banner",t],enabled:!!t,staleTime:6e4,queryFn:async()=>{const{data:s}=await _.from("event_classes").select("id, class_name, is_team_class").eq("event_id",t).eq("is_team_class",!0);return s??[]}});return!n||n.length===0?null:e.jsx(M,{className:"border-primary/40 bg-primary/5",children:e.jsxs(z,{className:"flex items-start gap-3 p-3 text-sm",children:[e.jsx(St,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:["This event has endurance team classes (",n.map(s=>s.class_name).join(", "),")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Team name, roster size limits, the team fee and captain invite links are added to the form automatically when a rider picks a team class. You don’t need to add your own “Team Name” or “Team Members” fields — a plain text field won’t create a real team."})]})]})})}function Ws(t){return t==="series"}function Ys(t){return t!=="practice"}function At(t,n){const s=[{system_key:"rider_name",field_type:"name",label:"Rider's Name",is_required:!0,reason:"Timing and results are keyed to the rider."},{system_key:"email",field_type:"email",label:"Email",is_required:!0,width:"half",reason:"Receipts, confirmations and rider alerts go here."},{system_key:"phone",field_type:"phone",label:"Phone Number",is_required:!0,width:"half",reason:"Used for race-day texts and transponder issues."},{system_key:"date_of_birth",field_type:"date",label:"Date of Birth",is_required:!0,width:"half",reason:"Drives age divisions and whether a guardian must sign."},{system_key:"gender",field_type:"gender",label:"Gender",is_required:!0,width:"half",reason:"Drives class eligibility and age/gender divisions."},{system_key:"address",field_type:"address",label:"Address",is_required:!0,reason:"Needed for membership records, insurance and mailing."},{system_key:"rider_alerts",field_type:"rider_alerts",label:"Rider Alerts",is_required:!1,reason:"Race-day texts about schedule changes and transponder issues."}];if(Ys(t)){const r=Ws(n);s.push({system_key:"class_selection",field_type:r?"season_registration":"event_registration",label:r?"Season Registration":"Class Registration",help_text:"Pick your class, bike make and number.",is_required:!0,reason:r?"Season form — riders pick rounds and classes here, with bike make and number per class.":"Riders pick their class here, with bike make and number per class.",equivalentTypes:["season_registration","event_registration","event_class_selector"]})}return s.push({system_key:"waiver",field_type:"waiver",label:"Waiver / Signature",is_required:!0,reason:"No rider may be scored without a signed release."}
26,{system_key:"guardian_info",field_type:"guardian_info",label:"Legal Guardian(s) — who is signing the waiver",is_required:!1,reason:"Shown for minors so the waiver has a valid signer."}),s}const tt=new Set(["season_registration","event_registration"]);function st(t,n){const s={missing:[],adopt:[],optionalViolations:[],typeMismatches:[],satisfied:[]},r=new Set;for(const d of n){const l=new Set([d.field_type,...d.equivalentTypes??[]]);let a=t.find(y=>y.system_key===d.system_key&&!r.has(y.id));if(a||(a=t.find(y=>l.has(y.field_type)&&!r.has(y.id))),!a){s.missing.push(d);continue}r.add(a.id),tt.has(d.field_type)&&tt.has(a.field_type)&&a.field_type!==d.field_type?s.typeMismatches.push({field:a,spec:d}):a.system_key!==d.system_key||!a.is_system?s.adopt.push({field:a,spec:d}):d.is_required&&!a.is_required?s.optionalViolations.push({field:a,spec:d}):s.satisfied.push(d)}return s}function Is(t){return $e({queryKey:["linkedRaceInfo",t],enabled:!!t,staleTime:3e4,queryFn:async()=>{const{data:n}=await _.from("events").select("id, event_kind, is_published, parent_event_id").eq("id",t).maybeSingle(),s=(n==null?void 0:n.event_kind)??null,r=[t];if(s==="series"){const{data:m}=await _.from("events").select("id").eq("parent_event_id",t);for(const y of m??[])r.push(y.id)}const{data:d}=await _.from("timing_lab_events").select("id, name, race_type, is_endurance, source_event_id").in("source_event_id",r).limit(50),l=d??[],a=l.find(m=>m.source_event_id===t)??l[0]??null;return{isLinked:!!a,raceType:a?a.is_endurance?"endurance":a.race_type??null:null,eventKind:s,labEventName:(a==null?void 0:a.name)??null,isPublished:!!(n!=null&&n.is_published),isRound:!!(n!=null&&n.parent_event_id)}}})}function qt(t){var g;const n=lt(),{data:s,isLoading:r}=Is(t),d=$e({queryKey:["requiredFormFields",t],enabled:!!t,queryFn:async()=>{const{data:c,error:j}=await _.from("form_fields").select("id, field_type, label, is_required, is_system, system_key, field_order").eq("event_id",t).order("field_order",{ascending:!0});if(j)throw j;return c??[]}}),l=s!=null&&s.isLinked?At(s.raceType,s.eventKind):[],a=st(d.data??[],l),m=((g=d.data)==null?void 0:g.length)??0,y=!!(s!=null&&s.isLinked)&&!s.isRound&&!s.isPublished,v=()=>{n.invalidateQueries({queryKey:["requiredFormFields",t]}),n.invalidateQueries({queryKey:["form-fields",t]})},w=_e({mutationFn:async()=>{if(!t||!(s!=null&&s.isLinked))return{created:0,adopted:0};if(s.isRound)return{created:0,adopted:0};const{data:c}=await _.from("form_fields").select("id, field_type, label, is_required, is_system, system_key, field_order").eq("event_id",t).order("field_order",{ascending:!0}),j=c??[],F=st(j,l);for(const{field:f,spec:$}of F.adopt)await _.from("form_fields").update({is_system:!0,system_key:$.system_key}).eq("id",f.id);let N=j.reduce((f,$)=>Math.max(f,Number($.field_order??0)),0)+1;const S=F.missing.map(f=>({event_id:t,field_type:f.field_type,label:f.label,help_text:f.help_text??null,is_required:f.is_required,field_order:N++,width:f.width??"full",is_system:!0,system_key:f.system_key}));if(S.length>0){const{error:f}=await _.from("form_fields").insert(S);if(f)throw f}return{created:S.length,adopted:F.adopt.length}},onSuccess:v}),i=_e({mutationFn:async c=>{const{error:j}=await _.from("form_fields").update({is_required:!0}).eq("id",c);if(j)throw j},onSuccess:v}),h=_e({mutationFn:async c=>{const j=a.typeMismatches.find($=>$.field.id===c);if(!j)return;const{spec:F,field:N}=j,S=!N.label||N.label==="Season Registration"||N.label==="Class Registration",{error:f}=await _.from("form_fields").update({field_type:F.field_type,is_system:!0,system_key:F.system_key,is_required:F.is_required,...S?{label:F.label}:{}}).eq("id",c);if(f)throw f},onSuccess:v});return{isLinked:!!(s!=null&&s.isLinked),hasForm:m>0,isPublished:!!(s!=null&&s.isPublished),isRound:!!(s!=null&&s.isRound),canAutoProvision:y,raceType:(s==null?void 0:s.raceType)??null,eventKind:(s==null?void 0:s.eventKind)??null,labEventName:(s==null?void 0:s.labEventName)??null,specs:l,...a,isLoading:r||d.isLoading,isComplete:!!(s!=null&&s.isLinked)&&a.missing.length===0&&a.optionalViolations.length===0&&a.typeMismatches.length===0,ensureRequiredFields:w,makeRequired:i,fixPickerType:h}}function Qs(t){const n=qt(t),{isLoading:s,isLinked:r,canAutoProvision:d,missing:l,adopt:a,ensureRequiredFields:m}=n,y=u.useRef(null);return u.useEffect(()=>{!t||s||!r||!d||l.length===0&&a.length===0||y.current!==t&&(y.current=t,m.mutate(void 0,{onSuccess:v=>{v&&v.created>0&&Se.success(`Added ${v.created} required field${v.created===1?"":"s"} for this race`)},onError:v=>Se.error("Could not add required fields: "+v.message)}))},[t,s,r,d,l.length,a.length,m]),{...n,pending:s||m.isPending||d&&(l.length>0||a.length>0)&&y.current!==t}}function Xs({eventId:t}){const{isLinked:n,isLoading:s,specs:r,missing:d,adopt:l,optionalViolations:a,typeMismatches:m,eventKind:y,labEventName:v,isRound:w,isPublished:i,ensureRequiredFields:h,makeRequired:g,fixPickerType:c}=qt(t);if(!n||s||w)return null;const j=new Set(d.map(f=>f.system_key)),F=new Map(a.map(f=>[f.spec.system_key,f.field.id])),N=new Map(m.map(f=>[f.spec.system_key,f.field.id])),S=y==="series";return e.jsx(M,{className:"border-primary/40 bg-primary/5",children:e.jsxs(z,{className:"space-y-2 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vs,{className:"h-4 w-4 text-primary"}),e.jsxs("h3",{className:"text-sm font-medium text-foreground",children:["Required for this race",v?` — ${v}`:""]})]}),(d.length>0||l.length>0)&&e.jsx(E,{size:"sm",variant:"outline",disabled:h.isPending,onClick:()=>h.mutate(),children:"Add missing fields"})]}),e.jsx("ul",{className:"space-y-1 text-xs",children:r.map(f=>{const $=j.has(f.system_key),R=F.get(f.system_key),C=N.get(f.system_key),q=$||!!R||!!C;return e.jsxs("li",{className:"flex items-start gap-2",children:[q?e.jsx(Ft,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(ot,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-primary"}),e.jsxs("span",{className:"flex-1",children:[e.jsx("span",{className:q?"text-destructive":"",children:f.label}),e.jsxs("span",{className:"text-muted-foreground",children:[" ","—"," ",C?
26S?"This is a season form but it has the single-event class picker.":"This is a single event but the form has the Season Registration picker.":f.reason]})]}),C&&e.jsx(E,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",disabled:c.isPending,onClick:()=>c.mutate(C,{onSuccess:()=>Se.success("Switched to the correct class picker"),onError:D=>Se.error("Could not switch picker: "+D.message)}),children:S?"Switch to season picker":"Switch to event picker"}),R&&e.jsx(E,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:()=>g.mutate(R),children:"Make required"})]},f.system_key)})}),i&&(d.length>0||l.length>0)&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"This form is live, so nothing is added automatically — press “Add missing fields” when you’re ready."}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"These fields are locked so the form can’t go out missing information the race needs. You can still reword labels, move them, and restyle them — you just can’t delete them."})]})})}const Zs={default:"bg-background",white:"bg-white","gray-light":"bg-gray-300","gray-medium":"bg-gray-500","gray-dark":"bg-gray-700",black:"bg-black",slate:"bg-slate-900",zinc:"bg-zinc-900",stone:"bg-stone-900",red:"bg-red-900",orange:"bg-orange-900",amber:"bg-amber-900",yellow:"bg-yellow-900",lime:"bg-lime-900",green:"bg-green-900",emerald:"bg-emerald-900",teal:"bg-teal-900",cyan:"bg-cyan-900",sky:"bg-sky-900",blue:"bg-blue-900",indigo:"bg-indigo-900",violet:"bg-violet-900",purple:"bg-purple-900",fuchsia:"bg-fuchsia-900",pink:"bg-pink-900",rose:"bg-rose-900"},it=["white","gray-light","amber","yellow","lime"],Js={default:"bg-card",white:"bg-white","gray-light":"bg-gray-300","gray-medium":"bg-gray-500","gray-dark":"bg-gray-700",black:"bg-black",slate:"bg-slate-800",zinc:"bg-zinc-800",stone:"bg-stone-800",red:"bg-red-800",orange:"bg-orange-800",amber:"bg-amber-800",yellow:"bg-yellow-800",lime:"bg-lime-800",green:"bg-green-800",emerald:"bg-emerald-800",teal:"bg-teal-800",cyan:"bg-cyan-800",sky:"bg-sky-800",blue:"bg-blue-800",indigo:"bg-indigo-800",violet:"bg-violet-800",purple:"bg-purple-800",fuchsia:"bg-fuchsia-800",pink:"bg-pink-800",rose:"bg-rose-800"};function ei({eventId:t,eventSlug:n,eventName:s,isPublished:r,backgroundColor:d,formColor:l,onPreview:a,onPublishChange:m,onBackgroundColorChange:y,onFormColorChange:v,onSwitchMode:w}){const{toast:i}=dt(),h=ct(),{currentOrganization:g}=mt(),{data:c=[],isLoading:j}=Ge(t),{data:F}=ds(t),N=Ht(),S=Vt(),f=Wt(),$=Yt(),R=Hs(),C=Us(t),{data:q=[]}=es(t),{data:D=[]}=It(t),[B,se]=u.useState(null),[W,ie]=u.useState(!1),[V,Y]=u.useState(!1),[A,L]=u.useState(!1),[I,K]=u.useState(!1),[re,Q]=u.useState(null),[ye,me]=u.useState(!1),[Te,ue]=u.useState(!1),pe=`${ys()}/org/${g==null?void 0:g.slug}/events/${n||t}`,Ae=gt(Ee(wt),Ee(jt,{coordinateGetter:vt})),ne=async()=>{Y(!0);try{const{error:o}=await _.from("events").update({is_published:!r}).eq("id",t);if(o)throw o;m(!r),i({title:r?"Event Unpublished":"Event Published!",description:r?"The registration form is no longer accessible.":"Your registration form is now live."})}catch(o){i({title:"Failed to update",description:o.message,variant:"destructive"})}finally{Y(!1)}},qe=async()=>{if(r){await ne();return}if(!C.isReadyToPublish||C.missingOptional.length>0){ue(!0);return}await ne()},ve=u.useCallback(o=>{var b;switch(o){case"form-fields":(b=document.querySelector('[data-tour="form-preview-area"]'))==null||b.scrollIntoView({behavior:"smooth",block:"start"});break;case"classes":h(`/admin/events/${t}/settings?tab=classes`);break;case"event-details":h(`/admin/events/${t}/settings`);break;case"confirmation-fields":w==null||w("confirmation");break;case"confirmation-image":w==null||w("confirmation"),setTimeout(()=>{var T;(T=document.getElementById("confirmation-image-section"))==null||T.scrollIntoView({behavior:"smooth",block:"center"})},200);break;case"preview":Ms(t),a();break}},[t,h,w,a]),Pe=async o=>{try{const{error:b}=await _.from("events").update({background_color:o}).eq("id",t);if(b)throw b;y(o),i({title:"Page background updated"})}catch(b){i({title:"Failed to update",description:b.message,variant:"destructive"})}},Re=async o=>{try{const{error:b}=await _.from("events").update({form_color:o}).eq("id",t);if(b)throw b;v(o),i({title:"Form color updated"})}catch(b){i({title:"Failed to update",description:b.message,variant:"destructive"})}},De=async()=>{await navigator.clipboard.writeText(pe),L(!0),i({title:"URL Copied!",description:"Share this link with your participants."}),setTimeout(()=>L(!1),2e3)},je=u.useCallback(async(o,b)=>{const T=Ct[o];let Z=b||T.label,H,ae;const J=cs(o,F);if(o==="rider_alerts"&&(Z=b||"Yes, I would like to receive race alerts and event updates via text message.",H="By checking this box, you consent to receive SMS/text message communications regarding this event. Message and data rates may apply. Message frequency varies. You may opt out at any time by replying STOP to any message. Reply HELP for help.",ae="true"),re!==null){const k=re,O=c.filter(le=>le.field_order>=k).map(le=>({id:le.id,field_order:le.field_order+1}));try{O.length>0&&await $.mutateAsync({eventId:t,fields:O}),await N.mutateAsync({event_id:t,field_type:o,label:Z,field_order:k,is_required:!1,width:"full",...H&&{help_text:H},...ae&&{default_value:ae},...J?{options:J}:{}}),i({title:"Field added"})}catch(le){i({title:"Failed to add field",description:le.message,variant:"destructive"})}Q(null)}
26else{const k=c.length>0?Math.max(...c.map(O=>O.field_order)):-1;try{await N.mutateAsync({event_id:t,field_type:o,label:Z,field_order:k+1,is_required:!1,width:"full",...H&&{help_text:H},...ae&&{default_value:ae},...J?{options:J}:{}}),i({title:"Field added"})}catch(O){i({title:"Failed to add field",description:O.message,variant:"destructive"})}}},[N,t,F,c,re,$,i]),Le=u.useCallback(o=>{Q(o.field_order),K(!0)},[]),Oe=u.useCallback(o=>{Q(o.field_order+1),K(!0)},[]);u.useCallback(()=>{Q(null),K(!0)},[]);const Be=u.useCallback((o,b)=>{je(o,b),K(!1)},[je]),Me=u.useCallback(o=>{se(o),ie(!0)},[]),ze=u.useCallback(async o=>{if(B)try{await S.mutateAsync({id:B.id,eventId:t,updates:o,fieldType:B.field_type}),i({title:"Field updated"})}catch(b){i({title:"Failed to update field",description:b.message,variant:"destructive"})}},[B,t,S,i]),p=u.useCallback(async o=>{const b=At(null,null).find(k=>{var O;return k.system_key===o.system_key||k.field_type===o.field_type||((O=k.equivalentTypes)==null?void 0:O.includes(o.field_type))}),{data:T,error:Z}=await _.from("form_fields").select("id, field_type, is_system, system_key").eq("event_id",t);if(Z){i({title:"Could not verify this field",description:Z.message,variant:"destructive"});return}const H=T??[];if(!H.some(k=>k.id===o.id)){await f.reset(),i({title:"Duplicate removed",description:"The form has been refreshed."}),window.location.reload();return}const J=H.some(k=>{var O;return k.id===o.id?!1:o.system_key&&k.system_key===o.system_key?!0:b?k.system_key===b.system_key||k.field_type===b.field_type||((O=b.equivalentTypes)==null?void 0:O.includes(k.field_type))===!0:!1});if(o.is_system&&!J){i({title:"This field is required",description:"The race linked to this form needs it, so it can’t be deleted.",variant:"destructive"});return}if(confirm("Are you sure you want to delete this field?"))try{await f.mutateAsync({id:o.id,eventId:t}),i({title:"Field deleted"})}catch(k){i({title:"Failed to delete field",description:k.message,variant:"destructive"})}},[f,t,i]),x=u.useCallback(async o=>{const b=c.length>0?Math.max(...c.map(T=>T.field_order)):-1;try{await N.mutateAsync({event_id:t,field_type:o.field_type,label:`${o.label} (Copy)`,placeholder:o.placeholder||void 0,help_text:o.help_text||void 0,options:o.options||void 0,is_required:o.is_required,field_order:b+1,validation_rules:o.validation_rules||void 0,default_value:o.default_value||void 0,image_url:o.image_url||void 0,width:o.width,label_styles:o.label_styles||void 0}),i({title:"Field duplicated"})}catch(T){i({title:"Failed to duplicate field",description:T.message,variant:"destructive"})}},[N,t,c,i]),P=u.useCallback(async o=>{const{active:b,over:T}=o;if(T&&b.id!==T.id){const Z=c.findIndex(k=>k.id===b.id),H=c.findIndex(k=>k.id===T.id),J=ht(c,Z,H).map((k,O)=>({id:k.id,field_order:O}));try{await $.mutateAsync({eventId:t,fields:J})}catch(k){i({title:"Failed to reorder",description:k.message,variant:"destructive"})}}},[c,t,$,i]),G=u.useCallback(async o=>{try{await R.mutateAsync({eventId:t,template:o,clearExisting:!0}),me(!1),i({title:"Template applied",description:`"${o.name}" template has been applied to your form.`})}catch(b){i({title:"Failed to apply template",description:b.message,variant:"destructive"})}},[R,t,i]);if(j)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(te,{className:"h-8 w-8 animate-spin text-primary"})});const U=l==="default"?"[&_label]:text-card-foreground [&_p]:text-muted-foreground":it.includes(l)?"[&_label]:text-gray-900 [&_p]:text-gray-700":"[&_label]:text-white [&_p]:text-gray-300";return e.jsxs("div",{className:"space-y-4","data-tour":"form-builder-container",children:[e.jsx(Vs,{eventId:t}),e.jsx(Xs,{eventId:t}),!r&&e.jsx(Os,{items:C.items,isReadyToPublish:C.isReadyToPublish,onJumpTo:ve}),e.jsx(M,{"data-tour":"form-publish-bar","data-guide":"form-publish-bar",className:`border ${r?"border-green-500/50 bg-green-500/5":"border-amber-500/50 bg-amber-500/5"}`,children:e.jsxs(z,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[r?e.jsx(js,{className:"h-5 w-5 text-green-500"}):e.jsx(Ls,{className:"h-5 w-5 text-amber-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:r?"Published":"Draft"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"Registration is open and accessible to participants":"This form is not yet visible to participants"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[r&&e.jsxs(e.Fragment,{children:[e.jsxs(E,{variant:"outline",size:"sm",onClick:De,className:"flex-1 sm:flex-none",children:[A?e.jsx(ot,{className:"h-4 w-4 mr-2"}):e.jsx(ws,{className:"h-4 w-4 mr-2"}),A?"Copied!":"Copy URL"]}),e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>window.open(pe,"_blank"),className:"flex-1 sm:flex-none",children:[e.jsx(_s,{className:"h-4 w-4 mr-2"}),"Open"]})]}),e.jsx(Ot,{children:e.jsxs(Bt,{children:[e.jsx(Mt,{asChild:!0,children:e.jsx("span",{className:r||C.isReadyToPublish?"":"cursor-not-allowed",children:e.jsxs(E,{onClick:qe,disabled:V,className:r?"bg-amber-500 hover:bg-amber-600":"bg-gradient-fire hover:opacity-90",size:"sm",children:[V&&e.jsx(te,{className:"h-4 w-4 mr-2 animate-spin"}),r?"Unpublish":"Publish"]})})}),!r&&!C.isReadyToPublish&&e.jsx(zt,{children:e.jsxs("p",{children:["Complete the setup checklist first (",C.missingRequired.length," item",C.missingRequired.length===1?"":"s"," remaining)"]})})]})})]})]}),r&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-border",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Share this URL:"}),e.jsx("code",{className:"text-xs bg-background/50 px-2 py-1 rounded border border-border block truncate",children:pe})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-xl text-foreground",children:"Form Builder"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Customize registration form for ",s]})]}),e.jsxs("div",{className:"flex gap-2","data-tour":"form-actions","data-guide":"form-actions",children:[e.jsxs(E,{onClick:()=>me(!0),variant:"outline",children:[e.jsx(Et,{className:"h-4 w-4 mr-2"})," Templates"]}),e.jsxs(E,{onClick:a,variant:"outline",children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"})," Preview Form"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-6 lg:items-start",children:[e.jsx("div",{className:"lg:col-span-1 lg:sticky lg:top-4 lg:self-start","data-tour":"form-palette","data-guide":"form-palette",children:e.jsx(Tt,{backgroundColor:d,formColor:l,onBackgroun
26dColorChange:Pe,onFormColorChange:Re})}),e.jsx("div",{className:"lg:col-span-3","data-tour":"form-preview-area","data-guide":"form-preview-area",children:e.jsx("div",{className:`rounded-lg p-4 min-h-[400px] org-branded-content org-branded-buttons ${Zs[d]||"bg-background"}`,style:{"--org-primary":(g==null?void 0:g.primary_color)||"hsl(var(--primary))"},children:e.jsx(M,{className:`border-border min-h-[360px] ${Js[l]||"bg-card"} ${U}`,children:e.jsx(z,{className:"p-6",children:c.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(be,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"font-medium text-foreground mb-1",children:"No fields yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Start building your form by adding fields from the palette"})]}):e.jsx(ft,{sensors:Ae,collisionDetection:xt,onDragEnd:P,children:e.jsx(bt,{items:c.map(o=>o.id),strategy:yt,children:e.jsx("div",{className:"grid grid-cols-12 gap-4",children:c.map((o,b)=>e.jsx(_t,{field:o,onEdit:Me,onDelete:p,onDuplicate:x,onAddBefore:Le,onAddAfter:Oe,isLightFormColor:it.includes(l),isDefaultFormColor:l==="default",isFirst:b===0,isLast:b===c.length-1,eventId:t,eventClasses:q,bikeMakes:D},o.id))})})})})})})})]}),e.jsx(kt,{field:B,allFields:c,isOpen:W,onClose:()=>ie(!1),onSave:ze}),e.jsx(Nt,{isOpen:I,onClose:()=>{K(!1),Q(null)},onSelect:Be}),e.jsx(Gs,{isOpen:ye,onClose:()=>me(!1),onSelectTemplate:G,hasExistingFields:c.length>0,isApplying:R.isPending}),e.jsx(ts,{open:Te,onOpenChange:ue,children:e.jsxs(ss,{children:[e.jsxs(is,{children:[e.jsx(as,{children:C.isReadyToPublish?"Publish without finishing optional setup?":"Setup is incomplete"}),e.jsx(rs,{asChild:!0,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{children:C.isReadyToPublish?"These optional items aren't set up yet:":"These required items must be completed before riders can register smoothly:"}),e.jsx("ul",{className:"list-disc list-inside text-sm space-y-1",children:(C.isReadyToPublish?C.missingOptional:C.missingRequired).map(o=>e.jsx("li",{className:"text-foreground",children:o.label},o.id))}),!C.isReadyToPublish&&e.jsx("p",{className:"text-xs text-muted-foreground pt-2",children:"You can still publish, but riders may see an incomplete experience."})]})})]}),e.jsxs(ns,{children:[e.jsx(ls,{children:"Go fix it"}),e.jsx(os,{onClick:async()=>{ue(!1),await ne()},className:"bg-gradient-fire hover:opacity-90",children:"Publish anyway"})]})]})})]})}function ti(t){return{default:"#1a1a1a",white:"#ffffff","gray-light":"#d1d5db","gray-medium":"#6b7280","gray-dark":"#374151",black:"#000000",slate:"#0f172a",zinc:"#18181b"}[t||"default"]||"#1a1a1a"}function si(t){return{default:"#1f2937",white:"#ffffff","gray-light":"#d1d5db","gray-medium":"#6b7280","gray-dark":"#374151",black:"#000000",slate:"#1e293b"}[t||"default"]||"#1f2937"}function ii(t){return["white","gray-light","amber","yellow","lime"].includes(t||"")}function at(t){const n={default:"#333333",white:"#ffffff",gray:"#6b7280",red:"#ef4444",orange:"#f97316",amber:"#f59e0b",yellow:"#eab308",lime:"#84cc16",green:"#22c55e",emerald:"#10b981",teal:"#14b8a6",cyan:"#06b6d4",sky:"#0ea5e9",blue:"#3b82f6",indigo:"#6366f1",violet:"#8b5cf6",purple:"#a855f7",fuchsia:"#d946ef",pink:"#ec4899",rose:"#f43f5e"};return n[t||"default"]||n.default}function ai(t,n,s){return!t||t.length===0?"":[...t].sort((r,d)=>r.field_order-d.field_order).map(r=>{var d;switch(r.field_type){case"heading":{const l=r.heading_styles||{},a=l.fontSize||24,m=l.align||"center",y=l.bold!==!1?"bold":"normal",v=l.italic?"italic":"normal",w=l.underline?"underline":"none",i=at(l.color),h=l.font==="display"?"'Bebas Neue', Impact, sans-serif":"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";return`<h2 style="font-size:${a}px;font-weight:${y};font-style:${v};text-decoration:${w};color:${i};text-align:${m};font-family:${h};margin:20px 0 10px;line-height:1.2;">${r.label||""}</h2>`}case"paragraph":{const l=r.label||r.help_text||"",m=(r.heading_styles||{}).align||"left";return`<div style="font-size:14px;color:#333;margin:10px 0;line-height:1.7;text-align:${m};"><style>.email-paragraph a{color:#f97316;text-decoration:underline;}.email-paragraph p{margin:0 0 12px 0;}.email-paragraph strong{font-weight:600;}.email-paragraph u{text-decoration:underline;}</style><div class="email-paragraph" style="text-align:${m};">${l}</div></div>`}case"divider":{const l=r.divider_styles||{},a=l.color==="default"?"#e5e7eb":at(l.color);return`<hr style="border:none;border-top:${l.width==="thick"?3:l.width==="medium"?2:1}px ${l.style||"solid"} ${a};margin:20px 0;" />`}case"image":case"banner":{if(!r.image_url)return"";const l=`<img src="${r.image_url}" alt="${r.label||"Image"}" style="max-width:100%;height:auto;border-radius:8px;" />`,a=r.field_type==="banner"&&r.options&&typeof r.options=="object"&&!Array.isArray(r.options)?r.options:null,m=a!=null&&a.linkUrl?String(a.linkUrl).trim():"",y=m&&(/^https?:\/\//i.test(m)||m.startsWith("/"))?m:"";return`<div style="text-align:center;margin:20px 0;">${y?`<a href="${y}" target="_blank" rel="noopener noreferrer" style="text-decoration:none;">${l}</a>`:l}</div>`}case"share_and_thank":return`<div style="background:#f3f4f6;border-radius:8px;padding:20px;text-align:center;margin:20px 0;"><p style="font-weight:600;color:#333;margin:0 0 10px;font-size:16px;">${r.label||"Share and Thank You!"}</p><p style="font-size:14px;color:#666;margin:0 0 15px;">
26Let your friends know you're participating!</p><div style="margin-top:15px;"><a href="https://www.facebook.com/sharer/sharer.php" target="_blank" style="display:inline-block;margin:0 8px;width:40px;height:40px;background:#1877F2;border-radius:50%;text-align:center;line-height:40px;color:white;text-decoration:none;font-size:18px;">f</a><a href="https://twitter.com/intent/tweet" target="_blank" style="display:inline-block;margin:0 8px;width:40px;height:40px;background:#000;border-radius:50%;text-align:center;line-height:40px;color:white;text-decoration:none;font-size:18px;">𝕏</a><a href="https://www.instagram.com/" target="_blank" style="display:inline-block;margin:0 8px;width:40px;height:40px;background:linear-gradient(45deg,#833AB4,#FD1D1D,#F77737);border-radius:50%;text-align:center;line-height:40px;color:white;text-decoration:none;font-size:18px;">📷</a></div>${r.help_text?`<p style="font-size:12px;color:#888;margin:15px 0 0;">${r.help_text}</p>`:""}</div>`;case"subtotal":return`<div style="background:#f9fafb;border-radius:8px;padding:16px;margin:20px 0;border:1px solid #e5e7eb;"><h3 style="font-weight:600;color:#333;margin:0 0 12px;font-size:16px;">${r.label||"Registration Summary"}</h3><table style="width:100%;font-size:14px;color:#666;border-collapse:collapse;">${s!=null&&s.name?`<tr><td style="padding:6px 0;">Event:</td><td style="padding:6px 0;text-align:right;color:#333;font-weight:500;">${s.name}</td></tr>`:""}${s!=null&&s.event_date?`<tr><td style="padding:6px 0;">Date:</td><td style="padding:6px 0;text-align:right;color:#333;font-weight:500;">${ut(s.event_date).toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})}</td></tr>`:""}<tr><td style="padding:6px 0;">Participant:</td><td style="padding:6px 0;text-align:right;color:#333;font-weight:500;">${n.first_name} ${n.last_name}</td></tr><tr><td style="padding:6px 0;">Class:</td><td style="padding:6px 0;text-align:right;color:#333;font-weight:500;">${n.racing_class}</td></tr>${n.subtotal?`<tr><td style="padding:6px 0;">Subtotal:</td><td style="padding:6px 0;text-align:right;color:#333;font-weight:500;">$${n.subtotal.toFixed(2)}</td></tr>`:""}${n.fees_total>0?`<tr><td style="padding:6px 0;">Fees:</td><td style="padding:6px 0;text-align:right;color:#333;font-weight:500;">$${n.fees_total.toFixed(2)}</td></tr>`:""}<tr><td style="padding:10px 0 0;border-top:1px solid #e5e7eb;font-weight:600;color:#333;">Total Paid:</td><td style="padding:10px 0 0;border-top:1px solid #e5e7eb;text-align:right;font-weight:700;color:#f97316;font-size:16px;">$${(d=n.total_amount)==null?void 0:d.toFixed(2)}</td></tr></table></div>`;default:return""}}).join("")}function ri(t){var $;const{backgroundColor:n,formColor:s,confirmationImageMode:r,confirmationIconUrl:d,fields:l,mockRegistration:a,eventName:m,eventDate:y,eventLocation:v}=t,w=ti(n),i=si(s),h=ii(s),g=h?"#1f2937":"#ffffff",c=h?"#6b7280":"rgba(255,255,255,0.7)",j=h?"#dcfce7":"rgba(34,197,94,0.2)",F=h?"#16a34a":"#4ade80",N=h?"#e5e7eb":"rgba(255,255,255,0.1)",S=h?"#f3f4f6":"rgba(255,255,255,0.05)",f=ai(l,a,{name:m,event_date:($=a.events)==null?void 0:$.event_date});return`<!DOCTYPE html>
27<html>
28<head>
29  <meta charset="utf-8">
30  <meta name="viewport" content="width=device-width, initial-scale=1.0">
31  <link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap" rel="stylesheet">
32</head>
33<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; margin: 0; padding: 0; background-color: ${w};">
34  <div style="padding: 40px 20px; background-color: ${w};">
35    <div style="max-width: 700px; margin: 0 auto; background-color: ${i}; border-radius: 12px; border: 1px solid ${N}; overflow: hidden;">
36      <div style="padding: 32px; text-align: center;">
37        ${r==="banner"&&d?`
38          <div style="margin: -32px -32px 24px -32px;">
39            <img src="${d}" alt="Banner" style="width: 100%; height: auto; display: block;" />
40          </div>
41        `:`
42          <div style="width: 80px; height: 80px; border-radius: 50%; background-color: ${j}; margin: 0 auto 24px; display: flex; align-items: center; justify-content: center; overflow: hidden;">
43            ${d?`
44              <img src="${d}" alt="Icon" style="width: 100%; height: 100%; object-fit: cover;" />
45            `:`
46              <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="${F}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
47                <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
48                <polyline points="22 4 12 14.01 9 11.01"/>
49              </svg>
50            `}
51          </div>
52        `}
53        <h1 style="font-family: 'Bebas Neue', Impact, sans-serif; font-size: 32px; color: ${g}; margin: 0 0 8px; letter-spacing: 1px;">
54          REGISTRATION COMPLETE!
55        </h1>
56        <p style="color: ${c}; margin: 0 0 24px; font-size: 16px;">
57          Your spot has been secured.
58        </p>
59        <div style="background-color: ${S}; border-radius: 8px; padding: 16px; margin-bottom: 24px;">
60          <p style="margin: 0 0 4px; font-size: 14px; color: ${c};">
61            Confirmation Number
62          </p>
63          <p style="margin: 0; font-size: 24px; font-weight: bold; color: #f97316; letter-spacing: 2px; font-family: 'Bebas Neue', Impact, sans-serif;">
64            ${a.confirmation_number}
65          </p>
66        </div>
67        <div style="text-align: left;">
68          ${f}
69        </div>
70        <div style="text-align: left; background-color: ${S}; border: 1px solid ${N}; border-radius: 8px; padding: 16px; margin: 24px 0;">
71          <h3 style="font-weight: 600; color: ${g}; margin: 0 0 12px; font-size: 16px;">
72            Order Summary
73          </h3>
74          <div style="font-size: 14px; color: ${c}; margin-bottom: 12px;">
75            <p style="margin: 4px 0;"><strong style="color: ${g};">Event:</strong> ${m}</p>
76            <p style="margin: 4px 0;"><strong style="color: ${g};">Date:</strong> ${y}</p>
77            <p style="margin: 4px 0;"><strong style="color: ${g};">Location:</strong> ${v}</p>
78            <p style="margin: 4px 0;"><strong style="color: ${g};">Rider:</strong> ${a.first_name} ${a.last_name}</p>
79            <p style="margin: 4px 0;"><strong style="color: ${g};">Class:</strong> ${a.racing_class}</p>
80          </div>
81          <hr style="border: none; border-top: 1px solid ${N}; margin: 12px 0;" />
82          <table style="width: 100%; font-size: 14px; color: ${c}; border-collapse: collapse;">
83            <tr>
84              <td style="padding: 4px 0;">Registration</td>
85              <td style="padding: 4px 0; text-align: right;">$${a.subtotal.toFixed(2)}</td>
86            </tr>
87            ${a.fees_total>0?`
88              <tr>
89                <td style="padding: 4px 0;">Fees</td>
90                <td style="padding: 4px 0; text-align: right;">$${a.fees_total.toFixed(2)}</td>
91              </tr>
92            `:""}
93            <tr>
94              <td colspan="2" style="padding: 0;"><hr style="border: none; border-top: 1px solid ${N}; margin: 8px 0;" /></td>
95            </tr>
96            <tr>
97              <td style="padding: 4px 0; font-weight: 600; color: ${g};">Total Paid</td>
98              <td style="padding: 4px 0; text-align: right; font-weight: 600; color: #f97316;">$${a.total_amount.toFixed(2)}</td>
99            </tr>
100          </table>
101        </div>
102        <p style="color: ${c}; font-size: 14px; margin: 0 0 24px;">
103          A confirmation email has been sent to you with all the details.
104        </p>
105      </div>
106    </div>
107    <div style="text-align: center; padding: 20px;">
108      <p style="margin: 0; color: ${c}; font-size: 12px;">
109        © ${new Date().getFullYear()} BeyondPro MX. All rights reserved.
110      </p>
111    </div>
112  </div>
113</body>
114</html>`}const ni={default:"bg-background",white:"bg-white","gray-light":"bg-gray-300","gray-medium":"bg-gray-500","gray-dark":"bg-gray-700",black:"bg-black",slate:"bg-slate-900",zinc:"bg-zinc-900",stone:"bg-stone-900",red:"bg-red-900",orange:"bg-orange-900",amber:"bg-amber-900",yellow:"bg-yellow-900",lime:"bg-lime-900",green:"bg-green-900",emerald:"bg-emerald-900",teal:"bg-teal-900",cyan:"bg-cyan-900",sky:"bg-sky-900",blue:"bg-blue-900",indigo:"bg-indigo-900",violet:"bg-violet-900",purple:"bg-purple-900",fuchsia:"bg-fuchsia-900",pink:"bg-pink-900",rose:"bg-rose-900"},li={default:"bg-card",white:"bg-white","gray-light":"bg-gray-300","gray-medium":"bg-gray-500","gray-dark":"bg-gray-700",black:"bg-black",slate:"bg-slate-800",zinc:"bg-zinc-800",stone:"bg-stone-800",red:"bg-red-800",orange:"bg-orange-800",amber:"bg-amber-800",yellow:"bg-yellow-800",lime:"bg-lime-800",green:"bg-green-800",emerald:"bg-emerald-800",teal:"bg-teal-800",cyan:"bg-cyan-800",sky:"bg-sky-800",blue:"bg-blue-800",indigo:"bg-indigo-800",violet:"bg-violet-800",purple:"bg-purple-800",fuchsia:"bg-fuchsia-800",pink:"bg-pink-800",rose:"bg-rose-800"},ee=["white","gray-light","amber","yellow","lime"];function oi({eventId:t,eventName:n,backgroundColor:s,formColor:r,confirmationIconUrl:d,confirmationImageMode:l,scrollToImage:a,onBackgroun
114dColorChange:m,onFormColorChange:y,onConfirmationIconChange:v,onConfirmationImageModeChange:w}){const{toast:i}=dt(),{data:h=[],isLoading:g}=He(t),c=Qt(),j=Xt(),F=Zt(),N=Jt(),[S,f]=u.useState(null),[$,R]=u.useState(!1),[C,q]=u.useState(!1),[D,B]=u.useState(null),[se,W]=u.useState(!1),[ie,V]=u.useState(!1),[Y,A]=u.useState(!1),[L,I]=u.useState(!1),[K,re]=u.useState("");u.useEffect(()=>{if(!a)return;const p=setTimeout(()=>{var x;(x=document.getElementById("confirmation-image-section"))==null||x.scrollIntoView({behavior:"smooth",block:"center"})},150);return()=>clearTimeout(p)},[a]);const Q={first_name:"John",last_name:"Rider",racing_class:"250cc",experience_level:"intermediate",subtotal:75,fees_total:8.5,total_amount:108.5,confirmation_number:"MX-PREVIEW1",registration_add_ons:[{id:"1",add_ons:{name:"Practice Session"},quantity:1,price_at_purchase:25}],events:{name:n,event_date:new Date(Date.now()+7*24*60*60*1e3).toISOString()}},ye=async()=>{if(!K.trim()){i({title:"Please enter an email address",variant:"destructive"});return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(K.trim())){i({title:"Please enter a valid email address",variant:"destructive"});return}A(!0);try{const{error:x}=await _.functions.invoke("send-confirmation-email",{body:{test_email:K.trim(),event_id:t}});if(x)throw x;i({title:"Test email sent",description:`Sent to ${K.trim()}`}),I(!1)}catch(x){console.error("Error sending test email:",x),i({title:"Failed to send test email",description:x.message,variant:"destructive"})}finally{A(!1)}},me=async()=>{const{data:{user:p}}=await _.auth.getUser();p!=null&&p.email&&re(p.email),I(!0)},Te=gt(Ee(wt),Ee(jt,{coordinateGetter:vt})),ue=async p=>{try{const{error:x}=await _.from("events").update({background_color:p}).eq("id",t);if(x)throw x;m(p),i({title:"Background updated"})}catch(x){i({title:"Failed to update",description:x.message,variant:"destructive"})}},pe=async p=>{try{const{error:x}=await _.from("events").update({form_color:p}).eq("id",t);if(x)throw x;y(p),i({title:"Card color updated"})}catch(x){i({title:"Failed to update",description:x.message,variant:"destructive"})}},Ae=async p=>{var P;const x=(P=p.target.files)==null?void 0:P[0];if(x){W(!0);try{const G=x.name.split(".").pop(),U=`confirmation-icons/${`${t}-confirmation-icon.${G}`}`,{error:o}=await _.storage.from("event-images").upload(U,x,{upsert:!0});if(o)throw o;const{data:{publicUrl:b}}=_.storage.from("event-images").getPublicUrl(U),{error:T}=await _.from("events").update({confirmation_icon_url:b}).eq("id",t);if(T)throw T;v(b),i({title:"Icon uploaded"})}catch(G){i({title:"Failed to upload icon",description:G.message,variant:"destructive"})}finally{W(!1)}}},ne=async()=>{try{const{error:p}=await _.from("events").update({confirmation_icon_url:null}).eq("id",t);if(p)throw p;v(null),i({title:"Icon removed"})}catch(p){i({title:"Failed to remove icon",description:p.message,variant:"destructive"})}},qe=async p=>{try{const{error:x}=await _.from("events").update({confirmation_image_mode:p}).eq("id",t);if(x)throw x;w(p),i({title:p==="banner"?"Switched to banner mode":"Switched to icon mode"})}catch(x){i({title:"Failed to update",description:x.message,variant:"destructive"})}},ve=u.useCallback(async(p,x)=>{const P=Ct[p],G=x||(P==null?void 0:P.label)||p;if(D!==null){const X=D,U=h.filter(o=>o.field_order>=X).map(o=>({id:o.id,field_order:o.field_order+1}));try{U.length>0&&await N.mutateAsync({eventId:t,fields:U}),await c.mutateAsync({event_id:t,field_type:p,label:G,field_order:X,width:"full"}),i({title:"Element added"})}catch(o){i({title:"Failed to add element",description:o.message,variant:"destructive"})}B(null)}else{const X=h.length>0?Math.max(...h.map(U=>U.field_order)):-1;try{await c.mutateAsync({event_id:t,field_type:p,label:G,field_order:X+1,width:"full"}),i({title:"Element added"})}catch(U){i({title:"Failed to add element",description:U.message,variant:"destructive"})}}},[c,t,h,D,N,i]),Pe=u.useCallback(p=>{B(p.field_order),q(!0)},[]),Re=u.useCallback(p=>{B(p.field_order+1),q(!0)},[]),De=u.useCallback(()=>{B(null),q(!0)},[]),je=u.useCallback((p,x)=>{ve(p,x),q(!1)},[ve]),Le=u.useCallback(p=>{f(p),R(!0)},[]),Oe=u.useCallback(async p=>{if(S)try{await j.mutateAsync({id:S.id,eventId:t,updates:p,fieldType:S.field_type}),i({title:"Element updated"})}catch(x){i({title:"Failed to update",description:x.message,variant:"destructive"})}},[S,t,j,i]),Be=u.useCallback(async p=>{if(confirm("Are you sure you want to delete this element?"))try{await F.mutateAsync({id:p.id,eventId:t}),i({title:"Element deleted"})}catch(x){i({title:"Failed to delete",description:x.message,variant:"destructive"})}},[F,t,i]),Me=u.useCallback(async p=>{const x=h.length>0?Math.max(...h.map(P=>P.field_order)):-1;try{await c.mutateAsync({event_id:t,field_type:p.field_type,label:`${p.label} (Copy)`,help_text:p.help_text||void 0,options:p.options||void 0,field_order:x+1,image_url:p.image_url||void 0,width:p.width,label_styles:p.label_styles||void 0}),i({title:"Element duplicated"})}catch(P){i({title:"Failed to duplicate",description:P.message,variant:"destructive"})}},[c,t,h,i]),ze=u.useCallback(async p=>{const{active:x,over:P}=p;if(P&&x.id!==P.id){const G=h.findIndex(b=>b.id===x.id),X=h.findIndex(b=>b.id===P.id),o=ht(h,G,X).map((b,T)=>({id:b.id,field_order:T}));try{await N.mutateAsync({eventId:t,fields:o})}catch(b){i({title:"Failed to reorder",description:b.message,variant:"destructive"})}}},[h,t,N,i]);return g?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(te,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(M,{className:"border border-primary/50 bg-primary/5",children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ke,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:"Confirmation Page Builder"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Customize the page users see after completing registration and payment"})]})]})})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-xl text-foreground",children:"Confirmation Page"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Design the confirmation page for ",n]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(E,{onClick:me,variant:"outline",children:[e.jsx(Ze,{className:"h-4 w-4 mr-2"}),"Send Test Email"]}),e.jsxs(E,{onClick:()=>V(!0),variant:"outline",children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"})," Preview Confirmation"]})]})]}
114),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5 gap-6 lg:items-start",children:[e.jsx("div",{className:"lg:col-span-1 lg:sticky lg:top-4 lg:self-start lg:max-h-[calc(100vh-6rem)] lg:overflow-y-auto lg:scrollbar-thin lg:scrollbar-thumb-muted lg:scrollbar-track-transparent",children:e.jsx(Tt,{backgroundColor:s,formColor:r,onBackgroundColorChange:ue,onFormColorChange:pe})}),e.jsx("div",{className:"lg:col-span-4",children:e.jsx("div",{className:`rounded-lg p-6 min-h-[400px] ${ni[s]||"bg-background"}`,children:e.jsx(M,{className:`max-w-2xl mx-auto border-border min-h-[360px] overflow-hidden ${li[r]||"bg-card"} ${ee.includes(r)?"[&_label]:text-gray-900 [&_p]:text-gray-700":"[&_label]:text-white [&_p]:text-gray-300"}`,children:e.jsxs(z,{className:"p-6",children:[e.jsx("div",{className:"flex items-center justify-center gap-4 mb-3",children:e.jsxs(ks,{value:l,onValueChange:qe,className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Xe,{value:"icon",id:"mode-icon"}),e.jsxs(oe,{htmlFor:"mode-icon",className:"text-xs cursor-pointer flex items-center gap-1",children:[e.jsx(Ps,{className:"h-3 w-3"})," Icon"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Xe,{value:"banner",id:"mode-banner"}),e.jsxs(oe,{htmlFor:"mode-banner",className:"text-xs cursor-pointer flex items-center gap-1",children:[e.jsx(Je,{className:"h-3 w-3"})," Banner"]})]})]})}),e.jsxs("div",{id:"confirmation-image-section",className:"text-center mb-6 scroll-mt-24",children:[l==="banner"?e.jsxs("div",{className:"relative group/icon -mx-6 mb-4",children:[d?e.jsx("img",{src:d,alt:"Confirmation banner",className:"w-full h-auto object-contain"}):e.jsxs("div",{className:`w-full h-32 rounded-lg flex flex-col items-center justify-center border-2 border-dashed ${ee.includes(r)?"border-gray-300 bg-gray-50":"border-white/20 bg-white/5"}`,children:[e.jsx(Je,{className:`h-8 w-8 mb-1 ${ee.includes(r)?"text-gray-400":"text-white/40"}`}),e.jsx("p",{className:`text-xs ${ee.includes(r)?"text-gray-400":"text-white/40"}`,children:"Upload a banner"})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover/icon:opacity-100 transition-opacity rounded-lg bg-black/30",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(oe,{htmlFor:"icon-upload",className:"w-10 h-10 rounded-full bg-background/90 flex items-center justify-center cursor-pointer hover:bg-background border border-border",children:se?e.jsx(te,{className:"h-4 w-4 animate-spin text-muted-foreground"}):e.jsx(et,{className:"h-4 w-4 text-muted-foreground"})}),d&&e.jsx("button",{onClick:ne,className:"w-10 h-10 rounded-full bg-destructive/90 flex items-center justify-center cursor-pointer hover:bg-destructive border border-destructive",children:e.jsx(We,{className:"h-4 w-4 text-destructive-foreground"})})]})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Recommended: 600 × 200px (landscape)"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Recommended: 64 × 64px"}),e.jsxs("div",{className:"relative inline-block group/icon",children:[e.jsx("div",{className:`w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4 overflow-hidden ${ee.includes(r)?"bg-green-100":"bg-green-500/20"}`,children:d?e.jsx("img",{src:d,alt:"Confirmation icon",className:"w-full h-full object-cover"}):e.jsx(Ke,{className:`h-8 w-8 ${ee.includes(r)?"text-green-600":"text-green-400"}`})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover/icon:opacity-100 transition-opacity",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(oe,{htmlFor:"icon-upload",className:"w-8 h-8 rounded-full bg-background/90 flex items-center justify-center cursor-pointer hover:bg-background border border-border",children:se?e.jsx(te,{className:"h-4 w-4 animate-spin text-muted-foreground"}):e.jsx(et,{className:"h-4 w-4 text-muted-foreground"})}),d&&e.jsx("button",{onClick:ne,className:"w-8 h-8 rounded-full bg-destructive/90 flex items-center justify-center cursor-pointer hover:bg-destructive border border-destructive",children:e.jsx(We,{className:"h-4 w-4 text-destructive-foreground"})})]})})]})]}),e.jsx(Ye,{id:"icon-upload",type:"file",accept:"image/*",className:"hidden",onChange:Ae,disabled:se}),e.jsx("p",{className:`text-sm ${ee.includes(r)?"text-gray-500":"text-white/60"}`,children:"Confirmation Number"}),e.jsx("p",{className:"font-display text-2xl text-primary",children:"MX-EXAMPLE"})]}),h.length===0?e.jsxs("div",{onClick:De,className:"flex flex-col items-center justify-center py-8 text-center border-2 border-dashed border-border rounded-lg cursor-pointer hover:border-primary/50 hover:bg-primary/5 transition-colors group",children:[e.jsx(Ns,{className:"h-8 w-8 text-muted-foreground mb-2 group-hover:text-primary transition-colors"}),e.jsx("p",{className:"text-sm text-muted-foreground group-hover:text-foreground transition-colors mb-1",children:"Click to add elements"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Build your confirmation page"})]}):e.jsx(ft,{sensors:Te,collisionDetection:xt,onDragEnd:ze,children:e.jsx(bt,{items:h.map(p=>p.id),strategy:yt,children:e.jsx("div",{className:"grid grid-cols-12 gap-4",children:h.map((p,x)=>e.jsx(_t,{field:p,onEdit:Le,onDelete:Be,onDuplicate:Me,onAddBefore:Pe,onAddAfter:Re,isLightFormColor:ee.includes(r),isFirst:x===0,isLast:
114x===h.length-1},p.id))})})})]})})})})]}),e.jsx(kt,{field:S,allFields:h,isOpen:$,onClose:()=>R(!1),onSave:Oe}),e.jsx(Nt,{isOpen:C,onClose:()=>{q(!1),B(null)},onSelect:je}),e.jsx(ke,{open:ie,onOpenChange:V,children:e.jsxs(Ne,{className:"max-w-3xl max-h-[90vh] overflow-hidden p-0",children:[e.jsx(Ce,{className:"p-6 pb-2",children:e.jsxs(Fe,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"h-5 w-5"}),"Email Preview — Exactly as recipients will see it"]})}),e.jsx("div",{className:"px-6 pb-6 overflow-hidden",style:{height:"calc(90vh - 80px)"},children:e.jsx("iframe",{title:"Email Preview",srcDoc:ri({backgroundColor:s,formColor:r,confirmationImageMode:l,confirmationIconUrl:d,fields:h,mockRegistration:Q,eventName:n,eventDate:ut(Q.events.event_date).toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"}),eventLocation:"BeyondPro MX Track"}),className:"w-full h-full border-0 rounded-lg",sandbox:"allow-same-origin"})})]})}),e.jsx(ke,{open:L,onOpenChange:I,children:e.jsxs(Ne,{className:"sm:max-w-md",children:[e.jsx(Ce,{children:e.jsx(Fe,{children:"Send Test Email"})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(oe,{htmlFor:"test-email",children:"Email Address"}),e.jsx(Ye,{id:"test-email",type:"email",placeholder:"Enter email address",value:K,onChange:p=>re(p.target.value),onKeyDown:p=>{p.key==="Enter"&&ye()}}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The confirmation email will be sent to this address with sample data."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(E,{variant:"outline",onClick:()=>I(!1),children:"Cancel"}),e.jsx(E,{onClick:ye,disabled:Y,children:Y?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"h-4 w-4 mr-2 animate-spin"}),"Sending..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ze,{className:"h-4 w-4 mr-2"}),"Send Email"]})})]})]})]})})]})}const rt=[{id:"start",title:"Starting Point"},{id:"fields",title:"Essential Fields"},{id:"layout",title:"Page Layout"},{id:"confirmation",title:"Confirmation"}],nt=[{id:"name",label:"Rider Name",defaultOn:!0},{id:"email",label:"Email Address",defaultOn:!0},{id:"phone",label:"Phone Number",defaultOn:!0},{id:"dob",label:"Date of Birth",defaultOn:!0},{id:"class",label:"Class Selector",defaultOn:!0},{id:"bike_number",label:"Bike/Rider Number",defaultOn:!1},{id:"emergency_contact",label:"Emergency Contact",defaultOn:!1},{id:"waiver",label:"Waiver/Signature",defaultOn:!1}];function di({eventName:t,onComplete:n,onSkip:s,onSelectTemplate:r}){const[d,l]=u.useState(0),[a,m]=u.useState(null),[y,v]=u.useState(Object.fromEntries(nt.map(c=>[c.id,c.defaultOn]))),[w,i]=u.useState(!1),h=()=>{if(d===0&&a==="template"){r();return}l(c=>Math.min(c+1,rt.length-1))},g=()=>{const c=Object.entries(y).filter(([,j])=>j).map(([j])=>j);n({startFrom:a||"blank",includeFields:c,multiPage:w})};return e.jsxs(Ss,{steps:rt,activeStep:d,onNext:h,onBack:()=>l(c=>Math.max(c-1,0)),onStepClick:c=>l(c),onFinish:g,finishLabel:"Create Form",children:[d===0&&e.jsxs(M,{children:[e.jsxs(de,{children:[e.jsx(ce,{children:"How would you like to start?"}),e.jsxs(fe,{children:['Choose a starting point for your "',t,'" registration form']})]}),e.jsxs(z,{className:"space-y-3",children:[e.jsx(he,{icon:e.jsx(Et,{className:"h-5 w-5"}),label:"Start from a template",description:"Choose from pre-built form templates for different event types",selected:a==="template",onClick:()=>m("template")}),e.jsx(he,{icon:e.jsx(be,{className:"h-5 w-5"}),label:"Start blank",description:"Build your form from scratch with essential fields",selected:a==="blank",onClick:()=>m("blank")}),e.jsx(he,{icon:e.jsx(Es,{className:"h-5 w-5"}),label:"Skip wizard",description:"Go directly to the drag-and-drop editor",selected:!1,onClick:s})]})]}),d===1&&e.jsxs(M,{children:[e.jsxs(de,{children:[e.jsx(ce,{children:"Essential Fields"}),e.jsx(fe,{children:"Select the fields to include in your registration form. You can add more later."})]}),e.jsx(z,{className:"space-y-3",children:nt.map(c=>e.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-border last:border-0",children:[e.jsx(oe,{htmlFor:`field-${c.id}`,className:"cursor-pointer",children:c.label}),e.jsx($s,{id:`field-${c.id}`,checked:y[c.id]||!1,onCheckedChange:j=>v(F=>({...F,[c.id]:j}))})]},c.id))})]}),d===2&&e.jsxs(M,{children:[e.jsxs(de,{children:[e.jsx(ce,{children:"Page Layout"}),e.jsx(fe,{children:"Choose how your form is organized"})]}),e.jsxs(z,{className:"space-y-3",children:[e.jsx(he,{icon:e.jsx(Rs,{className:"h-5 w-5"}),label:"Single page",description:"All fields appear on one page — simple and quick",selected:!w,onClick:()=>i(!1)}),e.jsx(he,{icon:e.jsx(Ds,{className:"h-5 w-5"}),label:"Multi-page with steps",description:"Split the form into sections with a progress indicator",selected:w,onClick:()=>i(!0)})]})]}),d===3&&e.jsxs(M,{children:[e.jsxs(de,{children:[e.jsx(ce,{children:"Confirmation Page"}),e.jsx(fe,{children:"After completing the wizard, you can customize the confirmation page that riders see after registering using the Confirmation Builder."})]}),e.jsx(z,{children:e.jsxs("div",{className:"bg-muted/50 rounded-lg p-6 text-center space-y-2",children:[e.jsx(Ts,{className:"h-8 w-8 mx-auto text-primary"}),e.jsx("p",{className:"font-medium",children:"Your form is ready to create!"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'Click "Create Form" to generate your registration form. You can then customize it further in the drag-and-drop editor and set up your confirmation page.'})]})})]})]})}const qr=()=>{const{eventId:t}
114=Ut(),n=ct(),{data:s,isLoading:r}=pt(t),{organizations:d,currentOrganization:l,setCurrentOrganization:a}=mt(),{data:m}=Ge(t),{data:y}=He(t),[v,w]=u.useState(!1),[i,h]=u.useState("default"),[g,c]=u.useState("default"),[j,F]=u.useState(null),[N,S]=u.useState("icon"),[f,$]=u.useState("form"),[R,C]=u.useState(!1),[q,D]=u.useState(null),[B,se]=u.useState(!1),W=u.useRef(!1),{pending:ie}=Qs(t),V=(A,L)=>{A==="confirmation"&&(W.current=!0,se(!!(L!=null&&L.scrollToImage))),$(A)};u.useEffect(()=>{f==="confirmation"&&(W.current=!0)},[f]);const Y=!W.current&&Array.isArray(y)&&y.length===0&&Array.isArray(m)&&m.length>0&&!v;return u.useEffect(()=>{if(!Y)return;const A=L=>{L.preventDefault(),L.returnValue=""};return window.addEventListener("beforeunload",A),()=>window.removeEventListener("beforeunload",A)},[Y]),u.useEffect(()=>{q===null&&m!==void 0&&!ie&&D(Array.isArray(m)&&m.length===0)},[m,q,ie]),u.useEffect(()=>{s&&(w(s.is_published??!1),h(s.background_color??"default"),c(s.form_color??"default"),F(s.confirmation_icon_url??null),S(s.confirmation_image_mode??"icon"))},[s]),u.useEffect(()=>{const A=s==null?void 0:s.organization_id;if(!A||d.length===0||(l==null?void 0:l.id)===A)return;const L=d.find(I=>I.id===A);L&&a(L)},[s,d,l==null?void 0:l.id,a]),r?e.jsx(e.Fragment,{children:e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(te,{className:"h-8 w-8 animate-spin text-primary"})})}):s?e.jsx(e.Fragment,{children:e.jsxs("section",{className:"py-8 bg-background min-h-screen",children:[e.jsx("div",{className:`transition-all duration-300 ${R?"mr-80":""}`,children:e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsx("div",{className:"flex items-center justify-end mb-6",children:e.jsxs("div",{className:"flex items-center gap-2",children:[!q&&e.jsxs(E,{variant:"outline",size:"sm","data-guide":"form-guided-setup",onClick:()=>D(!0),className:"gap-2",children:[e.jsx(As,{className:"h-4 w-4"})," Guided Setup"]}),q&&e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>D(!1),className:"gap-2",children:[e.jsx(qs,{className:"h-4 w-4"})," Manual Mode"]}),!q&&e.jsxs("div",{className:"flex items-center gap-1 p-1 bg-muted rounded-lg","data-tour":"form-mode-toggle","data-guide":"form-mode-toggle",children:[e.jsxs(E,{variant:f==="form"?"default":"ghost",size:"sm",onClick:()=>V("form"),className:"gap-2",children:[e.jsx(be,{className:"h-4 w-4"}),"Form Builder"]}),e.jsxs(E,{variant:f==="confirmation"?"default":"ghost",size:"sm",onClick:()=>V("confirmation"),className:"gap-2",children:[e.jsx(Ke,{className:"h-4 w-4"}),"Confirmation Builder"]})]})]})}),q?e.jsx(di,{eventName:s.name,onComplete:()=>D(!1),onSkip:()=>D(!1),onSelectTemplate:()=>D(!1)}):f==="form"?e.jsx(ei,{eventId:s.id,eventSlug:s.slug,eventName:s.name,isPublished:v,backgroundColor:i,formColor:g,onPreview:()=>n(`/org/${l==null?void 0:l.slug}/events/${s.slug||s.id}?preview=true`),onPublishChange:w,onBackgroundColorChange:h,onFormColorChange:c,onSwitchMode:A=>V(A,{scrollToImage:A==="confirmation"})}):e.jsx(oi,{eventId:s.id,eventName:s.name,backgroundColor:i,formColor:g,confirmationIconUrl:j,confirmationImageMode:N,scrollToImage:B,onBackgroundColorChange:h,onFormColorChange:c,onConfirmationIconChange:F,onConfirmationImageModeChange:S})]})}),!R&&e.jsx(Cs,{onClick:()=>C(!0)}),e.jsx(Fs,{pageContext:"admin-form-builder",isOpen:R,onClose:()=>C(!1),className:"fixed right-0 top-0 w-80 h-screen z-40"})]})}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"min-h-screen flex flex-col items-center justify-center",children:[e.jsx("h1",{className:"font-display text-4xl text-foreground mb-4",children:"Event Not Found"}),e.jsx(E,{asChild:!0,children:e.jsx(Kt,{to:"/admin",children:"Back to Dashboard"})})]})})};export{qr as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.