Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/instance-list-page/modal/transition/bulk/select-transition-step/SelectTransitionStepCard.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/list', '@frontend-taglib-clay$clayui/panel', 'frontend-js-react-web$react', '../../../ModalProvider.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.Card = void 0;

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

    var _form = require("@frontend-taglib-clay$clayui/form");

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

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

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

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

    var _ModalProvider = require("../../../ModalProvider.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 };
    }

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var Card = function Card(_ref) {
      var cardIndex = _ref.cardIndex,
          _ref$nextTransitions = _ref.nextTransitions,
          nextTransitions = _ref$nextTransitions === void 0 ? [] : _ref$nextTransitions,
          tasks = _ref.tasks;

      var _useContext = (0, _react.useContext)(_ModalProvider.ModalContext),
          _useContext$bulkTrans = _useContext.bulkTransition,
          transition = _useContext$bulkTrans.transition,
          transitionTasks = _useContext$bulkTrans.transitionTasks,
          setBulkTransition = _useContext.setBulkTransition;

      var _useState = (0, _react.useState)(''),
          _useState2 = _slicedToArray(_useState, 2),
          comment = _useState2[0],
          setComment = _useState2[1];

      var _useState3 = (0, _react.useState)(true),
          _useState4 = _slicedToArray(_useState3, 2),
          hasError = _useState4[0],
          setHasError = _useState4[1];

      var _useState5 = (0, _react.useState)(''),
          _useState6 = _slicedToArray(_useState5, 2),
          selectedTransition = _useState6[0],
          setSelectedTransition = _useState6[1];

      var _useState7 = (0, _react.useState)(false),
          _useState8 = _slicedToArray(_useState7, 2),
          showAll = _useState8[0],
          setShowAll = _useState8[1];

      var errors = transition.errors,
          onGoing = transition.onGoing;

      (0, _react.useEffect)(function () {
        var cardError = errors;
        cardError[cardIndex] = hasError;
        setBulkTransition({
          transition: _objectSpread({}, transition, {
            errors: cardError,
            onGoing: onGoing
          }),
          transitionTasks: [].concat(_toConsumableArray(transitionTasks.filter(function (_ref3) {
            var workflowTaskId = _ref3.workflowTaskId;
            return !tasks.some(function (_ref4) {
              var id = _ref4.id;
              return id === workflowTaskId;
            });
          })), _toConsumableArray(tasks.map(function (_ref5) {
            var id = _ref5.id;
            return {
              comment: comment,
              transitionName: selectedTransition,
              workflowTaskId: id
            };
          })))
        }); // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [comment, selectedTransition, tasks]);
      return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_panel["default"].Body, {
        className: "transition-panel-body"
      }, _react["default"].createElement("div", {
        className: "table-container"
      }, _react["default"].createElement("div", {
        className: "table-visualization ".concat(showAll ? 'table-visualization-show-all' : '')
      }, _react["default"].createElement(_list["default"], {
        className: showAll ? 'table-show-all' : ''
      }, _react["default"].createElement(_list["default"].Item, {
        flex: true,
        style: {
          backgroundColor: '#F7F8F9'
        }
      }, _react["default"].createElement(_list["default"].ItemField, {
        style: {
          width: '20%'
        }
      }, _react["default"].createElement(_list["default"].ItemTitle, null, Liferay.Language.get('id'))), _react["default"].createElement(_list["default"].ItemField, {
        expand: true
      }, _react["default"].createElement(_list["default"].ItemTitle, null, Liferay.Language.get('item-subject')))), tasks.map(function (_ref6) {
        var assetTitle = _ref6.assetTitle,
            assetType = _ref6.assetType,
            id = _ref6.id,
            instanceId = _ref6.instanceId;
        return _react["default"].createElement(_list["default"].Item, {
          className: "list-item-no-border",
          flex: true,
          key: id
        }, _react["default"].createElement(_list["default"].ItemField, {
          style: {
            width: '20%'
          }
        }, _react["default"].createElement(_list["default"].ItemTitle, null, instanceId)), _react["default"].createElement(_list["default"].ItemField, {
          expand: true
        }, _react["default"].createElement(_list["default"].ItemText, null, "".concat(assetType, ": ").concat(assetTitle))));
      }))), tasks.length > 10 && _react["default"].createElement("span", {
        className: "mt-4 show-all-button",
        "data-testid": "showAllButton",
        onClick: function onClick() {
          setShowAll(!showAll);
        }
      }, !showAll ? Liferay.Language.get('show-all') : Liferay.Language.get('show-less'))), _react["default"].createElement("div", {
        className: "".concat(errors[cardIndex] && onGoing ? 'has-error' : '', " ml-3")
      }, _react["default"].createElement("label", {
        className: "control-label",
        htmlFor: "transitionSelect".concat(cardIndex)
      }, "".concat(Liferay.Language.get('transition-to')), ' ', _react["default"].createElement(_icon["default"], {
        className: "reference-mark text-warning",
        symbol: "asterisk"
      })), _react["default"].createElement(_form.ClaySelect, {
        "aria-label": "Select Label",
        className: "error-field",
        "data-testid": "transitionSelect",
        id: "transitionSelect".concat(cardIndex),
        onChange: function handleChange(_ref2) {
          var target = _ref2.target;
          var showError = target.value === '';

          errors[cardIndex] = showError;
          setBulkTransition({
            transition: {
              errors: errors,
              onGoing: onGoing
            },
            transitionTasks: transitionTasks
          });
          setHasError(showError);
          setSelectedTransition(target.value);
        }
      }, _react["default"].createElement(_form.ClaySelect.Option, {
        label: "",
        value: ""
      }), nextTransitions.map(function (nextTransition) {
        return _react["default"].createElement(_form.ClaySelect.Option, {
          key: nextTransition.name,
          label: nextTransition.label,
          value: nextTransition.name
        });
      })), errors[cardIndex] && onGoing && _react["default"].createElement("label", {
        className: "help-block"
      }, _react["default"].createElement(_icon["default"], {
        className: "mr-1",
        symbol: "exclamation-full"
      }), Liferay.Language.get('select-a-transition')))), _react["default"].createElement(Card.Footer, {
        comment: comment,
        setComment: setComment
      }));
    };

    exports.Card = Card;

    var Footer = function Footer(_ref7) {
      var comment = _ref7.comment,
          setComment = _ref7.setComment;

      var _useState9 = (0, _react.useState)(false),
          _useState10 = _slicedToArray(_useState9, 2),
          addComment = _useState10[0],
          setAddComment = _useState10[1];

      return _react["default"].createElement(_panel["default"].Footer, {
        className: "pb-3",
        "data-testid": "selectTransitionFooter"
      }, !addComment ? _react["default"].createElement(_button["default"], {
        "data-testid": "addCommentButton",
        displayType: "secondary",
        onClick: function onClick() {
          return setAddComment(true);
        }
      }, _react["default"].createElement(_icon["default"], {
        className: "mr-3",
        symbol: "message"
      }), Liferay.Language.get('add-comment')) : _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement("label", {
        htmlFor: "commentTextArea"
      }, "".concat(Liferay.Language.get('comment'), " (").concat(Liferay.Language.get('optional'), ")")), _react["default"].createElement(_form.ClayInput, {
        component: "textarea",
        "data-testid": "commentField",
        id: "commentTextArea",
        onChange: function onChange(_ref8) {
          var target = _ref8.target;
          return setComment(target.value);
        },
        placeholder: Liferay.Language.get('comment'),
        type: "text",
        value: comment
      })));
    };

    Card.Footer = Footer;
    //# sourceMappingURL=SelectTransitionStepCard.es.js.map
  }
});
//# sourceMappingURL=SelectTransitionStepCard.es.js.map