import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-92f6d7ee.js';

const BsTransition = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.enterend = createEvent(this, "enterend", 3);
    this.leaveend = createEvent(this, "leaveend", 3);
    this.timers = {
      enterMountTimer: undefined,
      enterDurationTimer: undefined,
      leaveMountTimer: undefined,
      leaveDurationTimer: undefined
    };
    this.enterClass = undefined;
    this.enterAttribute = undefined;
    this.enterDuration = undefined;
    this.leaveClass = undefined;
    this.leaveAttribute = undefined;
    this.leaveDuration = undefined;
    this.enterControlled = false;
    this.enterTrigger = false;
    this.leaveTrigger = false;
  }
  /** Lazy-load the child element if it's available. */
  get childEl() {
    if (!this._childEl && this.hostEl.children.length > 0) {
      this._childEl = this.hostEl.children[0];
    }
    return this._childEl;
  }
  componentDidLoad() {
    if (!this.enterControlled) {
      this.handleEnterTransition();
    }
  }
  handleEnterTrigger(newValue) {
    if (this.enterControlled && newValue) {
      this.handleEnterTransition();
    }
  }
  handleLeaveTrigger(newValue) {
    if (newValue) {
      this.handleLeaveTransition();
    }
  }
  handleEnterTransition() {
    // Wait a few milliseconds to allow for the element to be rendered
    this.timers.enterMountTimer = setTimeout(() => {
      this.addEnterClassAndAttribute();
      this.timers.enterDurationTimer = setTimeout(() => {
        this.enterend.emit();
      }, this.enterDuration);
    }, 10);
  }
  /** Adds the "enter" class and/or attribute */
  addEnterClassAndAttribute() {
    if (this.enterClass) {
      this.childEl.classList.add(this.enterClass);
    }
    if (this.enterAttribute) {
      this.childEl.setAttribute(this.enterAttribute, '');
    }
  }
  handleLeaveTransition() {
    var _a;
    // Add/Remove the classes
    this.removeEnterClassAndAttribute();
    this.addLeaveClassAndAttribute();
    this.timers.leaveDurationTimer = setTimeout(() => {
      this.leaveend.emit();
    }, (_a = this.leaveDuration) !== null && _a !== void 0 ? _a : this.enterDuration);
  }
  /** Adds the "leave" class and/or attribute */
  addLeaveClassAndAttribute() {
    if (this.leaveClass) {
      this.childEl.classList.add(this.leaveClass);
    }
    if (this.leaveAttribute) {
      this.childEl.setAttribute(this.leaveAttribute, '');
    }
  }
  /** Removes the "enter" class and/or attribute */
  removeEnterClassAndAttribute() {
    if (this.enterClass) {
      this.childEl.classList.remove(this.enterClass);
    }
    if (this.enterAttribute) {
      this.childEl.removeAttribute(this.enterAttribute);
    }
  }
  disconnectedCallback() {
    // Cleanup timers
    Object.keys(this.timers).forEach(timer => {
      if (this.timers[timer]) {
        clearTimeout(this.timers[timer]);
        this.timers[timer] = undefined;
      }
    });
  }
  render() {
    return (h(Host, null, h("slot", null)));
  }
  get hostEl() { return getElement(this); }
  static get watchers() { return {
    "enterTrigger": ["handleEnterTrigger"],
    "leaveTrigger": ["handleLeaveTrigger"]
  }; }
};

export { BsTransition as bs_transition };

//# sourceMappingURL=bs-transition.entry.js.map