import{a0 as f,G as j,X as x,Q as N,w as e,D as v,C as b,t as C}from"./index-DDBPimHe.js";import{u}from"./useSuspenseQuery-BKRXugiP.js";import{A as y}from"./AppShell-EiEJ9r2t.js";import{E as w,b as P,c as D,f as E,g as M,L as o,I as d,T as Q,e as z,B as g,P as S}from"./textarea-eiWe3vmx.js";import{M as k,P as F}from"./phone-Ce61GH73.js";import{M as T}from"./map-pin-DXuI6B8e.js";import"./package-DE0SpHx9.js";import"./wrench-ep8n-Rsp.js";const h={nombre:"",email:"",telefono:"",direccion:"",notas:""};function I({open:t,onOpenChange:n}){const m=f(),[s,a]=j.useState(h),r=l=>c=>a(p=>({...p,[l]:c.target.value})),i=w({mutationFn:async()=>{if(!s.nombre.trim())throw new Error("El nombre es obligatorio");const l={nombre:s.nombre.trim(),email:s.email.trim()||null,telefono:s.telefono.trim()||null,direccion:s.direccion.trim()||null,notas:s.notas.trim()||null},{error:c}=await N.from("clientes_particulares").insert(l);if(c)throw c},onSuccess:()=>{x.success("Cliente creado"),m.invalidateQueries({queryKey:["particulares"]}),a(h),n(!1)},onError:l=>x.error(l.message??"Error al crear")});return e.jsx(P,{open:t,onOpenChange:n,children:e.jsxs(D,{className:"max-w-lg",children:[e.jsx(E,{children:e.jsx(M,{children:"Nuevo Cliente Particular"})}),e.jsxs("div",{className:"grid gap-3 py-2",children:[e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Nombre *"}),e.jsx(d,{value:s.nombre,onChange:r("nombre"),autoFocus:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Email"}),e.jsx(d,{type:"email",value:s.email,onChange:r("email")})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Teléfono"}),e.jsx(d,{value:s.telefono,onChange:r("telefono")})]})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Dirección"}),e.jsx(d,{value:s.direccion,onChange:r("direccion")})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Notas"}),e.jsx(Q,{rows:3,value:s.notas,onChange:r("notas")})]})]}),e.jsxs(z,{children:[e.jsx(g,{variant:"outline",onClick:()=>n(!1),disabled:i.isPending,children:"Cancelar"}),e.jsx(g,{onClick:()=>i.mutate(),disabled:i.isPending,children:i.isPending?"Creando...":"Crear"})]})]})})}function K(){const{data:t}=u(v()),{data:n}=u(b()),[m,s]=j.useState(!1);return e.jsx(y,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(I,{open:m,onOpenChange:s}),e.jsxs("div",{className:"flex items-end justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-widest text-muted-foreground font-mono",children:"Micro · On-demand"}),e.jsx("h1",{className:"text-3xl font-bold mt-1",children:"Clientes Particulares"}),e.jsxs("p",{className:"text-muted-foreground mt-1",children:[t.length," clientes registrados"]})]}),e.jsxs("button",{onClick:()=>s(!0),className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-md gradient-primary text-primary-foreground font-medium text-sm shadow-elevated",children:[e.jsx(S,{className:"size-4"})," Nuevo Cliente"]})]}),t.length===0&&e.jsx("div",{className:"bg-card border border-border rounded-xl p-10 text-center text-sm text-muted-foreground",children:"No hay clientes particulares cargados."}),e.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-4",children:t.map(a=>{const r=n.filter(i=>i.cliente_particular_id===a.id).length;return e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-12 rounded-full bg-accent text-accent-foreground grid place-items-center font-bold",children:C(a.nombre)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold truncate",children:a.nombre}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[r," servicios históricos"]})]})]}),e.jsxs("div",{className:"mt-4 space-y-1.5 text-xs text-muted-foreground",children:[a.email&&e.jsxs("div",{className:"inline-flex items-center gap-2",children:[e.jsx(k,{className:"size-3.5"})," ",a.email]}),a.telefono&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"size-3.5"})," ",a.telefono]}),a.direccion&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(T,{className:"size-3.5 mt-0.5"})," ",e.jsx("span",{children:a.direccion})]})]})]},a.id)})})]})})}export{K as component};
