@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($news) && ($news->id ?? false))
                @method('PUT')
            @endif
            @csrf

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

            <div class="form-group col-lg-6">
                <label>{{ __('news.image') }}</label>
                <input id="old_image" type="hidden" name="old_image" value="{{ optional($news ?? null)->image }}">
                <input type="file" class="form-control {{ $errors->has('image') ? 'is-invalid' : '' }}" name="image" accept="image/*">
                @if(optional($news ?? null)->image && optional($news ?? null)->image_url)
                    <a href="{{ optional($news)->image_url }}" class="btn btn-primary mt-2" target="_blank"><i class="fas fa-download"></i></a>
                @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
