'use client'
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result)
    __defProp(target, key, result);
  return result;
};

// src/m2m-user-menu.ts
var m2m_user_menu_exports = {};
__export(m2m_user_menu_exports, {
  M2MUserMenu: () => M2MUserMenu
});
module.exports = __toCommonJS(m2m_user_menu_exports);

// src/MenuBaseElement.ts
var import_lit = require("lit");
var import_ref = require("lit/directives/ref.js");
var import_decorators = require("lit/decorators.js");
var MenuBaseElement = class extends import_lit.LitElement {
  constructor() {
    super(...arguments);
    this.handleClickOutside = (event) => {
      if (!this.listRef.value || this.listRef.value.contains(event.composedPath()[0])) {
        return;
      }
      this.expanded = false;
    };
    this.additinalItems = [];
    this.expanded = false;
    this.handleToggleDrawer = (event) => {
      event.preventDefault();
      event.stopPropagation();
      this.expanded = !this.expanded;
      if (this.expanded) {
        window.addEventListener("click", this.handleClickOutside, false);
      }
    };
    this.listRef = (0, import_ref.createRef)();
  }
  updated() {
    if (this.expanded === false) {
      window.removeEventListener("click", this.handleClickOutside, false);
    }
  }
  disconnectedCallback() {
    super.disconnectedCallback();
    window.removeEventListener("click", this.handleClickOutside, false);
  }
};
MenuBaseElement.styles = import_lit.css`
    nav {
      position: relative;
      display: flex;
    }
    .navigation-drawer-controll-button {
      display: flex;
      align-items: center;
      justify-content: center;

      height: 42px;
      padding: 0;
      cursor: pointer;
      background-color: transparent;
      border: none;
      transition: background-color 0.2s;
      appearance: none;
    }
    .navigation-drawer-controll-button.navigation-drawer-controll-button--icon {
      width: 42px;
    }
    .navigation-drawer-controll-button:hover {
      background-color: rgba(0, 0, 0, 0.05);
    }
    .navigation-drawer-controll-button:active {
      background-color: rgba(0, 0, 0, 0.075);
    }

    .navigation-drawer {
      position: absolute;
      top: 100%;
      right: 0px;
      z-index: 1100;
      box-sizing: border-box;
      min-width: 200px;
      padding: 0px;
      margin: 0px;
      overflow: hidden;
      color: rgba(0, 0, 0, 0.87);
      white-space: nowrap;
      list-style: none;
      background-color: #fff;
      border-radius: 5px;
      box-shadow: 0px 1px 3px 0px rgb(0 0 0 / 20%),
        0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 2px 1px -1px rgb(0 0 0 / 12%);
    }
    .navigation-drawer-controll-button[aria-expanded="false"]
      ~ .navigation-drawer {
      display: none;
    }

    .navigation-drawer li {
      border-bottom: 1px solid #eeeeee;
    }
    .navigation-drawer li:last-of-type {
      border-bottom: none;
    }
    .navigation-drawer li > a,
    .navigation-drawer li > button {
      box-sizing: border-box;
      display: block;
      width: 100%;
      padding: 0;
      padding: 0.6em 1em;
      font: inherit;
      color: inherit;
      text-align: left;
      text-decoration: none;
      cursor: pointer;
      cursor: pointer;
      background-color: transparent;
      border: none;
      transition: 0.2s;
      appearance: none;
    }
    .navigation-drawer li > a:hover,
    .navigation-drawer li > button:hover {
      background-color: #ededed;
    }
    .navigation-drawer li > a:active,
    .navigation-drawer li > button:active {
      background-color: #dadada;
    }

    .navigation-drawer li ul {
      padding: 0;
      list-style: none;
    }
    .navigation-drawer li:has(> ul) li > a {
      padding-left: 2em;
    }

    .navigation-drawer li:has(> ul) > span {
      display: block;
      padding: 0.6em 1em;
      border-bottom: 1px solid #eeeeee;
    }
  `;
__decorateClass([
  (0, import_decorators.property)({
    type: Object,
    attribute: "additional-items"
  })
], MenuBaseElement.prototype, "additinalItems", 2);
__decorateClass([
  (0, import_decorators.property)()
], MenuBaseElement.prototype, "expanded", 2);

// src/m2m-user-menu.ts
var import_decorators2 = require("lit/decorators.js");

