import { customElement } from "../../decorator.js";
import { unsafeCSS, LitElement, html } from "lit";
import compentStyle from "./scrollbar.css.js";
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = decorator(result) || result;
  return result;
};
let ObcScrollbar = class extends LitElement {
  constructor() {
    super(...arguments);
    this._resizeObserver = null;
  }
  render() {
    return html`
      <div class="wrapper">
        <slot></slot>
      </div>
    `;
  }
  firstUpdated() {
    const wrapper = this.shadowRoot?.querySelector(".wrapper");
    if (wrapper) {
      this._resizeObserver = new ResizeObserver(() => this._checkOverflow());
      this._resizeObserver.observe(wrapper);
      const slot = wrapper.querySelector("slot");
      slot?.addEventListener("slotchange", () => this._checkOverflow());
    }
  }
  disconnectedCallback() {
    super.disconnectedCallback();
    this._resizeObserver?.disconnect();
    this._resizeObserver = null;
  }
  _checkOverflow() {
    const wrapper = this.shadowRoot?.querySelector(".wrapper");
    if (!wrapper) return;
    const isOverflowing = wrapper.scrollHeight > wrapper.clientHeight;
    this.toggleAttribute("overflowing", isOverflowing);
  }
  /**
   * Scrolls the content area to the bottom.
   *
   * Useful for chat logs, notifications, or any scenario where the latest content should be visible.
   *
   * Throws an error if the internal wrapper is not found (should not occur in normal usage).
   */
  scrollToBottom() {
    const wrapper = this.shadowRoot?.querySelector(".wrapper");
    if (!wrapper) {
      throw new Error("Wrapper not found");
    }
    wrapper.scrollTop = wrapper.scrollHeight;
  }
};
ObcScrollbar.styles = unsafeCSS(compentStyle);
ObcScrollbar = __decorateClass([
  customElement("obc-scrollbar")
], ObcScrollbar);
export {
  ObcScrollbar
};
//# sourceMappingURL=scrollbar.js.map
