<?php

/**
 * Notifications Popup
 *
 * @package Deligraph_Homegrade
 */

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


?>

<div class="homegrade-notifications">
	<?php if ($notifications) : ?>
		<?php foreach ($notifications as $notification) : ?>
			<?php
			$notification_id = 'homegrade_notification_' . md5($notification['title'] . $notification['content']);
			$cookie_already_hidden = isset($_COOKIE[$notification_id]) && $_COOKIE[$notification_id] === 'dismissed';
			$notificationType = $notification['type'] ?? 'info';

			if (!isset($_COOKIE[$notification_id])) {
				setcookie($notification_id, "visible", time() + (86400 * 30), "/");
			}

			?>
			<div class="notification notification--<?php echo $notificationType ?> <?php echo $cookie_already_hidden ? "notification--dismissed" : "" ?> " data-notification-id="<?php echo $notification_id; ?>">
				<div class="notification__inner">

					<h3 class="notification__title"><?php echo $notification['title']; ?></h3>
					<div class="notification__content"><?php echo $notification['content']; ?></div>
					<button class="notification__close" aria-label="<?php echo __("Fermer cette notification", "homegrade-theme__texte-fonctionnel") ?>">

						<img src="<?php echo get_template_directory_uri() . '/resources/img/graphic-assets/close_submenu_icon_transparent.svg' ?>" alt="">

					</button>
				</div>


			</div>
		<?php endforeach; ?>
	<?php endif; ?>
</div>