<?php 
 $cookiesConfirmTitle = resParameter('cookiesConfirmTitle', 'home');
 ?>

<?php if($cookiesConfirmTitle != ''): ?>
 <div x-data="cookiesPolicy">
 <div class="cookie-message" x-show="messageShow" style="display:none">
 <div class="cookie-message-inner">
 <div class="cookie-message-title">
 <?php echo \htmlentities($cookiesConfirmTitle??'', ENT_QUOTES, 'UTF-8', false); ?>

 </div>

 <button class="cookie-message-details" @click="modalShow=true">
 <?php echo \htmlentities(__('site.cookies_details')??'', ENT_QUOTES, 'UTF-8', false); ?>

 </button>

 <button class="cookie-message-close" type="button" @click="messageCloseClick()">
 <svg xmlns="http://www.w3.org/2000/svg" width="33" height="39" viewBox="0 0 33 39" fill="none">
 <path d="M23.6018 9.90819L24.6164 11.1072L17.5145 19.5002L24.6164 27.8933L23.6018 29.0923L16.5 20.6993L9.39819 29.0923L8.38364 27.8933L15.4855 19.5002L8.38364 11.1072L9.39819 9.90819L16.5 18.3012L23.6018 9.90819Z" fill="#58595B"/>
 </svg>
 </button>
 </div>
 </div>

 <div class="cookie-modal" x-show="modalShow" style="display:none">
 <button class="cookie-modal-close" @click="modalShow=false">
 <svg xmlns="http://www.w3.org/2000/svg" width="33" height="39" viewBox="0 0 33 39" fill="none">
 <path d="M23.6018 9.90819L24.6164 11.1072L17.5145 19.5002L24.6164 27.8933L23.6018 29.0923L16.5 20.6993L9.39819 29.0923L8.38364 27.8933L15.4855 19.5002L8.38364 11.1072L9.39819 9.90819L16.5 18.3012L23.6018 9.90819Z" fill="#58595B"/>
 </svg>
 </button>

 <div class="cookie-modal-inner">
 <div class="cookie-modal-content">
 <?php echo resParameter('cookiesConfirmContent', 'home'); ?>

 </div>

 <div class="cookie-modal-footer">
 <div class="cookie-modal-footer-text">
 <?php echo \htmlentities(__('site.cookies_footer')??'', ENT_QUOTES, 'UTF-8', false); ?>

 </div>

 <button class="cookie-modal-button" type="button" @click="modalButtonClick()">
 <?php echo \htmlentities(__('site.cookies_clear')??'', ENT_QUOTES, 'UTF-8', false); ?>

 </button>
 </div>
 </div>
 </div>
 </div>

 <script>
 document.addEventListener('alpine:init', () => {
 Alpine.data('cookiesPolicy', () => ({
 processed: false,
 forbidden: false,
 messageShow: false,
 modalShow: false,

 init() {
 const storageValue = localStorage.getItem('cookiesPolicy');
 this.processed = storageValue === null ? false : true;
 this.messageShow = !this.processed;

 if(storageValue == 'forbidden') {
 window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
 'event': 'agree_set'
 });
 console.log('dataLayer', {'event': 'agree_set'});
 }
 },

 messageCloseClick() {
 localStorage.setItem('cookiesPolicy', 'confirm');
 this.messageShow = false;
 this.processed = true;
 },

 modalButtonClick() {
 localStorage.setItem('cookiesPolicy', 'forbidden');
 this.modalShow = false;
 this.messageShow = false;
 this.processed = true;
 },
 }))
 })
 </script>
<?php endif; ?>


