@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">
                        @can('custom_fields.update', $field)
                            <x-ui.buttons.secondary size="sm" :href="route('settings.custom-fields.edit', $field)" icon="fe fe-edit-2">
                                {{ __('custom_fields.actions.edit') }}
                            </x-ui.buttons.secondary>
                        @endcan
                        @can('custom_fields.deactivate', $field)
                            @if ($field->is_active)
                                <form method="POST" action="{{ route('settings.custom-fields.deactivate', $field) }}" class="d-inline"
                                    onsubmit="return confirm(@json(__('custom_fields.actions.deactivate_confirm')))">
                                    @csrf
                                    <x-ui.buttons.danger outline type="submit" size="sm" icon="fe fe-slash">
                                        {{ __('custom_fields.actions.deactivate') }}
                                    </x-ui.buttons.danger>
                                </form>
                            @endif
                        @endcan
                    </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.layout.page>
