"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 = exports.MinimalExampleInDrawer = exports.MinimalExampleInCard = exports.FullExampleTablet = exports.FullExampleMobile = exports.FullExample = exports.Empty = exports.Default = exports.CustomTaskInfoPercentage = exports.CompletedWithProgressAndClose = exports.CompletedWithProgress = exports.CompletedSummaryOnly = void 0;
var _react = _interopRequireWildcard(require("react"));
var _addonViewport = require("@storybook/addon-viewport");
var _ = require("../..");
var _ReactRouterLinkHelper = require("../../common/Links/ReactRouterLinkHelper");
var _2 = _interopRequireDefault(require("."));
var _mocks = require("./mocks");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var meta = {
  component: _2.default,
  title: 'Molecules / CheckList',
  parameters: {
    viewport: {
      viewports: _addonViewport.INITIAL_VIEWPORTS
    }
  },
  decorators: [function (Story) {
    return _react.default.createElement(_ReactRouterLinkHelper.Provider, null, _react.default.createElement(Story, null));
  }]
};
var _default = exports.default = meta;
var CardContainer = function CardContainer(_ref) {
  var children = _ref.children;
  return _react.default.createElement(_.Card, null, _react.default.createElement(_.Box, {
    px: 3,
    py: 5,
    sm: {
      p: 5
    }
  }, children));
};
var Default = exports.Default = function Default() {
  return _react.default.createElement(_2.default, {
    checkList: _mocks.defaultCheckList
  });
};
var Empty = exports.Empty = function Empty() {
  return _react.default.createElement(_2.default, null);
};
var MinimalExampleInCard = exports.MinimalExampleInCard = function MinimalExampleInCard() {
  return _react.default.createElement(CardContainer, null, _react.default.createElement(_2.default, {
    checkList: _mocks.defaultCheckList,
    header: _mocks.header,
    labels: _mocks.labels,
    taskInfoMap: _mocks.defaultTaskInfoMap,
    displayMode: "CARD"
  }));
};
var MinimalExampleInDrawer = exports.MinimalExampleInDrawer = function MinimalExampleInDrawer() {
  return _react.default.createElement(_.Drawer, null, _react.default.createElement(_2.default, {
    checkList: _mocks.defaultCheckList,
    header: _mocks.header,
    labels: _mocks.labels,
    taskInfoMap: _mocks.defaultTaskInfoMap,
    displayMode: "DRAWER"
  }));
};
var CompletedWithProgress = exports.CompletedWithProgress = function CompletedWithProgress() {
  return _react.default.createElement(CardContainer, null, _react.default.createElement(_2.default, {
    checkList: _mocks.completedCheckList,
    header: _mocks.completedHeader,
    labels: _mocks.labels,
    taskInfoMap: _mocks.defaultTaskInfoMap,
    displayMode: "CARD"
  }));
};
var CompletedWithProgressAndClose = exports.CompletedWithProgressAndClose = function CompletedWithProgressAndClose() {
  return _react.default.createElement(CardContainer, null, _react.default.createElement(_2.default, {
    checkList: _mocks.completedCheckList,
    header: _mocks.completedHeaderWithClose,
    labels: _mocks.labels,
    taskInfoMap: _mocks.defaultTaskInfoMap,
    displayMode: "CARD"
  }));
};
var CompletedSummaryOnly = exports.CompletedSummaryOnly = function CompletedSummaryOnly() {
  return _react.default.createElement(CardContainer, null, _react.default.createElement(_2.default, {
    checkList: _mocks.completedCheckList,
    header: _mocks.completedHeader,
    labels: _mocks.labels,
    taskInfoMap: _mocks.defaultTaskInfoMap,
    showProgress: false,
    displayMode: "CARD"
  }));
};
var FullExample = exports.FullExample = function FullExample() {
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = _slicedToArray(_useState3, 2),
    showHelp = _useState4[0],
    setShowHelp = _useState4[1];
  var toggleOpen = function toggleOpen() {
    setOpen(!open);
  };
  var onClose = function onClose() {
    setOpen(false);
  };
  var toggleHelp = function toggleHelp() {
    setShowHelp(!showHelp);
  };
  var TASK_COUNT = 5;
  var _useFakeCheckList = (0, _mocks.useFakeCheckList)(TASK_COUNT),
    checkList = _useFakeCheckList.checkList,
    taskInfoMap = _useFakeCheckList.taskInfoMap;
  var isMobile = (0, _.useMedia)(function (theme) {
    return theme.media.lessThan(theme.breakpoints.sm);
  });
  var isCompleted = checkList.summary.percentageCompleted === checkList.summary.maxPercentage;
  (0, _react.useEffect)(function () {
    var percentageCompleted = checkList.tasks.reduce(function (pre, cur) {
      return cur.taskState === 'COMPLETED' ? pre + cur.percentage : cur.percentage + 0;
    }, 0);
    checkList.summary.percentageCompleted = percentageCompleted;
  }, [checkList]);
  var drawerTitle = _react.default.createElement(_2.default.DrawerTitle, {
    title: _mocks.header === null || _mocks.header === void 0 ? void 0 : _mocks.header.title,
    helpTitle: "What's this?",
    showHelpTitle: showHelp,
    onHelpClick: toggleHelp
  });
  var drawerDescription = _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_.Typography, {
    type: "secondary"
  }, "Your account is "), _react.default.createElement(_.Typography, {
    type: "title3",
    weight: "bold",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(checkList.summary.percentageCompleted, "% complete")), _react.default.createElement(_.Box, {
    pt: 2
  }, _react.default.createElement(_.Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.neutral.text_weak;
    }
  }, isCompleted ? "".concat(_mocks.completedHeader.title, " ").concat(_mocks.completedHeader.description) : 'Good job! Keep going.')));
  var cardTitle = isMobile ? 'Get started' : 'Get started checklist';
  var cardDescription = _react.default.createElement("span", null, !isMobile && _react.default.createElement(_.Typography, {
    type: "secondary"
  }, "Your account is "), _react.default.createElement(_.Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(checkList.summary.percentageCompleted, "% complete")));
  return _react.default.createElement(_.PageWrapper, {
    background: function background(t) {
      return t.colorTokens.neutral.background_medium;
    }
  }, _react.default.createElement(_.Box, {
    sm: {
      p: 10
    }
  }, _react.default.createElement(CardContainer, null, _react.default.createElement(_2.default, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, _mocks.header), {}, {
      title: isCompleted ? _mocks.completedHeader.title : cardTitle,
      description: isCompleted ? _mocks.completedHeader.description : cardDescription,
      onViewAll: toggleOpen
    }),
    labels: _mocks.labels,
    taskInfoMap: taskInfoMap,
    displayMode: "CARD"
  }))), _react.default.createElement(_.Drawer, {
    onClose: onClose,
    open: open,
    title: drawerTitle,
    preventOnClickOutsideDataAttributes: ['data-custom-prevent-click-outside']
  }, showHelp ? _react.default.createElement(_.Typography, null, "Showing help here") : _react.default.createElement(_2.default, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, _mocks.header), {}, {
      description: drawerDescription
    }),
    labels: _mocks.labels,
    taskInfoMap: taskInfoMap,
    displayMode: "DRAWER"
  })));
};
var FullExampleMobile = exports.FullExampleMobile = {
  render: function render() {
    return _react.default.createElement(FullExample, null);
  },
  parameters: {
    viewport: {
      defaultViewport: 'iphone5'
    }
  }
};
var FullExampleTablet = exports.FullExampleTablet = {
  render: function render() {
    return _react.default.createElement(FullExample, null);
  },
  parameters: {
    viewport: {
      defaultViewport: 'tablet'
    }
  }
};
var CustomTaskInfoPercentage = exports.CustomTaskInfoPercentage = function CustomTaskInfoPercentage() {
  var _useState5 = (0, _react.useState)(false),
    _useState6 = _slicedToArray(_useState5, 2),
    open = _useState6[0],
    setOpen = _useState6[1];
  var _useState7 = (0, _react.useState)(false),
    _useState8 = _slicedToArray(_useState7, 2),
    showHelp = _useState8[0],
    setShowHelp = _useState8[1];
  var _useFakeCheckListV = (0, _mocks.useFakeCheckListV2)(5),
    checkList = _useFakeCheckListV.checkList,
    taskInfoMap = _useFakeCheckListV.taskInfoMap;
  var toggleOpen = function toggleOpen() {
    setOpen(!open);
  };
  var onClose = function onClose() {
    setOpen(false);
  };
  var toggleHelp = function toggleHelp() {
    setShowHelp(!showHelp);
  };
  var isMobile = (0, _.useMedia)(function (theme) {
    return theme.media.lessThan(theme.breakpoints.sm);
  });
  var completedPercentage = (0, _mocks.getPercentage)(checkList === null || checkList === void 0 ? void 0 : checkList.tasks, taskInfoMap);
  var isCompleted = completedPercentage === 100;
  var drawerTitle = _react.default.createElement(_2.default.DrawerTitle, {
    title: _mocks.header === null || _mocks.header === void 0 ? void 0 : _mocks.header.title,
    helpTitle: "What's this?",
    showHelpTitle: showHelp,
    onHelpClick: toggleHelp
  });
  var drawerDescription = _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_.Typography, {
    type: "secondary"
  }, "Your account is "), _react.default.createElement(_.Typography, {
    type: "title3",
    weight: "bold",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(completedPercentage, "% complete")), _react.default.createElement(_.Box, {
    pt: 2
  }, _react.default.createElement(_.Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.neutral.text_weak;
    }
  }, isCompleted ? "".concat(_mocks.completedHeader.title, " ").concat(_mocks.completedHeader.description) : 'Good job! Keep going.')));
  var cardTitle = isMobile ? 'Get started' : 'Get started checklist';
  var cardDescription = _react.default.createElement("span", null, !isMobile && _react.default.createElement(_.Typography, {
    type: "secondary"
  }, "Your account is "), _react.default.createElement(_.Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(completedPercentage, "% complete")));
  return _react.default.createElement(_.PageWrapper, {
    background: function background(t) {
      return t.colorTokens.neutral.background_medium;
    }
  }, _react.default.createElement(_.Box, {
    sm: {
      p: 10
    }
  }, _react.default.createElement(CardContainer, null, _react.default.createElement(_2.default, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, _mocks.header), {}, {
      title: isCompleted ? _mocks.completedHeader.title : cardTitle,
      description: isCompleted ? _mocks.completedHeader.description : cardDescription,
      onViewAll: toggleOpen
    }),
    labels: _mocks.labels,
    taskInfoMap: taskInfoMap,
    displayMode: "CARD",
    summary: {
      percentageCompleted: completedPercentage,
      maxPercentage: 100
    }
  }))), _react.default.createElement(_.Drawer, {
    onClose: onClose,
    open: open,
    title: drawerTitle,
    preventOnClickOutsideDataAttributes: ['data-custom-prevent-click-outside']
  }, showHelp ? _react.default.createElement(_.Typography, null, "Showing help here") : _react.default.createElement(_2.default, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, _mocks.header), {}, {
      description: drawerDescription
    }),
    labels: _mocks.labels,
    taskInfoMap: taskInfoMap,
    displayMode: "DRAWER"
  })));
};