"use client"; import { useState } from "react"; import { TRANSACTION_CONDITIONS } from "@/features/transactions/lib/constants"; import { Label } from "@/shared/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger, } from "@/shared/components/ui/popover"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/shared/components/ui/select"; import { formatCurrency } from "@/shared/utils/currency"; import { cn } from "@/shared/utils/ui"; import { ConditionSelectContent } from "../../select-items"; import type { ConditionSectionProps } from "./transaction-dialog-types"; function InlineStartInstallmentPicker({ value, options, onChange, }: { value: string; options: number[]; onChange: (value: string) => void; }) { const [open, setOpen] = useState(false); const selected = Number(value || "1"); const selectedLabel = !Number.isNaN(selected) && selected > 0 ? `${selected}ª parcela` : "1ª parcela"; const disabled = options.length === 0; return (
Começar em
{options.map((option) => ( ))}
); } export function ConditionSection({ formState, onFieldChange, showInstallments, showRecurrence, }: ConditionSectionProps) { const parsedAmount = Number(formState.amount); const amount = Number.isNaN(parsedAmount) || parsedAmount <= 0 ? null : parsedAmount; const getInstallmentLabel = (count: number) => { if (amount) { const installmentValue = amount / count; return `${count}x de R$ ${formatCurrency(installmentValue)}`; } return `${count}x`; }; const installmentCount = Number(formState.installmentCount); const installmentSummary = showInstallments && formState.installmentCount && !Number.isNaN(installmentCount) && installmentCount > 0 ? getInstallmentLabel(installmentCount) : null; const startInstallmentOptions = showInstallments && formState.installmentCount && !Number.isNaN(installmentCount) && installmentCount > 0 ? Array.from({ length: installmentCount }, (_, index) => index + 1) : []; return (
{showInstallments ? (
onFieldChange("startInstallment", value)} />
) : null} {showRecurrence ? (
) : null}
); }