'use client';

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

export interface AtaType {
    id: number;
    titulo: string;
    tipo?: string;
    data?: string;
    projeto?: { nome: string };
    aprovada?: boolean;
}

export interface ModalOpcoesAtaProps {
    open: boolean;
    onClose: () => void;
    item: AtaType | null;
    onVer: (item: AtaType) => void;
    onAprovar?: (item: AtaType) => void;
    hideAprovar?: boolean;
}

export function ModalOpcoesAta({ open, onClose, item, onVer, onAprovar, hideAprovar }: ModalOpcoesAtaProps) {
    if (!item) return null;
    const tipoLabel = item.tipo ? getAtaTipoLabel(item.tipo) : null;
    const subtitle = [item.titulo, tipoLabel, item.aprovada ? 'Aprovada' : 'Pendente']
        .filter(Boolean)
        .join(' · ');
    const actions: ModalOpcaoAction[] = [
        { key: 'ver', label: 'Ver detalhes', icon: <Eye size={ICON_SIZE_MD} aria-hidden />, onClick: () => { onClose(); onVer(item); }, primary: true },
    ];
    if (!hideAprovar && onAprovar && !item.aprovada) actions.push({ key: 'aprovar', label: 'Aprovar', icon: <Check size={ICON_SIZE_MD} aria-hidden />, onClick: () => { onClose(); onAprovar(item); } });
    return (
        <ModalOpcoesBase
            open={open}
            onClose={onClose}
            data-testid="desenvolvimento-atas-opcoes-modal"
            aria-label="Opções da ata"
            title="Opções da ata"
            subtitle={subtitle}
            actions={actions}
            width={380}
        />
    );
}
