---
import { authService } from '@/lib/authService';

// Инициализация клиента PocketBase
const pb = authService.createClientFromRequest(Astro.request);

// Получение данных из PocketBase
const positionData = await pb.collection('open_positions').getFirstListItem('');
---

<!-- Open Positions Component -->
<section id="offene-stellen" class="py-20 bg-gradient-to-br from-slate-50 to-slate-100 scroll-mt-28">
    <div class="max-w-4xl mx-auto px-6">
        <div class="text-center mb-16">
            <h2 class="text-3xl md:text-4xl font-bold text-gray-900 mb-4">
                {positionData.section_title}
            </h2>
            <div class="w-24 h-1 bg-amber-500 mx-auto mb-6"></div>
        </div>

        <div class="space-y-8">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-slate-200 hover:shadow-xl transition-all duration-300 hover:-translate-y-2">
                <div class="p-8">
                    <div class="flex flex-col md:flex-row md:justify-between md:items-start gap-4">
                        <div>
                            <h3 class="text-2xl font-bold text-amber-600">
                                {positionData.position_title}
                            </h3>
                            <p class="text-gray-500 mt-2">{positionData.employment_type}</p>
                        </div>
                        <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800">
                            {positionData.status || 'Aktuell'}
                        </span>
                    </div>
                    <p class="mt-6 text-gray-700">
                        {positionData.description}
                    </p>
                    <div class="mt-8">
                        <a
                            href="#bewerbung"
                            class="inline-block bg-amber-500 text-slate-900 font-bold py-3 px-6 rounded-lg transition-all duration-300 hover:bg-amber-400 hover:scale-105 active:scale-95"
                            onclick="openApplicationModal()"
                        >
                            {positionData.btn_text}
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>