1import{r as p,j as e,a7 as u,d as f,B as h,C as y,l as g}from"./index-BJ_cpA-m.js";import{u as j}from"./useQuery-BReEIV68.js";import{A as N}from"./AdminLayout-DAjvB7aS.js";import{f as C}from"./format-VgUdphAZ.js";import{e as w}from"./es-C6aXSG5D.js";import{E as _}from"./external-link-CakzC5WX.js";import{C as v}from"./calendar-check-CJHcC0e1.js";import{C as E}from"./chevron-left-DGAvHWmc.js";import"./shield-check-BOzNhUaF.js";import"./building-2-B3tsWhhT.js";import"./paw-print-zaFqSEHd.js";import"./arrow-left-DXR_O1_Y.js";import"./en-US-g5X7NGE6.js";import"./normalizeDates-_jLPl24R.js";const d=50,S={pending:{label:"Pendiente",cls:"bg-amber-100 text-amber-800"},confirmed:{label:"Confirmada",cls:"bg-mint text-primary"},cancelled:{label:"Cancelada",cls:"bg-red-100 text-red-700 line-through"},completed:{label:"Completada",cls:"bg-secondary text-foreground"},no_show:{label:"No asistió",cls:"bg-muted text-muted-foreground"}};function P(t,l="EUR"){if(t==null)return"â";try{return new Intl.NumberFormat("es-ES",{style:"currency",currency:l}).format(t/100)}catch{return`${(t/100).toFixed(2)} ${l}`}}function K(){const[t,l]=p.useState(""),[n,i]=p.useState(0),{data:r}=j({queryKey:["admin-appts-stats"],queryFn:async()=>{const{data:s}=await g.rpc("admin_appointments_stats");return(Array.isArray(s)?s[0]:s)??null}}),{data:o,isFetching:c}=j({queryKey:["admin-appts",t,n],queryFn:async()=>{const{data:s,error:a}=await g.rpc("admin_list_appointments",{_status:t||null,_limit:d,_offset:n*d});if(a)throw a;return s??[]}}),m=Number(o?.[0]?.total_count??0),x=Math.max(1,Math.ceil(m/d));return e.jsxs(N,{title:"Citas",children:[e.jsx("div",{className:"mb-4 grid grid-cols-3 gap-2 sm:grid-cols-6",children:[["Total",r?.total,"bg-primary/10 text-primary"],["Próximas",r?.upcoming,"bg-mint text-primary"],["Pendientes",r?.pending,"bg-amber-100 text-amber-800"],["Confirmadas",r?.confirmed,"bg-mint text-primary"],["Canceladas",r?.cancelled,"bg-red-100 text-red-700"],["Completadas",r?.completed,"bg-secondary text-foreground"]].map(([s,a,b])=>e.jsxs("div",{className:u("rounded-xl p-2 text-center",b),children:[e.jsx("p",{className:"text-lg font-semibold leading-none",children:a??"â"}),e.jsx("p",{className:"mt-1 text-[10px] uppercase tracking-wide opacity-80",children:s})]},s))}),e.jsx("div",{className:"mb-3 flex items-center gap-2",children:e.jsxs("select",{value:t,onChange:s=>{l(s.target.value),i(0)},className:"rounded-xl border border-border bg-background px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"Todos los estados"}),e.jsx("option",{value:"pending",children:"Pendientes"}),e.jsx("option",{value:"confirmed",children:"Confirmadas"}),e.jsx("option",{value:"cancelled",children:"Canceladas"}),e.jsx("option",{value:"completed",children:"Completadas"}),e.jsx("option",{value:"no_show",children:"No asistió"})]})}),e.jsx("div",{className:"overflow-x-auto rounded-2xl border border-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"Cuándo"}),e.jsx("th",{className:"px-3 py-2",children:"Negocio / servicio"}),e.jsx("th",{className:"px-3 py-2",children:"Cliente"}),e.jsx("th",{className:"px-3 py-2",children:"Mascota"}),e.jsx("th",{className:"px-3 py-2",children:"Precio"}),e.jsx("th",{className:"px-3 py-2",children:"Estado"}),e.jsx("th",{className:"px-3 py-2"})]})}),e.jsxs("tbody",{children:[(o??[]).map(s=>{const a=S[s.status]??{label:s.status,cls:"bg-muted text-muted-foreground"};return e.jsxs("tr",{className:"border-t border-border align-top",children:[e.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:C(new Date(s.starts_at),"d MMM yyyy · HH:mm",{locale:w})}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("p",{className:"font-medium",children:s.business_name??"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.service_name??"â"})]}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("p",{children:s.owner_name??"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.owner_email})]}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:s.pet_name??"â"}),e.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:P(s.price_estimate_cents,s.currency??"EUR")}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:u("rounded-full px-2 py-0.5 text-[10px] font-bold",a.cls),children:a.label})}),e.jsx("td",{className:"px-3 py-2 text-right",children:s.manage_url&&e.jsxs("a",{href:s.manage_url,target:"_blank",rel:"noopener",className:"inline-flex items-center gap-1 text-xs text-primary",children:[e.jsx(_,{className:"h-3.5 w-3.5"})," snify"]})})]},s.id)}),!c&&(o??[]).length===0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:7,className:"px-3 py-12 text-center text-sm text-muted-foreground",children:[e.jsx(v,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground
1/40"}),"Sin citas"]})})]})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-sm text-muted-foreground",children:[e.jsx("span",{children:c?e.jsx(f,{className:"inline h-4 w-4 animate-spin"}):`${m} citas`}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{variant:"outline",size:"sm",className:"rounded-xl",disabled:n===0,onClick:()=>i(s=>Math.max(0,s-1)),children:e.jsx(E,{className:"h-4 w-4"})}),e.jsxs("span",{children:[n+1," / ",x]}),e.jsx(h,{variant:"outline",size:"sm",className:"rounded-xl",disabled:n+1>=x,onClick:()=>i(s=>s+1),children:e.jsx(y,{className:"h-4 w-4"})})]})]})]})}export{K as component};
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.