'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-128c5169.js');

const BsDropdownOption = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.mousefocus = index.createEvent(this, "mousefocus", 7);
    this.optionselect = index.createEvent(this, "optionselect", 7);
    this.value = undefined;
    this.variant = undefined;
    this.selected = false;
    this.shown = undefined;
    this.focused = undefined;
    this.index = undefined;
    this.dropdownId = undefined;
  }
  /** Handle focusing on initial load. */
  componentDidLoad() {
    this.onFocusChange(this.focused);
  }
  /** Handle focusing/blurring when the prop changes. */
  onFocusChange(newVal) {
    if (newVal) {
      this.option.focus();
    }
    else {
      this.option.blur();
    }
  }
  /** Handle various keyboard events for an option. */
  handleKeyDown(ev) {
    if (this.shown) {
      switch (ev.key) {
        case ' ':
          this.handleSelect();
          ev.preventDefault();
          break;
        case 'Enter':
          this.handleSelect();
          break;
        case 'NumpadEnter':
          this.handleSelect();
          break;
      }
    }
  }
  /** Handle mouse entering an option by notifying the parent. */
  handleMouseEnter() {
    this.mousefocus.emit(this.index);
  }
  /** Handle clicking on an option. */
  handleSelect() {
    this.optionselect.emit({ id: this.id, index: this.index, value: this.value });
  }
  /** Generate an ID for this option. */
  get id() {
    return `${this.dropdownId}-option-${this.index}`;
  }
  render() {
    return (index.h(index.Host, { "data-selected": this.selected ? '' : undefined, "data-variant": this.variant || undefined }, index.h("li", { role: "option", "data-selected": this.selected ? '' : undefined, "data-variant": this.variant || undefined, "aria-selected": this.selected ? 'true' : undefined, tabIndex: this.shown ? -1 : undefined, id: this.id, ref: el => this.option = el, part: "option" }, index.h("slot", null))));
  }
  static get watchers() { return {
    "focused": ["onFocusChange"]
  }; }
};

exports.bs_dropdown_option = BsDropdownOption;

//# sourceMappingURL=bs-dropdown-option.cjs.entry.js.map