PageSourceSearch

https://pryntsevballet.com/assets/index-Bs03mqie.js

js pryntsevballet.com collected 2026-10-04 20:15:32 UTC 121,667 bytes, 6 lines download raw bytes

1import{r as l,j as e}from"./react-vendor-Bmz6tUQp.js";import{s as G,a$ as se,bk as Ye,bl as Qe,bn as Ve,m as Ht,D as jt,d as vt,e as kt,f as St,T as yt,g as os,c as Gt,aE as is,bd as cs,bb as lt,bY as ds,U as Yt,cZ as us,X as ps,bF as xs,S as ms,h as fs,i as hs,j as gs,k as wt,bj as ys,aG as Nt,dl as bs,db as js,l as vs,cx as ks}from"./index-yGQYYxOL.js";import{u as Ss}from"./useCanEditStaffPortal-DUJKi-sN.js";import{D as n,k as _s,a as _t,C as D,b as ws}from"./tokens-DbMxyJkJ.js";import{R as Ns,b as Cs,B as Ms,d as $s}from"./dedupeRosterSeats-MSDtglkx.js";import{e as Be}from"./eventPlacement-CxUvVAat.js";import{f as ae,S as Ct,b as Qt,p as Ts,h as Ds,c as Is,e as Ls,B as Ge,G as Fe}from"./date-utils-Ds47y5fu.js";import{C as Es}from"./calendar-CI5PK0Q8.js";import{s as je,d as $e,f as Ze,a as xe,b as de,t as be,D as ve,W as ke,c as we,e as bt}from"./WeekGrid-DN9yKwmy.js";import{a as Ne,u as Rs}from"./react-query-CqJKaf_6.js";import{S as As,a as Ps,b as Os,c as Bs}from"./sheet-E8V6rKho.js";import{A as zs,a as Fs,b as Ws}from"./avatar-Cu9l6v2F.js";import{g as Us}from"./avatars-FpSs625g.js";import{c as qs}from"./dob-8X7X1E_X.js";import{a as Hs}from"./checklistUtils-BF3l88q6.js";import{P as Gs}from"./progress-C2bS0x0J.js";import{S as Ys}from"./sticky-note-CR4n5q_e.js";import{P as Qs}from"./pin-CF8z_lhB.js";import{C as Vt}from"./CancelPrivateLessonDialog-DDfmv1wI.js";import{S as Zt,b as Vs,l as Zs,c as Xs,d as Js,s as Oe,e as Ks,a as en,f as tn,g as sn,Q as Xt}from"./StaffShiftsPanel-DpiAnNtz.js";import{D as nn,u as an,a as rn,M as ln,b as on}from"./MeetingsTab-DFqi1LKS.js";import{C as cn}from"./calendar-plus-KQ3iy_EA.js";import{u as dn}from"./hqScopeSwitcherSlot-ER1G-C7G.js";import"./supabase-CPi6FgBv.js";import"./posthog-B4nvxm9K.js";import"./radix-ui-ZQ4NEGId.js";import"./twilio-C1U8FCrE.js";import"./charts-DLQlTo8W.js";import"./db-DT2Nhm7F.js";import"./returnPrivateLessonFunding-BopnlTuv.js";import"./alert-N9R4W8y9.js";import"./dates-TkbJcaEO.js";import"./credit-card-DVHhs4a_.js";import"./dueBadge-BHZnyCm2.js";import"./TaskDialog-8MPHHPH4.js";import"./MyStudioOsBand-puEEUkc0.js";import"./useStudioKPIs-Qej2jo0D.js";import"./manualWeekKey-pYG-CpS4.js";import"./mirrorKeysAcrossHistory-BgCQw6dR.js";import"./fetchAllRows-C4cjR9P8.js";import"./paymentDescription-S6ACYrN5.js";import"./saleAmount-DqzHiSIY.js";import"./seasonQuarters-DJV8ER8Y.js";import"./useStudioFinanceAccess-wyub5ly3.js";import"./downloadAttachment-CLOL60G3.js";import"./link-2-CC_XOAG7.js";import"./arrow-up-fLJe0fUX.js";import"./arrow-down-YhA2-Eqi.js";import"./ellipsis-D2TBdRN-.js";import"./link-CApbTa29.js";import"./flag-Dg4EOWNJ.js";import"./useHqStaffBase-YIwCFYDQ.js";import"./studioOsTodos-CanFdF7A.js";import"./SetWorkScheduleDialog-BPpA5mSI.js";import"./cadence-dvMhVGps.js";import"./calendar-range-D9JrD0Wn.js";import"./settings-2-CF1etbe1.js";import"./EditMeetingTimeDialog-C8ICzBwl.js";import"./useHqViewerCanEdit-fo51L0gH.js";import"./layout-template-CrlpYtgy.js";import"./arrow-right-BBWc1p1Z.js";import"./video-CXDthndq.js";const ot=1e3;async function Mt(t){const a=[];for(let s=0;;s+=ot){const{data:r,error:i}=await t().range(s,s+ot-1);if(i)throw console.error("[schedule-v2] paged fetch failed",i),i;const c=r??[];if(a.push(...c),c.length<ot)break}return a}function it(t){const[a,s]=t.split(":").map(Number);return[a||0,s||0]}function un(t,a){const[s,r]=t.split(":").map(Number),i=(s||0)*60+(r||0)+(a||0);return[Math.floor(i/60),i%60]}function pn(t){return t==="attending"?"going":t==="maybe"?"maybe":t==="not_attending"?"no":null}function xn(t){return t==="going"?"attending":t==="maybe"?"maybe":t==="no"?"not_attending":null}function mn({studio:t,staff:a}){const[s,r]=l.useState(!0),[i,c]=l.useState([]),[o,m]=l.useState([]),[p,x]=l.useState(new Map),[h,g]=l.useState([]),[C,j]=l.useState({}),[I,$]=l.useState(0),[u,d]=l.useState({}),[f,N]=l.useState({}),R=l.useCallback(async()=>{if(!(t!=null&&t.id))return;const b=ae(Ct(new Date,6),"yyyy-MM-dd"),_=await Mt(()=>G.from("class_sessions").select("id, session_date, start_time, end_time, status, room, notes, teacher_id_override, classes!inner(id, name, teacher_id, start_date, staff_members(full_name))").eq("studio_id",t.id).is("classes.deleted_at",null).eq("classes.is_active",!0).is("deleted_at",null).gte("session_date",b).order("id")),L=ae(new Date,"yyyy-MM-dd"),z=F=>{var K;const J=(K=F.classes)==null?void 0:K.start_date;return J?F.session_date>=L&&F.session_date<J:!1},Y=(_||[]).filter(F=>!z(F)).map(F=>{var ee,O,w,P,ne;const J=((ee=F.classes)==null?void 0:ee.name)||"Class",K=((w=(O=F.classes)==null?void 0:O.staff_members)==null?void 0:w.full_name)||null,Q=F.teacher_id_override??((P=F.classes)==null?void 0:P.teacher_id)??null;return{id:F.id,kind:"classes",title:J,start:it(F.start_time),end:it(F.end_time),date:F.session_date,room:F.room||null,instructor:K,teacherId:Q,classId:((ne=F.classes)==null?void 0:ne.id)||null,sessionId:F.id,lessonStatus:F.status==="completed"||F.status==="cancelled"?F.status:"scheduled"}});c(Y);const v=Array.from(new Set((_||[]).map(F=>{var J;return(J=F.classes)==null?void 0:J.id}
1).filter(Boolean)));if(v.length>0){const{data:F}=await G.from("class_enrollments").select("class_id, student_id, session_id, status, students!inner(id)").in("class_id",v).in("status",Ns),J=Cs(F??[]),K={};for(const Q of F??[])Q.status==="active"&&(K[Q.class_id]=(K[Q.class_id]||0)+1);j(K),c(Q=>Q.map(ee=>({...ee,students:J(ee.classId??null,ee.sessionId??ee.id)})))}else j({})},[t==null?void 0:t.id]),U=l.useCallback(async()=>{var Y;if(!(t!=null&&t.id))return;const b=ae(Ct(new Date,6),"yyyy-MM-dd"),_=await Mt(()=>G.from("private_lessons").select("id, lesson_date, start_time, duration_minutes, price, room, status, payment_status, teacher_id, student_id, is_recurring, parent_lesson_id, student:students(id, first_name, last_name, family_id)").eq("studio_id",t.id).gte("lesson_date",b).order("id")),L=(_||[]).map(v=>{var Q,ee;const F=((Q=v.student)==null?void 0:Q.first_name)||"",J=((ee=v.student)==null?void 0:ee.last_name)||"",K=`${F} ${J}`.trim()||"Private lesson";return{id:v.id,kind:"privates",title:K,start:it(v.start_time),end:un(v.start_time,v.duration_minutes||30),date:v.lesson_date,room:v.room||null,status:v.payment_status==="paid"||v.payment_status==="credit"?"paid":"unpaid",isRecurring:!!v.is_recurring,price:typeof v.price=="number"?v.price:Number(v.price)||0,durationMinutes:v.duration_minutes||0,teacherId:v.teacher_id??null,lessonStatus:v.status==="completed"||v.status==="cancelled"?v.status:"scheduled"}});m(L);const z=new Map;for(const v of _||[])z.set(v.id,{id:v.id,student_id:v.student_id||(((Y=v.student)==null?void 0:Y.id)??""),teacher_id:v.teacher_id,studio_id:(t==null?void 0:t.id)||"",lesson_date:v.lesson_date,start_time:v.start_time,duration_minutes:v.duration_minutes||0,price:typeof v.price=="number"?v.price:Number(v.price)||0,status:v.status,payment_status:v.payment_status,credit_id:v.credit_id||null,pricing_tier_id:v.pricing_tier_id||null,is_recurring:!!v.is_recurring,parent_lesson_id:v.parent_lesson_id||null,room:v.room||null,student:v.student?{first_name:v.student.first_name,last_name:v.student.last_name,family_id:v.student.family_id}:null});x(z)},[t==null?void 0:t.id]),H=l.useCallback(async()=>{if(!(t!=null&&t.id))return;const b=new Date;b.setFullYear(b.getFullYear()-1);const _=new Date;_.setFullYear(_.getFullYear()+2);const{data:L}=await G.from("studio_events").select("*, google_calendar_event_id").eq("studio_id",t.id).gte("start_at",b.toISOString()).lte("start_at",_.toISOString()).order("start_at",{ascending:!1}),Y=(L||[]).slice().reverse().map(v=>{const F=Be(v.start_at)??new Date(v.start_at),J=v.end_at?Be(v.end_at)??new Date(v.end_at):null;return{id:v.id,title:v.title,date:new Date(F.getFullYear(),F.getMonth(),F.getDate()),start:[F.getHours(),F.getMinutes()],end:J?[J.getHours(),J.getMinutes()]:[F.getHours()+1,0],location:v.location||null,desc:v.description||null,meetingCategory:v.meeting_category||null,rsvp:null,attending:0,total:0,allDay:!!v.all_day,eventType:v.event_type||"general",startAt:v.start_at,endAt:v.end_at||null,googleCalendarEventId:v.google_calendar_event_id||null}});g(Y)},[t==null?void 0:t.id]),X=l.useCallback(async()=>{if(!(t!=null&&t.id)||h.length===0){d({});return}const b=h.map(z=>z.id),{data:_}=await G.from("event_rsvps").select("event_id, status").in("event_id",b).eq("status","attending"),L={};for(const z of _||[])L[z.event_id]=(L[z.event_id]||0)+1;d(L)},[t==null?void 0:t.id,h]),B=l.useCallback(async()=>{if(!(a!=null&&a.id)){N({});return}const{data:b}=await G.from("event_rsvps").select("event_id, status").eq("staff_id",a.id),_={};for(const L of b||[])_[L.event_id]=pn(L.status);N(_)},[a==null?void 0:a.id]),k=l.useCallback(async()=>{if(!(t!=null&&t.id))return;const{count:b}=await G.from("staff_members").select("id",{count:"exact",head:!0}).eq("studio_id",t.id).eq("status","active");$(b||0)},[t==null?void 0:t.id]),A=l.useCallback(async()=>{if(t!=null&&t.id){r(!0);try{await Promise.all([R(),U(),H(),k(),B()])}catch(b){console.error("[schedule-v2] reload failed",b),se.error("Couldn't load the whole schedule — some classes may be missing. Try again.")}finally{r(!1)}}},[t==null?void 0:t.id,R,U,H,k,B]);l.useEffect(()=>{t!=null&&t.id&&A()},[t==null?void 0:t.id,A]),l.useEffect(()=>{if(!(t!=null&&t.id))return;let b=null;const _=()=>{b&&clearTimeout(b),b=setTimeout(()=>{A()},1500)},L=`studio_id=eq.${t.id}`,z=[G.channel(`schedule-v2-class-sessions-${t.id}`).on("postgres_changes",{event:"*",schema:"public",table:"class_sessions",filter:L},_).subscribe(),G.channel(`schedule-v2-private-lessons-${t.id}`).on("postgres_changes",{event:"*",schema:"public",table:"private_lessons",filter:L},_).subscribe(),G.channel(`schedule-v2-studio-events-${t.id}`).on("postgres_changes",{event:"*",schema:"public",table:"studio_events",filter:L},_).subscribe(),G.channel(`schedule-v2-event-rsvps-${t.id}`).on("postgres_changes",{event:"*",schema:"public",table:"event_rsvps"},_).subscribe()];return()=>{b&&clearTimeout(b);for(const Y of z)G.removeChannel(Y)}},[t==null?void 0:t.id,A]),l.useEffect(()=>{h.length>0&&X()},[h,X]);const E=l.useCallback((b,_)=>{N(L=>({...L,[b]:_}))},[]),M=l.useMemo(()=>h.map(b=>({...b,rsvp:f[b.id]||null,attending:u[b.id]||0,total:I})),[h,f,u,I]),T=l.useMemo(()=>{const b=[];for(const _ of i)b.push(_);for(const _ of o)b.push(_);for(const _ of h){const L=Be(_.startAt)??new Date(_.startAt),z=_.endAt?Be(_.endAt)??new Date(_.endAt):null;b.push({id:_.id,kind:_.meetingCategory?"meetings":"events",meetingCategory:_.meetingCategory??null,title:_.title,start:[L.getHours(),L.getMinutes()],end:z?[z.getHours(),z.getMinutes()]:[L.getHours()+1,0],date:ae(L,"yyyy-MM-dd"),room:_.location,description:_.desc,startAt:_.startAt,endAt:_.endAt,allDay:_.allDay})}return b},[i,o,h]);return{loading:s,calendarItems:T,eventList:M,enrollmentCounts:C,rawClassSessions:i,rawPrivateLessons:o,rawStudioEvents:h,privateLessonById:p,reload:A,setRsvpLocal:E}}function Te({value:t,onChange:a,placeholder:s="Search…",size:r="md",className:i=""}){const c=r==="sm";return e.jsxs("div",{className:`relative inline-flex items-center ${i}`,style:{width:c?"100%":240},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"absolute left-[10px] pointer-events-none",style:{color:n.ink3},"aria-hidden":"true",children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{type:"search",value:t,onChange:o=>a(o.target.value),placeholder:s,className:`w-full rounded-full font-medium ${c?"pl-[28px] pr-[28px] py-[5px] text-[12px]":"pl-[30px] pr-[30px] py-[6px] text-[12px]"} focus:outline-none focus:ring-1`,style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink}}),t&&e.jsx("button",{type:"button",onClick:()=>a(""),className:"absolute right-[8px]","aria-label":"Clear search",style:{color:n.ink3},children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})}function $t(t,a,s){return a==="day"?Qt(t,s):a==="week"?Ts(t,s):Ds(t,s)}function fn(t,a){return a==="month"?ae(t,"MMMM yyyy"):a==="week"?`Week of ${ae(t,"MMM d, yyyy")}`:ae(t,"EEE, MMM d, yyyy")}function De({value:t,onChange:a,step:s="week",size:r="md"}){const[i,c]=l.useState(!1),o=r==="sm",m="inline-flex items-center justify-center rounded-full transition-colors",p=o?"w-[26px] h-[26px]":"w-[28px] h-[28px]",x=o?"px-[10px] py-[5px] text-[12px]":"px-[12px] py-[6px] text-[12px]";return e.jsxs("div",{className:"inline-flex items-center gap-[6px]",children:[e.jsx("button",{type:"button",onClick:()=>a($t(t,s,-1)),className:`${m} ${p}`,style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink2},"aria-label":"Previous",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsxs(Ye,{open:i,onOpenChange:c,children:[e.jsx(Qe,{asChild:!0,children:e.jsxs("button",{type:"button",className:`${m} ${x} font-semibold gap-[6px]`,style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{color:n.ink3},children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),e.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),e.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),fn(t,s)]})}),e.jsx(Ve,{className:"w-auto p-0",align:"center",children:e.jsx(Es,{mode:"single",selected:t,onSelect:h=>{h&&(a(h),c(!1))},initialFocus:!0})})]}),e.jsx("button",{type:"button",onClick:()=>a($t(t,s,1)),className:`${m} ${p}`,style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink2},"aria-label":"Next",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})}function Ie({value:t,onChange:a,size:s="md"}){const i=s==="sm"?"px-[10px] py-[5px] text-[12px]":"px-[12px] py-[6px] text-[12px]";function c(o){return{border:`1px solid ${o?n.primary:n.hair}`,background:o?n.primarySoft:n.bg,color:o?n.primary:n.ink3}}return e.jsxs("div",{className:"inline-flex items-center gap-[6px]",children:[e.jsxs("button",{type:"button",onClick:()=>a({...t,past:!t.past}),className:`inline-flex items-center gap-[6px] rounded-full font-semibold transition-colors ${i}`,style:c(t.past),"aria-pressed":t.past,children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"11 17 6 12 11 7"}),e.jsx("polyline",{points:"18 17 13 12 18 7"})]}),"Past"]}),e.jsxs("button",{type:"button",onClick:()=>a({...t,upcoming:!t.upcoming}),className:`inline-flex items-center gap-[6px] rounded-full font-semibold transition-colors ${i}`,style:c(t.upcoming),"aria-pressed":t.upcoming,children:["Upcoming",e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"13 17 18 12 13 7"}),e.jsx("polyline",{points:"6 17 11 12 6 7"})]})]})]})}function Le(t,a,s){return s.past===s.upcoming?!0:s.upcoming?t>
1=a:t<a}const hn=[{mode:"list",label:"List",icon:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),e.jsx("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})},{mode:"day",label:"Day",icon:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),e.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),e.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]})},{mode:"week",label:"Week",icon:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),e.jsx("line",{x1:"9",y1:"10",x2:"9",y2:"22"})]})},{mode:"month",label:"Month",icon:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),e.jsx("line",{x1:"9",y1:"10",x2:"9",y2:"22"}),e.jsx("line",{x1:"15",y1:"10",x2:"15",y2:"22"}),e.jsx("line",{x1:"3",y1:"16",x2:"21",y2:"16"})]})}];function Ee({value:t,onChange:a,size:s="md"}){const i=s==="sm"?"px-[10px] py-[5px] text-[12px]":"px-[12px] py-[6px] text-[12px]";return e.jsx("div",{className:"inline-flex items-center gap-[2px] rounded-full p-[3px]",style:{background:n.surface,border:`1px solid ${n.hair}`},children:hn.map(({mode:c,label:o,icon:m})=>{const p=t===c;return e.jsxs("button",{type:"button",onClick:()=>a(c),className:`inline-flex items-center gap-[6px] rounded-full font-semibold transition-colors ${i}`,style:{background:p?n.bg:"transparent",color:p?n.primary:n.ink3,boxShadow:p?"0 1px 2px rgba(0,0,0,0.06)":"none"},"aria-pressed":p,children:[m,o]},c)})})}function Re(t){return t==="day"?"day":t==="month"?"month":"week"}const gn=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],yn=3;function Ae({monthAnchor:t,events:a,onSelect:s}){const{gridStart:r,days:i,monthIndex:c}=l.useMemo(()=>{const p=Is(t),x=Ls(t),h=Ge(p,{weekStartsOn:1}),g=Math.ceil((x.getTime()-h.getTime())/(1e3*60*60*24)+1),j=Math.ceil(g/7)*7,I=[];for(let $=0;$<j;$++)I.push(Qt(h,$));return{gridStart:h,days:I,monthIndex:p.getMonth()}},[t]),o=l.useMemo(()=>{const p=new Map;for(const x of a){const h=p.get(x.date)??[];h.push(x),p.set(x.date,h)}for(const x of p.values())x.sort((h,g)=>{const C=h.start[0]*60+h.start[1],j=g.start[0]*60+g.start[1];return C-j});return p},[a]),m=new Date;return e.jsx("div",{className:"h-full overflow-auto px-[20px] py-[12px]",children:e.jsxs("div",{className:"grid grid-cols-7 gap-px rounded-[10px] overflow-hidden",style:{background:n.hair,border:`1px solid ${n.hair}`},children:[gn.map(p=>e.jsx("div",{className:"px-[10px] py-[8px] text-[11px] font-bold uppercase",style:{background:n.surface,color:n.ink3,letterSpacing:"0.05em"},children:p},p)),i.map(p=>{const x=ae(p,"yyyy-MM-dd"),h=p.getMonth()===c,g=je(p,m),C=o.get(x)??[],j=C.slice(0,yn),I=C.length-j.length;return e.jsxs("div",{className:"flex flex-col gap-[3px] px-[6px] py-[6px] min-h-[96px]",style:{background:n.bg,opacity:h?1:.45,outline:g?`1.5px solid ${n.primary}`:"none",outlineOffset:-1},children:[e.jsx("div",{className:"text-[11px] font-bold",style:{color:g?n.primary:n.ink2},children:p.getDate()}),j.map($=>{const u=$.lessonStatus==="cancelled";return e.jsx("button",{type:"button",onClick:()=>s($),className:"text-left px-[5px] py-[2px] rounded-[4px] text-[10.5px] font-semibold truncate",style:{background:_s($.kind),color:_t($.kind),textDecoration:u?"line-through":"none",opacity:u?.55:1},title:$.title,children:$.title},$.id)}),I>0&&e.jsxs("div",{className:"text-[10px] font-medium px-[4px]",style:{color:n.ink3},children:["+",I," more"]})]},x)})]})})}function Xe({tabs:t,value:a,onChange:s,size:r="md"}){const c=r==="sm"?"px-[10px] py-[5px] text-[12px]":"px-[12px] py-[6px] text-[12.5px]";return t.length===0?null:e.jsx("div",{className:"flex items-center gap-[6px] overflow-x-auto",role:"tablist",children:t.map(o=>{const m=o.id===a;return e.jsxs("button",{type:"button",role:"tab","aria-selected":m,onClick:()=>s(o.id),className:`inline-flex items-center gap-[6px] rounded-full font-semibold whitespace-nowrap transition-colors ${c}`,style:{background:m?n.primarySoft:n.bg,color:m?n.primary:n.ink2,border:`1px solid ${m?n.primary:n.hair}`},children:[e.jsx("span",{children:o.label}),o.count!=null&&e.jsx("span",{className:"inline-flex items-center justify-center rounded-full text-[10.5px] font-bold px-[6px]",style:{background:m?n.primary:n.surface,color:m?"#fff":n.ink3,minWidth:18,height:16,lineHeight:"16px"},children:o.count})]},o.id)})})}const Jt=["scheduled","completed","cancelled"];function ct(t){return t?new Set(t.split(",").map(a=>
1a.trim()).filter(Boolean)):new Set}function dt(t){return t.size===0?null:Array.from(t).join(",")}function Je(){const[t,a]=Ht(),s=l.useMemo(()=>ct(t.get("teachers")),[t]),r=l.useMemo(()=>ct(t.get("rooms")),[t]),i=l.useMemo(()=>{const j=ct(t.get("statuses"));return new Set([...j].filter(I=>Jt.includes(I)))},[t]),c=t.get("density")==="compact"?"compact":"comfortable",o=l.useCallback((j,I)=>{a($=>{const u=new URLSearchParams($);return I==null?u.delete(j):u.set(j,I),u},{replace:!0})},[a]),m=l.useCallback(j=>o("teachers",dt(j)),[o]),p=l.useCallback(j=>o("rooms",dt(j)),[o]),x=l.useCallback(j=>o("statuses",dt(j)),[o]),h=l.useCallback(j=>o("density",j==="compact"?"compact":null),[o]),g=l.useCallback(()=>{a(j=>{const I=new URLSearchParams(j);return I.delete("teachers"),I.delete("rooms"),I.delete("statuses"),I},{replace:!0})},[a]),C=(s.size>0?1:0)+(r.size>0?1:0)+(i.size>0?1:0);return{teachers:s,rooms:r,statuses:i,density:c,activeCount:C,setTeachers:m,setRooms:p,setStatuses:x,setDensity:h,clearAll:g}}function Ke(t,a){if(a.teachers.size>0&&(!t.teacherId||!a.teachers.has(t.teacherId))||a.rooms.size>0&&(!t.room||!a.rooms.has(t.room)))return!1;if(a.statuses.size>0){const s=t.lessonStatus??"scheduled";if(!a.statuses.has(s))return!1}return!0}const bn={scheduled:"Scheduled",completed:"Completed",cancelled:"Cancelled"};function et({filters:t,teacherOptions:a,roomOptions:s,size:r="md"}){const[i,c]=l.useState(!1),m=r==="sm"?"px-[10px] py-[5px] text-[12px]":"px-[12px] py-[6px] text-[12px]",{teachers:p,rooms:x,statuses:h,activeCount:g,setTeachers:C,setRooms:j,setStatuses:I,clearAll:$}=t,u=(d,f)=>{const N=new Set(d);return N.has(f)?N.delete(f):N.add(f),N};return e.jsxs(Ye,{open:i,onOpenChange:c,children:[e.jsx(Qe,{asChild:!0,children:e.jsxs("button",{type:"button",className:`inline-flex items-center gap-[6px] rounded-full font-semibold transition-colors ${m}`,style:{background:g>0?n.primarySoft:n.bg,color:g>0?n.primary:n.ink2,border:`1px solid ${g>0?n.primary:n.hair}`},children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),"Filters",g>0&&e.jsx("span",{className:"inline-flex items-center justify-center rounded-full text-[10.5px] font-bold px-[6px]",style:{background:n.primary,color:"#fff",minWidth:18,height:16,lineHeight:"16px"},children:g})]})}),e.jsxs(Ve,{className:"w-[320px] p-0 max-h-[70vh] overflow-y-auto",align:"end",children:[e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between border-b",children:[e.jsx("div",{className:"text-[13px] font-bold",style:{color:n.ink},children:"Filters"}),g>0&&e.jsx("button",{type:"button",onClick:$,className:"text-[12px] font-semibold",style:{color:n.primary},children:"Clear all"})]}),e.jsxs(ut,{title:"Teacher",children:[a.length===0&&e.jsx(Tt,{text:"No teachers"}),a.map(d=>e.jsx(pt,{label:d.name,active:p.has(d.id),onClick:()=>C(u(p,d.id))},d.id))]}),e.jsxs(ut,{title:"Room",children:[s.length===0&&e.jsx(Tt,{text:"No rooms"}),s.map(d=>e.jsx(pt,{label:d,active:x.has(d),onClick:()=>j(u(x,d))},d))]}),e.jsx(ut,{title:"Status",children:Jt.map(d=>e.jsx(pt,{label:bn[d],active:h.has(d),onClick:()=>I(u(h,d))},d))})]})]})}function ut({title:t,children:a}){return e.jsxs("div",{className:"px-4 py-3 border-b last:border-b-0",children:[e.jsx("div",{className:"text-[11px] font-bold uppercase mb-[8px]",style:{color:n.ink3,letterSpacing:"0.05em"},children:t}),e.jsx("div",{className:"flex flex-wrap gap-[6px]",children:a})]})}function pt({label:t,active:a,onClick:s}){return e.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center px-[10px] py-[4px] rounded-full text-[12px] font-semibold transition-colors",style:{background:a?n.primarySoft:n.bg,color:a?n.primary:n.ink2,border:`1px solid ${a?n.primary:n.hair}`},children:t})}function Tt({text:t}){return e.jsx("div",{className:"text-[12px] font-medium",style:{color:n.ink3},children:t})}const jn=[{value:"comfortable",label:"Comfortable",hint:"Roomy padding, easier to scan"},{value:"compact",label:"Compact",hint:"Tighter rows, more on screen"}];function tt({filters:t,size:a="md"}){const[s,r]=l.useState(!1),c=a==="sm"?"px-[10px] py-[5px] text-[12px]":"px-[12px] py-[6px] text-[12px]";return e.jsxs(Ye,{open:s,onOpenChange:r,children:[e.jsx(Qe,{asChild:!0,children:e.jsxs("button",{type:"button",className:`inline-flex items-center gap-[6px] rounded-full font-semibold transition-colors ${c}`,style:{background:n.bg,color:n.ink2,border:`1px solid ${n.hair}`},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"15",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"9",y2:"18"})]}),"Options"]})}),e.jsxs(Ve,{className:"w-[240px] p-0",align:"end",children:[e.jsx("div",{className:"px-4 py-3 border-b text-[11px] font-bold uppercase",style:{color:n.ink3,letterSpacing:"0.05em"},children:"Density"}),e.jsx("div",{className:"p-2 flex flex-col gap-1",children:jn.map(o=>{const m=t.density===o.value;return e.jsxs("button",{type:"button",onClick:()=>
1t.setDensity(o.value),className:"flex items-start gap-2 text-left px-2 py-2 rounded-md transition-colors",style:{background:m?n.primarySoft:"transparent"},children:[e.jsx("span",{className:"mt-1 inline-block w-3 h-3 rounded-full",style:{border:`2px solid ${m?n.primary:n.hair}`,background:m?n.primary:"transparent"}}),e.jsxs("span",{className:"flex-1",children:[e.jsx("div",{className:"text-[13px] font-semibold",style:{color:m?n.primary:n.ink},children:o.label}),e.jsx("div",{className:"text-[11px]",style:{color:n.ink3},children:o.hint})]})]},o.value)})})]})]})}function Kt(t){return Ne({queryKey:["staff-portal-studio-programs",t],enabled:!!t,queryFn:async()=>{if(!t)return{programs:[],classToProgramIds:new Map};const{data:a,error:s}=await G.from("programs").select("id, name, is_active, deleted_at, program_classes(class_id)").eq("studio_id",t).eq("is_active",!0).is("deleted_at",null).order("name",{ascending:!0});if(s)return console.error("[useStudioPrograms] fetch failed",s),{programs:[],classToProgramIds:new Map};const r=[],i=new Map;for(const c of a??[]){const o=c.program_classes??[];if(o.length!==0){r.push({id:c.id,name:c.name});for(const m of o){if(!(m!=null&&m.class_id))continue;const p=i.get(m.class_id)??new Set;p.add(c.id),i.set(m.class_id,p)}}}return{programs:r,classToProgramIds:i}},staleTime:5*6e4})}function st(t){return Ne({queryKey:["staff-portal-studio-teachers",t],enabled:!!t,queryFn:async()=>{if(!t)return[];const{data:a,error:s}=await G.from("staff_members").select("id, full_name, status").eq("studio_id",t).eq("status","active").order("full_name",{ascending:!0});return s?(console.error("[useStudioTeachers] fetch failed",s),[]):(a??[]).filter(r=>!!r.id&&!!r.full_name).map(r=>({id:r.id,name:r.full_name}))},staleTime:5*6e4})}async function vn({classId:t,studentId:a,sessionDate:s,status:r,trial:i}){const{data:c,error:o}=await G.from("attendance").select("id").eq("class_id",t).eq("student_id",a).eq("date",s).maybeSingle();if(o)throw o;if(r===void 0){if(c){const{error:x}=await G.from("attendance").delete().eq("id",c.id);if(x)throw x}return}const m=r!=="absent";if(c){const{error:x}=await G.from("attendance").update({present:m,status:r}).eq("id",c.id);if(x)throw x}else{const{error:x}=await G.from("attendance").insert({class_id:t,student_id:a,date:s,present:m,status:r});if(x)throw x}if(!(i!=null&&i.isTrial)||!i.opportunityId)return;const p=i.opportunityId;r==="present"||r==="late"?(G.auth.getUser().then(({data:{user:x}})=>{const h=(x==null?void 0:x.id)||"system";G.from("lead_activities").insert({opportunity_id:p,activity_type:"trial_class_completed",content:"Trial class attended — marked present by staff",performed_by:h}).then(()=>Hs(p,"trial_class_completed",h)).catch(g=>console.error("Auto-complete trial_class_completed failed (non-fatal):",g))}),G.from("opportunities").update({pipeline_stage:"trial_completed",status:"Trial Completed",last_activity_at:new Date().toISOString()}).eq("id",p).then(({error:x})=>{x&&console.error("Pipeline stage update failed (non-fatal):",x)}),G.from("class_enrollments").update({trial_completed:!0,trial_completed_at:new Date().toISOString()}).eq("student_id",a).eq("class_id",t).eq("enrollment_type","trial").then(({error:x})=>{x&&console.error("trial_completed update failed (non-fatal):",x)})):r==="absent"&&(G.from("opportunities").select("custom_fields").eq("id",p).single().then(({data:x})=>{const h=x!=null&&x.custom_fields&&typeof x.custom_fields=="object"?x.custom_fields:{},g=typeof h.no_show_count=="number"?h.no_show_count:0;return G.from("opportunities").update({pipeline_stage:"trial_no_show",status:"Trial No-Show",custom_fields:{...h,no_show_count:g+1},last_activity_at:new Date().toISOString()}).eq("id",p)}).then(x=>{x!=null&&x.error&&console.error("No-show tracking failed (non-fatal):",x.error)}),G.from("lead_activities").insert({opportunity_id:p,activity_type:"trial_no_show",content:"Trial class no-show — marked absent by staff"}).then(()=>{}))}const kn={paid:"bg-emerald-100 text-emerald-700",method:"bg-slate-100 text-slate-700",warn:"bg-amber-100 text-amber-700",muted:"bg-muted text-muted-foreground",neutral:"bg-blue-100 text-blue-700"};function Sn(t){return kn[t]}function _n(t){if(!t)return null;const a=t.trim().toLowerCase();if(a.startsWith("wallet"))return"Membership";switch(a){case"card":case"stripe":return"Card";case"cash":return"Cash";case"credit":return"Credit";case"check":return"Check";case"zelle":return"Zelle";case"free":return"Free";default:{const s=a.replace(/_/g," ");return s.charAt(0).toUpperCase()+s.slice(1)}}}function wn(t,a){const s=(t??"").trim().toLowerCase(),r=_n(a);switch(s){case"unpaid":return{label:"Unpaid",tone:"warn",title:"Payment not collected"};case"overdue":case"past_due":return{label:"Overdue",tone:"warn",title:"Payment overdue"};case"failed":return{label:"Failed",tone:"warn",title:"Payment failed"};
1case"pending":case"pre_authorized":return{label:"Pending",tone:"muted",title:"Payment pending / authorising"};case"refunded":return{label:"Refunded",tone:"muted",title:"Payment refunded"};case"voided":return{label:"Voided",tone:"muted",title:"Payment voided"};case"cancelled":case"canceled":return{label:"Cancelled",tone:"muted",title:"Payment cancelled"};case"included_in_tuition":return{label:"Tuition",tone:"neutral",title:"Included in monthly tuition"};case"credit":return{label:r??"Membership",tone:"neutral",title:"Paid from a package / credit balance"}}return s==="paid"?r?{label:r,tone:r==="Membership"?"neutral":"paid",title:`Paid · ${r}`}:{label:"Paid",tone:"paid",title:"Paid"}:r?{label:r,tone:"method",title:`Method · ${r}`}:null}function Nn(t){try{return ae(Fe(t),"MMM d, yyyy")}catch{return t}}function Cn({student:t,onClose:a}){const{data:s=[],isLoading:r}=Ne({queryKey:["student-goals-view",t==null?void 0:t.id],enabled:!!(t!=null&&t.id),staleTime:3e4,queryFn:async()=>{const{data:i,error:c}=await G.from("student_goals").select("id, title, description, progress, status, target_date, created_at").eq("student_id",t.id).order("created_at",{ascending:!1});if(c)throw c;return i??[]}});return e.jsx(jt,{open:!!t,onOpenChange:i=>{i||a()},children:e.jsxs(vt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsxs(kt,{children:[e.jsxs(St,{className:"flex items-center gap-2",children:[e.jsx(yt,{className:"h-4 w-4 text-violet-600"}),t!=null&&t.name?`${t.name} — Goals`:"Goals"]}),e.jsx(os,{children:"Set by the student/family. View-only here."})]}),r?e.jsx("div",{className:"py-8 text-center",children:e.jsx(Gt,{className:"h-5 w-5 animate-spin mx-auto text-muted-foreground"})}):s.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"No goals set yet."}):e.jsx("div",{className:"space-y-3",children:s.map(i=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("div",{className:"font-medium text-sm break-words",children:i.title}),i.status&&e.jsx("span",{className:"shrink-0 text-[11px] rounded-full px-2 py-0.5 bg-muted text-muted-foreground capitalize",children:String(i.status).replace(/_/g," ")})]}),typeof i.progress=="number"&&e.jsxs("div",{className:"mt-2",children:[e.jsx(Gs,{value:i.progress,className:"h-1.5"}),e.jsxs("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[i.progress,"%"]})]}),i.description&&e.jsx("p",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap break-words",children:i.description}),i.target_date&&e.jsxs("div",{className:"mt-1 text-[11px] text-muted-foreground",children:["Target: ",Nn(i.target_date)]})]},i.id))})]})})}function Mn(t,a){return Ne({queryKey:["roster-student-goals-enabled",t],enabled:a&&!!t,staleTime:5*60*1e3,queryFn:async()=>{if(!t)return!1;const{data:s,error:r}=await G.from("studios").select("roster_student_goals_enabled").eq("id",t).maybeSingle();return r?!1:!!(s!=null&&s.roster_student_goals_enabled)}})}function $n(t,a){const s=[...t].sort().join(",");return Ne({queryKey:["roster-student-goals",s],enabled:a&&t.length>0,staleTime:60*1e3,queryFn:async()=>{const r=new Map;if(t.length===0)return r;const{data:i,error:c}=await G.from("student_goals").select("id, student_id, title, description, target_date, progress, status").in("student_id",t).eq("status","in_progress").order("created_at",{ascending:!1});if(c)return console.error("[useRosterStudentGoals] fetch failed",c),r;for(const o of i||[]){const m=o.student_id;if(!m||!o.title)continue;const p=r.get(m)??[];p.push({id:o.id,title:o.title,description:o.description??null,targetDate:o.target_date??null,progress:typeof o.progress=="number"?o.progress:null}),r.set(m,p)}return r}})}function Tn(t,a,s,r){return Ne({queryKey:["staff-portal-class-roster",t,a,s],enabled:r&&!!t&&!!a,queryFn:async()=>{if(!t||!a)return[];let i=G.from("class_enrollments").select(`id, status, enrollment_number, student_id, is_trial_enrollment, session_id, enrollment_source,
2           payment_status, payment_source,
3           students!inner (
4             id, first_name, last_name, date_of_birth, avatar_url, profile_id, opportunity_id,
5             profiles!students_profile_id_fkey ( full_name, email, avatar_url )
6           )`).eq("class_id",t).in("status",["active","trial","pending_cancellation"]).order("enrollment_number",{ascending:!0});s&&(i=i.or(`session_id.is.null,session_id.eq.${s}`));const[{data:c,error:o},{data:m},{data:p}]=await Promise.all([i,G.from("attendance").select("student_id, status").eq("class_id",t).eq("date",a),G.from("student_session_exclusions").select("student_id").eq("class_id",t).eq("exclusion_date",a)]);o&&console.error("[ClassRosterSheet] enrollments fetch failed",o);const x=new Map;for(const C of m||[])C.student_id&&C.status&&x.set(C.student_id,C.status);const h=new Set((p||[]).map(C=>
6C.student_id).filter(Boolean));return $s((c||[]).filter(C=>{var j;return!!((j=C.students)!=null&&j.id)}),C=>{var j;return(j=C.students)==null?void 0:j.id},{prefer:"classWide"}).map(C=>{var u;const j=C.students||{},I=j.profiles||null,$=((u=I==null?void 0:I.full_name)==null?void 0:u.trim())||[j.first_name,j.last_name].filter(Boolean).join(" ")||"Unknown student";return{enrollmentId:C.id,studentId:j.id,fullName:$,email:(I==null?void 0:I.email)||null,dateOfBirth:j.date_of_birth??null,status:C.status,trial:!!C.is_trial_enrollment||C.status==="trial",fromShareLink:C.enrollment_source==="public_share_link",opportunityId:j.opportunity_id||null,pendingCancellation:C.status==="pending_cancellation",cancelled:!1,excluded:h.has(j.id),paymentStatus:C.payment_status??null,paymentSource:C.payment_source??null,attendance:x.get(j.id)??null,avatar:{avatar_url:j.avatar_url??null,profiles:I?{avatar_url:I.avatar_url??null}:null}}})}})}function Dn(t,a){return Ne({queryKey:["staff-portal-class-notes",t],enabled:a&&!!t,queryFn:async()=>{const{data:s,error:r}=await G.from("class_notes").select("id, note, pinned, created_at, author:created_by ( full_name )").eq("class_id",t).order("pinned",{ascending:!1}).order("created_at",{ascending:!1}).limit(10);return r?(r.code!=="42P01"&&r.code!=="PGRST205"&&console.error("[ClassRosterSheet] class notes fetch failed",r),[]):s||[]}})}function In({notes:t}){if(t.length===0)return null;const a=t.slice(0,3);return e.jsxs("div",{"data-testid":"roster-class-notes",className:"mx-6 mt-4 rounded-xl border border-amber-200 bg-amber-50/60 px-3 py-2.5",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-amber-800",children:[e.jsx(Ys,{className:"h-3.5 w-3.5"}),"Class notes"]}),e.jsx("ul",{className:"space-y-1.5",children:a.map(s=>{var r;return e.jsxs("li",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[s.pinned&&e.jsx(Qs,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-600"}),e.jsx("p",{className:"line-clamp-3 whitespace-pre-wrap text-[12px] leading-snug text-amber-900",title:s.note,children:s.note})]}),e.jsxs("div",{className:`mt-0.5 text-[11px] text-amber-700/80 ${s.pinned?"pl-[18px]":""}`,children:[((r=s.author)==null?void 0:r.full_name)||"Staff"," ·"," ",new Date(s.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric"})]})]},s.id)})}),t.length>a.length&&e.jsxs("div",{className:"mt-1.5 text-[11px] text-amber-700/80",children:["+",t.length-a.length," more in Class Manage → Notes"]})]})}const Dt={present:{active:"bg-emerald-500 text-white border-emerald-500",inactive:"bg-white text-emerald-700 border-emerald-200 hover:bg-emerald-50",label:"Present"},late:{active:"bg-amber-500 text-white border-amber-500",inactive:"bg-white text-amber-700 border-amber-200 hover:bg-amber-50",label:"Late"},absent:{active:"bg-red-500 text-white border-red-500",inactive:"bg-white text-red-700 border-red-200 hover:bg-red-50",label:"Absent"}};function It({current:t,onChange:a,disabled:s}){return e.jsx("div",{className:"flex items-center gap-1",children:Object.keys(Dt).map(r=>{const i=t===r,c=Dt[r];return e.jsx("button",{type:"button",disabled:s,onClick:()=>a(i?void 0:r),className:`inline-flex items-center px-2.5 py-1 rounded-full border text-[11px] font-semibold transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${i?c.active:c.inactive}`,children:c.label},r)})})}function Ln({goals:t,onOpen:a}){return e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[t.map(s=>e.jsxs("button",{type:"button",onClick:a,title:s.description?`${s.title} — ${s.description}`:s.title,className:"inline-flex max-w-[18rem] items-center gap-1 rounded-full bg-violet-50 px-2 py-0.5 text-[11px] font-medium text-violet-700 hover:bg-violet-100 transition cursor-pointer",children:[e.jsx(yt,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:s.title}),typeof s.progress=="number"&&s.progress>0&&e.jsxs("span",{className:"shrink-0 text-violet-500",children:["· ",s.progress,"%"]})]},s.id)),t.length===0&&e.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center gap-1 rounded-full border border-dashed border-violet-200 px-2 py-0.5 text-[11px] font-medium text-violet-600 hover:bg-violet-50 transition cursor-pointer",children:[e.jsx(yt,{className:"h-3 w-3"}),"Goals"]})]})}function nt({open:t,onOpenChange:a,row:s,studioId:r}){const i=Rs(),c=(s==null?void 0:s.classId)??null,o=(s==null?void 0:s.date)??null,m=(s==null?void 0:s.sessionId)??null,{data:p,isLoading:x}=Tn(c,o,m,t),[h,g]=l.useState(new Set),[C,j]=l.useState({}),[I,$]=l.useState(null),{data:u}=Dn(c,t),d=l.useMemo(()=>
6{if(!o)return"";const k=$e(o);return`${Ze(k)}, ${xe(k)}`},[o]),f=(p??[]).map(k=>({...k,attendance:k.studentId in C?C[k.studentId]:k.attendance})),{data:N}=Mn(r,t),R=l.useMemo(()=>N?(p??[]).map(k=>k.studentId):[],[N,p]),{data:U}=$n(R,t&&!!N),H=f.filter(k=>k.attendance==="present"||k.attendance==="late").length,X=f.filter(k=>!k.excluded&&!k.cancelled).length,B=async(k,A)=>{if(!c||!o)return;const E=k.attendance;j(M=>({...M,[k.studentId]:A??null})),g(M=>{const T=new Set(M);return T.add(k.studentId),T});try{await vn({classId:c,studentId:k.studentId,sessionDate:o,status:A,trial:{isTrial:k.trial,opportunityId:k.opportunityId}});const M=A==="present"?"Present":A==="late"?"Late":A==="absent"?"Absent":"Cleared";se.success(`${k.fullName} · ${M}`,{duration:1200}),await i.invalidateQueries({queryKey:["staff-portal-class-roster",c,o,m]})}catch(M){j(T=>({...T,[k.studentId]:E??null})),se.error("Failed to save attendance",{description:(M==null?void 0:M.message)||"Unknown error"})}finally{g(M=>{const T=new Set(M);return T.delete(k.studentId),T})}};return e.jsx(As,{open:t,onOpenChange:a,children:e.jsxs(Ps,{side:"right",className:"w-full sm:max-w-xl p-0 flex flex-col",children:[e.jsxs(Os,{className:"px-6 pt-6 pb-4 border-b",children:[e.jsx(Bs,{className:"text-xl font-semibold",children:(s==null?void 0:s.title)||"Class roster"}),e.jsxs("div",{className:"text-sm text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1",children:[o&&e.jsx("span",{children:d}),s&&e.jsxs("span",{children:[de(...s.start)," – ",de(...s.end)]}),(s==null?void 0:s.instructor)&&e.jsx("span",{children:s.instructor}),(s==null?void 0:s.room)&&e.jsx("span",{children:s.room})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx(In,{notes:u??[]}),x?e.jsx("div",{className:"px-6 py-10 text-sm text-muted-foreground",children:"Loading roster…"}):f.length===0?e.jsx("div",{className:"px-6 py-10 text-sm text-muted-foreground",children:"No students enrolled in this session."}):e.jsx("ul",{className:"divide-y",children:f.map(k=>{const A=k.fullName.split(" ").map(L=>L[0]).filter(Boolean).slice(0,2).join("").toUpperCase()||"?",E=Us(k.avatar),M=qs(k.dateOfBirth),T=k.trial?null:wn(k.paymentStatus,k.paymentSource),b=k.excluded||k.cancelled||h.has(k.studentId),_=e.jsxs(e.Fragment,{children:[e.jsx(Ms,{dateOfBirth:k.dateOfBirth,referenceDate:o}),T&&e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-semibold ${Sn(T.tone)}`,title:T.title,children:T.label}),k.fromShareLink&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-semibold bg-emerald-100 text-emerald-700",title:"Booked via public class share link",children:"🔗 Share link"}),k.trial&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-semibold bg-blue-100 text-blue-700",children:"Trial"}),k.pendingCancellation&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-semibold bg-amber-100 text-amber-700",children:"Ending"}),k.cancelled&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-semibold bg-muted text-muted-foreground",children:"Cancelled"}),k.excluded&&!k.cancelled&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-[11px] font-semibold bg-muted text-muted-foreground",children:"Excluded"})]});return e.jsxs("li",{className:"px-6 py-3",style:{opacity:k.excluded||k.cancelled?.5:1},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(zs,{className:"h-9 w-9",children:[E&&e.jsx(Fs,{src:E,alt:k.fullName}),e.jsx(Ws,{className:"text-[12px] font-semibold",children:A})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{"data-testid":"roster-student-name",className:"text-sm font-semibold text-foreground truncate",children:[k.fullName,M!=null&&e.jsxs("span",{className:"ml-1 text-[12px] font-normal text-muted-foreground",children:["· age ",M]})]}),k.email&&e.jsx("div",{className:"text-[12px] text-muted-foreground truncate",children:k.email}),N&&e.jsx(Ln,{goals:(U==null?void 0:U.get(k.studentId))??[],onOpen:()=>$({id:k.studentId,name:k.fullName})})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 shrink-0",children:[_,e.jsx(It,{current:k.attendance,disabled:b,onChange:L=>B(k,L)})]})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 sm:hidden",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-w-0",children:_}),e.jsx("div",{className:"shrink-0",children:e.jsx(It,{current:k.attendance,disabled:b,onChange:L=>B(k,L)})})]})]},k.enrollmentId)})})]}),X>0&&e.jsxs("div",{className:"px-6 py-3 border-t bg-muted/30 text-[12px] text-muted-foreground",children:[H," of ",X," present"]}),e.jsx(Cn,{student:I,onClose:()=>$(null)})]})})}function En({items:t,studioId:a}){const[s,r]=l.useState(null),[i,c]=l.useState(""),[o,m]=l.useState(new Date),[p,x]=l.useState({past:!1,upcoming:!0}),[h,g]=l.useState("list"),[C,j]=l.useState("all"),{data:I}=Kt(a),$=(I==null?void 0:I.programs)??[],u=I==null?void 0:I.classToProgramIds,d=Je(),{data:f=[]}
6=st(a),N=l.useMemo(()=>{const A=new Set;for(const E of t)E.kind==="classes"&&E.room&&A.add(E.room);return Array.from(A).sort()},[t]),R=l.useMemo(()=>{const A=i.trim().toLowerCase();return t.filter(E=>E.kind==="classes").filter(E=>A?[E.title,E.room,E.instructor].filter(Boolean).join(" ").toLowerCase().includes(A):!0)},[t,i]),U=l.useMemo(()=>{const A=[{id:"all",label:"All",count:R.length}];for(const E of $){const M=R.filter(T=>{var b;return T.classId&&((b=u==null?void 0:u.get(T.classId))==null?void 0:b.has(E.id))}).length;A.push({id:E.id,label:E.name,count:M})}return A},[$,u,R]),H=l.useMemo(()=>(C==="all"?R:R.filter(E=>{var M;return E.classId&&((M=u==null?void 0:u.get(E.classId))==null?void 0:M.has(C))})).filter(E=>Ke(E,d)),[R,C,u,d]),X=l.useMemo(()=>{const A=ae(o,"yyyy-MM-dd");return H.filter(E=>Le(E.date,A,p)).sort((E,M)=>E.date.localeCompare(M.date)||be(E.start)-be(M.start))},[H,o,p]),B=l.useMemo(()=>{const A=new Map;for(const E of X)A.has(E.date)||A.set(E.date,[]),A.get(E.date).push(E);return Array.from(A.entries())},[X]),k=new Date;return e.jsxs("div",{className:"h-full overflow-y-auto",style:{background:D.surface},children:[e.jsxs("div",{className:"flex flex-col gap-[8px] px-[14px] py-[10px]",style:{background:D.bg,borderBottom:`1px solid ${D.hair}`},children:[e.jsxs("div",{className:"flex items-center justify-between gap-[6px] flex-wrap",children:[e.jsx(Ee,{value:h,onChange:g,size:"sm"}),h==="list"&&e.jsx(Ie,{value:p,onChange:x,size:"sm"})]}),U.length>1&&e.jsx(Xe,{tabs:U,value:C,onChange:j,size:"sm"}),e.jsx(Te,{value:i,onChange:c,placeholder:"Search classes…",size:"sm"}),e.jsx(De,{value:o,onChange:m,step:Re(h),size:"sm"}),e.jsxs("div",{className:"flex items-center justify-end gap-[6px]",children:[e.jsx(tt,{filters:d,size:"sm"}),e.jsx(et,{filters:d,teacherOptions:f,roomOptions:N,size:"sm"})]})]}),h==="list"&&B.map(([A,E])=>{const M=$e(A),T=je(M,k);return e.jsxs("div",{children:[e.jsxs("div",{className:"px-[16px] pt-[14px] pb-[6px] flex items-baseline gap-2 sticky top-0 z-[1]",style:{background:D.surface},children:[e.jsx("div",{className:"text-[11px] font-bold uppercase",style:{color:T?D.primary:D.ink2,letterSpacing:"0.06em"},children:T?"Today":Ze(M)}),e.jsx("div",{className:"text-[11px] font-medium",style:{color:D.ink3},children:xe(M)})]}),e.jsx("div",{style:{background:D.bg,borderTop:`1px solid ${D.hair}`,borderBottom:`1px solid ${D.hair}`},children:E.map((b,_)=>{const L=!!b.classId,z=b.lessonStatus==="cancelled";return e.jsxs("div",{onClick:()=>L&&r(b),className:`flex items-center gap-[12px] px-[16px] py-[12px] ${L?"cursor-pointer active:bg-muted/40":""}`,style:{borderTop:_>0?`1px solid ${D.hair2}`:"none",opacity:z?.5:1},children:[e.jsx("div",{className:"self-stretch rounded-[2px]",style:{width:4,minHeight:36,background:D.classes}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-[14.5px] font-semibold flex items-center gap-2 flex-wrap",style:{color:D.ink,textDecoration:z?"line-through":"none"},children:[b.title,z&&e.jsx("span",{className:"inline-flex items-center px-[7px] py-[2px] rounded-full text-[10px] font-bold uppercase",style:{background:"#fee2e2",color:"#b91c1c",letterSpacing:"0.04em"},children:"Cancelled"})]}),e.jsxs("div",{className:"text-[12px] mt-[2px]",style:{color:D.ink3},children:[de(...b.start)," – ",de(...b.end),b.room?` · ${b.room}`:""]})]}),b.students!=null&&e.jsxs("div",{className:"flex items-center gap-1 px-[8px] py-[4px] rounded-full text-[12px] font-semibold",style:{background:D.classesBg,color:D.classes},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),b.students]})]},b.id)})})]},A)}),h==="day"&&e.jsx(ve,{day:o,events:H,selected:null,onSelect:A=>r(A)}),h==="week"&&e.jsx(ke,{day:o,events:H,selected:null,onSelect:A=>r(A)}),h==="month"&&e.jsx(Ae,{monthAnchor:o,events:H,onSelect:A=>r(A)}),h==="list"&&e.jsx("div",{style:{height:24}}),e.jsx(nt,{open:!!s,onOpenChange:A=>!A&&r(null),row:s,studioId:a})]})}const Lt="grid grid-cols-[minmax(0,1fr)_120px_80px_120px_52px_76px]";function Rn({items:t,isSelfView:a,studioId:s}){const[r,i]=l.useState(null),[c,o]=l.useState(""),[m,p]=l.useState(new Date),[x,h]=l.useState({past:!1,upcoming:!0}),[g,C]=l.useState("list"),[j,I]=l.useState("all"),{data:$}=Kt(s),u=($==null?void 0:$.programs)??[],d=$==null?void 0:$.classToProgramIds,f=Je(),{data:N=[]}=st(s),R=l.useMemo(()=>{const M=new Set;for(const T of t)T.kind==="classes"&&T.room&&M.add(T.room);return Array.from(M).sort()},[t]),U=l.useMemo(()=>{const M=c.trim().toLowerCase();return t.filter(T=>T.kind==="classes").filter(T=>
6M?[T.title,T.room,T.instructor].filter(Boolean).join(" ").toLowerCase().includes(M):!0)},[t,c]),H=l.useMemo(()=>{const M=[{id:"all",label:"All",count:U.length}];for(const T of u){const b=U.filter(_=>{var L;return _.classId&&((L=d==null?void 0:d.get(_.classId))==null?void 0:L.has(T.id))}).length;M.push({id:T.id,label:T.name,count:b})}return M},[u,d,U]),X=l.useMemo(()=>(j==="all"?U:U.filter(T=>{var b;return T.classId&&((b=d==null?void 0:d.get(T.classId))==null?void 0:b.has(j))})).filter(T=>Ke(T,f)),[U,j,d,f]),B=l.useMemo(()=>{const M=ae(m,"yyyy-MM-dd");return X.filter(T=>Le(T.date,M,x)).sort((T,b)=>T.date.localeCompare(b.date)||be(T.start)-be(b.start))},[X,m,x]),k=l.useMemo(()=>{const M=new Map;for(const T of B)M.has(T.date)||M.set(T.date,[]),M.get(T.date).push(T);return Array.from(M.entries())},[B]),A=new Date,E=a?"You":"—";return e.jsxs("div",{className:"h-full overflow-auto px-[28px] py-[20px]",children:[e.jsxs("div",{className:"flex items-center gap-[10px] mb-[10px] flex-wrap",children:[e.jsx(Ee,{value:g,onChange:C}),e.jsx("div",{className:"flex-1"}),g==="list"&&e.jsx(Ie,{value:x,onChange:h})]}),H.length>1&&e.jsx("div",{className:"mb-[10px]",children:e.jsx(Xe,{tabs:H,value:j,onChange:I})}),e.jsxs("div",{className:"flex items-center gap-[10px] mb-[12px] flex-wrap",children:[e.jsx(Te,{value:c,onChange:o,placeholder:"Search classes…"}),e.jsx("div",{className:"flex-1"}),e.jsx(De,{value:m,onChange:p,step:Re(g)}),e.jsx(tt,{filters:f}),e.jsx(et,{filters:f,teacherOptions:N,roomOptions:R})]}),g==="list"&&e.jsxs("div",{className:"rounded-[10px] overflow-hidden",style:{background:n.bg,border:`1px solid ${n.hair}`},children:[e.jsxs("div",{className:`${Lt} px-[18px] py-[10px] text-[11px] font-bold uppercase border-b`,style:{background:n.surface,color:n.ink3,letterSpacing:"0.05em",borderColor:n.hair},children:[e.jsx("div",{children:"Class"}),e.jsx("div",{children:"Time"}),e.jsx("div",{children:"Room"}),e.jsx("div",{children:"Instructor"}),e.jsx("div",{className:"text-right",children:"Students"}),e.jsx("div",{className:"text-right",children:"Actions"})]}),k.map(([M,T],b)=>{const _=$e(M),L=je(_,A);return e.jsxs("div",{children:[e.jsxs("div",{className:"px-[18px] py-[10px] flex items-center gap-[10px]",style:{background:n.surface2,borderTop:b>0?`1px solid ${n.hair}`:"none"},children:[e.jsx("div",{className:"text-[12px] font-bold",style:{color:L?n.primary:n.ink},children:L?"Today":`${Ze(_)}, ${xe(_)}`}),L&&e.jsxs("span",{className:"text-[9px] font-bold uppercase px-[6px] py-px rounded",style:{color:n.primary,background:n.primarySoft,letterSpacing:"0.04em"},children:["Today · ",xe(_)]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"text-[11px] font-medium",style:{color:n.ink3},children:[T.length," ",T.length===1?"class":"classes"]})]}),T.map(z=>{const Y=!!z.classId,v=()=>{Y&&i(z)},F=z.lessonStatus==="cancelled";return e.jsxs("div",{onClick:v,className:`${Lt} px-[18px] ${f.density==="compact"?"py-[7px]":"py-[14px]"} items-center hover:bg-muted/30 transition-colors ${Y?"cursor-pointer":""}`,style:{borderTop:`1px solid ${n.hair2}`,opacity:F?.5:1},children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-[3px] h-[28px] rounded-[2px] shrink-0",style:{background:n.classes}}),e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"text-[12px] font-semibold flex items-center gap-2 min-w-0",style:{color:n.ink,textDecoration:F?"line-through":"none"},children:[e.jsx("span",{className:"truncate",children:z.title}),F&&e.jsx("span",{className:"inline-flex shrink-0 items-center px-[7px] py-[2px] rounded-full text-[10px] font-bold uppercase tracking-wider",style:{background:"#fee2e2",color:"#b91c1c",letterSpacing:"0.04em"},children:"Cancelled"})]})})]}),e.jsxs("div",{className:"text-[12px] font-medium",style:{color:n.ink2},children:[de(...z.start)," – ",de(...z.end)]}),e.jsx("div",{className:"text-[12px]",style:{color:n.ink2},children:z.room||"—"}),e.jsx("div",{className:"text-[12px]",style:{color:n.ink2},children:z.instructor||E}),e.jsx("div",{className:"text-right",children:z.students!=null&&e.jsx("span",{className:"inline-flex items-center gap-1 px-[9px] py-[3px] rounded-full text-[12px] font-bold",style:{background:n.classesBg,color:n.classes},children:z.students})}),e.jsx("div",{className:"flex justify-end gap-[6px]",onClick:J=>J.stopPropagation(),children:e.jsx(An,{primary:!0,onClick:v,children:"Open"})})]},z.id)})]},M)})]}),g==="day"&&e.jsx(ve,{day:m,events:X,selected:null,onSelect:M=>i(M)}),g==="week"&&e.jsx(ke,{day:m,events:X,selected:null,onSelect:M=>i(M)}),g==="month"&&e.jsx(Ae,{monthAnchor:m,events:X,onSelect:M=>i(M)}),e.jsx(nt,{open:!!r,onOpenChange:M=>!M&&i(null),row:r,studioId:s})]})}function An({children:t,primary:a,danger:s,onClick:r}){return e.jsx("button",{type:"button",onClick:r,className:"px-[11px] py-[5px] rounded-[6px] text-[12px] font-semibold",style:{background:a?n.primary:n.bg,color:a?"#fff":s?"#b91c1c":n.ink2,border:a?"none":`1px solid ${s?"#fecaca":n.hair}`},children:t})}
6function es({value:t,onChange:a,counts:s,variant:r="mobile"}){const i=[{key:"all",label:"All",n:s.all},{key:"paid",label:"Paid",n:s.paid},{key:"unpaid",label:"Unpaid",n:s.unpaid}],c=r==="mobile";return e.jsx("div",{className:"flex gap-[6px]",children:i.map(o=>{const m=t===o.key;return e.jsxs("button",{type:"button",onClick:()=>a(o.key),className:`flex items-center justify-center gap-[4px] font-semibold ${c?"flex-1 px-[8px] py-[6px]":"px-[12px] py-[6px]"} rounded-[7px] text-[12px]`,style:{border:`1px solid ${m?n.primary:n.hair}`,background:m?n.primarySoft:n.bg,color:m?n.primary:n.ink2},children:[o.label,e.jsx("span",{className:"text-[10.5px] font-semibold px-[5px] rounded",style:{opacity:.7,background:m?n.bg:n.surface2},children:o.n})]},o.key)})})}function Pn({items:t,isSelfView:a,isAdmin:s,studioId:r,staffName:i,noRefundHours:c,privateLessonById:o,onReload:m}){const[p,x]=l.useState("all"),[h,g]=l.useState(""),[C,j]=l.useState(new Date),[I,$]=l.useState({past:!1,upcoming:!0}),[u,d]=l.useState("list"),[f,N]=l.useState("all"),R=Je(),{data:U=[]}=st(r),H=l.useMemo(()=>{const O=new Set;for(const w of t)w.kind==="privates"&&w.room&&O.add(w.room);return Array.from(O).sort()},[t]),[X,B]=l.useState(null),[k,A]=l.useState(null),[E,M]=l.useState({}),T=O=>{var w;return O in E?E[O]:((w=o.get(O))==null?void 0:w.status)==="completed"},b=async O=>{const w=!T(O);M(ne=>({...ne,[O]:w}));const{error:P}=await G.from("private_lessons").update({status:w?"completed":"scheduled"}).eq("id",O);if(P){M(ne=>({...ne,[O]:!w})),se.error("Failed to update check-in");return}se.success(w?"✓ Checked in":"Check-in removed",{duration:1500})},_=l.useMemo(()=>{const O=h.trim().toLowerCase();return t.filter(w=>w.kind==="privates").filter(w=>O?[w.title,w.room].filter(Boolean).join(" ").toLowerCase().includes(O):!0)},[t,h]),L=l.useMemo(()=>{const O=_.filter(w=>w.isRecurring).length;return[{id:"all",label:"All",count:_.length},{id:"recurring",label:"Recurring",count:O},{id:"oneoff",label:"One-off",count:_.length-O}]},[_]),z=l.useMemo(()=>(f==="recurring"?_.filter(w=>w.isRecurring):f==="oneoff"?_.filter(w=>!w.isRecurring):_).filter(w=>Ke(w,R)),[_,f,R]),Y=l.useMemo(()=>{const O=ae(C,"yyyy-MM-dd");return z.filter(w=>Le(w.date,O,I)).sort((w,P)=>w.date.localeCompare(P.date)||be(w.start)-be(P.start))},[z,C,I]),v=l.useMemo(()=>({all:Y.length,paid:Y.filter(O=>O.status==="paid").length,unpaid:Y.filter(O=>O.status==="unpaid").length}),[Y]),F=l.useMemo(()=>p==="all"?Y:Y.filter(O=>O.status===p),[Y,p]),J=l.useMemo(()=>{const O=new Map;for(const w of F)O.has(w.date)||O.set(w.date,[]),O.get(w.date).push(w);return Array.from(O.entries())},[F]),K=new Date,Q=X&&o.get(X)||null,ee=k&&o.get(k)||null;return e.jsxs("div",{className:"h-full overflow-y-auto",style:{background:D.surface},children:[e.jsxs("div",{className:"flex flex-col gap-[8px] px-[14px] py-[10px]",style:{background:D.bg,borderBottom:`1px solid ${D.hair}`},children:[e.jsxs("div",{className:"flex items-center justify-between gap-[6px] flex-wrap",children:[e.jsx(Ee,{value:u,onChange:d,size:"sm"}),u==="list"&&e.jsx(Ie,{value:I,onChange:$,size:"sm"})]}),e.jsx(Xe,{tabs:L,value:f,onChange:N,size:"sm"}),e.jsx(Te,{value:h,onChange:g,placeholder:"Search private lessons…",size:"sm"}),e.jsx(De,{value:C,onChange:j,step:Re(u),size:"sm"}),e.jsxs("div",{className:"flex items-center justify-end gap-[6px]",children:[e.jsx(tt,{filters:R,size:"sm"}),e.jsx(et,{filters:R,teacherOptions:U,roomOptions:H,size:"sm"})]}),s&&u==="list"&&e.jsx(es,{value:p,onChange:x,counts:v,variant:"mobile"})]}),u==="list"&&J.length===0&&e.jsxs("div",{className:"px-[24px] py-[40px] text-center text-[13px]",style:{color:D.ink3},children:["No ",p," private lessons."]}),u==="list"&&J.map(([O,w])=>{const P=$e(O),ne=je(P,K);return e.jsxs("div",{children:[e.jsxs("div",{className:"px-[16px] pt-[14px] pb-[6px] flex items-baseline gap-2",children:[e.jsx("div",{className:"text-[11px] font-bold uppercase",style:{color:ne?D.primary:D.ink2,letterSpacing:"0.06em"},children:ne?"Today":Ze(P)}),e.jsx("div",{className:"text-[11px] font-medium",style:{color:D.ink3},children:xe(P)})]}),e.jsx("div",{style:{background:D.bg,borderTop:`1px solid ${D.hair}`,borderBottom:`1px solid ${D.hair}`},children:w.map((V,ye)=>{const re=V.title.split(" ").map(fe=>fe[0]).slice(0,2).join("").toUpperCase(),me=V.lessonStatus==="cancelled";return e.jsxs("div",{className:"px-[16px] py-[12px]",style:{borderTop:ye>0?`1px solid ${D.hair2}`:"none",opacity:me?.5:1},children:[e.jsxs("div",{className:"flex items-center gap-[12px]",children:[e.jsx("div",{className:"w-9 h-9 rounded-full flex items-center justify-center text-[13px] font-bold",style:{background:D.privatesBg,color:D.privates},children:re}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("div",{className:"text-[14.5px] font-semibold",style:{color:D.ink,textDecoration:me?"line-through":"none"},children:V.title}),e.jsx(Bn,{status:s?V.status:void 0,cancelled:me})]}),e.jsxs("div",{className:"text-[12px] mt-[2px]",style:{color:D.ink3},children:[de(...V.start)," ·"," ",V.durationMinutes?`${V.durationMinutes} min`:On(V.start,V.end),V.room?` · ${V.room}`:""]})]})]}),a&&!me&&e.jsxs("div",{className:"flex flex-col gap-2 mt-[10px] ml-[48px]",children:[e.jsx(Fn,{checkedIn:T(V.id),onClick:()=>
6b(V.id),disabled:!o.has(V.id)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Et,{onClick:()=>A(V.id),disabled:!o.has(V.id),children:"Reschedule"}),e.jsx(Et,{danger:!0,onClick:()=>B(V.id),disabled:!o.has(V.id),children:"Cancel"})]})]})]},V.id)})})]},O)}),u==="day"&&e.jsx(ve,{day:C,events:z,selected:null,onSelect:()=>{}}),u==="week"&&e.jsx(ke,{day:C,events:z,selected:null,onSelect:()=>{}}),u==="month"&&e.jsx(Ae,{monthAnchor:C,events:z,onSelect:()=>{}}),u==="list"&&e.jsx("div",{style:{height:24}}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Vt,{open:!!Q,onOpenChange:O=>!O&&B(null),lesson:Q,onSuccess:()=>{B(null),m()}}),e.jsx(Zt,{open:!!ee,onOpenChange:O=>!O&&A(null),lesson:ee,teacherName:i,noRefundHours:c,onSuccess:()=>{A(null),m()}})]})]})}function On(t,a){const s=a[0]*60+a[1]-(t[0]*60+t[1]);if(s<60)return`${s} min`;const r=Math.floor(s/60),i=s%60;return i?`${r}h ${i}m`:`${r}h`}function Bn({status:t,cancelled:a}){return a?e.jsx("div",{className:"px-[7px] py-[2px] rounded-full text-[10px] font-bold uppercase",style:{background:"#fee2e2",color:"#b91c1c",letterSpacing:"0.04em"},children:"Cancelled"}):e.jsx(zn,{status:t})}function zn({status:t}){if(!t)return null;const a=t==="paid";return e.jsx("div",{className:"px-[7px] py-[2px] rounded-full text-[10px] font-bold uppercase",style:{background:a?D.paidBg:D.unpaidBg,color:a?D.paid:D.unpaid,letterSpacing:"0.04em"},children:t})}function Fn({checkedIn:t,onClick:a,disabled:s}){return e.jsx("button",{type:"button",disabled:s,onClick:a,className:"px-[10px] py-[7px] rounded-[7px] text-[12.5px] font-semibold disabled:opacity-50 inline-flex items-center justify-center gap-[6px]",style:{background:t?D.paidBg:D.bg,color:t?D.paid:D.ink2,border:`1px solid ${t?D.paid:D.hair}`},children:t?e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Checked in"]}):"Check in"})}function Et({children:t,onClick:a,danger:s,primary:r,disabled:i}){return e.jsx("button",{type:"button",disabled:i,onClick:a,className:"flex-1 px-[10px] py-[7px] rounded-[7px] text-[12.5px] font-semibold disabled:opacity-50",style:{background:r?D.primary:D.bg,border:r?"none":`1px solid ${s?"#fecaca":D.hair}`,color:r?"#fff":s?"#b91c1c":D.ink2},children:t})}const Rt="grid grid-cols-[minmax(0,2fr)_minmax(0,1.2fr)_minmax(0,1fr)_minmax(0,1fr)_310px]";function Wn({items:t,isSelfView:a,isAdmin:s,studioId:r,staffName:i,noRefundHours:c,privateLessonById:o,outstandingBalance:m,onReload:p}){const[x,h]=l.useState("all"),[g,C]=l.useState(""),[j,I]=l.useState(new Date),[$,u]=l.useState({past:!1,upcoming:!0}),[d,f]=l.useState("list"),[N,R]=l.useState("all"),U=Je(),{data:H=[]}=st(r),X=l.useMemo(()=>{const w=new Set;for(const P of t)P.kind==="privates"&&P.room&&w.add(P.room);return Array.from(w).sort()},[t]),[B,k]=l.useState(null),[A,E]=l.useState(null),[M,T]=l.useState({}),b=w=>{var P;return w in M?M[w]:((P=o.get(w))==null?void 0:P.status)==="completed"},_=async w=>{const P=!b(w);T(V=>({...V,[w]:P}));const{error:ne}=await G.from("private_lessons").update({status:P?"completed":"scheduled"}).eq("id",w);if(ne){T(V=>({...V,[w]:!P})),se.error("Failed to update check-in");return}se.success(P?"✓ Checked in":"Check-in removed",{duration:1500})},L=l.useMemo(()=>{const w=g.trim().toLowerCase();return t.filter(P=>P.kind==="privates").filter(P=>w?[P.title,P.room].filter(Boolean).join(" ").toLowerCase().includes(w):!0)},[t,g]),z=l.useMemo(()=>{const w=L.filter(P=>P.isRecurring).length;return[{id:"all",label:"All",count:L.length},{id:"recurring",label:"Recurring",count:w},{id:"oneoff",label:"One-off",count:L.length-w}]},[L]),Y=l.useMemo(()=>(N==="recurring"?L.filter(P=>P.isRecurring):N==="oneoff"?L.filter(P=>!P.isRecurring):L).filter(P=>Ke(P,U)),[L,N,U]),v=l.useMemo(()=>{const w=ae(j,"yyyy-MM-dd");return Y.filter(P=>Le(P.date,w,$)).sort((P,ne)=>P.date.localeCompare(ne.date)||be(P.start)-be(ne.start))},[Y,j,$]),F=l.useMemo(()=>({all:v.length,paid:v.filter(w=>w.status==="paid").length,unpaid:v.filter(w=>w.status==="unpaid").length}),[v]),J=l.useMemo(()=>x==="all"?v:v.filter(w=>w.status===x),[v,x]),K=l.useMemo(()=>{const w=new Map;for(const P of J)w.has(P.date)||w.set(P.date,[]),w.get(P.date).push(P);return Array.from(w.entries())},[J]),Q=new Date,ee=B&&o.get(B)||null,O=A&&o.get(A)||null;return e.jsxs("div",{className:"h-full overflow-auto px-[28px] py-[20px]",children:[e.jsxs("div",{className:"flex items-center gap-[10px] mb-[10px] flex-wrap",children:[e.jsx(Ee,{value:d,onChange:f}),e.jsx("div",{className:"flex-1"}),d==="list"&&e.jsx(Ie,{value:$,onChange:u})]}),e.jsx("div",{className:"mb-[10px]",children:e.jsx(Xe,{tabs:z,value:N,onChange:R})}),e.jsxs("div",{className:"flex items-center gap-[10px] mb-[12px] flex-wrap",children:[e.jsx(Te,{value:g,onChange:C,placeholder:"Search private lessons…"}),e.jsx("div",{className:"flex-1"}),e.jsx(De,{value:j,onChange:I,step:Re(d)}),e.jsx(tt,{filters:U}),e.jsx(et,{filters:U,teacherOptions:H,roomOptions:X})]}),s&&d==="list"&&e.jsxs("div",{className:"flex items-center gap-2 mb-[14px]",children:[e.jsx(es,{value:x,onChange:h,counts:F,variant:"desktop"}),e.jsx("div",{className:"flex-1"}),m>0&&e.jsxs("div",{className:"text-[12px] font-medium ml-3",style:{color:n.ink3},children:["Outstanding balance:"," ",e.jsxs("span",{className:"font-bold",style:{color:n.unpaid},children:["$",m.toFixed(0)]})]})]}),d==="list"&&e.jsxs("div",{className:"rounded-[10px] overflow-hidden",style:{background:n.bg,border:`1px solid ${n.hair}`},children:[e.jsxs("div",{className:`${Rt} px-[18px] py-[10px] text-[11px] font-bold uppercase border-b`,style:{background:n.surface,color:n.ink3,letterSpacing:"0.05em",borderColor:n.hair},children:[e.jsx("div",{children:"Student"}),e.jsx("div",{children:"Time"}),e.jsx("div",{children:"Room"}),e.jsx("div",{children:"Status"}),e.jsx("div",{className:"text-right",children:"Actions"})]}),K.length===0&&e.jsxs("div",{className:"px-[24px] py-[40px] text-center text-[13px]",style:{color:n.ink3},children:["No ",x," private lessons."]}),K.map(([w,P],ne)=>{const V=$e(w),ye=je(V,Q);return e.jsxs("div",{children:[e.jsx("div",{className:"px-[18px] py-[10px] text-[12px] font-bold",style:{background:n.surface2,color:ye?n.primary:n.ink,borderTop:ne>0?`1px solid ${n.hair}`:"none"},children:ye?`Today · ${xe(V)}`:`${V.toLocaleDateString("en-US",{weekday:"short"})}, ${xe(V)}`}),P.map(re=>{const me=re.title.split(" ").map(Pe=>Pe[0]).slice(0,2).join("").toUpperCase(),fe=re.lessonStatus==="cancelled";return e.jsxs("div",{className:`${Rt} px-[18px] ${U.density==="compact"?"py-[7px]":"py-[14px]"} items-center`,style:{borderTop:`1px solid ${n.hair2}`,opacity:fe?.5:1},children:[e.jsxs("div",{className:"flex items-center gap-[12px]",children:[e.jsx("div",{className:"w-[34px] h-[34px] rounded-full flex items-center justify-center text-[12px] font-bold",style:{background:n.privatesBg,color:n.privates},children:me}),e.jsx("div",{children:e.jsx("div",{className:"text-[14px] font-semibold",style:{color:n.ink,textDecoration:fe?"line-through":"none"},children:re.title})})]}),e.jsxs("div",{className:"text-[13px] font-medium",style:{color:n.ink2},children:[de(...re.start)," – ",de(...re.end)]}),e.jsx("div",{className:"text-[13px]",style:{color:n.ink2},children:re.room||"—"}),e.jsx("div",{children:e.jsx(Un,{status:s?re.status:void 0,cancelled:fe})}),e.jsx("div",{className:"flex justify-end gap-[6px]",children:a&&!fe&&e.jsxs(e.Fragment,{children:[e.jsx(qn,{
6checkedIn:b(re.id),onClick:()=>_(re.id),disabled:!o.has(re.id)}),e.jsx(At,{onClick:()=>E(re.id),disabled:!o.has(re.id),children:"Reschedule"}),e.jsx(At,{danger:!0,onClick:()=>k(re.id),disabled:!o.has(re.id),children:"Cancel"})]})})]},re.id)})]},w)})]}),d==="day"&&e.jsx(ve,{day:j,events:Y,selected:null,onSelect:()=>{}}),d==="week"&&e.jsx(ke,{day:j,events:Y,selected:null,onSelect:()=>{}}),d==="month"&&e.jsx(Ae,{monthAnchor:j,events:Y,onSelect:()=>{}}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Vt,{open:!!ee,onOpenChange:w=>!w&&k(null),lesson:ee,onSuccess:()=>{k(null),p()}}),e.jsx(Zt,{open:!!O,onOpenChange:w=>!w&&E(null),lesson:O,teacherName:i,noRefundHours:c,onSuccess:()=>{E(null),p()}})]})]})}function Un({status:t,cancelled:a}){if(a)return e.jsxs("span",{className:"inline-flex items-center gap-[6px] px-[9px] py-[3px] rounded-full text-[11.5px] font-bold uppercase",style:{background:"#fee2e2",color:"#b91c1c",letterSpacing:"0.04em"},children:[e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full",style:{background:"#b91c1c"}}),"Cancelled"]});if(!t)return null;const s=t==="paid";return e.jsxs("span",{className:"inline-flex items-center gap-[6px] px-[9px] py-[3px] rounded-full text-[11.5px] font-bold uppercase",style:{background:s?n.paidBg:n.unpaidBg,color:s?n.paid:n.unpaid,letterSpacing:"0.04em"},children:[e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full",style:{background:s?n.paid:n.unpaid}}),t]})}function qn({checkedIn:t,onClick:a,disabled:s}){return e.jsx("button",{type:"button",onClick:a,disabled:s,className:"px-[11px] py-[5px] rounded-[6px] text-[12px] font-semibold disabled:opacity-50 inline-flex items-center gap-[5px]",style:{background:t?n.paidBg:n.bg,color:t?n.paid:n.ink2,border:`1px solid ${t?n.paid:n.hair}`},children:t?e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Checked in"]}):"Check in"})}function At({children:t,primary:a,danger:s,onClick:r,disabled:i}){return e.jsx("button",{type:"button",onClick:r,disabled:i,className:"px-[11px] py-[5px] rounded-[6px] text-[12px] font-semibold disabled:opacity-50",style:{background:a?n.primary:n.bg,color:a?"#fff":s?"#b91c1c":n.ink2,border:a?"none":`1px solid ${s?"#fecaca":n.hair}`},children:t})}const Pt=["#fda4af","#fcd34d","#86efac","#c4b5fd","#7dd3fc"];function Hn({count:t}){const a=Math.min(t,4);return a<=0?null:e.jsx("div",{className:"flex",children:Array.from({length:a}).map((s,r)=>e.jsx("div",{className:"rounded-full",style:{width:22,height:22,background:Pt[r%Pt.length],border:`2px solid ${n.bg}`,marginLeft:r===0?0:-6}},r))})}function ts({ev:t,variant:a="mobile",onRsvp:s}){const r=a==="desktop",i=je(t.date,new Date);return e.jsxs("div",{className:"overflow-hidden flex flex-col",style:{background:n.bg,border:`1px solid ${n.hair}`,borderRadius:12},children:[e.jsxs("div",{className:"flex",style:{gap:r?14:12,padding:r?16:14},children:[e.jsx(nn,{date:t.date,variant:a}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("div",{className:"font-semibold leading-tight",style:{color:n.ink,fontSize:r?15.5:15},children:t.title}),i&&e.jsx("span",{className:"font-bold uppercase",style:{fontSize:r?9.5:9,color:n.now,background:n.nowBg,padding:"2px 6px",borderRadius:4,letterSpacing:"0.04em"},children:"Today"})]}),e.jsxs("div",{className:"flex",style:{fontSize:r?12.5:12,color:n.ink3,marginTop:r?6:4,gap:r?14:8,flexDirection:r?"row":"column"},children:[e.jsxs(Ot,{icon:"clock",children:[de(...t.start)," – ",de(...t.end)]}),t.location&&e.jsx(Ot,{icon:"pin",children:t.location})]}),t.desc&&e.jsx("div",{className:"leading-relaxed",style:{color:n.ink2,fontSize:r?12.5:12,marginTop:8},children:t.desc}),t.total>0&&e.jsxs("div",{className:"flex items-center gap-2",style:{marginTop:12},children:[e.jsx(Hn,{count:t.attending}),e.jsxs("div",{className:"font-medium",style:{fontSize:11.5,color:n.ink3},children:[e.jsx("span",{style:{color:n.ink,fontWeight:600},children:t.attending})," ","of ",t.total," staff going"]})]})]})]}),e.jsxs("div",{className:"flex",style:{borderTop:`1px solid ${n.hair2}
6`,padding:r?10:8,gap:6},children:[e.jsx(xt,{value:"going",glyph:"✓",label:"Going",active:t.rsvp==="going",onClick:()=>s("going")}),e.jsx(xt,{value:"maybe",glyph:"?",label:"Maybe",active:t.rsvp==="maybe",onClick:()=>s("maybe")}),e.jsx(xt,{value:"no",glyph:"✕",label:"Can't Go",active:t.rsvp==="no",onClick:()=>s("no")})]})]})}function Ot({icon:t,children:a}){const s=t==="clock"?e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"}),e.jsx("circle",{cx:"12",cy:"10",r:"3"})]});return e.jsxs("div",{className:"flex items-center gap-[5px]",style:{color:n.ink3},children:[s,e.jsx("span",{children:a})]})}function xt({value:t,glyph:a,label:s,active:r,onClick:i}){const c=t==="going"?n.privates:t==="maybe"?"#b45309":"#b91c1c",o=t==="going"?n.privatesBg:t==="maybe"?n.unpaidBg:"#fee2e2";return e.jsxs("button",{type:"button",onClick:i,className:"flex-1 flex items-center justify-center gap-[5px] font-semibold",style:{padding:"7px 4px",borderRadius:7,border:`1px solid ${r?c:n.hair}`,background:r?o:n.bg,color:r?c:n.ink2,fontSize:12},children:[e.jsx("span",{style:{fontSize:11},children:a}),s]})}function Gn({events:t,calendarEvents:a,canEdit:s,onCreate:r,onRsvp:i}){const[c,o]=l.useState(""),[m,p]=l.useState(new Date),[x,h]=l.useState({past:!1,upcoming:!0}),[g,C]=l.useState("list"),j=l.useMemo(()=>{const $=c.trim().toLowerCase();return a.filter(u=>$?[u.title,u.room,u.description].filter(Boolean).join(" ").toLowerCase().includes($):!0)},[a,c]),I=l.useMemo(()=>{const $=ae(m,"yyyy-MM-dd"),u=c.trim().toLowerCase();return t.filter(d=>{const f=ae(d.date,"yyyy-MM-dd");return Le(f,$,x)?u?[d.title,d.desc,d.location].filter(Boolean).join(" ").toLowerCase().includes(u):!0:!1})},[t,m,x,c]);return e.jsxs("div",{className:"h-full overflow-auto px-[28px] py-[20px]",children:[e.jsxs("div",{className:"flex items-center gap-[10px] mb-[10px] flex-wrap",children:[e.jsx(Ee,{value:g,onChange:C}),e.jsx("div",{className:"flex-1"}),g==="list"&&e.jsx(Ie,{value:x,onChange:h})]}),e.jsxs("div",{className:"flex items-center gap-[10px] mb-[12px] flex-wrap",children:[e.jsx(Te,{value:c,onChange:o,placeholder:"Search events…"}),e.jsx("div",{className:"flex-1"}),e.jsx(De,{value:m,onChange:p,step:Re(g)})]}),e.jsxs("div",{className:"flex items-center mb-[16px]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold",style:{fontSize:16,color:n.ink,letterSpacing:"-0.01em"},children:"Events"}),g==="list"&&e.jsxs("div",{className:"text-[12px] mt-[2px]",style:{color:n.ink3},children:[I.length," ",I.length===1?"event":"events"]})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-[6px] font-semibold",style:{padding:"8px 14px",background:n.primary,color:"#fff",border:0,borderRadius:8,fontSize:13},children:[e.jsx("span",{style:{fontSize:15,marginTop:-1},children:"+"})," Create Event"]})]}),g==="list"&&(I.length===0?e.jsx("div",{className:"text-center py-[60px] text-[14px]",style:{color:n.ink3},children:"No events match."}):e.jsx("div",{className:"grid grid-cols-2 gap-[14px]",children:I.map($=>e.jsx(ts,{ev:$,variant:"desktop",onRsvp:u=>i($.id,u)},$.id))})),g==="day"&&e.jsx(ve,{day:m,events:j,selected:null,onSelect:()=>{}}),g==="week"&&e.jsx(ke,{day:m,events:j,selected:null,onSelect:()=>{}}),g==="month"&&e.jsx(Ae,{monthAnchor:m,events:j,onSelect:()=>{}})]})}function Yn({events:t,calendarEvents:a,canEdit:s,onCreate:r,onRsvp:i}){const[c,o]=l.useState(""),[m,p]=l.useState(new Date),[x,h]=l.useState({past:!1,upcoming:!0}),[g,C]=l.useState("list"),j=l.useMemo(()=>{const $=c.trim().toLowerCase();return a.filter(u=>$?[u.title,u.room,u.description].filter(Boolean).join(" ").toLowerCase().includes($):!0)},[a,c]),I=l.useMemo(()=>{const $=ae(m,"yyyy-MM-dd"),u=c.trim().toLowerCase();return t.filter(d=>{const f=ae(d.date,"yyyy-MM-dd");
6return Le(f,$,x)?u?[d.title,d.desc,d.location].filter(Boolean).join(" ").toLowerCase().includes(u):!0:!1})},[t,m,x,c]);return e.jsxs("div",{className:"h-full overflow-y-auto relative",style:{background:D.surface},children:[e.jsxs("div",{className:"flex flex-col gap-[8px] px-[14px] py-[10px]",style:{background:D.bg,borderBottom:`1px solid ${D.hair}`},children:[e.jsxs("div",{className:"flex items-center justify-between gap-[6px] flex-wrap",children:[e.jsx(Ee,{value:g,onChange:C,size:"sm"}),g==="list"&&e.jsx(Ie,{value:x,onChange:h,size:"sm"})]}),e.jsx(Te,{value:c,onChange:o,placeholder:"Search events…",size:"sm"}),e.jsx(De,{value:m,onChange:p,step:Re(g),size:"sm"})]}),e.jsxs("div",{className:"px-[16px] py-[14px] flex items-center justify-between",style:{background:D.bg,borderBottom:`1px solid ${D.hair}`},children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold",style:{fontSize:14.5,color:D.ink},children:"Events"}),g==="list"&&e.jsxs("div",{className:"mt-[2px]",style:{fontSize:11.5,color:D.ink3},children:[I.length," ",I.length===1?"event":"events"]})]}),s&&e.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-1 font-semibold",style:{padding:"8px 12px",background:D.primary,color:"#fff",border:0,borderRadius:8,fontSize:12.5},children:[e.jsx("span",{style:{fontSize:14,lineHeight:1,marginTop:-1},children:"+"})," ","Create"]})]}),g==="list"&&e.jsx("div",{className:"px-[14px] py-[12px] flex flex-col gap-[12px]",children:I.length===0?e.jsx("div",{className:"text-center py-[40px] text-[13px]",style:{color:D.ink3},children:"No events match."}):I.map($=>e.jsx(ts,{ev:$,variant:"mobile",onRsvp:u=>i($.id,u)},$.id))}),g==="day"&&e.jsx(ve,{day:m,events:j,selected:null,onSelect:()=>{}}),g==="week"&&e.jsx(ke,{day:m,events:j,selected:null,onSelect:()=>{}}),g==="month"&&e.jsx(Ae,{monthAnchor:m,events:j,onSelect:()=>{}}),g==="list"&&e.jsx("div",{style:{height:24}})]})}const ze=t=>String(t).padStart(2,"0"),Bt=t=>{const[a,s]=t.split(":").map(Number),r=a<12?"AM":"PM";return`${(a+11)%12+1}:${ze(s)} ${r}`};function mt({open:t,onClose:a,onCreated:s,studioId:r,userId:i,variant:c,seed:o,isMeeting:m,edit:p}){var k,A;const x=is(r),[h,g]=l.useState(""),[C,j]=l.useState("Main Hall"),[I,$]=l.useState(!1),[u,d]=l.useState(!1),f=l.useMemo(()=>{if(o!=null&&o.date)return Fe(o.date);const E=Fe(cs(x));return E.setDate(E.getDate()+7),E},[o==null?void 0:o.date,x]);if(l.useEffect(()=>{t&&(g((p==null?void 0:p.title)??""),j((p==null?void 0:p.location)??"Main Hall"),d(!1))},[t,p,o==null?void 0:o.date,(k=o==null?void 0:o.start)==null?void 0:k[0],(A=o==null?void 0:o.start)==null?void 0:A[1]]),!t)return null;const N=o?`${ze(o.start[0])}:${ze(o.start[1])}`:"14:00",R=o?`${ze(o.end[0])}:${ze(o.end[1])}`:"16:00",U=m?"Meeting":"Event",H=!!(p!=null&&p.id),X=async()=>{if(!h.trim())return;$(!0);const E=ae(f,"yyyy-MM-dd"),M=`${E}T${N}:00`,T=`${E}T${R}:00`;if(H){const z={title:h.trim(),location:C.trim()||null,updated_at:new Date().toISOString()};o&&(z.start_at=M,z.end_at=T);const{error:Y}=await G.from("studio_events").update(z).eq("id",p.id);if(Y){se.error(`Failed to update ${U.toLowerCase()}`),$(!1);return}se.success(`${U} updated`),$(!1),s();return}const b={studio_id:r,title:h.trim(),description:null,event_type:m?"meeting":"general",meeting_category:m?"custom":null,location:C.trim()||null,start_at:M,end_at:T,all_day:!1,created_by:i,updated_at:new Date().toISOString()},{data:_,error:L}=await G.from("studio_events").insert(b).select("id").single();if(L){se.error(`Failed to create ${U.toLowerCase()}`),$(!1);return}se.success(`${U} created`),u&&(_!=null&&_.id)&&(lt("notify-staff-content",{body:{kind:"event",id:_.id}}).catch(()=>{}),lt("google-calendar-staff",{body:{action:"sync-event",eventData:{...b,id:_==null?void 0:_.id},studio_id:r}}).catch(()=>{})),lt("google-calendar-oauth",{body:{action:"sync-studio-event",studio_id:r,event:{...b,id:_==null?void 0:_.id}}}).catch(()=>{}),$(!1),g(""),s()},B=c==="desktop";return e.jsx("div",{className:"fixed inset-0 z-[100] flex",style:{background:"rgba(15,23,42,0.45)",alignItems:B?"center":"flex-end",justifyContent:"center"},onClick:a,children:e.jsxs("div",{onClick:E=>E.stopPropagation(),style:{width:B?480:"100%",background:n.bg,borderRadius:B?12:"
616px 16px 0 0",padding:B?"22px 24px 20px":"18px 18px 24px",boxShadow:B?"0 20px 40px rgba(0,0,0,0.25)":"0 -8px 24px rgba(0,0,0,0.15)"},children:[!B&&e.jsx("div",{style:{width:36,height:4,borderRadius:2,background:n.hair,margin:"0 auto 14px"}}),e.jsxs("div",{className:"font-bold",style:{fontSize:B?18:16,color:n.ink,letterSpacing:"-0.01em",marginBottom:4},children:[H?"Edit":"New"," ",U]}),e.jsx("div",{style:{fontSize:12.5,color:n.ink3,marginTop:3,marginBottom:18},children:"Visible to all staff after publish."}),e.jsx(ht,{label:"Title",children:e.jsx("input",{value:h,onChange:E=>g(E.target.value),placeholder:m?"e.g. Weekly Team Meeting":"e.g. Recital Tech Rehearsal",style:ft,autoFocus:!0})}),e.jsxs("div",{className:"grid",style:{gridTemplateColumns:B?"1fr 1fr":"1fr",gap:10},children:[e.jsx(ht,{label:o?"When":"Date",children:e.jsxs("div",{style:{...ft,background:n.surface,cursor:"default"},children:[ae(f,"EEE, MMM d"),o?` · ${Bt(N)}–${Bt(R)}`:""]})}),e.jsx(ht,{label:"Location",children:e.jsx("input",{value:C,onChange:E=>j(E.target.value),style:ft})})]}),!H&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",style:{marginTop:12,fontSize:12.5,color:n.ink2},children:[e.jsx("input",{type:"checkbox",checked:u,onChange:E=>d(E.target.checked),style:{width:14,height:14,accentColor:n.primary,cursor:"pointer"}}),"Notify staff by email, bell and push"]}),e.jsxs("div",{className:"flex gap-2",style:{marginTop:18,justifyContent:B?"flex-end":"stretch"},children:[e.jsx("button",{type:"button",onClick:a,className:"font-semibold",style:{flex:B?"0 0 auto":1,padding:B?"8px 16px":"10px",borderRadius:8,background:n.bg,border:`1px solid ${n.hair}`,color:n.ink2,fontSize:13},children:"Cancel"}),e.jsx("button",{type:"button",onClick:X,disabled:I||!h.trim(),className:"font-semibold disabled:cursor-not-allowed",style:{flex:B?"0 0 auto":1,padding:B?"8px 18px":"10px",borderRadius:8,background:h.trim()?n.primary:n.hair,color:"#fff",border:0,fontSize:13},children:I?H?"Saving…":"Publishing…":H?"Save":"Publish"})]})]})})}const ft={width:"100%",padding:"9px 11px",borderRadius:7,border:`1px solid ${n.hair}`,fontSize:13,color:n.ink,background:n.bg,boxSizing:"border-box",outline:"none"};function ht({label:t,children:a}){return e.jsxs("div",{style:{marginBottom:10},children:[e.jsx("div",{className:"font-bold uppercase",style:{fontSize:11,color:n.ink3,marginBottom:5,letterSpacing:"0.05em"},children:t}),a]})}function Qn({todayCount:t,unpaidCount:a,nextLabel:s,nextSub:r,showUnpaid:i,eyebrow:c="Staff Portal",hideStats:o=!1,right:m}){return e.jsxs("div",{className:"px-[28px] py-[14px] flex items-center gap-[16px] border-b",style:{background:n.bg,borderColor:n.hair},children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-[11px] font-medium mb-px",style:{color:n.ink3},children:[c?`${c} · `:"",ae(new Date,"EEEE, MMMM d")]}),e.jsx("div",{className:"text-[22px] font-bold",style:{color:n.ink,letterSpacing:"-0.015em"},children:"Schedule"})]}),!o&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(gt,{label:"Today",value:String(t),sub:"bookings",tone:n.classes}),i&&e.jsx(gt,{label:"Unpaid",value:String(a),sub:"lessons",tone:n.unpaid}),e.jsx(gt,{label:"Next",value:s,sub:r,tone:n.ink2})]}),m]})}function gt({label:t,value:a,sub:s,tone:r}){return e.jsxs("div",{className:"px-[12px] py-[6px] rounded-[8px] min-w-[88px]",style:{background:n.surface,border:`1px solid ${n.hair}`},children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase",style:{color:n.ink3,letterSpacing:"0.05em"},children:t}),e.jsx("div",{className:"text-[16px] font-bold mt-px",style:{color:r},children:a}),e.jsx("div",{className:"text-[10.5px] font-medium truncate",style:{color:n.ink3},children:s})]})}function Vn({tab:t,setTab:a,counts:s,showRhythm:r,hideTabs:i}){const o=[{id:"calendar",label:"Calendar",count:null},{id:"classes",label:"Classes",count:s.classes},{id:"privates",label:"Private Lessons",count:s.privates},{id:"events",label:"Events",count:s.events},{id:"shifts",label:"Shifts",count:null},...r?[{id:"meetings",label:"Team Meetings",count:s.meetings??null},{id:"rhythm",label:"Rhythm",count:null}]:[]].filter(m=>!(i!=null&&i.includes(m.id)));return e.jsx("div",{className:"px-[20px] flex items-end gap-1 border-b overflow-x-auto",style:{background:n.bg,borderColor:n.hair},children:o.map(m=>{const p=t===m.id;return e.jsxs("button",{type:"button",onClick:()=>a(m.id),className:"px-[14px] pt-[12px] pb-[14px] text-[13.5px] -mb-px flex items-center gap-2 shrink-0 whitespace-nowrap",style:{fontWeight:p?600:500,color:p?n.primary:n.ink3,background:"transparent",borderWidth:0,borderBottomWidth:2,borderBottomStyle:"solid",borderBottomColor:p?n.primary:"transparent"},children:[m.label,m.count!=null&&e.jsx("span",{className:"text-[10.5px] font-semibold px-[6px] py-px rounded-full min-w-[16px] text-center",style:{background:p?n.primarySoft:n.surface2,color:p?n.primary:n.ink3},children:m.count})]},m.id)})})}function ss({ev:t,onClose:a,onOpenBooking:s,onEdit:r,onDelete:i}){const c=_t(t.kind),o=t.kind==="classes"?"Class":t.kind==="privates"?"Private Lesson":t.kind==="meetings"?"Meeting":"Event",p=$e(t.date).toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric"});return e.jsxs("div",{className:"w-[320px] max-w-full shrink-0 border-l overflow-auto",style:{background:n.bg,borderColor:n.hair,padding:"18px 20px"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-[10px]",children:[e.jsx("div",{className:"w-2 h-2 rounded-[2px]",style:{background:c}}),e.jsx("div",{className:"text-[11px] font-bold uppercase",style:{color:c,letterSpacing:"0.06em"},children:o}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",onClick:a,className:"w-[26px] h-[26px] rounded-[6px] text-[14px] leading-none",style:{background:n.bg,border:`1px solid ${n.hair}`,color:n.ink3},children:"×"})]}),e.jsx("div",{className:"text-[19px] font-bold leading-tight",style:{color:n.ink,letterSpacing:"-0.01em"},children:t.title}),e.jsx("div",{className:"text-[13px] mt-[4px]",style:{color:n.ink3},children:p}),e.jsxs("div",{className:"mt-[16px] rounded-[8px] flex flex-col gap-[10px] p-[12px]",style:{background:n.surface,border:`1px solid ${n.hair}`},children:[e.jsx(Me,{label:"Time",value:`${de(...t.start)} – ${de(...t.end)}`}),t.room&&e.jsx(Me,{label:"Room",value:t.room}),t.instructor&&e.jsx(Me,{label:"Instructor",value:t.instructor}),t.students!=null&&e.jsx(Me,{label:"Students",value:`${t.students} enrolled`}),t.status&&e.jsx(Me,{label:"Payment",value:e.jsx("span",{className:"text-[10.5px] font-bold uppercase px-[7px] py-[2px] rounded-full",style:{background:t.status==="paid"?n.paidBg:n.unpaidBg,color:t.status==="paid"?n.paid:n.unpaid,letterSpacing:"0.04em"},children:t.status})}),t.price!=null&&t.price>0&&e.jsx(Me,{label:"Price",value:`$${t.price.toFixed(2)}`})]}),(s||r||i)&&e.jsxs("div",{className:"flex gap-2 mt-[16px]",children:[s&&e.jsx("button",{type:"button",onClick:s,className:"flex-1 px-[10px] py-[8px] rounded-[7px] text-[12.5px] font-semibold text-white",style:{background:n.primary,border:"none"},children:"Open booking"}),r&&e.jsx("button",{type:"button",onClick:r,className:"flex-1 px-[12px] py-[8px] rounded-[7px] text-[12.5px] font-semibold",style:{background:n.bg,color:n.ink2,border:`1px solid ${n.hair}`},children:"Edit"}),i&&e.jsx("button",{type:"button",onClick:i,className:"px-[12px] py-[8px] rounded-[7px] text-[12.5px] font-semibold",style:{background:n.bg,color:"#dc2626",border:"1px solid #fecaca"},children:"Remove"})]})]})}function Me({label:t,value:a}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase shrink-0",style:{color:n.ink3,width:80,letterSpacing:"0.04em"},children:t}),e.jsx("div",{className:"text-[13px] font-medium flex-1",style:{color:n.ink},children:a})]})}function ns({kind:t,label:a,on:s,onClick:r}){const i=_t(t);return e.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-[6px] px-[10px] py-[5px] rounded-full text-[12px] font-semibold transition-opacity",style:{border:`1px solid ${s?i:n.hair}`,background:s?ws(t):n.bg,color:s?i:n.ink4,opacity:s?1:.7},children:[e.jsx("span",{className:"w-2 h-2 rounded-[2px]",style:{background:i,op
6acity:s?1:.4}}),a]})}const Zn={office_hours:"Office",time_block:"Time Block",rehearsal:"Rehearsal",admin_work:"Admin",training:"Training",other:"Other"},zt=t=>String(t).padStart(2,"0"),as=t=>`${t.getFullYear()}-${zt(t.getMonth()+1)}-${zt(t.getDate())}`,Ft=t=>{const[a,s]=t.split(":").map(Number);return[a||0,s||0]};function Xn(t,a){const s=t.shift,r=as(a);return s.specific_date?s.specific_date===r:!(s.day_of_week!==a.getDay()||s.excluded_dates&&s.excluded_dates.includes(r)||s.effective_from&&r<s.effective_from||s.effective_until&&r>s.effective_until)}function Jn(t,a){const s=[];for(const r of a){const i=as(r);for(const c of t){if(!Xn(c,r))continue;const o=c.shift,m=o.work_type==="time_block";s.push({id:`shift-${c.staffId}-${c.index??"x"}-${i}`,kind:"shifts",title:m?o.notes||"Time Block":c.staffName||"Shift",start:Ft(o.start_time),end:Ft(o.end_time),date:i,room:Zn[o.work_type]||"Shift",shift:{staffId:c.staffId,staffName:c.staffName,photoUrl:c.photoUrl,index:c.index,draft:o}})}}return s}const Wt=t=>{const[a,s]=t,r=a<12?"AM":"PM";return`${(a+11)%12+1}:${String(s).padStart(2,"0")} ${r}`};function Kn({range:t,onClose:a,onShift:s,onTimeBlock:r,onEvent:i,onMeeting:c}){const o=[{key:"timeblock",label:"Time block",hint:"Personal block — not a work shift",icon:ds,on:r},{key:"shift",label:"New shift",hint:"Staff work time",icon:Yt,on:s},{key:"event",label:"New event",hint:"Recital, workshop, showcase…",icon:cn,on:i},{key:"meeting",label:"New meeting",hint:"Team / L10 meeting",icon:us,on:c}].filter(m=>m.on);return e.jsx(jt,{open:!!t,onOpenChange:m=>!m&&a(),children:e.jsx(vt,{className:"max-w-xs",children:t&&e.jsxs(e.Fragment,{children:[e.jsx(kt,{children:e.jsx(St,{children:"Add to calendar"})}),e.jsxs("p",{className:"-mt-1 text-sm text-muted-foreground",children:[ae(Fe(t.date),"EEE, MMM d")," · ",Wt(t.start)," – ",Wt(t.end)]}),e.jsx("div",{className:"mt-1 space-y-2",children:o.map(m=>{const p=m.icon;return e.jsxs("button",{type:"button",onClick:()=>{var x;a(),(x=m.on)==null||x.call(m)},className:"flex w-full items-center gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors hover:bg-muted",children:[e.jsx(p,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-semibold",children:m.label}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:m.hint})]})]},m.key)})})]})})})}function ea({staffId:t,staffName:a,studioId:s,shiftCount:r,canEdit:i,onClose:c}){return e.jsxs("div",{className:"flex h-full w-[320px] shrink-0 flex-col overflow-hidden border-l",style:{background:n.bg,borderColor:n.hair},children:[e.jsxs("div",{className:"flex items-start justify-between border-b px-4 py-3",style:{borderColor:n.hair},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",style:{color:n.ink},children:a}),e.jsxs("div",{className:"text-[11px]",style:{color:n.ink3},children:[r," shift",r===1?"":"s"," this week"]})]}),e.jsx("button",{type:"button",onClick:c,className:"rounded p-1 text-muted-foreground hover:bg-muted","aria-label":"Close",children:e.jsx(ps,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-3",children:[e.jsx("div",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"To-dos"}),e.jsx(Vs,{staffId:t,staffName:a,studioId:s,canEdit:i})]})]})}const ta=t=>{var a;return t.kind==="shifts"&&((a=t.shift)==null?void 0:a.draft.work_type)==="time_block"},He=t=>`${String(t[0]).padStart(2,"0")}:${String(t[1]).padStart(2,"0")}`;function sa({events:t,studioId:a,advanced:s,showAll:r,onToggleAll:i,shiftEntries:c,staffRoster:o,meStaffId:m,defaultFilters:p,hiddenKinds:x,onCreateShift:h,onCreateTimeBlock:g,onEditShift:C,onCreateEvent:j,onEditEvent:I,onDeleteEvent:$,onMoveItem:u}){var Ue,qe;const[d,f]=l.useState("week"),N=l.useMemo(()=>{const y=new Date;return new Date(y.getFullYear(),y.getMonth(),y.getDate())},[]),[R,U]=l.useState(N),[H,X]=l.useState(()=>({classes:(p==null?void 0:p.classes)??!0,privates:(p==null?void 0:p.privates)??!0,events:(p==null?void 0:p.events)??!0,meetings:(p==null?void 0:p.meetings)??!0,shifts:(p==null?void 0:p.shifts
6)??!0,timeblocks:(p==null?void 0:p.timeblocks)??!1})),[B,k]=l.useState(null),[A,E]=l.useState(!1),[M,T]=l.useState("all"),[b,_]=l.useState(null),[L,z]=l.useState(null),[Y,v]=l.useState(null),F=!!(h||g||j),J=y=>{const[q,W]=y,te=q<12?"AM":"PM";return`${(q+11)%12+1}:${String(W).padStart(2,"0")} ${te}`},K=l.useMemo(()=>{if(!(c!=null&&c.length))return t;const y=d==="day"?[R]:Array.from({length:7},(te,ue)=>we(Ge(R,{weekStartsOn:1}),ue)),q=new Set,W=Jn(c,y).filter(te=>{var S;const he=[(((S=te.shift)==null?void 0:S.staffName)??"").trim().toLowerCase(),te.date,te.start.join(":"),te.end.join(":"),te.title].join("|");return q.has(he)?!1:(q.add(he),!0)});return[...t,...W]},[t,c,d,R]),Q=l.useMemo(()=>{const y=new Map;for(const W of o??[])W.id&&y.set(W.id,W.name||"Staff");for(const W of t)W.teacherId&&!y.has(W.teacherId)&&y.set(W.teacherId,W.instructor||"Staff");for(const W of c??[])W.staffId&&!y.has(W.staffId)&&y.set(W.staffId,W.staffName||"Staff");const q=new Map;for(const[W,te]of y){const ue=te.replace(/ · inactive$/,"").trim().toLowerCase(),he=q.get(ue);he?(he.ids.push(W),te.endsWith(" · inactive")||(he.name=te)):q.set(ue,{id:W,name:te,ids:[W]})}return[...q.values()].sort((W,te)=>W.name.localeCompare(te.name))},[o,t,c]),ee=l.useMemo(()=>new Map(Q.map(y=>[y.id,y.ids])),[Q]),O=l.useMemo(()=>{const y=new Map;for(const q of t)q.kind==="classes"&&q.classId&&y.set(q.classId,q.title);return[...y].map(([q,W])=>({id:q,title:W})).sort((q,W)=>q.title.localeCompare(W.title))},[t]);l.useEffect(()=>{if(A||!m)return;const y=Q.find(q=>q.ids.includes(m));y&&k(q=>q===null?new Set([y.id]):q)},[m,Q,A]);const w=y=>{if(!B||y.kind==="events"||y.kind==="meetings")return!0;const q=new Set([...B].flatMap(W=>ee.get(W)??[W]));return y.kind==="shifts"?!!y.shift&&q.has(y.shift.staffId):y.teacherId!=null&&q.has(y.teacherId)},P=y=>x!=null&&x.includes(y.kind)?!1:y.kind==="shifts"?ta(y)?H.timeblocks:H.shifts:H[y.kind],ne=l.useMemo(()=>K.filter(y=>P(y)&&w(y)&&(M==="all"||y.kind!=="classes"||y.classId===M)),[K,H,B,M]),V=A&&B&&B.size===1?[...B][0]:null,ye=V?((Ue=Q.find(y=>y.id===V))==null?void 0:Ue.name)??"Employee":null,re=l.useMemo(()=>V?K.filter(y=>{var q;return y.kind==="shifts"&&((q=y.shift)==null?void 0:q.staffId)===V}).length:0,[K,V]),me=y=>{if(y.kind==="shifts"&&y.shift&&C){C({staffId:y.shift.staffId,staffName:y.shift.staffName,shift:y.shift.draft,index:y.shift.index},y.date);return}_(y)},fe=!B||B.size===Q.length?"All employees":B.size===0?"No employees":B.size===1?((qe=Q.find(y=>y.id===[...B][0]))==null?void 0:qe.name)??"1 employee":`${B.size} employees`,Pe=y=>{E(!0),k(q=>{const W=q??new Set(Q.map(ue=>ue.id)),te=new Set(W);return te.has(y)?te.delete(y):te.add(y),te.size===Q.length?null:te})},We=d==="day"?1:7,at=d==="day"?je(R,N)?`Today · ${bt(R)}`:bt(R):(()=>{const y=Ge(R,{weekStartsOn:1}),q=we(y,6);return`${xe(y)} – ${xe(q)}, ${q.getFullYear()}`})();return e.jsxs("div",{className:"h-full flex flex-col",style:{background:n.bg},children:[e.jsxs("div",{className:"px-[20px] py-[12px] flex items-center gap-[14px] border-b",style:{borderColor:n.hair},children:[e.jsx("button",{type:"button",onClick:()=>U(N),className:"px-[12px] py-[6px] rounded-[7px] text-[12.5px] font-semibold",style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink},children:"Today"}),e.jsxs("div",{className:"flex gap-[2px]",children:[e.jsx(Ut,{dir:"‹",onClick:()=>U(y=>we(y,-We))}),e.jsx(Ut,{dir:"›",onClick:()=>U(y=>we(y,We))})]}),e.jsx("div",{className:"text-[15px] font-semibold",style:{color:n.ink,letterSpacing:"-0.01em"},children:at}),e.jsx("div",{className:"flex-1"}),i&&e.jsx("button",{type:"button",onClick:i,className:"rounded-full px-[12px] py-[6px] text-[12px] font-semibold shrink-0",style:{border:`1px solid ${r?n.ink:n.hair}`,background:r?n.ink:n.bg,color:r?"#fff":n.ink2},title:r?"Showing the whole studio schedule":"Show the whole studio schedule",children:"All"}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[[["classes","Classes"],["privates","Privates"],["events","Events"],["meetings","Meetings"],["shifts","Shifts"]].filter(([y])=>!(x!=null&&x.includes(y))).map(([y,q])=>e.jsx(ns,{kind:y,label:q,on:H[y],onClick:()=>X(W=>({...W,[y]:!W[y]}))},y)),e.jsxs("button",{type:"button",onClick:()=>X(y=>({...y,timeblocks:!y.timeblocks}
6)),className:"flex items-center gap-[6px] rounded-full px-[10px] py-[5px] text-[12px] font-semibold transition-opacity",style:{border:`1px solid ${H.timeblocks?"#e11d48":n.hair}`,background:H.timeblocks?"#ffe4e6":n.bg,color:H.timeblocks?"#be123c":n.ink4,opacity:H.timeblocks?1:.7},children:[e.jsx("span",{className:"h-2 w-2 rounded-[2px]",style:{background:"#e11d48",opacity:H.timeblocks?1:.4}}),"Time Blocks"]})]}),s&&(Q.length>0||O.length>0)&&e.jsxs("div",{className:"flex items-center gap-1",children:[Q.length>0&&e.jsxs(Ye,{children:[e.jsx(Qe,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded-[7px] px-[10px] py-[6px] text-[12.5px] font-medium",style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink},children:[e.jsx(Yt,{className:"h-3.5 w-3.5"}),fe]})}),e.jsxs(Ve,{align:"end",className:"w-56 p-2",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 px-1 pb-1",children:[e.jsx("button",{type:"button",onClick:()=>{E(!0),k(new Set(Q.map(y=>y.id)))},className:"flex-1 rounded-md border border-primary/40 bg-primary/5 px-2 py-1 text-[11px] font-semibold text-primary hover:bg-primary/10",children:"Select all"}),e.jsx("button",{type:"button",onClick:()=>{E(!0),k(new Set)},className:"flex-1 rounded-md border px-2 py-1 text-[11px] font-medium text-muted-foreground hover:bg-muted",children:"Clear all"})]}),e.jsx("div",{className:"max-h-64 space-y-0.5 overflow-auto border-t pt-1",children:Q.map(y=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted",children:[e.jsx(xs,{checked:!B||B.has(y.id),onCheckedChange:()=>Pe(y.id)}),e.jsx("span",{className:"truncate",children:y.name})]},y.id))})]})]}),O.length>0&&!(x!=null&&x.includes("classes"))&&e.jsxs(ms,{value:M,onValueChange:T,children:[e.jsx(fs,{className:"h-[32px] w-[150px] text-[12.5px]",children:e.jsx(hs,{})}),e.jsxs(gs,{children:[e.jsx(wt,{value:"all",children:"All classes"}),O.map(y=>e.jsx(wt,{value:y.id,children:y.title},y.id))]})]})]}),e.jsx("div",{className:"w-px self-stretch mx-1",style:{background:n.hair}}),e.jsx(na,{value:d,onChange:f,options:[["day","Day"],["week","Week"]]})]}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:d==="week"?e.jsx(ke,{day:R,events:ne,selected:b,onSelect:me,onRangeSelect:F?z:void 0,onMove:u?(y,q,W,te)=>v({ev:y,dateISO:q,start:W,end:te}):void 0}):e.jsx(ve,{day:R,events:ne,selected:b,onSelect:me,onRangeSelect:F?z:void 0})}),b&&b.kind!=="classes"&&b.kind!=="shifts"?e.jsx(ss,{ev:b,onClose:()=>_(null),onEdit:I&&(b.kind==="events"||b.kind==="meetings")?()=>{const y=b;_(null),I(y)}:void 0,onDelete:$&&(b.kind==="events"||b.kind==="meetings")?()=>{const y=b;_(null),$(y)}:void 0}):V&&a?e.jsx(ea,{staffId:V,staffName:ye??"Employee",studioId:a,shiftCount:re,canEdit:!!s,onClose:()=>{E(!0),k(null)}}):null]}),e.jsx(nt,{open:(b==null?void 0:b.kind)==="classes",onOpenChange:y=>!y&&_(null),row:(b==null?void 0:b.kind)==="classes"?b:null,studioId:a}),e.jsx(jt,{open:!!Y,onOpenChange:y=>!y&&v(null),children:e.jsx(vt,{className:"max-w-xs",children:Y&&e.jsxs(e.Fragment,{children:[e.jsx(kt,{children:e.jsxs(St,{children:["Move this ",Y.ev.kind==="shifts"?"shift":Y.ev.kind==="meetings"?"meeting":"event","?"]})}),e.jsxs("p",{className:"-mt-1 text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:Y.ev.title}),e.jsx("br",{}),"→ ",ae(Fe(Y.dateISO),"EEE, MMM d")," · ",J(Y.start)," – ",J(Y.end)]}),e.jsxs(ys,{className:"flex-row justify-end gap-2 sm:justify-end",children:[e.jsx(Nt,{variant:"outline",size:"sm",onClick:()=>v(null),children:"No"}),e.jsx(Nt,{size:"sm",onClick:()=>{u==null||u(Y.ev,Y.dateISO,Y.start,Y.end),v(null)},children:"Yes, move"})]})]})})}),e.jsx(Kn,{range:L,onClose:()=>z(null),onShift:h&&L?()=>h(L.date,He(L.start),He(L.end)):void 0,onTimeBlock:g&&L?()=>g(L.date,He(L.start),He(L.end)):void 0,onEvent:j&&L?()=>j(L,!1):void 0,onMeeting:j&&L?()=>j(L,!0):void 0})]})}function Ut({dir:t,onClick:a}){return e.jsx("button",{type:"button",onClick:a,className:"w-[30px] h-[30px] rounded-[7px] text-[16px] leading-none",style:{border:`1px solid ${n.hair}`,background:n.bg,color:n.ink2},children:t})}function na({value:t,onChange:a,options:s}){return e.jsx("div",{className:"flex p-[2px] rounded-[7px]",style:{background:n.surface2},children:s.map(([r,i])=>{const c=r===t;return e.jsx("button",{type:"button",onClick:()=>a(r),className:"px-[14px] py-[5px] rounded-[5px] text-[12.5px] font-semibold",style:{background:c?n.bg:"transparent",color:c?n.ink:n.ink3,boxShadow:c?"0 1px 2px rgba(0,0,0,0.06)":"none",border:"none"},children:i},r)})})}const aa=[["classes","Classes"],["privates","Privates"],["events","Events"]];function ra({events:t,studioId:a,showAll:s,onToggleAll:r,chips:i=aa}){const[c,o]=l.useState("day"),m=l.useMemo(()=>{const d=new Date;return new Date(d.getFullYear(),d.getMonth(),d.getDate())},[]),[p,x]=l.useState(m),[h,g]=l.useState(null),[C,j]=l.useState(()=>Object.fromEntries(i.map(([d])=>[d,!0]))),I=l.useMemo(()=>t.filter(d=>!!C[d.kind]),[t,C]),$=c==="day"?1:7,u=c==="day"?je(p,m)?`Today, ${xe(p)}`:bt(p):(()=>{const d=Ge(p,{weekStartsOn:1}
6),f=we(d,6);return`${xe(d)} – ${xe(f)}`})();return e.jsxs("div",{className:"h-full flex flex-col relative",style:{background:D.bg},children:[e.jsxs("div",{className:"sticky top-0 px-[14px] py-[8px] pt-[10px] flex items-center justify-between gap-2 border-b z-[4]",style:{background:D.bg,borderColor:D.hair2},children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(qt,{onClick:()=>x(d=>we(d,-$)),children:"‹"}),e.jsx("button",{type:"button",onClick:()=>x(m),className:"px-[8px] py-[4px] rounded-[6px] text-[11px] font-semibold",style:{border:`1px solid ${D.hair}`,background:"transparent",color:D.primary},children:"Today"}),e.jsx(qt,{onClick:()=>x(d=>we(d,$)),children:"›"})]}),e.jsx("div",{className:"flex-1 text-center text-[13px] font-semibold",style:{color:D.ink},children:u}),e.jsx(la,{value:c,onChange:o,options:[["day","Day"],["week","Week"]]})]}),e.jsxs("div",{className:"flex items-center gap-1 px-[14px] py-[8px] overflow-x-auto",style:{background:D.bg,borderBottom:`1px solid ${D.hair2}`},children:[r&&e.jsx("button",{type:"button",onClick:r,className:"shrink-0 px-[10px] py-[5px] rounded-full text-[11px] font-semibold mr-1",style:{border:`1px solid ${s?D.primary:D.hair}`,background:s?D.primary:"transparent",color:s?"#fff":D.ink2},title:s?"Showing the whole studio schedule":"Show the whole studio schedule",children:"All"}),i.map(([d,f])=>e.jsx(ns,{kind:d,label:f,on:!!C[d],onClick:()=>j(N=>({...N,[d]:!N[d]}))},d))]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:c==="day"?e.jsx(ve,{day:p,events:I,selected:h,onSelect:g}):e.jsx(ke,{day:p,events:I,selected:h,onSelect:g})}),h&&h.kind!=="classes"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 z-10 bg-black/20",onClick:()=>g(null)}),e.jsx("div",{className:"absolute inset-y-0 right-0 z-20 flex w-[min(320px,85%)] shadow-xl",children:e.jsx(ss,{ev:h,onClose:()=>g(null)})})]}),e.jsx(nt,{open:(h==null?void 0:h.kind)==="classes",onOpenChange:d=>!d&&g(null),row:(h==null?void 0:h.kind)==="classes"?h:null,studioId:a})]})}function qt({children:t,onClick:a}){return e.jsx("button",{type:"button",onClick:a,className:"w-[28px] h-[28px] rounded-[6px] flex items-center justify-center text-[16px] leading-none",style:{border:`1px solid ${D.hair}`,background:D.bg,color:D.ink2},children:t})}function la({value:t,onChange:a,options:s}){return e.jsx("div",{className:"flex p-[2px] rounded-[7px]",style:{background:D.hair2},children:s.map(([r,i])=>{const c=r===t;return e.jsx("button",{type:"button",onClick:()=>a(r),className:"px-[10px] py-[4px] rounded-[5px] text-[11.5px] font-semibold",style:{background:c?D.bg:"transparent",color:c?D.ink:D.ink3,boxShadow:c?"0 1px 2px rgba(0,0,0,0.06)":"none",border:"none"},children:i},r)})})}function rs(t,a){const s=a==null?void 0:a.self,r=a==null?void 0:a.orgStudioIds,i=r!=null&&r.length?[...r].sort().join(","):"",[c,o]=l.useState([]),[m,p]=l.useState(!0),x=l.useCallback(async()=>{p(!0);try{if(s){const u=await Zs(s.staffId);o([{staff_id:s.staffId,full_name:s.staffName,photo_url:null,studio_id:t,shifts:u}])}else o(i?await Xs(i.split(",")):t?await Js(t):[])}catch(u){console.error("load shift board",u),se.error("Failed to load shifts")}finally{p(!1)}},[t,s==null?void 0:s.staffId,s==null?void 0:s.staffName,i]);l.useEffect(()=>{x()},[x]);const h=l.useMemo(()=>new Map(c.map(u=>[u.staff_id,u])),[c]),g=l.useMemo(()=>s?[]:c.map(u=>({id:u.staff_id,name:u.inactive?`${u.full_name} · inactive`:u.full_name,avatar_url:u.photo_url})),[c,s]),C=l.useMemo(()=>c.flatMap(u=>u.shifts.map((d,f)=>({staffId:u.staff_id,staffName:u.full_name,photoUrl:u.photo_url,shift:d,index:f}))),[c]),j=l.useCallback(async(u,d,f)=>{const N=d??(f==null?void 0:f.targetStaffId)??(s==null?void 0:s.staffId);if(!N)return;const R=h.get(N);if(R)try{if((f==null?void 0:f.isEdit)&&f.index!=null&&f.targetStaffId&&f.targetStaffId!==N){const H=h.get(f.targetStaffId);H&&await Oe(f.targetStaffId,H.studio_id??t,H.shifts.filter((X,B)=>B!==f.index)),await Oe(N,R.studio_id??t,[...R.shifts,u]),se.success(`Moved the shift to ${R.full_name}`)}else{const H=f!=null&&f.isEdit&&f.index!=null?R.shifts.map((X,B)=>B===f.index?u:X):[...R.shifts,u];await Oe(N,R.studio_id??t,H),se.success(s?"Saved your shift":`Saved ${R.full_name}'s shift`)}await x()}catch(U){console.error("save staff shifts",U),se.error((U==null?void 0:U.message)||"Couldn't save shift")}},[h,t,s,x]),I=l.useCallback(async u=>
6{if(!(u!=null&&u.isEdit)||u.index==null||!u.targetStaffId)return;const d=h.get(u.targetStaffId);if(d)try{await Oe(u.targetStaffId,d.studio_id??t,d.shifts.filter((f,N)=>N!==u.index)),se.success(s?"Removed your shift":`Removed a shift for ${d.full_name}`),await x()}catch(f){console.error("delete staff shift",f),se.error((f==null?void 0:f.message)||"Couldn't delete shift")}},[h,t,s,x]),$=l.useCallback(async(u,d,f)=>{const N=h.get(u.staffId);if(!(!N||u.index==null))try{await Oe(u.staffId,N.studio_id??t,Ks(N.shifts,u.index,d,f)),se.success(s?"Updated your shifts":`Updated ${N.full_name}'s shifts`),await x()}catch(R){se.error((R==null?void 0:R.message)||"Couldn't delete shift")}},[h,t,s,x]);return{board:c,loading:m,byId:h,staffOptions:g,entries:C,reload:x,saveQuick:j,deleteQuick:I,deleteEntry:$}}function oa(){return e.jsxs("div",{className:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground",children:[e.jsx(Gt,{className:"h-4 w-4 animate-spin"})," Loading shifts…"]})}function ia({isAdmin:t,studioId:a,staffId:s,staffName:r}){return t?e.jsx(ca,{studioId:a}):s?e.jsx("div",{className:"h-full overflow-auto p-4",children:e.jsx(en,{staffId:s,studioId:a,staffName:r||"You",canEdit:!0,isSelf:!0})}):e.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"No staff profile is linked to your account yet."})}function ca({studioId:t}){const{board:a,loading:s,entries:r,staffOptions:i,saveQuick:c,deleteQuick:o,deleteEntry:m}=rs(t),[p,x]=l.useState(null),h=p??new Set(a.map(d=>d.staff_id)),[g,C]=l.useState(null),j=l.useMemo(()=>r.filter(d=>h.has(d.staffId)),[r,h]),I=d=>x(()=>{const f=new Set(h);return f.has(d)?f.delete(d):f.add(d),f}),$=(d,f)=>c(d,f,g).then(()=>C(null)),u=()=>o(g).then(()=>C(null));return s?e.jsx(oa,{}):e.jsxs("div",{className:"h-full overflow-auto p-4",children:[a.length>0&&e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>x(h.size===a.length?new Set:new Set(a.map(d=>d.staff_id))),className:"rounded-full border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted",children:h.size===a.length?"Clear all":"Select all"}),a.map(d=>{const f=h.has(d.staff_id);return e.jsxs("button",{type:"button",onClick:()=>I(d.staff_id),className:`flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs ${f?"font-medium":"text-muted-foreground opacity-60"}`,children:[e.jsx("span",{className:`inline-block h-2.5 w-2.5 rounded-full ${tn(d.staff_id).split(" ")[0]}`}),d.full_name]},d.staff_id)})]}),e.jsx(sn,{entries:j,colorBy:"staff",canEdit:!0,onCreateSlot:(d,f,N)=>C({seed:{dateISO:d,start_time:f,end_time:N,work_type:"office_hours"},isEdit:!1,targetStaffId:null,index:null}),onEditEntry:(d,f)=>C({seed:{dateISO:f,start_time:d.shift.start_time,end_time:d.shift.end_time,work_type:d.shift.work_type,specific_date:d.shift.specific_date,notes:d.shift.notes,color:d.shift.color,staffId:d.staffId},isEdit:!0,targetStaffId:d.staffId,index:d.index??null}),onDeleteEntry:(d,f,N)=>void m(d,f,N)}),e.jsx(Xt,{open:!!g,onOpenChange:d=>{d||C(null)},seed:(g==null?void 0:g.seed)??null,isEdit:!!(g!=null&&g.isEdit),staffOptions:g?i:void 0,onSave:$,onDelete:u})]})}const da=["calendar","classes","privates","events","shifts","meetings","rhythm"];function ua(t){return!!t&&da.includes(t)}function kr({studio:t,urlSync:a=!0,initialTab:s="calendar",hqContext:r=!1,orgWideShifts:i=!1,meetingsOnly:c=r}={}){const o=bs(),m=dn(),p=js(),x=t??(p==null?void 0:p.studio),{user:h,staffMember:g,userProfile:C}=vs(),[j,I]=Ht(),$=a&&ua(j.get("tab"))?j.get("tab"):s,[u,d]=l.useState($);l.useEffect(()=>{if(a){if(u==="calendar"){const S=new URLSearchParams(j);S.delete("tab"),I(S,{replace:!0})}else if(j.get("tab")!==u){const S=new URLSearchParams(j);S.set("tab",u),I(S,{replace:!0})}}},[u]);const f=l.useMemo(()=>x!=null&&x.id?{id:x.id,name:x.name,slug:x.slug,organizationId:x.organization_id,media_enabled:x.media_enabled}:null,[x]),N=l.useMemo(()=>!(g!=null&&g.id)||!(g!=null&&g.studio_id)?null:{id:g.id,full_name:(C==null?void 0:C.full_name)||g.full_name||"Your teacher",studio_id:g.studio_id},[g,C]),R=l.useMemo(()=>r&&(!o||o.isOrgAdmin)?!0:((g==null?void 0:g.roles)||[]).some(Z=>["admin","studio_founder_admin","founder","general_manager"].includes(Z)),[g,r,o]),U=Ss(),{data:H}=an(f==null?void 0:f.id,f==null?void 0:f.organizationId),{data:X=0}=rn(f==null?void 0:f.id,!!H),{loading:B,calendarItems:k,eventList:A,rawStudioEvents:E,privateLessonById:M,reload:T,setRsvpLocal:b}=mn({studio:f,staff:N,isAdmin:R}),[_,L]=l.useState(!1),[z,Y]=l.useState(2),[v,F]=l.useState(!1),{studioIds:J}=ks(i?(f==null?void 0:f.organizationId)??void 0:void 0,{includeHq:!0}),K=rs(N?(f==null?void 0:f.id)??"":"",{self:!R&&N?{staffId:N.id,staffName:N.full_name}:void 0,orgStudioIds:i&&N&&R?J:void 0}),[Q,ee]=l.useState(null),[O,w]=l.useState(null),[P,ne]=l.useState(null),V=async(S,Z,oe,ge)=>{const pe=le=>`${String(le[0]).padStart(2,"0")}
6:${String(le[1]).padStart(2,"0")}`;if(S.kind==="shifts"&&S.shift){const[le,ce,Se]=Z.split("-").map(Number),ie=new Date(le,ce-1,Se).getDay(),Ce=!S.shift.draft.specific_date,rt={...S.shift.draft,specific_date:Ce?null:Z,day_of_week:ie,start_time:pe(oe),end_time:pe(ge)};await K.saveQuick(rt,S.shift.staffId,{isEdit:!0,targetStaffId:S.shift.staffId,index:S.shift.index??null});return}if(S.kind==="events"||S.kind==="meetings"){const{error:le}=await G.from("studio_events").update({start_at:`${Z}T${pe(oe)}:00`,end_at:`${Z}T${pe(ge)}:00`,updated_at:new Date().toISOString()}).eq("id",S.id);if(le){se.error("Couldn't move it");return}T(),se.success("Rescheduled")}},ye=S=>ne(S),re=async S=>{const Z=S.kind==="meetings"?"Meeting":"Event",{data:oe}=await G.from("studio_events").select("*").eq("id",S.id).maybeSingle(),{error:ge}=await G.from("studio_events").delete().eq("id",S.id);if(ge){se.error(`Couldn't remove the ${Z.toLowerCase()}`);return}T(),se.success(`${Z} removed`,{action:oe?{label:"Undo",onClick:async()=>{const{id:pe,...le}=oe;await G.from("studio_events").insert(le),T()}}:void 0})},me=(S,Z,oe)=>ee({seed:{dateISO:S,start_time:Z,end_time:oe,work_type:"office_hours"},isEdit:!1,targetStaffId:R?null:(N==null?void 0:N.id)??null,index:null}),fe=(S,Z,oe)=>ee({seed:{dateISO:S,start_time:Z,end_time:oe,work_type:"time_block",color:"blue"},isEdit:!1,targetStaffId:R?null:(N==null?void 0:N.id)??null,index:null}),Pe=(S,Z)=>ee({seed:{dateISO:Z,start_time:S.shift.start_time,end_time:S.shift.end_time,work_type:S.shift.work_type,specific_date:S.shift.specific_date,notes:S.shift.notes,color:S.shift.color,staffId:S.staffId},isEdit:!0,targetStaffId:S.staffId,index:S.index??null}),We=(S,Z)=>K.saveQuick(S,Z,Q).then(()=>ee(null)),at=()=>K.deleteQuick(Q).then(()=>ee(null)),Ue=r?{classes:!1,privates:!1,events:!0,meetings:!0,shifts:!0,timeblocks:!1}:void 0;l.useEffect(()=>{f!=null&&f.id&&(async()=>{const{data:S}=await G.from("studios").select("private_lesson_cancel_norefund_hours").eq("id",f.id).single();(S==null?void 0:S.private_lesson_cancel_norefund_hours)!=null&&Y(S.private_lesson_cancel_norefund_hours)})()},[f==null?void 0:f.id]);const qe=l.useMemo(()=>{let S=0;for(const Z of M.values())Z.status!=="cancelled"&&Z.payment_status==="unpaid"&&!Z.credit_id&&(S+=Number(Z.price)||0);return S},[M]),y=l.useMemo(()=>!N||R?k:k.filter(S=>S.kind==="events"||S.kind==="meetings"?!0:S.teacherId===N.id),[k,N,R]),q=k.length>y.length,W=v&&q?k:y;l.useEffect(()=>{v&&!q&&F(!1)},[v,q]);const te=l.useMemo(()=>{const S=new Date,Z=ae(S,"yyyy-MM-dd"),oe=W.filter(ce=>ce.lessonStatus!=="cancelled"),ge=oe.filter(ce=>ce.kind==="classes"&&ce.date>=Z).length,pe=oe.filter(ce=>ce.kind==="privates"&&ce.date>=Z).length,le=E.filter(ce=>!ce.meetingCategory&&(Be(ce.startAt)??new Date(ce.startAt))>=new Date(S.toDateString())).length;return{classes:ge,privates:pe,events:le}},[W,E]),ue=l.useMemo(()=>{const S=new Date,Z=ae(S,"yyyy-MM-dd"),oe=W.filter(ie=>ie.lessonStatus!=="cancelled"),ge=oe.filter(ie=>ie.date===Z).length,pe=oe.filter(ie=>ie.kind==="privates"&&ie.status==="unpaid"&&ie.date>=Z).length,le=S.getTime(),Se=[...oe].sort((ie,Ce)=>{const rt=new Date(`${ie.date}T${_e(ie.start[0])}:${_e(ie.start[1])}:00`).getTime(),ls=new Date(`${Ce.date}T${_e(Ce.start[0])}:${_e(Ce.start[1])}:00`).getTime();return rt-ls}).find(ie=>new Date(`${ie.date}T${_e(ie.start[0])}:${_e(ie.start[1])}:00`).getTime()>le);return{todayCount:ge,unpaidCount:pe,nextLabel:Se?pa(Se.start[0],Se.start[1]):"—",nextSub:Se?Se.title:"Nothing scheduled"}},[W]);async function he(S,Z){var pe;if(!(N!=null&&N.id))return;if((((pe=A.find(le=>le.id===S))==null?void 0:pe.rsvp)??null)===Z){const{error:le}=await G.from("event_rsvps").delete().eq("event_id",S).eq("staff_id",N.id);if(le){se.error("Couldn't update RSVP");return}b(S,null)}else if(Z){const le=xn(Z);if(!le)return;const{error:ce}=await G.from("event_rsvps").upsert({event_id:S,staff_id:N.id,status:le},{onConflict:"event_id,staff_id"});if(ce){se.error("Couldn't update RSVP");return}b(S,Z)}}return!f||!N?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:f?"
6Staff record missing.":"Studio not found."})}):e.jsxs("div",{className:"h-full flex flex-col",style:{background:n.surface,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',color:n.ink},children:[e.jsx("div",{className:`hidden md:block ${u==="calendar"||u==="rhythm"?"":"w-full max-w-3xl"}`,children:e.jsx(Qn,{todayCount:ue.todayCount,unpaidCount:ue.unpaidCount,nextLabel:ue.nextLabel,nextSub:ue.nextSub,showUnpaid:R,eyebrow:o?"":void 0,hideStats:r,right:m})}),m&&e.jsx("div",{className:"md:hidden flex justify-end px-4 pt-2",children:m}),e.jsx("div",{className:u==="calendar"||u==="rhythm"||u==="shifts"?"":"w-full max-w-3xl",children:e.jsx(Vn,{tab:u,setTab:d,counts:{...te,meetings:X},showRhythm:!!H,hideTabs:r?["classes","privates"]:void 0})}),e.jsx("div",{className:`flex-1 min-h-0 overflow-hidden ${u==="calendar"||u==="rhythm"||u==="shifts"?"":"w-full max-w-3xl"}`,children:B?e.jsx(xa,{}):u==="shifts"?e.jsx(ia,{isAdmin:R,studioId:f.id,staffId:N.id,staffName:N.full_name}):!R&&k.length===0&&A.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-8 text-center",children:[e.jsx("p",{className:"text-base font-semibold",style:{color:n.ink},children:"No schedule yet"}),e.jsx("p",{className:"mt-1.5 max-w-xs text-sm text-muted-foreground",children:"You don't have any classes, lessons, or events assigned to you yet. Once an admin assigns you, they'll show up here."})]}):u==="calendar"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:flex h-full flex-col",children:e.jsx(sa,{events:W,studioId:(x==null?void 0:x.id)??null,advanced:R,showAll:v,onToggleAll:q?()=>F(S=>!S):void 0,shiftEntries:K.entries,staffRoster:K.staffOptions.map(S=>({id:S.id,name:S.name})),meStaffId:r?null:(N==null?void 0:N.id)??null,defaultFilters:Ue,hiddenKinds:r?["classes","privates"]:void 0,onCreateShift:me,onCreateTimeBlock:fe,onEditShift:Pe,onCreateEvent:U?(S,Z)=>w({range:S,isMeeting:Z}):void 0,onEditEvent:U?ye:void 0,onDeleteEvent:U?re:void 0,onMoveItem:U||R?V:void 0})}),e.jsx("div",{className:"md:hidden h-full",children:e.jsx(ra,{events:W,chips:r?[["events","Events"],["meetings","Meetings"]]:void 0,studioId:(x==null?void 0:x.id)??null,showAll:v,onToggleAll:q?()=>F(S=>!S):void 0})})]}):u==="classes"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block h-full",children:e.jsx(Rn,{items:W,isSelfView:!v,studioId:f.id})}),e.jsx("div",{className:"md:hidden h-full",children:e.jsx(En,{items:W,studioId:f.id})})]}):u==="privates"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block h-full",children:e.jsx(Wn,{items:W,isSelfView:!v,isAdmin:R,studioId:f.id,staffName:N.full_name,noRefundHours:z,privateLessonById:M,outstandingBalance:qe,onReload:T})}),e.jsx("div",{className:"md:hidden h-full",children:e.jsx(Pn,{items:W,isSelfView:!v,isAdmin:R,studioId:f.id,staffName:N.full_name,noRefundHours:z,privateLessonById:M,onReload:T})})]}):u==="meetings"?e.jsx(ln,{studioId:f.id,studioSlug:f.slug}):u==="rhythm"?e.jsx("div",{className:"h-full overflow-auto p-4",children:e.jsx(on,{studioId:f.id,userId:h==null?void 0:h.id,canEdit:U})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block h-full",children:e.jsx(Gn,{events:A.filter(S=>!S.meetingCategory),calendarEvents:W.filter(S=>S.kind==="events"),canEdit:U,onCreate:()=>L(!0),onRsvp:he})}),e.jsx("div",{className:"md:hidden h-full",children:e.jsx(Yn,{events:A.filter(S=>!S.meetingCategory),calendarEvents:W.filter(S=>S.kind==="events"),canEdit:U,onCreate:()=>L(!0),onRsvp:he})})]})}),_&&(h==null?void 0:h.id)&&e.jsx(mt,{open:_,onClose:()=>L(!1),onCreated:()=>{L(!1),T()},studioId:f.id,studioSlug:f.slug,userId:h.id,variant:"desktop"}),e.jsx(Xt,{open:!!Q,onOpenChange:S=>{S||ee(null)},seed:(Q==null?void 0:Q.seed)??null,isEdit:!!(Q!=null&&Q.isEdit),staffOptions:Q&&R?K.staffOptions:void 0,onSave:We,onDelete:at}),O&&(h==null?void 0:h.id)&&e.jsx(mt,{open:!!O,onClose:()=>w(null),onCreated:()=>{w(null),T()},studioId:f.id,studioSlug:f.slug,userId:h.id,variant:"desktop",seed:O.range,isMeeting:O.isMeeting}),P&&(h==null?void 0:h.id)&&e.jsx(mt,{open:!!P,onClose:()=>ne(null),onCreated:()=>{ne(null),T()}
6,studioId:f.id,studioSlug:f.slug,userId:h.id,variant:"desktop",isMeeting:P.kind==="meetings",seed:{date:P.date,start:P.start,end:P.end},edit:{id:P.id,title:P.title,location:P.room}})]})}function _e(t){return String(t).padStart(2,"0")}function pa(t,a){const s=t>=12?"PM":"AM";return`${(t+11)%12+1}:${_e(a)} ${s}`}function xa(){return e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx("div",{className:"text-sm",style:{color:n.ink3},children:"Loading schedule…"})})}export{kr 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.