import{r as y,j as e,a as x,J as s,f as h}from"./app-BZJf8lgN.js";import{L as j}from"./layout-DZ5xjWdd.js";import{D as b,C as n}from"./column.esm-BrHEUUD7.js";import{B as l}from"./button.esm-D_cwsnQR.js";import{T as g}from"./toast.esm-CYGIlaDH.js";import{C as v,c as C}from"./confirmdialog.esm-DF1Ea2vk.js";import"./hooks.esm-UVLztt_0.js";import"./CSSTransition-DBuKQJwM.js";import"./inputtext.esm-B1lZn37a.js";import"./index.esm-mvXJc0W-.js";import"./dropdown.esm-HqLoOpxI.js";import"./overlayservice.esm-B-BnP5c1.js";import"./index.esm-hRnQzR_k.js";import"./csstransition.esm-BNRxTMOa.js";import"./index.esm-CygY3Qsw.js";import"./index.esm-Ckth6fI3.js";import"./index.esm-B5zYYMSp.js";import"./dialog.esm-B_DzXfDY.js";const q=({items:m=[],fields:c=[],routes:t={},seccionName:a,idKey:o="id"})=>{const i=y.useRef(null),d=r=>{C({message:`¿Estás seguro de eliminar este elemento de ${a}?`,header:`Eliminar ${a}`,icon:"pi pi-exclamation-triangle",acceptClassName:"p-button-danger",acceptLabel:"Sí, eliminar",rejectLabel:"No, cancelar",accept:()=>p(r[o]),reject:()=>{i.current.show({severity:"warn",summary:"Cancelado",detail:"No se ha eliminado nada.",life:3e3})}})},p=r=>{if(!t.destroy){console.error("La ruta de eliminación (routes.destroy) no está definida."),i.current.show({severity:"error",summary:"Error",detail:"Ruta de eliminación no configurada.",life:3e3});return}h.delete(route(t.destroy,r),{onSuccess:()=>{i.current.show({severity:"success",summary:"Éxito",detail:`${a} eliminado correctamente.`,life:3e3})},onError:f=>{console.error("Error al eliminar:",f),i.current.show({severity:"error",summary:"Error",detail:`No se pudo eliminar el ${a}.`,life:3e3})},preserveScroll:!0})},u=r=>e.jsxs(e.Fragment,{children:[t.edit&&e.jsx(s,{href:route(t.edit,r[o]),className:"mr-2",children:e.jsx(l,{type:"button",icon:"pi pi-pencil"})}),t.destroy&&e.jsx(l,{type:"button",icon:"pi pi-times",severity:"danger",onClick:()=>d(r)})]});return e.jsxs(j,{children:[e.jsx(x,{title:a}),e.jsx(g,{ref:i}),e.jsx(v,{}),e.jsxs("div",{className:"card",children:[t.create&&e.jsx("div",{className:"card-header",style:{display:"flex",justifyContent:"flex-end"},children:e.jsx(s,{href:route(t.create),className:"p-button mb-2",style:{color:"white"},children:"Crear Nuevo"})}),e.jsxs(b,{value:m,paginator:!0,rows:10,rowsPerPageOptions:[5,10,25,50],tableStyle:{minWidth:"50rem"},children:[c.map(r=>e.jsx(n,{field:r.name,header:r.label,sortable:!0},r.name)),(t.edit||t.destroy)&&e.jsx(n,{header:"Acciones",body:u,exportable:!1,style:{minWidth:"8rem"}})]})]})]})};export{q as default};
//# sourceMappingURL=DynamicIndex-BeFtjP_F.js.map
