@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

$directions: rtl, ltr, ttb, btt;

@include b(drawer) {
  @include set-component-css-var('drawer', $drawer);

  position: absolute;
  box-sizing: border-box;
  background-color: getCssVar('drawer', 'bg-color');
  display: flex;
  flex-direction: column;
  box-shadow: getCssVar('box-shadow', 'dark');
  overflow: hidden;

  transition: all getCssVar('transition-duration');

  @each $direction in $directions {
    .#{$direction} {
      transform: translate(0, 0);
    }
  }

  &__sr-focus:focus {
    outline: none !important;
  }

  &__header {
    align-items: center;
    color: getCssVar('text-color-primary');
    height: 56px;
    line-height: 56px;
    display: flex;
    padding: getCssVar('drawer-padding-primary');
    border-bottom: getCssVar('drawer-head-border');
    box-sizing: border-box;
    & > :first-child {
      flex: 1;
    }
  }

  @include e(title) {
    margin: 0;
    flex: 1;
    line-height: inherit;
    font-size: 1rem;
  }

  @include e(footer) {
    padding: getCssVar('drawer-padding-footer-primary');
    border-top: getCssVar('drawer-footer-border');
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  // @each $direction in $directions {
  //   .#{$direction} {
  //     transform: translate(0, 0);
  //   }
  // }

  &__close-btn {
    border: none;
    cursor: pointer;
    font-size: getCssVar('font-size-extra-large');
    color: inherit;
    background-color: transparent;
    outline: none;
    &:focus,
    &:hover {
      i {
        color: getCssVar('color-primary');
      }
    }
    .#{$namespace}-icon {
      font-size: inherit;
      vertical-align: text-bottom;
    }
  }

  &__body {
    flex: 1;
    padding: getCssVar('drawer-content-padding');
    overflow: auto;
    & > * {
      box-sizing: border-box;
    }
  }

  &.ltr,
  &.rtl {
    height: 100%;
    top: 0;
    bottom: 0;
  }

  &.ttb,
  &.btt {
    width: 100%;
    left: 0;
    right: 0;
  }

  &.ltr {
    left: 0;
  }

  &.rtl {
    right: 0;
  }

  &.ttb {
    top: 0;
  }

  &.btt {
    bottom: 0;
  }
}

.#{$namespace}-drawer-fade {
  &-enter-active,
  &-leave-active {
    transition: all getCssVar('transition-duration');
  }

  &-enter-from,
  &-enter-active,
  &-enter-to,
  &-leave-from,
  &-leave-active,
  &-leave-to {
    overflow: hidden !important;
  }

  &-enter-from,
  &-leave-to {
    opacity: 0;
  }

  &-enter-to,
  &-leave-from {
    opacity: 1;
  }

  &-enter-from,
  &-leave-to {
    @each $direction in $directions {
      .#{$direction} {
        @if $direction == ltr {
          transform: translateX(-100%);
        }

        @if $direction == rtl {
          transform: translateX(100%);
        }

        @if $direction == ttb {
          transform: translateY(-100%);
        }

        @if $direction == btt {
          transform: translateY(100%);
        }
      }
    }
  }
}
