'use client';

import { TestTube } from 'lucide-react';
import { ICON_SIZE_MD } from '@/components/icons';
import React from 'react';
import { Card, Tag } from 'antd';
import type { ModalOpcoesTesteItem } from '@/features/projetos/qualidade-testes';

const tipoColors: Record<string, string> = { unitario: 'blue', integracao: 'green', e2e: 'purple', performance: 'orange', seguranca: 'red' };
const statusColors: Record<string, string> = { pendente: 'default', em_execucao: 'processing', passou: 'success', falhou: 'error', pulado: 'warning' };

export interface CardTesteProps {
    item: ModalOpcoesTesteItem;
    onOpenOpcoes?: (item: ModalOpcoesTesteItem) => void;
    onView?: (item: ModalOpcoesTesteItem) => void;
}

export function CardTeste({ item, onOpenOpcoes, onView }: CardTesteProps) {
    const handleClick = () => (onOpenOpcoes ? onOpenOpcoes(item) : onView?.(item));
    return (
        <Card
            hoverable
            className="module-card bordered-left"
            style={{ borderLeft: '6px solid #52c41a', marginBottom: 16, cursor: 'pointer' }}
            styles={{ body: { padding: '16px 20px' } }}
            onClick={handleClick}
        >
            <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
                <div style={{ fontWeight: 700, color: '#2c3e50' }}>
                    <TestTube size={ICON_SIZE_MD} style={{ marginRight: 8, color: '#52c41a' }} aria-hidden />
                    {item.nome}
                </div>
                <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
                    {item.tipo && <Tag color={tipoColors[item.tipo] || 'default'}>{item.tipo}</Tag>}
                    {item.status && <Tag color={statusColors[item.status] || 'default'}>{item.status}</Tag>}
                </div>
                {item.projeto?.nome && <div style={{ fontSize: 12, color: '#7f8c8d' }}>{item.projeto.nome}</div>}
            </div>
        </Card>
    );
}
