import{r as t,e as i,c as e,h as s,d as r}from"./p-5ab6b26f.js";class h{constructor(s){t(this,s),this.count=0,this.liked=!1,this.attribute="_likes",this.disabled=!1,this.iconNo="star-outline",this.iconYes="star",this.method="POST",this.glLike=i(this,"glLike",7),this.likeCtrl=e(this,"gl-like-controller"),this.restCtrl=e(this,"gl-rest-controller")}async componentWillLoad(){await this.setState()}async setState(){this.feature&&(this.count=this.feature.properties[this.attribute],this.proxy=await this.likeCtrl.create(this.feature),this.liked=this.proxy.isLiked())}async toggle(){this.liked=!this.liked,this.count+=this.liked?1:-1,this.feature&&this.feature.properties&&(this.feature.properties[this.attribute]=this.count),this.liked?this.proxy.like():this.proxy.unlike();let t=!1,i=this.proxy.getClientId();try{await this.restCtrl.create({type:"Feature",properties:{action:this.liked?"like":"unlike",feature_id:this.feature.id,client_id:i}},{url:this.url,token:this.token,method:this.method,mode:this.requestMode}),t=!0}catch(t){}this.glLike.emit({success:t,feature:this.feature,action:this.liked?"like":"unlike",client_id:i})}render(){return s("ion-button",{fill:"clear",onClick:()=>{this.disabled||this.toggle()},disabled:this.disabled},s("ion-icon",{slot:"start",name:this.liked?this.iconYes:this.iconNo}),s("span",{class:"gl-like-button-count"},this.count))}get el(){return r(this)}static get watchers(){return{feature:["setState"]}}}export{h as gl_like_button};