@use "sass:map" as sass-map;
@use "sass:math";
@use "../../../styles/tokens/base";
@use "../../../styles/tokens/color";
@use "../../../styles/tokens/space";
@use "../../../styles/tools/convert";
@use "../../../styles/tools/generate";
@use "../../../styles/tools/map";
@use "../../../styles/tokens/breakpoint";
@use "../../Button/styles/config" as button-config;
@use "../../Button/styles/mixins" as button-mixins;
@use "./config";

/* stylelint-disable value-no-vendor-prefix, property-no-vendor-prefix */

@mixin base {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  position: relative;
  margin-bottom: space.get("large");
}

@mixin viewport-wrapper {
  // wraps viewport and arrows to center them vertically
  position: relative;
}

@mixin viewport {
  margin: 0 auto;
  position: relative;
  overflow-y: hidden;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
  transform: translateZ(0);
  scrollbar-width: none; // hides scrollbar on FF

  @each $breakpoint, $size in config.$viewport-horizontal-spacing {
    @include breakpoint.get($breakpoint) {
      margin-left: $size;
      margin-right: $size;
    }
  }

  .carousel--scrollbar & {
    margin-left: 0;
    margin-right: 0;
  }

  @include breakpoint.get("sm", "down") {
    padding-bottom: math.div(config.$space, 2);
  }

  @include breakpoint.get("md") {
    margin-bottom: config.$space;
    overflow-x: hidden; // hide scrollbar on larger screens
  }

  &.is-draggable {
    user-select: none;
    cursor: -webkit-grab;
    cursor: grab;
  }

  &.is-dragging {
    cursor: -webkit-grabbing;
    cursor: grabbing;
  }
}

@mixin track {
  transform: translateZ(0);
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  z-index: 1;
}

@function get-breakout-media-query($min, $max) {
  @return if(
    $max,
    "(min-width: #{$min}) and (max-width: #{$max})",
    "(min-width: #{$min})"
  );
}

@mixin base-breakout-buttons {
  @each $min, $max in config.$breakout-buttons-breakpoints {
    @media only screen and #{get-breakout-media-query($min, $max)} {
      margin-left: -#{convert.to-rem(60px)};
      margin-right: -#{convert.to-rem(60px)};
    }
  }

  &.carousel--bleed-right {
    margin-left: 0;
    margin-right: 0;
  }
}

@mixin slide-base {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  flex: 0 0 auto;
  padding: 0;
  user-select: none;

  > * {
    flex-shrink: 1;
    flex-grow: 0;
  }

  > *:last-child {
    margin-bottom: 0;
  }

  img {
    user-select: none;
    pointer-events: none;
  }
}

@mixin button-base {
  @include button-mixins.base(button-config.$base);
  @include button-mixins.square-base();
  @include button-mixins.square-size("default");
  @include base.focusring-round();

  position: absolute;
  top: 50%;
  z-index: 10;
  margin: 0;
  border-radius: 100%;

  @include breakpoint.get("sm", "down") {
    display: none;
  }
}

@mixin button-prev {
  left: 0;
  transform: translateY(-50%);
}

@mixin button-next {
  right: 0;
  transform: translateY(-50%);
}

@mixin button-disabled {
  @include generate.css-map(sass-map.get(button-config.$base, "disabled"));
}

@mixin pagination {
  user-select: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0 auto;
  padding: 0;
}

@mixin pagination-item {
  background: none;
  border: 0;
  padding: 0;
  user-select: none;
  display: block;
  cursor: pointer;
  border-radius: 100%;

  @include generate.css-map(config.$dot-layout);
  @include base.focusring-round();

  background-color: sass-map.get(config.$dot, "default");

  &:hover {
    background-color: sass-map.get(config.$dot, "hover");
  }

  &.is-active {
    background-color: sass-map.get(config.$dot, "active");
  }
}

@mixin scrollbar-base {
  position: relative;
  overflow: visible;
}

@mixin scrollbar-horizontal {
  height: convert.to-rem(8px);
  appearance: none;
  background-color: transparent;
  border-radius: 99px;

  &::before {
    content: "";
    position: absolute;
    top: convert.to-rem(1px);
    right: 0;
    bottom: convert.to-rem(1px);
    left: 0;
    background-color: var(--color-surface-moderate);
    border-radius: 99px;
    pointer-events: none;
  }

  &:hover .carousel__scrollbar-drag,
  .carousel__scrollbar-drag:hover {
    height: convert.to-rem(8px);
    margin-top: 0;
  }
}

@mixin scrollbar-drag {
  opacity: 1;
  background-color: var(--color-fill-contrast);
  border-radius: 99px;
  height: convert.to-rem(6px);
  margin-top: convert.to-rem(1px);

  &:hover {
    background-color: var(--color-fill-secondary) !important;
  }
}

@mixin scrollbar-variant {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

@mixin bleed-right-variant {
  overflow: visible;

  .carousel__viewport-wrapper {
    width: var(--carousel-bleed-shell-width, 100%);
    max-width: var(--carousel-bleed-shell-width, 100%);
    margin-left: var(--carousel-bleed-shell-margin-left, 0) !important;
    overflow-x: hidden;
    overflow-x: clip;
    overflow-y: visible;
  }

  .carousel__viewport {
    width: var(--carousel-bleed-viewport-width, 100%);
    max-width: var(--carousel-bleed-viewport-width, 100%);
    margin-right: 0;
    margin-left: var(--carousel-bleed-margin-left, 0) !important;
    overflow: visible !important;
  }
}
