'use client';

import { Check, Eye, X } from 'lucide-react';
import { ICON_SIZE_MD } from '@/components/icons';
import React from 'react';
import { ModalOpcoesBase, type ModalOpcaoAction } from '@/components/ModalOpcoesBase';
import type { ProjetoCodeReview } from './types';

export interface ModalOpcoesCodeReviewProps {
    open: boolean;
    onClose: () => void;
    item: ProjetoCodeReview | null;
    onVerDetalhes: (item: ProjetoCodeReview) => void;
    onAprovar?: (item: ProjetoCodeReview) => void;
    onRejeitar?: (item: ProjetoCodeReview) => void;
}

export function ModalOpcoesCodeReview({
    open,
    onClose,
    item,
    onVerDetalhes,
    onAprovar,
    onRejeitar}: ModalOpcoesCodeReviewProps) {
    if (!item) return null;
    const subtitle = [item.titulo, item.status, item.projeto?.nome].filter(Boolean).join(' · ');
    const actions: ModalOpcaoAction[] = [
        {
            key: 'ver',
            label: 'Ver detalhes',
            icon: <Eye size={ICON_SIZE_MD} aria-hidden />,
            onClick: () => {
                onClose();
                onVerDetalhes(item);
            },
            primary: true},
    ];
    if (onAprovar && item.status !== 'aprovado') {
        actions.push({
            key: 'aprovar',
            label: 'Aprovar',
            icon: <Check size={ICON_SIZE_MD} aria-hidden />,
            onClick: () => {
                onClose();
                onAprovar(item);
            }});
    }
    if (onRejeitar && item.status !== 'rejeitado') {
        actions.push({
            key: 'rejeitar',
            label: 'Rejeitar',
            icon: <X size={ICON_SIZE_MD} aria-hidden />,
            onClick: () => {
                onClose();
                onRejeitar(item);
            },
            danger: true});
    }
    return (
        <ModalOpcoesBase
            open={open}
            onClose={onClose}
            title="Opções do code review"
            subtitle={subtitle}
            actions={actions}
            width={380}
            data-testid="projeto-qualidade-code-review-opcoes-modal"
            aria-label="Opções do code review"
        />
    );
}
