import{j as e}from"./vendor-ui-CUslpDkL.js";import{r as o,j as v}from"./vendor-react-Dg0Tra3e.js";import{x as i,B as N,T as u,S as w,C as S,o as h,s as k}from"./index-CJqEbhJN.js";import{B as g}from"./badge-But4vkun.js";import{S as C}from"./search-RJS4XthK.js";import{L as D}from"./loader-circle-zVnpfu52.js";import"./vendor-query-CN1EccJz.js";import"./vendor-supabase-yzuDJZPy.js";import"./vendor-motion-CiNtJfg1.js";const c=["Scanning neural network...","Analyzing your vibe pattern...","Cross-referencing anime database...","Matching mood signatures..."];function V(){const[l,f]=o.useState(""),[s,d]=o.useState(!1),[b,y]=o.useState(c[0]),[t,m]=o.useState(null),j=v(),x=async()=>{if(l.trim().length<5){h.error("Describe a bit more about the vibe you're looking for.");return}d(!0),m(null);let r=0;const n=setInterval(()=>{r=(r+1)%c.length,y(c[r])},2e3);try{const{data:a,error:p}=await k.functions.invoke("analyze-anime-vibe",{body:{prompt:l.trim()}});if(p)throw p;if(a?.error)throw new Error(a.error);m(a)}catch(a){console.error("Vibe search error:",a),h.error(a.message||"Something went wrong. Try again.")}finally{clearInterval(n),d(!1)}};return e.jsx("section",{className:"px-4 py-12 md:py-16",children:e.jsxs("div",{className:"mx-auto max-w-5xl",children:[e.jsxs("div",{className:"mb-6 text-center",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-primary/30 bg-primary/10 px-4 py-1.5 text-sm text-primary mb-3",children:[e.jsx(i,{className:"w-4 h-4"}),"AI-Powered"]}),e.jsxs("h2",{className:"text-3xl md:text-4xl font-bold tracking-tight",children:[e.jsx("span",{className:"neon-text",children:"Vibe"})," ",e.jsx("span",{className:"text-foreground",children:"Search"})]}),e.jsx("p",{className:"mt-2 text-muted-foreground max-w-xl mx-auto",children:"Describe the mood, plot, or style you want — our AI scans thousands of anime to find your perfect match."})]}),e.jsxs("div",{className:"relative flex flex-col sm:flex-row gap-3 mb-8",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(C,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"}),e.jsx("input",{type:"text",value:l,onChange:r=>f(r.target.value),onKeyDown:r=>r.key==="Enter"&&!s&&x(),placeholder:"Describe the vibe (e.g., A dark fantasy where the weak main character becomes overpowered...)",className:"w-full h-12 pl-12 pr-4 rounded-xl border border-primary/30 bg-card text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all text-sm md:text-base",disabled:s})]}),e.jsxs(N,{onClick:x,disabled:s||l.trim().length<5,size:"lg",className:"neon-glow-pink bg-gradient-to-r from-primary to-accent hover:opacity-90 rounded-xl px-6 shrink-0 h-12",children:[s?e.jsx(D,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(i,{className:"w-4 h-4 mr-2"}),"Scan Database"]})]}),s&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-4",children:[e.jsxs("div",{className:"relative w-16 h-16",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-primary/30 animate-ping"}),e.jsx("div",{className:"absolute inset-2 rounded-full border-2 border-t-primary border-r-transparent border-b-transparent border-l-transparent animate-spin"}),e.jsx(i,{className:"absolute inset-0 m-auto w-6 h-6 text-primary"})]}),e.jsx("p",{className:"text-muted-foreground animate-pulse text-sm",children:b})]}),t&&!s&&e.jsxs("div",{className:"flex flex-wrap gap-2 mb-6 justify-center",children:[t.vibe_keywords.map(r=>e.jsx(g,{variant:"outline",className:"border-secondary/40 text-secondary text-xs",children:r},r)),t.primary_genres.map(r=>e.jsx(g,{className:"bg-primary/20 text-primary border-primary/30 text-xs",children:r},r))]}),t&&!s&&t.results.length>0&&e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5",children:t.results.filter(r=>r.grounded).map((r,n)=>e.jsxs("div",{onClick:()=>{const a=r.slug||r.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"");j(`/shows/${a}`)},role:"button",tabIndex:0,className:"group relative flex flex-col rounded-xl border border-border bg-card overflow-hidden hover:border-primary/50 transition-all hover:shadow-[var(--shadow-neon-pink)] cursor-pointer",children:[e.jsxs("div",{className:"aspect-[3/4] relative overflow-hidden bg-muted",children:[r.poster_url?e.jsx("img",{src:r.poster_url,alt:r.title,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",loading:"lazy"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-muted-foreground",children:e.jsx(u,{className:"w-10 h-10"})}),r.score&&e.jsxs("div",{className:"absolute top-2 right-2 flex items-center gap-1 rounded-lg bg-background/80 backdrop-blur px-2 py-0.5 text-xs font-semibold text-primary",children:[e.jsx(w,{className:"w-3 h-3 fill-current"}),r.score]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 p-3 flex-1",children:[e.jsx("h3",{className:"text-sm font-semibold leading-tight line-clamp-2 text-foreground",children:r.title}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[r.year&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(S,{className:"w-3 h-3"})," ",r.year]}),r.episodes&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(u,{className:"w-3 h-3"})," ",r.episodes," ep"]})]}),e.jsx("p",{className:"text-xs text-primary/80 leading-relaxed mt-auto line-clamp-3",children:r.match_reason})]})]},n))}),t&&!s&&t.results.filter(r=>r.grounded).length===0&&e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No verified results found. Try a different description!"})]})})}export{V as default};