@extends('admin.layouts.container')

@section('content')
    <div class="side-title">
        <h3>{{$head ?? '' }}</h3>
    </div>
    <div class="border-item">
        <form class="form-row" onsubmit="saveForm(this)" method="post" action="{{ $action }}">
            @if($gallery ?? ''  && $gallery->id)
                @method('PUT')
            @endif
            @csrf

            <div class="form-group col-lg-6 arob">
                <label>{{ meta('status', getCurrentLocale()) ?? __('galleries.status') }} </label>
                <select onchange="selectStatus(this)" id="status" class="form-control {{ $errors->has('status') ? 'is-invalid' : '' }}" name="status" >
                    @foreach($statuses as $row)
                        <option {{ ($gallery->status ?? null ) == $row ? 'selected' : ''  }} value="{{$row}}">{{__('galleries.statuses.'.$row)}}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-6 type_{{$linkType}}" >
                <label>{{ meta('link', getCurrentLocale()) ?? __('galleries.link') }} </label>
                <input type="url" class="form-control {{ $errors->has('link') ? 'is-invalid' : '' }}" name="link" placeholder="{{ meta('link', getCurrentLocale()) ?? __('galleries.link') }}" value='{{ old("link", $gallery->link ?? "") }}'/>
            </div>

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

            @endforeach


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

@section('inner_js')
    <!-- Editor JS services -->
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
    <script>
        function selectStatus()
        {
            let status = $('#status').val()

            if(status == "{{$videoType}}")
            {
                $('.type_'+"{{$linkType}}").hide()
                $('.type_'+"{{$videoType}}").show()
            }
            else if(status == "{{$imageType}}")
            {
                $('.type_'+"{{$videoType}}").hide()
                $('.type_'+"{{$linkType}}").hide()
            }
            else
            {
                $('.type_'+"{{$videoType}}").hide()
                $('.type_'+"{{$linkType}}").show()
            }
        }
        $('#status').trigger('change');
    </script>
    <script>
        let currentLanguage = "{{getCurrentLocale()}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
@endsection

@endsection
