"use strict";

exports.__esModule = true;
exports.default = void 0;
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _novaIcons = require("@coorpacademy/nova-icons");
var _link = _interopRequireDefault(require("../../../../atom/link"));
var _provider = _interopRequireDefault(require("../../../../atom/provider"));
var _colors = require("../../../../variables/colors");
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ICON_TYPES = {
  arrow: _novaIcons.NovaSolidLightsLightbulb4,
  dashboard: _novaIcons.NovaCompositionCoorpacademyDashboard,
  analytics: _novaIcons.NovaCompositionCoorpacademyAnalytics,
  administration: _novaIcons.NovaCompositionCoorpacademyAdministration,
  animation: _novaIcons.NovaCompositionCoorpacademyAnimation,
  contentCreation: _novaIcons.NovaCompositionCoorpacademyContentCreation,
  editorialization: _novaIcons.NovaCompositionCoorpacademyEditorialization
};
const defaultStyle = {
  titleIcon: _style.default.titleIcon,
  label: _style.default.titleLabel,
  selectedLabel: _style.default.titleLabel,
  title: _style.default.setupTitle,
  container: _style.default.container,
  openHeader: _style.default.openHeader,
  closedHeader: _style.default.closedHeader,
  default: null
};
const setupThemeStyle = {
  titleIcon: _style.default.titleIcon,
  titleActivatedIcon: _style.default.setupTitleActivatedIcon,
  label: _style.default.setupTitleLabel,
  selectedLabel: _style.default.setupSelectedTitleLabel,
  setupSelectedTitle: _style.default.setupSelectedTitle,
  selectedTitle: _style.default.selectedTitle,
  title: _style.default.setupTitle,
  container: _style.default.setupContainer,
  openHeader: _style.default.coorpManagerOpenHeader,
  closedHeader: _style.default.coorpManagerClosedHeader
};
const MoreLessIcons = ({
  type,
  moreClassName,
  lessClassName,
  darkColor,
  mediumColor
}) => {
  return type !== 'iconLink' ? /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowDown, {
    className: moreClassName,
    style: {
      color: darkColor
    }
  }), /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowDown, {
    className: lessClassName,
    style: {
      color: mediumColor
    }
  })) : /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyOpenInNewTab, {
    className: _style.default.newTabIcon
  });
};
const Part = ({
  skin,
  selected,
  iconType,
  onParentClick,
  onClick,
  isOpen,
  title,
  type,
  children,
  theme
}) => {
  const darkColor = (0, _get2.default)('common.dark', skin);
  const mediumColor = (0, _get2.default)('common.medium', skin);
  const lessClassName = isOpen ? _style.default.openIconActivated : _style.default.openIcon;
  const moreClassName = !isOpen ? _style.default.closeIconActivated : _style.default.closeIcon;
  const iconColor = selected ? _style.default.iconBlue : _style.default.iconGrey;
  const hoverIconColor = selected && _style.default.blueTitleIcon;
  const selectedBlackLabel = selected && _style.default.labelBlack;
  const Icon = ICON_TYPES[iconType];
  const isLink = type === 'iconLink';
  const isCollapsible = type === 'collapsibleTab';
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.wrapper
  }, theme === 'setup' ? /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(_style.default.border, selected ? _style.default.borderBgBlue : _style.default.borderBgNone)
  }) : null, /*#__PURE__*/_react.default.createElement("div", {
    "data-type": iconType,
    onClick: onParentClick,
    style: {
      flex: 1
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "accordionPart",
    className: _style.default.setupPart
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.header,
    "data-type": iconType,
    onClick: onClick
  }, /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "title",
    className: _style.default.title
  }, Icon ? /*#__PURE__*/_react.default.createElement(Icon, {
    className: (0, _classnames.default)(_style.default.titleIcon, iconColor, hoverIconColor)
  }) : null, /*#__PURE__*/_react.default.createElement("h3", {
    className: (0, _classnames.default)(_style.default.titleLabel, selectedBlackLabel)
  }, title, isLink ? /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionCoorpacademyOpenInNewTab, {
    className: _style.default.newTabIcon
  }) : null)), isCollapsible ? /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowDown, {
    className: moreClassName,
    style: {
      color: darkColor
    }
  }), /*#__PURE__*/_react.default.createElement(_novaIcons.NovaCompositionNavigationArrowDown, {
    className: lessClassName,
    style: {
      color: mediumColor
    }
  })) : null), isCollapsible ? children : null)));
};
const AccordionPart = (props, context) => {
  const {
    skin
  } = context;
  const {
    title,
    content,
    iconType,
    theme,
    onClick = _noop2.default,
    selected = false,
    type,
    href,
    isOpen,
    onUpdateOpenedTab
  } = props;
  const themeStyle = theme === 'setup' ? setupThemeStyle : defaultStyle;
  function handleParentClick() {
    onUpdateOpenedTab();
    onClick();
  }
  const isCollapsibleTab = type === 'collapsibleTab';
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "accordionPart",
    className: themeStyle[theme]
  }, !isCollapsibleTab ? /*#__PURE__*/_react.default.createElement(_link.default, {
    onClick: handleParentClick,
    hoverColor: (0, _getOr2.default)(_colors.COLORS.brand, 'common.primary', skin),
    href: href,
    "data-name": `link-item`,
    target: '_blank',
    style: {
      textDecoration: 'none'
    }
  }, /*#__PURE__*/_react.default.createElement(Part, {
    skin: skin,
    title: title,
    content: content,
    iconType: iconType,
    theme: theme,
    onParentClick: handleParentClick,
    onClick: onClick,
    isOpen: isOpen,
    selected: selected,
    type: type
  })) : /*#__PURE__*/_react.default.createElement(Part, {
    skin: skin,
    title: title,
    content: content,
    iconType: iconType,
    theme: theme,
    onParentClick: handleParentClick,
    onClick: onClick,
    selected: selected,
    isOpen: isOpen,
    type: type
  }), isCollapsibleTab && isOpen ? /*#__PURE__*/_react.default.createElement("div", {
    className: themeStyle.container
  }, content) : null);
};
AccordionPart.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
AccordionPart.propTypes = process.env.NODE_ENV !== "production" ? {
  iconType: _propTypes.default.oneOf((0, _keys2.default)(ICON_TYPES)),
  type: _propTypes.default.oneOf(['simpleTab', 'collapsibleTab', 'iconLink']),
  title: _propTypes.default.string,
  content: _propTypes.default.node,
  onClick: _propTypes.default.func,
  selected: _propTypes.default.bool,
  theme: _propTypes.default.string,
  href: _propTypes.default.string,
  isOpen: _propTypes.default.bool,
  onUpdateOpenedTab: _propTypes.default.func
} : {};
MoreLessIcons.propTypes = process.env.NODE_ENV !== "production" ? {
  type: _propTypes.default.string,
  moreClassName: _propTypes.default.string,
  lessClassName: _propTypes.default.string,
  darkColor: _propTypes.default.string,
  mediumColor: _propTypes.default.string
} : {};
Part.propTypes = process.env.NODE_ENV !== "production" ? {
  ...AccordionPart.propTypes
} : {};
var _default = exports.default = AccordionPart;
//# sourceMappingURL=index.js.map