/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-12-10 08:11:28
 * @LastEditTime: 2022-06-13 15:29:37
 * @FilePath: \remaxui\src\steps\index.tsx
 */
import * as React from 'react';
import { View } from 'remax/one';
import classNames from 'classnames';
import Icon from '../icon';
import styles from './styles/index.module.less';
import { useConfig } from '../config-provider';

var Steps = function Steps(props) {
  var _useConfig = 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(View, {
      className: styles.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(View, {
        key: index,
        className: styles.steps_step
      }, index === (steps === null || steps === void 0 ? void 0 : steps.length) - 1 ? null : index < current ? /*#__PURE__*/React.createElement(View, {
        className: styles.steps_line_ahead
      }) : /*#__PURE__*/React.createElement(View, {
        className: styles.steps_line
      }), index === current ? /*#__PURE__*/React.createElement(View, {
        className: styles.steps_circle_current
      }, /*#__PURE__*/React.createElement(View, {
        className: styles.steps_circle_current_icon
      }, /*#__PURE__*/React.createElement(Icon, {
        name: statusIconType,
        color: statusIconColor,
        size: '20px'
      }))) : null, index < current ? /*#__PURE__*/React.createElement(View, {
        className: styles.steps_circle_ahead
      }) : null, index > current ? /*#__PURE__*/React.createElement(View, {
        className: styles.steps_circle
      }) : null, /*#__PURE__*/React.createElement(View, {
        className: styles.steps_step_header
      }, /*#__PURE__*/React.createElement(View, {
        className: styles.steps_step_header_title
      }, getTitle(item, index)), /*#__PURE__*/React.createElement(View, {
        className: styles.steps_step_header_extra
      }, item.extra)), /*#__PURE__*/React.createElement(View, {
        className: styles.steps_step_description
      }, item.description));
    }));
  }

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

export default Steps;