PageSourceSearch

https://new.proline.app/assets/events-DMQ1DxCC.js

js proline.app collected 2026-10-04 20:08:17 UTC 43,725 bytes, 1 lines download raw bytes

1import{aj as ws,bg as Ye,j2 as Ue,r as u,o as re,p as L,j as e,j3 as je,cs as be,a1 as F,V as K,bJ as qe,w as Je,a3 as Qe,d1 as Ss,j4 as Ns,j5 as Pe,d2 as Ts,d5 as Ge,d3 as ks,v as le,B as R,gj as Ds,bf as O,bh as Me,bi as _e,bj as Ae,bk as Re,bm as G,ab as Xe,ac as Ze,ad as es,ce as Es,cl as Is,dg as Ms,ai as P,bv as _s,h2 as As,hE as ss,j6 as ts,ct as pe,j7 as se,j8 as ns,j9 as Rs,ja as as,jb as Be,h3 as Os,jc as Ls,jd as Ps,hX as ge,je as rs,jf as Bs,h4 as H,jg as zs,jh as $s,h5 as Q,e_ as Vs,cp as Fs,cn as Ks,ji as Ws,bx as ls,q as Te,jj as Hs,jk as oe,aq as Ys,ar as Us,as as qs,at as Js,au as Qs,bw as Gs,t as W,bu as Xs,be as Zs,cJ as et,gM as st,a as os,g6 as tt,s as nt,cb as at,jl as rt,ap as lt,ge as ot,jm as it,jn as ct,jo as dt,jp as ut,jq as mt}from"./index-CcCY4UFy.js";import{C as Ce,a as we,b as Se}from"./collapsible-gVXT2Y0Z.js";import{S as ht}from"./sliders-horizontal-CRB2n77K.js";import{s as xt}from"./subDays-B05XBQP_.js";import{u as gt,S as pt}from"./use-sms-input-limit-CpHmsKpu.js";import{V as ft}from"./variable-textarea-CH0comn3.js";import{C as yt}from"./circle-alert-CzERthCN.js";import{EventSheet as vt}from"./index-DKfRRUdE.js";import"./index-BJFSeajg.js";import"./event-duration-BgrDCR5D.js";import"./availability-picker-bO4-7EE9.js";import"./alert-DrCasA9D.js";import"./projectAssignmentEligibility-7akrPgBn.js";import"./user-multi-select-DOJmxdBk.js";import"./maps-external-CShhNVhJ.js";import"./lock-RpgWdkgY.js";const jt=[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]],ze=ws("car",jt);function bt(s,t,n){return Ye(s,-1,n)}function Ct(s,t,n){return Ue(s,-1,n)}function wt(s){return s==="month"||s==="week"||s==="day"||s==="dispatch"||s==="route"?s:"month"}function St(s,t,n){if(s.endTime>t.startTime)return"Schedule conflict";if(!n)return null;const a=Math.ceil((s.endTime+n.durationSeconds*1e3-t.startTime)/6e4);return a>0?`${a} min short`:null}function is({filters:s,onFiltersChange:t,hideAssignees:n=!1}){const[a,r]=u.useState(["calendar","assignee","location","eventType"]),o=re(L.crud.calendars.getByCompany,{}),g=re(L.crud.users.getByCompany,{}),p=re(L.crud.locations.getByCompany,{}),m=re(L.crud.eventTypes.getByCompany,{}),h=c=>{r(w=>w.includes(c)?w.filter(j=>j!==c):[...w,c])},E=c=>{if(!o)return;const w=s.calendarIds===null||s.calendarIds.includes(c);let j;w?s.calendarIds===null?j=o.filter(i=>i._id!==c).map(i=>i._id):j=s.calendarIds.filter(i=>i!==c):j=[...s.calendarIds??[],c];const k=o.every(i=>j.includes(i._id));t({...s,calendarIds:k?null:j})},N=c=>{if(!g)return;const w=s.assigneeIds===null||s.assigneeIds.includes(c);let j;w?s.assigneeIds===null?j=g.filter(i=>i._id!==c).map(i=>i._id):j=s.assigneeIds.filter(i=>i!==c):j=[...s.assigneeIds??[],c];const k=g.every(i=>j.includes(i._id));t({...s,assigneeIds:k?null:j})},b=c=>{if(!p)return;const w=s.locationIds===null||s.locationIds.includes(c);let j;w?s.locationIds===null?j=p.filter(i=>i._id!==c).map(i=>i._id):j=s.locationIds.filter(i=>i!==c):j=[...s.locationIds??[],c];const k=p.every(i=>j.includes(i._id));t({...s,locationIds:k?null:j})},_=()=>{t({...s,calendarIds:s.calendarIds===null?[]:null})},S=()=>{t({...s,assigneeIds:s.assigneeIds===null?[]:null})},y=()=>{t({...s,locationIds:s.locationIds===null?[]:null})},T=c=>{if(!m)return;const w=s.eventTypeIds===null||s.eventTypeIds.includes(c);let j;w?s.eventTypeIds===null?j=m.filter(i=>i._id!==c).map(i=>i._id):j=s.eventTypeIds.filter(i=>i!==c):j=[...s.eventTypeIds??[],c];const k=m.every(i=>j.includes(i._id));t({...s,eventTypeIds:k?null:j})},I=()=>{t({...s,eventTypeIds:s.eventTypeIds===null?[]:null})};return e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs(Ce,{open:a.includes("calendar"),onOpenChange:()=>h("calendar"),children:[e.jsxs(we,{className:"flex items-center justify-between w-full px-4 py-3 text-sm font-medium hover:bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Filter By Calendar"}),a.includes("calendar")?e.jsx(je,{size:16}):e.jsx(be,{size:16})]}),e.jsx(Se,{className:"border-b border-border",children:e.jsxs("div",{className:"px-4 py-3 space-y-2",children:[o&&o.length>0&&e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.calendarIds===null,onCheckedChange:_}),e.jsx("span",{children:"All Calendars"})]}),o?.map(c=>e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.calendarIds===null||s.calendarIds.includes(c._id),onCheckedChange:()=>E(c._id)}),e.jsx("span",{children:c.name})]},c._id)),(!o||o.length===0)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No calendars configured"})]})})]}),!n&&e.jsxs(Ce,{open:a.includes("assignee"),onOpenChange:()=>h("assignee"),children:[e.jsxs(we,{className:"flex items-center justify-between w-full px-4 py-3 text-sm font-medium hover:bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Filter By Assignee"}),a.includes("assignee")?e.jsx(je,{size:16}):e.jsx(be,{size:16})]}),e.jsx(Se,{className:"border-b border-border",children:e.jsxs("div",{className:"px-4 py-3 space-y-2",children:[g&&g.length>0&&e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.assigneeIds===null,onCheckedChange:S}),e.jsx("span",{children:"All Assignees"})]}),g?.map(c=>e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.assigneeIds===null||s.assigneeIds.includes(c._id),onCheckedChange:()=>N(c._id)}),e.jsx("span",{children:qe(c)})]},c._id))]})})]}),e.jsxs(Ce,{open:a.includes("location"),onOpenChange:()=>h("location"),children:[e.jsxs(we,{className:"flex items-center justify-between w-full px-4 py-3 text-sm font-medium hover:bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Filter By Location"}),a.includes("location")?e.jsx(je,{size:16}):e.jsx(be,{size:16})]}),e.jsx(Se,{className:"border-b border-border",children:e.jsxs("div",{className:"px-4 py-3 space-y-2",children:[p&&p.length>0&&e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.locationIds===null,onCheckedChange:y}),e.jsx("span",{children:"All Locations"})]}),p?.map(c=>e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.locationIds===null||s.locationIds.includes(c._id),onCheckedChange:()=>b(c._id)}),e.jsx("span",{children:c.name})]},c._id))]})})]}),e.jsxs(Ce,{open:a.includes("eventType"),onOpenChange:()=>h("eventType"),children:[e.jsxs(we,{className:"flex items-center justify-between w-full px-4 py-3 text-sm font-medium hover:bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Filter By Event Type"}),a.includes("eventType")?e.jsx(je,{size:16}):e.jsx(be,{size:16})]}),e.jsx(Se,{className:"border-b border-border",children:e.jsxs("div",{className:"px-4 py-3 space-y-2",children:[m&&m.length>0&&e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.eventTypeIds===null,onCheckedChange:I}),e.jsx("span",{children:"All Event Types"})]}),m?.map(c=>e.jsxs(F,{className:"cursor-pointer font-normal",children:[e.jsx(K,{checked:s.eventTypeIds===null||s.eventTypeIds.includes(c._id),onCheckedChange:()=>T(c._id)}),e.jsx("span",{children:c.name})]},c._id)),(!m||m.length===0)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No event types configured"})]})})]})]})}function Nt(s){const t=Je(L.operations.events.route.actions.compute),a=Qe({day:{query:L.operations.events.route.day.getDay,args:s}}).day,r=a instanceof Error?void 0:a,o=r?JSON.stringify(r):"",g=JSON.stringify(s),[p,m]=u.useState(0),h=JSON.stringify([g,o,p]),E=u.useRef(new Map),[N,b]=u.useState(null);u.useEffect(()=>{if(!o)return;let S=!0,y=E.current.get(h);return y||(y=t(JSON.parse(g)),E.current.set(h,y),E.current.size>10&&E.current.delete(E.current.keys().next().value)),y.then(T=>{S&&b({key:h,result:T?.version===o?T:null,error:T?.version===o?null:"The route changed. Please refresh the estimates."})},()=>{S&&b({key:h,result:null,error:"Travel estimates are unavailable. Wait a moment and retry."})}),()=>{S=!1}},[g,t,h,o]);const _=N?.key===h?N:null;return{day:r,result:_?.result??null,error:a instanceof Error?"This day could not be loaded. Try narrowing the filters.":_?.error??null,loading:!(a instanceof Error)&&(r===void 0||!!r&&!_),retry:()=>m(S=>S+1)}}function Tt({stops:s,legs:t,selectedId:n}){const a=Ge(),r=Ds("geometry");u.useEffect(()=>{if(!a||!r)return;const p=t.filter(m=>m.polyline).map(m=>new google.maps.Polyline({map:a,path:r.encoding.decodePath(m.polyline),strokeColor:"#2675d8",strokeOpacity:.9,strokeWeight:5}));return()=>
1p.forEach(m=>m.setMap(null))},[a,r,t]);const o=JSON.stringify(s.map(p=>p.coordinates));u.useEffect(()=>{if(!a)return;const p=JSON.parse(o),m=new google.maps.LatLngBounds;p.forEach(h=>{h&&m.extend(h)}),m.isEmpty()||(m.getNorthEast().equals(m.getSouthWest())?(a.setCenter(m.getCenter()),a.setZoom(14)):a.fitBounds(m,65))},[a,o]);const g=s.find(p=>p.id===n)?.coordinates;return u.useEffect(()=>{a&&g&&a.panTo(g)},[a,g]),null}function kt(s){const t=Ge(),n=new Map;return s.stops.forEach((a,r)=>{if(!a.coordinates)return;const o=`${a.coordinates.lat},${a.coordinates.lng}`;n.set(o,[...n.get(o)??[],{stop:a,number:r+1}])}),e.jsxs(e.Fragment,{children:[e.jsx(Tt,{...s}),[...n.entries()].map(([a,r])=>e.jsx(ks,{position:r[0].stop.coordinates,children:e.jsx("div",{className:"flex max-w-48 flex-wrap gap-1 rounded-2xl bg-card p-1 shadow-md",children:r.map(({stop:o,number:g})=>e.jsx("button",{type:"button","aria-label":`Stop ${g}: ${o.title}`,onClick:()=>s.onSelect(o.id),className:le("h-9 min-w-9 rounded-full bg-primary px-2 text-sm font-semibold text-primary-foreground",s.selectedId===o.id&&"ring-2 ring-primary ring-offset-2"),children:g},o.id))})},a)),e.jsx("div",{className:"absolute right-3 top-3",children:e.jsx(R,{variant:"secondary",size:"sm",onClick:()=>{if(!t)return;const a=new google.maps.LatLngBounds;s.stops.forEach(r=>{r.coordinates&&a.extend(r.coordinates)}),a.isEmpty()||t.fitBounds(a,65)},children:"Fit route"})})]})}function cs(){return e.jsx("div",{role:"status",className:"flex h-full min-h-80 items-center justify-center bg-muted p-6 text-center text-sm text-muted-foreground",children:"Map is currently unavailable. Your appointments and directions are still available in the list."})}function Dt(s){const t=Ns();return t===Pe.AUTH_FAILURE||t===Pe.FAILED?e.jsx(cs,{}):e.jsx(Ts,{mapId:"calendar-route",defaultCenter:{lat:39.8,lng:-98.6},defaultZoom:4,gestureHandling:"greedy",disableDefaultUI:!1,streetViewControl:!1,mapTypeControl:!1,className:"h-full min-h-80",children:e.jsx(kt,{...s})})}function Et(s){const t="AIzaSyCOIpP6ij7mgIkpJrlHbwijLVQOSS24cOs",[n,a]=u.useState(!1);return n?e.jsx(cs,{}):e.jsx(Ss,{apiKey:t,onError:()=>a(!0),children:e.jsx(Dt,{...s})})}const It=[];function Mt({currentDate:s,timeZone:t,userId:n,canViewAllEvents:a,initialFilters:r,onEventClick:o}){const[g,p]=u.useState(n),[m,h]=u.useState(r),E=re(L.crud.users.getByCompany,a?{}:"skip"),N=a?g:n,b=Nt({date:O(s,"yyyy-MM-dd"),timeZone:t,assigneeId:N,...m.calendarIds===null?{}:{calendarIds:m.calendarIds},...m.locationIds===null?{}:{locationIds:m.locationIds},...m.eventTypeIds===null?{}:{eventTypeIds:m.eventTypeIds}}),[_,S]=u.useState(null),y=u.useRef(new Map),T=b.result?.stops??b.day?.stops??[],I=T.filter(l=>l.routable&&!l.reason),c=T.filter(l=>!l.routable||l.reason),w=b.result?.legs??It,j=l=>O(new P(l,t),"h:mm a"),k=I.find(l=>l.id===_),i=l=>{S(l),y.current.get(l)?.scrollIntoView({block:"nearest",behavior:"smooth"})},C=l=>`https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(l.address??"")}&travelmode=driving`;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-b bg-card px-4 py-3",children:[a?e.jsxs(Me,{value:N,onValueChange:l=>p(l),children:[e.jsx(_e,{className:"w-48","aria-label":"Route person",children:e.jsx(Ae,{placeholder:"Select person"})}),e.jsx(Re,{children:E?.map(l=>e.jsx(G,{value:l._id,children:qe(l)},l._id))})]}):e.jsx("span",{className:"font-medium",children:"My day route"}),e.jsxs("span",{className:"text-sm",children:[I.length," stops"]}),b.result&&e.jsxs("span",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ze,{size:16}),b.result.incomplete?"Partial: ":"",Math.ceil(b.result.durationSeconds/60)," min driving ·"," ",(b.result.distanceMeters/1609.344).toFixed(1)," mi"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Between appointments · Excludes traffic"}),e.jsxs(Xe,{children:[e.jsx(Ze,{asChild:!0,children:e.jsxs(R,{variant:"outline",size:"sm",className:"ml-auto",children:[e.jsx(ht,{size:14}),"Filters"]})}),e.jsx(es,{align:"end",className:"max-h-[65vh] overflow-auto p-0",children:e.jsx(is,{filters:m,onFiltersChange:h,hideAssignees:!0})})]})]}),(b.error||b.result?.error)&&e.jsxs("div",{role:"status",className:"flex items-center justify-between gap-3 border-b bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:bg-amber-950 dar
1k:text-amber-100",children:[e.jsx("span",{children:b.error||b.result?.error}),e.jsx(R,{variant:"outline",size:"sm",onClick:b.retry,children:"Retry estimates"})]}),b.day===null?e.jsx("p",{className:"p-6 text-muted-foreground",children:"Calendar Route is not available."}):e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-1 overflow-auto lg:grid-cols-[360px_minmax(0,1fr)] lg:overflow-hidden",children:[e.jsxs("aside",{"aria-label":"Day route",className:"border-r bg-card lg:overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsx("h3",{className:"font-semibold",children:"Day route"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Appointment order"})]}),b.loading&&e.jsx("p",{role:"status",className:"px-4 py-2 text-sm text-muted-foreground",children:b.day?"Calculating travel estimates…":"Loading appointments…"}),!b.loading&&!T.length&&!b.error&&e.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:"No appointments for this person and day."}),e.jsx("div",{className:"p-2",children:I.map((l,x)=>{const f=I[x+1],B=f?w.find(D=>D.fromId===l.id&&D.toId===f.id):void 0,$=T.filter(D=>D.reason!=="All-day appointment"&&D.reason!=="Already in progress"),z=f&&$[$.findIndex(D=>D.id===l.id)+1]?.id===f.id?St(l,f,B):null;return e.jsxs("div",{ref:D=>{D?y.current.set(l.id,D):y.current.delete(l.id)},children:[e.jsxs("button",{type:"button",onClick:()=>i(l.id),className:le("flex w-full gap-3 rounded-lg border border-transparent p-3 text-left hover:bg-muted/50",k?.id===l.id&&"border-primary bg-primary/5"),children:[e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-sm font-semibold text-primary-foreground",children:x+1}),e.jsxs("span",{className:"min-w-0 space-y-1",children:[e.jsxs("span",{className:"block text-xs",children:[j(l.startTime)," – ",j(l.endTime)]}),e.jsx("span",{className:"block font-semibold",children:l.title}),e.jsxs("span",{className:"block text-xs text-muted-foreground",children:[l.eventTypeName,l.projectName?` · ${l.projectName}`:""]}),e.jsxs("span",{className:"flex gap-1 text-sm text-muted-foreground",children:[e.jsx(Es,{size:14,className:"mt-0.5 shrink-0"}),l.address]})]})]}),k?.id===l.id&&e.jsxs("div",{className:"flex gap-2 px-14 pb-3",children:[e.jsx(R,{size:"sm",variant:"outline",onClick:()=>o(l.id),children:"View event"}),e.jsx(R,{size:"sm",asChild:!0,children:e.jsxs("a",{href:C(l),target:"_blank",rel:"noopener noreferrer",children:["Directions",e.jsx(Is,{size:12})]})})]}),f&&e.jsxs("div",{className:"ml-6 border-l border-dashed py-3 pl-8 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ze,{size:14}),B?`${Math.ceil(B.durationSeconds/60)} min · ${(B.distanceMeters/1609.344).toFixed(1)} mi`:"Travel unavailable"]}),z&&e.jsxs("span",{className:"mt-1 flex items-center gap-1 text-amber-700 dark:text-amber-400",children:[e.jsx(Ms,{size:14}),z]})]})]},l.id)})}),c.length>0&&e.jsxs("div",{className:"m-3 rounded-lg border bg-muted/20 p-3",children:[e.jsxs("h4",{className:"mb-2 text-sm font-semibold",children:["Not mapped (",c.length,")"]}),c.map(l=>e.jsxs("button",{type:"button",onClick:()=>o(l.id),className:"block w-full border-t py-3 text-left text-sm",children:[e.jsxs("span",{className:"block font-medium",children:[j(l.startTime)," · ",l.title]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:l.reason})]},l.id))]})]}),e.jsx("div",{className:"relative min-h-[400px] lg:min-h-0",children:e.jsx(Et,{stops:I,legs:w,selectedId:k?.id??null,onSelect:i})})]})]})}function _t(s){const[t,n]=u.useState(()=>new P(Date.now(),s)),a=u.useMemo(()=>_s(t),[t]),r=u.useMemo(()=>As(t),[t]),o=u.useMemo(()=>ss(a),[a]),g=u.useMemo(()=>ts(r),[r]);return{currentDate:t,monthStart:a,monthEnd:r,calendarStart:o,calendarEnd:g,goToToday:()=>n(new P(Date.now(),s)),goToPrevMonth:()=>n(y=>bt(y)),goToNextMonth:()=>n(y=>Ye(y,1)),goToPrevWeek:()=>n(y=>Ct(y)),goToNextWeek:()=>n(y=>Ue(y,1)),goToPrevDay:()=>n(y=>xt(y,1)),goToNextDay:()=>n(y=>pe(y,1)),goToDate:y=>{n(new P(y.getTime(),s))}}}function At({event:s,timeZone:t,onClick:n}){const a=se(s),r=ns(s),o=Rs(s),g=p=>
1{if(a){p.preventDefault();return}p.dataTransfer.setData("application/json",JSON.stringify(s)),p.dataTransfer.effectAllowed="move"};return e.jsxs("div",{draggable:!a,onDragStart:g,className:le("relative flex w-full min-w-0 items-center gap-1 overflow-hidden truncate rounded border px-1.5 py-0.5 pr-3 text-left text-xs shadow-xs hover:opacity-80",a?"cursor-pointer":"cursor-grab active:cursor-grabbing",a&&"border-dashed",s.isCanceled&&"opacity-50 line-through"),style:{backgroundColor:r.backgroundColor,borderColor:r.borderColor,color:r.textColor},onClick:p=>{p.stopPropagation(),n?.()},children:[e.jsx("span",{className:"absolute bottom-0 right-0 top-0 w-1",style:{backgroundColor:r.assigneeRailColor}}),e.jsxs("span",{className:"truncate",children:[!s.isAllDay&&e.jsx("span",{className:"font-medium",children:O(new P(s.startTime,t),"h:mma").toLowerCase()})," ",o]})]})}function Rt({day:s,timeZone:t,onClick:n,onEventClick:a,onEventDrop:r,onShowMore:o,onDateNavigate:g,bulkSelecting:p=!1,bulkCanSelect:m=!1,bulkSelected:h=!1,onBulkToggleDay:E,previewProposals:N=[],omittedEventIds:b,reservedAllDayRows:_=0}){const[S,y]=u.useState(!1),T=as(s.events),I=b?T.filter(x=>!b.has(String(x._id))):T,c=I.slice(0,Be),w=I.length-Be,j=p&&m,k=!!g&&!p,i=x=>{p||N.length>0||(x.preventDefault(),x.dataTransfer.dropEffect="move",y(!0))},C=()=>{y(!1)},l=x=>{if(!(p||N.length>0)){x.preventDefault(),y(!1);try{const f=JSON.parse(x.dataTransfer.getData("application/json"));if(se(f))return;r(f,s.date)}catch{}}};return e.jsxs("div",{className:le("border-r border-b border-border p-1 min-h-[120px] hover:bg-muted/50 transition-colors",!s.isCurrentMonth&&"bg-muted/30",p&&m?"cursor-pointer":"cursor-default",h&&"bg-primary/10 ring-2 ring-primary/50 ring-inset",N.length>0&&"bg-blue-50 dark:bg-blue-950/20",S&&"bg-primary/10 ring-2 ring-primary ring-inset"),onClick:p?m?E:void 0:n,onDragOver:i,onDragLeave:C,onDrop:l,children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[j?e.jsxs("label",{className:"flex items-center gap-1 text-xs font-medium text-muted-foreground",onClick:x=>x.stopPropagation(),children:[e.jsx("input",{type:"checkbox",checked:h,onChange:E,className:"h-3.5 w-3.5"}),"Select"]}):e.jsx("span",{}),e.jsx("button",{type:"button","aria-disabled":!k||void 0,tabIndex:k?void 0:-1,className:le("text-sm w-6 h-6 flex items-center justify-center rounded-full transition-all",k?"cursor-pointer hover:ring-2 hover:ring-primary/40":"cursor-default",s.isToday&&"bg-primary text-primary-foreground",!s.isCurrentMonth&&"text-muted-foreground"),onClick:x=>{x.stopPropagation(),k&&g?.(s.date)},children:O(s.date,"d")})]}),e.jsxs("div",{className:"space-y-1",style:_>0?{paddingTop:_*24}:void 0,children:[N.map(x=>{const f=ns(x);return e.jsxs("button",{type:"button",className:le("relative flex w-full items-center gap-1 overflow-hidden rounded border px-1.5 py-0.5 pr-3 text-left text-xs truncate shadow-xs",x.status==="failed"?"border-destructive/40 bg-destructive/10 text-destructive":""),style:x.status!=="failed"?{backgroundColor:f.backgroundColor,borderColor:f.borderColor,color:f.textColor}:void 0,title:x.reason,children:[x.status!=="failed"?e.jsx("span",{className:"absolute bottom-0 right-0 top-0 w-1",style:{backgroundColor:f.assigneeRailColor}}):null,e.jsxs("span",{className:"truncate",children:[!x.isAllDay&&x.proposedStartTime?e.jsx("span",{className:"font-medium",children:O(new P(x.proposedStartTime,t),"h:mma").toLowerCase()}):null," ",x.eventTitle]})]},x._id)}),c.map(x=>e.jsx(At,{event:x,timeZone:t,onClick:()=>a(x)},x._id)),w>0&&e.jsxs("button",{type:"button",className:"w-full rounded-sm px-1 py-0.5 text-left text-xs font-medium text-primary underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:x=>{x.stopPropagation(),o({...s,events:T})},children:["+",w," more"]})]})]})}const Ot=["SUN","MON","TUE","WED","THU","FRI","SAT"],xe=7,Lt=34,Pt=24,Bt=22,$e=4;function zt(s,t){if(!s.proposedStartTime)return[];if(!s.isAllDay||!s.proposedEndTime)return[H(s.proposedStartTime,t)];const n=H(s.proposedStartTime,t),a=H(Math.max(s.proposedStartTime,s.proposedEndTime-1),t),r=[];let o=Q(n,t),g=n;for(;g<=a;)r.push(g),o=pe(o,1),g=H(o.getTime(),t);return r}
1function $t({currentDate:s,calendarStart:t,calendarEnd:n,events:a,timeZone:r,onDayClick:o,onEventClick:g,onEventDrop:p,onDateNavigate:m,bulkSelecting:h=!1,selectedBulkDateKeys:E,onBulkToggleDay:N,previewProposals:b=[]}){const _=Os(r),[S,y]=u.useState(null),T=u.useMemo(()=>Ls({start:t,end:n}).map(C=>{const l=a.filter(x=>{if(x.isAllDay)return Ps(x,C,r);const f=new P(x.startTime,r);return ge(f,C)});return{date:C,isCurrentMonth:rs(C,s),isToday:ge(C,_),events:as(l)}}),[t,n,s,a,r,_]),I=u.useMemo(()=>{const i=new Map;for(const C of b)for(const l of zt(C,r)){const x=i.get(l)??[];x.push(C),i.set(l,x)}return i},[b,r]),c=u.useMemo(()=>{const i=[];for(let C=0;C<T.length;C+=xe)i.push(T.slice(C,C+xe));return i},[T]),w=u.useMemo(()=>{const i=Bs(a,T.map(C=>C.date),r,xe);return c.map((C,l)=>i.filter(x=>x.rowIndex===l))},[T,a,r,c]),j=u.useMemo(()=>{const i=new Set;for(const C of w)for(const l of C)i.add(String(l.event._id));return i},[w]),k=H(_.getTime(),r);return e.jsxs("div",{className:"flex flex-col h-full bg-white dark:bg-background",children:[e.jsx("div",{className:"grid grid-cols-7 border-b border-border",children:Ot.map(i=>e.jsx("div",{className:"px-2 py-2 text-xs font-medium text-muted-foreground text-center border-r border-border last:border-r-0",children:i},i))}),e.jsx("div",{className:"grid flex-1",style:{gridTemplateRows:`repeat(${c.length}, minmax(120px, 1fr))`},children:c.map((i,C)=>{const l=w[C]??[],x=l.length>0?Math.max(...l.map(f=>f.lane))+1:0;return e.jsxs("div",{className:"relative grid min-h-0 grid-cols-7",children:[i.map(f=>{const B=H(f.date.getTime(),r),$=B>=k&&f.events.some(X=>!se(X));return e.jsx(Rt,{day:f,timeZone:r,onClick:()=>o(f.date),onEventClick:g,onEventDrop:p,onShowMore:y,onDateNavigate:m,bulkSelecting:h,bulkCanSelect:$,bulkSelected:E?.has(B)??!1,onBulkToggleDay:()=>N?.(B),previewProposals:I.get(B)??[],omittedEventIds:j,reservedAllDayRows:x},f.date.toISOString())}),e.jsx("div",{className:"pointer-events-none absolute inset-0",children:l.map(f=>e.jsx(zs,{event:f.event,onClick:g,startsBefore:f.startsBefore,continuesAfter:f.continuesAfter,draggable:!se(f.event),className:"pointer-events-auto absolute h-[22px]",style:{left:`calc(${f.startIndex/xe*100}% + ${$e}px)`,width:`calc(${f.span/xe*100}% - ${$e*2}px)`,top:Lt+f.lane*Pt,height:Bt}},`${f.event._id}-${f.rowIndex}`))})]},`week-${C}`)})}),S&&e.jsx($s,{day:S,open:S!==null,timeZone:r,onOpenChange:i=>{i||y(null)},onEventClick:g})]})}function Vt(s,t){switch(t){case"month":return O(s,"MMMM yyyy");case"week":{const n=ss(s),a=ts(s);return rs(n,a)?`${O(n,"MMM d")} - ${O(a,"d, yyyy")}`:Ws(n,a)?`${O(n,"MMM d")} - ${O(a,"MMM d, yyyy")}`:`${O(n,"MMM d, yyyy")} - ${O(a,"MMM d, yyyy")}`}case"day":case"dispatch":case"route":return O(s,"EEEE, MMMM d, yyyy")}}function Ft({currentDate:s,timeZone:t,view:n,onViewChange:a,onToday:r,onPrevMonth:o,onNextMonth:g,onPrevWeek:p,onNextWeek:m,onPrevDay:h,onNextDay:E,onNewEvent:N,onBulkReschedule:b,bulkRescheduleDisabled:_,bulkControls:S}){const y=()=>{switch(n){case"month":o();break;case"week":p();break;case"day":case"dispatch":case"route":h();break}},T=()=>{switch(n){case"month":g();break;case"week":m();break;case"day":case"dispatch":case"route":E();break}};return e.jsxs("header",{className:`flex items-center justify-between px-4 py-3 border-b border-border bg-card ${n==="route"?"flex-wrap gap-3":""}`,children:[e.jsxs("div",{className:`flex items-center gap-4 ${n==="route"?"flex-wrap":""}`,children:[e.jsx(R,{variant:"outline",size:"sm",onClick:r,children:"Today"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(R,{variant:"ghost",size:"icon",onClick:y,children:e.jsx(Vs,{size:18})}),e.jsx(R,{variant:"ghost",size:"icon",onClick:T,children:e.jsx(Fs,{size:18})})]}),e.jsx("h2",{className:"text-lg font-semibold",children:Vt(s,n)})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t.replace(/_/g," ")}),S||(b?e.jsx(R,{variant:"outline",size:"sm",disabled:_,onClick:b,children:"Bulk Reschedule"}):null),S?null:e.jsxs(Me,{value:n,onValueChange:I=>a(I),children:[e.jsx(_e,{className:n==="route"?"w-[140px]":"w-[110px]",children:e.jsx(Ae,{})}),e.jsxs(Re,{children:[e.jsx(G,{value:"month",children:"Month"}),e.jsx(G,{value:"week",children:"Week"}),e.jsx(G,{value:"day",children:"Day"}),e.jsx(G,{value:"dispatch",children:"Dispatch"}),e.jsx(G,{value:"route",children:"Route"})]})]}),!S&&N?e.jsxs(R,{onClick:N,children:[e.jsx(Ks,{className:"mr-2",size:16}),"New Event"]}):null]})]})}function Kt({currentDate:s,timeZone:t,onDateSelect:n,filters:a,onFiltersChange:r}){return e.jsxs("aside",{className:"w-64 border-r border-border flex flex-col h-full overflow-hidden bg-card",children:[e.jsx("div",{className:"border-b border-border shrink-0",children:e.jsx(ls,{mode:"single",selected:s,onSelect:o=>o&&n(o),timeZone:t,noonSafe:!0,className:"w-full rounded-none p-0"})}),e.jsx(is,{filters:a,onFiltersChange:r})]})}const Wt="EXTERNAL_EVENTS_NOT_RESCHEDULABLE",ds="External sync events cannot be bulk rescheduled in ProLine. Reschedule them in the system they came from and select a day with at least one ProLine event to continue.";
1function Ve(s){const t=H(Date.now(),s),n=Q(t,s),a=pe(n,1);return H(a.getTime(),s)}function Fe(s,t){return H(new P(s,t).getTime(),t)}function Ht(s,t,n){const a=Q(t,n),r=oe(a,0,0,n).getTime(),o=oe(pe(a,1),0,0,n).getTime();return s.startTime<o&&s.endTime>r}function Ne(s,t){return s===null?!0:s.length===0?!1:t!==void 0&&s.includes(t)}function Yt(s,t){return Ne(t.calendarIds,s.calendarId)&&Ne(t.assigneeIds,s.assigneeId)&&Ne(t.locationIds,s.locationId)&&Ne(t.eventTypeIds,s.eventTypeId)}function Ut(s){const t=st(s);return typeof t=="object"&&t!==null&&"code"in t&&t.code===Wt?ds:s instanceof Error?s.message:"Could not preview schedule"}function qt({open:s,onOpenChange:t,timeZone:n,selectedDateKeys:a,events:r,filters:o,onPreviewReady:g}){const p=Te(L.operations.events.bulkReschedule.createSession),m=Je(L.operations.events.bulkReschedule.previewSession),[h,E]=u.useState(()=>Ve(n)),[N,b]=u.useState("wave"),[_,S]=u.useState(!1),[y,T]=u.useState(!1),[I,c]=u.useState(""),w=gt(I),[j,k]=u.useState(!1),[i,C]=u.useState(!1),[l,x]=u.useState(!1),[f,B]=u.useState(!1),[$,X]=u.useState(!1),z=u.useRef(null),D=u.useMemo(()=>{const v=[...a].sort(),M=v[v.length-1],A=M?Fe(pe(Q(M,n),1),n):Ve(n),Y=Fe(Hs(new P(Date.now(),n),1),n);return{minimumDateKey:A,maximumDateKey:Y,hasValidRange:A<=Y}},[a,n]),ie=o.assigneeIds===null||o.assigneeIds.length>1;u.useEffect(()=>{(h<D.minimumDateKey||h>D.maximumDateKey)&&E(D.minimumDateKey)},[D.maximumDateKey,D.minimumDateKey,h]);const q=u.useMemo(()=>{if(a.length===0)return null;const v=new Set;let M=!1;for(const A of a){const Y=r.filter(J=>Ht(J,A,n)&&Yt(J,o)),te=Y.some(J=>!se(J)),me=Y.filter(se);M||=te;for(const J of me)v.add(J._id)}return v.size===0?null:{externalCount:v.size,isBlocking:!M}},[r,o,a,n]),ce=u.useMemo(()=>oe(Q(h,n),0,0,n).getTime(),[h,n]),ke=v=>{const M=`{{${v}}}`,A=z.current,Y=A?.selectionStart??I.length,te=A?.selectionEnd??Y,me=I.slice(0,Y)+M+I.slice(te),J=w.limitChange(me);c(J.value);const ne=Y+M.length;setTimeout(()=>{z.current?.focus(),z.current?.setSelectionRange(ne,ne)},0)},De=u.useMemo(()=>{const[v,M,A]=h.split("-").map(Number);return new P(v,M-1,A,12,0,0,n)},[h,n]),fe=async()=>{if(a.length===0){W.error("Select at least one day");return}if(!q?.isBlocking){if(!D.hasValidRange){W.error("The selected days are too far in the future to bulk reschedule");return}if(h<D.minimumDateKey||h>D.maximumDateKey){W.error("Choose a start date within the allowed range");return}B(!0);try{const v=await p({selectedDateKeys:a,timezone:n,dateMinimum:ce,rescheduleType:N,allowWeekends:_,allowReassignment:ie?l:!1,sendSms:y,smsMessage:y&&I.trim()?I.trim():void 0,sendInternalEmail:i,calendarIds:o.calendarIds??void 0,assigneeIds:o.assigneeIds??void 0,locationIds:o.locationIds??void 0,eventTypeIds:o.eventTypeIds??void 0});await m({sessionId:v}),g(v),t(!1),W.success("Preview ready")}catch(v){W.error(Ut(v))}finally{B(!1)}}},Z=u.useMemo(()=>{const v=[...a].sort();return v.length===0?"":v.length===1?`For ${O(Q(v[0],n),"MMM d")}`:`From ${O(Q(v[0],n),"MMM d")} to ${O(Q(v[v.length-1],n),"MMM d")}`},[a,n]),de=N==="wave"?"Events on the selected days will be rebooked starting from the date you select above and will push other events to make room for them, keeping the chronological order":"Events on the selected days will be rescheduled to the next available slot from the date you select above",ue=q?q.isBlocking?ds:`${q.externalCount} external synced ${q.externalCount===1?"event will":"events will"} stay on the calendar and will not be moved.`:null;return e.jsx(Ys,{open:s,onOpenChange:t,children:e.jsxs(Us,{className:"max-h-[calc(100vh-2rem)] gap-0 overflow-hidden p-0 sm:max-w-[860px]",children:[e.jsxs(qs,{className:"border-b px-8 py-6 pr-14",children:[e.jsxs(Js,{className:"text-2xl leading-tight text-muted-foreground",children:["Reschedule ",a.length," ",a.length===1?"day":"days"]}),e.jsx(Qs,{className:"text-base font-semibold text-muted-foreground",children:Z})]}),e.jsxs("div",{className:"max-h-[calc(100vh-15rem)] space-y-5 overflow-y-auto px-8 py-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{children:"Reschedule events starting"}),e.jsxs(Xe,{open:$,onOpenChange:X,children:[e.jsx(Ze,{asChild:!0,children:e.jsxs(R,{type:"button",variant:"outline",className:"h-12 w-full justify-start text-left font-normal",children:[e.jsx(Gs,{className:"mr-2 size-4 text-muted-foreground"}),O(Q(h,n),"MMM d, yyyy")]})}),e.jsx(es,{className:"z-[80] w-auto p-0",align:"start",children:e.jsx(ls,{mode:"single",selected:De,onSelect:v=>{if(!v)return;const M=new P(v.getTime(),n),A=`${M.getFullYear()}
1-${String(M.getMonth()+1).padStart(2,"0")}-${String(M.getDate()).padStart(2,"0")}`;if(A<D.minimumDateKey||A>D.maximumDateKey){W.error("Choose a date after the selected days and within one year");return}E(A),X(!1)},timeZone:n,noonSafe:!0,disabled:v=>{const M=new P(v.getTime(),n),A=`${M.getFullYear()}-${String(M.getMonth()+1).padStart(2,"0")}-${String(M.getDate()).padStart(2,"0")}`;return A<D.minimumDateKey||A>D.maximumDateKey},className:"rounded-md p-3 [--cell-size:--spacing(8)]"})})]}),D.hasValidRange?null:e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:"The selected days are too far in the future to bulk reschedule."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{htmlFor:"bulk-reschedule-type",children:"Type of reschedule"}),e.jsxs(Me,{value:N,onValueChange:v=>b(v),children:[e.jsx(_e,{id:"bulk-reschedule-type",className:"w-full",children:e.jsx(Ae,{})}),e.jsxs(Re,{children:[e.jsx(G,{value:"wave",children:"Wave Reschedule"}),e.jsx(G,{value:"next_available",children:"Next Available Slot"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-md bg-muted px-4 py-3 text-sm text-muted-foreground",children:[e.jsx(Xs,{className:"size-4 shrink-0"}),e.jsx("span",{className:"font-medium",children:de})]}),ue?e.jsxs("div",{className:q?.isBlocking?"flex items-center gap-3 rounded-md border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive":"flex items-center gap-3 rounded-md border border-amber-300 bg-amber-50 px-4 py-3 text-sm text-amber-900",role:q?.isBlocking?"alert":"status",children:[e.jsx(yt,{className:"size-4 shrink-0"}),e.jsx("span",{className:"font-medium",children:ue})]}):null,e.jsxs("div",{className:"space-y-3",children:[e.jsx(F,{children:"Additional Settings"}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(K,{checked:_,onCheckedChange:v=>S(v===!0)}),"Allow rescheduling on weekends"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(K,{checked:y,onCheckedChange:v=>T(v===!0)}),"Send SMS notification to customers"]}),y?e.jsxs("div",{className:"rounded-md bg-muted p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx(F,{htmlFor:"bulk-sms-message",children:"SMS Message"}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("button",{type:"button",className:"font-medium text-primary underline underline-offset-2",onClick:()=>k(!0),children:"Show Variables"}),e.jsx("span",{className:"text-muted-foreground",children:"Event details are appended automatically"})]})]}),e.jsx(ft,{ref:z,id:"bulk-sms-message",acceptVariables:!0,value:I,onChange:v=>{const M=w.limitChange(v.target.value);c(M.value)},placeholder:"Type here..."}),e.jsx(pt,{messageCount:w.messageCount,limitMessage:w.limitMessage,className:"mt-2"})]}):null,e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(K,{checked:i,onCheckedChange:v=>C(v===!0)}),"Send internal email notification to team members"]}),ie?e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(K,{checked:l,onCheckedChange:v=>x(v===!0)}),"Allow events to be reassigned"]}):null]})]}),e.jsxs(Zs,{className:"border-t px-8 py-5 sm:justify-center",children:[e.jsx(R,{type:"button",variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(R,{type:"button",disabled:f||q?.isBlocking===!0||!D.hasValidRange,onClick:fe,children:f?"Finding Available Slots...":"Preview New Schedule"})]}),e.jsx(et,{open:j,onOpenChange:k,onSelect:ke,selectActionLabel:"Click to insert into the message."})]})})}const Jt=/^\d{4}-\d{2}-\d{2}$/,us=1440*60*1e3;function Ie(s){if(!Jt.test(s))return null;const t=Date.parse(`${s}T00:00:00.000Z`);return Number.isFinite(t)&&new Date(t).toISOString().slice(0,10)===s?t:null}function Qt(s,t){const n=Ie(s);return n===null?s:new Date(n+t*us).toISOString().slice(0,10)}function Gt({eventStartTime:s,eventEndTime:t,eventTimeZone:n,dropDate:a,calendarTimeZone:r}){const o=H(s,n),g=H(t,n),p=Ie(o),m=Ie(g),h=p===null||m===null?0:Math.max(0,Math.round((m-p)/us)),E=H(a.getTime(),r);return{allDayStartDate:E,allDayEndDate:Qt(E,h)}}const Xt=10080*60*1e3,Ke=60,Zt="CALENDAR_QUERY_CAPACITY_EXCEEDED";function We(s){return s.message.includes(Zt)}function He(s,t){if(!Number.isSafeInteger(s))throw new Error(`${t} must be a finite integer timestamp`)}function en(s){if(He(s.start,"Calendar range start"),He(s.end,"Calendar range end"),s.end<s.start)throw new Error("Calendar range end must be on or after its start");const t=[];let n=s.start;for(;n<=s.end;){const a=Math.min(s.end,n+Xt);if(t.push({start:n,end:a}),t.length>Ke)throw new Error(`Calendar range exceeds ${Ke} query segments`);n=a+1}return t}function sn(s,t){const n=new Map;for(let a=0;a<s;a+=1){const r=t[`range-${a}`];if(r instanceof Error)return{data:void 0,error:r};
1if(r===void 0)return{data:void 0,error:void 0};for(const o of r)n.set(o._id,o)}return{data:[...n.values()].sort((a,r)=>a.startTime===r.startTime?a._id.localeCompare(r._id):a.startTime-r.startTime),error:void 0}}function tn(s){const t=u.useMemo(()=>en({start:s.startDate,end:s.endDate}),[s.endDate,s.startDate]),n=u.useMemo(()=>Object.fromEntries((s.enabled===!1?[]:t).map((o,g)=>[`range-${g}`,{query:L.crud.events.getByDateRange,args:{startDate:o.start,endDate:o.end,...s.filters.calendarIds===null?{}:{calendarIds:s.filters.calendarIds},...s.filters.assigneeIds===null?{}:{assigneeIds:s.filters.assigneeIds},...s.filters.locationIds===null?{}:{locationIds:s.filters.locationIds},...s.filters.eventTypeIds===null?{}:{eventTypeIds:s.filters.eventTypeIds}}}])),[s.enabled,s.filters.assigneeIds,s.filters.calendarIds,s.filters.eventTypeIds,s.filters.locationIds,t]),a=Qe(n),r=u.useMemo(()=>sn(t.length,a),[t,a]);return{events:r.data,error:r.error}}function bn(){const{company:s,user:t}=os(),{timeZone:n,isLoading:a}=tt();return a||!n?e.jsx("div",{className:"flex h-full bg-white dark:bg-background items-center justify-center",children:e.jsx(nt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx(nn,{timeZone:n},`${n}:${s?._id}:${t?._id}`)}function nn({timeZone:s}){const t=_t(s),{user:n}=os(),a=at(),r=Te(L.crud.users.setCalendarDefaultView),o=n?.calendarDefaultView??"month",[g,p]=u.useState(null),h=wt(g??o),E=d=>{p(d),r({view:d}).catch(()=>W.error("Could not save your calendar view"))},[N,b]=rt(n?.currentCompany,n?._id),[_,S]=u.useState(!1),[y,T]=u.useState(!1),[I,c]=u.useState(!1),[w,j]=u.useState("idle"),[k,i]=u.useState(()=>new Set),[C,l]=u.useState(null),[x,f]=u.useState(null),[B,$]=u.useState(!1),[X,z]=u.useState(null),[D,ie]=u.useState(null),{hasPermission:q}=lt(),ce=q("general.view_all_events"),ke=Te(L.operations.events.bulkReschedule.confirmSession),De=Te(L.operations.events.bulkReschedule.cancelSession),{openProject:fe}=ot(),{events:Z,error:de}=tn({enabled:h!=="route",startDate:t.calendarStart.getTime(),endDate:t.calendarEnd.getTime(),filters:N}),ue=re(L.operations.events.bulkReschedule.getSessionPreview,C?{sessionId:C}:"skip"),v=d=>{z(null),f(oe(d,9,0,s)),$(!1),S(!0)},M=(d,V,U,ee)=>{z(null),f(oe(d,V,U,s)),$(!0),S(!0)},A=d=>{z(d),f(null),$(!1),S(!0)},Y=d=>{t.goToDate(d)},te=d=>{t.goToDate(d),E("day")},me=()=>{z(null),f(null),$(!1),S(!0)},J=()=>{j("selecting"),i(new Set),l(null)},ne=()=>{j("idle"),i(new Set),l(null),c(!1)},ms=d=>{i(V=>{const U=new Set(V);
1return U.has(d)?(U.delete(d),U):U.size>=5?(W.error("Select at most 5 days"),V):(U.add(d),U)})},hs=async()=>{if(C)try{await De({sessionId:C})}catch(d){W.error(d instanceof Error?d.message:"Could not cancel session");return}ne()},xs=async()=>{if(C)try{await ke({sessionId:C}),W.success("All events have been rescheduled successfully."),ne()}catch(d){W.error(d instanceof Error?d.message:"Could not confirm schedule")}},gs=d=>{S(d),d||(T(!1),z(null),f(null),$(!1),ie(null))},ps=u.useCallback(d=>{T(!0),fe({projectId:d,initialTab:"events",onClose:()=>T(!1)})},[fe]),ye=(d,V,U)=>{if(se(d))return;const ee=new P(d.startTime,s),js=new P(d.endTime,s),Ee=new P(V.getTime(),s),bs=!ge(ee,Ee),Le=js.getTime()-ee.getTime();let ae,ve;if(mt(V,s))ae=new Date(V.getTime()),ve=new Date(ae.getTime()+Le);else{if(ge(ee,Ee)&&U===void 0)return;ge(ee,Ee)?(ae=new Date(d.startTime),ve=new Date(d.endTime)):(ae=oe(V,ee.getHours(),ee.getMinutes(),s),ve=new Date(ae.getTime()+Le))}const Cs=d.isAllDay&&bs?Gt({eventStartTime:d.startTime,eventEndTime:d.endTime,eventTimeZone:d.displayTimeZone??s,dropDate:V,calendarTimeZone:s}):{};ie({newStart:ae,newEnd:ve,assigneeId:U,...Cs}),z(d),$(!1),S(!0)},fs=ue?.proposals??[],Oe=w==="preview"?fs.map(d=>({_id:d._id,eventId:d.eventId,eventTitle:d.eventTitle,isAllDay:d.isAllDay,eventTypeColor:d.eventTypeColor,assigneeColor:d.assigneeColor,proposedStartTime:d.proposedStartTime,proposedEndTime:d.proposedEndTime,status:d.status,reason:d.reason})):[],ys=new Set(Oe.map(d=>d.eventId)),he=w==="preview"&&Z?Z.filter(d=>!ys.has(d._id)):Z,vs=w==="selecting"?e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx("span",{className:"font-medium text-primary",children:k.size===0?"Select days you want to reschedule":`You selected ${k.size} ${k.size===1?"day":"days"}`}),e.jsx(R,{size:"sm",disabled:k.size===0,onClick:()=>c(!0),children:"Reschedule Days"}),e.jsx(R,{size:"sm",variant:"outline",onClick:ne,children:"Cancel"})]}):w==="preview"?e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsxs("span",{className:"font-medium text-primary",children:[ue?.session.rescheduleType==="next_available"?"Next Available Slot":"Wave Reschedule",": Please review and confirm this new schedule"]}),e.jsx(R,{size:"sm",variant:"outline",onClick:hs,children:"Cancel"}),e.jsx(R,{size:"sm",onClick:xs,children:"Confirm"})]}):null;return e.jsxs("div",{className:"flex h-full bg-white dark:bg-background",children:[ce&&h!=="route"?e.jsx(Kt,{currentDate:t.currentDate,timeZone:s,onDateSelect:Y,filters:N,onFiltersChange:b}):null,e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(Ft,{currentDate:t.currentDate,timeZone:s,view:h,onViewChange:E,onToday:t.goToToday,onPrevMonth:t.goToPrevMonth,onNextMonth:t.goToNextMonth,onPrevWeek:t.goToPrevWeek,onNextWeek:t.goToNextWeek,onPrevDay:t.goToPrevDay,onNextDay:t.goToNextDay,onNewEvent:me,onBulkReschedule:h==="month"&&w==="idle"?J:void 0,bulkRescheduleDisabled:Z===void 0||!ce,bulkControls:vs}),e.jsx("div",{className:"flex-1 overflow-auto",children:h==="route"&&n?e.jsx(Mt,{currentDate:t.currentDate,timeZone:s,userId:n._id,canViewAllEvents:ce,initialFilters:N,onEventClick:d=>{a.query(L.crud.events.getById,{id:d}).then(V=>{V&&A(V)}).catch(()=>W.error("Could not open this event"))}}):de?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[e.jsx("p",{className:"font-medium",children:We(de)?"Calendar range is too busy":"Calendar couldn’t be loaded"}),e.jsx("p",{className:"max-w-md text-sm text-muted-foreground",children:We(de)?"Narrow the people or calendars in the sidebar, then try again.":"Try resetting the filters. If this keeps happening, contact support."}),e.jsx(R,{size:"sm",variant:"outline",onClick:()=>b(it(n?._id)),children:"Reset filters"})]}):he===void 0?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading..."})}):h==="month"?e.jsx($t,{currentDate:t.currentDate,calendarStart:t.calendarStart,calendarEnd:t.calendarEnd,events:he,timeZone:s,onDayCl
1ick:v,onEventClick:A,onEventDrop:ye,onDateNavigate:te,bulkSelecting:w==="selecting",selectedBulkDateKeys:k,onBulkToggleDay:ms,previewProposals:Oe}):h==="week"?e.jsx(ct,{currentDate:t.currentDate,events:he,timeZone:s,onTimeSlotClick:M,onEventClick:A,onEventDrop:ye,onDateNavigate:te}):h==="day"?e.jsx(dt,{currentDate:t.currentDate,events:he,timeZone:s,onTimeSlotClick:M,onEventClick:A,onEventDrop:ye}):e.jsx(ut,{currentDate:t.currentDate,events:he,timeZone:s,assigneeIds:N.assigneeIds,onTimeSlotClick:M,onEventClick:A,onEventDrop:ye})})]}),e.jsx(vt,{open:_,onOpenChange:gs,defaultDate:x,defaultDateIsExplicitTimeSlot:B,onOpenProject:ps,allowBackgroundInteraction:y,preventOutsideDismiss:y,event:X,calendarTimeZone:s,dragDropDates:D}),e.jsx(qt,{open:I,onOpenChange:c,timeZone:s,selectedDateKeys:[...k].sort(),events:Z??[],filters:N,onPreviewReady:d=>{l(d),j("preview")}})]})}export{bn as EventsPage};

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.