var _defaultCheckList$tas, _defaultCheckList$sum;
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 _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 _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; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 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); }
import React, { useState } from 'react';
import { action } from '@storybook/addon-actions';
import { Icon, Typography } from '../..';
export var defaultCheckList = {
  summary: {
    maxPercentage: 100,
    percentageCompleted: 30
  },
  tasks: [{
    taskId: 'TASK_1',
    taskState: 'INCOMPLETE',
    percentage: 30
  }, {
    taskId: 'TASK_2',
    taskState: 'INCOMPLETE',
    percentage: 30
  }, {
    taskId: 'TASK_3',
    taskState: 'DISMISSED',
    percentage: 20
  }, {
    taskId: 'TASK_4',
    taskState: 'DISMISSED',
    percentage: 20
  }]
};
export var completedCheckList = {
  summary: _objectSpread(_objectSpread({}, defaultCheckList.summary), {}, {
    percentageCompleted: 100
  }),
  tasks: (_defaultCheckList$tas = defaultCheckList.tasks) === null || _defaultCheckList$tas === void 0 ? void 0 : _defaultCheckList$tas.map(function (task) {
    return _objectSpread(_objectSpread({}, task), {}, {
      taskState: 'COMPLETED'
    });
  })
};
export var defaultTaskInfoMap = {
  TASK_1: {
    icon: React.createElement(Icon.Search24, null),
    title: 'Find investments',
    description: 'Discover stocks and funds to invest in.',
    startAction: {
      label: 'Start guide',
      onClick: action('startAction: Find investments')
    },
    onDismiss: action('dismiss: Find investments')
  },
  TASK_2: {
    icon: React.createElement(Icon.Account24, null),
    title: 'Second task money',
    description: 'Transfer money to your account.',
    startAction: {
      label: 'Deposit now',
      to: '/deposit-money'
    },
    onDismiss: action('dismiss: Deposit money')
  },
  TASK_3: {
    icon: React.createElement(Icon.Deposit24, null),
    title: 'Third task money',
    description: 'Transfer money to your account.',
    startAction: {
      label: 'Deposit now',
      to: '/deposit-money'
    },
    onDismiss: action('dismiss: Deposit money')
  },
  TASK_4: {
    icon: React.createElement(Icon.Book24, null),
    title: 'Fourth task money',
    description: 'Transfer money to your account.',
    startAction: {
      label: 'Deposit now',
      to: '/deposit-money'
    },
    onDismiss: action('dismiss: Deposit money')
  }
};
export var defaultCheckListV2 = {
  onboardingCompletedAt: '2023-10-03T07:01:57.702Z',
  tasks: [{
    taskId: 'TASK_1',
    taskState: 'COMPLETED',
    completedAt: '2023-10-03T07:01:57.702Z'
  }, {
    taskId: 'TASK_2',
    taskState: 'COMPLETED',
    completedAt: '2023-10-03T07:01:57.702Z'
  }, {
    taskId: 'TASK_3',
    taskState: 'INCOMPLETE',
    completedAt: '2023-10-03T07:01:57.702Z'
  }, {
    taskId: 'TASK_4',
    taskState: 'INCOMPLETE',
    completedAt: '2023-10-03T07:01:57.702Z'
  }],
  customerProgress: 'LEVEL_1'
};
export var customPercentageTaskInfoMap = {
  TASK_1: {
    icon: React.createElement(Icon.Search24, null),
    title: 'Find investments',
    description: 'Discover stocks and funds to invest in.',
    customPercentage: 25,
    startAction: {
      label: 'Start guide',
      onClick: action('startAction: Find investments')
    },
    onDismiss: action('dismiss: Find investments')
  },
  TASK_2: {
    icon: React.createElement(Icon.Account24, null),
    title: 'Second task',
    description: 'Transfer money to your account.',
    customPercentage: 25,
    startAction: {
      label: 'Deposit now',
      to: '/deposit-money'
    },
    onDismiss: action('dismiss: Deposit money')
  },
  TASK_3: {
    icon: React.createElement(Icon.Deposit24, null),
    title: 'Third task',
    description: 'Transfer money to your account.',
    customPercentage: 25,
    startAction: {
      label: 'Deposit now',
      to: '/deposit-money'
    },
    onDismiss: action('dismiss: Deposit money')
  },
  TASK_4: {
    icon: React.createElement(Icon.Book24, null),
    title: 'Fourth task',
    description: 'Transfer money to your account.',
    customPercentage: 25,
    startAction: {
      label: 'Deposit now',
      to: '/deposit-money'
    },
    onDismiss: action('dismiss: Deposit money')
  }
};
var generateNumSeries = function generateNumSeries(ratio, n, total) {
  var x = total * (1 - 1 / ratio) / (Math.pow(ratio, n) - 1);
  var arr = _toConsumableArray(new Array(n)).map(function (_) {
    x *= ratio;
    return Math.round(x);
  });
  arr[n - 1] = total - arr.slice(0, -1).reduce(function (a, c) {
    return a + c;
  });
  return arr;
};
var generateTasks = function generateTasks(taskCount) {
  var percentages = generateNumSeries(1.5, taskCount, 100);
  var tasks = _toConsumableArray(Array(taskCount).keys()).map(function (i) {
    return {
      taskId: "TASK_".concat(i + 1),
      taskState: i < taskCount / 3 ? 'COMPLETED' : 'INCOMPLETE',
      percentage: i < taskCount / 3 ? percentages.shift() || 0 : percentages.pop() || 0
    };
  });
  return tasks;
};
var generateV2Tasks = function generateV2Tasks(taskCount) {
  var tasks = _toConsumableArray(Array(taskCount).keys()).map(function (i) {
    return {
      taskId: "TASK_".concat(i + 1),
      taskState: i < taskCount / 3 ? 'COMPLETED' : 'INCOMPLETE',
      completedAt: '2023-10-03T07:01:57.702Z'
    };
  });
  return tasks;
};
export var generateCheckList = function generateCheckList(taskCount) {
  var tasks = generateTasks(taskCount);
  var percentageCompleted = tasks.reduce(function (prev, curr) {
    return curr.taskState === 'COMPLETED' && curr.percentage ? prev + curr.percentage : prev;
  }, 0);
  return {
    summary: {
      maxPercentage: 100,
      percentageCompleted: percentageCompleted
    },
    tasks: tasks
  };
};
export var useFakeCheckListV2 = function useFakeCheckListV2(taskCount) {
  var initialTasks = generateV2Tasks(taskCount);
  var _useState = useState(initialTasks),
    _useState2 = _slicedToArray(_useState, 2),
    tasks = _useState2[0],
    setTasks = _useState2[1];
  var dismissTask = function dismissTask(taskId) {
    var updatedTasks = tasks.map(function (task) {
      if (task.taskId === taskId) {
        return _objectSpread(_objectSpread({}, task), {}, {
          taskState: 'COMPLETED'
        });
      }
      return task;
    });
    setTasks(updatedTasks);
  };
  var taskInfoMap = generateTaskInfoMap(taskCount, dismissTask);
  var percentageCompleted = getPercentage(tasks, taskInfoMap);
  var checkList = {
    onboardingCompletedAt: percentageCompleted === 100 ? '2023-10-03T07:01:57.702Z' : undefined,
    tasks: tasks,
    customerProgress: percentageCompleted === 100 ? 'ONBOARDED' : 'LEVEL_1'
  };
  return {
    checkList: checkList,
    taskInfoMap: taskInfoMap
  };
};
export var useFakeCheckList = function useFakeCheckList(taskCount) {
  var initialTasks = generateTasks(taskCount);
  var _useState3 = useState(initialTasks),
    _useState4 = _slicedToArray(_useState3, 2),
    tasks = _useState4[0],
    setTasks = _useState4[1];
  var dismissTask = function dismissTask(taskId) {
    var updatedTasks = tasks.map(function (task) {
      if (task.taskId === taskId) {
        return _objectSpread(_objectSpread({}, task), {}, {
          taskState: 'COMPLETED'
        });
      }
      return task;
    });
    setTasks(updatedTasks);
  };
  var percentageCompleted = tasks.reduce(function (prev, curr) {
    return curr.taskState === 'COMPLETED' && curr.percentage ? prev + curr.percentage : prev;
  }, 0);
  var taskInfoMap = generateTaskInfoMap(taskCount, dismissTask);
  var checkList = {
    summary: {
      maxPercentage: 100,
      percentageCompleted: percentageCompleted
    },
    tasks: tasks
  };
  return {
    checkList: checkList,
    taskInfoMap: taskInfoMap
  };
};
export var generateTaskInfoMap = function generateTaskInfoMap(taskCount, dismissTask) {
  var iconArray = Object === null || Object === void 0 ? void 0 : Object.entries(Icon).filter(function (_ref) {
    var _ref2 = _slicedToArray(_ref, 2),
      iconName = _ref2[0],
      _ = _ref2[1];
    return iconName.endsWith('24');
  }).map(function (_ref3) {
    var _ref4 = _slicedToArray(_ref3, 2),
      key = _ref4[0],
      IconComponent = _ref4[1];
    return React.createElement(IconComponent, {
      key: key
    });
  });
  return _toConsumableArray(Array(taskCount).keys()).reduce(function (obj, i) {
    return _objectSpread(_objectSpread({}, obj), {}, _defineProperty({}, "TASK_".concat(i + 1), {
      icon: iconArray[i],
      title: "This is the title for task ".concat(i + 1),
      description: "This is the description for task ".concat(i + 1, ". ").repeat(i % 3 + 1),
      customPercentage: i + 1 ? 20 : undefined,
      startAction: {
        label: i % 2 ? "Link to step ".concat(i + 1) : "Open step ".concat(i + 1),
        onClick: action("startAction (".concat(i % 2 ? 'link' : 'button', ") task ").concat(i + 1)),
        to: i % 2 ? "/route".concat(i + 1) : undefined
      },
      onDismiss: dismissTask ? function () {
        return dismissTask("TASK_".concat(i + 1));
      } : action("onDismiss task ".concat(i + 1))
    }));
  }, {});
};
export var getPercentage = function getPercentage(tasks, taskInfoMap) {
  var taskInfo = tasks.map(function (task) {
    return task.taskState === 'COMPLETED' ? taskInfoMap[task.taskId] : undefined;
  });
  var customPercentage = taskInfo.map(function (info) {
    return (info === null || info === void 0 ? void 0 : info.customPercentage) || 0;
  });
  var sum = customPercentage.reduce(function (accumulator, currentValue) {
    if (accumulator !== undefined && currentValue !== undefined) {
      return accumulator + currentValue;
    }
    return accumulator || 0 + currentValue || 0;
  }, 0);
  return sum;
};
export var header = {
  title: 'Get started checklist',
  description: React.createElement("span", null, React.createElement(Typography, {
    type: "secondary"
  }, "Your account is "), React.createElement(Typography, {
    type: "secondary",
    color: function color(t) {
      return t.colorTokens.action.text_default;
    }
  }, "".concat(defaultCheckList === null || defaultCheckList === void 0 || (_defaultCheckList$sum = defaultCheckList.summary) === null || _defaultCheckList$sum === void 0 ? void 0 : _defaultCheckList$sum.percentageCompleted, "% complete"))),
  viewAllLabel: 'View all',
  onViewAll: action('onViewAll'),
  onClose: action('onClose')
};
export var labels = {
  completedLabel: 'Completed',
  todoLabel: 'To do',
  dismissLabel: 'Dismiss',
  dismissQuestion: 'Mark task as done?',
  dismissConfirmLabel: 'Mark as done',
  dismissCancelLabel: 'Cancel'
};
export var completedHeader = _objectSpread(_objectSpread({}, header), {}, {
  title: 'Congratulations!',
  description: 'You are all set.',
  onClose: undefined
});
export var completedHeaderWithClose = _objectSpread(_objectSpread({}, header), {}, {
  title: 'Congratulations!',
  description: 'You are all set.'
});