1import{r as c,j as e,f as j,B as d,e as k,I as t,s as x,h as n}from"./index-BNGXKjJb.js";import{C as p}from"./card-ZW3TLzfr.js";import{B as S}from"./badge-LPC9Ul6S.js";import{D,f as A,a as B,b as P,c as V,e as R}from"./dialog-MheTz5Oq.js";import{S as I}from"./switch-DXtWRaAB.js";import{A as L}from"./AdminLogoutButton-DcljFTE6.js";import{A as O}from"./arrow-left-B5H9nXD_.js";import{V as z}from"./vote-Dxnlr4H-.js";import{P as E}from"./plus-BSa8Ebeu.js";import{S as T}from"./save-NG5S4ZHZ.js";import{T as q}from"./trash-2-Ciny9sdn.js";import"./index-DNCZTDFl.js";import"./index-B8oBx2Ss.js";import"./index-Bnh4fyV8.js";import"./log-out-DPgU9Hc4.js";const g=["party-pi","party-rni","party-pam","party-uc","party-usfp","party-pjd","party-mp","party-pps","party-autres"];function ae(){const[N,v]=c.useState(!0),[_,f]=c.useState(null),[u,b]=c.useState([]),[y,h]=c.useState(!1),[r,o]=c.useState({id:"",name_fr:"",name_ar:"",sigle:"",color_token:"party-autres",ordre:99,is_active:!0});async function m(){const{data:s,error:a}=await x.from("parties").select("*").order("ordre");if(a){n.error("Erreur de chargement");return}b(s??[]),v(!1)}c.useEffect(()=>{m()},[]);async function l(s,a){f(s);const{error:i}=await x.from("parties").update(a).eq("id",s);if(f(null),i){n.error("Ãchec : "+i.message);return}n.success("Mis à jour"),m()}
1async function w(s){if(!confirm(`Supprimer le parti « ${s} » ?`))return;const{error:a}=await x.from("parties").delete().eq("id",s);if(a){n.error("Ãchec : "+a.message);return}n.success("Parti supprimé"),m()}async function C(){var a,i;if(!r.id.trim()||!r.name_fr.trim()){n.error("ID et nom français requis");return}const{error:s}=await x.from("parties").insert({id:r.id.trim().toLowerCase(),name_fr:r.name_fr.trim(),name_ar:((a=r.name_ar)==null?void 0:a.trim())||null,sigle:((i=r.sigle)==null?void 0:i.trim().toUpperCase())||null,color_token:r.color_token,ordre:r.ordre,is_active:r.is_active});if(s){n.error("Ãchec : "+s.message);return}n.success("Parti créé"),h(!1),o({id:"",name_fr:"",name_ar:"",sigle:"",color_token:"party-autres",ordre:99,is_active:!0}),m()}return N?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(j,{className:"w-6 h-6 animate-spin text-primary"})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"gradient-pi p-4 sticky top-0 z-30",children:e.jsxs("div",{className:"max-w-5xl mx-auto flex items-center gap-3 flex-wrap",children:[e.jsx(d,{asChild:!0,size:"sm",variant:"secondary",children:e.jsxs(k,{to:"/admin",children:[e.jsx(O,{className:"w-4 h-4 mr-1"})," Hub National"]})}),e.jsx(z,{className:"w-5 h-5 text-primary-foreground"}),e.jsx("h1",{className:"text-xl font-bold text-primary-foreground",children:"Référentiel â Partis politiques"}),e.jsx("div",{className:"ml-auto flex items-center gap-2",children:e.jsx(L,{})})]})}),e.jsxs("main",{className:"max-w-5xl mx-auto px-4 py-6 space-y-4",children:[e.jsx(p,{className:"p-4 bg-muted/30 border-dashed",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Gérez la liste nationale des partis. Les modifications sont auditées et impactent immédiatement tous les écrans (formulaires PV, agrégations, charts).",e.jsx("strong",{children:" Réservé à l'admin national."})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:u.length})," partis ·"," ",e.jsx("strong",{className:"text-foreground",children:u.filter(s=>s.is_active).length})," actifs"]}),e.jsxs(D,{open:y,onOpenChange:h,children:[e.jsx(A,{asChild:!0,children:e.jsxs(d,{size:"sm",children:[e.jsx(E,{className:"w-4 h-4 mr-1"})," Nouveau parti"]})}),e.jsxs(B,{children:[e.jsx(P,{children:e.jsx(V,{children:"Nouveau parti"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:"ID (slug, ex: pi, rni)"}),e.jsx(t,{value:r.id,onChange:s=>o({...r,id:s.target.value}),placeholder:"ex: msd"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:"Nom français"}),e.jsx(t,{value:r.name_fr,onChange:s=>o({...r,name_fr:s.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:"Sigle (ex: PAM, RNI)"}),e.jsx(t,{value:r.sigle??"",onChange:s=>o({...r,sigle:s.target.value}),placeholder:"ex: MDS"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:"Nom arabe"}),e.jsx(t,{value:r.name_ar??"",onChange:s=>o({...r,name_ar:s.target.value}),dir:"rtl"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:"Couleur (token)"}),e.jsx("select",{className:"w-full h-9 border rounded-md px-2 text-sm bg-background",value:r.color_token,onChange:s=>o({...r,color_token:s.target.value}),children:g.map(s=>e.jsx("option",{value:s,children:s},s))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:"Ordre"}),e.jsx(t,{type:"number",value:r.ordre,onChange:s=>o({...r,ordre:parseInt(s.target.value)||0})})]})]})]}),e.jsxs(R,{children:[e.jsx(d,{variant:"outline",onClick:()=>h(!1),children:"Annuler"}),e.jsxs(d,{onClick:C,children:[e.jsx(T,{className:"w-4 h-4 mr-1"})," Créer"]})]})]})]})]}),e.jsx(p,{className:"p-0 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2",children:"ID"}),e.jsx("th",{className:"text-left p-2",children:"Sigle"}),e.jsx("th",{className:"text-left p-2",children:"Nom (FR)"}),e.jsx("th",{className:"text-left p-2",children:"Nom (AR)"}),e.jsx("th",{className:"text-left p-2",children:"Symbole (AR)"}),e.jsx("th",{className:"text-left p-2",children:"Symbole (FR)"}),e.jsx("th",{className:"text-left p-2",children:"Couleur"}),e.jsx("th",{className:"text-left p-2",children:"Ordre"}),e.jsx("th",{className:"text-left p-2",children:"Actif"}),e.jsx("th",{className:"text-right p-2",children:"Actions"})]})}),e.jsx("tbody",{children:u.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-2",children:e.jsx(S,{variant:"outline",className:"font-mono text-[10px]",children:s.id})}),e.jsx("td",{className:"p-2 w-24",children:e.jsx(t,{defaultValue:s.sigle??"",onBlur:a=>a.target.value!==(s.sigle??"")&&l(s.id,{sigle:a.target.value.trim().toUpperCase()||null}),className:"h-8 text-sm w-20 font-semibold",placeholder:"â"})}),e.jsx("td",{className:"p-2",children:e.jsx(t,{defaultValue:s.name_fr,onBlur:a=>a.target.value!==s.name_fr&&l(s.id,{name_fr:a.target.value}),className:"h-8 text-sm"})}),e.jsx("td",{className:"p-2",children:e.jsx(t,{defaultValue:s.name_ar??"",dir:"rtl",onBlur:a=>a.target.value!==(s.name_ar??"")&&l(s.id,{name_ar:a.target.value||null}),className:"h-8 text-sm"})}),e.jsx("td",{className:"p-2",children:e.jsx(t,{defaultValue:s.symbole_ar??"",dir:"rtl",title:s.symbole_note??void 0,onBlur:a=>a.target.value!==(s.symbole_ar??"")&&l(s.id,{symbole_ar:a.target.value||null}),className:"h-8 text-sm w-28",placeholder:"â"})}),e.jsx("td",{className:"p-2",children:e.jsx(t,{defaultValue:s.symbole_fr??"",title:s.symbole_note??void 0,onBlur:a=>a.target.value!==(s.symbole_fr??"")&&l(s.id,{symbole_fr:a.target.value||null}),className:"h-8 text-sm w-32",placeholder:"â"})}),e.jsx("td",{className:"p-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-4 h-4 rounded-full border",style:{background:`hsl(var(--${s.c
1olor_token}))`}}),e.jsx("select",{defaultValue:s.color_token,onChange:a=>l(s.id,{color_token:a.target.value}),className:"h-8 border rounded-md px-1 text-xs bg-background",children:g.map(a=>e.jsx("option",{value:a,children:a},a))})]})}),e.jsx("td",{className:"p-2 w-20",children:e.jsx(t,{type:"number",defaultValue:s.ordre,onBlur:a=>{const i=parseInt(a.target.value)||0;i!==s.ordre&&l(s.id,{ordre:i})},className:"h-8 text-sm w-16"})}),e.jsx("td",{className:"p-2",children:e.jsx(I,{checked:s.is_active,onCheckedChange:a=>l(s.id,{is_active:a})})}),e.jsxs("td",{className:"p-2 text-right",children:[_===s.id&&e.jsx(j,{className:"w-4 h-4 animate-spin inline mr-2"}),e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>w(s.id),className:"text-destructive hover:bg-destructive/10",children:e.jsx(q,{className:"w-4 h-4"})})]})]},s.id))})]})})})]})]})}export{ae 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.