import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef } from 'react';
import styled, { css } from 'styled-components';
import { rgba } from 'polished';
import { defaultThemeProp } from '../../theme';
import { tryCatch } from '../../utils';
import { calculateFontSize } from '../../styles';
export const StyledText = styled.span(props => {
    const { variant, status, theme: { base: { 'font-size': fontSize, 'font-scale': fontScale, palette: { 'foreground-color': foregroundColor, urgent: error, warn: warning, success }, transparency: { 'transparent-3': secondaryAlpha } }, components: { text } } } = props;
    let color;
    if (status) {
        color = {
            error,
            warning,
            success
        }[status];
    }
    if (variant === 'secondary') {
        color = tryCatch(() => rgba(color ?? foregroundColor, secondaryAlpha));
    }
    const fontSizes = calculateFontSize(fontSize, fontScale);
    return css `
    font-size: ${fontSizes[text[variant]['font-size']]};
    font-weight: ${text[variant]['font-weight']};
    color: ${color};
  `;
});
StyledText.defaultProps = defaultThemeProp;
const Text = forwardRef(function Text({ variant = 'primary', as, ...restProps }, ref) {
    // If variant is for a heading, and no as is passed, set as to heading tag.
    if (!as && /h\d/i.test(variant))
        as = variant;
    return _jsx(StyledText, { ref: ref, variant: variant, as: as, ...restProps });
});
export default Text;
//# sourceMappingURL=Text.js.map