"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var React = _interopRequireWildcard(require("react"));

var _one = require("remax/one");

var _classnames = _interopRequireDefault(require("classnames"));

var _icon = _interopRequireDefault(require("../icon"));

var _indexModule = _interopRequireDefault(require("./styles/index.module.less"));

var _configProvider = require("../config-provider");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-12-10 08:11:28
 * @LastEditTime: 2022-06-13 15:29:37
 * @FilePath: \remaxui\src\steps\index.tsx
 */
var Steps = function Steps(props) {
  var _useConfig = (0, _configProvider.useConfig)(),
      brandPrimary = _useConfig.brandPrimary;

  var _props$direction = props.direction,
      direction = _props$direction === void 0 ? 'horizontal' : _props$direction,
      _props$color = props.color,
      color = _props$color === void 0 ? '#ff4d4f' : _props$color,
      _props$activeColor = props.activeColor,
      activeColor = _props$activeColor === void 0 ? brandPrimary : _props$activeColor,
      _props$current = props.current,
      current = _props$current === void 0 ? 0 : _props$current,
      steps = props.steps,
      status = props.status;
  var statusIconType = status === 'error' ? 'clear2' : 'zhengque';
  var statusIconColor = status === 'error' ? color : activeColor;

  var getTitle = function getTitle(item, index) {
    if (index === current) {
      if (status === 'error') {
        return item.errorTitle || item.title;
      }
    }

    return item.title;
  };

  if (direction === 'vertical') {
    var _steps$reverse, _steps$reverse$call;

    return /*#__PURE__*/React.createElement(_one.View, {
      className: _indexModule.default.steps
    }, steps === null || steps === void 0 ? void 0 : (_steps$reverse = steps.reverse) === null || _steps$reverse === void 0 ? void 0 : (_steps$reverse$call = _steps$reverse.call(steps)) === null || _steps$reverse$call === void 0 ? void 0 : _steps$reverse$call.map(function (item, index) {
      return /*#__PURE__*/React.createElement(_one.View, {
        key: index,
        className: _indexModule.default.steps_step
      }, index === (steps === null || steps === void 0 ? void 0 : steps.length) - 1 ? null : index < current ? /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_line_ahead
      }) : /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_line
      }), index === current ? /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_circle_current
      }, /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_circle_current_icon
      }, /*#__PURE__*/React.createElement(_icon.default, {
        name: statusIconType,
        color: statusIconColor,
        size: '20px'
      }))) : null, index < current ? /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_circle_ahead
      }) : null, index > current ? /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_circle
      }) : null, /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_step_header
      }, /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_step_header_title
      }, getTitle(item, index)), /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_step_header_extra
      }, item.extra)), /*#__PURE__*/React.createElement(_one.View, {
        className: _indexModule.default.steps_step_description
      }, item.description));
    }));
  }

  return /*#__PURE__*/React.createElement(_one.View, {
    className: _indexModule.default.steps_horizontal
  }, steps === null || steps === void 0 ? void 0 : steps.map(function (item, index) {
    return /*#__PURE__*/React.createElement(_one.View, {
      key: index,
      className: (0, _classnames.default)(_indexModule.default.steps_horizontal_step, index <= current - 1 && _indexModule.default.steps_horizontal_step_finish)
    }, /*#__PURE__*/React.createElement(_one.View, {
      className: _indexModule.default.steps_horizontal_step_container
    }, /*#__PURE__*/React.createElement(_one.View, {
      className: _indexModule.default.steps_horizontal_step_container_icon
    }, index < current ? /*#__PURE__*/React.createElement(_icon.default, {
      name: "zhengque",
      color: activeColor,
      size: '20px'
    }) : null, index === current ? /*#__PURE__*/React.createElement(_icon.default, {
      name: statusIconType,
      color: statusIconColor,
      size: '20px'
    }) : null, index > current ? /*#__PURE__*/React.createElement(_one.View, {
      className: _indexModule.default.steps_horizontal_step_container_icon_default
    }, /*#__PURE__*/React.createElement(_one.View, null)) : null), /*#__PURE__*/React.createElement(_one.View, {
      className: _indexModule.default.steps_horizontal_step_container_content
    }, /*#__PURE__*/React.createElement(_one.View, {
      className: _indexModule.default.steps_horizontal_step_container_content_title
    }, getTitle(item, index)))));
  }));
};

var _default = Steps;
exports.default = _default;