function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import * as React from 'react';
import { View, Text } from 'remax/one';
import classNames from 'classnames';
import Icon from '../icon';
import { getPrefixCls } from './../common';
var prefixCls = getPrefixCls('steps');

var Steps = function Steps(props) {
  var _a, _b;

  var _props$direction = props.direction,
      direction = _props$direction === void 0 ? 'horizontal' : _props$direction,
      _props$current = props.current,
      current = _props$current === void 0 ? 0 : _props$current,
      steps = props.steps,
      status = props.status;
  var statusIconType = status === 'error' ? 'roundclosefill' : 'roundcheckfill';
  var statusIconColor = status === 'error' ? '#f5222d' : '#1890FF';

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

    return item.title;
  };

  if (direction === 'vertical') {
    return /*#__PURE__*/React.createElement(View, {
      className: prefixCls
    }, (_b = (_a = steps === null || steps === void 0 ? void 0 : steps.reverse) === null || _a === void 0 ? void 0 : _a.call(steps)) === null || _b === void 0 ? void 0 : _b.map(function (item, index) {
      return /*#__PURE__*/React.createElement(View, {
        key: index,
        className: "".concat(prefixCls, "-step")
      }, index === (steps === null || steps === void 0 ? void 0 : steps.length) - 1 ? null : index < current ? /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-line-ahead")
      }) : /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-line")
      }), index === current ? /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-circle_current")
      }, /*#__PURE__*/React.createElement(Text, {
        className: "".concat(prefixCls, "-circle_current-icon")
      }, /*#__PURE__*/React.createElement(Icon, {
        type: statusIconType,
        color: statusIconColor
      }))) : null, index < current ? /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-circle-ahead")
      }) : null, index > current ? /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-circle")
      }) : null, /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-step-header")
      }, /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-step-header-title")
      }, getTitle(item, index)), /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-step-header-extra")
      }, item.extra)), /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-step-description")
      }, item.description));
    }));
  }

  return /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "_horizontal")
  }, steps === null || steps === void 0 ? void 0 : steps.map(function (item, index) {
    var _classNames;

    return /*#__PURE__*/React.createElement(View, {
      key: index,
      className: classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "_horizontal-step"), true), _defineProperty(_classNames, "".concat(prefixCls, "_horizontal-step-finish"), index <= current - 1), _classNames))
    }, /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "_horizontal-step-container")
    }, /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "_horizontal-step-container-icon")
    }, index < current ? /*#__PURE__*/React.createElement(Icon, {
      type: "roundcheckfill",
      color: "#1890FF",
      size: 28
    }) : null, index === current ? /*#__PURE__*/React.createElement(Icon, {
      type: statusIconType,
      color: statusIconColor,
      size: 28
    }) : null, index > current ? /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "_horizontal-step-container-icon-default")
    }, /*#__PURE__*/React.createElement(View, null)) : null), /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "_horizontal-step-container-content")
    }, /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "_horizontal-step-container-content-title")
    }, getTitle(item, index)))));
  }));
};

export default Steps;