<?php /* Template Name: Publications | Archive */
get_header();
$current_page_id = get_queried_object_id();
$pageIcon = get_field('page_icon', get_queried_object_id()) ?? null;

$posts_per_page = 5;

// #### BROCHURES QUERY
$args = array(
	'post_type' => 'brochures',
	'posts_per_page' => $posts_per_page,
	'post_status' => 'publish',
	'order' => 'DESC',
	'orderby' => 'date',
	'meta_key'      => 'brochure_pdf',
	'meta_value' => '',
	'meta_compare' => '!=',
	// ICI METAQUERY FOR LE PDF
);
$brochuresPosts = new WP_Query($args);

// #### FICHES INFOS QUERY
$args = array(
	'post_type' => 'fiches-infos',
	'posts_per_page' => $posts_per_page,
	'post_status' => 'publish',
	'order' => 'DESC',
	'orderby' => 'date',
	'meta_key'      => 'brochure_pdf',
	'meta_value' => '',
	'meta_compare' => '!=',
	// ICI METAQUERY FOR LE PDF
);
$fichesInfosPosts = new WP_Query($args);

// #### VIDÉOS & WEBINAIRES QUERY
$videosWebinairesDatas = get_field('videos_webinaires', $current_page_id)['videos_webinaires_datas'] ?? null;

$total_posts_found = $brochuresPosts->found_posts + $fichesInfosPosts->found_posts + count($videosWebinairesDatas);

