"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const prop_types_1 = __importDefault(require("prop-types"));
const react_1 = __importDefault(require("react"));
const react_native_1 = require("react-native");
const Color_1 = __importDefault(require("./Color"));
const utils_1 = require("./utils");
class Actions extends react_1.default.Component {
    constructor() {
        super(...arguments);
        this.onActionsPress = () => {
            const { options } = this.props;
            const optionKeys = Object.keys(options);
            const cancelButtonIndex = optionKeys.indexOf('Cancel');
            this.context.actionSheet().showActionSheetWithOptions({
                options: optionKeys,
                cancelButtonIndex,
                tintColor: this.props.optionTintColor,
            }, (buttonIndex) => {
                const key = optionKeys[buttonIndex];
                if (key) {
                    options[key](this.props);
                }
            });
        };
    }
    renderIcon() {
        if (this.props.icon) {
            return this.props.icon();
        }
        return (react_1.default.createElement(react_native_1.View, { style: [styles.wrapper, this.props.wrapperStyle] },
            react_1.default.createElement(react_native_1.Text, { style: [styles.iconText, this.props.iconTextStyle] }, "+")));
    }
    render() {
        return (react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.container, this.props.containerStyle], onPress: this.props.onPressActionButton || this.onActionsPress }, this.renderIcon()));
    }
}
exports.default = Actions;
Actions.defaultProps = {
    options: {},
    optionTintColor: Color_1.default.optionTintColor,
    icon: undefined,
    containerStyle: {},
    iconTextStyle: {},
    wrapperStyle: {},
};
Actions.propTypes = {
    onSend: prop_types_1.default.func,
    options: prop_types_1.default.object,
    optionTintColor: prop_types_1.default.string,
    icon: prop_types_1.default.func,
    onPressActionButton: prop_types_1.default.func,
    wrapperStyle: utils_1.StylePropType,
    containerStyle: utils_1.StylePropType,
};
Actions.contextTypes = {
    actionSheet: prop_types_1.default.func,
};
const styles = react_native_1.StyleSheet.create({
    container: {
        width: 26,
        height: 26,
        marginLeft: 10,
        marginBottom: 10,
    },
    wrapper: {
        borderRadius: 13,
        borderColor: Color_1.default.defaultColor,
        borderWidth: 2,
        flex: 1,
    },
    iconText: {
        color: Color_1.default.defaultColor,
        fontWeight: 'bold',
        fontSize: 16,
        backgroundColor: Color_1.default.backgroundTransparent,
        textAlign: 'center',
    },
});
//# sourceMappingURL=Actions.js.map