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

var _react2 = _interopRequireDefault(_react);

require('./index.less');

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

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

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

        var _this = (0, _possibleConstructorReturn3['default'])(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;
    }

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

exports['default'] = Catalogue;
module.exports = exports['default'];