import{f as v}from"./numbers.js";import{b as p,a as g,_ as S}from"./timer2.js";import{o as n,c as i,a as e,t as a,e as h,_ as r,f as M,d as E,n as b,r as _,b as m}from"./index.js";const T={class:"snowballs-scoreboard"},$={class:"snowballs-scoreboard__team"},y={class:"snowballs-scoreboard__team__score"},B={class:"snowballs-scoreboard__team__name"},I={class:"snowballs-scoreboard__timer"},U=e("img",{src:p},null,-1),C={class:"snowballs-scoreboard__team"},x={class:"snowballs-scoreboard__team__name"},L={class:"snowballs-scoreboard__team__score"};function N(s,t,o,c,d,l){return n(),i("div",T,[e("div",$,[e("div",y,a(l.formatNumberWithSpaces(o.score[0])),1),e("div",B,a(o.teams[0]),1)]),e("div",I,[U,h(a(l.formatedTime),1)]),e("div",C,[e("div",x,a(o.teams[1]),1),e("div",L,a(l.formatNumberWithSpaces(o.score[1])),1)])])}const D={props:["teams","score","time"],computed:{formatedTime(){const s=new Date(this.time),t=s.getUTCMinutes().toString().padStart(2,"0"),o=s.getUTCSeconds().toString().padStart(2,"0");return`${t}:${o}`}},methods:{formatNumberWithSpaces:v}},A=r(D,[["render",N]]),V=e("div",{class:"snowballs-ball__before"},null,-1),k=e("img",{class:"snowballs-ball__ball",src:g},null,-1),P={class:"snowballs-ball__value"},O=["textContent"],W={key:0,class:"snowballs-ball__mouse",src:S},z={class:"snowballs-ball__progress"};function G(s,t,o,c,d,l){return n(),i("div",{class:b(["snowballs-ball",{"snowballs-ball_disabled":!s.isActive,"snowballs-bar_mobile":l.isMobile}])},[V,k,e("div",P,[h(a(o.snowballs),1),e("div",{class:"snowballs-ball__value__text",textContent:a(l.getSnowballsText())},null,8,O)]),l.isMobile?M("",!0):(n(),i("img",W)),e("div",z,[e("div",{class:"snowballs-ball__progress__fill",style:E({width:`${s.fill}%`})},null,4)])],2)}const u=2,H={props:["snowballs"],data:()=>({fill:0,timer:null,isActive:!1,duration:1e3}),computed:{delay(){return this.duration/100},isMobile(){return this.$root.isMobile}},mounted(){this.isMobile?(document.addEventListener("touchstart",this.onMouseDown),document.addEventListener("touchend",this.onMouseUp)):(document.addEventListener("mousedown",this.onMouseDown),document.addEventListener("mouseup",this.onMouseUp))},unmounted(){this.isMobile?(document.removeEventListener("touchstart",this.onMouseDown),document.removeEventListener("touchend",this.onMouseUp)):(document.removeEventListener("mousedown",this.onMouseDown),document.removeEventListener("mouseup",this.onMouseUp)),this.timer&&(clearInterval(this.timer),this.timer=null)},methods:{getSnowballsText(){return this.snowballs%10>=2&&this.snowballs%10<=4?"снежка":this.snowballs%10==1?"снежок":"снежков"},onMouseDown(s){if(this.isMobile){for(let t of s.changedTouches)if(!(t.target.nativeElement||t.target).matches(".hud-iface"))return}this.snowballs<=0||!this.isMobile&&s.button!==u||(this.timer&&clearInterval(this.timer),this.isActive=!0,this.timer=setInterval(()=>{if(++this.fill>=100){clearInterval(this.timer),this.timer=null;return}},this.delay))},onMouseUp(s){if(this.isMobile){for(let t of s.changedTouches)if(!(t.target.nativeElement||t.target).matches(".hud-iface"))return}this.snowballs<=0||!this.isMobile&&s.button!==u||(this.timer&&clearInterval(this.timer),this.isActive=!1,this.timer=null,this.fill>=30&&this.onEnd(this.fill),this.fill=0)},onEnd(s){this.snowballs>0&&(this.$emit("updateSnowballs",this.snowballs-1),setTimeout(()=>{window.playSound("snowballs/sfx_snowball_throw.ogg",!1,3)},200),sendClientEvent(gm.EVENT_EXECUTE_PUBLIC,"OnSnowBattleEvent",parseInt(s)))}}},R=r(H,[["render",G]]);function X(s,t,o,c,d,l){const w=_("Scoreboard"),f=_("Ball");return n(),i("div",{class:b(["snowballs iface-container",{snowballs_mobile:l.isMobile}])},[m(w,{class:"snowballs__scoreboard",teams:s.teams,score:s.score,time:s.time},null,8,["teams","score","time"]),m(f,{class:"snowballs__ball",snowballs:s.snowballs,onUpdateSnowballs:l.updateSnowballs},null,8,["snowballs","onUpdateSnowballs"])],2)}const j={props:["openParams"],components:{Scoreboard:A,Ball:R},data:()=>({teams:["С","К"],snowballs:0,score:[0,0],timer:null,time:0}),computed:{isMobile(){return this.$root.isMobile}},created(){this.$data.noAdaptation=!0,this.updateTimer(this.openParams[0]),this.updateSnowballs(this.openParams[1])},unmounted(){this.timer&&(clearInterval(this.timer),this.timer=null)},methods:{updateTimer(s){this.timer&&clearInterval(this.timer),this.time=s,this.timer=setInterval(()=>{if(this.time<=0){this.time=0,clearInterval(this.timer),this.timer=null;return}this.time-=1e3},1e3)},updateScores(s,t){this.score[0]=s,this.score[1]=t},updateSnowballs(s){this.snowballs<s&&setTimeout(()=>{window.playSound("snowballs/sfx_snowball_making.ogg",!1,3)},100),this.snowballs=s}}},K=r(j,[["render",X]]);export{K as default};
