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

<x-ui.layout.page
    :title="__('activity_logs.title')"
    :subtitle="__('activity_logs.subtitle')"
    page-icon="fe fe-activity"
    :breadcrumbs="$breadcrumbs"
>
    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <form method="get" action="{{ route('admin.activity-logs.index') }}" class="row g-3 align-items-end">
                <div class="col-md-4">
                    <x-ui.form.search-select
                        name="tenant_id"
                        :label="__('activity_logs.filters.tenant')"
                        :options="$tenantOptions"
                        :selected="request('tenant_id')"
                        :placeholder="__('activity_logs.filters.all')"
                        optional
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="module"
                        :label="__('activity_logs.filters.module')"
                        :options="$moduleOptions"
                        :selected="request('module')"
                        :placeholder="__('activity_logs.filters.all')"
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.select
                        name="action"
                        :label="__('activity_logs.filters.action')"
                        :options="$actionOptions"
                        :selected="request('action')"
                        :placeholder="__('activity_logs.filters.all')"
                    />
                </div>
                <div class="col-md-2 d-flex gap-2">
                    <x-ui.buttons.primary type="submit" icon="fe fe-filter" class="flex-grow-1">
                        {{ __('activity_logs.filters.apply') }}
                    </x-ui.buttons.primary>
                    <x-ui.buttons.secondary :href="route('admin.activity-logs.index')" icon="fe fe-x" class="flex-shrink-0">
                        {{ __('activity_logs.filters.clear') }}
                    </x-ui.buttons.secondary>
                </div>
            </form>
        </div>
    </div>

    <x-ui.table.table :columns="[
        ['label' => __('activity_logs.columns.created_at')],
        ['label' => __('activity_logs.columns.tenant')],
        ['label' => __('activity_logs.columns.user')],
        ['label' => __('activity_logs.columns.module')],
        ['label' => __('activity_logs.columns.action')],
        ['label' => __('activity_logs.columns.entity')],
        ['label' => __('activity_logs.columns.description')],
    ]">
        @forelse ($logs as $log)
            <x-ui.table.row>
                <td class="text-nowrap">{{ $log->created_at?->format('Y-m-d H:i') }}</td>
                <td>{{ $log->tenant?->name ?? '—' }}</td>
                <td>{{ $log->user?->email ?? '—' }}</td>
                <td><code>{{ $log->module }}</code></td>
                <td><span class="badge bg-secondary-subtle text-secondary">{{ $log->action }}</span></td>
                <td>
                    <small class="text-muted">{{ class_basename($log->entity_type) }}</small>
                    @if ($log->entity_id !== null)
                        <span class="text-muted">#{{ $log->entity_id }}</span>
                    @endif
                </td>
                <td>{{ $log->description }}</td>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="7" class="text-center text-muted py-4">
                    {{ __('activity_logs.empty') }}
                </td>
            </x-ui.table.row>
        @endforelse
    </x-ui.table.table>

    <div class="mt-3">
        {{ $logs->links() }}
    </div>

    <x-ui.modal.actions />
</x-ui.layout.page>
