@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";

@mixin base {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  position: relative;
}

@mixin viewport-wrapper {
  width: 100%;
  max-width: 100%;
}

@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
  min-width: 0;
  width: 100%;
  max-width: 100%;
  margin-bottom: convert.to-rem(30px);

  .carousel--scrollbar & {
    @include breakpoint.get("md", "down") {
      margin-bottom: convert.to-rem(20px);
    }
  }

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

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

@mixin navigation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: config.$navigation-gap;
  row-gap: convert.to-rem(12px);
}

@mixin controls {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: convert.to-rem(8px);
}

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

@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-disabled {
  @include generate.css-map(sass-map.get(button-config.$base, "disabled"));
}

@mixin pagination {
  user-select: none;
  display: flex;
  margin: 0;
  padding: 0;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
}

@mixin pagination-item {
  appearance: none;
  background: none;
  user-select: none;
  display: block;
  cursor: pointer;
  border-radius: 100%;
  border: 0;
  box-shadow: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;

  @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");
  }

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

  &.is-active {
    background-color: transparent;
    box-shadow: 0 0 0 2px var(--color-border-accent);
  }

  &.is-active:hover,
  &.is-active:active,
  &.is-active:focus,
  &.is-active:focus-visible {
    background-color: transparent;
    box-shadow: 0 0 0 2px var(--color-border-accent);
  }
}

@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;
  }
}
