/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as n } from "../../chunks/runtime.js";
import { Telemetry as a } from "@esri/telemetry";
import { GoogleAnalytics as r } from "@esri/telemetry-google-analytics";
import { Amazon as i } from "@esri/telemetry-amazon";
import { u as l } from "../../chunks/useT9n.js";
import { LitElement as m, createEvent as c } from "@arcgis/lumina";
import { css as p } from "lit";
const h = p`:host{display:block}`;
class d extends m {
  constructor() {
    super(...arguments), this.amazonAppId = "", this.amazonAppName = "", this.amazonUserPoolID = "", this.amazonVersion = "", this.firstUseVar = "", this.measurementIds = [], this._open = !1, this._translations = l({ name: "consent-manager", blocking: !0 }), this._loaded = !1, this.consentGranted = c();
  }
  static {
    this.properties = { amazonAppId: 1, amazonAppName: 1, amazonUserPoolID: 1, amazonVersion: 1, firstUseVar: 1, measurementIds: 0, portal: 0, _open: 16, _translations: 16 };
  }
  static {
    this.styles = h;
  }
  async getInstance() {
    if (localStorage.getItem(this.firstUseVar) === "true" || this.portal?.eueiEnabled)
      return await this._init(), this._telemetryInstance;
  }
  async load() {
    this._open = localStorage.getItem(this.firstUseVar) === null;
  }
  render() {
    return "";
  }
  loaded() {
    this.consentGranted.emit({
      granted: localStorage.getItem(this.firstUseVar) === "true"
    });
  }
  async _init() {
    if (!this._loaded) {
      const s = {
        info: console.info ? console.info.bind(console) : console.log.bind(console),
        error: console.error ? console.error.bind(console) : console.log.bind(console),
        warn: (e, ...o) => {
          (!e.includes("non-primitive value") || !e.includes("userSince")) && (console.warn || console.log)(e, ...o);
        }
      }, t = {
        plugins: [],
        portal: this.portal,
        logger: s
      };
      if (this.measurementIds?.length > 0) {
        const e = new r({
          measurementIds: this.measurementIds
        });
        t.plugins.push(e);
      }
      if (this.amazonUserPoolID) {
        const e = new i({
          userPoolID: this.amazonUserPoolID,
          app: {
            name: this.amazonAppName,
            id: this.amazonAppId,
            version: this.amazonVersion
          }
        });
        t.plugins.push(e);
      }
      this._telemetryInstance = new a(t), await this._telemetryInstance.init(), this._loaded = !0;
    }
  }
  _alertClosed() {
    this._open = !1, localStorage.getItem(this.firstUseVar) !== "true" && localStorage.setItem(this.firstUseVar, "false");
  }
  _accept() {
    localStorage.setItem(this.firstUseVar, "true"), this.consentGranted.emit({
      granted: !0
    }), this._open = !1;
  }
}
n("consent-manager", d);
export {
  d as ConsentManager
};
