<?php
/**
 * @package Bravisthemes
 */
$archive_readmore_text = kaitex()->get_theme_opt('archive_readmore_text', esc_html__('Read More', 'kaitex'));
$archive_excerpt_on = kaitex()->get_theme_opt('archive_excerpts', true);
$archive_excerpt = get_the_excerpt($post->ID);
$archive_date = kaitex()->get_theme_opt( 'archive_date', true );
$post_format = get_post_format($post->ID);
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('pxl-item--archive'); ?>>
    <div class="item--inner">
        <?php if ($post_format == false && has_post_thumbnail()) {
            echo '<div class="item--featured">'; ?>
            <a href="<?php echo esc_url( get_permalink()); ?>"><?php the_post_thumbnail('kaitex-thumb-medium'); ?></a>
            <?php echo '</div>';
        } else if ($post_format == 'video' ) {
            $video_url = get_post_meta($post->ID, 'video_url', true);
            $video_thumbnail = get_post_meta($post->ID, 'video_thumbnail', true);
            if (!empty($video_url) || !empty($video_thumbnail)) { ?>
                <div class="pxl-post--video">
                    <?php $image_id = attachment_url_to_postid($video_thumbnail);
                        if (!$image_id) {
                            $attachment_id = pxl_upload_external_image($video_thumbnail);
                            if ($attachment_id) {
                                update_post_meta($post->ID, 'video_thumbnail', wp_get_attachment_url($attachment_id));
                                $video_thumbnail = get_post_meta($post->ID, 'video_thumbnail', true);
                                $image_id = attachment_url_to_postid($video_thumbnail);
                                $img = pxl_get_image_by_size( array(
                                    'attach_id'  => $image_id,
                                    'thumb_size' => 'kaitex-thumb-medium',
                                    'class' => 'no-lazyload'
                                ) );
                                $thumbnail = $img['thumbnail'];
                                echo '<div class="pxl-video--image">';
                                echo wp_kses_post($thumbnail);
                                echo '</div>';
                            }
                        } elseif ($image_id) {
                        $img = pxl_get_image_by_size( array(
                            'attach_id'  => $image_id,
                            'thumb_size' => 'kaitex-thumb-medium',
                            'class' => 'no-lazyload'
                        ) );
                        $thumbnail = $img['thumbnail'];
                        echo '<div class="pxl-video--image">';
                        echo wp_kses_post($thumbnail);
                        echo '</div>';
                    }
                    ?>
                    <?php if(!empty($video_url)) : ?>
                        <a class="btn-video" href="<?php echo esc_url($video_url); ?>">
                            <i class="ion-ios-play"></i>
                        </a>
                    <?php endif; ?>
                </div>
            <?php }
        } ?>
        <div class="item--content">
            <?php kaitex()->blog->get_archive_meta(); ?>
            <h4 class="item--title">
                <a href="<?php echo esc_url( get_permalink()); ?>" title="<?php the_title_attribute(); ?>">
                    <?php if(is_sticky()) { ?>
                        <i class="caseicon-check-mark"></i>
                    <?php } ?>
                    <?php the_title(); ?>
                </a>
            </h4>
            <?php if($archive_excerpt_on && !empty($archive_excerpt)): ?>
                <div class="item--excerpt">
                    <?php
                    kaitex()->blog->get_excerpt();
                    wp_link_pages( array(
                        'before'      => '<div class="page-links">',
                        'after'       => '</div>',
                        'link_before' => '<span>',
                        'link_after'  => '</span>',
                    ) );
                    ?>
                </div>
            <?php endif; ?>
            <div class="item--footer">
                <a class="item--button btn-default style2" href="<?php echo esc_url( get_permalink()); ?>">
                    <span class="btn-text">
                        <?php echo kaitex_html($archive_readmore_text); ?>
                    </span>
                </a>
                <?php if($archive_date) : ?>
                    <div class="item--date"><?php echo date_i18n('d/M', strtotime(get_the_date())); ?></div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</article>