<?php
$currentIndex = -1;
foreach(($items ?? array()) as $idx => $newsItem){
    if((int)($newsItem['id'] ?? 0) === (int)($item['id'] ?? 0)){
        $currentIndex = $idx;
        break;
    }
}
$prevItem = $currentIndex > 0 ? $items[$currentIndex - 1] : null;
$nextItem = ($currentIndex >= 0 && isset($items[$currentIndex + 1])) ? $items[$currentIndex + 1] : null;
if(!function_exists('news_detail_display_date')){
    function news_detail_display_date($item){
        $raw = '';
        foreach(array('publish_time', 'date', 'updated_at', 'created_at') as $field){
            if(!empty($item[$field])){
                $raw = $item[$field];
                break;
            }
        }
        $ts = is_numeric($raw) ? intval($raw) : strtotime((string)$raw);
        if(!$ts) return (string)($item['date'] ?? '');
        $weekMap = array('日','一','二','三','四','五','六');
        return date('Y年m月d日', $ts) . ' 星期' . $weekMap[intval(date('w', $ts))];
    }
}
$displayDate = news_detail_display_date($item ?? array());
?>
<section class="page-title detail-hero">
  <div class="container">
    <div class="detail-kicker">新闻资讯</div>
    <h1><?php echo e($item['title'] ?? ''); ?></h1>
    <p><?php echo e($displayDate); ?> · <?php echo e($item['type'] ?? '企业新闻'); ?></p>
  </div>
</section>

<section class="section detail-section">
  <div class="container detail-layout">
    <main class="detail-main article-pro">
      <?php if(!empty($item['image'])): ?>
      <div class="article-cover">
        <img src="<?php echo e($item['image']); ?>" alt="<?php echo e($item['title'] ?? ''); ?>">
      </div>
      <?php endif; ?>
      <div class="article-body">
        <?php echo article_content_render($item, 'content'); ?>
      </div>
      <nav class="article-pager" aria-label="新闻上一篇下一篇">
        <div class="article-pager-item">
          <span>上一篇</span>
          <?php if($prevItem): ?>
          <a href="/news/<?php echo intval($prevItem['id'] ?? 0); ?>.html"><?php echo e($prevItem['title'] ?? ''); ?></a>
          <?php else: ?>
          <em>没有上一篇</em>
          <?php endif; ?>
        </div>
        <div class="article-pager-item">
          <span>下一篇</span>
          <?php if($nextItem): ?>
          <a href="/news/<?php echo intval($nextItem['id'] ?? 0); ?>.html"><?php echo e($nextItem['title'] ?? ''); ?></a>
          <?php else: ?>
          <em>没有下一篇</em>
          <?php endif; ?>
        </div>
      </nav>
    </main>
    <aside class="detail-side">
      <div class="side-card">
        <h3>相关新闻</h3>
        <?php $count=0; foreach(($items ?? array()) as $n): if(($n['id'] ?? null)==($item['id'] ?? null)) continue; if($count++>=5) break; ?>
        <a class="side-link" href="/news/<?php echo intval($n['id'] ?? 0); ?>.html">
          <span><?php echo e($n['date'] ?? ''); ?></span>
          <strong><?php echo e($n['title'] ?? ''); ?></strong>
        </a>
        <?php endforeach; ?>
      </div>
      <div class="side-card contact-mini">
        <h3>咨询联系</h3>
        <p><?php echo e($company['name'] ?? ''); ?></p>
        <p>电话：<?php echo e($company['phone'] ?? ''); ?></p>
        <a class="btn" href="/contact/">联系我们</a>
      </div>
    </aside>
  </div>
</section>
