<?php
/**
 * HuSNS - 签到记录页面
 */
?>
<div class="admin-content signin-page">
    <div class="page-header">
        <h2><i class="fa fa-calendar-check-o"></i> 签到记录</h2>
        <a href="<?php echo Helper::url('point/signin'); ?>" class="btn btn-default">
            <i class="fa fa-arrow-left"></i> 返回
        </a>
    </div>

    <!-- 搜索 -->
    <div class="admin-search">
        <form method="get">
            <input type="hidden" name="r" value="point/signinLogs">
            <div class="search-form-row">
                <div class="search-item">
                    <input type="text" name="keyword" value="<?php echo htmlspecialchars($keyword ?? ''); ?>" placeholder="搜索用户名">
                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                    <a href="<?php echo Helper::url('point/signinLogs'); ?>" class="btn btn-default"><i class="fa fa-refresh"></i> 重置</a>
                </div>
            </div>
        </form>
    </div>

    <!-- 记录列表 -->
    <div class="admin-table">
        <table class="table">
            <thead>
                <tr>
                    <th width="80">ID</th>
                    <th>用户</th>
                    <th width="100">获得积分</th>
                    <th width="100">剩余积分</th>
                    <th width="160">签到时间</th>
                    <th>备注</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($logs)): ?>
                <tr>
                    <td colspan="6">
                        <div class="empty-state">
                            <i class="fa fa-calendar-times-o"></i>
                            <p>暂无签到记录</p>
                        </div>
                    </td>
                </tr>
                <?php else: ?>
                <?php foreach ($logs as $log): ?>
                <tr>
                    <td>#<?php echo $log['id']; ?></td>
                    <td>
                        <img src="<?php echo $log['user_avatar'] ? Helper::uploadUrl($log['user_avatar']) : Helper::assetUrl('images/default-avatar.png'); ?>"
                             alt="" class="avatar-xs">
                        <?php echo htmlspecialchars($log['user_name'] ?? '未知用户'); ?>
                    </td>
                    <td><span class="text-success">+<?php echo $log['points']; ?></span></td>
                    <td><?php echo $log['balance']; ?></td>
                    <td><?php echo date('Y-m-d H:i', $log['created_at']); ?></td>
                    <td><?php echo htmlspecialchars($log['remark'] ?? ''); ?></td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>

        <?php if ($pages > 1): ?>
        <div class="pagination-wrap">
            <ul class="pagination">
                <?php if ($page > 1): ?>
                <li><a href="?r=point/signinLogs&page=<?php echo $page - 1; ?>&keyword=<?php echo urlencode($keyword ?? ''); ?>">«</a></li>
                <?php endif; ?>

                <?php for ($i = max(1, $page - 2); $i <= min($pages, $page + 2); $i++): ?>
                <li><a href="?r=point/signinLogs&page=<?php echo $i; ?>&keyword=<?php echo urlencode($keyword ?? ''); ?>"
                       class="<?php echo $page == $i ? 'active' : ''; ?>"><?php echo $i; ?></a></li>
                <?php endfor; ?>

                <?php if ($page < $pages): ?>
                <li><a href="?r=point/signinLogs&page=<?php echo $page + 1; ?>&keyword=<?php echo urlencode($keyword ?? ''); ?>">»</a></li>
                <?php endif; ?>
            </ul>
        </div>
        <?php endif; ?>
    </div>
</div>

<style>
.signin-page .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.signin-page .page-header h2 {
    margin: 0;
    font-size: 18px;
}
.signin-page .admin-search {
    background: #fff;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 15px;
}
.signin-page .search-form-row {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}
.signin-page .search-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
.signin-page .search-item input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 180px;
}
.signin-page .admin-table {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
}
.signin-page .empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}
.signin-page .empty-state i {
    font-size: 48px;
    color: #ddd;
    margin-bottom: 10px;
    display: block;
}
.signin-page .text-success {
    color: #27ae60;
    font-weight: 600;
}
.signin-page .avatar-xs {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
</style>
