'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog' import { Progress } from '@/components/ui/progress' import { Paperclip } from 'lucide-react' import VatTreatmentSelect from './VatTreatmentSelect' import { EXPENSE_CATEGORIES, INCOME_CATEGORIES } from './transaction-types' import type { TransactionCategory, VatTreatment } from '@/types' const expenseCategories = EXPENSE_CATEGORIES const incomeCategories = INCOME_CATEGORIES interface BatchCategorySelectorProps { open: boolean onOpenChange: (open: boolean) => void selectedCount: number onSelectCategory: (category: TransactionCategory, vatTreatment?: VatTreatment) => void progress: { done: number; total: number } | null } export default function BatchCategorySelector({ open, onOpenChange, selectedCount, onSelectCategory, progress, }: BatchCategorySelectorProps) { const t = useTranslations('tx_batch_selector') const tCat = useTranslations('tx_categories') // 'auto' sends no explicit treatment: the server derives the correct default // per category (exempt for bank/card fees, 12% representation, else 25%). // A hardcoded 'standard_25' initial value used to override that derivation // and claim 25% moms on VAT-exempt bank fees. const [vatTreatment, setVatTreatment] = useState('auto') const isProcessing = progress !== null const handleSelectCategory = (category: TransactionCategory) => { // 'auto' omits the treatment so the server derives it per category. An // explicit 'Ingen moms' goes over the wire as 'exempt' (books no VAT // line): the old collapse to undefined made an explicit no-VAT choice // book the DERIVED default, i.e. 25% moms on most expense categories. const resolvedVat = vatTreatment === 'auto' ? undefined : vatTreatment === 'none' ? 'exempt' : vatTreatment onSelectCategory(category, resolvedVat) } return ( {isProcessing ? t('title_processing', { done: progress.done, total: progress.total }) : t('title_default', { count: selectedCount })} {isProcessing ? t('description_processing') : t('description_default')} {isProcessing ? (

{t('progress_label', { done: progress.done, total: progress.total })}

) : (
{/* Underlag reminder */}

{t('underlag_reminder')}

{t('vat_label')}

{t('expenses_label')}

{expenseCategories.map((cat) => ( ))}

{t('income_label')}

{incomeCategories.map((cat) => ( ))}
)}
) }