// =============================================================================
// Nav Layout - SCSS Mixins
// =============================================================================

@use 'sass:list';
@use 'variables' as *;

// -----------------------------------------------------------------------------
// 过渡动画 Mixins
// -----------------------------------------------------------------------------

/// 导航过渡动画
/// @param {List} $properties... - 需要过渡的属性列表（可变参数）
@mixin nav-transition($properties...) {
  @if length($properties) == 0 {
    transition: all $nav-transition-duration $nav-transition-timing;
  } @else {
    $transitions: ();
    @each $prop in $properties {
      $transitions: list.append($transitions, $prop $nav-transition-duration $nav-transition-timing, comma);
    }
    transition: $transitions;
  }
}

/// 快速过渡动画
/// @param {List} $properties... - 需要过渡的属性列表（可变参数）
@mixin nav-transition-fast($properties...) {
  @if length($properties) == 0 {
    transition: all $nav-transition-fast $nav-transition-timing;
  } @else {
    $transitions: ();
    @each $prop in $properties {
      $transitions: list.append($transitions, $prop $nav-transition-fast $nav-transition-timing, comma);
    }
    transition: $transitions;
  }
}

// -----------------------------------------------------------------------------
// Flexbox Mixins
// -----------------------------------------------------------------------------

/// 居中对齐的 Flex 容器
@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/// 两端对齐的 Flex 容器
@mixin flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/// 垂直居中的 Flex 容器
@mixin flex-align-center {
  display: flex;
  align-items: center;
}

/// 垂直方向的 Flex 容器
@mixin flex-column {
  display: flex;
  flex-direction: column;
}

// -----------------------------------------------------------------------------
// 文本 Mixins
// -----------------------------------------------------------------------------

/// 文本溢出省略号
@mixin text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/// 多行文本溢出省略号
/// @param {Number} $lines [2] - 显示的行数
@mixin text-ellipsis-multiline($lines: 2) {
  display: -webkit-box;
  -webkit-line-clamp: $lines;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

// -----------------------------------------------------------------------------
// 响应式 Mixins
// -----------------------------------------------------------------------------

/// 响应式断点
/// @param {String} $breakpoint - 断点名称 (sm, md, lg, xl)
@mixin respond-to($breakpoint) {
  @if $breakpoint == sm {
    @media (max-width: $nav-breakpoint-sm) {
      @content;
    }
  } @else if $breakpoint == md {
    @media (max-width: $nav-breakpoint-md) {
      @content;
    }
  } @else if $breakpoint == lg {
    @media (max-width: $nav-breakpoint-lg) {
      @content;
    }
  } @else if $breakpoint == xl {
    @media (max-width: $nav-breakpoint-xl) {
      @content;
    }
  }
}

/// 最小宽度响应式断点
/// @param {String} $breakpoint - 断点名称 (sm, md, lg, xl)
@mixin respond-from($breakpoint) {
  @if $breakpoint == sm {
    @media (min-width: $nav-breakpoint-sm) {
      @content;
    }
  } @else if $breakpoint == md {
    @media (min-width: $nav-breakpoint-md) {
      @content;
    }
  } @else if $breakpoint == lg {
    @media (min-width: $nav-breakpoint-lg) {
      @content;
    }
  } @else if $breakpoint == xl {
    @media (min-width: $nav-breakpoint-xl) {
      @content;
    }
  }
}

// -----------------------------------------------------------------------------
// 工具 Mixins
// -----------------------------------------------------------------------------

/// 滚动条样式（跨平台兼容）
@mixin custom-scrollbar($width: 4px, $track-color: transparent, $thumb-color: rgba(255, 255, 255, 0.2)) {
  // 强制显示滚动条（覆盖 macOS 的 overlay 行为）
  overflow-y: scroll;
  overflow-x: hidden;
  
  // Firefox 滚动条样式
  scrollbar-width: thin;
  scrollbar-color: $thumb-color $track-color;

  // Webkit 浏览器（Chrome、Safari、Edge）滚动条样式
  &::-webkit-scrollbar {
    width: $width;
    background: $track-color;
  }

  &::-webkit-scrollbar-track {
    background: $track-color;
    border-radius: calc($width / 2);
  }

  &::-webkit-scrollbar-thumb {
    background: $thumb-color;
    border-radius: calc($width / 2);

    &:hover {
      background: rgba(255, 255, 255, 0.3);
    }
  }

  &::-webkit-scrollbar-corner {
    background: $track-color;
  }
}

/// 隐藏元素但保持可访问性
@mixin visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
