import { r as registerInstance, c as getElement } from './core-b78a8f7e.js';

const SpinnerController = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
    }
    componentDidLoad() {
        this.targetEl = this.element.parentElement;
    }
    componentDidUnload() {
        if (this.spinner && this.spinner.parentElement) {
            this.spinner.parentElement.removeChild(this.spinner);
            this.spinner = undefined;
        }
    }
    /**
     * Spins while an arbitrary promise completes.
     * Returns the value of the promise
     */
    async spinWhile(work, target) {
        if (!this.spinner) {
            await this.spin(target);
        }
        const completed = await work;
        await this.stop();
        return completed;
    }
    /**
     * Loads the spinner
     */
    async spin(target) {
        const targetEl = target || this.targetEl;
        this.spinner = document.createElement('anj-spinner');
        this.spinner.setAttribute('fixed', 'true');
        targetEl.appendChild(this.spinner);
        return this.spinner;
    }
    /**
     * Unload the spinner
     */
    async stop() {
        return this.componentDidUnload();
    }
    get element() { return getElement(this); }
};

export { SpinnerController as anj_spinner_controller };
