Liferay.Loader.define("segments-experiment-web@2.0.19/js/components/SegmentsExperimentsActions.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/link', '@frontend-taglib-clay$clayui/modal', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', '../context.es', '../state/actions.es', '../util/statuses.es', './../state/context.es', './ReviewExperimentModal.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports["default"] = void 0;

    var _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

    var _link = _interopRequireDefault(require("@frontend-taglib-clay$clayui/link"));

    var _modal = require("@frontend-taglib-clay$clayui/modal");

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _context = _interopRequireDefault(require("../context.es"));

    var _actions = require("../state/actions.es");

    var _statuses = require("../util/statuses.es");

    var _context2 = require("./../state/context.es");

    var _ReviewExperimentModal = require("./ReviewExperimentModal.es");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { "default": obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj["default"] = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { "default": obj };
    }

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * The contents of this file are subject to the terms of the Liferay Enterprise
     * Subscription License ("License"). You may not use this file except in
     * compliance with the License. You can obtain a copy of the License by
     * contacting Liferay, Inc. See the License for the specific language governing
     * permissions and limitations under the License, including but not limited to
     * distribution rights of the Software.
     */
    function SegmentsExperimentsActions(_ref) {
      var onEditSegmentsExperimentStatus = _ref.onEditSegmentsExperimentStatus;

      var _useContext = (0, _react.useContext)(_context2.StateContext),
          experiment = _useContext.experiment,
          reviewExperimentModal = _useContext.reviewExperimentModal,
          variants = _useContext.variants,
          viewExperimentURL = _useContext.viewExperimentURL;

      var dispatch = (0, _react.useContext)(_context2.DispatchContext);

      var _useModal = (0, _modal.useModal)({
        onClose: function onClose() {
          return dispatch((0, _actions.closeReviewAndRunExperiment)());
        }
      }),
          observer = _useModal.observer,
          onClose = _useModal.onClose;

      var _useContext2 = (0, _react.useContext)(_context["default"]),
          APIService = _useContext2.APIService;

      return _react["default"].createElement(_react["default"].Fragment, null, experiment.status.value === _statuses.STATUS_DRAFT && _react["default"].createElement(_button["default"], {
        className: "w-100",
        onClick: function onClick() {
          return dispatch((0, _actions.reviewAndRunExperiment)());
        }
      }, Liferay.Language.get('review-and-run-test')), experiment.status.value === _statuses.STATUS_RUNNING && _react["default"].createElement(_button["default"], {
        className: "w-100",
        displayType: "secondary",
        onClick: function onClick() {
          var confirmed = confirm(Liferay.Language.get('are-you-sure-you-want-to-terminate-this-test'));

          if (confirmed) {
            onEditSegmentsExperimentStatus(experiment, _statuses.STATUS_TERMINATED);
          }
        }
      }, Liferay.Language.get('terminate-test')), experiment.status.value === _statuses.STATUS_PAUSED && _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_button["default"], {
        className: "w-100",
        onClick: function onClick() {
          return onEditSegmentsExperimentStatus(experiment, _statuses.STATUS_RUNNING);
        }
      }, Liferay.Language.get('restart-test'))), experiment.status.value === _statuses.STATUS_FINISHED_WINNER && _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_button["default"], {
        className: "w-100",
        displayType: "secondary",
        onClick: _handleDiscardExperiment
      }, Liferay.Language.get('discard-test'))), experiment.status.value === _statuses.STATUS_FINISHED_NO_WINNER && _react["default"].createElement(_button["default"], {
        className: "w-100",
        displayType: "primary",
        onClick: _handleDiscardExperiment
      }, Liferay.Language.get('discard-test')), reviewExperimentModal.active && _react["default"].createElement(_ReviewExperimentModal.ReviewExperimentModal, {
        modalObserver: observer,
        onModalClose: onClose,
        onRun: function _handleRunExperiment(_ref2) {
          var confidenceLevel = _ref2.confidenceLevel,
              splitVariantsMap = _ref2.splitVariantsMap;
          var body = {
            confidenceLevel: confidenceLevel,
            segmentsExperimentId: experiment.segmentsExperimentId,
            segmentsExperimentRels: JSON.stringify(splitVariantsMap),
            status: _statuses.STATUS_RUNNING
          };
          return APIService.runExperiment(body).then(function (response) {
            var segmentsExperiment = response.segmentsExperiment;
            dispatch((0, _actions.runExperiment)({
              experiment: segmentsExperiment,
              splitVariantsMap: splitVariantsMap
            }));
          });
        },
        variants: variants
      }), viewExperimentURL && _react["default"].createElement(_link["default"], {
        className: "btn btn-secondary btn-sm mt-3 w-100",
        displayType: "secondary",
        href: viewExperimentURL,
        target: "_blank"
      }, Liferay.Language.get('view-data-in-analytics-cloud'), _react["default"].createElement(_icon["default"], {
        className: "ml-2",
        symbol: "shortcut"
      })));

      function _handleDiscardExperiment() {
        var body = {
          segmentsExperimentId: experiment.segmentsExperimentId,
          status: _statuses.STATUS_COMPLETED,
          winnerSegmentsExperienceId: experiment.segmentsExperienceId
        };
        APIService.publishExperience(body).then(function (_ref3) {
          var segmentsExperiment = _ref3.segmentsExperiment;
          dispatch((0, _actions.updateSegmentsExperimentStatus)(segmentsExperiment));
        });
      }
    }

    var _default = SegmentsExperimentsActions;
    exports["default"] = _default;
    //# sourceMappingURL=SegmentsExperimentsActions.es.js.map
  }
});
//# sourceMappingURL=SegmentsExperimentsActions.es.js.map