"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _reactRedux = require("react-redux");

var _baseActionComponent = _interopRequireDefault(require("../app/base-action-component"));

var _errorMessage = require("../app/error-message");

var _app = require("../app");

var _designSystem = require("../design-system");

var _wrapper = _interopRequireDefault(require("./utils/wrapper"));

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

const ResourceAction = props => {
  const {
    resources,
    match
  } = props;
  const {
    resourceId,
    actionName
  } = match.params;
  const resource = resources.find(r => r.id === resourceId);

  if (!resource) {
    return _react.default.createElement(_errorMessage.NoResourceError, {
      resourceId: resourceId
    });
  }

  const action = resource.resourceActions.find(r => r.name === actionName);

  if (!action) {
    return _react.default.createElement(_errorMessage.NoActionError, {
      resourceId: resourceId,
      actionName: actionName
    });
  }

  const ActionWrapper = action.showInDrawer ? _designSystem.Drawer : _wrapper.default;
  return _react.default.createElement(ActionWrapper, null, !(action === null || action === void 0 ? void 0 : action.showInDrawer) ? _react.default.createElement(_app.ActionHeader, {
    resource: resource,
    action: action
  }) : '', _react.default.createElement(_baseActionComponent.default, {
    action: action,
    resource: resource
  }));
};

const mapStateToProps = state => ({
  resources: state.resources
});

var _default = (0, _reactRedux.connect)(mapStateToProps)(ResourceAction);

exports.default = _default;