<?php
/**
 * Post header template: Post header template with image and details
 */

// Transparent header
$blog_post_transparent_header = get_theme_mod('blog_post_transparent_header', false);

// Blog post header layout
$post_header_layout = get_post_meta( get_the_ID(), '_cookandmeal_post_header_layout', true );

// Post header layout
if(empty($post_header_layout)) {
    $blog_post_header_layout = get_theme_mod('blog_post_header_layout', 'inheader');
} else {
    $blog_post_header_layout = $post_header_layout;
}

// Allow transparent header only for 'inheader' layout
if($blog_post_header_layout !== 'inheader') {
    $blog_post_transparent_header = false;
}

// Header image - uploaded
if(get_theme_mod('blog_post_header_image_type', 'header') == 'header') {
    $header_background_image = get_post_meta( get_the_ID(), '_cookandmeal_header_image', true );
} else {
// Header image - thumb
    $header_background_image_data = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'cookandmeal-blog-thumb');
    $header_background_image = $header_background_image_data[0];
}

$header_parallax = get_post_meta( get_the_ID(), '_cookandmeal_header_parallax', true );

if(isset($header_background_image) && ($header_background_image !== '')) {
    $header_background_image_style = 'background-image: url('.$header_background_image.');';
    $header_background_class = ' with-bg';

    if($header_parallax) {
        $header_background_class .= ' cookandmeal-parallax';
    }

} else {
    $header_background_image_style = '';
    $header_background_class = ' without-bg';
}

// Header width
$post_header_width = get_post_meta( get_the_ID(), '_cookandmeal_post_header_width', true );

if(!empty($post_header_width)) {
    $blog_post_header_width = $post_header_width;
} else {
    $blog_post_header_width = get_theme_mod('blog_post_header_width', 'boxed');
}

// Blog post header width
if($blog_post_header_width == 'fullwidth') {
    $container_class = 'container-fluid';
} else {
    $container_class = 'container';
}

// Don't allow boxed header for transparent header
if($header_background_class !== ' without-bg' && $blog_post_transparent_header) {
    $container_class = 'container-fluid';
}

?>
<div class="<?php echo esc_attr($container_class); ?> container-page-item-title<?php echo esc_attr($header_background_class); ?>" data-style="<?php echo esc_attr($header_background_image_style); ?>" data-speed="0.1">
    <?php
    if(get_theme_mod('blog_post_review', true)) {
        do_action('cookandmeal_post_review_rating'); // this action called from plugin
    }
    ?>
    <div class="row">
        <div class="col-md-12 col-overlay">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-item-title-single">
                            <?php
                            $categories_list = cookandmeal_get_the_category_list();
                            ?>
                            <div class="cookandmeal-post-single cookandmeal-post">
                                <div class="post-categories"><?php echo wp_kses($categories_list, cookandmeal_esc_data()); ?></div>
                                <div class="cookandmeal-post-details">

                                    <h1 class="post-title entry-title"><?php the_title(); ?></h1>
                                    <?php
                                    if(get_theme_mod('blog_posts_author', false)):
                                    ?>
                                    <div class="post-author">
                                        <span class="vcard">
                                            <?php echo esc_html__('By', 'cookandmeal'); ?> <span class="fn"><?php echo get_the_author_posts_link(); ?></span>
                                        </span>
                                    </div>
                                    <div class="post-info-dot"></div>
                                    <?php endif; ?>
                                    <div class="post-date"><?php echo cookandmeal_get_post_date(); ?></div>
                                    <?php if(get_theme_mod('blog_post_read_time', true)): ?>
                                    <div class="post-info-dot"></div>
                                    <div class="post-read-time"><?php echo cookandmeal_get_post_read_time($post->ID); ?></div>
                                    <?php endif; ?>
                                    <?php
                                    // Post details bottom
                                    get_template_part( 'inc/templates/part/post-details-single-bottom-inline' );
                                    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
