1import{ap as Q,ah as K,r as n,c as L,j as s,o as O,h as c}from"./index-D8aFWAV7.js";import{u as f}from"./useMutation-BiAgjwu9.js";import{I as G}from"./ImageUpload-Dtpc2i5V.js";import{l as h}from"./useAuditLog-DIN-o5Cu.js";import{u as U,U as R}from"./UnauthorizedPage-B-bZ1nRn.js";import{P as V}from"./plus-D9gEL-RT.js";import{E as H}from"./external-link-BY3msAz9.js";import{P as J}from"./pencil-BxjZT4z5.js";import{T as W}from"./trash-2-CH55cono.js";import"./alert-dialog-ChgfKMZn.js";import"./button-Ddpy21M9.js";import"./arrow-left-BIg2J9Hg.js";import"./upload-Cve2i-Jo.js";import"./check-Doi6Na_i.js";import"./image-D62Ln678.js";import"./lock-C-4tRXYI.js";const j={financiador:"Financiadores",aliado:"Aliados Estratégicos",academico:"Instituciones Académicas",gobierno:"Gobierno",sociedad_civil:"Sociedad Civil"},v=["financiador","aliado","academico","gobierno","sociedad_civil"],z={name:"",logo_url:"",website:"",category:"aliado",description:"",is_active:!0},ue=()=>{const{showSuccess:m,showError:l}=Q(),u=K(),[S,i]=n.useState(!1),[x,w]=n.useState(null),[a,g]=n.useState(z),[d,b]=n.useState(null),[p,D]=n.useState("financiador"),{canManagePartners:y}=U(),{data:C=[],isLoading:P}=L({queryKey:["admin-aliados"],queryFn:async()=>{const{data:e,error:t}=await c.from("partners").select("id, name, logo_url, website, category, description, display_order, is_active").order("display_order",{ascending:!0});if(t)throw t;return e??[]}}),N=f({mutationFn:async e=>{const{data:t,error:o}=await c.from("partners").insert(e).select("id").single();if(o)throw o;return{id:t==null?void 0:t.id,name:e.name}},onSuccess:async e=>{await h({action:"create",entity_type:"partner",entity_id:e.id,entity_label:e.name}),u.invalidateQueries({queryKey:["admin-aliados"]}),m("Aliado agregado"),i(!1)},onError:e=>l(e.message||"Error al crear")}),_=f({mutationFn:async({id:e,payload:t,name:o})=>{const{error:F}=await c.from("partners").update(t).eq("id",e);if(F)throw F;return{id:e,name:o}},onSuccess:async e=>{await h({action:"update",entity_type:"partner",entity_id:e.id,entity_label:e.name}),u.invalidateQueries({queryKey:["admin-aliados"]}),m("Aliado actualizado"),i(!1)},onError:e=>l(e.message||"Error al actualizar")}),A=f({mutationFn:async e=>{const{error:t}=await c.from("partners").delete().eq("id",e.id);if(t)throw t;return e},onSuccess:async e=>{await h({action:"delete",entity_type:"partner",entity_id:e.id,entity_label:e.name}),u.invalidateQueries({queryKey:["admin-aliados"]}),m("Aliado eliminado"),b(null)},onError:()=>l("Error al eliminar")});if(!y)return s.jsx(R,{});const q=()=>{w(null),g(z),i(!0)},B=e=>{w(e.id),g({name:e.name,logo_url:e.logo_url??"",website:e.website??"",category:e.category,description:e.description??"",is_active:e.is_active}),i(!0)},r=(e,t)=>g(o=>({...o,[e]:t})),T=async()=>{if(!a.name.trim()){l("Nombre es requerido");return}const e={name:a.name,logo_url:a.logo_url||null,website:a.website||null,category:a.category,description:a.description||null,is_active:a.is_active};if(x)_.mutate({id:x,payload:e,name:a.name});else{const t=C.filter(o=>o.category===a.category).length;N.mutate({...e,display_order:t})}},M=()=>{d&&A.mutate(d)},I=v.map(e=>({cat:e,label:j[e],items:C.filter(t=>t.category===e).sort((t,o)=>t.display_order-o.display_order)})),E=N.isPending||_.isPending,k=A.isPending;return s.jsxs("div",{className:"w-full max-w-full min-w-0 overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[s.jsx("h1",{className:"font-heading text-[28px] font-bold",style:{color:"#021526"},children:"Aliados y Financiadores"}),y&&s.jsxs("button",{onClick:q,className:"flex items-center gap-2 rounded-md px-5 py-2.5 text-sm font-semibold",style:{backgroundColor:"#FFD700",color:"#021526"},children:[s.jsx(V,{size:18})," Agregar"]})]}),s.jsx("div",{className:"flex gap-1 mb-6 border-b overflow-x-auto",style:{borderColor:"#E1F3F9"},children:v.map(e=>s.jsx("button",{onClick:()=>D(e),className:"px-3 sm:px-4 py-2.5 text-xs sm:text-sm font-medium transition-colors border-b-2 -mb-px whitespace-nowrap",style:{borderColor:p===e?"#FFD700":"transparent",color:p===e?"#021526":"#8FA8BB"},children:j[e]},e))}),!P&&I.filter(e=>e.cat===p).map(e=>s.jsx("div",{children:e.items.length===0?s.jsxs("div",{className:"bg-white rounded-lg p-12 text-center",style:{boxShadow:"0 1px 8px rgba(0,0,0,0.06)"},children:[s.jsx(O,{size:40,className:"mx-auto mb-3",style:{color:"#C5D9E5"}}),s.jsx("p",{className:"text-sm",style:{color:"#8FA8BB"},children:"No hay organizaciones en esta categorÃa."})]}):s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:e.items.map(t=>s.jsxs("div",{className:"bg-white rounded-lg border p-4 sm:p-5 flex gap-3 sm:gap-4",style:{borderColor:"#C5D9E5",opacity:t.is_active?1:.6},children:[s.jsx("div",{className:"shrink-0",children:t.logo_url?s.jsx("img",{src:t.logo_url,alt:t.name,className:"w-12 h-12 rounded-lg object-contain"}):s.jsx("div",{className:"w-12 h-12 rounded-lg flex items-center justify-center font-heading text-lg font-bold text-white",style:{backgroundColor:"#0A4C7A"},children:t.name.charAt(0)})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"font-heading font-semibold text-sm truncate",style:{color:"#021526"},children:t.name}),t.website&&s.jsxs("a",{href:t.website,target:"_blank",rel:"noopener noreferrer",className:"text-xs flex items-center gap-1 mt-0.5",style:{color:"#0A4C7A"},children:[s.jsx(H,{size:10})," Sitio web"]}),y&&s.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[s.jsx("button",{onClick:()=>B(t),className:"p-1 rounded hover:bg-gray-100",title:"Editar",children:s.jsx(J,{size:14,style:{color:"#0A4C7A"}})}),s.jsx("button",{onClick:()=>b(t),className:"p-1 rounded hover:bg-red-50",title:"Eliminar",children:s.jsx(W,{size:14,style:{color:"#E74C3C"}})})]})]})]},t.id))})},e.cat)),S&&s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:s.jsxs("div",{className:"bg-white rounded-xl p-8 max-w-[500px] w-full mx-4 max-h-[90vh] overflow-y-auto",children:[s.jsx("h3",{className:"font-heading text-lg font-semibold mb-4",style:{color:"#021526"},children:x?"Editar organización":"Agregar organización"}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium block mb-1",style:{color:"#021526"},children:"Nombre *"}),s.jsx("input",{value:a.name,onChange:e=>r("name",e.target.value),className:"w-full rounded-md border px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[#0A4C7A]",style:{borderColor:"#C5D9E5"}})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium block mb-1",style:{color:"#021526"},children:"CategorÃa"}),s.jsx("select",{value:a.category,onChange:e=>r("category",e.target.value),className:"w-full rounded-md border px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[#0A4C7A]",style:{borderColor:"#C5D9E5"},children:v.map(e=>s.jsx("option",{value:e,children:j[e]},e))})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium block mb-1",style:{color:"#021526"},children:"Sitio web"}),s.jsx("input",{value:a.website,onChange:e=>r("website",e.target.value),placeholder:"https://",className:"w-full rounded-md border px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[#0A4C7A]",style:{borderColor:"#C5D9E5"}})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-sm font-medium block mb-1",style:{color:"#021526"},children:"Descripción"}),s.jsx("textarea",{value:a.description,onChange:e=>r("description",e.target.value),rows:3,className:"w-full rounded-md border px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[#0A4C7A] resize-none",style:{borderColor:"#C5D9E5"}})]}),s.jsx(G,{value:a.logo_url,onChange:e=>r("logo_url",e),folder:"yais/aliados",label:"Logo de la organización"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"checkbox",id:"partner_active",checked:a.is_active,onChange:e=>r("is_active",e.target.checked),className:"rounded"}),s.jsx("label",{htmlFor:"partner_active",className:"text-sm",style:{color:"#021526"},children:"Visible en el sitio público"})]})]}),s.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[s.jsx("button",{onClick:()=>i(!1),className:"px-4 py-2 rounded-md text-sm font-medium border",style:{borderColor:"#C5D9E5",color:"#021526"},children:"Cancelar"}),s.jsx("button",{onClick:T,disabled:E,className:"px-5 py-2 rounded-md text-sm font-semibold disabled:opacity-50",style:{backgroundColor:"#FFD700",color:"#021526"},children:E?"Guardando...":"Guardar"})]})]})}),d&&s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:s.jsxs("div",{className:"bg-white rounded-xl p-8 max-w-md w-full mx-4",children:[s.jsx("h3",{className:"font-heading text-lg font-semibold mb-2",style:{color:"#021526"},children:"¿Eliminar esta organización?"}),s.jsxs("p",{className:"text-sm mb-6",style:{color:"#8FA8BB"},children:['"',s.jsx("strong",{children:d.name}),'" será eliminada permanentemente.']}),s.jsxs("div",{className:"flex justify-end gap-3",children:[s.jsx("button",{onClick:()=>b(null),className:"px-4 py-2 rounded-md text-sm font-medium border",style:{borderColor:"#C5D9E5",color:"#021526"},children:"Cancelar"}),s.jsx("button",{onClick:M,disabled:k,className:"px-4 py-2 rounded-md text-sm font-medium text-white disabled:opacity-50",style:{backgroundColor:"#E74C3C"},children:k?"Eliminando...":"SÃ, eliminar"})]})]})})]})};export{ue 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.