<?php get_header(); ?>

<div class="category-header mx-auto pb-8">
    <div class="mb-8 md:max-w-7xl mx-auto pt-28 px-4">
        <div>
            <h1 class="font-bold text-2xl text-white tracking-tight lg:text-4xl"><?php wp_title( '' ); ?></h1>
        </div>
    </div>
</div>
<div class="pb-28 pt-12">
    <div class="max-w-7xl mx-auto px-4">
        <div class="mx-auto">
            <div class="grid grid-cols-4">
                <?php if ( have_posts() ) : ?>
                    <div class="col-span-4 gap-4 grid grid-cols-2 mb-5 md:grid-cols-3 lg:col-span-3">
                        <?php while ( have_posts() ) : the_post(); ?>
                            <?php PG_Helper_v2::rememberShownPost(); ?>
                            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                                <div class="mb-4">
                                    <div class="overflow-hidden relative rounded-lg w-full"><a href="<?php echo esc_url( get_permalink() ); ?>" class="cursor-pointer"><?php echo PG_Image::getPostImage( null, 'large', array(
                                                    'class' => 'h-full object-center object-cover w-full',
                                                    'sizes' => '(max-width: 100px) 11px, (max-width: 768px) 88vw, (max-width: 1024px) 45vw, (max-width: 1280px) 22vw, 293px'
                                            ), 'both', null ) ?></a>
                                    </div>
                                    <div class="mt-4 space-y-2 text-left">
                                        <div class="flex flex-col items-start justify-between mb-2 space-y-2">
                                            <?php $terms = get_the_terms( get_the_ID(), 'category' ) ?>
                                            <?php if( !empty( $terms ) ) : ?>
                                                <?php foreach( $terms as $term_i => $term ) : ?>
                                                    <?php if( $term_i == 0 ) : ?>
                                                        <a class="font-medium text-base text-gray-400" href="<?php echo esc_url( get_term_link( $term, 'category' ) ) ?>"><?php echo $term->name; ?></a>
                                                    <?php endif; ?>
                                                <?php endforeach; ?>
                                            <?php endif; ?>
                                            <h3 class="font-normal text-gray-400 text-xs"><?php the_time( get_option( 'date_format' ) ); ?></h3>
                                        </div><a href="<?php echo esc_url( get_permalink() ); ?>"><h3 class="font-medium text-gray-900 text-lg"><?php the_title(); ?></h3></a>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile; ?>
                    </div>
                <?php else : ?>
                    <p><?php _e( 'Sorry, no posts matched your criteria.', 'leonpharmacy' ); ?></p>
                <?php endif; ?>
                <?php if ( is_active_sidebar( 'archive' ) ) : ?>
                    <div class="hidden pl-8 lg:block">
                        <?php dynamic_sidebar( 'archive' ); ?>
                    </div>
                <?php endif; ?>
            </div>
            <?php if ( PG_Pagination::isPaginated() ) : ?>
                <nav class="isolate inline-flex -space-x-px rounded-md shadow-sm" aria-label="Pagination"><a class="<?php if(!( PG_Pagination::getCurrentPage() > 1 )) echo 'disabled'; ?> bg-white border border-gray-300 focus:z-20 font-black hover:bg-gray-50 inline-flex items-center px-2 py-2 relative rounded-md text-gray-500 text-sm" <?php echo PG_Pagination::getPreviousHrefAttribute(); ?>> <span class="sr-only"><?php _e( 'Previous', 'leonpharmacy' ); ?></span> <!-- Heroicon name: mini/chevron-left --> <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                            <path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd"/>
                        </svg> </a>
                    <!-- Current: "z-10 bg-indigo-50 border-indigo-500 text-indigo-600", Default: "bg-white border-gray-300 text-gray-500 hover:bg-gray-50" -->
                    <?php $dots = false; ?>
                    <?php for( $page_num = 1; $page_num <= PG_Pagination::getMaxPages(); $page_num++) : ?>
                        <?php if( $page_num == PG_Pagination::getCurrentPage() ) : ?>
                            <a href="<?php echo esc_url( get_pagenum_link( $page_num ) ) ?>" aria-current="page" class="bg-blue-500 border border-yellow-500 focus:z-20 font-bold inline-flex items-center px-4 py-2 relative text-sm text-white z-10"><?php echo $page_num ?></a>
                            <?php $dots = false; ?>
                        <?php elseif ( false || ( $page_num <= 1 || ( PG_Pagination::getCurrentPage() && $page_num >= PG_Pagination::getCurrentPage() - 2 && $page_num <= PG_Pagination::getCurrentPage() + 2 ) || $page_num > PG_Pagination::getMaxPages() - 1 ) ) : ?>
                            <a href="<?php echo esc_url( get_pagenum_link( $page_num ) ) ?>" class="<?php if( $page_num == PG_Pagination::getCurrentPage() ) echo 'active'; ?> bg-white border border-gray-300 focus:z-20 font-medium hover:bg-gray-50 inline-flex items-center px-4 py-2 relative text-gray-500 text-sm"><?php echo $page_num ?></a>
                            <?php $dots = false; ?>
                        <?php else : ?>
                            <?php if(!$dots) : ?>
                                <span class="relative inline-flex items-center border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700">...</span>
                                <?php $dots = true; ?>
                            <?php endif; ?>
                        <?php endif; ?>
                    <?php endfor; ?>                                  <a class="<?php if(!( PG_Pagination::getCurrentPage() < PG_Pagination::getMaxPages() )) echo 'disabled'; ?> bg-white border border-gray-300 focus:z-20 font-black hover:bg-gray-50 inline-flex items-center px-2 py-2 relative rounded-md text-gray-500 text-sm" <?php echo PG_Pagination::getNextHrefAttribute(); ?>> <span class="sr-only"><?php _e( 'Next', 'leonpharmacy' ); ?></span> <!-- Heroicon name: mini/chevron-right --> <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                            <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd"/>
                        </svg> </a>
                </nav>
            <?php endif; ?>
        </div>
    </div>
</div>            

<?php get_footer(); ?>