1import{j as a,r as d,aM as k,bj as z,bc as A,aY as V,h as E,aD as x,aC as h}from"./vendor-D7sP4EZJ.js";import{B}from"./MainMenu-CsK5RHuw.js";import{C as M}from"./ConfirmDialog-CmY8KMS5.js";import{M as L}from"./index-BZxi0YQ4.js";import{A as O}from"./Alert-D23B6COt.js";import{C as Y}from"./BaseModal-BHYwYBHz.js";import{F as W}from"./Form-pPSRkN2m.js";import{I as D}from"./Input-BtexvFaC.js";import{W as G}from"./weekdays-OAkTgpls.js";import{S as b}from"./Select-VKcV5r-T.js";import{g as Q}from"./getFormUtils-BOGtiGj-.js";import{S as q}from"./SelectFlights-BQ6VCTaK.js";import{v as H}from"./match-weeks-templates-_kwAn8MK.js";import{I as R}from"./IconButton-DhZu8wMO.js";import{F as U,g as $}from"./table-fuzzy-sort-CjLIV1Nx.js";import{B as K}from"./Badge-B4FHhwNL.js";import{f as P}from"./formatDivisionStatus-DYFMpA1Q.js";import{d as J,c as X}from"./lodash-Cu4MISdH.js";import{I as Z,D as ee}from"./update-division-mutation-CL3sHGiG.js";import{E as p}from"./gql-BVT0OZVb.js";import"./dynamic-object-helper-BH-O6lvi.js";import"./flights-ghoAesaS.js";import"./game-type-enum-LVdcLwUQ.js";import"./LinkButton-B-9LZl-0.js";import"./date-helper-UxJ3bhcm.js";import"./useDebounce-DbwOX8K0.js";import"./Table-DDCVu7WD.js";function te(e,s){const o=J(e,["__typename","league","matches","league_teams"]);return e.id?o:{...o,league_id:s,...e?.league_teams?{league_team_divisions:{data:e.league_teams?.map((i,n)=>({league_team_id:i.id,slot:typeof i.slot>"u"?n:i.slot})),on_conflict:{constraint:"league_team_division_pkey",update_columns:["division_id","league_team_id"]}}}:{}}}const ae=e=>a.jsx(b,{...e,options:G}),se=[4,5,6,8],ie=({activeWeeksCount:e,disabled:s,error:o,...i})=>{const n=se.filter(r=>H(r,e).isValid),t=n.length===0;return a.jsx(b,{...i,options:n.map(r=>({key:r,label:`${r} Teams`})),error:t?`No team-count options are available for ${e} active weeks.`:o,disabled:s||t})},oe=({value:e,activeWeeksCount:s,validate:o,disabled:i,onChange:n})=>{const{handleFormChanges:t,requiredField:r}=Q({value:e,validate:o,onChange:n});return a.jsx(W,{children:a.jsxs("div",{className:"mb-10",children:[a.jsx(D,{label:"Name",value:e?.name,onChange:l=>t("name",l.target.value),error:r("name"),disabled:i}),a.jsx(q,{label:"Flight",value:e?.flight||"",onChange:l=>t("flight",l.target.value),error:r("flight"),disabled:i}),a.jsx(ae,{label:"Match Day",value:e?.match_week_day||"",onChange:l=>t("match_week_day",l.target.value),error:r("match_week_day"),disabled:i}),a.jsx(D,{type:"time",label:"Start Time",value:e?.start_time,onChange:l=>t("start_time",l.target.value),error:r("start_time"),disabled:i}),a.jsx(ie,{label:"Number of teams",activeWeeksCount:s,value:e?.number_of_teams||"",onChange:l=>t("number_of_teams",l.target.value),error:r("number_of_teams"),disabled:i})]})})},re={pending:"secondary",in_progress:"primary",completed:"primary"},ne=({status:e})=>a.jsx(K,{variant:re[e],children:P(e)}),u=$(),c=V(),le=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],C=e=>e?le.indexOf(e):-1,me=(e,s,o)=>{const i=e.getValue(o),n=s.getValue(o);return C(i)-C(n)},ce=({onRemove:e,loading:s=!1,divisions:o=[],hideActions:i=!1})=>{const n=d.useMemo(()=>X([c.accessor("name",{id:"name",header:"Division",footer:t=>t.column.id,filterFn:"fuzzy",sortingFn:u,meta:{includeInCsv:!0}}),c.accessor("number_of_teams",{id:"number_of_teams",header:"Number of teams",cell:t=>`${t.getValue()} Teams`,footer:t=>t.column.id,filterFn:"fuzzy",sortingFn:u,meta:{includeInCsv:!0}}),c.accessor("match_week_day",{id:"match_week_day",header:"Day",cell:t=>t.getValue()?.slice(0,3).toUpperCase(),footer:t=>t.column.id,filterFn:"fuzzy",sortingFn:me,meta:{includeInCsv:!0}}),c.accessor("start_time",{id:"startDate",header:"Time",cell:t=>{const r=t.getValue();return r&&k(z(r,"H:mm",new Date),"h:mm a")},footer:t=>t.column.id,filterFn:"fuzzy",sortingFn:"datetime",meta:{includeInCsv:!0}}),c.accessor("flight",{id:"flight",header:"Flight",footer:t=>t.column.id,filterFn:"fuzzy",sortingFn:u,meta:{includeInCsv:!0}}),c.accessor("status",{id:"status",header:"Status",cell:t=>a.jsx(ne,{status:t.getValue()||"pending"}),footer:t=>t.column.id,filterFn:"fuzzy",sortingFn:u,meta:{includeInCsv:!0}}),!i&&c.display({id:"actions",cell:t=>a.jsx(R,{danger:!0,onClick:()=>e?.(t.row.original.id),iconPath:A})})]),[i,e]);return a.jsx(U,{hideActions:!0,data:o,columns:n,loading:s,tableKey:"league_divisions"})};function de(e){const s=[];return e.name||s.push("You need to fill a name for the division"),e.flight||s.push("You need to set a flight for the division"),e.match_week_day||s.push("You need to set a match day for the division"),e.start_time||s.push("You need to set a start time for the division"),{isValid:!s.length,errors:s}}const j=()=>({start_time:"12:00"}),Oe=({league:e,disabled:s})=>
1{const[o,i]=d.useState(j()),[n,t]=d.useState(!1),{openModal:r}=d.useContext(L),[l,v]=d.useState(!1),f=e?.id,{data:F,loading:g}=E(p,{variables:f!=null?{league_id:f}:void 0,skip:f==null}),_=m=>{m.evict({id:m.identify(e)})},[S]=x(Z,{update:_}),[w]=x(ee,{refetchQueries:[{query:p,variables:{league_id:e.id}},"GetLeagueTeamsByLeagueId"],update:_}),y=F?.divisions||[];async function I(){v(!0);const{isValid:m,errors:N}=de(o);if(!m){h(N[0]);return}t(!0),await S({refetchQueries:[{query:p,variables:{league_id:e.id}}],variables:{payload:te(o,e.id)}}),v(!1),t(!1),i(j())}function T(m){r({content:a.jsx(M,{title:"Confirm action",text:"Are you sure you want to remove the division? This will remove all matches, including in progress and completed.",onConfirm:async()=>{try{await w({variables:{id:m}}),h("Division has been removed successfully")}catch{h("Division cannot be removed, try again later")}}})})}return a.jsxs("div",{children:[s&&a.jsx(O,{type:"warning",message:"The add/remove divisions feature is not accessible after the start of league play."}),a.jsxs("div",{className:"flex flex-row",children:[a.jsx("div",{className:"flex-grow",children:a.jsx("h2",{children:"Add Divisions"})}),a.jsx("div",{children:a.jsxs("span",{className:"text-gray-500 text-sm",children:["Total Divisions: ",y?.length||0]})})]}),a.jsxs("div",{className:"flex flex-row gap-8",children:[a.jsx("div",{className:"w-4/12",children:a.jsxs(Y,{children:[a.jsx(oe,{value:o,activeWeeksCount:e.league_active_weeks?.length??0,validate:l,disabled:g||n||s,onChange:m=>i(m)}),a.jsx(B,{disabled:g||n||s,primary:!0,label:"Add",onClick:()=>I()})]})}),a.jsx("div",{className:"flex-grow",children:a.jsx(ce,{divisions:y,onRemove:T,loading:g,hideActions:s})})]})]})};export{Oe 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.