"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Text = void 0;
const react_1 = __importDefault(require("react"));
const css_utilities_1 = require("@shopify/css-utilities");
const legacy_1 = require("../../utilities/legacy");
const typography_styles_css_1 = __importDefault(require("../../utilities/typography-styles.css"));
const Text_css_1 = __importDefault(require("./Text.css"));
function Text({ children, size, emphasized, subdued, appearance, role, style, id, }) {
    const className = css_utilities_1.classNames(Text_css_1.default.Text, emphasized && Text_css_1.default.emphasized, emphasized && legacy_1.utilityDefaultTextColorEmphasized, subdued && Text_css_1.default.subdued, subdued && legacy_1.utilityDefaultTextColorSubdued, size && Text_css_1.default[css_utilities_1.variationName('size', size)], appearance && Text_css_1.default[css_utilities_1.variationName('appearance', appearance)], appearance && appearance === 'accent' && legacy_1.utilityDefaultColorAccent, style && typography_styles_css_1.default[style]);
    const content = emphasized ? <strong>{children}</strong> : children;
    const defaultProps = {
        className,
        id,
    };
    if (typeof role === 'string') {
        switch (role) {
            case 'address':
                return <address {...defaultProps}>{content}</address>;
            case 'deletion':
                return <del {...defaultProps}>{content}</del>;
            default:
                throw new Error('Invalid Text’s role');
        }
    }
    if (typeof role === 'object') {
        switch (role.type) {
            case 'abbreviation':
                return (<abbr {...{
                    defaultProps,
                    className: css_utilities_1.classNames(className, Text_css_1.default.Abbr),
                }} title={role.for}>
            {content}
          </abbr>);
            case 'directional-override':
                return (<bdo {...defaultProps} dir={role.direction}>
            {content}
          </bdo>);
            case 'datetime':
                return (<time {...defaultProps} dateTime={role.machineReadable}>
            {content}
          </time>);
            default:
                throw new Error('Invalid Text’s role');
        }
    }
    const Component = emphasized ? 'strong' : 'span';
    return <Component {...defaultProps}>{children}</Component>;
}
exports.Text = Text;
