@use 'sass:math';
@use 'sass:list';
@use 'sass:meta';

@function calc-rem($values, $base: 16px) {
  $result: ();

  @for $i from 1 through list.length($values) {
    $val: list.nth($values, $i);

    // Only convert if it's a number with px
    @if meta.type-of($val) == 'number' and math.unit($val) == 'px' {
      $rem: math.div($val, $base) * 1rem;
      $result: list.append($result, $rem, space);
    } @else {
      $result: list.append($result, $val, space);
    }
  }

  @return $result;
}

@function round-to($number, $decimals: 4) {
  $factor: math.pow(10, $decimals);
  @return math.div(math.round($number * $factor), $factor);
}

@function clamp-font($minFont, $maxFont, $minVw: 390px, $maxVw: 1920px) {
  $slope: math.div(100 * ($maxFont - $minFont), ($maxVw - $minVw));

  $y: $minFont - $slope * math.div($minVw, 100);

  $minFontRem: math.div($minFont, 16px);
  $maxFontRem: math.div($maxFont, 16px);
  $yRem: math.div($y, 16px);

  @return clamp(
          #{round-to($minFontRem)}rem,
          #{round-to($yRem)}rem + #{round-to($slope)}vw,
          #{round-to($maxFontRem)}rem
  );
}

@function gcd($a, $b) {
    @if $b == 0 {
        @return $a;
    }
    @return gcd($b, $a % $b);
}

@function aspect-ratio($width, $height) {
    $divisor: gcd($width, $height);
    $w: math.div($width, $divisor);
    $h: math.div($height, $divisor);
    @return list.slash($w, $h);
}

@mixin truncate($lines: 2){
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: $lines;
    line-clamp: $lines;
    -webkit-box-orient: vertical;
}
