<?php
    $footer_logo                = get_field('footer_logo', 'option');

    $social_facebook            = get_field('social_facebook', 'option');
    $social_instagram           = get_field('social_instagram', 'option');
    $social_youtube             = get_field('social_youtube', 'option');
    $social_linkedin            = get_field('social_linkedin', 'option');

    $footer_contact_title       = get_field('footer_contact_title', 'option');
    $footer_number              = get_field('footer_number', 'option');
    $footer_email               = get_field('footer_email', 'option');

    $footer_address_title       = get_field('footer_address_title', 'option');
    $footer_address             = get_field('footer_address', 'option');
?>

<footer>
    <div class="wrapper">
        <a class="logo">
            <img src="<?php echo get_field('footer_logo', 'option')['url']; ?>" alt="<?php echo get_field('footer_logo', 'option')['url']; ?>">
        </a>
        <?php
        if ($footer_number || $footer_email) :
        ?>
            <div class="contact item">
                <div class="title">
                    <?php echo $footer_contact_title; ?>
                </div>
                <a href="tel:<?php echo $footer_number; ?>" class="text">
                    <svg>
                        <use xlink:href="#phone"></use>
                    </svg>
                    <?php echo $footer_number; ?>
                </a>
                <a href="mailto:<?php echo $footer_email; ?>" class="text">
                    <svg>
                        <use xlink:href="#email"></use>
                    </svg>
                    <?php echo $footer_email; ?>
                </a>
            </div>
        <?php
        endif;
        if ($footer_address) :
        ?>
            <div class="address item">
                <div class="title">
                    <?php echo $footer_address_title; ?>
                </div>
                <div class="text">
                    <?php echo $footer_address; ?>
                </div>
            </div>
        <?php
        endif;
        ?>
        <div class="footer-menu">
            <?php
                wp_nav_menu(array(
                    'menu_class' => 'sm sm-simple',
                    'menu_id' => 'footer-menu',
                    'container' => '',
                    'theme_location' => 'footer_menu'
                ));
            ?>
        </div>
        <div class="social">
            <?php if ($social_linkedin || $social_instagram || $social_facebook || $social_youtube) : ?>
                <div class="footer-social">
                    <ul class="social-links">
                        <?php if ($social_linkedin) : ?>
                            <li>
                                <a href="<?php echo $social_linkedin; ?>" target="_blank">
                                    <svg>
                                        <use xlink:href="#linkedin"></use>
                                    </svg>
                                </a>
                            </li>
                        <?php endif; ?>
                        <?php if ($social_instagram) : ?>
                            <li>
                                <a href="<?php echo $social_instagram; ?>" target="_blank">
                                    <svg>
                                        <use xlink:href="#insta"></use>
                                    </svg>
                                </a>
                            </li>
                        <?php endif; ?>
                        <?php if ($social_facebook) : ?>
                            <li>
                                <a href="<?php echo $social_facebook; ?>" target="_blank">
                                    <svg>
                                        <use xlink:href="#fb"></use>
                                    </svg>
                                </a>
                            </li>
                        <?php endif; ?>
                        <?php if ($social_youtube) : ?>
                            <li>
                                <a href="<?php echo $social_youtube; ?>" target="_blank">
                                    <svg>
                                        <use xlink:href="#yt"></use>
                                    </svg>
                                </a>
                            </li>
                        <?php endif; ?>
                    </ul>
                </div>
            <?php endif; ?>
        </div>
    </div>
</footer>

<?php include dirname(__FILE__) . '/inc/inc-svg.php'; ?>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Playfair+Display:wght@400;700&display=swap" rel="stylesheet">
<?php if ( is_front_page() ) : ?>
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/sass/home.min.css">
<?php else : ?>
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/sass/style.min.css">
<?php endif; ?>
<script src="<?php echo get_template_directory_uri(); ?>/js/libraries.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/scripts.min.js"></script>
<script>
    refresh_handler = function(e) {
        var elements = document.querySelectorAll("*[data-src]");
        for (var i = 0; i < elements.length; i++) {
            var elementType = elements[i].localName;
            var boundingClientRect = elements[i].getBoundingClientRect();
            if (elements[i].hasAttribute("data-src") && boundingClientRect.top < window.innerHeight) {
                if (elementType == 'img'){
                    elements[i].setAttribute("src", elements[i].getAttribute("data-src"));
                }else{
                    elements[i].setAttribute("srcset", elements[i].getAttribute("data-src"));
                }
                elements[i].removeAttribute("data-src");
            }
        }
    };

    window.addEventListener('scroll', refresh_handler);
    window.addEventListener('load', refresh_handler);
    window.addEventListener('resize', refresh_handler);
    window.addEventListener('load', function() {
		pageRelatedCss('https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css?ver=5.2.2');
	})

    function pageRelatedCss(filename){
		// Create new link Element 
		var link = document.createElement('link');  
	
		// set the attributes for link element 
		link.rel = 'stylesheet';  
	
		link.type = 'text/css'; 
	
		link.href = filename;  

		// Get HTML head element to append  

		// link element to it  
		document.getElementsByTagName('HEAD')[0].appendChild(link);  
	}
</script>
<script>
    var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
</script>
<?php wp_footer(); ?>
<?php get_tracking_codes('footer'); ?>
</body>
</html>
