'use strict';

const shared_tailwindElement_index = require('./index-179a633e.cjs');
const queryAssignedElements = require('./query-assigned-elements-d5e45650.cjs');
const index = require('./index-1d3f4a5a.cjs');
require('./components/lukso-icon/index.cjs');
require('./components/lukso-profile/index.cjs');
require('./components/lukso-username/index.cjs');

const style = ":host {\n    display: flex;\n    width: 100%\n}";

const uniqId = () => {
  const s4 = () => ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
  return `${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
};

const debounceFunction = (func, timeout = 100) => {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => {
      typeof func === "function" && func.apply(void 0, args);
    }, timeout);
  };
};

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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;
};
exports.LuksoDropdown = class LuksoDropdown extends shared_tailwindElement_index.TailwindStyledElement(style) {
  constructor() {
    super();
    this.id = "";
    this.triggerId = "";
    this.isOpen = false;
    this.isOpenOnOutsideClick = false;
    this.openTop = false;
    this.isRight = false;
    this.isFullWidth = false;
    this.size = "medium";
    this.styles = index.ce({
      base: `bg-neutral-100 border w-full border-neutral-90 shadow-1xl z-50
      flex absolute flex-col gap-1 overflow-y-auto max-h-64 `,
      variants: {
        openTop: {
          true: "bottom-[48px] mb-2 mt-0"
        },
        size: {
          small: "rounded-8 p-2 mt-1 min-w-[120px] paragraph-inter-12-regular",
          medium: "rounded-12 p-3 mt-2 min-w-[200px] paragraph-inter-14-regular"
        },
        isRight: {
          true: "right-0"
        },
        isFullWidth: {
          true: "w-full"
        }
      },
      compoundVariants: [
        {
          isFullWidth: false,
          size: "small",
          class: "max-w-[200px]"
        },
        {
          isFullWidth: false,
          size: "medium",
          class: "max-w-[300px]"
        }
      ]
    });
    this.handleClick = debounceFunction((event) => {
      const element = event.target;
      if (element.id === this.triggerId || this.id === element.id) {
        this.isOpen = !this.isOpen;
        return;
      }
      if (!this.isOpenOnOutsideClick) {
        this.isOpen = false;
      }
    });
    if (!this.id) {
      this.id = uniqId();
    }
  }
  connectedCallback() {
    super.connectedCallback();
    window.addEventListener("click", this.handleClick.bind(this));
  }
  disconnectedCallback() {
    super.disconnectedCallback();
    window.removeEventListener("click", this.handleClick);
  }
  async willUpdate(changedProperties) {
    if (changedProperties.has("isOpen")) {
      await this.updateComplete;
      const changeEvent = new CustomEvent(
        "on-change",
        {
          detail: {
            isOpen: this.isOpen
          },
          bubbles: false,
          composed: true
        }
      );
      this.dispatchEvent(changeEvent);
    }
  }
  render() {
    const styles = this.styles({
      openTop: this.openTop,
      size: this.size,
      isRight: this.isRight,
      isFullWidth: this.isFullWidth
    });
    if (!this.isOpen) {
      return shared_tailwindElement_index.A;
    }
    return shared_tailwindElement_index.x`<div class="${styles} animate-fade-in animation-duration-200">
      <slot></slot>
    </div>`;
  }
};
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoDropdown.prototype, "id", 2);
__decorateClass([
  queryAssignedElements.n({ type: String, attribute: "trigger-id" })
], exports.LuksoDropdown.prototype, "triggerId", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "is-open", reflect: true })
], exports.LuksoDropdown.prototype, "isOpen", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "is-open-on-outside-click" })
], exports.LuksoDropdown.prototype, "isOpenOnOutsideClick", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "open-top" })
], exports.LuksoDropdown.prototype, "openTop", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "is-right" })
], exports.LuksoDropdown.prototype, "isRight", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "is-full-width" })
], exports.LuksoDropdown.prototype, "isFullWidth", 2);
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoDropdown.prototype, "size", 2);
exports.LuksoDropdown = __decorateClass([
  queryAssignedElements.e("lukso-dropdown")
], exports.LuksoDropdown);

exports.uniqId = uniqId;
