// #region Imports
import { RendererServiceLocator } from '../../../../../Dom/Renderer';
import { on } from '@breadstone/mosaik-elements';
import { Attachable } from '../../../../Behaviors/Attachable';
import { Disableable } from '../../../../Behaviors/Disableable';
import { CustomElement } from '../../../Abstracts/CustomElement';
// #endregion
/**
 * The `{@link AdornerElement}` element.
 *
 * @public
 */
export class AdornerElement extends Disableable(Attachable(CustomElement)) {
    // #region Fields
    _adornerElement;
    _mouseEnterSubscription;
    _mouseMoveSubscription;
    _mouseLeaveSubscription;
    _mouseDownSubscription;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._adornerElement = null;
        this._mouseEnterSubscription = null;
        this._mouseMoveSubscription = null;
        this._mouseLeaveSubscription = null;
        this._mouseDownSubscription = null;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-adorner';
    }
    // #endregion
    // #region Methods
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        if (this.control) {
            this._mouseEnterSubscription = on(this.control, 'mouseenter', () => this.show());
            this._mouseMoveSubscription = on(this.control, 'mousemove', () => this.show());
            this._mouseLeaveSubscription = on(this.control, 'mouseleave', () => this.hide());
            this._mouseDownSubscription = on(this.control, 'mousedown', () => this.hide());
        }
    }
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        this._mouseEnterSubscription?.dispose();
        this._mouseMoveSubscription?.dispose();
        this._mouseLeaveSubscription?.dispose();
        this._mouseDownSubscription?.dispose();
        super.disconnectedCallback();
    }
    /**
     * @protected
     */
    create(config) {
        this._adornerElement = RendererServiceLocator.current.createElement(AdornerElement.is);
        if (this._adornerElement) {
            const classes = Array.isArray(config.classes) ? config.classes : [config.classes];
            classes.forEach((x) => {
                if (this._adornerElement) {
                    RendererServiceLocator.current.addClass(this._adornerElement, x ?? '');
                }
            });
            const parent = config.parent ?? RendererServiceLocator.current.parentNode(this);
            RendererServiceLocator.current.appendChild(parent, this._adornerElement);
        }
        return this._adornerElement;
    }
    /**
     * @protected
     */
    dispose() {
        if (this._adornerElement) {
            const parent = RendererServiceLocator.current.parentNode(this._adornerElement);
            if (parent && this._adornerElement) {
                RendererServiceLocator.current.removeChild(parent, this._adornerElement);
                this._adornerElement = null;
            }
        }
    }
}
//# sourceMappingURL=AdornerElement.js.map