<?php include __DIR__ . '/../header.php'; ?>

<div class="content-wrapper">
<section class="content pt-3">
<div class="container-fluid pb-5">

<div class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4">
    <div>
        <h3 class="mb-1 fw-bold">
            <i class="bi bi-bar-chart-fill me-2 text-primary"></i>
            <?= __('team.performance_title','Team Performance Stats') ?>
        </h3>
        <p class="text-muted mb-0 small"><?= __('team.performance_subtitle','Confirmation rate per team member') ?></p>
    </div>
    <div class="d-flex gap-2 align-items-center">
        <?php foreach([7,30,90] as $d): ?>
        <a href="?days=<?= $d ?>" class="btn btn-sm <?= $days==$d?'btn-primary':'btn-outline-secondary' ?>">
            <?= $d ?> <?= __('team.days','days') ?>
        </a>
        <?php endforeach; ?>
        <a href="/admin/team" class="btn btn-outline-secondary btn-sm ms-1">
            <i class="bi bi-arrow-right me-1"></i><?= __('actions.back','Back') ?>
        </a>
    </div>
</div>

<?php if(empty($teamStats)): ?>
<div class="card border-0 shadow-sm">
    <div class="card-body text-center py-5 text-muted">
        <i class="bi bi-people display-4 d-block mb-2 opacity-50"></i>
        <p class="mb-0"><?= __('team.no_confirmers','No confirmers yet') ?></p>
    </div>
</div>
<?php else: ?>
<div class="row g-4">
    <?php foreach($teamStats as $s):
        $rate=(float)($s['confirm_rate']??0);
        $rateColor=$rate>=70?'success':($rate>=40?'warning':'danger');
        $total=max(1,(int)$s['total']);
    ?>
    <div class="col-md-4">
        <div class="card border-0 shadow-sm h-100" style="border-top:3px solid var(--bs-<?= $rateColor ?>) !important">
            <div class="card-body">
                <div class="d-flex align-items-center gap-3 mb-4">
                    <div class="rounded-circle bg-success-subtle d-flex align-items-center justify-content-center flex-shrink-0"
                         style="width:48px;height:48px">
                        <i class="bi bi-person text-success fs-4"></i>
                    </div>
                    <div>
                        <div class="fw-bold"><a href="/admin/team/member/<?= (int)$s['id'] ?>?days=<?= (int)$days ?>" class="text-decoration-none"><?= htmlspecialchars($s['username']) ?></a></div>
                        <div class="text-muted small"><?= \Core\App\Models\TeamMemberModel::roleLabel($s['role']) ?></div>
                    </div>
                </div>
                <div class="row g-2 text-center mb-4">
                    <div class="col-4">
                        <div class="rounded-3 bg-success-subtle py-2">
                            <div class="fw-bold fs-4 text-success"><?= (int)$s['confirmed'] ?></div>
                            <div class="text-muted" style="font-size:.72rem"><?= __('team.confirmed','Confirmed') ?></div>
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="rounded-3 bg-danger-subtle py-2">
                            <div class="fw-bold fs-4 text-danger"><?= (int)$s['rejected'] ?></div>
                            <div class="text-muted" style="font-size:.72rem"><?= __('team.rejected','Rejected') ?></div>
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="rounded-3 bg-primary-subtle py-2">
                            <div class="fw-bold fs-4 text-primary"><?= (int)$s['total'] ?></div>
                            <div class="text-muted" style="font-size:.72rem"><?= __('team.total','Total') ?></div>
                        </div>
                    </div>
                </div>
                <div class="d-flex align-items-center gap-2 mb-1">
                    <div class="progress flex-grow-1" style="height:8px;border-radius:4px">
                        <div class="progress-bar bg-<?= $rateColor ?>" style="width:<?= $rate ?>%"></div>
                    </div>
                    <span class="fw-bold text-<?= $rateColor ?>"><?= $rate ?>%</span>
                </div>
                <div class="text-muted" style="font-size:.73rem"><?= __('team.confirm_rate','Confirm Rate') ?></div>
            </div>
        </div>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>

</div></section></div>
<?php include __DIR__ . '/../footer.php'; ?>
