1import{G as X}from"./PhArrowLeft.vue-DzABxcBw.js";import{d as Z,E as ee,T as ae,i as te,D,j as se,A as n,f as o,av as y,as as re,x as oe,G as ie,Y as le,B as ne,r as ce,o as L,g as de,w as R,a as c,b as i,u as x,aW as ue,e as P,t as d,c as k,F as me,k as pe,p as U,ad as G,a0 as ve,ac as fe}from"./index-BRlEgfCl.js";import{u as he}from"./LocaleSwitcher.vue_vue_type_script_setup_true_lang-BYWN_9xX.js";import{u as Le}from"./loading-CkBk-9qr.js";import{t as _e}from"./toComputed-Cx5bW2CU.js";import{_ as ye}from"./Layout.vue_vue_type_script_setup_true_lang-Dmg5kEs8.js";import{M as g,a as Re,b as ke,c as be,d as we,e as Ie,_ as xe}from"./LockBadge.vue_vue_type_script_setup_true_lang-DzCoEhc3.js";import{_ as Pe}from"./ResultsMatchDetailHeader.vue_vue_type_script_setup_true_lang-jdlKHz04.js";import"./Logo.vue_vue_type_script_setup_true_lang-BwpF6QV6.js";import"./humanOrderBy-B_s4SR3K.js";import"./CountryFlag-DKg-XIs5.js";import"./RouterLinkWithDisable-Cpg1WGLd.js";import"./useMatch-CqqRs247.js";import"./dateTime-HpcSVMQW.js";const ge={class:"page-container flex-col flex gap-y-4 !max-w-[900px]"},Ce={class:"text-4xl font-bold font-bebas_neue uppercase"},$e={class:"mb-4"},Se={class:"mb-4 text-sm whitespace-pre-line"},Ve={key:0,class:"text-red-500 font-bold mb-4"},Me={key:0,class:"text-black"},Ae={class:"flex flex-wrap flex-col md:flex-row gap-2"},Ke=Z({__name:"MatchRosterPage",setup(Be){const{isLoading:W,wrapWithLoader:b}=Le(),C=ee(),w=ae(),{t:$}=te(),{matchesById:j}=_e(D()),{teamsById:H}=se(),Y=D(),h=n([]),S=n(new g),u=n(new Set),m=n(new Set),V=n(new Re),l=n({isValid:!0,errors:[]}),{parseException:q}=he(),p=o(()=>{var a;const t=C.params.id;return(a=Y.matchesByCategoryAndMatchNumber[t])==null?void 0:a.id}),M=o(()=>j.value[p.value]),I=o(()=>C.params.side),v=o(()=>I.value==="home"?M.value.homeTeamId:I.value==="away"?M.value.awayTeamId:void 0),J=o(()=>H[v.value]),A=n(),B=o(()=>{var t,a;return((a=(t=A.value)==null?void 0:t.rosterLock)==null?void 0:a[I.value])??!1}),E=o(()=>[y.competitionReporter,y.competitionSuperReporter,y.admin,y.superAdmin].some(t=>re().hasRole(t))),f=o(()=>E.value?!1:B.value??!1),T=b(async()=>{const t=await ke({params:{teamId:`${v.value}`,matchId:`${p.value}`}});h.value=t.teamRoster,A.value=t.meta,u.value.clear(),m.value.clear();const a=h.value.filter(e=>e.status!=="cannot_play").map(e=>e.matchParticipant);a.filter(e=>e.participant.isPlayer).forEach(e=>{e.isPlayer&&u.value.add(e.participant.id)}),a.filter(e=>e.participant.isLeader).forEach(e=>{e.isLeader&&m.value.add(e.participant.id)}),u.value.size===0&&a.filter(e=>e.participant.isPlayer).forEach(e=>{e.hasPlayedPreviousMatchAsPlayer&&u.value.add(e.participant.id)}),m.value.size===0&&a.filter(e=>e.participant.isLeader).forEach(e=>{e.hasPlayedPreviousMatchAsLeader&&m.value.add(e.participant.id)}),S.value=new g}),K=b(async()=>{V.value=await be()}),N=b(async({lock:t})=>{const a=new g;a.matchId=p.value,a.teamId=v.value,h.value[0].matchParticipant.participant.isLeader;const e=oe(()=>ie(h.value,r=>r.matchParticipant),r=>{for(const s of r)s.isPlayer=u.value.has(s.participant.id),s.isLeader=m.value.has(s.participant.id);return r},r=>r.filter(s=>s.isPlayer||s.isLeader))();a.teamRoster=e,a.lock=t;try{await we({input:a}),await T(),w.toast($("rosters.matchRoster.toast.saved"))}catch(r){const{message:s}=q(r);w.toast(s,{type:le.error})}});async function O(){await N({lock:!1})}async function Q(){(E.value||await w.confirm($("rosters.matchRoster.modal.saveAndLock"),{alwaysResolve:!1}))&&await N({lock:!0})}return ne(()=>[v.value,p.value],()=>{!v.value||!p.value||Promise.all([T(),K()])},{immediate:!0}),(t,a)=>{const e=ce("router-link");return L(),de(ye,null,{default:R(()=>{var r,s,F,z;return[c("div",ge,[i(e,{to:{name:x(ue).teamPlan,params:{id:v.value}},class:"link inline-flex items-center gap-2 mb-3",replace:""},{default:R(()=>[i(x(X)),P(" "+d(t.$t("rosters.matchRoster.backButton")),1)]),_:1},8,["to"]),i(Pe,{matchId:p.value},null,8,["matchId"]),a[1]||(a[1]=c("hr",{class:"mb-4"},null,-1)),c("div",null,[c("h1",Ce,d(t.$t("rosters.matchRoster.title",{clubName:J.value.clubName})),1),c("div",$e,[i(Ie,{hasRoster:B.value,class:"text-sm"},null,8,["hasRoster"])]),c("p",Se,d(t.$t("rosters.matchRoster.instructions")),1),i(xe,{val
1idations:l.value,"onUpdate:validations":a[0]||(a[0]=_=>l.value=_),class:"mb-8",isLocked:f.value,candidates:h.value,selectedPlayerIds:u.value,selectedLeaderIds:m.value,roster:S.value,rosterLimits:V.value},null,8,["validations","isLocked","candidates","selectedPlayerIds","selectedLeaderIds","roster","rosterLimits"]),!((r=l.value)!=null&&r.isValid)||f.value?(L(),k("ul",Ve,[(L(!0),k(me,null,pe(l.value.errors,_=>(L(),k("li",{key:_},d(_),1))),128)),f.value?(L(),k("li",Me,d(t.$t("rosters.matchRoster.errors.isLocked")),1)):U("",!0)])):U("",!0),c("div",Ae,[i(G,{disabled:!((s=l.value)!=null&&s.isValid)||f.value,class:"btn btn-white flex-1 md:flex-none",onClick:O},{default:R(()=>[P(d(t.$t("rosters.matchRoster.actions.save")),1)]),_:1},8,["disabled"]),i(G,{class:ve(["btn btn-primary flex-1 md:flex-none",{"opacity-50":!((F=l.value)!=null&&F.isValid)||f.value}]),disabled:!((z=l.value)!=null&&z.isValid)||f.value,onClick:Q},{default:R(()=>[P(d(t.$t("rosters.matchRoster.actions.saveAndLock")),1)]),_:1},8,["class","disabled"])])])]),i(fe,{isLoading:x(W)},null,8,["isLoading"])]}),_:1})}}});
1export{Ke 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.