// Functions :: List to selector

// Dependencies
@import "./str-replace";

@function _get-selector($selector: false) {
  @if not $selector {
    @error "_get-selector: A selector must be pass as the argument";
  }
  // Get the type of the selector
  $type: type-of($selector);

  @if $type == "list" {
    // Transforms the list into a string
    $selector: inspect($selector);
  }

  // After the transformation, the string will look like this:
  // (.class,)
  // We want the output to look like this:
  // .class

  // Normalizing the string
  $selector: _str-replace($selector, ",", "");
  $selector: _str-replace($selector, "((", "(");
  $selector: _str-replace($selector, "))", ")");


  @if str-index($selector, "(") == 1 {
    $selector: str-slice($selector, 2);
  }


  @if str-index($selector, ")") == str-length($selector) {
    $end: str-length($selector) - 1;
    $selector: str-slice($selector, 1, $end);
  }

  // This is repeated to catch situations where double parenthesis could
  // slip through. An example would be in the case of :not()
  $selector: _str-replace($selector, "))", ")");

  @return #{$selector};
}
