<?php

/**
 * Display a category card layout with header, image, and metadata.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}

$category_title = $term->name;
$category_url   = aiopod_get_category_page_url( $term );   

$image = aiopod_get_image( array(     
    'term'        => $term,
    'taxonomy'    => 'aiopod_categories',
    'placeholder' => AIOPOD_PLUGIN_PLACEHOLDER_IMAGE_URL 
) );
?>
<div class="aiopod-category aiopod-responsive-wrapper" data-term_id="<?php echo esc_attr( $term->term_id ); ?>">
    <div class="aiopod-card aiopod-card--category">
        <a href="<?php echo esc_url( $category_url ); ?>" class="aiopod-card__image-wrapper aiopod-category__image-wrapper aiopod-link-unstyled" title="<?php echo esc_attr( $category_title ); ?>">
            <?php aiopod_the_image( $image ); ?>
        </a>

        <?php
        // Category content
        $category_content = '';

        // Category title
        if ( ! empty( $attributes['show_name'] ) ) {
            $category_content .= '<div class="aiopod-category__name aiopod-text-medium">';
            $category_content .= sprintf(
                '<a href="%s" class="aiopod-link-unstyled" title="%s">%s</a>',
                esc_url( $category_url ),
                esc_attr( $category_title ),
                wp_kses_post( $category_title )
            );
            $category_content .= '</div>';
        }

        // Podcasts count
        if ( ! empty( $attributes['show_count'] ) ) {
            $category_content .= '<div class="aiopod-category__meta aiopod-leading-normal aiopod-text-muted aiopod-text-small">';
            $category_content .= '<span class="aiopod-category__podcasts-count aiopod-ui-text">';
            $category_content .= '<svg xmlns="http://www.w3.org/2000/svg" fill="none" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" d="M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z" />
            </svg>';
            $category_content .= sprintf( _n( '%s podcast', '%s podcasts', $term->count, 'aio-podcast-studio' ), number_format_i18n( $term->count ) );
            $category_content .= '</span>';
            $category_content .= '</div>';
        }

        // Category description
        if ( ! empty( $attributes['show_description'] ) && ! empty( $term->description ) ) {
            $category_content .= '<div class="aiopod-category__description">';
            $category_content .= wp_kses_post( $term->description );
            $category_content .= '</div>';
        }

        // Output the category content
        if ( ! empty( $category_content ) ) {
            echo '<div class="aiopod-card__content-wrapper aiopod-category__content-wrapper">';
            echo $category_content;
            echo '</div>';
        }
        ?>
    </div>
</div>