1import{a as o,j as e}from"./react-vendor-DJtAp8P_.js";import{d as _e}from"./dayjs-CeefjyDY.js";import{aB as Ut,B as Ea,F as Da,ao as Ma,bm as va,bn as Ta,bo as _a}from"./mutation-CBAS9dQ5.js";import{o as Yt,a as ka,aJ as Fa,aK as Aa,aL as Oa}from"./query-C7Xvvnmk.js";import{T as xt,d as ft,u as mt,e as $t,V as Qe,W as Xe,R as O,X as qe,d8 as La,E as Va,h as Bt,P as K,N as kt,a1 as Ra,q as be,j as Ia,ac as Ua,aa as Ya}from"./index-D7JOLfRZ.js";import{a as $a}from"./club-f_sCz1gj.js";import{w as Ba,p as Pa,a as Wa}from"./gafferDugoutHandoff-XpKOt_uZ.js";import{r as Pt}from"./imageUrl-gCnBcCAn.js";import{ManageFixtureModalV2 as za}from"./index-B9RpxLnA.js";import{DuplicateFixtureModalV2 as Ha}from"./index-B1YZx4o_.js";import{DuplicateSessionModalV2 as Qa}from"./DuplicateSessionModalV2-B4hPKdTn.js";import{C as Xa}from"./index-CwydS-DZ.js";import{u as qa}from"./index-CyvRS9jZ.js";import{D as Wt,a as zt,b as Ht,c as Ga,e as Ja}from"./dropdown-menu-F3swUiZd.js";import{B as Qt}from"./index-BqhCUeR9.js";import{I as ge}from"./IconTooltipC-BpUCGPZT.js";import{S as Za}from"./sliders-horizontal-BXZc9NIH.js";import{P as pt}from"./plus-BUgo-MEI.js";import{C as Xt}from"./chevron-down-mjJIujzU.js";import{S as Ka,I as es,D as ts,M as as,W as ss,a as ns,R as os,b as is,r as rs}from"./syncfusion-BI7Abxc7.js";import{a as ls,b as ds,c as cs}from"./popover-B8lrz72k.js";import{C as Ft}from"./chevron-left-9Y5dS79z.js";import{u as us,p as At,v as ms,q as ps,x as Ot,s as xs,y as fs,z as hs,A as bs,i as gs}from"./subMonths-CpZP7vPB.js";import{C as Lt}from"./chevron-right-Kzd-kxi5.js";import{C as Ss}from"./index-D4k8Kw6s.js";import{l as ys}from"./loadSyncfusionTheme-vI47UJ_T.js";import{f as js}from"./findIndex-5S0T5r6i.js";import{E as ws}from"./external-link-DBEjKCSi.js";import{C as Cs}from"./copy-ukyGeVBH.js";import{P as Ns}from"./pencil-iZ6mTsM-.js";import{T as Es}from"./trash-2-DDb6D_B2.js";import{c as Ds,e as Ms,g as Vt,d as vs,u as Ts}from"./index.esm-M6qXUo6E.js";import{S as _s}from"./index-rc50KUs-.js";import{u as ks,F as Fs}from"./FormColumnV2-Cd4kkuab.js";import{n as ce,e as He,u as As}from"./apollo-WxVwhmyD.js";import{f as Os}from"./filter-CCNg3K-_.js";import{i as Rt,s as Ls}from"./some-DWTvIxlZ.js";try{let r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new r.Error().stack;s&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[s]="ba7f11d0-a199-4900-adcf-10912f862c38",r._sentryDebugIdIdentifier="sentry-dbid-ba7f11d0-a199-4900-adcf-10912f862c38")}catch{}const $e=r=>r===""||r===null||r===void 0?null:Number(r),Be=r=>(r||[]).map(s=>Number(s));function Vs({open:r,onClose:s,teamId:n,date:c,onSaved:h,lockTeam:m=!1,hideScopeToggle:d=!1}){const[j,D]=o.useState("teamSession"),w=j==="teamSession",T=!w,[k]=xt(),p=k,A=ft(),L=mt(g=>g.club),{currentSeason:u,isAllSeasonSelected:b}=$t(),N=(A==null?void 0:A.club_id)||(L==null?void 0:L.club_id)||0,[Y]=ce(Ut),[C,ee]=o.useState(!1),Q=()=>{D("teamSession"),s()},y=async(g,{resetForm:P})=>{var ne,oe;if(w&&(!u||b)){p({msg:"Please select an active season to create sessions.",variant:"error",autoHideDuration:3e3});return}const ae={session_name:g.session,session_type:$e(g.sessionType),duration:$e(g.duration)??0,area_size:g.areaSize,session_note:g.notes,id:0,club_id:Number(N),session_documents:[],deleted_documents:[],usedDefaultStructure:!0},W=w?{team_ids:Be(g.team),session_date_time:La(g.dateTime),surface:$e(g.surface),...((ne=g.team)==null?void 0:ne.length)===1?{players:Be(g.players),coaches:Be(g.coaches),age_group:$e(g.ageGroup)}:{}}:{},se=T?{suitable_age_groups:Be(g.suitableAgeGroups)}:{},ue={...ae,...W,...se};ee(!0);try{const z=await Y({variables:{createSessionInput:T?ue:{...ue,season_id:u==null?void 0:u.id}}}),{success:R,message:J}=((oe=z==null?void 0:z.data)==null?void 0:oe.createSession)||{};if(!R){p({msg:J||"Save failed. Please check the form and try again.",variant:"error"});return}p({msg:J||"Session created. Share it with your team.",variant:"success"}),h(),P(),Q()}catch(z){p({msg:z instanceof Error?z.message:"Unexpected error while saving. Please try again.",variant:"error"})}finally{ee(!1)}},v=ks({isTeamSession:w,isUpdated:!1,teamId:n!=null?Number(n):null,date:c,open:r,onSubmit:y});return e.jsx(Qe,{open:r,onOpenChange:g=>g?null:Q(),children:e.jsxs(Xe,{className:O("max-w-[560px] w-[calc(100vw-2rem)] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden p-0 gap-0 bg-bg-raised text-fg font-body","border border-tt-border border-l-2 border-l-accent-2 roun
1ded-2xl"),children:[e.jsxs("div",{className:"shrink-0 px-5 pt-5 pb-4",children:[e.jsxs("div",{className:"font-mono text-[9.5px] uppercase tracking-wide14 text-accent-2 inline-flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-accent-2"}),"CALENDAR · CREATE"]}),e.jsxs("h2",{className:"mt-2 font-head text-[22px] font-bold uppercase tracking-wide2 leading-[1.1] text-fg",children:["Add New ",w?"Team":"Club"," Session"]}),!d&&e.jsx("div",{role:"group","aria-label":"Session scope",className:"mt-3 inline-flex rounded-md border border-tt-border bg-card p-0.5",children:[["teamSession","Team Session"],["clubSession","Club Session"]].map(([g,P])=>e.jsx("button",{type:"button",onClick:()=>D(g),"aria-pressed":j===g,className:O("cursor-pointer rounded-sm px-3 py-1.5 font-head text-xs uppercase tracking-wide12 outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-accent-2",j===g?"bg-accent-2 text-bg":"text-muted hover:text-fg"),children:P},g))})]}),e.jsx("div",{className:"min-h-0 flex-1 px-5 pb-4 overflow-y-auto",children:e.jsx(Fs,{form:v,isTeamSession:w,lockTeam:m})}),e.jsxs("div",{className:"shrink-0 flex items-center justify-end gap-3 border-t border-hairline px-5 py-4 pb-[max(16px,env(safe-area-inset-bottom))] bg-card [&_button]:min-h-11 [&_button]:rounded-lg [&_button]:text-sm",children:[e.jsx("button",{type:"button",onClick:Q,disabled:C,className:O("h-8 px-3 inline-flex items-center rounded-sm border border-hairline bg-bg","font-head text-[11px] font-bold uppercase tracking-wide10 text-fg hover:bg-card-hi",C&&"opacity-50 cursor-not-allowed"),children:"Discard"}),e.jsx(qe,{type:"button",onClick:()=>v.formik.handleSubmit(),disabled:C,className:"h-8 px-4 rounded-sm bg-accent text-bg font-head text-[11px] font-bold uppercase tracking-wide10 hover:brightness-110 hover:bg-accent",children:C?"Savingâ¦":"Save Session"})]})]})})}function Rs({showTitle:r,filterActive:s,isMobileView:n,fixtureColor:c,sessionColor:h,customEventColor:m,canAddFixture:d,canAddSession:j,showIconBtn:D,handleOpenManageLegend:w,handleOpenFilterModal:T,handleOpenManageFixture:k,handleOpenManageSession:p,handleOpenCustomEvent:A,addSheetOpen:L,setAddSheetOpen:u,onOpenAddSheet:b}){const N=[...d?[{label:"Add Fixture",onClick:k}]:[],...j?[{label:"Add Session",onClick:p}]:[],...j?[{label:"Add Custom Event",onClick:()=>A()}]:[],...j?[{label:"Manage Legend",onClick:w}]:[]],Y=[{label:"Fixture",color:c},{label:"Session",color:h},{label:"Custom Event",color:m}];return e.jsxs("div",{className:"flex flex-col gap-4 border-b border-hairline bg-bg px-7 py-4 md:flex-row md:items-end md:justify-between",children:[r&&e.jsx("div",{className:"flex flex-col",children:e.jsx("h1",{className:"font-head text-[22px] sm:text-[36px] font-bold uppercase tracking-wide2 leading-[1] text-fg",children:"Calendar"})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 md:gap-5",children:[e.jsx("div",{className:"flex items-center gap-3 md:gap-4",children:Y.map(C=>e.jsxs("button",{type:"button",onClick:w,className:"flex items-center gap-1.5","aria-label":`Edit ${C.label} colour`,children:[e.jsx("span",{className:"inline-block h-3 w-3 rounded-full",style:{background:`${C.color}3d`,border:`1px solid ${C.color}`}}),e.jsx("span",{className:"font-mono text-[11px] uppercase tracking-wide6 text-muted",children:C.label})]},C.label))}),e.jsxs("div",{className:"flex items-center gap-2 md:gap-3",children:[e.jsxs("button",{type:"button",onClick:T,className:O("box-border inline-flex h-9 items-center gap-2 rounded-md border bg-bg px-3 font-head text-[13px] font-bold uppercase tracking-wide6 text-fg hover:bg-card md:px-4",s?"border-accent-2":"border-tt-border"),children:[e.jsx(Za,{className:"h-4 w-4"}),!n&&"Filter"]}),D&&(n?e.jsx(ge,{label:"Add event",children:e.jsx("button",{type:"button","aria-label":"Add",onClick:b,className:"box-border inline-flex h-9 w-9 items-center justify-center rounded-md bg-accent text-bg",children:e.jsx(pt,{className:"h-4 w-4"})})}):e.jsxs(Wt,{children:[e.jsx(zt,{asChild:!0,children:e.jsxs("button",{type:"button",className:"box-border inline-flex h-9 items-center gap-2 rounded-md bg-accent px-4 font-head text-[13px] font-bold uppercase tracking-wide6 text-bg hover:brightness-110",children:[e.jsx(pt,{className:"h-4 w-4"}),"Add",e.jsx(Xt,{className:"h-4 w-4"})]})}),e.jsx(Ht,{align:"end",className:"min-w-[200px]",children:N.map(C=>e.jsx(Ga,{onSelect:()=>C.onClick(),className:"font-head text-[13px] font-bold uppercase tracking-wide6",children:C.label},C.label))})]}))]})]}),D?e.jsx(Qt,{open:L,onClose:()=>u(!1),eyebrow:"CALENDAR",title:"Add to calendar",children:e.jsx("div",{className:"flex flex-col gap-2 px-4 pb-4",children:N.map(C=>e.jsx("button",{type:"button",onClick:()=>{u(!1),C.onClick()},className:"box-border w-full rounded-md border border-tt-border bg-bg px-4 py-3 text-left font-head text-sm font-bold uppercase tracking-wide6 text-fg hover:bg-card-hi",children:C.label},C.label))})}):null]})}const Is=["M","T","W","T","F","S","S"];function Us(r){const s=xs(fs(r),{weekStartsOn:1}
1),n=hs(bs(r),{weekStartsOn:1}),c=[];let h=s;for(;h<=n;)c.push(h),h=gs(h,1);const m=[];for(let d=0;d<c.length;d+=7)m.push(c.slice(d,d+7));return m}const Ys=["Day","Week","Month"];function It({currentView:r,currentDate:s,selectedDate:n,handleChangeView:c,handleNavigate:h,handleToday:m,setSelectedDate:d}){const[j,D]=o.useState(!1),[w,T]=o.useState(n);o.useEffect(()=>{j&&T(n)},[j,n]);const k=Us(w);return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 rounded-t-[14px] border border-tt-border bg-bg-raised px-4 py-4 md:px-6",children:[e.jsxs("div",{className:"flex w-full min-w-0 items-center justify-between gap-1 md:w-auto md:gap-3",children:[e.jsx(ge,{label:"Previous period",children:e.jsx("button",{type:"button","aria-label":"Previous",onClick:()=>h("back"),className:"box-border flex h-9 w-9 items-center justify-center rounded-md border border-tt-border bg-bg text-muted hover:text-fg hover:bg-card",children:e.jsx(Ft,{className:"h-4 w-4"})})}),e.jsxs(ls,{open:j,onOpenChange:D,children:[e.jsx(ds,{asChild:!0,children:e.jsxs("button",{type:"button",className:"box-border flex min-w-0 items-center justify-center gap-1 rounded-md px-1 py-2 font-head text-sm md:px-3 md:text-lg font-bold uppercase tracking-wide2 text-fg hover:bg-card",children:[s,e.jsx(Xt,{className:"h-4 w-4 text-subtle"})]})}),e.jsxs(cs,{className:"w-[260px] border border-tt-border bg-card p-3 text-fg",align:"center",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx(ge,{label:"Previous month",children:e.jsx("button",{type:"button","aria-label":"Previous month",onClick:()=>T(p=>us(p)),className:"flex h-7 w-7 items-center justify-center rounded text-muted hover:text-fg hover:bg-card-hi",children:e.jsx(Ft,{className:"h-4 w-4"})})}),e.jsx("span",{className:"font-mono text-xs uppercase tracking-wide8 text-subtle",children:At(w,"MMMM yyyy")}),e.jsx(ge,{label:"Next month",children:e.jsx("button",{type:"button","aria-label":"Next month",onClick:()=>T(p=>ms(p,1)),className:"flex h-7 w-7 items-center justify-center rounded text-muted hover:text-fg hover:bg-card-hi",children:e.jsx(Lt,{className:"h-4 w-4"})})})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-0.5",children:[Is.map((p,A)=>e.jsx("div",{className:"flex h-7 items-center justify-center font-mono text-[10px] uppercase text-faint",children:p},`${p}-${A}`)),k.flat().map(p=>{const A=ps(p,w),L=Ot(p,n),u=Ot(p,new Date);return e.jsx("button",{type:"button",onClick:()=>{d(p),D(!1)},className:O("box-border flex h-8 w-8 items-center justify-center rounded font-mono text-xs tabular-nums",A?"text-fg":"text-faint",!L&&"hover:bg-card-hi",L&&"bg-accent text-bg font-semibold",!L&&u&&"text-accent-2"),children:At(p,"d")},p.toISOString())})]})]})]}),e.jsx(ge,{label:"Next period",children:e.jsx("button",{type:"button","aria-label":"Next",onClick:()=>h("next"),className:"box-border flex h-9 w-9 items-center justify-center rounded-md border border-tt-border bg-bg text-muted hover:text-fg hover:bg-card",children:e.jsx(Lt,{className:"h-4 w-4"})})})]}),e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 md:w-auto md:gap-4",children:[e.jsx("button",{type:"button",onClick:m,className:"box-border h-9 rounded-md border border-tt-border bg-bg px-3 font-head text-[13px] font-bold uppercase tracking-wide6 text-fg hover:bg-card md:px-4",children:"Today"}),e.jsx("div",{className:"flex items-center overflow-hidden rounded-md border border-tt-border",children:Ys.map(p=>{const A=p===r;return e.jsx("button",{type:"button",onClick:()=>c(p),className:O("box-border h-9 px-3 font-head text-[13px] font-bold uppercase tracking-wide6 md:px-4",A?"bg-accent-2 text-bg":"bg-bg text-muted hover:text-fg hover:bg-card"),children:p},p)})})]})]})}const $s={Fixture:"Fixture",Session:"Session",customEvent:"Custom Event"};function Bs({open:r,loading:s,event:n,date:c,fixtureColor:h,sessionColor:m,customEventColor:d,handleClose:j,handleMove:D}){const w=(n==null?void 0:n.type)==="Fixture"?h:(n==null?void 0:n.type)==="Session"?m:d,T=(n==null?void 0:n.opposition)||(n==null?void 0:n.session_name)||(n==null?void 0:n.name)||(n==null?void 0:n.Subject)||"Event",k=c?_e(c):null,p=e.jsxs("div",{className:"flex flex-col gap-4",children:[n&&e.jsx("div",{className:"flex items-center gap-3 rounded-lg border border-tt-border bg-bg-raised px-4 py-3",style:{borderLeft:`3px solid ${w}`},children:e.jsxs("div",{children:[e.jsx("div",{className:"font-head text-base leading-tight text-fg",children:T}),e.jsx("div",{className:"font-mono text-[11px] uppercase tracking-wide6 text-subtle",children:$s[n.type]??"Event"})]})}),e.jsxs("p",{className:"font-body text-sm leading-6 text-muted",children:["Are you sure you want to move this event to"," ",e.jsx("span",{className:"font-semibold text-fg",children:k?k.format("ddd D MMM YY"):""})," at"," ",e.jsx("span",{className:"font-semibold text-fg",children:k?k.format("h:mm A"):""}),"?"]}),e.jsx("div",{className:"rounded-lg border border-tt-border bg-card-hi px-4 py-3",children:e.jsx("p",{className:"font-body text-[13px] leading-5 text-subtle",children:"Cancel reverts the event to its original slot â nothing is saved until you confirm."})})]});return e.jsx(Ss,{open:r,loading:s,eyebrow:"CALENDAR",title:"Move Event?",description:p,actionBtnTitle:"Move Event",cancelBtnTitle:"Cancel",handleClose:j,handleConfirm:D})}const Ps="#f59e0b",Ws="#22d3ee",zs="#ff80d0",Pe="calendar-v2-scope";rs("Mgo+DSMBaFt+QHJqVk1hXk5Hd0BLVGpAblJ3T2ZQdVt5ZDU7a15RRnVfRF1hSX9WdkdjWX5ddA==;Mgo+DSMBPh8sVXJ1S0R+X1pFdEBBXHxAd1p/VWJYdVt5flBPcDwsT3RfQF5jT35RdkRmWX1ecHdVQg==;ORg4AjUWIQA/Gnt2VFhiQlJPd11dXmJWd1p/THNYflR1fV9DaUwxOX1dQl9gSXhTdEViXH9ccHRRQ2Q=;MjI4OTYwN0AzMjMxMmUzMDJlMzBkMWxzcm9ISG5pdEVISUVrNXRRTWEwaWlqVWc0RVd3OFBlMWFFM0pZSzhNPQ==;
1MjI4OTYwOEAzMjMxMmUzMDJlMzBpOFMvdkQrbk0yS2s4cHg5YWJ0aTlXZExQNUFaUGRoYWFPdkpaUmxvdE1rPQ==;NRAiBiAaIQQuGjN/V0d+Xk9HfV5AQmBIYVp/TGpJfl96cVxMZVVBJAtUQF1hSn5VdkdjWHpecnRURGdY;MjI4OTYxMEAzMjMxMmUzMDJlMzBlM1RkUlNKVVVHUWVtdndEVkMwalhaeTNjVkppN3A4NVNRODI0MUlFZXhZPQ==;MjI4OTYxMUAzMjMxMmUzMDJlMzBaQnVVWHpScEd5ZU1iSWxCdXdRNmhuOWdzU01oOXZoZDNCVmNzR1Q1SjJNPQ==;Mgo+DSMBMAY9C3t2VFhiQlJPd11dXmJWd1p/THNYflR1fV9DaUwxOX1dQl9gSXhTdEViXH9ccHZUQmQ=;MjI4OTYxM0AzMjMxMmUzMDJlMzBqeVZZMW5ZRE1FNU1ZazNqeldHWnArUkJXQkd5K0xrV1BDTFExclk5cU9ZPQ==;MjI4OTYxNEAzMjMxMmUzMDJlMzBvcW1VSEhhQ3JSUXFaT1Z1YTNNbm1hQTVBcDFKOCsvRm9SdGpobmhueEtBPQ==;MjI4OTYxNUAzMjMxMmUzMDJlMzBlM1RkUlNKVVVHUWVtdndEVkMwalhaeTNjVkppN3A4NVNRODI0MUlFZXhZPQ==");ys();const Hs={Fixture:"Fixture",Session:"Session",customEvent:"Custom Event"};function Qs(r){const{canEditCalendar:s,events:n,teamList:c,fixtureColor:h,sessionColor:m,customEventColor:d,fixturePermissions:j,sessionPermissions:D,isMobileView:w=!1,loadingEvents:T,refreshing:k=!1,setEvents:p,setSelectedEvent:A,handleUpdateDraggedEvent:L,handleOpenFixtureModal:u,handleEditFixture:b,handleEditSession:N,handleCreateSession:Y,handleOpenDuplicateSessionModal:C,handleOpenDuplicateFixtureModal:ee,handleOpenCustomEventModal:Q,handleOpenDeleteModal:y,selectedDate:v,setSelectedDate:g}=r,[P,ae]=o.useState(null),[W,se]=o.useState("Month"),[ue,ne]=o.useState(!1),[oe,z]=o.useState(null),[R,J]=o.useState(null),[Z,Se]=o.useState(null),B=ft(),ye=Va(),je=Bt(),te=(D==null?void 0:D.add)===K.YES,ie=(j==null?void 0:j.add)===K.YES,ke=()=>ne(!0),pe=()=>{R&&J(t=>t&&{...t,cancel:!0}),ne(!1)},xe=t=>t==="Fixture"?h:t==="Session"?m:d,we=t=>{var x,V,$;const S=t.team_id??((x=t.team)==null?void 0:x.id);return((V=t.team)==null?void 0:V.name)||(($=c.find(U=>String(U.id)===String(S)))==null?void 0:$.name)||(S?"Team unavailable":"Club event")},re=()=>P==null?void 0:P.closeQuickInfoPopup(),Fe=t=>{!w&&!(P!=null&&P.isAdaptive)||(t.cancel=!0,(te||ie)&&s&&z(t.startTime??null))},Ae=t=>{var S,x;if((x=(S=t==null?void 0:t.element)==null?void 0:S.classList)==null||x.add(Pe),t.type==="Editor"||t.type==="QuickInfo"){const V=t.data??{};!(V.Id!=null||V.id!=null)&&t.type==="Editor"&&(t.cancel=!0)}},Oe=t=>{re(),t.type==="Fixture"?b(t):t.type==="Session"?N(t):Q()},Ce=t=>{re(),t==="Fixture"?ee():t==="Session"?C():Q(void 0,!0)},Le=()=>{re(),y()},Ve=t=>se(t),Re=t=>{const S=t==="next"?1:-1;W==="Month"?g(new Date(v.getFullYear(),v.getMonth()+S,1)):W==="Week"?g(new Date(v.getFullYear(),v.getMonth(),v.getDate()+S*7)):W==="Day"&&g(new Date(v.getFullYear(),v.getMonth(),v.getDate()+S))},Ie=()=>g(new Date),le=t=>t.cancel=!0,Ge=t=>{t.action==="view"&&t.currentView==="Day"&&W!=="Day"&&t.currentDate&&(se("Day"),g(t.currentDate))},fe=()=>{if(W==="Week"){const t=new Date(v),S=t.getDay(),x=new Date(t);x.setDate(t.getDate()-S);const V=new Date(x);V.setDate(x.getDate()+6);const $=x.getFullYear(),U=V.getFullYear();if($===U){const at=x.toLocaleDateString("en-US",{month:"long"}),st=x.toLocaleDateString("en-US",{day:"numeric"}),nt=V.toLocaleDateString("en-US",{day:"numeric"});return`${at} ${st} - ${nt}, ${U}`}const G=x.toLocaleDateString("en-US",{month:"long",day:"numeric"}),me=V.toLocaleDateString("en-US",{month:"long",day:"numeric"});return`${G} - ${me}, ${U}`}return v.toLocaleString("default",{...W==="Day"?{day:"2-digit"}:{},month:"long",year:"numeric"})},Je=t=>{const S=xe(t.type),V=(t.StartTime instanceof Date?t.StartTime:new Date(Number(t.StartTime))).toLocaleString("en-US",{hour:"2-digit",minute:"2-digit"}),$=t.Subject??"",U=we(t);return e.jsxs("div",{title:`${U} · ${$} · ${V}`,className:"calendar-event-card box-border flex h-full w-full items-center gap-2 overflow-hidden rounded-[3px] px-1.5",style:{borderLeft:`3px solid ${S}`,background:`${S}1f`},children:[e.jsx("span",{className:"calendar-event-time font-mono text-[11px] tabular-nums text-muted",children:V}),e.jsxs("span",{className:"truncate font-body text-[12px] text-fg",children:[U," · ",$]})]})},i=t=>{if(!((te||ie)&&s))return e.jsx("div",{});const S=xe(t==null?void 0:t.type);return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full",style:{background:t!=null&&t.id?S:"var(--accent-2)"}}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[e.jsx("span",{className:"font-mono text-[11px] uppercase tracking-wide8",style:{color:t!=null&&t.id?S:void 0},children:t!=null&&t.id?Hs[t.type]??"Event":"Add Event"}),e.jsx(ge,{label:"Close",children:e.jsx("button",{type:"button","aria-label":"Close",onClick:re,className:"flex h-7 w-7 items-center justify-center rounded text-muted hover:text-fg hover:bg-card-hi",children:e.jsx(Ra,{className:"h-4 w-4"})})})]})]})},H=(t,S)=>e.jsxs(e.Fragment,{children:[ie&&e.jsx(We,{color:h,label:"Add Fixture",onClick:()=>{S(),u(t)}}),te&&e.jsx(We,{color:m,label:"Add Session",onClick:()=>{S(),Y(t)}}),te&&e.jsx(We,{color:d,label:"Add Custom Event",onClick:()=>{S(),Q(t)}}),te&&e.jsx(We,{color:"var(--accent-2)",label:"Gaffer Session",onClick:()=>{S(),t&&Ba(t.getTime()),je(`/the-gaffer?src=calendar${t?`&date=${t.getTime()}`:""}`)}})]}),he=t=>{let S=s,x=s;(t==null?void 0:t.type)==="Fixture"?((j==null?void 0:j.manage)!==K.YES&&(S=!1),(j==null?void 0:j.delete)!==K.YES&&(x=!1)):((t==null?void 0:t.type)==="Session"||(t==null?void 0:t.type)==="customEvent")&&((D==null?void 0:D.manage)!==K.YES&&(S=!1),(D==null?void 0:D.delete)!==K.YES&&(x=!1));const V=(t==null?void 0:t.StartTime)instanceof Date?t.StartTime:t!=null&&t.StartTime?new Date(Number(t.StartTime)):null,$=V?V.toLocaleTimeString("en-US",{hour:"numeric",minute:"numeric",hour12:!0}):"",U=xe(t==null?void 0:t.type);if(t!=null&&t.id){const me=t.type==="Fixture"||t.type==="Session";return e.jsxs("div",{className:"flex flex-col gap-3 px-4 pb-4 box-border",style:{width:"min(320px, calc(100vw - 32px))"},children:[e.jsxs("button",{type:"button",disabled:!me,onClick:()=>{t.type==="Fixture"?window.open(`/dugout/fixture/${t.id}?teamId=${t.team_id}`,"_blank"):t.type==="Session"&&window.open(`/dugout/session/${t.id}`,"_blank")},className:O("box-border flex w-full min-w-0 items-start justify-between gap-2 rounded-lg px-3 py-2 text-left",me&&"cursor-pointer hover:brightness-110"),style:{background:`${U}1f`,borderLeft:`3px solid ${U}`},children:[e.jsxs("span",{className:"min-w-0 break-words",children:[e.jsx("span",{className:"mb-1 block font-body text-[12px] font-semibold text-accent-2",children:we(t)}),e.jsx("span",{className:"block font-head text-[15px] leading-tight text-fg",children:t.Subject}),e.jsx("span",{className:"font-mono text-[11px] text-muted",children:$})]}),me&&e.jsx(ws,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-subtle"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[S&&e.jsx(dt,{icon:e.jsx(Cs,{className:"h-3.5 w-3.5"}),label:"Duplicate",onClick:()=>Ce(t.type)}),S&&e.jsx(dt,{icon:e.jsx(Ns,{className:"h-3.5 w-3.5"}),label:"Edit",onClick:()=>Oe(t)}),x&&e.jsx(dt,{icon:e.jsx(Es,{className:"h-3.5 w-3.5"}),label:"Delete",danger:!0,onClick:()=>Le()})]})]})}if(!((te||ie)&&s))return e.jsx("div",{});const G=t.startTime??t.StartTime;return e.jsx("div",{className:"box-border flex flex-col gap-2 overflow-hidden px-3 pb-3",style:{width:"min(320px, calc(100vw - 32px))"},children:H(G,re)})},I=()=>e.jsx("div",{}),X=()=>({dataSource:[...n],template:Je,allowDrag:s,allowResize:s}),Ze=t=>A(t.event??null),Ke=t=>Se(t.data),et=t=>{J(t.data),ke()},q=()=>{pe(),R&&R.cancel!==!0&&(L(R),J(null),Se(null))};if(o.useEffect(()=>{se(w?"Day":"Month")},[w]),o.useEffect(()=>{if((R==null?void 0:R.cancel)===!0&&n.length&&Z){const t=[...n],S=js(t,x=>x.id===Z.id&&x.type===Z.type);S>=0&&t.splice(S,1,Z),p([...t]),J(null),Se(null)}},[R==null?void 0:R.cancel,n,Z,p]),o.useEffect(()=>
1{var t,S,x;ye==null||ye.capture(kt.DUGOUT_CALENDAR_ACCESSED,{customData:{userId:B==null?void 0:B.id,email:B==null?void 0:B.email,clubId:B==null?void 0:B.club_id,roles:(S=(t=B==null?void 0:B.userRolesPermissions)==null?void 0:t.roles)==null?void 0:S.map(V=>V.name)}}),typeof window<"u"&&typeof window.fbq=="function"&&((x=window.fbq)==null||x.call(window,"track",kt.DUGOUT_CALENDAR_ACCESSED))},[]),T)return e.jsxs("div",{className:O(Pe,"flex h-full w-full flex-col overflow-hidden rounded-[14px]"),children:[e.jsx(It,{currentView:W,currentDate:fe(),selectedDate:v,isMobileView:w,handleChangeView:Ve,handleNavigate:Re,handleToday:Ie,setSelectedDate:g}),e.jsx("div",{className:"grid min-h-0 flex-1 grid-cols-7 gap-px bg-hairline p-px","aria-busy":"true","aria-label":"Loading calendar",children:Array.from({length:35}).map((t,S)=>e.jsxs("div",{className:"min-h-[56px] bg-bg p-1.5",children:[e.jsx("div",{className:"h-2.5 w-5 rounded-[2px] bg-skeleton-base"}),S%4===0?e.jsx("div",{className:"mt-2 h-3 w-full rounded-[2px] bg-gradient-to-r from-skeleton-base via-skeleton-shimmer to-skeleton-base bg-[length:200%_100%] animate-shimmer"}):null]},S))})]});const Ne=X(),tt={header:t=>i(t),content:t=>he(t),footer:I};return e.jsxs("div",{className:O(Pe,"relative flex h-full w-full flex-col overflow-hidden rounded-[14px]"),children:[k?e.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-start justify-center bg-bg/40 pt-24","aria-busy":"true",children:e.jsx("span",{className:"h-7 w-7 animate-spin rounded-full border-2 border-solid border-hairline border-t-accent-2"})}):null,e.jsx(It,{currentView:W,currentDate:fe(),selectedDate:v,isMobileView:w,handleChangeView:Ve,handleNavigate:Re,handleToday:Ie,setSelectedDate:g}),e.jsx(Ka,{id:"calendar-v2-scheduler",cssClass:Pe,width:"100%",height:"calc(100% - 73px)",ref:t=>ae(t),showHeaderBar:!1,currentView:W,selectedDate:v,eventSettings:Ne,timeScale:{enable:!0,interval:60,slotCount:1},cellClick:Fe,cellDoubleClick:le,navigating:Ge,popupOpen:Ae,eventClick:Ze,dragStart:Ke,dragStop:et,quickInfoTemplates:tt,children:e.jsx(es,{services:[ts,as,ss,ns,os,is]})}),e.jsx(Bs,{open:ue,event:R,date:R==null?void 0:R.StartTime,fixtureColor:h,sessionColor:m,customEventColor:d,handleClose:pe,handleMove:q}),e.jsx(Qt,{open:oe!==null,onClose:()=>z(null),title:"Add Event",eyebrow:"Dugout · Calendar",children:e.jsx("div",{className:"box-border flex flex-col gap-2 px-[18px] py-3",children:H(oe??void 0,()=>z(null))})})]})}function dt({icon:r,label:s,onClick:n,danger:c}){return e.jsxs("button",{type:"button",onClick:n,className:O("box-border inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 font-head text-[11px] font-bold uppercase tracking-wide6",c?"border-tt-border text-[#d44f5e] hover:bg-card-hi":"border-tt-border text-fg hover:bg-card-hi"),children:[r,s]})}function We({color:r,label:s,onClick:n}){return e.jsxs("button",{type:"button",onClick:n,className:"group box-border flex w-full min-w-0 items-center gap-1.5 rounded-md border border-solid border-border bg-card-hi px-2 py-2 text-left font-head text-[11px] font-bold uppercase tracking-wide2 text-fg transition-colors hover:border-accent-2 hover:text-accent-2",children:[e.jsx(pt,{className:"h-3.5 w-3.5 text-subtle transition-colors group-hover:text-accent-2"}),e.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{background:r}}),s]})}function Xs(r){const s=r instanceof Date?r:new Date(r);if(isNaN(s.getTime()))return"";const n=c=>String(c).padStart(2,"0");return`${s.getFullYear()}-${n(s.getMonth()+1)}-${n(s.getDate())}T${n(s.getHours())}:${n(s.getMinutes())}`}function qs(){const r=new Date;return r.setDate(r.getDate()+1),r.setHours(0,0,0,0),r}function Gs(r){const{open:s,loading:n,isDuplicate:c,teamId:h,selectedCustomEvent:m,teamOptions:d,date:j,handleClose:D,handleSubmit:w}=r,[T]=xt(),k=T,p=c||be(m),A=o.useMemo(()=>Ds({title:vs().required("Event name is required"),dateTime:Vt().required("Date and Time is required"),team:p?Ms().min(1,"At least one team is required").required("Team Name is required"):Vt().required("Team is required")}),[p]);function L(){return!be(m)&&(m!=null&&m.StartTime)?new Date(m.StartTime):j?
1new Date(j):qs()}const u=Ts({enableReinitialize:!0,initialValues:{title:"",dateTime:L(),description:"",team:p?h?[+h]:[]:h?+h:""},validationSchema:A,onSubmit:(y,{resetForm:v})=>{const g=typeof y.dateTime=="string"?new Date(y.dateTime):y.dateTime;if(isNaN(g.getTime())){k({msg:"Please enter a valid date and time.",variant:"error"});return}w({title:y.title,dateTime:g,description:y.description,team:y.team},v)}});o.useEffect(()=>{s&&d.length===1&&!c&&!h&&be(m)&&u.setFieldValue("team",[d[0].id])},[s,d,c,h,m]),o.useEffect(()=>{var y,v;s&&!be(m)&&m&&u.setValues({title:m.name??"",dateTime:new Date(m.StartTime),description:m.description??"",team:c?[((y=m.team)==null?void 0:y.id)??0]:((v=m.team)==null?void 0:v.id)??""})},[s,m,c]);function b(){u.resetForm(),D()}const N=Array.isArray(u.values.team)?u.values.team:[],Y=N.length?d.filter(y=>N.includes(y.id)).map(y=>y.name).join(", "):"Select team(s)â¦",C=c?"Duplicate Custom Event":"Custom Event",ee=c?"Duplicate Custom Event":"Save Custom Event",Q=c?"CALENDAR · CREATE":"CALENDAR";return e.jsx(Qe,{open:s,onOpenChange:y=>y?null:b(),children:e.jsxs(Xe,{onInteractOutside:y=>y.preventDefault(),className:O("max-w-[560px] p-0 gap-0 bg-bg-raised text-fg font-body","border border-tt-border border-l-2 border-l-accent-2 rounded-[3px]"),children:[e.jsxs("div",{className:"px-6 pt-5 pb-3",children:[e.jsxs("div",{className:"font-mono text-[9.5px] uppercase tracking-wide14 text-accent-2 inline-flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-accent-2"}),Q]}),e.jsx("h2",{className:"mt-2 font-head text-[22px] font-bold uppercase tracking-wide2 leading-[1.1] text-fg",children:C})]}),e.jsxs("div",{className:"px-6 pb-4 flex flex-col gap-4",children:[e.jsx(ze,{label:"EVENT TITLE",required:!0,error:u.touched.title?u.errors.title:void 0,children:e.jsx("input",{type:"text",name:"title",value:u.values.title,onChange:u.handleChange,onBlur:u.handleBlur,placeholder:"Enter event title",className:"h-9 px-2.5 rounded-sm bg-bg border border-hairline font-body text-[12px] text-fg box-border w-full"})}),e.jsx(ze,{label:"DATE & TIME",required:!0,error:u.touched.dateTime?u.errors.dateTime:void 0,children:e.jsx("input",{type:"datetime-local",name:"dateTime",value:u.values.dateTime?Xs(u.values.dateTime):"",onChange:y=>{const v=y.target.value;u.setFieldValue("dateTime",v?new Date(v):null)},onBlur:()=>u.setFieldTouched("dateTime",!0),className:"h-9 px-2.5 rounded-sm bg-bg border border-hairline font-body text-[12px] text-fg box-border w-full"})}),e.jsx(ze,{label:"DESCRIPTION",children:e.jsx("textarea",{name:"description",rows:4,value:u.values.description,onChange:u.handleChange,onBlur:u.handleBlur,placeholder:"Enter description",className:"px-2.5 py-2 rounded-sm bg-bg border border-hairline font-body text-[12px] text-fg box-border w-full resize-none"})}),e.jsx(ze,{label:"TEAM",required:!0,error:u.touched.team?Array.isArray(u.errors.team)?u.errors.team.join(", "):u.errors.team:void 0,children:p?e.jsxs(Wt,{children:[e.jsxs(zt,{disabled:!!h,className:O("h-9 px-2.5 rounded-sm bg-bg border border-hairline font-body text-[12px] text-fg box-border w-full text-left","inline-flex items-center justify-between",h&&"opacity-50 cursor-not-allowed"),children:[e.jsx("span",{className:"truncate",children:Y}),e.jsx("span",{className:"ml-2 text-muted",children:"â¾"})]}),e.jsx(Ht,{className:"w-[--radix-dropdown-menu-trigger-width] min-w-[220px]",children:d.map(y=>e.jsx(Ja,{checked:N.includes(y.id),onCheckedChange:v=>{const g=N,P=v?[...g,y.id]:g.filter(ae=>ae!==y.id);u.setFieldValue("team",P)},children:y.name},y.id))})]}):e.jsx(_s,{ariaLabel:"Team",value:u.values.team,onChange:y=>u.setFieldValue("team",Number(y)),onOpen:()=>u.setFieldTouched("team",!0),disabled:!!h,className:O("h-9 rounded-sm bg-bg border border-hairline box-border w-full",h&&"opacity-50 cursor-not-allowed"),align:"start",options:[{value:"",label:"Select teamâ¦"},...d.map(y=>({value:String(y.id),label:y.name}))]})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-hairline px-6 py-3 bg-card",children:[e.jsx("button",{type:"button",onClick:b,disabled:n,className:O("h-8 px-3 inline-flex items-center rounded-sm border border-hairline bg-bg","font-head text-[11px] font-bold uppercase tracking-wide10 text-fg hover:bg-card-hi",n&&"opacity-50 cursor-not-allowed"),children:"Cancel"}),e.jsx(qe,{type:"button",onClick:()=>
1u.handleSubmit(),disabled:n,className:"h-8 px-4 rounded-sm bg-accent text-bg font-head text-[11px] font-bold uppercase tracking-wide10 hover:brightness-110 hover:bg-accent",children:ee})]})]})})}const ze=({label:r,required:s,error:n,children:c})=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"font-mono text-[9px] uppercase tracking-wide14 text-muted",children:[r,s&&e.jsx("span",{className:"ml-0.5 text-accent",children:"*"})]}),c,n&&e.jsx("span",{className:"font-body text-[11px] text-danger",children:n})]}),ct=["#f59e0b","#22d3ee","#ff80d0","#10b981","#d44f5e"];function Js(r){const{open:s,loading:n,fixture:c,session:h,customEvent:m,handleClose:d,handleSave:j}=r,[D,w]=o.useState(c),[T,k]=o.useState(h),[p,A]=o.useState(m);o.useEffect(()=>{w(c),k(h),A(m)},[c,h,m]);function L(){j(D,T,p),d()}return e.jsx(Qe,{open:s,onOpenChange:u=>u?null:d(),children:e.jsxs(Xe,{className:O("max-w-[560px] p-0 gap-0 bg-bg-raised text-fg font-body","border border-tt-border border-l-2 border-l-accent-2 rounded-[3px]"),children:[e.jsxs("div",{className:"px-6 pt-5 pb-3",children:[e.jsxs("div",{className:"font-mono text-[9.5px] uppercase tracking-wide14 text-accent-2 inline-flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-accent-2"}),"CALENDAR"]}),e.jsx("h2",{className:"mt-2 font-head text-[22px] font-bold uppercase tracking-wide2 leading-[1.1] text-fg",children:"Event Colours"})]}),e.jsxs("div",{className:"px-6 pb-4 flex flex-col gap-5",children:[e.jsx(ut,{label:"FIXTURE",color:D,onChange:w,presets:ct}),e.jsx(ut,{label:"SESSION",color:T,onChange:k,presets:ct}),e.jsx(ut,{label:"CUSTOM EVENT",color:p,onChange:A,presets:ct}),e.jsx("div",{className:"rounded-sm bg-card-hi px-4 py-3",children:e.jsx("p",{className:"font-body text-[13px] text-subtle leading-[1.5]",children:"Colours apply club-wide and persist to GET_CLUB_INFO â every coach sees the same legend."})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-hairline px-6 py-3 bg-card",children:[e.jsx("button",{type:"button",onClick:d,disabled:n,className:O("h-8 px-3 inline-flex items-center rounded-sm border border-hairline bg-bg","font-head text-[11px] font-bold uppercase tracking-wide10 text-fg hover:bg-card-hi",n&&"opacity-50 cursor-not-allowed"),children:"Cancel"}),e.jsx(qe,{type:"button",onClick:L,disabled:n,className:"h-8 px-4 rounded-sm bg-accent text-bg font-head text-[11px] font-bold uppercase tracking-wide10 hover:brightness-110 hover:bg-accent",children:"Save Changes"})]})]})})}const ut=({label:r,color:s,onChange:n,presets:c})=>{function h(d){const j=d.target.value;n(j)}function m(d){n(d.target.value)}return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wide14 text-muted",children:r}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("label",{className:"relative cursor-pointer",children:[e.jsx("span",{className:"block h-8 w-8 rounded-sm border border-hairline",style:{backgroundColor:s}}),e.jsx("input",{type:"color",value:s.startsWith("#")&&s.length===7?s:"#000000",onChange:m,className:"absolute inset-0 opacity-0 cursor-pointer w-full h-full"})]}),e.jsx("input",{type:"text",value:s,onChange:h,maxLength:7,placeholder:"#000000",className:"h-9 w-28 px-2.5 rounded-sm bg-bg border border-hairline font-mono text-[12px] text-fg box-border"}),e.jsx("div",{className:"flex items-center gap-1.5",children:c.map(d=>e.jsx("button",{type:"button",title:d,onClick:()=>n(d),className:O("h-6 w-6 rounded-sm border-2 transition-transform hover:scale-110",s.toLowerCase()===d.toLowerCase()?"border-fg scale-110":"border-transparent"),style:{backgroundColor:d}},d))})]})]})},Zs=[{id:"1",name:"Fixture",color:"#f59e0b"},{id:"2",name:"Session",color:"#22d3ee"},{id:"3",name:"customEvent",color:"#ff80d0"}];function Ks(r){return r==="customEvent"?"Custom Event":r}function en(r){const{open:s,clubId:n,filters:c,handleClose:h,handleFilters:m}=r,{data:d}=He(Yt,{variables:{coachListInput:{club_id:n??0}},fetchPolicy:"cache-and-network",skip:!s}),j=o.useMemo(()=>{const b=d==null?void 0:d.coachListNew;return b!=null&&b.success?(b.data??[]).map(N=>({id:N.id,name:`${N.username??""} ${N.lastname??""}`.trim(),avatar:Pt(N.profile_image)})):[]},[d]),[D,w]=o.useState(c.event),[T,k]=o.useState(c.coach);o.useEffect(()=>{s&&(w(c.event),k(c.coach))},[s,c.event,c.coach]);function p(b){w(N=>N.some(C=>C.id===b.id)?N.filter(C=>C.id!==b.id):[...N,{id:b.id,name:b.name}])}function A(b){k(N=>N.some(C=>C.id===b.id)?N.filter(C=>C.id!==b.id):[...N,b])}function L(){m({event:D,coach:T}),h()}function u(){w([]),k([])}return e.jsx(Qe,{open:s,onOpenChange:b=>b?null:h(),children:e.jsxs(Xe,{className:O("max-w-[560px] p-0 gap-0 bg-bg-raised text-fg font-body","border border-tt-border border-l-2 border-l-accent-2 roun
1ded-[3px]"),children:[e.jsxs("div",{className:"px-6 pt-5 pb-3",children:[e.jsxs("div",{className:"font-mono text-[9.5px] uppercase tracking-wide14 text-accent-2 inline-flex items-center gap-2",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-accent-2"}),"CALENDAR"]}),e.jsx("h2",{className:"mt-2 font-head text-[22px] font-bold uppercase tracking-wide2 leading-[1.1] text-fg",children:"Filter Events"})]}),e.jsxs("div",{className:"px-6 pb-4 flex flex-col gap-5",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wide14 text-muted",children:"Event Type"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Zs.map(b=>{const N=D.some(Y=>Y.id===b.id);return e.jsxs("button",{type:"button",onClick:()=>p({id:b.id,name:b.name}),className:O("inline-flex items-center gap-1.5 h-7 px-3 rounded-full border font-mono text-[10px] uppercase tracking-wide10 transition-colors",N?"border-accent-2 text-accent-2 bg-bg":"border-hairline text-muted bg-bg hover:border-accent-2/50"),style:N?{boxShadow:"0 0 0 1px #22d3ee"}:void 0,children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full flex-shrink-0",style:{backgroundColor:b.color}}),Ks(b.name)]},b.id)})})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"font-mono text-[9px] uppercase tracking-wide14 text-muted",children:"Coach"}),j.length===0?e.jsx("p",{className:"font-body text-[12px] text-subtle",children:"No coaches found."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(b=>{const N=T.some(Y=>Y.id===b.id);return e.jsx("button",{type:"button",onClick:()=>A(b),className:O("inline-flex items-center gap-1.5 h-7 px-3 rounded-full border font-mono text-[10px] uppercase tracking-wide10 transition-colors",N?"border-accent-2 text-accent-2 bg-bg":"border-hairline text-muted bg-bg hover:border-accent-2/50"),style:N?{boxShadow:"0 0 0 1px #22d3ee"}:void 0,children:b.name},b.id)})})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-hairline px-6 py-3 bg-card",children:[e.jsx("button",{type:"button",onClick:u,className:"font-body text-[12px] text-muted hover:text-fg underline underline-offset-2 transition-colors",children:"Clear"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:h,className:O("h-8 px-3 inline-flex items-center rounded-sm border border-hairline bg-bg","font-head text-[11px] font-bold uppercase tracking-wide10 text-fg hover:bg-card-hi"),children:"Cancel"}),e.jsx(qe,{type:"button",onClick:L,className:"h-8 px-4 rounded-sm bg-accent text-bg font-head text-[11px] font-bold uppercase tracking-wide10 hover:brightness-110 hover:bg-accent",children:"Apply Filters"})]})]})]})})}const tn=()=>{const[r,s]=o.useState(typeof window<"u"?window.matchMedia("(max-width: 899.95px)").matches:!1);return o.useEffect(()=>{const n=window.matchMedia("(max-width: 899.95px)"),c=()=>s(n.matches);return n.addEventListener("change",c),()=>n.removeEventListener("change",c)},[]),r};function an({showHeaderTitle:r=!0,teamId:s}){var Nt,Et,Dt,Mt,vt,Tt,_t;const n=tn(),c=As(),h=Bt(),[m,d]=o.useState(null),[j,D]=o.useState(!1),[w,T]=o.useState(!1),[k,p]=o.useState(!1),[A,L]=o.useState(!1),[u,b]=o.useState(!1),[N,Y]=o.useState(!1),[C,ee]=o.useState(!1),[Q,y]=o.useState(!1),[v,g]=o.useState(!1),[P,ae]=o.useState(!1),[W,se]=o.useState(!1),[ue,ne]=o.useState(!1),[oe,z]=o.useState(!1),[R,J]=o.useState(!1),[Z,Se]=o.useState([]),[B,ye]=o.useState(!0),[je,te]=o.useState(Ps),[ie,ke]=o.useState(Ws),[pe,xe]=o.useState(zs),[we,re]=o.useState([]),[Fe,Ae]=o.useState([]),[Oe,Ce]=o.useState([]),[Le,Ve]=o.useState([]),[Re,Ie]=o.useState([]),[le,Ge]=o.useState(()=>Pa()??new Date);o.useEffect(()=>{Wa()},[]);const[fe,Je]=o.useState({event:[],coach:[]}),[i,H]=o.useState(null),he=mt(a=>a.club),I=ft(),{currentSeason:X,isAllSeasonSelected:Ze,isReadOnlyMode:Ke,isUpcomingSeason:et}=$t(),q=mt(a=>{var l;return(l=a.teams)==null?void 0:l.team}),Ne=!Ke||!!et,[tt]=xt(),t=tt,S=Ia(),x=I!=null&&I.club_id?I.club_id:he!=null&&he.club_id?he.club_id:0,{clubInfoUpdateData:V}=$a(),$={month:"2-digit",day:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0},U=(Dt=(Et=(Nt=I==null?void 0:I.userRolesPermissions)==null?void 0:Nt.permissions)==null?void 0:Et.dugout)==null?void 0:Dt.fixtures,G=(Tt=(vt=(Mt=I==null?void 0:I.userRolesPermissions)==null?void 0:Mt.permissions)==null?void 0:vt.dugout)==null?void 0:Tt.sessions,me=(G==null?void 0:G.add)===K.YES,at=(U==null?void 0:U.add)===K.YES,st=(U==null?void 0:U.add)===K.YES||(G==null?void 0:G.add)===K.YES,[nt]=ce(Ea),[qt]=ce(Da),[Gt]=ce(Ut),[Jt]=ce(Ma),[Zt]=ce(va),[ht]=ce(Ta),[Kt]=ce(_a),{data:Ee}=He(ka,{variables:{club_id:x,...Ze?{}:{season_id:X==null?void 0:X.id}},fetchPolicy:"no-cache",skip:!(X!=null&&X.id)});o.useEffect(()=>{var a;if((a=Ee==null?void 0:Ee.getClubTeamsLite)!=null&&a.success){const l=Ee.getClubTeamsLite.data.map(_=>
1({name:_.name,id:_.id,avatar:Pt(_.logo)??_.name,logo:_.logo}));Se(l)}},[Ee]);const{data:Ue}=He(Yt,{variables:{coachListInput:{club_id:x??0}}}),ea=((_t=Ue==null?void 0:Ue.coachListNew)!=null&&_t.success?Ue.coachListNew.data:[]).map(a=>({id:a.id,name:`${a.username} ${a.lastname}`})),{data:de,refetch:ta}=He(Ya,{variables:{club_id:x??0},fetchPolicy:"no-cache"}),De=async()=>{se(!0);const a=await c.query({query:Fa,variables:{club_id:x,coach_id:I!=null&&I.isCoach?I.id:0,startDate:_e(le).startOf("month").format("YYYY-MM-DD HH:mm:ss"),endDate:_e(le).endOf("month").format("YYYY-MM-DD HH:mm:ss"),team_ids:s?[+s]:q},fetchPolicy:"no-cache"});try{const l=a==null?void 0:a.data;if(l!=null&&l.calendarFixtureListing){const{status:_}=l.calendarFixtureListing;if(_===200){const E=l.calendarFixtureListing.data,F=E==null?void 0:E.filter(M=>M!=null&&M.id!==null&&M.fixture_date_time!==null),f=F==null?void 0:F.map(M=>{var Ye;const Te=(Ye=M==null?void 0:M.coach_ids)==null?void 0:Ye.split(",");return M&&(M==null?void 0:M.id)&&{...M,fixtureSummaryFlag:M==null?void 0:M.fixtureSummaryFlag,coach_ids:(M==null?void 0:M.coach_ids)&&Te.map(Na=>parseInt(Na,10)),type:"Fixture",Subject:M==null?void 0:M.opposition,StartTime:new Date(Number(M.fixture_date_time)).toLocaleString("en-US",$),EndTime:new Date(Number(M.fixture_date_time)).toLocaleString("en-US",$)}});Ae(f)}else Ae([])}}finally{se(!1)}},Me=async()=>{ne(!0);const a=await c.query({query:Aa,variables:{sessionEventListingInput:{club_id:x,team_ids:s?[+s]:q,startDate:_e(le).startOf("month").format("YYYY-MM-DD HH:mm:ss"),endDate:_e(le).endOf("month").format("YYYY-MM-DD HH:mm:ss")}},fetchPolicy:"no-cache"});try{const l=a==null?void 0:a.data;if(q!=null&&q.length){if(l!=null&&l.sessionEventListing){const{status:_}=l.sessionEventListing;if(_===200){const E=l.sessionEventListing.data,F=E==null?void 0:E.map(f=>f&&(f==null?void 0:f.id)&&{...f,type:"Session",Subject:f==null?void 0:f.session_name,StartTime:new Date(Number(f.session_date_time)).toLocaleString("en-US",$),EndTime:new Date(Number(f.session_date_time)).toLocaleString("en-US",$)});Ce(F)}else Ce([])}}else Ce([])}finally{ne(!1)}},ve=async()=>{z(!0);const a=await c.query({query:Oa,variables:{customEventListingInput:{club_id:x,team_ids:s?[+s]:[]}},fetchPolicy:"no-cache"});try{const l=a==null?void 0:a.data;if(l!=null&&l.customEventListing){const{status:_}=l.customEventListing;if(_===200||_===201){const E=l.customEventListing.data,F=E==null?void 0:E.map(f=>f&&(f==null?void 0:f.id)&&{...f,type:"customEvent",Subject:f==null?void 0:f.name,StartTime:new Date(Number(f.date)).toLocaleString("en-US",$),EndTime:new Date(Number(f.date)).toLocaleString("en-US",$)});Ve(F)}}}finally{z(!1)}};o.useEffect(()=>{x&&(De(),Me())},[x,s,q,le]),o.useEffect(()=>{x&&ve()},[x,s]);const ot=()=>H(null),aa=a=>{d(null),H(null),D(!0)},it=qa("the calendar"),bt=a=>{it.guard(()=>{a&&d(a),b(!0)})},gt=()=>{b(!1),d(null),H(null)},sa=a=>{a&&d(a),Y(!0)},St=()=>{Y(!1),d(null),H(null)},na=a=>{(a==null?void 0:a.id)!=null&&(localStorage.setItem("openManageDrawerOnMange","true"),localStorage.setItem("sessionType",a.team_id?"teamSession":"club"),h(`/dugout/session/${a.id}`))},oa=a=>{(a==null?void 0:a.id)!=null&&h(`/dugout/fixture/${a.id}${a.team_id?`?teamId=${a.team_id}`:""}`)},yt=a=>{a&&d(a),ee(!0)},ia=()=>{ee(!1),d(null),H(null)},ra=a=>{a&&d(a),y(!0)},la=()=>{y(!1),d(null),H(null)},jt=(a,l=!1)=>{it.guard(()=>{a&&d(a),J(l),g(!0)})},rt=()=>{g(!1),d(null),H(null),J(!1)},da=()=>p(!0),ca=()=>p(!1),ua=()=>L(!0),wt=()=>L(!1),ma=()=>ae(!0),pa=()=>ae(!1),xa=async(a,l,_)=>{const E=[{type:"fixture_color",value:a,apply:()=>te(a)},{type:"session_color",value:l,apply:()=>ke(l)},{type:"customEvent_color",value:_,apply:()=>xe(_)}];(await Promise.all(E.map(f=>V({clubId:x,field:f.type,value:f.value,setAlert:()=>{},clubInfoRefetch:ta})))).forEach((f,M)=>{f!=null&&f.status&&E[M].apply()})},fa=async a=>{var l,_,E,F;if(Ne){if(a.type==="Fixture"){const f=await nt({variables:{club_id:x,id:a.id,fixture_date_time:a.StartTime.getTime(),team_ids:[a.team_id],Format_id:a.Format_id,Formation_id:a.Formation_id,fixture_created_by:a.fixture_created_by,isUpdated:!0,matchDuration:a.matchDuration,homeAway:a.venue,venue:a.venue,surface:a.surface,coach_ids:a.coach_ids??[],competition:a.competition,opposition:a.opposition}});(_=(l=f==null?void 0:f.data)==null?void 0:l.createFixture)!=null&&_.success&&(De(),t({msg:"Fixture moved successfully",variant:"success"}))}else if(a.type==="Session"){const f={club_id:x,id:a.id,session_name:a.session_name,team_ids:[a.team_id],session_type:a.session_type,session_date_time:a.StartTime.getTime(),coaches:a.c
1oach_ids,surface:a.surface,age_group:a.age_group,duration:a.duration,players:a.team_players},M=await Gt({variables:{createSessionInput:f}}),{success:Te,message:Ye}=((E=M==null?void 0:M.data)==null?void 0:E.createSession)??{};Te&&(Me(),t({msg:Ye||"Session updated successfully",variant:"success"}))}else a.type==="customEvent"&&(await ht({variables:{updateCustomEventInput:{name:a.name,id:parseInt(String(a.id)),date:a.StartTime.getTime(),team_id:(F=a.team)==null?void 0:F.id,description:a.description}}})).data.updateCustomEvent.status===200&&(ve(),t({msg:"Custom Event moved successfully",variant:"success"}));H(null)}},ha=async()=>{var a,l,_;if(i){if(T(!0),i.type==="Fixture"){const{data:E}=await qt({variables:{fixture_ids:[i.id]}});E.deleteFixtures.success&&(t({msg:"Fixture Deleted",variant:"success"}),De()),T(!1)}else if(i.type==="Session"){const E=await Jt({variables:{ids:i.id.toString(),type:1,club_id:x}});(l=(a=E==null?void 0:E.data)==null?void 0:a.deleteTraining)!=null&&l.success&&(t({msg:"Session Deleted",variant:"success"}),Me()),T(!1)}else if(i.type==="customEvent"){const E=await Kt({variables:{deleteCustomEventInput:{id:i.id}}}),{status:F,message:f}=((_=E==null?void 0:E.data)==null?void 0:_.deleteCustomEvent)??{};F===200?(ve(),t({msg:f||"Custom Event deleted successfully",variant:"success"})):t({msg:f||"Error in deleting custom event",variant:"error"}),T(!1)}H(null),wt()}},ba=async(a,l)=>{T(!0);const _=await Zt({variables:{createCustomEventInput:{club_id:x,name:a.title,date:new Date(a.dateTime).getTime(),team_ids:a.team,description:a.description}}}),{status:E,message:F}=_.data.createCustomEvent;(E===200||E===201)&&(ve(),t({msg:F||"Custom Event Created",variant:"success"}),l(),rt()),T(!1)},ga=async(a,l)=>{(await ht({variables:{updateCustomEventInput:{id:parseInt(String((i==null?void 0:i.id)||"0")),name:a.title,date:new Date(a.dateTime).getTime(),team_id:Number(a.team),description:a.description}}})).data.updateCustomEvent.status===200&&(l(),ve(),t({msg:"Custom Event updated successfully",variant:"success"}),rt())},Sa=a=>{const l=a.event.map(F=>F.name),_=a.coach.map(F=>F.id),E=Os(we,F=>{const f=be(l)||Rt(l,F.type),M=be(_)||F.coach_ids!=null&&Ls(_,Te=>Rt(F.coach_ids,Te));return f&&M});Je({event:a.event,coach:a.coach}),Ie(E)};o.useEffect(()=>{var a;if((a=de==null?void 0:de.clubInfo)!=null&&a.success){const l=JSON.parse(de.clubInfo.data);S(Ua(l)),l!=null&&l.fixture_color&&te(l.fixture_color),l!=null&&l.session_color&&ke(l.session_color),l!=null&&l.customEvent_color&&xe(l.customEvent_color)}},[de,de==null?void 0:de.clubInfo,S]),o.useEffect(()=>{const a=Fe.concat(Oe).concat(Le);re(a)},[Fe,Oe,Le]),o.useEffect(()=>{ye(ue||W||oe)},[ue,W,oe]);const lt=o.useRef(!1);B||(lt.current=!0);const ya=B&&!lt.current,ja=B&<.current,Ct=!!(fe.event.length||fe.coach.length),wa=Ct?Re:we,Ca=(i==null?void 0:i.type)==="Fixture"?{id:Number(i.id),opposition:i.opposition??"",team:{id:s?+s:Number(i.team_id)},surface:i.surface??null,homeAway:i.homeAway||i.venue||null,competition:i.competition??null,location:i.location??null,matchDuration:i.matchDuration??null,fixture_date_time:i.fixture_date_time??0,Format_id:i.Format_id??null,Formation_id:i.Formation_id??null,coach_ids:i.coach_ids??null}:null;return e.jsxs("div",{className:"flex h-full w-full flex-col bg-bg",children:[e.jsx(Rs,{showTitle:r,filterActive:Ct,isMobileView:n,fixtureColor:je,sessionColor:ie,customEventColor:pe,canAddFixture:at,canAddSession:me,showIconBtn:st&&Ne,handleOpenManageLegend:da,handleOpenFilterModal:ma,handleOpenManageFixture:()=>{ot(),bt()},handleOpenManageSession:()=>{ot(),yt()},handleOpenCustomEvent:()=>{ot(),jt()},addSheetOpen:j,setAddSheetOpen:D,onOpenAddSheet:()=>aa()}),e.jsx("div",{className:"min-h-0 flex-1 p-4 md:p-6",children:e.jsx(Qs,{canEditCalendar:Ne,isMobileView:n,events:wa,teamList:Z,fixtureColor:je,sessionColor:ie,customEventColor:pe,loadingEvents:ya,refreshing:ja,fixturePermissions:U,sessionPermissions:G,setEvents:re,setSelectedEvent:H,handleUpdateDraggedEvent:fa,handleOpenFixtureModal:bt,handleEditFixture:oa,handleEditSession:na,handleCreateSession:yt,handleOpenDuplicateSessionModal:ra,handleOpenDuplicateFixtureMod
1al:sa,handleOpenCustomEventModal:jt,handleOpenDeleteModal:ua,selectedDate:le,setSelectedDate:Ge})}),e.jsx(Js,{open:k,handleSave:xa,handleClose:ca,fixture:je,session:ie,customEvent:pe}),e.jsx(za,{open:u,onOpenChange:a=>a?b(!0):gt(),clubId:x,seasonId:(X==null?void 0:X.id)??null,createdByUserId:(I==null?void 0:I.id)??0,teams:Z,coaches:ea,fixtureId:(i==null?void 0:i.type)==="Fixture"?Number(i.id):null,editFixture:Ca,initialTeamId:s?+s:q==null?void 0:q[0],initialDate:m,askOpenAfterCreate:!0,onSaved:(a,l)=>{De(),l!=="create"&>()}}),e.jsx(Ha,{open:N,onOpenChange:a=>a?Y(!0):St(),selectedFixtures:(i==null?void 0:i.type)==="Fixture"?[i]:[],teams:Z,onSaved:()=>{De(),St()}}),C&&e.jsx(Vs,{open:C,onClose:ia,teamId:s,date:m,onSaved:Me}),e.jsx(Qa,{open:Q,onClose:la,onSuccess:Me,selectedSession:(i==null?void 0:i.type)==="Session"?i:null,selectedSessionIds:(i==null?void 0:i.type)==="Session"?[Number(i.id)]:[]}),e.jsx(Gs,{open:v,loading:w,isDuplicate:R,teamId:s,selectedCustomEvent:(i==null?void 0:i.type)==="customEvent"?i:null,teamOptions:Z,date:m,handleClose:rt,handleSubmit:(i==null?void 0:i.type)==="customEvent"&&!R?ga:ba}),e.jsx(en,{open:P,clubId:x,filters:fe,handleClose:pa,handleFilters:Sa}),e.jsx(Xa,{open:A,loading:w,handleClose:wt,handleDelete:ha,title:`Delete ${(i==null?void 0:i.type)==="customEvent"?"Custom Event":(i==null?void 0:i.type)??""}?`,actionBtnTitle:"Delete",subjectName:i==null?void 0:i.Subject,warning:"This action cannot be undone."}),it.modal]})}const $n=Object.freeze(Object.defineProperty({__proto__:null,default:an},Symbol.toStringTag,{value:"Module"}));export{an as C,Vs as M,$n as a};
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.