"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _getOr = _interopRequireDefault(require("lodash/fp/getOr"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _buttonLink = _interopRequireDefault(require("../../atom/button-link"));
var _buttonLinkIcon = _interopRequireDefault(require("../../atom/button-link-icon"));
var _wizardSteps = _interopRequireDefault(require("../../atom/wizard-steps"));
var _wizardSummary = _interopRequireDefault(require("../../molecule/wizard-summary"));
var _brandForm = _interopRequireDefault(require("../brand-form"));
var _contentTranslation = _interopRequireDefault(require("../content-translation"));
var _searchAndChipsResults = _interopRequireDefault(require("../search-and-chips-results"));
var _courseSelection = _interopRequireDefault(require("../course-selection"));
var _courseSections = _interopRequireDefault(require("../../molecule/course-sections"));
var _brandTabs = _interopRequireDefault(require("../../molecule/brand-tabs"));
var _bulletPointMenuButton = _interopRequireDefault(require("../../molecule/bullet-point-menu-button"));
var _rewardsForm = _interopRequireDefault(require("../rewards-form"));
var _expandibleActionableTable = _interopRequireDefault(require("../../molecule/expandible-actionable-table"));
var _bulkInfos = _interopRequireDefault(require("../../molecule/bulk-infos"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const buildHeader = (wizardHeader, actions, steps, tabs) => {
  const {
    title,
    onClick
  } = wizardHeader;
  const buttonCloseIcon = {
    size: 'small',
    'data-name': 'close-button',
    'aria-label': 'close button',
    icon: 'close',
    onClick
  };
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.header
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.titleWrapper
  }, /*#__PURE__*/_react.default.createElement(_buttonLinkIcon.default, buttonCloseIcon), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.headerTitle,
    "data-name": 'content-title'
  }, title)), actions ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.actionsWrapper
  }, actions.bulletPointMenuButton ? /*#__PURE__*/_react.default.createElement(_bulletPointMenuButton.default, actions.bulletPointMenuButton) : null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.buttonLink
  }, /*#__PURE__*/_react.default.createElement(_buttonLink.default, actions.firstButtonLink)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.buttonLink
  }, /*#__PURE__*/_react.default.createElement(_buttonLink.default, actions.secondButtonLink))) : null), steps ? /*#__PURE__*/_react.default.createElement(_wizardSteps.default, {
    steps: steps
  }) : null, tabs ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.tabs
  }, /*#__PURE__*/_react.default.createElement(_brandTabs.default, {
    type: "light",
    tabs: tabs
  })) : null);
};
const buildView = content => {
  const {
    type
  } = content;
  switch (type) {
    case 'form':
      return /*#__PURE__*/_react.default.createElement(_brandForm.default, content);
    case 'translate':
      return /*#__PURE__*/_react.default.createElement(_contentTranslation.default, content);
    case 'populations':
      return /*#__PURE__*/_react.default.createElement(_searchAndChipsResults.default, content);
    case 'courses':
      return /*#__PURE__*/_react.default.createElement(_courseSelection.default, content);
    case 'organize-courses':
      return /*#__PURE__*/_react.default.createElement(_courseSections.default, content);
    case 'rewards':
      return /*#__PURE__*/_react.default.createElement(_rewardsForm.default, content);
    case 'expandible-table':
      return /*#__PURE__*/_react.default.createElement(_expandibleActionableTable.default, content);
    case 'upload-progression':
      return /*#__PURE__*/_react.default.createElement(_bulkInfos.default, content);
  }
};
const buildButton = (type, step, side) => {
  const ICONS = {
    previous: {
      position: 'left',
      type: 'chevron-left'
    },
    next: {
      position: 'right',
      type: 'chevron-right'
    },
    publish: {
      position: 'left',
      type: 'publish'
    }
  };
  const {
    label,
    onClick
  } = step;
  const buttonProps = {
    type: type === 'previous' ? 'secondary' : 'primary',
    'aria-label': `${type} step button`,
    'data-name': `${type}-step-button-${side}`,
    icon: ICONS[type],
    label,
    onClick
  };
  return /*#__PURE__*/_react.default.createElement(_buttonLink.default, buttonProps);
};
const buildActionZone = (previousStep, nextStep, side) => {
  const previousButton = previousStep ? buildButton('previous', previousStep, side) : null;
  const nextStepType = (0, _getOr.default)('next', 'type', nextStep);
  const nextButton = nextStep ? buildButton(nextStepType, nextStep, side) : null;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.actionZone
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.button
  }, previousButton), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.button
  }, nextButton));
};
const THEMES = {
  'no-summary': {
    container: _style.default.containerWithoutSummary,
    footer: _style.default.footerWithoutSummary,
    actionFooter: _style.default.actionFooterWithoutSummary,
    leftSection: _style.default.leftSectionWithoutSummary
  },
  summary: {
    container: _style.default.container,
    footer: _style.default.footer,
    actionFooter: _style.default.actionFooter,
    leftSection: _style.default.leftSection
  }
};
const getTheme = summary => summary ? 'summary' : 'no-summary';
const WizardContents = props => {
  const {
    isLoading,
    wizardHeader,
    actions,
    steps,
    tabs,
    summary,
    content,
    nextStep,
    previousStep
  } = props;
  const headerView = buildHeader(wizardHeader, actions, steps, tabs);
  const view = buildView({
    ...content,
    isLoading
  });
  const rightActionView = buildActionZone(previousStep, nextStep, 'right');
  const footerActionView = buildActionZone(previousStep, nextStep, 'footer');
  const currentStyle = THEMES[getTheme(summary)];
  const summaryWrapper = /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.rightSection,
    "data-name": "summary-right-section"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.stickySection
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.summaryZone,
    "data-name": "summary-zone"
  }, /*#__PURE__*/_react.default.createElement(_wizardSummary.default, _extends({}, summary, {
    side: 'right'
  }))), rightActionView));
  return /*#__PURE__*/_react.default.createElement("div", {
    className: currentStyle.container,
    "data-name": "content-summary"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: currentStyle.leftSection
  }, headerView, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.form
  }, view)), summary ? summaryWrapper : null, /*#__PURE__*/_react.default.createElement("div", {
    className: currentStyle.footer,
    "data-name": "footer-section"
  }, summary ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.summaryFooter
  }, /*#__PURE__*/_react.default.createElement(_wizardSummary.default, _extends({}, summary, {
    side: 'footer'
  }))) : null, /*#__PURE__*/_react.default.createElement("div", {
    className: currentStyle.actionFooter
  }, footerActionView)));
};
WizardContents.propTypes = process.env.NODE_ENV !== "production" ? {
  isLoading: _propTypes.default.bool,
  wizardHeader: _propTypes.default.shape({
    title: _propTypes.default.string,
    onClick: _propTypes.default.func
  }).isRequired,
  actions: _propTypes.default.shape({
    bulletPointMenuButton: _propTypes.default.shape({
      buttonAriaLabel: _propTypes.default.string,
      menuAriaLabel: _propTypes.default.string,
      buttons: _propTypes.default.arrayOf(_propTypes.default.shape({
        'data-name': _propTypes.default.string,
        label: _propTypes.default.string,
        type: _propTypes.default.string,
        onClick: _propTypes.default.func
      })),
      onClick: _propTypes.default.func
    }),
    firstButtonLink: _propTypes.default.shape(_buttonLink.default.propTypes),
    secondButtonLink: _propTypes.default.shape(_buttonLink.default.propTypes)
  }),
  steps: _wizardSteps.default.propTypes.steps,
  tabs: _brandTabs.default.propTypes.tabs,
  summary: _propTypes.default.shape({
    ..._wizardSummary.default.propTypes
  }),
  content: _propTypes.default.oneOfType([_propTypes.default.shape({
    ..._brandForm.default.propTypes,
    type: _propTypes.default.oneOf(['form'])
  }), _propTypes.default.shape({
    ..._contentTranslation.default.propTypes,
    type: _propTypes.default.oneOf(['translate'])
  }), _propTypes.default.shape({
    ..._searchAndChipsResults.default.propTypes,
    type: _propTypes.default.oneOf(['populations'])
  }), _propTypes.default.shape({
    ..._courseSelection.default.propTypes,
    type: _propTypes.default.oneOf(['courses'])
  }), _propTypes.default.shape({
    ..._courseSections.default.propTypes,
    type: _propTypes.default.oneOf(['organize-courses'])
  }), _propTypes.default.shape({
    ..._rewardsForm.default.propTypes,
    type: _propTypes.default.oneOf(['rewards'])
  }), _propTypes.default.shape({
    ..._expandibleActionableTable.default.propTypes,
    type: _propTypes.default.oneOf(['expandible-table'])
  }), _propTypes.default.shape({
    ..._bulkInfos.default.propTypes,
    type: _propTypes.default.oneOf(['upload-progression'])
  })]),
  previousStep: _propTypes.default.shape({
    label: _propTypes.default.string,
    onClick: _propTypes.default.func
  }),
  nextStep: _propTypes.default.shape({
    type: _propTypes.default.oneOf(['next', 'publish']),
    label: _propTypes.default.string,
    onClick: _propTypes.default.func
  })
} : {};
var _default = exports.default = WizardContents;
//# sourceMappingURL=index.js.map