import { Component, h, Host, Listen, Method, Prop, Element, Event } from '@stencil/core';
export class Dropdown {
  constructor() {
    /**
     * Limit the height of the dropdown content. Pass the amount of pixel.
     */
    this.scrollable = 0;
    /**
     * If `true` the dropdown content is open.
     */
    this.isActive = false;
  }
  /**
   * Open the dropdown menu.
   */
  async open() {
    this.isActive = true;
    this.balChange.emit(this.isActive);
  }
  /**
   * Closes the dropdown menu.
   */
  async close() {
    this.isActive = false;
    this.balChange.emit(this.isActive);
  }
  /**
   * Open or closes the dropdown.
   */
  async toggle() {
    this.isActive = !this.isActive;
    this.balChange.emit(this.isActive);
  }
  /**
   * Returns the `HTMLDivElement` of the menu element
   */
  async getMenuElement() {
    return this.menuElement;
  }
  /**
   * Returns the `HTMLDivElement` of the content element
   */
  async getContentElement() {
    return this.contentElement;
  }
  async tabOutside(event) {
    if (event.key === 'Tab' && !this.element.contains(document.activeElement) && this.isActive) {
      await this.toggle();
    }
  }
  async clickOnOutside(event) {
    if (!this.element.contains(event.target) && this.isActive) {
      await this.toggle();
    }
  }
  get contentStyle() {
    if (this.scrollable === 0) {
      return {};
    }
    else {
      const maxHeight = `${this.scrollable}px`;
      return {
        'max-height': maxHeight,
        'overflow': 'auto',
      };
    }
  }
  render() {
    return (h(Host, null,
      h("div", { class: {
          'dropdown': true,
          'is-active': this.isActive,
        } },
        h("div", { class: "dropdown-trigger" },
          h("slot", { name: "trigger" })),
        h("div", { class: "dropdown-menu", id: "dropdown-menu", role: "menu", ref: el => (this.menuElement = el) },
          h("div", { class: "dropdown-content", style: this.contentStyle, ref: el => (this.contentElement = el) },
            h("slot", null))))));
  }
  static get is() { return "bal-dropdown"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["bal-dropdown.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["bal-dropdown.css"]
  }; }
  static get properties() { return {
    "scrollable": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Limit the height of the dropdown content. Pass the amount of pixel."
      },
      "attribute": "scrollable",
      "reflect": false,
      "defaultValue": "0"
    },
    "isActive": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "If `true` the dropdown content is open."
      },
      "attribute": "is-active",
      "reflect": true,
      "defaultValue": "false"
    }
  }; }
  static get events() { return [{
      "method": "balChange",
      "name": "balChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Listen when the dropdown opens or closes. Returns the current `isActive` value."
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }]; }
  static get methods() { return {
    "open": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Open the dropdown menu.",
        "tags": []
      }
    },
    "close": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Closes the dropdown menu.",
        "tags": []
      }
    },
    "toggle": {
      "complexType": {
        "signature": "() => Promise<void>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          }
        },
        "return": "Promise<void>"
      },
      "docs": {
        "text": "Open or closes the dropdown.",
        "tags": []
      }
    },
    "getMenuElement": {
      "complexType": {
        "signature": "() => Promise<HTMLDivElement>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          },
          "HTMLDivElement": {
            "location": "global"
          }
        },
        "return": "Promise<HTMLDivElement>"
      },
      "docs": {
        "text": "Returns the `HTMLDivElement` of the menu element",
        "tags": []
      }
    },
    "getContentElement": {
      "complexType": {
        "signature": "() => Promise<HTMLDivElement>",
        "parameters": [],
        "references": {
          "Promise": {
            "location": "global"
          },
          "HTMLDivElement": {
            "location": "global"
          }
        },
        "return": "Promise<HTMLDivElement>"
      },
      "docs": {
        "text": "Returns the `HTMLDivElement` of the content element",
        "tags": []
      }
    }
  }; }
  static get elementRef() { return "element"; }
  static get listeners() { return [{
      "name": "keyup",
      "method": "tabOutside",
      "target": "document",
      "capture": false,
      "passive": false
    }, {
      "name": "click",
      "method": "clickOnOutside",
      "target": "document",
      "capture": false,
      "passive": false
    }]; }
}
