import { Router, type Request, type Response } from 'express';
import {
  getTranslations,
  getSupportedLocales,
} from '../translations/index.js';

const router = Router();

router.get('/translations/:locale', (req: Request, res: Response) => {
  try {
    const { locale } = req.params;
    if (!locale) {
      res.status(400).json({ error: 'Locale is required' });
      return;
    }
    const translations = getTranslations(locale);
    res.json(translations);
  } catch (err) {
    console.error('Error fetching translations:', err);
    res.status(500).json({ error: 'Failed to fetch translations' });
  }
});

router.get('/locales', (_req: Request, res: Response) => {
  try {
    const locales = getSupportedLocales();
    res.json({ locales });
  } catch (err) {
    console.error('Error listing locales:', err);
    res.status(500).json({ error: 'Failed to list locales' });
  }
});

export default router;
