/**
 * Activity Tab Component
 */

import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Activity } from 'lucide-react';
import { formatDateTime } from '@/utils/dateFormatter';
import { getActionTypeIcon } from '@/utils/requestDetailHelpers';

interface ActivityTabProps {
  request: any;
}

export function ActivityTab({ request }: ActivityTabProps) {
  return (
    <Card>
      <CardHeader>
        <CardTitle className="flex items-center gap-2 text-sm sm:text-base">
          <Activity className="w-4 h-4 sm:w-5 sm:h-5 text-orange-600" />
          Activity Timeline
        </CardTitle>
        <CardDescription className="text-xs sm:text-sm">Complete audit trail of all request activities</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="space-y-4 sm:space-y-6">
          {request.auditTrail && request.auditTrail.length > 0 ? (
            request.auditTrail.map((entry: any, index: number) => (
              <div key={index} className="flex items-start gap-4" data-testid={`activity-item-${index}`}>
                <div className="flex-shrink-0">
                  <div className="w-10 h-10 rounded-full bg-gray-100 flex items-center justify-center">
                    {getActionTypeIcon(entry.type)}
                  </div>
                </div>

                <div className="flex-1 min-w-0">
                  <div className="bg-white rounded-lg border border-gray-200 p-4 shadow-sm">
                    <div className="flex items-center justify-between mb-2">
                      <h4 className="font-semibold text-gray-900">{entry.action}</h4>
                      <span className="text-xs text-gray-500 whitespace-nowrap ml-4">{formatDateTime(entry.timestamp)}</span>
                    </div>

                    <div className="text-sm text-gray-600 leading-relaxed">
                      <p className="whitespace-pre-line break-words">{entry.details}</p>
                    </div>
                  </div>
                </div>
              </div>
            ))
          ) : (
            <div className="text-center py-12" data-testid="no-activity">
              <Activity className="w-12 h-12 text-gray-400 mx-auto mb-4" />
              <p className="text-sm text-gray-500">No activity recorded yet</p>
              <p className="text-xs text-gray-400 mt-2">Actions and updates will appear here</p>
            </div>
          )}
        </div>
      </CardContent>
    </Card>
  );
}

