(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7573],{4627:(e,t,s)=>{Promise.resolve().then(s.bind(s,6380))},6288:(e,t,s)=>{"use strict";s.d(t,{X:()=>a.A});var a=s(4416)},6380:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>b});var a=s(5155),r=s(2115),i=s(5695),l=s(3226),n=s(283),c=s(6982),d=s(9074),o=s(4186),x=s(4357),h=s(1066),m=s(4835),u=s(5690),g=s(2525),p=s(2318);function b(){let{user:e}=(0,n.A)(),t=(0,i.useRouter)(),{getUserParties:s,deleteParty:b,leaveParty:y}=(0,l.x)(),{showToast:j}=(0,c.dj)(),[v,w]=(0,r.useState)([]),[N,f]=(0,r.useState)(!0),[C,_]=(0,r.useState)(null),k=async()=>{if(!e)return void f(!1);try{f(!0),_(null);let e=await s();w(e)}catch(e){_("Failed to load your parties")}finally{f(!1)}};(0,r.useEffect)(()=>{k()},[e]);let A=async e=>{try{await navigator.clipboard.writeText(e),j("Invite code copied to clipboard!","success")}catch(e){j("Failed to copy invite code","error")}},P=e=>{t.push("/party/".concat(e))},S=async e=>{if(confirm("Are you sure you want to delete this party? This action cannot be undone."))try{await b(e),j("Party deleted successfully","success"),k()}catch(e){j("Failed to delete party","error")}},T=async e=>{if(confirm("Are you sure you want to leave this party?"))try{await y(e),j("Left party successfully","success"),k()}catch(e){j("Failed to leave party","error")}},E=e=>new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});return e?(0,a.jsx)("div",{className:"min-h-screen bg-gray-900 py-8",children:(0,a.jsxs)("div",{className:"container mx-auto px-4",children:[(0,a.jsx)("div",{className:"mb-8",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-3xl font-bold text-white mb-2",children:"My Watch Parties"}),(0,a.jsx)("p",{className:"text-gray-400",children:"Manage your active watch parties and join ongoing sessions"})]}),(0,a.jsxs)("button",{onClick:()=>t.push("/search"),className:"bg-red-600 hover:bg-red-700 text-white px-6 py-3 rounded-lg transition-colors flex items-center gap-2",children:[(0,a.jsx)(p.A,{className:"w-5 h-5"}),"Create New Party"]})]})}),N&&(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-red-600"})}),C&&(0,a.jsxs)("div",{className:"bg-red-900/50 border border-red-500 rounded-lg p-4 mb-6",children:[(0,a.jsx)("p",{className:"text-red-400",children:C}),(0,a.jsx)("button",{onClick:k,className:"mt-2 text-red-300 hover:text-red-200 underline",children:"Try again"})]}),!N&&!C&&0===v.length&&(0,a.jsxs)("div",{className:"text-center py-12",children:[(0,a.jsx)(h.A,{className:"w-16 h-16 text-gray-600 mx-auto mb-4"}),(0,a.jsx)("h2",{className:"text-xl font-semibold text-white mb-2",children:"No watch parties yet"}),(0,a.jsx)("p",{className:"text-gray-400 mb-6",children:"Create your first watch party to start watching with friends!"}),(0,a.jsx)("button",{onClick:()=>t.push("/search"),className:"bg-red-600 hover:bg-red-700 text-white px-6 py-3 rounded-lg transition-colors",children:"Create Your First Party"})]}),!N&&!C&&v.length>0&&(0,a.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:v.map(t=>{let s=t.host_id===e.id;return(0,a.jsxs)("div",{className:"bg-gray-800 rounded-lg overflow-hidden shadow-lg hover:shadow-xl transition-shadow",children:[(0,a.jsxs)("div",{className:"p-4 border-b border-gray-700",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat(t.is_active?"bg-green-900 text-green-300":"bg-yellow-900 text-yellow-300"),children:t.is_active?"Active":"Waiting"}),(0,a.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat(s?"bg-blue-900 text-blue-300":"bg-gray-700 text-gray-300"),children:s?"Host":"Member"})]}),(0,a.jsx)("h3",{className:"text-lg font-semibold text-white mb-1 truncate",children:t.title||"Watch Party"}),(0,a.jsxs)("div",{className:"flex items-center gap-4 text-sm text-gray-400",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(d.A,{className:"w-4 h-4"}),E(t.created_at)]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(o.A,{className:"w-4 h-4"}),t.updated_at&&E(t.updated_at)]})]})]}),(0,a.jsxs)("div",{className:"p-4",children:[(0,a.jsxs)("div",{className:"mb-4",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-400 mb-1",children:"Invite Code"}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("code",{className:"bg-gray-700 px-3 py-1 rounded text-white font-mono",children:t.invite_code}),(0,a.jsx)("button",{onClick:()=>A(t.invite_code),className:"p-1 text-gray-400 hover:text-white transition-colors",title:"Copy invite code",children:(0,a.jsx)(x.A,{className:"w-4 h-4"})})]})]})," ",t.media_id&&(0,a.jsx)("div",{className:"mb-4",children:(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-400",children:[(0,a.jsx)(h.A,{className:"w-4 h-4"}),(0,a.jsxs)("span",{children:["movie"===t.media_type?"Movie":"TV Show"," • ID: ",t.media_id]})]})}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)("button",{onClick:()=>P(t.id),className:"flex-1 bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg transition-colors flex items-center justify-center gap-2",children:[(0,a.jsx)(u.A,{className:"w-4 h-4"}),t.is_active?"Join Party":"View Party"]}),s&&(0,a.jsx)("button",{onClick:()=>S(t.id),className:"bg-gray-700 hover:bg-red-600 text-gray-300 hover:text-white px-4 py-2 rounded-lg transition-colors",title:"Delete party",children:(0,a.jsx)(g.A,{className:"w-4 h-4"})}),!s&&(0,a.jsx)("button",{onClick:()=>T(t.id),className:"bg-gray-700 hover:bg-red-600 text-gray-300 hover:text-white px-4 py-2 rounded-lg transition-colors",title:"Leave party",children:(0,a.jsx)(m.A,{className:"w-4 h-4"})})]})]})]},t.id)})})]})}):(0,a.jsx)("div",{className:"min-h-screen bg-gray-900 flex items-center justify-center",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("h1",{className:"text-2xl font-bold text-white mb-4",children:"Please sign in"}),(0,a.jsx)("p",{className:"text-gray-400 mb-8",children:"You need to be signed in to view your watch parties."}),(0,a.jsx)("button",{onClick:()=>t.push("/auth/login"),className:"bg-red-600 hover:bg-red-700 text-white px-6 py-2 rounded-lg transition-colors",children:"Sign In"})]})})}},6982:(e,t,s)=>{"use strict";s.d(t,{dj:()=>n,tE:()=>c});var a=s(5155),r=s(2115),i=s(6288);let l=(0,r.createContext)(void 0),n=()=>{let e=(0,r.useContext)(l);if(!e)throw Error("useToast must be used within a ToastProvider");return e},c=e=>{let{children:t}=e,[s,n]=(0,r.useState)([]),c=(0,r.useCallback)((e,t)=>{let s=Math.random().toString(36).substring(2,9);return n(a=>[...a,{id:s,message:e,type:t}]),setTimeout(()=>{d(s)},4e3),s},[]),d=(0,r.useCallback)(e=>{n(t=>t.filter(t=>t.id!==e))},[]);return(0,a.jsxs)(l.Provider,{value:{toasts:s,showToast:c,hideToast:d},children:[" ",t,(0,a.jsx)("div",{className:"fixed top-4 right-4 z-[200] flex flex-col gap-2",children:s.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-lg p-3 shadow-lg transition-all transform animate-slide-in-top\n ".concat("success"===e.type?"bg-green-600/90 text-white":"error"===e.type?"bg-red-600/90 text-white":"bg-blue-600/90 text-white"," \n backdrop-blur-sm border border-white/10 min-w-[300px] max-w-sm"),children:[(0,a.jsx)("p",{className:"text-sm font-medium flex-1",children:e.message}),(0,a.jsx)("button",{onClick:()=>d(e.id),className:"rounded-full p-1 hover:bg-white/20 transition-colors",children:(0,a.jsx)(i.X,{size:16})})]},e.id))})]})}}},e=>{var t=t=>e(e.s=t);e.O(0,[8096,3226,8441,7358],()=>t(4627)),_N_E=e.O()}]);