Liferay.Loader.define("portal-workflow-metrics-web@2.0.46/js/components/instance-list-page/InstanceListPageItem.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/layout', '@frontend-taglib-clay$clayui/table', 'frontend-js-react-web$react', '../../shared/components/quick-action-kebab/QuickActionKebab.es', '../../shared/util/moment.es', '../../shared/util/util.es', '../AppContext.es', './InstanceListPageProvider.es', './modal/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.Item = void 0;

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

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

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

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

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

    var _QuickActionKebab = _interopRequireDefault(require("../../shared/components/quick-action-kebab/QuickActionKebab.es"));

    var _moment = _interopRequireDefault(require("../../shared/util/moment.es"));

    var _util = require("../../shared/util/util.es");

    var _AppContext = require("../AppContext.es");

    var _InstanceListPageProvider = require("./InstanceListPageProvider.es");

    var _ModalProvider = require("./modal/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 _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    var getSLAStatusIcon = function getSLAStatusIcon(slaStatus) {
      var items = {
        OnTime: {
          bgColor: 'bg-success-light',
          iconColor: 'text-success',
          iconName: 'check-circle'
        },
        Overdue: {
          bgColor: 'bg-danger-light',
          iconColor: 'text-danger',
          iconName: 'exclamation-circle'
        },
        Untracked: {
          bgColor: 'bg-info-light',
          iconColor: 'text-info',
          iconName: 'hr'
        }
      };
      return items[slaStatus] || items.Untracked;
    };

    var Item = function Item(_ref) {
      var isAdmin = _ref.isAdmin,
          totalCount = _ref.totalCount,
          instance = _objectWithoutProperties(_ref, ["isAdmin", "totalCount"]);

      var _useContext = (0, _react.useContext)(_AppContext.AppContext),
          userId = _useContext.userId;

      var _useContext2 = (0, _react.useContext)(_InstanceListPageProvider.InstanceListContext),
          _useContext2$selected = _useContext2.selectedItems,
          selectedItems = _useContext2$selected === void 0 ? [] : _useContext2$selected,
          setInstanceId = _useContext2.setInstanceId,
          setSelectAll = _useContext2.setSelectAll,
          setSelectedItems = _useContext2.setSelectedItems;

      var _useContext3 = (0, _react.useContext)(_ModalProvider.ModalContext),
          openModal = _useContext3.openModal;

      var assetTitle = instance.assetTitle,
          assetType = instance.assetType,
          _instance$assignees = instance.assignees,
          assignees = _instance$assignees === void 0 ? [] : _instance$assignees,
          completed = instance.completed,
          creator = instance.creator,
          dateCreated = instance.dateCreated,
          id = instance.id,
          slaStatus = instance.slaStatus,
          _instance$taskNames = instance.taskNames,
          taskNames = _instance$taskNames === void 0 ? [Liferay.Language.get('not-available')] : _instance$taskNames;
      var checked = !!selectedItems.find(function (item) {
        return item.id === id;
      });
      var assignedToUser = !!assignees.find(function (_ref2) {
        var id = _ref2.id;
        return id === Number(userId);
      });
      var assigneeNames = assignees.map(function (user) {
        return user.name;
      }).join(', ');

      var _ref3 = assignees.find(function (_ref4) {
        var id = _ref4.id;
        return id === -1;
      }) || {},
          reviewer = _ref3.reviewer;

      var disableCheckbox = completed;

      if (!isAdmin) {
        disableCheckbox = !assignedToUser && !reviewer;
      }

      var slaStatusIcon = getSLAStatusIcon(slaStatus);
      var formattedAssignees = !completed ? assigneeNames : Liferay.Language.get('not-available');
      var formattedTaskNames = !completed ? taskNames.join(', ') : Liferay.Language.get('completed');

      return (/*#__PURE__*/_react.default.createElement(_table.default.Row, {
          className: checked ? 'table-active' : ''
        }, /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, /*#__PURE__*/_react.default.createElement("div", {
          className: "table-first-element-group"
        }, /*#__PURE__*/_react.default.createElement(_form.ClayCheckbox, {
          checked: checked,
          disabled: disableCheckbox,
          onChange: function handleCheck(_ref5) {
            var target = _ref5.target;
            var updatedItems = target.checked ? [].concat(_toConsumableArray(selectedItems), [instance]) : selectedItems.filter(function (item) {
              return item.id !== id;
            });
            setSelectAll(totalCount > 0 && totalCount === updatedItems.length);
            setSelectedItems(updatedItems);
          }
        }), /*#__PURE__*/_react.default.createElement("span", {
          className: "sticker sticker-sm ".concat(slaStatusIcon.bgColor)
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "inline-item"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: slaStatusIcon.iconColor,
          symbol: slaStatusIcon.iconName
        }))))), /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, /*#__PURE__*/_react.default.createElement("span", {
          className: "link-text",
          onClick: function onClick() {
            setInstanceId(id);
            openModal('instanceDetails');
          },
          tabIndex: "-1"
        }, /*#__PURE__*/_react.default.createElement("strong", null, id))), /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, "".concat(assetType, ": ").concat(assetTitle)), /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, formattedTaskNames), /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, formattedAssignees), /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, creator ? creator.name : ''), /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, _moment.default.utc(dateCreated).format(Liferay.Language.get('mmm-dd-yyyy-lt'))), /*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          style: {
            paddingRight: '0rem'
          }
        }, /*#__PURE__*/_react.default.createElement(QuickActionMenu, {
          disabled: disableCheckbox,
          instance: instance
        })))
      );
    };

    exports.Item = Item;

    var QuickActionMenu = function QuickActionMenu(_ref6) {
      var disabled = _ref6.disabled,
          instance = _ref6.instance;

      var _useContext4 = (0, _react.useContext)(_ModalProvider.ModalContext),
          openModal = _useContext4.openModal,
          setSingleTransition = _useContext4.setSingleTransition;

      var _useContext5 = (0, _react.useContext)(_InstanceListPageProvider.InstanceListContext),
          setSelectedItem = _useContext5.setSelectedItem,
          setSelectedItems = _useContext5.setSelectedItems;

      var _instance$transitions = instance.transitions,
          transitions = _instance$transitions === void 0 ? [] : _instance$transitions,
          _instance$taskNames2 = instance.taskNames,
          taskNames = _instance$taskNames2 === void 0 ? [] : _instance$taskNames2;

      var handleClick = function handleClick(bulkModal, singleModal) {
        if (taskNames.length > 1) {
          setSelectedItems([instance]);
          openModal(bulkModal);
        } else {
          setSelectedItem(instance);
          openModal(singleModal);
        }
      };

      var transitionLabel = (0, _util.capitalize)(Liferay.Language.get('transition'));
      var updateDueDateItem = {
        icon: 'date',
        label: Liferay.Language.get('update-due-date'),
        onClick: function onClick() {
          return handleClick('bulkUpdateDueDate', 'updateDueDate');
        }
      };
      var kebabItems = [{
        icon: 'change',
        label: Liferay.Language.get('reassign-task'),
        onClick: function onClick() {
          return handleClick('bulkReassign', 'singleReassign');
        }
      }, updateDueDateItem];

      if (transitions.length > 0) {
        var transitionItems = [{
          type: 'divider'
        }, {
          items: transitions.map(function (_ref7) {
            var label = _ref7.label,
                name = _ref7.name;
            return {
              label: label,
              name: name,
              onClick: function onClick() {
                openModal('singleTransition');
                setSelectedItem(instance);
                setSingleTransition({
                  title: label,
                  transitionName: name
                });
              }
            };
          }),
          label: transitionLabel,
          name: transitionLabel,
          type: 'group'
        }];
        kebabItems.push.apply(kebabItems, transitionItems);
      } else if (transitions.length === 0 && taskNames.length > 1) {
        kebabItems.splice(1, 1, {
          label: transitionLabel,
          onClick: function onClick() {
            setSelectedItems([instance]);
            openModal('bulkTransition');
          }
        }, updateDueDateItem);
      }

      return (/*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, null, /*#__PURE__*/_react.default.createElement(_QuickActionKebab.default, {
          disabled: disabled,
          items: kebabItems
        }))
      );
    };

    Item.QuickActionMenu = QuickActionMenu;
    //# sourceMappingURL=InstanceListPageItem.es.js.map
  }
});
//# sourceMappingURL=InstanceListPageItem.es.js.map