import{_ as q,l as P,d as w,g as T,r as l,h as G,o as t,a as n,e as r,c as a,F as k,n as h,t as u,q as S,b as J,v as K,f as R,j as Q,p as x}from"./index-oOcXnyQ9.js";import{p as B,c as W}from"./modules-BhuCDmAi.js";import{C as X}from"./ClientLayout-C3WDU1OJ.js";import{L as H}from"./LoadingSpinner-C0J2L7A3.js";import{E as Y}from"./ErrorMessage-BMhxI1b9.js";const Z={key:2,class:"services-section"},ee={key:0,class:"category-label"},se={class:"services-row"},te=["onClick"],ae={class:"service-info"},oe={class:"service-meta"},le={key:0,class:"check"},ne={key:3,class:"title-sm"},re={key:4,class:"barbers-row"},ie=["onClick"],ce={class:"barber-avatar"},ue={class:"barber-name"},de={key:5,class:"title-sm"},ve={key:6,class:"date-time-section"},me=["min"],pe={key:0,class:"slots-wrap"},_e={key:0,class:"slots-loading"},ye={key:1,class:"no-slots"},fe={key:2,class:"time-grid"},ge=["onClick"],ke=["disabled"],he={key:8,class:"success-screen"},be={__name:"BookingView",setup(Ce){const A=l(1),_=l(!1),v=l(""),L=l([]),V=l([]),b=l([]),C=l(!1),i=l(null),d=l(null),c=l(""),f=l(""),g=l(!1),D=l(!1),E=x(()=>new Date().toISOString().split("T")[0]),I=x(()=>{const e={};for(const s of L.value){const m=s.category||"Otros";e[m]||(e[m]=[]),e[m].push(s)}return e}),M=x(()=>{if(!c.value)return"(Seleccionar fecha)";const e=new Date(c.value),s=new Date;return s.setHours(0,0,0,0),e.setHours(0,0,0,0),e.getTime()===s.getTime()?"(Hoy)":""}),$=e=>Number(e).toLocaleString("es-CR"),j=e=>e.split(" ").map(s=>s[0]).join("").substring(0,2).toUpperCase();P(z);async function z(){_.value=!0;try{const e=await B.getServices();L.value=e.data}catch{v.value="Error al cargar servicios"}finally{_.value=!1}}async function F(e){i.value=e,_.value=!0;try{const s=await B.getBarbers();V.value=s.data.filter(m=>m.services?.some(o=>o.id===e.id))}catch{v.value="Error al cargar barberos"}finally{_.value=!1}}function O(e){d.value=e,c.value=E.value,N()}async function N(){if(!(!c.value||!d.value||!i.value)){C.value=!0;try{const e=await B.getSlots(d.value.id,i.value.id,c.value);b.value=e.data}catch{v.value="Error al cargar horarios"}finally{C.value=!1}}}async function U(){g.value=!0,v.value="";try{await W.createAppointment({barber_id:d.value.id,service_id:i.value.id,appointment_date:c.value,start_time:f.value}),D.value=!0}catch(e){v.value=e.response?.data?.message||"Error al crear la reserva"}finally{g.value=!1}}return(e,s)=>{const m=G("router-link");return t(),w(X,null,{default:T(()=>[s[5]||(s[5]=n("h2",{style:{margin:"0 0 5px 0","font-size":"22px"}},"Nueva Reserva",-1)),v.value?(t(),w(Y,{key:0,message:v.value},null,8,["message"])):r("",!0),_.value?(t(),w(H,{key:1})):r("",!0),s[6]||(s[6]=n("div",{class:"title-sm"},"1. Servicio",-1)),A.value>=1?(t(),a("div",Z,[(t(!0),a(k,null,h(I.value,(o,y)=>(t(),a("div",{key:y,class:"category-group"},[y?(t(),a("div",ee,u(y),1)):r("",!0),n("div",se,[(t(!0),a(k,null,h(o,p=>(t(),a("div",{key:p.id,onClick:we=>F(p),class:S(["card service-card",{selected:i.value?.id===p.id}])},[n("div",ae,[n("strong",null,u(p.name),1),n("span",oe,u(p.duration_minutes)+" min • ₡"+u($(p.price)),1)]),i.value?.id===p.id?(t(),a("span",le,"✓")):r("",!0)],10,te))),128))])]))),128))])):r("",!0),i.value?(t(),a("div",ne,"2. Barbero")):r("",!0),i.value?(t(),a("div",re,[(t(!0),a(k,null,h(V.value,o=>(t(),a("div",{key:o.id,onClick:y=>O(o),class:S(["barber-item",{selected:d.value?.id===o.id}])},[n("div",ce,u(j(o.user.name)),1),n("span",ue,u(o.user.name.split(" ")[0]),1)],10,ie))),128))])):r("",!0),d.value?(t(),a("div",de,"3. Horario "+u(M.value),1)):r("",!0),d.value?(t(),a("div",ve,[J(n("input",{"onUpdate:modelValue":s[0]||(s[0]=o=>c.value=o),type:"date",min:E.value,onChange:N,class:"input-control date-input"},null,40,me),[[K,c.value]]),c.value?(t(),a("div",pe,[C.value?(t(),a("div",_e,[R(H)])):b.value.length===0?(t(),a("div",ye,"No hay horarios disponibles")):(t(),a("div",fe,[(t(!0),a(k,null,h(b.value,o=>(t(),a("button",{key:o,onClick:y=>f.value=o,class:S(["time-slot",{active:f.value===o}])},u(o),11,ge))),128))]))])):r("",!0)])):r("",!0),i.value&&d.value&&f.value?(t(),a("button",{key:7,onClick:U,disabled:g.value,class:"btn btn-gold",style:{"margin-top":"30px"}},u(g.value?"Reservando...":"Confirmar Reserva"),9,ke)):r("",!0),D.value?(t(),a("div",he,[s[2]||(s[2]=n("div",{class:"success-icon"},"✓",-1)),s[3]||(s[3]=n("h2",{class:"header-title"},"Reserva Confirmada",-1)),s[4]||(s[4]=n("p",{class:"success-text"},"Tu cita ha sido reservada exitosamente.",-1)),R(m,{to:"/client/inicio",class:"btn btn-outline",style:{display:"inline-block",width:"auto","text-decoration":"none"}},{default:T(()=>[...s[1]||(s[1]=[Q(" Ver mis citas ",-1)])]),_:1})])):r("",!0)]),_:1})}}},De=q(be,[["__scopeId","data-v-f59d825d"]]);export{De as default};
