"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.Typography = void 0;

var _style = _interopRequireDefault(require("styled-jsx/style"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _useTheme = _interopRequireDefault(require("../../hooks/useTheme"));

var _isThemePalette = _interopRequireDefault(require("../../utils/isThemePalette"));

var _jsxRuntime = require("react/jsx-runtime");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// Generated with util/create-component.js
const Typography = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
  const theme = (0, _useTheme.default)();
  const {
    children,
    color = theme.palette.text,
    component,
    variant = "body1",
    className = null,
    weight = null,
    align = "left",
    ...otherProps
  } = props;

  function handleTextAlign() {
    return align;
  }

  function handleVariantComponent() {
    switch (variant) {
      case "h1":
        return "h1";

      case "h2":
        return "h2";

      case "h3":
        return "h3";

      case "h4":
        return "h4";

      case "h5":
        return "h5";

      case "h6":
        return "h6";

      case "subtitle1":
        return "div";

      case "subtitle2":
        return "div";

      case "body1":
        return "p";

      case "body2":
        return "span";

      case "caption1":
        return "caption";

      case "caption2":
        return "span";

      case "code":
        return "pre";

      case "label":
        return "label";
    }
  }

  function handleColor() {
    if (!color) return `color: ${theme.palette.text};`;

    switch (color) {
      case "text":
        return `color: ${theme.palette.text};
                stroke: ${theme.palette.text}`;

      case "subtext":
        return `color: ${theme.palette.subtext};
                stroke: ${theme.palette.subtext}`;

      case "background":
        return `color: ${theme.palette.background};
                stroke: ${theme.palette.background}`;

      case "highlight":
        return `color: ${theme.palette.highlight};
                stroke: ${theme.palette.highlight}`;

      case "shade":
        return `color: ${theme.palette.shade};
                stroke: ${theme.palette.shade}`;

      default:
        return `color: ${(0, _isThemePalette.default)(color) ? theme.palette[color][500] : color};
                stroke: ${(0, _isThemePalette.default)(color) ? theme.palette[color][500] : color}`;
    }
  }

  const Component = component ? component : handleVariantComponent();
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, {
    "data-testid": "Typography",
    ref: ref,
    ...otherProps,
    className: _style.default.dynamic([["3708389123", [theme.font[variant].fontSize, theme.font[variant].fontFamily, weight ? weight : theme.font[variant].fontWeight, theme.font[variant].lineHeight, theme.font[variant].textTransform, theme.font[variant].letterSpacing, handleTextAlign(), handleColor()]]]) + " " + (otherProps && otherProps.className != null && otherProps.className || (0, _classnames.default)("Typography", className) || ""),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_style.default, {
      id: "3708389123",
      dynamic: [theme.font[variant].fontSize, theme.font[variant].fontFamily, weight ? weight : theme.font[variant].fontWeight, theme.font[variant].lineHeight, theme.font[variant].textTransform, theme.font[variant].letterSpacing, handleTextAlign(), handleColor()],
      children: `.Typography.__jsx-style-dynamic-selector{font-size:${theme.font[variant].fontSize};font-family:${theme.font[variant].fontFamily};font-weight:${weight ? weight : theme.font[variant].fontWeight};line-height:${theme.font[variant].lineHeight};text-transform:${theme.font[variant].textTransform};-webkit-letter-spacing:${theme.font[variant].letterSpacing};-moz-letter-spacing:${theme.font[variant].letterSpacing};-ms-letter-spacing:${theme.font[variant].letterSpacing};letter-spacing:${theme.font[variant].letterSpacing};text-align:${handleTextAlign()};${handleColor()};}`
    }), children]
  });
});
exports.Typography = Typography;