'use client' import { useTranslations } from 'next-intl' import { useState, useCallback } from 'react' import { Label } from '@/components/ui/label' import { Switch } from '@/components/ui/switch' import { Textarea } from '@/components/ui/textarea' import { useToast } from '@/components/ui/use-toast' import type { CompanySettings } from '@/types' interface PdfPrintSettingsProps { settings: CompanySettings onUpdate: (updates: Partial) => void } export function PdfPrintSettings({ settings, onUpdate }: PdfPrintSettingsProps) { const t = useTranslations('settings_pdf_print') const { toast } = useToast() const [lateFeeText, setLateFeeText] = useState(settings.invoice_late_fee_text || '') const [creditTermsText, setCreditTermsText] = useState(settings.invoice_credit_terms_text || '') const saveToggle = useCallback(async (field: string, value: boolean) => { try { const response = await fetch('/api/settings', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ [field]: value }), }) if (!response.ok) throw new Error() onUpdate({ [field]: value } as Partial) } catch { toast({ title: t('toast_save_failed'), variant: 'destructive' }) } }, [onUpdate, toast, t]) const savePosition = useCallback(async (value: 'header' | 'footer') => { try { const response = await fetch('/api/settings', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ invoice_company_name_position: value }), }) if (!response.ok) throw new Error() onUpdate({ invoice_company_name_position: value }) } catch { toast({ title: t('toast_save_failed'), variant: 'destructive' }) } }, [onUpdate, toast, t]) const saveText = useCallback(async (field: string, value: string) => { try { const response = await fetch('/api/settings', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ [field]: value || null }), }) if (!response.ok) throw new Error() onUpdate({ [field]: value || null } as Partial) } catch { toast({ title: t('toast_save_failed'), variant: 'destructive' }) } }, [onUpdate, toast, t]) return (

{t('heading')}

{t('ore_rounding_help')}

saveToggle('ore_rounding', v)} />

{t('show_ocr_help')}

saveToggle('invoice_show_ocr', v)} />

{t('show_bankgiro_help')}

saveToggle('invoice_show_bankgiro', v)} />

{t('show_plusgiro_help')}

saveToggle('invoice_show_plusgiro', v)} />

{t('show_swish_help')}

saveToggle('invoice_show_swish', v)} aria-label={t('show_swish_label')} />

{t('show_logo_help')}

saveToggle('invoice_show_logo', v)} />

{t('show_company_name_help')}

saveToggle('invoice_show_company_name', v)} />
{(settings.invoice_show_company_name ?? true) && (

{t('placement_label')}

{(['header', 'footer'] as const).map((pos) => { const active = (settings.invoice_company_name_position ?? 'header') === pos return ( ) })}
)}