1import{s as V,r as n,b as K,t as v,j as e,L as W}from"./vendor-react-core-_0sZDOLQ.js";import{c as J,B as i,b as l}from"./index-j07E1qHv.js";import{C as k,a as D}from"./card-DHmBnTdH.js";import{B as H}from"./badge-BXqwvh8U.js";import{I as b}from"./input-rti45mgP.js";import{L as d}from"./label-7HT5__eZ.js";import{D as X,b as Y,c as Z,d as ee}from"./dialog-C9ty4md6.js";import{t as o}from"./index-CDqomOa1.js";import{o as _,b as se}from"./orgaosSociais-lZ4163aP.js";import{_ as ae,L,aa as re,a0 as oe,a9 as F,ad as te,ae as ie,ag as ne}from"./vendor-lucide-Ddz0eB7N.js";import{m as le}from"./vendor-framer-motion-C1oRD-X5.js";import"./vendor-radix-CFmJ1img.js";import"./vendor-utils-BRu4i-LD.js";import"./vendor-supabase-Ca6cp8v2.js";const ce=["image/jpeg","image/png","image/webp"],de=5*1024*1024,E=m=>({id:null,organ:m,section:"",name:"",role:"",photo_url:"",sort_order:0});function _e(){const m=V(),[c,z]=n.useState(_[0].id),[I,u]=n.useState(!1),[a,t]=n.useState(E(_[0].id)),[x,M]=n.useState(!1),g=n.useRef(null),{data:h=[],isLoading:B}=K({queryKey:["admin-committee-members"],queryFn:()=>l.entities.CommitteeMember.list("sort_order"),initialData:[]}),p=()=>{m.invalidateQueries({queryKey:["admin-committee-members"]}),m.invalidateQueries({queryKey:["committee-members"]})},S=v({mutationFn:s=>l.entities.CommitteeMember.create(s),onSuccess:()=>{p(),o.success("Membro adicionado"),j()},onError:s=>o.error("Erro ao adicionar: "+s.message)}),P=v({mutationFn:({id:s,data:r})=>l.entities.CommitteeMember.update(s,r),onSuccess:()=>{p(),o.success("Membro atualizado"),j()},onError:s=>o.error("Erro ao atualizar: "+s.message)}),q=v({mutationFn:s=>l.entities.CommitteeMember.delete(s),onSuccess:()=>{p(),o.success("Membro eliminado")},onError:s=>o.error("Erro ao eliminar: "+s.message)}),y=v({mutationFn:async()=>{const s=se();for(const r of s)await l.entities.CommitteeMember.create(r);return s.length},onSuccess:s=>{p(),o.success(`${s} membros importados da composição atual`)},onError:s=>o.error("Erro ao importar: "+s.message)}),w=n.useMemo(()=>h.filter(s=>s.organ===c).sort((s,r)=>(s.sort_order??0)-(r.sort_order??0)),[h,c]),G=async s=>{var f,N;const r=(f=s.target.files)==null?void 0:f[0];if(r){if(!ce.includes(r.type)){o.error("Formato inválido. Utilize JPG, PNG ou WEBP.");return}if(r.size>de){o.error("A fotografia não pode exceder 5 MB.");return}M(!0);try{const C=((N=r.name.split(".").pop())==null?void 0:N.toLowerCase())||"jpg",$=`committee/${a.organ}/${Date.now()}.${C}`,{url:Q}=await l.storage.upload(r,"public",$);t(T=>({...T,photo_url:Q})),o.success("Foto carregada")}catch(C){o.error("Erro ao carregar foto: "+C.message)}finally{M(!1),g.current&&(g.current.value="")}}},O=()=>{const s=w.length;t({...E(c),sort_order:s}),u(!0)},U=s=>{t({id:s.id,organ:s.organ,section:s.section||"",name:s.name||"",role:s.role||"",photo_url:s.photo_url||"",sort_order:s.sort_order??0}),u(!0)},j=()=>{u(!1),t(E(c))},R=()=>{if(!a.name.trim()){o.error("Indique o nome do membro");return}const s={organ:a.organ,section:a.section.trim()||null,name:a.name.trim(),role:a.role.trim(),photo_url:a.photo_url||null,sort_order:Number(a.sort_order)||0};a.id?P.mutate({id:a.id,data:s}):S.mutate(s)},A=S.isPending||P.isPending;return e.jsx("main",{className:"min-h-screen bg-gray-50 py-12",children:e.jsxs("div",{className:"container mx-auto px-4 max-w-6xl",children:[e.jsx(W,{to:J("Admin"),children:e.jsxs(i,{variant:"ghost",className:"mb-6",children:[e.jsx(ae,{className:"w-4 h-4 mr-2"}),"Voltar ao Dashboard"]})}),e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Ãrgãos Sociais"}),e.jsx("p",{className:"text-gray-600 mt-1",children:"Gerir membros, cargos e fotos da Direção (Conselho de Administração) e dos restantes conselhos."})]}),e.jsxs("div",{className:"flex gap-2",children:[h.length===0&&e.jsxs(i,{variant:"outline",onClick:()=>y.mutate(),disabled:y.isPending,children:[y.isPending?e.jsx(L,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(re,{className:"w-4 h-4 mr-2"}),"Importar composição atual"]}),e.jsxs(i,{onClick:O,className:"bg-red-600 hover:bg-red-700",children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Novo Membro"]})]})]}),e.jsx("div",{className:"mb-6 grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-7",children:_.map(s=>{const r=h.filter(N=>
1N.organ===s.id).length,f=s.icon;return e.jsxs("button",{onClick:()=>z(s.id),className:`rounded-lg border p-3 text-left transition-all ${c===s.id?"border-red-600 bg-red-600 text-white shadow":"border-gray-200 bg-white text-gray-700 hover:border-red-200"}`,children:[e.jsx(f,{className:"h-4 w-4 mb-2"}),e.jsx("span",{className:"block text-xs font-bold uppercase leading-tight",children:s.label}),e.jsxs("span",{className:"text-[11px] opacity-70",children:[r," membro(s)"]})]},s.id)})}),B?e.jsx("div",{className:"space-y-3",children:[...Array(4)].map((s,r)=>e.jsx("div",{className:"bg-white rounded-xl h-20 animate-pulse"},r))}):w.length===0?e.jsx(k,{children:e.jsxs(D,{className:"p-10 text-center text-gray-500",children:["Sem membros neste órgão. Use ",e.jsx("strong",{children:"Novo Membro"})," para adicionar."]})}):e.jsx("div",{className:"space-y-3",children:w.map((s,r)=>e.jsx(le.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:r*.03},children:e.jsx(k,{className:"hover:shadow-md transition-shadow",children:e.jsxs(D,{className:"p-4 flex items-center gap-4",children:[s.photo_url?e.jsx("img",{src:s.photo_url,alt:s.name,className:"h-14 w-14 flex-shrink-0 rounded-full object-cover ring-2 ring-gray-100"}):e.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(F,{className:"h-6 w-6"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:s.name}),s.section&&e.jsx(H,{variant:"outline",className:"text-[10px]",children:s.section})]}),e.jsx("p",{className:"text-sm text-red-600 font-semibold uppercase tracking-wide",children:s.role})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{variant:"outline",size:"sm",onClick:()=>U(s),children:e.jsx(te,{className:"w-4 h-4"})}),e.jsx(i,{variant:"destructive",size:"sm",onClick:()=>{confirm(`Eliminar ${s.name}?`)&&q.mutate(s.id)},children:e.jsx(ie,{className:"w-4 h-4"})})]})]})})},s.id))}),e.jsx(X,{open:I,onOpenChange:s=>s?u(!0):j(),children:e.jsxs(Y,{className:"max-w-lg",children:[e.jsx(Z,{children:e.jsx(ee,{children:a.id?"Editar Membro":"Novo Membro"})}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[a.photo_url?e.jsx("img",{src:a.photo_url,alt:"Pré-visualização",className:"h-20 w-20 rounded-full object-cover ring-2 ring-gray-100"}):e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(F,{className:"h-8 w-8"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(d,{className:"text-xs font-bold uppercase tracking-wide text-gray-700",children:"Foto do Membro"}),e.jsx("input",{ref:g,type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:G}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsxs(i,{type:"button",variant:"outline",size:"sm",disabled:x,onClick:()=>{var s;return(s=g.current)==null?void 0:s.click()},children:[x?e.jsx(L,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(ne,{className:"w-4 h-4 mr-2"}),x?"A carregar...":"Carregar foto"]}),a.photo_url&&e.jsx(i,{type:"button",variant:"ghost",size:"sm",onClick:()=>t(s=>({...s,photo_url:""})),children:"Remover"})]}),e.jsx("p",{className:"mt-1 text-[11px] text-gray-400",children:"JPG, PNG ou WEBP, até 5 MB."})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Nome *"}),e.jsx(b,{value:a.name,onChange:s=>t({...a,name:s.target.value}),placeholder:"Ex: FERNANDO ALVES SIMÃES",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Cargo"}),e.jsx(b,{value:a.role,onChange:s=>t({...a,role:s.target.value}),placeholder:"Ex: Presidente, Vice-Presidente, Vogal...",className:"mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Subsecção (opcional)"}),e.jsx(b,{value:a.section,onChange:s=>t({...a,section:s.target.value}),placeholder:"Ex: Membros Executivos",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Ordem"}),e.jsx(b,{type:"number",value:a.sort_order,onChange:s=>t({...a,sort_order:s.target.value}),className:"mt-1"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2 border-t",children:[e.jsx(i,{variant:"outline",onClick:j,children:"Cancelar"}),e.jsx(i,{onClick:R,disabled:A||x,className:"bg-red-600 hover:bg-red-700",children:A?"A guardar...":a.id?"Atualizar":"Adicionar"})]})]})})]})})}export{_e 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.