import { r as registerInstance, c as createEvent, h, H as Host } from './index-72f3c995.js';

const BsDropdownOption = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.mousefocus = createEvent(this, "mousefocus", 7);
    this.optionselect = 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 (h(Host, { "data-selected": this.selected ? '' : undefined, "data-variant": this.variant || undefined }, 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" }, h("slot", null))));
  }
  static get watchers() { return {
    "focused": ["onFocusChange"]
  }; }
};

export { BsDropdownOption as bs_dropdown_option };

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