import { Card } from '@/components/ui/card';
import { Progress } from '@/components/ui/progress';
import { Badge } from '@/components/ui/badge';
import { MemoryStick } from 'lucide-react';
import { SystemPerformance } from '@/types/monitor';

interface MemoryMetricCardProps {
  performance: SystemPerformance;
  getUsageColor: (usage: number) => string;
  getUsageStatus: (usage: number) => string;
  formatBytes: (bytes: number) => string;
}

export function MemoryMetricCard({ performance, getUsageColor, getUsageStatus, formatBytes }: MemoryMetricCardProps) {
  return (
    <Card className="p-6">
      <div className="flex items-center justify-between mb-4">
        <div className="flex items-center gap-2">
          <MemoryStick className="w-5 h-5 text-green-600" />
          <h3>内存使用率</h3>
        </div>
        <Badge className={getUsageColor(performance.memory.usage)}>
          {getUsageStatus(performance.memory.usage)}
        </Badge>
      </div>
      <div className="space-y-3">
        <div className="flex items-center justify-between">
          <span className="text-sm text-muted-foreground">使用率</span>
          <span className={getUsageColor(performance.memory.usage)}>
            {performance.memory.usage.toFixed(1)}%
          </span>
        </div>
        <Progress value={performance.memory.usage} className="h-2" />
        <div className="grid grid-cols-2 gap-2 text-sm">
          <div>
            <span className="text-muted-foreground">已用</span>
            <p>{formatBytes(performance.memory.used)}</p>
          </div>
          <div>
            <span className="text-muted-foreground">总量</span>
            <p>{formatBytes(performance.memory.total)}</p>
          </div>
        </div>
      </div>
    </Card>
  );
}