@use 'ui-design-system/src/styles/semantic/index' as *;

.ui-drawer {
  // Drawer Backdrop
  &__backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: $semantic-z-index-overlay;
    opacity: 0;
    transition: opacity $semantic-motion-duration-normal $semantic-motion-easing-ease;
    backdrop-filter: blur(2px);
    
    &--visible {
      opacity: 1;
    }
    
    &--entering {
      animation: drawer-backdrop-fade-in $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
    
    &--leaving {
      animation: drawer-backdrop-fade-out $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
  }

  // Drawer Container
  &__container {
    position: fixed;
    background: $semantic-color-surface-primary;
    box-shadow: $semantic-shadow-elevation-4;
    z-index: $semantic-z-index-modal;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform $semantic-motion-duration-normal $semantic-motion-easing-ease;
    
    &--visible {
      transform: translateX(0);
    }
    
    &--entering {
      animation: drawer-slide-in-left $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
    
    &--leaving {
      animation: drawer-slide-out-left $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
  }

  // Position Variants
  &--left {
    .ui-drawer__container {
      top: 0;
      left: 0;
      height: 100vh;
      border-right: 1px solid $semantic-color-outline;
      transform: translateX(-100%);
      
      &--entering {
        animation: drawer-slide-in-left $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
      
      &--leaving {
        animation: drawer-slide-out-left $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
    }
  }
  
  &--right {
    .ui-drawer__container {
      top: 0;
      right: 0;
      height: 100vh;
      border-left: 1px solid $semantic-color-outline;
      transform: translateX(100%);
      
      &--visible {
        transform: translateX(0);
      }
      
      &--entering {
        animation: drawer-slide-in-right $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
      
      &--leaving {
        animation: drawer-slide-out-right $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
    }
  }
  
  &--top {
    .ui-drawer__container {
      top: 0;
      left: 0;
      width: 100vw;
      border-bottom: 1px solid $semantic-color-outline;
      transform: translateY(-100%);
      
      &--visible {
        transform: translateY(0);
      }
      
      &--entering {
        animation: drawer-slide-in-top $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
      
      &--leaving {
        animation: drawer-slide-out-top $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
    }
  }
  
  &--bottom {
    .ui-drawer__container {
      bottom: 0;
      left: 0;
      width: 100vw;
      border-top: 1px solid $semantic-color-outline;
      transform: translateY(100%);
      
      &--visible {
        transform: translateY(0);
      }
      
      &--entering {
        animation: drawer-slide-in-bottom $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
      
      &--leaving {
        animation: drawer-slide-out-bottom $semantic-motion-duration-normal $semantic-motion-easing-ease;
      }
    }
  }

  // Size Variants
  &--sm {
    .ui-drawer__container {
      width: 280px;
    }
    
    &.ui-drawer--top .ui-drawer__container,
    &.ui-drawer--bottom .ui-drawer__container {
      height: 200px;
    }
  }
  
  &--md {
    .ui-drawer__container {
      width: 360px;
    }
    
    &.ui-drawer--top .ui-drawer__container,
    &.ui-drawer--bottom .ui-drawer__container {
      height: 300px;
    }
  }
  
  &--lg {
    .ui-drawer__container {
      width: 480px;
    }
    
    &.ui-drawer--top .ui-drawer__container,
    &.ui-drawer--bottom .ui-drawer__container {
      height: 400px;
    }
  }
  
  &--xl {
    .ui-drawer__container {
      width: 640px;
    }
    
    &.ui-drawer--top .ui-drawer__container,
    &.ui-drawer--bottom .ui-drawer__container {
      height: 500px;
    }
  }

  // Drawer Header
  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: $semantic-spacing-component-lg;
    border-bottom: 1px solid $semantic-color-outline;
    background: $semantic-color-surface-primary;
    flex-shrink: 0;
    
    &--no-border {
      border-bottom: none;
    }
  }

  &__title {
    font-size: $semantic-typography-heading-h4-size;
    font-weight: $semantic-typography-font-weight-semibold;
    color: $semantic-color-on-surface;
    margin: 0;
    line-height: 1.4;
  }

  &__close-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: $semantic-border-radius-md;
    color: $semantic-color-on-surface-variant;
    cursor: pointer;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    &:hover {
      background: $semantic-color-surface-variant;
      color: $semantic-color-on-surface;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-primary;
      outline-offset: 2px;
    }
    
    &:active {
      background: $semantic-color-surface-container;
    }
  }

  // Drawer Body
  &__body {
    padding: $semantic-spacing-component-lg;
    overflow-y: auto;
    flex: 1;
    
    &--no-padding {
      padding: 0;
    }
    
    &--scrollable {
      overflow-y: auto;
    }
  }

  &__content {
    color: $semantic-color-on-surface;
    font-size: $semantic-typography-font-size-md;
    line-height: 1.6;
  }

  // Drawer Footer
  &__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: $semantic-spacing-component-sm;
    padding: $semantic-spacing-component-lg;
    border-top: 1px solid $semantic-color-outline;
    background: $semantic-color-surface-primary;
    flex-shrink: 0;
    
    &--no-border {
      border-top: none;
    }
    
    &--center {
      justify-content: center;
    }
    
    &--start {
      justify-content: flex-start;
    }
    
    &--between {
      justify-content: space-between;
    }
  }

  // State Variants
  &--loading {
    .ui-drawer__body {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 200px;
    }
  }

  &--persistent {
    .ui-drawer__backdrop {
      display: none;
    }
  }

  // Loading Spinner
  &__loader {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid $semantic-color-outline;
    border-radius: 50%;
    border-top-color: $semantic-color-primary;
    animation: drawer-spin 1s linear infinite;
  }
  
  // Dark Mode Support
  :host-context(.dark-theme) & {
    &__backdrop {
      background: rgba(0, 0, 0, 0.7);
    }
  }
  
  // Responsive Design
  @media (max-width: 768px) {
    &--sm .ui-drawer__container,
    &--md .ui-drawer__container,
    &--lg .ui-drawer__container,
    &--xl .ui-drawer__container {
      width: 85vw;
      max-width: 400px;
    }
    
    &__header {
      padding: $semantic-spacing-component-md;
    }
    
    &__body {
      padding: $semantic-spacing-component-md;
    }
    
    &__footer {
      padding: $semantic-spacing-component-md;
      flex-direction: column;
      gap: $semantic-spacing-component-xs;
      
      .ui-button {
        width: 100%;
      }
    }
    
    &__title {
      font-size: $semantic-typography-heading-h5-size;
    }
  }
  
  @media (max-width: 480px) {
    &--sm .ui-drawer__container,
    &--md .ui-drawer__container,
    &--lg .ui-drawer__container,
    &--xl .ui-drawer__container {
      width: 100vw;
      max-width: none;
    }
  }
}

// Animations
@keyframes drawer-backdrop-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes drawer-backdrop-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes drawer-slide-in-left {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes drawer-slide-out-left {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-100%);
  }
}

@keyframes drawer-slide-in-right {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes drawer-slide-out-right {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(100%);
  }
}

@keyframes drawer-slide-in-top {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes drawer-slide-out-top {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-100%);
  }
}

@keyframes drawer-slide-in-bottom {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes drawer-slide-out-bottom {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(100%);
  }
}

@keyframes drawer-spin {
  to {
    transform: rotate(360deg);
  }
}