1import{r,j as e}from"./vendor-ui-BdR_ANcL.js";import{s as l,X as w}from"./index-Cn5xffnt.js";import{A as k,P as C}from"./AdminLayout-kL7wkakl.js";import{u as P}from"./vendor-react-2wG_afoi.js";import{P as S}from"./plus-D30fJu8P.js";import{E as A}from"./eye-BMzCEiAZ.js";import{C as E}from"./check-CD-_Uj2C.js";import{L as O}from"./loader-circle-DVFRhfMM.js";import{P as f}from"./pencil-CKaDS7vy.js";import{T as g}from"./trash-2-rse5P_FJ.js";import"./vendor-supabase-XW2fJUyV.js";import"./vendor-query-usLDJ6bn.js";import"./search-d-yVYwhR.js";import"./button-Cleb-rsw.js";import"./input-AF-TwFbP.js";import"./layout-dashboard-CMZY6z1g.js";import"./calendar-days-BI0Zyafy.js";import"./file-pen-line-BY8VawwN.js";import"./tag-C8jgmNm_.js";import"./sparkles-BL_WcjYp.js";import"./file-text-BYWNfX8q.js";import"./shield-D4huCjMA.js";import"./credit-card-Cb42gfjS.js";import"./smartphone-BPRZu-pi.js";import"./log-out-DIk4ReN6.js";const b={name:"",min_days:"1",max_days:"",discount_percent:"0",active:!0,sort_order:"0",subtitle:"",color:"blue",icon_emoji:"ð",features:"",show_on_homepage:!1,cta_label:"Réserver maintenant"},j=[{value:"blue",label:"Bleu",gradient:"from-blue-500 to-blue-700"},{value:"green",label:"Vert",gradient:"from-green-500 to-green-700"},{value:"purple",label:"Violet",gradient:"from-purple-500 to-purple-700"},{value:"red",label:"Rouge",gradient:"from-red-500 to-red-700"},{value:"orange",label:"Orange",gradient:"from-orange-500 to-orange-700"},{value:"teal",label:"Teal",gradient:"from-teal-500 to-teal-700"}];function I(o){return j.find(n=>n.value===o)?.gradient||"from-blue-500 to-blue-700"}function re(){const o=P(),[n,N]=r.useState([]),[v,u]=r.useState(!0),[i,d]=r.useState(null),[s,a]=r.useState(b);r.useEffect(()=>{l.auth.getSession().then(({data:t})=>{t.session||o("/admin/login")})},[o]);const c=r.useCallback(async()=>{u(!0);const{data:t}=await l.from("promotions").select("*").order("sort_order",{ascending:!0});N(t||[]),u(!1)},[]);r.useEffect(()=>{c()},[c]);function m(t){t?(d(t.id),a({name:t.name,min_days:String(t.min_days),max_days:t.max_days!==null?String(t.max_days):"",discount_percent:String(t.discount_percent),active:t.active,sort_order:String(t.sort_order||0),subtitle:t.subtitle||"",color:t.color||"blue",icon_emoji:t.icon_emoji||"ð",features:(t.features||[]).join(` 2`),show_on_homepage:t.show_on_homepage||!1,cta_label:t.cta_label||"Réserver maintenant"})):(d("new"),a(b))}async function _(){const t={name:s.name,min_days:parseInt(s.min_days)||1,max_days:s.max_days?parseInt(s.max_days):null,discount_percent:parseFloat(s.discount_percent)||0,active:s.active,sort_order:parseInt(s.sort_order)||0,subtitle:s.subtitle,color:s.color,icon_emoji:s.icon_emoji,features:s.features.split(` 3`).map(x=>x.trim()).filter(Boolean),show_on_homepage:s.show_on_homepage,cta_label:s.cta_label};i==="new"?await l.from("promotions").insert(t):await l.from("promotions").update(t).eq("id",i),d(null),c()}async function h(t){confirm("Supprimer cette promotion ?")&&(await l.from("promotions").delete().eq("id",t),c())}const p=n.filter(t=>t.show_on_homepage&&t.active);return e.jsx(k,{title:"Promotions",icon:e.jsx(C,{className:"w-5 h-5 text-primary"}),children:e.jsxs("div",{className:"max-w-5xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold font-heading text-foreground",children:"Gestion des Promotions"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:`Les promotions s'appliquent automatiquement. Cochez "Afficher sur la page d'accueil" pour les cartes promo.`})]}),e.jsxs("button",{onClick:()=>m(),className:"btn-accent flex items-center gap-2 text-sm px-4 py-2",children:[e.jsx(S,{className:"h-4 w-4"})," Ajouter"]})]}),p.length>0&&e.jsxs("div",{className:"bg-background rounded-xl border border-border p-5",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4 text-primary"}),' Aperçu "Promotions du Moment"']}),e.jsx("div",{className:"grid sm:grid-cols-3 gap-4",children:p.slice(0,3).map(t=>e.jsxs("div",{className:`relative bg-gradient-to-br ${I(t.color)} rounded-xl p-5 text-white shadow-lg`,children:[e.jsxs("div",{className:"absolute top-3 right-3 bg-yellow-400 text-gray-900 px-2 py-0.5 rounded-full text-xs font-bold",children:["-",t.discount_percent,"%"]}),e.jsxs("div",{className:"text-center mb-3",children:[e.jsx("div",{className:"text-3xl mb-2",children:t.icon_emoji}),e.jsx("h4",{className:"text-lg font-bold",children:t.name}),e.jsx("p",{className:"text-white/80 text-xs",children:t.subtitle})]}),e.jsx("ul",{className:"space-y-1 mb-3 text-xs",children:(t.features||[]).map((x,y)=>e.jsxs("li",{className:"flex items-center gap-1",children:["â ",x]},y))}),e.jsx("div",{className:"bg-white rounded-md py-1.5 text-center text-xs font-bold",style:{color:"hsl(var(--primary))"},children:t.cta_label})]},t.id))})]}),i&&e.jsxs("div",{className:"bg-background rounded-xl border border-border p-5 space-y-4",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:i==="new"?"Nouvelle promotion":"Modifier la promotion"}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Nom"}),e.jsx("input",{value:s.name,onChange:t=>a({...s,name:t.target.value}),className:"input-field",placeholder:"Ex: Offre Weekend"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Sous-titre"}),e.jsx("input",{value:s.subtitle,onChange:t=>a({...s,subtitle:t.target.value}),className:"input-field",placeholder:"Ex: Vendredi - Lundi"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Réduction (%)"}),e.jsx("input",{type:"number",value:s.discount_percent,onChange:t=>a({...s,discount_percent:t.target.value}),className:"input-field",min:"0",max:"100"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Emoji / Icône"}),e.jsx("input",{value:s.icon_emoji,onChange:t=>a({...s,icon_emoji:t.target.value}),className:"input-field",placeholder:"ð"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Jours min"}),e.jsx("input",{type:"number",value:s.min_days,onChange:t=>a({...s,min_days:t.target.value}),className:"input-field",min:"1"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Jours max (vide = illimité)"}),e.jsx("input",{type:"number",value:s.max_days,onChange:t=>a({...s,max_days:t.target.value}),className:"input-field",placeholder:"â"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Couleur de la carte"}),e.jsx("select",{value:s.color,onChange:t=>a({...s,color:t.target.value}),className:"input-field",children:j.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Texte du bouton CTA"}),e.jsx("input",{value:s.cta_label,onChange:t=>a({...s,cta_label:t.target.value}),className:"input-field"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Ordre d'affichage"}),e.jsx("input",{type:"number",value:s.sort_order,onChange:t=>a({...s,sort_order:t.target.value}),className:"input-field"})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-6",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx("input",{type:"checkbox",checked:s.active,onChange:t=>a({...s,active:t.target.checked}),className:"h-4 w-4"}),"Active"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx("input",{type:"checkbox",checked:s.show_on_homepage,onChange:t=>a({...s,show_on_homepage:t.target.checked}),className:"h-4 w-4"}),"ð Page d'accueil"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-foreground",children:"Avantages (un par ligne)"}),e.jsx("textarea",{value:s.features,onChange:t=>a({...s,features:t.target.value}),className:"input-field",rows:3,placeholder:`20% de réduction 4Kilométrage illimité 5GPS gratuit`})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("button",{onClick:_,className:"btn-accent flex items-center gap-2 text-sm px-4 py-2",children:[e.jsx(E,{className:"h-4 w-4"})," Enregistrer"]}),e.jsxs("button",{onClick:()=>d(null),className:"btn-outline flex items-center gap-2 text-sm px-4 py-2",children:[e.jsx(w,{className:"h-4 w-4"})," Annuler"]})]})]}),e.jsx("div",{className:"bg-background rounded-xl border border-border overflow-hidden",children:v?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(O,{className:"h-6 w-6 animate-spin text-primary"})}):n.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Aucune promotion configurée."}):e.jsxs(e.Fragment,{children:[e.jsxs("table",{className:"w-full text-sm hidden sm:table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-muted text-muted-foreground border-b border-border",children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold",children:"Nom"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold",children:"Jours"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold",children:"Réduction"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold",children:"Accueil"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold",children:"Statut"}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold",children:"Actions"})]})}),e.jsx("tbody",{children:n.map(t=>e.jsxs("tr",{className:"border-b border-border hover:bg-muted/50 transition-colors",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:t.icon_emoji}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:t.name}),t.subtitle&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.subtitle})]})]})}),e.jsxs("td",{className:"px-4 py-3 text-muted-foreground",children:[t.min_days," â ",t.max_days??"â"," j"]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`font-bold ${t.discount_percent>0?"text-green-600":"text-muted-foreground"}`,children:t.discount_percent>0?`-${t.discount_percent}%`:"0%"})}),e.jsx("td",{className:"px-4 py-3",children:t.show_on_homepage?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-blue-100 text-blue-800 font-semibold",children:"ð Oui"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-semibold ${t.active?"bg-green-100 text-green-800":"bg-muted text-muted-foreground"}`,children:t.active?"Active":"Inactive"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>m(t),className:"p-1.5 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-primary",children:e.jsx(f,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>h(t.id),className:"p-1.5 rounded hover:bg-red-50 transition-colors text-red-500",children:e.jsx(g,{className:"h-4 w-4"})})]})})]},t.id))})]}),e.jsx("div",{className:"sm:hidden divide-y divide-border",children:n.map(t=>e.jsxs("div",{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium text-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:t.icon_emoji})," ",t.name]}),e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-semibold ${t.active?"bg-green-100 text-green-800":"bg-muted text-muted-foreground"}`,children:t.active?"Active":"Inactive"})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[t.min_days," â ",t.max_days??"â"," j"]}),e.jsx("span",{className:`font-bold ${t.discount_percent>0?"text-green-600":"text-muted-foreground"}`,children:t.discount_percent>0?`-${t.discount_percent}%`:"0%"})]}),t.show_on_homepage&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-blue-100 text-blue-800 font-semibold",children:"ð Page d'accueil"}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsxs("button",{onClick:()=>m(t),className:"flex items-center gap-1 text-xs px-3 py-1.5 rounded bg-muted text-muted-foreground hover:text-primary transition-colors",children:[e.jsx(f,{className:"h-3.5 w-3.5"})," Modifier"]}),e.jsxs("button",{onClick:()=>h(t.id),className:"flex items-center gap-1 text-xs px-3 py-1.5 rounded bg-red-50 text-red-500 hover:bg-red-100 transition-colors",children:[e.jsx(g,{className:"h-3.5 w-3.5"})," Supprimer"]})]})]},t.id))})]})})]})})}export{re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.