'use strict';

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

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

var _extends3 = _interopRequireDefault(_extends2);

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

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

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

var _index = require('./style/index');

var _index2 = _interopRequireDefault(_index);

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

function noop() {}

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

    function Brief() {
        (0, _classCallCheck3["default"])(this, Brief);
        return (0, _possibleConstructorReturn3["default"])(this, _React$Component.apply(this, arguments));
    }

    Brief.prototype.render = function render() {
        var _props = this.props,
            children = _props.children,
            style = _props.style,
            _props$styles = _props.styles,
            styles = _props$styles === undefined ? _index2["default"] : _props$styles,
            wrap = _props.wrap;

        var numberOfLines = {};
        if (wrap === false) {
            numberOfLines = {
                numberOfLines: 1
            };
        }
        return _react2["default"].createElement(
            _reactNative.View,
            { style: [styles.Brief] },
            _react2["default"].createElement(
                _reactNative.Text,
                (0, _extends3["default"])({ style: [styles.BriefText, style] }, numberOfLines),
                children
            )
        );
    };

    return Brief;
}(_react2["default"].Component);

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

    function Item() {
        (0, _classCallCheck3["default"])(this, Item);
        return (0, _possibleConstructorReturn3["default"])(this, _React$Component2.apply(this, arguments));
    }

    Item.prototype.render = function render() {
        var _props2 = this.props,
            _props2$styles = _props2.styles,
            styles = _props2$styles === undefined ? _index2["default"] : _props2$styles,
            children = _props2.children,
            multipleLine = _props2.multipleLine,
            thumb = _props2.thumb,
            extra = _props2.extra,
            _props2$arrow = _props2.arrow,
            arrow = _props2$arrow === undefined ? '' : _props2$arrow,
            style = _props2.style,
            onClick = _props2.onClick,
            _props2$onPressIn = _props2.onPressIn,
            onPressIn = _props2$onPressIn === undefined ? noop : _props2$onPressIn,
            _props2$onPressOut = _props2.onPressOut,
            onPressOut = _props2$onPressOut === undefined ? noop : _props2$onPressOut,
            wrap = _props2.wrap,
            disabled = _props2.disabled,
            align = _props2.align;

        var numberOfLines = {};
        if (wrap === false) {
            numberOfLines = {
                numberOfLines: 1
            };
        }
        var underlayColor = {};
        if (!disabled && onClick) {
            underlayColor = {
                underlayColor: _index2["default"].underlayColor,
                activeOpacity: 0.5
            };
        } else {
            underlayColor = {
                activeOpacity: 1
            };
        }
        var alignStyle = {};
        if (align === 'top') {
            alignStyle = {
                alignItems: 'flex-start'
            };
        } else if (align === 'bottom') {
            alignStyle = {
                alignItems: 'flex-end'
            };
        }
        var contentDom = void 0;
        if (Array.isArray(children)) {
            (function () {
                var tempContentDom = [];
                children.forEach(function (el, index) {
                    if (_react2["default"].isValidElement(el)) {
                        tempContentDom.push(el);
                    } else {
                        tempContentDom.push(_react2["default"].createElement(
                            _reactNative.Text,
                            (0, _extends3["default"])({ style: [styles.Content] }, numberOfLines, { key: index + '-children' }),
                            el
                        ));
                    }
                });
                contentDom = _react2["default"].createElement(
                    _reactNative.View,
                    { style: [styles.column] },
                    tempContentDom
                );
            })();
        } else {
            if (_react2["default"].isValidElement(children)) {
                contentDom = _react2["default"].createElement(
                    _reactNative.View,
                    { style: [styles.column] },
                    children
                );
            } else {
                contentDom = _react2["default"].createElement(
                    _reactNative.View,
                    { style: [styles.column] },
                    _react2["default"].createElement(
                        _reactNative.Text,
                        (0, _extends3["default"])({ style: [styles.Content] }, numberOfLines),
                        children
                    )
                );
            }
        }
        var extraDom = void 0;
        if (extra) {
            extraDom = _react2["default"].createElement(
                _reactNative.View,
                { style: [styles.column] },
                _react2["default"].createElement(
                    _reactNative.Text,
                    (0, _extends3["default"])({ style: [styles.Extra] }, numberOfLines),
                    extra
                )
            );
            if (_react2["default"].isValidElement(extra)) {
                var extraChildren = extra.props.children;
                if (Array.isArray(extraChildren)) {
                    (function () {
                        var tempExtraDom = [];
                        extraChildren.forEach(function (el, index) {
                            if (typeof el === 'string') {
                                tempExtraDom.push(_react2["default"].createElement(
                                    _reactNative.Text,
                                    (0, _extends3["default"])({}, numberOfLines, { style: [styles.Extra], key: index + '-children' }),
                                    el
                                ));
                            } else {
                                tempExtraDom.push(el);
                            }
                        });
                        extraDom = _react2["default"].createElement(
                            _reactNative.View,
                            { style: [styles.column] },
                            tempExtraDom
                        );
                    })();
                } else {
                    extraDom = extra;
                }
            }
        }
        var arrEnum = {
            horizontal: _react2["default"].createElement(_reactNative.Image, { source: require('../style/images/arrow.png'), style: styles.Arrow }),
            down: _react2["default"].createElement(_reactNative.Image, { source: require('../style/images/arrow-down.png'), style: styles.ArrowV }),
            up: _react2["default"].createElement(_reactNative.Image, { source: require('../style/images/arrow-up.png'), style: styles.ArrowV })
        };
        var itemView = _react2["default"].createElement(
            _reactNative.View,
            (0, _extends3["default"])({}, this.props, { style: [styles.Item, style] }),
            typeof thumb === 'string' ? _react2["default"].createElement(_reactNative.Image, { source: { uri: thumb }, style: [styles.Thumb, multipleLine && styles.multipleLine.Thumb] }) : thumb,
            _react2["default"].createElement(
                _reactNative.View,
                { style: [styles.Line, multipleLine && styles.multipleLine.Line, multipleLine && alignStyle] },
                contentDom,
                extraDom,
                arrow ? arrEnum[arrow] || _react2["default"].createElement(_reactNative.View, { style: styles.Arrow }) : null
            )
        );
        return _react2["default"].createElement(
            _reactNative.TouchableHighlight,
            (0, _extends3["default"])({}, underlayColor, { onPress: onClick ? onClick : undefined, onPressIn: onPressIn, onPressOut: onPressOut }),
            itemView
        );
    };

    return Item;
}(_react2["default"].Component);

exports["default"] = Item;

Item.defaultProps = {
    error: false,
    multipleLine: false,
    wrap: false
};
Item.Brief = Brief;
module.exports = exports['default'];