@use 'sass:list';

@function g($enclosed, $scoped) {
  @if $scoped {
    @return ':global([data-is-#{$enclosed}]) &';
  } @else {
    @return '[data-is-#{$enclosed}] &';
  }
}

@mixin scroll-is($top: null, $bottom: null, $going-up: null, $scoped: false) {
  $sels: ();

  @if $top {
    $sels: list.append($sels, g('top=true', $scoped), comma);
  }
  @if $bottom {
    $sels: list.append($sels, g('bottom=true', $scoped), comma);
  }
  @if $going-up {
    $sels: list.append($sels, g('scrolling-up=true', $scoped), comma);
  }

  @if $top == false {
    $sels: list.append($sels, g('top=false', $scoped), comma);
  }
  @if $bottom == false {
    $sels: list.append($sels, g('bottom=false', $scoped), comma);
  }
  @if $going-up == false {
    $sels: list.append($sels, g('scrolling-up=false', $scoped), comma);
  }

  @at-root #{$sels} {
    @content;
  }
}

@mixin has-scroll($scoped: false) {
  @if $scoped {
    @at-root :global([data-has-scroll='true']) & {
      @content;
    }
  } @else {
    @at-root [data-has-scroll='true'] & {
      @content;
    }
  }
}
