import{j as e,b as Ie,u as J,P as O,g as G,e as Kt,a2 as Ye,d as Ge,c as Wt,H as qt}from"./vendor-ui-CUslpDkL.js";import{r as m}from"./vendor-react-Dg0Tra3e.js";import{c as se,q as te,V as Xt,r as Re,s as U,p as Ze,B as A,X as Je,u as Qe,a as Yt,x as Gt}from"./index-CJqEbhJN.js";import{C as oe,a as ie,b as Zt,c as Jt,d as Qt}from"./card-BSxrPlO5.js";import{u as et}from"./index-CSX6DdY0.js";import{B as q}from"./badge-But4vkun.js";import{I as Oe}from"./input-BddqDKi_.js";import{T as es}from"./textarea-Cl_ytQkU.js";import{L as ve}from"./label-DW0D2B1w.js";import{S as ts}from"./send-DRRNY0V9.js";import{W as ss}from"./wand-sparkles-BA-wznA0.js";import{Z as we}from"./zap-CkbLqKyG.js";import{U as He}from"./upload-DQzlkcfH.js";import{S as rs}from"./share-2-CprN_Tkl.js";import{L as ns}from"./loader-circle-zVnpfu52.js";import{S as Ke}from"./search-RJS4XthK.js";import{C as as}from"./circle-alert-xOefwxaD.js";import{T as os}from"./triangle-alert-CrjyZwlk.js";import"./vendor-query-CN1EccJz.js";import"./vendor-supabase-yzuDJZPy.js";import"./vendor-motion-CiNtJfg1.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 is=se("Crop",[["path",{d:"M6 2v14a2 2 0 0 0 2 2h14",key:"ron5a4"}],["path",{d:"M18 22V8a2 2 0 0 0-2-2H2",key:"7s9ehn"}]]);/**
* @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 cs=se("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);/**
* @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 ls=se("Move",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]]);/**
* @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 We=se("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]]);/**
* @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 ds=se("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
* @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 ms=se("ThumbsUp",[["path",{d:"M7 10v12",key:"1qc93n"}],["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",key:"emmmcr"}]]);/**
* @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 us=se("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]),hs=Xt("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),ye=m.forwardRef(({className:t,variant:s,...o},r)=>e.jsx("div",{ref:r,role:"alert",className:te(hs({variant:s}),t),...o}));ye.displayName="Alert";const fs=m.forwardRef(({className:t,...s},o)=>e.jsx("h5",{ref:o,className:te("mb-1 font-medium leading-none tracking-tight",t),...s}));fs.displayName="AlertTitle";const je=m.forwardRef(({className:t,...s},o)=>e.jsx("div",{ref:o,className:te("text-sm [&_p]:leading-relaxed",t),...s}));je.displayName="AlertDescription";var me="Checkbox",[ps,vr]=Ie(me),[xs,Ee]=ps(me);function gs(t){const{__scopeCheckbox:s,checked:o,children:r,defaultChecked:l,disabled:n,form:u,name:i,onCheckedChange:d,required:f,value:p="on",internal_do_not_use_render:c}=t,[h,g]=Ge({prop:o,defaultProp:l??!1,onChange:d,caller:me}),[j,v]=m.useState(null),[b,w]=m.useState(null),S=m.useRef(!1),y=j?!!u||!!j.closest("form"):!0,k={checked:h,disabled:n,setChecked:g,control:j,setControl:v,name:i,form:u,value:p,hasConsumerStoppedPropagationRef:S,required:f,defaultChecked:Z(l)?!1:l,isFormControl:y,bubbleInput:b,setBubbleInput:w};return e.jsx(xs,{scope:s,...k,children:bs(c)?c(k):r})}var tt="CheckboxTrigger",st=m.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:o,...r},l)=>{const{control:n,value:u,disabled:i,checked:d,required:f,setControl:p,setChecked:c,hasConsumerStoppedPropagationRef:h,isFormControl:g,bubbleInput:j}=Ee(tt,t),v=J(l,p),b=m.useRef(d);return m.useEffect(()=>{const w=n?.form;if(w){const S=()=>c(b.current);return w.addEventListener("reset",S),()=>w.removeEventListener("reset",S)}},[n,c]),e.jsx(O.button,{type:"button",role:"checkbox","aria-checked":Z(d)?"mixed":d,"aria-required":f,"data-state":it(d),"data-disabled":i?"":void 0,disabled:i,value:u,...r,ref:v,onKeyDown:G(s,w=>{w.key==="Enter"&&w.preventDefault()}),onClick:G(o,w=>{c(S=>Z(S)?!0:!S),j&&g&&(h.current=w.isPropagationStopped(),h.current||w.stopPropagation())})})});st.displayName=tt;var Pe=m.forwardRef((t,s)=>{const{__scopeCheckbox:o,name:r,checked:l,defaultChecked:n,required:u,disabled:i,value:d,onCheckedChange:f,form:p,...c}=t;return e.jsx(gs,{__scopeCheckbox:o,checked:l,defaultChecked:n,disabled:i,required:u,onCheckedChange:f,name:r,form:p,value:d,internal_do_not_use_render:({isFormControl:h})=>e.jsxs(e.Fragment,{children:[e.jsx(st,{...c,ref:s,__scopeCheckbox:o}),h&&e.jsx(ot,{__scopeCheckbox:o})]})})});Pe.displayName=me;var rt="CheckboxIndicator",nt=m.forwardRef((t,s)=>{const{__scopeCheckbox:o,forceMount:r,...l}=t,n=Ee(rt,o);return e.jsx(Kt,{present:r||Z(n.checked)||n.checked===!0,children:e.jsx(O.span,{"data-state":it(n.checked),"data-disabled":n.disabled?"":void 0,...l,ref:s,style:{pointerEvents:"none",...t.style}})})});nt.displayName=rt;var at="CheckboxBubbleInput",ot=m.forwardRef(({__scopeCheckbox:t,...s},o)=>{const{control:r,hasConsumerStoppedPropagationRef:l,checked:n,defaultChecked:u,required:i,disabled:d,name:f,value:p,form:c,bubbleInput:h,setBubbleInput:g}=Ee(at,t),j=J(o,g),v=et(n),b=Ye(r);m.useEffect(()=>{const S=h;if(!S)return;const y=window.HTMLInputElement.prototype,D=Object.getOwnPropertyDescriptor(y,"checked").set,_=!l.current;if(v!==n&&D){const P=new Event("click",{bubbles:_});S.indeterminate=Z(n),D.call(S,Z(n)?!1:n),S.dispatchEvent(P)}},[h,v,n,l]);const w=m.useRef(Z(n)?!1:n);return e.jsx(O.input,{type:"checkbox","aria-hidden":!0,defaultChecked:u??w.current,required:i,disabled:d,name:f,value:p,form:c,...s,tabIndex:-1,ref:j,style:{...s.style,...b,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});ot.displayName=at;function bs(t){return typeof t=="function"}function Z(t){return t==="indeterminate"}function it(t){return Z(t)?"indeterminate":t?"checked":"unchecked"}const Se=m.forwardRef(({className:t,...s},o)=>e.jsx(Pe,{ref:o,className:te("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...s,children:e.jsx(nt,{className:te("flex items-center justify-center text-current"),children:e.jsx(Re,{className:"h-4 w-4"})})}));Se.displayName=Pe.displayName;var De="Progress",Me=100,[vs,wr]=Ie(De),[ws,ys]=vs(De),ct=m.forwardRef((t,s)=>{const{__scopeProgress:o,value:r=null,max:l,getValueLabel:n=js,...u}=t;(l||l===0)&&!qe(l)&&console.error(Ss(`${l}`,"Progress"));const i=qe(l)?l:Me;r!==null&&!Xe(r,i)&&console.error(Ns(`${r}`,"Progress"));const d=Xe(r,i)?r:null,f=de(d)?n(d,i):void 0;return e.jsx(ws,{scope:o,value:d,max:i,children:e.jsx(O.div,{"aria-valuemax":i,"aria-valuemin":0,"aria-valuenow":de(d)?d:void 0,"aria-valuetext":f,role:"progressbar","data-state":mt(d,i),"data-value":d??void 0,"data-max":i,...u,ref:s})})});ct.displayName=De;var lt="ProgressIndicator",dt=m.forwardRef((t,s)=>{const{__scopeProgress:o,...r}=t,l=ys(lt,o);return e.jsx(O.div,{"data-state":mt(l.value,l.max),"data-value":l.value??void 0,"data-max":l.max,...r,ref:s})});dt.displayName=lt;function js(t,s){return`${Math.round(t/s*100)}%`}function mt(t,s){return t==null?"indeterminate":t===s?"complete":"loading"}function de(t){return typeof t=="number"}function qe(t){return de(t)&&!isNaN(t)&&t>0}function Xe(t,s){return de(t)&&!isNaN(t)&&t<=s&&t>=0}function Ss(t,s){return`Invalid prop \`max\` of value \`${t}\` supplied to \`${s}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${Me}\`.`}function Ns(t,s){return`Invalid prop \`value\` of value \`${t}\` supplied to \`${s}\`. The \`value\` prop must be:
- a positive number
- less than the value passed to \`max\` (or ${Me} if no \`max\` prop is set)
- \`null\` or \`undefined\` if the progress is indeterminate.
Defaulting to \`null\`.`}var ut=ct,Cs=dt;const ht=m.forwardRef(({className:t,value:s,...o},r)=>e.jsx(ut,{ref:r,className:te("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...o,children:e.jsx(Cs,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(s||0)}%)`}})}));ht.displayName=ut.displayName;async function ks(t){const{data:{user:s}}=await U.auth.getUser();if(!s)throw new Error("Must be logged in to share with community");const{data:o,error:r}=await U.from("public_searches").insert({user_id:s.id,image_url:t.imageUrl,anime_title:t.animeTitle,episode:t.episode,timestamp_from:t.timestampFrom,timestamp_to:t.timestampTo,similarity:t.similarity,anilist_id:t.anilistId,filename:t.filename,is_solved:t.similarity>=.8}).select("id").maybeSingle();if(r)throw r;return o}function Is(t,s){const o=s.getImageData(0,0,t.width,t.height),r=o.data;let l=255,n=0;for(let d=0;d<r.length;d+=4){const f=(r[d]+r[d+1]+r[d+2])/3;l=Math.min(l,f),n=Math.max(n,f)}const u=n-l;if(u>200||u<20)return;const i=255/u;for(let d=0;d<r.length;d+=4)r[d]=Math.min(255,Math.max(0,(r[d]-l)*i)),r[d+1]=Math.min(255,Math.max(0,(r[d+1]-l)*i)),r[d+2]=Math.min(255,Math.max(0,(r[d+2]-l)*i));s.putImageData(o,0,0)}function Rs(t,s=20){const{width:o,height:r,data:l}=t,n=p=>{const c=l[p],h=l[p+1],g=l[p+2];return c<s&&h<s&&g<s};let u=0;for(let p=0;p<r;p++){let c=!0;for(let h=0;h<o;h+=10){const g=(p*o+h)*4;if(!n(g)){c=!1;break}}if(!c)break;u=p}let i=r;for(let p=r-1;p>=0;p--){let c=!0;for(let h=0;h<o;h+=10){const g=(p*o+h)*4;if(!n(g)){c=!1;break}}if(!c)break;i=p}let d=0;for(let p=0;p<o;p++){let c=!0;for(let h=u;h<i;h+=10){const g=(h*o+p)*4;if(!n(g)){c=!1;break}}if(!c)break;d=p}let f=o;for(let p=o-1;p>=0;p--){let c=!0;for(let h=u;h<i;h+=10){const g=(h*o+p)*4;if(!n(g)){c=!1;break}}if(!c)break;f=p}return{top:u,bottom:r-i,left:d,right:o-f}}function Es(t,s=0){const{width:o,height:r,data:l}=t,n=Math.floor(r/3),u=r-n-s;let i=r;for(let d=r-1-s;d>=u;d--){let f=0,p=0;for(let h=Math.floor(o*.1);h<Math.floor(o*.9);h+=5){const g=(d*o+h)*4,j=l[g],v=l[g+1],b=l[g+2];p++,(j>200&&v>200&&b>200||j>200&&v>180&&b<100)&&f++}const c=f/p;c>.05&&c<.5&&(i=d)}return Math.min(r-i+10,n)}async function Ps(t,s){return new Promise((o,r)=>{const l=new FileReader;l.onload=n=>{const u=new Image;u.onload=()=>{const i=document.createElement("canvas");i.width=s.width,i.height=s.height;const d=i.getContext("2d");if(!d){r(new Error("Failed to get canvas context"));return}d.drawImage(u,s.x,s.y,s.width,s.height,0,0,s.width,s.height),i.toBlob(f=>{if(f){const p=new File([f],t.name,{type:"image/jpeg",lastModified:Date.now()});o(p)}else r(new Error("Failed to create cropped image"))},"image/jpeg",.85)},u.onerror=r,u.src=n.target?.result},l.onerror=r,l.readAsDataURL(t)})}async function Ds(t){return new Promise((s,o)=>{const r=new FileReader;r.onload=l=>{const n=new Image;n.onload=()=>{const u=document.createElement("canvas");u.width=n.width,u.height=n.height;const i=u.getContext("2d");if(!i){s({file:t,cropApplied:!1,cropInfo:""});return}i.drawImage(n,0,0);const d=i.getImageData(0,0,n.width,n.height),f=Rs(d),p=Es(d,f.bottom),c=f.top,h=Math.max(f.bottom,p),g=f.left,j=f.right,v=n.width-g-j,b=n.height-c-h;if(1-v*b/(n.width*n.height)<.05||v<100||b<100){s({file:t,cropApplied:!1,cropInfo:""});return}const S=document.createElement("canvas");S.width=v,S.height=b;const y=S.getContext("2d");if(!y){s({file:t,cropApplied:!1,cropInfo:""});return}y.drawImage(n,g,c,v,b,0,0,v,b),Is(S,y),S.toBlob(k=>{if(k){const D=new File([k],t.name,{type:"image/jpeg",lastModified:Date.now()}),_=[];(f.top>0||f.bottom>0)&&_.push("black bars"),p>f.bottom&&_.push("subtitles"),s({file:D,cropApplied:!0,cropInfo:`Removed ${_.join(" & ")}`})}else s({file:t,cropApplied:!1,cropInfo:""})},"image/jpeg",.85)},n.onerror=()=>s({file:t,cropApplied:!1,cropInfo:""}),n.src=l.target?.result},r.onerror=()=>s({file:t,cropApplied:!1,cropInfo:""}),r.readAsDataURL(t)})}var ft=["PageUp","PageDown"],pt=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],xt={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},ae="Slider",[Ne,Ms,As]=Wt(ae),[gt,yr]=Ie(ae,[As]),[_s,ue]=gt(ae),bt=m.forwardRef((t,s)=>{const{name:o,min:r=0,max:l=100,step:n=1,orientation:u="horizontal",disabled:i=!1,minStepsBetweenThumbs:d=0,defaultValue:f=[r],value:p,onValueChange:c=()=>{},onValueCommit:h=()=>{},inverted:g=!1,form:j,...v}=t,b=m.useRef(new Set),w=m.useRef(0),y=u==="horizontal"?Ts:Fs,[k=[],D]=Ge({prop:p,defaultProp:f,onChange:R=>{[...b.current][w.current]?.focus(),c(R)}}),_=m.useRef(k);function P(R){const B=$s(k,R);M(R,B)}function N(R){M(R,w.current)}function L(){const R=_.current[w.current];k[w.current]!==R&&h(k)}function M(R,B,{commit:X}={commit:!1}){const Q=Ks(n),H=Ws(Math.round((R-r)/n)*n+r,Q),ee=Ze(H,[r,l]);D((V=[])=>{const K=Bs(V,ee,B);if(Hs(K,d*n)){w.current=K.indexOf(ee);const Y=String(K)!==String(V);return Y&&X&&h(K),Y?K:V}else return V})}return e.jsx(_s,{scope:t.__scopeSlider,name:o,disabled:i,min:r,max:l,valueIndexToChangeRef:w,thumbs:b.current,values:k,orientation:u,form:j,children:e.jsx(Ne.Provider,{scope:t.__scopeSlider,children:e.jsx(Ne.Slot,{scope:t.__scopeSlider,children:e.jsx(y,{"aria-disabled":i,"data-disabled":i?"":void 0,...v,ref:s,onPointerDown:G(v.onPointerDown,()=>{i||(_.current=k)}),min:r,max:l,inverted:g,onSlideStart:i?void 0:P,onSlideMove:i?void 0:N,onSlideEnd:i?void 0:L,onHomeKeyDown:()=>!i&&M(r,0,{commit:!0}),onEndKeyDown:()=>!i&&M(l,k.length-1,{commit:!0}),onStepKeyDown:({event:R,direction:B})=>{if(!i){const H=ft.includes(R.key)||R.shiftKey&&pt.includes(R.key)?10:1,ee=w.current,V=k[ee],K=n*H*B;M(V+K,ee,{commit:!0})}}})})})})});bt.displayName=ae;var[vt,wt]=gt(ae,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Ts=m.forwardRef((t,s)=>{const{min:o,max:r,dir:l,inverted:n,onSlideStart:u,onSlideMove:i,onSlideEnd:d,onStepKeyDown:f,...p}=t,[c,h]=m.useState(null),g=J(s,y=>h(y)),j=m.useRef(void 0),v=qt(l),b=v==="ltr",w=b&&!n||!b&&n;function S(y){const k=j.current||c.getBoundingClientRect(),D=[0,k.width],P=Ae(D,w?[o,r]:[r,o]);return j.current=k,P(y-k.left)}return e.jsx(vt,{scope:t.__scopeSlider,startEdge:w?"left":"right",endEdge:w?"right":"left",direction:w?1:-1,size:"width",children:e.jsx(yt,{dir:v,"data-orientation":"horizontal",...p,ref:g,style:{...p.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:y=>{const k=S(y.clientX);u?.(k)},onSlideMove:y=>{const k=S(y.clientX);i?.(k)},onSlideEnd:()=>{j.current=void 0,d?.()},onStepKeyDown:y=>{const D=xt[w?"from-left":"from-right"].includes(y.key);f?.({event:y,direction:D?-1:1})}})})}),Fs=m.forwardRef((t,s)=>{const{min:o,max:r,inverted:l,onSlideStart:n,onSlideMove:u,onSlideEnd:i,onStepKeyDown:d,...f}=t,p=m.useRef(null),c=J(s,p),h=m.useRef(void 0),g=!l;function j(v){const b=h.current||p.current.getBoundingClientRect(),w=[0,b.height],y=Ae(w,g?[r,o]:[o,r]);return h.current=b,y(v-b.top)}return e.jsx(vt,{scope:t.__scopeSlider,startEdge:g?"bottom":"top",endEdge:g?"top":"bottom",size:"height",direction:g?1:-1,children:e.jsx(yt,{"data-orientation":"vertical",...f,ref:c,style:{...f.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:v=>{const b=j(v.clientY);n?.(b)},onSlideMove:v=>{const b=j(v.clientY);u?.(b)},onSlideEnd:()=>{h.current=void 0,i?.()},onStepKeyDown:v=>{const w=xt[g?"from-bottom":"from-top"].includes(v.key);d?.({event:v,direction:w?-1:1})}})})}),yt=m.forwardRef((t,s)=>{const{__scopeSlider:o,onSlideStart:r,onSlideMove:l,onSlideEnd:n,onHomeKeyDown:u,onEndKeyDown:i,onStepKeyDown:d,...f}=t,p=ue(ae,o);return e.jsx(O.span,{...f,ref:s,onKeyDown:G(t.onKeyDown,c=>{c.key==="Home"?(u(c),c.preventDefault()):c.key==="End"?(i(c),c.preventDefault()):ft.concat(pt).includes(c.key)&&(d(c),c.preventDefault())}),onPointerDown:G(t.onPointerDown,c=>{const h=c.target;h.setPointerCapture(c.pointerId),c.preventDefault(),p.thumbs.has(h)?h.focus():r(c)}),onPointerMove:G(t.onPointerMove,c=>{c.target.hasPointerCapture(c.pointerId)&&l(c)}),onPointerUp:G(t.onPointerUp,c=>{const h=c.target;h.hasPointerCapture(c.pointerId)&&(h.releasePointerCapture(c.pointerId),n(c))})})}),jt="SliderTrack",St=m.forwardRef((t,s)=>{const{__scopeSlider:o,...r}=t,l=ue(jt,o);return e.jsx(O.span,{"data-disabled":l.disabled?"":void 0,"data-orientation":l.orientation,...r,ref:s})});St.displayName=jt;var Ce="SliderRange",Nt=m.forwardRef((t,s)=>{const{__scopeSlider:o,...r}=t,l=ue(Ce,o),n=wt(Ce,o),u=m.useRef(null),i=J(s,u),d=l.values.length,f=l.values.map(h=>It(h,l.min,l.max)),p=d>1?Math.min(...f):0,c=100-Math.max(...f);return e.jsx(O.span,{"data-orientation":l.orientation,"data-disabled":l.disabled?"":void 0,...r,ref:i,style:{...t.style,[n.startEdge]:p+"%",[n.endEdge]:c+"%"}})});Nt.displayName=Ce;var ke="SliderThumb",Ct=m.forwardRef((t,s)=>{const o=Ms(t.__scopeSlider),[r,l]=m.useState(null),n=J(s,i=>l(i)),u=m.useMemo(()=>r?o().findIndex(i=>i.ref.current===r):-1,[o,r]);return e.jsx(Ls,{...t,ref:n,index:u})}),Ls=m.forwardRef((t,s)=>{const{__scopeSlider:o,index:r,name:l,...n}=t,u=ue(ke,o),i=wt(ke,o),[d,f]=m.useState(null),p=J(s,S=>f(S)),c=d?u.form||!!d.closest("form"):!0,h=Ye(d),g=u.values[r],j=g===void 0?0:It(g,u.min,u.max),v=Vs(r,u.values.length),b=h?.[i.size],w=b?Us(b,j,i.direction):0;return m.useEffect(()=>{if(d)return u.thumbs.add(d),()=>{u.thumbs.delete(d)}},[d,u.thumbs]),e.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${j}% + ${w}px)`},children:[e.jsx(Ne.ItemSlot,{scope:t.__scopeSlider,children:e.jsx(O.span,{role:"slider","aria-label":t["aria-label"]||v,"aria-valuemin":u.min,"aria-valuenow":g,"aria-valuemax":u.max,"aria-orientation":u.orientation,"data-orientation":u.orientation,"data-disabled":u.disabled?"":void 0,tabIndex:u.disabled?void 0:0,...n,ref:p,style:g===void 0?{display:"none"}:t.style,onFocus:G(t.onFocus,()=>{u.valueIndexToChangeRef.current=r})})}),c&&e.jsx(kt,{name:l??(u.name?u.name+(u.values.length>1?"[]":""):void 0),form:u.form,value:g},r)]})});Ct.displayName=ke;var zs="RadioBubbleInput",kt=m.forwardRef(({__scopeSlider:t,value:s,...o},r)=>{const l=m.useRef(null),n=J(l,r),u=et(s);return m.useEffect(()=>{const i=l.current;if(!i)return;const d=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(d,"value").set;if(u!==s&&p){const c=new Event("input",{bubbles:!0});p.call(i,s),i.dispatchEvent(c)}},[u,s]),e.jsx(O.input,{style:{display:"none"},...o,ref:n,defaultValue:s})});kt.displayName=zs;function Bs(t=[],s,o){const r=[...t];return r[o]=s,r.sort((l,n)=>l-n)}function It(t,s,o){const n=100/(o-s)*(t-s);return Ze(n,[0,100])}function Vs(t,s){return s>2?`Value ${t+1} of ${s}`:s===2?["Minimum","Maximum"][t]:void 0}function $s(t,s){if(t.length===1)return 0;const o=t.map(l=>Math.abs(l-s)),r=Math.min(...o);return o.indexOf(r)}function Us(t,s,o){const r=t/2,n=Ae([0,50],[0,r]);return(r-n(s)*o)*o}function Os(t){return t.slice(0,-1).map((s,o)=>t[o+1]-s)}function Hs(t,s){if(s>0){const o=Os(t);return Math.min(...o)>=s}return!0}function Ae(t,s){return o=>{if(t[0]===t[1]||s[0]===s[1])return s[0];const r=(s[1]-s[0])/(t[1]-t[0]);return s[0]+r*(o-t[0])}}function Ks(t){return(String(t).split(".")[1]||"").length}function Ws(t,s){const o=Math.pow(10,s);return Math.round(t*o)/o}var Rt=bt,qs=St,Xs=Nt,Ys=Ct;const Et=m.forwardRef(({className:t,...s},o)=>e.jsxs(Rt,{ref:o,className:te("relative flex w-full touch-none select-none items-center",t),...s,children:[e.jsx(qs,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:e.jsx(Xs,{className:"absolute h-full bg-primary"})}),e.jsx(Ys,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));Et.displayName=Rt.displayName;function Gs({imageUrl:t,originalFile:s,onCropComplete:o,onCancel:r}){const l=m.useRef(null),[n,u]=m.useState({width:0,height:0}),[i,d]=m.useState({x:0,y:0,width:100,height:100}),[f,p]=m.useState(1),[c,h]=m.useState(!1),[g,j]=m.useState({x:0,y:0}),[v,b]=m.useState(!1);m.useEffect(()=>{const N=new Image;N.onload=()=>{u({width:N.width,height:N.height});const L=N.width*.6,M=N.height*.6;d({x:(N.width-L)/2,y:(N.height-M)/2,width:L,height:M})},N.src=t},[t]);const w=N=>{h(!0),j({x:N.clientX-i.x*f,y:N.clientY-i.y*f})},S=m.useCallback(N=>{if(!c)return;const L=Math.max(0,Math.min((N.clientX-g.x)/f,n.width-i.width)),M=Math.max(0,Math.min((N.clientY-g.y)/f,n.height-i.height));d(R=>({...R,x:L,y:M}))},[c,g,f,n,i.width,i.height]),y=m.useCallback(()=>{h(!1)},[]);m.useEffect(()=>{if(c)return window.addEventListener("mousemove",S),window.addEventListener("mouseup",y),()=>{window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",y)}},[c,S,y]);const k=N=>{const L=N[0]/100,M=n.width*L,R=n.height*L;d({x:(n.width-M)/2,y:(n.height-R)/2,width:M,height:R})},D=async()=>{b(!0);try{const N=await Ps(s,{x:Math.round(i.x),y:Math.round(i.y),width:Math.round(i.width),height:Math.round(i.height)});o(N)}catch(N){console.error("Crop failed:",N)}finally{b(!1)}},P=600/n.width||1;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-card rounded-xl shadow-xl border border-border max-w-2xl w-full p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(us,{className:"w-5 h-5 text-primary"}),"Adjust Crop Area"]}),e.jsx(A,{variant:"ghost",size:"icon",onClick:r,children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Drag the selection to focus on a character's face for better results."}),e.jsxs("div",{ref:l,className:"relative mx-auto overflow-hidden rounded-lg bg-muted",style:{width:n.width*P,height:n.height*P},children:[e.jsx("img",{src:t,alt:"Original",className:"w-full h-full object-contain opacity-40",draggable:!1}),e.jsx("div",{className:"absolute inset-0 bg-black/50"}),e.jsxs("div",{className:"absolute cursor-move border-2 border-primary rounded-lg overflow-hidden",style:{left:i.x*P,top:i.y*P,width:i.width*P,height:i.height*P},onMouseDown:w,children:[e.jsx("img",{src:t,alt:"Crop preview",className:"absolute",style:{width:n.width*P,height:n.height*P,left:-i.x*P,top:-i.y*P},draggable:!1}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:e.jsx("div",{className:"p-2 rounded-full bg-primary/20",children:e.jsx(ls,{className:"w-6 h-6 text-primary"})})})]})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Crop Size"}),e.jsxs("span",{className:"font-medium",children:[Math.round(i.width/n.width*100),"%"]})]}),e.jsx(Et,{value:[i.width/n.width*100],onValueChange:k,min:20,max:100,step:5})]}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsx(A,{variant:"outline",onClick:r,className:"flex-1",children:"Cancel"}),e.jsx(A,{onClick:D,disabled:v,className:"flex-1",children:v?"Processing...":e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"w-4 h-4 mr-2"}),"Apply Crop"]})})]})]})})}function Zs({sceneId:t,currentTitle:s,currentEpisode:o,onClose:r,onSubmitted:l}){const{t:n}=Qe(),[u,i]=m.useState(s),[d,f]=m.useState(o?.toString()||""),[p,c]=m.useState(""),[h,g]=m.useState(!1),j=async()=>{if(u.trim()){g(!0);try{const{data:{user:v}}=await U.auth.getUser();if(!v)throw new Error("Not authenticated");const{error:b}=await U.from("scene_corrections").insert({scene_id:t,user_id:v.id,suggested_title:u.trim(),suggested_episode:d?parseInt(d):null,reason:p.trim()||null});if(b)throw b;l()}catch(v){console.error("Correction error:",v)}finally{g(!1)}}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-card rounded-xl shadow-xl border border-border max-w-md w-full p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:n("correction.submitCorrection")}),e.jsx(A,{variant:"ghost",size:"icon",onClick:r,children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:n("correction.helpImprove")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(ve,{htmlFor:"title",children:n("correction.animeTitle")}),e.jsx(Oe,{id:"title",value:u,onChange:v=>i(v.target.value),placeholder:n("correction.enterCorrectTitle")})]}),e.jsxs("div",{children:[e.jsx(ve,{htmlFor:"episode",children:n("correction.episodeOptional")}),e.jsx(Oe,{id:"episode",type:"number",value:d,onChange:v=>f(v.target.value),placeholder:n("correction.episodeNumber")})]}),e.jsxs("div",{children:[e.jsx(ve,{htmlFor:"reason",children:n("correction.howDoYouKnow")}),e.jsx(es,{id:"reason",value:p,onChange:v=>c(v.target.value),placeholder:n("correction.reasonPlaceholder"),rows:2})]})]}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsx(A,{variant:"outline",onClick:r,className:"flex-1",children:n("common.cancel")}),e.jsxs(A,{onClick:j,disabled:!u.trim()||h,className:"flex-1",children:[e.jsx(ts,{className:"w-4 h-4 mr-2"}),n(h?"correction.submitting":"correction.submit")]})]})]})})}function jr(){const{t}=Qe(),{toast:s}=Yt(),[o,r]=m.useState(null),[l,n]=m.useState(null),[u,i]=m.useState(null),[d,f]=m.useState("idle"),[p,c]=m.useState(0),[h,g]=m.useState(null),[j,v]=m.useState(null),[b,w]=m.useState(null),[S,y]=m.useState(null),[k,D]=m.useState(!1),[_,P]=m.useState(!1),[N,L]=m.useState(!1),[M,R]=m.useState(!1),[B,X]=m.useState(null),[Q,H]=m.useState(null),[ee,V]=m.useState(!1),[K,Y]=m.useState(!1),[_e,Pt]=m.useState(null),[Te,Dt]=m.useState(!0),[Mt,he]=m.useState(0),[Fe,fe]=m.useState([]),Le=m.useRef(null);m.useEffect(()=>{U.auth.getSession().then(({data:{session:x}})=>{L(!!x)});const{data:{subscription:a}}=U.auth.onAuthStateChange((x,C)=>{L(!!C)});return()=>a.unsubscribe()},[]);const ze=a=>{const x=Math.floor(a/3600),C=Math.floor(a%3600/60),I=Math.floor(a%60);return`${x.toString().padStart(2,"0")}:${C.toString().padStart(2,"0")}:${I.toString().padStart(2,"0")}`},pe=a=>a>=.9?"text-green-500":a>=.85?"text-emerald-500":a>=.8?"text-yellow-500":a>=.7?"text-orange-500":"text-red-500",At=a=>a>=.9?"Very High":a>=.85?"High":a>=.8?"Medium":a>=.7?"Low":"Very Low",xe=a=>new Promise((x,C)=>{const I=new FileReader;I.onload=W=>{const T=new Image;T.onload=()=>{let z=T.width,$=T.height;z>$&&z>480?($=$*480/z,z=480):$>480&&(z=z*480/$,$=480);const E=document.createElement("canvas");E.width=z,E.height=$,E.getContext("2d")?.drawImage(T,0,0,z,$),E.toBlob(ne=>{if(ne){const le=new File([ne],a.name,{type:"image/jpeg",lastModified:Date.now()});x(le)}else C(new Error("Failed to resize image"))},"image/jpeg",.6)},T.onerror=C,T.src=W.target?.result},I.onerror=C,I.readAsDataURL(a)}),_t=async(a,x)=>{const I=await(await fetch(a)).blob();return new File([I],x,{type:I.type||"image/jpeg"})},ce=m.useCallback(async a=>{if(!a.type.startsWith("image/")){y("Please select a valid image file (JPG, PNG, WebP)");return}try{f("preprocessing"),c(10),n(a),he(0),H(null);const{file:x,cropApplied:C,cropInfo:I}=await Ds(a);c(50),C?(X(I),s({title:t("screenshot.imageCleaned"),description:I})):X(null);const W=await xe(x);if(c(100),W.size>300*1024){y("Image is still too large after compression. Please use a simpler screenshot."),f("idle");return}r(W),y(null),g(null),w(null),f("idle");const T=new FileReader;T.onloadend=()=>{i(T.result)},T.readAsDataURL(a)}catch(x){console.error("Error processing image:",x),y("Failed to process image. Please try another file."),f("idle")}},[s]),Tt=a=>{const x=a.target.files?.[0];x&&ce(x)},Ft=a=>{a.preventDefault(),D(!0)},Lt=a=>{a.preventDefault(),D(!1)},zt=a=>{a.preventDefault(),D(!1);const x=a.dataTransfer.files[0];x&&ce(x)},ge=m.useCallback(a=>{const x=a.clipboardData?.items;if(x){for(let C=0;C<x.length;C++)if(x[C].type.startsWith("image/")){const I=x[C].getAsFile();I&&ce(I);break}}},[ce]);m.useEffect(()=>(window.addEventListener("paste",ge),()=>window.removeEventListener("paste",ge)),[ge]);const Bt=async a=>{V(!1),X("Manual crop applied");const x=await xe(a);r(x);const C=new FileReader;C.onloadend=()=>{i(C.result)},C.readAsDataURL(a),s({title:t("screenshot.cropApplied"),description:t("screenshot.searchWithCropped")})},Be=async a=>{try{const x=new FormData;x.append("image",a);const{data:C,error:I}=await U.functions.invoke("enhance-image",{body:x});if(I)return console.error("Enhance error:",I),null;if(C?.enhanced&&C?.imageUrl){H("AI enhanced");const W=await _t(C.imageUrl,"enhanced-"+a.name);return await xe(W)}return null}catch(x){return console.error("Enhancement failed:",x),null}},Ve=async()=>{if(!o)return;const a=Mt+1;he(a),f("trace-moe"),c(0),y(null),g(null),v(null),w(null),R(!1),fe([]);let x=o;const C=[];try{if(Te&&a===1){f("enhancing"),c(15),s({title:t("screenshot.enhancingImage"),description:t("screenshot.usingAI")});const E=await Be(o);E?(x=E,c(30)):H(null)}f("trace-moe"),c(40),C.push("trace.moe");const I=new FormData;I.append("image",x);const{data:W,error:T}=await U.functions.invoke("search-anime-screenshot",{body:I});if(c(55),T){const E=W?.error;throw new Error(E||T.message)}const F=W;if(F.error)throw new Error(F.error);const z=F.result?.[0]?.similarity||0;if(F.result&&F.result.length>0&&z>=.85){g(F.result),f("complete"),c(100),fe(C),_&&N&&await $e(F.result[0]);return}if(F.result&&F.result.length>0&&g(F.result),z<.85){f("saucenao"),c(65),C.push("SauceNAO"),s({title:t("screenshot.ensembleSearch"),description:t("screenshot.queryingSauceNAO")});try{const E=new FormData;E.append("image",x);const{data:re,error:ne}=await U.functions.invoke("search-saucenao",{body:E});if(!ne&&re?.results){const le=re.results.filter(Ht=>Ht.similarity>=.8);le.length>0&&v(le)}}catch(E){console.error("SauceNAO fallback error:",E)}c(75)}const $=j?.[0]?.similarity||0;if(z<.85&&$<.85){f("ai-fallback"),c(80),C.push("AI Vision"),s({title:t("screenshot.lowConfidence"),description:t("screenshot.runningAI")});try{const E=new FormData;E.append("image",x);const{data:re,error:ne}=await U.functions.invoke("analyze-scene-ai",{body:E});c(95),!ne&&re&&w(re)}catch(E){console.error("AI fallback error:",E)}}f("complete"),c(100),fe(C),_&&N&&F.result?.[0]&&await $e(F.result[0])}catch(I){console.error("Search error:",I),y(I instanceof Error?I.message:"Failed to search anime scene. Please try again."),f("idle")}},Vt=async()=>{if(o){f("enhancing"),c(10),y(null),s({title:t("screenshot.retryingWithAI"),description:t("screenshot.enhancingQuality")});try{const a=await Be(o);if(a)r(a),H("AI enhanced"),c(50),await Ve();else throw new Error("Enhancement failed")}catch(a){console.error("Retry with upscale error:",a),y("Failed to enhance image. Try manual crop instead."),f("idle")}}},$t=()=>{l&&V(!0)},$e=async a=>{try{const x=await ks({imageUrl:a.image,animeTitle:a.filename?.replace(/\.mp4$/,"")||null,episode:a.episode,timestampFrom:a.from,timestampTo:a.to,similarity:a.similarity,anilistId:a.anilist,filename:a.filename});Pt(x?.id||null),R(!0),s({title:t("screenshot.sharedToCommunity"),description:t("screenshot.sharedDescription")})}catch(x){console.error("Share error:",x)}},Ut=()=>{switch(d){case"preprocessing":return t("screenshot.cleaningImage");case"enhancing":return t("screenshot.aiEnhancing");case"trace-moe":return t("screenshot.searchingTraceMoe");case"saucenao":return t("screenshot.queryingSauceNAOShort");case"ai-fallback":return t("screenshot.runningAIAnalysis");case"complete":return t("screenshot.searchComplete");default:return""}},be=h&&h[0]?.similarity<.85,Ue=d==="complete"&&(!h||h.length===0)&&(!j||j.length===0),Ot=j&&j.length>0;return e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"px-4 py-12 md:py-16",children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsxs("h2",{className:"text-3xl md:text-4xl font-bold mb-3 flex items-center justify-center gap-3",children:[e.jsx(cs,{className:"w-8 h-8 text-primary"}),t("screenshot.title")]}),e.jsx("p",{className:"text-muted-foreground text-lg",children:t("screenshot.description")})]}),e.jsx(oe,{className:"glass-card",children:e.jsxs(ie,{className:"pt-6",children:[e.jsx("div",{onDragOver:Ft,onDragLeave:Lt,onDrop:zt,className:`
relative border-2 border-dashed rounded-lg p-8 mb-6 transition-all
${k?"border-primary bg-primary/5":"border-border"}
${u?"min-h-0":"min-h-[300px]"}
flex flex-col items-center justify-center gap-4
`,children:u?e.jsxs("div",{className:"w-full",children:[e.jsx("img",{src:u,alt:"Selected screenshot",className:"max-w-full max-h-[400px] mx-auto rounded-lg shadow-lg"}),(B||Q)&&e.jsxs("div",{className:"mt-3 flex justify-center gap-2 flex-wrap",children:[B&&e.jsxs(q,{variant:"secondary",className:"gap-1",children:[e.jsx(ss,{className:"w-3 h-3"}),B]}),Q&&e.jsxs(q,{variant:"secondary",className:"gap-1 bg-primary/20 text-primary",children:[e.jsx(we,{className:"w-3 h-3"}),Q]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-4",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>l&&V(!0),className:"gap-1",children:[e.jsx(is,{className:"w-4 h-4"}),t("screenshot.adjustCrop")]}),e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>{r(null),n(null),i(null),g(null),w(null),y(null),X(null),H(null),he(0)},className:"text-muted-foreground hover:text-foreground",children:t("screenshot.clear")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"w-12 h-12 text-muted-foreground"}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg font-medium mb-1",children:t("screenshot.dropzone")}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[t("screenshot.orClick")," • ",t("screenshot.browseFormats")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("screenshot.pasteHint")})]}),e.jsx("input",{ref:Le,type:"file",accept:"image/jpeg,image/jpg,image/png,image/webp",onChange:Tt,className:"hidden","aria-label":"Upload anime screenshot",id:"screenshot-upload"}),e.jsxs(A,{onClick:()=>Le.current?.click(),variant:"outline",size:"lg",children:[e.jsx(He,{className:"w-4 h-4 mr-2"}),t("screenshot.uploadImage")]})]})}),e.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 rounded-lg bg-primary/5 border border-primary/20",children:[e.jsx(Se,{id:"use-enhancer",checked:Te,onCheckedChange:a=>Dt(a===!0)}),e.jsxs("label",{htmlFor:"use-enhancer",className:"text-sm flex items-center gap-2 cursor-pointer",children:[e.jsx(we,{className:"w-4 h-4 text-primary"}),e.jsx("span",{children:t("screenshot.aiEnhancement")}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",t("screenshot.sharpensBlurry"),")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(Se,{id:"share-community",checked:_,disabled:!N,onCheckedChange:a=>{if(!N){s({title:t("common.loginRequired"),description:t("screenshot.loginToShare")});return}P(a===!0)}}),e.jsxs("label",{htmlFor:"share-community",className:"text-sm flex items-center gap-2 cursor-pointer",children:[e.jsx(rs,{className:"w-4 h-4 text-primary"}),e.jsx("span",{children:t("screenshot.shareWithCommunity")}),!N&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",t("common.loginRequired"),")"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(A,{onClick:Ve,disabled:!o||d!=="idle"&&d!=="complete",size:"lg",className:"w-full neon-glow-pink bg-gradient-to-r from-primary to-secondary hover:opacity-90",children:d!=="idle"&&d!=="complete"?e.jsxs(e.Fragment,{children:[e.jsx(ns,{className:"w-5 h-5 mr-2 animate-spin"}),Ut()]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"w-5 h-5 mr-2"}),t("screenshot.searchAnime")]})}),d!=="idle"&&d!=="complete"&&e.jsx(ht,{value:p,className:"h-1"})]}),M&&e.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2 text-sm text-primary",children:[e.jsx(Re,{className:"w-4 h-4"}),t("screenshot.sharedToExplore")]}),S&&e.jsxs(ye,{variant:"destructive",className:"mt-6",children:[e.jsx(as,{className:"h-4 w-4"}),e.jsx(je,{children:S})]}),(be||Ue)&&d==="complete"&&e.jsxs(ye,{className:"mt-6 border-warning/50 bg-warning/10",children:[e.jsx(os,{className:"h-4 w-4 text-warning"}),e.jsx(je,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsx("strong",{className:"text-warning",children:t(Ue?"screenshot.noMatches":"screenshot.lowConfidence")}),e.jsx("span",{className:"block sm:inline sm:ml-1 text-muted-foreground",children:t("screenshot.improveResults")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:$t,className:"gap-1 border-warning/50 hover:bg-warning/10",children:[e.jsx(ds,{className:"w-4 h-4"}),t("screenshot.manualCrop")]}),!Q&&e.jsxs(A,{variant:"outline",size:"sm",onClick:Vt,className:"gap-1 border-primary/50 hover:bg-primary/10",children:[e.jsx(we,{className:"w-4 h-4"}),t("screenshot.retryWithEnhance")]}),N&&e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>Y(!0),className:"gap-1 border-secondary/50 hover:bg-secondary/10",children:[e.jsx(We,{className:"w-4 h-4"}),t("screenshot.correctTheSauce")]})]})]})})]}),Fe.length>0&&d==="complete"&&e.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[t("screenshot.searched"),":"]}),Fe.map(a=>e.jsx(q,{variant:"outline",className:"text-xs",children:a},a))]}),h&&h.length>0&&e.jsxs("div",{className:"mt-8 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-semibold",children:t("screenshot.results")}),be&&N&&e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>Y(!0),className:"gap-1",children:[e.jsx(We,{className:"w-4 h-4"}),t("screenshot.submitCorrection")]})]}),h.map((a,x)=>e.jsxs(oe,{className:`
glass-card-hover
${x===0?"border-primary/50":""}
${a.similarity<.8?"opacity-75":""}
`,children:[e.jsx(Zt,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(Jt,{className:"text-lg mb-2",children:a.filename.replace(/\.mp4$/,"")}),e.jsxs(Qt,{className:"space-y-1",children:[a.episode&&e.jsxs("div",{children:[t("screenshot.episode"),": ",a.episode]}),e.jsxs("div",{children:[t("screenshot.timestamp"),": ",ze(a.from)," - ",ze(a.to)]}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("screenshot.confidence"),":"]}),e.jsxs("span",{className:`font-bold ${pe(a.similarity)}`,children:[(a.similarity*100).toFixed(1),"%"]}),e.jsx(q,{variant:"outline",className:`text-xs ${pe(a.similarity)}`,children:At(a.similarity)})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[x===0&&a.similarity>=.85&&e.jsx("span",{className:"px-3 py-1 text-xs font-semibold rounded-full bg-primary text-primary-foreground",children:t("screenshot.bestMatch")}),x===0&&a.similarity<.85&&e.jsx("span",{className:"px-3 py-1 text-xs font-semibold rounded-full bg-warning/20 text-warning",children:t("screenshot.uncertain")})]})]})}),a.image&&e.jsx(ie,{children:e.jsx("img",{src:a.image,alt:"Scene preview",className:"w-full rounded-lg"})})]},x))]}),Ot&&e.jsxs("div",{className:"mt-8 space-y-4",children:[e.jsxs("h3",{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5 text-secondary"}),t("screenshot.sauceNAOResults")]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:j.slice(0,4).map((a,x)=>e.jsx(oe,{className:"glass-card-hover",children:e.jsxs(ie,{className:"p-3 flex gap-3",children:[a.thumbnail&&e.jsx("img",{src:a.thumbnail,alt:a.title,className:"w-16 h-24 object-cover rounded"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h5",{className:"font-medium text-sm line-clamp-2",children:a.title}),a.episode&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[t("screenshot.episode"),": ",a.episode]}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs("span",{className:`text-xs font-medium ${pe(a.similarity)}`,children:[(a.similarity*100).toFixed(1),"%"]}),e.jsx(q,{variant:"outline",className:"text-xs",children:"SauceNAO"})]})]})]})},x))})]}),b&&e.jsxs("div",{className:"mt-8 space-y-4",children:[e.jsxs("h3",{className:"text-xl font-semibold flex items-center gap-2",children:[e.jsx(Gt,{className:"w-5 h-5 text-primary"}),t("screenshot.aiDetectiveAnalysis")]}),e.jsx(oe,{className:"glass-card border-primary/30",children:e.jsxs(ie,{className:"pt-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-1",children:t("screenshot.sceneDescription")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:b.analysis.description})]}),b.analysis.characters.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-1",children:t("screenshot.characters")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:b.analysis.characters.map((a,x)=>e.jsx(q,{variant:"secondary",children:typeof a=="string"?a:a.name||JSON.stringify(a)},x))})]}),b.analysis.possibleAnime.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-1",children:t("screenshot.aiSuggestions")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:b.analysis.possibleAnime.map((a,x)=>e.jsx(q,{className:"bg-primary/20 text-primary",children:a},x))})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("screenshot.aiConfidence"),":"]}),e.jsx(q,{variant:b.analysis.confidence==="high"?"default":b.analysis.confidence==="medium"?"secondary":"outline",children:b.analysis.confidence})]})]})}),b.anilistResults.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:t("screenshot.relatedAnime")}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:b.anilistResults.map(a=>e.jsx(oe,{className:"glass-card-hover",children:e.jsxs(ie,{className:"p-3 flex gap-3",children:[e.jsx("img",{src:a.coverImage.large,alt:a.title.romaji,className:"w-16 h-24 object-cover rounded"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h5",{className:"font-medium text-sm line-clamp-2",children:a.title.english||a.title.romaji}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:a.genres.slice(0,2).map(x=>e.jsx(q,{variant:"outline",className:"text-xs px-1",children:x},x))}),a.averageScore&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[t("screenshot.score"),": ",a.averageScore,"%"]})]})]})},a.id))})]})]}),h&&N&&!be&&e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsxs(A,{variant:"ghost",size:"sm",onClick:()=>Y(!0),className:"gap-1 text-muted-foreground",children:[e.jsx(ms,{className:"w-4 h-4"}),t("screenshot.knowTheAnswer")]})}),e.jsxs("p",{className:"text-xs text-muted-foreground text-center mt-6",children:[t("screenshot.poweredBy")," ",e.jsx("a",{href:"https://trace.moe",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline decoration-primary/50 hover:decoration-primary",children:"trace.moe"})," ","+"," ",e.jsx("a",{href:"https://saucenao.com",target:"_blank",rel:"noopener noreferrer",className:"text-secondary underline decoration-secondary/50 hover:decoration-secondary",children:"SauceNAO"})," ","+"," ",e.jsx("span",{className:"text-primary",children:"AI Vision"})," ","+"," ",e.jsx("span",{className:"text-primary",children:"AI Upscaler"})]})]})})]})}),ee&&l&&u&&e.jsx(Gs,{imageUrl:u,originalFile:l,onCropComplete:Bt,onCancel:()=>V(!1)}),K&&_e&&e.jsx(Zs,{sceneId:_e,currentTitle:h?.[0]?.filename?.replace(/\.mp4$/,"")||"",currentEpisode:h?.[0]?.episode||void 0,onClose:()=>Y(!1),onSubmitted:()=>{Y(!1),s({title:t("screenshot.correctionSubmitted"),description:t("screenshot.correctionThanks")})}})]})}export{jr as default};