@use "sass:map";
@use "../mixins/breakpoints";
@use "../mixins/text-emphasis";
@use "../mixins/text-hide";
@use "../mixins/text-truncate";
@use "../vendor/rfs";
@use "../variables";

// stylelint-disable declaration-no-important

//
// Text
//

.text-monospace { font-family: variables.$font-family-monospace !important; }

// Alignment

.text-justify  { text-align: justify !important; }
.text-wrap     { white-space: normal !important; }
.text-nowrap   { white-space: nowrap !important; }
.text-truncate { @include text-truncate.text-truncate(); }

// Responsive alignment

@each $breakpoint in map.keys(variables.$grid-breakpoints) {
  @include breakpoints.media-breakpoint-up($breakpoint) {
    $infix: breakpoints.breakpoint-infix($breakpoint, variables.$grid-breakpoints);

    .text#{$infix}-left   { text-align: left !important; }
    .text#{$infix}-right  { text-align: right !important; }
    .text#{$infix}-center { text-align: center !important; }
  }
}

// Size

@each $size, $value in variables.$font-sizes {
  .font-size-#{$size} {
    font-size: $value !important;
  }
}

// Responsive size

@each $breakpoint in map.keys(variables.$grid-breakpoints) {
  @include breakpoints.media-breakpoint-up($breakpoint) {
    $infix: breakpoints.breakpoint-infix($breakpoint, variables.$grid-breakpoints);
    @each $size, $value in variables.$font-sizes {
      $line-height: map.get(variables.$line-heights, $size);
      .font-size#{$infix}-#{$size} {
        font-size: $value !important;
        line-height: $line-height !important;
      }
    }
  }
}

.font-size-h1 { @include rfs.font-size(variables.$h1-font-size, true); }
.font-size-h2 { @include rfs.font-size(variables.$h2-font-size, true); }
.font-size-h3 { @include rfs.font-size(variables.$h3-font-size, true); }
.font-size-h4 { @include rfs.font-size(variables.$h4-font-size, true); }
.font-size-h5 { @include rfs.font-size(variables.$h5-font-size, true); }
.font-size-h6 { @include rfs.font-size(variables.$h6-font-size, true); }

@include breakpoints.media-breakpoint-up(lg) {
  .font-size-h1 { @include rfs.font-size(variables.$h1-font-size-desktop, true); }
  .font-size-h2 { @include rfs.font-size(variables.$h2-font-size-desktop, true); }
  .font-size-h3 { @include rfs.font-size(variables.$h3-font-size-desktop, true); }
  .font-size-h4 { @include rfs.font-size(variables.$h4-font-size-desktop, true); }
  .font-size-h5 { @include rfs.font-size(variables.$h5-font-size-desktop, true); }
  .font-size-h6 { @include rfs.font-size(variables.$h6-font-size-desktop, true); }
}

// Transformation

.text-lowercase  { text-transform: lowercase !important; }
.text-uppercase  { text-transform: uppercase !important; }
.text-capitalize { text-transform: capitalize !important; }

// Weight and italics

.font-weight-lightest { font-weight: variables.$font-weight-lightest !important; }
.font-weight-light    { font-weight: variables.$font-weight-light !important; }
.font-weight-lighter  { font-weight: variables.$font-weight-lighter !important; }
.font-weight-normal   { font-weight: variables.$font-weight-normal !important; }
.font-weight-semibold { font-weight: variables.$font-weight-semibold !important; }
.font-weight-bold     { font-weight: variables.$font-weight-bold !important; }
.font-weight-bolder   { font-weight: variables.$font-weight-bolder !important; }
.font-weight-boldest  { font-weight: variables.$font-weight-boldest !important; }
.font-italic          { font-style: italic !important; }

// Line height
.line-height-base { line-height: variables.$line-height-base !important; }

// Contextual colors

.text-white { color: variables.$white !important; }

@each $color, $value in variables.$theme-colors {
  @include text-emphasis.text-emphasis-variant(".text-#{$color}", $value, true);
}

.text-body { color: variables.$body-color !important; }
.text-muted { color: variables.$text-muted !important; }

.text-black-50 { color: rgba(variables.$black, .5) !important; }
.text-white-50 { color: rgba(variables.$white, .5) !important; }

// Misc

.text-hide {
  @include text-hide.text-hide($ignore-warning: true);
}

.text-decoration-none { text-decoration: none !important; }

.text-break {
  word-break: break-word !important; // Deprecated, but avoids issues with flex containers
  word-wrap: break-word !important; // Used instead of `overflow-wrap` for IE & Edge Legacy
}

// Reset

.text-reset { color: inherit !important; }

@mixin text-colors($color, $value, $relative: true) {
  .text-#{$color} {
    color: $value !important;
  }
}

// theme-colors are in _text-variants.scss
// Add color text classes
@each $color, $value in variables.$colors {
  @include text-colors($color, $value);
}

// Core colors
@each $color, $value in variables.$core-colors {
  @include text-colors($color, $value);
}

// Add gray text colors classes
@each $color, $value in variables.$grays {
  @include text-colors($color, $value);
}

// Add teal text colors classes
@each $color, $value in variables.$teals {
  @include text-colors($color, $value);
}

// Add cyan text colors classes
@each $color, $value in variables.$cyans {
  @include text-colors($color, $value);
}

// Add pink text colors classes
@each $color, $value in variables.$pinks {
  @include text-colors($color, $value);
}

// Add yellow text colors classes
@each $color, $value in variables.$yellows {
  @include text-colors($color, $value);
}

// Add orange text colors classes
@each $color, $value in variables.$oranges {
  @include text-colors($color, $value);
}

// Add blue text colors classes
@each $color, $value in variables.$blues {
  @include text-colors($color, $value);
}
