@use "sass:map" as sass-map;
@use "sass:math";
@use "../../../styles/tokens/base";
@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 "../../Grid/styles/mixins" as grid-mixins;
@use "../../../styles/typography/config" as typography-config;
@use "./config";

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

@mixin base {
  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;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
  transform: translateZ(0);
  scrollbar-width: none; // hides scrollbar on FF

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

  @include breakpoint.get("md") {
    margin-bottom: config.$space;
  }

  &::-webkit-scrollbar {
    opacity: 0;
    height: 0;

    @include breakpoint.get("sm", "down") {
      height: convert.to-rem(6px);
      appearance: none;
      background-color: var(--color-surface-moderate);
      border-radius: 99px;
    }
  }

  &::-webkit-scrollbar-thumb {
    @include breakpoint.get("sm", "down") {
      opacity: 1;
      border-radius: 99px;
      background-color: var(--color-fill-contrast);
    }
  }

  &.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(
    sass($max): "(min-width: #{$min}) and (max-width: #{$max})";
      else: "(min-width: #{$min})"
  );
}

@mixin slide-base {
  display: flex;
  max-width: 100%;
  flex: 0 0 auto;
  user-select: none;
  background-color: var(--color-surface-primary);

  &--black {
    background-color: var(--color-surface-contrast);
    color: var(--color-text-inverse) !important;
  }

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

  @include breakpoint.get("md") {
    flex-direction: row-reverse;
    justify-content: space-between;
  }

  &:is(a) {
    cursor: pointer;
    &,
    &:visited,
    &:hover,
    &:active {
      color: inherit;
    }
  }
}

@mixin slide-image {
  width: convert.to-rem(100px);
  height: convert.to-rem(100px);
  display: flex;
  align-self: center;
  flex-shrink: 0;
  margin: space.get("small");

  picture,
  img {
    margin-bottom: 0;
  }

  img {
    user-select: none;
    pointer-events: none;
    width: 100%;
    height: 100%;
  }

  @include breakpoint.get("md") {
    width: convert.to-rem(176px);
    height: convert.to-rem(176px);
    flex-grow: 1;
    border-radius: 0;
    background-color: unset;
    justify-content: end;
    position: relative;
    margin: 0 convert.to-rem(50px) 0 0;

    img,
    picture {
      width: 100%;
      max-width: convert.to-rem(176px);
      object-fit: cover;
    }
  }

  @include breakpoint.get("lg") {
    width: convert.to-rem(200px);
    height: convert.to-rem(200px);
    margin-right: convert.to-rem(100px);

    img,
    picture {
      max-width: convert.to-rem(200px);
    }
  }
}

@mixin slide-title {
  margin-bottom: 0;
  @each $property,
    $value in map.map-deep-get(typography-config.$headings, 5, "default")
  {
    #{$property}: $value;
  }
  @include breakpoint.get("md") {
    @each $property,
      $value in map.map-deep-get(typography-config.$headings, 3, md)
    {
      #{$property}: $value;
    }

    margin-bottom: space.get();
  }
  @include breakpoint.get("lg") {
    @each $property,
      $value in map.map-deep-get(typography-config.$headings, 1, md)
    {
      #{$property}: $value;
    }
  }
  font-weight: 700;
}

@mixin slide-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: space.get("small") space.get("small") space.get("small") 0;

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

  @include breakpoint.get("md") {
    height: 100%;
    max-width: convert.to-rem(545px);
    justify-content: space-between;
    padding: space.get("medium");
  }

  @include breakpoint.get("md", "down") {
    @include generate.responsive-css-map(
      sass-map.get(typography-config.$body-text, "small")
    );
  }
}

@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 generate.css-map(sass-map.get(config.$dot, "default"));

  &:hover {
    @include generate.css-map(sass-map.get(config.$dot, "hover"));
  }

  &.is-active:not(:hover) {
    @include generate.css-map(sass-map.get(config.$dot, "active"));
  }

  .is-autoplay &.is-active:not(:focus-visible) {
    outline: none;
  }

  &:active {
    @include generate.css-map(sass-map.get(config.$dot, "default"));
  }

  &:focus-visible:not(:active) {
    @include generate.css-map(sass-map.get(config.$dot, "focus"));
  }
}

@mixin pagination-svg() {
  position: relative;
  display: none;
  left: -#{config.$outline-width-default};
  top: -#{config.$outline-width-default};
  // This transform is a workaround due to Safari not supporting negative values for stroke-dashoffset.
  // We're rotating the SVG so that the line starts to animate from the top (12o'clock).
  // The vertical flip is to make the line animate clockwise.
  transform: rotate(-90deg) scale(1, -1);

  .is-autoplay .is-active > & {
    display: block;
  }
}

@mixin pagination-circle() {
  stroke-width: config.$outline-width-default;
  stroke: var(--color-border-contrast);
  stroke-dasharray: config.$animated-dot-circumference;
  stroke-dashoffset: config.$animated-dot-circumference;
  animation-name: countdown;
  animation-iteration-count: 1;
  animation-timing-function: linear;
  animation-direction: reverse;
}
