// #region Imports
import { InfiniteScrollController } from '../../Controllers/InfiniteScrollController';
import { noChange } from 'lit';
import { AsyncDirectiveBase, PartType } from '../Abstracts/AsyncDirectiveBase';
import { directive } from 'lit/async-directive.js';
// #endregion
/**
 * Represents the `InfiniteScrollDirective` class.
 *
 * @private
 */
class InfiniteScrollDirective extends AsyncDirectiveBase {
    // #region Fields
    _controller = null;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `InfiniteScrollDirective` class.
     *
     * @public
     * @param args - The directive arguments.
     */
    constructor(args) {
        super(args);
        if (args.type !== PartType.ELEMENT) {
            throw new Error('The `infiniteScroll` directive can only be used on elements.');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @public
     */
    render(_config) {
        return noChange;
    }
    /**
     * @public
     * @override
     */
    update(part, [config]) {
        if (!this._controller) {
            // host is the element the directive is attached to
            this._controller = new InfiniteScrollController(this.internals.element, {
                ...config
            });
            this._controller.initialize();
        }
        else {
            this._controller.disabled = !!config.disabled;
            this._controller.delay = config.delay ?? 0;
            this._controller.offset = config.offset ?? 0;
            this._controller.directionReversed = !!config.directionReversed;
            this._controller.container = part.element;
        }
        return this.render(config);
    }
    /**
     * @public
     * @override
     */
    disconnected() {
        if (this._controller) {
            this._controller.disconnect();
            this._controller = null;
        }
    }
}
/**
 * The `infiniteScroll` directive is used to implement infinite scrolling functionality on an element.
 *
 * @public
 */
export const infiniteScroll = directive(InfiniteScrollDirective);
//# sourceMappingURL=InfiniteScrollDirective.js.map