@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 }}" enctype="multipart/form-data">
        <input type="hidden" name="user_id" value="{{auth()->id()}}">
        @if($article ?? ''  && $article->id)
            @method('PUT')
        @endif
        @csrf

        <div class="form-group col-lg-12">
            <label>{{ meta('category_id', getCurrentLocale()) ?? __('articles.category') }}</label>
            <select name="category_id" id="category_id" class="form-control my-editor {{ $errors->has('category_id') ? 'is-invalid' : '' }}">
                <option value="">{{meta('category_id', getCurrentLocale()) ?? __('articles.category')}}</option>
                @foreach (articleCategories() as $category)
                    <option {{old("category_id", $article->category_id ?? "") == $category->id ? 'selected': ''}} value="{{$category->id}}">{{descriptions($category)->name ?? ''}}</option>
                @endforeach
            </select>
        </div>

        @foreach(languages() as $language)
        <div class="form-group col-lg-6">
            <label>{{ meta('title', $language->local) ?? __('articles.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) ?? __('articles.title') }}" value='{{ old("title_{$language->local}", $article[$language->local]->title ?? "") }}'/>
        </div>

        <div class="form-group col-lg-6">
            <label>{{ meta('slug', $language->local) ?? __('articles.slug') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
            <input type="text" class="form-control {{ $errors->has('slug_'.$language->local) ? 'is-invalid' : '' }}" name="slug_{{ $language->local }}" placeholder="{{ meta('slug', $language->local) ?? __('articles.slug')}}" value='{{ old("slug_{$language->local}", $article[$language->local]->slug ?? "") }}'/>
        </div>

        <div class="form-group col-lg-12">
            <label>{{ meta('keywords', $language->local) ?? __('articles.keywords')}} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
            <input type="text" class="form-control {{ $errors->has('keywords_'.$language->local) ? 'is-invalid' : '' }}" name="keywords_{{ $language->local }}" placeholder="{{ meta('keywords', $language->local) ?? __('articles.keywords')}}" value='{{ old("keywords_{$language->local}", $article[$language->local]->keywords ?? "") }}'/>

        </div>

        <div class="form-group col-lg-12">
            <label>{{ meta('meta_description', $language->local) ?? __('articles.meta_description')}} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
            <input type="text" class="form-control {{ $errors->has('meta_description_'.$language->local) ? 'is-invalid' : '' }}" name="meta_description_{{ $language->local }}" placeholder="{{ meta('meta_description', $language->local) ?? __('articles.meta_description')}}" value='{{ old("meta_description_{$language->local}", $article[$language->local]->meta_description ?? "") }}'/>
        </div>

        <div class="form-group col-lg-12">
            <label>{{ meta('description', $language->local) ?? __('articles.description')}} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
            <textarea name="description_{{ $language->local }}" class="form-control my-editor {{ $errors->has('description_'.$language->local) ? 'is-invalid' : '' }}" placeholder="{{ meta('description', $language->local) ?? __('articles.description')}}">{{ old("description_{$language->local}", $article[$language->local]->description ?? "") }}</textarea>
        </div>

        @endforeach

        <div class="border-item photos col-md-12 other_image_container">
            <div class="row">
                @if ($article ?? false)
                    @foreach ($article['photos'] as $photo)
                        <div class="col-md-4">
                            <div class="items">
                                <div class="img">
                                    <a href="{{ asset($photo->image ?? '')}}" data-fancybox="gallery"><img src="{{ asset($photo->image ?? '')}}" alt=""></a>
                                </div>
                                <input type="hidden" name="images[]" value="{{ $photo->image ?? "" }}">
                                <a href="#" class="close"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    @endforeach
                @endif
            </div>
            <div class="text-center">
                <input id="other_image_thumbnail" class="other_image_thumbnail" type="hidden"/>
                <div class="clearfix"></div>
                <span id="add">
                    <a id="lfm" data-width="" data-cache="article_gallery" data-input=".other_image_thumbnail" data-preview="" data-show="" data-hide="" class="lfm add">
                        Add New Item
                    </a>
                </span>
            </div>
        </div>
        {{--End image container--}}

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

@endsection

@section('inner_js')
    <!-- Editor JS files -->
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
{{--        <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>--}}
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}",
            inputName = "";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
    <script src="{{ asset('assets/admin/js/articles.js') }}"></script>
@endsection



