<?php
/**
 * 芋头CMS - 招聘列表页
 */
if (!defined('ROOT_PATH')) { exit('Access Denied'); }

require_once __DIR__ . '/../_header.php';

$allChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE channel_type = 9 AND is_show = 1 ORDER BY list_order ASC, id ASC");
$curChannelId = isset($_GET['channel_id']) ? intval($_GET['channel_id']) : 0;

$sql = "SELECT r.*, c.channel_name FROM {$db->table('recruit')} r LEFT JOIN {$db->table('channel')} c ON r.channel_id=c.id WHERE r.status=1";
$params = [];
if ($curChannelId > 0) {
    $sql .= " AND r.channel_id = ?";
    $params[] = $curChannelId;
}
$sql .= " ORDER BY r.create_time DESC";
$recruitList = $db->fetchAll($sql, $params);
?>

<div style="padding-top:70px;">
<div style="height:280px;background:linear-gradient(135deg,var(--dark) 0%,var(--primary-dark) 100%);display:flex;align-items:center;justify-content:center;">
<div style="text-align:center;color:white;">
<h1 style="font-size:36px;margin-bottom:10px;"><?php echo htmlspecialchars($channel['channel_name'] ?? '人才招聘'); ?></h1>
</div>
</div>

<section class="section">
<div class="container">
<div style="display:grid;grid-template-columns:220px 1fr;gap:30px;align-items:start;">

<aside style="background:#fff;border-radius:10px;padding:20px;box-shadow:0 2px 8px rgba(0,0,0,0.06);position:sticky;top:90px;">
<h3 style="font-size:16px;font-weight:600;color:var(--dark);margin-bottom:16px;padding-bottom:12px;border-bottom:2px solid var(--border);">招聘分类</h3>
<ul style="list:none;padding:0;margin:0;">
<li>
<a href="?m=channel&id=<?php echo intval($id); ?>&channel_id=0" style="display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-radius:6px;font-size:14px;color:<?php echo $curChannelId == 0 ? 'var(--accent)' : 'var(--text)'; ?>;background:<?php echo $curChannelId == 0 ? 'var(--bg-light)' : 'transparent'; ?>;text-decoration:none;">
全部
</a>
</li>
<?php foreach ($allChannels as $ch): ?>
<li>
<a href="?m=channel&id=<?php echo intval($id); ?>&channel_id=<?php echo $ch['id']; ?>" style="display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-radius:6px;font-size:14px;color:<?php echo $curChannelId == $ch['id'] ? 'var(--accent)' : 'var(--text)'; ?>;background:<?php echo $curChannelId == $ch['id'] ? 'var(--bg-light)' : 'transparent'; ?>;text-decoration:none;">
<?php echo htmlspecialchars($ch['channel_name']); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</aside>

<div>
<?php if (!empty($recruitList)): ?>
<?php foreach ($recruitList as $r): ?>
<div style="background:#fff;border-radius:10px;padding:24px;margin-bottom:20px;box-shadow:0 2px 8px rgba(0,0,0,0.06);">
<div style="display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:12px;">
<div>
<h3 style="font-size:18px;color:var(--dark);font-weight:600;margin-bottom:8px;"><?php echo htmlspecialchars($r['title']); ?></h3>
<div style="display:flex;gap:16px;flex-wrap:wrap;font-size:13px;color:var(--gray);">
<?php if (!empty($r['department'])): ?><span>📌 部门：<?php echo htmlspecialchars($r['department']); ?></span><?php endif; ?>
<?php if (!empty($r['region'])): ?><span>📍 工作地点：<?php echo htmlspecialchars($r['region']); ?></span><?php endif; ?>
<?php if (!empty($r['work_type'])): ?><span>💼 工作性质：<?php echo htmlspecialchars($r['work_type']); ?></span><?php endif; ?>
</div>
</div>
<div style="flex-shrink:0;text-align:right;">
<?php if (!empty($r['salary'])): ?>
<p style="font-size:20px;font-weight:700;color:var(--primary);"><?php echo htmlspecialchars($r['salary']); ?></p>
<?php endif; ?>
<a href="<?php echo getUrl('recruit', $r['id']); ?>" style="display:inline-block;margin-top:10px;padding:8px 20px;background:var(--accent);color:#fff;border-radius:4px;font-size:14px;text-decoration:none;">查看详情</a>
</div>
</div>
<div style="display:flex;gap:20px;flex-wrap:wrap;font-size:13px;color:var(--gray-light);border-top:1px solid var(--border);padding-top:12px;margin-top:12px;">
<?php if (!empty($r['experience'])): ?><span>📅 经验要求：<?php echo htmlspecialchars($r['experience']); ?></span><?php endif; ?>
<?php if (!empty($r['education'])): ?><span>🎓 学历要求：<?php echo htmlspecialchars($r['education']); ?></span><?php endif; ?>
<?php if (!empty($r['quantity'])): ?><span>👥 招聘人数：<?php echo htmlspecialchars($r['quantity']); ?>人</span><?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div style="text-align:center;padding:60px 0;color:var(--gray-light);">暂无招聘信息</div>
<?php endif; ?>
</div>

</div>
</div>
</section>
</div>

<?php require_once __DIR__ . '/../_footer.php'; ?>