@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('admin.title')],
        ['label' => __('admin.dashboard')],
    ];

    $cards = [
        [
            'label' => __('modules.title'),
            'value' => $stats['modules'],
            'icon' => 'fe fe-grid',
            'href' => route('admin.modules.index'),
        ],
        [
            'label' => __('plans.title'),
            'value' => $stats['plans'],
            'icon' => 'fe fe-package',
            'href' => route('admin.plans.index'),
        ],
        [
            'label' => __('tenants.title'),
            'value' => $stats['tenants'],
            'icon' => 'fe fe-users',
            'href' => route('admin.tenants.index'),
        ],
        [
            'label' => __('admin.active_subscriptions'),
            'value' => $stats['active_subscriptions'],
            'icon' => 'fe fe-check-circle',
            'href' => null,
        ],
    ];
@endphp

<x-ui.layout.page
    :title="__('admin.dashboard')"
    :subtitle="__('admin.dashboard_subtitle')"
    page-icon="fe fe-sliders"
    :breadcrumbs="$breadcrumbs"
>
    <div class="row g-3 mb-4">
        @foreach ($cards as $card)
            <div class="col-sm-6 col-xl-3">
                <div class="card h-100">
                    <div class="card-body d-flex align-items-center justify-content-between">
                        <div>
                            <div class="text-muted small">{{ $card['label'] }}</div>
                            <div class="fs-3 fw-semibold">{{ number_format($card['value']) }}</div>
                        </div>
                        <div class="fs-3 text-primary">
                            <i class="{{ $card['icon'] }}"></i>
                        </div>
                    </div>
                    @if ($card['href'])
                        <a href="{{ $card['href'] }}" class="card-footer text-decoration-none small">
                            {{ __('common.view_all') }} <i class="fe fe-arrow-right"></i>
                        </a>
                    @endif
                </div>
            </div>
        @endforeach
    </div>

    <x-ui.table.table :columns="[
        ['label' => __('tenants.fields.name')],
        ['label' => __('tenants.fields.plan')],
        ['label' => __('tenants.fields.status')],
        ['label' => __('common.created_at')],
    ]">
        @forelse ($latestTenants as $tenant)
            <x-ui.table.row>
                <td><strong>{{ $tenant->name }}</strong></td>
                <td>{{ $tenant->plan?->name ?? '—' }}</td>
                <td>
                    @if ($tenant->is_active)
                        <span class="badge bg-success">{{ __('common.active') }}</span>
                    @else
                        <span class="badge bg-secondary">{{ __('common.inactive') }}</span>
                    @endif
                </td>
                <td>{{ $tenant->created_at->format('Y-m-d') }}</td>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="4" class="text-center text-muted py-4">
                    {{ __('tenants.empty') }}
                </td>
            </x-ui.table.row>
        @endforelse
    </x-ui.table.table>
</x-ui.layout.page>
