import { format as formatDate } from 'date-fns';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

import enTranslations from './resources/en';
import rsTranslations from './resources/rs'

i18n.use(initReactI18next).init({
  lng: 'rs',
  fallbackLng: 'rs',
  debug: false,
  supportedLngs: ['rs', 'en'],
  resources: {
    rs: {
      translation: rsTranslations,
    },
    en: {
      translation: enTranslations,
    },
  },
  interpolation: {
    format: (value, format) => {
      if (value instanceof Date) {
        return formatDate(value, format);
      }

      return value;
    },
  },
});

export default i18n;
