1import{j as e,S as G,r as K,s as Q,q as X,o as $,K as H,O as J,_ as Y,t as Z,D as I,ab as ee,T as se,c as m,X as te,J as re,p as V,ac as ae,ad as le,Z as ie}from"./vendor-ui-Bom0WISh.js";import{r as i}from"./vendor-react-BVq_0oXA.js";import{s as S,A as ne,B as oe}from"./feature-admin-C7FsrmIp.js";import{N as ce}from"./index-Bxm0HLNQ.js";import{f as de,g as ue,D as W}from"./vendor-forms-ErPCSlVj.js";import{f as O}from"./feature-events-konOxz-2.js";import{I as me}from"./ImageUpload-CtLR_quv.js";/* empty css */import"./vendor-utils-CNkd3xx2.js";import"./feature-files-CeAUSXKh.js";const xe=({articles:a,onEdit:j,onDelete:f,onArchive:g,onRestore:_,isArchiveView:C=!1,selectedArticles:k,onSelectArticles:p,archiving:T=!1,restoring:v=null})=>{const[u,b]=i.useState({}),[o,N]=i.useState(!1),[F,E]=i.useState(null),[x,w]=i.useState(1),y=10,h=a.filter(s=>{var P;let r=!0;if(u.search){const t=u.search.toLowerCase();r=r&&(s.title.toLowerCase().includes(t)||s.content.toLowerCase().includes(t)||((P=s.excerpt)==null?void 0:P.toLowerCase().includes(t))||!1)}return u.category&&(r=r&&s.category===u.category),u.startDate&&(r=r&&(!s.publish_date||new Date(s.publish_date)>=u.startDate)),u.endDate&&(r=r&&(!s.publish_date||new Date(s.publish_date)<=u.endDate)),r}),A=Math.ceil(h.length/y),z=h.slice((x-1)*y,x*y),M=s=>{switch(s){case"published":return"bg-green-100 text-green-800";case"draft":return"bg-yellow-100 text-yellow-800";case"archived":return"bg-gray-100 text-gray-800";default:return"bg-gray-100 text-gray-800"}},D=s=>{switch(s){case"published":return"Publié";case"draft":return"Brouillon";case"archived":return"Archivé";default:return s}},q=async(s,r)=>{r.stopPropagation(),r.preventDefault(),E(s);try{await f(s)}finally{E(null)}},B=async(s,r)=>{r.stopPropagation(),r.preventDefault(),g&&await g(s)},R=async(s,r)=>{r.stopPropagation(),r.preventDefault(),_&&await _(s)},U=()=>{k.length===h.length?p([]):p(h.map(s=>s.id))},n=(s,r)=>{r.stopPropagation(),r.preventDefault(),k.includes(s)?p(k.filter(P=>P!==s)):p([...k,s])};return e.jsxs("div",{className:"bg-white rounded-lg shadow-md overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200",children:[e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 items-center justify-between",children:[e.jsxs("div",{className:"relative flex-grow max-w-md",children:[e.jsx(G,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400",size:20}),e.jsx("input",{type:"text",placeholder:"Rechercher un article...",className:"w-full pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",onChange:s=>b(r=>({...r,search:s.target.value}))})]}),e.jsxs("button",{onClick:()=>N(!o),className:"flex items-center gap-2 px-4 py-2 bg-purple-100 text-purple-700 rounded-lg hover:bg-purple-200 transition-colors",children:[e.jsx(K,{size:20}),e.jsx("span",{children:"Filtres"}),e.jsx(Q,{size:20,className:`transform transition-transform ${o?"rotate-180":""}`})]})]}),e.jsx(X,{children:o&&e.jsxs($.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"mt-4 grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Catégorie"}),e.jsxs("select",{className:"w-full rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500 p-2",onChange:s=>b(r=>({...r,category:s.target.value||void 0})),value:u.category||"",children:[e.jsx("option",{value:"",children:"Toutes les catégories"}),ce.map(s=>e.jsx("option",{value:s,children:s},s))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date de début"}),e.jsx("input",{type:"date",className:"w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",onChange:s=>b(r=>({...r,startDate:s.target.value?new Date(s.target.value):void 0}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date de fin"}),e.jsx("input",{type:"date",className:"w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",onChange:s=>b(r=>({...r,endDate:s.target.value?new Date(s.target.value):void 0}))})]})]})})]}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-10",children:e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:U,className:"focus:outline-none",title:k.length===
1h.length?"Tout désélectionner":"Tout sélectionner",children:k.length===h.length&&h.length>0?e.jsx(H,{className:"w-5 h-5 text-purple-600"}):e.jsx(J,{className:"w-5 h-5 text-gray-400"})})})}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Titre"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Catégorie"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Publication"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Statut"}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:z.map(s=>e.jsxs($.tr,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{onClick:r=>n(s.id,r),className:"focus:outline-none",children:k.includes(s.id)?e.jsx(H,{className:"w-5 h-5 text-purple-600"}):e.jsx(J,{className:"w-5 h-5 text-gray-400"})})})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center",children:[s.image_url&&e.jsx("img",{src:s.image_url,alt:s.title,className:"h-10 w-10 rounded-lg object-cover mr-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:s.title}),s.excerpt&&e.jsx("div",{className:"text-sm text-gray-500 line-clamp-2",children:s.excerpt})]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:"px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-purple-100 text-purple-800",children:s.category})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:s.publish_date?e.jsx("time",{className:"text-sm text-gray-500",children:de(new Date(s.publish_date),"dd MMMM yyyy",{locale:O})}):e.jsx("span",{className:"text-sm text-gray-500",children:"Non définie"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full ${M(s.status)}`,children:D(s.status)})}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium",children:[C?e.jsx("button",{onClick:r=>R(s.id,r),disabled:v===s.id,className:"text-green-600 hover:text-green-900 mx-2",title:"Restaurer",children:v===s.id?e.jsx(I,{size:18,className:"animate-spin"}):e.jsx(ee,{size:18})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>j(s),className:"text-blue-600 hover:text-blue-900 mx-2",title:"Modifier",children:e.jsx(Y,{size:18})}),e.jsx("button",{onClick:r=>B(s.id,r),disabled:T,className:"text-amber-600 hover:text-amber-900 mx-2",title:"Archiver",children:e.jsx(Z,{size:18,className:T?"animate-pulse":""})})]}),e.jsx("button",{onClick:r=>q(s.id,r),className:"text-red-600 hover:text-red-900 mx-2",title:"Supprimer",disabled:F===s.id,children:F===s.id?e.jsx(I,{size:18,className:"animate-spin"}):e.jsx(se,{size:18})})]})]},s.id))})]}),h.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(G,{className:"mx-auto h-12 w-12 text-gray-400"}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:"Aucun article trouvé"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:"Aucun article ne correspond à vos critères de recherche."})]}),A>1&&e.jsxs("div",{className:"px-6 py-4 flex items-center justify-between border-t border-gray-200",children:[e.jsxs("div",{className:"flex-1 flex justify-between sm:hidden",children:[e.jsx("button",{onClick:()=>w(s=>Math.max(1,s-1)),disabled:x===1,className:"relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Précédent"}),e.jsx("button",{onClick:()=>w(s=>Math.min(A,s+1)),disabled:x===A,className:"ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Suivant"})]}),e.jsxs("div",{className:"hidden sm:flex-1 sm:flex sm:items-center sm:justify-between",children:[e.jsx("div",{children:e.jsxs("p",{className:"text-sm text-gray-700",children:["Affichage de ",e.jsx("span",{className:"font-medium",children:(x-1)*y+1})," à "," ",e.jsx("span",{className:"font-medium",children:Math.min(x*y,h.length)})," ","sur ",e.jsx("span",{className:"font-medium",children:h.length})," résultats"]})}),e.jsx("div",{children:e.jsxs("nav",{className:"relative z-0 inline-flex rounded-md shadow-sm -space-x-px","aria-label":"Pagination",children:[e.jsxs("button",{onClick:()=>w(s=>Math.max(1,s-1)),disabled:x===1,className:"relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"sr-only",children:"Précédent"}),e.jsx("svg",{className:"h-5 w-5",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})]}),Array.from({length:A},(s,r)=>r+1).map(s=>e.jsx("button",{onClick:()=>w(s),className:`relative inline-flex items-center px-4 py-2 border text-sm font-medium ${x===s?"z-10 bg-purple-50 border-purple-500 text-purple-600":"bg-white border-gray-300 text-gray-500 hover:bg-gray-50"}`,children:s},s)),e.jsxs("button",{onClick:()=>w(s=>Math.min(A,s+1)),disabled:x===A,className:"relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"sr-only",children:"Suivant"}),e.jsx("svg",{className:"h-5 w-5",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})]})]})})]})]})]})]})},he=({article:a,onSubmit:j,onCancel:f})=>{const[g,_]=i.useState((a==null?void 0:a.title)||""),[C,k]=i.useState((a==null?void 0:a.content)||""),[p,T]=i.useState((a==null?void 0:a.image_url)||""),[v,u]=i.useState(a!=null&&a.publish_date?new Date(a.publish_date):null),[b,o]=i.useState(a!=null&&a.expiry_date?new Date(a.expiry_date):null),[N,F]=i.useState((a==null?void 0:a.category)||""),[E,x]=i.useState((a==null?void 0:a.status)||"published"),[w,y]=i.useState(!1),h=i.useRef(null),[A,z]=i.useState(!1);i.useEffect(()=>{if(!w)return;const n=setTimeout(()=>{M(!0)},12e4);return()=>clearTimeout(n)},[g,C,p,v,b,N,E]);const M=async(n=!1)=>
1{if(!g||!C||!N){n||m.error("Veuillez remplir tous les champs obligatoires");return}const s={title:g,content:C,image_url:p,publish_date:v==null?void 0:v.toISOString(),expiry_date:b==null?void 0:b.toISOString(),category:N,status:E};j(s),y(!1)},D=i.useCallback(()=>{y(!0)},[]),q=async n=>{var P;const s=(P=n.target.files)==null?void 0:P[0];if(!s)return;if(!["image/jpeg","image/png","image/gif","image/webp"].includes(s.type)){m.error("Format de fichier non supporté. Utilisez JPG, PNG, GIF ou WEBP.");return}if(s.size>5*1024*1024){m.error("Le fichier est trop volumineux (5MB maximum)");return}z(!0);try{const{data:{session:t}}=await S.auth.getSession();if(!(t!=null&&t.user))throw new Error("Non authentifié");const c=`news/${new Date().getTime()}-${s.name.replace(/[^a-zA-Z0-9.-]/g,"-")}`,{error:d}=await S.storage.from("files").upload(c,s);if(d)throw d;const{data:{publicUrl:L}}=S.storage.from("files").getPublicUrl(c);T(L),y(!0),m.success("Image téléchargée avec succès")}catch(t){console.error("Error uploading image:",t),m.error("Erreur lors du téléchargement de l'image")}finally{z(!1),n.target.value=""}},B=n=>{T(n),D()},R={toolbar:{container:[[{header:[1,2,!1]}],["bold","italic","underline","strike","blockquote"],[{align:["","center","right","justify"]}],[{list:"ordered"},{list:"bullet"},{indent:"-1"},{indent:"+1"}],["link","image"],["clean"]]},clipboard:{matchVisual:!1}},U=["header","bold","italic","underline","strike","blockquote","align","list","bullet","indent","link","image"];return e.jsxs($.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"bg-white rounded-lg shadow-md p-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"text-2xl font-bold",children:a?"Modifier l'article":"Nouvel article"}),e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{onClick:f,className:"px-4 py-2 text-gray-600 hover:text-gray-800 transition-colors",children:e.jsx(te,{className:"w-5 h-5"})})})]}),e.jsxs("form",{onSubmit:n=>{n.preventDefault(),M()},className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"title",className:"block text-sm font-medium text-gray-700 mb-1",children:["Titre ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",id:"title",value:g,onChange:n=>{_(n.target.value),D()},className:"w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",required:!0})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Image"}),e.jsx("div",{className:"mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-lg",children:e.jsxs("div",{className:"space-y-1 text-center",children:[e.jsx(re,{className:"mx-auto h-12 w-12 text-gray-400"}),e.jsxs("div",{className:"flex text-sm text-gray-600",children:[e.jsxs("label",{htmlFor:"file-upload",className:"relative cursor-pointer bg-white rounded-md font-medium text-purple-600 hover:text-purple-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-purple-500",children:[e.jsx("span",{children:"Télécharger une image"}),e.jsx("input",{id:"file-upload",name:"file-upload",type:"file",className:"sr-only",accept:"image/*",onChange:q,disabled:A})]}),e.jsx("p",{className:"pl-1",children:"ou glisser-déposer"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"PNG, JPG, GIF jusqu'à 5MB"}),A&&e.jsx("div",{className:"mt-2 text-sm text-purple-600",children:"Téléchargement en cours..."})]})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"OU utiliser l'outil de sélection d'image"}),e.jsx(me,{onImageUploaded:B,currentImage:p})]}),p&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Image sélectionnée :"}),e.jsx("div",{className:"mt-2 relative w-full h-48 bg-gray-100 rounded-lg overflow-hidden",children:e.jsx("img",{src:p,alt:"Preview",className:"w-full h-full object-contain"})})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Contenu ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("div",{className:"prose prose-sm max-w-none min-h-[400px]",children:e.jsx(ue,{ref:h,value:C,onChange:n=>{k(n),D()},modules:R,formats:U,className:"h-[300px] [&_.ql-editor]:min-h-[250px] [&_.ql-container]:!h-auto [&_.ql-editor]:overflow-y-auto",theme:"snow"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date de publication"}),e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400",size:20}),e.jsx(W,{selected:v,onChange:n=>{u(n),D()},locale:O,showTimeSelect:!0,timeFormat:"HH:mm",timeIntervals:15,dateFormat:"Pp",className:"w-full pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",placeholderText:"Sélectionner une date"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date d'expiration"}),e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400",size:20}),e.jsx(W,{selected:b,onChange:n=>{o(n),D()},locale:O,showTimeSelect:!0,timeFormat:"HH:mm",timeIntervals:15,dateFormat:"Pp",className:"w-full pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",placeholderText:"Sélectionner une date",minDate:v||new Date})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Catégorie ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{value:N,onChange:n=>{F(n.target.value),D()},className:"w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",required:!0,children:[e.jsx("option",{value:"",children:"Sélectionner une catégorie"}),e.jsx("option",{value:"Actualités municipales",children:"Actualités municipales"}),e.jsx("option",{value:"Culture",children:"Culture"}),e.jsx("option",{value:"Sport",children:"Sport"}),e.jsx("option",{value:"Ãducation",children:"Ãducation"}
1),e.jsx("option",{value:"Environnement",children:"Environnement"}),e.jsx("option",{value:"Travaux",children:"Travaux"}),e.jsx("option",{value:"Ãconomie",children:"Ãconomie"}),e.jsx("option",{value:"Social",children:"Social"}),e.jsx("option",{value:"Jeunesse",children:"Jeunesse"}),e.jsx("option",{value:"Seniors",children:"Seniors"}),e.jsx("option",{value:"Associations",children:"Associations"}),e.jsx("option",{value:"Autre",children:"Autre"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Statut"}),e.jsxs("select",{value:E,onChange:n=>{x(n.target.value),D()},className:"w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500",children:[e.jsx("option",{value:"published",children:"Publié"}),e.jsx("option",{value:"draft",children:"Brouillon"}),e.jsx("option",{value:"archived",children:"Archivé"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-4",children:[e.jsx("button",{type:"button",onClick:f,className:"px-6 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors",children:"Annuler"}),e.jsxs("button",{type:"submit",className:"px-6 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors flex items-center gap-2",children:[e.jsx(ae,{size:20}),a?"Mettre à jour":"Créer"," l'article"]})]})]})]})},Ce=()=>{const[a,j]=i.useState([]),[f,g]=i.useState([]),[_,C]=i.useState(null),[k,p]=i.useState(!1),[T,v]=i.useState(!0),[u,b]=i.useState("active"),[o,N]=i.useState([]),[F,E]=i.useState(!1),[x,w]=i.useState(null),[y,h]=i.useState(!1),[A,z]=i.useState(null);i.useEffect(()=>{M()},[]);const M=async()=>{try{v(!0);const{data:t,error:l}=await S.from("news_articles").select("*").order("created_at",{ascending:!1});if(l)throw l;const c=(t==null?void 0:t.filter(L=>L.status!=="archived"))||[],d=(t==null?void 0:t.filter(L=>L.status==="archived"))||[];j(c),g(d)}catch(t){console.error("Error fetching articles:",t),m.error("Erreur lors du chargement des articles")}finally{v(!1)}},D=()=>{C(null),p(!0)},q=t=>{C(t),p(!0)},B=async t=>{try{z(t);const{data:l,error:c}=await S.from("news_articles").update({status:"draft"}).eq("id",t).select().single();if(c)throw c;m.success("Article restauré avec succès"),g(f.filter(d=>d.id!==t)),j([l,...a])}catch(l){console.error("Error restoring article:",l),m.error("Erreur lors de la restauration de l'article")}finally{z(null)}},R=async t=>{try{h(!0);const{data:l,error:c}=await S.from("news_articles").update({status:"archived"}).eq("id",t).select().single();if(c)throw c;m.success("Article archivé avec succès"),j(a.filter(d=>d.id!==t)),g([l,...f])}catch(l){console.error("Error archiving article:",l),m.error("Erreur lors de l'archivage de l'article")}finally{h(!1)}},U=async t=>{if(confirm("Ãtes-vous sûr de vouloir supprimer cet article ?"))try{w(t);const{error:l}=await S.from("news_articles").delete().eq("id",t);if(l)throw l;m.success("Article supprimé avec succès"),u==="active"?j(a.filter(c=>c.id!==t)):g(f.filter(c=>c.id!==t))}catch(l){console.error("Error deleting article:",l),m.error("Erreur lors de la suppression de l'article")}finally{w(null)}},n=async()=>{if(o.length!==0)try{w("bulk");const{error:t}=await S.from("news_articles").delete().in("id",o);if(t)throw t;m.success(`${o.length} article(s) supprimé(s) avec succès`),u==="active"?j(a.filter(l=>!o.includes(l.id))):g(f.filter(l=>!o.includes(l.id))),N([])}catch(t){console.error("Error bulk deleting articles:",t),m.error("Erreur lors de la suppression des articles")}finally{w(null),E(!1)}},s=async()=>{if(o.length!==0)try{h(!0);const t=a.filter(d=>o.includes(d.id)),{error:l}=await S.from("news_articles").update({status:"archived"}).in("id",o);if(l)throw l;m.success(`${o.length} article(s) archivé(s) avec succès`);const c=a.filter(d=>o.includes(d.id));j(a.filter(d=>!o.includes(d.id))),g([...c,...f]),N([])}catch(t){console.error("Error bulk archiving articles:",t),m.error("Erreur lors de l'archivage des articles")}finally{h(!1)}},r=async t=>{try{const{data:{user:l}}=await S.auth.getUser();if(!l)throw new Error("User not authenticated");if(_){const{error:c}=await S.from("news_articles").update(t).eq("id",_.id);if(c)throw c;j(a.map(d=>d.id===_.id?{...d,...t}:d)),m.success("Article mis à jour avec succès")}else{const{data:c,error:d}=await S.from("news_articles").insert([{...t,created_by:l.id}]).select().single();if(d)throw d;j([c,...a]),m.success("Article créé avec succès")}p(!1),C(null)}catch(l){console.error("Error saving article:",l),m.error("Erreur lors de l'enregistrement de l'article")}},P=()=>F?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-lg p-6 max-w-md w-full mx-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4 text-red-600",children:[e.jsx(ie,{className:"w-6 h-6"}),e.jsx("h3",{className:"text-xl font-semibold",children:"Confirmer la suppression multiple"})]}),e.jsxs("p",{className:"text-gray-600 mb-6",children:["Ãtes-vous sûr de vouloir supprimer les ",o.length," article
1(s) sélectionné(s) ? Cette action est irréversible."]}),e.jsxs("div",{className:"flex justify-end gap-4",children:[e.jsx("button",{onClick:()=>E(!1),className:"px-4 py-2 text-gray-600 hover:text-gray-800",disabled:x==="bulk",children:"Annuler"}),e.jsxs("button",{onClick:n,disabled:x==="bulk",className:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:opacity-50 flex items-center gap-2",children:[x==="bulk"&&e.jsx(I,{className:"w-4 h-4 animate-spin"}),x==="bulk"?"Suppression...":"Supprimer la sélection"]})]})]})}):null;return T?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-purple-600"})}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{}),e.jsxs("div",{className:"container mx-auto px-4 py-8 mt-16",children:[e.jsxs("div",{className:"flex justify-between items-center mb-8",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(oe,{}),e.jsx("h1",{className:"text-3xl font-bold",children:"Gestion des actualités"})]}),e.jsxs("button",{onClick:D,className:"flex items-center px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors",children:[e.jsx(le,{className:"w-5 h-5 mr-2"}),"Nouvel article"]})]}),e.jsx($.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3},children:k?e.jsx(he,{article:_,onSubmit:r,onCancel:()=>{p(!1),C(null)}}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex border-b border-gray-200 mb-6",children:[e.jsx("button",{className:`py-2 px-4 font-medium ${u==="active"?"text-purple-600 border-b-2 border-purple-600":"text-gray-500 hover:text-gray-700"}`,onClick:()=>{b("active"),N([])},children:"Articles actifs"}),e.jsxs("button",{className:`py-2 px-4 font-medium flex items-center ${u==="archived"?"text-purple-600 border-b-2 border-purple-600":"text-gray-500 hover:text-gray-700"}`,onClick:()=>{b("archived"),N([])},children:["Archives",f.length>0&&e.jsx("span",{className:"ml-2 bg-gray-100 text-gray-700 px-2 py-0.5 rounded-full text-xs",children:f.length})]})]}),o.length>0&&e.jsxs("div",{className:"bg-purple-50 p-4 rounded-lg mb-4 flex justify-between items-center",children:[e.jsxs("p",{className:"text-purple-700",children:[o.length," article(s) sélectionné(s)"]}),e.jsxs("div",{className:"flex gap-2",children:[u==="active"&&e.jsxs("button",{onClick:s,disabled:y,className:"px-4 py-2 bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors flex items-center gap-2",children:[y&&e.jsx(I,{className:"w-4 h-4 animate-spin"}),e.jsx(Z,{className:"w-4 h-4"}),"Archiver la sélection"]}),e.jsxs("button",{onClick:()=>E(!0),className:"px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors flex items-center gap-2",children:[e.jsx(I,{className:`w-4 h-4 ${x==="bulk"?"animate-spin":"hidden"}`}),"Supprimer la sélection"]})]})]}),e.jsx(xe,{articles:u==="active"?a:f,onEdit:q,onDelete:U,onArchive:R,onRestore:B,isArchiveView:u==="archived",selectedArticles:o,onSelectArticles:N,archiving:y,restoring:A})]})})]}),e.jsx(P,{})]})};export{Ce 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.