<?php

$press_kit_datas = get_field('press_kit_datas', 'option');


function getRessourceIcon($ressource_type)
{
	switch ($ressource_type) {
		case 'image/jpeg':
			return plugin_dir_url(__DIR__) . "src/img/homegrade_image.svg";

		case 'application/pdf':
			return plugin_dir_url(__DIR__) . "src/img/homegrade_fiches.svg";

		default:
			return plugin_dir_url(__DIR__) . "src/img/homegrade_fiches.svg";
	}
}

?>
<h1>sasmljkdcbsmkdjfbds</h1>
<section <?php echo get_block_wrapper_attributes(["class" => "homegrade-blocks-kit-presse"]); ?>>
	<?php echo $content; ?>

	<ul class="homegrade-blocks-kit-presse__press-grid-datas">

		<div class="table_head" aria-hidden="true">
			<p><?php echo __("Fichier", "homegrade-blocks") ?></p>
			<p><?php echo __("Format", "homegrade-blocks") ?></p>
			<p><?php echo __("Mise à jour", "homegrade-blocks") ?></p>
		</div>
		<?php foreach ($press_kit_datas as $data) : ?>
			<?php
			$ressourceType = $data['mime_type'];
			$ressourceIcon = getRessourceIcon($ressourceType);


			setlocale(LC_TIME, 'fr_FR');
			$timestamp = strtotime($data['modified']);
			$formatted_date = strftime("%B %Y", $timestamp);

			?>
			<li class="homegrade-blocks-kit-presse__press-ressource">
				<div class="homegrade-blocks-kit-presse__ressource-icon">
					<img src="<?php echo $ressourceIcon ?>" alt="">
				</div>
				<p class="homegrade-blocks-kit-presse__ressource-title"><?php echo $data['title'] ?></p>
				<p class="homegrade-blocks-kit-presse__ressource-type"><?php echo $data['subtype'] ?></p>
				<p class="homegrade-blocks-kit-presse__ressource-date"><?php echo $formatted_date ?></p>
				<a class="homegrade-blocks-kit-presse__ressource-download cta cta--secondary cta--button" href=""><?php echo __('Télécharger') ?></a>

			</li>



		<?php endforeach; ?>

	</ul>

</section>