import React from 'react'

const tagByVariant = {
  h1: 'h1',
  h2: 'h2',
  h3: 'h3',
  h4: 'h4',
  h5: 'h5',
  h6: 'h6',
  pageTitle: 'h1',
  pageSubtitle: 'h2',
  sectionTitle: 'h2',
  sectionSubtitle: 'h3',
  note: 'h3',
  paragraph: 'p',
  body: 'span',
  label: 'p',
}
const classNameByVariant = {
  h1: 'mt-typography__h1',
  h2: 'mt-typography__h2',
  h3: 'mt-typography__h3',
  h4: 'mt-typography__h4',
  h5: 'mt-typography__h5',
  h6: 'mt-typography__h6',
  pageTitle: 'mt-typography__page-title',
  pageSubtitle: 'mt-typography__page-subtitle',
  sectionTitle: 'mt-typography__section-title',
  sectionSubtitle: 'mt-typography__section-subtitle',
  note: 'mt-typography__note',
  paragraph: 'mt-typography__paragraph',
  body: 'mt-typography__body',
  label: 'mt-typography__label',
}

const MTTypography = ({
  variant = 'paragraph',
  margin = true,
  padding = true,
  children,
  ...rest
}) => {
  const Tag = tagByVariant[variant]
  const className = classNameByVariant[variant]
  const marginModifier = margin ? '' : 'm-n'
  const paddingModifier = padding ? '' : 'p-n'

  return (
    <Tag
      className={ `${className} ${marginModifier} ${paddingModifier} ${rest.className}` }
      { ...rest }
    >
      { children }
    </Tag>
  )
}

export default MTTypography