// src/domains.ts
var getDomains = () => {
  return globalThis.M2M_COMPONENTS_ENV === "production" ? {
    core: "https://core.m2msystems.cloud",
    sumyca: "https://manage.sumyca.com",
    cleaning: "https://manager-cleaning.m2msystems.cloud",
    users: "https://manage-users.m2msystems.cloud",
    inspection: "https://inspection.m2msystems.cloud",
    checkin: "https://manage.checkin.m2msystems.cloud",
    systems: "https://m2msystems.cloud/"
  } : {
    core: "https://dev--m2m-core-manager-front.netlify.app",
    sumyca: "https://dev--sumyca-manager-front.netlify.app",
    cleaning: "https://dev--m2m-cleaning-manager-front.netlify.app",
    users: "https://dev--manage-users.netlify.app",
    inspection: "https://dev--m2m-inspection-manager-front.netlify.app",
    checkin: "https://manage.dev.checkin.m2msystems.cloud",
    systems: "https://dev.m2msystems.cloud"
  };
};

// src/m2m-user-menu.ts
var import_lit2 = require("lit");

// src/storage/client.ts
var context = {};
var getStorage = async (timeout = 5e3) => {
  const storage = await new Promise((resolve, reject) => {
    const rejectTimer = window.setTimeout(function() {
      reject(
        new Error(
          "Timeout: M2mStorageClient could not connect. Please call m2mStorageClient.init() before using m2mStorageClient."
        )
      );
    }, timeout);
    const storage2 = context.storage;
    if (storage2) {
      window.clearTimeout(rejectTimer);
      resolve(storage2);
    }
    const timer = window.setInterval(() => {
      const storage3 = context.storage;
      if (storage3) {
        window.clearTimeout(rejectTimer);
        window.clearInterval(timer);
        resolve(storage3);
      }
    }, 200);
  });
  await storage.onConnect();
  return storage;
};
var M2M_AUTH_TOKEN_KEY = "M2M_APP_AUTH_TOKEN";
var getAuthTokenCache = () => {
  return window.localStorage.getItem(M2M_AUTH_TOKEN_KEY);
};
var getAuthToken = async () => {
  try {
    const storage = await getStorage();
    const autuToken = await storage.get(M2M_AUTH_TOKEN_KEY);
    return autuToken || getAuthTokenCache();
  } catch (error) {
    console.warn(error);
    return getAuthTokenCache();
  }
};
var setAuthToken = async (token) => {
  window.localStorage.setItem(M2M_AUTH_TOKEN_KEY, token);
  try {
    const storage = await getStorage();
    await storage.set(M2M_AUTH_TOKEN_KEY, token);
  } catch (error) {
    console.warn(error);
  }
};
var clearAuthToken = async () => {
  window.localStorage.removeItem(M2M_AUTH_TOKEN_KEY);
  try {
    const storage = await getStorage();
    await storage.del(M2M_AUTH_TOKEN_KEY);
  } catch (error) {
    console.warn(error);
  }
};
var m2mAuthTokenApi = {
  get: getAuthToken,
  getCache: getAuthTokenCache,
  set: setAuthToken,
  clear: clearAuthToken
};

// src/m2m-user-menu.ts
var import_ref2 = require("lit/directives/ref.js");
var M2MUserMenu = class extends MenuBaseElement {
  constructor() {
    super(...arguments);
    this.handleLogout = () => {
      void m2mAuthTokenApi.clear();
      window.location.reload();
    };
  }
  render() {
    var _a;
    const domains = getDomains();
    const additionalItems = (_a = this.additinalItems) == null ? void 0 : _a.map((item) => {
      return import_lit2.html`
        <li>
          <a href="${item.href}">${item.label}</a>
        </li>
      `;
    });
    return import_lit2.html`<nav>
      <button
        type="button"
        class="navigation-drawer-controll-button navigation-drawer-controll-button--icon"
        aria-controls="m2m-user-menu__navigation-drawer"
        aria-expanded=${this.expanded}
        @click=${this.handleToggleDrawer}
      >
        <svg viewBox="0 0 24 24" width="38px" height="38px" fill="#000000">
          <path d="M0 0h24v24H0z" fill="none" />
          <path
            d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z"
          />
        </svg>
      </button>
      <ul
        ${(0, import_ref2.ref)(this.listRef)}
        id="m2m-user-menu__navigation-drawer"
        aria-hidden=${!this.expanded}
        class="navigation-drawer"
      >
        <li><a href="${domains.users}">アカウント情報</a></li>
        <li @click=${this.handleLogout}>
          <button type="button">ログアウト</button>
        </li>
        ${additionalItems}
      </ul>
    </nav>`;
  }
};
M2MUserMenu = __decorateClass([
  (0, import_decorators2.customElement)("m2m-user-menu")
], M2MUserMenu);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  M2MUserMenu
});
//# sourceMappingURL=m2m-user-menu.js.map