import { isPlainObject as p } from "../../core/utilities.mjs";
import { LOG_LEVEL as s } from "../levels.mjs";
class y {
  timer;
  queue = [];
  defaultStyle = [
    "border-radius: 3px",
    "font-size: 14px",
    "font-weight: bold",
    "color: white",
    "-webkit-text-stroke: .6px black",
    "padding: 2px 5px",
    "margin-right: 2px"
  ].join(";");
  config;
  color;
  levelColorMap = {
    1: "#00BCD4",
    //cyan
    2: "#f39c12",
    //yellow
    3: "#c0392b",
    //red
    4: "#2ecc71",
    //green
    5: "#7f8c8d"
    //gray
  };
  constructor(t) {
    this.config = t, this.color = this.colorize(t.namespace);
  }
  getStyle(t = s.DEFAULT) {
    return `background: ${this.levelColorMap[t] ?? this.levelColorMap[5]}; ${this.defaultStyle}`;
  }
  report(t, e) {
    const { enabled: o, grouped: i, namespace: a } = this.config, { args: h = [], date: n, group: g, level: l } = e;
    if (o)
      if (i)
        this.queue.push({ ...e, message: t }), this.bouncingOutput();
      else {
        const d = this.getConsole(l), c = `color: ${this.levelColorMap[l]}`, r = [];
        for (const u of h)
          p(u) ? r.push(JSON.parse(JSON.stringify(u))) : r.push(u);
        d(
          `%c${a}%c${n}%c${g}%c${t}`,
          `background: ${this.color}; ${this.defaultStyle}`,
          this.getStyle(5),
          this.getStyle(l),
          c,
          ...r
        );
      }
  }
  reportInfo(t, e, ...o) {
    const i = new Intl.DateTimeFormat(["pt-PT", "de-DE", "en-GB"], {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    }).format(Date.now());
    this.report(t, { level: s.INFO, group: e, date: i, args: o });
  }
  reportWarning(t, e, ...o) {
    const i = new Intl.DateTimeFormat(["pt-PT", "de-DE", "en-GB"], {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    }).format(Date.now());
    this.report(t, { level: s.WARN, group: e, date: i, args: o });
  }
  reportError(t, e, ...o) {
    const i = new Intl.DateTimeFormat(["pt-PT", "de-DE", "en-GB"], {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    }).format(Date.now());
    this.report(t, { level: s.ERROR, group: e, date: i, args: o });
  }
  getOptions() {
    return this.config;
  }
  stdout() {
    const { namespace: t, title: e } = this.config;
    console.group(
      `%c🟣 ${t.toUpperCase()}%c${e}`,
      `background: ${this.colorize(t)}; ${this.defaultStyle}`,
      this.getStyle(3)
    );
    for (const o of this.queue) {
      const { args: i = [], date: a, group: h, level: n, message: g } = o, l = this.getConsole(n), d = `color: ${this.levelColorMap[n]}`, c = [];
      for (const r of i)
        p(r) ? c.push(JSON.parse(JSON.stringify(r))) : c.push(r);
      l(`%c${a}%c${h}%c${g}`, this.getStyle(5), this.getStyle(n), d, ...c);
    }
    console.groupEnd(), this.reset();
  }
  getConsole(t) {
    let e = console.log.bind(console);
    switch (t) {
      case s.ERROR:
        e = console.error.bind(console);
        break;
      case s.INFO:
        e = console.info.bind(console);
        break;
      case s.WARN:
        e = console.warn.bind(console);
        break;
    }
    return e;
  }
  colorize(t) {
    let e = 0;
    for (let i = 0; i < t.length; e = t.charCodeAt(i++) + ((e << 5) - e)) ;
    const o = Math.floor(Math.abs(Math.sin(e) * 1e4 % 1 * 16777216)).toString(16);
    return "#" + Array(6 - o.length + 1).join("0") + o;
  }
  bouncingOutput() {
    this.timer && clearTimeout(this.timer), this.timer = setTimeout(() => this.stdout(), this.config.delay);
  }
  reset() {
    this.queue = [], this.timer && clearTimeout(this.timer);
  }
}
export {
  y as BrowserReporter
};
//# sourceMappingURL=browser.mjs.map
