1import{j as e,b as L}from"./query-Q_ThwKGI.js";import{T as B,a as A,b as N,c as v}from"./tabs-CMLwnORc.js";import{F as G,O as J}from"./OptinPage-S5pcXiel.js";import{u as M,r as h,R as S}from"./react-vendor-wefok28f.js";import{s as x}from"./client-DjLwxtrO.js";import{h as _,u as H}from"./index-C4Kq7kkR.js";import{v as F}from"./types-C-Liuvzf.js";import{v as T,d as K}from"./checkIn-CbxIkDcA.js";import{initializeTracking as Q}from"./trackingScripts-1XOvU7Jx.js";import{C as y}from"./card-DYyqUxY6.js";import{B as E}from"./button-DrepnwkX.js";import{I as V}from"./input-Cu6Tiemi.js";import{L as j,O as I}from"./icons-By8asZST.js";import"./index-lwN0GFAE.js";import"./index-CryppvJw.js";import"./textarea-DJfrjX2A.js";import"./label-Ch0F7L4t.js";import"./checkbox-Gmf95s3M.js";import"./index-CSO0Tzy2.js";import"./radio-group-CTqv7D_7.js";import"./select-DECm7gW5.js";import"./index-DviHZN-M.js";import"./useTranslation-DNoH3foE.js";import"./differenceInDays-3zXMvGNK.js";import"./format-NnwPU_mP.js";import"./pt-BR-9-TZCPQM.js";import"./useLogger-CDsXA2_R.js";import"./FormUnavailableError-D5g8vwrQ.js";import"./MarkdownText-DKqKFDLC.js";import"./supabase-COHOFxoQ.js";const C=({children:r,headerColor:n="#222222"})=>{const l=i=>{const t=_(i,.03),u=_(i,.07);return`linear-gradient(135deg, ${t} 0%, ${u} 100%)`};return e.jsx("div",{className:"min-h-screen flex items-center justify-center p-4",style:{background:l(n)},children:e.jsx("div",{className:"container max-w-xl mx-auto",children:e.jsx(y,{className:"p-6 space-y-6 bg-white/90 backdrop-blur-md",children:r})})})},Y=({settings:r})=>e.jsxs("div",{className:"text-center space-y-4 mb-8 animate-fade-in",children:[e.jsx("h2",{className:`font-poppins font-bold text-${r.title_size} md:text-${r.title_size}`,style:{color:r.title_color},children:r.title}
1),r.subtitle&&e.jsx("p",{className:`font-poppins text-${r.subtitle_size} md:text-${r.subtitle_size}`,style:{color:r.subtitle_color},children:r.subtitle})]}),U=({email:r,setEmail:n,onSubmit:l,isSubmitting:i,settings:t})=>e.jsxs("form",{onSubmit:l,className:"space-y-4 animate-fade-in",children:[e.jsx(V,{type:"email",placeholder:"Enter your email",value:r,onChange:u=>n(u.target.value),required:!0,className:"w-full transition-all duration-200",style:{borderColor:t.border_color}}),e.jsx(E,{type:"submit",disabled:i,className:`w-full font-medium py-3 transition-all duration-200 ${t.button_effect?"animated-button":""}`,size:t.button_size,style:{backgroundColor:t.button_color,backgroundImage:t.button_effect?`linear-gradient(45deg, ${t.button_color} 0%, ${_(t.button_color,.8)} 100%)`:"none"},children:i?e.jsx(j,{className:"h-5 w-5 animate-spin"}):t.button_text})]}),W=({formData:r,setFormData:n,onSubmit:l,isSubmitting:i,settings:t,theme:u,fields:c})=>e.jsxs("form",{onSubmit:l,className:"space-y-6 animate-fade-in",children:[e.jsx("div",{className:"text-center text-sm mb-6",style:{color:t.subtitle_color},children:"Please complete your registration to check in"}),e.jsx(G,{fields:c,formData:r,setFormData:n,theme:u}),e.jsx(E,{type:"submit",disabled:i,className:`w-full font-medium py-3 transition-all duration-200 ${t.button_effect?"animated-button":""}`,size:t.button_size,style:{backgroundColor:t.button_color,backgroundImage:t.button_effect?`linear-gradient(45deg, ${t.button_color} 0%, ${_(t.button_color,.8)} 100%)`:"none"},children:i?e.jsx(j,{className:"h-5 w-5 animate-spin"}):t.button_text}),t.footer_text&&e.jsx("p",{className:"text-sm text-center animate-fade-in mt-6",style:{color:t.subtitle_color},children:t.footer_text})]}),X=({theme:r,settings:n})=>{const{formId:l}=M(),{toast:i}=H(),[t,u]=h.useState(""),[c,w]=h.useState({}),[k,f]=h.useState(!1),[g,D]=h.useState(!1),m=l,{data:a,isLoading:O,error:b}=L({queryKey:["form-checkin",m],queryFn:async()=>{if(!m)throw new Error("No form ID provided");const{data:d,error:s}=await x.from("forms").select(` 2 *, 3 form_fields (*) 4 `).eq("id",m).maybeSingle();if(s)throw s;if(!d)throw new Error("Form not found");return d}}),o=S.useMemo(()=>a!=null&&a.check_in_settings?T(a.check_in_settings):n||K,[a,n]),$=S.useMemo(()=>a!=null&&a.theme?F(a.theme):r,[a,r]);h.useEffect(()=>{a&&Q(a)},[a]);const R=async d=>{d.preventDefault(),f(!0);try{const{data:s}=await x.from("leads").select("*").eq("form_id",m).eq("email",t).maybeSingle();if(s){const{error:p}=await x.from("leads").update({is_checked_in:!0,checked_in_at:new Date().toISOString()}).eq("id",s.id);if(p)throw p;if(o!=null&&o.webhook_url)try{await fetch(o.webhook_url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({formId:m,formName:a==null?void 0:a.name,type:"check_in",leadData:{...s,is_checked_in:!0,checked_in_at:new Date().toISOString()},timestamp:new Date().toISOString()})})}catch(P){console.error("Check-in webhook failed:",P)}i({title:"Success",description:"You have been checked in successfully!"}),o!=null&&o.post_checkin_url&&(window.location.href=o.post_checkin_url)}else w({email:t}),D(!0)}catch{i({title:"Error",description:"Failed to check in. Please try again.",variant:"destructive"})}finally{f(!1)}},z=async d=>{d.preventDefault(),f(!0);try{const{error:s}=await x.from("leads").insert({form_id:m,email:c.email,name:c.name,phone:c.phone,additional_data:c,is_registered:!0,is_checked_in:!0,checked_in_at:new Date().toISOString(),registered_at:new Date().toISOString()});if(s)throw s;if(o!=null&&o.webhook_url)try{await fetch(o.webhook_url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({formId:m,formName:a==null?void 0:a.name,type:"registration_and_check_in",submissionData:c,leadData:{form_id:m,email:c.email,name:c.name,phone:c.phone,additional_data:c,is_registered:!0,is_checked_in:!0,checked_in_at:new Date().toISOString(),registered_at:new Date().toISOString()},timestamp:new Date().toISOString()})})}catch(p){console.error("Registration webhook failed:",p)}i({title:"Success",description:"Registration and check-in completed successfully!"}),o!=null&&o.post_checkin_url&&(window.location.href=o.post_checkin_url)}catch{i({title:"Error",description:"Failed to register. Please try again.",variant:"destructive"})}finally{f(!1)}};if(O)return e.jsx(C,{children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(j,{className:"h-8 w-8 animate-spin text-primary"})})});if(b)return e.jsxs(y,{className:"w-full max-w-md mx-auto p-6 text-center space-y-4 animate-fade-in",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx(I,{className:"h-12 w-12 text-red-500"})}),e.jsx("h2",{className:"text-lg font-semibold text-red-600",children:"Error Loading Form"}),e.jsx("p",{className:"text-muted-foreground",children:b instanceof Error?b.message:"Form not found"})]});if(!a)return e.jsxs(y,{className:"w-full max-w-md mx-auto p-6 text-center space-y-4 animate-fade-in",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx(I,{className:"h-12 w-12 text-red-500"})}),e.jsx("h2",{className:"text-lg font-semibold text-red-600",children:"Form Not Found"}),e.jsx("p",{className:"text-muted-foreground",children:"The form you're looking for doesn't exist or has been deleted."})]});const q=a.form_fields?[...a.form_fields].sort((d,s)=>d.order_index-s.order_index):[];return e.jsxs(C,{headerColor:o.title_color,children:[e.jsx(Y,{settings:o}),g?e.jsx(W,{formData:c,setFormData:w,onSubmit:z,isSubmitting:k,settings:o,theme:$,fields:q}):e.jsx(U,{email:t,setEmail:u,onSubmit:R,isSubmitting:k,settings:o}),o.footer_text&&!g&&e.jsx("p",{className:"text-sm text-center animate-fade-in mt-6",style:{color:o.subtitle_color},children:o.footer_text})]})},Z=({theme:r,checkInSettings:n})=>(console.log("FormTabs received theme:",r),e.jsxs(B,{defaultValue:"optin",className:"w-full",children:[e.jsxs(A,{className:"grid w-full grid-cols-2",children:[e.jsx(N,{value:"optin",children:"Registration"}),e.jsx(N,{value:"checkin",children:"Check-in"})]}),e.jsx(v,{value:"optin",children:e.jsx(J,{theme:r})}),e.jsx(v,{value:"checkin",children:e.jsx(X,{theme:r,settings:n})})]}
4)),Te=({formId:r,theme:n,checkInSettings:l})=>{const i=n||F(null),t=l||T(null);return e.jsx("div",{className:"w-full",children:e.jsx(Z,{theme:i,checkInSettings:t})})};export{Te 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.