@extends('admin.layouts.container')

@section('content')
    <div class="side-title">
        <h3>{{ $head ?? '' }}</h3>
    </div>

    <div class="border-item">
        <form class="form-row" method="post" action="{{ $action }}" onsubmit="saveForm(this)"
            enctype="multipart/form-data">
            @if (isset($banner) && ($banner->id ?? false))
                @method('PUT')
            @endif
            @csrf

            @foreach ($languages as $language)
                <div class="form-group col-lg-6">
                    <label>{{ __('banners.title') }} {{ count($languages) > 1 ? "({$language->name})" : '' }}</label>
                    <input type="text" name="title_{{ $language->local }}"
                        class="form-control {{ $errors->has('title_' . $language->local) ? 'is-invalid' : '' }}"
                        value="{{ old('title_' . $language->local, data_get($banner ?? null, $language->local . '.title')) }}"
                        maxlength="60" required>
                    <small class="form-text text-muted">{{ __('banners.title_limit') }}</small>
                </div>
                <div class="form-group col-lg-6">
                    <label>{{ __('banners.description') }} {{ count($languages) > 1 ? "({$language->name})" : '' }}</label>
                    <textarea name="description_{{ $language->local }}"
                        class="form-control {{ $errors->has('description_' . $language->local) ? 'is-invalid' : '' }}"
                        placeholder="{{ __('banners.description') }}" maxlength="180" required>{{ old('description_' . $language->local, data_get($banner ?? null, $language->local . '.description')) }}</textarea>
                    <small class="form-text text-muted">{{ __('banners.description_limit') }}</small>
                </div>
            @endforeach

            <div class="form-group col-lg-6">
                <label>{{ __('banners.image') }}</label>
                <input type="hidden" name="old_image" value="{{ optional($banner ?? null)->image }}">
                <input type="file" name="image" class="form-control {{ $errors->has('image') ? 'is-invalid' : '' }}"
                    accept="image/*" {{ isset($banner) ? '' : 'required' }}>
                @if (optional($banner ?? null)->image_url)
                    <div class="mt-2">
                        <img src="{{ optional($banner ?? null)->image_url }}" alt="banner" width="200">
                    </div>
                @endif
            </div>

            <div class="text-center mt-5 col-12">
                <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
            </div>
        </form>
    </div>
@endsection

@section('inner_js')
@endsection
