@props([
    'action',
    'method' => 'POST',
    'translation' => null,
    'languages',
    'submitLabel',
])

@php
    $localeOptions = $languages->pluck('code', 'code')->all();
@endphp

<form method="POST" action="{{ $action }}" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-6">
                    <x-ui.form.input
                        name="key"
                        :label="__('translations.fields.key')"
                        :value="$translation?->key"
                        :placeholder="__('translations.placeholders.key')"
                        required
                    />
                </div>

                <div class="col-md-3">
                    <x-ui.form.input
                        name="group"
                        :label="__('translations.fields.group')"
                        :value="$translation?->group"
                        :placeholder="__('translations.placeholders.group')"
                    />
                </div>

                <div class="col-md-3">
                    <x-ui.form.select
                        name="locale"
                        :label="__('translations.fields.locale')"
                        :options="$localeOptions"
                        :selected="$translation?->locale"
                        :placeholder="__('translations.placeholders.locale')"
                        required
                    />
                </div>

                <div class="col-12">
                    @php
                        $errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag();
                        $valueError = $errorBag->first('value');
                        $valueCurrent = old('value', $translation?->value);
                    @endphp
                    <label for="value" class="form-label">
                        {{ __('translations.fields.value') }} <span class="text-danger">*</span>
                    </label>
                    <textarea
                        id="value" name="value" rows="4" required
                        @class(['form-control', 'is-invalid' => $valueError])
                    >{{ $valueCurrent }}</textarea>
                    @if ($valueError)
                        <div class="invalid-feedback d-block">{{ $valueError }}</div>
                    @endif
                </div>
            </div>
        </div>

        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('settings.translations.index')">
                {{ __('common.cancel') }}
            </x-ui.buttons.secondary>
            <x-ui.buttons.primary type="submit" icon="fe fe-save">
                {{ $submitLabel }}
            </x-ui.buttons.primary>
        </div>
    </div>
</form>
