import{_ as T,a as F,y as R,f as y,i as q,I as z,J as _,E as k,x as g,r as v,G as M,o as n,b as t,g as m,c as r,t as i,F as S,l as $,s as j}from"./index-BmPrhdN5.js";import{A as G}from"./AdminLayout-oZ8qR84B.js";import{B as H}from"./BarberLayout-HFrZtaEE.js";import{L as J}from"./LoadingSpinner-B_fmRZ4T.js";import{E as W}from"./ErrorMessage-Yfj_sPug.js";import"./LogoutButton-DYQ5NjCX.js";const K={class:"inbox-page"},O={class:"inbox-header"},Q=["disabled"],U={key:2,class:"flash-ok"},X={key:3,class:"flash-err"},Y={key:4,class:"card empty-inbox"},Z={class:"inbox-toolbar card"},ee={class:"select-all"},ae=["checked"],te={class:"toolbar-actions"},se=["disabled"],ne=["disabled"],le={class:"card table-wrap"},oe={class:"table inbox-table"},ie={key:0},re={class:"col-check"},ue=["checked","onChange"],ce={key:0},de={__name:"PendingInboxView",setup(ve){const w=M(),C=F(),u=g(()=>w.path.startsWith("/admin/")),A=g(()=>u.value?G:H),L=g(()=>C.staffLabelSingular),f=v(!0),p=v(""),l=v([]),s=v([]),h=v(!1),c=v(""),d=v(""),E=g(()=>l.value.length?l.value.every(a=>s.value.includes(a.id)):!1);function I(a){if(!a)return"";const e=String(a);return e.length>=5?e.slice(0,5):e}function B(a){return a?new Date(`${String(a).slice(0,10)}T12:00:00`).toLocaleDateString("es-ES",{weekday:"short",day:"numeric",month:"short"}):""}function V(a){const e=new Set(s.value);e.has(a)?e.delete(a):e.add(a),s.value=[...e]}function D(a){a.target.checked?s.value=l.value.map(e=>e.id):s.value=[]}async function b(){f.value=!0,p.value="",d.value="",c.value="";try{const a=u.value?_:k,{data:e}=await a.getPendingInbox();l.value=Array.isArray(e)?e:[],s.value=s.value.filter(o=>l.value.some(x=>x.id===o))}catch(a){p.value=a.response?.data?.message||a.message||"No se pudo cargar la bandeja.",l.value=[]}finally{f.value=!1}}async function N(){if(s.value.length){c.value="",d.value="",h.value=!0;try{const a=u.value?_:k,{data:e}=await a.confirmInboxAppointments({ids:s.value});d.value=e?.message||"Listo.",s.value=[],await b()}catch(a){c.value=a.response?.data?.message||a.message||"Error al confirmar."}finally{h.value=!1}}}async function P(){if(window.confirm("¿Confirmar todas las citas pendientes de la lista? Si hay muchas, puede tardar un momento.")){c.value="",d.value="",h.value=!0;try{const a=u.value?_:k,{data:e}=await a.confirmInboxAppointments({all:!0});d.value=e?.message||"Listo.",s.value=[],await b()}catch(a){c.value=a.response?.data?.message||a.message||"Error al confirmar."}finally{h.value=!1}}}return R(u,()=>{s.value=[],b()}),b(),(a,e)=>(n(),y(z(A.value),null,{default:q(()=>[t("div",K,[t("div",O,[e[0]||(e[0]=t("div",null,[t("h2",{style:{margin:"0 0 6px 0","font-size":"20px"}},"Por confirmar"),t("p",{class:"inbox-lead"}," Reservas web en estado pendiente. Podés confirmar todas, o solo las que marques. ")],-1)),t("button",{type:"button",class:"btn btn-outline btn-sm",disabled:f.value,onClick:b}," Actualizar ",8,Q)]),f.value?(n(),y(J,{key:0})):m("",!0),p.value?(n(),y(W,{key:1,message:p.value},null,8,["message"])):m("",!0),d.value?(n(),r("p",U,i(d.value),1)):m("",!0),c.value?(n(),r("p",X,i(c.value),1)):m("",!0),!f.value&&l.value.length===0?(n(),r("div",Y,[...e[1]||(e[1]=[t("p",{style:{margin:"0"}},"No hay citas pendientes de confirmación.",-1)])])):!f.value&&l.value.length>0?(n(),r(S,{key:5},[t("div",Z,[t("label",ee,[t("input",{type:"checkbox",checked:E.value,onChange:D},null,40,ae),$(" Seleccionar todas ("+i(l.value.length)+") ",1)]),t("div",te,[t("button",{type:"button",class:"btn btn-gold",disabled:h.value||s.value.length===0,onClick:N}," Confirmar selección ("+i(s.value.length)+") ",9,se),t("button",{type:"button",class:"btn btn-outline",disabled:h.value,onClick:P}," Confirmar todas ",8,ne)])]),t("div",le,[t("table",oe,[t("thead",null,[t("tr",null,[e[2]||(e[2]=t("th",{class:"col-check","aria-label":"Seleccionar"},null,-1)),e[3]||(e[3]=t("th",null,"Fecha",-1)),e[4]||(e[4]=t("th",null,"Hora",-1)),e[5]||(e[5]=t("th",null,"Cliente",-1)),e[6]||(e[6]=t("th",null,"Servicio",-1)),u.value?(n(),r("th",ie,i(L.value),1)):m("",!0)])]),t("tbody",null,[(n(!0),r(S,null,j(l.value,o=>(n(),r("tr",{key:o.id},[t("td",re,[t("input",{type:"checkbox",checked:s.value.includes(o.id),onChange:x=>V(o.id)},null,40,ue)]),t("td",null,i(B(o.appointment_date)),1),t("td",null,i(I(o.start_time)),1),t("td",null,i(o.client?.name||"—"),1),t("td",null,i(o.service?.name||"—"),1),u.value?(n(),r("td",ce,i(o.barber?.user?.name||"—"),1)):m("",!0)]))),128))])])])],64)):m("",!0)])]),_:1}))}},ye=T(de,[["__scopeId","data-v-25f74dea"]]);export{ye as default};
