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

<x-ui.layout.page
    :title="__('modules.title')"
    :subtitle="__('modules.subtitle')"
    page-icon="fe fe-grid"
    :breadcrumbs="$breadcrumbs"
>
    <x-slot:actions>
        @can('modules.create')
            <x-ui.buttons.primary :href="route('admin.modules.create')" icon="fe fe-plus">
                {{ __('modules.actions.add') }}
            </x-ui.buttons.primary>
        @endcan
    </x-slot:actions>

    <x-ui.table.table :columns="[
        ['label' => __('modules.fields.name')],
        ['label' => __('modules.fields.slug')],
        ['label' => __('modules.fields.description')],
        ['label' => __('modules.fields.status')],
        ['label' => __('common.actions'), 'align' => 'end', 'width' => '120px'],
    ]">
        @forelse ($modules as $module)
            <x-ui.table.row>
                <td><strong>{{ $module->name }}</strong></td>
                <td><code>{{ $module->slug }}</code></td>
                <td class="text-muted">{{ $module->description ?? '—' }}</td>
                <td>
                    @if ($module->is_active)
                        <span class="badge bg-success">{{ __('common.active') }}</span>
                    @else
                        <span class="badge bg-secondary">{{ __('common.inactive') }}</span>
                    @endif
                </td>
                <td class="text-end">
                    <x-ui.table.actions-trigger
                        :type="__('modules.singular')"
                        :id="$module->id"
                        :view-href="auth()->user()?->can('modules.update', $module) ? route('admin.modules.edit', $module) : null"
                        :delete-url="auth()->user()?->can('modules.delete', $module) ? route('admin.modules.destroy', $module) : null"
                    />
                </td>
            </x-ui.table.row>
        @empty
            <x-ui.table.row>
                <td colspan="5" class="text-center text-muted py-4">
                    {{ __('modules.empty') }}
                </td>
            </x-ui.table.row>
        @endforelse
    </x-ui.table.table>

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