(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[405],{5557:function(e,t,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/",function(){return r(5989)}])},1398:function(e,t,r){"use strict";r.d(t,{Z:function(){return o}});var a=r(5893),n=r(9008),s=r.n(n),l=r(1664),i=r.n(l);function o(e){let{children:t}=e;return(0,a.jsxs)("div",{children:[(0,a.jsxs)(s(),{children:[(0,a.jsx)("title",{children:"Real-time NBA Analytics"}),(0,a.jsx)("meta",{name:"description",content:"AI-powered NBA analytics and commentary"}),(0,a.jsx)("link",{rel:"icon",href:"/favicon.ico"})]}),(0,a.jsx)("nav",{className:"bg-black text-white p-4",children:(0,a.jsxs)("div",{className:"container mx-auto flex items-center",children:[(0,a.jsx)("div",{className:"flex-1",children:(0,a.jsx)("span",{className:"text-neon-purple text-sm font-roboto",children:"Powered with ❤️ on SingleStore"})}),(0,a.jsx)("div",{className:"flex-1 text-center",children:(0,a.jsx)(i(),{href:"/",className:"text-3xl font-bold text-neon-green font-orbitron",children:"NBA OnTheFlyAI"})}),(0,a.jsx)("div",{className:"flex-1 flex justify-end",children:(0,a.jsxs)("ul",{className:"flex space-x-4",children:[(0,a.jsx)("li",{children:(0,a.jsx)(i(),{href:"/",className:"hover:text-green-400 text-neon-green font-orbitron",children:"Home"})}),(0,a.jsx)("li",{children:(0,a.jsx)(i(),{href:"/analytics",className:"hover:text-green-400 text-neon-green font-orbitron",children:"Analytics"})})]})})]})}),(0,a.jsx)("main",{children:t})]})}},5989:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return f}});var a=r(5893),n=r(1398),s=r(7294);function l(e){let{commentary:t,onSendMessage:r,showAIMessages:n,onToggleAIMessages:l,onGenerateCommentary:i,isAIWatching:o}=e,c=(0,s.useRef)(null),[d,m]=(0,s.useState)("");return(0,s.useEffect)(()=>{c.current&&(c.current.scrollTop=c.current.scrollHeight)},[t]),(0,a.jsxs)("div",{className:"commentary bg-black rounded-lg flex flex-col h-full text-neon-green",style:{maxHeight:"80vh"},children:[(0,a.jsxs)("div",{className:"p-4 bg-black border-b border-gray-600 flex-shrink-0",children:[(0,a.jsx)("h2",{className:"text-2xl font-bold mb-2",children:"Live Chat"}),(0,a.jsx)("button",{onClick:l,className:"w-full",children:n?"Hide AI Messages":"Show AI Messages"})]}),(0,a.jsx)("div",{className:"flex-grow overflow-y-auto p-4 bg-black",ref:c,children:(0,a.jsx)("div",{className:"space-y-4",children:t.map((e,t)=>n||"ai"!==e.type?(0,a.jsxs)("div",{className:"p-3 rounded shadow ".concat("user"===e.type?"bg-green-600 text-white text-right":"bg-gray-700 text-white"),children:[(0,a.jsx)("p",{className:"text-xs text-gray-400",children:new Date(e.timestamp).toLocaleTimeString()}),(0,a.jsx)("p",{className:"mt-1",children:e.text})]},t):null)})}),(0,a.jsxs)("form",{onSubmit:e=>{e.preventDefault(),d.trim()&&(r&&r(d),m(""))},className:"p-4 bg-black border-t border-gray-600 flex gap-2 flex-shrink-0",children:[(0,a.jsx)("input",{type:"text",value:d,onChange:e=>m(e.target.value),placeholder:"Type your message...",className:"flex-grow px-3 py-2 bg-gray-600 text-white rounded-l-lg focus:outline-none focus:ring-2 focus:ring-green-500"}),(0,a.jsx)("button",{type:"submit",className:"send",children:"Send"}),(0,a.jsx)("button",{type:"button",onClick:i,className:"generate-commentary",disabled:o,children:o?"Speaking...":"Speak"})]})]})}var i=r(2305),o=r(2332),c=r(4206),d=r(2154),m=r(4283),x=r(6910),h=r(3447),y=r(8933);function u(e){let{videoSrc:t}=e,r=(0,s.useRef)(null),[n,u]=(0,s.useState)(null),[f,F]=(0,s.useState)([]),[b,j]=(0,s.useState)(!0),[p,v]=(0,s.useState)(!1),[g,k]=(0,s.useState)({}),[w,N]=(0,s.useState)(!0),[S,O]=(0,s.useState)(!1),C=(0,s.useRef)(null),A=(0,s.useCallback)(async()=>{try{let e=await fetch("/api/analytics"),t=await e.json();k(t)}catch(e){console.error("Error fetching latest analytics:",e)}},[]);(0,s.useEffect)(()=>{A();let e=setInterval(()=>{A()},2e3);return()=>clearInterval(e)},[A]);let D=(0,s.useCallback)(()=>{C.current||(C.current=setInterval(()=>{L()},2e3))},[]),E=(0,s.useCallback)(()=>{C.current&&(clearInterval(C.current),C.current=null)},[]);(0,s.useEffect)(()=>{let e=r.current;if(e){let t=()=>{O(!0),D()},r=()=>{O(!1),E()};return e.addEventListener("play",t),e.addEventListener("playing",t),e.addEventListener("pause",r),e.addEventListener("ended",r),()=>{e.removeEventListener("play",t),e.removeEventListener("playing",t),e.removeEventListener("pause",r),e.removeEventListener("ended",r),E()}}},[D,E]);let L=(0,s.useCallback)(async()=>{try{v(!0);let e=document.createElement("canvas"),t=r.current;e.width=t.videoWidth,e.height=t.videoHeight,e.getContext("2d").drawImage(t,0,0,e.width,e.height);let a=e.toDataURL("image/jpeg"),n=await fetch("/api/commentary",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({imageData:a,width:e.width,height:e.height})}),s=await n.json();s.text?F(e=>[...e,{timestamp:s.timestamp||new Date().toISOString(),text:s.text,type:"ai"}]):(console.error("No commentary text received from API."),u("No commentary received. Please try again.")),v(!1)}catch(e){console.error("Error generating commentary:",e),u("Error generating commentary. Please check the console for details."),v(!1)}},[]),I=(0,s.useCallback)(e=>{F(t=>[...t,{timestamp:new Date().toISOString(),text:e,type:"user"}])},[]),K=(0,s.useCallback)(()=>{if(0===f.length){alert("No commentary available for speech synthesis.");return}let e=f[f.length-1].text,t=window.speechSynthesis,r=new SpeechSynthesisUtterance(e);t.speak(r)},[f]),_=(0,s.useCallback)(e=>{let{commentaries:t}=e;return(0,a.jsx)(i.h,{width:"100%",height:"100%",children:(0,a.jsxs)(o.w,{data:t,children:[(0,a.jsx)(c.q,{strokeDasharray:"3 3",stroke:"#444"}),(0,a.jsx)(d.K,{dataKey:"date",stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(m.B,{stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(x.u,{contentStyle:{backgroundColor:"#000000",borderColor:"#00FF00"},labelStyle:{color:"#00FF00",fontFamily:"Orbitron"},itemStyle:{color:"#00FF00",fontFamily:"Orbitron"}}),(0,a.jsx)(h.D,{wrapperStyle:{fontFamily:"Orbitron",color:"#00FF00"}}),(0,a.jsx)(y.x,{type:"monotone",dataKey:"count",stroke:"#00FF00",dot:!1,isAnimationActive:!1})]})})},[]),P=(0,s.useCallback)(e=>{let{latencies:t=[]}=e,r=t.map(e=>{var t;return{timestamp:new Date(e.timestamp).toLocaleString(),latency:null!==(t=e.latency)&&void 0!==t?t:0}});return(0,a.jsx)(i.h,{width:"100%",height:"100%",children:(0,a.jsxs)(o.w,{data:r,children:[(0,a.jsx)(c.q,{strokeDasharray:"3 3",stroke:"#444"}),(0,a.jsx)(d.K,{dataKey:"timestamp",stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(m.B,{stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(x.u,{contentStyle:{backgroundColor:"#000000",borderColor:"#00FF00"},labelStyle:{color:"#00FF00",fontFamily:"Orbitron"},itemStyle:{color:"#00FF00",fontFamily:"Orbitron"}}),(0,a.jsx)(h.D,{wrapperStyle:{fontFamily:"Orbitron",color:"#00FF00"}}),(0,a.jsx)(y.x,{type:"monotone",dataKey:"latency",stroke:"#00FF00",dot:!1,isAnimationActive:!1})]})})},[]),T=(0,s.useCallback)(e=>{let{commentaries:t=[]}=e,r=t.map(e=>{var t,r;return{timestamp:new Date(e.timestamp).toLocaleString(),length:(null===(t=e.commentary)||void 0===t?void 0:t.length)||(null===(r=e.text)||void 0===r?void 0:r.length)||0}});return(0,a.jsx)(i.h,{width:"100%",height:"100%",children:(0,a.jsxs)(o.w,{data:r,children:[(0,a.jsx)(c.q,{strokeDasharray:"3 3",stroke:"#444"}),(0,a.jsx)(d.K,{dataKey:"timestamp",stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(m.B,{stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(x.u,{contentStyle:{backgroundColor:"#000000",borderColor:"#00FF00"},labelStyle:{color:"#00FF00",fontFamily:"Orbitron"},itemStyle:{color:"#00FF00",fontFamily:"Orbitron"}}),(0,a.jsx)(h.D,{wrapperStyle:{fontFamily:"Orbitron",color:"#00FF00"}}),(0,a.jsx)(y.x,{type:"monotone",dataKey:"length",stroke:"#00FF00",dot:!1,isAnimationActive:!1})]})})},[]),B=(0,s.useCallback)(e=>{let{scoresData:t=[]}=e,r=t.map(e=>{var t,r;return{timestamp:new Date(e.timestamp).toLocaleString(),warriorsScore:null!==(t=e.warriors_score)&&void 0!==t?t:0,cavaliersScore:null!==(r=e.cavaliers_score)&&void 0!==r?r:0}});return(0,a.jsx)(i.h,{width:"100%",height:"100%",children:(0,a.jsxs)(o.w,{data:r,children:[(0,a.jsx)(c.q,{strokeDasharray:"3 3",stroke:"#444"}),(0,a.jsx)(d.K,{dataKey:"timestamp",stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(m.B,{stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(x.u,{contentStyle:{backgroundColor:"#000000",borderColor:"#00FF00"},labelStyle:{color:"#00FF00",fontFamily:"Orbitron"},itemStyle:{color:"#00FF00",fontFamily:"Orbitron"}}),(0,a.jsx)(h.D,{wrapperStyle:{fontFamily:"Orbitron",color:"#00FF00"}}),(0,a.jsx)(y.x,{type:"monotone",dataKey:"warriorsScore",stroke:"#00FFFF",name:"Warriors",dot:!1,isAnimationActive:!1}),(0,a.jsx)(y.x,{type:"monotone",dataKey:"cavaliersScore",stroke:"#FF3131",name:"Cavaliers",dot:!1,isAnimationActive:!1})]})})},[]),H=(0,s.useCallback)(e=>{let{winProbabilityData:t=[]}=e,r=t.map(e=>{var t;return{timestamp:new Date(e.timestamp).toLocaleString(),winProbability:null!==(t=e.win_probability)&&void 0!==t?t:50}});return(0,a.jsx)(i.h,{width:"100%",height:"100%",children:(0,a.jsxs)(o.w,{data:r,children:[(0,a.jsx)(c.q,{strokeDasharray:"3 3",stroke:"#444"}),(0,a.jsx)(d.K,{dataKey:"timestamp",stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(m.B,{domain:[0,100],stroke:"#00FF00",tick:{fontFamily:"Orbitron",fill:"#00FF00"}}),(0,a.jsx)(x.u,{contentStyle:{backgroundColor:"#000000",borderColor:"#00FF00"},labelStyle:{color:"#00FF00",fontFamily:"Orbitron"},itemStyle:{color:"#00FF00",fontFamily:"Orbitron"}}),(0,a.jsx)(h.D,{wrapperStyle:{fontFamily:"Orbitron",color:"#00FF00"}}),(0,a.jsx)(y.x,{type:"monotone",dataKey:"winProbability",stroke:"#00FF00",name:"Warriors Win Probability %",dot:!1,isAnimationActive:!1})]})})},[]);return(0,a.jsxs)("div",{className:"flex flex-col min-h-screen bg-black text-neon-green font-orbitron",children:[(0,a.jsxs)("div",{className:"flex flex-grow",children:[(0,a.jsx)("div",{className:"w-2/3 p-4 flex flex-col",children:(0,a.jsxs)("div",{className:"video-container",children:[(0,a.jsx)("video",{ref:r,src:t,controls:!0,crossOrigin:"anonymous",className:"w-full h-auto object-contain"}),n&&(0,a.jsx)("p",{className:"text-red-500 mt-2",children:n}),p&&(0,a.jsx)("div",{className:"ai-watching",children:"AI is watching"})]})}),(0,a.jsx)("div",{className:"w-1/3 p-4 flex flex-col",style:{maxHeight:"80vh"},children:(0,a.jsx)(l,{commentary:f,showAIMessages:b,onToggleAIMessages:()=>j(!b),onGenerateCommentary:K,isAIWatching:p,onSendMessage:I})})]}),(0,a.jsxs)("div",{className:"bg-black p-4",children:[(0,a.jsx)("button",{onClick:()=>N(!w),className:"mb-4",children:w?"Hide Analytics":"Show Analytics"}),w&&(0,a.jsxs)("div",{className:"analytics-container",children:[(0,a.jsxs)("div",{className:"analytics-card",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Total Commentaries"}),(0,a.jsx)(_,{commentaries:(null==g?void 0:g.commentariesOverTime)||[]})]}),(0,a.jsxs)("div",{className:"analytics-card",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Latest Latencies"}),(0,a.jsx)(P,{latencies:(null==g?void 0:g.latestLatency)||[]})]}),(0,a.jsxs)("div",{className:"analytics-card",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Latest Commentaries"}),(0,a.jsx)(T,{commentaries:(null==g?void 0:g.latestCommentaries)||[]})]}),(0,a.jsxs)("div",{className:"analytics-card",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Scores Over Time"}),(0,a.jsx)(B,{scoresData:(null==g?void 0:g.scoresOverTime)||[]})]}),(0,a.jsxs)("div",{className:"analytics-card",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Warriors Win Probability"}),(0,a.jsx)(H,{winProbabilityData:(null==g?void 0:g.winProbabilityOverTime)||[]})]}),(0,a.jsx)("div",{className:"analytics-card flex items-center justify-center",children:(0,a.jsx)("p",{children:"Additional Graph Placeholder"})})]})]})]})}function f(){return(0,a.jsx)(n.Z,{children:(0,a.jsx)(u,{videoSrc:"/sample-video.mp4"})})}}},function(e){e.O(0,[176,888,774,179],function(){return e(e.s=5557)}),_N_E=e.O()}]);