// Font sizing extends, using rem mixin
// All line-heights are aligned to baseline grid
// stylelint-disable property-no-vendor-prefix

@function fontSizeToRemOrEm($size, $sizingMethod: 'rem') {
  @if ($sizingMethod == 'rem') {
    @return #{$size / $euiFontSize}rem;
  } @else if ($sizingMethod == 'em') {
    @return #{$size / $euiFontSize}em;
  }
}

@function marginToRemOrEm($elementSize, $elementFontSize, $sizingMethod: 'rem') {
  @if ($sizingMethod == 'rem') {
    @return #{$elementSize / $euiFontSize}rem;
  } @else if ($sizingMethod == 'em') {
    @return #{$elementSize / $elementFontSize}em;
  }
}

// Spit out rem and px
@mixin fontSize($size: $euiFontSize, $sizingMethod: 'rem') {
  @if ($sizingMethod == 'rem') {
    font-size: $size;
    font-size: fontSizeToRemOrEm($size, 'rem');
  } @else if ($sizingMethod == 'em') {
    font-size: fontSizeToRemOrEm($size, 'em');
  }
}

@mixin lineHeightFromBaseline($multiplier: 3) {
  line-height: lineHeightFromBaseline($multiplier);
}

// Some mixins that help us deal with browser scaling of text more consistently.
// Essentially, fonts across eui should scale against the root html element, not
// against parent inheritance.

// Redoing this mixin mainly to remove the letter-spacing
@mixin euiFont {
  font-family: $euiFontFamily;
  font-weight: $euiFontWeightRegular;
  letter-spacing: normal;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  font-kerning: normal;
}

@mixin euiFontSizeXS {
  @include fontSize($euiFontSizeXS);
  @include lineHeightFromBaseline(2);
}

@mixin euiFontSizeS {
  @include fontSize($euiFontSizeS);
  @include lineHeightFromBaseline(3);
}

@mixin euiFontSize {
  @include fontSize($euiFontSize);
  @include lineHeightFromBaseline(3);
}

@mixin euiFontSizeM {
  @include fontSize($euiFontSizeM);
  @include lineHeightFromBaseline(3);
}

@mixin euiFontSizeL {
  @include fontSize($euiFontSizeL);
  @include lineHeightFromBaseline(4);
}

@mixin euiFontSizeXL {
  @include fontSize($euiFontSizeXL);
  @include lineHeightFromBaseline(4);
}

@mixin euiFontSizeXXL {
  @include fontSize($euiFontSizeXXL);
  @include lineHeightFromBaseline(5);
}
