<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * Template part for displaying posts
 * Supports both modern and classic card styles
 *
 * @package Pawfect
 */

// Get card style from context or customizer
$card_style = isset($args['card_style']) ? $args['card_style'] : get_theme_mod('pawfect_blog_card_style', 'modern');
$layout_style = isset($args['layout_style']) ? $args['layout_style'] : get_theme_mod('pawfect_blog_layout_style', 'grid');
$show_featured_image = isset($args['show_featured_image']) ? $args['show_featured_image'] : get_theme_mod('pawfect_blog_show_featured_image', true);
$show_meta = isset($args['show_meta']) ? $args['show_meta'] : get_theme_mod('pawfect_blog_show_meta', true);
$show_excerpt = isset($args['show_excerpt']) ? $args['show_excerpt'] : get_theme_mod('pawfect_blog_show_excerpt', true);
$excerpt_length = isset($args['excerpt_length']) ? $args['excerpt_length'] : get_theme_mod('pawfect_blog_excerpt_length', 25);
$show_read_more = isset($args['show_read_more']) ? $args['show_read_more'] : get_theme_mod('pawfect_blog_show_read_more', true);
$read_more_text = isset($args['read_more_text']) ? $args['read_more_text'] : get_theme_mod('pawfect_blog_read_more_text', __('Read More', 'pawfect'));

// Check if we should use drag & drop ordering (for archive pages)
$use_drag_drop = isset($args['use_drag_drop']) ? $args['use_drag_drop'] : false;

// Determine card classes based on style
$card_classes = 'pawfect-post-card pawfect-group pawfect-relative pawfect-bg-white pawfect-overflow-hidden pawfect-transition-all pawfect-duration-300';

if ($card_style === 'modern') {
    $card_classes .= ' pawfect-rounded-2xl ';
}
else {
    $card_classes .= ' pawfect-rounded-xl pawfect-border pawfect-border-gray-100 ';
}

if ($layout_style === 'list') {
    $card_classes .= ' pawfect-mb-8';
}
?>

<article id="post-<?php the_ID(); ?>" <?php post_class($card_classes); ?>>

    <?php if ($use_drag_drop): ?>
        <!-- Use Drag & Drop Ordering (for archive pages) -->

       

        <div class="pawfect-relative pawfect-z-10">
            <!-- Dynamic Post Content Based on Ordering -->
            <?php
    $content_order = pawfect_get_blog_content_ordering();
    foreach ($content_order as $element) {
        pawfect_render_blog_post_element($element);
    }
?>
        </div>

    <?php
elseif ($layout_style === 'list'): ?>
        <!-- List Layout - Exact Match to content.html lines 252-304 -->
        <?php if ($show_featured_image && has_post_thumbnail()): ?>
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('large', [
            'class' => 'pawfect-w-full pawfect-h-auto pawfect-object-cover pawfect-mb-6'
        ]); ?>
            </a>
        <?php
    endif; ?>

        <?php if ($show_meta): ?>
            <div class="pawfect-post-meta pawfect-text-xs pawfect-uppercase pawfect-tracking-widest pawfect-text-gray-400 pawfect-mb-2">
                <?php if (has_category()): ?>
                    <span><?php the_category(', '); ?></span>
                    <span> &bull; </span>
                <?php
        endif; ?>
                <time datetime="<?php echo esc_attr(get_the_date('c')); ?>">
                    <?php echo esc_html(get_the_date()); ?>
                </time>
            </div>
        <?php
    endif; ?>

        <h2 class="pawfect-text-5xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-4">
            <a href="<?php the_permalink(); ?>" class="pawfect-transition-colors pawfect-duration-300 hover:pawfect-text-pawfect-primary">
                <?php the_title(); ?>
            </a>
        </h2>

        <?php if ($show_excerpt): ?>
            <div class="pawfect-text-lg pawfect-text-gray-600 pawfect-leading-relaxed pawfect-mb-6">
                <?php echo wp_trim_words(get_the_excerpt(), $excerpt_length, '...'); ?>
            </div>
        <?php
    endif; ?>

        <?php if ($show_read_more): ?>
            <a href="<?php the_permalink(); ?>" class="pawfect-text-pawfect-primary pawfect-font-semibold pawfect-text-sm pawfect-transition-colors pawfect-duration-300 hover:pawfect-text-gray-900">
                <?php echo esc_html($read_more_text); ?> &rarr;
            </a>
        <?php
    endif; ?>

    <?php
