1import{r as t,c as i,h as e}from"./p-CLQce7zD.js";import{m as s,a}from"./p-YZTT4Nu5.js";import{W as n,I as o,i as l,p as h}from"./p-BStZpeKB.js";import{P as r}from"./p-D0wAz_bu.js";import"./p-AuPLCHfl.js";import"./p-E-ZsRS8r.js";const c=class{constructor(e){t(this,e),this.competitionGroupListUpdated=i(this,"competitionGroupListUpdated",7),this.updateGroup=i(this,"updateGroup",7),this.updatedCompetitionTeam=i(this,"updatedCompetitionTeam",7),this.entityLabel="Team",this.searchPrompt="Search for a team",this.modalTitle="Add",this.editNameHeader="Edit team name",this.editNameMessage="Enter new team name for",this.editNameLabel="New team name",this.cancelPrompt="Cancel",this.updatePrompt="Update",this.deletePrompt="Delete",this.deleteText="The team itself will not be deleted",this.promptTitle="Are you sure?",this.pageIndex=0,this.pageSize=12}watchHandler(t){this.selectedCompetitionGroup=t,this.getPagedItems()}async handlePageIndex(t){this.pageIndex=t.detail}async handlePageSizeChange(t){this.pageSize=+t.detail,this.pageIndex=0}getPagedItems(){const t=this.pageIndex*this.pageSize,i=t+this.pageSize;return this.selectedCompetitionGroup&&this.selectedCompetitionGroup.teamIds?this.teams.filter((t=>this.selectedCompetitionGroup.teamIds.includes(t.id))).slice(t,i):[]}async updateTeamNameById(t,i){const e=this.teams.find((i=>i.id===t));e&&(e.teamName=i,this.updatedCompetitionTeam.emit(e))}async addTeamModal(t){var i;t.stopPropagation();const e=this.teams.map((t=>({name:t.teamName||t.groupName,blobImage:t.logo,id:t.id}))),a=await s.create({component:"select-from-options-modal",componentProps:{options:e,mainTitle:this.modalTitle,defaultLogo:this.defaultLogo}});await a.present();const{data:n}=await a.onDidDismiss();if(n){let t=n;if(!t)return;let e=[];this.teams&&(e=e.concat(this.teams)),(null===(i=this.selectedCompetitionGroup)||void 0===i?void 0:i.teamIds)||(this.selectedCompetitionGroup.teamIds=[]),this.selectedCompetitionGroup.teamIds.push(t.id),this.updateGroup.emit(this.selectedCompetitionGroup),this.selectedCompetitionGroup=Object.assign({},this.selectedCompetitionGroup)}}async editTeamName(t){let i={header:this.editNameHeader,message:`${this.editNameMessage} ${t.teamName||t.groupName}`,buttons:[{text:this.cancelPrompt,role:"cancel"},{text:this.updatePrompt,handler:i=>this.updateTeamNameById(t.id,i.textarea)}],inputs:[{name:"textarea",type:"textarea",label:this.editNameLabel}]};const e=await a.create(i);await e.present()}removeTeamFromCompetitionGroup(t){const i=this.selectedCompetitionGroup.teamIds.indexOf(this.teams[t].id);this.selectedCompetitionGroup.teamIds.splice(i,1),this.updateGroup.emit(this.selectedCompetitionGroup),this.selectedCompetitionGroup=Object.assign({},this.selectedCompetitionGroup)}renderAddTeamItem(){return e("ion-item",{lines:"none"},e("ion-buttons",{slot:"end"},e("ion-button",{onClick:t=>this.addTeamModal(t),slot:"end"},e("ion-icon",{slot:"start",name:"add-outline"}),this.entityLabel)))}groupIsExcluded(t){return!(!this.checkIfCompetitionRules(t)&&!this.checkIfSiteRules(t))}checkIfSiteRules(t){var i,e;return null===(e=null===(i=this.siteRules)||void 0===i?void 0:i.excludedTeams)||void 0===e?void 0:e.some((i=>{var e,s;if((null===(s=null===(e=this.competition)||void 0===e?void 0:e.playerLevel)||void 0===s?void 0:s.name)===(null==i?void 0:i.playerLevel)||"*"===(null==i?void 0:i.playerLevel))return i.groupId===t.id}))}checkIfCompetitionRules(t){var i,e;return null===(e=null===(i=this.competitionRules)||void 0===i?void 0:i.excludedTeams)||void 0===e?void 0:e.some((i=>{var e,s;if((null===(s=null===(e=this.competition)||void 0===e?void 0:e.playerLevel)||void 0===s?void 0:s.name)===(null==i?void 0:i.playerLevel)||"*"===(null==i?void 0:i.playerLevel))return i.groupId===t.id}))}renderCompetitionGroupsList(){var t;return e("div",null,e("ion-grid",null,e("ion-row",null,null===(t=this.getPagedItems())||void 0===t?void 0:t.map((t=>{const i=this.teams.indexOf(t),s=t.teamName||t.groupName,a={src:this.imageResolver(t).src||this.defaultLogo};return e("ion-col",{sizeSm:"12",sizeLg:"6"},e("ion-item",{lines:"none"},e("ion-thumbnail",{slot:"start"},e("app-image",{image:a,alt:"Logo",class:"center"})),e("ion-label",{slot:"start"},s),this.isEditable&&e("ion-buttons",{slot:"end"},e("app-delete-button",{slot:"end",buttonFill:"clear",confirmText:this.deletePrompt,cancelText:this.cancelPrompt,headerText:this.promptTitle,messageText:this.deleteText,callback:()=>this.removeTeamFromCompetitionGroup(i)}))))}
1)))),e("app-paging",{rows:this.getPagedItems(),pageIndex:this.pageIndex,pageSize:this.pageSize,onHandleNavigate:t=>this.handlePageIndex(t),onHandlePageSizeChange:t=>this.handlePageSizeChange(t)}))}render(){return e("div",{key:"28c9da3af18e96b088e4388c0498136d3957ea68"},this.isEditable&&this.renderAddTeamItem(),this.renderCompetitionGroupsList())}static get watchers(){return{selectedCompetitionGroup:[{watchHandler:0}]}}},d=class{constructor(e){t(this,e),this.createCompetitionTeam=i(this,"createCompetitionTeam",7),this.deleteCompetitionTeam=i(this,"deleteCompetitionTeam",7),this.updatedCompetitionTeam=i(this,"updatedCompetitionTeam",7),this.participatingTeams=[],this.shownTeams=[],this.pageIndex=0,this.pageSize=20,this.teamsWithLineups=[]}async watchHandler(){this.getPagedItems();const t=(await this.checkIfParticipatingTeamsRoster()).map((t=>t.teamId));this.teamsWithLineups=t}componentWillLoad(){this.getPagedItems(),n.getLineups({competitionId:this.competition.id,teamType:o.ROSTER}).then((t=>{const i=t.map((t=>t.teamId));this.teamsWithLineups=i}))}async checkIfParticipatingTeamsRoster(){const t={competitionId:this.competition.id,teamType:o.ROSTER};return await n.getLineups(t)}async addTeamModal(t){t.stopPropagation();const i=await s.create({component:"browse-and-select-modal",componentProps:{searchFunction:this.fetchGroupsToSelectFrom,entityLabel:l("COMPETITION_ADMIN_GROUPS.TEAM"),mode:"SINGLE",showDefaultLogo:!0,usePlayerLevels:!1,searchPrompt:l("COMPETITION_ADMIN_GROUPS.GROUP_SEARCH_PROMPT"),modalTitle:l("COMPETITION_ADMIN_PAGE.PROMPT_ADD")}});await i.present();const{data:e}=await i.onDidDismiss();if(e){let t=e.selectedItems[0];if(!t)return;this.createCompetitionTeam.emit({teamName:t.name,groupId:t.id,groupName:t.name,competitionId:this.competition.id,logo:t.logo,siteId:this.competition.siteId})}}getPagedItems(){const t=this.pageIndex*this.pageSize,i=this.participatingTeams.slice(t,t+this.pageSize);return JSON.stringify(i)!==JSON.stringify(this.shownTeams)&&(this.shownTeams=i),this.shownTeams}async handlePageIndex(t){this.pageIndex=t.detail,this.getPagedItems()}async handlePageSizeChange(t){this.pageSize=+t.detail,this.pageIndex=0,this.getPagedItems()}async editTeamName(t){let i={header:l("COMPETITION_ADMIN_GROUPS.GROUP_NAME_HEADER"),message:`${l("COMPETITION_ADMIN_GROUPS.TEAM_NAME_MESSAGE")} ${t.teamName||t.groupName}`,buttons:[{text:l("COMPETITION_ADMIN_PAGE.PROMPT_CANCEL"),role:"cancel"},{text:l("COMPETITION_ADMIN_PAGE.PROMPT_UPDATE"),handler:i=>this.updateTeamNameById(t.id,i.textarea)}],inputs:[{value:(null==t?void 0:t.teamName)||(null==t?void 0:t.groupName),name:"textarea",type:"textarea",label:l("COMPETITION_ADMIN_GROUPS.TEAM_NAME_LABEL")}]};const e=await a.create(i);await e.present()}async updateTeamNameById(t,i){const e=this.participatingTeams.find((i=>i.id===t));e&&(e.teamName=i,this.updatedCompetitionTeam.emit(e))}goToDetailPage(t){r.goTo(`/competition/${this.competition.id}/team/${t.id}`)}renderParticipatingTeams(){return e("ion-card",null,e("ion-item",{lines:"none",color:"light"},e("ion-icon",{name:"people-outline",slot:"start"}),e("ion-label",null,l("COMPETITION_ADMIN_GROUPS.PARTICIPATING_TEAMS")),e("ion-buttons",null,e("ion-button",{color:"primary",fill:"solid",onClick:t=>this.addTeamModal(t)},e("ion-icon",{slot:"start",name:"add-outline"}),l("COMPETITION_ADMIN_GROUPS.TEAM")))),this.shownTeams.map((t=>{const i=this.teamsWithLineups.includes(t.id);return e("ion-item",null,e("ion-avatar",{slot:"start"},e("img",{src:t.logo?h(t.logo).src:this.defaultLogo})),e("ion-label",null,t.teamName),e("ion-buttons",null,e("ion-button",{onClick:()=>this.goToDetailPage(t)},i?[e("ion-icon",{color:"success",name:"people-circle-outline"})]:[e("ion-icon",{color:"warning",name:"people-circle-outline"})]),e("ion-button",{slot:"end",fill:"clear",onClick:()=>this.editTeamName(t)},e("ion-icon",{slot:"start",name:"create-outline"})),e("app-delete-button",{slot:"end",buttonFill:"clear",confirmText:l("COMPETITION_ADMIN_PAGE.PROMPT_DELETE"),cancelText:l("COMPETITION_ADMIN_PAGE.PROMPT_CANCEL"),headerText:l("COMPETITION_ADMIN_PAGE.PROMPT_TITLE"),messageText:l("COMPETITION_ADMIN_GROUPS.DELETE_TEXT"),callback:()=>this.deleteCompetitionTeam.emit(t)})))})),e("app-paging",{rows:this.getPagedItems(),pageIndex:this.pageIndex,pageSize:this.pageSize,onHandleNavigate:t=>this.handlePageIndex(t),onHandlePageSizeChange:t=>this.handlePageSizeChange(t)}
1))}render(){return[this.renderParticipatingTeams()]}static get watchers(){return{participatingTeams:[{watchHandler:0}]}}};export{c as competition_teams_manager,d as participating_teams}
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.