?>
<div class="template-archives template-archives--publications">
	<?php /* ------------
		BREADCRUMB
 		-----------------*/ ?>
	<nav class="breadcrumbs_navigation" aria-label="breadcrumbs">
		<ol>
			<li><a href="<?php echo home_url() ?>">Home</a></li>
			<li><a href="<?php echo get_post_type_archive_link('brochures') ?>" aria-current='location'>Publications</a></li>
		</ol>
	</nav>


	<?php /* ---------
		HEADING BOX
 -----------------*/ ?>
	<?php
	get_template_part("template-components/heading-box", null, array(
		"pageIcon" => $pageIcon,
		"title" => get_the_title(get_queried_object_id()),
		"description" =>  __("Découvrez toutes nos publications et outils en ligne", "homegrade-theme__texte-fonctionnel"),
	));
	?>

	<?php /* -------
		FILTERS
 ---------------*/ ?>
	<div class="filters-toolbar filters-toolbar--archive-publications">
		<div class="filters-toolbar__posts-results-indications">
			<p class="filters-toolbar__posts-results-amount filter-disable" role="status">
				<span class="results-amount">
					<?php echo $total_posts_found ?>
				</span>
				<span class="results-text">
					<?php echo __("résultat(s)", "homegrade-theme__texte-fonctionnel"); ?>
				</span>

				<span class="results-for">
					<?php echo __("pour", "homegrade-theme__texte-fonctionnel") . " : "; ?>
				</span>
				<span class="results-filter-name">
					<?php echo __("categorie", "homegrade-theme__texte-fonctionnel"); ?>
				</span>
			</p>
			<button class="filters-toolbar__action-button--load-all" data-term-id="all" data-publication-type="all"><?php echo __("Afficher toutes les publications", "homegra-theme_texte-fonctionnel") ?></button>

		</div>


		<ul>
			<li>
				<button class="filters-toolbar__action-button" data-term-id="all" data-publication-type="all">Tous</button>
			</li>
			<li>
				<button class="filters-toolbar__action-button" data-publication-type="brochures">
					<img class="icon" src="<?php echo get_template_directory_uri() . '/resources/img/pictogrammes/pictogramme-brochures.svg' ?>" alt='' />
					<?php echo __("Brochures thématiques", "homegrade-theme__texte-fonctionnel") ?>
				</button>
			</li>
			<li>
				<button class="filters-toolbar__action-button" data-publication-type="fiches-infos">
					<img class="icon" src="<?php echo get_template_directory_uri() . '/resources/img/pictogrammes/pictogramme-fiches.svg' ?>" alt='' />
					<?php echo __("Fiches Infos", "homegrade-theme__texte-fonctionnel") ?>
				</button>
			</li>
			<li>
				<button class="filters-toolbar__action-button" data-publication-type="webinaires">
					<img class="icon" src="<?php echo get_template_directory_uri() . '/resources/img/pictogrammes/pictogramme-videos.svg' ?>" alt='' />
					<?php echo __("Vidéos & Webinaires", "homegrade-theme__texte-fonctionnel") ?>
				</button>
			</li>

		</ul>
	</div>

	<?php /* ---------
		BROCHURES 
 -----------------*/ ?>
	<section class="brochures-archives">
		<div class="section_titling section_titling--left">

			<h2 class="section_titling__title"><?php echo __("Nos Brochures thématiques", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></h2>
			<p class="section_titling__subtitle">Curabitur eleifend neque eu erat lacinia tincidunt</p>
		</div>
		<!-- HIGHLIGHTED BROCHURE -->
		<div class="highlighted-publication">

			<?php
			$highlightedBrochure = get_field('highlighted_brochure', $current_page_id) ?? null;
			$highlightedBrochurePdf = get_field('brochure_pdf', $highlightedBrochure['post']) ?? null;
			$highlightedBrochureCover = get_field('brochure_cover_image', $highlightedBrochurePdf['ID']) ?? null;
			$highlightedBrochureComment = get_field('highlighted_brochure_comment', $current_page_id) ?? null;
			?>
			<?php if ($highlightedBrochurePdf) : ?>
				<div class="highlighted-publication__infos">

					<div class="highlighted-publication__titling">
						<div class="highlighted-publication__titling__icon">
							<img src="<?php echo get_template_directory_uri() . '/resources/img/graphic-assets/house-homegrade-icon.svg' ?>" alt="">
						</div>
						<h3 class="highlighted-publication__titling__title">
							<?php echo __("Sélection de nos conseillers", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?>
						</h3>
					</div>

					<?php if ($highlightedBrochureComment) : ?>
						<p class="highlighted-publication__comment"><?php echo $highlightedBrochureComment ?></p>
					<?php endif; ?>
					<a class="cta cta--secondary cta--button" href="<?php echo $highlightedBrochurePdf['url']  ?>" target="_blank"><?php echo __("Consulter le PDF", "homegrade-theme__texte-fonctionnel__archive-publications") ?></a>
				</div>
				<?php if ($highlightedBrochureCover) : ?>
					<img class="highlighted-publication__cover" src='<?php echo $highlightedBrochureCover['sizes']['large'] ?>' />
				<?php endif; ?>


			<?php endif; ?>
		</div>

		<!-- BROCHURES GRID -->
		<ul id="brochures-rows" class="publications-grid">
			<?php
			get_template_part(
				'template-components/archives/brochure-rows',
				null,
				array(
					'brochuresPosts' => $brochuresPosts,
				)
			)
			?>
		</ul>

		<!-- LOAD MORE -->
		<button id="load-more-brochures" class="cta cta--button cta--shadowed" target="_blank"><?php echo __("Consulter plus de brochures", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></button>
		<?php wp_reset_postdata(); ?>

	</section>


	<?php /* -----------
		FICHES INFOS
 ------------------*/ ?>
	<section class="fiches-infos-archives">
		<div class="section_titling section_titling--left">
			<h2 class="section_titling__title"><?php echo __("Nos Fiches infos", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></h2>
			<p class="section_titling__subtitle">Phasellus elit turpis, viverra id porta gravida</p>
		</div>


		<ul id="fiche-infos-rows" class="publications-grid">
			<?php
			get_template_part(
				'template-components/archives/fiche-info-rows',
				null,
				array(
					'fichesInfosPosts' => $fichesInfosPosts,
				)
			)
			?>
		</ul>
		<button id="load-more-brochures" class="cta cta--button cta--shadowed" target="_blank"><?php echo __("Consulter plus de fiches infos", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></button>
		<?php wp_reset_postdata(); ?>
	</section>

	<?php /* ---------------
		VIDÉOS & WEBINAIRES
 -----------------------*/ ?>
	<section class="videos-webinaires-archives">
		<div class="section_titling section_titling--left">
			<h2 class="section_titling__title"><?php echo __("Nos vidéos et webinaires", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></h2>
			<p class="section_titling__subtitle">Phasellus elit turpis, viverra id porta gravida</p>
		</div>
		<?php
		$highlightedWebinaire = get_field('highlighted_webinaire', $current_page_id) ?? null;

		?>
		<!-- HIGHLIGHTED WEBINAIRE -->
		<div class="highlighted-publication">
			<?php if ($highlightedWebinaire) : ?>
				<div class="highlighted-publication__infos">
					<div class="highlighted-publication__titling">
						<div class="highlighted-publication__titling__icon">
							<img src="<?php echo get_template_directory_uri() . '/resources/img/graphic-assets/house-homegrade-icon.svg' ?>" alt="">
						</div>
						<h3 class="highlighted-publication__titling__title">
							<?php echo __("Sélection de nos conseillers", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?>
						</h3>
					</div>
					<?php if ($highlightedWebinaire['title']) : ?>
						<h4 class="highlighted-publication__titling__subtitle"><?php echo $highlightedWebinaire['title'] ?></h4>
					<?php endif; ?>
					<?php if ($highlightedWebinaire['commentary']) : ?>
						<p class="highlighted-publication__comment"><?php echo $highlightedWebinaire['commentary'] ?></p>
					<?php endif; ?>
					<a class="cta cta--secondary cta--button" href="<?php echo $highlightedWebinaire['url']  ?>" target="_blank"><?php echo __("Consulter la vidéo", "homegrade-theme__texte-fonctionnel__archive-publications") ?></a>
				</div>
				<?php if ($highlightedWebinaire['thumbnail']) : ?>
					<div class="highlighted-publication__thumbnail-cover">
						<img src='<?php echo $highlightedWebinaire['thumbnail']['url'] ?>' alt="<?php echo $highlightedWebinaire['thumbnail']['alt'] ?>" />
					</div>
				<?php endif; ?>
				<?php if ($highlightedWebinaire['embed']) : ?>
					<?php echo $highlightedWebinaire['embed'] ?>

				<?php endif; ?>

			<?php endif; ?>
		</div>


		<ul id="webinaires-rows" class="publications-grid publications-grid--webinaires">
			<?php
			get_template_part(
				'template-components/archives/webinaire-rows',
				null,
				array(
					'videosWebinairesDatas' => $videosWebinairesDatas,
				)
			)
			?>
		</ul>
		<button id="load-more-brochures" class="cta cta--button cta--shadowed" target="_blank"><?php echo __("Consulter plus de fiches infos", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></button>
		<?php wp_reset_postdata(); ?>
	</section>



</div>






<?php
get_footer();
