// #region Imports
import { directive, PartType } from 'lit/directive.js';
import { DirectiveBase } from '../../../Directives/Abstracts/DirectiveBase';
import { StickyController } from './StickyController';
import { isReactiveControllerHost } from '../../../Controllers/Utils';
import { noChange } from 'lit';
// #endregion
/**
 * @private
 */
class StickyDirective extends DirectiveBase {
    // #region Fields
    _controller;
    _lastTop;
    _lastLeft;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `StickyDirective` class.
     *
     * @public
     */
    constructor(args) {
        super(args);
        if (args.type !== PartType.ELEMENT) {
            throw new Error('The `sticky` directive can only be used on elements.');
        }
        if (!isReactiveControllerHost(args.element)) {
            throw new Error('The `sticky` directive can only be used on reactive controller host elements.');
        }
        this._controller = new StickyController(args.element);
    }
    // #endregion
    // #region Methods
    /**
     * @public
     */
    render(top, left) {
        if (this._lastTop === top && this._lastLeft === left) {
            return noChange;
        }
        this._controller.top = (this._lastTop = top) ?? '0px';
        this._controller.left = (this._lastLeft = left) ?? '0px';
        return noChange;
    }
    /**
     * @public
     * @override
     */
    update(_part, [top, left]) {
        return this.render(top, left);
    }
}
/**
 * The `sticky` directive enables sticky positioning for any element using `StickyController`.
 *
 * @public
 * @param top - CSS top offset (e.g. `'0px'`).
 * @param left - CSS left offset (e.g. `'0px'`).
 */
export const sticky = directive(StickyDirective);
//# sourceMappingURL=StickyDirective.js.map