<?php
if (!defined('ABSPATH')) exit;

$pid       = get_the_ID();
$title     = get_the_title();
$link      = get_permalink();
$thumb     = get_the_post_thumbnail_url($pid, 'large');

$genre     = get_post_meta($pid, 'genre', true);
$price     = get_post_meta($pid, 'price', true);
$time      = get_post_meta($pid, 'game_time', true);
$players   = get_post_meta($pid, 'players', true);
$hardship  = get_post_meta($pid, 'hardship', true);
$location  = get_post_meta($pid, 'location', true);
$teaser    = get_post_meta($pid, 'teaser_url', true);

if (!$thumb) {
  $thumb = 'https://via.placeholder.com/800x500?text=Game';
}
?>
<article class="jg-card">
  <a class="jg-thumb-wrap" href="<?php echo esc_url($link); ?>">
    <img class="jg-thumb" src="<?php echo esc_url($thumb); ?>" alt="<?php echo esc_attr($title); ?>">
    <span class="jg-overlay"></span>
  </a>

  <div class="jg-card-body">
    <div class="jg-head">
      <div class="jg-title-row">
        <h3 class="jg-title">
          <a href="<?php echo esc_url($link); ?>"><?php echo esc_html($title); ?></a>
        </h3>
        <?php if ($genre): ?>
          <span class="jg-genre"><?php echo esc_html($genre); ?></span>
        <?php endif; ?>
      </div>
    </div>

    <div class="jg-specs-grid">
      <?php if ($time): ?>
        <div class="jg-spec">
          <span class="jg-ic"><?php echo jg_svg('clock', '#ffd54a'); ?></span>
          <span><?php echo esc_html($time); ?></span>
        </div>
      <?php endif; ?>

      <?php if ($players): ?>
        <div class="jg-spec">
          <span class="jg-ic"><?php echo jg_svg('users', '#ffd54a'); ?></span>
          <span><?php echo esc_html($players); ?></span>
        </div>
      <?php endif; ?>

      <?php if ($hardship): ?>
        <div class="jg-spec">
          <span class="jg-ic"><?php echo jg_svg('star', '#ffd54a'); ?></span>
          <span><?php echo esc_html($hardship); ?></span>
        </div>
      <?php endif; ?>

      <?php if ($location): ?>
        <div class="jg-spec location">
          <span class="jg-ic"><?php echo jg_svg('location', '#ffd54a'); ?></span>
          <span><?php echo esc_html($location); ?></span>
        </div>
      <?php endif; ?>

      <?php if ($teaser): ?>
        <div class="jg-spec">
          <span class="jg-ic"><?php echo jg_svg('play', '#ffd54a'); ?></span>
          <a href="<?php echo esc_url($teaser); ?>" target="_blank" rel="noopener">تیزر</a>
        </div>
      <?php endif; ?>
    </div>

    <div class="jg-card-footer">
      <?php if ($price): ?>
        <div class="jg-price">
          <span class="txt">از </span>
          <span class="number"><?php echo esc_html($price); ?></span>
          <span class="txt"> تومان</span>
        </div>
      <?php endif; ?>

      <a class="jg-btn" href="<?php echo esc_url($link); ?>">رزرو</a>
    </div>
  </div>
</article>
