"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.LoadingRowState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
var _bexCore = require("@wix/bex-core");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
class LoadingRowState {
  constructor() {
    (0, _defineProperty2.default)(this, "loadingItems", _mobx.observable.map([], {
      deep: false
    }));
    (0, _defineProperty2.default)(this, "animationDuration", 2000);
    (0, _defineProperty2.default)(this, "animationData", undefined);
    (0, _defineProperty2.default)(this, "LottieRenderer", undefined);
    (0, _defineProperty2.default)(this, "loadAnimationAssetsTask", new _bexCore.TaskState());
    (0, _mobx.makeObservable)(this, {
      animationData: _mobx.observable.ref,
      LottieRenderer: _mobx.observable.ref,
      addLoadingItem: _mobx.action,
      removeLoadingItem: _mobx.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 Promise.resolve().then(() => _interopRequireWildcard(require('lottie-react')))).default;
  }
  async setAnimationData() {
    this.animationData = (await Promise.resolve().then(() => _interopRequireWildcard(require('./aiLoadingLottie')))).aiLoadingLottie;
  }
  _loadAnimationAssets() {
    this.loadAnimationAssetsTask.runOnce(async () => {
      await Promise.all([this.setLottieRenderer(), this.setAnimationData()]);
    });
  }
}
exports.LoadingRowState = LoadingRowState;
//# sourceMappingURL=LoadingRowState.js.map