"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getButtonColors = exports.useStyles = void 0;
const core_1 = require("@material-ui/core");
const styles_1 = require("@material-ui/core/styles");
exports.useStyles = core_1.makeStyles({
    contained: (props) => {
        const { color, disabled, muiTheme, theme } = props;
        if (!color || (color === 'default' && !disabled) || disabled) {
            return {};
        }
        const colors = getButtonColors(props, muiTheme, theme);
        return {
            backgroundColor: colors.main,
            color: colors.text,
            '&:hover': {
                backgroundColor: colors.hover,
            },
        };
    },
    outlined: (props) => {
        const { color, disabled, muiTheme, theme } = props;
        if (!color || (color === 'default' && !disabled) || disabled) {
            return {};
        }
        const colors = getButtonColors(props, muiTheme, theme);
        return {
            border: `1px solid ${styles_1.alpha(colors.main, 0.5)}`,
            color: colors.main,
            '&:hover': {
                '@media (hover: none)': {
                    backgroundColor: 'transparent',
                },
                backgroundColor: styles_1.alpha(colors.hover, theme.palette.action.hoverOpacity),
                border: `1px solid ${colors.main}`,
            },
        };
    },
    text: (props) => {
        const { color, disabled, muiTheme, theme } = props;
        if (!color || (color === 'default' && !disabled) || disabled) {
            return {};
        }
        const colors = getButtonColors(props, muiTheme, theme);
        return {
            color: colors.main,
            '&:hover': {
                '@media (hover: none)': {
                    backgroundColor: 'transparent',
                },
                backgroundColor: styles_1.alpha(colors.hover, theme.palette.action.hoverOpacity),
            },
        };
    },
});
function getButtonColors({ color, disabled, variant }, muiTheme, theme) {
    const colors = {
    // hover: theme.palette.primary.main,
    // main: theme.palette.primary.main,
    // text: theme.palette.text.primary,
    };
    if (disabled) {
        colors.hover = theme.palette.action.disabledBackground;
        colors.main = theme.palette.action.disabledBackground;
        colors.text = theme.palette.action.disabled;
        return colors;
    }
    if (!color || (color === 'default' && !disabled)) {
        return colors;
    }
    // If color is NOT primary, secondary or default then create custom styles
    if (color === 'primary' ||
        color === 'secondary' ||
        color === 'success' ||
        color === 'error' ||
        color === 'warning') {
        if (variant === 'contained') {
            colors.hover = theme.palette[color].dark;
            colors.main = theme.palette[color].main;
            colors.text = theme.palette[color].contrastText;
        }
        else {
            colors.hover = theme.palette[color].dark;
            colors.main = theme.palette[color].main;
            colors.text = theme.palette[color].contrastText;
        }
    }
    else {
        colors.hover = color;
        colors.main = color;
        colors.text = muiTheme.palette.getContrastText(color);
    }
    return colors;
}
exports.getButtonColors = getButtonColors;
