"use client"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { LANCAMENTO_CONDITIONS } from "@/lib/lancamentos/constants"; import { cn } from "@/lib/utils/ui"; import { useMemo } from "react"; import { ConditionSelectContent } from "../../select-items"; import type { ConditionSectionProps } from "./lancamento-dialog-types"; function formatCurrency(value: number): string { return value.toLocaleString("pt-BR", { minimumFractionDigits: 2, maximumFractionDigits: 2, }); } export function ConditionSection({ formState, onFieldChange, showInstallments, showRecurrence, }: ConditionSectionProps) { const amount = useMemo(() => { const value = Number(formState.amount); return Number.isNaN(value) || value <= 0 ? null : value; }, [formState.amount]); const getInstallmentLabel = (count: number) => { if (amount) { const installmentValue = amount / count; return `${count}x de R$ ${formatCurrency(installmentValue)}`; } return `${count}x`; }; const getRecurrenceLabel = (count: number) => { return `${count} meses`; }; const installmentSummary = useMemo(() => { if (!showInstallments || !formState.installmentCount || !amount) { return null; } const count = Number(formState.installmentCount); if (Number.isNaN(count) || count <= 0) { return null; } return getInstallmentLabel(count); }, [showInstallments, formState.installmentCount, amount]); const recurrenceSummary = useMemo(() => { if (!showRecurrence || !formState.recurrenceCount) { return null; } const count = Number(formState.recurrenceCount); if (Number.isNaN(count) || count <= 0) { return null; } return `Por ${count} meses`; }, [showRecurrence, formState.recurrenceCount]); return (