<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TenantPilot Admin Consent</title>
    <style>
        body { font-family: sans-serif; max-width: 640px; margin: 2rem auto; padding: 1.5rem; line-height: 1.6; }
        .card { border: 1px solid #e2e8f0; border-radius: 12px; padding: 1.25rem; box-shadow: 0 8px 20px rgba(0,0,0,0.06); }
        .status { display: inline-block; padding: 0.35rem 0.75rem; border-radius: 999px; font-size: 0.9rem; }
        .ok { background: #dcfce7; color: #166534; }
        .error { background: #fee2e2; color: #991b1b; }
        .warning { background: #fef3c7; color: #92400e; }
        a { color: #2563eb; text-decoration: none; }
    </style>
</head>
<body>
    <div class="card">
        <h1>Admin Consent Status</h1>
        <p><strong>ManagedEnvironment:</strong> {{ $tenant->name }} ({{ $tenant->graphTenantId() }})</p>
        @isset($connection)
            <p><strong>Connection:</strong> {{ $connection->connection_type->value === 'platform' ? 'Platform connection' : 'Dedicated connection' }}</p>
            <p><strong>Verification state:</strong> {{ $verificationStateLabel ?? ucfirst($connection->verification_status->value) }}</p>
        @endisset
        <p>
            <span class="status {{ $status === 'ok' ? 'ok' : ($status === 'consent_denied' ? 'warning' : 'error') }}">
                Status: {{ ucfirst(str_replace('_', ' ', $status)) }}
            </span>
        </p>
        @if($error)
            <p><strong>Error:</strong> {{ $error }}</p>
        @elseif($consentGranted === false)
            <p>Admin consent was not granted. Review the connection state and try again.</p>
        @else
            <p>Admin consent was granted. Run verification again to confirm operational readiness.</p>
        @endif

        <p>
            @php
                $isOnboarding = in_array($tenant->status, [\App\Models\ManagedEnvironment::STATUS_DRAFT, \App\Models\ManagedEnvironment::STATUS_ONBOARDING], true);
                $backUrl = $isOnboarding
                    ? route('admin.onboarding')
                    : \App\Support\ManagedEnvironmentLinks::viewUrl($tenant);
                $backLabel = $isOnboarding ? 'Zurück zum Onboarding' : 'Zurück zur ManagedEnvironment-Detailseite';
            @endphp

            <a href="{{ $backUrl }}">
                {{ $backLabel }}
            </a>
        </p>
    </div>
</body>
</html>
