import { __classPrivateFieldGet } from 'tslib';
import { ɵɵdefineInjectable, ɵɵinject, RendererFactory2, Injectable } from '@angular/core';

var _createLoading;
class SdLoadingService {
    constructor(rendererFactory) {
        this.loadingId = "L8d556b9b-f6dd-46e9-9710-757e65d82839";
        this.loadingMap = new WeakMap();
        this.start = (element = "body") => {
            const ele = document.querySelector(element);
            if (ele && !this.loadingMap.has(ele)) {
                const loadingElement = __classPrivateFieldGet(this, _createLoading).call(this);
                ele.appendChild(loadingElement);
                this.loadingMap.set(ele, loadingElement);
            }
        };
        this.isLoading = (element = "body") => {
            const ele = document.querySelector(element);
            return ele && this.loadingMap.has(ele);
        };
        this.stop = (element = "body") => {
            const ele = document.querySelector(element);
            if (ele && this.loadingMap.has(ele)) {
                const loadingElement = this.loadingMap.get(ele);
                loadingElement === null || loadingElement === void 0 ? void 0 : loadingElement.remove();
                this.loadingMap.delete(ele);
            }
        };
        _createLoading.set(this, () => {
            const renderer = this.renderer;
            const container = this.renderer.createElement('div');
            const icon = this.renderer.createElement('i');
            const containerStyle = {
                position: 'absolute',
                top: 0,
                left: 0,
                height: '100%',
                width: '100%',
                opacity: 0.6,
                background: '#FFFFFF',
                'z-index': 99999
            };
            const iconStyle = {
                position: 'absolute',
                top: 'calc(50% - 2.5rem)',
                left: 'calc(50% - 2.5rem)',
            };
            renderer.addClass(container, 'sd-loading');
            renderer.setAttribute(container, 'id', this.loadingId);
            Object.entries(containerStyle).forEach((entry) => {
                renderer.setStyle(container, entry[0], entry[1]);
            });
            renderer.setAttribute(icon, 'class', 'fa fa-5x fa-spinner fa-pulse');
            Object.entries(iconStyle).forEach((entry) => {
                renderer.setStyle(icon, entry[0], entry[1]);
            });
            container.appendChild(icon);
            return container;
        });
        this.renderer = rendererFactory.createRenderer(null, null);
    }
}
_createLoading = new WeakMap();
SdLoadingService.ɵprov = ɵɵdefineInjectable({ factory: function SdLoadingService_Factory() { return new SdLoadingService(ɵɵinject(RendererFactory2)); }, token: SdLoadingService, providedIn: "root" });
SdLoadingService.decorators = [
    { type: Injectable, args: [{
                providedIn: "root",
            },] }
];
SdLoadingService.ctorParameters = () => [
    { type: RendererFactory2 }
];

/*
 * Public API Surface of superdev-angular-core
 */

/**
 * Generated bundle index. Do not edit.
 */

export { SdLoadingService };
//# sourceMappingURL=sd-angular-core-loading.js.map
