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

            <div class="form-group col-lg-4 hotel_selection">
                <label>{{ meta('hotel_id', $lang) ?? __('hotels.hotel_id') }}</label>
                <select name="hotel_id" class="form-control hotel_id {{ $errors->has('hotel_id') ? 'is-invalid' : '' }}">
                    <option value="">{{ meta('hotel_id', $lang) ?? __('hotels.hotel_id') }}</option>
                    @foreach ($hotels as $parentHotel)
                        @if(($hotel->id ?? null) == $parentHotel->id) @continue @endif
                        <option {{old("hotel_id", $hotel->hotel_id ?? "") == $parentHotel->id ? 'selected': ''}} value="{{$parentHotel->id}}">{{$hotels->room_name ?? ''}}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-4 hotel_details">
                <label>{{ meta('category_id', $lang) ?? __('hotels.category_id') }}</label>
                <select name="category_id" id="category_id" class="form-control {{ $errors->has('category_id') ? 'is-invalid' : '' }}">
                    <option value="">{{meta('category_id', $lang) ?? __('hotels.category')}}</option>
                    @foreach ($categories as $category)
                        <option {{old("category_id", $hotel->category_id ?? "") == $category->id ? 'selected': ''}} value="{{$category->id}}">{{$category->name ?? ''}}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-4 hotel_details">
                <label>{{ meta('distance_from_haram', $lang) ?? __('hotels.distance_from_haram') }} </label>
                <input type="number" min="1" class="form-control {{ $errors->has('distance_from_haram') ? 'is-invalid' : '' }}" name="distance_from_haram" placeholder="{{ meta('distance_from_haram', $lang) ?? __('hotels.distance_from_haram') }}" value='{{ old("distance_from_haram", $hotel->distance_from_haram ?? "") }}'/>
            </div>

            <div class="form-group col-lg-3 hotel_details">
                <label>{{ meta('floors_number', $lang) ?? __('hotels.floors_number') }} </label>
                <input type="number" min="1" class="form-control {{ $errors->has('floors_number') ? 'is-invalid' : '' }}" name="floors_number" placeholder="{{ meta('floors_number', $lang) ?? __('hotels.floors_number') }}" value='{{ old("floors_number", $hotel->floors_number ?? "") }}'/>
            </div>

            <div class="form-group col-lg-3 hotel_details">
                <label>{{ meta('rooms_number', $lang) ?? __('hotels.rooms_number') }} </label>
                <input type="number" min="1" class="form-control {{ $errors->has('rooms_number') ? 'is-invalid' : '' }}" name="rooms_number" placeholder="{{ meta('rooms_number', $lang) ?? __('hotels.rooms_number') }}" value='{{ old("rooms_number", $hotel->rooms_number ?? "") }}'/>
            </div>

            <div class="form-group col-lg-3 hotel_details">
                <label>{{ meta('beds_number', $lang) ?? __('hotels.beds_number') }} </label>
                <input type="number" min="1" class="form-control {{ $errors->has('beds_number') ? 'is-invalid' : '' }}" name="beds_number" placeholder="{{ meta('beds_number', $lang) ?? __('hotels.beds_number') }}" value='{{ old("beds_number", $hotel->beds_number ?? "") }}'/>
            </div>

            <div class="form-group col-lg-3 hotel_details">
                <label>{{ meta('phone', $lang) ?? __('hotels.phone') }} </label>
                <input type="tel" class="form-control {{ $errors->has('phone') ? 'is-invalid' : '' }}" name="phone" placeholder="{{ meta('phone', $lang) ?? __('hotels.phone') }}" value='{{ old("phone", $hotel->phone ?? "") }}'/>
            </div>

            <div class="form-group col-lg-12 hotel_details">
                <label>{{ meta('map', $lang) ?? __('hotels.map') }} </label>
                <input type="text" class="form-control {{ $errors->has('map') ? 'is-invalid' : '' }}" name="map" placeholder="{{ meta('map', $lang) ?? __('hotels.map') }}" value='{{ old("map", $hotel->map ?? "") }}'/>
            </div>



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

                <div class="form-group col-lg-6 hotel_details">
                    <label>{{ meta('slug', $language->local) ?? __('hotels.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) ?? __('hotels.slug')}}" value='{{ old("slug_{$language->local}", $hotel[$language->local]->slug ?? "") }}'/>
                </div>

                <div class="form-group col-lg-12 hotel_details">
                    <label>{{ meta('keywords', $language->local) ?? __('hotels.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) ?? __('hotels.keywords')}}" value='{{ old("keywords_{$language->local}", $hotel[$language->local]->keywords ?? "") }}'/>

                </div>

                <div class="form-group col-lg-12 hotel_details">
                    <label>{{ meta('meta_description', $language->local) ?? __('hotels.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) ?? __('hotels.meta_description')}}" value='{{ old("meta_description_{$language->local}", $hotel[$language->local]->meta_description ?? "") }}'/>
                </div>

                <div class="form-group col-lg-12 hotel_details">
                    <label>{{ meta('description', $language->local) ?? __('hotels.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) ?? __('hotels.description')}}">{{ old("description_{$language->local}", $hotel[$language->local]->description ?? "") }}</textarea>
                </div>

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

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

            @endforeach

            <div class="border-item photos col-md-12 other_image_container">
                <div class="row">
                    @if ($hotel ?? false)
                        @foreach ($hotel['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-cache="photo_gallery" data-width="" 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 = "{{$lang}}",
            imagePath = "{{asset('')}}",
            inputName = null,
            imageTitle = null;
    </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/photos.js') }}"></script>

    <script>

        if ($('.hotel_id option:selected').val() !== ''){
            let hotelDetails = $('.hotel_details');
            hotelDetails.addClass('d-none');
            hotelDetails.children('input').val('');
            $('.hotel_selection').toggleClass(' col-lg-4 col-md-12')
        }

        $(document).ready(function () {

            $('.hotel_id').change(function () {
                let hotelDetails = $('.hotel_details'), hotel_selection = $('.hotel_selection');
                if ($(this).val() !== ''){
                    hotelDetails.addClass('d-none');
                    hotelDetails.children('input').val('');
                    hotel_selection.removeClass('col-lg-4');
                    hotel_selection.addClass('col-md-12');
                } else {
                    hotelDetails.removeClass('d-none');
                    hotel_selection.addClass('col-lg-4');
                    hotel_selection.removeClass('col-md-12');

                }


            })
        });
    </script>

@endsection



