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

    $groupOptions = collect($groups)->mapWithKeys(fn ($g) => [$g => $g])->all();
    $localeOptions = $languages->pluck('code', 'code')->all();
@endphp

<x-ui.layout.page
    :title="__('translations.title')"
    :subtitle="__('translations.subtitle')"
    page-icon="fe fe-message-square"
    :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.translations.create')"
                        :label="__('translations.actions.add')"
                        permission="translations.create"
                    />
                </x-slot:primary>
            </x-ui.operational.action-bar>
        </x-slot:toolbar>

        <form method="GET" class="card mb-4 border-0 shadow-sm">
            <div class="card-body">
                <div class="row g-3 align-items-end">
                    <div class="col-md-3">
                        <x-ui.form.select
                            name="group"
                            :label="__('translations.fields.group')"
                            :options="$groupOptions"
                            :selected="$filters['group'] ?? null"
                            :placeholder="__('translations.filters.all_groups')"
                        />
                    </div>
                    <div class="col-md-3">
                        <x-ui.form.select
                            name="locale"
                            :label="__('translations.fields.locale')"
                            :options="$localeOptions"
                            :selected="$filters['locale'] ?? null"
                            :placeholder="__('translations.filters.all_locales')"
                        />
                    </div>
                    <div class="col-md-4">
                        <x-ui.form.input
                            name="q"
                            :label="__('translations.filters.search')"
                            :value="$filters['q'] ?? null"
                            :placeholder="__('translations.filters.search_placeholder')"
                        />
                    </div>
                    <div class="col-md-2 d-grid">
                        <x-ui.buttons.primary type="submit" icon="fe fe-filter">
                            {{ __('translations.actions.filter') }}
                        </x-ui.buttons.primary>
                    </div>
                </div>
            </div>
        </form>

        <x-ui.table.table :columns="[
            ['label' => __('translations.fields.key')],
            ['label' => __('translations.fields.group'), 'width' => '160px'],
            ['label' => __('translations.fields.locale'), 'width' => '90px', 'align' => 'center'],
            ['label' => __('translations.fields.value')],
            ['label' => __('common.actions'), 'align' => 'end', 'width' => '150px'],
        ]">
            @forelse ($translations as $translation)
                <x-ui.table.row>
                    <td><code>{{ $translation->key }}</code></td>
                    <td>
                        <x-ui.operational.status-badge :label="$translation->group" variant="neutral" />
                    </td>
                    <td class="text-center"><code class="text-uppercase">{{ $translation->locale }}</code></td>
                    <td>{{ \Illuminate\Support\Str::limit($translation->value, 80) }}</td>
                    <td class="text-end">
                        @include('pages.settings.translations._row_actions', ['translation' => $translation])
                    </td>
                </x-ui.table.row>
            @empty
                <x-ui.table.row>
                    <td colspan="5" class="p-0">
                        <x-ui.operational.empty-state :title="__('translations.empty')" />
                    </td>
                </x-ui.table.row>
            @endforelse
        </x-ui.table.table>

        <x-slot:pagination>
            {{ $translations->links() }}
        </x-slot:pagination>
    </x-ui.operational.index-shell>
</x-ui.layout.page>
