/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { c as customElement } from "../../chunks/runtime.js";
import { css, html } from "lit";
import { LitElement, createEvent } from "@arcgis/lumina";
import { u as useFocusTrap } from "../../chunks/useFocusTrap.js";
import { u as useSetFocus } from "../../chunks/useSetFocus.js";
const styles = css`:host{display:contents}:host([hidden]){display:none}[hidden]{display:none}`;
class FocusTrap extends LitElement {
  constructor() {
    super(...arguments);
    this._active = false;
    this.focusSetter = useSetFocus()(this);
    this.focusTrapController = useFocusTrap({
      focusTrapOptions: {
        onActivate: () => {
          this.setActive(true);
        },
        onDeactivate: () => {
          this.setActive(false);
        }
      }
    })(this);
    this.focusTrapDisabled = false;
    this.calciteFocusTrapActiveChange = createEvent({ cancelable: false });
  }
  static {
    this.properties = { focusTrapDisabled: [7, {}, { reflect: true, type: Boolean }], active: [32, {}, { attribute: false, readOnly: true }], focusTrapDisabledOverride: [0, {}, { attribute: false }], focusTrapOptions: [0, {}, { attribute: false }] };
  }
  static {
    this.styles = styles;
  }
  get active() {
    return this._active;
  }
  async activate() {
    this.focusTrapController.activate();
  }
  async deactivate() {
    this.focusTrapController.deactivate();
  }
  async setFocus(options) {
    return this.focusSetter(() => this.el, options);
  }
  async updateFocusTrapElements(extraContainers) {
    this.focusTrapController.setExtraContainers(extraContainers);
    this.focusTrapController.updateContainerElements();
  }
  setActive(active) {
    const oldActive = this._active;
    this._active = active;
    this.requestUpdate("active", oldActive);
    this.calciteFocusTrapActiveChange.emit();
  }
  render() {
    return html`<slot></slot>`;
  }
}
customElement("calcite-focus-trap", FocusTrap);
export {
  FocusTrap
};
