$fontWeightNamesMap = {
  '100': 'Thin',
  '200': 'ExtraLight',
  '300': 'Light',
  '400': 'Regular',
  '500': 'Medium',
  '600': 'SemiBold',
  '700': 'Bold',
  '800': 'ExtraBold'
  '900': 'Black',
  normal: 'Regular',
  bold: 'Bold'
}

DEPRECATED_SIZES = default xs 's' m l xl xxl xxxl xxxxl xxxxxl

font(size = body2)
  // Workaround global built-in function s()
  // http://stylus-lang.com/docs/bifs.html#sfmt-
  size = 's' if size is s
  size = body2 if size is default // DEPRECATED
  if size in DEPRECATED_SIZES
    p('font() mixin: size ' + size + ' is deprecated')
  font-size: $UI.fontSizes[size]
  line-height: $UI.lineHeights[size]

text(key = default) // DEPRECATED
  p('text() mixin is deprecated, use font() instead')
  // color
  if key is description
    color: $UI.colors.secondaryText
  else
    color: $UI.colors.mainText

  // font, line
  if key is default
    font()
  else if key is description
    font()
  else if key is h1
    font(xxxxxl)
  else if key is h2
    font(xxxxl)
  else if key is h3
    font(xxxl)
  else if key is h4
    font(xxl)
  else if key is h5
    font(xl)
  else if key is h6
    font(l)

fontFamily(
  fontName = normal,
  fontWeight = $UI.fontWeights.normal,
  fontStyle = normal
)
  defaultFontFamilies = $UI.fontFamilies.default || {}
  platformFontFamilies = $UI.fontFamilies[$PLATFORM] || {}
  fontFamily = defaultFontFamilies[fontName] || platformFontFamilies[fontName] || fontName

  if (fontFamily) {
    if (isCustomFont(fontFamily)) {
      thickness = $fontWeightNamesMap['' + fontWeight]
      isRegular = thickness is 'Regular'
      isItalic = fontStyle is italic

      fontFamily += '-'
      // add thickness
      // don't add thickness to font family name if regular and italic
      if (!isRegular || !isItalic) {
        fontFamily += $fontWeightNamesMap['' + fontWeight]
      }
      // add style
      if (isItalic) {
        fontFamily += 'Italic'
      }
    } else {
      font-weight fontWeight
      font-style fontStyle
    }

    font-family fontFamily
  }

isCustomFont(fontFamily)
  return index($UI.customFontFamilies, fontFamily) isnt null
