veza/apps/web/dist_verification/assets/TrackDetailPage-BzykkTeC.js
senke 670282989b chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 19:39:18 +01:00

1 line
54 KiB
JavaScript

import{j as e,a as m}from"./vendor-react-C9dYU-TK.js";import{g as I,v as F,q as W,B as S,c as w,C as A,b as De,d as Re,L as re,h as H,f as Oe,p as Ae,D as Me,S as k,G as Ie,w as _e}from"./index-BMBS6scK.js";import{u as te,b as ae,a as U}from"./vendor-tanstack-C4XaEYj2.js";import{A as _}from"./vendor-http-CctT3C58.js";import{T as C,g as Le}from"./trackService-Dud99AaM.js";import{u as Ne,D as Pe,a as Ve,b as Ke,c as oe}from"./useIsRateLimited-8kuXO8Mx.js";import{g as je,o as ye,J as ze,q as le,r as J,aU as Ue,af as qe,c as ee,aV as Qe,aQ as $e,ah as Fe,aW as We,x as we,ae as B,aJ as He,aX as Be,i as be,ak as ne,X as ke,aY as Ge,C as Je,a3 as ce,ar as ie,aZ as Xe,E as Ye,a as Ce,$ as Ze,P as es,l as ss,n as rs,aa as ts,ao as ue,a_ as de,A as as}from"./vendor-icons-BSV6HBy1.js";import{T as ns,a as is,b as X,c as Y}from"./Tabs-CJTCBu5-.js";import{A as os}from"./avatar-DAue0w7u.js";import{I as G,L as ls}from"./input-DeoQfymd.js";import{C as cs}from"./confirmation-dialog-BlZmJOYR.js";import{a as us,c as ds}from"./vendor-utils-D0JLFg89.js";import{m as $,A as ms}from"./vendor-motion-CbAtAbUE.js";import{t as hs}from"./tracks-0_sMTeS6.js";import{u as ps}from"./useCopyToClipboard-BDqgiukK.js";import{A as xs,a as fs}from"./alert-Bql2WpQW.js";import{a as Ee,b as gs}from"./vendor-router-Dr0ZB7zf.js";import"./vendor-CjLUfV8Y.js";import"./vendor-security-DsrNJhpn.js";import"./vendor-i18n-PN7w4axr.js";import"./dropdown-CPqsiWN7.js";function vs({track:r}){const s=r.cover_art_path;return e.jsxs("div",{className:"absolute inset-0 h-layout-lyrics overflow-hidden pointer-events-none select-none",children:[s&&e.jsx("img",{src:s,alt:"","aria-hidden":"true",className:"absolute inset-0 w-full h-full object-cover scale-110 opacity-25 blur-3xl"}),e.jsx("div",{className:"absolute inset-x-0 -top-40 h-full opacity-15",style:{background:s?`url(${s}) center/cover no-repeat`:"linear-gradient(135deg, var(--primary), transparent)"}}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-transparent via-background/60 to-background"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-background/30 via-background/70 to-background"})]})}async function Ns(r){try{await I.post(`/tracks/${r}/like`)}catch(s){if(s instanceof _){if(s.response?.status===401)throw new C("Non autorisé: Veuillez vous connecter pour liker ce track","VALIDATION",!1,s);if(s.response?.status===404)throw new C("Track introuvable","VALIDATION",!1,s);if(s.response?.status===500)throw new C("Erreur serveur: Impossible de liker le track. Veuillez réessayer plus tard.","SERVER",!0,s);if(s.code==="ECONNABORTED"||s.code==="ETIMEDOUT"||!s.response)throw new C("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,s);const a=s.response?.data?.error||s.message||"Échec du like du track";throw new C(a,"UNKNOWN",!1,s)}throw s instanceof C?s:new C("Erreur inconnue lors du like du track","UNKNOWN",!1,s)}}async function js(r){try{await I.delete(`/tracks/${r}/like`)}catch(s){if(s instanceof _){if(s.response?.status===401)throw new C("Non autorisé: Veuillez vous connecter pour unliker ce track","VALIDATION",!1,s);if(s.response?.status===404)throw new C("Track introuvable","VALIDATION",!1,s);if(s.response?.status===500)throw new C("Erreur serveur: Impossible de unliker le track. Veuillez réessayer plus tard.","SERVER",!0,s);if(s.code==="ECONNABORTED"||s.code==="ETIMEDOUT"||!s.response)throw new C("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,s);const a=s.response?.data?.error||s.message||"Échec de l'unlike du track";throw new C(a,"UNKNOWN",!1,s)}throw s instanceof C?s:new C("Erreur inconnue lors de l'unlike du track","UNKNOWN",!1,s)}}async function ys(r){try{const s=await I.get(`/tracks/${r}/likes`);return{count:s.data.count,isLiked:s.data.is_liked}}catch(s){if(s instanceof _){if(s.response?.status===404)throw new C("Track introuvable","VALIDATION",!1,s);if(s.response?.status===500)throw new C("Erreur serveur: Impossible de récupérer les likes. Veuillez réessayer plus tard.","SERVER",!0,s);if(s.code==="ECONNABORTED"||s.code==="ETIMEDOUT"||!s.response)throw new C("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,s);const a=s.response?.data?.error||s.message||"Échec de la récupération des likes";throw new C(a,"UNKNOWN",!1,s)}throw s instanceof C?s:new C("Erreur inconnue lors de la récupération des likes","UNKNOWN",!1,s)}}function me({trackId:r,initialLikeCount:s,initialIsLiked:a=!1,onLikeChange:t,className:i,size:o="default",variant:n="ghost",showCount:h=!0,compact:d=!1}){const{data:g}=F(),{success:p,error:y}=W(),j=te(),u=Ne(),[N,E]=m.useState(a),[c,l]=m.useState(s??0),[x,b]=m.useState(!1),[D,R]=m.useState(!1),{data:M}=ae({queryKey:["trackLikes",r],queryFn:()=>ys(r),enabled:!!r&&!!g,staleTime:3e4,retry:!1});m.useEffect(()=>{M?(E(M.isLiked),l(M.count)):a!==void 0&&E(a),s!==void 0&&l(s)},[M,a,s]);const V=U({mutationFn:()=>Ns(r),onMutate:async()=>{E(!0),l(T=>T+1),b(!0)},onSuccess:()=>{p("Ajouté aux favoris"),t?.(!0,c+1),j.invalidateQueries({queryKey:["trackLikes",r]}),j.invalidateQueries({queryKey:["tracks"]})},onError:T=>{E(!1),l(Q=>Math.max(0,Q-1));const q=T.response?.data?.error?.message||T.response?.data?.message||T.message||"Erreur lors de l'ajout aux favoris";y(q)},onSettled:()=>{b(!1)}}),v=U({mutationFn:()=>js(r),onMutate:async()=>{E(!1),l(T=>Math.max(0,T-1)),b(!0)},onSuccess:()=>{p("Retiré des favoris"),t?.(!1,Math.max(0,c-1)),j.invalidateQueries({queryKey:["trackLikes",r]}),j.invalidateQueries({queryKey:["tracks"]})},onError:T=>{E(!0),l(Q=>Q+1);const q=T.response?.data?.error?.message||T.response?.data?.message||T.message||"Erreur lors du retrait des favoris";y(q)},onSettled:()=>{b(!1)}}),O=T=>{T.stopPropagation(),!(x||!g||u)&&(N||(R(!0),setTimeout(()=>R(!1),400)),N?v.mutate():V.mutate())};if(!g)return null;const L=V.isPending||v.isPending||x;return e.jsx(S,{onClick:O,disabled:L||u,variant:n,size:o,className:w("rounded-md transition-[color,transform] duration-[var(--sumi-duration-normal)]",i,N&&"text-destructive hover:text-destructive/90",d&&"h-auto p-1"),"aria-label":N?"Retirer des favoris":"Ajouter aux favoris","aria-pressed":N,children:L?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:w("h-4 w-4 animate-spin",h&&"mr-2")}),!d&&h&&e.jsx("span",{className:"tabular-nums tracking-tight",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:w("h-4 w-4 transition-colors duration-[var(--sumi-duration-normal)]",D&&"animate-like-bounce drop-shadow-[0_0_8px_var(--sumi-vermillion)]",N&&"fill-current",h&&"mr-2"),"aria-hidden":"true"}),h&&e.jsx("span",{className:w("tabular-nums tracking-tight",d&&"text-xs"),children:c>0?c:""})]})})}function ws({track:r,isCurrentlyPlaying:s,onPlay:a,onPause:t,onAddToQueue:i,onShare:o}){const n=r.cover_art_path,h=r.play_count??0;return e.jsxs("div",{className:"sticky top-24 space-y-6",children:[e.jsxs("div",{className:"relative aspect-square rounded-2xl overflow-hidden shadow-cover-depth border border-border group",children:[n?e.jsx("img",{src:n,alt:r.title,className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-105"}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-muted to-background flex items-center justify-center",children:e.jsx(ze,{className:"h-24 w-24 text-muted-foreground/30"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-tr from-white/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500 pointer-events-none"}),e.jsx("button",{onClick:s?t:a,className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-300 bg-background/60 cursor-pointer","aria-label":s?"Pause":"Play",children:e.jsx("div",{className:"w-16 h-16 rounded-full bg-primary flex items-center justify-center shadow-sm transition-transform duration-300",children:s?e.jsx(le,{className:"h-7 w-7 text-primary-foreground fill-current"}):e.jsx(J,{className:"h-7 w-7 text-primary-foreground fill-current ml-1"})})})]}),e.jsx(A,{variant:"glass",className:"p-4 border-white/5 bg-black/30 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center gap-3",children:[s?e.jsxs(S,{onClick:t,size:"lg",className:"flex-1 h-12 bg-primary text-primary-foreground font-bold rounded-full shadow-sm hover:brightness-110 transition-all duration-300",children:[e.jsx(le,{className:"h-5 w-5 mr-2 fill-current"})," Pause"]}):e.jsxs(S,{onClick:a,size:"lg",className:"flex-1 h-12 bg-primary text-primary-foreground font-bold rounded-full shadow-sm hover:brightness-110 transition-all duration-300",children:[e.jsx(J,{className:"h-5 w-5 mr-2 fill-current"})," Play"]}),e.jsx(me,{trackId:r.id,initialLikeCount:r.like_count,size:"icon",variant:"ghost",showCount:!1,className:"h-12 w-12 rounded-full hover:bg-muted/50"}),e.jsx(S,{onClick:i,variant:"ghost",size:"icon",className:"h-12 w-12 rounded-full hover:bg-muted/50",title:"Add to Queue",children:e.jsx(Ue,{className:"h-5 w-5"})}),e.jsx(S,{onClick:o,variant:"ghost",size:"icon",className:"h-12 w-12 rounded-full hover:bg-muted/50",title:"Share",children:e.jsx(qe,{className:"h-5 w-5"})})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(A,{variant:"glass",className:"p-4 flex flex-col items-center justify-center bg-muted/20 text-center hover:bg-muted/50 transition-colors duration-300 group/stat",children:[e.jsx(J,{className:"w-4 h-4 text-primary mb-1.5 transition-transform duration-300 group-hover/stat:scale-110"}),e.jsx("span",{className:"text-xl font-bold text-foreground tabular-nums",children:h.toLocaleString()}),e.jsx("span",{className:"text-label",children:"Plays"})]}),e.jsxs(A,{variant:"glass",className:"p-4 flex flex-col items-center justify-center bg-muted/20 text-center hover:bg-muted/50 transition-colors duration-300 group/stat",children:[e.jsx(me,{trackId:r.id,initialLikeCount:r.like_count,size:"sm",variant:"ghost",showCount:!0,compact:!0,className:"flex-col gap-0.5 h-auto p-0 hover:bg-transparent"}),e.jsx("span",{className:"text-label",children:"Likes"})]})]})]})}function he(r){const s=Math.floor(r/60),a=Math.floor(r%60);return`${s}:${a.toString().padStart(2,"0")}`}function bs(){const r=m.useMemo(()=>Array.from({length:80},(s,a)=>{const t=Math.sin(a*.15)*30+Math.sin(a*.08)*15+40;return Math.max(8,Math.min(95,t))}),[]);return e.jsx("div",{className:"flex items-end gap-px h-16 w-full","aria-hidden":"true",children:r.map((s,a)=>e.jsx("div",{className:"flex-1 rounded-full bg-primary/20 hover:bg-primary/50 transition-colors duration-150 cursor-pointer",style:{height:`${s}%`,minWidth:"2px"}},a))})}function z({icon:r,label:s,value:a}){return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-muted/30 border border-border hover:bg-muted/50 transition-colors duration-300",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-primary/10 text-primary shrink-0",children:r}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-label",children:s}),e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:String(a)})]})]})}function ks({track:r}){const s=r.waveform_path,a=r.album,t=r.year,i=r.genre,o=r.bitrate,n=r.sample_rate,h=r.format,d=r.created_at,g=d?new Date(d).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}):null;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[i&&e.jsx("span",{className:"inline-block text-caption mb-2 px-2.5 py-0.5 rounded-full bg-primary/10 text-primary text-xs font-medium uppercase tracking-wider",children:i}),e.jsx("h1",{className:"text-display md:text-4xl lg:text-5xl font-heading text-foreground mb-2 leading-tight",children:r.title}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-lg text-muted-foreground",children:[e.jsx("span",{className:"text-primary font-medium",children:r.artist}),a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground/50",children:"·"}),e.jsx("span",{children:a})]}),t!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground/50",children:"·"}),e.jsx("span",{children:t})]}),e.jsx("span",{className:"text-muted-foreground/50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ee,{className:"w-3.5 h-3.5"})," ",he(r.duration)]})]})]}),s?e.jsxs("div",{className:"relative h-20 w-full bg-black/20 rounded-xl border border-white/5 overflow-hidden group cursor-pointer",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-primary/10 to-primary/5 opacity-50"}),e.jsx("img",{src:s,alt:"Waveform",className:"w-full h-full object-cover opacity-60 group-hover:opacity-90 transition-opacity duration-300 mix-blend-screen"}),e.jsx("div",{className:"absolute top-0 bottom-0 left-1/3 w-px bg-primary/60"})]}):e.jsx("div",{className:"relative py-2 px-4 bg-muted/20 rounded-xl border border-border",children:e.jsx(bs,{})}),e.jsx(A,{variant:"glass",className:"p-4 bg-muted/20 border-border",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:[e.jsx(z,{icon:e.jsx(ee,{className:"w-4 h-4"}),label:"Duration",value:he(r.duration)}),i&&e.jsx(z,{icon:e.jsx(Qe,{className:"w-4 h-4"}),label:"Genre",value:i}),h&&e.jsx(z,{icon:e.jsx($e,{className:"w-4 h-4"}),label:"Format",value:h.toUpperCase()}),o!=null&&o>0&&e.jsx(z,{icon:e.jsx(Fe,{className:"w-4 h-4"}),label:"Bitrate",value:`${o} kbps`}),n!=null&&n>0&&e.jsx(z,{icon:e.jsx(We,{className:"w-4 h-4"}),label:"Sample Rate",value:`${(n/1e3).toFixed(1)} kHz`}),g&&e.jsx(z,{icon:e.jsx(we,{className:"w-4 h-4"}),label:"Uploaded",value:g})]})})]})}class f extends Error{constructor(s,a,t=!1,i){super(s),this.code=a,this.retryable=t,this.originalError=i,this.name="CommentError"}}async function Se(r,s,a){try{return(await I.post(`/tracks/${r}/comments`,{content:s,parent_id:a})).data.comment}catch(t){if(t instanceof _){if(t.response?.status===401)throw new f("Non autorisé: Veuillez vous connecter pour commenter","VALIDATION",!1,t);if(t.response?.status===404)throw new f("Track ou commentaire parent introuvable","VALIDATION",!1,t);if(t.response?.status===400){const o=t.response?.data?.error||"Données invalides";throw new f(o,"VALIDATION",!1,t)}if(t.response?.status===500)throw new f("Erreur serveur: Impossible de créer le commentaire. Veuillez réessayer plus tard.","SERVER",!0,t);if(t.code==="ECONNABORTED"||t.code==="ETIMEDOUT"||!t.response)throw new f("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,t);const i=t.response?.data?.error||t.message||"Échec de la création du commentaire";throw new f(i,"UNKNOWN",!1,t)}throw t instanceof f?t:new f("Erreur inconnue lors de la création du commentaire","UNKNOWN",!1,t)}}async function Cs(r,s=1,a=20){try{return(await I.get(`/tracks/${r}/comments?page=${s}&limit=${a}`)).data}catch(t){if(t instanceof _){if(t.response?.status===404)throw new f("Track introuvable","VALIDATION",!1,t);if(t.response?.status===500)throw new f("Erreur serveur: Impossible de récupérer les commentaires. Veuillez réessayer plus tard.","SERVER",!0,t);if(t.code==="ECONNABORTED"||t.code==="ETIMEDOUT"||!t.response)throw new f("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,t);const i=t.response?.data?.error||t.message||"Échec de la récupération des commentaires";throw new f(i,"UNKNOWN",!1,t)}throw t instanceof f?t:new f("Erreur inconnue lors de la récupération des commentaires","UNKNOWN",!1,t)}}async function Es(r,s){try{return(await I.put(`/comments/${r}`,{content:s})).data.comment}catch(a){if(a instanceof _){if(a.response?.status===401)throw new f("Non autorisé: Veuillez vous connecter pour modifier ce commentaire","VALIDATION",!1,a);if(a.response?.status===403)throw new f("Non autorisé: Vous ne pouvez modifier que vos propres commentaires","VALIDATION",!1,a);if(a.response?.status===404)throw new f("Commentaire introuvable","VALIDATION",!1,a);if(a.response?.status===400){const i=a.response?.data?.error||"Données invalides";throw new f(i,"VALIDATION",!1,a)}if(a.response?.status===500)throw new f("Erreur serveur: Impossible de mettre à jour le commentaire. Veuillez réessayer plus tard.","SERVER",!0,a);if(a.code==="ECONNABORTED"||a.code==="ETIMEDOUT"||!a.response)throw new f("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,a);const t=a.response?.data?.error||a.message||"Échec de la mise à jour du commentaire";throw new f(t,"UNKNOWN",!1,a)}throw a instanceof f?a:new f("Erreur inconnue lors de la mise à jour du commentaire","UNKNOWN",!1,a)}}async function Ss(r){try{await I.delete(`/comments/${r}`)}catch(s){if(s instanceof _){if(s.response?.status===401)throw new f("Non autorisé: Veuillez vous connecter pour supprimer ce commentaire","VALIDATION",!1,s);if(s.response?.status===403)throw new f("Non autorisé: Vous ne pouvez supprimer que vos propres commentaires","VALIDATION",!1,s);if(s.response?.status===404)throw new f("Commentaire introuvable","VALIDATION",!1,s);if(s.response?.status===500)throw new f("Erreur serveur: Impossible de supprimer le commentaire. Veuillez réessayer plus tard.","SERVER",!0,s);if(s.code==="ECONNABORTED"||s.code==="ETIMEDOUT"||!s.response)throw new f("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,s);const a=s.response?.data?.error||s.message||"Échec de la suppression du commentaire";throw new f(a,"UNKNOWN",!1,s)}throw s instanceof f?s:new f("Erreur inconnue lors de la suppression du commentaire","UNKNOWN",!1,s)}}async function Ts(r,s=1,a=20){try{return(await I.get(`/comments/${r}/replies?page=${s}&limit=${a}`)).data}catch(t){if(t instanceof _){if(t.response?.status===404)throw new f("Commentaire parent introuvable","VALIDATION",!1,t);if(t.response?.status===500)throw new f("Erreur serveur: Impossible de récupérer les réponses. Veuillez réessayer plus tard.","SERVER",!0,t);if(t.code==="ECONNABORTED"||t.code==="ETIMEDOUT"||!t.response)throw new f("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,t);const i=t.response?.data?.error||t.message||"Échec de la récupération des réponses";throw new f(i,"UNKNOWN",!1,t)}throw t instanceof f?t:new f("Erreur inconnue lors de la récupération des réponses","UNKNOWN",!1,t)}}function Ds({count:r,className:s}){return e.jsx(De,{className:w(s),children:e.jsxs(Re,{className:"flex items-center gap-2 tracking-tight",children:[e.jsx(B,{className:"h-5 w-5 text-primary/90","aria-hidden":!0}),"Commentaires (",r,")"]})})}const Rs=3;function Os({commentId:r,trackId:s,showReplies:a,initialReplies:t}){const i=Array.isArray(t)&&t.length>0,{data:o,isLoading:n}=ae({queryKey:["commentReplies",r],queryFn:()=>Ts(r,1,20),enabled:a&&!i});return{replies:i?t:o?.replies??[],isLoadingReplies:a&&!i&&n}}function As({comment:r,trackId:s,callbacks:a={}}){const{data:t}=F(),{success:i,error:o}=W(),n=te(),{onReplySuccess:h,onEditSuccess:d,onDeleteSuccess:g}=a,p=U({mutationFn:c=>Se(s,c,r.id),onMutate:async c=>{await n.cancelQueries({queryKey:["commentReplies",r.id]}),await n.cancelQueries({queryKey:["trackComments",s]});const l=n.getQueryData(["commentReplies",r.id]),x=n.getQueryData(["trackComments",s]);if(l&&t){const b={id:`temp-${Date.now()}`,track_id:s,user_id:t.id,parent_id:r.id,content:c.trim(),is_edited:!1,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),user:{id:t.id,username:t.username||"",avatar:t.avatar_url}};n.setQueryData(["commentReplies",r.id],{...l,replies:[...l.replies||[],b]})}return{previousReplies:l,previousComments:x}},onError:(c,l,x)=>{x?.previousReplies&&n.setQueryData(["commentReplies",r.id],x.previousReplies),x?.previousComments&&n.setQueryData(["trackComments",s],x.previousComments),o(c.message||"Erreur lors de la publication de la réponse")},onSuccess:()=>{n.invalidateQueries({queryKey:["trackComments",s]}),n.invalidateQueries({queryKey:["commentReplies",r.id]}),i("Réponse publiée"),h?.()}}),y=U({mutationFn:c=>Es(r.id,c),onMutate:async c=>{await n.cancelQueries({queryKey:["trackComments",s]}),await n.cancelQueries({queryKey:["commentReplies",r.parent_id||r.id]});const l=n.getQueryData(["trackComments",s]),x=r.parent_id?n.getQueryData(["commentReplies",r.parent_id]):null;return l&&n.setQueryData(["trackComments",s],{...l,comments:l.comments.map(b=>b.id===r.id?{...b,content:c.trim(),is_edited:!0,updated_at:new Date().toISOString()}:b)}),x&&r.parent_id&&n.setQueryData(["commentReplies",r.parent_id],{...x,replies:x.replies.map(b=>b.id===r.id?{...b,content:c.trim(),is_edited:!0,updated_at:new Date().toISOString()}:b)}),{previousComments:l,previousReplies:x}},onError:(c,l,x)=>{x?.previousComments&&n.setQueryData(["trackComments",s],x.previousComments),x?.previousReplies&&r.parent_id&&n.setQueryData(["commentReplies",r.parent_id],x.previousReplies),o(c.message||"Erreur lors de la modification")},onSuccess:()=>{n.invalidateQueries({queryKey:["trackComments",s]}),i("Commentaire modifié"),d?.()}}),j=U({mutationFn:()=>Ss(r.id),onMutate:async()=>{await n.cancelQueries({queryKey:["trackComments",s]}),await n.cancelQueries({queryKey:["commentReplies",r.parent_id||r.id]});const c=n.getQueryData(["trackComments",s]),l=r.parent_id?n.getQueryData(["commentReplies",r.parent_id]):null;return c&&n.setQueryData(["trackComments",s],{...c,comments:c.comments.filter(x=>x.id!==r.id),total:Math.max((c.total||1)-1,0)}),l&&r.parent_id&&n.setQueryData(["commentReplies",r.parent_id],{...l,replies:l.replies.filter(x=>x.id!==r.id)}),{previousComments:c,previousReplies:l}},onError:(c,l,x)=>{x?.previousComments&&n.setQueryData(["trackComments",s],x.previousComments),x?.previousReplies&&r.parent_id&&n.setQueryData(["commentReplies",r.parent_id],x.previousReplies),o("Erreur lors de la suppression")},onSuccess:()=>{n.invalidateQueries({queryKey:["trackComments",s]}),i("Commentaire supprimé"),g?.()}});return{createReplyMutation:p,updateCommentMutation:y,deleteCommentMutation:j,handleReplySubmit:(c,l)=>{c.preventDefault(),!(!l.trim()||!t)&&p.mutate(l.trim())},handleEditSubmit:(c,l)=>{c.preventDefault(),l.trim()&&y.mutate(l.trim())},handleDelete:()=>{j.mutate()}}}function Ms({comment:r,canEdit:s,canDelete:a,onEdit:t,onDelete:i,className:o}){return e.jsxs("div",{className:w("flex items-start justify-between gap-2",o),"data-testid":"comment-thread-header",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm tracking-tight text-foreground",children:r.user?.username||"Utilisateur"}),e.jsx("span",{className:"text-xs text-muted-foreground/90",children:us(new Date(r.created_at),{addSuffix:!0,locale:ds})}),r.is_edited&&e.jsx("span",{className:"text-xs text-muted-foreground/80 italic",children:"(modifié)"})]})}),(s||a)&&e.jsxs(Pe,{children:[e.jsx(Ve,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-md transition-colors duration-[var(--sumi-duration-normal)] hover:text-foreground hover:bg-muted/50",children:e.jsx(He,{className:"h-4 w-4"})})}),e.jsxs(Ke,{align:"end",className:"rounded-lg",children:[s&&e.jsxs(oe,{onClick:t,children:[e.jsx(Be,{className:"mr-2 h-4 w-4"}),"Modifier"]}),a&&e.jsxs(oe,{onClick:i,className:"text-destructive",children:[e.jsx(be,{className:"mr-2 h-4 w-4"}),"Supprimer"]})]})]})]})}function Is({comment:r,isEditing:s,editContent:a,onEditContentChange:t,onEditSubmit:i,onEditCancel:o,isEditPending:n,className:h}){return s?e.jsxs("form",{onSubmit:i,className:w("space-y-2 rounded-lg transition-opacity duration-[var(--sumi-duration-normal)]",h),"data-testid":"comment-edit-form",children:[e.jsx(G,{value:a,onChange:d=>t(d.target.value),maxLength:500,autoFocus:!0,className:"rounded-md transition-[border-color,box-shadow] duration-[var(--sumi-duration-normal)]"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{type:"submit",size:"sm",disabled:!a.trim()||n,className:"rounded-md transition-transform duration-[var(--sumi-duration-normal)] active:scale-95",children:[n?e.jsx(re,{size:"sm",inline:!0,className:"mr-2"}):e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Enregistrer"]}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:o,className:"rounded-md transition-colors duration-[var(--sumi-duration-normal)]",children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Annuler"]})]})]}):e.jsx("p",{className:w("text-sm text-foreground/90 whitespace-pre-wrap break-words tracking-tight leading-relaxed transition-colors duration-[var(--sumi-duration-normal)]",h),"data-testid":"comment-content",children:r.content})}const pe={type:"spring",stiffness:300,damping:30},xe={rest:{scale:1},hover:{scale:1.03},tap:{scale:.97}};function _s({canReply:r,hasUser:s,repliesCount:a,showReplies:t,onToggleReply:i,onToggleReplies:o,className:n}){return e.jsxs("div",{className:w("flex items-center gap-4",n),"data-testid":"comment-thread-actions",children:[r&&s&&e.jsx($.div,{initial:"rest",whileHover:"hover",whileTap:"tap",variants:xe,transition:pe,children:e.jsxs(S,{variant:"ghost",size:"sm",onClick:i,className:"h-7 text-xs tracking-tight rounded-md transition-colors duration-[var(--sumi-duration-normal)] hover:text-primary hover:bg-primary/10",children:[e.jsx(Ge,{className:"h-3 w-3 mr-1 text-primary/90"}),"Répondre"]})}),a>0&&e.jsx($.div,{initial:"rest",whileHover:"hover",whileTap:"tap",variants:xe,transition:pe,children:e.jsxs(S,{variant:"ghost",size:"sm",onClick:o,className:"h-7 text-xs tracking-tight rounded-md transition-colors duration-[var(--sumi-duration-normal)] hover:text-primary hover:bg-primary/10",children:[e.jsx(B,{className:"h-3 w-3 mr-1 text-primary/90"}),t?"Masquer":"Afficher"," ",a," ",a===1?"réponse":"réponses"]})})]})}function Ls({placeholder:r,value:s,onChange:a,onSubmit:t,onCancel:i,isPending:o,className:n}){return e.jsxs("form",{onSubmit:t,className:w("space-y-2 pt-2 rounded-lg transition-opacity duration-[var(--sumi-duration-normal)]",n),"data-testid":"comment-reply-form",children:[e.jsx(G,{value:s,onChange:h=>a(h.target.value),placeholder:r,maxLength:500,autoFocus:!0,className:"rounded-md transition-[border-color,box-shadow] duration-[var(--sumi-duration-normal)]"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{type:"submit",size:"sm",disabled:!s.trim()||o,className:"rounded-md transition-transform duration-[var(--sumi-duration-normal)] active:scale-95",children:[o?e.jsx(re,{size:"sm",inline:!0,className:"mr-2"}):e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Publier"]}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:i,className:"rounded-md transition-colors duration-[var(--sumi-duration-normal)]",children:[e.jsx(ke,{className:"h-4 w-4 mr-2"}),"Annuler"]})]})]})}function se({className:r}){return e.jsxs("div",{className:w("flex gap-4 animate-pulse rounded-lg transition-opacity duration-[var(--sumi-duration-normal)]",r),"data-testid":"comment-thread-skeleton",children:[e.jsx("div",{className:"h-8 w-8 shrink-0 rounded-full bg-muted"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-24 rounded-md bg-muted"}),e.jsx("div",{className:"h-3 w-16 rounded-md bg-muted"})]}),e.jsx("div",{className:"h-4 w-full rounded-md bg-muted"}),e.jsx("div",{className:"h-4 w-2/3 rounded-md bg-muted"})]})]})}function Ps({isLoading:r,children:s,className:a}){return e.jsx("div",{className:w("space-y-4 pt-2 pl-4 border-l-2 border-border/80 rounded-sm transition-colors duration-[var(--sumi-duration-normal)]",a),"data-testid":"comment-replies-list",children:r?e.jsxs("div",{className:"space-y-2","data-testid":"replies-loading",children:[e.jsx(se,{}),e.jsx(se,{})]}):s})}function Te({comment:r,trackId:s,depth:a=0,className:t}){const{data:i}=F(),[o,n]=m.useState(!1),[h,d]=m.useState(!1),[g,p]=m.useState(""),[y,j]=m.useState(r.content),[u,N]=m.useState(a===0),[E,c]=m.useState(!1),{replies:l,isLoadingReplies:x}=Os({commentId:r.id,trackId:s,showReplies:u,initialReplies:r.replies}),{createReplyMutation:b,updateCommentMutation:D,deleteCommentMutation:R,handleReplySubmit:M,handleEditSubmit:V,handleDelete:v}=As({comment:r,trackId:s,callbacks:{onReplySuccess:()=>{p(""),n(!1),N(!0)},onEditSuccess:()=>d(!1),onDeleteSuccess:()=>c(!1)}}),O=a<Rs,L=i?.id===r.user_id,T=i?.id===r.user_id||i?.role==="admin",q=K=>{V(K,y)},Q=K=>{M(K,g)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:w("space-y-4 rounded-lg p-3 -m-3 transition-[color,box-shadow] duration-[var(--sumi-duration-normal)]","hover:bg-muted/20 focus-within:ring-1 focus-within:ring-primary/20 focus-within:ring-inset focus-within:bg-muted/10",t),children:e.jsxs("div",{className:"flex gap-4",children:[e.jsx(os,{src:r.user?.avatar,fallback:r.user?.username?.charAt(0).toUpperCase()||"U",size:"sm",className:"h-8 w-8 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsx(Ms,{comment:r,canEdit:L,canDelete:T,onEdit:()=>d(!0),onDelete:()=>c(!0)}),e.jsx(Is,{comment:r,isEditing:h,editContent:y,onEditContentChange:j,onEditSubmit:q,onEditCancel:()=>{d(!1),j(r.content)},isEditPending:D.isPending}),!h&&e.jsxs(e.Fragment,{children:[e.jsx(_s,{canReply:O,hasUser:!!i,repliesCount:l.length,showReplies:u,onToggleReply:()=>n(!o),onToggleReplies:()=>N(!u)}),o&&i&&e.jsx(Ls,{placeholder:`Répondre à ${r.user?.username}...`,value:g,onChange:p,onSubmit:Q,onCancel:()=>{n(!1),p("")},isPending:b.isPending}),e.jsx(ms,{initial:!1,children:u&&e.jsx($.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{type:"spring",stiffness:300,damping:30},className:"overflow-hidden",children:e.jsx(Ps,{isLoading:x,children:l.map(K=>e.jsx(Te,{comment:K,trackId:s,depth:a+1},K.id))})})})]})]})]})}),e.jsx(cs,{open:E,onClose:()=>c(!1),onConfirm:v,title:"Supprimer le commentaire",description:"Êtes-vous sûr de vouloir supprimer ce commentaire ? Cette action est irréversible.",confirmLabel:"Supprimer",cancelLabel:"Annuler",variant:"destructive",isLoading:R.isPending})]})}function Vs({rows:r=4,className:s}){return e.jsx("div",{className:w("space-y-4",s),"data-testid":"comment-section-skeleton",children:Array.from({length:Math.min(Math.max(r,1),6)}).map((a,t)=>e.jsx(se,{},t))})}function Ks({className:r}){return e.jsx("div",{className:w("text-center text-muted-foreground/90 py-8 text-sm tracking-tight",r),"data-testid":"comment-section-empty",children:"Aucun commentaire pour le moment. Soyez le premier à commenter !"})}function zs({error:r,resourceId:s,onRetry:a,className:t}){return e.jsx("div",{className:w(t),"data-testid":"comment-section-error",children:e.jsx(H,{error:r,variant:"card",severity:"error",context:{action:"fetching comments",resource:"comments",resourceId:s},onRetry:a})})}function Us({value:r,onChange:s,onSubmit:a,placeholder:t="Écrire un commentaire...",maxLength:i=500,isPending:o=!1,isRateLimited:n=!1,hasUser:h,className:d}){const g=!r.trim()||o||n,p=h;return e.jsx("div",{className:w("transition-opacity duration-[var(--sumi-duration-normal)]",d),"data-testid":"comment-editor",children:p?e.jsxs("form",{onSubmit:a,className:"flex gap-2",children:[e.jsx(G,{value:r,onChange:y=>s(y.target.value),placeholder:t,maxLength:i}),e.jsx(S,{type:"submit",disabled:g,children:o?e.jsx(re,{size:"sm",inline:!0}):e.jsx(ne,{className:"h-4 w-4"})})]}):e.jsx("p",{className:"text-sm text-muted-foreground tracking-tight",children:"Connectez-vous pour commenter"})})}const qs={visible:{transition:{staggerChildren:.06,delayChildren:.03}}},Qs={hidden:{opacity:0,y:10},visible:{opacity:1,y:0,transition:{type:"spring",stiffness:300,damping:30}}};function $s({comments:r,trackId:s,className:a}){return e.jsx($.ul,{className:w("space-y-4 list-none p-0 m-0",a),variants:qs,initial:"hidden",animate:"visible","data-testid":"comment-list",children:r.map(t=>e.jsx($.li,{variants:Qs,children:e.jsx(Te,{comment:t,trackId:s})},t.id))})}function Fs({page:r,totalPages:s,onPageChange:a,className:t}){return s<=1?null:e.jsxs("div",{className:w("flex items-center justify-center gap-2 pt-4",t),"data-testid":"comment-section-pagination",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>a(Math.max(1,r-1)),disabled:r===1,children:"Précédent"}),e.jsxs("span",{className:"text-sm text-muted-foreground/90 tracking-tight",children:["Page ",r," sur ",s]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>a(Math.min(s,r+1)),disabled:r===s,children:"Suivant"})]})}const fe=20;function Ws({trackId:r}){const{data:s}=F(),a=W(),t=te(),i=Ne(),[o,n]=m.useState(""),[h,d]=m.useState(null),[g,p]=m.useState(1),[y,j]=m.useState(""),[u,N]=m.useState(0),{data:E,isLoading:c,error:l}=ae({queryKey:["trackComments",r,g],queryFn:()=>Cs(r,g,fe),enabled:!!r}),x=U({mutationFn:v=>Se(r,v),onMutate:async v=>{await t.cancelQueries({queryKey:["trackComments",r]});const O=t.getQueryData(["trackComments",r,g]);if(O&&s){const L={id:`temp-${Date.now()}`,track_id:r,user_id:s.id,content:v.trim(),is_edited:!1,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),user:{id:s.id,username:s.username||"",avatar:s.avatar_url}};t.setQueryData(["trackComments",r,g],{...O,comments:[L,...O.comments],total:(O.total||0)+1})}return{previousComments:O}},onError:(v,O,L)=>{L?.previousComments&&t.setQueryData(["trackComments",r,g],L.previousComments),d(new Error(v.message||"Erreur lors de la publication")),j(o.trim())},onSuccess:()=>{t.invalidateQueries({queryKey:["trackComments",r]}),n(""),d(null),N(0),j(""),a.success("Commentaire publié")}}),b=v=>{v.preventDefault(),!(!o.trim()||!s)&&(j(o.trim()),x.mutate(o.trim()))},D=async()=>{if(!(!y||u>=3)){N(v=>v+1);try{await x.mutateAsync(y)}catch{}}},R=E?.comments?.filter(v=>!v.parent_id)||[],M=E?.total||0,V=Math.ceil(M/fe);return e.jsxs(A,{children:[e.jsx(Ds,{count:E?.total??0}),e.jsxs(Oe,{className:"space-y-4",children:[h&&e.jsx(H,{error:h,variant:"banner",severity:"error",context:{action:"publishing comment",resource:"comment"},onRetry:u<3?D:void 0,onDismiss:()=>{d(null),N(0),j("")}}),e.jsx(Us,{value:o,onChange:n,onSubmit:b,isPending:x.isPending,isRateLimited:!!i,hasUser:!!s}),c?e.jsx(Vs,{rows:4}):l?e.jsx(zs,{error:l instanceof Error?l:new Error("Failed to load comments"),resourceId:r,onRetry:()=>t.invalidateQueries({queryKey:["trackComments",r]})}):R.length===0?e.jsx(Ks,{}):e.jsxs(e.Fragment,{children:[e.jsx($s,{comments:R,trackId:r}),e.jsx(Fs,{page:g,totalPages:V,onPageChange:p})]})]})]})}function Hs({open:r,onClose:s,trackId:a}){const[t,i]=m.useState(null),[o,n]=m.useState(!1),[h,d]=m.useState(null),[g,p]=m.useState(0),y=m.useRef(null),j=W(),{copied:u,copy:N}=ps();m.useEffect(()=>{r&&!t&&E()},[r]);const E=async()=>{const b=async()=>{const D=new Date;D.setDate(D.getDate()+7);const R=await hs.createShare(a,{permissions:"read",expires_at:D.toISOString()});i(R),d(null),p(0),y.current=null};y.current=b,n(!0),d(null);try{await b()}catch(D){const R=Ae(D);d(new Error(R.message))}finally{n(!1)}},c=async()=>{if(!(!y.current||g>=3)){p(b=>b+1),n(!0);try{await y.current()}catch{}finally{n(!1)}}},l=async()=>{if(!t)return;const b=`${window.location.origin}/tracks/shared/${t.token}`;await N(b)?j.success("Link copied to clipboard"):j.error("Failed to copy link")},x=t?`${window.location.origin}/tracks/shared/${t.token}`:"";return e.jsx(Me,{open:r,onClose:s,title:"Share Track",variant:"default",size:"md",children:e.jsxs("div",{className:"space-y-4 transition-opacity duration-[var(--sumi-duration-normal)]",children:[h&&e.jsx(H,{error:h,variant:"banner",severity:"error",context:{action:"creating share link",resource:"track",resourceId:a},onRetry:g<3?c:void 0,onDismiss:()=>{d(null),p(0),y.current=null}}),o?e.jsx("div",{className:"text-center py-4 text-muted-foreground/90 tracking-tight",children:"Creating share link..."}):t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ls,{className:"text-muted-foreground/90 tracking-tight",children:"Share Link"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{value:x,readOnly:!0,className:"flex-1 rounded-md transition-[border-color] duration-[var(--sumi-duration-normal)]"}),e.jsx(S,{onClick:l,variant:"outline",className:"rounded-md transition-[color,transform] duration-[var(--sumi-duration-normal)] active:scale-95",children:u?e.jsx(Je,{className:"h-4 w-4 text-success"}):e.jsx(ce,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"text-xs text-muted-foreground/90 tracking-tight",children:"This link will expire in 7 day(s)"}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(S,{variant:"outline",onClick:s,className:"rounded-md transition-colors duration-[var(--sumi-duration-normal)]",children:"Close"}),e.jsxs(S,{onClick:l,className:"rounded-md transition-[color,transform] duration-[var(--sumi-duration-normal)] active:scale-95",children:[e.jsx(ce,{className:"mr-2 h-4 w-4"}),"Copy Link"]})]})]}):e.jsx("div",{className:"text-center text-destructive tracking-tight",children:"Failed to create share link"})]})})}class P extends Error{constructor(s,a,t=!1,i){super(s),this.code=a,this.retryable=t,this.originalError=i,this.name="TrackHistoryError"}}async function Bs(r,s){try{const a=new URLSearchParams;s?.limit!==void 0&&a.append("limit",s.limit.toString()),s?.offset!==void 0&&a.append("offset",s.offset.toString());const t=a.toString(),i=`/tracks/${r}/history${t?`?${t}`:""}`;return(await I.get(i)).data}catch(a){if(a instanceof _){if(a.response?.status===400)throw new P("Requête invalide: ID de track invalide","VALIDATION",!1,a);if(a.response?.status===404)throw new P("Track introuvable","NOT_FOUND",!1,a);if(a.response?.status===500)throw new P("Erreur serveur: Impossible de récupérer l'historique. Veuillez réessayer plus tard.","SERVER",!0,a);if(a.code==="ECONNABORTED"||a.code==="ETIMEDOUT"||!a.response)throw new P("Erreur réseau: Impossible de se connecter au serveur. Veuillez vérifier votre connexion.","NETWORK",!0,a);const t=a.response?.data?.error||a.message||"Échec de la récupération de l'historique";throw new P(t,"UNKNOWN",!1,a)}throw a instanceof P?a:new P("Erreur inconnue lors de la récupération de l'historique","UNKNOWN",!1,a)}}function Gs(r,s){const[a,t]=m.useState([]),[i,o]=m.useState(!0),[n,h]=m.useState(null),[d,g]=m.useState(0),[p,y]=m.useState(0),j=m.useCallback(async()=>{o(!0),h(null);try{const l=await Bs(r,{limit:s,offset:p});t(l.history),g(l.total)}catch(l){l instanceof P?h(l.message):h("Impossible de charger l'historique")}finally{o(!1)}},[r,p,s]);m.useEffect(()=>{j()},[j]);const u=p>0,N=p+s<d,E=m.useCallback(()=>{p>0&&y(l=>Math.max(0,l-s))},[p,s]),c=m.useCallback(()=>{p+s<d&&y(l=>l+s)},[p,s,d]);return{history:a,loading:i,error:n,total:d,currentOffset:p,limit:s,hasPreviousPage:u,hasNextPage:N,handlePreviousPage:E,handleNextPage:c,reload:j}}function Js({total:r}){return e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"h-5 w-5 text-primary/90","aria-hidden":!0}),e.jsx("h3",{className:"text-lg font-semibold tracking-tight text-foreground",children:"Historique des modifications"}),r>0&&e.jsxs("span",{className:"text-sm text-muted-foreground/90 tracking-tight",children:["(",r,")"]})]})})}function Xs(){return e.jsxs("div",{className:"text-center py-8 text-muted-foreground/90 text-sm tracking-tight rounded-xl",children:[e.jsx(ie,{className:"h-12 w-12 mx-auto mb-4 opacity-50 transition-opacity duration-[var(--sumi-duration-normal)]","aria-hidden":!0}),e.jsx("p",{children:"Aucune modification enregistrée"})]})}function Ys(r){const s=new Date(r);return Number.isNaN(s.getTime())?r:new Intl.DateTimeFormat("fr-FR",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(s)}function Zs(r){switch(r){case"created":return es;case"updated":return Ze;case"deleted":return be;case"published":return Ce;case"unpublished":return Ye;case"restored":return Xe;default:return ie}}function er(r){switch(r){case"created":return"Créé";case"updated":return"Modifié";case"deleted":return"Supprimé";case"published":return"Publié";case"unpublished":return"Dépublié";case"restored":return"Restauré";default:return r}}function sr(r){switch(r){case"created":return"text-success bg-success/10";case"updated":return"text-muted-foreground bg-muted";case"deleted":return"text-destructive bg-destructive/10";case"published":return"text-primary bg-primary/10";case"unpublished":return"text-warning bg-warning/10";case"restored":return"text-primary bg-primary/10";default:return"text-muted-foreground bg-muted"}}function ge(r){if(!r)return null;try{return JSON.parse(r)}catch{return r}}function ve(r){return r==null?"":typeof r=="string"?r:typeof r=="object"?JSON.stringify(r,null,2):String(r)}function rr({item:r}){const s=Zs(r.action),a=sr(r.action),t=ge(r.old_value),i=ge(r.new_value);return e.jsxs("div",{className:"relative flex gap-4 transition-colors duration-[var(--sumi-duration-normal)]",children:[e.jsx("div",{className:w("relative z-10 flex h-12 w-12 shrink-0 items-center justify-center rounded-full border-2 border-background",a),children:e.jsx(s,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2 pb-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:w("text-sm font-semibold tracking-tight",a.split(" ")[0]),children:er(r.action)}),e.jsxs("span",{className:"text-xs text-muted-foreground/90 tracking-tight",children:["#",r.id]})]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground/90 tracking-tight",children:[e.jsx(we,{className:"h-3 w-3 shrink-0","aria-hidden":!0}),e.jsx("span",{children:Ys(r.created_at)})]})]}),(t!==null||i!==null)&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-border/80 bg-muted/50 p-4 text-sm transition-colors duration-[var(--sumi-duration-normal)]",children:[t!==null&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground/90 mb-1 tracking-tight",children:"Ancienne valeur:"}),e.jsx("pre",{className:"text-xs bg-background rounded-md p-2 overflow-x-auto tracking-tight",children:ve(t)})]}),i!==null&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground/90 mb-1 tracking-tight",children:"Nouvelle valeur:"}),e.jsx("pre",{className:"text-xs bg-background rounded-md p-2 overflow-x-auto tracking-tight",children:ve(i)})]})]})]})]})}function tr({currentOffset:r,limit:s,total:a,hasPreviousPage:t,hasNextPage:i,onPrevious:o,onNext:n}){return e.jsxs("div",{className:"flex items-center justify-between border-t border-border/80 pt-4 transition-colors duration-[var(--sumi-duration-normal)]",children:[e.jsxs("div",{className:"text-sm text-muted-foreground/90 tracking-tight tabular-nums",children:["Affichage ",r+1," -"," ",Math.min(r+s,a)," sur ",a]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:o,disabled:!t,children:[e.jsx(ss,{className:"h-4 w-4 mr-1"}),"Précédent"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:n,disabled:!i,children:["Suivant",e.jsx(rs,{className:"h-4 w-4 ml-1"})]})]})]})}function ar(){return e.jsxs("div",{className:"space-y-4 min-h-layout-story",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5 rounded-md"}),e.jsx(k,{className:"h-6 w-52 rounded-md"}),e.jsx(k,{className:"h-4 w-8 rounded-md"})]})}),e.jsxs("div",{className:"relative space-y-6",children:[e.jsx("div",{className:"absolute left-6 top-0 bottom-0 w-0.5 bg-border/80"}),[1,2,3].map(r=>e.jsxs("div",{className:"relative flex gap-4",children:[e.jsx(k,{className:"relative z-10 h-12 w-12 shrink-0 rounded-full"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2 pb-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(k,{className:"h-4 w-24 rounded-md"}),e.jsx(k,{className:"h-3 w-32 rounded-md"})]}),e.jsx(k,{className:"h-16 rounded-lg"})]})]},r))]})]})}function nr({trackId:r,className:s,limit:a=50}){const{history:t,loading:i,error:o,total:n,currentOffset:h,limit:d,hasPreviousPage:g,hasNextPage:p,handlePreviousPage:y,handleNextPage:j}=Gs(r,a);return i?e.jsx("div",{className:w("min-h-layout-story",s),children:e.jsx(ar,{})}):o?e.jsx("div",{className:w("p-4",s),children:e.jsx(xs,{variant:"destructive",className:"rounded-xl",children:e.jsx(fs,{className:"tracking-tight",children:o})})}):e.jsxs("div",{className:w("space-y-4 transition-opacity duration-[var(--sumi-duration-normal)]",s),children:[e.jsx(Js,{total:n}),t.length===0?e.jsx(Xs,{}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-6 top-0 bottom-0 w-0.5 bg-border/80 transition-colors duration-[var(--sumi-duration-normal)]"}),e.jsx("div",{className:"space-y-6",children:t.map(u=>e.jsx(rr,{item:u},u.id))})]}),n>d&&e.jsx(tr,{currentOffset:h,limit:d,total:n,hasPreviousPage:g,hasNextPage:p,onPrevious:y,onNext:j})]})]})}async function ir(r){try{return(await I.get(`/tracks/${r}/stats`)).data.stats}catch(s){if(s instanceof _){if(s.response?.status===404)throw new C("Track introuvable","VALIDATION",!1,s);if(s.response?.status===500)throw new C("Erreur serveur: Impossible de récupérer les statistiques. Veuillez réessayer plus tard.","SERVER",!0,s);if(s.code==="ECONNABORTED"||s.code==="ETIMEDOUT"||!s.response)throw new C("Erreur réseau: Impossible de se connecter au serveur.","NETWORK",!0,s);const a=s.response?.data?.error||s.message||"Échec de la récupération des statistiques";throw new C(a,"UNKNOWN",!1,s)}throw s instanceof C?s:new C("Erreur inconnue lors de la récupération des statistiques","UNKNOWN",!1,s)}}function or({trackId:r,className:s,variant:a="horizontal",showLabels:t=!1}){const[i,o]=m.useState(null),[n,h]=m.useState(!0),[d,g]=m.useState(null);m.useEffect(()=>{(async()=>{h(!0),g(null);try{const N=await ir(r);o(N)}catch(N){g(N instanceof C?N.message:"Telemetry interrupted")}finally{h(!1)}})()},[r]);const p=u=>u>=1e6?`${(u/1e6).toFixed(1)}M`:u>=1e3?`${(u/1e3).toFixed(1)}K`:u.toString(),y=u=>{const N=Math.floor(u/3600),E=Math.floor(u%3600/60),c=u%60;return N>0?`${N}h ${E}m`:E>0?`${E}m ${c}s`:`${c}s`};if(n)return e.jsxs("div",{className:w("flex h-10 items-center gap-2 text-xs font-mono text-muted-foreground/90 tracking-tight","animate-pulse transition-opacity duration-[var(--sumi-duration-normal)]"),children:[e.jsx(je,{className:"w-3 h-3 animate-spin"}),"SCANNING..."]});if(d||!i)return null;const j=[{icon:Ce,value:p(i.views),label:"Views",color:"text-chart-1",bg:"bg-chart-1/10"},{icon:ye,value:p(i.likes),label:"Likes",color:"text-chart-2",bg:"bg-chart-2/10"},{icon:B,value:p(i.comments),label:"Comms",color:"text-chart-3",bg:"bg-chart-3/10"},{icon:ts,value:p(i.downloads),label:"Data",color:"text-chart-4",bg:"bg-chart-4/10"},{icon:ee,value:y(i.total_play_time),label:"Pulse",color:"text-primary",bg:"bg-primary/10"}];return a==="grid"?e.jsx("div",{className:w("grid grid-cols-2 md:grid-cols-5 gap-3 transition-opacity duration-[var(--sumi-duration-normal)]",s),children:j.map((u,N)=>{const E=u.icon;return e.jsxs(A,{variant:"outline",className:w("p-3 border-border flex flex-col items-center gap-1","hover:border-primary/30 hover:shadow-md transition-[border-color,box-shadow,transform] duration-[var(--sumi-duration-normal)]"),children:[e.jsx("div",{className:w("p-2 rounded-md mb-1 transition-transform duration-[var(--sumi-duration-normal)]",u.bg,u.color),children:e.jsx(E,{className:"w-4 h-4"})}),e.jsx("div",{className:"text-lg font-heading font-bold text-foreground tabular-nums tracking-tight",children:u.value}),e.jsx("div",{className:"text-xs font-mono text-muted-foreground/90 uppercase tracking-widest",children:u.label})]},N)})}):e.jsx("div",{className:w("flex flex-wrap items-center gap-6 transition-opacity duration-[var(--sumi-duration-normal)]",s),children:j.map((u,N)=>{const E=u.icon;return e.jsxs("div",{className:"flex items-center gap-2 group cursor-default",children:[e.jsx("div",{className:w("p-1.5 rounded-md opacity-80 group-hover:opacity-100 transition-[opacity,transform] duration-[var(--sumi-duration-normal)]",u.bg,u.color),children:e.jsx(E,{className:"w-3.5 h-3.5","aria-hidden":!0})}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-bold text-foreground tabular-nums tracking-tight group-hover:text-primary transition-colors duration-[var(--sumi-duration-normal)]",children:u.value}),t&&e.jsx("span",{className:"text-xs font-mono text-muted-foreground/90 uppercase tracking-wider",children:u.label})]})]},N)})})}const Z="rounded-none border-b-2 border-transparent data-[state=active]:bg-transparent data-[state=active]:border-primary data-[state=active]:text-primary py-3 px-1 text-base font-medium bg-transparent transition-colors duration-200 hover:text-foreground gap-2";function lr({track:r,isShareDialogOpen:s,onShareDialogClose:a}){const t=parseInt(r.id,10)||0;return e.jsxs(e.Fragment,{children:[e.jsxs(ns,{defaultValue:"comments",className:"w-full",children:[e.jsxs(is,{className:"bg-transparent border-b border-border w-full justify-start h-auto p-0 gap-6 mb-6 rounded-none",children:[e.jsxs(X,{value:"comments",className:Z,children:[e.jsx(B,{className:"w-4 h-4"}),"Discussion",e.jsx("span",{className:"text-xs bg-muted/30 px-2 py-0.5 rounded-full text-muted-foreground tabular-nums",children:"24"})]}),e.jsxs(X,{value:"analytics",className:Z,children:[e.jsx(ue,{className:"w-4 h-4"}),"Analytics"]}),e.jsxs(X,{value:"history",className:Z,children:[e.jsx(de,{className:"w-4 h-4"}),"History"]})]}),e.jsx(Y,{value:"comments",className:"animate-fade-in mt-0",children:e.jsx(Ws,{trackId:r.id})}),e.jsx(Y,{value:"analytics",className:"animate-fade-in mt-0",children:e.jsxs(A,{variant:"glass",className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-primary/10",children:e.jsx(ue,{className:"w-4 h-4 text-primary"})}),e.jsx("h3",{className:"text-heading-3",children:"Performance Data"})]}),e.jsx(or,{trackId:t,variant:"horizontal",showLabels:!0})]})}),e.jsx(Y,{value:"history",className:"animate-fade-in mt-0",children:e.jsxs(A,{variant:"glass",className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-primary/10",children:e.jsx(de,{className:"w-4 h-4 text-primary"})}),e.jsx("h3",{className:"text-heading-3",children:"Version History"})]}),e.jsx(nr,{trackId:r.id,limit:20})]})})]}),e.jsx(Hs,{open:s,onClose:a,trackId:r.id,trackTitle:r.title})]})}function cr({error:r,onRetry:s}){const a=Ee();return e.jsx("div",{className:"container mx-auto px-4 py-8 flex flex-col items-center justify-center min-h-layout-page",children:e.jsx(H,{error:r||new Error("Track not found"),variant:"card",severity:"error",onRetry:s,actions:[{label:"Go Back",onClick:()=>a(-1),variant:"outline"}]})})}function ur(){return e.jsxs("div",{className:"min-h-layout-page pb-24 relative overflow-hidden bg-background transition-opacity duration-[var(--sumi-duration-normal)]",children:[e.jsx("div",{className:"absolute inset-0 h-layout-lyrics bg-muted/30 pointer-events-none"}),e.jsxs("div",{className:"container mx-auto px-4 relative z-10 pt-8",children:[e.jsx(k,{className:"h-10 w-24 rounded-full mb-8"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-12 items-start",children:[e.jsxs("div",{className:"lg:col-span-4 space-y-6",children:[e.jsx(k,{className:"aspect-square rounded-2xl"}),e.jsx(A,{variant:"glass",className:"p-4 border-border bg-card/80 backdrop-blur-xl",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{className:"flex-1 h-12 rounded-full"}),e.jsx(k,{className:"h-12 w-12 rounded-full"}),e.jsx(k,{className:"h-12 w-12 rounded-full"}),e.jsx(k,{className:"h-12 w-12 rounded-full"})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(A,{variant:"glass",className:"p-4 bg-muted/20",children:[e.jsx(k,{className:"h-5 w-8 rounded-lg mx-auto mb-2"}),e.jsx(k,{className:"h-4 w-12 rounded-lg mx-auto"})]}),e.jsxs(A,{variant:"glass",className:"p-4 bg-muted/20",children:[e.jsx(k,{className:"h-5 w-8 rounded-lg mx-auto mb-2"}),e.jsx(k,{className:"h-4 w-12 rounded-lg mx-auto"})]})]})]}),e.jsxs("div",{className:"lg:col-span-8 space-y-8",children:[e.jsxs("div",{children:[e.jsx(k,{className:"h-5 w-16 rounded-full mb-3"}),e.jsx(k,{className:"h-12 w-3/4 max-w-xl rounded-lg mb-3"}),e.jsx(k,{className:"h-5 w-56 rounded-lg"})]}),e.jsx(k,{className:"h-20 w-full rounded-xl"}),e.jsx(A,{variant:"glass",className:"p-4 bg-muted/20 border-border",children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Array.from({length:4}).map((r,s)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-muted/30",children:[e.jsx(k,{className:"w-8 h-8 rounded-lg shrink-0"}),e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx(k,{className:"h-3 w-12 rounded"}),e.jsx(k,{className:"h-4 w-16 rounded"})]})]},s))})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-6 border-b border-border pb-3",children:[e.jsx(k,{className:"h-5 w-28 rounded"}),e.jsx(k,{className:"h-5 w-20 rounded"}),e.jsx(k,{className:"h-5 w-16 rounded"})]}),e.jsx(k,{className:"h-64 w-full rounded-xl"})]})]})]})]})]})}function dr(r){const{id:s}=gs(),a=r??s??"",[t,i]=m.useState(null),[o,n]=m.useState(!0),[h,d]=m.useState(null),[g,p]=m.useState(!1),{play:y,pause:j,currentTrack:u,isPlaying:N,addToQueue:E}=Ie(),c=m.useCallback(async()=>{if(!a){d(new Error("Track ID is required")),n(!1);return}try{n(!0),d(null);const v=await Le(a);i(v)}catch(v){const O=v instanceof C||v instanceof Error?v.message:"Failed to load track";d(new Error(O))}finally{n(!1)}},[a]);m.useEffect(()=>{c()},[c]);const l=v=>({id:v.id,title:v.title,artist:v.artist,album:v.album,duration:v.duration,url:v.stream_manifest_url||v.file_path,cover:v.cover_art_path,genre:v.genre}),x=()=>{t&&y(l(t))},b=()=>j(),D=()=>{t&&(E([l(t)]),_e.success("Added to queue"))},R=()=>p(!0),M=u?.id===t?.id;return{id:a,track:t,isLoading:o,error:h,loadTrack:c,isShareDialogOpen:g,setIsShareDialogOpen:p,handlePlay:x,handlePause:b,handleAddToQueue:D,handleShare:R,isCurrentTrack:M,isCurrentlyPlaying:M&&N}}function Mr(r){const s=r?.trackId,a=Ee(),{track:t,isLoading:i,error:o,loadTrack:n,isShareDialogOpen:h,setIsShareDialogOpen:d,handlePlay:g,handlePause:p,handleAddToQueue:y,handleShare:j,isCurrentlyPlaying:u}=dr(s);return i?e.jsx(ur,{}):o||!t?e.jsx(cr,{error:o,onRetry:n}):e.jsxs("div",{className:"min-h-layout-page pb-24 relative overflow-hidden bg-background",children:[e.jsx(vs,{track:t}),e.jsxs("div",{className:"container mx-auto px-4 relative z-10 pt-8",children:[e.jsxs(S,{onClick:()=>a(-1),variant:"ghost",className:"mb-6 rounded-full hover:bg-muted/50 animate-fade-in",children:[e.jsx(as,{className:"h-4 w-4 mr-2"})," Back"]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-12 items-start",children:[e.jsx("div",{className:"lg:col-span-4 animate-stagger-in",style:{animationDelay:"50ms"},children:e.jsx(ws,{track:t,isCurrentlyPlaying:u,onPlay:g,onPause:p,onAddToQueue:y,onShare:j})}),e.jsxs("div",{className:"lg:col-span-8 space-y-8 animate-stagger-in",style:{animationDelay:"120ms"},children:[e.jsx(ks,{track:t}),e.jsx(lr,{track:t,isShareDialogOpen:h,onShareDialogClose:()=>d(!1)})]})]})]})]})}export{Mr as TrackDetailPage,cr as TrackDetailPageNotFound,ur as TrackDetailPageSkeleton};