"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
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 Composer_1 = __importDefault(require("./Composer"));
const Send_1 = __importDefault(require("./Send"));
const Actions_1 = __importDefault(require("./Actions"));
const Color_1 = __importDefault(require("./Color"));
const utils_1 = require("./utils");
const styles = react_native_1.StyleSheet.create({
    container: {
        borderTopWidth: react_native_1.StyleSheet.hairlineWidth,
        borderTopColor: Color_1.default.defaultColor,
        backgroundColor: Color_1.default.white,
        bottom: 0,
        left: 0,
        right: 0,
    },
    primary: {
        flexDirection: 'row',
        alignItems: 'flex-end',
    },
    accessory: {
        height: 44,
    },
});
class InputToolbar extends react_1.default.Component {
    constructor() {
        super(...arguments);
        this.state = {
            position: 'absolute',
        };
        this.keyboardWillShowListener = undefined;
        this.keyboardWillHideListener = undefined;
        this.keyboardWillShow = () => {
            if (this.state.position !== 'relative') {
                this.setState({
                    position: 'relative',
                });
            }
        };
        this.keyboardWillHide = () => {
            if (this.state.position !== 'absolute') {
                this.setState({
                    position: 'absolute',
                });
            }
        };
    }
    componentDidMount() {
        this.keyboardWillShowListener = react_native_1.Keyboard.addListener('keyboardWillShow', this.keyboardWillShow);
        this.keyboardWillHideListener = react_native_1.Keyboard.addListener('keyboardWillHide', this.keyboardWillHide);
    }
    componentWillUnmount() {
        if (this.keyboardWillShowListener) {
            this.keyboardWillShowListener.remove();
        }
        if (this.keyboardWillHideListener) {
            this.keyboardWillHideListener.remove();
        }
    }
    renderActions() {
        const _a = this.props, { containerStyle } = _a, props = __rest(_a, ["containerStyle"]);
        if (this.props.renderActions) {
            return this.props.renderActions(props);
        }
        if (this.props.onPressActionButton) {
            return react_1.default.createElement(Actions_1.default, Object.assign({}, props));
        }
        return null;
    }
    renderSend() {
        if (this.props.renderSend) {
            return this.props.renderSend(this.props);
        }
        return react_1.default.createElement(Send_1.default, Object.assign({}, this.props));
    }
    renderComposer() {
        if (this.props.renderComposer) {
            return this.props.renderComposer(this.props);
        }
        return react_1.default.createElement(Composer_1.default, Object.assign({}, this.props));
    }
    renderAccessory() {
        if (this.props.renderAccessory) {
            return (react_1.default.createElement(react_native_1.View, { style: [styles.accessory, this.props.accessoryStyle] }, this.props.renderAccessory(this.props)));
        }
        return null;
    }
    render() {
        return (react_1.default.createElement(react_native_1.View, { style: [
                styles.container,
                { position: this.state.position },
                this.props.containerStyle,
            ] },
            react_1.default.createElement(react_native_1.View, { style: [styles.primary, this.props.primaryStyle] },
                this.renderActions(),
                this.renderComposer(),
                this.renderSend()),
            this.renderAccessory()));
    }
}
exports.default = InputToolbar;
InputToolbar.defaultProps = {
    renderAccessory: null,
    renderActions: null,
    renderSend: null,
    renderComposer: null,
    containerStyle: {},
    primaryStyle: {},
    accessoryStyle: {},
    onPressActionButton: () => { },
};
InputToolbar.propTypes = {
    renderAccessory: prop_types_1.default.func,
    renderActions: prop_types_1.default.func,
    renderSend: prop_types_1.default.func,
    renderComposer: prop_types_1.default.func,
    onPressActionButton: prop_types_1.default.func,
    containerStyle: utils_1.StylePropType,
    primaryStyle: utils_1.StylePropType,
    accessoryStyle: utils_1.StylePropType,
};
//# sourceMappingURL=InputToolbar.js.map