<?php

if ( ! defined( 'ABSPATH' ) ) exit;

$gridpress_terms_class   = '';
$gridpress_likes_str     = '';
$gridpress_views_str     = '';
$gridpress_behance_url   = '';
$gridpress_author_img_url = '';
$gridpress_author_url    = '';

if ( isset($gridpress_card_data['type']) && $gridpress_card_data['type'] === 'post' ) {

    $gridpress_author_img_url = get_avatar_url(
        $gridpress_card_data['author_id'],
        ['size' => 62]
    );

    $gridpress_author_url = get_author_posts_url(
        $gridpress_card_data['author_id']
    );

    if ( ! empty($gridpress_display_settings['top_filter_tax']) ) {

        $gridpress_taxonomy = $gridpress_display_settings['top_filter_tax'];

        $gridpress_tax_terms = wp_get_post_terms(
            $gridpress_card_data['id'],
            $gridpress_taxonomy
        );

        $gridpress_terms_class = apply_filters(
            'gridpress_card_item_term_classes',
            $gridpress_terms_class,
            $gridpress_taxonomy,
            $gridpress_card_data['id']
        );
    }

} else {

    $gridpress_author_img_url = '';

    if ( ! empty($gridpress_card_data['author_image_attach_id']) ) {
        $gridpress_author_img_url = wp_get_attachment_image_url(
            $gridpress_card_data['author_image_attach_id'],
            'thumbnail'
        );
    }

    $gridpress_author_url = 'javascript:;';
    $gridpress_terms_str   = $gridpress_card_data['category'] ?? '';

    $gridpress_likes_str   = $gridpress_card_data['item_likes'] ?? '';
    $gridpress_views_str   = $gridpress_card_data['item_views'] ?? '';
    $gridpress_behance_url = $gridpress_card_data['behance_url'] ?? '';
}

$gridpress_large_class = ( isset($gridpress_card_counter) && $gridpress_card_counter > 2 )
    ? ''
    : ' large';

$gridpress_class = 'jc-cards' . $gridpress_terms_class . $gridpress_large_class;
?>
<div class="<?php echo esc_attr( $gridpress_class ); ?>">

    <div class="jc-cards-image">
        <?php
        $gridpress_card_url   = isset( $gridpress_card_data['url'] ) ? (string) $gridpress_card_data['url'] : '';
        $gridpress_image_url  = isset( $gridpress_card_data['imag_url'] ) ? (string) $gridpress_card_data['imag_url'] : '';
        $gridpress_card_title = isset( $gridpress_card_data['title'] ) ? (string) $gridpress_card_data['title'] : '';
        ?>
        <a class="jc-cards-image-wrap"
            href="<?php echo esc_url( $gridpress_card_url ); ?>">
            <img src="<?php echo esc_url( $gridpress_image_url ); ?>" alt="<?php echo esc_attr( $gridpress_card_title ); ?>"/>
        </a>
    </div>

    <div class="jc-cards-textbox">

        <ul class="jc-cards-meta">

            <?php if ( ! empty($gridpress_card_data['author']) && ($gridpress_display_settings['show_author'] ?? '') === 'on' ) : ?>
                <li>
                    <img class="jc-cards-avatar"
                         src="<?php echo esc_url($gridpress_author_img_url); ?>"
                         alt="<?php echo esc_attr($gridpress_card_data['author']); ?>">

                    <a href="<?php echo esc_url($gridpress_author_url); ?>">
                        <?php echo esc_html($gridpress_card_data['author']); ?>
                    </a>
                </li>
            <?php endif; ?>

            <?php if ( ! empty($gridpress_views_str) ) : ?>
                <li>
                    <img class="jc-cards-icon"
                         src="<?php echo esc_url(GRIDPRESS_URL); ?>images/eye-black.svg"
                         alt="<?php echo esc_attr__('Views', 'gridpress-grid-layout-design'); ?>">
                    <span><?php echo absint($gridpress_views_str); ?></span>
                </li>
            <?php endif; ?>

            <?php if ( ! empty($gridpress_likes_str) ) : ?>
                <li>
                    <img class="jc-cards-icon"
                         src="<?php echo esc_url(GRIDPRESS_URL); ?>images/likes.svg"
                         alt="<?php echo esc_attr__('Likes', 'gridpress-grid-layout-design'); ?>">
                    <span><?php echo absint($gridpress_likes_str); ?></span>
                </li>
            <?php endif; ?>

        </ul>

        <?php if ( ! empty($gridpress_behance_url) ) : ?>
            <div class="jc-cards-logo">
                <a href="<?php echo esc_url($gridpress_behance_url); ?>">
                    <img src="<?php echo esc_url(GRIDPRESS_URL); ?>images/behance.svg"
                         alt="<?php echo esc_attr__('Behance', 'gridpress-grid-layout-design'); ?>"
                         title="<?php echo esc_attr__('Behance', 'gridpress-grid-layout-design'); ?>">
                </a>
            </div>
        <?php endif; ?>

    </div>
</div>