// #region Imports
import { directive, PartType } from 'lit/directive.js';
import { RendererServiceLocator } from '../../../../Dom/Renderer';
import { DirectiveBase } from '../../../Directives/Abstracts/DirectiveBase';
import { TooltipElement } from './TooltipElement';
// #endregion
/**
 * @private
 */
class TooltipDirective extends DirectiveBase {
    // #region Fields
    _tooltipElement = null;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `TooltipDirective` class.
     *
     * @public
     */
    constructor(args) {
        super(args);
        // Ensure the directive is used on elements only
        if (args.type !== PartType.ELEMENT) {
            throw new Error('The `tooltip` directive can only be used on elements.');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @public
     */
    render(_config) {
        // Config is passed for rendering but is handled in the update method
        return '';
    }
    /**
     * @public
     * @override
     */
    update(part, [config]) {
        const hostElement = part.element;
        if (!this._tooltipElement) {
            this._tooltipElement = new TooltipElement();
            RendererServiceLocator.current.insertAfter(hostElement, this._tooltipElement);
        }
        Object.assign(this._tooltipElement, config);
        this._tooltipElement.attach(hostElement);
        return this.render(config);
    }
    /**
     * @public
     */
    disconnected() {
        if (this._tooltipElement) {
            this._tooltipElement.detach();
            this._tooltipElement.remove();
            this._tooltipElement = null;
        }
    }
}
/**
 * @public
 */
export const tooltip = directive(TooltipDirective);
//# sourceMappingURL=TooltipDirective.js.map