Liferay.Loader.define("commerce-frontend-js@3.0.15/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");

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Lesser General Public License as published by the Free
     * Software Foundation; either version 2.1 of the License, or (at your option)
     * any later version.
     *
     * This library is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     * details.
     */
    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