import{r as e}from"./p-5ab6b26f.js";class t{constructor(e,t={}){this.feature=e,t.keyPrefix||(t.keyPrefix="webmapgl.like"),t.clientId||(t.clientId=localStorage.getItem(t.keyPrefix+".clientId"),t.clientId||(t.clientId=this.makeId(64),localStorage.setItem(t.keyPrefix+".clientId",t.clientId))),this.options=t}getClientId(){return this.options.clientId}isLiked(){return-1!==this.getArray(this.feature.layer).indexOf(this.feature.id)}like(){let e=this.getArray(this.feature.layer);-1===e.indexOf(this.feature.id)&&e.push(this.feature.id),this.setArray(this.feature.layer,e)}unlike(){let e=this.getArray(this.feature.layer),t=e.indexOf(this.feature.id);-1!==t&&e.splice(t,1),this.setArray(this.feature.layer,e)}makeId(e){var t="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(let i=0;i<e;i++)t+=r.charAt(Math.floor(Math.random()*r.length));return t}getLayerKey(e){return this.options.keyPrefix+"|"+document.location.pathname+"|"+(e||"default")}getArray(e){let t=localStorage.getItem(this.getLayerKey(e));return t?t.split(",").map(e=>parseInt(e)).filter(e=>!isNaN(e)):[]}setArray(e,t){let r=t.filter(e=>!isNaN(e)).map(e=>e.toString()).join(",");localStorage.setItem(this.getLayerKey(e),r)}}class r{constructor(t){e(this,t)}async create(e,r={}){return new t(e,r)}}class i{constructor(t){e(this,t)}async create(e,t){let r={"Content-Type":"application/json"};return t.token&&(r.Authorization="Bearer "+t.token),await fetch(t.url,{body:JSON.stringify(e),headers:r,method:t.method||"POST",mode:t.mode||"cors"})}}export{r as gl_like_controller,i as gl_rest_controller};