---
import Layout from '@layouts/Layout.astro';
import FaqComponent from '@components/faq/Faq';
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 = "hilfe"');
const title = `${pageData.title} | ${pageData.meta_title}`;
const description = pageData.meta_description;
const canonicalLink = pageData.canonical_url ? pageData.canonical_url : `${siteUrl}/${pageData.slug}`;

// Получаем все FAQ данные для страницы помощи из PocketBase
const faqItemsResponse = await pb.collection('faq_items').getFullList({
    sort: 'order',
    filter: 'is_active=true && show_on_homepage=true',
    fields: 'question,answer,order,show_on_homepage,is_active,category,created,updated,collectionId,collectionName,id'
});

// Преобразуем RecordModel в FaqItem
const faqItems = faqItemsResponse.map(item => ({
    id: item.id,
    question: item.question,
    answer: item.answer,
    show_on_homepage: item.show_on_homepage,
    order: item.order,
    is_active: item.is_active,
    category: item.category,
    collectionId: item.collectionId,
    collectionName: item.collectionName,
    created: item.created,
    updated: item.updated
}));
---

<Layout {title} {description} {canonicalLink}>
    <h1 class="sr-only">Häufig gestellte Fragen - Berlin Minivan Transfers</h1>
    <FaqComponent faqItems={faqItems} client:visible />
</Layout>

