---
import { DEFAULT_LOCALE, type Locale } from '~/consts';
import { getLocaleFromUrl } from '~/i18n/ui';

interface Props {
	date: Date;
	locale?: Locale;
	class?: string;
}

const {
	date,
	locale = getLocaleFromUrl(Astro.url) ?? DEFAULT_LOCALE,
	class: className,
} = Astro.props;
const tag = locale === 'de' ? 'de-DE' : 'en-US';
---

<time datetime={date.toISOString()} class={className}>
	{
		date.toLocaleDateString(tag, {
			year: 'numeric',
			month: 'short',
			day: 'numeric',
		})
	}
</time>
