@use 'sass:map';
@use './tabs-theme';

$oui-tab-animation-duration: 500ms !default;

// Combines the various structural styles we need for the tab group and tab nav bar.
@mixin structural-styles {
  .oui-mdc-tab-ripple {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    pointer-events: none;
  }
}
.oui-tab {
  &.oui-primary {
    .mdc-tab-indicator--active .mdc-tab-indicator__content,
    .oui-mdc-focus-indicator .mdc-tab-indicator__content {
      border-color: #006bb1;
    }
  }
}
.chatonce {
  .oui-tab {
    &.oui-primary {
      .mdc-tab-indicator--active .mdc-tab-indicator__content,
      .oui-mdc-focus-indicator .mdc-tab-indicator__content {
        border-color: #b731a9;
      }
    }
  }
}
.inviteonce {
  .oui-tab {
    &.oui-primary {
      .mdc-tab-indicator--active .mdc-tab-indicator__content,
      .oui-mdc-focus-indicator .mdc-tab-indicator__content {
        border-color: #197439;
      }
    }
  }
}
@mixin tab {
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-decoration: none;

  // Tabs might be `button` elements so we have to reset the user agent styling.
  background: none;

  &.mdc-tab {
    min-width: 90px;
    padding-right: 24px;
    padding-left: 24px;
    display: flex;
    flex: 1 0 auto;
    justify-content: center;
    box-sizing: border-box;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    outline: none;
    text-align: center;
    white-space: nowrap;
    margin: 0 5px;
    cursor: pointer;
    -webkit-appearance: none;
    z-index: 1;
    // MDC's tabs stretch to fit the header by default, whereas stretching on our current ones
    // is an opt-in behavior. Also technically we don't need to combine the two classes, but
    // we need the extra specificity to avoid issues with CSS insertion order.
    flex-grow: 0;
    border: 1px solid transparent !important;
    border-bottom: 0 !important;
    &.cdk-keyboard-focused {
      border: 1px solid #006bb1 !important;
      border-bottom: 0 !important;
    }
  }

  .mdc-tab__text-label {
    transition: 150ms color linear;
    display: inline-block;
    line-height: 1;
    z-index: 2;
    font-size: 16px;
    line-height: 22px;
    font-weight: 600;
    color: #666;
  }

  .mdc-tab--active .mdc-tab__text-label,
  .mdc-tab--active .mdc-tab__icon {
    transition-delay: 100ms;
  }

  &.oui-mdc-tab-disabled {
    // MDC doesn't support disabled tabs so we need to improvise.
    opacity: 0.4;

    // We use `pointer-events` to make the element unclickable when it's disabled, rather than
    // preventing the default action through JS, because we can't prevent the action reliably
    // due to other directives potentially registering their events earlier. This shouldn't cause
    // the user to click through, because we always have a header behind the tab. Furthermore, this
    // saves us some CSS, because we don't have to add `:not(.oui-mdc-tab-disabled)` to all the
    // hover and focus selectors.
    pointer-events: none;

    // We also need to prevent content from being clickable.
    .mdc-tab__content {
      pointer-events: none;
    }
  }

  // Used to render out the background tint when hovered/focused. Usually this is done by
  // MDC's ripple styles, however we're using our own ripples due to size concerns.
  .mdc-tab__ripple::before {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    pointer-events: none;
  }

  .mdc-tab__text-label {
    // We support projecting icons into the tab. These styles ensure that they're centered.
    display: inline-flex;
    align-items: center;
  }

  .mdc-tab__content {
    // Required for `fitInkBarToContent` to work. This used to be included with MDC's
    // `without-ripple` mixin, but that no longer appears to be the case with `static-styles`.
    // Since the latter is ~10kb smaller, we include this one extra style ourselves.
    position: relative;

    // MDC sets `pointer-events: none` on the content which prevents interactions with the
    // nested content. Re-enable it since we allow nesting any content in the tab (see #26195).
    pointer-events: auto;
  }
}

