"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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 component_mapper_1 = require("@bluebase/component-mapper");
const withPropsStyles_1 = require("../../withPropsStyles");
const styles_2 = require("@material-ui/core/styles");
// (MUIButton as any).displayName = 'Button';
exports.Button = withPropsStyles_1.withPropsStyles(styles_1.styles)(styles_2.withTheme(component_mapper_1.componentMapper(Button_1.default, {
    children: (props) => {
        const { title, children, loading, icon, bluebaseTheme } = props;
        const content = children ? children : title;
        const colors = styles_1.getButtonColors(props, props.theme, props.bluebaseTheme);
        let _icon;
        if (loading) {
            _icon = (react_1.default.createElement(components_1.ActivityIndicator, { color: colors.text, style: {
                    height: bluebaseTheme.spacing.unit * 3,
                    marginRight: bluebaseTheme.spacing.unit,
                    width: bluebaseTheme.spacing.unit * 3,
                } }));
        }
        else if (icon) {
            const size = icon.size || 24;
            const iconProps = Object.assign({ color: colors.text, size, style: Object.assign({ lineHeight: size, marginRight: bluebaseTheme.spacing.unit }, icon.style) }, icon);
            _icon = react_1.default.createElement(components_1.DynamicIcon, Object.assign({}, iconProps));
        }
        return (react_1.default.createElement(react_1.default.Fragment, null,
            _icon,
            content));
    },
    classes: 'classes',
    disabled: 'disabled',
    fullWidth: 'fullWidth',
    onClick: 'onPress',
    size: 'size',
    style: ({ style }) => react_native_1.StyleSheet.flatten(style),
    variant: 'variant',
})));
exports.Button.defaultProps = components_1.ButtonDefaultProps;
exports.Button.displayName = 'Button';
