@use 'sass:math';
@use 'sass:meta';
@use 'variables' as vars;

@function strip-unit($value) {
  @if meta.type-of($value)=='number' and not math.is-unitless($value) {
    @return math.div($value, ($value * 0 + 1));
  }

  @return $value;
}

@function rem($value, $base: 16px) {
  @if math.is-unitless($value) {
    $value: $value * 1px;
  }

  @return math.div(strip-unit($value), strip-unit($base)) * 1rem;
}

@function fluid($min-size,
  $max-size,
  $min-vw: vars.$fluid-min-vw,
  $max-vw: vars.$fluid-max-vw) {
  $min-size-num: strip-unit($min-size);
  $max-size-num: strip-unit($max-size);
  $min-vw-num: strip-unit($min-vw);
  $max-vw-num: strip-unit($max-vw);

  @if $max-vw-num <=$min-vw-num {
    @error '$max-vw must be greater than $min-vw.';
  }

  $slope: math.div($max-size-num - $min-size-num, $max-vw-num - $min-vw-num);
  $slope-vw: $slope * 100;
  $intercept: $min-size-num - ($slope * $min-vw-num);

  @return clamp(#{$min-size}, #{$slope-vw}vw + #{$intercept}px, #{$max-size});
}