"use strict";

exports.__esModule = true;
exports.default = void 0;
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _title = _interopRequireDefault(require("../../atom/title"));
var _select = _interopRequireDefault(require("../../atom/select"));
var _inputSwitch = _interopRequireDefault(require("../../atom/input-switch"));
var _certificationCard = _interopRequireDefault(require("../../molecule/certification-card"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (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 && {}.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 _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 Certifications = (props, context) => {
  const {
    locales: {
      title,
      subtitle,
      tag,
      count
    },
    certifications,
    sorting
  } = props;
  const {
    translate
  } = context;
  const [showCompleted, setShowCompleted] = (0, _react.useState)(true);
  const sortView = sorting !== undefined ? /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "choice"
  }, /*#__PURE__*/_react.default.createElement(_select.default, _extends({}, sorting, {
    "aria-label": "All courses sort"
  }))) : null;
  const handleShowCompletedToggle = (0, _react.useCallback)(() => {
    setShowCompleted(!showCompleted);
  }, [showCompleted, setShowCompleted]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.backgroudnContainer
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.container,
    "data-name": "Certifications"
  }, /*#__PURE__*/_react.default.createElement(_title.default, {
    title: title,
    subtitle: subtitle,
    type: "form-group",
    titleSize: "standard-light-weight",
    subtitleSize: "standard-without-margin",
    icon: {
      iconName: 'wreath-laurel',
      iconColor: '#B87A00',
      borderRadius: '12px',
      backgroundColor: '#FFEECC'
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.sortSectionWrapper
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.certificatesCount
  }, count), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.sortSection
  }, /*#__PURE__*/_react.default.createElement(_inputSwitch.default, {
    id: 'show-completed-courses-switch',
    type: "switch",
    name: translate('show_completed'),
    title: translate('show_completed'),
    "aria-label": 'Show completed courses aria label',
    value: showCompleted,
    onChange: handleShowCompletedToggle
  }), sorting ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.sortWrapper
  }, translate('sort_by'), sortView) : null)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.certificateList
  }, (0, _map2.default)(certification => {
    const {
      label,
      progress
    } = certification;
    if (!showCompleted && progress === 100) return null;
    return /*#__PURE__*/_react.default.createElement("div", {
      key: label
    }, /*#__PURE__*/_react.default.createElement(_certificationCard.default, _extends({}, certification, {
      locales: {
        ...certification.locales,
        tag
      }
    })));
  }, certifications))));
};
Certifications.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
Certifications.propTypes = process.env.NODE_ENV !== "production" ? {
  certifications: _propTypes.default.arrayOf(_propTypes.default.shape({
    label: _propTypes.default.string,
    goal: _propTypes.default.shape({
      title: _propTypes.default.string,
      condition: _propTypes.default.shape({
        nbDone: _propTypes.default.number
      })
    }),
    progress: _propTypes.default.number,
    imgUrl: _propTypes.default.string,
    onClick: _propTypes.default.func,
    locales: _propTypes.default.shape({
      conditionDescriptionProgress: _propTypes.default.string
    })
  })),
  locales: _propTypes.default.shape({
    title: _propTypes.default.string,
    subtitle: _propTypes.default.string,
    tag: _propTypes.default.string,
    count: _propTypes.default.string
  }),
  sorting: _propTypes.default.shape(_select.default.propTypes)
} : {};
var _default = exports.default = Certifications;
//# sourceMappingURL=index.js.map