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

$directions: rtl, ltr, ttb, btt;

.#{$namespace}-overlay.is-drawer {
  overflow: hidden;
}

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

@include b(drawer) {
  position: absolute;
  box-sizing: border-box;
  background-color: getCssVar('drawer', 'bg-color');
  display: flex;
  flex-direction: column;
  box-shadow: getCssVar('box-shadow', 'dark');
  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');
    display: flex;
    margin-bottom: 32px;
    padding: getCssVar('drawer-padding-primary');
    padding-bottom: 0;
    overflow: hidden;
    & > :first-child {
      flex: 1;
    }
  }

  &__title {
    margin: 0;
    flex: 1;
    line-height: inherit;
    font-size: 16px;
  }

  @include e(footer) {
    padding: getCssVar('drawer-padding-primary');
    padding-top: 10px;
    text-align: right;
    overflow: hidden;
  }

  &__close-btn {
    display: inline-flex;
    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');
      }
    }
  }

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

  @include when(dragging) {
    transition: none;
  }

  @include e(dragger) {
    position: absolute;
    background-color: transparent;
    user-select: none;
    transition: all 0.2s;

    &::before {
      content: '';
      position: absolute;
      background-color: transparent;
      transition: all 0.2s;
    }

    &:hover::before {
      background-color: getCssVar('color-primary');
    }
  }

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

    > .#{$namespace}-drawer__dragger {
      height: 100%;
      width: getCssVar('drawer-dragger-size');
      top: 0;
      bottom: 0;
      cursor: ew-resize;

      &::before {
        top: 0;
        bottom: 0;
        width: 3px;
      }
    }
  }

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

    > .#{$namespace}-drawer__dragger {
      width: 100%;
      height: getCssVar('drawer-dragger-size');
      left: 0;
      right: 0;
      cursor: ns-resize;

      &::before {
        left: 0;
        right: 0;
        height: 3px;
      }
    }
  }

  &.ltr {
    left: 0;

    > .#{$namespace}-drawer__dragger {
      right: 0;

      &::before {
        right: -2px;
      }
    }
  }

  &.rtl {
    right: 0;

    > .#{$namespace}-drawer__dragger {
      left: 0;

      &::before {
        left: -2px;
      }
    }
  }

  &.ttb {
    top: 0;

    > .#{$namespace}-drawer__dragger {
      bottom: 0;

      &::before {
        bottom: -2px;
      }
    }
  }

  &.btt {
    bottom: 0;

    > .#{$namespace}-drawer__dragger {
      top: 0;

      &::before {
        top: -2px;
      }
    }
  }
}

.#{$namespace}-modal-drawer {
  &.is-penetrable {
    pointer-events: none;

    .#{$namespace}-drawer {
      pointer-events: auto;
    }
  }
}

.#{$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 {
    background-color: transparent !important;
  }

  &-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%);
        }
      }
    }
  }
}
