<?php 
	get_header(); 

	$useragent=$_SERVER['HTTP_USER_AGENT'];
	$mobile = false;
	if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) $mobile = true;
	$id =  get_the_id();
?>

<?php $teacher_subjects = carbon_get_post_meta( get_the_id(), 'teacher_subjects' ); ?>
<main class="teacher-page">
	<div class="breadcrumbs-teacher">
		<nav class="container" aria-label="Хлебные крошки">
			<ul class="breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">
				<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
					<a itemprop="item" href="/" class="home fa-home" title="Главная страница">
						<span itemprop="name" style='display:none;'>Главная</span>
						<svg width="21" height="16" viewBox="0 0 21 16" fill="none">
							<path d="M11.6473 10.6896H12.1473V11.1896V15.4691H16.4353C16.5143 15.4691 16.5756 15.4462 16.6432 15.3788C16.7108 15.3113 16.7333 15.2505 16.7333 15.1725V9.36976L10.0513 3.8712L3.36922 9.36976V15.1725C3.36922 15.2505 3.39178 15.3113 3.45937 15.3788C3.52698 15.4462 3.5883 15.4691 3.66723 15.4691H7.95527V11.1896V10.6896H8.45527H11.6473ZM10.3711 1.74407L18.9226 8.86174L19.5643 8.09722L16.9141 5.8987L16.7333 5.74874V5.51388V0.537319H14.5413V2.86272V3.93127L13.7209 3.2466L10.6815 0.709949C10.5114 0.572829 10.3095 0.499981 10.0513 0.499981C9.79293 0.499981 9.59094 0.572914 9.42075 0.710194L0.538196 8.09712L1.17996 8.86174L9.73142 1.74407L10.0513 1.47783L10.3711 1.74407Z" fill="white" stroke="white"/>
						</svg>
					</a>
