PageSourceSearch

https://buil-fogwill.com/assets/ViewingsCalendar-D1oJ4t0E.js

js buil-fogwill.com collected 2026-10-07 19:57:12 UTC 27,953 bytes, 7 lines download raw bytes

1import{o as fs,s as ee,bP as Ns,bR as bs,r as o,ae as Ce,af as xe,j as e,aF as Qe,aG as Je,aH as Ye,aI as Xe,a6 as Ae,I as be,aD as He,b3 as ye,bG as ys,bH as ws,B as g,bI as vs,V as ue,W as he,Y as pe,Z as je,_ as N,b7 as Ze,b0 as Re,b as Cs,y as _s,C as L,f as q,c as se,d as te,O as we,K as Ss,Q as ks,R as Ms,T as Ds,at as es,ax as Ts,a1 as Os,au as Es,as as Fs,U as Be,aJ as Vs,g as Le,bp as Is}from"./index-DYzDqWEM.js";import{u as ss}from"./useStaffAgents-DUFTi-5e.js";import{u as $s,b as ts,d as Ps,e as zs,f as As}from"./useViewings-DQbScoGX.js";import{A as Hs,a as Rs,b as Bs}from"./avatar-53fNvxZx.js";import{u as Ls,F as qs,a as O,b as E,c as F,e as V,d as ae,t as Gs}from"./form-Dj5PXyZI.js";import{u as Ks,a as Us,g as qe,T as Ws}from"./TaskFormDialog-CvieELbw.js";import{b as Qs}from"./property-search-BpZzWnHg.js";import{a as as,b as ns,C as Js,e as ne,i as Ys}from"./calendar-BMpoG7r9.js";import{C as rs}from"./calendar-GGqUTgIG.js";import{f as h,s as re}from"./format-DTSXrGtn.js";import{G as Xs}from"./GoogleCalendarSettings-C7J4Ohtv.js";import{C as Zs}from"./calendar-days-DfmrVSI0.js";import{L as me}from"./list-todo-BKMbdCFg.js";import{C as et}from"./chevron-left-ELxThf8y.js";import{c as st}from"./constructNow-BEznPmI4.js";import{i as ls}from"./isSameDay-joLYwakD.js";import{C as is}from"./circle-check-big-DuM05Th2.js";import{C as cs}from"./circle-x-BCpQ06Qz.js";import{C as tt}from"./circle-alert-BY9C85RP.js";import{s as Ge}from"./startOfMonth-DdINBIhw.js";import{e as Ke}from"./endOfMonth-DEMI3k8K.js";import{e as Ue}from"./endOfDay-BhUuZ7eU.js";import{p as ve}from"./parseISO-QekYdFx_.js";import{e as We}from"./eachDayOfInterval-BoSQl7tw.js";import{a as at}from"./addDays-BSbVNr0x.js";import{s as nt}from"./subDays-DRxbqYu5.js";import{e as I}from"./es-BgTUXONc.js";import"./useClientTasks-DpJVdByA.js";import"./alert-dialog-DAkrOCOf.js";import"./useGoogleCalendar-CET1ugX1.js";import"./bell-j274dyXJ.js";import"./trash-2-Dqf-WBHC.js";import"./en-US-DWZo7XR8.js";import"./isAfter-DG4OP79x.js";import"./unlink-B8gCmWxy.js";import"./link-2-Clk6sOkv.js";function le(r){return ls(r,st(r))}function rt(r,f){return as(r,-f)}function lt(r,f){return ns(r,-f)}const it=fs({client_id:ee().min(1,"Selecciona un cliente"),property_id:ee().min(1,"Selecciona una propiedad"),agent_id:ee().optional().nullable(),scheduled_date:Ns({required_error:"Selecciona una fecha"}),scheduled_time:ee().min(1,"Selecciona una hora"),duration_minutes:bs().min(15).max(480),notes:ee().optional()});function ct({open:r,onOpenChange:f,viewing:d,defaultDate:K}){const[p,$]=o.useState(""),[i,U]=o.useState(""),[P,b]=o.useState(""),[ge,_]=o.useState(!1),[w,z]=o.useState(!1),S=o.useRef(null),W=o.useRef(null);o.useEffect(()=>{const a=setTimeout(()=>U(p),300);return()=>clearTimeout(a)},[p]),o.useEffect(()=>{const a=n=>{S.current&&!S.current.contains(n.target)&&_(!1),W.current&&!W.current.contains(n.target)&&z(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]);const Q=$s(),A=ts(),H=!!d,{data:k,isLoading:fe}=Ce({queryKey:["properties-search",i],queryFn:async()=>{let a=xe.from("properties").select("id, title_es, resales_ref, public_ref, external_id, zone, subzone, urbanization").eq("is_active",!0);i&&(a=a.or(Qs(i))),a=a.order("title_es").limit(30);const{data:n,error:Y}=await a;if(Y)throw Y;return n},enabled:i.length>0}),{data:v}=ss(),{results:M}=Ks(P,{enabled:r}),j=Ls({resolver:Gs(it),defaultValues:{client_id:"",property_id:"",agent_id:null,
1scheduled_date:K||new Date,scheduled_time:"10:00",duration_minutes:60,notes:""}}),ie=j.watch("client_id"),{data:R}=Us(ie),ce=M.find(a=>a.id===ie)||R||null;o.useEffect(()=>{if(d){const a=new Date(d.scheduled_at);j.reset({client_id:d.client_id,property_id:d.property_id,agent_id:d.agent_id,scheduled_date:a,scheduled_time:h(a,"HH:mm"),duration_minutes:d.duration_minutes,notes:d.notes||""})}else j.reset({client_id:"",property_id:"",agent_id:null,scheduled_date:K||new Date,scheduled_time:"10:00",duration_minutes:60,notes:""})},[d,K,j]);const J=a=>{const[n,Y]=a.scheduled_time.split(":").map(Number),D=new Date(a.scheduled_date);D.setHours(n,Y,0,0);const X={client_id:a.client_id,property_id:a.property_id,agent_id:a.agent_id==="unassigned"?null:a.agent_id,scheduled_at:D.toISOString(),duration_minutes:a.duration_minutes,notes:a.notes||null};H?A.mutate({id:d.id,...X},{onSuccess:()=>f(!1)}):Q.mutate(X,{onSuccess:()=>f(!1)})},B=j.watch("property_id"),{data:C}=Ce({queryKey:["property-selected",B],queryFn:async()=>{const{data:a,error:n}=await xe.from("properties").select("id, title_es, resales_ref, public_ref, external_id, zone, subzone, urbanization").eq("id",B).single();if(n)throw n;return a},enabled:!!B});return e.jsx(Qe,{open:r,onOpenChange:f,children:e.jsxs(Je,{className:"sm:max-w-lg",children:[e.jsx(Ye,{children:e.jsx(Xe,{children:H?"Editar Visita":"Nueva Visita"})}),e.jsx(qs,{...j,children:e.jsxs("form",{onSubmit:j.handleSubmit(J),className:"space-y-4",children:[e.jsx(O,{control:j.control,name:"client_id",render:({field:a})=>e.jsxs(E,{className:"flex flex-col",children:[e.jsx(F,{children:"Cliente *"}),e.jsxs("div",{className:"relative",ref:S,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(be,{placeholder:"Buscar por nombre, email o teléfono...",value:P,onChange:n=>{b(n.target.value),_(!0)},onFocus:()=>_(!0),className:"pl-9"})]}),ce&&!P&&e.jsxs("div",{className:"mt-1 text-sm text-foreground flex items-center gap-2",children:[e.jsx(He,{className:"h-3 w-3 text-primary"}),qe(ce),e.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-destructive",onClick:()=>{a.onChange(""),b("")},children:"✕"})]}),ge&&P&&e.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-md border bg-popover shadow-md max-h-60 overflow-y-auto",children:M&&M.length>0?M.slice(0,30).map(n=>e.jsx("button",{type:"button",className:ye("w-full text-left px-3 py-2 hover:bg-accent flex items-center gap-2 text-sm",a.value===n.id&&"bg-accent"),onClick:()=>{a.onChange(n.id),b(""),_(!1)},children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:qe(n)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[n.email&&n.email,n.phone&&` · ${n.phone}`]})]})},n.id)):e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"No se encontraron clientes"})})]}),e.jsx(V,{})]})}),e.jsx(O,{control:j.control,name:"property_id",render:({field:a})=>e.jsxs(E,{className:"flex flex-col",children:[e.jsx(F,{children:"Propiedad *"}),e.jsxs("div",{className:"relative",ref:W,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(be,{placeholder:"Buscar por título, ref, urbanización o zona...",value:p,onChange:n=>{$(n.target.value),z(!0)},onFocus:()=>z(!0),className:"pl-9"})]}),C&&!p&&e.jsxs("div",{className:"mt-1 text-sm text-foreground flex items-center gap-2",children:[e.jsx(He,{className:"h-3 w-3 text-primary"}),C.title_es,C.resales_ref&&` (${C.resales_ref})`,e.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-destructive",onClick:()=>{a.onChange(""),$("")},children:"✕"})]}),w&&p&&e.jsx("div",{className:"absolute z-50 mt-1 w-full rounded-md border bg-popover shadow-md max-h-60 overflow-y-auto",children:fe?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Buscando..."}):k&&k.length>0?k.map(n=>e.jsx("button",{type:"button",className:ye("w-full text-left px-3 py-2 hover:bg-accent flex items-center gap-2 text-sm",a.value===n.id&&"bg-accent"),onClick:()=>{a.onChange(n.id),$(""),z(!1)},children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:n.title_es}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[(n.external_id||n.resales_ref)&&`Ref: ${n.external_id||n.resales_ref}`,n.urbanization&&` · ${n.urbanization}`,n.zone&&` · ${n.zone}`]})]})},n.id)):e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"No se encontraron propiedades"})})]}),e.jsx(V,{})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(O,{control:j.control,name:"scheduled_date",render:({field:a})=>e.jsxs(E,{className:"flex flex-col",children:[e.jsx(F,{children:"Fecha *"}),e.jsxs(ys,{children:[e.jsx(ws,{asChild:!0,children:e.jsx(ae,{children:e.jsxs(g,{variant:"outline",className:ye("pl-3 text-left font-normal",!a.value&&"text-muted-foreground"),children:[a.value?h(a.value,"dd/MM/yyyy"):e.jsx("span",{children:"Seleccionar"}),e.jsx(rs,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(vs,{className:"w-auto p-0",align:"start",children:e.jsx(Js,{mode:"single",selected:a.value,onSelect:a.onChange,disabled:n=>n<new Date})})]}),e.jsx(V,{})]})}),e.jsx(O,{control:j.control,name:"scheduled_time",render:({field:a})=>e.jsxs(E,{children:[e.jsx(F,{children:"Hora *"}),e.jsx(ae,{children:e.jsx(be,{type:"time",...a})}),e.jsx(V,{})]})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(O,{control:j.control,name:"duration_minutes",render:({field:a})=>e.jsxs(E,{children:[e.jsx(F,{children:"Duración (minutos)"}),e.jsxs(ue,{onValueChange:n=>a.onChange(Number(n)),value:a.value.toString(),children:[e.jsx(ae,{children:e.jsx(he,{children:e.jsx(pe,{})})}),e.jsxs(je,{children:[e.jsx(N,{value:"30",children:"30 min"}),e.jsx(N,{value:"45",children:"45 min"}),e.jsx(N,{value:"60",children:"1 hora"}),e.jsx(N,{value:"90",children:"1h 30min"}),e.jsx(N,{value:"120",children:"2 horas"})]})]}),e.jsx(V,{})]})}),e.jsx(O,{control:j.control,name:"agent_id",render:({field:a})=>e.jsxs(E,{children:[e.jsx(F,{children:"Agente"}),e.jsxs(ue,{onValueChange:a.onChange,value:a.value||"unassigned",children:[e.jsx(ae,{children:e.jsx(he,{children:e.jsx(pe,{placeholder:"Sin asignar"})})}),e.jsxs(je,{children:[e.jsx(N,{value:"unassigned",children:"Sin asignar"}),v==null?void 0:v.map(n=>e.jsx(N,{value:n.id,children:n.full_name||"Sin nombre"},n.id))]})]}),e.jsx(V,{})]})})]}),e.jsx(O,{control:j.control,name:"notes",render:({field:a})=>e.jsxs(E,{children:[e.jsx(F,{children:"Notas"}),e.jsx(ae,{children:e.jsx(Ze,{placeholder:"Notas adicionales sobre la visita...",...a})}),e.jsx(V,{})]})}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(g,{type:"button",variant:"outline",onClick:()=>f(!1),children:"Cancelar"}),e.jsx(g,{type:"submit",disabled:Q.isPending||A.isPending,children:H?"Guardar cambios":"Programar visita"})]})]})})]})})}const G={scheduled:{label:"Programada",color:"bg-blue-500",icon:e.jsx(es,{className:"h-3 w-3"})},completed:{label:"Completada",color:"bg-green-500",icon:e.jsx(is,{className:"h-3 w-3"})},cancelled:{label:"Cancelada",color:"bg-red-500",icon:e.jsx(cs,{className:"h-3 w-3"})},no_show:{label:"No asistió",color:"bg-gray-500",icon:e.jsx(tt,{className:"h-3 w-3"})}},ot={high:"bg-orange-500",medium:"bg-yellow-500",low:"bg-slate-400"};function Kt(){var Te,Oe,Ee,Fe,Ve,Ie,$e,Pe,ze;const[r,f]=o.useState(new Date),[d,K]=o.useState("month"),[p,$]=o.useState(null),[i,U]=o.useState(null),[P,b]=o.useState(!1),[ge,_]=o.useState(!1),[w,z]=o.useState("all"),[S,W]=o.useState("all"),[Q,A]=o.useState(""),[H,k]=o.useState(0),[fe,v]=o.useState(!1),[M,j]=o.useState(!1),[ie,R]=o.use
1State(!1),[ce,J]=o.useState(null);Ps();const B=o.useMemo(()=>{if(d==="month"){const s=Ge(r),t=Ke(r);return{start:re(s,{weekStartsOn:1}),end:ne(t,{weekStartsOn:1})}}else return d==="week"?{start:re(r,{weekStartsOn:1}),end:ne(r,{weekStartsOn:1})}:{start:Re(r),end:Ue(r)}},[r,d]),C=Re(B.start).toISOString(),a=Ue(B.end).toISOString(),{data:n,isLoading:Y}=zs({status:S!=="all"?S:void 0,agentId:w!=="all"?w:void 0,startDate:C,endDate:a}),{data:D}=Ce({queryKey:["calendar-tasks",C,a,w],queryFn:async()=>{let s=xe.from("client_tasks").select("*").gte("due_date",C).lte("due_date",a).neq("status","completed").order("due_date",{ascending:!0});w!=="all"&&(s=s.contains("assigned_to",[w]));const{data:t,error:l}=await s;if(l)throw l;const c=[...new Set((t||[]).map(x=>x.client_id).filter(Boolean))];let m={};if(c.length>0){const{data:x}=await xe.from("clients").select("id, name").in("id",c);x&&(m=x.reduce((y,u)=>(y[u.id]=u.name,y),{}))}return(t||[]).map(x=>({...x,client:x.client_id?{id:x.client_id,name:m[x.client_id]||"Cliente"}:null}))}}),X=ts(),os=As(),{hasAnyRole:ds}=Cs(),ms=ds(["super_admin","admin","manager","senior_agent"]),{data:T}=ss(),Ne=o.useMemo(()=>{const s={};return T==null||T.forEach(t=>{s[t.id]={name:[t.full_name,t.last_name].filter(Boolean).join(" ")||t.email||"Agente",avatar:t.avatar_url}}),s},[T]),oe=(s,t="h-4 w-4")=>s!=null&&s.length?e.jsx("span",{className:"flex -space-x-1 shrink-0",children:s.slice(0,3).map(l=>{const c=Ne[l],m=((c==null?void 0:c.name)||"?").split(" ").map(x=>x[0]).slice(0,2).join("").toUpperCase();return e.jsxs(Hs,{className:`${t} ring-1 ring-background`,title:(c==null?void 0:c.name)||"Agente",children:[(c==null?void 0:c.avatar)&&e.jsx(Rs,{src:c.avatar,alt:(c==null?void 0:c.name)||"Agente"}),e.jsx(Bs,{className:"text-[8px] bg-background text-foreground",children:m})]},l)})}):null,_e=o.useMemo(()=>{const s=[];return n==null||n.forEach(t=>{var c,m,x;const l=ve(t.scheduled_at);s.push({id:t.id,type:"viewing",title:((c=t.property)==null?void 0:c.title_es)||"Visita",subtitle:(m=t.client)==null?void 0:m.name,startTime:l,endMinutes:t.duration_minutes||60,color:((x=G[t.status])==null?void 0:x.color)||"bg-blue-500",agentIds:t.agent_id?[t.agent_id]:[],data:t})}),D==null||D.forEach(t=>{var c;if(!t.due_date)return;const l=ve(t.due_date);s.push({id:t.id,type:"task",title:t.title,subtitle:(c=t.client)==null?void 0:c.name,startTime:l,endMinutes:30,color:ot[t.priority]||"bg-slate-400",agentIds:Array.isArray(t.assigned_to)?t.assigned_to:t.assigned_to?[t.assigned_to]:[],data:t})}),s},[n,D]),de=o.useMemo(()=>{const s={};return _e.forEach(t=>{const l=h(t.startTime,"yyyy-MM-dd");s[l]||(s[l]=[]),s[l].push(t)}),Object.values(s).forEach(t=>t.sort((l,c)=>l.startTime.getTime()-c.startTime.getTime())),s},[_e]),Se=o.useMemo(()=>p?de[h(p,"yyyy-MM-dd")]||[]:[],[p,de]),ke=s=>{f(d==="month"?s===1?as(r,1):rt(r,1):d==="week"?s===1?ns(r,1):lt(r,1):s===1?at(r,1):nt(r,1))},xs=o.useMemo(()=>{if(d==="month")return h(r,"MMMM yyyy",{locale:I});if(d==="week"){const s=re(r,{weekStartsOn:1}),t=ne(r,{weekStartsOn:1});return`${h(s,"d MMM",{locale:I})} – ${h(t,"d MMM yyyy",{locale:I})}`}return h(r,"EEEE, d 'de' MMMM yyyy",{locale:I})},[r,d]),us=o.useMemo(()=>{if(d!=="month")return[];const s=Ge(r),t=Ke(r);return We({start:re(s,{weekStartsOn:1}),end:ne(t,{weekStartsOn:1})})},[r,d]),hs=o.useMemo(()=>d!=="week"?[]:We({start:re(r,{weekStartsOn:1}),end:ne(r,{weekStartsOn:1})}),[r,d]),ps=Array.from({length:14},(s,t)=>t+7),js=()=>{i&&X.mutate({id:i.id,status:"completed",feedback:Q,rating:H||null},{onSuccess:()=>{v(!1),b(!1),A(""),k(0)}})},Me=s=>{s.type==="viewing"?(U(s.data),b(!0)):s.type==="task"&&(J(s.data),R(!0))},gs=(s,t=!0)=>e.jsxs("button",{onClick:l=>{l.stopPropagation(),Me(s)},className:`text-xs px-1.5 py-0.5 rounded truncate text-white flex items-center gap-1 w-full text-left ${s.color}`,children:[s.type==="task"&&e.jsx(me,{className:"h-2.5 w-2.5 shrink-0"}),t&&e.jsx("span",{className:"shrink-0",children:h(s.startTime,"HH:mm")}),e.jsx("span",{className:"truncate flex-1",children:s.title}),oe(s.agentIds)]},s.id),De=s=>{const t=s.length===1;return e.jsx("div",{className:"overflow-auto max-h-[calc(100vh-280px)] border rounded-lg",children:e.jsxs("div",{className:"grid",style:{gridTemplateColumns:`60px repeat(${s.length}, 1fr)`},children:[e.jsx("div",{className:"sticky top-0 z-10 bg-background border-b border-r h-12"}
1),s.map(l=>e.jsxs("div",{className:`sticky top-0 z-10 bg-background border-b px-2 py-2 text-center ${le(l)?"bg-primary/5":""}`,children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:h(l,"EEE",{locale:I})}),e.jsx("div",{className:`text-lg font-semibold ${le(l)?"text-primary":""}`,children:h(l,"d")})]},l.toISOString())),ps.map(l=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-r border-b px-1 py-0 text-xs text-muted-foreground text-right pr-2 h-16 flex items-start pt-1",children:`${l}:00`},`label-${l}`),s.map(c=>{const m=h(c,"yyyy-MM-dd"),y=(de[m]||[]).filter(u=>{const Z=u.startTime.getHours();return u.type==="task"&&(Z<7||Z>20)?l===9:Z===l});return e.jsx("div",{className:`border-b border-r h-16 relative px-0.5 py-0.5 ${le(c)?"bg-primary/[0.02]":""}`,onClick:()=>$(c),children:e.jsx("div",{className:"space-y-0.5",children:y.map(u=>e.jsxs("button",{onClick:Z=>{Z.stopPropagation(),Me(u)},className:`text-xs px-1 py-0.5 rounded text-white w-full text-left truncate flex items-center gap-1 ${u.color}`,children:[u.type==="task"&&e.jsx(me,{className:"h-2.5 w-2.5 shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:t?`${u.subtitle||""} - ${u.title}`:u.title}),oe(u.agentIds)]},u.id))})},`${m}-${l}`)})]}))]})})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Calendario"}),e.jsx("p",{className:"text-muted-foreground",children:"Visitas y tareas programadas"})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>j(!M),children:[e.jsx(Zs,{className:"h-4 w-4 mr-2"}),"Google Calendar"]}),e.jsxs(g,{variant:"outline",onClick:()=>R(!0),children:[e.jsx(me,{className:"h-4 w-4 mr-2"}),"Nueva Tarea"]}),e.jsxs(g,{onClick:()=>{U(null),_(!0)},children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Nueva Visita"]})]})]}),M&&e.jsx(Xs,{}),e.jsxs("div",{className:"flex flex-wrap gap-4 items-center justify-between",children:[e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(ue,{value:w,onValueChange:z,children:[e.jsx(he,{className:"w-[180px]",children:e.jsx(pe,{placeholder:"Todos los agentes"})}),e.jsxs(je,{children:[e.jsx(N,{value:"all",children:"Todos los agentes"}),T==null?void 0:T.map(s=>e.jsx(N,{value:s.id,children:s.full_name||"Sin nombre"},s.id))]})]}),e.jsxs(ue,{value:S,onValueChange:W,children:[e.jsx(he,{className:"w-[180px]",children:e.jsx(pe,{placeholder:"Todos los estados"})}),e.jsxs(je,{children:[e.jsx(N,{value:"all",children:"Todos los estados"}),Object.entries(G).map(([s,t])=>e.jsx(N,{value:s,children:t.label},s))]})]})]}),e.jsx("div",{className:"flex items-center gap-1 bg-muted rounded-lg p-1",children:["day","week","month"].map(s=>e.jsx(g,{variant:d===s?"default":"ghost",size:"sm",onClick:()=>K(s),className:"text-xs px-3",children:s==="day"?"Día":s==="week"?"Semana":"Mes"},s))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold capitalize",children:xs}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"outline",size:"icon",onClick:()=>ke(-1),children:e.jsx(et,{className:"h-4 w-4"})}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>f(new Date),children:"Hoy"}),e.jsx(g,{variant:"outline",size:"icon",onClick:()=>ke(1),children:e.jsx(_s,{className:"h-4 w-4"})})]})]}),d==="month"&&e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsx(L,{className:"lg:col-span-2",children:e.jsxs(q,{className:"pt-4",children:[e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-2",children:["Lun","Mar","Mié","Jue","Vie","Sáb","Dom"].map(s=>e.jsx("div",{className:"text-center text-sm font-medium text-muted-foreground py-2",children:s},s))}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:us.map(s=>{const t=h(s,"yyyy-MM-dd"),l=de[t]||[],c=Ys(s,r),m=p&&ls(s,p);return e.jsxs("button",{onClick:()=>$(s),className:`
2                        min-h-[80px] p-1 rounded-lg border transition-all text-left
3                        ${c?"bg-background":"bg-muted/30"}
4                        ${m?"ring-2 ring-primary":""}
5                        ${le(s)?"border-primary":"border-border"}
6                        hover:bg-muted/50
7                      `,children:[e.jsx("div",{className:`text-sm font-medium ${le(s)?"text-primary":c?"":"text-muted-foreground"}`,children:h(s,"d")}),e.jsxs("div",{className:"mt-1 space-y-0.5",children:[l.slice(0,3).map(x=>gs(x)),l.length>3&&e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["+",l.length-3," más"]})]})]},t)})})]})}),e.jsxs(L,{children:[e.jsx(se,{children:e.jsx(te,{className:"text-lg",children:p?h(p,"EEEE, d 'de' MMMM",{locale:I}):"Selecciona un día"})}),e.jsx(q,{children:p?Se.length>0?e.jsx("div",{className:"space-y-3",children:Se.map(s=>{var t,l,c;if(s.type==="viewing"){const m=s.data,x=G[m.status]||G.scheduled;return e.jsxs("button",{onClick:()=>{U(m),b(!0)},className:"w-full text-left p-3 rounded-lg border hover:bg-muted/50 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"font-medium text-sm",children:h(s.startTime,"HH:mm")}
7),e.jsx(we,{className:`${x.color} text-white`,children:x.label})]}),e.jsx("p",{className:"text-sm truncate",children:(t=m.property)==null?void 0:t.title_es}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:(l=m.client)==null?void 0:l.name}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[oe(s.agentIds,"h-6 w-6"),e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[120px]",children:s.agentIds.map(y=>{var u;return(u=Ne[y])==null?void 0:u.name}).filter(Boolean).join(", ")})]})]})]},s.id)}else{const m=s.data;return e.jsxs("button",{onClick:()=>{J(m),R(!0)},className:"w-full text-left p-3 rounded-lg border bg-muted/20 hover:bg-muted/40 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsx(me,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Tarea"]}),e.jsx(we,{variant:"outline",className:"text-xs capitalize",children:m.priority})]}),e.jsx("p",{className:"text-sm",children:m.title}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:(c=m.client)==null?void 0:c.name}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[oe(s.agentIds,"h-6 w-6"),e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[120px]",children:s.agentIds.map(x=>{var y;return(y=Ne[x])==null?void 0:y.name}).filter(Boolean).join(", ")})]})]})]},s.id)}})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No hay eventos"}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Selecciona un día para ver los eventos"})})]})]}),d==="week"&&De(hs),d==="day"&&De([r]),e.jsxs("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-3 w-3 rounded bg-blue-500"})," Visita programada"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-3 w-3 rounded bg-green-500"})," Visita completada"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-3 w-3 rounded bg-orange-500"})," Tarea alta prioridad"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-3 w-3 rounded bg-yellow-500"})," Tarea media"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-3 w-3 rounded bg-slate-400"})," Tarea baja"]})]}),e.jsx(Ss,{open:P,onOpenChange:b,children:e.jsx(ks,{className:"sm:max-w-lg",children:i&&e.jsxs(e.Fragment,{children:[e.jsx(Ms,{children:e.jsx(Ds,{children:"Detalles de la Visita"})}),e.jsxs("div",{className:"mt-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:h(ve(i.scheduled_at),"EEEE, d MMM yyyy 'a las' HH:mm",{locale:I})})]}),e.jsx(we,{className:`${(Te=G[i.status])==null?void 0:Te.color} text-white`,children:(Oe=G[i.status])==null?void 0:Oe.label})]}),e.jsxs(L,{children:[e.jsx(se,{className:"pb-2",children:e.jsxs(te,{className:"text-sm flex items-center gap-2",children:[e.jsx(Ts,{className:"h-4 w-4"}),"Propiedad"]})}),e.jsxs(q,{children:[e.jsx("p",{className:"font-medium",children:(Ee=i.property)==null?void 0:Ee.title_es}),((Fe=i.property)==null?void 0:Fe.zone)&&e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1 mt-1",children:[e.jsx(Os,{className:"h-3 w-3"}),i.property.zone]}),((Ve=i.property)==null?void 0:Ve.resales_ref)&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Ref: ",i.property.resales_ref]})]})]}),e.jsxs(L,{children:[e.jsx(se,{className:"pb-2",children:e.jsxs(te,{className:"text-sm flex items-center gap-2",children:[e.jsx(Es,{className:"h-4 w-4"}),"Cliente"]})}),e.jsxs(q,{children:[e.jsx("p",{className:"font-medium",children:(Ie=i.client)==null?void 0:Ie.name}),(($e=i.client)==null?void 0:$e.email)&&e.jsx("a",{href:`mailto:${i.client.email}`,className:"text-sm text-primary hover:underline",children:i.client.email}),((Pe=i.client)==null?void 0:Pe.phone)&&e.jsxs("p",{className:"text-sm flex items-center gap-1 mt-1",children:[e.jsx(Fs,{className:"h-3 w-3"}),i.client.phone]}
7)]})]}),((ze=i.agent)==null?void 0:ze.full_name)&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Agente: ",i.agent.full_name]}),i.notes&&e.jsxs(L,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(te,{className:"text-sm",children:"Notas"})}),e.jsx(q,{children:e.jsx("p",{className:"text-sm",children:i.notes})})]}),i.status==="completed"&&e.jsxs(e.Fragment,{children:[i.rating&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Valoración:"}),e.jsx("div",{className:"flex",children:[1,2,3,4,5].map(s=>e.jsx(Be,{className:`h-5 w-5 ${s<=i.rating?"text-yellow-400 fill-yellow-400":"text-gray-300"}`},s))})]}),i.feedback&&e.jsxs(L,{children:[e.jsx(se,{className:"pb-2",children:e.jsx(te,{className:"text-sm",children:"Feedback"})}),e.jsx(q,{children:e.jsx("p",{className:"text-sm",children:i.feedback})})]})]}),ms&&i.status==="scheduled"&&e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsxs(g,{className:"flex-1",onClick:()=>{A(""),k(0),v(!0)},children:[e.jsx(is,{className:"h-4 w-4 mr-2"}),"Completar"]}),e.jsxs(g,{variant:"destructive",className:"flex-1",onClick:()=>{os.mutate(i.id,{onSuccess:()=>b(!1)})},children:[e.jsx(cs,{className:"h-4 w-4 mr-2"}),"Cancelar"]})]})]})]})})}),e.jsx(Qe,{open:fe,onOpenChange:v,children:e.jsxs(Je,{children:[e.jsxs(Ye,{children:[e.jsx(Xe,{children:"Completar Visita"}),e.jsx(Vs,{children:"Añade valoración y feedback de la visita"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(Le,{children:"Valoración del cliente"}),e.jsx("div",{className:"flex gap-1 mt-2",children:[1,2,3,4,5].map(s=>e.jsx("button",{onClick:()=>k(s),className:"p-1",children:e.jsx(Be,{className:`h-8 w-8 transition-colors ${s<=H?"text-yellow-400 fill-yellow-400":"text-gray-300 hover:text-yellow-200"}`})},s))})]}),e.jsxs("div",{children:[e.jsx(Le,{children:"Feedback / Notas"}),e.jsx(Ze,{value:Q,onChange:s=>A(s.target.value),placeholder:"¿Cómo fue la visita? ¿Qué comentó el cliente?",className:"mt-2"})]})]}),e.jsxs(Is,{children:[e.jsx(g,{variant:"outline",onClick:()=>v(!1),children:"Cancelar"}),e.jsx(g,{onClick:js,disabled:X.isPending,children:"Guardar y Completar"})]})]})}),e.jsx(ct,{open:ge,onOpenChange:_,viewing:i,defaultDate:p}),e.jsx(Ws,{open:ie,onOpenChange:s=>{R(s),s||J(null)},defaultDate:p,task:ce})]})}export{Kt 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.