UNPKG

klioso

Version:

Multi-Service Provider Management System for WordPress and Web Development with Enhanced Scanner

2 lines (1 loc) 10.5 kB
import{j as e,L as p,a as P,d as N}from"./app-DZ07njAd.js";import{A as M}from"./AuthenticatedLayout-BKOGad_C.js";import{B as y}from"./Button-D6Jcp-tA.js";const b=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})}),k=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})});function V({columns:n=[],data:i=[],loading:f=!1,onRowClick:t,sortBy:u=null,sortDirection:g="asc",onSort:m=null}){const c=r=>u!==r?e.jsxs("div",{className:"flex flex-col opacity-30",children:[e.jsx(b,{className:"h-3 w-3 -mb-1"}),e.jsx(k,{className:"h-3 w-3"})]}):g==="asc"?e.jsx(b,{className:"h-4 w-4"}):e.jsx(k,{className:"h-4 w-4"}),l=r=>{r.sortable!==!1&&m&&m(r.key)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsx("tr",{children:n.map((r,d)=>e.jsx("th",{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider ${r.sortable!==!1&&m?"cursor-pointer hover:bg-gray-100":""}`,onClick:()=>l(r),children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx("span",{children:(r==null?void 0:r.label)||""}),r.sortable!==!1&&m&&e.jsx("span",{className:"ml-1",children:c(r.key)})]})},(r==null?void 0:r.key)||(r==null?void 0:r.label)||`header-${d}`))})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:f?e.jsx("tr",{children:e.jsx("td",{colSpan:n.length,className:"px-6 py-8 text-center text-gray-400",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-gray-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Loading..."]})})}):!i||i.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:n.length,className:"px-6 py-8 text-center text-gray-400",children:"No records found."})}):i.map((r,d)=>e.jsx("tr",{className:`${t?"cursor-pointer hover:bg-gray-50":""} transition-colors duration-150`,onClick:t?()=>t(r):void 0,children:n.map((s,x)=>e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:s.render?s.render(r):r==null?void 0:r[s.key]},(s==null?void 0:s.key)||(s==null?void 0:s.label)||`col-${x}`))},(r==null?void 0:r.id)||`row-${d}`))})]})}),e.jsx("div",{className:"md:hidden",children:f?e.jsx("div",{className:"p-8 text-center text-gray-400",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-3 h-5 w-5 text-gray-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Loading..."]})}):!i||i.length===0?e.jsx("div",{className:"p-8 text-center text-gray-400",children:"No records found."}):e.jsx("div",{className:"divide-y divide-gray-200",children:i.map((r,d)=>e.jsx("div",{className:`p-4 ${t?"cursor-pointer hover:bg-gray-50":""} transition-colors duration-150`,onClick:t?()=>t(r):void 0,children:e.jsxs("div",{className:"space-y-2",children:[n.map((s,x)=>{if(s.key==="actions"||s.hideOnMobile)return null;const a=s.render?s.render(r):r==null?void 0:r[s.key];return!a||a==="-"?null:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("span",{className:"text-sm font-medium text-gray-500 w-1/3 flex-shrink-0",children:[s==null?void 0:s.label,":"]}),e.jsx("span",{className:"text-sm text-gray-900 w-2/3 text-right",children:a})]},(s==null?void 0:s.key)||(s==null?void 0:s.label)||`mobile-col-${x}`)}),n.find(s=>s.key==="actions")&&e.jsx("div",{className:"pt-2 border-t border-gray-100 mt-3",children:n.find(s=>s.key==="actions").render(r)})]})},(r==null?void 0:r.id)||`card-${d}`))})})]})}const w=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),C=({className:n})=>e.jsx("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})});function z({current_page:n,last_page:i,per_page:f,total:t,from:u,to:g,links:m=[],path:c="",preserveScroll:l=!0}){if(i<=1)return null;const d=(()=>{const s=[];let a=Math.max(1,n-Math.floor(2.5)),o=Math.min(i,a+5-1);o-a<4&&(a=Math.max(1,o-5+1)),a>1&&(s.push(1),a>2&&s.push("..."));for(let j=a;j<=o;j++)s.push(j);return o<i&&(o<i-1&&s.push("..."),s.push(i)),s})();return e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm text-gray-700 order-2 sm:order-1",children:["Showing ",e.jsx("span",{className:"font-medium",children:u})," to ",e.jsx("span",{className:"font-medium",children:g})," of"," ",e.jsx("span",{className:"font-medium",children:t})," results"]}),e.jsxs("div",{className:"flex items-center space-x-1 order-1 sm:order-2",children:[n>1?e.jsxs(p,{href:`${c}?page=${n-1}`,preserveScroll:l,className:"relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-l-md hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500",children:[e.jsx(w,{className:"h-5 w-5"}),e.jsx("span",{className:"sr-only",children:"Previous"})]}):e.jsxs("span",{className:"relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-300 bg-white border border-gray-300 rounded-l-md cursor-not-allowed",children:[e.jsx(w,{className:"h-5 w-5"}),e.jsx("span",{className:"sr-only",children:"Previous"})]}),d.map((s,x)=>s==="..."?e.jsx("span",{className:"relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300",children:"..."},`ellipsis-${x}`):s===n?e.jsx("span",{className:"relative inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-indigo-600 border border-indigo-600",children:s},s):e.jsx(p,{href:`${c}?page=${s}`,preserveScroll:l,className:"relative inline-flex items-center px-4 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500",children:s},s)),n<i?e.jsxs(p,{href:`${c}?page=${n+1}`,preserveScroll:l,className:"relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-r-md hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500",children:[e.jsx(C,{className:"h-5 w-5"}),e.jsx("span",{className:"sr-only",children:"Next"})]}):e.jsxs("span",{className:"relative inline-flex items-center px-2 py-2 text-sm font-medium text-gray-300 bg-white border border-gray-300 rounded-r-md cursor-not-allowed",children:[e.jsx(C,{className:"h-5 w-5"}),e.jsx("span",{className:"sr-only",children:"Next"})]})]})]})}function A({title:n,data:i=[],columns:f=[],createRoute:t,createButtonText:u="Add New",searchPlaceholder:g="Search...",emptyStateMessage:m="No records found.",filters:c={},searchRoute:l,sortBy:r=null,sortDirection:d="asc",pagination:s=null,children:x}){const[a,o]=P.useState((c==null?void 0:c.search)||"");function j(h){h.preventDefault(),l&&N.get(l,{search:a,sort_by:r,sort_direction:d})}function L(h){if(!l)return;let v="asc";r===h&&d==="asc"&&(v="desc"),N.get(l,{search:a,sort_by:h,sort_direction:v,page:1})}function $(){o(""),N.get(l,{sort_by:r,sort_direction:d})}return e.jsx(M,{children:e.jsx("div",{className:"py-8",children:e.jsx("div",{className:"max-w-7xl mx-auto sm:px-6 lg:px-8",children:e.jsxs("div",{className:"bg-white overflow-hidden shadow-sm sm:rounded-lg",children:[e.jsxs("div",{className:"p-6 border-b border-gray-200",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-800",children:n}),t&&e.jsxs(y,{as:p,href:t,className:"w-full sm:w-auto",children:["+ ",u]})]}),l&&e.jsx("div",{className:"mt-4",children:e.jsxs("form",{onSubmit:j,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",placeholder:g,value:a,onChange:h=>o(h.target.value),className:"flex-1 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{type:"submit",variant:"outline",className:"flex-1 sm:flex-none",children:"Search"}),a&&e.jsx(y,{type:"button",variant:"ghost",onClick:$,className:"flex-1 sm:flex-none",children:"Clear"})]})]})}),x]}),e.jsx("div",{className:"overflow-hidden",children:i&&i.length>0?e.jsxs(e.Fragment,{children:[e.jsx(V,{columns:f,data:i,sortBy:r,sortDirection:d,onSort:L}),s&&e.jsx("div",{className:"px-6 py-4 border-t border-gray-200",children:e.jsx(z,{...s})})]}):e.jsx("div",{className:"text-center py-12",children:e.jsxs("div",{className:"max-w-md mx-auto",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:a?`No ${n.toLowerCase()} found`:`No ${n.toLowerCase()}`}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:a?`No ${n.toLowerCase()} match your search criteria.`:m}),t&&e.jsx("div",{className:"mt-6",children:e.jsxs(y,{as:p,href:t,children:["+ Create your first ",n.toLowerCase().slice(0,-1)]})})]})})})]})})})})}export{A as R};