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); }
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; }
import React, { useEffect, useState } from 'react';
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import { Box, Card, Drawer, PageWrapper, Typography, useMedia } from '../..';
import { Provider } from '../../common/Links/ReactRouterLinkHelper';
import CheckList from '.';
import { defaultCheckList, completedCheckList, defaultTaskInfoMap, header, labels, completedHeader, completedHeaderWithClose, useFakeCheckList, useFakeCheckListV2, getPercentage } from './mocks';
var meta = {
  component: CheckList,
  title: 'Molecules / CheckList',
  parameters: {
    viewport: {
      viewports: INITIAL_VIEWPORTS
    }
  },
  decorators: [function (Story) {
    return React.createElement(Provider, null, React.createElement(Story, null));
  }]
};
export default meta;
var CardContainer = function CardContainer(_ref) {
  var children = _ref.children;
  return React.createElement(Card, null, React.createElement(Box, {
    px: 3,
    py: 5,
    sm: {
      p: 5
    }
  }, children));
};
export var Default = function Default() {
  return React.createElement(CheckList, {
    checkList: defaultCheckList
  });
};
export var Empty = function Empty() {
  return React.createElement(CheckList, null);
};
export var MinimalExampleInCard = function MinimalExampleInCard() {
  return React.createElement(CardContainer, null, React.createElement(CheckList, {
    checkList: defaultCheckList,
    header: header,
    labels: labels,
    taskInfoMap: defaultTaskInfoMap,
    displayMode: "CARD"
  }));
};
export var MinimalExampleInDrawer = function MinimalExampleInDrawer() {
  return React.createElement(Drawer, null, React.createElement(CheckList, {
    checkList: defaultCheckList,
    header: header,
    labels: labels,
    taskInfoMap: defaultTaskInfoMap,
    displayMode: "DRAWER"
  }));
};
export var CompletedWithProgress = function CompletedWithProgress() {
  return React.createElement(CardContainer, null, React.createElement(CheckList, {
    checkList: completedCheckList,
    header: completedHeader,
    labels: labels,
    taskInfoMap: defaultTaskInfoMap,
    displayMode: "CARD"
  }));
};
export var CompletedWithProgressAndClose = function CompletedWithProgressAndClose() {
  return React.createElement(CardContainer, null, React.createElement(CheckList, {
    checkList: completedCheckList,
    header: completedHeaderWithClose,
    labels: labels,
    taskInfoMap: defaultTaskInfoMap,
    displayMode: "CARD"
  }));
};
export var CompletedSummaryOnly = function CompletedSummaryOnly() {
  return React.createElement(CardContainer, null, React.createElement(CheckList, {
    checkList: completedCheckList,
    header: completedHeader,
    labels: labels,
    taskInfoMap: defaultTaskInfoMap,
    showProgress: false,
    displayMode: "CARD"
  }));
};
export var FullExample = function FullExample() {
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var _useState3 = 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 = useFakeCheckList(TASK_COUNT),
    checkList = _useFakeCheckList.checkList,
    taskInfoMap = _useFakeCheckList.taskInfoMap;
  var isMobile = useMedia(function (theme) {
    return theme.media.lessThan(theme.breakpoints.sm);
  });
  var isCompleted = checkList.summary.percentageCompleted === checkList.summary.maxPercentage;
  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.createElement(CheckList.DrawerTitle, {
    title: header === null || header === void 0 ? void 0 : header.title,
    helpTitle: "What's this?",
    showHelpTitle: showHelp,
    onHelpClick: toggleHelp
  });
  var drawerDescription = React.createElement(React.Fragment, null, React.createElement(Typography, {
    type: "secondary"
  }, "Your account is "), React.createElement(Typography, {
    type: "title3",
    weight: "bold",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(checkList.summary.percentageCompleted, "% complete")), React.createElement(Box, {
    pt: 2
  }, React.createElement(Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.neutral.text_weak;
    }
  }, isCompleted ? "".concat(completedHeader.title, " ").concat(completedHeader.description) : 'Good job! Keep going.')));
  var cardTitle = isMobile ? 'Get started' : 'Get started checklist';
  var cardDescription = React.createElement("span", null, !isMobile && React.createElement(Typography, {
    type: "secondary"
  }, "Your account is "), React.createElement(Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(checkList.summary.percentageCompleted, "% complete")));
  return React.createElement(PageWrapper, {
    background: function background(t) {
      return t.colorTokens.neutral.background_medium;
    }
  }, React.createElement(Box, {
    sm: {
      p: 10
    }
  }, React.createElement(CardContainer, null, React.createElement(CheckList, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, header), {}, {
      title: isCompleted ? completedHeader.title : cardTitle,
      description: isCompleted ? completedHeader.description : cardDescription,
      onViewAll: toggleOpen
    }),
    labels: labels,
    taskInfoMap: taskInfoMap,
    displayMode: "CARD"
  }))), React.createElement(Drawer, {
    onClose: onClose,
    open: open,
    title: drawerTitle,
    preventOnClickOutsideDataAttributes: ['data-custom-prevent-click-outside']
  }, showHelp ? React.createElement(Typography, null, "Showing help here") : React.createElement(CheckList, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, header), {}, {
      description: drawerDescription
    }),
    labels: labels,
    taskInfoMap: taskInfoMap,
    displayMode: "DRAWER"
  })));
};
export var FullExampleMobile = {
  render: function render() {
    return React.createElement(FullExample, null);
  },
  parameters: {
    viewport: {
      defaultViewport: 'iphone5'
    }
  }
};
export var FullExampleTablet = {
  render: function render() {
    return React.createElement(FullExample, null);
  },
  parameters: {
    viewport: {
      defaultViewport: 'tablet'
    }
  }
};
export var CustomTaskInfoPercentage = function CustomTaskInfoPercentage() {
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    open = _useState6[0],
    setOpen = _useState6[1];
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    showHelp = _useState8[0],
    setShowHelp = _useState8[1];
  var _useFakeCheckListV = 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 = useMedia(function (theme) {
    return theme.media.lessThan(theme.breakpoints.sm);
  });
  var completedPercentage = getPercentage(checkList === null || checkList === void 0 ? void 0 : checkList.tasks, taskInfoMap);
  var isCompleted = completedPercentage === 100;
  var drawerTitle = React.createElement(CheckList.DrawerTitle, {
    title: header === null || header === void 0 ? void 0 : header.title,
    helpTitle: "What's this?",
    showHelpTitle: showHelp,
    onHelpClick: toggleHelp
  });
  var drawerDescription = React.createElement(React.Fragment, null, React.createElement(Typography, {
    type: "secondary"
  }, "Your account is "), React.createElement(Typography, {
    type: "title3",
    weight: "bold",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(completedPercentage, "% complete")), React.createElement(Box, {
    pt: 2
  }, React.createElement(Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.neutral.text_weak;
    }
  }, isCompleted ? "".concat(completedHeader.title, " ").concat(completedHeader.description) : 'Good job! Keep going.')));
  var cardTitle = isMobile ? 'Get started' : 'Get started checklist';
  var cardDescription = React.createElement("span", null, !isMobile && React.createElement(Typography, {
    type: "secondary"
  }, "Your account is "), React.createElement(Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(completedPercentage, "% complete")));
  return React.createElement(PageWrapper, {
    background: function background(t) {
      return t.colorTokens.neutral.background_medium;
    }
  }, React.createElement(Box, {
    sm: {
      p: 10
    }
  }, React.createElement(CardContainer, null, React.createElement(CheckList, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, header), {}, {
      title: isCompleted ? completedHeader.title : cardTitle,
      description: isCompleted ? completedHeader.description : cardDescription,
      onViewAll: toggleOpen
    }),
    labels: labels,
    taskInfoMap: taskInfoMap,
    displayMode: "CARD",
    summary: {
      percentageCompleted: completedPercentage,
      maxPercentage: 100
    }
  }))), React.createElement(Drawer, {
    onClose: onClose,
    open: open,
    title: drawerTitle,
    preventOnClickOutsideDataAttributes: ['data-custom-prevent-click-outside']
  }, showHelp ? React.createElement(Typography, null, "Showing help here") : React.createElement(CheckList, {
    checkList: checkList,
    header: _objectSpread(_objectSpread({}, header), {}, {
      description: drawerDescription
    }),
    labels: labels,
    taskInfoMap: taskInfoMap,
    displayMode: "DRAWER"
  })));
};