import type { DateTimeFormats, LocaleCode } from '../../../types'; import locales from '../../../locales'; // Function to get the date format based on the displayFormat and locale, // if no displayFormat or locale is provided, use the default fullDate format export const getDateFormat = ({ displayFormat, locale, localizeDateTime, }: { displayFormat?: string; locale?: string; localizeDateTime: (key: keyof DateTimeFormats) => string; }) => { // Prioritise displayFormat if (displayFormat) { return displayFormat; } // If locale is provided, find the corresponding locale in the locales object if (locale && locales[locale as LocaleCode]) { const localeObject = locales[locale as LocaleCode]; if (localeObject) { return localeObject.dateTimeFormats.fullDate; } } // If no displayFormat or locale is provided, use the default fullDate format return localizeDateTime('fullDate'); };