1import{w as U,b as Z,r as i,y as ee,x as se,s as v,k as y,j as e,R as T,a8 as V,z as g,ap as ae,av as B,G as F,$ as re,B as f,an as te,W as G,aV as le,D as oe,e as ie,aW as ne,aX as ce,aY as de,p as q}from"./index-Dpbt8EhT.js";import{T as ue,a as me,b as C}from"./tabs-EA-YpKt3.js";import{u as xe}from"./useSessionSecurity-DWLyNydt.js";import{L as he}from"./LoadingSpinner-CItf0PQc.js";const je=()=>{const b=U(),{user:h}=Z(),[u,L]=i.useState([]),[$,D]=i.useState(!0),[d,k]=i.useState(null),[m,z]=i.useState("all"),[p,I]=i.useState(""),{loadPurchases:M}=ee(),{hasSubscription:O}=se(),x=O("street_casting"),w=i.useRef(0);xe(),i.useEffect(()=>{if(!h){b("/auth");return}Q(h.id),M(h.id)},[h,b,x]);const Q=async s=>{const r=++w.current;D(!0);try{const o=[],_=new Set,{data:K,error:R}=await v.from("purchases").select(` 2 user_id, 3 purchased_at, 4 downloaded, 5 videos ( 6 id, title, duration, thumbnail_url, video_url, full_video_url, cdn_url, video_type, 7 categories (name) 8 ) 9 `).eq("user_id",s).order("purchased_at",{ascending:!1});if(R)throw R;if((K??[]).filter(c=>c.user_id===s&&c.videos).forEach(c=>{var a;const t=c.videos;_.add(t.id),o.push({id:t.id,title:t.title,duration:t.duration||0,thumbnail_url:t.thumbnail_url,video_url:t.video_url,full_video_url:t.full_video_url,cdn_url:t.cdn_url,video_type:t.video_type,category_name:((a=t.categories)==null?void 0:a.name)||"",source:"purchased",purchased_at:c.purchased_at,downloaded:c.downloaded})}),x){const{data:c}=await v.from("categories").select("id").eq("slug","street-casting").single();if(c){const{data:a,error:j}=await v.from("videos").select(` 10 id, title, duration, thumbnail_url, video_url, full_video_url, cdn_url, video_type, 11 categories (name) 12 `).eq("category_id",c.id).or("video_type.is.null,video_type.eq.standard").or("is_hidden.is.null,is_hidden.eq.false").or("is_preorder.is.null,is_preorder.eq.false").order("created_at",{ascending:!1});if(j)throw j;a==null||a.forEach(l=>{var N;_.has(l.id)||(_.add(l.id),o.push({id:l.id,title:l.title,duration:l.duration||0,thumbnail_url:l.thumbnail_url,video_url:l.video_url,full_video_url:l.full_video_url,cdn_url:l.cdn_url,video_type:l.video_type,category_name:((N=l.categories)==null?void 0:N.name)||"",source:"subscription"}))})}const{data:t}=await v.from("videos").select(` 13 id, title, duration, thumbnail_url, video_url, full_video_url, cdn_url, video_type, 14 categories (name), 15 video_actors ( 16 actors (id, name) 17 ) 18 `).eq("video_type","bonus").or("is_hidden.is.null,is_hidden.eq.false");t==null||t.forEach(a=>{var j,l,N,P;_.has(a.id)||(_.add(a.id),o.push({id:a.id,title:a.title,duration:a.duration||0,thumbnail_url:a.thumbnail_url,video_url:a.video_url,full_video_url:a.full_video_url,cdn_url:a.cdn_url,video_type:a.video_type,category_name:((j=a.categories)==null?void 0:j.name)||"",source:"bonus",actor_name:(P=(N=(l=a.video_actors)==null?void 0:l[0])==null?void 0:N.actors)==null?void 0:P.name}))})}r===w.current&&L(o)}catch(o){console.error("Error loading collection:",o),y.error("Impossible de charger votre collection"),r===w.current&&L([])}finally{r===w.current&&D(!1)}},S=i.useMemo(()=>{let s=u;if(m!=="all"&&(s=s.filter(r=>r.source===m)),p.trim()){const r=p.toLowerCase();s=s.filter(o=>o.title.toLowerCase().includes(r)||o.category_name.toLowerCase().includes(r)||o.actor_name&&o.actor_name.toLowerCase().includes(r))}return s},[u,m,p]),n=i.useMemo(()=>({all:u.length,purchased:u.filter(s=>s.source==="purchased").length,subscription:u.filter(s=>s.source==="subscription").length,bonus:u.filter(s=>s.source==="bonus").length}),[u]),A=s=>k(s),[W,E]=i.useState(null),X=async s=>{if(h){if(!s.category_name.toLowerCase().includes("furies room")&&!s.category_name.toLowerCase().includes("furies x")){y.error("Le téléchargement est réservé aux clips Furies Room et Furies X");return}E(s.id);try{const r=await ce(s.id);await de({url:r.url,filename:r.filename||`${s.title}.mp4`}),await v.from("purchases").update({downloaded:!0,downloaded_at:new Date().toISOString()}).eq("user_id",h.id).eq("video_id",s.id),y.success(`Téléchargement de "${s.title}" lancé`)}catch(r){console.error("Download error:",r),y.error(r.message||"Erreur lors du téléchargement")}finally{E(null)}}},H=s=>s.category_name.toLowerCase().includes("furies room")||s.category_name.toLowerCase().includes("furies x"),Y=s=>{if(!s)return"N/A";const r=Math.floor(s/60),o=s%60;return`${r}:${o.toString().padStart(2,"0")}`},J=s=>{switch(s){case"purchased":return e.jsxs(q,{className:"bg-primary/20 text-primary border-primary/30 text-[10px] px-1.5 py-0.5",children:[e.jsx(B,{className:"w-2.5 h-2.5 mr-0.5"}),"Acheté"]});case"subscription":return e.jsxs(q,{className:"bg-violet-500/20 text-violet-400 border-violet-500/30 text-[10px] px-1.5 py-0.5",children:[e.jsx(g,{className:"w-2.5 h-2.5 mr-0.5"}),"Gold Card"]});case"bonus":return e.jsxs(q,{className:"bg-amber-500/20 text-amber-400 border-amber-500/30 text-[10px] px-1.5 py-0.5",children:[e.jsx(F,{className:"w-2.5 h-2.5 mr-0.5"}),"Bonus"]}
18)}};return $?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(T,{}),e.jsx(he,{text:"Chargement de votre collection"}),e.jsx(V,{})]}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(T,{}),e.jsxs("main",{className:"container mx-auto px-4 pt-32 pb-16",children:[e.jsxs("div",{className:"flex flex-col gap-4 mb-8",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold text-foreground mb-2",children:"Ma Collection"}),e.jsxs("p",{className:"text-muted-foreground",children:[n.all," clip",n.all>1?"s":""," accessible",n.all>1?"s":"",x&&e.jsxs("span",{className:"ml-2 inline-flex items-center gap-1 text-violet-400",children:[e.jsx(g,{className:"w-3.5 h-3.5"}),"Gold Card actif"]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-muted/30 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded-md bg-background p-2 border",children:e.jsx(ae,{className:"h-4 w-4 text-foreground"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-foreground",children:"Sécurité : 1 session par compte"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:`Pour protéger vos achats, l'accès à "Ma Collection" est limité à un seul appareil à la fois.`})]})]})}),x&&e.jsx("div",{className:"rounded-lg border border-violet-500/20 bg-violet-500/5 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded-md bg-violet-500/10 p-2 border border-violet-500/20",children:e.jsx(g,{className:"h-4 w-4 text-violet-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-foreground text-sm",children:"Votre abonnement Gold Card est actif"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Tous les clips ",e.jsx("span",{className:"text-foreground font-medium",children:"Furies Casting"})," et tous les ",e.jsx("span",{className:"text-amber-400 font-medium",children:"Clips Bonus"})," sont automatiquement ajoutés à votre collection pour un accès rapide."]})]})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-4 mb-8",children:[e.jsx(ue,{value:m,onValueChange:s=>
18z(s),className:"w-full sm:w-auto",children:e.jsxs(me,{className:"bg-muted/50 h-10",children:[e.jsxs(C,{value:"all",className:"text-xs px-3",children:["Tous (",n.all,")"]}),e.jsxs(C,{value:"purchased",className:"text-xs px-3",children:[e.jsx(B,{className:"w-3 h-3 mr-1"}),"Achats (",n.purchased,")"]}),x&&e.jsxs(C,{value:"subscription",className:"text-xs px-3",children:[e.jsx(g,{className:"w-3 h-3 mr-1"}),"Gold Card (",n.subscription,")"]}),e.jsxs(C,{value:"bonus",className:"text-xs px-3",children:[e.jsx(F,{className:"w-3 h-3 mr-1"}),"Bonus (",n.bonus,")"]})]})}),e.jsxs("div",{className:"relative w-full sm:w-64 sm:ml-auto",children:[e.jsx(re,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"Rechercher un clip...",value:p,onChange:s=>I(s.target.value),className:"w-full pl-9 pr-4 py-2 rounded-lg bg-muted/50 border border-border/50 focus:border-primary/50 focus:ring-1 focus:ring-primary/20 outline-none text-sm"})]})]}),!x&&m==="all"&&n.purchased===0&&e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"w-20 h-20 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto mb-6",children:e.jsx(g,{className:"w-10 h-10 text-primary"})}),e.jsx("h2",{className:"text-2xl font-bold mb-2",children:"Votre collection est vide"}),e.jsx("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:"Abonnez-vous à Gold Card pour accéder aux clips Furies Casting en streaming illimité, ou achetez des clips à l'unité."}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsxs(f,{onClick:()=>b("/pricing"),children:[e.jsx(g,{className:"w-4 h-4 mr-2"}),"S'abonner à Gold Card"]}),e.jsx(f,{variant:"outline",onClick:()=>b("/catalog"),children:"Explorer le catalogue"})]})]}),S.length===0&&(n.all>0||x)&&e.jsxs("div",{className:"text-center py-16",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:p?`Aucun résultat pour "${p}"`:m==="bonus"?"Aucun clip bonus débloqué. Achetez au moins 2 clips d'une même actrice pour débloquer ses bonus.":"Aucun clip dans cette catégorie"}),m==="bonus"&&e.jsx(f,{variant:"outline",onClick:()=>b("/catalog"),children:"Explorer le catalogue"})]}),S.length>0&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:S.map(s=>e.jsxs(te,{className:"group overflow-hidden bg-card border-border hover:border-primary/50 transition-all duration-300",children:[e.jsxs("div",{className:"relative aspect-video overflow-hidden",children:[e.jsx("img",{src:s.thumbnail_url||"/placeholder.svg",alt:s.title,className:"w-full h-full object-cover group-hover:scale-110 transition-transform duration-300"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/80 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300"}),e.jsx(f,{size:"icon",variant:"secondary",className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 transition-all duration-300 scale-75 group-hover:scale-100",onClick:()=>A(s),children:e.jsx(G,{className:"h-6 w-6"})}),e.jsx("div",{className:"absolute top-2 left-2",children:J(s.source)}),e.jsx("div",{className:"absolute bottom-2 right-2 px-1.5 py-0.5 bg-black/70 rounded text-[10px] text-white font-medium",children:Y(s.duration)})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"font-semibold text-foreground mb-2 line-clamp-2 text-sm",children:s.title}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground mb-3",children:[e.jsx("span",{children:s.category_name}),s.actor_name&&e.jsx("span",{className:"text-amber-400",children:s.actor_name})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{variant:"default",size:"sm",className:"flex-1",onClick:()=>A(s),children:[e.jsx(G,{className:"h-4 w-4 mr-1"}),"Regarder"]}),H(s)&&e.jsx(f,{variant:"outline",size:"sm",onClick:()=>X(s),disabled:W===s.id,title:"Télécharger MP4",children:e.jsx(le,{className:"h-4 w-4"})})]}),s.purchased_at&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-3",children:["Acheté le ",new Date(s.purchased_at).toLocaleDateString("fr-FR")]})]})]},`${s.id}-${s.source}`))})]}),e.jsx(oe,{open:!!d,onOpenChange:()=>k(null),children:e.jsx(ie,{className:"max-w-6xl p-0",children:d&&e.jsx("div",{className:"relative",children:e.jsx(ne,{videoId:d.id,videoPath:d.full_video_url||d.video_url,cdnUrl:d.cdn_url,title:d.title,poster:d.thumbnail_url,className:"w-full aspect-video"})})})}),e.jsx(V,{})]})};export{je as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.