// Structural styles for a tab header. Used by both `oui-tab-header` and `oui-tab-nav-bar`.
// We need this styles on top of MDC's, because MDC doesn't support pagination like ours.
@mixin paginated-tab-header {
  .oui-mdc-tab-header {
    display: flex;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    min-height: 48px;
    padding-top: 0;
    border-bottom: 1px solid #c8c8c8;
    justify-content: center;
  }

  .mdc-tab-indicator .mdc-tab-indicator__content {
    transition-duration: var(500ms, 250ms);
  }

  .mdc-tab-indicator {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    justify-content: center;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
  }

  .oui-mdc-tab:not(.mdc-tab--stacked) {
    padding: 19px 20px 10px;
  }

  .oui-mdc-tab-header-pagination {
    position: relative;
    display: none;
    justify-content: center;
    align-items: center;
    min-width: 32px;
    cursor: pointer;
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    box-sizing: content-box;
    background: none;
    border: none;
    outline: 0;
    padding: 0;

    &::-moz-focus-inner {
      border: 0;
    }

    .oui-mdc-tab-header-pagination-controls-enabled & {
      display: flex;
    }
  }

  // The pagination control that is displayed on the left side of the tab header.
  .oui-mdc-tab-header-pagination-before,
  .oui-mdc-tab-header-rtl .oui-mdc-tab-header-pagination-after {
    padding-left: 4px;
    .oui-mdc-tab-header-pagination-chevron {
      transform: rotate(-135deg);
    }
  }

  // The pagination control that is displayed on the right side of the tab header.
  .oui-mdc-tab-header-rtl .oui-mdc-tab-header-pagination-before,
  .oui-mdc-tab-header-pagination-after {
    padding-right: 4px;
    .oui-mdc-tab-header-pagination-chevron {
      transform: rotate(45deg);
    }
  }

  .oui-mdc-tab-header-pagination-chevron {
    border-style: solid;
    border-width: 2px 2px 0 0;
    height: 8px;
    width: 8px;
  }

  .oui-mdc-tab-header-pagination-disabled {
    box-shadow: none;
    cursor: default;
    pointer-events: none;

    .oui-mdc-tab-header-pagination-chevron {
      opacity: 0.4;
    }
  }

  .mdc-tab-indicator__content--underline {
    align-self: flex-end;
    box-sizing: border-box;
    width: 100%;
    border-top-style: solid;
  }

  .mdc-tab-indicator__content {
    transform-origin: left;
    opacity: 0;
  }

  .mdc-tab-indicator .mdc-tab-indicator__content {
    transition: 250ms transform cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mdc-tab-indicator--active .mdc-tab-indicator__content,
  .oui-mdc-tab-link.active .mdc-tab-indicator__content {
    opacity: 1;
  }

  .oui-mdc-tab-list {
    position: relative;
    transition: transform 500ms cubic-bezier(0.35, 0, 0.25, 1);
    width: 100%;

    ._oui-animation-noopable & {
      transition: none;
    }
    .oui-mdc-tab.mdc-tab {
      &:first-child {
        margin-left: 0;
      }
      &:last-child {
        margin-right: 0;
      }
    }
  }

  // The `span` is in the selector in order to increase the specificity, ensuring
  // that it's always higher than the selector that declares the transition.
  ._oui-animation-noopable {
    span.mdc-tab-indicator__content,
    span.mdc-tab__text-label {
      transition: none;
    }
  }
}

// Structural styles for the element that wraps the paginated header items.
@mixin paginated-tab-header-item-wrapper($parent) {
  display: flex;
  flex: 1 0 auto;
  justify-content: center;
  text-transform: capitalize;
  [oui-align-tabs='start'] > #{$parent} & {
    justify-content: start;
  }

  [oui-align-tabs='end'] > #{$parent} & {
    justify-content: flex-end;
  }
}

// Structural styles for the element that wraps the paginated container's content.
@mixin paginated-tab-header-container {
  display: flex;
  flex-grow: 1;
  overflow: hidden;
  z-index: 1;
  justify-content: center;
}

.oui-tab
  .oui-tab-labels-container
  .cdk-keyboard-focused:not(.mdc-tab--active)
  .mdc-tab-indicator
  .mdc-tab-indicator__content,
.oui-tab
  .oui-tab-labels-container
  .oui-mdc-tab:hover:not(.mdc-tab--active)
  .mdc-tab-indicator
  .mdc-tab-indicator__content,
.oui-tab
  .oui-mdc-tab-link-container
  .oui-mdc-tab-link:hover:not(.active)
  .mdc-tab-indicator
  .mdc-tab-indicator__content,
.oui-tab
  .oui-mdc-tab-link-container
  .cdk-keyboard-focused:not(.active)
  .mdc-tab-indicator
  .mdc-tab-indicator__content {
  border-color: #666;
  opacity: 1;
}
