<?php
/**
 * Template part for displaying featured post on blog page.
 *
 * @package pawwell
 */

$categories = get_the_category();
$category   = ! empty( $categories ) ? $categories[0] : null;
$reading_time = pawwell_estimated_reading_time( get_the_content() );
$author_id    = get_the_author_meta( 'ID' );
$author_name  = get_the_author_meta( 'display_name' );
$author_initial = $author_name ? strtoupper( substr( $author_name, 0, 1 ) ) : 'P';
?>

<article class="featured-post">
    <div class="featured-post-grid">
        <div class="featured-image">
            <span class="featured-badge"><?php esc_html_e( 'Featured', 'pawwell' ); ?></span>
            <?php if ( has_post_thumbnail() ) : ?>
                <?php the_post_thumbnail( 'large', array( 'class' => 'featured-image-img', 'alt' => esc_attr( get_the_title() ) ) ); ?>
            <?php else : ?>
                <div class="featured-image-placeholder"></div>
            <?php endif; ?>
        </div>
        <div class="featured-body">
            <?php if ( $category ) : ?>
            <div class="featured-cat">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 7a2 2 0 0 1 2-2h3.2a2 2 0 0 1 1.4.6l7.8 7.8a2 2 0 0 1 0 2.8l-3.2 3.2a2 2 0 0 1-2.8 0L4.6 11.6A2 2 0 0 1 4 10.2z"/><circle cx="8.5" cy="8.5" r="1.2" fill="currentColor" stroke="none"/></svg>
                <?php echo esc_html( $category->name ); ?>
            </div>
            <?php endif; ?>
            <h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <p class="featured-excerpt"><?php echo wp_trim_words( get_the_excerpt(), 24, '...' ); ?></p>
            <div class="featured-meta">
                <div class="f-author">
                    <?php echo get_avatar( $author_id, 42, '', $author_name, array( 'class' => 'f-avatar-img' ) ); ?>
                    <div>
                        <div class="f-name"><?php echo esc_html( $author_name ); ?></div>
                        <div class="f-role"><?php esc_html_e( 'Contributor', 'pawwell' ); ?></div>
                    </div>
                </div>
                <span class="f-dot"></span>
                <span class="f-meta-item">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 9h18M8 3v4M16 3v4"/></svg>
                    <?php echo esc_html( get_the_date() ); ?>
                </span>
                <span class="f-dot"></span>
                <span class="f-meta-item">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>
                    <?php echo esc_html( $reading_time ); ?> <?php esc_html_e( 'min read', 'pawwell' ); ?>
                </span>
            </div>
            <a href="<?php the_permalink(); ?>" class="featured-link">
                <?php esc_html_e( 'Read Article', 'pawwell' ); ?>
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg>
            </a>
        </div>
    </div>
</article>
