@use 'sass:map';

@use 'config';
@use 'function' as *;
@use '../common/var' as *;

// set css var value, because we need translate value to string
// for example:
// @include set-var-value(('color', 'primary'), red);
// --vs-color-primary: red;
@mixin set-var-value($name, $value) {
  #{joinVarName($name)}: #{$value};
}

@mixin set-color($name, $color) {
  @include set-var-value($name, #{hex2rgb($color)});
}

// @include set-var-type('color', 'primary', $map);
// --vs-color-primary: #{map.get($map, 'primary')};
@mixin set-var-type($name, $type, $variables) {
  #{getCssVarName($name, $type)}: #{map.get($variables, $type)};
}

@mixin set-colors($type) {
  @include set-var-value($type, hex2rgb(map.get($colors, $type, 'base')));

  @each $i in (3, 5, 7, 8, 9) {
    @include set-color(
      ($type, 'light', $i),
      map.get($colors, $type, 'light-#{$i}')
    );
  }

  @include set-color(($type, 'dark-2'), map.get($colors, $type, 'dark-2'));
}

// set all css var for component by map
@mixin set-component-var($name, $variables) {
  @each $attribute, $value in $variables {
    @if $attribute == 'default' {
      #{getCssVarName($name)}: #{$value};
    } @else {
      #{getCssVarName($name, $attribute)}: #{$value};
    }
  }
}

@mixin set-component-color($component, $variables) {
  @each $name, $color in $variables {
    $separator: '';
    @if $component != '' and $name != '' {
      $separator: '-';
    }
    @include set-color($component + $separator + $name, $color);
  }
}

// generate css var from existing css var
// for example:
// @include css-var-from-global(('button', 'text-color'), ('color', $type))
// --vs-button-text-color: var(--vs-color-#{$type});
@mixin css-var-from-global($var, $gVar) {
  $varName: joinVarName($var);
  $gVarName: joinVarName($gVar);
  #{$varName}: var(#{$gVarName});
}
