@php
    $c = config('theme.colors');
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('admin.title'), 'url' => route('admin.dashboard')],
        ['label' => __('tenants.title'), 'url' => route('admin.tenants.index')],
        ['label' => $tenant->name],
        ['label' => __('operations.tenant_diagnostics_title')],
    ];
@endphp

<x-ui.layout.page
    :title="__('operations.tenant_diagnostics_title')"
    :subtitle="__('operations.tenant_diagnostics_subtitle')"
    page-icon="fe fe-activity"
    :breadcrumbs="$breadcrumbs"
>
    <div class="row row-cards">
        <div class="col-12">
            <div class="card mb-3">
                <div class="card-header"><h3 class="card-title" style="color: {{ $c['text'] }}">Snapshot</h3></div>
                <div class="card-body">
                    <pre class="small mb-0" style="white-space: pre-wrap">{{ json_encode($snapshot, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card mb-3">
                <div class="card-header"><h3 class="card-title" style="color: {{ $c['text'] }}">{{ __('operations.impersonation') }}</h3></div>
                <div class="card-body">
                    <p class="text-muted small">{{ __('operations.impersonation_hint') }}</p>
                    <form method="post" action="{{ route('admin.operations.impersonations.store') }}" class="d-grid gap-2">
                        @csrf
                        <input type="hidden" name="tenant_id" value="{{ $tenant->id }}">
                        <label class="form-label">Target user ID</label>
                        <input class="form-control" type="number" name="target_user_id" required min="1">
                        <label class="form-label">{{ __('tenant_lifecycle.reason') }}</label>
                        <textarea class="form-control" name="reason" rows="3" required></textarea>
                        <x-ui.buttons.primary type="submit">{{ __('operations.impersonation_start') }}</x-ui.buttons.primary>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card mb-3">
                <div class="card-header"><h3 class="card-title" style="color: {{ $c['text'] }}">{{ __('operations.billing_failure') }}</h3></div>
                <div class="card-body">
                    <form method="post" action="{{ route('admin.tenants.billing.failed-payment', $tenant) }}" class="d-grid gap-2">
                        @csrf
                        <textarea class="form-control" name="reason" rows="3" required placeholder="Reason"></textarea>
                        <input class="form-control" name="reference" placeholder="External reference (optional)">
                        <x-ui.buttons.primary type="submit">{{ __('common.save') }}</x-ui.buttons.primary>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <x-ui.buttons.secondary :href="route('admin.tenants.edit', $tenant)">{{ __('common.back') }}</x-ui.buttons.secondary>
</x-ui.layout.page>
