"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const tslib_1 = require("tslib");
const components_1 = require("@bluebase/components");
const styles_1 = require("./styles");
const Button_1 = tslib_1.__importDefault(require("@material-ui/core/Button"));
const react_1 = tslib_1.__importDefault(require("react"));
const react_native_1 = require("react-native");
const styles_2 = require("@material-ui/core/styles");
const core_1 = require("@bluebase/core");
exports.Button = (props) => {
    const { title, children, loading, icon, disabled, fullWidth, onPress, size, variant } = props;
    const { theme } = core_1.useTheme();
    const muiTheme = styles_2.useTheme();
    const classes = styles_1.useStyles(Object.assign(Object.assign({}, props), { theme, muiTheme }));
    const style = react_native_1.StyleSheet.flatten(props.style);
    const content = children ? children : title;
    const colors = styles_1.getButtonColors(props, muiTheme, theme);
    let _icon;
    if (loading) {
        _icon = (react_1.default.createElement(components_1.ActivityIndicator, { color: variant === 'contained' ? colors.text : colors.main, style: {
                height: theme.spacing.unit * 3,
                marginRight: theme.spacing.unit,
                width: theme.spacing.unit * 3,
            } }));
    }
    else if (icon) {
        const iconSize = icon.size || 24;
        const iconProps = Object.assign({ color: variant === 'contained' ? colors.text : colors.main, size: iconSize, style: Object.assign({ lineHeight: iconSize, marginRight: theme.spacing.unit }, icon.style) }, icon);
        _icon = react_1.default.createElement(components_1.DynamicIcon, Object.assign({}, iconProps));
    }
    return (react_1.default.createElement(Button_1.default, { classes: classes, disabled: disabled, fullWidth: fullWidth, onClick: onPress, size: size, style: style, variant: variant },
        _icon,
        content));
};
exports.Button.defaultProps = components_1.ButtonDefaultProps;
exports.Button.displayName = 'Button';
