<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * Template part for displaying single posts
 *
 * @package Pawfect
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class('pawfect-single-post-content'); ?>>

    <!-- Premium Post Header -->
    <div class="pawfect-p-12 md:pawfect-p-16 pawfect-pb-8">
        <!-- 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);
        }
        ?>

        <!-- Premium Page Links for Multi-page Posts -->
        <?php
        wp_link_pages(array(
            'before' => '<div class="pawfect-page-links pawfect-mt-12 pawfect-text-center pawfect-p-6 pawfect-bg-gray-50 pawfect-rounded-xl"><span class="pawfect-page-links-title pawfect-font-semibold pawfect-text-gray-700 pawfect-mr-4">' . esc_html__('Pages:', 'pawfect') . '</span>',
            'after'  => '</div>',
            'link_before' => '<span class="pawfect-page-number pawfect-inline-block pawfect-px-4 pawfect-py-2 pawfect-mx-1 pawfect-bg-white pawfect-border pawfect-border-gray-200 pawfect-rounded-lg pawfect-text-sm pawfect-font-medium pawfect-transition-all pawfect-duration-300 hover:pawfect-bg-pawfect-primary hover:pawfect-text-white hover:pawfect-border-pawfect-primary">',
            'link_after'  => '</span>',
        ));
        ?>
    </div>

    <!-- Premium Post Tags -->
    <?php if (get_the_tags()): ?>
        <div class="pawfect-post-tags pawfect-px-12 md:pawfect-px-16 pawfect-pb-8">
            <div class="pawfect-border-t pawfect-border-gray-100 pawfect-pt-8">
                <h4 class="pawfect-text-sm pawfect-font-semibold pawfect-text-gray-500 pawfect-uppercase pawfect-tracking-wider pawfect-mb-4">
                    <?php esc_html_e('Tagged in', 'pawfect'); ?>
                </h4>
                <div class="pawfect-flex pawfect-flex-wrap pawfect-gap-3">
                    <?php foreach (get_the_tags() as $tag): ?>
                        <a href="<?php echo esc_url( get_tag_link($tag->term_id) ); ?>" class="pawfect-tag pawfect-inline-block pawfect-px-4 pawfect-py-2 pawfect-bg-gray-50 hover:pawfect-bg-pawfect-primary hover:pawfect-text-white pawfect-rounded-full pawfect-text-sm pawfect-text-gray-700 pawfect-font-medium pawfect-transition-all pawfect-duration-300 pawfect-border pawfect-border-transparent hover:pawfect-border-pawfect-primary">
                            <?php echo esc_html($tag->name); ?>
                        </a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <!-- Premium Author Bio -->
    <?php if (get_the_author_meta('description')): ?>
        <div class="pawfect-author-bio pawfect-px-12 md:pawfect-px-16 pawfect-pb-8">
            <div class="pawfect-border-t pawfect-border-gray-100 pawfect-pt-8">
                <h4 class="pawfect-text-sm pawfect-font-semibold pawfect-text-gray-500 pawfect-uppercase pawfect-tracking-wider pawfect-mb-6">
                    <?php esc_html_e('About the Author', 'pawfect'); ?>
                </h4>
                <div class="pawfect-bg-gradient-to-r pawfect-from-gray-50 pawfect-to-gray-100 pawfect-p-8 pawfect-rounded-2xl">
                    <div class="pawfect-flex pawfect-items-start pawfect-gap-6">
                        <div class="pawfect-author-avatar pawfect-flex-shrink-0">
                            <?php echo wp_kses_post( get_avatar(get_the_author_meta('ID'), 80, '', '', array('class' => 'pawfect-rounded-full pawfect-border-4 pawfect-border-white pawfect-shadow-lg')) ); ?>
                        </div>
                        <div class="pawfect-author-info pawfect-flex-1">
                            <h5 class="pawfect-text-xl pawfect-font-bold pawfect-text-gray-900 pawfect-mb-3">
                                <?php echo esc_html( get_the_author() ); ?>
                            </h5>
                            <p class="pawfect-text-gray-600 pawfect-leading-relaxed pawfect-text-lg">
                                <?php echo esc_html( get_the_author_meta('description') ); ?>
                            </p>

                            <!-- Author Website Link -->
                            <?php
                            $author_website = get_the_author_meta('user_url');
                            if ($author_website): ?>
                                <div class="pawfect-mt-4">
                                    <a href="<?php echo esc_url($author_website); ?>" target="_blank" rel="noopener" class="pawfect-inline-flex pawfect-items-center pawfect-gap-2 pawfect-text-pawfect-primary hover:pawfect-text-pawfect-dark pawfect-font-semibold pawfect-transition-colors pawfect-duration-300">
                                        <svg class="pawfect-w-4 pawfect-h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
                                        </svg>
                                        <?php esc_html_e('Visit Website', 'pawfect'); ?>
                                    </a>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <!-- Premium Post Navigation -->
    <div class="pawfect-px-12 md:pawfect-px-16 pawfect-pb-12">
        <div class="pawfect-border-t pawfect-border-gray-100 pawfect-pt-8">
            <h4 class="pawfect-text-sm pawfect-font-semibold pawfect-text-gray-500 pawfect-uppercase pawfect-tracking-wider pawfect-mb-6 pawfect-text-center">
                <?php esc_html_e('Continue Reading', 'pawfect'); ?>
            </h4>

            <nav class="pawfect-post-navigation pawfect-grid pawfect-grid-cols-1 md:pawfect-grid-cols-2 pawfect-gap-6">
                <!-- Previous Post -->
                <div class="pawfect-nav-previous">
                    <?php
                    $prev_post = get_previous_post();
                    if ($prev_post): ?>
                        <a href="<?php echo esc_url( get_permalink($prev_post->ID) ); ?>" class="pawfect-group pawfect-block pawfect-bg-gradient-to-br pawfect-from-gray-50 pawfect-to-gray-100 hover:pawfect-from-pawfect-primary hover:pawfect-to-pawfect-dark pawfect-p-6 pawfect-rounded-xl pawfect-transition-all pawfect-duration-500 pawfect-transform hover:pawfect-scale-105 pawfect-shadow-lg hover:pawfect-shadow-xl">
                            <div class="pawfect-flex pawfect-items-center pawfect-gap-4 pawfect-mb-3">
                                <div class="pawfect-w-10 pawfect-h-10 pawfect-bg-white pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-md group-hover:pawfect-bg-white group-hover:pawfect-shadow-lg pawfect-transition-all pawfect-duration-300">
                                    <svg class="pawfect-w-5 pawfect-h-5 pawfect-text-pawfect-primary group-hover:pawfect-text-pawfect-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                                    </svg>
                                </div>
                                <span class="pawfect-text-sm pawfect-font-semibold pawfect-text-gray-600 group-hover:pawfect-text-white pawfect-uppercase pawfect-tracking-wider"><?php esc_html_e('Previous', 'pawfect'); ?></span>
                            </div>
                            <h5 class="pawfect-text-lg pawfect-font-bold pawfect-text-gray-900 group-hover:pawfect-text-white pawfect-leading-tight pawfect-transition-colors pawfect-duration-300">
                                <?php echo esc_html( wp_trim_words($prev_post->post_title, 6) ); ?>
                            </h5>
                        </a>
                    <?php else: ?>
                        <div class="pawfect-bg-gray-100 pawfect-p-6 pawfect-rounded-xl pawfect-opacity-50">
                            <div class="pawfect-text-center pawfect-text-gray-400">
                                <div class="pawfect-w-10 pawfect-h-10 pawfect-bg-gray-200 pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-mx-auto pawfect-mb-3">
                                    <svg class="pawfect-w-5 pawfect-h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                                    </svg>
                                </div>
                                <span class="pawfect-text-sm pawfect-font-medium"><?php esc_html_e('No previous post', 'pawfect'); ?></span>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>

                <!-- Next Post -->
                <div class="pawfect-nav-next">
                    <?php
                    $next_post = get_next_post();
                    if ($next_post): ?>
                        <a href="<?php echo esc_url( get_permalink($next_post->ID) ); ?>" class="pawfect-group pawfect-block pawfect-bg-gradient-to-bl pawfect-from-gray-50 pawfect-to-gray-100 hover:pawfect-from-pawfect-primary hover:pawfect-to-pawfect-dark pawfect-p-6 pawfect-rounded-xl pawfect-transition-all pawfect-duration-500 pawfect-transform hover:pawfect-scale-105 pawfect-shadow-lg hover:pawfect-shadow-xl">
                            <div class="pawfect-flex pawfect-items-center pawfect-justify-end pawfect-gap-4 pawfect-mb-3">
                                <span class="pawfect-text-sm pawfect-font-semibold pawfect-text-gray-600 group-hover:pawfect-text-white pawfect-uppercase pawfect-tracking-wider"><?php esc_html_e('Next', 'pawfect'); ?></span>
                                <div class="pawfect-w-10 pawfect-h-10 pawfect-bg-white pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-md group-hover:pawfect-bg-white group-hover:pawfect-shadow-lg pawfect-transition-all pawfect-duration-300">
                                    <svg class="pawfect-w-5 pawfect-h-5 pawfect-text-pawfect-primary group-hover:pawfect-text-pawfect-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                                    </svg>
                                </div>
                            </div>
                            <h5 class="pawfect-text-lg pawfect-font-bold pawfect-text-gray-900 group-hover:pawfect-text-white pawfect-leading-tight pawfect-text-right pawfect-transition-colors pawfect-duration-300">
                                <?php echo esc_html( wp_trim_words($next_post->post_title, 6) ); ?>
                            </h5>
                        </a>
                    <?php else: ?>
                        <div class="pawfect-bg-gray-100 pawfect-p-6 pawfect-rounded-xl pawfect-opacity-50">
                            <div class="pawfect-text-center pawfect-text-gray-400">
                                <div class="pawfect-w-10 pawfect-h-10 pawfect-bg-gray-200 pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-mx-auto pawfect-mb-3">
                                    <svg class="pawfect-w-5 pawfect-h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                                    </svg>
                                </div>
                                <span class="pawfect-text-sm pawfect-font-medium"><?php esc_html_e('No next post', 'pawfect'); ?></span>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </nav>
        </div>
    </div>

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