All files / src/app/settings/sections LanguageRegionSettingsSection.tsx

100% Statements 160/160
100% Branches 3/3
100% Functions 3/3
100% Lines 160/160

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 1611x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x  
/**
 * @file LanguageRegionSettingsSection.tsx
 * @module app/settings/sections/LanguageRegionSettingsSection
 *
 * @summary
 * Language and region settings section component.
 * Manages date format and number format preferences with preview examples.
 *
 * @enterprise
 * - Focused on language and region settings
 * - Real-time preview examples for date and number formats
 * - Radio button groups for format selection
 * - i18n support for labels and descriptions
 * - Type-safe format selection
 * - Full TypeDoc coverage for locale settings
 */
 
import {
  FormControl,
  FormLabel,
  RadioGroup,
  FormControlLabel,
  Radio,
  Box,
  Typography,
  Stack,
} from '@mui/material';
import { useTranslation } from 'react-i18next';
import { formatDate, formatNumber } from '../../../utils/formatters';
import type { DateFormat, NumberFormat } from '../../../context/settings';
 
interface LanguageRegionSettingsSectionProps {
  /** Current date format value */
  dateFormat: DateFormat;
 
  /** Callback when date format changes */
  onDateFormatChange: (format: DateFormat) => void;
 
  /** Current number format value */
  numberFormat: NumberFormat;
 
  /** Callback when number format changes */
  onNumberFormatChange: (format: NumberFormat) => void;
}
 
/**
 * Language and region settings section component.
 *
 * Provides date format and number format selectors with live preview examples.
 * Isolated from other settings for independent testing and reuse.
 *
 * @param props - Component props
 * @returns JSX element rendering language and region settings controls
 *
 * @example
 * ```tsx
 * <LanguageRegionSettingsSection
 *   dateFormat="DD.MM.YYYY"
 *   onDateFormatChange={handleDateChange}
 *   numberFormat="DE"
 *   onNumberFormatChange={handleNumberChange}
 * />
 * ```
 */
export default function LanguageRegionSettingsSection({
  dateFormat,
  onDateFormatChange,
  numberFormat,
  onNumberFormatChange,
}: LanguageRegionSettingsSectionProps) {
  const { t } = useTranslation(['common']);
 
  return (
    <Stack spacing={2}>
      {/* Date Format Selector */}
      <FormControl>
        <FormLabel sx={{ fontWeight: 600, mb: 1 }}>
          {t('settings.dateFormat', 'Date Format')}
        </FormLabel>
        <RadioGroup
          value={dateFormat}
          onChange={(e) => onDateFormatChange(e.target.value as DateFormat)}
        >
          <FormControlLabel
            value="DD.MM.YYYY"
            control={<Radio size="small" />}
            label={
              <Box>
                <Typography variant="body2">DD.MM.YYYY</Typography>
                <Typography variant="caption" color="text.secondary">
                  {formatDate(new Date(), 'DD.MM.YYYY')}
                </Typography>
              </Box>
            }
          />
          <FormControlLabel
            value="YYYY-MM-DD"
            control={<Radio size="small" />}
            label={
              <Box>
                <Typography variant="body2">YYYY-MM-DD</Typography>
                <Typography variant="caption" color="text.secondary">
                  {formatDate(new Date(), 'YYYY-MM-DD')}
                </Typography>
              </Box>
            }
          />
          <FormControlLabel
            value="MM/DD/YYYY"
            control={<Radio size="small" />}
            label={
              <Box>
                <Typography variant="body2">MM/DD/YYYY</Typography>
                <Typography variant="caption" color="text.secondary">
                  {formatDate(new Date(), 'MM/DD/YYYY')}
                </Typography>
              </Box>
            }
          />
        </RadioGroup>
      </FormControl>
 
      {/* Number Format Selector */}
      <FormControl>
        <FormLabel sx={{ fontWeight: 600, mb: 1 }}>
          {t('settings.numberFormat', 'Number Format')}
        </FormLabel>
        <RadioGroup
          value={numberFormat}
          onChange={(e) => onNumberFormatChange(e.target.value as NumberFormat)}
        >
          <FormControlLabel
            value="DE"
            control={<Radio size="small" />}
            label={
              <Box>
                <Typography variant="body2">German (DE)</Typography>
                <Typography variant="caption" color="text.secondary">
                  {formatNumber(1234.56, 'DE')}
                </Typography>
              </Box>
            }
          />
          <FormControlLabel
            value="EN_US"
            control={<Radio size="small" />}
            label={
              <Box>
                <Typography variant="body2">English (US)</Typography>
                <Typography variant="caption" color="text.secondary">
                  {formatNumber(1234.56, 'EN_US')}
                </Typography>
              </Box>
            }
          />
        </RadioGroup>
      </FormControl>
    </Stack>
  );
}