'use strict';

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

const index = require('./index-305226cb.js');

const BsDropdownOption = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.optmouseenter = index.createEvent(this, "optmouseenter", 7);
    this.optselect = index.createEvent(this, "optselect", 7);
    this.value = undefined;
    this.variant = undefined;
    this.optionsId = undefined;
    this.selected = false;
    this.focused = false;
    this.index = undefined;
  }
  componentDidLoad() {
    this.onFocusChange(this.focused);
  }
  onFocusChange(isFocusedNow) {
    if (isFocusedNow) {
      this.option.focus();
    }
    else {
      this.option.blur();
    }
  }
  handleKeyDown(ev) {
    var _a;
    switch (ev.key) {
      case ' ':
      case 'Enter':
      case 'NumpadEnter':
        this.handleSelect();
        // If the option is a link, click it
        (_a = this.option.querySelector('a')) === null || _a === void 0 ? void 0 : _a.click();
        break;
    }
    ev.preventDefault();
  }
  /** Notify parent of mouse entering so it can set focus. */
  handleMouseEnter() {
    this.optmouseenter.emit(this.index);
  }
  handleSelect() {
    var _a;
    this.optselect.emit({ id: this.id, index: this.index, value: this.value });
    // If the option is a link, click it
    (_a = this.option.querySelector('a')) === null || _a === void 0 ? void 0 : _a.click();
  }
  /** Generate an ID. */
  get id() {
    return `${this.optionsId}-option-${this.index}`;
  }
  render() {
    return (index.h(index.Host, { value: this.value }, index.h("li", { role: "option", "data-selected": this.selected ? '' : undefined, "data-variant": this.variant || undefined, "aria-selected": this.selected ? 'true' : undefined, id: this.id, tabIndex: -1, ref: el => this.option = el }, index.h("slot", null))));
  }
  static get watchers() { return {
    "focused": ["onFocusChange"]
  }; }
};

const bsDropdownWithOptionsCss = "bs-dropdown-with-options{display:block}";

const BsDropdownWithOptions = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.optselected = index.createEvent(this, "optselected", 7);
    this.close = index.createEvent(this, "close", 7);
    this.enterend = index.createEvent(this, "enterend", 3);
    this.leaveend = index.createEvent(this, "leaveend", 3);
    this.toggleId = undefined;
    this.containerId = undefined;
    this.optionsId = undefined;
    this.width = undefined;
    this.top = false;
    this.center = false;
    this.label = undefined;
    this.selectedValue = undefined;
    this.enterControlled = false;
    this.enterTrigger = false;
    this.leaveTrigger = false;
    this.helperText = undefined;
    this.helperDescription = undefined;
    this.isVisible = false;
  }
  /** Dropdown has fully rendered */
  handleEnterEnd() {
    this.isVisible = true;
    this.enterend.emit();
  }
  handleOptSelected(ev) {
    ev.stopPropagation();
    this.isVisible = false;
    this.optselected.emit(ev.detail);
    this.close.emit();
  }
  handleClose(ev) {
    ev.stopPropagation();
    if (this.isVisible) {
      this.isVisible = false;
      this.close.emit();
    }
  }
  render() {
    return (index.h(index.Host, null, index.h("bs-dropdown", { width: this.width, top: this.top, center: this.center, toggleId: this.toggleId, containerId: this.containerId, enterControlled: this.enterControlled, enterTrigger: this.enterTrigger, leaveTrigger: this.leaveTrigger, helperText: this.helperText, helperDescription: this.helperDescription, onClose: (e) => this.handleClose(e), onEnterend: () => this.handleEnterEnd(), onLeaveend: () => this.leaveend.emit() }, index.h("bs-dropdown-option-list", { optionsId: this.optionsId, visible: this.isVisible, focusDelay: 0, label: this.label, selectedValue: this.selectedValue, onOptselected: (e) => this.handleOptSelected(e), onClose: (e) => this.handleClose(e) }, index.h("slot", null)))));
  }
};
BsDropdownWithOptions.style = bsDropdownWithOptionsCss;

exports.bs_dropdown_option = BsDropdownOption;
exports.bs_dropdown_with_options = BsDropdownWithOptions;

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