<meta itemprop="position" content="1">
<meta itemprop="position" content="2">
<meta itemprop="position" content="3">
				</li>
			</ul>
		</nav>
	</div>

	<div class="about-teacher container">
		<div class="about-teacher-wrapper"> 
			<div class="left-part">
				<section class="section teacher-description">
					<div class="container">
						<div class="teacher-description-wrapper">
							<p class="teacher-description_text mobile">
							   <?php echo carbon_get_post_meta( get_the_id(), 'teacher_description' ); ?>
							</p>
							<?php $foto = carbon_get_post_meta( get_the_id(), 'teacher_avatar' ); ?>
							<div class="teacher__rating">
								<!--<div class="teacher__rating-img-wrapper">-->
									<div class="teacher__rating-img">
										<?php if ($foto) { ?>
											<img class="teacher__rating-img_foto" src="<?php echo wp_get_attachment_url($foto); ?>" alt="<?php echo get_post_meta( $foto, '_wp_attachment_image_alt', true ); ?>">
										<?php } else { ?>
											<img class="taxonomy-block__name_logo" src="<?php echo get_template_directory_uri(); ?>/assets/images/no-photo.png" alt="заглушка изображения">
										<?php } ?>
									</div>	
								<!--</div>-->
							   
							   	<h1 class="teacher_name mobile">
									<?php
										$name = explode( " ", get_the_title() );
										$count;
										$change_name = "";
										foreach ($name as $word) {
											if ( $count == 0 ) $change_name .= $word . "<br> ";  else $change_name .= $word . " ";
											$count++;
										}
										echo $change_name;
									?>
								</h1>
								
								<div class="teacher_stars">
								  <svg width="25" height="25" viewBox="0 0 21 19" fill="none" xmlns="http://www.w3.org/2000/svg">
									 <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>
								  <span class="teacher__stars_rating"><?php echo carbon_get_post_meta( get_the_id(), 'teacher_rating' ); ?></span>
								  <?php
										// получим все отзывы текущего преподавателя
										$args = array(
											'posts_per_page' => -1,
											'post_type' => 'reviews',
											'meta_query' => array(
												array(
													'key' => 'prepodavatel', // name of custom field
													'value' => '"' . get_the_id() . '"',
													'compare' => 'LIKE'
												)
											)
										);
										
										$the_query = new WP_Query($args);
									?>
									
								  <span class="teacher__stars_reviews">(оценок: <?php echo $the_query->found_posts; ?>)</span>
								</div>
								
								<div class="teacher-description_location">Щелково</div>
							   
							</div>
						</div>
						
						<div class="teacher_name-wrapper">
							<div class="accordion conteiner-text">
								<?php 
								$listSubjects_title = '';
								foreach ($teacher_subjects as $item) { ?>
									<div class="box__accordion">
										<div class="box__accordion_label">
										<?php 
											$listSubjects_title .= $item['teacher_subjects_title'] . ', ';
											echo $item['teacher_subjects_title']; 
										?></div>
										<div class="box__accordion_content">
												<div class="taxonomy-block">
													<div class="taxonomy-block__name">
													   <img class="taxonomy-block__name_logo" src="<?php echo get_template_directory_uri(); ?>/assets/images/icon-direction.svg" alt="icon направления">
													   <span class="taxonomy-block__name_text">Направления:</span>
													</div>
													<div class="taxonomy-block__content">
														<?php echo $item['select_direction']; ?>
													</div>
												 </div>
											<?php
											$categories = $item['select_category'];
											if( $categories ) {?>
												<div class="taxonomy-block">
													<div class="taxonomy-block__name">
													   <img class="taxonomy-block__name_logo" src="<?php echo get_template_directory_uri(); ?>/assets/images/icon-category.svg" alt="icon категории">
													   <span class="taxonomy-block__name_text">Категория:</span>
													</div>
													<div class="taxonomy-block__content">
														<?php foreach ($categories as $category) { ?>
														   <div class="taxonomy-block__content_item"> <?php echo get_term( $category['id'] )->name; ?></div>
														<?php } ?>
													</div>
												 </div>
											<?php } ?>
										</div>
									</div>
								<?php } ?>
								
							</div>
						</div>
						
					</div>
				</section>

				<section class="section teacher-about ">
					<div class="container teacher-about-wrapper">
						<?php 

						$certificates = carbon_get_post_meta( get_the_id(), 'certificates' );
						if ( count($certificates) > 0 ) {
						?>
						<h2 class="certificates_title desktop">Дипломы и сертификаты</h2>
						<div class="certificates desktop">
							<?php //foreach ($certificates as $certificat) { ?>
								<div class="certificate__img">
									<img class="certificates__item_img" src="<?php echo get_template_directory_uri(); ?>/assets/images/sertificats.png" alt="сертификаты">
								</div>
							<?php //} ?>
						</div>
						
						<div class="screen-certificates">
							<div class="clickRemove"></div>
							<button class="btn-close-certificates">
								<img class="btn-close-certificates-img" src="<?php echo get_template_directory_uri(); ?>/assets/images/btn-close-modal.svg" alt="кнопка закрыть окно">
							</button>
							<!--<div class="certificates-owl_wrapper">-->
								<div class="swiper certificates-owl">
									<div class="swiper-wrapper">
										<?php foreach ($certificates as $certificat) { 
											if ($certificat['certificates_foto'] != '') { ?>
												<div class="swiper-slide certificates__item">
													<img class="certificates__item_img" src="<?php echo wp_get_attachment_url($certificat['certificates_foto']); ?>" alt="<?php echo get_post_meta( $certificat['certificates_foto'], '_wp_attachment_image_alt', true ); ?>">
												</div>
											<?php } ?>
										<?php } ?>
									</div>
									<div class="custom-button-next certificates-owl-next"></div>
									<div class="custom-button-prev certificates-owl-prev"></div>
								</div>
							<!--</div>-->
						</div>
						
						<?php } ?>
					</div>
				</section>
			</div>
			<div class="right-part">
				<div class="teacher_name desktop">
					<?php echo get_the_title(); ?>
				</div>
				<p class="teacher-description_text desktop">
				   <?php echo carbon_get_post_meta( get_the_id(), 'teacher_description' ); ?>
				</p>
				<?php 
				$o_sebe = carbon_get_post_meta( get_the_id(), 'teacher_about' );
				$add_class= "more";
				if ($o_sebe != "") {
					if ( strlen($o_sebe) < 560 ) $add_class= "";
					?>
					<div class="teacher-about_content <?php echo $add_class; ?>">
						<h2 class="teacher_title">О себе</h2>
						<div class="teacher-about_text"><?php echo $o_sebe; ?></div>
						<button class="btn-more"><span class="btn-more-click">... Читать еще</span></button>
					</div>
				<?php } ?>
				<div class="accordion obrazovanie">
					<div class="box__accordion">
						<div class="box__accordion_label">Образование</div>
						<div class="box__accordion_content">
							<?php echo carbon_get_post_meta( get_the_id(), 'teacher_education' ); ?>
						</div>
					</div>
					<div class="box__accordion">
						<div class="box__accordion_label">Повышение квалификации</div>
						<div class="box__accordion_content">
							<?php echo carbon_get_post_meta( get_the_id(), 'teacher_add_education' ); ?>
						</div>
					</div>
				</div>
				<?php 
				if ( count($certificates) > 0 ) { ?>
					<div class="certificates_title mobile">Дипломы и сертификаты</div>
					<div class="certificates mobile">
							<div class="certificate__img">
								<img class="certificates__item_img" src="<?php echo get_template_directory_uri(); ?>/assets/images/sertificats.png" alt="сертификаты">
							</div>
					</div>
				<?php } ?>
			
				<?php 
				$teacher_video = carbon_get_post_meta( get_the_id(), 'teacher_video' );
				if ( $teacher_video ) { ?>
				<section class="video">
					<div class="container">
						<h2 class="teacher_title">Видеопрезентация</h2>
						<div class="video-wrapper">
							<?php echo $teacher_video; ?>
						</div>
					</div>
				</section>
				<?php } ?>
			</div>
		</div>
	</div>

	<?php get_template_part( 'template-parts/promo-form' ); ?>

	<?php
		$params = [ 'teacher' => get_the_id()];
		get_template_part( 'template-parts/reviews', null, $params ); 
	?>

	<?php
	$questions = carbon_get_post_meta( get_the_id(), 'questions' );
	if ( count($questions) > 0) : ?>
	<section class="questions">
		<div class="container">
			<h2 class="page_h2">Вопрос-ответ</h2>
			<div class="accordion"  id="accordion1">
				<?php
				$schema_FAQPage = '';
				foreach ($questions as $question) { ?>
					<div class="box__accordion">
						<h3 class="box__accordion_label"><?php echo $question['questions_question']; ?></h3>
						<div class="box__accordion_content">
							<p><?php echo $question['questions_answer']; ?></p>
						</div>
					</div>
					<?php
						$schema_FAQPage .='{"@type": "Question",
											"name": "'. replaceQuotes($question['questions_question']) .'",
											"acceptedAnswer": {
												"@type": "Answer",
												"text": "' .replaceQuotes($question['questions_answer']) .'"}},';
				} ?>
			</div>
		</div>
	</section>
	<?php endif; ?>

	<?php get_template_part( 'template-parts/teachers', null, [ 'count' => 4] ); ?>
	
	<?php get_template_part( 'template-parts/map' ); ?>