elseif ($card_style === 'modern'): ?>
        <!-- Modern Card Style - Exact Match to content.html lines 45-137 -->

        <?php if ($show_featured_image && has_post_thumbnail()): ?>
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('medium_large', [
            'class' => 'pawfect-w-full pawfect-h-auto pawfect-object-cover pawfect-rounded-lg pawfect-mb-4'
        ]); ?>
            </a>
        <?php
    endif; ?>

        <?php if ($show_meta): ?>
            <div class="pawfect-post-meta pawfect-text-xs pawfect-uppercase pawfect-tracking-widest pawfect-text-gray-400 pawfect-mb-2">
                <?php
        $categories = get_the_category();
        if (!empty($categories)): ?>
                    <span><?php the_category(', '); ?></span>
                    <span> &bull; </span>
                <?php
        endif; ?>
                <time datetime="<?php echo esc_attr(get_the_date('c')); ?>">
                    <?php echo esc_html(get_the_date()); ?>
                </time>
            </div>
        <?php
    endif; ?>

        <h2 class="pawfect-text-2xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-2">
            <a href="<?php the_permalink(); ?>" class="pawfect-transition-colors pawfect-duration-200 hover:pawfect-text-pawfect-primary">
                <?php the_title(); ?>
            </a>
        </h2>

        <?php if ($show_excerpt): ?>
            <div class="pawfect-text-gray-600 pawfect-mb-4 pawfect-line-clamp-3">
                <?php echo wp_trim_words(get_the_excerpt(), $excerpt_length, '...'); ?>
            </div>
        <?php
    endif; ?>

        <?php if ($show_read_more): ?>
            <a href="<?php the_permalink(); ?>" class="pawfect-text-pawfect-primary pawfect-font-medium pawfect-text-sm pawfect-transition-colors pawfect-duration-200 hover:pawfect-text-gray-900">
                <?php echo esc_html($read_more_text); ?> &rarr;
            </a>
        <?php
    endif; ?>

    <?php
else: ?>
        <!-- Classic Card Style - Exact Match to content.html -->

        <?php if ($show_featured_image && has_post_thumbnail()): ?>
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('medium_large', [
            'class' => 'pawfect-w-full pawfect-h-auto pawfect-object-cover pawfect-rounded-lg pawfect-mb-4'
        ]); ?>
            </a>
        <?php
    endif; ?>

        <?php if ($show_meta): ?>
            <div class="pawfect-post-meta pawfect-text-xs pawfect-uppercase pawfect-tracking-widest pawfect-text-gray-400 pawfect-mb-2">
                <?php
        $categories = get_the_category();
        if (!empty($categories)): ?>
                    <span><?php the_category(', '); ?></span>
                    <span> &bull; </span>
                <?php
        endif; ?>
                <time datetime="<?php echo esc_attr(get_the_date('c')); ?>">
                    <?php echo esc_html(get_the_date()); ?>
                </time>
            </div>
        <?php
    endif; ?>

        <h2 class="pawfect-text-2xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-2">
            <a href="<?php the_permalink(); ?>" class="pawfect-transition-colors pawfect-duration-200 hover:pawfect-text-pawfect-primary">
                <?php the_title(); ?>
            </a>
        </h2>

        <?php if ($show_excerpt): ?>
            <div class="pawfect-text-gray-600 pawfect-mb-4 pawfect-line-clamp-3">
                <?php echo wp_trim_words(get_the_excerpt(), $excerpt_length, '...'); ?>
            </div>
        <?php
    endif; ?>

        <?php if ($show_read_more): ?>
            <a href="<?php the_permalink(); ?>" class="pawfect-text-pawfect-primary pawfect-font-medium pawfect-text-sm pawfect-transition-colors pawfect-duration-200 hover:pawfect-text-gray-900">
                <?php echo esc_html($read_more_text); ?> &rarr;
            </a>
        <?php
    endif; ?>
    <?php
endif; ?>

</article><!-- #post-<?php the_ID(); ?> -->
