<?php

/**
 * The default template for displaying content
 *
 * Used for both singular and index.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Vintuna
 * @since 1.0.0
 */

$vintuna_default = vintuna_get_default_theme_options();
$vintuna_archive_layout = esc_attr(get_theme_mod('vintuna_archive_layout', $vintuna_default['vintuna_archive_layout']));
$global_sidebar_layout = esc_attr(get_theme_mod('global_sidebar_layout', $vintuna_default['global_sidebar_layout']));
$title_size = 'large';

if ($vintuna_archive_layout == 'default') {

    $image_size = 'medium';
    $title_size = 'big';
} elseif ($vintuna_archive_layout == 'masonry') {

    $image_size = 'medium_large';
    $title_size = 'medium';
} else {

    if ($global_sidebar_layout == 'no-sidebar') {
        $image_size = 'full';
    } else {
        $image_size = 'large';
    }
} ?>

<div class="theme-article-area">
    <article id="post-<?php the_ID(); ?>" <?php post_class('news-article'); ?>>

        <?php
        $vintuna_default = vintuna_get_default_theme_options();
        $vintuna_archive_layout = get_theme_mod('vintuna_archive_layout', $vintuna_default['vintuna_archive_layout']);



        $bg_size = 'entry-image-medium';
        if ($vintuna_archive_layout == 'full') {
            $bg_size = 'entry-image-large';
        }

        if ($vintuna_archive_layout == 'masonry') {
            $image_classes = ['entry-image-large', 'entry-image-big', 'entry-image-medium'];
            $bg_size = $image_classes[array_rand($image_classes)];
        }


        ?>


        <?php
        $fallback_image_url = vintuna_get_fallback_image_url();
        if (has_post_thumbnail() || $fallback_image_url) : ?>
            <div class="entry-image image-hover-effect hover-effect-shine <?php echo esc_attr($bg_size); ?>">
                <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                    <?php
                    if (has_post_thumbnail()) {
                        the_post_thumbnail('large', [
                            'alt' => the_title_attribute(['echo' => false]),
                        ]);
                    } else {
                        echo '<img src="' . esc_url($fallback_image_url) . '" alt="' . esc_attr(get_the_title()) . '" />';
                    }
                    ?>
                </a>
            </div>
        <?php endif; ?>

        <div class="post-content">

            <header class="entry-header">

                <?php
                if (!is_search() && 'post' === get_post_type()) { ?>

                    <div class="entry-meta">

                        <?php vintuna_entry_footer($cats = true, $tags = false, $edits = false, $text = false, $icon = false); ?>

                    </div>

                <?php  } ?>
                <h2 class="entry-title entry-title-<?php echo $title_size; ?> line-clamp-2">

                    <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                </h2>

            </header>



            <div class="entry-content entry-content-muted line-clamp-2">
                <?php
                if (has_excerpt()) {

                    the_excerpt();
                } else {

                    echo '<p>';
                    echo esc_html(wp_trim_words(get_the_content(), 20, '...'));
                    echo '</p>';
                } ?>

            </div>

            <?php if (!is_search()) { ?>


                <div class="entry-footer">
                    <div class="entry-meta">
                        <?php vintuna_posted_by(); ?>
                    </div>

                </div>

            <?php } ?>

        </div>

    </article>
</div>