"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AutomationModal = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _analyticsNext = require("@atlaskit/analytics-next");
var _modalDialog = _interopRequireWildcard(require("@atlaskit/modal-dialog"));
var _menuContext = require("./menu-context");
var _body = require("./sub-components/body");
var _executionStateMessage = require("./sub-components/execution-state-message");
var _footer = require("./sub-components/footer");
var _header = require("./sub-components/header");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(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 (var _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); }
var AutomationModal = exports.AutomationModal = function AutomationModal(_ref) {
  var baseAutomationUrl = _ref.baseAutomationUrl,
    siteAri = _ref.siteAri,
    objectAri = _ref.objectAri,
    canManageAutomation = _ref.canManageAutomation,
    onClose = _ref.onClose,
    onCloseComplete = _ref.onCloseComplete,
    modalTitle = _ref.modalTitle,
    modalDescription = _ref.modalDescription,
    emptyStateDescription = _ref.emptyStateDescription,
    emptyStateAdminDescription = _ref.emptyStateAdminDescription,
    analyticsSource = _ref.analyticsSource;
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
    createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
  var _useState = (0, _react.useState)(),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    selectedRule = _useState2[0],
    setSelectedRule = _useState2[1];
  (0, _react.useEffect)(function () {
    createAnalyticsEvent({
      type: 'sendScreenEvent',
      data: {
        name: analyticsSource
      }
    }).fire();
  }, [createAnalyticsEvent, analyticsSource]);
  return /*#__PURE__*/_react.default.createElement(_menuContext.AutomationMenuContextContainer, {
    baseAutomationUrl: baseAutomationUrl,
    objectAri: objectAri,
    siteAri: siteAri,
    canManageAutomation: canManageAutomation,
    analyticsSource: analyticsSource,
    emptyStateDescription: emptyStateDescription,
    emptyStateAdminDescription: emptyStateAdminDescription,
    onRuleInvocationSuccess: onClose,
    onRuleInvocationFailure: function onRuleInvocationFailure() {
      return setSelectedRule(undefined);
    }
  }, function () {
    return /*#__PURE__*/_react.default.createElement(_modalDialog.default, {
      onClose: onClose,
      onCloseComplete: onCloseComplete,
      width: 600,
      height: 480,
      testId: "smart-card-automation-action-modal"
    }, /*#__PURE__*/_react.default.createElement(_header.AutomationModalHeader, {
      modalTitle: modalTitle,
      modalDescription: modalDescription
    }), /*#__PURE__*/_react.default.createElement(_modalDialog.ModalBody, null, /*#__PURE__*/_react.default.createElement(_body.AutomationModalBody, {
      selectedRule: selectedRule,
      setSelectedRule: setSelectedRule
    })), /*#__PURE__*/_react.default.createElement(_executionStateMessage.AutomationModalExecutionState, null), /*#__PURE__*/_react.default.createElement(_modalDialog.ModalFooter, null, /*#__PURE__*/_react.default.createElement(_footer.AutomationModalFooter, {
      selectedRule: selectedRule,
      onClose: onClose
    })));
  });
};