import ProjectionRow from '@/pages/investments/components/projection-row';
import type { InvestmentProjection } from '@/pages/investments/types';
import { formatCurrency } from '@/pages/investments/utils';

type ProjectionSummaryProps = {
    projection: InvestmentProjection;
    totalLabel?: string;
    showInitialLabel?: string;
    plusPrefix?: boolean;
    compact?: boolean;
};

export default function ProjectionSummary({
    projection,
    totalLabel = 'Total proyectado',
    showInitialLabel = 'Inversión inicial',
    plusPrefix = true,
    compact = false,
}: ProjectionSummaryProps) {
    const prefix = plusPrefix ? '+' : '';

    return (
        <div
            className={
                compact
                    ? 'space-y-2 text-xs'
                    : 'space-y-4 text-sm'
            }
        >
            <ProjectionRow
                compact={compact}
                label={showInitialLabel}
                value={formatCurrency(projection.amount)}
            />
            <ProjectionRow
                compact={compact}
                label="Duración"
                value={projection.selectedDuration?.label ?? '-'}
            />
            <ProjectionRow
                compact={compact}
                label={`Rendimiento mensual (${projection.monthlyReturn}%)`}
                value={`${prefix}${formatCurrency(projection.monthlyProfit)}`}
                highlight
            />
            <ProjectionRow
                compact={compact}
                label={`Ganancia total (${projection.totalReturn.toFixed(1)}%)`}
                value={`${prefix}${formatCurrency(projection.totalProfit)}`}
                highlight
            />
            <div className={compact ? 'border-t pt-3' : 'border-t pt-4'}>
                <ProjectionRow
                    compact={compact}
                    label={totalLabel}
                    value={formatCurrency(projection.projectedTotal)}
                    highlight
                    large
                />
            </div>
        </div>
    );
}
