<?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,
	// 'posts_per_page' => -1,
	'post_status' => 'publish',
	'order' => 'DESC',
	'orderby' => 'date',
	'meta_key'      => 'brochure_pdf',
	'meta_value' => '',
	'meta_compare' => '!=',
);
$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' => '!=',
);
$fichesInfosPosts = new WP_Query($args);


// #### WEBINAIRES QUERY
$args = array(
	'post_type' => 'videos-webinaires',
	'posts_per_page' => -1,
	'post_status' => 'publish',
	'order' => 'DESC',
	'meta_key' => 'video_publication_date',
	'orderby' => 'meta_value_num',
);
$videosWebinairesPosts = new WP_Query($args);

$total_posts_found = $brochuresPosts->found_posts + $fichesInfosPosts->found_posts + $videosWebinairesPosts->found_posts;

?>
<div class="template-archives template-archives--publications">
	<?php /* ------------
		BREADCRUMB
 		-----------------*/ ?>
	<nav class=" breadcrumbs_navigation" aria-label="<?php echo __("Vous êtes ici", "homegrade-theme__texte-fonctionnel") ?>">
		<ol>
			<li>
				<a href="<?php echo home_url() ?>" title="<?php echo __("Accueil", "homegrade-theme__texte-fonctionnel") ?>">
					<img src="<?php echo get_template_directory_uri() . "/resources/img/pictogrammes/icon_house_dark.svg" ?>" alt="">
				</a>
			</li>
			<li><a href="<?php echo get_post_type_archive_link('brochures') ?>" aria-current='location' aria-disabled="true">Publications</a></li>

		</ol>
	</nav>


	<?php /* ---------
		HEADING BOX
 -----------------*/ ?>
	<?php

	$receivePrintedPublicationsDatas = get_field('section_share_publications', $current_page_id) ?? null;
	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" active-publication-type="all">
		<!-- RESULTS INDICATIONS -->
		<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", "homegrade-theme_texte-fonctionnel") ?></button>

		</div>

		<!-- FILTERS (PUBLICATIONS & THEMATIQUES) -->
		<div class="filters-toolbar__filters-container">
			<!-- PUBLICATIONS TYPES FILTERS -->
			<ul class="publication-type-filters-wrapper">
				<li>
					<button class="filters-toolbar__action-button filters-toolbar__action-button--active" data-term-id="all" data-publication-type="all" aria-pressed="true"><?php echo __("Tous", "homegrade-theme_texte-fonctionnel") ?></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 Info", "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>

			<!-- THEMATIQUES FILTERS -->
			<div class="action-thematiques-filters-wrapper">
				<?php
				$thematiques = get_terms(array(
					'taxonomy'   => 'thematiques',
					'hide_empty' => true,
					'parent' => 0,
				));

				?>
				<div class="filters-toolbar__action-thematiques-filters">
					<button class="filter-by-thematiques-submenu-toggle" aria-expanded="false"><?php echo __("Filtrer par thématique", "homegrade-theme__texte-fonctionnel") ?></button>
					<ul class="action-thematiques-filters-list" hidden aria-hidden>
						<li>
							<input class="filters-toolbar__action-thematiques-filter--show-all" type="checkbox" id="all" name="all" value="all" checked>
							<label for="all"><?php echo __("Tous", "homegrade-theme__texte-fonctionnel")  ?></label>
						</li>

						<?php foreach ($thematiques as $thematique) : ?>
							<li>
								<input class="filters-toolbar__action-thematiques-filter" type="checkbox" id="<?php echo $thematique->slug ?>" name="<?php echo $thematique->slug ?>" value="<?php echo $thematique->term_id ?>" data-title="<?php echo $thematique->name ?>">
								<label for="<?php echo $thematique->slug ?>"><?php echo $thematique->name ?></label>
							</li>
						<?php endforeach; ?>
					</ul>
				</div>
			</div>
		</div>

		<!-- ACTIVE FILTERS VIEWER -->
		<div class="filters-toolbar__active-filters-viewer">
			<div class="active-filters-button-container">
			</div>
			<button class="filters-toolbar__action-button--reset-filter cta cta--button cta--outline" hidden><?php echo __("Réinitialiser le filtre ", "homegrade-theme__texte-fonctionnel") ?></button>
		</div>


	</div>

	<?php /* ---------------
		HIGHLIGHTED BROCHURE
 -----------------------*/ ?>
	<div id="highlighted-document" class="highlighted-publication">
		<?php
		$highlightedDocumentDatas = get_field('highlighted_document', $current_page_id) ?? null;
		$documentThumbnail = get_field('brochure_cover_image', $highlightedDocumentDatas['document']['ID']);

		?>
		<?php if ($highlightedDocumentDatas) : ?>

			<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 $highlightedDocumentDatas['highlight_title'] ?>
					</h3>
				</div>

				<?php if ($highlightedDocumentDatas['commentary']) : ?>
					<div class="highlighted-publication__comment"><?php echo $highlightedDocumentDatas['commentary'] ?></div>
				<?php endif; ?>
				<?php if ($highlightedDocumentDatas['document']) : ?>
					<a class="cta cta--secondary cta--button" href="<?php echo $highlightedDocumentDatas['document']['url']  ?>" target="_blank"><?php echo __("Consulter le PDF", "homegrade-theme__texte-fonctionnel__archive-publications") ?></a>
				<?php endif; ?>
			</div>
			<img class="highlighted-publication__cover" src='<?php echo $highlightedDocumentDatas['cover']['url'] ?>' alt="<?php echo $highlightedDocumentDatas['cover']['alt'] ?>" />


		<?php endif; ?>
	</div>

	<?php /* ---------
		BROCHURES 
 -----------------*/ ?>
	<section class="brochures-archives">
		<div class="section_titling section_titling--left">
			<?php
			$sectionBrochureDatas = get_field('section_brochure_datas', $current_page_id);
			?>
			<h2 class="section_titling__title"><?php echo $sectionBrochureDatas['title'] ?></h2>
			<p class="section_titling__subtitle"><?php echo $sectionBrochureDatas['subtitle'] ?></p>
		</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--outline cta--button cta--centered cta--load-more" data-publication-type="brochures"><?php echo __("Consulter plus de brochures", "homegrade-theme__texte-fonctionnel__publications-archive-brochures") ?></button>
		<?php wp_reset_postdata(); ?>

		<?php
		$sharePublications = get_field('section_share_publications', $current_page_id);
		?>
	</section>


	<?php
	/* -------------------------
		DISTRIBUEZ PUBLICATIONS
 	-----------------------------*/
	?>
	<?php
	$receivePrintedPublicationsDatas['order_form_url'] ?? null
	?>
	<section class="distribuez-publications wp-block-homegrade-content-blocks-highlight homegrade-blocks-highlight homegrade-blocks-highlight--classic homegrade-blocks-highlight--has-illustration">

		<div class="homegrade-blocks-highlight--has-illustration__content">
			<div class="homegrade-blocks-highlight__titling ">
				<div class="icon"><img decoding="async" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNi4wMTIiIGhlaWdodD0iMTUuOTk5IiB2aWV3Qm94PSIwIDAgMTYuMDEyIDE1Ljk5OSI+CiAgPGcgaWQ9Ikljb25fZmVhdGhlci1saW5rIiBkYXRhLW5hbWU9Ikljb24gZmVhdGhlci1saW5rIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMS45OTMgLTIuMDA3KSI+CiAgICA8cGF0aCBpZD0iVHJhY8OpXzE4NTU5IiBkYXRhLW5hbWU9IlRyYWPDqSAxODU1OSIgZD0iTTE1LDEwLjcwN2EzLjUsMy41LDAsMCwwLDUuMjguMzc4bDIuMS0yLjFBMy41LDMuNSwwLDEsMCwxNy40Myw0LjAzM2wtMS4yLDEuMiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTYuNDAyIDApIiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIyIi8+CiAgICA8cGF0aCBpZD0iVHJhY8OpXzE4NTYwIiBkYXRhLW5hbWU9IlRyYWPDqSAxODU2MCIgZD0iTTExLjQsMTQuOWEzLjUsMy41LDAsMCwwLTUuMjgtLjM3OGwtMi4xLDIuMUEzLjUsMy41LDAsMSwwLDguOTcsMjEuNTdsMS4yLTEuMiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCAtNS41OSkiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjIiLz4KICA8L2c+Cjwvc3ZnPgo=" alt=""></div>
				<h3 class="homegrade-blocks-highlight__block-title"><?php echo $receivePrintedPublicationsDatas['title'] ?></h3>
			</div>

			<div class="homegrade-blocks-highlight__content__innerblocks">
				<p><?php echo $receivePrintedPublicationsDatas['description'] ?></p>
				<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="<?php echo $receivePrintedPublicationsDatas['order_form_url']  ?>" target="_blank" rel="noreferrer noopener"><?php echo $receivePrintedPublicationsDatas['cta_title'] ?></a></div>
			</div>
		</div>

		<img class="homegrade-blocks-highlight--has-illustration__illustration" decoding="async" src="<?php echo get_template_directory_uri() . "/resources/img/illustrations/homegrade_brochure-impression-domicile.svg" ?>" alt="">


	</section>



	<?php /* -----------
		FICHES INFOS
 ------------------*/ ?>
	<section class="fiches-infos-archives">
		<div class="section_titling section_titling--left">
			<?php
			$sectionFichesInfosDatas = get_field('section_fiches_infos_datas', $current_page_id);
			?>
			<h2 class="section_titling__title"><?php echo $sectionFichesInfosDatas['title'] ?></h2>
			<p class="section_titling__subtitle"><?php echo $sectionFichesInfosDatas['subtitle'] ?></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--outline cta--button cta--centered cta--load-more" data-publication-type="fiches-infos"><?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">
			<?php
			$sectionWebinairesDatas = get_field('section_webinaires_datas', $current_page_id);
			?>
			<h2 class="section_titling__title"><?php echo $sectionWebinairesDatas['title'] ?></h2>
			<p class="section_titling__subtitle"><?php echo $sectionWebinairesDatas['subtitle'] ?></p>
		</div>
		<?php
		$highlightedWebinaire = get_field('highlighted_webinaire', $current_page_id) ?? null;
		$webinaireThumbnail = get_the_post_thumbnail_url($highlightedWebinaire->ID);
		$webinaireEmbed = get_field('embed', $highlightedWebinaire->ID);
		$highlightedWebinaireUrl = get_field('url', $highlightedWebinaire->ID);

		?>
		<!-- 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>
					<h4 class="highlighted-publication__titling__subtitle"><?php echo $highlightedWebinaire->post_title ?></h4>

					<p class="highlighted-publication__comment"><?php echo get_the_excerpt($highlightedWebinaire->ID) ?></p>
					<a class="cta cta--secondary cta--button" href="<?php echo $highlightedWebinaireUrl ?>" target="_blank"><?php echo __("Consulter la vidéo", "homegrade-theme__texte-fonctionnel__archive-publications") ?></a>
				</div>

				<?php if ($webinaireEmbed) : ?>
					<?php echo $webinaireEmbed ?>

				<?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(
					'videosWebinairesPosts' => $videosWebinairesPosts,
				)
			)
			?>
		</ul>
		<!-- <button id="load-more-brochures" class="cta cta--button cta--outline cta--button cta--centered cta--load-more" 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();
