(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[288],{3998:(e,t,a)=>{"use strict";a.d(t,{$:()=>o});var n=a(95155),s=a(49574),r=a(83101),i=a(64269);let l=(0,r.F)("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground [a]:hover:bg-primary/80",outline:"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",destructive:"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",xs:"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",lg:"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",icon:"size-8","icon-xs":"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg","icon-lg":"size-9"}},defaultVariants:{variant:"default",size:"default"}});function o(e){let{className:t,variant:a="default",size:r="default",...o}=e;return(0,n.jsx)(s.Button,{"data-slot":"button",className:(0,i.cn)(l({variant:a,size:r,className:t})),...o})}},11186:(e,t,a)=>{"use strict";a.d(t,{bq:()=>k,eb:()=>T,gC:()=>w,l6:()=>y,yv:()=>N});var n=a(95155);a(12115);var s=a(217),r=a(77261),i=a(98593),l=a(53769),o=a(27813),d=a(75828),c=a(17578),u=a(45423),m=a(34385),p=a(72276),x=a(9106),g=a(59569),f=a(26435),b=a(64269),h=a(23916),v=a(25352),j=a(57419);function y(e){let{value:t,onValueChange:a,defaultValue:r,children:i,...l}=e;return(0,n.jsx)(s.H,{value:t,defaultValue:r,onValueChange:e=>{if(a){var t;a(Array.isArray(e)?null!=(t=e[0])?t:null:e)}},...l,children:i})}function N(e){let{className:t,...a}=e;return(0,n.jsx)(r.y,{"data-slot":"select-value",className:(0,b.cn)("flex flex-1 text-left",t),...a})}function k(e){let{className:t,size:a="default",children:s,...r}=e;return(0,n.jsxs)(i.b,{"data-slot":"select-trigger","data-size":a,className:(0,b.cn)("flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r,children:[s,(0,n.jsx)(l.w,{render:(0,n.jsx)(h.A,{className:"pointer-events-none size-4 text-muted-foreground"})})]})}function w(e){let{className:t,children:a,side:s="bottom",sideOffset:r=4,align:i="center",alignOffset:l=0,alignItemWithTrigger:m=!0,...p}=e;return(0,n.jsx)(o.V,{children:(0,n.jsx)(d.l,{side:s,sideOffset:r,align:i,alignOffset:l,alignItemWithTrigger:m,className:"isolate z-50",children:(0,n.jsxs)(c.t,{"data-slot":"select-content","data-align-trigger":m,className:(0,b.cn)("relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",t),...p,children:[(0,n.jsx)(S,{}),(0,n.jsx)(u.B,{children:a}),(0,n.jsx)(z,{})]})})})}function T(e){let{className:t,children:a,...s}=e;return(0,n.jsxs)(m.e,{"data-slot":"select-item",className:(0,b.cn)("relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...s,children:[(0,n.jsx)(p.h,{className:"flex flex-1 shrink-0 gap-2 whitespace-nowrap",children:a}),(0,n.jsx)(x.h,{render:(0,n.jsx)("span",{className:"pointer-events-none absolute right-2 flex size-4 items-center justify-center"}),children:(0,n.jsx)(v.A,{className:"pointer-events-none"})})]})}function S(e){let{className:t,...a}=e;return(0,n.jsx)(g.w,{"data-slot":"select-scroll-up-button",className:(0,b.cn)("top-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",t),...a,children:(0,n.jsx)(j.A,{})})}function z(e){let{className:t,...a}=e;return(0,n.jsx)(f.d,{"data-slot":"select-scroll-down-button",className:(0,b.cn)("bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",t),...a,children:(0,n.jsx)(h.A,{})})}},13406:(e,t,a)=>{"use strict";a.d(t,{Tabs:()=>c,TabsContent:()=>x,TabsList:()=>m,TabsTrigger:()=>p});var n=a(95155),s=a(15499),r=a(11506),i=a(78598),l=a(92272),o=a(83101),d=a(64269);function c(e){let{className:t,orientation:a="horizontal",...r}=e;return(0,n.jsx)(s.p,{"data-slot":"tabs","data-orientation":a,className:(0,d.cn)("group/tabs flex gap-2 data-horizontal:flex-col",t),...r})}let u=(0,o.F)("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function m(e){let{className:t,variant:a="default",...s}=e;return(0,n.jsx)(r.j,{"data-slot":"tabs-list","data-variant":a,className:(0,d.cn)(u({variant:a}),t),...s})}function p(e){let{className:t,...a}=e;return(0,n.jsx)(i.M,{"data-slot":"tabs-trigger",className:(0,d.cn)("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent","data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",t),...a})}function x(e){let{className:t,...a}=e;return(0,n.jsx)(l.R,{"data-slot":"tabs-content",className:(0,d.cn)("flex-1 text-sm outline-none",t),...a})}},13502:(e,t,a)=>{Promise.resolve().then(a.bind(a,28103))},28103:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>L});var n=a(95155),s=a(12115),r=a(67909),i=a(983),l=a(31442),o=a(97081),d=a(86749),c=a(77650),u=a(59202),m=a(22544),p=a(66942),x=a(95154),g=a(18720),f=a(56531),b=a(14763),h=a(83410),v=a(69746),j=a(56978),y=a(27667),N=a(71163),k=a(93366),w=a(65828),T=a(47790),S=a(35056),z=a(89778),C=a(51834),_=a(3998),D=a(65142),I=a(76444),M=a(11186),V=a(13406);let A=x.Ik({dates:x.YO(x.p6()).min(1,"Selecciona al menos un d\xeda"),startTime:x.Yj().min(1,"Hora de inicio requerida"),endTime:x.Yj().min(1,"Hora de fin requerida"),blockType:x.k5(["surgery","admin","vacation","event"]),notes:x.Yj().optional()}).refine(e=>!e.startTime||!e.endTime||e.startTimee.patientId.length>0&&""!==e.patientId,{message:"Selecciona un paciente v\xe1lido",path:["patientId"]}).refine(e=>!e.startTime||!e.endTime||e.startTime(0,c.U)(),[]),l=(0,u.j)(e=>e.activeModal),o=(0,u.j)(e=>e.modalPayload),d=(0,u.j)(e=>e.closeModal),x="slotAction"===l,[q,H]=(0,s.useState)([]),[P,J]=(0,s.useState)([]),[G,Y]=(0,s.useState)(""),[E,B]=(0,s.useState)(!1),[L,F]=(0,s.useState)(new Date),[$,W]=(0,s.useState)(!1),U=(0,s.useMemo)(()=>{if(!o)return[];let{start:e,end:t}=o;if(!e||!t)return[];let a=(0,k.o)(new Date(e)),n=new Date((0,k.o)(new Date(t)).getTime()-864e5);if(n.getTime()<=a.getTime())return[a];let s=[],r=a;for(;r<=n;)s.push(new Date(r)),r=new Date(r.getTime()+864e5);return s},[o]),R=(0,s.useMemo)(()=>{if(!o)return"08:00";let{start:e}=o;if(!e)return"08:00";let t=(0,N.GP)(new Date(e),"HH:mm");return"00:00"===t?"08:00":t},[o]),X=(0,s.useMemo)(()=>{if(!o)return"09:00";let{end:e,start:t}=o;if(!e)return"09:00";let a=(0,N.GP)(new Date(e),"HH:mm");if("00:00"===a){let e=t?(0,N.GP)(new Date(t),"HH:mm"):"08:00";if("00:00"===e)return"09:00";let[a,n]=e.split(":").map(Number),s=60*a+n+60,r=Math.floor(s/60)%24;return"".concat(String(r).padStart(2,"0"),":").concat(String(s%60).padStart(2,"0"))}return a},[o]),Q=(0,m.mN)({resolver:(0,p.u)(A),defaultValues:{dates:U,startTime:R,endTime:X,blockType:"admin",notes:""}}),K=Q.watch("dates"),Z=Q.watch("startTime"),ee=Q.watch("endTime");(0,s.useEffect)(()=>{x&&((async()=>{let{data:e}=await i.from("procedures").select("id, name, duration_min").eq("is_active",!0).order("name");J(null!=e?e:[])})(),es.reset({patientSearch:"",patientId:"",procedureId:"",startTime:R,endTime:X,channel:"web"}),Q.reset({dates:U,startTime:R,endTime:X,blockType:"admin",notes:""}),Y(""),H([]),W(!1),U.length>0&&F(U[0]))},[x]);let et=(0,s.useRef)(null),ea=(0,s.useCallback)(async e=>{let t=e.trim();if(!t)return void H([]);B(!0);let a=t.replace(/[%_]/g,"\\$&"),{data:n}=await i.from("patients").select("id, name, phone").or("name.ilike.%".concat(a,"%,phone.ilike.%").concat(a,"%")).limit(5);H(null!=n?n:[]),B(!1)},[i]),en=(0,s.useCallback)(async e=>{let[t,a]=e.startTime.split(":").map(Number),[n,s]=e.endTime.split(":").map(Number),l=e.dates.map(r=>{let i=(0,T.g)((0,w.a)((0,k.o)(r),t),a),l=(0,T.g)((0,w.a)((0,k.o)(r),n),s);return{start_at:i.toISOString(),end_at:l.toISOString(),block_type:e.blockType,status:"blocked"}}),{error:o}=await i.from("slots").insert(l);if(o)return void g.o.error("Error al bloquear los espacios.");g.o.success("".concat(l.length," espacio(s) bloqueado(s): ").concat(e.blockType)),d(),null==r||r()},[d,r,i]),es=(0,m.mN)({resolver:(0,p.u)(O),defaultValues:{patientSearch:"",patientId:"",procedureId:"",startTime:R,endTime:X,channel:"web"},mode:"onChange"}),er=(0,s.useCallback)(async e=>{let{start:t}=o,a=(0,N.GP)(new Date(t),"yyyy-MM-dd"),[n,s]=e.startTime.split(":").map(Number),[l,c]=e.endTime.split(":").map(Number),u=new Date("".concat(a,"T").concat(String(n).padStart(2,"0"),":").concat(String(s).padStart(2,"0"),":00")),m=new Date("".concat(a,"T").concat(String(l).padStart(2,"0"),":").concat(String(c).padStart(2,"0"),":00")),{error:p}=await i.from("slots").insert({start_at:u.toISOString(),end_at:m.toISOString(),block_type:"appointment",patient_id:e.patientId,procedure_id:e.procedureId,status:"confirmed",channel:e.channel});if(p)return void g.o.error("Error al crear la cita.");g.o.success("Cita agendada correctamente."),d(),null==r||r()},[d,o,r,i]);return(0,n.jsx)(C.lG,{open:x,onOpenChange:e=>!e&&d(),children:(0,n.jsxs)(C.Cf,{className:"max-w-lg rounded-[18px]",children:[(0,n.jsx)(C.c7,{children:(0,n.jsx)(C.L3,{className:"font-heading text-lg font-semibold",children:"Acci\xf3n sobre el espacio"})}),(0,n.jsxs)(V.Tabs,{defaultValue:"appointment",className:"mt-2",children:[(0,n.jsxs)(V.TabsList,{className:"bg-muted/50 rounded-[12px] w-full",children:[(0,n.jsxs)(V.TabsTrigger,{value:"appointment",className:"flex-1 text-xs",children:[(0,n.jsx)(f.A,{className:"size-3 mr-1.5"}),"Agendar cita"]}),(0,n.jsxs)(V.TabsTrigger,{value:"block",className:"flex-1 text-xs",children:[(0,n.jsx)(b.A,{className:"size-3 mr-1.5"}),"Bloquear espacio"]})]}),(0,n.jsx)(V.TabsContent,{value:"appointment",className:"mt-4",children:(0,n.jsxs)("form",{onSubmit:es.handleSubmit(er),className:"space-y-4",children:[(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)(I.J,{className:"text-sm font-medium",children:"Paciente"}),(0,n.jsx)(D.p,{placeholder:"Buscar por nombre o tel\xe9fono…",value:G,onChange:e=>{let t=e.target.value;Y(t),es.setValue("patientSearch",t),et.current&&clearTimeout(et.current),et.current=setTimeout(()=>{ea(t)},300)}}),E&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:"Buscando…"}),q.length>0&&(0,n.jsx)("div",{className:"border border-border rounded-[12px] overflow-hidden",children:q.map(e=>(0,n.jsxs)("button",{type:"button",className:"w-full text-left px-3 py-2 text-sm hover:bg-muted/50 transition-colors border-b last:border-0 border-border/50",onClick:()=>{es.setValue("patientId",e.id,{shouldValidate:!0,shouldDirty:!0}),es.setValue("patientSearch",e.name,{shouldValidate:!0}),Y(e.name),H([])},children:[(0,n.jsx)("p",{className:"font-medium",children:e.name}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground",children:e.phone})]},e.id))}),es.formState.errors.patientId&&(0,n.jsx)("p",{className:"text-xs text-destructive",children:es.formState.errors.patientId.message})]}),(0,n.jsx)(m.xI,{control:es.control,name:"patientId",render:e=>{let{field:t}=e;return(0,n.jsx)("input",{type:"hidden",...t})}}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)(I.J,{className:"text-sm font-medium",children:"Procedimiento"}),(0,n.jsx)(m.xI,{control:es.control,name:"procedureId",render:e=>{let{field:t}=e;return(0,n.jsxs)(M.l6,{value:t.value,onValueChange:e=>t.onChange(null!=e?e:""),children:[(0,n.jsx)(M.bq,{className:"rounded-[12px]",children:(0,n.jsx)(M.yv,{placeholder:"Seleccionar procedimiento"})}),(0,n.jsx)(M.gC,{children:P.map(e=>(0,n.jsxs)(M.eb,{value:e.id,children:[e.name," (",e.duration_min," min)"]},e.id))})]})}})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsxs)(I.J,{className:"text-sm font-medium flex items-center gap-1.5",children:[(0,n.jsx)(h.A,{className:"size-3.5 text-muted-foreground"}),"Horario de la cita"]}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)(I.J,{className:"text-xs text-muted-foreground",children:"Hora inicio"}),(0,n.jsx)(D.p,{type:"time",value:null!=(t=es.watch("startTime"))?t:R,onChange:e=>es.setValue("startTime",e.target.value,{shouldValidate:!0,shouldDirty:!0}),className:"rounded-[12px] h-9 text-sm"})]}),(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)(I.J,{className:"text-xs text-muted-foreground",children:"Hora fin"}),(0,n.jsx)(D.p,{type:"time",value:null!=(a=es.watch("endTime"))?a:X,onChange:e=>es.setValue("endTime",e.target.value,{shouldValidate:!0,shouldDirty:!0}),className:"rounded-[12px] h-9 text-sm"})]})]}),es.formState.errors.startTime&&(0,n.jsx)("p",{className:"text-xs text-destructive",children:es.formState.errors.startTime.message}),es.formState.errors.endTime&&(0,n.jsx)("p",{className:"text-xs text-destructive",children:es.formState.errors.endTime.message})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)(I.J,{className:"text-sm font-medium",children:"Canal de origen"}),(0,n.jsx)(m.xI,{control:es.control,name:"channel",render:e=>{let{field:t}=e;return(0,n.jsxs)(M.l6,{value:t.value,onValueChange:e=>t.onChange(null!=e?e:"web"),children:[(0,n.jsx)(M.bq,{className:"rounded-[12px]",children:(0,n.jsx)(M.yv,{})}),(0,n.jsx)(M.gC,{children:["whatsapp","messenger","instagram","web","tiktok","manual"].map(e=>(0,n.jsx)(M.eb,{value:e,className:"capitalize",children:e},e))})]})}})]}),(0,n.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,n.jsx)(_.$,{type:"button",variant:"outline",className:"flex-1 rounded-[12px]",onClick:d,children:"Cancelar"}),(0,n.jsx)(_.$,{type:"submit",className:"flex-1 bg-primary text-[#0D141D] font-semibold rounded-[12px] hover:bg-primary/90",disabled:es.formState.isSubmitting,children:es.formState.isSubmitting?(0,n.jsx)(v.A,{className:"size-4 animate-spin"}):"Confirmar cita"})]})]})}),(0,n.jsx)(V.TabsContent,{value:"block",className:"mt-4",children:(0,n.jsxs)("form",{onSubmit:Q.handleSubmit(en),className:"space-y-4",children:[(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsxs)(I.J,{className:"text-sm font-medium flex items-center gap-1.5",children:[(0,n.jsx)(j.A,{className:"size-3.5 text-muted-foreground"}),"D\xedas a bloquear"]}),K&&K.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[...K].sort((e,t)=>e.getTime()-t.getTime()).map((e,t)=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-[8px] bg-muted text-xs font-medium",children:[(0,N.GP)(e,"d MMM",{locale:S.es}),(0,n.jsx)("button",{type:"button",onClick:()=>(e=>{let t=Q.getValues("dates");Q.setValue("dates",t.filter(t=>t.toDateString()!==e.toDateString()),{shouldValidate:!0,shouldDirty:!0})})(e),className:"text-muted-foreground hover:text-destructive transition-colors",children:(0,n.jsx)(y.A,{className:"size-3"})})]},t))}),(0,n.jsxs)(_.$,{type:"button",variant:"outline",size:"sm",className:"w-full rounded-[12px] text-xs h-8",onClick:()=>W(!$),children:[(0,n.jsx)(j.A,{className:"size-3.5 mr-1.5"}),$?"Ocultar calendario":"Seleccionar d\xedas"]}),$&&(0,n.jsx)("div",{className:"flex justify-center border border-border rounded-[12px] bg-background mt-1",children:(0,n.jsx)(z.h,{mode:"multiple",selected:null!=K?K:[],onSelect:e=>{Q.setValue("dates",null!=e?e:[],{shouldValidate:!0,shouldDirty:!0})},month:L,onMonthChange:F,locale:S.es,showOutsideDays:!1,disabled:{before:new Date},classNames:{root:"p-3",months:"flex flex-col gap-3",month:"flex flex-col gap-3",nav:"absolute inset-x-0 top-0 flex items-center justify-between gap-1 p-2",month_caption:"flex justify-center h-8 items-center font-medium text-sm",weekdays:"flex",weekday:"flex-1 text-[0.7rem] font-normal text-muted-foreground text-center",week:"flex w-full mt-1",day:"flex-1 aspect-square text-center p-0 [&:first-child>button]:rounded-l-[8px] [&:last-child>button]:rounded-r-[8px]",day_button:"size-full rounded-[8px] text-xs hover:bg-muted transition-colors border-0 bg-transparent",selected:"bg-primary text-primary-foreground rounded-[8px] hover:bg-primary/90",today:"font-bold bg-muted/50",outside:"text-muted-foreground/40",disabled:"text-muted-foreground/30",chevron:"size-4"}})}),Q.formState.errors.dates&&(0,n.jsx)("p",{className:"text-xs text-destructive",children:Q.formState.errors.dates.message})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsxs)(I.J,{className:"text-sm font-medium flex items-center gap-1.5",children:[(0,n.jsx)(h.A,{className:"size-3.5 text-muted-foreground"}),"Horario del bloqueo"]}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)(I.J,{className:"text-xs text-muted-foreground",children:"Hora inicio"}),(0,n.jsx)(D.p,{type:"time",value:null!=Z?Z:"09:00",onChange:e=>Q.setValue("startTime",e.target.value,{shouldValidate:!0,shouldDirty:!0}),className:"rounded-[12px] h-9 text-sm"})]}),(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)(I.J,{className:"text-xs text-muted-foreground",children:"Hora fin"}),(0,n.jsx)(D.p,{type:"time",value:null!=ee?ee:"09:30",onChange:e=>Q.setValue("endTime",e.target.value,{shouldValidate:!0,shouldDirty:!0}),className:"rounded-[12px] h-9 text-sm"})]})]}),Q.formState.errors.startTime&&(0,n.jsx)("p",{className:"text-xs text-destructive",children:Q.formState.errors.startTime.message}),Q.formState.errors.endTime&&(0,n.jsx)("p",{className:"text-xs text-destructive",children:Q.formState.errors.endTime.message})]}),K&&K.length>0&&Z&&ee&&(0,n.jsxs)("div",{className:"rounded-[12px] bg-muted/50 p-3 text-xs text-muted-foreground space-y-0.5",children:[(0,n.jsxs)("p",{children:[(0,n.jsx)("span",{className:"font-medium text-foreground",children:K.length})," d\xeda(s) seleccionados"]}),(0,n.jsxs)("p",{children:["Bloque de ",(0,n.jsx)("span",{className:"font-medium text-foreground",children:Z})," a"," ",(0,n.jsx)("span",{className:"font-medium text-foreground",children:ee})]})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)(I.J,{className:"text-sm font-medium",children:"Tipo de bloqueo"}),(0,n.jsx)(m.xI,{control:Q.control,name:"blockType",render:e=>{let{field:t}=e;return(0,n.jsxs)(M.l6,{value:t.value,onValueChange:e=>t.onChange(null!=e?e:"admin"),children:[(0,n.jsx)(M.bq,{className:"rounded-[12px]",children:(0,n.jsx)(M.yv,{})}),(0,n.jsxs)(M.gC,{children:[(0,n.jsx)(M.eb,{value:"surgery",children:"\uD83D\uDD2A Cirug\xeda"}),(0,n.jsx)(M.eb,{value:"admin",children:"\uD83D\uDCCB Administrativo"}),(0,n.jsx)(M.eb,{value:"vacation",children:"\uD83C\uDFD6️ Vacaciones"}),(0,n.jsx)(M.eb,{value:"event",children:"\uD83C\uDFAF Evento"})]})]})}})]}),(0,n.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,n.jsx)(_.$,{type:"button",variant:"outline",className:"flex-1 rounded-[12px]",onClick:d,children:"Cancelar"}),(0,n.jsx)(_.$,{type:"submit",className:"flex-1 bg-primary text-[#0D141D] font-semibold rounded-[12px] hover:bg-primary/90",disabled:Q.formState.isSubmitting,children:Q.formState.isSubmitting?(0,n.jsx)(v.A,{className:"size-4 animate-spin"}):"Bloquear espacio"})]})]})})]})]})})}let H=(0,r.default)(()=>a.e(6385).then(a.bind(a,36385)),{loadableGenerated:{webpack:()=>[null]},ssr:!1}),P={sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},J=[i.A,l.A,o.Ay],G={left:"prev,next today",center:"title",right:"dayGridMonth,timeGridWeek,timeGridDay"},Y={prev:"<",next:">"},E={confirmed:"#10b981",reschedule:"#f59e0b",cancelled:"#ef4444",completed:"#6b7280"},B={surgery:"#6366f1",admin:"#8b5cf6",vacation:"#ec4899",event:"#f97316"};function L(){let e=(0,s.useMemo)(()=>(0,c.U)(),[]),[t,a]=(0,s.useState)([]),[r,i]=(0,s.useState)(null),[l,o]=(0,s.useState)(!0),m=(0,u.j)(e=>e.openModal),{slotMinTime:p,slotMaxTime:x,businessHours:g}=(0,s.useMemo)(()=>(function(e){let t=e&&Object.keys(e).length>0?e:{mon:["08:00","18:00"],tue:["08:00","18:00"],wed:["08:00","18:00"],thu:["08:00","18:00"],fri:["08:00","18:00"],sat:["08:00","13:00"],sun:null},a=[],n="23:59",s="00:00";for(let[e,r]of Object.entries(t)){if(!r)continue;let t=P[e];if(void 0===t)continue;let[i,l]=r;a.push({daysOfWeek:[t],startTime:i,endTime:l}),is&&(s=l)}return{slotMinTime:"".concat(n,":00"),slotMaxTime:"".concat(s,":00"),businessHours:a}})(r),[r]);(0,s.useEffect)(()=>{(async()=>{let{data:t}=await e.from("agent_config").select("working_hours").single();(null==t?void 0:t.working_hours)&&i(t.working_hours)})()},[e]);let f=(0,s.useCallback)(async()=>{let t=new Date,n=new Date(t.getFullYear(),t.getMonth()-3,1),s=new Date(t.getFullYear(),t.getMonth()+4,0),[{data:r},{data:i}]=await Promise.all([e.from("slots").select("id, start_at, end_at, block_type").neq("block_type","appointment").gte("start_at",n.toISOString()).lte("start_at",s.toISOString()).limit(500),e.from("slots").select("id, start_at, end_at, status, channel, notes, patient:patients(name), procedure:procedures(name)").eq("block_type","appointment").in("status",["pending","confirmed","completed"]).order("created_at",{ascending:!1}).limit(200)]);a([...(null!=r?r:[]).map(e=>{var t;return{id:"slot-".concat(e.id),title:e.block_type?"\uD83D\uDD12 ".concat(e.block_type):"Bloqueado",start:e.start_at,end:e.end_at,backgroundColor:null!=(t=B[e.block_type])?t:"#8b5cf6",borderColor:"transparent",textColor:"#fff",extendedProps:{type:"slot",slotId:e.id}}}),...(null!=i?i:[]).map(e=>{var t,a,n,s,r;return{id:"appt-".concat(e.id),title:"".concat(null!=(n=null==(t=e.patient)?void 0:t.name)?n:"Paciente"," \xb7 ").concat(null!=(s=null==(a=e.procedure)?void 0:a.name)?s:"Consulta"),start:e.start_at,end:e.end_at,backgroundColor:null!=(r=E[e.status])?r:"#6b7280",borderColor:"transparent",textColor:"#fff",extendedProps:{type:"appointment",appointment:e}}})]),o(!1)},[e]);(0,s.useEffect)(()=>{f()},[]),(0,s.useEffect)(()=>{let t=e.channel("calendar-realtime").on("postgres_changes",{event:"*",schema:"public",table:"slots",filter:"block_type=neq.null"},()=>{f()}).subscribe();return()=>{e.removeChannel(t)}},[f,e]);let b=(0,s.useCallback)(e=>{m("slotAction",{start:e.startStr,end:e.endStr})},[m]),h=(0,s.useCallback)(e=>{let{type:t,appointment:a}=e.event.extendedProps;"appointment"===t&&m("appointmentDetail",{appointment:a})},[m]);return(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"font-heading font-bold text-2xl text-foreground",children:"Agenda Cl\xednica"}),(0,n.jsx)("p",{className:"text-muted-foreground text-sm mt-1",children:"Gestiona citas, bloqueos y disponibilidad en tiempo real"})]}),(0,n.jsx)("div",{className:"bg-card rounded-[18px] border border-border p-4 shadow-sm overflow-hidden",children:0===t.length&&l?(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)(v.A,{className:"size-6 animate-spin"})}):(0,n.jsx)(H,{plugins:J,initialView:"timeGridWeek",locale:d.A,headerToolbar:G,buttonText:Y,events:t,selectable:!0,selectMirror:!0,select:b,eventClick:h,height:"calc(100vh - 280px)",slotMinTime:p,slotMaxTime:x,slotDuration:"01:00:00",slotLabelInterval:"01:00",businessHours:g,allDaySlot:!1,nowIndicator:!0,eventDisplay:"block",dayMaxEvents:3})}),(0,n.jsx)(q,{onSuccess:f})]})}},51834:(e,t,a)=>{"use strict";a.d(t,{Cf:()=>b,L3:()=>v,c7:()=>h,lG:()=>x,rr:()=>j});var n=a(95155);a(12115);var s=a(68422),r=a(87263),i=a(54915),l=a(23737),o=a(58905),d=a(50989),c=a(48893),u=a(64269),m=a(3998),p=a(34788);function x(e){let{...t}=e;return(0,n.jsx)(s.D,{"data-slot":"dialog",...t})}function g(e){let{...t}=e;return(0,n.jsx)(r.Z,{"data-slot":"dialog-portal",...t})}function f(e){let{className:t,...a}=e;return(0,n.jsx)(i.X,{"data-slot":"dialog-overlay",className:(0,u.cn)("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",t),...a})}function b(e){let{className:t,children:a,showCloseButton:s=!0,...r}=e;return(0,n.jsxs)(g,{children:[(0,n.jsx)(f,{}),(0,n.jsxs)(l.h,{"data-slot":"dialog-content",className:(0,u.cn)("fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",t),...r,children:[a,s&&(0,n.jsxs)(o.H,{"data-slot":"dialog-close",render:(0,n.jsx)(m.$,{variant:"ghost",className:"absolute top-2 right-2",size:"icon-sm"}),children:[(0,n.jsx)(p.A,{}),(0,n.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function h(e){let{className:t,...a}=e;return(0,n.jsx)("div",{"data-slot":"dialog-header",className:(0,u.cn)("flex flex-col gap-2",t),...a})}function v(e){let{className:t,...a}=e;return(0,n.jsx)(d.L,{"data-slot":"dialog-title",className:(0,u.cn)("font-heading text-base leading-none font-medium",t),...a})}function j(e){let{className:t,...a}=e;return(0,n.jsx)(c.r,{"data-slot":"dialog-description",className:(0,u.cn)("text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",t),...a})}},59202:(e,t,a)=>{"use strict";a.d(t,{j:()=>r});var n=a(25959),s=a(89863);let r=(0,n.v)()((0,s.lt)(e=>({sidebarOpen:!0,activeModal:null,modalPayload:null,setSidebarOpen:t=>e({sidebarOpen:t},!1,"ui/setSidebarOpen"),toggleSidebar:()=>e(e=>({sidebarOpen:!e.sidebarOpen}),!1,"ui/toggleSidebar"),openModal:function(t){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e({activeModal:t,modalPayload:a},!1,"ui/openModal")},closeModal:()=>e({activeModal:null,modalPayload:null},!1,"ui/closeModal")}),{name:"UIStore",enabled:!1}))},64269:(e,t,a)=>{"use strict";a.d(t,{cn:()=>r});var n=a(2821),s=a(75889);function r(){for(var e=arguments.length,t=Array(e),a=0;a{"use strict";a.d(t,{p:()=>i});var n=a(95155);a(12115);var s=a(50092),r=a(64269);function i(e){let{className:t,type:a,...i}=e;return(0,n.jsx)(s.p,{type:a,"data-slot":"input",className:(0,r.cn)("h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",t),...i})}},76444:(e,t,a)=>{"use strict";a.d(t,{J:()=>r});var n=a(95155);a(12115);var s=a(64269);function r(e){let{className:t,...a}=e;return(0,n.jsx)("label",{"data-slot":"label",className:(0,s.cn)("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...a})}},77650:(e,t,a)=>{"use strict";a.d(t,{U:()=>s});var n=a(79786);function s(){return(0,n.createBrowserClient)("https://supabase.silvioalzate.shop","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNzc5MTYzNDQ1LCJleHAiOjE5MzY4NDM0NDV9.RGVwyQdA7oigXmMylP2Df7DKpNno_8_rSTwd0471zLk")}}},e=>{e.O(0,[5730,6018,7711,7349,9574,3540,8720,7958,3652,8814,5922,778,8548,533,3395,4352,8441,1255,7358],()=>e(e.s=13502)),_N_E=e.O()}]);