1import{j as r,b as F}from"./query-Q_ThwKGI.js";import{r as d,R as L,u as W,i as $}from"./react-vendor-wefok28f.js";import{s as b}from"./client-DjLwxtrO.js";import{B as k}from"./button-DrepnwkX.js";import{S as P}from"./scroll-area-D3rGvhtF.js";import{I as z}from"./input-Cu6Tiemi.js";import{u as R,P as q}from"./index-C4Kq7kkR.js";import{U as D,q as O}from"./icons-By8asZST.js";import{u as V}from"./useLogger-CDsXA2_R.js";import{initializeTracking as B,trackPageView as Y}from"./trackingScripts-1XOvU7Jx.js";import{b as G,a as H}from"./utmUtils-B5TLLIZ-.js";import{M as E}from"./MarkdownText-DKqKFDLC.js";import"./supabase-COHOFxoQ.js";import"./index-CryppvJw.js";const U=({webinarId:m,userEmail:u="You"})=>{const[l,c]=d.useState([]),[i,_]=d.useState(""),[T,j]=d.useState(null),C=d.useRef(null),s=d.useRef(null),w=d.useRef([]),{toast:e}=R(),S=()=>{var a;(a=C.current)==null||a.scrollIntoView({behavior:"smooth"})};d.useEffect(()=>{S()},[l]),d.useEffect(()=>()=>{w.current.forEach(a=>clearTimeout(a)),w.current=[]},[m]),d.useEffect(()=>{const a=async()=>{const{data:f,error:g}=await b.from("webinars").select("ghost_participants").eq("id",m).single();if(g){console.error("Error fetching webinar:",g);return}f!=null&&f.ghost_participants&&j(f.ghost_participants)},y=async()=>{console.log("Fetching ghost comments for webinar:",m);const{data:f,error:g}=await b.from("webinar_ghost_comments").select("*").eq("webinar_id",m).order("delay_time",{ascending:!0});if(g){console.error("Error fetching ghost comments:",g),e({title:"Error",description:"Failed to fetch ghost comments",variant:"destructive"});return}console.log("Retrieved ghost comments:",f),f&&(w.current.forEach(h=>clearTimeout(h)),w.current=[],f.forEach(h=>{const t=setTimeout(()=>{h.is_participant_event&&h.participant_count!==null?j(h.participant_count):c(n=>[{id:h.id,username:h.username||"System",message:h.comment_text,timestamp:new Date,isGhost:!0},...n].slice(0,10))},h.delay_time*1e3);w.current.push(t)}))};return a(),y(),s.current=b.channel(`webinar-${m}`).on("broadcast",{event:"chat-message"},({payload:f})=>{console.log("Received chat message:",f),c(g=>[f,...g].slice(0,10))}).subscribe(),()=>{s.current&&b.removeChannel(s.current)}},[m,e]);const v=async a=>{if(a.preventDefault(),!i.trim())return;const y={id:crypto.randomUUID(),username:u,message:i,timestamp:new Date};c(f=>[y,...f].slice(0,10)),s.current.send({type:"broadcast",event:"chat-message",payload:y}),_("")};return r.jsxs("div",{className:"flex flex-col h-full bg-white/95 backdrop-blur-md rounded-xl shadow-lg",children:[r.jsx("div",{className:"p-2 md:p-3 border-b border-gray-200",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("h3",{className:"font-semibold text-base",children:"Live Chat"}),T!==null&&r.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[r.jsx(D,{className:"w-4 h-4"}),r.jsxs("span",{children:[T," watching"]})]})]})}),r.jsx(P,{className:"flex-1 p-2 md:p-3",children:r.jsxs("div",{className:"space-y-2",children:[l.map(a=>r.jsxs("div",{className:`flex flex-col ${a.isGhost?"opacity-80":""}`,children:[r.jsx("span",{className:`text-xs font-medium ${a.username==="You"?"text-primary":"text-accent"}`,children:a.username}),r.jsx("p",{className:"text-xs text-foreground leading-relaxed",children:a.message})]},a.id)),r.jsx("div",{ref:C})]})}),r.jsx("form",{onSubmit:v,className:"p-2 md:p-3 border-t border-gray-200",children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(z,{value:i,onChange:a=>_(a.target.value),placeholder:"Type your message...",className:"flex-1 text-sm"}),r.jsx(k,{type:"submit",size:"icon",children:r.jsx(O,{className:"h-4 w-4"})})]})})]})},K=({links:m})=>{if(!m||m.length===0)return null;const u=m.filter(i=>i.position==="left"),l=m.filter(i=>i.position==="center"),c=m.filter(i=>i.position==="right");return r.jsx("footer",{className:"py-6 px-4 border-t border-border/20 bg-background/50 backdrop-blur-sm",children:r.jsx("div",{className:"max-w-6xl mx-auto",children:r.jsxs("div",{className:"flex flex-col gap-3",children:[(u.length>0||c.length>0)&&r.jsxs("div",{className:"flex justify-center items-center flex-wrap gap-2",children:[u.map((i,_)=>r.jsxs(L.Fragment,{children:[r.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:i.label}),(_<u.length-1||c.length>
10)&&r.jsx("span",{className:"text-muted-foreground/50 mx-1",children:"â¢"})]},i.id)),c.map((i,_)=>r.jsxs(L.Fragment,{children:[r.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:i.label}),_<c.length-1&&r.jsx("span",{className:"text-muted-foreground/50 mx-1",children:"â¢"})]},i.id))]}),l.length>0&&r.jsx("div",{className:"space-y-1",children:l.map(i=>r.jsx("div",{className:"flex justify-center",children:r.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:i.label})},i.id))})]})})})},de=()=>{const m=W(),u=m.webinarId,l=m.userCode,c=m.webinarSlug,[i,_]=d.useState(!1),[T,j]=d.useState(!1),{toast:C}=R(),s=V("Webinar"),w=$();d.useEffect(()=>{s.info("Webinar page initialized",{webinarId:u,userCode:l,webinarSlug:c,url:window.location.href})},[s,u,l,c]);const{data:e,isLoading:S,error:v}=F({queryKey:["webinar",u,l,c],queryFn:async()=>{var n;s.info("Fetching webinar data",{webinarId:u,userCode:l,webinarSlug:c});let t;if(u){s.debug("Fetching by webinarId",{webinarId:u});const{data:o,error:x}=await b.from("webinars").select("*, profiles:user_id(user_code)").eq("id",u).single();if(x)throw s.error("Failed to fetch webinar by ID",{error:x,webinarId:u}),x;if(t=o,t&&t.slug&&((n=t.profiles)!=null&&n.user_code)&&(window.location.pathname.includes("/webinar/")||window.location.pathname.includes("/w/"))){const p=`/${t.profiles.user_code}/webinar/${t.slug}`;s.info("Redirecting to new URL format",{oldPath:window.location.pathname,newPath:p}),w(p,{replace:!0})}}else if(l&&c){s.debug("Fetching by userCode and webinarSlug",{userCode:l,webinarSlug:c});const o=Number(l);if(isNaN(o)){const N="Invalid user code format";throw s.error(N,{userCode:l}),new Error(N)}const{data:x,error:p}=await b.from("profiles").select("id").eq("user_code",o).single();if(p)throw s.error("Failed to fetch user profile",{error:p,userCode:l}),p;if(!x){const N="User not found";throw s.error(N,{userCode:l}),new Error(N)}const M=x.id,{data:A,error:I}=await b.from("webinars").select("*").eq("user_id",M).eq("slug",c).single();if(I)throw s.error("Failed to fetch webinar by slug",{error:I,userCode:l,webinarSlug:c,userId:M}),I;t=A}else{const o="Missing webinar identification parameters";throw s.error(o,{webinarId:u,userCode:l,webinarSlug:c}),new Error(o)}if(!t){const o="Webinar not found";throw s.error(o,{webinarId:u,userCode:l,webinarSlug:c}),C({title:"Error",description:"Webinar not found",variant:"destructive"}),new Error(o)}s.info("Webinar data retrieved",{webinarId:t.id,name:t.name,videoType:t.video_type||"legacy",hasVideoUrl:!!t.video_url,hasEmbedCode:!!t.embed_code,hasCTA:!!t.button_url});try{await b.rpc("increment_webinar_views",{webinar_id:t.id}),s.debug("Views count incremented",{webinarId:t.id})}catch(o){s.warning("Failed to increment view count",{error:o})}return t},retry:1,staleTime:1e3*60*5});if(d.useEffect(()=>{if(e!=null&&e.name&&(document.title=e.name),e){const t={facebook_pixel_id:e.facebook_pixel_id,google_analytics_id:e.google_analytics_id,google_tag_manager_id:e.google_tag_manager_id};console.log("ð Webinar Tracking - Initializing with config:",{webinarId:e.id,webinarName:e.name,facebookPixelId:t.facebook_pixel_id||"NOT SET",googleAnalyticsId:t.google_analytics_id||"NOT SET",googleTagManagerId:t.google_tag_manager_id||"NOT SET"}),B(t),Y(e.name,window.location.href),console.log("ð Webinar Tracking - Initialization complete")}return()=>{document.title="Leads Flow"}},[e]),v)return s.error("Error in webinar query",{error:v}),r.jsxs("div",{className:"min-h-screen flex flex-col items-center justify-center p-4 text-center",children:[r.jsx("p",{className:"text-lg text-red-600 mb-2",children:"Failed to load webinar"}),r.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:v instanceof Error?v.message:"Unknown error occurred"}),r.jsx(k,{onClick:()=>window.location.reload(),variant:"outline",children:"Try Again"})]});const a=d.useMemo(()=>{if(!e)return null;if(e.video_type==="embed"&&e.embed_code)return{embedCode:e.embed_code,isEmbed:!0};if(e.video_type==="url"&&e.video_url)try{const t=new URL(e.video_url);let n="",o=!1;return t.pathname.includes("/shorts/")?(n=t.pathname.split("/shorts/")[1].split("?")[0],o=!0):t.hostname==="youtu.be"?n=t.pathname.substring(1):t.hostname.includes("youtube.com")&&(n=t.searchParams.get("v")||""),n?{embedUrl:`https://www.youtube.com/embed/${n}?autoplay=1&controls=1&rel=0&modestbranding=1&showinfo=0&enablejsapi=1&playsinline=1&mute=1`,isShort:o,isEmbed:!1}:(s.warning("Invalid YouTube URL format",{url:e.video_url}),null)}catch(t){return s.error("Error processing video URL:",{error:t,url:e.video_url}),null}if(e.video_url&&!e.video_type)try{const t=new URL(e.video_url);let n="",o=!1;return t.pathname.includes("/shorts/")?(n=t.pathname.split("/shorts/")[1].split("?")[0],o=!0):t.hostname==="youtu.be"?n=t.pathname.substring(1):t.hostname.includes("youtube.com")&&(n=t.searchParams.get("v")||""),n?{embedUrl:`https://www.youtube.com/embed/${n}?autoplay=1&controls=1&rel=0&modestbranding=1&showinfo=0&enablejsapi=1&playsinline=1&mute=1`,isShort:o,isEmbed:!1}:(s.warning("Invalid YouTube URL format",{url:e.video_url}),null)}catch(t){return s.error("Error processing video URL:",{error:t,url:e.video_url}),null}return null},[e,s]);d.useEffect(()=>{if(a!=null&&a.isShort)j(!0);else if(a!=null&&a.embedCode){const t=a.embedCode.toLowerCase();(t.includes("vertical")||t.includes("9:16")||t.includes("portrait"))&&j(!0)}},[a]),d.useEffect(()=>{if(e&&!e.manual_cta&&e.cta_display_time>0){s.debug("Setting CTA timer",{display_time:e.cta_display_time,manual_cta:e.manual_cta});const t=setTimeout(()=>{_(!0),s.info("CTA displayed automatically",{webinarId:e.id})},e.cta_display_time*1e3);return()=>{s.debug("Clearing CTA timer"),clearTimeout(t)}}},[e,s]),d.useEffect(()=>{if(!(e!=null&&e.id))return;const t=e.custom_scripts;if(!t)return;const n=[];if(t.head){const o=document.createElement("div");
1o.innerHTML=t.head,Array.from(o.children).forEach(x=>{const p=x.cloneNode(!0);document.head.appendChild(p),n.push(p)})}if(t.body){const o=document.createElement("div");o.innerHTML=t.body,Array.from(o.children).forEach(x=>{const p=x.cloneNode(!0);document.body.appendChild(p),n.push(p)})}return()=>{n.forEach(o=>o.remove())}},[e==null?void 0:e.id]);const y=async()=>{if(e!=null&&e.id&&(e!=null&&e.button_url))try{s.info("CTA clicked",{webinarId:e.id,buttonUrl:e.button_url}),await b.rpc("increment_webinar_cta_clicks",{webinar_id:e.id}),s.debug("CTA clicks incremented",{webinarId:e.id});let t=e.button_url;if(e.utm_tracking){const n=G({enabled:!0,parameterName:e.utm_parameter_name||"sck",trackedParams:e.utm_tracked_params||["utm_source","utm_campaign","utm_medium"],separator:e.utm_separator||"_",paramsOrder:e.utm_params_order||["utm_source","utm_campaign","utm_medium"]});n&&(t=H(e.button_url,n,e.utm_parameter_name||"sck"),s.debug("UTM tracking applied",{originalUrl:e.button_url,finalUrl:t,utmString:n}))}window.open(t,"_blank")}catch(t){s.error("Error tracking CTA click",{error:t,webinarId:e.id}),window.open(e.button_url,"_blank")}};if(S)return r.jsx(q,{});if(!e||!a)return r.jsxs("div",{className:"min-h-screen flex flex-col items-center justify-center p-4 text-center",children:[r.jsx("p",{className:"text-lg text-muted-foreground mb-2",children:e?"No video content available":"Webinar not found"}),r.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"The webinar you're looking for might have been removed or the video content is missing."}),r.jsx(k,{onClick:()=>window.location.reload(),variant:"outline",children:"Try Again"})]});const f=e.id,g=e.show_live_chat!==!1,h=e.footer_links||[];return r.jsxs("div",{className:"min-h-screen flex flex-col",children:[r.jsx("div",{className:"flex-1 py-2 md:py-4 px-2 md:px-4",children:r.jsxs("div",{className:"max-w-7xl mx-auto w-full",children:[r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4",children:[r.jsx("div",{className:"flex-1",children:r.jsxs("div",{className:"bg-background/95 backdrop-blur-md rounded-2xl p-3 md:p-6",children:[e.logo_url&&r.jsx("div",{className:"flex justify-center mb-4 md:mb-6",children:r.jsx("img",{src:e.logo_url,alt:"Logo",className:"w-auto h-auto max-h-16 object-contain"})}),(e.social_proof_url||e.social_proof_text)&&r.jsxs("div",{className:"flex items-center justify-center gap-2 md:gap-3 mb-4 md:mb-6",children:[e.social_proof_url&&r.jsx("img",{src:e.social_proof_url,alt:"Social proof",className:"h-8 md:h-10 w-auto object-contain"}),e.social_proof_text&&r.jsx("span",{className:"text-sm md:text-base font-medium text-muted-foreground",children:r.jsx(E,{children:e.social_proof_text})})]}),r.jsxs("div",{className:"mb-3 md:mb-6 text-center",children:[e.headline&&r.jsx("h1",{className:`font-poppins font-bold mb-2 md:mb-3 text-${e.headline_size} md:text-${e.headline_size}`,style:{color:e.header_color||"#222222"},children:r.jsx(E,{children:e.headline})}),e.subheadline&&r.jsx("p",{className:`font-poppins mb-2 md:mb-4 text-${e.subheadline_size} md:text-${e.subheadline_size}`,style:{color:e.subheadline_color||"#666666"},children:r.jsx(E,{children:e.subheadline})})]}),r.jsx("div",{className:"mb-3 md:mb-6 flex justify-center",children:r.jsx("div",{className:`relative bg-black rounded-xl overflow-hidden ${T?"aspect-[9/16] w-full max-w-[280px] md:max-w-[360px]":"aspect-video w-full max-w-[640px] md:max-w-[800px]"}`,children:a.isEmbed?r.jsx("div",{className:"w-full h-full",dangerouslySetInnerHTML:{__html:a.embedCode}}):r.jsx("iframe",{className:"w-full h-full",src:a.embedUrl,title:"Webinar Video",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0})})}),(i||e.manual_cta)&&e.button_url&&r.jsxs("div",{className:"space-y-2 md:space-y-3 animate-fade-in text-center max-w-2xl mx-auto",children:[e.cta_text&&r.jsx("p",{className:`text-sm md:${e.cta_text_size} animate-fade-in`,style:{color:e.cta_text_color||"#666666"},children:r.jsx(E,{children:e.cta_text})}),r.jsx(k,{className:`text-white font-medium py-2 px-4 md:px-6 rounded-lg transition-all duration-300 transform hover:-translate-y-1 hover:shadow-lg ${e.button_size==="sm"?"text-sm":e.button_size==="lg"?"text-base":"text-sm"}`,style:{backgroundColor:e.button_color||"#7E69AB",boxShadow:"0 4px 14px rgba(0, 0, 0, 0.15)"},onClick:y,children:r.jsx(E,{children:e.button_text||"Learn More"})})]})]})}),g&&r.jsx("div",{className:"hidden lg:block w-96",children:r.jsx(U,{webinarId:f})})]}),g&&r.jsx("div",{className:"lg:hidden mt-4",children:r.jsx(U,{webinarId:f})})]})}),r.jsx(K,{links:h})]})};export{de 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.