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atter.ts"],"sourcesContent":["import { useRegionStore } from '~/stores/region'\n\n/**\n * 🌍 useFormatter Composable\n *\n * Provides locale-aware formatting utilities for numbers, currencies, dates,\n * and percentages. Uses the active region configuration from the RegionStore\n * to determine the appropriate locale, currency, and timezone.\n *\n * Falls back to 'en-EU' locale and 'EUR' currency if no region is configured.\n */\nexport function useFormatter() {\n const regionStore = useRegionStore()\n\n /**\n * Format a number according to the active locale.\n * Example: 1234567.89 → \"1,234,567.89\" (en) or \"1 234 567,89\" (hu)\n */\n function formatNumber(value: number, options?: Intl.NumberFormatOptions): string {\n const locale = regionStore.activeLocale || 'en-EU'\n try {\n return new Intl.NumberFormat(locale, options).format(value)\n } catch {\n return new Intl.NumberFormat('en-EU', options).format(value)\n }\n }\n\n /**\n * Format a currency value according to the active region's currency and locale.\n * Example: 1234.50 → \"€1,234.50\" (EUR/en) or \"3 456 Ft\" (HUF/hu)\n */\n function formatCurrency(\n value: number,\n currency?: string,\n options?: Intl.NumberFormatOptions,\n ): string {\n const locale = regionStore.activeLocale || 'en-EU'\n const curr = currency || regionStore.activeCurrency || 'EUR'\n try {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: curr,\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n ...options,\n }).format(value)\n } catch {\n return `${value.toFixed(2)} ${curr}`\n }\n }\n\n /**\n * Format a date according to the active locale and timezone.\n * Example: 2026-06-24 → \"24/06/2026\" (en-GB) or \"2026. 06. 24.\" (hu-HU)\n */\n function formatDate(\n date: Date | string | number,\n options?: Intl.DateTimeFormatOptions,\n ): string {\n const locale = regionStore.activeLocale || 'en-EU'\n const timezone = regionStore.activeTimezone || 'Europe/Brussels'\n const d = typeof date === 'string' || typeof date === 'number' ? new Date(date) : date\n\n try {\n return new Intl.DateTimeFormat(locale, {\n timezone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n ...options,\n }).format(d)\n } catch {\n return d.toLocaleDateString('en-GB')\n }\n }\n\n /**\n * Format a datetime with time according to the active locale and timezone.\n * Example: \"2026-06-24T14:30:00Z\" → \"24/06/2026, 16:30\" (hu-HU/Budapest)\n */\n function formatDateTime(\n date: Date | string | number,\n options?: Intl.DateTimeFormatOptions,\n ): string {\n const locale = regionStore.activeLocale || 'en-EU'\n const timezone = regionStore.activeTimezone || 'Europe/Brussels'\n const d = typeof date === 'string' || typeof date === 'number' ? new Date(date) : date\n\n try {\n return new Intl.DateTimeFormat(locale, {\n timezone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n ...options,\n }).format(d)\n } catch {\n return d.toLocaleString('en-GB')\n }\n }\n\n /**\n * Format a percentage value.\n * Example: 27 → \"27%\" or 27.5 → \"27,5%\" (hu)\n */\n function formatPercent(\n value: number,\n options?: Intl.NumberFormatOptions,\n ): string {\n const locale = regionStore.activeLocale || 'en-EU'\n try {\n return new Intl.NumberFormat(locale, {\n style: 'percent',\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n ...options,\n }).format(value / 100)\n } catch {\n return `${value}%`\n }\n }\n\n /**\n * Calculate price including VAT for the active region.\n * VAT rate comes from the active region's default_vat_rate.\n */\n function calculatePriceWithVat(\n netPrice: number,\n vatRate?: number,\n ): { net: number; vat: number; gross: number; vatRate: number } {\n const rate = vatRate ?? regionStore.activeVatRate ?? 0\n const vat = netPrice * (rate / 100)\n const gross = netPrice + vat\n return { net: netPrice, vat, gross, vatRate: rate }\n }\n\n /**\n * Format a price range with VAT breakdown.\n * Example: (100, 27) → \"Net: €100.00 | VAT: €27.00 (27%) | Gross: €127.00\"\n */\n function formatPriceWithVat(\n netPrice: number,\n vatRate?: number,\n currency?: string,\n ): string {\n const { net, vat, gross, vatRate: rate } = calculatePriceWithVat(netPrice, vatRate)\n const curr = currency || regionStore.activeCurrency || 'EUR'\n return `Net: ${formatCurrency(net, curr)} | VAT: ${formatCurrency(vat, curr)} (${rate}%) | Gross: ${formatCurrency(gross, curr)}`\n }\n\n return {\n formatNumber,\n formatCurrency,\n formatDate,\n formatDateTime,\n formatPercent,\n calculatePriceWithVat,\n formatPriceWithVat,\n }\n}\n"],"version":3} |