@use "sass:list";
@use "sass:map";
@use "../variables/border-width.scss" as *;
@use "../variables/radius.scss" as *;

@function ds-border-radius($units: null) {
  @if ($units) {
    @return _ds-get-metric($radius, $units);
  }

  @return null;
}

@function ds-border-width($units: null) {
  @if ($units) {
    @return _ds-get-metric($border-width, $units);
  }

  @return null;
}

@function _ds-get-metric($map, $units) {
  $values: ();

  @each $unit in $units {
    $value: map.get($map, $unit);
    @if ($unit == 0) {
      $value: 0;
    } @else if ($value) {
      $value: $value * 1px;
    }
    $values: list.append($values, $value);
  }

  @if list.length($values) == 1 {
    @return list.nth($values, 1);
  }

  @return $values;
}
