1import{k as o,j as t}from"./vendor-Dfxs0MA2.js";import{s as g,t as M}from"./index-5f6L9I3c.js";const O=["Dom","Lun","Mar","Mié","Jue","Vie","Sáb"],k=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];function b(a){return a==="arrived"||a==="completed"?"#22c55e":a==="no_show"?"#ef4444":a==="cancelled"?"#71717a":a==="confirmed"?"#3b82f6":a==="arrived_pending_confirm"?"#f59e0b":"#a855f7"}function P(a){return a==="arrived"?"Llegó":a==="completed"?"Completada":a==="no_show"?"No llegó":a==="cancelled"?"Cancelada":a==="confirmed"?"Confirmada":a==="arrived_pending_confirm"?"¿Llegó?":"Pendiente"}const h=a=>`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,"0")}-${String(a.getDate()).padStart(2,"0")}`;function U({onClose:a}){const[c,_]=o.useState([]),[z,f]=o.useState(!0),[s,v]=o.useState(()=>{const e=new Date;return e.setDate(1),e.setHours(0,0,0,0),e}),[x,T]=o.useState(()=>h(new Date)),[p,F]=o.useState(null),[I,j]=o.useState(!1),[m,A]=o.useState(!1);o.useEffect(()=>{(async()=>{if(!g){f(!1);return}const{data:e}=await g.auth.getUser();if(!e.user){f(!1);return}const[{data:r},{data:i}]=await Promise.all([g.from("appointments").select("*, prospect:prospects(name, phone, vehicle, purchased_at)").eq("user_id",e.user.id).order("scheduled_at"),g.from("profiles").select("calendar_token").eq("id",e.user.id).maybeSingle()]);_(r||[]);const n=i==null?void 0:i.calendar_token;n&&F(`https://lywlurmaxbdokqmkfuuj.supabase.co/functions/v1/calendar-feed?t=${n}`),f(!1)})()},[]);const S=o.useMemo(()=>{const e=new Map;for(const r of c){const i=new Date(r.scheduled_at),n=h(i),d=e.get(n);d?d.push(r):e.set(n,[r])}return e},[c]),W=o.useMemo(()=>{const e=new Date(s);return e.setDate(1-s.getDay()),Array.from({length:42},(r,i)=>{const n=new Date(e);return n.setDate(e.getDate()+i),n})},[s]),w=h(new Date),y=(S.get(x)??[]).slice().sort((e,r)=>e.scheduled_at.localeCompare(r.scheduled_at)),C=y.filter(e=>e.status==="cancelled").length,u=m?y:y.filter(e=>e.status!=="cancelled"),$=o.useMemo(()=>c.filter(e=>{const r=new Date(e.scheduled_at);return r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth()}),[c,s]),N=new Set(["arrived_pending_confirm","arrived","completed"]),B=Date.now(),l=$.filter(e=>new Date(e.scheduled_at).getTime()<B&&e.status!=="cancelled"),E=l.filter(e=>N.has(e.status)).length,R=new Set(l.filter(e=>{var r;return e.purchase_verdict!=="not_bought"&&(e.purchase_verdict==="bought"||e.status==="completed"&&((r=e.prospect)==null?void 0:r.purchased_at))}).map(e=>e.prospect_id).filter(Boolean)).size,Y=l.filter(e=>e.status==="no_show").length;function L(){var e;p&&((e=navigator.clipboard)==null||e.writeText(p).then(()=>{j(!0),setTimeout(()=>j(!1),2500)},()=>{}))}return t.jsx("div",{className:"mask",onClick:a,children:t.jsxs("div",{className:"modal-card",onClick:e=>e.stopPropagation(),style:{maxWidth:760,width:"96vw"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10},children:[t.jsx("h2",{className:"modal-h",style:{margin:0},children:"ð
Calendario de citas"}),t.jsx("button",{onClick:a,style:{background:"transparent",border:"none",color:"var(--text-tertiary)",fontSize:22,cursor:"pointer"},children:"Ã"})]}),z?t.jsx("div",{style:{padding:24,textAlign:"center",color:"var(--text-tertiary)"},children:"Cargando tus citasâ¦"}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:8},children:[t.jsx("button",{className:"btn btn-ghost",onClick:()=>v(new Date(s.getFullYear(),s.getMonth()-1,1)),children:"â¹"}),t.jsxs("strong",{style:{fontSize:15},children:[k[s.getMonth()]," ",s.getFullYear()]}),t.jsx("button",{className:"btn btn-ghost",onClick:()=>v(new Date(s.getFullYear(),s.getMonth()+1,1)),children:"âº"})]}),l.length>0&&t.jsxs("div",{style:{display:"flex",gap:14,flexWrap:"wrap",marginBottom:10,padding:"8px 12px",background:"var(--bg-elevated, rgba(255,255,255,.03))",border:"1px solid var(--border-default, rgba(255,255,255,.08))",borderRadius:10,fontSize:12.5},children:[t.jsxs("span",{children:[t.jsx("strong",{children:l.length})," citas de ",k[s.getMonth()]]}),t.jsxs("span",{style:{color:"#22c55e"},children:[t.jsx("strong",{children:E})," llegaron"]}),t.jsxs("span",{style:{color:"var(--accent, #c2410c)"},children:[t.jsx("strong",{children:R})," compraron"]}),t.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[t.jsx("strong",{children:Y})," no llegaron"]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(7, 1fr)",gap:3},children:[O.map(e=>t.jsx("div",{style:{textAlign:"center",fontSize:10.5,color:"var(--text-tertiary)",padding:"2px 0"},children:e},e)),W.map(e=>{const r=h(e),i=e.getMonth()===s.getMonth(),n=S.get(r)??[],d=r===x;return t.jsxs("button",{type:"button",onClick:()=>T(r),style:{minHeight:54,padding:"4px 3px",borderRadius:8,cursor:"pointer",fontFamily:"inherit",background:d?"var(--accent, #c2410c)":"var(--bg-elevated, rgba(255,255,255,.03))",border:`1px solid ${r===w?"var(--accent, #c2410c)":"var(--border-default, rgba(255,255,255,.08))"}`,opacity:i?1:.35,color:d?"#fff":"inherit",display:"flex",flexDirection:"column",alignItems:"center",gap:3},children:[t.jsx("span",{style:{fontSize:12,fontWeight:r===w?800:500},children:e.getDate()}),t.jsxs("span",{style:{display:"flex",gap:2,flexWrap:"wrap",justifyContent:"center"},children:[n.slice(0,4).map(D=>t.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:b(D.status)}},D.id)),n.length>4&&t.jsxs("span",{style:{fontSize:9},children:["+",n.length-4]})]})]},r)})]}),t.jsxs("div",{style:{marginTop:12,borderTop:"1px solid var(--border-default, rgba(255,255,255,.08))",paddingTop:10},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:6},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700},children:u.length?`${u.length} cita${u.length>
11?"s":""} el ${x.split("-").reverse().join("/")}`:"Sin citas ese dÃa"}),C>0&&t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11,color:"var(--text-tertiary)",cursor:"pointer"},children:[t.jsx("input",{type:"checkbox",checked:m,onChange:e=>A(e.target.checked)}),m?M("calendar.hideCancelled"):M("calendar.viewCancelled",{count:C})]})]}),t.jsx("div",{style:{display:"grid",gap:6,maxHeight:190,overflowY:"auto"},children:u.map(e=>{var i,n;const r=new Date(e.scheduled_at);return t.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",padding:"7px 10px",borderRadius:8,background:"var(--bg-elevated, rgba(255,255,255,.03))"},children:[t.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:b(e.status),flexShrink:0}}),t.jsx("strong",{style:{fontSize:13,minWidth:62},children:r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}),t.jsxs("span",{style:{fontSize:13,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[((i=e.prospect)==null?void 0:i.name)||"Cliente",(n=e.prospect)!=null&&n.vehicle?` · ${e.prospect.vehicle}`:""]}),t.jsx("span",{style:{fontSize:11,color:b(e.status),flexShrink:0},children:P(e.status)})]},e.id)})})]}),p&&t.jsxs("div",{style:{marginTop:12,borderTop:"1px solid var(--border-default, rgba(255,255,255,.08))",paddingTop:10},children:[t.jsx("div",{style:{fontSize:13,fontWeight:700,marginBottom:2},children:"ð² Verlas en Google Calendar o en tu teléfono"}),t.jsxs("div",{style:{fontSize:11.5,color:"var(--text-tertiary)",marginBottom:8,lineHeight:1.5},children:["Pega esta dirección una sola vez y tus citas aparecen ahà solas, sin abrir Auttiv.",t.jsx("br",{}),t.jsx("strong",{children:"Google Calendar:"})," Otros calendarios â Desde URL.  ",t.jsx("strong",{children:"iPhone:"})," Ajustes â Calendario â Cuentas â Añadir â Otra â Suscripción."]}),t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[t.jsx("input",{readOnly:!0,value:p,onFocus:e=>e.currentTarget.select(),style:{flex:1,minWidth:0,fontSize:11,padding:"7px 9px"}}),t.jsx("button",{className:"btn",onClick:L,style:{flexShrink:0},children:I?"â Copiada":"Copiar"})]}),t.jsx("div",{style:{fontSize:10.5,color:"var(--text-tertiary)",marginTop:6},children:"Es privada y de solo lectura: nadie puede cambiar ni borrar tus citas desde ahÃ."})]})]})]})})}export{U as default};
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.