<?php
/*
Template Name: Шаблон страницы Лагерь
*/
?>
<?php

get_header();
$post_id = get_the_ID();

$priceMin = 1000000;
$programs = carbon_get_post_meta($post_id, 'programs' );

if (is_array($programs)) {
    foreach ($programs as $item) {
        $price = (int)$item['programs_price'];
        if ($price < $priceMin) $priceMin = $price;
    }
}

/**
 * Banner helper
 */
function getBanner($suffix, $post_id) {
    $img = carbon_get_post_meta($post_id, 'banner_add_img' . $suffix);
    $img_url = $img ? wp_get_attachment_url($img) : '';
    if (!$img_url) return;
    $title = carbon_get_post_meta($post_id, 'banner_add_title' . $suffix);
    $text  = carbon_get_post_meta($post_id, 'banner_add_text' . $suffix);
    $note  = carbon_get_post_meta($post_id, 'banner_add_text_min' . $suffix);
    ?>
    <div class='banner banner-add' style='background-image: url(<?php echo esc_url($img_url); ?>)'>
        <div class='banner__left-part'>
            <div class='banner_title'><?php echo esc_html($title); ?></div>
            <p class='banner_text'><?php echo esc_html($text); ?></p>
            <button class='banner_btn btn-write-camp'><?php esc_html_e('ЗАБРОНИРОВАТЬ'); ?></button>
            <p class='banner_text-min'><?php echo esc_html($note); ?></p>
        </div>
        <div class='banner__right-part'></div>
    </div>
    <?php
}
?>
<main class="camp container_camp">

<?php

/**
 * === Все данные из Carbon Fields собираем в одном месте ===
 */
$hero = [
    'h1'       => carbon_get_post_meta( $post_id, 'hero_title_h1' )   ?: 'Детский лагерь Декарт.',
    'span'     => carbon_get_post_meta( $post_id, 'hero_title_span' ) ?: 'Яркое лето без забот!',
    'btn_text' => carbon_get_post_meta( $post_id, 'hero_btn_primary' ) ?: 'Записаться на пробный день',
    'image_id' => carbon_get_post_meta( $post_id, 'banner_img' ),
];

$metrics = [
    [
        'img_id'       => carbon_get_post_meta( $post_id, 'hero_metric_1_img' ),
        'number'       => carbon_get_post_meta( $post_id, 'hero_metric_1_number' ) ?: '12',
        'label'        => carbon_get_post_meta( $post_id, 'hero_metric_1_label' )  ?: 'лет в городе',
        'default_icon' => get_template_directory_uri() . '/assets/images/doodles/icon-home.png',
    ],
    [
        'img_id'       => carbon_get_post_meta( $post_id, 'hero_metric_2_img' ),
        'number'       => carbon_get_post_meta( $post_id, 'hero_metric_2_number' ) ?: '2 500+',
        'label'        => carbon_get_post_meta( $post_id, 'hero_metric_2_label' )  ?: 'счастливых детей',
        'default_icon' => get_template_directory_uri() . '/assets/images/doodles/icon-bulb.png',
    ],
    [
        'img_id'       => carbon_get_post_meta( $post_id, 'hero_metric_3_img' ),
        'number'       => carbon_get_post_meta( $post_id, 'hero_metric_3_number' ) ?: '4.9 / 5',
        'label'        => carbon_get_post_meta( $post_id, 'hero_metric_3_label' )  ?: 'рейтинг от родителей',
        'default_icon' => get_template_directory_uri() . '/assets/images/doodles/icon-award.png',
    ],
];


?>

