<?php get_header(); ?>

<div class="wrapper--default">
  <div class="wrapper--inner">
    <section class="lg:container lg:mx-auto lg:mb-12">
      <div class="p-6">
        <h1>Nasze realizacje</h1>
      </div>

      <div class="p-6 flex flex-col md:flex-row md:flex-wrap md:items-start md:justify-center lg:justify-start lg:p-0 gap-2">
        <?php
        $args = array(
          'post_type'              => array('realizacje'),
          'nopaging'               => false,
          'posts_per_page'         => '24',
          'posts_per_archive_page' => '24',
          'paged'                  => get_query_var('paged') ? get_query_var('paged') : 1, // Dodano obsługę stronicowania
        );

        $query = new WP_Query($args);
        if ($query->have_posts()) {
          while ($query->have_posts()) {
            $query->the_post(); ?>

            <a class="mb-10 flex flex-col md:w-72 md:m-4 box-border transform hover:opacity-95" href="<?php the_permalink(); ?>">
              <div class="pb-72 bg-cover" style="background-image:url(<?php echo get_the_post_thumbnail_url(); ?>)">
              </div>
              <h4 class="text-xl text-center font-semibold pt-6 lg:text-left"><?php the_title(); ?></h4>
            </a>

        <?php
          }
        } else {
          // Brak postów
        }
        wp_reset_postdata();
        ?>

        <!-- Dodanie stronicowania poniżej -->
        <div class="pagination">
          <?php
          echo paginate_links(array(
            'total' => $query->max_num_pages,
            'current' => max(1, get_query_var('paged')),
            'format' => '?paged=%#%',
            'show_all' => false,
            'type' => 'plain',
            'end_size' => 2,
            'mid_size' => 1,
            'prev_next' => true,
            'prev_text' => sprintf('<i></i> %1$s', __('Poprzednia', 'text-domain')),
            'next_text' => sprintf('%1$s <i></i>', __('Następna', 'text-domain')),
            'add_args' => false,
            'add_fragment' => '',
          ));
          ?>
        </div>
      </div>
    </section>
  </div>
</div>

<?php get_footer(); ?>
