1import{r as s,j as e,B as i,a as A,b as z,X as E,E as L,w as q,C as G,s as c,t as r}from"./index-CowhCOWN.js";import{C as y,a as D}from"./card-BLbw1ekn.js";import{D as H,a as Y,b,c as U,e as V}from"./dialog-DuVWCFQP.js";import{A as $,a as X,b as J,c as K,d as Q,e as W,f as Z,g as ee}from"./alert-dialog-D7RhGaIx.js";import{B as f}from"./badge-DUOqbc8O.js";import{u as te}from"./useServerFn-D2gARKP5.js";import{d as ae}from"./upload.functions-Dzc8ICZ_.js";import{B as se}from"./BackToPartners-6hc_puqV.js";import{B as re}from"./BenefitForm-KvFMJlOa.js";import{E as S,B as F,a as ie,b as ne,c as le}from"./benefits-CBi80tgg.js";import{P as oe}from"./plus-Brwqy4y8.js";import{C as ce}from"./clock-SM1Ry1rl.js";import{M as me}from"./map-pin-nyiJzMgM.js";import{M as de}from"./mail-DkDDuS8P.js";import{P as pe}from"./pencil-BlgVpXJc.js";import{T as ue}from"./trash-2-D9kxAHen.js";import{G as xe}from"./gift-bJLrnt79.js";import"./index-CvFYP4_A.js";import"./index-Bl2K_kVK.js";import"./index-BDJ43p2d.js";import"./index-DNauxUwX.js";import"./index-R4QDO2ZY.js";import"./index-DRz5Di7l.js";import"./auth-middleware-BzIwszNl.js";import"./arrow-left-Jkal33Te.js";import"./input-D2OO1sCJ.js";import"./label-CQeSIlgo.js";import"./textarea-DDMwI1YU.js";import"./switch-DSveKqAg.js";import"./index-CuHniv-8.js";import"./select-BrmKvK-X.js";import"./index-DmKQT1G3.js";import"./index-C5FsXfzk.js";import"./chevron-down-DFXQwo6o.js";import"./ImageUploader-BkUJgma0.js";import"./upload-http-BFb09Ope.js";import"./image-CTtByhsV.js";import"./upload-Bud1puEv.js";import"./external-link-QAbIUs5A.js";import"./PartnerPicker-BF1AeWzr.js";import"./popover-RB91kQq2.js";import"./command-D9Q-Kvet.js";import"./search-Bk70yWaV.js";function rt(){const[n,B]=s.useState([]),[k,h]=s.useState(!0),[T,l]=s.useState(!1),[m,j]=s.useState(null),[x,g]=s.useState(S),[v,N]=s.useState(!1),[d,p]=s.useState(null),M=te(ae),u=async()=>{h(!0);const{data:t,error:a}=await c.from("privilege_benefits").select("*").order("display_order",{ascending:!1,nullsFirst:!1}).order("created_at",{ascending:!1});a&&r.error(a.message),B(t??[]),h(!1)};s.useEffect(()=>{u()},[]);const I=()=>{j(null),g(S),l(!0)},O=t=>{j(t),g(ne(t)),l(!0)},P=async()=>{if(!x.title.trim()){r.error("Le titre est obligatoire");return}N(!0);const t=le(x),{error:a}=m?await c.from("privilege_benefits").update(t).eq("id",m.id):await c.from("privilege_benefits").insert(t);if(N(!1),a){r.error(a.message);return}r.success(m?"Avantage mis à jour":"Avantage créé"),l(!1),u()},R=async()=>{if(!d)return;const t=n.find(o=>o.id===d),{error:a}=await c.from("privilege_benefits").delete().eq("id",d);if(a){r.error(a.message),p(null);return}if(t?.image_url)try{await M({data:{url:t.image_url}})}catch(o){console.warn(o)}r.success("Avantage supprimé"),p(null),u()},w=async(t,a)=>{const o=a==="rejected"?window.prompt("Motif du rejet (optionnel, sera visible par le partenaire) :")??"":"",{error:C}=await c.from("privilege_benefits").update({status:a,admin_review_note:o||null}).eq("id",t.id);if(C){r.error(C.message);return}r.success(a==="approved"?"Avantage validé":"Avantage rejeté"),u()},_=n.filter(t=>t.status==="pending");return e.jsxs("div",{className:"space-y-6",children:[e.jsx(se,{}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Avantages Carte Privilège"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[n.length," avantage(s)",_.length>0?` · ${_.length} en attente de validation`:""]})]}),e.jsxs(i,{onClick:I,children:[e.jsx(oe,{className:"h-4 w-4"})," Nouvel avantage"]})]}),k?e.jsx(A,{className:"h-5 w-5 animate-spin"}):e.jsxs("div",{className:"grid gap-3",children:[n.map(t=>e.jsx(y,{children:e.jsxs(D,{className:"flex items-center gap-3 p-4",children:[e.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center overflow-hidden rounded-lg bg-muted text-2xl",children:t.image_url?e.jsx("img",{src:z(t.image_url),alt:"",className:"h-full w-full object-cover"}):F[t.category]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate font-semibold",children:t.title}),t.status==="pending"&&e.jsxs(f,{variant:"default",className:"gap-1 bg-amber-500 hover:bg-amber-500",children:[e.jsx(ce,{className:"h-3 w-3"})," à valider"]}),t.status==="rejected"&&e.jsxs(f,{variant:"destructive",className:"gap-1",children:[e.jsx(E,{className:"h-3 w-3"})," Rejeté"]}),t.status==="approved"&&e.jsxs(f,{variant:t.is_active?"default":"secondary",className:"gap-1",children:[t.is_active?e.jsx(L,{className:"h-3 w-3"}):e.jsx(q,{className:"h-3 w-3"}),t.is_active?"En ligne":"Masqué"]})]}),e.jsxs("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[F[t.category]," ",t.category_label||ie[t.category],t.partner_name?` · ${t.partner_name}`:"",t.location?e.jsxs(e.Fragment,{children:[" · ",e.jsx(me,{className:"inline h-3 w-3"})," ",t.location]}):null]}),t.partner_email&&e.jsxs("p",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"inline h-3 w-3"})," ",t.partner_email]}),t.status==="rejected"&&t.admin_review_note&&e.jsxs("p",{className:"mt-1 text-[11px] text-destructive",children:["Motif : ",t.admin_review_note]})]}),t.status!=="approved"&&e.jsx(i,{variant:"ghost",size:"icon",onClick:()=>w(t,"approved"),"aria-label":"Valider",title:"Valider",children:e.jsx(G,{className:"h-4 w-4 text-green-600"})}),t.status!=="rejected"&&e.jsx(i,{variant:"ghost",size:"icon",onClick:()=>w(t,"rejected"),"aria-label":"Rejeter",title:"Rejeter",children:e.jsx(E,{className:"h-4 w-4 text-destructive"})}),e.jsx(i,{variant:"ghost",size:"icon",onClick:()=>O(t),"aria-label":"Modifier",children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsx(i,{variant:"ghost",size:"icon",onClick:()=>p(t.id),"aria-label":"Supprimer",children:e.jsx(ue,{className:"h-4 w-4 text-destructive"})})]})},t.id)),n.length===0&&e.jsx(y,{children:e.jsxs(D,{className:"flex flex-col items-center gap-2 py-10 text-center text-sm text-muted-foreground",children:[e.jsx(xe,{className:"h-8 w-8 text-muted-foreground
1/50"}),"Aucun avantage pour le moment. Créez le premier !"]})})]}),e.jsx(H,{open:T,onOpenChange:l,children:e.jsxs(Y,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",children:[e.jsx(b,{children:e.jsx(U,{children:m?"Modifier l'avantage":"Nouvel avantage"})}),e.jsx(re,{form:x,setForm:g,allowEmailEdit:!0}),e.jsxs(V,{children:[e.jsx(i,{variant:"outline",onClick:()=>l(!1),children:"Annuler"}),e.jsx(i,{onClick:P,disabled:v,children:v?e.jsx(A,{className:"h-4 w-4 animate-spin"}):"Enregistrer"})]})]})}),e.jsx($,{open:!!d,onOpenChange:t=>!t&&p(null),children:e.jsxs(X,{children:[e.jsxs(J,{children:[e.jsx(K,{children:"Supprimer cet avantage ?"}),e.jsx(Q,{children:"Cette action est irréversible."})]}),e.jsxs(W,{children:[e.jsx(Z,{children:"Annuler"}),e.jsx(ee,{onClick:R,className:"bg-destructive text-destructive-foreground",children:"Supprimer"})]})]})})]})}export{rt 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.