"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AutomationModalBody = void 0;
var _react = _interopRequireWildcard(require("react"));
var _menuContext = require("../../menu-context");
var _errorState = require("../error-state");
var _ruleList = require("../rule-list");
var _skeleton = require("../skeleton");
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 AutomationModalBody = exports.AutomationModalBody = function AutomationModalBody(_ref) {
  var selectedRule = _ref.selectedRule,
    setSelectedRule = _ref.setSelectedRule;
  var _useAutomationMenu = (0, _menuContext.useAutomationMenu)(),
    triggerFetch = _useAutomationMenu.triggerFetch,
    initialised = _useAutomationMenu.initialised,
    rules = _useAutomationMenu.rules,
    fetchError = _useAutomationMenu.fetchError;
  (0, _react.useEffect)(function () {
    void triggerFetch();
    // Want to ensure that triggerFetch is only called once when the component is mounted.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  if (!initialised) {
    return /*#__PURE__*/_react.default.createElement(_skeleton.Skeleton, {
      lineCount: 10
    });
  } else if (fetchError && rules.length === 0) {
    return /*#__PURE__*/_react.default.createElement(_errorState.AutomationModalErrorState, null);
  }
  return /*#__PURE__*/_react.default.createElement(_ruleList.AutomationModalRuleList, {
    selectedRule: selectedRule,
    setSelectedRule: setSelectedRule
  });
};