1import{r as N,b2 as O,j as e,B as u,cb as J,S as Ne,bw as Z,dN as ee,k as p,aj as P,x as o,aX as be,an as ye,ce as we,l as te,a2 as se,a4 as Ce,a5 as ke,a6 as Se,a7 as Te,o as c,p as F,a3 as ae,b1 as qe,ep as Ae,as as ze,ap as Me,q as De,s as m,aT as Ie,aU as Be,cf as Fe,aq as Le,I as $e,ca as Ee}from"./index-BTrKqWIn.js";import{C as Oe}from"./seo-BeeBjzgY.js";import{T as Pe}from"./TestimonyInstagramExporter-D0_wOuBP.js";import{C as re,a as le}from"./card-vCGE_HIz.js";import{L as n}from"./label-t1-XzSMS.js";import{S as L}from"./slider-AqPrgKgE.js";import{B as S}from"./badge-BICT-3y_.js";import{S as R}from"./skeleton-C4ETrcps.js";import{T as Re,a as Ue,b as U,c as V}from"./tabs-Dl7mwtDU.js";import{S as T,a as q,b as A,c as z,f as y}from"./select-C5QQdRg6.js";import{b as Ve}from"./useBattles-CxPsJOz-.js";import{f as H}from"./format-BVj67mn_.js";import{f as He}from"./formatDistanceToNow-On8Bb1CP.js";import{f as Ge}from"./fr-rJMxQRdi.js";import"./index-BdQq_4o_.js";import"./index-CXDJVP3B.js";import"./en-US-Cvlt25QH.js";import"./constructNow-BVVOLb7H.js";import"./getRoundingMethod-BUByHx3z.js";import"./endOfMonth-DMbqykJX.js";const Ke=i=>`${Oe}/battle/${encodeURIComponent(i)}/index.html`,$={draft:"Brouillon",open:"En cours",closed:"Clôturée",archived:"Archivée"},We={draft:"bg-zinc-500/20 text-zinc-700",open:"bg-emerald-500/20 text-emerald-700",closed:"bg-amber-500/20 text-amber-700",archived:"bg-zinc-300 text-zinc-700"},Xe=[{value:"black",label:"Noir"},{value:"primary",label:"Rouge"},{value:"blue",label:"Bleu"},{value:"green",label:"Vert"}],Ye={title:"",question:"",style_constraints:[],custom_constraint:"",difficulty:"moyen",max_duration_seconds:90,question_font_size:"lg",how_it_works:"",background_image:"",share_image_url:"",cover_video_url:"",overlay_color:"black",overlay_opacity:.6,overlay_height:100,accent_word_red:"",accent_word_green:"",accent_color_red:"",accent_color_green:"",cta_bg_color:"",cta_text_color:"",highlight_word:"",highlight_bg_color:"",highlight_text_color:"",highlight_word_2:"",highlight_bg_color_2:"",highlight_text_color_2:"",content_position:80,winners_per_round:3,current_round:1,total_rounds:1,is_final:!1,opens_at:new Date().toISOString().slice(0,16),closes_at:new Date(Date.now()+7*864e5).toISOString().slice(0,16),status:"draft"};function Qe(i){const s=Math.floor(i/60),l=Math.floor(i%60);return`${s}:${l.toString().padStart(2,"0")}`}function ne({value:i,onChange:s}){const[l,C]=N.useState(!1),[b,h]=N.useState(!i||i.startsWith("http")?"url":"upload"),M=async g=>{var D;const j=(D=g.target.files)==null?void 0:D[0];if(j){C(!0);try{const v=j.name.split(".").pop(),I=`battles/covers/${Date.now()}-${Math.random().toString(36).slice(2)}.${v}`,{error:_}=await m.storage.from("landing-images").upload(I,j);if(_)throw _;const{data:E}=m.storage.from("landing-images").getPublicUrl(I);s(E.publicUrl),o.success("Image téléchargée")}catch(v){o.error(v.message)}finally{C(!1)}}};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{type:"button",size:"sm",variant:b==="upload"?"default":"outline",onClick:()=>h("upload"),children:[e.jsx(ze,{className:"w-4 h-4 mr-1"})," Upload"]}),e.jsxs(u,{type:"button",size:"sm",variant:b==="url"?"default":"outline",onClick:()=>h("url"),children:[e.jsx(Me,{className:"w-4 h-4 mr-1"})," URL"]})]}),b==="url"?e.jsx(c,{value:i,onChange:g=>s(g.target.value),placeholder:"https://..."}):e.jsx(c,{type:"file",accept:"image/*",onChange:M,disabled:l}),l&&e.jsxs("div",{className:"flex items-center text-xs text-muted-foreground",children:[e.jsx(De,{className:"w-3 h-3 animate-spin mr-1"})," Upload en coursâ¦"]}),i&&e.jsx("img",{src:i,alt:"aperçu",className:"w-full h-32 object-cover rounded-lg border"})]})}const ie=i=>{var s;return!!(i!=null&&i.constraint_name)||Array.isArray(i==null?void 0:i.style_constraints)&&(((s=i==null?void 0:i.style_constraints)==null?void 0:s.length)??0)>0};function jt(){const i=Ve(),[s,l]=N.useState(null),[C,b]=N.useState(null),[h,M]=N.useState(null),g=N.useRef(null),[j,D]=N.useState("all"),[v,I]=N.useState("all"),{data:_=[],isLoading:E}=O({queryKey:["admin-battles"],queryFn:async()=>{const{data:t,error:a}=await m.from("battles").select("*").order("created_at",{ascending:!1});if(a)throw a;return t||[]}}),{data:w=[],isLoading:oe}=O({queryKey:["admin-battle-contributions-all","pending"],queryFn:async()=>{const{data:t,error:a}=await m.from("battle_contributions").select("*").eq("status","pen
1ding").order("created_at",{ascending:!0});if(a)throw a;return t||[]}}),{data:B=[],isLoading:ce}=O({queryKey:["admin-battle-contributions-all","approved"],queryFn:async()=>{const{data:t,error:a}=await m.from("battle_contributions").select("*").eq("status","approved").order("is_featured",{ascending:!1}).order("published_at",{ascending:!1});if(a)throw a;return t||[]}}),G=new Map(_.map(t=>[t.id,t])),de=async()=>{var r,d,f;if(!s)return;if(!s.title.trim()||!s.question.trim()){o.error("Titre et question requis");return}const t=s.style_constraints[0],a={title:s.title.trim(),question:s.question.trim(),style_constraints:s.style_constraints,constraint_name:((r=t==null?void 0:t.name)==null?void 0:r.trim())||null,constraint_description:((d=t==null?void 0:t.description)==null?void 0:d.trim())||null,difficulty:s.difficulty||null,max_duration_seconds:s.max_duration_seconds,question_font_size:s.question_font_size,how_it_works:s.how_it_works.trim()||null,background_image:s.background_image.trim()||null,share_image_url:s.share_image_url.trim()||null,cover_video_url:s.cover_video_url.trim()||null,overlay_color:s.overlay_color,overlay_opacity:s.overlay_opacity,overlay_height:s.overlay_height,accent_word_red:s.accent_word_red.trim()||null,accent_word_green:s.accent_word_green.trim()||null,accent_color_red:s.accent_color_red.trim()||null,accent_color_green:s.accent_color_green.trim()||null,cta_bg_color:s.cta_bg_color.trim()||null,cta_text_color:s.cta_text_color.trim()||null,highlight_word:s.highlight_word.trim()||null,highlight_bg_color:s.highlight_bg_color.trim()||null,highlight_text_color:s.highlight_text_color.trim()||null,highlight_word_2:s.highlight_word_2.trim()||null,highlight_bg_color_2:s.highlight_bg_color_2.trim()||null,highlight_text_color_2:s.highlight_text_color_2.trim()||null,content_position:s.content_position,winners_per_round:s.winners_per_round,current_round:s.current_round,total_rounds:s.total_rounds,is_final:s.is_final,opens_at:new Date(s.opens_at).toISOString(),closes_at:new Date(s.closes_at).toISOString(),custom_constraint:((f=s.custom_constraint)==null?void 0:f.trim())||null,status:s.status};if(s.id){const{error:x}=await m.from("battles").update(a).eq("id",s.id);if(x)return o.error(x.message);o.success("Battle mise à jour")}else{const{error:x}=await m.from("battles").insert(a);if(x)return o.error(x.message);o.success("Battle créée")}l(null),i()},ue=async t=>{if(!confirm(`Supprimer la battle "${t.title}" et toutes ses contributions ?`))return;const{error:a}=await m.from("battles").delete().eq("id",t.id);if(a)return o.error(a.message);o.success("Supprimée"),i()},he=async t=>{const{id:a,created_at:r,updated_at:d,...f}=t,x={...f,title:`${t.title} (copie)`,status:"draft"},{error:k}=await m.from("battles").insert(x);if(k)return o.error(k.message);o.success("Battle dupliquée"),i()},me=async(t,a)=>{const{error:r}=await m.from("battles").update({status:a}).eq("id",t.id);if(r)return o.error(r.message);o.success(`Statut â ${$[a]}`),i()},K=async(t,a)=>{const{error:r}=await m.from("battle_contributions").update({status:a,moderated_at:new Date().toISOString(),published_at:a==="approved"?new Date().toISOString():null}).eq("id",t);if(r)return o.error(r.message);o.success(a==="approved"?"Tchatche approuvée":"Tchatche rejetée"),i()},xe=async t=>{if(!confirm("Supprimer cette tchatche ?"))return;const{error:a}=await m.from("battle_contributions").delete().eq("id",t.id);if(a)return o.error(a.message);o.success("Tchatche supprimée"),i()},ge=async t=>{const a=!t.is_featured,{error:r}=await m.from("battle_contributions").update({is_featured:a}).eq("id",t.id);if(r)return o.error(r.message);o.success(a?"Mise à la une":"Retirée de la une"),i()},_e=t=>{var a;C===t.id?((a=g.current)==null||a.pause(),b(null)):g.current&&(g.current.src=t.audio_url,g.current.play(),b(t.id))},pe=t=>{const a=document.createElement("a");a.href=t.audio_url;const r=t.author_name||"tchatche";a.download=`battle_${r}_${H(new Date(t.created_at),"yyyy-MM-dd")}.webm`,a.target="_blank",document.body.appendChild(a),a.click(),document.body.removeChild(a)},je=t=>{const a=Array.isArray(t.style_constraints)&&t.style_constraints.length>0?t.style_constraints:t.constraint_name?[{name:t.constraint_name,description:t.constraint_description||""}]:[];l({id:t.id,title:t.title,question:t.question,style_constraints:a,custom_constraint:t.custom_constraint||"",difficulty:t.difficulty||"moyen",max_duration_seconds:t.max_duration_seconds,question_font_size:t.question_font_size||"lg",how_it_works:t.how_it_works||"",background_image:t.background_image||"",share_image_url:t.share_image_url||"",cover_video_url:t.cover_video_url||"",overlay_color:t.overlay_color||"black",overlay_opacity:t.overlay_opacity??.6,overlay_height:t.overlay_height??100,accent_word_red:t.accent_word_red||"",accent_word_green:t.accent_word_green||"",accent_color_red:t.accent_color_red||"",accent_color_green:t.accent_color_green||"",cta_bg_color:t.cta_bg_color||"",cta_text_color:t.cta_text_color||"",highlight_word:t.highlight_word||"",highlight_bg_color:t.highlight_bg_color||"",highlight_text_color:t.highlight_text_color||"",highlight_word_2:t.highlight_word_2||"",highlight_bg_color_2:t.highlight_bg_color_2||"",highlight_text_color_2:t.highlight_text_color_2||"",content_position:t.content_position??80,winners_per_round:t.winners_per_round??3,current_roun
1d:t.current_round??1,total_rounds:t.total_rounds??1,is_final:t.is_final??!1,opens_at:t.opens_at.slice(0,16),closes_at:t.closes_at.slice(0,16),status:t.status})},ve=()=>{s&&l({...s,style_constraints:[...s.style_constraints,{name:"",description:""}]})},W=(t,a)=>{if(!s)return;const r=[...s.style_constraints];r[t]={...r[t],...a},l({...s,style_constraints:r})},fe=t=>{s&&l({...s,style_constraints:s.style_constraints.filter((a,r)=>r!==t)})},X=({c:t,showModeration:a=!1})=>{var Y,Q;const r=G.get(t.battle_id),d=ie(r),f=d?"bg-emerald-500":"bg-blue-500",x=d?"text-emerald-600 border-emerald-300":"text-blue-600 border-blue-300",k=((Q=(Y=r==null?void 0:r.style_constraints)==null?void 0:Y[0])==null?void 0:Q.name)||(r==null?void 0:r.constraint_name)||null;return e.jsxs(re,{className:p("relative overflow-hidden",t.is_featured&&"border-amber-400/60 bg-amber-50/40"),children:[e.jsx("div",{className:p("absolute top-0 left-0 right-0 h-1",f)}),e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(u,{variant:"outline",size:"icon",className:"shrink-0 h-12 w-12 rounded-full",onClick:()=>_e(t),children:C===t.id?e.jsx(Ie,{className:"h-5 w-5"}):e.jsx(Be,{className:"h-5 w-5 ml-0.5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[(r==null?void 0:r.title)&&e.jsx("h4",{className:"font-medium text-sm mb-1 line-clamp-1",children:r.title}),e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[k?e.jsxs(S,{variant:"outline",className:p("text-xs gap-1",x),children:[e.jsx(P,{className:"h-2.5 w-2.5"}),k]}):e.jsxs(S,{variant:"outline",className:p("text-xs gap-1",x),children:[e.jsx(P,{className:"h-2.5 w-2.5"}),"Battle"]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(Fe,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-medium",children:t.author_name||"Anonyme"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground flex-wrap",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Z,{className:"h-3 w-3"}),Qe(t.duration_seconds||0)]}),e.jsx("span",{children:He(new Date(t.created_at),{addSuffix:!0,locale:Ge})}),t.author_city&&e.jsx("span",{children:t.author_city}),t.listen_count>0&&e.jsxs("span",{children:[t.listen_count," écoute",t.listen_count>1?"s":""]})]})]}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>pe(t),title:"Télécharger l'audio",children:e.jsx(Le,{className:"h-4 w-4"})}
1),!a&&e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-pink-500/80 hover:text-pink-600",onClick:()=>M(t),title:"Générer la vidéo Instagram",children:e.jsx($e,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex items-center gap-1",children:a?e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-green-600 hover:text-green-700 hover:bg-green-100",onClick:()=>K(t.id,"approved"),title:"Approuver",children:e.jsx(se,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-100",onClick:()=>K(t.id,"rejected"),title:"Rejeter",children:e.jsx(ae,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"ghost",size:"icon",className:p("h-8 w-8",t.is_featured?"text-amber-500 hover:text-amber-600":"hover:text-amber-500"),onClick:()=>ge(t),title:t.is_featured?"Retirer de la une":"Mettre à la une",children:e.jsx(Ee,{className:p("h-4 w-4",t.is_featured&&"fill-current")})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>xe(t),title:"Supprimer",children:e.jsx(te,{className:"h-4 w-4"})})]})})]})})]})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("audio",{ref:g,onEnded:()=>b(null),className:"hidden"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Battles d'éloquence"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Crée des battles, modère les tchatches audio."})]}),e.jsxs(u,{onClick:()=>l({...Ye}),children:[e.jsx(J,{className:"w-4 h-4 mr-2"})," Nouvelle battle"]})]}),e.jsxs(Re,{defaultValue:"battles",className:"w-full",children:[e.jsxs(Ue,{className:"grid w-full grid-cols-3",children:[e.jsxs(U,{value:"battles",className:"gap-2",children:[e.jsx(Ne,{className:"h-4 w-4"}),"Battles"]}),e.jsxs(U,{value:"moderation",className:"gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),"En attente",w.length>0&&e.jsx(S,{variant:"destructive",className:"ml-1 h-5 w-5 p-0 justify-center",children:w.length})]}),e.jsxs(U,{value:"published",className:"gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Publiées"]})]}),e.jsxs(V,{value:"battles",className:"space-y-4",children:[e.jsxs("h3",{className:"font-semibold",children:["Battles (",_.length,")"]}),E?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(t=>e.jsx(R,{className:"h-24"},t))}):_.length===0?e.jsx("div",{className:"rounded-xl border border-dashed p-8 text-center text-muted-foreground",children:"Aucune battle pour le moment."}):e.jsx("div",{className:"space-y-3",children:_.map(t=>{const a=ie(t);return e.jsxs(re,{className:p("relative overflow-hidden",t.status==="open"&&"border-primary/50 bg-primary/5"),children:[e.jsx("div",{className:p("absolute top-0 left-0 right-0 h-1",a?"bg-emerald-500":"bg-blue-500")}),e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[t.background_image&&e.jsx("img",{src:t.background_image,alt:"",className:"w-20 h-20 object-cover rounded-lg shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx(S,{className:We[t.status],children:$[t.status]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[H(new Date(t.opens_at),"dd/MM HH:mm")," â"," ",H(new Date(t.closes_at),"dd/MM HH:mm")]}),e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(P,{className:"w-3 h-3"}),t.contribution_count," approuvée",t.contribution_count>1?"s":""]})]}),e.jsx("p",{className:"font-medium",children:t.title}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2 mt-1",children:t.question}),a&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:(t.style_constraints||[]).map((r,d)=>e.jsx(S,{variant:"outline",className:"text-emerald-600 border-emerald-300 text-[10px]",children:r.name},d))})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(T,{value:t.status,onValueChange:r=>me(t,r),children:[e.jsx(q,{className:"h-8 w-32 text-xs",children:e.jsx(A,{})}),e.jsx(z,{children:["draft","open","closed","archived"].map(r=>e.jsx(y,{value:r,children:$[r]},r))})]}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:!t.slug,title:"Copier le lien de partage (réseaux sociaux)",onClick:async()=>{const r=t.slug;if(!r){o.error("Slug manquant",{description:"Re-sauvegarde la battle pour générer un lien."});return}const d=Ke(r);try{await navigator.clipboard.writeText(d),o.success("Lien de partage copié !",{description:"Aperçu avec miniature pour WhatsApp, Facebook, Xâ¦"})}catch{o.error("Impossible de copier",{description:d})}},children:e.jsx(be,{className:"h-4 w-4 text-blue-500"})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>je(t),title:"Modifier",children:e.jsx(ye,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>he(t),title:"Dupliquer",children:e.jsx(we,{className:"h-4 w-4"})}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>ue(t),title:"Supprimer",children:e.jsx(te,{className:"h-4 w-4"})})]})]})})]},t.id)})})]}),e.jsx(V,{value:"moderation",className:"space-y-4",children:(()=>{const t=j==="all"?w:w.filter(a=>a.battle_id===j);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h3",{className:"font-semibold",children:["Tchatches en attente (",t.length,j!=="all"?` / ${w.length}`:"",")"]}),e.jsxs(T,{value:j,onValueChange:D,children:[e.jsx(q,{className:"w-[260px]",children:e.jsx(A,{placeholder:"Toutes les battles"})}),e.jsxs(z,{children:[e.jsx(y,{value:"all",children:"Toutes les battles"}),_.map(a=>{const r=w.filter(d=>d.battle_id===a.id).length;return e.jsxs(y,{value:a.id,children:[(a.title||"Sans titre").slice(0,50),r>0?` (${r})`:""]},a.id)})]})]})]}),oe?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(a=>e.jsx(R,{className:"h-20"},a))}):t.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(se,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Aucune tchatche en attente"})]}):e.jsx("div",{className:"space-y-3",children:t.map(a=>e.jsx(X,{c:a,showModeration:!0},a.id))})]})})()}),e.jsx(V,{value:"published",className:"space-y-4",children:(()=>{const t=v==="all"?B:B.filter(a=>a.battle_id===v);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("h3",{className:"font-semibold",children:["Tchatches publiées (",t.length,v!=="all"?` / ${B.length}`:"",")"]}),e.jsxs(T,{value:v,onValueChange:I,children:[e.jsx(q,{className:"w-[260px]",children:e.jsx(A,{placeholder:"Toutes les battles"})}),e.jsxs(z,{children:[e.jsx(y,{value:"all",children:"Toutes les battles"}),_.map(a=>{const r=B.filter(d=>d.battle_id===a.id).length;return e.jsxs(y,{value:a.id,children:[(a.title||"Sans titre").slice(0,50),r>0?` (${r})`:""]},a.id)})]})]})]}),ce?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(a=>e.jsx(R,{className:"h-20"},a))}):t.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ee,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Aucune tchatche publiée"})]}):e.jsx("div",{className:"space-y-3",children:t.map(a=>e.jsx(X,{c:a},a.id))})]})})()})]}),e.jsx(Ce,{open:!!s,onOpenChange:t=>!t&&l(null),children:e.jsxs(ke,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Se,{children:e.jsx(Te,{children:s!=null&&s.id?"Modifier la battle":"Nouvelle battle"})}),s&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Titre interne"}),e.jsx(c,{value:s.title,onChange:t=>l({...s,title:t.target.value}),placeholder:"ex: Le pardon est une violence"})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Question / thèse imposée *"}),e.jsx(F,{value:s.question,onChange:t=>l({...s,question:t.target.value}),rows:3})]}),e.jsxs("div",{className:"rounded-xl border p-3 space-y-4",children:[e.jsx(n,{className:"text-sm font-semibold",children:"Contraintes de la battle"}),e.jsxs("div",{children:[e.jsxs(n,{className:"text-xs",children:["Temps (en secondes) ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(c,{type:"number",min:15,max:300,value:s.max_duration_seconds,onChange:t=>l({...s,max_duration_seconds:Number(t.target.value)||90})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n,{className:"text-xs",children:"Style"}),e.jsxs(u,{size:"sm",variant:"outline",onClick:ve,children:[e.jsx(J,{className:"w-3 h-3 mr-1"})," Ajouter un style"]})]}),s.style_constraints.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:"Aucun style imposé."}):s.style_constraints.map((t,a)=>e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-2 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{value:t.name,onChange:r=>W(a,{name:r.target.value}),placeholder:"Nom (ex: STYLE PRÃCHEUR)"}),e.jsx(u,{size:"sm",variant:"ghost",onClick:()=>fe(a),children:e.jsx(ae,{className:"w-3 h-3"})})]}),e.jsx(F,{value:t.description||"",onChange:r=>W(a,{description:r.target.value}),rows:2,placeholder:"Description courte"})]},a))]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Contrainte particulière"}),e.jsx(F,{value:s.custom_constraint,onChange:t=>l({...s,custom_constraint:t.target.value}),rows:2,placeholder:"Ex: Doit citer le mot 'liberté'"})]})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Comment ça marche (texte affiché dans la modale ?)"}),e.jsx(F,{value:s.how_it_works,onChange:t=>l({...s,how_it_works:t.target.value}),rows:4,placeholder:"Explique en quelques lignes le principe de la battleâ¦"})]}),e.jsxs("div",{className:"rounded-xl border p-3 space-y-3",children:[e.jsx(n,{className:"text-sm font-semibold",children:"Sélection & tournoi"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Gagnants à sélectionner"}),e.jsx(c,{type:"number",min:1,max:20,value:s.winners_per_round,onChange:t=>l({...s,winners_per_round:Number(t.target.value)||1})})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Tour actuel"}
1),e.jsx(c,{type:"number",min:1,value:s.current_round,onChange:t=>l({...s,current_round:Number(t.target.value)||1})})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Nombre de tours"}),e.jsx(c,{type:"number",min:1,value:s.total_rounds,onChange:t=>l({...s,total_rounds:Number(t.target.value)||1})})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:s.is_final,onChange:t=>l({...s,is_final:t.target.checked})}),"Cette battle est la finale"]})]}),e.jsxs("div",{className:"rounded-xl border p-3 space-y-3",children:[e.jsx(n,{className:"text-sm font-semibold",children:"Apparence du titre"}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Image d'arrière-plan"}),e.jsx(ne,{value:s.background_image,onChange:t=>l({...s,background_image:t})})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Miniature de partage (1200Ã630, optionnel)"}),e.jsx(ne,{value:s.share_image_url,onChange:t=>l({...s,share_image_url:t})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Format paysage 1200Ã630 utilisé pour l'aperçu sur les réseaux sociaux. Si vide, l'image d'arrière-plan est utilisée."})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Cover vidéo (YouTube ou MP4) â optionnel"}),e.jsx(c,{value:s.cover_video_url,onChange:t=>l({...s,cover_video_url:t.target.value}),placeholder:"https://youtube.com/watch?v=⦠ou https://â¦/video.mp4"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Si renseignée, la vidéo s'affiche en fond, autoplay muet en boucle, à la place de l'image."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("div",{children:(()=>{const t=s.question_font_size,a={sm:18,md:24,lg:32,xl:40,"2xl":48};let r=32;return t&&(a[t]!==void 0?r=a[t]:/^(\d+(?:\.\d+)?)px$/.test(t)?r=parseFloat(t):(/^(\d+(?:\.\d+)?)rem$/.test(t)||/^(\d+(?:\.\d+)?)em$/.test(t))&&(r=Math.round(parseFloat(t)*16))),e.jsxs(e.Fragment,{children:[e.jsxs(n,{className:"text-xs",children:["Taille du titre : ",r,"px"]}),e.jsx(L,{value:[r],min:12,max:96,step:1,onValueChange:d=>l({...s,question_font_size:`${d[0]}px`}),className:"mt-3"})]})})()}),e.jsxs("div",{children:[e.jsxs(n,{className:"text-xs",children:["Position verticale (",s.content_position,"%)"]}),e.jsx(L,{value:[s.content_position],min:10,max:95,step:1,onValueChange:t=>l({...s,content_position:t[0]}),className:"mt-3"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Couleur d'overlay"}),e.jsxs(T,{value:s.overlay_color,onValueChange:t=>l({...s,overlay_color:t}),children:[e.jsx(q,{children:e.jsx(A,{})}),e.jsx(z,{children:Xe.map(t=>e.jsx(y,{value:t.value,children:t.label},t.value))})]})]}),e.jsxs("div",{children:[e.jsxs(n,{className:"text-xs",children:["Opacité de l'overlay : ",Math.round(s.overlay_opacity*100),"%"]}),e.jsx(L,{value:[s.overlay_opacity],min:0,max:1,step:.05,onValueChange:t=>l({...s,overlay_opacity:t[0]}),className:"mt-3"})]})]}),e.jsxs("div",{children:[e.jsxs(n,{className:"text-xs",children:["Ãtirement de l'opacité : ",s.overlay_height??100,"%"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground mb-2",children:"100% = couvre toute l'image. Réduire pour ne couvrir que le bas avec un dégradé."}),e.jsx(L,{value:[s.overlay_height??100],min:10,max:100,step:5,onValueChange:t=>l({...s,overlay_height:t[0]}),className:"mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Mot accent 1"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{value:s.accent_word_red,placeholder:"ex: BATTLE",onChange:t=>l({...s,accent_word_red:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.accent_color_red||"#ef4444",onChange:t=>l({...s,accent_color_red:t.target.value}),title:"Couleur du mot"})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Mot accent 2"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{value:s.accent_word_green,placeholder:"ex: GO",onChange:t=>l({...s,accent_word_green:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.accent_color_green||"#34d399",onChange:t=>l({...s,accent_color_green:t.target.value}),title:"Couleur du mot"})]})]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground leading-snug",children:["Astuce : pour cibler précisément un mot répété, utilisez"," ",e.jsx("code",{className:"px-1 rounded bg-muted",children:"{{mot|#ff0000}}"})," dans la question."]}),e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(n,{className:"text-xs font-semibold",children:"Surlignage rectangulaire #1"}),e.jsx(c,{value:s.highlight_word,placeholder:"Mot(s) à surligner â ex: BATTLE",onChange:t=>l({...s,highlight_word:t.target.value})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-[11px] text-muted-foreground",children:"Fond"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(c,{value:s.highlight_bg_color,placeholder:"#fde047",onChange:t=>l({...s,highlight_bg_color:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.highlight_bg_color||"#fde047",onChange:t=>l({...s,highlight_bg_color:t.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-[11px] text-muted-foreground",children:"Texte"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(c,{value:s.highlight_text_color,placeholder:"#000000",onChange:t=>l({...s,highlight_text_color:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.highlight_text_color||"#000000",onChange:t=>l({...s,highlight_text_color:t.target.value})})]})]})]})]}),e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx(n,{className:"text-xs font-semibold",children:"Surlignage rectangulaire #2"}),e.jsx(c,{value:s.highlight_word_2,placeholder:"Second mot à surligner",onChange:t=>l({...s,highlight_word_2:t.target.value})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-[11px] text-muted-foreground",children:"Fond"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(c,{value:s.highlight_bg_color_2,placeholder:"#fde047",onChange:t=>l({...s,highlight_bg_color_2:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.highlight_bg_color_2||"#fde047",onChange:t=>l({...s,highlight_bg_color_2:t.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-[11px] text-muted-foreground",children:"Texte"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(c,{value:s.highlight_text_color_2,placeholder:"#000000",onChange:t=>l({...s,highlight_text_color_2:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.highlight_text_color_2||"#000000",onChange:t=>l({...s,highlight_text_color_2:t.target.value})})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 pt-1",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"CTA â Couleur de fond"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(c,{value:s.cta_bg_color,placeholder:"ex: #ef4444",onChange:t=>l({...s,cta_bg_color:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.cta_bg_color||"#ef4444",onChange:t=>l({...s,cta_bg_color:t.target.value}),title:"Fond du CTA"})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"CTA â Couleur du texte"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(c,{value:s.cta_text_color,placeholder:"ex: #ffffff",onChange:t=>l({...s,cta_text_color:t.target.value})}),e.jsx("input",{type:"color",className:"h-10 w-12 rounded border border-input bg-background cursor-pointer shrink-0",value:s.cta_text_color||"#ffffff",onChange:t=>l({...s,cta_text_color:t.target.value}),title:"Texte du CTA"})]})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Aperçu"}),e.jsxs("div",{className:"mt-2 relative mx-auto w-[200px] aspect-[9/16] rounded-xl overflow-hidden border bg-black",children:[s.background_image&&e.jsx("img",{src:s.background_image,alt:"",className:"absolute inset-0 w-full h-full object-cover"}),(()=>{const t=s.overlay_height??100,a=Math.max(0,t-20),r=t>=100?void 0:`linear-gradient(to top, black 0%, black ${a}%, transparent ${t}%)`;return e.jsx("div",{className:p("absolute inset-0",s.overlay_color==="primary"?"bg-primary":s.overlay_color==="blue"?"bg-blue-900":s.overlay_color==="green"?"bg-green-900":"bg-black"),style:{opacity:s.overlay_opacity,WebkitMaskImage:r,maskImage:r}})})(),e.jsx("div",{className:"absolute left-3 right-3 -translate-y-full text-white",style:{to
1p:`${s.content_position}%`},children:e.jsx("p",{className:"font-bold uppercase leading-[1.05] whitespace-pre-line",style:{fontFamily:"'Anton', sans-serif",fontSize:(()=>{const t=s.question_font_size;return t?/^(sm|md|lg|xl|2xl)$/.test(t)?{sm:"12px",md:"14px",lg:"16px",xl:"18px","2xl":"20px"}[t]:`calc(${t} * 0.4)`:"16px"})()},children:qe(s.question||"Votre questionâ¦",s.accent_word_red,s.accent_word_green,s.accent_color_red,s.accent_color_green)})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{children:"Ouverture"}),e.jsx(c,{type:"datetime-local",value:s.opens_at,onChange:t=>l({...s,opens_at:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Fermeture"}),e.jsx(c,{type:"datetime-local",value:s.closes_at,onChange:t=>l({...s,closes_at:t.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(n,{children:"Statut"}),e.jsxs(T,{value:s.status,onValueChange:t=>l({...s,status:t}),children:[e.jsx(q,{children:e.jsx(A,{})}),e.jsx(z,{children:["draft","open","closed","archived"].map(t=>e.jsx(y,{value:t,children:$[t]},t))})]})]})]}),e.jsxs(Ae,{children:[e.jsx(u,{variant:"outline",onClick:()=>l(null),children:"Annuler"}),e.jsx(u,{onClick:de,children:"Enregistrer"})]})]})}),h&&(()=>{var r,d;const t=G.get(h.battle_id),a=((d=(r=t==null?void 0:t.style_constraints)==null?void 0:r[0])==null?void 0:d.name)||(t==null?void 0:t.constraint_name)||null;return e.jsx(Pe,{testimony:{id:h.id,audio_url:h.audio_url,duration_seconds:h.duration_seconds,media_type:"audio",title:null,stance:null,author_name:h.author_name,avatar_url:h.avatar_url,published_at:h.published_at,created_at:h.created_at,user_id:h.user_id??null},questionText:t==null?void 0:t.question,variant:"battles",constraintLabel:a,showThumbs:!1,open:!!h,onOpenChange:f=>!f&&M(null)})})()]})}export{jt as BattleManager};
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.