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

.ui-aspect-ratio {
  // Core Structure
  display: block;
  position: relative;
  width: 100%;
  overflow: hidden;
  
  // Visual Design
  background: $semantic-color-surface-primary;
  border-radius: $semantic-border-radius-md;
  
  // Default aspect ratio container
  &::before {
    content: '';
    display: block;
    padding-bottom: 56.25%; // 16:9 default
  }
  
  // Content wrapper
  &__content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    
    // Ensure content fills the container properly
    & > * {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    
    // For images and videos
    & > img,
    & > video {
      object-fit: cover;
      border-radius: inherit;
    }
    
    // For custom content that needs centering
    &--center {
      & > * {
        width: auto;
        height: auto;
        object-fit: initial;
      }
    }
  }
  
  // Common Aspect Ratio Variants
  &--square {
    &::before {
      padding-bottom: 100%; // 1:1
    }
  }
  
  &--video {
    &::before {
      padding-bottom: 56.25%; // 16:9
    }
  }
  
  &--cinema {
    &::before {
      padding-bottom: 42.86%; // 21:9
    }
  }
  
  &--photo {
    &::before {
      padding-bottom: 66.67%; // 3:2
    }
  }
  
  &--portrait {
    &::before {
      padding-bottom: 133.33%; // 3:4
    }
  }
  
  &--golden {
    &::before {
      padding-bottom: 61.8%; // Golden ratio ~1.618:1
    }
  }
  
  // Size variants for different contexts
  &--sm {
    border-radius: $semantic-border-radius-sm;
    
    .ui-aspect-ratio__content {
      & > img,
      & > video {
        border-radius: $semantic-border-radius-sm;
      }
    }
  }
  
  &--lg {
    border-radius: $semantic-border-radius-lg;
    
    .ui-aspect-ratio__content {
      & > img,
      & > video {
        border-radius: $semantic-border-radius-lg;
      }
    }
  }
  
  // Surface variants
  &--elevated {
    background: $semantic-color-surface-elevated;
    box-shadow: $semantic-shadow-elevation-2;
  }
  
  &--bordered {
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
  }
  
  // Interactive state for clickable aspect ratios
  &--interactive {
    cursor: pointer;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    &:hover {
      box-shadow: $semantic-shadow-elevation-3;
      transform: translateY(-1px);
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
    
    &:active {
      transform: translateY(0);
      box-shadow: $semantic-shadow-elevation-1;
    }
  }
  
  // Loading state
  &--loading {
    background: $semantic-color-surface-secondary;
    
    .ui-aspect-ratio__content {
      display: flex;
      align-items: center;
      justify-content: center;
      
      &::after {
        content: '';
        width: 32px;
        height: 32px;
        border: 3px solid $semantic-color-border-subtle;
        border-top: 3px solid $semantic-color-primary;
        border-radius: 50%;
        animation: spin $semantic-motion-duration-slow linear infinite;
      }
    }
  }
  
  // Responsive adjustments
  @media (max-width: calc($semantic-breakpoint-md - 1px)) {
    border-radius: $semantic-border-radius-sm;
    
    &--sm {
      border-radius: $semantic-border-radius-sm;
    }
    
    &--lg {
      border-radius: $semantic-border-radius-md;
    }
  }
}

// Loading animation
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}