---
import FallbackImage from '../assets/theme/social/anglefeint-og.jpg';
import { resolveSocialImage } from '../social/resolve.mjs';
import { publicDir } from 'virtual:anglefeint-social';
import { THEME_CONFIG } from '@anglefeint/user-config';
import { SITE_DESCRIPTION, SITE_TITLE, SITE_URL } from '@anglefeint/site-config/site';
import { type Locale, getLocaleOgLocale } from '@anglefeint/site-i18n/config';
import { getMessages } from '@anglefeint/site-i18n/messages';

interface Props {
  locale: Locale;
  destination: string;
}

const { locale, destination } = Astro.props;
const siteURL = Astro.site ?? SITE_URL;
const canonicalURL = new URL(destination, siteURL);
const description = getMessages(locale).siteDescription || SITE_DESCRIPTION;
const image = await resolveSocialImage({
  override: THEME_CONFIG.site.ogImage?.trim(),
  enabled: false,
  fallback: FallbackImage,
  data: { title: SITE_TITLE },
  publicDir,
  base: import.meta.env.BASE_URL,
});
const imageURL = new URL(image.src, siteURL);
const ogLocale = getLocaleOgLocale(locale);
---

<meta charset="utf-8" />
<meta name="robots" content="noindex, follow" />
<meta http-equiv="refresh" content={`0;url=${destination}`} />
<link rel="canonical" href={canonicalURL} />
<title>Redirecting...</title>
<meta name="description" content={description} />
<meta property="og:type" content="website" />
<meta property="og:url" content={canonicalURL} />
<meta property="og:title" content={SITE_TITLE} />
<meta property="og:description" content={description} />
<meta property="og:image" content={imageURL} />
<meta property="og:image:alt" content={SITE_TITLE} />
{
  typeof image.width === 'number' && (
    <meta property="og:image:width" content={String(image.width)} />
  )
}
{
  typeof image.height === 'number' && (
    <meta property="og:image:height" content={String(image.height)} />
  )
}
{ogLocale && <meta property="og:locale" content={ogLocale} />}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:url" content={canonicalURL} />
<meta name="twitter:title" content={SITE_TITLE} />
<meta name="twitter:description" content={description} />
<meta name="twitter:image" content={imageURL} />
<meta name="twitter:image:alt" content={SITE_TITLE} />
