1import{j as t,a as p}from"./react-vendor-DJtAp8P_.js";import{z as C,E as B,a7 as Na,T as v,aL as fo,K as yo,w as No,a8 as Pe,u as La,J as Ee,j as bo,aM as Wa,aN as za,C as So,aC as $o,aO as Ua,aP as Co,aQ as wo,aR as jo}from"./mui-DvP2hOwX.js";import{d as ft}from"./dayjs-CFxoC4n5.js";import{h as ae}from"./moment-Bj79pgB5.js";import{F as Lo,e as Fo,g as Ha,u as Je,c as Ga,d as qa,I as he,t as Wo,f as zo,ab as Va,a0 as Ya,m as ye,ac as Qa,Z as Xa,ad as Ka,ae as Ja,af as _o,z as vo,ag as Za}from"./app-DT7WuczB.js";import{S as yt}from"./Add-DRSElN7O.js";import{S as en}from"./Manage-BcZiAr0H.js";import{S as tn}from"./Copy-Bx2E8fMZ.js";import{S as on}from"./DeleteGray-K_LbbGcc.js";import{f as an}from"./fixtures-import-D2qsSBTS.js";import{b as Se,q as Do,p as nn,s as sn,D as rn,B as ln,I as Io,u as ko}from"./swiper-react-DcF17yCe.js";import{B as Be}from"./Button-C4goEOKP.js";import{w as cn,a as dn,x as pn}from"./query-CcmDMjHA.js";import{bL as Uo,bC as Oe,bi as mn,aT as hn,aW as be,bM as Mo,bN as bt,bO as un,bP as To,bQ as Ze}from"./index-CyS3LFy6.js";import{B as Ho,F as gn,G as xn,H as fn}from"./mutation--iSLlBrt.js";import{D as yn}from"./DeleteModal-BX6BaNP3.js";import{c as Go,e as bn,u as qo,f as Ao}from"./index.esm-CWqXbt53.js";import{F as Sn}from"./FilterHeader-RonmFUsJ.js";import{M as Eo}from"./SessionPlannerMobile-85wkJ1ZS.js";import{G as $n}from"./GridCardView-DEqv0l0G.js";import{S as Cn}from"./Search-BEYvHCFs.js";import{S as wn}from"./SecondaryHeader-CQ32PoR-.js";import{T as Bo}from"./ToggleButton-mhLknYBH.js";import{A as jn}from"./AlertModal-CGXcj45Q.js";import{S as Fn}from"./SortMenu-CjsJdGGV.js";import{S as _n,M as vn}from"./MultiSelectMenu-T4g75gFl.js";import{I as Dn}from"./InlineHint-BwtPd7HF.js";import{u as In}from"./club-bdHkPrsY.js";import{g as kn,i as St}from"./fixtureConstants-B-crqK8o.js";import{M as Mn,a as Tn}from"./ManageFixtureModal-ZcJHVBOM.js";import{M as Ct}from"./Modal-BzPnYVEi.js";import{ImportFixturesModal as An}from"./ImportFixturesModal-BSr7J64q.js";import{n as Re,e as Vo,u as En}from"./apollo-DL0KWP0Y.js";import{f as et}from"./findKey-Gt-tDAVi.js";import{s as Bn}from"./some-YFJAbcVi.js";import{m as Rn}from"./mapValues-CGRglPEa.js";import{g as Pn}from"./groupBy-BsGpKOH5.js";import{m as On}from"./map-BI8CQ8np.js";import"./mui-styles-C9F12l22.js";import"./babel-helpers-D2wBBc1I.js";import"./imageOptimization-zUL1CBPb.js";import"./lodash-icp7yO-G.js";import"./merge-TfBrBrIh.js";import"./_baseAssignValue-CjtYt4eh.js";import"./_baseClone-DByvJCmO.js";import"./isArrayLikeObject-CcVCHQro.js";import"./browser-B3fhYDhb.js";import"./_arrayIncludes-DFQcso6E.js";import"./_baseIndexOf-DqPIyCu4.js";import"./hello-pangea-dnd-1bhs5THC.js";import"./index-B79atc36.js";import"./_baseDifference-BHjDay7E.js";import"./omit-BaIHraq0.js";import"./index-bEsv4Yks.js";import"./mui-x-DMY3qA32.js";import"./s3FileHandler-Bp64keCt.js";import"./compact-DZdspzxW.js";import"./cloneDeep-mVQ3twB2.js";import"./Filter-vdZeYdaV.js";import"./SearchBlue-Cq--C03-.js";import"./values-DeBIqcD0.js";try{let s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},h=new s.Error().stack;h&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[h]="965aed3f-4ebe-4ea2-8c56-ea907b6272c1",s._sentryDebugIdIdentifier="sentry-dbid-965aed3f-4ebe-4ea2-8c56-ea907b6272c1")}catch{}const Nn={teams:[]},Ln=({open:s,loading:h,handleClose:a,teamOptions:r,handleDuplicateFixture:$})=>{const y=Go({teams:bn().min(1,"At least one team is required").required("At least one team is required")}),l=qo({initialValues:Nn,enableReinitialize:!0,validationSchema:y,onSubmit:(i,{resetForm:n})=>{$({...i},n)}}),g=()=>{a(),l.resetForm()};return t.jsx(Ct,{open:s,actionBtnTitle:"Duplicate Fixture",handleClose:g,title:"Duplicate Fixture",actionHandler:l.submitForm,loading:h,children:t.jsx(C,{container:!0,spacing:3,children:t.jsx(C,{size:12,children:t.jsx(Se,{multiple:!0,name:"teams",label:"Teams",showTextValue:!1,value:l.values.teams,onChange:l.handleChange,options:r,error:l.touched.teams&&!!l.errors.teams,helperText:l.touched.teams&&l.errors.teams})})})})},Wn=({open:s,loading:h,recipients:a,onConfirm:r,onSkip:$,creating:y})=>{const[l,g]=p.useState(new Set);p.useEffect(()=>{a.length>
10&&g(new Set(a.map(d=>d.id)))},[a]);const i=d=>{g(k=>{const T=new Set(k);return T.has(d)?T.delete(d):T.add(d),T})},n=a.filter(d=>d.role==="Coach"),u=a.filter(d=>d.role==="Parent");return t.jsx(Ct,{open:s,title:"Notify Recipients",actionBtnTitle:"Confirm & create",actionHandler:()=>r([...l]),loading:y,disabledBtn:h,cancelBtn:!1,secondaryBtnTitle:"Create without notifications",secondaryBtnHandler:$,secondaryBtnLoading:y,disableBackdropClick:!0,children:h?t.jsx(B,{display:"flex",justifyContent:"center",py:4,children:t.jsx(Na,{size:32})}):a.length===0?t.jsx(v,{color:"text.secondary",children:"No recipients found for this team and season."}):t.jsxs(B,{children:[t.jsx(v,{variant:"body2",color:"text.secondary",mb:2,children:"Select who should receive a notification about this new fixture. All recipients are pre-selected."}),n.length>0&&t.jsxs(B,{mb:2,children:[t.jsx(v,{variant:"subtitle2",fontWeight:700,mb:1,children:"Coaches"}),n.map(d=>t.jsx(fo,{control:t.jsx(yo,{checked:l.has(d.id),onChange:()=>i(d.id),size:"small"}),label:t.jsx(v,{variant:"body2",children:d.name}),sx:{display:"flex",ml:0}},d.id))]}),n.length>0&&u.length>0&&t.jsx(No,{sx:{mb:2}}),u.length>0&&t.jsxs(B,{children:[t.jsx(v,{variant:"subtitle2",fontWeight:700,mb:1,children:"Parents"}),u.map(d=>t.jsx(fo,{control:t.jsx(yo,{checked:l.has(d.id),onChange:()=>i(d.id),size:"small"}),label:t.jsx(v,{variant:"body2",children:d.name}),sx:{display:"flex",ml:0}},d.id))]})]})})},me={select:{"& .MuiOutlinedInput-input":{backgroundColor:s=>s.palette.common.white,color:"text.primary"}},teamName:{fontSize:"14px",fontWeight:600,textAlign:"center"},vs:{fontSize:"12px",color:"text.secondary",fontWeight:600},avatar:{width:48,height:48,fontSize:"16px",fontWeight:700}},zn=({open:s,handleClose:h,fixture:a,onSuccess:r})=>{var je,Le,We,Fe,H,ne,L,ze,Ue,_e;const[$]=Re(Ho),[y,l]=p.useState([]),[g,i]=p.useState(!1),[n]=Lo(),u=Go({goalsScored:Ao().integer("Must be a whole number").required("Required"),goalsConceded:Ao().integer("Must be a whole number").required("Required")}),d=qo({initialValues:{goalsScored:"",goalsConceded:"",outCome:"",starPlayer:""},enableReinitialize:!0,validationSchema:u,onSubmit:M=>T(M)}),{data:k}=Vo(cn,{variables:{fixtureId:+(a==null?void 0:a.id)||0,includeSoftDeleted:!0,teamId:(je=a==null?void 0:a.team)==null?void 0:je.id},fetchPolicy:"no-cache",skip:!(a!=null&&a.id)||!((Le=a==null?void 0:a.team)!=null&&Le.id)});p.useEffect(()=>{if(k){const M=k.fixturePlayers.map(G=>({id:G.player_id,name:`${G.player_name} ${G.player_surname}`.trim()}));l(M)}},[k]),p.useEffect(()=>{const{goalsScored:M,goalsConceded:G}=d.values;if(M!==""&&G!==""&&typeof M=="number"&&typeof G=="number"){const q=M>G?1:M<G?2:3;d.setFieldValue("outCome",q)}},[d.values.goalsScored,d.values.goalsConceded]);const T=async M=>{var G;i(!0);try{const q=await $({variables:{id:+a.id,teamScore:M.goalsScored,oppTeamScore:M.goalsConceded,result:M.outCome,report_status:1,...M.starPlayer?{topPlayer:M.starPlayer,is_star_player_selected_manually:!0}:{}}}),{success:He,message:se}=(G=q==null?void 0:q.data)==null?void 0:G.updateFixture;He?(n({msg:se||"Score saved. Rate your players to track performance",variant:"success"}),r==null||r(),h()):n({msg:se||"Failed to update fixture.",variant:"error"})}catch{n({msg:"Something went wrong.",variant:"error"})}i(!1)},V=()=>{d.resetForm(),h()},Y=d.values.outCome?(We=Uo[d.values.outCome])==null?void 0:We.label:"-";return t.jsxs(Ct,{open:s,handleClose:V,title:"Quick Score",actionBtnTitle:"Save & Complete",actionHandler:d.handleSubmit,loading:g,disabledBtn:!d.isValid||!d.dirty,dialogMaxWidth:"xs",children:[t.jsxs(C,{container:!0,alignItems:"center",justifyContent:"center",spacing:2,sx:{mb:3},children:[t.jsx(C,{size:5,children:t.jsxs(B,{display:"flex",flexDirection:"column",alignItems:"center",gap:1,children:[t.jsx(Pe,{sx:me.avatar,src:(Fe=a==null?void 0:a.team)!=null&&Fe.logo?`${Oe}${a.team.logo}`:void 0,children:(L=(ne=(H=a==null?void 0:a.team)==null?void 0:H.name)==null?void 0:ne[0])==null?void 0:L.toUpperCase()}),t.jsx(v,{sx:me.teamName,children:(ze=a==null?void 0:a.team)==null?void 0:ze.name})]})}),t.jsx(C,{size:2,children:t.jsx(B,{display:"flex",justifyContent:"center",children:t.jsx(v,{sx:me.vs,children:"VS"})})}),t.jsx(C,{size:5,children:t.jsxs(B,{display:"flex",flexDirection:"column",alignItems:"center",gap:1,children:[t.jsx(Pe,{sx:me.avatar,src:a!=null&&a.opposition_team_logo?`${Oe}${a.opposition_team_logo}`:void 0,children:(_e=(Ue=a==null?void 0:a.opposition)==null?void 0:Ue[0])==null?void 0:_e.toUpperCase()}),t.jsx(v,{sx:me.teamName,children:a==null?void 0:a.opposition})]})})]}),t.jsxs(C,{container:!0,spacing:1,alignItems:"center",children:[t.jsx(C,{size:5,children:t.jsx(Se,{useNullishCoalescing:!0,isS
1howClearable:!1,name:"goalsScored",label:"Scored",customStyle:me.select,options:Do(100,!1,!0,"number"),value:d.values.goalsScored,error:d.touched.goalsScored&&!!d.errors.goalsScored,helperText:d.touched.goalsScored&&d.errors.goalsScored,onChange:d.handleChange})}),t.jsx(C,{size:2,children:t.jsx(B,{display:"flex",alignItems:"center",justifyContent:"center",children:t.jsx(v,{sx:{fontWeight:700,fontSize:"18px",color:"text.secondary"},children:"-"})})}),t.jsx(C,{size:5,children:t.jsx(Se,{useNullishCoalescing:!0,isShowClearable:!1,name:"goalsConceded",label:"Conceded",customStyle:me.select,options:Do(100,!1,!0,"number"),value:d.values.goalsConceded,error:d.touched.goalsConceded&&!!d.errors.goalsConceded,helperText:d.touched.goalsConceded&&d.errors.goalsConceded,onChange:d.handleChange})})]}),d.values.outCome&&t.jsx(B,{sx:{textAlign:"center",mt:1.5,mb:.5},children:t.jsx(v,{sx:{fontSize:"14px",fontWeight:700,color:d.values.outCome===1?"#22C55E":d.values.outCome===2?"#EF4444":"#F59E0B"},children:Y})}),t.jsx(No,{sx:{my:2}}),t.jsx(Se,{name:"starPlayer",label:"Star Player (optional)",customStyle:me.select,options:y,value:d.values.starPlayer,onChange:d.handleChange})]})},R=(s,h)=>{let a=0;for(let r=0;r<((s==null?void 0:s.length)||0);r++)a=(a<<5)-a+s.charCodeAt(r)|0;return h[Math.abs(a)%h.length]},Ne=s=>(s==null?void 0:s.result)===1||(s==null?void 0:s.result)===2||(s==null?void 0:s.result)===3,wt=s=>(s==null?void 0:s.result)==null,Un=s=>(s==null?void 0:s.opposition)||"this fixture",Hn=s=>{if(!Ne(s))return null;const{teamScore:h,oppTeamScore:a,result:r,homeAway:$,opposition:y}=s;if(h==null||a==null)return null;const l=y||"the opposition",g=Math.abs(h-a),i=$==="A",n=`${h}-${a}`;return r===1&&g>=3?{text:R(l,[`A commanding ${n} demolition of ${l}. ${i?"Away from home too â ruthless.":"Fortress mentality on full display."}`,`${l} were swept aside ${n}. ${i?"Devastating on the road.":"Completely dominant at home."}`,`${n} against ${l} â clinical from start to finish. ${i?"A statement away day.":"The home crowd got their money's worth."}`]),type:"highlight",icon:"MilitaryTech"}:r===1&&g===1?{text:R(l,[`A gutsy ${n} victory over ${l}. Tight affair, but the lads found a way.${i?" Priceless away from home.":""}`,`Edged past ${l} ${n}. Nervy at times, but winners find a way.${i?" Gritty away win.":""}`,`${n} over ${l} â had to grind it out. ${i?"A steal on the road.":"Job done at home."}`]),type:"positive",icon:"ThumbUp"}:r===1?{text:R(l,[`${n} against ${l} â a professional job.${i?" Solid away day.":" Comfortable at home."}`,`Beat ${l} ${n}. Controlled the contest well.${i?" Good on the travels.":""}`,`${l} dispatched ${n}. ${i?"Composed away from home.":"Home advantage used well."}`]),type:"positive",icon:"ThumbUp"}:r===2&&g>=3?{text:R(l,[`Hammered ${n} by ${l}. A tough afternoon to digest.${i?" Hostile trip.":" Difficult at home."}`,`${l} ran riot â ${n}. Lessons to learn from this one.${i?" Away days don't get harder.":""}`,`A ${n} mauling at the hands of ${l}. Back to the drawing board.`]),type:"warning",icon:"SentimentDissatisfied"}:r===2&&g===1?{text:R(l,[`Fell short ${n} against ${l}. Fine margins â not far away.${i?" Could have snatched something on the road.":""}`,`${l} nicked it ${n}. Agonisingly close.${i?" A point would have been fair.":" One that got away at home."}`,`Lost ${n} to ${l}. Went toe-to-toe but came up just short.`]),type:"warning",icon:"SentimentNeutral"}:r===2?{text:R(l,[`Beaten ${n} by ${l}. Outgunned on the day.${i?" Tough away fixture.":""}`,`${l} took it ${n}. Second best this time around.`,`Went down ${n} against ${l}. Plenty to reflect on.`]),type:"warning",icon:"SentimentDissatisfied"}:{text:R(l,[`Honours even at ${n} with ${l}
1.${i?" A point on the road is never bad.":" One that could have gone either way."}`,`Shared the spoils ${n} against ${l}. ${h>0?"Entertaining contest.":"Defences on top."}`,`${n} stalemate with ${l}.${i?" A solid away point.":" Will feel like two dropped at home."}`]),type:"neutral",icon:"Handshake"}},Gn=s=>{if(!Ne(s))return null;const{tactical_summary_score:h,in_possession_score:a,out_possession_score:r,transition_summary_score:$,opposition:y}=s,g=Object.entries({tactical_summary_score:h,in_possession_score:a,out_possession_score:r,transition_summary_score:$}).filter(([,V])=>V!=null&&V>0);if(g.length<2)return null;const i=y||"the opposition",n=g.reduce((V,[,Y])=>V+Y,0)/g.length,u=[...g].sort((V,Y)=>Y[1]-V[1]),d=u[0],k=u[u.length-1],T={tactical_summary_score:"tactical shape",in_possession_score:"possession play",out_possession_score:"defensive structure",transition_summary_score:"transitions"};return n>=8?{text:R(i,[`Dictated proceedings against ${i} â ${T[d[0]]} was outstanding at ${d[1]}/10.`,`A masterclass against ${i}. Averaged ${n.toFixed(1)}/10 across all phases. Complete performance.`,`Controlled every phase against ${i}. ${T[d[0]]} peaked at ${d[1]}/10 â textbook stuff.`]),type:"highlight",icon:"Psychology"}:n>=6?d[1]-k[1]>=3?{text:R(i,[`Strong in ${T[d[0]]} (${d[1]}/10) against ${i}, but ${T[k[0]]} lagged at ${k[1]}/10.`,`${T[d[0]]} impressed at ${d[1]}/10 vs ${i}. Focus needed on ${T[k[0]]} (${k[1]}/10).`,`Mixed bag against ${i} â ${T[d[0]]} shone (${d[1]}/10) while ${T[k[0]]} dipped to ${k[1]}/10.`]),type:"neutral",icon:"Psychology"}:{text:R(i,[`Organised display against ${i} â averaging ${n.toFixed(1)}/10 across all four phases.`,`Competent all-round showing vs ${i}. No glaring weaknesses â ${n.toFixed(1)}/10 average.`,`Tidy performance against ${i}. Balanced across all areas at ${n.toFixed(1)}/10.`]),type:"positive",icon:"Psychology"}:n<4?{text:R(i,[`Overrun against ${i} â ${n.toFixed(1)}/10 average. ${T[k[0]]} was the biggest concern at ${k[1]}/10.`,`Struggled across the board vs ${i}. ${T[k[0]]} (${k[1]}/10) needs urgent attention.`,`${i} exposed weaknesses everywhere â ${n.toFixed(1)}/10 average. Rebuild around ${T[d[0]]} (${d[1]}/10).`]),type:"warning",icon:"ReportProblem"}:{text:R(i,[`Room for improvement against ${i} â ${n.toFixed(1)}/10 average. ${T[k[0]]} (${k[1]}/10) is the priority.`,`Workmanlike showing vs ${i}. ${T[d[0]]} (${d[1]}/10) was the bright spot among a ${n.toFixed(1)}/10 average.`,`Patchy against ${i} â ${T[k[0]]} at ${k[1]}/10 let the side down. Overall ${n.toFixed(1)}/10.`]),type:"neutral",icon:"Psychology"}},qn=s=>{if(!Ne(s))return null;const{player:h,opposition:a}=s;if(!(h!=null&&h.player_name))return null;const r=a||"the opposition",$=`${h.player_name} ${h.player_surname||""}`.trim();return{text:R(r,[`${$} led from the front against ${r}. Named star player for a reason.`,`${$} stood out against ${r} â made the difference when it mattered most.`,`${$} delivered the goods vs ${r}. The standout performer on the pitch.`,`All eyes on ${$} against ${r} â produced the headline moments.`]),type:"highlight",icon:"Stars"}},Vn=s=>{if(!Ne(s)||(s==null?void 0:s.report_status)===1)return null;const h=(s==null?void 0:s.opposition)||"this fixture";return{text:R(h,[`Match report for ${h} still to be completed â capture it while it's fresh.`,`The ${h} report hasn't been filed yet. Lock in those observations before they fade.`,`Don't let the ${h} match slip â the report is waiting to be finished.`]),type:"warning",icon:"EditNote"}},Yn=(s,h)=>{if(!wt(s))return null;const a=(s==null?void 0:s.opposition)||"the next opponents",$=(s==null?void 0:s.homeAway)==="A"?"on the road":"at home";if(!(h!=null&&h.length))return{text:R(a,[`${a} up next ${$}. No recent form to draw from â go in with a clean slate.`,`First test of the run â ${a} ${$}. Time to set the tone.`,`${a} await ${$}. Fresh start, fresh opportunity.`]),type:"neutral",icon:"Event"};const y=h.slice(-5),l=y.filter(i=>i===1).length,g=y.filter(i=>i===2).length;return l>=4?{text:R(a,[`Riding a wave of confidence into ${a} ${$} â ${l} wins from the last ${y.length}. Keep the foot down.`,`Flying into the ${a} clash ${$}. ${l} from ${y.length} â momentum is real.`,`${a} face a side in red-hot form ${$} â ${l} wins in ${y.length}. Carry it forward.`]),type:"positive",icon:"Whatshot"}:g>=4?{text:R(a,[`Looking to bounce back against ${a} ${$}. ${g} defeats from ${y.length} â time to turn the tide.`,`${a} ${$} is the chance to snap a run of ${g} losses in ${y.length}. Reset and respond.`,`Tough spell â ${g} losses from ${y.length}. ${a} ${$} is the perfect reset fixture.`]),type:"warning",icon:"Replay"}:l>=3?{text:R(a,[`Building nicely heading into ${a} ${$} â ${l} wins from the last ${y.length}. In good shape.`,`Solid recent form before ${a} ${$}. ${l} from ${y.length} â the squad will feel good.`,`${a} ${$} next, and the form reads well â ${l} wins in the last ${y.length}.`]),type:"positive",icon:"TrendingUp"}:{text:R(a,[`Mixed bag recently â ${l}W ${g}L from the last ${y.length}. ${a} ${$} is a chance to find rhythm.`,`Form is inconsistent heading into ${a} ${$}. ${l} wins, ${g} losses from ${y.length} â searching for consistency.`,`${a} ${$} next. Recent results have been patchy (${l}W ${g}L) â a settled performance would go a long way.`]),type:"neutral",icon:"Shuffle"}},Ro=s=>{const h=s==null?void 0:s.fixture_players_id;if(!(h!=null&&h.length))return null;const a=(s==null?void 0:s.opposition)||"this fixture",r=h.length;return r>=16?{text:R(a,[`Full-strength squad of ${r} selected for ${a}. Plenty of options from the bench.`,`${r}
1 players named for ${a} â a deep squad to pick from. Competition for places is healthy.`,`Strength in depth against ${a} â ${r} in the matchday group. No shortage of firepower.`]),type:"positive",icon:"Groups"}:r<=11?{text:R(a,[`Light on numbers for ${a} â only ${r} players available. No margin for error.`,`Just ${r} bodies for the ${a} match. Bare bones â every player will need to dig in.`,`${r} players named against ${a}. Threadbare squad â manage the minutes carefully.`]),type:"warning",icon:"PersonOff"}:{text:R(a,[`${r} players in the squad for ${a}. Decent numbers â enough cover if needed.`,`Squad of ${r} for ${a}. Solid selection â a few options off the bench.`,`${r} named for ${a}. Workable squad with a bit of flexibility.`]),type:"neutral",icon:"Groups"}},Po=(s,h)=>{if(!s)return[];const a=[],r=y=>{y&&a.push(y)};Ne(s)?(r(Hn(s)),r(Gn(s)),r(qn(s)),r(Vn(s)),r(Ro(s))):wt(s)&&(r(Yn(s,h)),r(Ro(s)));const $={highlight:0,warning:1,positive:2,neutral:3};return a.sort((y,l)=>($[y.type]??4)-($[l.type]??4)),a},Qn=(s,h)=>{const a=Un(s);if(!s)return{noData:!0,text:"No match data recorded yet."};if(wt(s)){const l=Po(s,h);if(!l.length)return{noData:!0,text:"Fixture coming up â insights will appear after the match."};const g=l.find(n=>n.type==="highlight")||l.find(n=>n.type==="positive"),i=l.find(n=>n.type==="warning")||l.find(n=>n.type==="neutral"&&n!==g);return{noData:!1,strength:(g==null?void 0:g.text)||null,improve:(i==null?void 0:i.text)||null}}const r=Po(s,h);if(!r.length)return{noData:!0,text:R(a,[`No match data recorded yet for ${a}. Complete the report to unlock insights.`,`The ${a} fixture has no data yet. Fill in the details to see what happened.`,`Nothing captured for ${a} â add match data to bring this fixture to life.`])};const $=r.find(l=>l.type==="highlight")||r.find(l=>l.type==="positive"),y=r.find(l=>l.type==="warning")||r.find(l=>l.type==="neutral"&&l!==$);return{noData:!1,strength:($==null?void 0:$.text)||null,improve:(y==null?void 0:y.text)||null}},Xn=({isMobileView:s,tabsCollapse:h,clubPrimaryColor:a})=>({container:{height:"100%",backgroundColor:r=>r.palette.common.white},typography:{fontSize:"14px"},searchContainer:{padding:{xs:"16px 6px 0px",sm:"16px"},background:r=>r.palette.common.white,...!s&&{borderBottom:r=>`1px solid ${r.palette.divider}`}},avatar:{fontSize:"14px"},btnSelect:{width:"50px",fontSize:"14px",fontWeight:"400",lineHeight:"22px",color:"text.primary",justifyContent:"start",backgroundColor:"unset","&:hover":{backgroundColor:"unset"}},btnMenu:{padding:0,margin:0,"& .MuiMenuItem-root":{height:"40px",padding:"10px","& .MuiGrid-container":{justifyContent:"start","& .MuiGrid-container":{display:"block",width:"unset"}}}},tableIndicator:{height:"19px",width:"19px",borderRadius:"50%"},deleteBtn:{height:"36px",borderColor:r=>r.availability.unavailable,color:r=>r.availability.unavailable,"&:hover":{borderColor:r=>r.availability.unavailable}},duplicateBtn:{height:"36px"},collapseBtnContainer:{zIndex:100,height:"22px",width:"22px",position:"absolute",top:"158px",left:"47%",display:{xs:"block",sm:"none"},backgroundColor:r=>a||r.palette.primary.main,borderRadius:"50%"},collapseBtn:{position:"relative",color:r=>r.palette.common.white,top:"-1px",left:"-1px",transform:h?"unset":"rotateX(180deg)",cursor:"pointer"},searchCustomStyles:{maxWidth:{xs:"100%",sm:"320px"}}}),Oo={tooltip:{sx:{maxWidth:360,backgroundColor:"#1A2027",borderRadius:"10px",px:1.5,py:1}},arrow:{sx:{color:"#1A2027"}}};function $t(s,h){const a=(s==null?void 0:s.start_date)||(h==null?void 0:h.season_start_date),r=(s==null?void 0:s.end_date)||(h==null?void 0:h.season_end_date);return!a||!r?{startDate:"",endDate:""}:{startDate:he(Wo(a)),endDate:he(zo(r))}}const ii=()=>{var io,ro,lo,co,po,mo,ho,uo,go,xo;const{t:s}=Fo("common"),{t:h}=Fo("dugout"),a=kn(h),r=mn(),$=Ha(),y=La(e=>e.breakpoints.down("md")),l=hn(),g=Je(e=>{var o;return(o=e==null?void 0:e.teams)==null?void 0:o.team}),i=Je(e=>e.club),n=Ga(),{currentSeason:u,isAllSeasonSelected:d,isReadOnlyMode:k,isUpcomingSeason:T,isArchived:V}=qa();Je(e=>e.app.mobileNavigationCollapse);const Y=Je(e=>{var o,c;return((c=(o=e==null?void 0:e.app)==null?void 0:o.dataViews)==null?void 0:c.fixtures)||"grid"}),je=En(),[Le]=Re(gn),[We]=Re(xn),[Fe]=Re(fn),[H,ne]=p.useState(0),[L,ze]=p.useState(50),[Ue,_e]=p.useState(null),[M,G]=p.useState(""),[q,He]=p.useState(St),[se,Yo]=p.useState("asc"),[F,Ge]=p.useState([]),[jt,qe]=p.useState(0),[Z,$e]=p.useState({}),[ee,ue]=p.useState(-1),[Qo,tt]=p.useState(((io=l==null?void 0:l.state)==null?void 0:io.openManageModal)||!1),[Xo,Ft]=p.useState(!1),[Ko,_t]=p.useState(!1),[Jo,ot]=p.useState(!1),[ve,re]=p.useState(!1),[at,nt]=p.useState(!0),[st,Zo]=p.useState([]),[ge]=Lo(),[it,xe]=p.useState({}),O=Object.keys(it).map(Number),[ea]=Re(Ho),[Kn,Ve]=p.useState(!1),Q=p.useRef(null),Ce=p.useRef(0),[le,fe]=p.useState({startDate:"",endDate:""}),rt=p.useRef(le);rt.current=le;const[lt,vt]=p.useState(0),[ta,Jn]=p.useState(!1),[oa,Dt]=p.useState("Default Range"),[De,It]=p.useState("all"),[aa,kt]=p.useState(!1),[na,Mt]=p.useState({}),[we,Tt]=p.useState([]),[ie,ct]=p.useState([]),[ce,sa]=p.useState([]),{coachListRes:te,getClubListingData:ia}=In(),[At,dt]=p.useState(null),[ra,pt]=p.useState(null),[Ie,la]=p.useState({value:null,order:"ASC"}),[ke,Et]=p.useState([{name:"default",type:"radio"}]),[ca,Bt]=p.useState(!1),[da,mt]=p.useState(null),[Rt,ht]=p.useState(null),[pa,Pt]=p.useState(!1),[ma]=p.useState([]),[ha]=p.useState(!1),[Ot,Nt]=p.useState(null),[Lt,Wt]=p.useState(null),X=(co=(lo=(ro=n==null?void 0:n.userRolesPermissions)==null?void 0:ro.permissions)==null?void 0:lo.dugout)==null?void 0:co.fixtures,zt=(X==null?void 0:X.add)===be.YES&&(!k||T),N=Xn({isMobileView:y,tabsCollapse:ta,clubPrimaryColor:i==null?void 0:i.color});p.useEffect(()=>{i&&fe($t(u,i))},[u==null?void 0:u.id,i]),p.useEffect(()=>{xe({}),ue(-1),$e({}),Ge([]),qe(0),ct([])},[u==null?void 0:u.id]);const{data:de}=Vo(dn,{variables:{club_id:n.club_id?n.club_id:i.club_id,...d?{}:{season_id:u==null?void 0:u.id}},fetchPolicy:"no-cache",skip:!(u!=null&&u.id)}
1),oe=async(e,o,c="",m,f,_=le.startDate,x=le.endDate)=>{var w,b,A,z,U;Q.current&&(Q.current.abort(),Q.current=null),Ce.current+=1;const S=Ce.current,D=JSON.stringify(g!=null&&g.length?g:[]),I=[...ie||[]].sort((W,K)=>W-K).join(","),P=new AbortController;Q.current=P,nt(!0),Ve(!0);try{const W=await je.query({query:pn,variables:{fixtureListingInput:{club_id:n!=null&&n.club_id?n==null?void 0:n.club_id:i.club_id,limit:e,offset:e*o,team_ids:g!=null&&g.length?g==null?void 0:g.join():"",searchQuery:c,sortOrder:y?Ie.order:m,sortBy:y?Ie.value||void 0:f,startDate:_,endDate:x,status:Mo.find(({id:pe})=>pe===De).id,filter:Rn(Pn(we,"category"),pe=>On(pe,"value")),...d?{}:{season_id:u==null?void 0:u.id},...ie!=null&&ie.length?{coach_ids:ie}:{}}},skip:!(n!=null&&n.club_id)||!(u!=null&&u.id),fetchPolicy:"no-cache",context:{fetchOptions:{signal:P.signal}}}),K=JSON.stringify(g!=null&&g.length?g:[]),Te=[...ie||[]].sort((pe,Ae)=>pe-Ae).join(",");if(Ce.current!==S||P.signal.aborted||D!==K||I!==Te)return;const E=W==null?void 0:W.data;if(E!=null&&E.fixtureListing&&((w=E==null?void 0:E.fixtureListing)==null?void 0:w.success)&&Ce.current===S&&!P.signal.aborted){const Ae=(A=(b=E==null?void 0:E.fixtureListing)==null?void 0:b.data)==null?void 0:A.fixtures.map(j=>{var J,Ke;return{...j,score:j.result?`${j.teamScore||0}-${j.oppTeamScore||0}`:"",venue:j.homeAway?j.homeAway==="H"?"Home":"Away":"",status:j.result?Xa(Uo,j.result).label:"",starPlayer:`${((J=j==null?void 0:j.player)==null?void 0:J.player_name)||""} ${((Ke=j==null?void 0:j.player)==null?void 0:Ke.player_surname)||""}`.trim(),competition:j.competition,matchDuration:j.matchDuration||""}});Ge(Ae),qe((z=E==null?void 0:E.fixtureListing)==null?void 0:z.data.count)}}catch(W){if(W.name==="AbortError"||((U=W.networkError)==null?void 0:U.name)==="AbortError"||P.signal.aborted)return;Ce.current===S&&console.error("Error fetching fixture list:",W)}finally{Ce.current===S&&Q.current===P&&(nt(!1),Ve(!1),Q.current=null)}};p.useEffect(()=>{if(de){const{success:e}=de==null?void 0:de.getClubTeamsLite;if(e){const o=de==null?void 0:de.getClubTeamsLite.data.map(c=>({name:c.name,id:c.id,avatar:c.logo?`${Oe}/${c.logo}`:c.name}));Zo(o)}}},[de]),p.useEffect(()=>{!(ce!=null&&ce.length)&&(n!=null&&n.club_id||i!=null&&i.club_id)&&ia({club_id:n!=null&&n.club_id?n==null?void 0:n.club_id:i.club_id})},[ce==null?void 0:ce.length,n==null?void 0:n.club_id,i==null?void 0:i.club_id]),p.useEffect(()=>{var e,o,c;if(te!=null&&te.data){const{success:m}=(e=te==null?void 0:te.data)==null?void 0:e.coachListNew;m&&sa(((c=(o=te==null?void 0:te.data)==null?void 0:o.coachListNew)==null?void 0:c.data)||[])}},[te]);const Ut=(g==null?void 0:g.join(","))??"",Ht=[...ie||[]].sort((e,o)=>e-o).join(","),Gt=p.useRef({});p.useEffect(()=>{Q.current&&(Q.current.abort(),Q.current=null);const e=(u==null?void 0:u.start_date)||(i==null?void 0:i.season_start_date),o=(u==null?void 0:u.end_date)||(i==null?void 0:i.season_end_date),c=De==="all"&<===0,m=c&&e?he(Wo(e)):rt.current.startDate,f=c&&o?he(zo(o)):rt.current.endDate,_={page:H,rowsPerPage:L,selectedTeamsKey:Ut,statusFilter:De,dateRangeTrigger:lt,fixtureFilterChip:we,selectedCoachIdsKey:Ht,sort:Ie,seasonId:u==null?void 0:u.id};return Object.entries(_).filter(([S,D])=>Gt.current[S]!==D).map(([S])=>S),Gt.current=_,!!(n!=null&&n.club_id&&(u!=null&&u.id))?oe(L,H,M,se,et(q,S=>S===!0),m,f):(nt(!1),Ve(!1)),()=>{Q.current&&(Q.current.abort(),Q.current=null)}},[H,L,Ut,Ht,De,lt,we,Ie,u==null?void 0:u.id]);const qt=e=>{const[o,c]=e;It("all"),fe({startDate:o,endDate:c}),vt(m=>m+1)},ua=e=>{const[o,c]=e;fe({startDate:o,endDate:c})},ut=(e,o)=>{o&&o!==Y&&(ne(0),$(Ka({fixtures:o})))},ga=e=>{we.name!==e&&(Tt(o=>o.some(m=>m.name===e)?o.filter(m=>m.name!==e):[...o,bt.find(m=>m.name===e)]),ne(0),Ge([]),qe(0))},Vt=(e,o)=>{ne(o)},Yt=({target:{value:e}})=>{ze(e),ne(0)},xa=()=>F==null?void 0:F.map((e,o)=>{var c,m,f,_,x,S,D,I,P;return{id:e.id,team:t.jsxs(C,{container:!0,alignItems:"center",gap:2,wrap:"nowrap",width:"150px",children:[t.jsx(C,{children:t.jsx(Pe,{alt:e.team.name.toUpperCase(),src:e.team.logo?`${Oe}/${e.team.logo}
1`:"/",sx:N.avatar,slotProps:{img:{loading:"lazy",decoding:"async"}},children:(c=e.team.name.split(" ").slice(0,2).map(w=>w[0]).join(""))==null?void 0:c.toUpperCase()})}),t.jsx(C,{flex:1,children:t.jsx(Ee,{title:e.team.name,arrow:!0,slotProps:Oo,children:t.jsxs(v,{sx:{...N.typography,overflow:"hidden",overflowWrap:"break-word",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:"2",WebkitBoxOrient:"vertical"},children:[e.team.name," "]})})})]}),opposition:t.jsxs(C,{container:!0,alignItems:"center",gap:2,wrap:"nowrap",children:[t.jsx(C,{children:t.jsx(Pe,{alt:(m=e.opposition)==null?void 0:m.toUpperCase(),src:e!=null&&e.opposition_team_logo?`${Oe}/${e==null?void 0:e.opposition_team_logo}`:"",sx:N.avatar,slotProps:{img:{loading:"lazy",decoding:"async"}},children:(_=(f=e.opposition)==null?void 0:f.split(" ").slice(0,2).map(w=>w[0]).join(""))==null?void 0:_.toUpperCase()})}),t.jsx(C,{flex:1,children:(()=>{const w=oo[e.id];if(!w)return t.jsxs(v,{sx:N.typography,children:[e.opposition," "]});const b=w.noData?t.jsxs(B,{sx:{display:"flex",alignItems:"flex-start",gap:.75,py:.25},children:[t.jsx(Co,{sx:{fontSize:16,mt:"2px",flexShrink:0}}),t.jsx(v,{component:"span",sx:{fontSize:"13px",lineHeight:1.4},children:w.text})]}):t.jsxs(B,{sx:{display:"flex",flexDirection:"column",gap:1,py:.25},children:[w.strength&&t.jsxs(B,{sx:{display:"flex",alignItems:"flex-start",gap:.75},children:[t.jsx(wo,{sx:{fontSize:16,mt:"2px",flexShrink:0,color:"#FFD54F"}}),t.jsx(v,{component:"span",sx:{fontSize:"13px",lineHeight:1.4},children:w.strength})]}),w.improve&&t.jsxs(B,{sx:{display:"flex",alignItems:"flex-start",gap:.75},children:[t.jsx(jo,{sx:{fontSize:16,mt:"2px",flexShrink:0,color:"#90CAF9"}}),t.jsx(v,{component:"span",sx:{fontSize:"13px",lineHeight:1.4},children:w.improve})]})]});return t.jsx(Ee,{title:b,arrow:!0,placement:"top-start",slotProps:Oo,children:t.jsxs(v,{sx:N.typography,children:[e.opposition," "]})})})()})]}),venue:e.venue?t.jsx(Io,{label:e.venue,colorType:e.venue==="Home"?"win":"away"}):t.jsx(v,{children:"-"}),status:e.status?t.jsx(Io,{label:e.status,colorType:e.status.toLowerCase()}):t.jsx(v,{children:"-"}),score:t.jsxs(v,{children:[e.score||"-"," "]}),starPlayer:ye(e.starPlayer)?t.jsx(v,{children:"-"}):t.jsxs(C,{container:!0,gap:2,alignItems:"center",wrap:"nowrap",children:[t.jsx(C,{children:t.jsx(Pe,{sx:N.avatar,alt:(x=e.starPlayer)==null?void 0:x.toUpperCase(),src:"/",children:(D=(S=e.starPlayer)==null?void 0:S.split(" ").slice(0,2).map(w=>w[0]).join(""))==null?void 0:D.toUpperCase()})}),t.jsxs(C,{children:[t.jsxs(v,{sx:N.typography,children:[((I=e==null?void 0:e.player)==null?void 0:I.player_name)||""," "]}),t.jsxs(v,{sx:N.typography,children:[((P=e==null?void 0:e.player)==null?void 0:P.player_surname)||""," "]})]})]}),fixture_date_time:t.jsxs(B,{children:[t.jsx(v,{sx:{...N.typography,fontWeight:600},children:he(e.fixture_date_time)}),t.jsx(v,{sx:{...N.typography,color:"text.secondary"},children:ft(e.fixture_date_time).format("hh:mm A")})]}),report_status:k&&!T?t.jsx(C,{display:"flex",justifyContent:"center",children:t.jsx(B,{sx:{...N.tableIndicator,backgroundColor:w=>_o(w.availability,e.report_status)}})}):t.jsx(C,{display:"flex",justifyContent:"center",children:t.jsx(ln,{showIcon:!1,menuWidth:"40px",iconPadding:!1,selectedMenuItemId:[e.report_status],selectedBackgroundColor:!1,menuCustomStyles:N.btnMenu,buttonCustomStyles:N.btnSelect,anchorOrigin:{vertical:"bottom",horizontal:"center"},onClickBtn:e!=null&&e.result?void 0:w=>{w==null||w.stopPropagation(),Me(o,!1)},menuItems:[{id:1,name:"",indicator:!0,icon:!0,onClick:()=>ao("1",e.id)},{id:2,name:"",indicator:!0,icon:!0,onClick:()=>ao("2",e.id)}],buttonStartIcon:t.jsx(B,{sx:{...N.tableIndicator,backgroundColor:w=>_o(w.availability,e.report_status)}})})})}}),fa=()=>(F==null?void 0:F.map((o,c)=>{const m=!o.result,f=m&&ae(o.fixture_date_time).isSameOrAfter(ae())?ae(o.fixture_date_time).diff(ae(),"days"):null,_=m?f!==null?f===0?"Today":f===1?"Tomorrow":`In ${f} days`:"Pending":null,x=(i==null?void 0:i.color)||"#2F80ED",S=m||o.status==="Draw",D={id:ko(),label:m?_:o.status||"-",colorType:o.status==="Loss"?"red":o.status==="Win"?"green":"blue",...S?{customStyles:{backgroundColor:`${x}1A`,color:x}}:{}},I=o.competition?{id:ko(),label:o.competition,colorType:"gray"}:null;F.filter(E=>E.result).slice(0,5);
1const w=[D,I].filter(Boolean),b=o.status==="Win"?"#22C55E":o.status==="Loss"?"#EF4444":o.status==="Draw"?x:"#637381",A=ae(o.fixture_date_time).isAfter(ae(),"day"),z=m&&!A,U=o.venue==="Home"?"(H)":o.venue==="Away"?"(A)":"",W=`${he(o.fixture_date_time)} @ ${ae(o.fixture_date_time).format("hh:mm A")}${U?` ${U}`:""}`,K=t.jsxs(B,{sx:{textAlign:"center",mt:.5},children:[t.jsx(v,{sx:{fontSize:"12px",color:"text.secondary"},children:W}),t.jsx(B,{sx:{height:"36px",display:"flex",alignItems:"center",justifyContent:"center"},children:z?t.jsx(So,{label:"Add Result",variant:"outlined",size:"small",onClick:E=>{E.stopPropagation(),ht(o)},sx:{fontWeight:600,fontSize:"12px",borderColor:x,color:x,cursor:"pointer","&:hover, &:hover:active":{backgroundColor:`${x} !important`,borderColor:`${x} !important`,color:"#fff !important"}}}):m?t.jsx(v,{sx:{fontSize:"14px",fontWeight:600,color:x},children:"To Be Played"}):t.jsxs(v,{sx:{fontSize:"24px",fontWeight:800,color:b,letterSpacing:"2px"},children:[o.teamScore??0," - ",o.oppTeamScore??0]})})]}),Te=[{heading:"Star Player",text:o.starPlayer||"-"}];return{id:c,primaryAvatarName:o.team.name,primaryAvatar:o.team.logo,secondaryAvatarName:o.opposition,secondaryAvatar:(o==null?void 0:o.opposition_team_logo)||"",primaryText:`${o.team.name} vs ${o.opposition}`,primaryTooltipOverride:(()=>{const E=oo[o.id];return E?E.noData?t.jsxs(B,{sx:{display:"flex",alignItems:"flex-start",gap:.75,py:.25},children:[t.jsx(Co,{sx:{fontSize:16,mt:"2px",flexShrink:0}}),t.jsx(v,{component:"span",sx:{fontSize:"13px",lineHeight:1.4},children:E.text})]}):t.jsxs(B,{sx:{display:"flex",flexDirection:"column",gap:1,py:.25},children:[E.strength&&t.jsxs(B,{sx:{display:"flex",alignItems:"flex-start",gap:.75},children:[t.jsx(wo,{sx:{fontSize:16,mt:"2px",flexShrink:0,color:"#FFD54F"}}),t.jsx(v,{component:"span",sx:{fontSize:"13px",lineHeight:1.4},children:E.strength})]}),E.improve&&t.jsxs(B,{sx:{display:"flex",alignItems:"flex-start",gap:.75},children:[t.jsx(jo,{sx:{fontSize:16,mt:"2px",flexShrink:0,color:"#90CAF9"}}),t.jsx(v,{component:"span",sx:{fontSize:"13px",lineHeight:1.4},children:E.improve})]})]}):null})(),secondaryTextElement:K,status:o.report_status===1?{value:"complete",tooltip:"Fixture review complete"}:{value:"incomplete",tooltip:"Fixture review Incomplete"},handleOnClick:()=>Me(c),chips:w,footer:Te}}))||[],ya=(e,o)=>{_e(e),ue(o)},ba=()=>{_e(null)},Qt=({target:{value:e}})=>{Ve(!0),Sa(e),G(e)},Sa=p.useCallback(Va(e=>{ne(0),Ge([]),qe(0),oe(L,0,e)},1e3),[H,L,we,le.startDate,le.endDate]),$a=e=>{const c=q[e]&&se==="asc"?"desc":"asc";Yo(c),He({...St,[e]:!0}),oe(L,H,M,c,e)},Ye=()=>{tt(!0)},Xt=()=>{tt(!1),$e({}),ue(-1)},Ca=e=>{Mt(e),kt(!0),gt()},Kt=()=>{kt(!1)},Jt=()=>{var b;const{id:e,opposition:o,team:c,surface:m,homeAway:f,fixture_date_time:_,competition:x,Format_id:S,Formation_id:D,coach_ids:I,matchDuration:P,location:w}=F[ee];$e({id:e,opposition:o,team:c.id,surface:((b=Ze.find(A=>A.name===m))==null?void 0:b.id)||"",venue:f,competition:x,format:S,formation:D,dateTime:ft(_).format("MMM DD, YYYY hh:mm a"),coachIds:I||[],matchDuration:P||"",location:w||""}),Ft(!0)},Zt=()=>{Ft(!1),O.length!==1&&ue(-1)},wa=()=>{_t(!0)},gt=()=>{_t(!1)},Qe=async(e,o,c)=>{var _,x,S,D;re(!0),G("");const m={team_ids:e.team,fixture_created_by:n.id?n.id:0,club_id:(n.club_id,n.club_id),season_id:u.id,id:ye(Z)?0:Z.id,homeAway:e.venue||"",venue:e.venue||"",surface:((_=Ze.find(I=>I.id===e.surface))==null?void 0:_.name)||"",competition:e.competition,isUpdated:!ye(Z),opposition:e.opposition,fixture_date_time:new Date(e.dateTime).getTime()||0,location:e.location||"",notificationRecipientIds:c,...e.team.length===1?{Format_id:e.format,Formation_id:e.formation,coach_ids:vo(e.coaches),matchDuration:e.matchDuration||0}:{}},f=await Le({variables:m});if((x=f==null?void 0:f.data)!=null&&x.createFixture){const{success:I,message:P,ids:w}=(S=f==null?void 0:f.data)==null?void 0:S.createFixture;I&&(ge({msg:P||"Fixture created. Add your lineup from the fixture page",variant:"success"}),ne(0),await je.refetchQueries({include:["fixtureListing"]}),await oe(L,0),w.length===1&&r(`/dugout/fixture/${w[0]}?teamId=${(D=e.team)==null?void 0:D[0]}`))}o(),Xt(),re(!1)},ja=async(e,o)=>{if(!u||d){ge({msg:"Please select an active season to create fixtures.",variant:"error",autoHideDuration:3e3});return}if(!ye(Z)){await Qe(e,o,null);return}await Qe(e,o,[])},Fa=async e=>{Pt(!1);const o=Ot,c=Lt;Nt(null),Wt(null),await Qe(o,c,e)},_a=async()=>{Pt(!1);const e=Ot,o=Lt;Nt(null),Wt(null),await Qe(e,o,[])},eo=()=>
1{if(O.length==1){const e=F.find(o=>O.includes(o.id));$e(e),ot(!0)}else ot(!0)},to=()=>{ot(!1),ue(-1),xe({}),$e({})},va=async()=>{re(!0);const e=(O==null?void 0:O.length)>0?O:[F[ee].id],{data:o}=await We({variables:{fixture_ids:e}}),{success:c,message:m}=o.deleteFixtures;c&&(ge({msg:m||"Fixture Deleted",variant:"success"}),oe(L,H,M,se,et(q,f=>f===!0))),to(),re(!1),xe({})},Da=()=>{var b;const{id:e,opposition:o,team:c,surface:m,homeAway:f,fixture_date_time:_,competition:x,Format_id:S,Formation_id:D,coach_ids:I,matchDuration:P,location:w}=F[ee];$e({id:e,opposition:o,team:c.id,surface:((b=Ze.find(A=>A.name===m))==null?void 0:b.id)||"",venue:f,competition:x,format:S,formation:D,dateTime:ft(_).format("MMM DD, YYYY hh:mm a"),coachIds:I||[],matchDuration:P||"",location:w||""}),tt(!0)},Me=(e,o=!0)=>{var m,f;const c=F[e];r(o?`/dugout/fixture/${c.id}?teamId=${(m=c.team)==null?void 0:m.id}`:`/dugout/fixture/${c.id}?teamId=${(f=c.team)==null?void 0:f.id}&result=${o}`)},Xe=p.useMemo(()=>{var x,S,D,I,P,w;if(!(F!=null&&F.length))return[];const e=[],o=Date.now(),c=F.filter(b=>b.result),m=F.filter(b=>!b.result&&Number(b.fixture_date_time)>o);if(c.length>0){const A=[...c].sort((j,J)=>Number(j.fixture_date_time)-Number(J.fixture_date_time)).slice(-6),z=[...new Set(A.map(j=>{var J;return(J=j.team)==null?void 0:J.name}).filter(Boolean))],U=z.length===1?`${z[0]} â `:"",W=A.map(j=>{const J=j.result===1?"W":j.result===2?"L":"D",Ke=`${j.teamScore||0}-${j.oppTeamScore||0}`;return`${J} ${Ke} vs ${j.opposition||"TBC"}`}),K=A.map(j=>j.result===1?"W":j.result===2?"L":"D").join(""),Te=A.reduce((j,J)=>j+(J.result===1?3:J.result===3?1:0),0),E=A.filter(j=>j.result===1).length,pe=A.filter(j=>j.result===3).length,Ae=A.filter(j=>j.result===2).length;e.push({key:"form",label:`Form: ${U}${K} (W${E} D${pe} L${Ae} · ${Te}pts from ${A.length})`,fixtureId:null,teamId:null,color:"#F9A825",bg:"#FFF8E1",tooltipLines:W})}if(m.length>0){const A=[...m].sort((z,U)=>Number(z.fixture_date_time)-Number(U.fixture_date_time))[0];e.push({key:"nextFixture",label:`Next: ${(x=A.team)!=null&&x.name?`${A.team.name} `:""}vs ${A.opposition||"TBC"} · ${ae(Number(A.fixture_date_time)).format("ddd D MMM, h:mma")}`,fixtureId:A.id,teamId:(S=A.team)==null?void 0:S.id,color:"#2E7D32",bg:"#E8F5E9"})}const f=c.filter(b=>b.result===1);if(f.length>0){const b=[...f].sort((z,U)=>{const W=(U.teamScore||0)-(U.oppTeamScore||0),K=(z.teamScore||0)-(z.oppTeamScore||0);return W-K})[0];(b.teamScore||0)-(b.oppTeamScore||0)>0&&e.push({key:"biggestWin",label:`Biggest Win: ${(D=b.team)!=null&&D.name?`${b.team.name} `:""}vs ${b.opposition} (${b.teamScore}-${b.oppTeamScore})`,fixtureId:b.id,teamId:(I=b.team)==null?void 0:I.id,color:"#2E7D32",bg:"#E8F5E914"})}const _=c.filter(b=>(b.oppTeamScore||0)===0);if(_.length>0&&e.push({key:"cleanSheets",label:`Clean Sheets: ${_.length}`,fixtureId:null,teamId:null,color:"#1E88E5",bg:"#E3F2FD"}),c.length>0){const b=[...c].sort((z,U)=>{const W=(U.teamScore||0)+(U.oppTeamScore||0),K=(z.teamScore||0)+(z.oppTeamScore||0);return W-K})[0];(b.teamScore||0)+(b.oppTeamScore||0)>0&&e.push({key:"topScoring",label:`Top Scoring: ${(P=b.team)!=null&&P.name?`${b.team.name} `:""}vs ${b.opposition} (${b.teamScore}-${b.oppTeamScore})`,fixtureId:b.id,teamId:(w=b.team)==null?void 0:w.id,color:"#E53935",bg:"#FFEBEE"})}return e},[F]),oo=p.useMemo(()=>{if(!(F!=null&&F.length))return{};const e={};for(const o of F){const f=[...F.filter(_=>{var x,S;return((x=_.team)==null?void 0:x.id)===((S=o.team)==null?void 0:S.id)&&_.id!==o.id&&_.result})].sort((_,x)=>Number(_.fixture_date_time)-Number(x.fixture_date_time)).slice(-5).map(_=>_.result);e[o.id]=Qn(o,f)}return e},[F]),Ia=async(e,o)=>{var S,D,I,P;re(!0);const c={fixture_ids:[e.id],team_ids:e.team,home_away:e.venue||"",venue:e.venue||"",surface:((S=Ze.find(w=>w.id===e.surface))==null?void 0:S.name)||"",competition:e.competition,opposition:e.opposition,fixture_date_time:new Date(e.dateTime).getTime(),location:e.location||"",...((D=e==null?void 0:e.team)==null?void 0:D.length)===1?{format_id:e.format,formation_id:e.formation,coach_ids:vo(e.coaches),match_duration:e.matchDuration||0}:{}},m=await Fe({variables:c}),{success:f,message:_,data:x}=(I=m==null?void 0:m.data)==null?void 0:I.duplicateFixture;f&&(x.length===1&&r(`/dugout/fixture/${x==null?void 0:x[0]}?teamId=${(P=c.team_ids)==null?void 0:P[0]}`),ge({msg:_||"Fixture Created",variant:"success"}),oe(L,0)),o(),xe({}),re(!1),Zt()},ka=async()=>{var f;re(!0);const e={team_ids:na.teams,fixture_ids:O},o=await Fe({variables:e}),{success:c,message:m}=(f=o==null?void 0:o.data)==null?void 0:f.duplicateFixture;c&&(ge({msg:m||"Fixture Created",variant:"success"}),oe(L,0)),xe({}),re(!1),Kt(),Mt({}),gt()},ao=async(e,o)=>{var f;const c=await ea({variables:{id:+o,report_status:+e}}),{success:m}=(f=c==null?void 0:c.data)==null?void 0:f.updateFixture;m&&(ge({msg:"Fixture status updated successfully..",variant:"success"}),oe(L,H,M,se,et(q,_=>_===!0)))},no=({target:{value:e}})=>{switch(e){case"upcoming":fe({startDate:he(new Date),endDate:""});break;case"past":fe({startDate:"",endDate:he(new Date)});break;default:fe($t(u,i));break}Dt("Default Range"),Et(o=>[...o.filter(c=>c.type!=="radio"),{name:"default",type:"radio"}]),It(e),xe({})},Ma=e=>{const o=Ja(e);if(o.length===1){const c=F.findIndex(m=>m.id===+o[0]);ue(c)}else ue(-1);xe(e)},Ta=()=>{He(St),oe(L,H,M,"asc",void 0)},Aa=()=>{const e=!d&&!V,o=O.length>0;return t.jsxs(C,{container:!0,gap:1,flexWrap:"nowrap",children:[X.add===be.YES&&t.jsx(Be,{variant:"outlined",text:y?"Duplicate":"Duplicate Fixtures",customStyles:N.duplicateBtn,disabled:!e||!o,onClick:O.length===1?Jt:wa}),X.delete===be.YES&&t.jsx(Be,{variant:"outlined",text:y?"Delete":"Delete Fixtures",customStyles:N.deleteBtn,disabled:!e||!o,onClick:eo})]})},Ea=e=>{la(o=>o.value===e?{value:e,order:o.order==="ASC"?"DESC":"ASC"}:{value:e,order:"DESC"})},xt=()=>{mt(null)},Ba=async()=>{xt();try{const o=await(await fetch(an)).blob(),c=URL.createObjectURL(o),m=document.createElement("a");m.href=c,m.download="touchtight-fixtures-template.xlsx",document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(c)}catch(e){console.error(e),ge({msg:"Could not download the template. Please try again.",variant:"error"})}},Ra=()=>{xt(),Bt(!0)},Pa=()=>{Bt(!1)},so=async()=>{await oe(L,H,M,se,et(q,e=>e===!0))},Oa=(e,o,c)=>{var _;const m=To.find(x=>x.key===e),f=m.type==="radio"?[...ke.filter(S=>S.type!=="radio"),{name:o,type:"radio"}]:ke.some(S=>S.name===o&&S.type==="checkbox")?ke.filter(S=>!(S.name===o&&S.type==="checkbox")):[...ke,{name:o,type:"checkbox"}];
1switch(Et(f),e){case"date":{if(c==="default"){const x=$t(u,i);fe({startDate:x.startDate,endDate:x.endDate}),vt(0)}else qt(Za(c));break}case"status":{const x=f.some(I=>I.name==="upcoming"),S=f.some(I=>I.name==="past"),D=x&&S?"all":((_=f.find(I=>I.name==="upcoming"||I.name==="past"))==null?void 0:_.name)||"all";no({target:{value:D}});break}default:{Tt(x=>x.some(D=>D.name===o)?x.filter(D=>D.name!==o):[...x,bt.find(D=>D.name===o)]);break}}};return t.jsxs(t.Fragment,{children:[t.jsxs(C,{container:!0,direction:"column",sx:N.container,flexWrap:"nowrap",children:[t.jsx(C,{children:t.jsx(wn,{title:s("fixture.fixtures"),primaryBtnText:"Add Fixture",showPrimaryBtn:y?!1:X.add===be.YES&&(!k||T),secondaryBtnText:"Import / Export",showSecondaryBtn:!y&&zt,secondaryBtnHandler:e=>{mt(e.currentTarget)},primaryBtnIcon:t.jsx(yt,{}),primaryBtnHandler:Ye})}),X&&t.jsx(Dn,{id:"fixtures-lineup-tip",message:"Tap a fixture to manage lineup and availability",sx:{mx:{xs:"6px",sm:2},mt:1}}),y?t.jsxs(t.Fragment,{children:[t.jsx(_n,{search:M,view:Y,primaryBtnText:"Add Fixture",showImportAndExportBtn:zt,handleChangeSearch:Qt,handleChangeView:ut,primaryBtnHandler:Ye,showPrimaryBtn:X.add===be.YES&&(!k||T),handleOpenFilterMenu:e=>dt(e.currentTarget),handleOpenSortMenu:e=>pt(e.currentTarget),handleOpenExportAndImportMenu:e=>{mt(e.currentTarget)}}),t.jsx(C,{container:!0,sx:{px:2,pt:2,pb:1},alignItems:"center",children:t.jsx(C,{sx:{width:"100%"},children:t.jsx(Se,{multiple:!0,name:"fixtureCoachFilter",placeholder:"Coach Assigned",options:ce.map(e=>({id:String(e.id),name:[e.username,e.lastname].filter(Boolean).join(" ").trim()||`User ${e.id}`})).sort((e,o)=>e.id===String(n==null?void 0:n.id)?-1:o.id===String(n==null?void 0:n.id)?1:0),value:ie.map(String),onChange:({target:{value:e}})=>ct(e.map(o=>parseInt(o,10))),showAvatarValue:!1,size:"small",customStyle:{width:"100%"}})})})]}):t.jsx(C,{children:t.jsxs(C,{container:!0,flexDirection:{xs:"column",md:"row"},sx:N.searchContainer,gap:1,children:[t.jsxs(C,{container:!0,flex:1,gap:1,flexWrap:"nowrap",children:[t.jsx(Cn,{onChange:Qt,value:M,customStyles:N.searchCustomStyles}),t.jsx(Bo,{value:Y,handleChange:ut,iconHeight:16,iconWidth:16,customStyles:{borderRadius:"8px",height:"32px",padding:"2px",display:{xs:"block",md:"none"},"& .MuiToggleButtonGroup-root":{height:"100%"},"& .MuiToggleButtonGroup-root .MuiButtonBase-root":{height:"100%"}}})]}),t.jsx(C,{children:t.jsxs(C,{container:!0,flexDirection:{xs:"column",md:"row"},gap:{xs:"10px",md:1},children:[t.jsx(C,{children:t.jsx(nn,{value:[le.startDate,le.endDate],onChange:qt,onSeasonReset:ua,selectedRange:oa,setSelectedRange:Dt})}),t.jsx(C,{children:t.jsx(Se,{optionKey:"name",placeholder:"Status",name:"Status",value:De,onChange:no,options:Mo,isShowClearable:!1,size:"small",customStyle:{minWidth:{xs:"100%",md:"120px"}}})})]})}),t.jsx(C,{sx:{display:{xs:"none",md:"block"}},children:t.jsx(Bo,{value:Y,handleChange:ut,iconHeight:16,iconWidth:16,customStyles:{borderRadius:"8px",height:"32px",padding:"2px","& .MuiToggleButtonGroup-root":{height:"100%"},"& .MuiToggleButtonGroup-root .MuiButtonBase-root":{height:"100%"}}})})]})}),!y&&t.jsxs(C,{container:!0,alignItems:"center",pr:3,flexWrap:{xs:"wrap",md:"nowrap"},gap:1,sx:{borderBottom:e=>`1px solid ${e.border}`},children:[t.jsx(C,{flex:1,minWidth:0,children:t.jsx(Sn,{titleKey:"displayName",isMultiSelect:!0,showDateRange:!1,disableBorderBottom:!0,selectedFilterChip:we.map(e=>e.name),filters:bt.slice(0,6),handleChangeFilterChip:ga})}),t.jsx(C,{sx:{flexShrink:0,width:{xs:"100%",md:180},py:1.5},children:t.jsx(Se,{multiple:!0,name:"fixtureCoachFilter",placeholder:"Coach Assigned",options:ce.map(e=>({id:String(e.id),name:[e.username,e.lastname].filter(Boolean).join(" ").trim()||`User ${e.id}`})).sort((e,o)=>e.id===String(n==null?void 0:n.id)?-1:o.id===String(n==null?void 0:n.id)?1:0),value:ie.map(String),onChange:({target:{value:e}})=>ct(e.map(o=>parseInt(o,10))),showAvatarValue:!1,size:"small",customStyle:{width:"100%"}})}),Y==="list"?t.jsx(C,{children:t.jsx(Be,{text:"clear sort",customStyles:{padding:"5px 12px",fontSize:"14px"},disabled:!Bn(q,e=>e===!0),onClick:Ta})}):t.jsxs(C,{container:!0,gap:.5,alignItems:"center",children:[t.jsx(Ee,{title:"Sort",children:t.jsx(bo,{onClick:e=>pt(e.currentTarget),size:"small",children:t.jsx(Wa,{})})}),t.jsx(Ee,{title:"Filter",children:t.jsx(bo,{onClick:e=>dt(e.currentTarget),size:"small",children:t.jsx(za,{})})})]})]}),(O==null?void 0:O.length)>0&&t.jsx(sn,{items:O,title:s("fixture.fixtures"),rightElement:Aa()}),Xe.length>0&&!at&&t.jsx(B,{sx:{display:"flex",gap:1,px:2,py:{xs:1,sm:1.5},overflowX:"auto",flexShrink:0,backgroundColor:"common.white",position:"relative",zIndex:1,"&::-webkit-scrollbar":{display:"none"},scrollbarWidth:"none"},children:Xe.map(e=>{const o=t.jsx(So,{label:e.label,onClick:e.fixtureId?()=>r(`/dugout/fixture/${e.fixtureId}?teamId=${e.teamId}`):void 0,sx:{height:32,borderRadius:"16px",fontSize:"12px",fontWeight:600,backgroundColor:e.bg,border:"1px solid",borderColor:`${e.color}40`,color:e.color,cursor:e.fixtureId?"pointer":"default",flexShrink:0,"& .MuiChip-label":{color:"text.primary"},...e.fixtureId&&{"&:hover":{backgroundColor:`${e.color}30`,borderColor:e.color,boxShadow:`0 0 0 1px ${e.color}40`}}}},e.key);return e.tooltipLines?t.jsx(Ee,{title:e.tooltipLines.map((c,m)=>t.jsx("div",{children:c},m)),arrow:!0,placement:"bottom",children:o},e.key):o})}),t.jsx(C,{flex:"1",sx:{height:{xs:"unset",md:Y==="gird"?"unset":ye(it)?`calc(100% - ${295+(Xe.length>0?56:0)}px)`:`calc(100% - ${365+(Xe.length>0?56:0)}px)`}},children:at?t.jsx(Ya,{}):Y==="list"?t.jsx(rn,{isSelectable:!d&&!V&&(X.delete!==be.NO||X.add!==be.NO),selected:it,setSelected:Ma,tableBorders:!0,isRowClickable:!0,tableStickyPagination:!0,tableStickyColumn:!0,page:H,count:jt,setAnchorEl:ya,c
1anEdit:!O.length,sortOrder:se,sort:q,sortHandler:$a,rowsPerPage:L,headCells:a.map(e=>({...e,sort:y?!1:e.sort})),handleChangePage:Vt,handleChangeRowsPerPage:Yt,handleRowClick:e=>Me(e),data:xa(),emptyContentTitle:"No Fixtures Found",emptyContentDescription:M?"No fixtures match your search. Try a different search term.":"Schedule your first fixture to start tracking match results.",emptyContentAction:M?null:t.jsx(Be,{text:"Add Fixture",startIcon:t.jsx(yt,{}),onClick:Ye})}):t.jsx($n,{page:H,cards:fa(),loading:at,count:jt,rowsPerPage:L,handleChangePage:Vt,handleChangeRowsPerPage:Yt,emptyContentTitle:"No Fixtures Found",emptyContentDescription:M?"No fixtures match your search. Try a different search term.":"Schedule your first fixture to start tracking match results.",emptyContentAction:M?null:t.jsx(Be,{text:"Add Fixture",startIcon:t.jsx(yt,{}),onClick:Ye})})})]}),t.jsx(Eo,{width:"180px",itemHeight:"58px",itemPadding:"22px 24px",items:Qa(d||V?[{name:"View",icon:$o,iconCustomStyles:{width:"20px",height:"20px"},onClick:()=>Me(ee)}]:[{name:"View",icon:$o,iconCustomStyles:{width:"20px",height:"20px"},onClick:()=>Me(ee)},...!((po=F==null?void 0:F[ee])!=null&&po.result)&&!ae((mo=F==null?void 0:F[ee])==null?void 0:mo.fixture_date_time).isAfter(ae(),"day")?[{name:"Quick Score",icon:Ua,iconCustomStyles:{width:"20px",height:"20px"},onClick:()=>ht(F[ee])}]:[],{name:"Manage",icon:en,onClick:Da},{name:"Duplicate",icon:tn,onClick:()=>Jt()},{name:"Delete",icon:on,onClick:eo}],X),enableDividers:!1,anchorEl:Ue,handleClose:ba}),t.jsx(Mn,{open:Qo,actionBtnTitle:ye(Z)?"Save Fixture":"Update Fixture",handleClose:Xt,teamOptions:st,handleSubmitFixture:ja,loading:ve,selectedFixture:Z,isUpdated:!ye(Z)}),t.jsx(Wn,{open:pa,loading:ha,recipients:ma,onConfirm:Fa,onSkip:_a,creating:ve}),t.jsx(Tn,{loading:ve,teamOptions:st,open:Xo,handleDuplicateFixture:Ia,handleClose:Zt,selectedFixture:Z}),t.jsx(Ln,{open:Ko,handleClose:gt,selectedFixtureIds:O,teamOptions:st,handleDuplicateFixture:Ca}),t.jsx(yn,{handleClose:to,open:Jo,handleDelete:va,title:"Delete Fixture?",actionBtnTitle:"Delete Fixture",entityName:(O==null?void 0:O.length)<2?`${((ho=Z==null?void 0:Z.team)==null?void 0:ho.name)||((go=(uo=F[ee])==null?void 0:uo.team)==null?void 0:go.name)} vs ${(xo=F[ee])==null?void 0:xo.opposition}`:"Fixtures",loading:ve}),t.jsx(jn,{title:"Confirm Duplication",loading:ve,description:"Are you sure you want to duplicate the fixtures for selected team(s)? This action cannot be undone.",open:aa,handleClose:Kt,actionHandler:ka}),t.jsx(Eo,{width:"180px",items:[{name:"Download Template",onClick:Ba},...k?[]:[{name:"Import Fixtures",onClick:Ra}]],anchorEl:da,enableDividers:!1,handleClose:xt}),t.jsx(An,{open:ca,handleCloseModal:Pa,refetchFixtureList:so,fixturePermissions:X}),t.jsx(zn,{open:!!Rt,handleClose:()=>ht(null),fixture:Rt,onSuccess:so}
1),t.jsx(Fn,{sortMenuAnchor:ra,menuItems:un,sort:Ie,handleChangeSortBy:Ea,setSortMenuAnchor:pt}),t.jsx(vn,{gridSize:6,menuData:To,selected:ke.map(e=>e.name),anchorEl:At,open:!!At,handleSelectMenu:Oa,onClose:()=>dt(null)})]})};export{ii as Fixtures,ii 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.