import{r as t,f as i,h as s,d as e}from"./p-23450e8b.js";import{f as h}from"./p-d8674de4.js";const n=class{constructor(s){t(this,s);this.glLike=i(this,"glLike",7);this.likeClicked=()=>{if(!this.disabled)this.toggle()};this.count=0;this.liked=false;this.proxy=undefined;this.likeCtrl=undefined;this.restCtrl=undefined;this.attribute="_likes";this.disabled=false;this.feature=undefined;this.iconNo="star-outline";this.iconYes="star";this.method="POST";this.requestMode=undefined;this.token=undefined;this.url=undefined}async componentWillLoad(){await this.setState()}async setState(){if(this.feature!=undefined){this.count=this.feature.properties[this.attribute];if(this.likeCtrl==undefined){this.likeCtrl=await h("gl-like-controller")}this.proxy=await this.likeCtrl.create(this.feature);this.liked=this.proxy.isLiked()}}async toggle(){var t;this.liked=!this.liked;this.count+=this.liked?1:-1;if(((t=this.feature)===null||t===void 0?void 0:t.properties)!=undefined)this.feature.properties[this.attribute]=this.count;this.liked?this.proxy.like():this.proxy.unlike();let i=false;let s=this.proxy.getClientId();try{if(this.restCtrl==undefined){this.restCtrl=await h("gl-rest-controller")}await this.restCtrl.create({type:"Feature",properties:{action:this.liked?"like":"unlike",feature_id:this.feature.id,client_id:s}},{url:this.url,token:this.token,method:this.method,mode:this.requestMode});i=true}catch(t){}this.glLike.emit({success:i,feature:this.feature,action:this.liked?"like":"unlike",client_id:s})}render(){return s("ion-button",{fill:"clear",onClick:this.likeClicked,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 e(this)}static get watchers(){return{feature:["setState"]}}};export{n as gl_like_button};
//# sourceMappingURL=p-8d22e12f.entry.js.map