@charset "UTF-8";

// Built-in modules
@use "sass:color";
@use "sass:list";
@use "sass:map";
@use "sass:math";
@use "sass:meta";
@use "sass:selector";
@use "sass:string";

// Mixkit settings and modules
@use "mixkit/settings" as settings;
@use "to-number" as convert;
@use "helpers/lengths" as convert-helpers;

/// Add unit to number without casting to string.
///
/// @name to-length
///
/// @group mixkit/convert
///
/// @param {string|number} $value
///
/// @param {string} $length
///   Valid CSS length.
///
/// @return {number (with unit)}
///
/// @require {function (mixkit/validate)} is-length
///
/// @require {map (mixkit/convert/helpers)} $map-all
///
/// @access public
///
/// @since 1.0.0

@function to-length($value, $length) {
  // Vars
  $list: ();
  $length-key: map.has-key(convert-helpers.$map-all, $length);

  // Check args
  @if not meta.type-of($value) == "number" {
    @error "Invalid argument type/s.";
  }

  // Return immediately
  @if meta.type-of($value) == "number" and not math.is-unitless($value) {
    @return $value;
  }

  // Multiply and return number with unit if map key exists
  @if $length-key {
    @return $value * map.get(convert-helpers.$map-all, $length);
  } @else {
    @return null;
  }
}
