"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Icon = exports.Loading = exports.TextButton = exports.ButtonWrapper = exports.Touchable = void 0;
const tslib_1 = require("tslib");
const native_1 = tslib_1.__importDefault(require("styled-components/native"));
const theme_toolkit_1 = require("@platformbuilders/theme-toolkit");
const Icon_1 = tslib_1.__importDefault(require("../Icon"));
const LoadingIndicator_1 = tslib_1.__importDefault(require("../LoadingIndicator"));
const Touchable_1 = tslib_1.__importDefault(require("../Touchable"));
const Typography_1 = tslib_1.__importDefault(require("../Typography"));
const borderWidthSmall = (0, theme_toolkit_1.getTheme)('borderWidth.sm');
const brandPrimary = (0, theme_toolkit_1.getTheme)('brand.primary.main');
const brandPrimaryContrast = (0, theme_toolkit_1.getTheme)('brand.primary.contrast');
const brandSecondary = (0, theme_toolkit_1.getTheme)('brand.secondary.main');
const brandSecondaryContrast = (0, theme_toolkit_1.getTheme)('brand.secondary.contrast');
const brandAccent = (0, theme_toolkit_1.getTheme)('brand.accent.main');
const brandAccentContrast = (0, theme_toolkit_1.getTheme)('brand.accent.contrast');
const infoMain = (0, theme_toolkit_1.getTheme)('info.main');
const infoContrast = (0, theme_toolkit_1.getTheme)('info.contrast');
const dangerMain = (0, theme_toolkit_1.getTheme)('danger.main');
const dangerContrast = (0, theme_toolkit_1.getTheme)('danger.contrast');
const successMain = (0, theme_toolkit_1.getTheme)('success.main');
const successContrast = (0, theme_toolkit_1.getTheme)('success.contrast');
const warningMain = (0, theme_toolkit_1.getTheme)('warning.main');
const warningContrast = (0, theme_toolkit_1.getTheme)('warning.contrast');
const buttonRadius = (0, theme_toolkit_1.getTheme)('borderRadius.sm');
const minimumSpacing = (0, theme_toolkit_1.getTheme)('spacing.xs');
const smallSpacing = (0, theme_toolkit_1.getTheme)('spacing.sm');
const isLeftIcon = (0, theme_toolkit_1.ifStyle)('leftIcon');
const isRightIcon = (0, theme_toolkit_1.ifStyle)('rightIcon');
const hasBorder = (0, theme_toolkit_1.ifStyle)('hasBorder');
const isFlat = (0, theme_toolkit_1.ifStyle)('flat');
const isDisabled = (0, theme_toolkit_1.ifStyle)('disabled');
const buttonSize = 45;
function isTintVariant(bandSelected, props) {
    if (props.buttonVariant === 'tint') {
        return `${bandSelected(props)}10`;
    }
    else {
        return `${bandSelected(props)}`;
    }
}
const getBackgroundColor = (props) => {
    if (props.buttonVariant === 'flat' ||
        props.buttonVariant === 'ghost' ||
        props.buttonVariant === 'outline') {
        return 'transparent';
    }
    switch (props.colorVariant) {
        case 'primary':
            return isTintVariant(brandPrimary, props);
        case 'secondary':
            return isTintVariant(brandSecondary, props);
        case 'accent':
            return isTintVariant(brandAccent, props);
        case 'info':
            return isTintVariant(infoMain, props);
        case 'warning':
            return isTintVariant(warningMain, props);
        case 'danger':
            return isTintVariant(dangerMain, props);
        case 'success':
            return isTintVariant(successMain, props);
        default:
            return `${brandPrimary(props)}`;
    }
};
const getTextColor = (props) => {
    switch (props.colorVariant) {
        case 'primary':
            return `${props.buttonVariant === 'filled'
                ? brandPrimaryContrast(props)
                : brandPrimary(props)}`;
        case 'secondary':
            return `${props.buttonVariant === 'filled'
                ? brandSecondaryContrast(props)
                : brandSecondary(props)}`;
        case 'accent':
            return `${props.buttonVariant === 'filled'
                ? brandAccentContrast(props)
                : brandAccent(props)}`;
        case 'danger':
            return `${props.buttonVariant === 'filled'
                ? dangerContrast(props)
                : dangerMain(props)}`;
        case 'info':
            return `${props.buttonVariant === 'filled' ? infoContrast(props) : infoMain(props)}`;
        case 'warning':
            return `${props.buttonVariant === 'filled'
                ? warningContrast(props)
                : warningMain(props)}`;
        case 'success':
            return `${props.buttonVariant === 'filled'
                ? successContrast(props)
                : successMain(props)}`;
        default:
            return `${brandPrimaryContrast(props)}`;
    }
};
exports.Touchable = (0, native_1.default)(Touchable_1.default) `
  border-radius: ${(props) => props.rounded ? buttonSize / 2 : buttonRadius(props)}px;
`;
exports.ButtonWrapper = native_1.default.View `
  height: ${buttonSize}px;
  flex-direction: row;
  align-items: center;
  min-width: ${({ minWidth }) => `${minWidth || '180px'}`};
  max-width: ${({ maxWidth }) => maxWidth || '100%'};
  overflow: hidden;
  padding: ${(props) => props.rounded ? '0' : `${minimumSpacing(props)}px`};
  border-radius: ${(props) => props.rounded ? buttonSize / 2 : buttonRadius(props)}px;
  justify-content: center;
  background-color: ${isFlat('transparent', getBackgroundColor)};
  border-color: ${getTextColor};
  border-width: ${hasBorder(borderWidthSmall, '0')}px;
  opacity: ${isDisabled(0.3, 1)};
`;
exports.TextButton = (0, native_1.default)(Typography_1.default) `
  letter-spacing: 0.4px;
  color: ${isFlat(getBackgroundColor, getTextColor)};
  font-weight: bold;
`;
exports.Loading = (0, native_1.default)(LoadingIndicator_1.default).attrs({
    variant: 'button',
}) `
  align-self: center;
  width: 55px;
`;
exports.Icon = (0, native_1.default)(Icon_1.default).attrs((props) => ({
    color: getTextColor(props),
})) `
  margin-right: ${isLeftIcon(smallSpacing, 0)}px;
  margin-left: ${isRightIcon(smallSpacing, 0)}px;
`;
//# sourceMappingURL=styles.js.map