'use strict';

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

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _tabs = require('../tabs');

var _tabs2 = _interopRequireDefault(_tabs);

var _Tab = require('./Tab');

var _Tab2 = _interopRequireDefault(_Tab);

var _getDataAttr = require('../_util/getDataAttr');

var _getDataAttr2 = _interopRequireDefault(_getDataAttr);

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

var Item = exports.Item = function (_React$Component) {
    (0, _inherits3['default'])(Item, _React$Component);

    function Item() {
        (0, _classCallCheck3['default'])(this, Item);
        return (0, _possibleConstructorReturn3['default'])(this, (Item.__proto__ || Object.getPrototypeOf(Item)).apply(this, arguments));
    }

    (0, _createClass3['default'])(Item, [{
        key: 'render',
        value: function render() {
            return _react2['default'].createElement(
                'div',
                null,
                this.props.children
            );
        }
    }]);
    return Item;
}(_react2['default'].Component);

var AntTabBar = function (_React$Component2) {
    (0, _inherits3['default'])(AntTabBar, _React$Component2);

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

        var _this2 = (0, _possibleConstructorReturn3['default'])(this, (AntTabBar.__proto__ || Object.getPrototypeOf(AntTabBar)).apply(this, arguments));

        _this2.getTabs = function () {
            return _react2['default'].Children.map(_this2.props.children, function (c) {
                return (0, _extends3['default'])({}, c.props);
            });
        };
        _this2.renderTabBar = function () {
            var _this2$props = _this2.props,
                barTintColor = _this2$props.barTintColor,
                hidden = _this2$props.hidden,
                prefixCls = _this2$props.prefixCls,
                tintColor = _this2$props.tintColor,
                unselectedTintColor = _this2$props.unselectedTintColor;

            var barCls = hidden ? prefixCls + '-bar-hidden' : prefixCls + '-bar';
            var tabsData = _this2.getTabs();
            var content = tabsData.map(function (cProps, index) {
                return _react2['default'].createElement(_Tab2['default'], { key: index, prefixCls: _this2.props.prefixCls + '-tab', badge: cProps.badge, dot: cProps.dot, selected: cProps.selected, icon: cProps.icon, selectedIcon: cProps.selectedIcon, title: cProps.title, tintColor: tintColor, unselectedTintColor: unselectedTintColor, dataAttrs: (0, _getDataAttr2['default'])(cProps), onClick: function onClick() {
                        return cProps.onPress && cProps.onPress();
                    } });
            });
            return _react2['default'].createElement(
                'div',
                { className: barCls, style: { backgroundColor: barTintColor } },
                content
            );
        };
        return _this2;
    }

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

            var tabs = this.getTabs();
            var activeIndex = 0;
            tabs.forEach(function (tab, index) {
                if (tab.selected) {
                    activeIndex = index;
                }
            });
            return _react2['default'].createElement(
                'div',
                { className: this.props.prefixCls },
                _react2['default'].createElement(
                    _tabs2['default'],
                    { tabs: tabs, renderTabBar: this.renderTabBar, tabBarPosition: 'bottom', page: activeIndex < 0 ? undefined : activeIndex, animated: false, swipeable: false },
                    children
                )
            );
        }
    }]);
    return AntTabBar;
}(_react2['default'].Component);

AntTabBar.defaultProps = {
    prefixCls: 'am-tab-bar',
    barTintColor: 'white',
    tintColor: '#108ee9',
    hidden: false,
    unselectedTintColor: '#888',
    placeholder: '正在加载'
};
AntTabBar.Item = Item;
exports['default'] = AntTabBar;