'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

require('./index.less');

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

var CardSteps = function (_Component) {
    (0, _inherits3['default'])(CardSteps, _Component);

    function CardSteps(props) {
        (0, _classCallCheck3['default'])(this, CardSteps);

        var _this = (0, _possibleConstructorReturn3['default'])(this, (CardSteps.__proto__ || Object.getPrototypeOf(CardSteps)).call(this, props));

        _this.onStepClick = function (data, index) {
            var _this$props = _this.props,
                clickable = _this$props.clickable,
                onClick = _this$props.onClick;

            clickable && onClick(data, index);
        };
        _this.getStepNode = function (data, index) {
            var _this$props2 = _this.props,
                current = _this$props2.current,
                clickable = _this$props2.clickable;

            return _react2['default'].createElement(
                'div',
                { key: data.name, className: (0, _classnames2['default'])({ csNodeOut: true, beforeCurrent: index <= current }), style: { width: _this.nodeWidth }, onClick: function onClick() {
                        _this.onStepClick(data, index);
                    } },
                _react2['default'].createElement(
                    'div',
                    { className: 'csNodeIn', style: { cursor: clickable ? 'pointer' : '' } },
                    _react2['default'].createElement(
                        'span',
                        { className: 'csIndex' },
                        index + 1
                    ),
                    _react2['default'].createElement(
                        'span',
                        { className: 'csName' },
                        data.name
                    )
                ),
                _react2['default'].createElement('div', { className: 'csTriangle' }),
                _react2['default'].createElement(
                    'div',
                    { className: 'csTriangleBack' },
                    _react2['default'].createElement('div', { className: 'csWhiteTriagle' })
                )
            );
        };
        _this.sourceLength = _this.props.dataSource.length;
        _this.nodeWidth = _this.sourceLength > 0 ? 100 / _this.sourceLength + '%' : '100%';
        return _this;
    }

    (0, _createClass3['default'])(CardSteps, [{
        key: 'render',
        value: function render() {
            var dataSource = this.props.dataSource;

            return _react2['default'].createElement(
                'div',
                { className: 'csWraper' },
                dataSource.length > 0 && dataSource.map(function (data, index) {
                    return this.getStepNode(data, index);
                }.bind(this))
            );
        }
    }]);
    return CardSteps;
}(_react.Component);

CardSteps.defaultProps = {
    current: 0,
    dataSource: [],
    clickable: false
};
exports['default'] = CardSteps;
module.exports = exports['default'];