---
import Layout from '@layouts/Layout.astro';
import LoginForm from '@components/auth/LoginForm.astro';
import NotificationToast from '@components/base/NotificationToast.astro';
import { authService } from '@/lib/authService';

// Получаем глобальные настройки сайта из PocketBase
const pb = authService.createClientFromRequest(Astro.request);
const siteSettings = await pb.collection('site_settings').getFirstListItem('');
const siteUrl = siteSettings.site_url;

// Получаем данные страницы из PocketBase
const pageData = await pb.collection('pages').getFirstListItem('slug = "login"');
const title = `${pageData.title} | ${siteSettings.site_name}`;
const description = pageData.meta_description;
const canonicalLink = pageData.canonical_url ? pageData.canonical_url : `${siteUrl}/${pageData.slug}`;

// Получаем ошибку из URL параметров, если есть
let error = null;
if (Astro.url.searchParams.get('error')) {
    error = Astro.url.searchParams.get('error');
}

// Проверяем параметр emailVerified из URL
const emailVerified = Astro.url.searchParams.get('emailVerified') === 'true';
---

<Layout {title} {description} {canonicalLink}>
	<div class="login-container">
		<h1 class="sr-only">Anmelden bei Berlin Minivan Transfers</h1>
		{emailVerified && (
			<NotificationToast
				message="Ihre E-Mail-Adresse wurde erfolgreich bestätigt! Sie können sich jetzt anmelden."
				type="success"
				duration={5000}
			/>
		)}
		<LoginForm {error} />
	</div>
</Layout>