Liferay.Loader.define("commerce-frontend-js@3.0.43/utilities/actionItems/bulkActions", ['module', 'exports', 'require', 'frontend-js-web', '../index'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.listenToBulkActionStatus = listenToBulkActionStatus;

    var _frontendJsWeb = require("frontend-js-web");

    var _index = require("../index");

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */
    function listenToBulkActionStatus(id, batchTasksStatusApiUrl) {
      var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10000;
      var interval;
      return Promise.race([new Promise(function (resolve, reject) {
        interval = setInterval(function getBulkActionStatus() {
          return (0, _frontendJsWeb.fetch)("".concat(batchTasksStatusApiUrl, "/").concat(id), _index.fetchParams).then(function (response) {
            return response.json();
          }).then(function (jsonResponse) {
            if (jsonResponse.executeStatus === 'COMPLETED') {
              clearInterval(interval);
              resolve('success');
            }

            if (jsonResponse.executeStatus === 'FAILED') {
              clearInterval(interval);
              reject(jsonResponse.errorMessage);
            }
          });
        }, 1000);
      }), new Promise(function (_, reject) {
        return setTimeout(function () {
          clearInterval(interval);
          reject(Liferay.Language.get('request-timeout'));
        }, timeout);
      })]);
    }
    //# sourceMappingURL=bulkActions.js.map
  }
});
//# sourceMappingURL=bulkActions.js.map