// Sass混合器 - 复杂样式逻辑的封装

// 响应式断点混合器
@mixin mobile {
  @media (max-width: 639px) {
    @content;
  }
}

@mixin tablet {
  @media (min-width: 640px) and (max-width: 1023px) {
    @content;
  }
}

@mixin desktop {
  @media (min-width: 1024px) {
    @content;
  }
}

@mixin large-desktop {
  @media (min-width: 1280px) {
    @content;
  }
}

// 自定义断点
@mixin breakpoint($size) {
  @media (min-width: $size) {
    @content;
  }
}

// 卡片样式混合器
@mixin card($padding: var(--spacing-lg), $radius: var(--radius-lg)) {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: $radius;
  padding: $padding;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);

  &:hover {
    box-shadow: var(--shadow-md);
  }
}

// 按钮基础样式混合器
@mixin button-base {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: var(--text-sm);
  line-height: 1.5;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  &:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
  }
}

// 按钮变体混合器
@mixin button-variant($bg-color, $text-color, $border-color: $bg-color) {
  background-color: $bg-color;
  color: $text-color;
  border-color: $border-color;

  &:hover:not(:disabled) {
    filter: brightness(0.9);
  }

  &:active:not(:disabled) {
    filter: brightness(0.8);
  }
}

// 输入框样式混合器
@mixin input-base {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-background);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);

  &:focus {
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  }

  &:disabled {
    background-color: var(--color-gray-100);
    cursor: not-allowed;
  }

  &::placeholder {
    color: var(--color-text-secondary);
  }
}

// 文本截断混合器
@mixin text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@mixin text-truncate-lines($lines: 2) {
  display: -webkit-box;
  -webkit-line-clamp: $lines;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

// 居中混合器
@mixin center-absolute {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

@mixin center-flex {
  display: flex;
  align-items: center;
  justify-content: center;
}

// 动画混合器
@mixin fade-in($duration: var(--transition-normal)) {
  animation: fadeIn $duration ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@mixin slide-up($duration: var(--transition-normal)) {
  animation: slideUp $duration ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 加载动画混合器
@mixin loading-spinner($size: 20px, $color: var(--color-primary-500)) {
  width: $size;
  height: $size;
  border: 2px solid transparent;
  border-top: 2px solid $color;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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