import { action, makeObservable, observable } from 'mobx';
import { TaskState } from '@wix/bex-core';
export class LoadingRowState {
    constructor() {
        this.loadingItems = observable.map([], {
            deep: false,
        });
        this.animationDuration = 2000;
        this.animationData = undefined;
        this.LottieRenderer = undefined;
        this.loadAnimationAssetsTask = new TaskState();
        makeObservable(this, {
            animationData: observable.ref,
            LottieRenderer: observable.ref,
            addLoadingItem: action,
            removeLoadingItem: action,
        });
    }
    addLoadingItem(id) {
        this._loadAnimationAssets();
        this.loadingItems.set(id, {
            id,
            startTime: Date.now(),
        });
        window.setTimeout(() => {
            this.removeLoadingItem(id);
        }, this.animationDuration);
    }
    removeLoadingItem(id) {
        this.loadingItems.delete(id);
    }
    isLoading(id) {
        return this.loadingItems.has(id);
    }
    async setLottieRenderer() {
        this.LottieRenderer = (await import('lottie-react')).default;
    }
    async setAnimationData() {
        this.animationData = (await import('./aiLoadingLottie')).aiLoadingLottie;
    }
    _loadAnimationAssets() {
        this.loadAnimationAssetsTask.runOnce(async () => {
            await Promise.all([this.setLottieRenderer(), this.setAnimationData()]);
        });
    }
}
//# sourceMappingURL=LoadingRowState.js.map