export class SpinnerController {
    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();
    }
    static get is() { return "anj-spinner-controller"; }
    static get methods() { return {
        "spinWhile": {
            "complexType": {
                "signature": "(work: Promise<any>, target?: HTMLElement) => Promise<any>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }, {
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "HTMLElement": {
                        "location": "global"
                    }
                },
                "return": "Promise<any>"
            },
            "docs": {
                "text": "Spins while an arbitrary promise completes.\nReturns the value of the promise",
                "tags": []
            }
        },
        "spin": {
            "complexType": {
                "signature": "(target?: HTMLElement) => Promise<HTMLAnjSpinnerElement>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "HTMLAnjSpinnerElement": {
                        "location": "global"
                    },
                    "HTMLElement": {
                        "location": "global"
                    }
                },
                "return": "Promise<HTMLAnjSpinnerElement>"
            },
            "docs": {
                "text": "Loads the spinner",
                "tags": []
            }
        },
        "stop": {
            "complexType": {
                "signature": "() => Promise<void>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    }
                },
                "return": "Promise<void>"
            },
            "docs": {
                "text": "Unload the spinner",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "element"; }
}
