---
import Layout from '@layouts/Layout.astro';
import { SITE_URL } from '@constants';
import PageHero from '@components/base/PageHero.astro';
import ReviewFormContainer from '@components/reviews/ReviewFormContainer.tsx';
import ReviewsList from '@components/reviews/ReviewsList.astro';
---

<Layout
	title="Отзывы клиентов — автоюрист в Сургуте"
	description="Отзывы реальных клиентов о нашей юридической помощи по автоспорам в Сургуте. Реальные истории и голосования."
	canonicalLink={`${SITE_URL}/reviews`}
	breadcrumbs={[
		{ label: 'Главная', href: '/' },
		{ label: 'Отзывы' }
	]}
>
	<PageHero
		badgeText="ОТЗЫВЫ КЛИЕНТОВ"
		titleWhite="Реальные истории"
		titleGold="водителей из Сургута"
		description="Узнайте, как мы помогли нашим клиентам решить их проблемы с автоспорами"
		layout="with-image"
		sideImage="/images/reviews/revImg.avif"
		sideImageAlt="Автоюрист Сургут"
		experienceBadge={{
			number: "95%",
			text: "ДОВОЛЬНЫХ КЛИЕНТОВ"
		}}
		bgImage="/images/reviews/revBg.avif"
		icon="chat"
	/>

	<section class="reviews-page">
		<div class="site-container">

<!-- Блок статистики голосования -->
			<ReviewsList />

			<!-- Форма для отзыва -->
			<section class="review-form-section">
				<div class="site-container">
					<div class="form-header">
						<h2 class="section-title animate-on-scroll" data-animation="fade-up">
							Оставьте <span class="text-gold">отзыв</span>
						</h2>
						<p class="section-description animate-on-scroll" data-animation="fade-up" data-delay="100">
							Поделитесь своим опытом — ваше мнение важно для нас
						</p>
					</div>

					<ReviewFormContainer client:load />
				</div>
			</section>
		</div>
	</section>
</Layout>

<style>
	.reviews-page {
		padding: 0;
		background: #f8fafc;
	}

	/* ===== GRID ===== */
	.reviews-grid {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
		gap: 2rem;
		margin: 3rem 0;
	}

	/* ===== REVIEW FORM SECTION ===== */
	.review-form-section {
		padding: 5rem 0;
		background: #ffffff;
	}

	.form-header { text-align: center; margin-bottom: 3rem; }
	.section-title { font-size: clamp(2rem, 4vw, 2.5rem); font-weight: 800; color: #1e293b; margin: 0 0 1rem; }
	.section-description { color: #64748b; font-size: 1.1rem; margin: 0; }

	/* Review Form Styles */
	.review-form {
		max-width: 700px;
		margin: 0 auto;
		display: flex;
		flex-direction: column;
		gap: 1.5rem;
	}

	.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
	.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
	.form-label { font-size: 0.9rem; font-weight: 600; color: #1e293b; }

	.form-input, .form-textarea {
		padding: 0.875rem 1rem;
		border: 2px solid #e2e8f0;
		border-radius: 0.75rem;
		font-size: 1rem;
		font-family: inherit;
		transition: all 0.2s ease;
		outline: none;
		background: #f8fafc;
	}

	.form-input:focus, .form-textarea:focus {
		border-color: #d4af37;
		box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
		background: #ffffff;
	}

	.form-textarea { resize: vertical; min-height: 140px; }

	.submit-btn {
		background: linear-gradient(135deg, #d4af37 0%, #eac26e 100%);
		color: #1e293b;
		border: none;
		padding: 1rem 2rem;
		border-radius: 0.75rem;
		font-size: 1.1rem;
		font-weight: 700;
		cursor: pointer;
		transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
		box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
	}

	.submit-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(212, 175, 55, 0.4); }
	.form-privacy { font-size: 0.8rem; color: #94a3b8; text-align: center; }
	.privacy-link { color: #d4af37; text-decoration: underline; }

	/* Анимации */
	.animate-on-scroll {
		opacity: 0;
		will-change: opacity, transform;
	}

	[data-animation="fade-up"] {
		transform: translateY(30px);
		transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1),
					transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
	}

	.animate-on-scroll.is-visible {
		opacity: 1;
		transform: translateY(0);
	}

	@media (prefers-reduced-motion: reduce) {
		.animate-on-scroll {
			opacity: 1;
			transform: none;
			transition: none;
		}
	}

	@media (max-width: 768px) {
		.reviews-grid {
			grid-template-columns: 1fr;
			gap: 1.5rem;
		}

		.form-row { grid-template-columns: 1fr; }
	}
</style>

<script>
	// Intersection Observer для анимаций при скроллинге
	const setupAnimations = () => {
		const observerOptions = {
			root: null,
			rootMargin: '0px 0px -50px 0px',
			threshold: 0.1
		};

		const observer = new IntersectionObserver((entries) => {
			entries.forEach(entry => {
				if (entry.isIntersecting) {
					const el = entry.target as HTMLElement;
					const delay = parseInt(el.dataset.delay || '0');

					setTimeout(() => {
						el.classList.add('is-visible');
					}, delay);

					observer.unobserve(el);
				}
			});
		}, observerOptions);

		document.querySelectorAll('.animate-on-scroll').forEach((el) => {
			observer.observe(el);
		});
	};

	// Запуск
	setupAnimations();

	// Для поддержки View Transitions в Astro
	document.addEventListener('astro:after-swap', () => {
		setupAnimations();
	});
</script>
