<?php
/**
 * CloudForge Theme - Case Detail
 */
$pageDescription = $case['summary'] ?: strip_tags(mb_substr($case['content'], 0, 200, 'UTF-8'));
$pageKeywords = $case['seo_keywords'];
$breadcrumbItems = [
    ['title' => '成功案例', 'url' => cms_url('cases')],
    ['title' => $case['title']]
];
?>
<?php echo breadcrumb($breadcrumbItems); ?>

<div class="main-content">
    <div class="container container--sidebar">
        <div class="content-main">
            <article class="article-detail">
                <header class="article-detail-header">
                    <h1 class="article-detail-title"><?php echo xss_clean($case['title']); ?></h1>
                    <div class="article-detail-meta">
                        <?php if ($case['client_name']): ?>
                        <span class="meta-item">
                            <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><rect x="2" y="3" width="10" height="8" rx="1" stroke="currentColor" stroke-width="1"/><path d="M2 6h10" stroke="currentColor" stroke-width="1"/></svg>
                            <?php echo xss_clean($case['client_name']); ?>
                        </span>
                        <?php endif; ?>
                        <?php if ($case['project_time']): ?>
                        <span class="meta-item">
                            <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><rect x="2" y="3" width="10" height="9" rx="1" stroke="currentColor" stroke-width="1"/><path d="M2 5h10M5 2v2M9 2v2" stroke="currentColor" stroke-width="1" stroke-linecap="round"/></svg>
                            <?php echo date('Y-m-d', strtotime($case['project_time'])); ?>
                        </span>
                        <?php endif; ?>
                        <span class="meta-item">
                            <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M1 7c1.5-3 3.5-4.5 6-4.5S11.5 4 13 7c-1.5 3-3.5 4.5-6 4.5S2.5 10 1 7z" stroke="currentColor" stroke-width="1"/><circle cx="7" cy="7" r="2" stroke="currentColor" stroke-width="1"/></svg>
                            <?php echo $case['views']; ?> views
                        </span>
                    </div>
                </header>

                <?php if ($case['cover_image']): ?>
                <div class="article-detail-cover">
                    <img src="<?php echo $case['cover_image']; ?>" alt="<?php echo xss_clean($case['title']); ?>">
                </div>
                <?php endif; ?>

                <?php if ($case['gallery']): ?>
                <?php $gallery = json_decode($case['gallery'], true); ?>
                <?php if ($gallery): ?>
                <div class="gallery-grid">
                    <?php foreach ($gallery as $img): ?>
                    <div class="gallery-item">
                        <img src="<?php echo $img; ?>" alt="" loading="lazy">
                    </div>
                    <?php endforeach; ?>
                </div>
                <?php endif; ?>
                <?php endif; ?>

                <div class="article-content">
                    <?php echo $case['content']; ?>
                </div>

                <?php if ($case['project_url']): ?>
                <div class="project-url-box">
                    <a href="<?php echo $case['project_url']; ?>" target="_blank" rel="noopener" class="btn btn--outline">
                        <span>访问项目</span>
                        <svg width="14" height="14" viewBox="0 0 16 16" fill="none"><path d="M4 12L12 4M6 4h6v6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
                    </a>
                </div>
                <?php endif; ?>
            </article>
        </div>

        <aside class="sidebar">
            <div class="widget">
                <h3 class="widget-title">// 更多案例</h3>
                <ul class="widget-list widget-list--ranked">
                    <?php $moreCases = db_query("SELECT `title`,`slug` FROM `cases` WHERE `status`=1 AND `id`!=? ORDER BY `sort_order` ASC LIMIT 8", [$case['id']]); ?>
                    <?php foreach ($moreCases as $idx => $mc): ?>
                    <li>
                        <span class="rank-num"><?php echo sprintf('%02d', $idx + 1); ?></span>
                        <a href="<?php echo cms_url('case', ['slug' => $mc['slug']]); ?>"><?php echo xss_clean($mc['title']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </aside>
    </div>
</div>
