<?php

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

$newsnation_default = newsnation_get_default_theme_options();
$newsnation_archive_layout = esc_attr(get_theme_mod('newsnation_archive_layout', $newsnation_default['newsnation_archive_layout']));
$global_sidebar_layout = esc_attr(get_theme_mod('global_sidebar_layout', $newsnation_default['global_sidebar_layout']));
$title_size = 'large';

if ($newsnation_archive_layout == 'default') {

    $image_size = 'medium';
    $title_size = 'big';
} elseif ($newsnation_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
        $newsnation_default = newsnation_get_default_theme_options();
        $newsnation_archive_layout = get_theme_mod('newsnation_archive_layout', $newsnation_default['newsnation_archive_layout']);



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

        if ($newsnation_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 = newsnation_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 newsnation_entry_footer($cats = true, $tags = false, $edits = false, $text = false, $icon = false); ?>

                    </div>

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

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

            </header>

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


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

                </div>

            <?php } ?>

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

                    the_excerpt();
                } else {

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

            </div>



        </div>

    </article>
</div>