</main>

<?php 
// Микроразметка для курсов
$home_url = get_site_url();
$current_url = home_url(add_query_arg(array(),$wp->request));
$site_name = carbon_get_theme_option( 'site_name' );

$site_person = get_the_title();;

$site_index = carbon_get_theme_option( 'site_index' );
$site_region = carbon_get_theme_option( 'site_region' );
$site_address = carbon_get_theme_option( 'site_address' );
$site_city = carbon_get_theme_option( 'site_city' );
$site_phone = carbon_get_theme_option( 'site_phone' );
$site_mail = carbon_get_theme_option( 'site_mail' );

$listSubjects_title = substr($listSubjects_title, 0, -2); // Удаляем последний символ

$teacher_description = replaceQuotes(carbon_get_post_meta( get_the_id(), 'teacher_description' ));

$foto = carbon_get_post_meta( get_the_id(), 'teacher_foto' );
$foto  = wp_get_attachment_url($foto);
?>

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Person",
  "name": "<?php echo $site_person; ?>",
  "jobTitle": "<?php echo $listSubjects_title; ?>",
  "description": "<?php echo $teacher_description; ?>",
  "url": "<?php echo $current_url; ?>/",
  "image": "<?php echo $foto; ?>",
  "worksFor": {
    "@type": "EducationalOrganization",
    "name": "<?php echo $site_name . ' ' . $site_city; ?>",
    "url": "<?php echo $home_url; ?>",
	"address": {
		"@type": "PostalAddress",
		"streetAddress": "<?php echo $site_address; ?>",
		"addressLocality": "<?php echo $site_city; ?>",
		"addressRegion": "<?php echo $site_region; ?>",
		"postalCode": "<?php echo $site_index; ?>",
		"addressCountry": "RU"
	}
  },
  "contactPoint": [
    {
      "@type": "ContactPoint",
      "telephone": "<?php echo $site_phone; ?>",
      "contactType": "customer service",
      "areaServed": "RU",
      "availableLanguage": ["Russian"]
    }
  ]
}
<?php 
if ( count($questions) > 0) : ?>
	{
	  "@context": "https://schema.org",
	  "@type": "FAQPage",
	  "mainEntity": [
		<?php echo $schema_FAQPage; ?>
	  ]
	}
<?php endif; ?>
</script>

<script>
  document.addEventListener('click', (event) => {
		if (event.target.classList.contains('btn-more-click')) {
			
			//onclick='this.parentNode.parentNode.classList.remove("more")'
			const parent = event.target.parentNode.parentNode;
			const element = event.target;
			parent.classList.toggle('more');
			if (parent.classList.contains('more')) element.textContent = '... Читать еще'; else element.textContent = 'Свернуть';
			return;
		}
  });
</script>

<?php get_footer(); ?>