/**
 * Component: Tabs
 */

$vd-tabs_transition-duration: 300ms !default;
$vd-tabs_transition-distance: 64 !default;

@include comp('tabs') {
  position: relative;
  flex: 1 1 100%;
  max-width: 100%;
  min-width: 0;

  overflow: hidden;

  @include elem('header', 'header-item', 'separator', 'body', 'container', 'wrapper') {
    position: relative;
  }

  @include elem('header-item', 'indicator', 'wrapper') {
    transition-timing-function: ease-in-out;
    transition-duration: $vd-tabs_transition-duration;
  }

  @include elem('header') {
    width: 100%;
    height: rem(map-get($map: $tabs-header-size-map, $key: 'medium'));
    padding: 0;

    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-start;
    align-content: stretch;
    align-items: stretch;

    font-size: rem(map-get($map: $tabs-header-font-size-map, $key: 'medium'));
  }

  @include elem('header-item') {
    cursor: pointer;

    min-width: 0;
    height: 100%;
    flex: none;
    padding: 0 rem($gap-base);
    margin: 0;
    border: none;

    color: inherit;
    background: transparent;
    white-space: nowrap;

    @include when('selected') {
      color: tone();
    }

    transition-property: color;
  }

  @each $size in $type-size {
    @include prop(
      (
        'size': $size,
      )
    ) {
      @include elem('header') {
        height: rem(map-get($map: $tabs-header-size-map, $key: $size));
        font-size: rem(map-get($map: $tabs-header-font-size-map, $key: $size));
      }
    }
  }

  @each $flex in $type-flex-preset {
    @include prop(
      (
        'header-flex': $flex,
      )
    ) {
      @include elem('header-item') {
        padding: 0;
        @if $flex == expand {
          flex: 1;
        } @else {
          flex: $flex;
        }
      }
    }
  }

  @include elem('indicator') {
    position: absolute;
    left: 0;
    bottom: rem(-$border-base);
    width: 0;
    height: rem($border-base * 2);

    background-color: tone();

    transition-property: left, width;
  }

  @include elem('separator') {
    width: 100%;
    height: 0;
    border-bottom: rem($border-base) solid transparent;
  }

  @include elem('body') {
    padding: rem($gap-base);
  }
  @include when('no-gap') {
    @include elem('body') {
      padding: 0;
    }
  }

  @include elem('container') {
    width: 100%;
  }

  @include elem('wrapper') {
    width: 100%;

    > * {
      display: none;
    }

    @include elem('pane') {
      @include when('selected') {
        display: block;
      }
    }
  }

  @include elem('pane') {
    width: 100%;

    @each $direction in 'left', 'right' {
      @each $state in 'in', 'out' {
        @keyframes '#{class-comp('tab-pane')}-#{$direction}-#{$state}' {
          from {
            display: block;
            opacity: if($state == 'in', 0, 1);
            transform: if(
              $state == 'in',
              translateX(
                rem($vd-tabs_transition-distance) * if($direction == 'left', -1, 1)
              ),
              translateX(0)
            );
          }
          to {
            display: block;
            opacity: if($state == 'in', 1, 0);
            transform: if(
              $state == 'in',
              translateX(0),
              translateX(
                rem($vd-tabs_transition-distance) * if($direction == 'left', -1, 1)
              )
            );
          }
        }
      }
    }

    @each $transition in 'left-in', 'left-out', 'right-in', 'right-out' {
      @include when($transition) {
        animation: vd-tab-pane-#{$transition} $vd-tabs_transition-duration ease-out;
      }
    }
  }

  @each $theme in $type-theme {
    @include prop(
      (
        'theme': $theme,
      )
    ) {
      color: theme($theme);

      @include elem('header') {
        background-color: theme($theme, 'bg');
      }

      @include elem('separator') {
        border-color: theme($theme, 'bd');
      }
    }
  }
}
