<?php
/**
 * The template for displaying the footer
 *
 * Contains the closing of the #content div and all content after.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Glowify WP
 */

if(is_page() && get_post_meta($post->ID, 'header_meta', true)) {
    $header_meta = get_post_meta($post->ID, 'header_meta', true);
} else {
    $header_meta = array();
}

$enable_footer = glowify_wp_option('enable_footer');
$image_logo = glowify_wp_option('image_logo');
$image_logo_max_height = glowify_wp_option('image_logo_max_height');
$text_logo = glowify_wp_option('text_logo');
$footer_copyright_text = glowify_wp_option('footer_copyright_text');
$footer_bg_default = glowify_wp_option('footer_bg_default');
if($footer_bg_default) {
    $footer_bg_default_image_src = wp_get_attachment_image_src($footer_bg_default['id'], 'full', false);
}

$footer_style = glowify_wp_option('footer_style');
$default_footer_style = glowify_wp_option('footer_style');

if(array_key_exists('page_footer', $header_meta) && $header_meta['page_footer'] != 'default') {
    $footer_style = $header_meta['page_footer'];
} elseif(!empty($default_footer_style)) {
    $footer_style = glowify_wp_option('footer_style');
} else {
    $footer_style = '1';
}

if(is_page() && get_post_meta($post->ID, 'glowify_wp_page_options', true)) {
    $header_meta = get_post_meta($post->ID, 'glowify_wp_page_options', true);
} else {
    $header_meta = array();
}
?>

</main>

<?php if(class_exists('CSF')) :?>
    <?php if($enable_footer) : ?>
        <footer class="cs_footer cs_footer footer cs_primary_bg cs_ternary_color">
			<?php if(is_active_sidebar('glowify-footer-1')) : ?>
            <div class="cs_footer_main">
                <div class="container">
                    <div class="cs_footer_row">
						<?php if(is_active_sidebar('glowify-footer-1')) : ?>
                        <div class="cs_footer_col">
                            <?php dynamic_sidebar('glowify-footer-1'); ?>
                        </div>
                        <?php endif; ?>
						<?php if(is_active_sidebar('glowify-footer-2')) : ?>
                        <div class="cs_footer_col">
                            <?php dynamic_sidebar('glowify-footer-2'); ?>
                        </div>
                        <?php endif; ?>
                        <?php if(is_active_sidebar('glowify-footer-3')) : ?>
                        <div class="cs_footer_col">
                            <?php dynamic_sidebar('glowify-footer-3'); ?>
                        </div>
                        <?php endif; ?>
                        <?php if(is_active_sidebar('glowify-footer-4')) : ?>
                        <div class="cs_footer_col">
                            <?php dynamic_sidebar('glowify-footer-4'); ?>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
			<?php endif;?>
            <div class="cs_bottom_footer_wrap cs_heading_bg cs_white_color">
                <div class="container">
                    <div class="cs_bottom_footer position-relative cs_copyright cs_footer_bottom_in">
						<?php if(!empty($footer_copyright_text)) : ?>
							<?php echo wp_kses_post($footer_copyright_text); ?>
						<?php else :?>
							<?php esc_html_e('&copy; Glowify. All Right Reserved', 'glowify-wp'); ?>
						<?php endif;?>
                    </div>
                </div>
            </div>
        </footer>
    <?php endif;?>
	<?php else :?>
        <div class="cs_bottom_footer_wrap cs_heading_bg cs_white_color cs_bottom_default">
            <div class="container">
                <div class="cs_bottom_footer position-relative cs_copyright cs_footer_bottom_in">
                    <?php esc_html_e('&copy; Glowify. All Right Reserved', 'glowify-wp'); ?>
                </div>
            </div>
        </div>
	<?php endif;?>

<?php wp_footer(); ?>
</body>
</html>