<section class="section-bg hero-media-search" data-bg="hero">
    <div class="container">
        <div class="hero-media-search__container">

            <!-- Левая колонка -->
            <div class="hero-media-search__content">
                <h1 class="heading-1"><?php echo wp_kses_post( $hero['h1'] ); ?></h1>
                <h2 class="hero-subtitle-brand"><?php echo wp_kses_post( $hero['span'] ); ?></h2>

                <!-- Метрики (десктоп) -->
                <div class="hero-media-search__propositions on-desktop">
                    <?php foreach ( $metrics as $metric ) : ?>
                        <?php render_hero_metric( $metric ); ?>
                    <?php endforeach; ?>
                </div>

                <!-- CTA (десктоп) -->
                <div class="hero-cta on-desktop">
                        <a href="#" class="btn-write-camp about-us__cta-link" aria-label="<?php echo esc_attr( $hero['btn_text'] ); ?>">
                            <?php echo esc_html( $hero['btn_text'] ); ?> →
                        </a>
                        <p class="hero-cta__note">Один пробный день — за наш счёт. Оцените качество сами, а решение примете после.</p>
                    </div>
                </div>

            <!-- Правая колонка (изображение + мобильные элементы) -->
            <div class="hero-media-search__media">
                <div class="hero-media-search__frame">
                    <?php if ( $hero['image_id'] ) : ?>
                        <?php echo wp_get_attachment_image( $hero['image_id'], 'full', false, [
                            'class'   => 'hero-media-search__image',
                            'fetchpriority' => 'high',
                            'loading' => 'eager',
                            'alt'     => esc_attr( wp_trim_words( $hero['h1'], 10 ) )
                        ] ); ?>
                    <?php else : ?>
                        <img class="hero-media-search__image"
                             fetchpriority="high" src="<?php echo get_template_directory_uri(); ?>/assets/images/camp-hero.jpg"
                             alt="Детский лагерь Декарт" loading="eager">
                    <?php endif; ?>

                    <!-- Декоративные элементы -->
                    <img src="<?php echo get_template_directory_uri(); ?>/assets/images/doodles/hero-doodle-gears.svg"
                         alt="" class="doodle doodle--top-left">
                    <img src="<?php echo get_template_directory_uri(); ?>/assets/images/doodles/hero-doodle-pencils.svg"
                         alt="" class="doodle doodle--bottom-right">
                </div>

                <!-- Метрики + CTA (мобильная версия) -->
                <div class="hero-media-search__wrapper">
                    <div class="hero-media-search__propositions on-mobile">
                    <?php foreach ( $metrics as $metric ) : ?>
                        <?php render_hero_metric( $metric ); ?>
                    <?php endforeach; ?>
                    </div>

                    <div class="hero-cta on-mobile">
                        <a href="#0" class="btn-write-camp about-us__cta-link" aria-label="<?php echo esc_attr( $hero['btn_text'] ); ?>">
                            <?php echo esc_html( $hero['btn_text'] ); ?> →
                        </a>
                        <p class="hero-cta__note">Один пробный день — за наш счёт. Оцените качество сами, а решение примете после.</p>
                    </div>
                </div>
            </div>

        </div>
    </div>
