'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactNative = require('react-native');

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

var _index2 = _interopRequireDefault(_index);

var _Modal = require('rc-dialog/lib/Modal');

var _Modal2 = _interopRequireDefault(_Modal);

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

var ActionSheetAndroid = _react2["default"].createClass({
    displayName: 'ActionSheetAndroid',
    getDefaultProps: function getDefaultProps() {
        return {
            share: false
        };
    },
    getInitialState: function getInitialState() {
        return {
            visible: this.props.visible || false
        };
    },
    componentWillMount: function componentWillMount() {
        var _this = this;

        _reactNative.DeviceEventEmitter.addListener('antActionSheetHide', function () {
            _this.close();
        });
    },
    componentWillUnmount: function componentWillUnmount() {
        _reactNative.DeviceEventEmitter.removeAllListeners('antActionSheetHide');
    },
    close: function close() {
        this.setState({
            visible: false
        });
    },
    render: function render() {
        var _props = this.props,
            config = _props.config,
            share = _props.share,
            callback = _props.callback,
            onAnimationEnd = _props.onAnimationEnd;
        var title = config.title,
            message = config.message,
            url = config.url,
            options = config.options,
            destructiveButtonIndex = config.destructiveButtonIndex,
            cancelButtonIndex = config.cancelButtonIndex,
            excludedActivityTypes = config.excludedActivityTypes;

        var titleMsg = share ? url && _react2["default"].createElement(
            _reactNative.View,
            { style: _index2["default"].title, key: '0' },
            _react2["default"].createElement(
                _reactNative.Text,
                null,
                url
            )
        ) : title && _react2["default"].createElement(
            _reactNative.View,
            { style: _index2["default"].title, key: '0' },
            _react2["default"].createElement(
                _reactNative.Text,
                { style: _index2["default"].titleText },
                title
            )
        );
        return _react2["default"].createElement(
            _Modal2["default"],
            { animationDuration: 200, animateAppear: true, visible: this.state.visible, onAnimationEnd: onAnimationEnd, style: _index2["default"].content, animationType: 'slide-up', maskClosable: true, onClose: this.close },
            _react2["default"].createElement(
                _reactNative.View,
                null,
                titleMsg,
                message && _react2["default"].createElement(
                    _reactNative.View,
                    { style: _index2["default"].message, key: '1' },
                    _react2["default"].createElement(
                        _reactNative.Text,
                        null,
                        message
                    )
                ),
                _react2["default"].createElement(
                    _reactNative.View,
                    null,
                    share ? excludedActivityTypes.map(function (item, index) {
                        return _react2["default"].createElement(
                            _reactNative.View,
                            { key: index },
                            item
                        );
                    }) : options.map(function (item, index) {
                        return _react2["default"].createElement(
                            _reactNative.View,
                            { key: index, style: [cancelButtonIndex === index ? _index2["default"].cancelBtn : null] },
                            _react2["default"].createElement(
                                _reactNative.TouchableHighlight,
                                { style: [_index2["default"].btn], underlayColor: _index.vars.fill_tap, onPress: function onPress() {
                                        return callback && callback(index);
                                    } },
                                _react2["default"].createElement(
                                    _reactNative.Text,
                                    { style: [destructiveButtonIndex === index ? _index2["default"].destructiveBtn : null] },
                                    item
                                )
                            ),
                            cancelButtonIndex === index ? _react2["default"].createElement(_reactNative.View, { style: _index2["default"].cancelBtnMask }) : null
                        );
                    })
                )
            )
        );
    }
});
exports["default"] = ActionSheetAndroid;
module.exports = exports['default'];