@import '../core/style/variables';
@import '../core/style/elevation';
@import '../core/style/layout-common';
@import '../core/a11y/a11y';


// Mixin to help with defining LTR/RTL 'transform: translate3d()' values.
// @param $open The translation value when the sidenav is opened.
// @param $close The translation value when the sidenav is closed.
@mixin md-sidenav-transition($open, $close) {
  transform: translate3d($close, 0, 0);

  &.md-sidenav-closed {
    // We use 'visibility: hidden | visible' because 'display: none' will not animate any
    // transitions, while visibility will interpolate transitions properly.
    // see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility, the Interpolation
    // section.
    visibility: hidden;
  }
  &.md-sidenav-closing {
    transform: translate3d($close, 0, 0);
  }
  &.md-sidenav-opening {
    @include md-elevation(16);
    visibility: visible;
    transform: translate3d($open, 0, 0);
  }
  &.md-sidenav-opened {
    @include md-elevation(16);
    transform: translate3d($open, 0, 0);
  }
}

// Mixin that creates a new stacking context.
// see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
@mixin md-sidenav-stacking-context() {
  position: relative;

  // Use a transform to create a new stacking context.
  transform: translate3d(0, 0, 0);
}

.md-sidenav-container {
  // We need a stacking context here so that the backdrop and drawers are clipped to the
  // MdSidenavContainer. This creates a new z-index stack so we use low numbered z-indices.
  // We create another stacking context in the '.md-sidenav-content' and in each sidenav so that
  // the application content does not get messed up with our own CSS.
  @include md-sidenav-stacking-context();

  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;

  // Need this to take up space in the layout.
  display: block;

  // Hide the sidenavs when they're closed.
  overflow: hidden;

  // TODO(hansl): Update this with a more robust solution.
  &[fullscreen] {
    @include md-fill();

    &.md-sidenav-opened {
      overflow: hidden;
    }
  }
}

.md-sidenav-backdrop {
  @include md-fill();

  display: block;

  // Because of the new stacking context, the z-index stack is new and we can use our own
  // numbers.
  z-index: 2;

  // We use 'visibility: hidden | visible' because 'display: none' will not animate any
  // transitions, while visibility will interpolate transitions properly.
  // see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility, the Interpolation
  // section.
  visibility: hidden;

  &.md-sidenav-shown {
    visibility: visible;
  }

  @include cdk-high-contrast {
    opacity: 0.5;
  }
}

.md-sidenav-content {
  @include md-sidenav-stacking-context();

  display: block;
  height: 100%;
  overflow: auto;
}

md-sidenav {
  @include md-sidenav-stacking-context();

  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  min-width: 5%;
  outline: 0;

  @include md-sidenav-transition(0, -100%);

  &.md-sidenav-side {
    z-index: 1;
  }

  &.md-sidenav-end {
    right: 0;

    @include md-sidenav-transition(0, 100%);
  }

  [dir='rtl'] & {
    @include md-sidenav-transition(0, 100%);

    &.md-sidenav-end {
      left: 0;
      right: auto;

      @include md-sidenav-transition(0, -100%);
    }
  }
}

.md-sidenav-focus-trap {
  height: 100%;

  > .cdk-focus-trap-content {
    box-sizing: border-box;
    height: 100%;
    overflow-y: auto; // TODO(kara): revisit scrolling behavior for sidenavs

    // Prevents unnecessary repaints while scrolling.
    transform: translateZ(0);
  }
}

.md-sidenav-invalid {
  display: none;
}
