import{j as e}from"./vendor-ui-CUslpDkL.js";import{r,i as G,L as C}from"./vendor-react-Dg0Tra3e.js";import{c as A,a as O,B as c,r as X,s as m,l as _,n as Y,b as ee,F as te,J as se,K as ae,N as ne,O as ie,Q as re,E as L}from"./index-CJqEbhJN.js";import{u as oe}from"./useIndexNow-C3dRJY1T.js";import{b as ce,u as U,c as z}from"./vendor-query-CN1EccJz.js";import{T as R}from"./textarea-Cl_ytQkU.js";import{I as q}from"./input-BddqDKi_.js";import{C as H,b as B,c as W,a as P}from"./card-BSxrPlO5.js";import{S as le}from"./share-2-CprN_Tkl.js";import{A as me}from"./arrow-left-DtOv4JyO.js";import{m as S}from"./vendor-motion-CiNtJfg1.js";import{P as de}from"./play-Cs8ErDIS.js";import{F as he}from"./flame-DnD4Z7Bh.js";import{T as xe}from"./triangle-alert-CrjyZwlk.js";import{C as ue}from"./circle-check-big-Cs5aOdeL.js";import{S as pe}from"./send-DRRNY0V9.js";import"./vendor-supabase-yzuDJZPy.js";/**
* @license lucide-react v0.462.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const ge=A("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/**
* @license lucide-react v0.462.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const fe=A("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
* @license lucide-react v0.462.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const je=A("Twitter",[["path",{d:"M22 4s-.7 2.1-2 3.4c1.6 10-9.4 17.3-18 11.6 2.2.1 4.4-.6 6-2C3 15.5.5 9.6 3 5c2.2 2.6 5.6 4.1 9 4-.9-4.2 4-6.6 7-3.8 1.1 0 3-1.2 3-1.2z",key:"pff0z6"}]]);function we({sceneId:a,animeTitle:n,episode:d,similarity:o}){const{toast:u}=O(),[p,g]=r.useState(!1),l=`https://www.what-anime.com/scene/${a}`,j=n?`I found this anime scene from ${n}${d?` (Episode ${d})`:""} with ${(o*100).toFixed(0)}% confidence using What-Anime!`:"Check out this anime scene I found using What-Anime!",f=()=>{const h=`https://twitter.com/intent/tweet?text=${encodeURIComponent(j)}&url=${encodeURIComponent(l)}`;window.open(h,"_blank","noopener,noreferrer,width=600,height=400")},w=()=>{const h=n?`Found this scene from ${n} using What-Anime`:"Found this anime scene using What-Anime",N=`https://www.reddit.com/submit?url=${encodeURIComponent(l)}&title=${encodeURIComponent(h)}`;window.open(N,"_blank","noopener,noreferrer,width=600,height=600")},y=()=>{const h=`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(l)}`;window.open(h,"_blank","noopener,noreferrer,width=600,height=400")},v=async()=>{try{await navigator.clipboard.writeText(l),g(!0),u({title:"Link copied!",description:"Share it anywhere you like."}),setTimeout(()=>g(!1),2e3)}catch{u({title:"Failed to copy",variant:"destructive"})}};return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground mr-1",children:[e.jsx(le,{className:"w-4 h-4 inline mr-1"}),"Share:"]}),e.jsxs(c,{variant:"outline",size:"sm",onClick:f,className:"gap-1.5 hover:bg-[#1DA1F2]/10 hover:text-[#1DA1F2] hover:border-[#1DA1F2]/50",children:[e.jsx(je,{className:"w-4 h-4"}),"Twitter"]}),e.jsxs(c,{variant:"outline",size:"sm",onClick:w,className:"gap-1.5 hover:bg-[#FF4500]/10 hover:text-[#FF4500] hover:border-[#FF4500]/50",children:[e.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.248 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z"})}),"Reddit"]}),e.jsxs(c,{variant:"outline",size:"sm",onClick:y,className:"gap-1.5 hover:bg-[#1877F2]/10 hover:text-[#1877F2] hover:border-[#1877F2]/50",children:[e.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"})}),"Facebook"]}),e.jsx(c,{variant:"outline",size:"sm",onClick:v,className:"gap-1.5",children:p?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"w-4 h-4 text-green-500"}),"Copied!"]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-4 h-4"}),"Copy Link"]})})]})}const K=a=>{const n=Math.floor(a/3600),d=Math.floor(a%3600/60),o=Math.floor(a%60);return n>0?`${n}:${d.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}`:`${d}:${o.toString().padStart(2,"0")}`},ye=[{name:"Crunchyroll",url:"https://crunchyroll.com",color:"bg-orange-500"},{name:"Netflix",url:"https://netflix.com",color:"bg-red-600"},{name:"Funimation",url:"https://funimation.com",color:"bg-purple-600"},{name:"Hulu",url:"https://hulu.com",color:"bg-green-500"}];function ze(){const{id:a}=G(),{toast:n}=O(),d=ce(),[o,u]=r.useState(null),[p,g]=r.useState(""),[l,j]=r.useState(""),[f,w]=r.useState(""),[y,v]=r.useState(""),[h,N]=r.useState(!1),{pingIndexNow:E}=oe(),I=r.useRef(!1);r.useEffect(()=>{m.auth.getUser().then(({data:{user:i}})=>{u(i)});const{data:{subscription:t}}=m.auth.onAuthStateChange((i,$)=>{u($?.user??null)});return()=>t.unsubscribe()},[]),r.useEffect(()=>{a&&m.rpc("increment_scene_view",{scene_id:a})},[a]);const{data:s,isLoading:Q}=U({queryKey:["scene",a],queryFn:async()=>{const{data:t,error:i}=await m.from("public_searches").select("*").eq("id",a).maybeSingle();if(i)throw i;return t},enabled:!!a});r.useEffect(()=>{s&&!I.current&&(I.current=!0,E([`/scene/${a}`]))},[s,a,E]);const{data:b,isLoading:J}=U({queryKey:["scene_comments",a],queryFn:async()=>{const{data:t,error:i}=await m.from("scene_comments").select("id, content, created_at, user_id").eq("scene_id",a).order("created_at",{ascending:!0});if(i)throw i;if(!t)return[];const $=[...new Set(t.map(x=>x.user_id))],{data:V}=await m.from("profiles").select("id, username").in("id",$),Z=new Map(V?.map(x=>[x.id,x])||[]);return t.map(x=>({...x,profiles:Z.get(x.user_id)||{username:null}}))},enabled:!!a}),D=z({mutationFn:async t=>{const{error:i}=await m.from("scene_comments").insert({scene_id:a,user_id:o.id,content:t});if(i)throw i},onSuccess:()=>{g(""),d.invalidateQueries({queryKey:["scene_comments",a]}),n({title:"Comment added!"})},onError:t=>{n({title:"Error adding comment",description:t.message,variant:"destructive"})}}),T=z({mutationFn:async()=>{const{error:t}=await m.from("scene_corrections").insert({scene_id:a,user_id:o.id,suggested_title:l,suggested_episode:f?parseInt(f):null,reason:y||null});if(t)throw t},onSuccess:()=>{j(""),w(""),v(""),N(!1),n({title:"Correction submitted!",description:"Thanks for helping improve our database."})},onError:t=>{n({title:"Error submitting correction",description:t.message,variant:"destructive"})}});if(Q)return e.jsx("div",{className:"min-h-screen px-4 py-8",children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsx(_,{className:"h-96 w-full rounded-xl mb-6"}),e.jsx(_,{className:"h-8 w-1/2 mb-4"}),e.jsx(_,{className:"h-4 w-1/3"})]})});if(!s)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Scene not found"}),e.jsx(C,{to:"/explore",className:"text-primary hover:underline",children:"Back to Explore"})]})});const M=s.image_url,k=s.anime_title?`${s.anime_title}${s.episode?` - Episode ${s.episode}`:""} | What-Anime`:"Anime Scene | What-Anime",F=s.anime_title?`Found anime scene from ${s.anime_title}${s.episode?`, Episode ${s.episode}`:""}. Confidence: ${(s.similarity*100).toFixed(0)}%`:"Discover this anime scene on What-Anime. Help identify the source!";return e.jsxs(e.Fragment,{children:[e.jsxs(Y,{children:[e.jsx("title",{children:k}),e.jsx("meta",{name:"description",content:F}),e.jsx("meta",{property:"og:title",content:k}),e.jsx("meta",{property:"og:description",content:F}),e.jsx("meta",{property:"og:image",content:M}),e.jsx("meta",{property:"og:type",content:"article"}),e.jsx("meta",{name:"twitter:card",content:"summary_large_image"}),e.jsx("meta",{name:"twitter:title",content:k}),e.jsx("meta",{name:"twitter:description",content:F}),e.jsx("meta",{name:"twitter:image",content:M})]}),e.jsx("div",{className:"min-h-screen px-4 py-8",children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsxs(C,{to:"/explore",className:"inline-flex items-center gap-2 text-muted-foreground hover:text-foreground mb-6 transition-colors",children:[e.jsx(me,{className:"w-4 h-4"}),"Back to Explore"]}),e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"rounded-xl overflow-hidden mb-6 glass-card",children:e.jsx("img",{src:s.image_url,alt:s.anime_title||"Anime scene",className:"w-full max-h-[600px] object-contain bg-black"})}),e.jsxs(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:"mb-8",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold mb-2",children:s.anime_title||"Unknown Anime"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[s.episode&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(de,{className:"w-4 h-4"}),"Episode ",s.episode]}),s.timestamp_from&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ee,{className:"w-4 h-4"}),K(s.timestamp_from),s.timestamp_to&&` - ${K(s.timestamp_to)}`]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(he,{className:"w-4 h-4 text-orange-500"}),s.view_count," views"]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsxs("div",{className:`
px-3 py-1 rounded-full text-sm font-semibold
${s.similarity>=.9?"bg-green-500/20 text-green-400":s.similarity>=.8?"bg-yellow-500/20 text-yellow-400":"bg-orange-500/20 text-orange-400"}
`,children:[(s.similarity*100).toFixed(0),"% Match"]}),!s.is_solved&&e.jsx("span",{className:"px-3 py-1 text-xs font-semibold rounded-full bg-orange-500/90 text-white",children:"Unsolved"})]})]}),e.jsx("div",{className:"mb-4",children:e.jsx(we,{sceneId:a,animeTitle:s.anime_title,episode:s.episode,similarity:s.similarity})}),e.jsxs(te,{open:h,onOpenChange:N,children:[e.jsx(se,{asChild:!0,children:e.jsxs(c,{variant:"outline",className:"gap-2",children:[e.jsx(xe,{className:"w-4 h-4"}),"Is this wrong?"]})}),e.jsxs(ae,{className:"glass-card",children:[e.jsxs(ne,{children:[e.jsx(ie,{children:"Suggest a Correction"}),e.jsx(re,{children:"Help us improve by suggesting the correct anime title."})]}),o?e.jsxs("div",{className:"space-y-4 mt-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Correct Anime Title *"}),e.jsx(q,{value:l,onChange:t=>j(t.target.value),placeholder:"Enter the correct anime title"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Episode (optional)"}),e.jsx(q,{type:"number",value:f,onChange:t=>w(t.target.value),placeholder:"Episode number"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"How do you know? (optional)"}),e.jsx(R,{value:y,onChange:t=>v(t.target.value),placeholder:"e.g., I've watched this anime",rows:2})]}),e.jsxs(c,{onClick:()=>T.mutate(),disabled:!l||T.isPending,className:"w-full",children:[e.jsx(ue,{className:"w-4 h-4 mr-2"}),"Submit Correction"]})]}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Please sign in to suggest a correction."}),e.jsx(C,{to:"/auth",children:e.jsx(c,{children:"Sign In"})})]})]})]})]}),e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2},children:e.jsxs(H,{className:"glass-card mb-8",children:[e.jsx(B,{children:e.jsxs(W,{className:"text-lg flex items-center gap-2",children:[e.jsx(L,{className:"w-5 h-5"}),"Where to Watch"]})}),e.jsxs(P,{children:[e.jsx("div",{className:"flex flex-wrap gap-3",children:ye.map(t=>e.jsxs("a",{href:`${t.url}/search?q=${encodeURIComponent(s.anime_title||"")}`,target:"_blank",rel:"noopener noreferrer",className:`
${t.color} px-4 py-2 rounded-lg text-white text-sm font-medium
hover:opacity-80 transition-opacity flex items-center gap-2
`,children:[t.name,e.jsx(L,{className:"w-3 h-3"})]},t.name))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Availability may vary by region. These are external links."})]})]})}),e.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.3},children:e.jsxs(H,{className:"glass-card",children:[e.jsx(B,{children:e.jsxs(W,{className:"text-lg flex items-center gap-2",children:[e.jsx(fe,{className:"w-5 h-5"}),"Discussion (",b?.length||0,")"]})}),e.jsxs(P,{children:[o?e.jsxs("div",{className:"flex gap-3 mb-6",children:[e.jsx(R,{value:p,onChange:t=>g(t.target.value),placeholder:"Share your thoughts...",rows:2,className:"flex-1"}),e.jsx(c,{onClick:()=>D.mutate(p),disabled:!p.trim()||D.isPending,size:"icon",className:"h-auto",children:e.jsx(pe,{className:"w-4 h-4"})})]}):e.jsxs("div",{className:"text-center py-4 mb-6 bg-muted/30 rounded-lg",children:[e.jsx("p",{className:"text-muted-foreground mb-2",children:"Sign in to join the discussion"}),e.jsx(C,{to:"/auth",children:e.jsx(c,{variant:"outline",size:"sm",children:"Sign In"})})]}),J?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(t=>e.jsx(_,{className:"h-20 w-full rounded-lg"},t))}):b&&b.length>0?e.jsx("div",{className:"space-y-4",children:b.map(t=>e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"font-medium text-sm",children:t.profiles?.username||"Anonymous"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()})]}),e.jsx("p",{className:"text-sm",children:t.content})]},t.id))}):e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No comments yet. Be the first to share your thoughts!"})]})]})})]})})]})}export{ze as default};