</section>
	<section class="section-reveal section-bg about-us" data-bg="white">
	<div class="container">
		<div class="about-us__wrapper">
			<div class="about-us__image-col">
				<div class="about-us__frame">
				<?php
					$about_img_id = carbon_get_post_meta( $post_id, 'about_us_img' );
					if ( $about_img_id ) :
						echo wp_get_attachment_image( $about_img_id, 'large', false, [
							'class'   => 'about-us__image',
							'loading' => 'lazy',
							'alt'     => 'Фото детского лагеря Декарт'
						] );
					else :
						echo '<div class="about-us__image-placeholder">
							<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
								<rect x="3" y="3" width="18" height="18" rx="2"/>
								<circle cx="8.5" cy="8.5" r="1.5"/>
								<path d="M21 15l-5-5L5 21"/>
							</svg>
							<span>Добавьте фото</span>
						</div>';
					endif;
				?>
					<img src="<?php echo get_template_directory_uri(); ?>/assets/images/doodles/galileo/paperplane-galileo.svg"
					     alt="" class="about-us__doodle about-us__doodle--plane">
					<img src="<?php echo get_template_directory_uri(); ?>/assets/images/doodles/galileo/orangegear-white.svg"
					     alt="" class="about-us__doodle about-us__doodle--heart">
				</div>
			</div>
			<div class="about-us__content-col">
				<h2 class="camp_title about-us__title">Лето, которое не хочется ставить на паузу</h2>
				<div class="about-us__text">
					<?php echo wp_kses_post( carbon_get_post_meta( $post_id, 'about_us_text' ) ?: 'Всю зиму ребёнок в телефоне? Бабушка устала? А ведь лето может быть другим — ярким, живым, полезным.
В Dekart дети не просто под присмотром. Они собирают роботов, ставят опыты, играют в театре, бегают на квестах и находят друзей.А главное — бегут в лагерь каждое утро без уговоров.' ); ?>
				</div>
				<div class="about-us__social-proof">
					<span class="about-us__badge">⭐ 2500+ мам доверили нам лето</span>
				</div>
				<div class="about-us__cta">
					<a href="#" class="btn-write-camp about-us__cta-link">Хочу на пробный день →</a>
				</div>
			</div>

		</div>
	</div>
</section>
<section class="section-reveal section-bg suggestions" data-bg="mint">
	<div class="container">
	<h2 class="camp_title">Почему мамы выбирают Dekart: дети бегут сюда сами</h2>
	<p class="suggestions__subtitle">Никаких уговоров по утрам. Никаких «забери меня». Только горящие глаза и «а можно ещё?»</p>
	<div class="suggestions-wrapper">		<?php 			$suggestions = carbon_get_post_meta($post_id, 'suggestions' );			$icons = ['innovation-white.svg', 'steamprojects-35x35-1.svg', 'handson-35x35-1.svg', 'orangegear-white.svg', 'outdoor-white.svg', 'heart_sticker.svg'];
			if (is_array($suggestions)) {
				foreach ($suggestions as $index => $item) {
					$suggestions_title = $item['suggestions_title'];
					$suggestions_text = $item['suggestions_text'];
					$icon_file = $icons[$index % count($icons)];
				?>				<div class="suggestions__item">
						<div class="suggestions__icon-wrap">
							<img src="<?php echo get_template_directory_uri(); ?>/assets/images/doodles/galileo/<?php echo $icon_file; ?>"
						     alt="" class="suggestions__icon">
						</div>
						<h3 class="suggestions__item_title"><?php echo esc_html( $suggestions_title ); ?></h3>
						<p class="suggestions__item_text"><?php echo esc_html( $suggestions_text ); ?></p>
					</div>		<?php }
			} ?>	</div>
	</div>
</section>
	<section class="section-reveal section-bg infograph" data-bg="white">
		<div class="container">
			<h2 class="camp_title">Цифры, которые говорят сами за себя</h2>
			<p class="infograph__lead">Мы создаём среду, где каждый ребёнок раскрывает свой потенциал</p>
			<div class="infograph__grid">

				<div class="infograph__card">
					<div class="infograph__icon infograph__icon--age">
						<img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/age.svg" alt="" width="48" height="48">
					</div>
					<p class="infograph__stat">6,5−11 лет</p>
					<p class="infograph__label">возраст</p>
				</div>

				<div class="infograph__card">
					<div class="infograph__icon infograph__icon--group">
						<img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/group.svg" alt="" width="48" height="48">
					</div>
					<p class="infograph__stat">до 10 детей</p>
					<p class="infograph__label">каждая группа</p>
				</div>

				<div class="infograph__card">
					<div class="infograph__icon infograph__icon--time">
						<img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/time.svg" alt="" width="48" height="48">
					</div>
					<p class="infograph__stat">на выбор</p>
					<p class="infograph__label">время посещения</p>
				</div>

				<div class="infograph__card">
					<div class="infograph__icon infograph__icon--price">
						<img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/price.svg" alt="" width="48" height="48">
					</div>
					<p class="infograph__stat">от <?php echo esc_html( number_format($priceMin, 0, ',', ' ') ); ?> ₽</p>
					<p class="infograph__label">стоимость недели</p>
				</div>

			</div>
		</div>
	</section>

	<section class="section-reveal section-bg programs" data-bg="mint" itemscope itemtype="https://schema.org/ItemList">
		<div class="container">
			<h2 class="camp_title" itemprop="name">Летние программы</h2>
			<div class="programs__grid">
				<?php
				$programs = carbon_get_post_meta($post_id, 'programs');
				if (is_array($programs)) {
					foreach ($programs as $item) {
						$programs_img = $item['programs_img'];
						$programs_title = $item['programs_title'];
						$programs_date = $item['programs_date'];
						$programs_text = $item['programs_text'];
						$programs_price = $item['programs_price'];
						$programs_days = $item['programs_days'];
						$programs_content = $item['programs_content'];?>
				<article class="programs__card">
					<img class="programs__image" loading="lazy" width="360" height="225" src="<?php echo wp_get_attachment_url($programs_img); ?>" alt="<?php echo get_post_meta($programs_img, '_wp_attachment_image_alt', true); ?>">
					<div class="programs__body">
						<h3 class="programs__name"><?php echo esc_html($programs_title); ?></h3>
						<p class="programs__date"><?php echo esc_html($programs_date); ?></p>
						<p class="programs__desc"><?php echo esc_html($programs_text); ?></p>
						<div class="programs__footer">
							<span class="programs__price"><?php echo number_format((int)$programs_price, 0, ',', ' '); ?> ₽</span>
							<span class="programs__duration"><?php echo esc_html($programs_days); ?></span>
						</div>
						<div class="programs_content" style="display: none;"><?php echo wp_kses_post($programs_content); ?></div>
						<button class="programs__btn btn-program" aria-label="Подробнее о программе <?php echo esc_attr($programs_title); ?>">Подробнее</button>
					</div>
				</article>
				<?php
					}
				} ?>
			</div>
		</div>
	</section>

	<?php getBanner('', $post_id); ?>

	<section class="section-reveal section-bg bring-child" data-bg="white" itemscope itemtype="https://schema.org/Product">
    <meta itemprop="name" content="Городской лагерь Декарт">
    <meta itemprop="description" content="Стоимость пребывания в городском лагере Декарт">
	<?php 
		$price_half_day = carbon_get_post_meta($post_id, 'price_half_day' );
		$price_full_day = carbon_get_post_meta($post_id, 'price_full_day' );
	?>
	 <h2 class="camp_title">Приводите ребёнка, когда вам удобно</h2>
	 <div class="bring-child-wrapper">
		<div class="part-day camp-left-part">
		   <div class="part-day_title">
			  <div class="block-row">
				 <p class="part-day_title-text">Половина дня</p>
				 <img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/green-star.svg" width="30" height="30" alt="">
			  </div>
			  <p class="part-day_text">Время пребывания — на выбор (до обеда или до вечера)</p>
		   </div>
		   <div class="part-day__price">
			  <div class="block-row">
				 <div class="part-day__price_price" itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price" content="<?php echo esc_attr($price_half_day); ?>"><?php echo number_format($price_half_day, 0, ',', ' '); ?></span><meta itemprop="priceCurrency" content="RUB"></div>
				 <div class="part-day__price_time">с 8:30 до 13:30</div>
			  </div>
			  <p class="part-day__price_text">за 5 дней пребывания</p>
		   </div>
		   <div class="part-day__price">
			  <div class="block-row">
				 <div class="part-day__price_price">
                  <?php echo number_format($price_half_day, 0, ',', ' '); ?></div>
				 <div class="part-day__price_time non-bg">с 13:30 до 18:30</div>
			  </div>
			  <p class="part-day__price_text">за 5 дней пребывания</p>
		   </div>
		   <div class="block-row">
			  <img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/calendar.png" width="27" height="28" alt="">
			  <p class="part-day_text">Тематическая неделя на выбор</p>
		   </div>
		   <button class="btn-place btn-write-camp">Занять место</button>
		   <ul>
			  <li><b>5 дней</b> пребывания в клубе</li>
			  <li>творческие занятия и мастер-классы <b>1 раз в день</b></li>
			  <li>умные прогулки <b>1 раз в день</b> (в зависимости от погодные условий)</li>
		   </ul>
		</div>
		<div class="part-day camp-right-part">
		   <div class="part-day_title">
			  <div class="block-row">
				 <p class="part-day_title-text">Полный день</p>
				 <img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/star-02.svg" width="30" height="30" alt="">
			  </div>
			  <p class="part-day_text">Пребывание в клубе с утра до вечера, дополнительные активности</p>
		   </div>
		   <div class="part-day__price">
			  <div class="block-row">
				 <div class="part-day__price_price" itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price" content="<?php echo esc_attr($price_full_day); ?>"><?php echo number_format($price_full_day, 0, ',', ' '); ?></span><meta itemprop="priceCurrency" content="RUB"></div>
				 <div class="part-day__price_time non-bg">с 8:30 до 18:30</div>
			  </div>
			  <p class="part-day__price_text">за 5 дней пребывания</p>
		   </div>
		   <div class="block-row">
			  <img loading="lazy" src="<?php echo get_template_directory_uri(); ?>/assets/images/calendar+.png" width="27" height="28" alt="">
			  <p class="part-day_text">Тематическая неделя на выбор</p>
		   </div>
		   <button class="btn-place btn-write-camp">Занять место</button>
		   <ul>
			  <li><b>5 дней</b> пребывания в клубе</li>
			  <li>творческие занятия и мастер-классы <b>2 раза в день</b></li>
			  <li>умные прогулки <b>2 раза в день</b> (в зависимости от погодные условий)</li>
			  <li>тематические экскурсии каждую неделю</li>
		   </ul>
		</div>
	 </div>
	</section>

<section class="section-reveal section-bg mentors" data-bg="mint">
<h2 class="camp_title">Наши наставники и ведущие мастер-классов</h2>
     <div class="mentors-wrapper">
        <?php 
        $mentors = carbon_get_post_meta($post_id, 'mentors' );
        if (is_array($mentors)) {
            foreach ($mentors as $item) { 
                $mentor = $item['mentor'];
                $mentorName = get_the_title($mentor[0]['id']);
                $mentor_job = $item['mentor_job'];
                $mentor_directions = $item['mentor_directions'];
                $HTMLdirection = "";
                $post_url = get_permalink($mentor[0]['id']);
                if (is_array($mentor_directions)) {
                    foreach ($mentor_directions as $direction) {$HTMLdirection .= "<span>" . esc_html($direction['direction_name'])."</span>";}
                }
                $teacher_foto = carbon_get_post_meta($mentor[0]['id'] , 'teacher_avatar');
            ?>
                <div class="mentors__item">
                    <?php if ( $teacher_foto == '' ) { ?>
                        <img class="mentors__item_img" loading="lazy" width="260" height="270" src="<?php echo get_template_directory_uri(); ?>/assets/images/no-photo.png" alt="">
                    <?php } else { ?>
                       <img class="mentors__item_img" loading="lazy" width="260" height="270" src="<?php echo wp_get_attachment_url($teacher_foto); ?>" alt="<?php echo get_post_meta( $teacher_foto, '_wp_attachment_image_alt', true ); ?>">
                    <?php } ?>
                   <a href="<?php echo esc_url($post_url); ?>" class="mentors__item_name"><?php echo esc_html($mentorName); ?></a>
                   <a href="<?php echo esc_url($post_url); ?>" class="mentors__item_text"><?php echo esc_html($mentor_job); ?></a>
                   <button class="btn-details btn-mentors">Подробнее</button>
                   <div class="mentor-modal-content" style="display: none;">
                       <?php
                            $post_url = get_permalink($mentor[0]['id']);
                            $mentor_education = carbon_get_post_meta($mentor[0]['id'] , 'teacher_education');
                            $mentor_experience = $item['mentor_experience'];
                            $mentor_add_experience = carbon_get_post_meta($mentor[0]['id'] , 'teacher_add_education');
                        ?>
                        <div class="HTMLdirection"><?php echo $HTMLdirection; ?></div>
                        <div class="mentor_education"><?php echo esc_html($mentor_education); ?></div>
                        <div class="mentor_experience"><?php echo esc_html($mentor_experience); ?></div>
                        <div class="mentor_add_experience"><?php echo esc_html($mentor_add_experience); ?></div>
                   </div>
                </div>
            <?php }
        } ?>
     </div>

    </section>

	<section class="section-reveal section-bg routine" data-bg="white">
		<h2 class="camp_title">Распорядок дня в клубе</h2>
		<div class="routine-wrapper">
	 	<?php 
			$routine = carbon_get_post_meta($post_id, 'routine' );
			if (is_array($routine)) {
				foreach ($routine as $item) { 
					$routine_time = $item['routine_time'];
					$routine_title = $item['routine_title'];
					$routine_text = $item['routine_text'];
				?>
				<div class="routine__item">
					<div class="routine__item_time"><?php echo esc_html($routine_time); ?></div>
					<div class="routine__item_circle"></div>
					<div class="routine__item_text">
					  <p class="routine__item_time-mobile"><?php echo esc_html($routine_time); ?></p>
					  <p class="routine__item_text-title"><?php echo esc_html($routine_title); ?></p>
					  <p class="routine__item_text-text"><?php echo esc_html($routine_text); ?></p>
					</div>
				</div>
			<?php }
			} ?>
		</div>
	</section>

	<section class="section-reveal section-bg foto" data-bg="mint">
	 <h2 class="camp_title">Наши фотографии</h2>
	 <div class="camp-foto-wrapper">
		<?php 
			$fotos = carbon_get_post_meta($post_id, 'fotos' );
			$fotos_content = carbon_get_post_meta($post_id, 'fotos_content' );
			$fotos_link_vk = carbon_get_post_meta($post_id, 'fotos_link_vk' );
			$HTMLimgs = "";
			if (is_array($fotos)) {
				foreach ($fotos as $item) { 
					$img = wp_get_attachment_url($item['foto']);
                    $alt = esc_attr(get_post_meta( $item['foto'], '_wp_attachment_image_alt', true ));
                    $HTMLimgs .= "<div class='swiper-slide'>
                                    <img loading='lazy' src='$img' alt='$alt' width='560' height='420'>
                                  </div>";
				}
			} ?>
		<div class="foto-left-part">
		   <div class="swiper-container camp-swiper-foto">
			  <div class="swiper-wrapper">
					<?php echo $HTMLimgs; ?>
			  </div>
			  <div class="swiper-button-next"></div>
			  <div class="swiper-button-prev"></div>
		   </div>
		   <div thumbsSlider="" class="swiper-container camp-swiper-foto-thumbsSlider">
			  <div class="swiper-wrapper">
					<?php echo $HTMLimgs; ?>
			  </div>
		   </div>
		</div>
		<div class="foto-content"><?php echo esc_html($fotos_content); ?></div>
	 </div>
	</section>

	<section class="section-reveal section-bg camp-reviews" data-bg="white">
		<h2 class="camp_title">Что говорят о нас родители</h2>
	<?php 

		$key = [
		[ 
			'key' => 'review_type',
			'value' => 'camp',
			'compare' => '='
			]
		]; 
		
		?>
		<div class="camp-reviews-wrapper">
			<div class="reviews-wrapper">
				<div class='swiper reviews-owl'>
					<div class='swiper-wrapper'>
					<?php
					$args = array(
						'posts_per_page' 	=> -1,
						'post_type' 	=> 'reviews',
						'orderby'		=> 'date',
						'order'			=> 'DESC',
						'suppress_filters' => true,
						'meta_query' => $key,
					);
					$the_query = new WP_Query($args);
					if ($the_query->have_posts()) : 
						while ($the_query->have_posts()) : $the_query->the_post(); 
						
							$review_id = get_the_ID();

							$review_date = get_the_date( 'd.m.Y');
							$review_level = carbon_get_post_meta( $review_id, 'review_level' );
							
							$avatar = carbon_get_post_meta( $review_id, 'review_avatar' );

							$stars = carbon_get_post_meta( $review_id, 'review_star' );
							$tekst_otzyva = carbon_get_post_meta( $review_id, 'review_text' );
							$prepodavatel = carbon_get_post_meta( $review_id, 'review_teacher' );
						
							$add_class= "more";
						
							if ( strlen($tekst_otzyva) < 350 ) $add_class= "";

							if ( $tekst_otzyva ) : ?>
								<div class="swiper-slide reviews__item">
										<div class="reviews__item-wrapper">
											 <div class="reviews__item-client">
												<div class="reviews__item-client_avatar" style="background: <?php echo esc_attr(rand_color()); ?>">
													<?php if ($avatar) : ?>
														<img loading="lazy" width="57" height="57" class="reviews__item-client_avatar-img" src="<?php echo wp_get_attachment_url($avatar); ?>" alt="<?php echo get_post_meta( $avatar, '_wp_attachment_image_alt', true ); ?>">
													<?php endif; ?>
												</div>
												<div class="reviews__item-client_data">
												   <div class="reviews__item-client_name"><?php the_title(); ?></div>
												   <div class="reviews__item-client_lavel" ><?php echo esc_html($review_level); ?></div>
												</div>
											</div>
											<div class="reviews__item-client_stars">
												<?php 
													if (!$stars) $stars = 5;
													for ($i = 1; $i <= $stars; $i++) { ?>
														<svg width="20" height="20" viewBox="0 0 21 19" fill="none">
															<path d="M9.58463 1.50884C9.89101 0.602477 11.1729 0.602476 11.4793 1.50884L13.1158 6.35007C13.2531 6.75637 13.6343 7.02985 14.0631 7.02985H19.2721C20.2504 7.02985 20.6467 8.28958 19.8447 8.84971L15.6995 11.7446C15.335 11.9991 15.1823 12.4636 15.3247 12.8847L16.9239 17.6158C17.233 18.5302 16.1954 19.3085 15.404 18.7559L11.1045 15.7533C10.7606 15.5131 10.3033 15.5131 9.95941 15.7533L5.65991 18.7559C4.86857 19.3085 3.83092 18.5302 4.14001 17.6158L5.73926 12.8847C5.8816 12.4636 5.72891 11.9991 5.36448 11.7446L1.21924 8.84971C0.417196 8.28958 0.813532 7.02985 1.79181 7.02985H7.00081C7.42969 7.02985 7.81081 6.75637 7.94815 6.35007L9.58463 1.50884Z" fill="#FFD43E" />
														</svg>
													<?php } ?>
													<span><?php echo esc_html($review_date); ?></span>
											</div>
											<div class="reviews__item-client_text <?php echo esc_attr($add_class); ?>">
												<?php echo wp_kses_post($tekst_otzyva); ?>
												<button class="btn-more"><span onclick='this.parentNode.parentNode.classList.remove("more")'>... Читать еще</span></button>
											</div>
										</div>
									</div>
								<?php
								endif;
							endwhile; ?>
						</div>
					</div>
			<?php endif; ?>
				</div>
				<div class='custom-button-next reviews-owl-next'></div>
				<div class='custom-button-prev reviews-owl-prev'></div>
				<?php wp_reset_postdata(); ?>
			</div>
		</section>

		<?php getBanner("2", $post_id); ?>

		<section class="section-reveal section-bg camp-faq" data-bg="mint">
			<h2 class="camp_title">Часто задаваемые вопросы</h2>
			<div class="faq-wrapper" itemscope itemtype="https://schema.org/FAQPage">

			<?php 
				$post_id = get_the_ID();
				$questions = carbon_get_post_meta($post_id, 'questions' );
				$HTMcol1 = '';
				$HTMcol2 = '';

				$count = 0;
				if (is_array($questions)) {
					foreach ($questions as $item) { 
						$questions_question = $item['questions_question'];
						$questions_answer = $item['questions_answer'];
						$accordion_item = "<div class='box__accordion'>
							  <div class='box__accordion_label' role='button' tabindex='0' itemscope itemprop='mainEntity' itemtype='https://schema.org/Question'>
								 <span itemprop='name'>" . esc_html($questions_question) . "</span>
								 <svg role='presentation' focusable='false' width='24px' height='24px' viewBox='0 0 24 24'>
									<g stroke='none' stroke-width='2px' fill='none' fill-rule='evenodd' stroke-linecap='square'>
									   <g transform='translate(1.000000, 1.000000)' stroke='#3bb273'>
										  <path d='M0,11 L22,11'></path>
										  <path d='M11,0 L11,22'></path>
									   </g>
									</g>
								 </svg>
							  </div>
							  <div class='box__accordion_content' itemscope itemprop='acceptedAnswer' itemtype='https://schema.org/Answer'>
								 <div class='box__accordion_content-text' itemprop='text'>" . wp_kses_post($questions_answer) . "</div>
							  </div>
						   </div>";
						if ($count % 2 === 0) {
							$HTMcol1 .= $accordion_item;
						} else {
							$HTMcol2 .= $accordion_item;
						}
						$count++;
					}
				}
				echo "<div class='accordion'>$HTMcol1</div>";
				echo "<div class='accordion accordion-last'>$HTMcol2</div>"; 
				?>
			</div>
		</section>

		<section class="section-reveal section-bg camp-contact" data-bg="white">
			<?php 
				$contact_tel = carbon_get_post_meta($post_id, 'contact_tel' );
				$contact_address = carbon_get_post_meta($post_id, 'contact_address' );
				$contact_location = carbon_get_post_meta($post_id, 'contact_location' );
				$contact_location_text = carbon_get_post_meta($post_id, 'contact_location_text' );
				$contact_mail = carbon_get_post_meta($post_id, 'contact_mail' );
			?>
			<h2 class="camp_title">Контакты</h2>
			<div class="contact-wrapper">
				<div class="contact-content">
					<div class="contact_subtitle">Телефон:</div>
					<a class="contact_tel" href="tel:+<?php echo preg_replace('/[^0-9]/', '', $contact_tel); ?>" target="_blank"><?php echo esc_html($contact_tel); ?></a>
					<div class="contact_subtitle">Почта:</div>
					<a class="contact_tel" href="mailto:<?php echo esc_attr($contact_mail); ?>" target="_blank"><?php echo esc_html($contact_mail); ?></a>
					<div class="contact_subtitle">Адрес:</div>
					<div class="contact_tel"><?php echo esc_html($contact_address); ?></div>
					<div class="contact_subtitle">Наши соцсети:</div>
					<div class="contact_social">
						<?php 
						$social_media = carbon_get_post_meta( $post_id, 'social_media' );
						if (is_array($social_media)) {
							foreach( $social_media as $item ) { 
								$icon =  $item['social_media_img']; 
								if ($item['social_media_link'] != '') { ?>
								<a class="social_item" href="<?php echo esc_url($item['social_media_link']); ?>" title="<?php echo esc_attr($item['social_media_name']); ?>">
									<img loading="lazy" width="32" height="32" src="<?php echo wp_get_attachment_url($icon); ?>" alt="">
								</a>
								<?php }
							}
						} ?>
					</div>
				</div>
			<div class="contact-map">
				<div id="ya-map" style="width: 100%; height: 625px;"></div>
			</div>
			</div>
		</section>

</main>

<div class="modal-programs" role="dialog" aria-modal="true" aria-label="Программа лагеря">
	<div class="modal-programs__card">
		<button class="modal-programs__close btn-close-programs" aria-label="Закрыть">
			<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M18 6L6 18M6 6l12 12" stroke="#fff" stroke-width="2" stroke-linecap="round"\/><\/svg>
		</button>
		<div class="modal-programs__img">
			<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='300'%3E%3C/svg%3E" alt="">
		</div>
		<div class="modal-programs__body">
			<h3 class="programs__item_title"></h3>
			<p class="programs__item_price"></p>
			<div class="programs__content"></div>
		</div>
	</div>
</div>

<div class="modal-mentors" role="dialog" aria-modal="true" aria-label="Информация о наставнике">
 <div class="modal-mentors-wrapper">
	<button class="btn-close-mentors" aria-label="Закрыть">
	   <svg role="presentation" class="t-popup__close-icon" width="23px" height="23px" viewBox="0 0 23 23">
		  <g stroke="none" stroke-width="1" fill="#3bb273" fill-rule="evenodd">
			 <rect
				transform="translate(11.313708, 11.313708) rotate(-45.000000) translate(-11.313708, -11.313708) "
				x="10.3137085" y="-3.6862915" width="2" height="30"></rect>
			 <rect
				transform="translate(11.313708, 11.313708) rotate(-315.000000) translate(-11.313708, -11.313708) "
				x="10.3137085" y="-3.6862915" width="2" height="30"></rect>
		  </g>
	   </svg>
	</button>
	<div class="modal-programs__img">
	   <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='300'%3E%3C/svg%3E" alt="">
	</div>
	<div class="modal-mentors__content">
	   <div class="modal-mentors_name"></div>
	   <div class="modal-mentors_job"></div>
	   <div class="modal-mentors__directions"></div>
	   <div class="modal-mentors__about">
		  <div class="about-item">
			 <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icons/icon-education.svg" alt="" width="60" height="58" loading="lazy">
			 <div class="mentors__about-col">
				<p class="mentors__about-col_title">Образование:</p>
				<div class="mentors__about-col_text"></div>
			 </div>
		  </div>
		  <div class="about-item">
			 <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icons/icon-experience.svg" alt="" width="59" height="58" loading="lazy">
			 <div class="mentors__about-col">
				<p class="mentors__about-col_title">Опыт работы в сфере образования:</p>
				<div class="mentors__experience-col_text"></div>
			 </div>
		  </div>
	   </div>
	   <div class="modal-additional__education">
		  <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icons/icon-certificate.svg" alt="" width="58" height="60" loading="lazy">
		  <div class="mentors__about-col">
			 <p class="mentors__about-col_title">Дополнительное образование:</p>
			 <div class="modal-additional__education_list">
			 </div>
		  </div>
	   </div>
	</div>
 </div>
</div>

<div class="modal-camp-request-form" style="display: none;">
	<div class="form-wrapper">
		<button class="btn-close-request-form">
			<img class="btn-close-request-form-camp" src="<?php echo get_template_directory_uri(); ?>/assets/images/btn-close-modal.svg" alt="кнопка закрыть окно">
		</button>
		<?php echo carbon_get_post_meta($post_id, 'camp_bitrix_script' ); ?>
	</div>
</div>

<script>
(function() {
    var mapLoaded = false;
    var mapContainer = document.getElementById("ya-map");
    if (!mapContainer) return;

    var observer = new IntersectionObserver(function(entries) {
        if (entries[0].isIntersecting && !mapLoaded) {
            mapLoaded = true;
            observer.disconnect();

            var script = document.createElement("script");
            script.src = "https://api-maps.yandex.ru/2.1/?lang=ru_RU";
            script.onload = function() {
            script.onerror = function() { console.warn("Yandex Maps API failed to load"); };
                ymaps.ready(function() {
                    var coords = <?php echo $contact_location ? '[' . esc_js($contact_location) . ']' : '[55.76, 37.64]'; ?>;
                    var map = new ymaps.Map("ya-map", {
                        center: coords,
                        zoom: 16
                    }, {
                        searchControlProvider: "yandex#search"
                    });

                    var placemark = new ymaps.Placemark(
                        coords,
                        { iconContent: "<?php echo esc_js($contact_location_text); ?>" },
                        { preset: "islands#redStretchyIcon" }
                    );
                    map.geoObjects.add(placemark);
                });
            };
            document.body.appendChild(script);
        }
    }, { rootMargin: "200px" });

    observer.observe(mapContainer);
})();
</script>


<?php
get_footer();
