import{c as E,r as s,j as e,L as O}from"./index-DiwDH9aE.js";import{S as Q}from"./search-h1vL1q1e.js";import{X as D,C as Y}from"./x-D4vgwdOf.js";import{C as Z,I as F,T as ee,a as te}from"./triangle-alert-BxjRBxgM.js";import{C as se}from"./circle-check-big-CvbUXdGb.js";/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const re=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],q=E("arrow-down",re);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ae=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],A=E("arrow-up",ae);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const le=[["path",{d:"m11 17-5-5 5-5",key:"13zhaf"}],["path",{d:"m18 17-5-5 5-5",key:"h8a8et"}]],ne=E("chevrons-left",le);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const oe=[["path",{d:"m6 17 5-5-5-5",key:"xnjwq"}],["path",{d:"m13 17 5-5-5-5",key:"17xmmf"}]],ie=E("chevrons-right",oe),ge=({columns:p=[],data:g=null,onFetchData:c,initialParams:n={},renderActions:d,loading:b=!1,loadingMessage:v="Cargando datos...",searchable:M=!0,autoSearch:x=!0,sortable:u=!0,searchPlaceholder:V="Buscar...",emptyMessage:k="No hay datos disponibles",perPageOptions:f=[10,15,25,50,100]})=>{const[a,C]=s.useState(n.search||""),[o,X]=s.useState(n.sort_by||"id"),[m,T]=s.useState(n.order||"asc"),[_,z]=s.useState(n.per_page||f[0]),[I,l]=s.useState(1),P=s.useRef({}),y=s.useRef(!1);s.useEffect(()=>{const{search:t,sort_by:h,order:r,per_page:N,page:$,...w}=n;P.current=w},[]),s.useEffect(()=>{c&&!y.current&&(y.current=!0,j(1))},[c]),s.useEffect(()=>{if(!y.current||!x)return;const t=setTimeout(()=>{l(1),j(1)},500);return()=>clearTimeout(t)},[a,x]),s.useEffect(()=>{y.current&&(l(1),j(1))},[o,m,_]),s.useEffect(()=>{y.current&&j(I)},[I]);const j=(t=1)=>{const h={page:t,per_page:_,sort_by:o,order:m,...P.current};a.trim()&&(h.search=a.trim()),c(h)},L=()=>{l(1),j(1)},U=()=>{C(""),l(1);const t={page:1,per_page:_,sort_by:o,order:m,...P.current};c(t)},W=t=>{o===t?T(m==="asc"?"desc":"asc"):(X(t),T("asc"))},R=g?.data||[],G=g?.meta||{},{current_page:i=1,from:H=0,to:J=0,total:B=0,last_page:S=1}=G,K=(()=>{const t=[],r=Math.floor(2.5);let N=Math.max(1,i-r),$=Math.min(S,N+5-1);$-N+1<5&&(N=Math.max(1,$-5+1));for(let w=N;w<=$;w++)t.push(w);return t})();return e.jsxs("div",{className:"space-y-4 relative bg-white p-2 rounded-lg border border-gray-200",children:[b&&e.jsx(O,{message:v,variant:"light",portal:!1,overlay:!0}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between ",children:[M&&e.jsxs("div",{className:"flex items-center gap-2 flex-1 max-w-md",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Q,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4"}),e.jsx("input",{type:"text",value:a,onChange:t=>C(t.target.value),onKeyDown:t=>!x&&t.key==="Enter"&&L(),placeholder:V,className:"w-full pl-10 pr-10 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all"}),a&&e.jsx("button",{type:"button",onClick:U,className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors",title:"Limpiar búsqueda",children:e.jsx(D,{className:"w-4 h-4"})})]}),!x&&e.jsx("button",{type:"button",onClick:L,className:"px-4 py-2 bg-[#00306e] text-white rounded-lg hover:bg-[#004080] transition-colors whitespace-nowrap",children:"Buscar"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"perPage",className:"text-sm text-gray-700 whitespace-nowrap",children:"Mostrar:"}),e.jsx("select",{id:"perPage",value:_,onChange:t=>z(Number(t.target.value)),className:"border border-gray-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all",children:f.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),e.jsx("div",{className:"overflow-x-auto bg-white rounded-lg border border-gray-200",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[p.map(t=>e.jsx("th",{onClick:()=>t.sortable!==!1&&u&&W(t.key),className:`px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider transition-colors ${t.sortable!==!1&&u?"cursor-pointer hover:bg-gray-100 select-none":""} ${t.width||""}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t.label}),t.sortable!==!1&&u&&e.jsx("div",{className:"flex flex-col",children:o===t.key&&m==="asc"?e.jsx(A,{className:"w-3 h-3 text-[#00306e]"}):o===t.key&&m==="desc"?e.jsx(q,{className:"w-3 h-3 text-[#00306e]"}):e.jsxs("div",{className:"flex flex-col opacity-30",children:[e.jsx(A,{className:"w-3 h-3 -mb-1"}),e.jsx(q,{className:"w-3 h-3"})]})})]})},t.key)),d&&e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider w-32",children:"Acciones"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200",children:R.length>0?R.map((t,h)=>e.jsxs("tr",{className:"hover:bg-gray-50 transition-colors",children:[p.map(r=>e.jsx("td",{className:`px-6 py-4 text-sm text-gray-900 ${r.wrap===!1?"whitespace-nowrap":"whitespace-normal break-words"} ${r.maxWidth||""}`,children:r.render?r.render(t[r.key],t):t[r.key]??"-"},r.key)),d&&e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm",children:e.jsx("div",{className:"flex items-center justify-end gap-2",children:d(t)})})]},t.id||h)):e.jsx("tr",{children:e.jsx("td",{colSpan:p.length+(d?1:0),className:"px-6 py-12 text-center text-gray-500",children:k})})})]})}),R.length>0&&B>0&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-white border border-gray-200 rounded-lg",children:[e.jsxs("div",{className:"text-sm text-gray-700",children:["Mostrando ",e.jsx("span",{className:"font-medium",children:H})," a"," ",e.jsx("span",{className:"font-medium",children:J})," de"," ",e.jsx("span",{className:"font-medium",children:B})," registros"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>l(1),disabled:i===1,className:"p-2 rounded-lg border border-gray-300 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Primera página",children:e.jsx(ne,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:()=>l(i-1),disabled:i===1,className:"p-2 rounded-lg border border-gray-300 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Página anterior",children:e.jsx(Z,{className:"w-4 h-4"})}),K.map(t=>e.jsx("button",{type:"button",onClick:()=>l(t),className:`px-3 py-1 rounded-lg text-sm font-medium transition-colors ${t===i?"bg-[#00306e] text-white":"text-gray-700 hover:bg-gray-100"}`,children:t},t)),e.jsx("button",{type:"button",onClick:()=>l(i+1),disabled:i===S,className:"p-2 rounded-lg border border-gray-300 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Página siguiente",children:e.jsx(Y,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:()=>l(S),disabled:i===S,className:"p-2 rounded-lg border border-gray-300 hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Última página",children:e.jsx(ie,{className:"w-4 h-4"})})]})]})]})},be=({variant:p="info",title:g="",message:c="",children:n,dismissible:d=!0,autoClose:b=0,onClose:v,className:M="",icon:x})=>{const[u,V]=s.useState(!0);s.useEffect(()=>{if(b>0){const o=setTimeout(()=>{k()},b);return()=>clearTimeout(o)}},[b]);const k=()=>{V(!1),v&&v()};if(!u)return null;const f={success:{container:"bg-green-50 border-green-200 text-green-800",icon:e.jsx(se,{className:"w-5 h-5 text-green-600"}),title:"text-green-900"},error:{container:"bg-red-50 border-red-200 text-red-800",icon:e.jsx(te,{className:"w-5 h-5 text-red-600"}),title:"text-red-900"},warning:{container:"bg-yellow-50 border-yellow-200 text-yellow-800",icon:e.jsx(ee,{className:"w-5 h-5 text-yellow-600"}),title:"text-yellow-900"},info:{container:"bg-blue-50 border-blue-200 text-blue-800",icon:e.jsx(F,{className:"w-5 h-5 text-blue-600"}),title:"text-blue-900"}},a=f[p]||f.info,C=x||a.icon;return e.jsxs("div",{className:`
                relative flex items-start gap-3 px-4 py-3 mb-4 rounded-lg border
                ${a.container}
                ${M}
            `,role:"alert",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:C}),e.jsxs("div",{className:"flex-1 min-w-0",children:[g&&e.jsx("h4",{className:`font-semibold text-sm mb-1 ${a.title}`,children:g}),c&&e.jsx("p",{className:"text-sm",children:c}),n&&e.jsx("div",{className:"mt-2 text-sm",children:n})]}),d&&e.jsx("button",{type:"button",onClick:k,className:"flex-shrink-0 p-1 rounded-md hover:bg-black/5 transition-colors","aria-label":"Cerrar alerta",children:e.jsx(D,{className:"w-4 h-4"})})]})};export{be as A,ge as D};
