import{r as O,u as pe,j as r,c as ge,a as ye,g as ve,b as be,d as J,L as xe,e as le,f as ue,h as je,i as we,k as Ve,C as Se,R as re,l as se,m as Q,B as ce,n as Ce}from"./index-B92aEPQH.js";import{P as Ee}from"./PageBreadcrumb-Dsn9CkpH.js";import{S as Ne,r as Oe}from"./SessionVitalsModal-DDMDFsin.js";import{C as ie,a as oe}from"./Card-DPmHd5BI.js";import{T as Pe}from"./Table-BCHyhTAY.js";import"./PageMetaData-DFmRpQLs.js";import"./Modal-D4T7V4-p.js";import"./FormCheck-QYGhbIhB.js";import"./FormContext-IkkKm1bh.js";import"./FormControl-BhzYseFY.js";const he=O.forwardRef(({bsPrefix:o,bg:V="primary",pill:g=!1,text:f,className:S,as:d="span",...i},l)=>{const c=pe(o,"badge");return r.jsx(d,{ref:l,...i,className:ge(S,c,g&&"rounded-pill",f&&`text-${f}`,V&&`bg-${V}`)})});he.displayName="Badge";var X={},Z={exports:{}},Re=Z.exports,de;function Fe(){return de||(de=1,(function(o,V){(function(g,f){f(V)})(Re,(function(g){var f=function(){return f=Object.assign||function(d){for(var i,l=1,c=arguments.length;ln.endVal;n.frameVal=y?n.endVal:n.frameVal,n.frameVal=Number(n.frameVal.toFixed(n.options.decimalPlaces)),n.printValue(n.frameVal),p1?n.options.decimal+G[1]:"",n.options.useGrouping){b="";for(var v=3,T=0,P=0,k=y.length;Pwindow.scrollY&&i.paused?(i.paused=!1,setTimeout((function(){return i.start()}),i.options.scrollSpyDelay),i.options.scrollSpyOnce&&(i.once=!0)):(window.scrollY>m||n>l)&&!i.paused&&i.reset()}},d.prototype.determineDirectionAndSmartEasing=function(){var i=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>i;var l=i-this.startVal;if(Math.abs(l)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=i;var c=this.countDown?1:-1;this.endVal=i+c*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=i,this.finalEndVal=null;this.finalEndVal!==null?this.useEasing=!1:this.useEasing=this.options.useEasing},d.prototype.start=function(i){this.error||(this.options.onStartCallback&&this.options.onStartCallback(),i&&(this.options.onCompleteCallback=i),this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},d.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},d.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},d.prototype.update=function(i){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(i),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,this.finalEndVal==null&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},d.prototype.printValue=function(i){var l;if(this.el){var c=this.formattingFn(i);!((l=this.options.plugin)===null||l===void 0)&&l.render?this.options.plugin.render(this.el,c):this.el.tagName==="INPUT"?this.el.value=c:this.el.tagName==="text"||this.el.tagName==="tspan"?this.el.textContent=c:this.el.innerHTML=c}},d.prototype.ensureNumber=function(i){return typeof i=="number"&&!isNaN(i)},d.prototype.validateValue=function(i){var l=Number(i);return this.ensureNumber(l)?l:(this.error="[CountUp] invalid start or end value: ".concat(i),null)},d.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},d.prototype.parse=function(i){var l=function(p){return p.replace(/([.,'  ])/g,"\\$1")},c=l(this.options.separator),n=l(this.options.decimal),m=i.replace(new RegExp(c,"g"),"").replace(new RegExp(n,"g"),".");return parseFloat(m)},d})();g.CountUp=S}))})(Z,Z.exports)),Z.exports}var fe;function Ue(){if(fe)return X;fe=1,Object.defineProperty(X,"__esModule",{value:!0});var o=ye(),V=Fe();function g(a,t){var e=a==null?null:typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(e!=null){var s,u,h,F,C=[],x=!0,j=!1;try{if(h=(e=e.call(a)).next,t!==0)for(;!(x=(s=h.call(e)).done)&&(C.push(s.value),C.length!==t);x=!0);}catch(w){j=!0,u=w}finally{try{if(!x&&e.return!=null&&(F=e.return(),Object(F)!==F))return}finally{if(j)throw u}}return C}}function f(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(u){return Object.getOwnPropertyDescriptor(a,u).enumerable})),e.push.apply(e,s)}return e}function S(a){for(var t=1;t=0)&&(e[u]=a[u]);return e}function m(a,t){if(a==null)return{};var e=n(a,t),s,u;if(Object.getOwnPropertySymbols){var h=Object.getOwnPropertySymbols(a);for(u=0;u=0)&&Object.prototype.propertyIsEnumerable.call(a,s)&&(e[s]=a[s])}return e}function p(a,t){return y(a)||g(a,t)||E(a,t)||M()}function y(a){if(Array.isArray(a))return a}function E(a,t){if(a){if(typeof a=="string")return b(a,t);var e=Object.prototype.toString.call(a).slice(8,-1);if(e==="Object"&&a.constructor&&(e=a.constructor.name),e==="Map"||e==="Set")return Array.from(a);if(e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return b(a,t)}}function b(a,t){(t==null||t>a.length)&&(t=a.length);for(var e=0,s=new Array(t);e0?D.current=setTimeout(A,C*1e3):A(),j?.({pauseResume:B,reset:I,update:Y})}),B=v(function(){N().pauseResume(),w?.({reset:I,start:W,update:Y})}),I=v(function(){N().el&&(D.current&&clearTimeout(D.current),N().reset(),_?.({pauseResume:B,start:W,update:Y}))}),Y=v(function(A){N().update(A),L?.({pauseResume:B,reset:I,start:W})}),W=v(function(){I(),H()}),ae=v(function(A){h&&(A&&I(),H())});return o.useEffect(function(){U.current?F&&ae(!0):(U.current=!0,ae())},[F,U,ae,C,t.start,t.suffix,t.prefix,t.duration,t.separator,t.decimals,t.decimal,t.formattingFn]),o.useEffect(function(){return function(){I()}},[I]),{start:W,pauseResume:B,reset:I,update:Y,getCountUp:N}},te=["className","redraw","containerProps","children","style"],ne=function(t){var e=t.className,s=t.redraw,u=t.containerProps,h=t.children,F=t.style,C=m(t,te),x=o.useRef(null),j=o.useRef(!1),w=R(S(S({},C),{},{ref:x,startOnMount:typeof h!="function"||t.delay===0,enableReinitialize:!1})),_=w.start,L=w.reset,z=w.update,q=w.pauseResume,D=w.getCountUp,U=v(function(){_()}),$=v(function(B){t.preserveValue||L(),z(B)}),N=v(function(){if(typeof t.children=="function"&&!(x.current instanceof Element)){console.error(`Couldn't find attached element to hook the CountUp instance into! Try to attach "containerRef" from the render prop to a an Element, eg. .`);return}D()});o.useEffect(function(){N()},[N]),o.useEffect(function(){j.current&&$(t.end)},[t.end,$]);var H=s&&t;return o.useEffect(function(){s&&j.current&&U()},[U,s,H]),o.useEffect(function(){!s&&j.current&&U()},[U,s,t.start,t.suffix,t.prefix,t.duration,t.separator,t.decimals,t.decimal,t.className,t.formattingFn]),o.useEffect(function(){j.current=!0},[]),typeof h=="function"?h({countUpRef:x,start:_,reset:L,update:z,pauseResume:q,getCountUp:D}):o.createElement("span",c({className:e,ref:x,style:F},u),typeof t.start<"u"?D().formattingFn(t.start):"")};return X.default=ne,X.useCountUp=R,X}var Ae=Ue();const Me=ve(Ae),me=({item:o})=>{const{title:V,iconBg:g,icon:f,prefix:S,suffix:d,value:i}=o;return r.jsx(ie,{children:r.jsx(oe,{children:r.jsxs("div",{className:"d-flex justify-content-between align-items-center",children:[r.jsx("div",{className:"avatar fs-60 avatar-img-size flex-shrink-0",children:r.jsx("span",{className:`avatar-title bg-${g}-subtle text-${g} rounded-circle fs-24`,children:r.jsx(f,{})})}),r.jsxs("div",{className:"text-end",children:[r.jsx("h3",{className:"mb-2 fw-normal",children:r.jsx("span",{children:r.jsx(Me,{end:i,suffix:d,prefix:S})})}),r.jsx("p",{className:"mb-0 text-muted",children:r.jsx("span",{children:V})})]})]})})})};function Te(o){if(!o)return"";const[V,g,f]=o.split("-").map(Number);return new Date(V,g-1,f).toLocaleDateString(void 0,{weekday:"long",day:"numeric",month:"short",year:"numeric"})}function De(o){return o?[o.firstName,o.lastName].filter(Boolean).join(" "):""}function Ye(){const{can:o,user:V,isAdmin:g}=be(),[f,S]=O.useState({patients:0,pending:0,confirmed:0,rejected:0,users:0}),[d,i]=O.useState([]),[l,c]=O.useState({date:"",googleConnected:!0,canGenerate:!1}),[n,m]=O.useState(!0),[p,y]=O.useState(!1),[E,b]=O.useState(""),[M,G]=O.useState(null),[v,T]=O.useState(null),[P,k]=O.useState(""),R=V?.role?.systemKey==="educator",te=async()=>{m(!0),b("");try{const e=await J("/api/dashboard/meetings");i(e.meetings||[]),c({date:e.date||"",googleConnected:e.googleConnected!==!1,canGenerate:!!e.canGenerate})}catch(e){b(e.message||"Could not load today's meetings")}finally{m(!1)}};O.useEffect(()=>{J("/api/dashboard/stats").then(S).catch(()=>{}),te().catch(()=>{}),g&&J("/api/dashboard/coordinator").then(G).catch(()=>{})},[]);const ne=async()=>{y(!0),b("");try{const e=await J("/api/dashboard/meetings/generate",{method:"POST",body:{}});i(e.meetings||[]),c({date:e.date||l.date,googleConnected:e.googleConnected!==!1,canGenerate:!!e.canGenerate})}catch(e){b(e.message||"Could not generate meetings")}finally{y(!1)}},a=async e=>{k("");try{const s=await J(`/api/cohort-sessions/${e.id}`);T(Oe(s))}catch(s){k(s.message||"Could not open vitals")}},t=[...o("onboarding","view")?[{title:"Patients",value:f.patients,icon:xe,iconBg:"primary",url:"/onboarding"},{title:"Pending",value:f.pending,icon:le,iconBg:"warning",url:"/onboarding?list=pending"},{title:"Confirmed",value:f.confirmed,icon:ue,iconBg:"success",url:"/onboarding?list=confirmed"},{title:"Rejected",value:f.rejected,icon:je,iconBg:"danger",url:"/onboarding?list=rejected"}]:[],...g&&M?[{title:"Pending payments",value:M.pendingPayments,icon:le,iconBg:"warning",url:"/onboarding?list=pending"},{title:"Unmatched pool",value:M.unmatchedPool,icon:we,iconBg:"info",url:"/matching"},{title:"Leave to approve",value:M.leaveToApprove,icon:Ve,iconBg:"danger",url:"/leaves"},{title:"Reassignment queue",value:M.reassignmentQueue,icon:ue,iconBg:"secondary",url:"/matching"}]:[]];return r.jsxs(Se,{fluid:!0,children:[r.jsx(Ee,{title:"Dashboard"}),r.jsx(re,{children:r.jsx(se,{children:r.jsx(ie,{children:r.jsxs(oe,{children:[r.jsx("h5",{className:"mb-2",children:"Welcome to VirtualPR"}),r.jsx("p",{className:"text-muted mb-3",children:"Manage pulmonary rehab patients, cohorts, and PRT access from this dashboard."}),r.jsxs("div",{className:"d-flex flex-wrap gap-2",children:[o("onboarding","add")?r.jsx(Q,{className:"btn btn-success",to:"/onboarding/new",children:"Add patient"}):null,o("onboarding","view")?r.jsx(Q,{className:"btn btn-outline-success",to:"/onboarding",children:"Patients"}):null,o("users","view")?r.jsx(Q,{className:"btn btn-outline-secondary",to:"/users",children:"Manage users"}):null]})]})})})}),t.length?r.jsx(re,{className:"row-cols-xxl-4 row-cols-md-2 row-cols-1",children:t.map(e=>r.jsx(se,{children:e.url?r.jsx(Q,{to:e.url,className:"text-reset",children:r.jsx(me,{item:e})}):r.jsx(me,{item:e})},e.title))}):null,r.jsx(re,{children:r.jsx(se,{children:r.jsx(ie,{children:r.jsxs(oe,{children:[r.jsxs("div",{className:"d-flex flex-wrap justify-content-between align-items-start gap-2 mb-3",children:[r.jsxs("div",{children:[r.jsx("h5",{className:"mb-1",children:"Today's meetings"}),r.jsxs("p",{className:"text-muted mb-0",children:[l.date?Te(l.date):"Cohort sessions for today",R?" · repeat Meet series from your Google Calendar":" · one repeating Meet per cohort"]})]}),l.canGenerate?r.jsx(ce,{variant:"outline-primary",size:"sm",onClick:ne,disabled:p,children:p?"Creating meetings...":"Create repeat meetings"}):null]}),R&&!l.googleConnected?r.jsxs("div",{className:"alert alert-warning",children:["Connect Google Calendar on your ",r.jsx(Q,{to:"/profile",children:"Profile"})," so this morning's cohort sessions can get a Meet link from your account."]}):null,E?r.jsx("div",{className:"alert alert-danger",children:E}):null,P?r.jsx("div",{className:"alert alert-danger",children:P}):null,n?r.jsx("p",{className:"text-muted mb-0",children:"Loading today's meetings..."}):d.length?r.jsxs(Pe,{responsive:!0,className:"mb-0 align-middle",children:[r.jsx("thead",{children:r.jsxs("tr",{children:[r.jsx("th",{children:"Time"}),r.jsx("th",{children:"Cohort"}),g?r.jsx("th",{children:"Virtual PRT"}):null,r.jsx("th",{children:"Meet"})]})}),r.jsx("tbody",{children:d.map(e=>r.jsxs("tr",{children:[r.jsxs("td",{className:"text-nowrap",children:[e.startTime,e.endTime?` – ${e.endTime}`:""]}),r.jsxs("td",{children:[r.jsx("div",{className:"fw-semibold",children:e.cohort?.name||e.title}),e.status==="failed"?r.jsx("div",{className:"small text-danger",children:e.error||"Could not create Meet link"}):null]}),g?r.jsx("td",{children:De(e.virtualPrt)}):null,r.jsx("td",{children:r.jsxs("div",{className:"d-flex flex-wrap align-items-center gap-2",children:[e.meetUrl?r.jsxs("a",{className:"btn btn-sm btn-success",href:e.meetUrl,target:"_blank",rel:"noreferrer",children:[r.jsx(Ce,{className:"me-1"}),"Join Meet"]}):e.status==="failed"?r.jsx(he,{bg:"danger",children:"Failed"}):r.jsx("span",{className:"text-muted",children:"Pending"}),r.jsx(ce,{size:"sm",variant:"outline-primary",onClick:()=>a(e),children:"Vitals"})]})})]},e.id))})]}):r.jsx("p",{className:"text-muted mb-0",children:R?"No cohort session is scheduled for you today (or it falls on a holiday / leave day).":"No cohort sessions are scheduled today."})]})})})}),r.jsx(Ne,{roster:v,onChange:T,onClose:()=>T(null)})]})}export{Ye as default};