"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("../polyfills/tslib.js");
var chunk_853b4351_js_1 = require("./chunk-853b4351.js");
var _nextId = 0, Style = function () { function e() { var e = this; this.handlers = { click: function (t) { return e.handleClick(t); }, mouseenter: function () { return e.handleMouseenter(); }, mouseleave: function () { return e.handleMouseleave(); } }, this.basemap = !1, this.clickableLayers = [], this.enabled = !0, this.json = {}; } return e.prototype.componentWillLoad = function () { void 0 === this.id && (this.id = "style-" + _nextId.toString(), _nextId += 1), this.url && this.fetchJSON(); }, e.prototype.componentDidLoad = function () { this.clickableLayers && this.clickableLayers.length && this.updateClickable(this.clickableLayers), this.glStyleElementAdded.emit(this); }, e.prototype.componentDidUpdate = function () { this.glStyleElementModified.emit(this); }, e.prototype.componentDidUnload = function () { this.glStyleElementRemoved.emit(this); }, e.prototype.getMap = function () { return this.el.closest("gl-map").map; }, e.prototype.fetchJSON = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var e, t, n, l; return tslib_1.__generator(this, function (o) { switch (o.label) {
    case 0: return [4, fetch(this.url)];
    case 1: return e = o.sent(), t = this, [4, e.json()];
    case 2:
        if (t.json = o.sent(), this.token && this.json.sources)
            for (n in this.json.sources)
                (l = this.json.sources[n]).data && (l.data = l.data.replace(/\$\{TOKEN\}/g, this.token));
        return [2];
} }); }); }, e.prototype.updateClickable = function (e, t) { var n = this.getMap(); e = chunk_853b4351_js_1.b(e), t = chunk_853b4351_js_1.b(t); for (var l = 0, o = e; l < o.length; l++) {
    var i = t.indexOf(s = o[l]);
    -1 === i ? (n.on("click", c = this.id + ":" + s, this.handlers.click), n.on("mouseenter", c, this.handlers.mouseenter), n.on("mouseleave", c, this.handlers.mouseleave)) : t.splice(i, 1);
} for (var a = 0, r = t; a < r.length; a++) {
    var s, c;
    n.off("click", c = this.id + ":" + (s = r[a]), this.handlers.click), n.off("mouseenter", c, this.handlers.mouseenter), n.off("mouseleave", c, this.handlers.mouseleave);
} }, e.prototype.handleClick = function (e) { this.glFeatureClick.emit(e); }, e.prototype.handleMouseenter = function () { this.getMap().getCanvas().style.cursor = "pointer"; }, e.prototype.handleMouseleave = function () { this.getMap().getCanvas().style.cursor = ""; }, Object.defineProperty(e, "is", { get: function () { return "gl-style"; }, enumerable: !0, configurable: !0 }), Object.defineProperty(e, "properties", { get: function () { return { basemap: { type: Boolean, attr: "basemap" }, clickableLayers: { type: String, attr: "clickable-layers", watchCallbacks: ["updateClickable"] }, el: { elementRef: !0 }, enabled: { type: Boolean, attr: "enabled" }, id: { type: String, attr: "id", reflectToAttr: !0, mutable: !0 }, json: { type: "Any", attr: "json", mutable: !0 }, name: { type: String, attr: "name" }, thumbnail: { type: String, attr: "thumbnail" }, token: { type: String, attr: "token" }, url: { type: String, attr: "url" } }; }, enumerable: !0, configurable: !0 }), Object.defineProperty(e, "events", { get: function () { return [{ name: "glFeatureClick", method: "glFeatureClick", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glStyleElementAdded", method: "glStyleElementAdded", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glStyleElementModified", method: "glStyleElementModified", bubbles: !0, cancelable: !0, composed: !0 }, { name: "glStyleElementRemoved", method: "glStyleElementRemoved", bubbles: !0, cancelable: !0, composed: !0 }]; }, enumerable: !0, configurable: !0 }), e; }();
exports.GlStyle = Style;
