import{LitElement as t,html as e,css as o}from"lit";import{dispatchCustomEvent as a}from"./lib/events.js";import{i18n as i}from"./translation.js";import"./cc-map-marker-dot.js";import"./cc-map.js";import"./cc-toggle.js";class s extends t{static get properties(){return{appName:{type:String,attribute:"app-name"},availableModes:{type:Array,attribute:"available-modes"},centerLat:{type:Number,attribute:"center-lat"},centerLon:{type:Number,attribute:"center-lon"},error:{type:Boolean,reflect:!0},heatmapPoints:{type:Array,attribute:"heatmap-points"},loading:{type:Boolean,reflect:!0},mode:{type:String},orgaName:{type:String,attribute:"orga-name"},viewZoom:{type:Number,attribute:"view-zoom"},_points:{type:Array,state:!0}}}constructor(){super(),this.appName=null,this.availableModes=["points","heatmap"],this.centerLat=48.9,this.centerLon=2.4,this.error=!1,this.heatmapPoints=null,this.loading=!1,this.mode="points",this.orgaName=null,this.viewZoom=2,this._points=[],this._pointsByCoords={}}addPoints(t,e={}){const{spreadDuration:o=!1}=e,a=!1!==o?Math.floor(Number(o)/t.length):0;t.forEach(((t,e)=>{setTimeout((()=>this._addPoint(t)),a*e)}))}_addPoint({lat:t,lon:e,count:o=1,delay:a=1e3,tooltip:i}){const s=[t,e].join(","),r={lat:t,lon:e,count:o,tooltip:i};null==this._pointsByCoords[s]&&(this._pointsByCoords[s]=[]),this._pointsByCoords[s].push(r),this._updatePoints(),setTimeout((()=>{this._pointsByCoords[s]=this._pointsByCoords[s].filter((t=>t!==r)),0===this._pointsByCoords[s].length&&delete this._pointsByCoords[s],this._updatePoints()}),a)}_updatePoints(){this._points=Object.entries(this._pointsByCoords).map((([t,e])=>{const{lat:o,lon:a}=e[0],i=e.map((t=>t.count)).reduce(((t,e)=>t+e),0),s=e.filter((t=>null!=t.tooltip&&""!==t.tooltip)).map((t=>t.tooltip)),r=Array.from(new Set(s));r.length>=3&&(r.length=3,r[2]=r[2]+"...");return{lat:o,lon:a,marker:{tag:"cc-map-marker-dot",count:i},tooltip:r.length>0?r.join("<br>"):null}}))}_getModes(){const t=[{label:i("cc-logsmap.mode.points"),value:"points"},{label:i("cc-logsmap.mode.heatmap"),value:"heatmap"}];return this.availableModes.map((e=>t.find((({value:t})=>t===e)))).filter((t=>null!=t))}_getLegend(){return"points"===this.mode?null==this.appName?i("cc-logsmap.legend.points",{orgaName:this.orgaName}):i("cc-logsmap.legend.points.app",{appName:this.appName}):null==this.appName?i("cc-logsmap.legend.heatmap",{orgaName:this.orgaName}):i("cc-logsmap.legend.heatmap.app",{appName:this.appName})}render(){const t=this._getModes();return e`${t.length>1?e`<cc-toggle .choices=${t} value=${this.mode} @cc-toggle:input=${this._onModeChange}></cc-toggle>`:""}<cc-map center-lat=${this.centerLat} center-lon=${this.centerLon} view-zoom=${this.viewZoom} mode=${this.mode} ?loading=${this.loading} ?error=${this.error} .heatmapPoints=${this.heatmapPoints} .points=${this._points}>${this._getLegend()}</cc-map>`}_onModeChange({detail:t}){this.mode=t,a(this,"mode",this.mode)}static get styles(){return o`:host{background-color:var(--cc-color-bg-default,#fff);border:1px solid var(--cc-color-border-neutral,#aaa);border-radius:var(--cc-border-radius-default,.25em);display:block;height:15em;overflow:hidden;position:relative;width:20em}cc-toggle{left:.5em;position:absolute;top:.5em;z-index:2}cc-map{height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}cc-map[view-zoom='1']{--cc-map-marker-dot-size:6px}cc-map[view-zoom='2']{--cc-map-marker-dot-size:8px}cc-map[view-zoom='3']{--cc-map-marker-dot-size:10px}cc-map[view-zoom='4']{--cc-map-marker-dot-size:12px}cc-map[view-zoom='5']{--cc-map-marker-dot-size:14px}cc-map[view-zoom='6']{--cc-map-marker-dot-size:16px}`}}window.customElements.define("cc-logsmap",s);export{s as CcLogsMap};
//# sourceMappingURL=cc-logsmap.js.map
