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 './index.less';

var Catalogue = function (_React$Component) {
    _inherits(Catalogue, _React$Component);

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

        var _this = _possibleConstructorReturn(this, (Catalogue.__proto__ || Object.getPrototypeOf(Catalogue)).apply(this, arguments));

        _this.state = { activeKey: '', showCate: false };
        _this.componentDidMount = function () {
            var _this$props = _this.props,
                data = _this$props.data,
                isShow = _this$props.isShow;

            _this.setState({ activeKey: data && data[0] && data[0].model && data[0].model.catgName, showCate: isShow });
        };
        _this.onCateOver = function () {
            var onChangeDisplay = _this.props.onChangeDisplay;

            onChangeDisplay && onChangeDisplay(true, true);
        };
        _this.onCateLeave = function () {
            var onChangeDisplay = _this.props.onChangeDisplay;

            _this.setState({ showCate: false });
            onChangeDisplay && onChangeDisplay(false, false);
        };
        return _this;
    }

    _createClass(Catalogue, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var data = this.props.data;
            var _state = this.state,
                activeKey = _state.activeKey,
                showCate = _state.showCate;

            return React.createElement(
                'div',
                { className: showCate ? "category-container" : "category-container-hidden", onMouseOver: function onMouseOver() {
                        return _this2.onCateOver();
                    }, onMouseLeave: function onMouseLeave() {
                        return _this2.onCateLeave();
                    } },
                React.createElement(
                    'div',
                    { className: 'category-first-level' },
                    React.createElement(
                        'ul',
                        { className: 'menu-ul' },
                        data && data.map(function (d) {
                            return React.createElement(
                                'li',
                                { className: 'menu-li', key: d.model.catgId, onMouseOver: function onMouseOver() {
                                        return _this2.setState({ activeKey: d.model.catgName });
                                    } },
                                React.createElement(
                                    'a',
                                    { className: activeKey === d.model.catgName ? "menu-a-active" : "menu-a", href: '/offer-list/catg/' + d.model.catgId },
                                    React.createElement(
                                        'span',
                                        { className: 'menu-li-text' },
                                        d.model && d.model.catgName
                                    ),
                                    activeKey === d.model.catgName && React.createElement(
                                        'span',
                                        { style: { color: '#ed2121', float: 'right', marginRight: '12px' } },
                                        '>'
                                    )
                                )
                            );
                        })
                    )
                ),
                React.createElement('div', { className: 'category-divider' }),
                React.createElement(
                    'div',
                    { className: 'category-second-level' },
                    data && data.map(function (d, index) {
                        if (activeKey === d.model.catgName) {
                            return React.createElement(
                                'div',
                                { key: index },
                                d.children && d.children.map(function (chi, index) {
                                    return React.createElement(
                                        'div',
                                        { key: index, className: 'second-level-warp' },
                                        React.createElement(
                                            'div',
                                            { className: 'second-left' },
                                            React.createElement(
                                                'a',
                                                { href: '/offer-list/catg/' + chi.model.catgId },
                                                React.createElement(
                                                    'span',
                                                    { className: 'second-name' },
                                                    chi.model && chi.model.catgName
                                                ),
                                                React.createElement(
                                                    'span',
                                                    { className: 'second-gt' },
                                                    '>'
                                                )
                                            )
                                        ),
                                        React.createElement(
                                            'div',
                                            { className: 'third-right' },
                                            chi.children && chi.children.map(function (ch, ind) {
                                                return React.createElement(
                                                    'a',
                                                    { key: ind, className: 'third-name', href: '/offer-list/catg/' + ch.model.catgId },
                                                    ch.model.catgName
                                                );
                                            })
                                        )
                                    );
                                })
                            );
                        } else {
                            return '';
                        }
                    })
                )
            );
        }
    }]);

    return Catalogue;
}(React.Component);

export default Catalogue;