import { css as $, LitElement as C, html as f } from "lit";
import { property as d, query as M, state as O } from "lit/decorators.js";
import { map as L } from "lit/directives/map.js";
import "@material/web/menu/menu.js";
import { getLocale as g, setLocale as S } from "./localization.js";
import { str as P } from "@lit/localize/internal/str-tag.js";
import { updateWhenLocaleChanges as w, msg as I } from "@lit/localize";
import { importMdMenuSafely as b, importMdMenuItemSafely as k, importMdIconSafely as x, importMdIconButtonSafely as E, customElementSafe as N } from "./custom-element-safe.js";
var z = Object.defineProperty, A = Object.getOwnPropertyDescriptor, y = (e) => {
  throw TypeError(e);
}, l = (e, n, t, s) => {
  for (var a = s > 1 ? void 0 : s ? A(n, t) : n, c = e.length - 1, m; c >= 0; c--)
    (m = e[c]) && (a = (s ? m(n, t, a) : m(a)) || a);
  return s && a && z(n, t, a), a;
}, D = (e, n, t) => n.has(e) || y("Cannot " + t), T = (e, n, t) => n.has(e) ? y("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(e) : n.set(e, t), o = (e, n, t) => (D(e, n, "access private method"), t), r, v, _, p, u;
b();
k();
x();
E();
const h = {
  cs: "cz",
  en: "gb",
  "en-US": "us",
  "en-GB": "gb",
  sk: "sk",
  de: "de",
  hu: "hu",
  pl: "pl",
  uk: "ua",
  es: "es"
};
let i = class extends C {
  constructor() {
    super(), T(this, r), this.locales = ["en"], this.flagIconsPath = "./assets/flag-icons/css/flag-icons.min.css", this.menuOpen = !1, w(this);
  }
  render() {
    const e = g() || (navigator.languages || [navigator.language || "en"])[0], n = o(this, r, u).call(this, e), t = o(this, r, p).call(this, e);
    return f`
      <link rel="stylesheet" href="${this.flagIconsPath}" />
      <md-menu-item
        @click=${() => this.menu.open = !this.menu.open}
        id="locale-anchor"
        keep-open
        aria-haspopup="menu"
        aria-expanded="${this.menuOpen ? "true" : "false"}"
        aria-controls="locale-menu"
        aria-label=${I(P`Change language, currently ${t}`, {
      id: "polyfea.change-language-label"
    })}
        locale=${e}
      >
        <div slot="headline" class="menu-content">
          <span class="flag-icon fi fi-${n}"></span>
          <span class="lang-name">${t}</span>
        </div>
        <md-icon slot="end">arrow_right</md-icon>
      </md-menu-item>
      <md-menu id="locale-menu" anchor="locale-anchor" .open="${this.menuOpen}">
        ${L(this.locales || [], (s) => o(this, r, v).call(this, s, e))}
      </md-menu>
    `;
  }
};
r = /* @__PURE__ */ new WeakSet();
v = function(e, n) {
  const t = n === e, s = o(this, r, u).call(this, e), a = o(this, r, p).call(this, e);
  return f`
      <md-menu-item
        @click="${() => o(this, r, _).call(this, e)}"
        ?selected="${t}"
        role="menuitemradio"
        aria-checked=${t ? "true" : "false"}
        locale="${e}"
      >
        <div slot="headline" class="menu-content">
          <span class="flag-icon fi fi-${s}"></span>
          <span class="lang-name">${a}</span>
        </div>
      </md-menu-item>
    `;
};
_ = function(e) {
  this.menuOpen = !1, !(!e || e === g()) && S(e);
};
p = function(e) {
  let n;
  try {
    n = new Intl.DisplayNames([e], { type: "language" }).of(e), n = n ? n.charAt(0).toUpperCase() + n.slice(1) : e;
  } catch {
  }
  return n || e;
};
u = function(e) {
  return h[e] ? h[e] : e.includes("-") ? e.split("-")[1].toLowerCase() : "un";
};
i.styles = $`
    :host {
      display: inline-block;
      position: relative;
    }

    .flag-icon {
      border-radius: 2px;
      margin-right: 0.75rem;
      font-size: 1.125rem;
      line-height: 1.125rem;
    }

    .menu-content {
      display: flex;
      align-items: center;
      min-width: 150px;
    }

    .lang-name {
      font-family: var(--md-sys-typescale-label-large-font, sans-serif);
      font-size: var(--md-sys-typescale-label-large-size, 14px);
    }
  `;
l([
  d({ type: Array })
], i.prototype, "locales", 2);
l([
  d({ type: String, attribute: "flag-icons-path" })
], i.prototype, "flagIconsPath", 2);
l([
  M("md-menu")
], i.prototype, "menu", 2);
l([
  O()
], i.prototype, "menuOpen", 2);
i = l([
  N("polyfea-md-locale-menu")
], i);
export {
  i as PolyfeaMdLocaleMenu
};
