import _extends from 'babel-runtime/helpers/extends';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import React from 'react';
import Tabs from '../tabs';
import Tab from './Tab';
import getDataAttr from '../_util/getDataAttr';
export var Item = function (_React$Component) {
    _inherits(Item, _React$Component);

    function Item() {
        _classCallCheck(this, Item);

        return _possibleConstructorReturn(this, (Item.__proto__ || Object.getPrototypeOf(Item)).apply(this, arguments));
    }

    _createClass(Item, [{
        key: 'render',
        value: function render() {
            return React.createElement(
                'div',
                null,
                this.props.children
            );
        }
    }]);

    return Item;
}(React.Component);

var AntTabBar = function (_React$Component2) {
    _inherits(AntTabBar, _React$Component2);

    function AntTabBar() {
        _classCallCheck(this, AntTabBar);

        var _this2 = _possibleConstructorReturn(this, (AntTabBar.__proto__ || Object.getPrototypeOf(AntTabBar)).apply(this, arguments));

        _this2.getTabs = function () {
            return React.Children.map(_this2.props.children, function (c) {
                return _extends({}, 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 React.createElement(Tab, { 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: getDataAttr(cProps), onClick: function onClick() {
                        return cProps.onPress && cProps.onPress();
                    } });
            });
            return React.createElement(
                'div',
                { className: barCls, style: { backgroundColor: barTintColor } },
                content
            );
        };
        return _this2;
    }

    _createClass(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 React.createElement(
                'div',
                { className: this.props.prefixCls },
                React.createElement(
                    Tabs,
                    { tabs: tabs, renderTabBar: this.renderTabBar, tabBarPosition: 'bottom', page: activeIndex < 0 ? undefined : activeIndex, animated: false, swipeable: false },
                    children
                )
            );
        }
    }]);

    return AntTabBar;
}(React.Component);

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