// #region Imports
import { directive, PartType } from 'lit/directive.js';
import { RendererServiceLocator } from '../../../../Dom/Renderer';
import { DirectiveBase } from '../../../Directives/Abstracts/DirectiveBase';
import { FocusRingElement } from './FocusRingElement';
// #endregion
/**
 * @private
 */
class FocusRingDirective extends DirectiveBase {
    // #region Fields
    _focusRingElement = null;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `FocusRingDirective` class.
     *
     * @public
     */
    constructor(args) {
        super(args);
        // Ensure the directive is used on elements only
        if (args.type !== PartType.ELEMENT) {
            throw new Error('The `focusRing` 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._focusRingElement) {
            this._focusRingElement = new FocusRingElement();
            RendererServiceLocator.current.appendChild(hostElement, this._focusRingElement);
        }
        Object.assign(this._focusRingElement, config);
        this._focusRingElement.attach(hostElement);
        return this.render(config);
    }
    /**
     * @public
     */
    disconnected() {
        if (this._focusRingElement) {
            this._focusRingElement.detach();
            this._focusRingElement.remove();
            this._focusRingElement = null;
        }
    }
}
/**
 * @public
 */
export const focusRing = directive(FocusRingDirective);
//# sourceMappingURL=FocusRingDirective.js.map