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

<x-ui.layout.page
    :title="__('custom_fields.title')"
    :subtitle="__('custom_fields.subtitle')"
    page-icon="fe fe-sliders"
    :breadcrumbs="$breadcrumbs"
>
    <x-ui.operational.index-shell>
        <x-slot:toolbar>
            <x-ui.operational.action-bar>
                <x-slot:primary>
                    <x-ui.operational.create-button
                        :href="route('settings.custom-fields.create')"
                        :label="__('custom_fields.actions.add')"
                        permission="custom_fields.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <x-ui.table.table :columns="[
            ['label' => __('custom_fields.fields.name')],
            ['label' => __('custom_fields.fields.slug')],
            ['label' => __('custom_fields.fields.field_type')],
            ['label' => __('custom_fields.fields.sort_order')],
            ['label' => __('custom_fields.fields.status')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '160px'],
        ]">
            @forelse ($fields as $field)
                <x-ui.table.row>
                    <td><strong>{{ $field->name }}</strong></td>
                    <td><code>{{ $field->slug }}</code></td>
                    <td>{{ __('custom_fields.types.'.$field->field_type) }}</td>
                    <td>{{ $field->sort_order }}</td>
                    <td>
                        <x-ui.operational.status-badge
                            :label="$field->is_active ? __('custom_fields.status.active') : __('custom_fields.status.inactive')"
                            :variant="$field->is_active ? 'success' : 'neutral'"
                        />
                    </td>
                    <td class="text-end">
                        <x-ui.action-modal.trigger
                            :entity="__('custom_fields.title')"
                            :record="$field->name"
                            :edit-url="auth()->user()?->can('custom_fields.update', $field) ? route('settings.custom-fields.edit', $field) : null"
                            :deactivate-url="$field->is_active && auth()->user()?->can('custom_fields.deactivate', $field) ? route('settings.custom-fields.deactivate', $field) : null"
                            :deactivate-hint="__('custom_fields.actions.deactivate_confirm')"
                        />
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="6" class="p-0">
                        <x-ui.operational.empty-state :title="__('custom_fields.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>
    </x-ui.operational.index-shell>
    <x-ui.action-modal />
</x-ui.layout.page>
