1import{c as D,l as ae,Q as re,r as a,S as oe,Y as ie,j as e,O as H,a as ce,B as w,L as k,X as le,s as o}from"./index-R1fY2Chg.js";import{u as de}from"./useAuth-D0bG9vDX.js";import{l as q}from"./logo-club-peinard-DbSL6r7V.js";import{T as me}from"./trophy-CavHzKF4.js";import{M as ue}from"./megaphone-D8kYd53g.js";import{C as xe}from"./chart-column-0cgYSQRo.js";import{C as pe}from"./coins-BBeTR_vM.js";import{C as fe}from"./calendar-DERR54K5.js";import{C as he}from"./calendar-plus-jw9tnhY7.js";import{M as be}from"./mail-BxbDcTV9.js";import{U as ge}from"./users-yEAK88ST.js";import{M as je}from"./message-square-Ch0rEkGa.js";import{G as ve}from"./gift-BKhgfnhO.js";import{H as Ne}from"./handshake-XMCBo_ET.js";import{I as ye}from"./image-Whg1l61N.js";import{M as we}from"./mail-open-B1f5FZ79.js";import{C as ke}from"./code-xml-rcJ9XcTe.js";import{S as Ce}from"./shield-C_ulZBEA.js";import{L as W}from"./log-out-DdQiKTml.js";import{M as Se}from"./menu-CQmvV-9O.js";import{C as Ae}from"./chevron-down-CteprVnA.js";const Pe=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m9 14 2 2 4-4",key:"df797q"}]],B=D("clipboard-check",Pe);const _e=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],qe=D("inbox",_e);const Me=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],De=D("settings",Me),M=[{to:"/admin/jeux",label:"Jeux & tirages",icon:me,badgeKey:"pendingDraws"},{to:"/admin/publicites",label:"Publicités",icon:ue,badgeKey:"pendingAds"},{to:"/admin/statistiques",label:"Statistiques",icon:xe},{to:"/admin/jackpot",label:"Jackpot",icon:pe,badgeKey:"jackpotWins"},{to:"/admin/evenements",label:"Ãvènements",icon:fe},{to:"/admin/import-evenements",label:"Import d'évènements",icon:he},{to:"/admin/participations",label:"Participations",icon:be},{to:"/admin/adherents",label:"Adhérents",icon:ge},{to:"/admin/reactions",label:"Réactions",icon:je},{to:"/admin/mes-partenaires",label:"Partenaires",icon:Ne,badgeKey:"pendingPartnerAll",children:[{to:"/admin/partenaires",label:"Demandes partenaires",icon:qe,badgeKey:"pendingPartnerReq"},{to:"/admin/jeux-soumissions",label:"Jeux à valider",icon:B,badgeKey:"pendingSubmissions"},{to:"/admin/evenements-soumissions",label:"Ãvènements à valider",icon:B,badgeKey:"pendingEventSubmissions"},{to:"/admin/avantages",label:"Avantages",icon:ve}]},{to:"/admin/albums",label:"Albums photos",icon:ye},{to:"/admin/horoscopes",label:"Horoscopes",icon:oe},{to:"/admin/notifications",label:"Notifications",icon:ie},{to:"/admin/templates-mail",label:"Templates de mails",icon:we},{to:"/admin/api-docs",label:"Documentation API",icon:ke},{to:"/admin/administrateurs",label:"Administrateurs",icon:Ce},{to:"/admin/parametres",label:"Paramètres",icon:De}];function g(u,x,i){return i?u===x:u===x||u.startsWith(x+"/")}function es(){const{loading:u,rolesLoading:x,user:i,isAdmin:c,isEditor:J,allowedSections:F,signOut:C}=de(),j=ae(),r=re(),[T,p]=a.useState(!1),[I,G]=a.useState(0),[L,Q]=a.useState(0),[K,U]=a.useState(0),[O,X]=a.useState(0),[Y,Z]=a.useState(0),[ee,se]=a.useState(0),te=r.pathname==="/admin/login",R=s=>c||(F?.includes(s)??!1),S=s=>c||R(s.to)||(s.children?.some(S)??!1),$=M.filter(S);if(a.useEffect(()=>{if(!c)return;let s=!1;return(async()=>{const f=new Date().toISOString(),n=new Date().toISOString().slice(0,10),[{count:l},{count:v},{count:h},{data:b},{count:N},{count:P}]=await Promise.all([o.from("contests").select("*",{count:"exact",head:!0}).eq("submission_status","pending"),o.from("events").select("*",{count:"exact",head:!0}
1).eq("submission_status","pending"),o.from("ad_slots").select("*",{count:"exact",head:!0}).eq("status","pending_review"),o.from("contests").select("id").eq("is_offline",!1).neq("status","closed").or(`end_date.lt.${f},draw_date.lte.${n}`),o.from("jackpot_prizes").select("*",{count:"exact",head:!0}).eq("status","won").eq("redeem_status","pending"),o.from("partner_requests").select("*",{count:"exact",head:!0}).eq("status","pending")]);if(!s){G(l??0),Q(v??0),U(h??0),se(N??0),X(P??0);const d=(b??[]).map(m=>m.id);let t=0;if(d.length>0){const{data:m}=await o.from("winners").select("contest_id").in("contest_id",d),y=new Set((m??[]).map(_=>_.contest_id));t=d.filter(_=>!y.has(_)).length}s||Z(t)}})(),()=>{s=!0}},[c]),te)return e.jsx(H,{});if(u||i&&x)return e.jsx("div",{className:"flex min-h-screen items-center justify-center",children:e.jsx(ce,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(!i)return j({to:"/admin/login"}),null;if(!c&&!J)return e.jsxs("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 px-4 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Accès refusé"}),e.jsx("p",{className:"text-muted-foreground",children:"Votre compte n'a pas les droits d'administration."}),e.jsx(w,{variant:"outline",onClick:()=>C(),children:"Se déconnecter"})]});const z=M.find(s=>g(r.pathname,s.to,s.exact)),ne=r.pathname==="/admin";if(!c&&z&&!R(z.to)&&!ne)return e.jsxs("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 px-4 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Section non autorisée"}),e.jsx("p",{className:"text-muted-foreground",children:"Vous n'avez pas accès à cette section."}),e.jsx(w,{variant:"outline",onClick:()=>j({to:"/admin"}),children:"Retour"})]});const E=s=>{switch(s){case"pendingPartnerAll":return I+L+K+O;case"pendingPartnerReq":return O;case"pendingSubmissions":return I;case"pendingEventSubmissions":return L;case"pendingAds":return K;case"pendingDraws":return Y;case"jackpotWins":return ee;default:return 0}},V=(s,A,f=!1)=>e.jsx(e.Fragment,{children:s.map(n=>{const l=g(r.pathname,n.to,n.exact),v=E(n.badgeKey),h=n.children?.filter(S)??[],b=h.length>0,N=b&&h.some(t=>g(r.pathname,t.to,t.exact)),P=`flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition ${f?"py-2.5":""} ${l?"bg-primary text-primary-foreground":f?"text-foreground hover:bg-muted":"text-muted-foreground hover:bg-muted hover:text-foreground"}`,d=t=>`inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1.5 text-[10px] font-bold ${t?"bg-primary-foreground text-primary":"bg-destructive text-destructive-foreground"}`;return e.jsxs("div",{children:[e.jsxs(k,{to:n.to,onClick:A,className:P,children:[e.jsx(n.icon,{className:"h-4 w-4 flex-none"}),e.jsx("span",{className:"flex-1 truncate",children:n.label}),v>0&&e.jsx("span",{className:d(l),children:v}),b&&e.jsx(Ae,{className:`h-3.5 w-3.5 flex-none opacity-60 transition-transform ${N||l?"":"-rotate-90"}`})]}),b&&(l||N)&&e.jsx("div",{className:"ml-3 mt-1 space-y-1 border-l border-border pl-2",children:h.map(t=>{const m=g(r.pathname,t.to,t.exact),y=E(t.badgeKey);return e.jsxs(k,{to:t.to,onClick:A,className:`flex items-center gap-2 rounded-lg px-3 py-1.5 text-xs font-medium transition ${m?"bg-primary text-primary-foreground":f?"text-foreground hover:bg-muted":"text-muted-foreground hover:bg-muted hover:text-foreground"}`,children:[e.jsx(t.icon,{className:"h-3.5 w-3.5 flex-none"}),e.jsx("span",{className:"flex-1 truncate",children:t.label}),y>0&&e.jsx("span",{className:d(m),children:y})]},t.to)})})]},n.to)})});return e.jsxs("div",{className:"flex min-h-screen bg-muted/30",children:[e.jsxs("aside",{className:"hidden w-64 flex-col border-r border-border bg-surface md:flex",children:[e.jsxs("div",{className:"flex h-16 items-center gap-2 border-b border-border px-6",children:[e.jsx("img",{src:q,alt:"",className:"h-8 w-8 object-contain"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-bold text-primary",children:"Club Peinard"}),e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Admin"})]})]}),e.jsx("nav",{className:"flex-1 space-y-1 overflow-y-auto p-3",children:V($)}),e.jsxs("div",{className:"border-t border-border p-3",children:[e.jsx("div",{className:"mb-2 px-3 text-xs text-muted-foreground truncate",children:i.email}),e.jsxs(w,{variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>C().then(()=>j({to:"/admin/login"})),children:[e.jsx(W,{className:"h-4 w-4"})," Déconnexion"]})]})]}),e.jsxs("div",{className:"flex-1 overflow-x-hidden",children:[e.jsxs("header",{className:"sticky top-0 z-40 flex h-14 items-center justify-between border-b border-border bg-surface/90 px-4 backdrop-blur md:px-8",children:[e.jsxs("div",{className:"flex items-center gap-2 md:hidden",children:[e.jsx("button",{onClick:()=>p(!0),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-border text-foreground","aria-label":"Menu",children:e.jsx(Se,{className:"h-5 w-5"})}),e.jsx("img",{src:q,alt:"",className:"h-7 w-7"}),e.jsx("span",{className:"text-sm font-bold text-primary",children:"Admin"})]}),e.jsx("div",{className:"hidden md:block text-sm text-muted-foreground",children:M.find(s=>g(r.pathname,s.to,s.exact))?.label??"Admin"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{to:"/admin/scan",className:"text-xs text-muted-foreground hover:text-foreground",children:"Scanner QR â"}),e.jsx(k,{to:"/",className:"text-xs text-muted-foreground hover:text-foreground",children:"Voir le site â"})]})]}),e.jsx("main",{className:"p-4 md:p-8",children:e.jsx(H,{})}),T&&e.jsxs("div",{className:"fixed inset-0 z-50 md:hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60",onClick:()=>p(!1)}),e.jsxs("aside",{className:"absolute left-0 top-0 flex h-full w-72 max-w-[85%] flex-col bg-surface shadow-xl",children:[e.jsxs("div",{className:"flex h-14 items-center justify-between border-b border-border px-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:q,alt:"",className:"h-7 w-7"}),e.jsx("span",{className:"text-sm font-bold text-primary",children:"Admin"})]}),e.jsx("button",{onClick:()=>p(!1),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground hover:bg-muted","aria-label":"Fermer",children:e.jsx(le,{className:"h-5 w-5"})})]}),e.jsx("nav",{className:"flex-1 space-y-1 overflow-y-auto p-3",children:V($,()=>p(!1),!0)}),e.jsxs("div",{className:"border-t border-border p-3",children:[e.jsx("div",{className:"mb-2 px-3 text-xs text-muted-foreground truncate",children:i.email}),e.jsxs(w,{variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>{p(!1),C().then(()=>j({to:"/admin/login"}))},children:[e.jsx(W,{className:"h-4 w-4"})," Déconnexion"]})]})]})]})]})]})}export{es as component};
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.