@use 'sass:map';

@use './color';
@use '../functions/tokens';
@use '../functions/icons';
@use '../functions/utilities';
@use '../variables/components/forms';

// Source: https://kovart.github.io/dashed-border-generator/ + added stroke-vector-effect
@function get-background-svg-stroke(
  $type,
  $color,
  $stroke-dasharray,
  $stroke-pathlength,
  $stroke-width
) {
  $svg-additional-attributes: '';
  $stroke-pathlength-attribute: '';

  @if ($type == 'circle') {
    $svg-additional-attributes: "rx='100' ry='100'";
  }
  @if ($type == 'switch') {
    $svg-additional-attributes: "rx='12' ry='12'";
  }
  @if ($stroke-pathlength != 'initial') {
    $stroke-pathlength-attribute: " pathLength='" + $stroke-pathlength + "'";
  }
  @return "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%' height='100%' " +
    $svg-additional-attributes + " fill='none' stroke='" + #{color.encode-uri-color($color)} +
    "' stroke-width='" + $stroke-width "' stroke-dasharray='" + $stroke-dasharray + "'" +
    $stroke-pathlength-attribute + ' /%3e%3c/svg%3e';
}

@function select-arrow-icon($state: null, $mode: 'light') {
  // Hardcoded colors because CSS variables cannot be used as fill color of background-image
  $arrow-color-map: (
    'enabled-light': #050400,
    'enabled-dark': #050400,
    'hover-light': #504f4b,
    'hover-dark': #504f4b,
    'selected-light': #050400,
    'selected-dark': #050400,
    'disabled-light': #696864,
    'disabled-dark': #fcfcfc99,
    'enabled-hcm-light': #050400,
    'enabled-hcm-dark': #fff,
    'selected-hcm-dark': #fff,
    'hover-hcm-dark': #fff,
    'hover-hcm-light': #050400,
  );
  @if ($state) {
    $icon: icons.get-colored-svg-url('2052', map.get($arrow-color-map, '#{$state}-#{$mode}'));
    $state: url('#{$icon}');
  }

  @return $state;
}
