@use "./config";
@use "../../../styles/tokens/base";
@use "../../../styles/tokens/space";
@use "../../../styles/tools/convert";
@use "../../../styles/tools/generate";

$tab-focus-radius: convert.to-rem(5px);
$tab-focusring-space: convert.to-rem(
  base.$focusring-width + base.$focusring-offset
);
$tab-overflow-fade-width: convert.to-rem(72px);

@mixin list-viewport {
  position: relative;
  overflow: hidden;
  padding: $tab-focusring-space $tab-focusring-space 0;

  &::before,
  &::after {
    z-index: 2;
    width: $tab-overflow-fade-width;
    content: "";
    position: absolute;
    top: 0;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  &::before {
    left: 0;
    background: linear-gradient(
      to left,
      transparent 0%,
      var(--color-background-primary) 100%
    );
  }

  &::after {
    right: 0;
    background: linear-gradient(
      to right,
      transparent 0%,
      var(--color-background-primary) 100%
    );
  }

  &.has-left-overflow::before {
    opacity: 1;
  }

  &.has-right-overflow::after {
    opacity: 1;
  }
}

@mixin list-base($spacing: config.$tablist-spacing) {
  display: flex;
  overflow-x: auto;
  overflow-y: visible;
  margin-bottom: space.get("large");
  align-items: stretch;

  @include generate.css-map($spacing);
}

@mixin list-equal {
  flex-grow: 1;

  .tab-list__tab {
    text-align: center;
  }
}

@mixin list-item {
  display: flex;
  flex-flow: column;
  max-width: 66.66666%;
}

@mixin tab {
  flex: 1 1 auto;
  display: flex;
  flex-flow: column;
  justify-content: center;
  height: initial;
  position: relative;
  font-weight: 700;
  background: transparent;
  border-width: 0;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;

  &::after {
    content: "";
    position: absolute;
    inset: $tab-focusring-space * -1;
    border: base.$focus-outline;
    border-radius: calc(#{$tab-focus-radius} + #{$tab-focusring-space});
    opacity: 0;
    pointer-events: none;
  }

  &:focus {
    z-index: 1;
    outline-width: 0;
    outline-color: transparent;
  }

  &:focus::after {
    opacity: 1;
  }

  &:focus-visible {
    outline-width: 0;
    outline-color: transparent;
  }

  &:focus-visible::after {
    opacity: 1;
  }

  &:focus:not(:focus-visible)::after {
    opacity: 0;
  }

  &[aria-selected="true"] {
    z-index: 1;
  }
}

@mixin color-variant($config: config.$tab) {
  @include generate.css-map($config, "default");

  &[aria-selected="true"] {
    @include generate.css-map($config, "active");
  }

  &:hover:not([aria-selected="true"]):not([aria-disabled="true"]) {
    @include generate.css-map(config.$tab, "hover");
  }

  &[aria-disabled="true"]:not([aria-selected="true"]) {
    @include generate.css-map(config.$tab, "disabled");
  }
}

@mixin tab-size($size, $config: config.$tab-sizes) {
  @include generate.css-map($config, $size);
}

@mixin underline {
  flex: 1 1 auto;
  max-width: none;
  box-shadow: inset 0 -1px 0 0 var(--color-surface-moderate);
}

@mixin list-equal-item {
  flex-grow: 1;
  flex-basis: 0;
}
