"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _range2 = _interopRequireDefault(require("ramda/src/range"));
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _ = require("../..");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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 && Object.prototype.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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var StyledContainer = (0, _styledComponents.default)(_.Flexbox).withConfig({
  displayName: "ProgressBar__StyledContainer",
  componentId: "sc-11x02c0-0"
})(["width:100%;", "{padding-bottom:", "px;}"], function (p) {
  return p.theme.media.greaterThan(p.theme.breakpoints.md);
}, function (_ref) {
  var theme = _ref.theme,
    hasLabels = _ref.hasLabels;
  return hasLabels ? theme.spacing.unit(8) : 0;
});
var Bubble = (0, _styledComponents.default)(_.Badge.Icon).withConfig({
  displayName: "ProgressBar__Bubble",
  componentId: "sc-11x02c0-1"
})(["position:relative;"]);
var StyledTypography = (0, _styledComponents.default)(_.Typography).withConfig({
  displayName: "ProgressBar__StyledTypography",
  componentId: "sc-11x02c0-2"
})(["display:none;text-align:center;white-space:nowrap;", "{display:block;position:absolute;top:", "px;}"], function (p) {
  return p.theme.media.greaterThan(p.theme.breakpoints.md);
}, function (_ref2) {
  var theme = _ref2.theme;
  return theme.spacing.unit(10);
});
var StyledLine = _styledComponents.default.div.withConfig({
  displayName: "ProgressBar__StyledLine",
  componentId: "sc-11x02c0-3"
})(["width:100%;height:2px;background-color:", ";"], function (p) {
  return p.lineColor;
});
var ProgressBar = function ProgressBar(_ref3) {
  var numberOfSteps = _ref3.numberOfSteps,
    currentStep = _ref3.currentStep,
    stepLabels = _ref3.stepLabels,
    _ref3$failed = _ref3.failed,
    failed = _ref3$failed === void 0 ? false : _ref3$failed,
    _ref3$warning = _ref3.warning,
    warning = _ref3$warning === void 0 ? false : _ref3$warning,
    colorDone = _ref3.colorDone,
    colorActive = _ref3.colorActive,
    colorNext = _ref3.colorNext,
    colorFailure = _ref3.colorFailure,
    colorText = _ref3.colorText,
    colorLabel = _ref3.colorLabel,
    titleContainer = _ref3.titleContainer,
    titleDone = _ref3.titleDone,
    titleActive = _ref3.titleActive,
    titleNext = _ref3.titleNext,
    titleFailure = _ref3.titleFailure;
  var theme = (0, _styledComponents.useTheme)();
  var stepBubble = function stepBubble(stepNumber) {
    var stepDone = stepNumber < currentStep;
    var stepActive = stepNumber === currentStep;
    var lineActive = stepNumber + 1 === currentStep;
    var titleProgress = function titleProgress() {
      if (stepDone) {
        return titleDone || 'step done';
      }
      if (stepActive) {
        return titleActive || 'active step';
      }
      if (failed) {
        return titleFailure || 'failure step';
      }
      if (warning) {
        return titleFailure || 'warning step';
      }
      return titleNext || 'step not done';
    };
    var title = "".concat(stepLabels ? stepLabels[stepNumber - 1] : stepNumber.toString(), " - ").concat(titleProgress());
    var getStepIcon = function getStepIcon() {
      if (stepDone) {
        return _react.default.createElement(_.Icon.Check16, {
          color: function color(t) {
            return colorText ? colorText(t) : t.color.progressBarText;
          }
        });
      }
      if (stepActive && failed) {
        return _react.default.createElement(_.Icon.Cross16, {
          color: function color(t) {
            return colorText ? colorText(t) : t.color.progressBarText;
          }
        });
      }
      if (stepActive && warning) {
        return _react.default.createElement(_.Icon.Warning16, {
          color: function color(t) {
            return colorText ? colorText(t) : t.color.progressBarText;
          }
        });
      }
      return stepNumber;
    };
    var getColor = function getColor(active) {
      if (active && failed) {
        return colorFailure ? colorFailure(theme) : theme.color.progressBarFailure;
      }
      if (active && warning) {
        return colorFailure ? colorFailure(theme) : theme.color.progressBarWarning;
      }
      if (active) {
        return colorActive ? colorActive(theme) : theme.color.progressBarActive;
      }
      if (stepDone) {
        return colorDone ? colorDone(theme) : theme.color.progressBarDone;
      }
      return colorNext ? colorNext(theme) : theme.color.progressBarNext;
    };
    return _react.default.createElement(_react.default.Fragment, {
      key: stepNumber
    }, _react.default.createElement(Bubble, {
      title: title,
      badgeColor: function badgeColor() {
        return getColor(stepActive);
      },
      badgeSize: 8
    }, _react.default.createElement(_.Typography, {
      type: "secondary",
      color: function color(t) {
        return colorText ? colorText(t) : t.color.progressBarText;
      },
      weight: "bold",
      "aria-hidden": true
    }, getStepIcon()), _react.default.createElement(StyledTypography, {
      type: "secondary",
      weight: stepActive ? 'bold' : 'regular',
      color: function color(t) {
        return colorLabel ? colorLabel(t) : t.color.text;
      },
      "aria-hidden": true
    }, stepLabels && stepLabels[stepNumber - 1])), stepNumber < numberOfSteps && _react.default.createElement(StyledLine, {
      lineColor: function lineColor() {
        return getColor(lineActive);
      }
    }));
  };
  var generateSteps = function generateSteps() {
    var steps = (0, _range2.default)(1, numberOfSteps + 1);
    return steps === null || steps === void 0 ? void 0 : steps.map(function (step) {
      return stepBubble(step);
    });
  };
  return _react.default.createElement(StyledContainer, {
    container: true,
    alignItems: "center",
    title: titleContainer || 'progress bar',
    hasLabels: stepLabels && stepLabels.length > 0
  }, generateSteps());
};
var _default = exports.default = ProgressBar;