@use 'sass:color';
@use 'sass:meta';
@use 'sass:math';
@use 'sass:string';

@function rgb-values($color) {
  @if (meta.type-of($color) != color) {
    @error "Please provide a valid color for this function. Got '#{$color}'";
  }
  $red: null;
  $green: null;
  $blue: null;

  @if meta.function-exists('channel', $module: color) {
    $red: color.channel($color, 'red', $space: rgb);
    $green: color.channel($color, 'green', $space: rgb);
    $blue: color.channel($color, 'blue', $space: rgb);
  } @else {
    $red: color.red($color);
    $green: color.green($color);
    $blue: color.blue($color);
  }

  @return $red, $green, $blue;
}

@function get-hex-string($color) {
  @if (meta.type-of($color) != color) {
    @error "Please provide a color for this function. Supplied: '#{$color}'.";
  }
  $hex: string.slice(color.ie-hex-str($color), 4);

  @return string.unquote('\##{string.to-lower-case($hex)}');
}

// Source: https://gist.github.com/certainlyakey/e9c0d8f5c87ff47e3d5b
@function encode-uri-color($string) {
  @if meta.type-of($string) == 'color' and string.index(#{$string}, '#') == 1 {
    $hex: string.slice(color.ie-hex-str($string), 4);
    $string: string.unquote('#{$hex}');

    @return '%23' + $string;
  }

  @return $string;
}
