<?php
/** archive-journal.php — CPT: journal アーカイブ (/members/journals/) */
include('header-member.php');
?>

<div id="contents">
  <div id="main_content">

    <div class="title_container">
      <h1>学術雑誌まとめ</h1>
      <h2>journal</h2>
    </div>

    <div class="section_wrapper">
      <div class="common_list_container">

        <?php if ( have_posts() ) : ?>
          <div class="journal-archive-grid">
            <?php while ( have_posts() ) : the_post(); ?>
              <?php
                $toc = get_post_meta(get_the_ID(), '_journal_toc', true);
                $toc_count = (is_array($toc)) ? count($toc) : 0;
              ?>
              <article id="post-<?php the_ID(); ?>" <?php post_class('journal-card'); ?>>
                <a class="card-link" href="<?php the_permalink(); ?>">
                  <div class="card-cover">
                    <?php if ( has_post_thumbnail() ) the_post_thumbnail('journal-cover'); else echo '<div class="no-cover">No Cover</div>'; ?>
                  </div>
                  <h3 class="card-title"><?php the_title(); ?></h3>
                </a>
                <div class="card-meta">
                  <span class="toc-count">目次 <?php echo (int)$toc_count; ?> 件</span>
                  <time class="published" datetime="<?php echo esc_attr(get_the_date('c')); ?>">
                    <?php echo esc_html(get_the_date('Y.m.d')); ?>
                  </time>
                </div>
                <?php if ( has_excerpt() ) : ?>
                  <p class="card-excerpt"><?php echo esc_html( get_the_excerpt() ); ?></p>
                <?php endif; ?>
              </article>
            <?php endwhile; ?>
          </div>

          <nav class="journal-pagination">
            <?php the_posts_pagination([
              'mid_size'  => 1,
              'prev_text' => '← 前へ',
              'next_text' => '次へ →',
            ]); ?>
          </nav>

        <?php else : ?>
          <p>まだ学術雑誌がありません。</p>
        <?php endif; ?>

      </div>
    </div>

  </div>
</div>

<?php get_footer(); ?>
