"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _ = require("../..");
var _CheckListStep = _interopRequireDefault(require("./CheckListStep"));
var _Title = _interopRequireDefault(require("./Title"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var CheckListInner = function CheckListInner(_ref) {
  var tasks = _ref.tasks,
    taskInfoMap = _ref.taskInfoMap,
    subHeader = _ref.subHeader,
    labels = _ref.labels,
    displayMode = _ref.displayMode;
  return _react.default.createElement("div", null, subHeader && _react.default.createElement(_.Box, {
    py: 3
  }, _react.default.createElement(_.Typography, {
    type: "primary",
    weight: "extrabold"
  }, subHeader)), _react.default.createElement(_.List, null, _react.default.createElement(_.Flexbox, {
    container: true,
    gap: 2,
    direction: "column"
  }, tasks === null || tasks === void 0 ? void 0 : tasks.map(function (task) {
    return _react.default.createElement(_.ListItem, {
      key: task.taskId
    }, _react.default.createElement(_CheckListStep.default, _extends({
      task: task,
      taskInfo: taskInfoMap === null || taskInfoMap === void 0 ? void 0 : taskInfoMap[task.taskId]
    }, labels, {
      displayMode: displayMode
    })));
  }))));
};
var CheckList = function CheckList(_ref2) {
  var _checkList$tasks, _checkList$tasks2;
  var checkList = _ref2.checkList,
    header = _ref2.header,
    taskInfoMap = _ref2.taskInfoMap,
    labels = _ref2.labels,
    _ref2$displayMode = _ref2.displayMode,
    displayMode = _ref2$displayMode === void 0 ? 'CARD' : _ref2$displayMode,
    showProgress = _ref2.showProgress,
    summary = _ref2.summary;
  var tasksToDo = checkList === null || checkList === void 0 || (_checkList$tasks = checkList.tasks) === null || _checkList$tasks === void 0 ? void 0 : _checkList$tasks.filter(function (t) {
    return t.taskState === 'INCOMPLETE';
  });
  var tasksCompleted = checkList === null || checkList === void 0 || (_checkList$tasks2 = checkList.tasks) === null || _checkList$tasks2 === void 0 ? void 0 : _checkList$tasks2.filter(function (t) {
    return t.taskState === 'DISMISSED' || t.taskState === 'COMPLETED';
  });
  if (!checkList) return null;
  var isDrawer = displayMode === 'DRAWER';
  return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_Title.default, _extends({}, checkList.summary ? _objectSpread({}, checkList.summary) : _objectSpread({}, summary), header, {
    displayMode: displayMode,
    showProgress: showProgress
  })), isDrawer && _react.default.createElement(_.Flexbox, {
    container: true,
    direction: "column",
    gap: 4
  }, !!(tasksToDo !== null && tasksToDo !== void 0 && tasksToDo.length) && _react.default.createElement(CheckListInner, {
    tasks: tasksToDo,
    taskInfoMap: taskInfoMap,
    subHeader: (labels === null || labels === void 0 ? void 0 : labels.todoLabel) || 'To do',
    labels: labels,
    displayMode: displayMode
  }), !!(tasksCompleted !== null && tasksCompleted !== void 0 && tasksCompleted.length) && _react.default.createElement(CheckListInner, {
    tasks: tasksCompleted,
    taskInfoMap: taskInfoMap,
    subHeader: (labels === null || labels === void 0 ? void 0 : labels.completedLabel) || 'Completed',
    labels: labels,
    displayMode: displayMode
  })), !isDrawer && !!(tasksToDo !== null && tasksToDo !== void 0 && tasksToDo.length) && _react.default.createElement(_.Box, {
    pt: 5
  }, _react.default.createElement(CheckListInner, {
    tasks: tasksToDo,
    taskInfoMap: taskInfoMap,
    labels: labels,
    displayMode: displayMode
  })));
};
var _default = exports.default = CheckList;