---
export interface Props {
  title?: string;
  columns?: number;
  gap?: 'small' | 'medium' | 'large';
}

const { 
  title, 
  columns = 4,
  gap = 'medium'
} = Astro.props;

const gapClasses = {
  small: 'gap-4',
  medium: 'gap-6',
  large: 'gap-8'
};
---

<div class="metrics-grid-container">
  {title && (
    <h3 class="metrics-title">{title}</h3>
  )}
  
  <div class={`metrics-grid ${gapClasses[gap]}`} style={`--columns: ${columns}`}>
    <slot />
  </div>
</div>

<style>
  .metrics-grid-container {
    margin-bottom: 2rem;
  }
  
  .metrics-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #011a2d;
    margin: 0 0 1.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(91, 119, 142, 0.3);
  }
  
  .metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    width: 100%;
  }
  
  /* 响应式列数 */
  @media (min-width: 1200px) {
    .metrics-grid {
      grid-template-columns: repeat(var(--columns, 4), 1fr);
    }
  }
  
  @media (max-width: 768px) {
    .metrics-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: 1rem;
    }
  }
  
  @media (max-width: 480px) {
    .metrics-grid {
      grid-template-columns: 1fr;
    }
  }
  
  /* 交错动画 */
  .metrics-grid > * {
    animation: fadeInUp 0.6s ease-out;
    animation-fill-mode: both;
  }
  
  .metrics-grid > *:nth-child(1) { animation-delay: 0.1s; }
  .metrics-grid > *:nth-child(2) { animation-delay: 0.2s; }
  .metrics-grid > *:nth-child(3) { animation-delay: 0.3s; }
  .metrics-grid > *:nth-child(4) { animation-delay: 0.4s; }
  .metrics-grid > *:nth-child(n+5) { animation-delay: 0.5s; }
  
  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(30px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
</style>