<?= $this->extend('layouts/enterprise') ?>

<?= $this->section('content') ?>

<?php
$statusPill = static function (string $status): string {
    $map = ['draft' => 'default', 'published' => 'active'];
    $class = $map[$status] ?? 'inactive';

    return '<span class="enterprise-status-pill enterprise-status-pill--' . esc($class) . '">'
        . esc(ucfirst($status)) . '</span>';
};

$isDraft = ($score['status'] ?? '') === 'draft';
?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Operations',
    'workspaceCrumbCurrent' => $score['number'],
    'workspaceTitle'        => esc($score['number']),
    'workspaceDesc'         => esc($score['metric_name']),
]) ?>

<div class="row g-4">
    <div class="col-lg-8">
        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-chart-simple"></i>
                <h2 class="enterprise-settings-card__title">Score Information</h2>
            </div>
            <dl class="row mb-0 small">
                <dt class="col-sm-4 text-muted">Number</dt>
                <dd class="col-sm-8 fw-semibold"><?= esc($score['number']) ?></dd>
                <dt class="col-sm-4 text-muted">Status</dt>
                <dd class="col-sm-8"><?= $statusPill($score['status']) ?></dd>
                <dt class="col-sm-4 text-muted">Subject Type</dt>
                <dd class="col-sm-8"><?= esc(ucwords(str_replace('_', ' ', $score['subject_type']))) ?></dd>
                <dt class="col-sm-4 text-muted">Subject ID</dt>
                <dd class="col-sm-8"><?= (int) $score['subject_id'] ?></dd>
                <dt class="col-sm-4 text-muted">Subject Label</dt>
                <dd class="col-sm-8"><?= esc($score['subject_label'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Metric Code</dt>
                <dd class="col-sm-8"><code><?= esc($score['metric_code']) ?></code></dd>
                <dt class="col-sm-4 text-muted">Metric Name</dt>
                <dd class="col-sm-8"><?= esc($score['metric_name']) ?></dd>
                <dt class="col-sm-4 text-muted">Score</dt>
                <dd class="col-sm-8"><?= esc($score['score']) ?> / <?= esc($score['max_score']) ?></dd>
                <dt class="col-sm-4 text-muted">Period</dt>
                <dd class="col-sm-8">
                    <?= esc($score['period_start'] ?: '—') ?> → <?= esc($score['period_end'] ?: '—') ?>
                </dd>
                <dt class="col-sm-4 text-muted">Scored By</dt>
                <dd class="col-sm-8"><?= esc($score['scored_by_name'] ?? '—') ?></dd>
                <dt class="col-sm-4 text-muted">Notes</dt>
                <dd class="col-sm-8"><?= nl2br(esc($score['notes'] ?: '—')) ?></dd>
            </dl>
        </article>
    </div>

    <div class="col-lg-4">
        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-bolt"></i>
                <h2 class="enterprise-settings-card__title">Actions</h2>
            </div>
            <div class="d-grid gap-2">
                <?php if ($isDraft): ?>
                    <a href="<?= base_url('operations/quality-control/performance-scores/' . $score['id'] . '/edit') ?>" class="btn btn-outline-primary btn-sm">
                        <i class="fa-solid fa-pen me-1"></i> Edit
                    </a>
                    <form action="<?= base_url('operations/quality-control/performance-scores/' . $score['id'] . '/publish') ?>" method="post"
                          onsubmit="return confirm('Publish this performance score?');">
                        <?= csrf_field() ?>
                        <button type="submit" class="btn btn-primary btn-sm w-100">
                            <i class="fa-solid fa-upload me-1"></i> Publish
                        </button>
                    </form>
                    <form action="<?= base_url('operations/quality-control/performance-scores/' . $score['id'] . '/delete') ?>" method="post"
                          onsubmit="return confirm('Delete this score permanently?');">
                        <?= csrf_field() ?>
                        <button type="submit" class="btn btn-outline-danger btn-sm w-100">
                            <i class="fa-solid fa-trash me-1"></i> Delete
                        </button>
                    </form>
                <?php endif; ?>
                <a href="<?= base_url('operations/quality-control/performance-scores') ?>" class="btn btn-outline-secondary btn-sm">Back to Scores</a>
            </div>
        </article>
    </div>
</div>

<?= $this->endSection() ?>
