<?php $__env->startSection('content'); ?>
    <div class="side-title">
        <h3><?php echo e($head ?? ''); ?></h3>
    </div>

    <div class="border-item">
        <form class="form-row add_package_form" method="post" action="<?php echo e($action); ?>" enctype="multipart/form-data" autocomplete="off">
            <?php if($package ?? ''  && $package->id): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>
            <?php echo csrf_field(); ?>

            <div class="form-group col-lg-3">
                <label><?php echo e(meta('package_type', $local) ?? __('packages.package_type')); ?> </label>
                <select name="package_type" class="form-control">

                    <option <?php echo e(($package->package_type) == 'u' ? 'selected' : ''); ?> value="u"><?php echo e(__('packages.u')); ?></option>
                    <option <?php echo e(($package->package_type) == 'ut' ? 'selected' : ''); ?> value="ut"><?php echo e(__('packages.ut')); ?></option>
                    <option <?php echo e(($package->package_type) == 'uta' ? 'selected' : ''); ?> value="uta"><?php echo e(__('packages.uta')); ?></option>
                </select>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('package_date', $local) ?? __('packages.package_date')); ?> </label>
                <input type="date" class="form-control <?php echo e($errors->has('package_date') ? 'is-invalid' : ''); ?>" name="package_date" placeholder="<?php echo e(meta('package_date', $local) ?? __('packages.package_date')); ?>" value='<?php echo e(old("package_date", $package->package_date ?? "")); ?>' <?php echo e(($package->email ?? null)); ?>/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('price_per_person', $local) ?? __('packages.price_per_person')); ?> </label>
                <input type="number" min="1" class="form-control <?php echo e($errors->has('price_per_person') ? 'is-invalid' : ''); ?>" name="price_per_person" placeholder="<?php echo e(meta('price_per_person', $local) ?? __('packages.price_per_person')); ?>" value='<?php echo e(old("price_per_person", $package->price_per_person ?? "")); ?>' <?php echo e(($package->email ?? null)); ?>/>
            </div>
            <div class="form-group col-lg-3">
                <label><?php echo e(meta('status', $local) ?? __('packages.status')); ?> </label>
                <select name="status" class="form-control <?php echo e($errors->has('status') ? 'is-invalid' : ''); ?>">
                    <option <?php echo e(old('status', $package->status ?? null) == 1 ? 'selected' : ''); ?> value="1"><?php echo e(__('packages.active')); ?></option>
                    <option <?php echo e(old('status', $package->status ?? null) == '0' ? 'selected' : ''); ?> value="0"><?php echo e(__('packages.non_active')); ?></option>
                </select>
            </div>

            <div class="form-group col-lg-6 show_both <?php echo e(in_array(($package->package_type ?? null), ['ut', 'uta']) ? '' : 'd-none'); ?>">
                <label><?php echo e(meta('departure_city', $local) ?? __('packages.departure_city')); ?> </label>
                <select name="departure_city" class="form-control">
                    <option value=""><?php echo e(meta('departure_city', $local) ?? __('packages.departure_city')); ?></option>
                    <?php if(count($cities)): ?>
                        <?php $__currentLoopData = $cities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $city): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option <?php echo e(($package->departure_city ?? null) == $city->id ? 'selected': ''); ?> value="<?php echo e($city->id); ?>"><?php echo e($city->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </select>
            </div>

            <div class="form-group col-lg-6 show_both <?php echo e(in_array(($package->package_type ?? null), ['ut', 'uta']) ? '' : 'd-none'); ?>">
                <label><?php echo e(meta('arrival_city', $local) ?? __('packages.arrival_city')); ?> </label>
                <select name="arrival_city" class="form-control">
                    <?php if(in_array(($package->package_type ?? null), ['ut', 'uta'])): ?>
                        <?php if(count($cities)): ?>
                            <?php $__currentLoopData = $cities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $city): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($city->id == $package->departure_city): ?> <?php continue; ?> <?php endif; ?>
                                <option <?php echo e(($package->arrival_city ?? null) == $city->id ? 'selected': ''); ?> value="<?php echo e($city->id); ?>"><?php echo e($city->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                        <?php else: ?>
                        <option value=""><?php echo e(meta('arrival_city', $local) ?? __('packages.arrival_city')); ?></option>
                    <?php endif; ?>
                </select>
            </div>
            <div class="form-group col-lg-12 show_both <?php echo e(in_array(($package->package_type ?? null), ['ut', 'uta']) ? '' : 'd-none'); ?> point_container">
                <label for="location"><?php echo e(meta('point_address', $local) ?? __('packages.point_address')); ?></label>
                <?php if(count($package->rally_point_info)): ?>
                    <?php $__currentLoopData = $package->rally_point_info; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $point): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="d-flex justify-content-between align-items-center mb-4 <?php echo e($loop->iteration != 1 ? 'deleted_point' : ''); ?>">
                            <?php if($loop->iteration != 1): ?>
                                <a href="#" class="delete_point_link ml-2"> <i class="fas fa-times fa-2x text-danger"></i> </a>
                            <?php endif; ?>
                            <input type="text" name="point_address[]" class="form-control" placeholder="<?php echo e(__('packages.point_address') . __('packages.choose_address_via_map')); ?>" value='<?php echo e($point['address']); ?>'>
                            <button style="font-size: 12px" type="button" class="butn small modal-btn mr-2 point_map_button" data-toggle="modal" data-target="#exampleModalCenter">
                                <span><?php echo e(__('packages.point_location')); ?></span>
                            </button>
                            <input type="hidden" name="lat[]" value='<?php echo e($point['lat']); ?>'>
                            <input type="hidden" name="lng[]" value='<?php echo e($point['lng']); ?>'>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php else: ?>
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <input type="text" name="point_address[]" class="form-control" placeholder="<?php echo e(__('packages.point_address') . __('packages.choose_address_via_map')); ?>" value='<?php echo e($package->address ?? ""); ?>'>
                        <button style="font-size: 12px" type="button" class="butn small modal-btn mr-2 point_map_button" data-toggle="modal" data-target="#exampleModalCenter">
                            <span><?php echo e(__('packages.point_location')); ?></span>
                        </button>
                        <input type="hidden" name="lat[]" value='<?php echo e($package->lat ?? ""); ?>'>
                        <input type="hidden" name="lng[]" value='<?php echo e($package->lng ?? ""); ?>'>
                    </div>
                <?php endif; ?>


            </div>
            <div class="form-group col-md-12 show_both <?php echo e(in_array(($package->package_type ?? null), ['ut', 'uta']) ? '' : 'd-none'); ?>">
                <a href="#" class="add_point_link btn btn-primary ml-2"><i class="fa fa-plus"></i> <?php echo e(__('packages.add_point')); ?> </a>
            </div>
            <div class="form-group col-lg-12 show_uta <?php echo e(in_array(($package->package_type ?? null), ['uta']) ? '' : 'd-none'); ?>">
                <label><?php echo e(meta('house_type', $local) ?? __('packages.house_type')); ?> </label>
                <select name="house_type" class="form-control">
                    <option value=""><?php echo e(__('packages.house_type')); ?></option>
                    <option <?php echo e(($package->house_type ?? null) == 'private' ? 'selected' : ''); ?> value="private"><?php echo e(__('packages.private')); ?></option>
                    <option <?php echo e(($package->house_type ?? null) == 'group' ? 'selected' : ''); ?> value="group"><?php echo e(__('packages.group')); ?></option>
                </select>
            </div>

            <?php $__currentLoopData = languages(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $language): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="form-group col-lg-12">
                <label><?php echo e(meta('name', $language->local) ?? __('packages.name')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                <input type="text" class="form-control" name="name_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('name', $language->local) ?? __('packages.name')); ?>" value='<?php echo e($package[$language->local]->name ?? ""); ?>'/>
            </div>

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

            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


            
                <div class="form-group col-lg-12">
                    <label><?php echo e(meta('image', $local) ?? __('packages.image')); ?> </label>
                    <input id="image_thumbnail" class="image_thumbnail" type="hidden" name="image" value="<?php echo e(old("image", $package->image ?? "")); ?>"/>

                    <div class="photos main_photo <?php echo e(old('image', $package->image ?? '') ? ' wow fadeInUp' : 'hide'); ?>">
                        <div class="col-lg-4">
                            <div class="items">
                                <div class="img">
                                    <a href="#" id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" class="lfm" data-hide=".pick_button">
                                        <img src="<?php echo e(asset(old('image', $package->image ?? ''))); ?> "  id="image_holder" class="image_holder"/>
                                    </a>
                                </div>
                                <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail" data-hide=".main_photo" data-show=".pick_button"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <span class="input-group-btn pick_button <?php echo e(old('image', $package->image ?? '') ? 'hide' : ''); ?> ">
                        <a id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" data-show=".main_photo" data-hide=".pick_button" class="lfm btn btn-primary text-light">
                            <i class="fas fa-camera-retro"></i> Choose
                        </a>
                    </span>
                </div>
            

            <div class="text-center mt-5 col-12">
                <button class="butn add_package_button"><span><?php echo e(__('dashboard.save')); ?></span></button>
            </div>
        </form>
    </div>


    <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLongTitle"><?php echo e(__('packages.point_location')); ?></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div style="border:0; height: 400px; width: 100%" class="map" id="map"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="butn color small save_location"><span><?php echo e(__('packages.save_location')); ?></span></button>
                </div>
            </div>
        </div>
    </div>


<?php $__env->stopSection(); ?>

<?php $__env->startSection('inner_js'); ?>
    <!-- Editor JS files -->
    <script src="<?php echo e(asset('/assets/admin/js/lib/tinymce.min.js')); ?>"></script>
    
    <script>
        let route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>",
            url = "<?php echo e(url('/')); ?>/",
            imagePath = "<?php echo e(asset('')); ?>",
            currentLanguage = "<?php echo e($local); ?>",
            inputName = null;
    </script>
    <script src="<?php echo e(asset('assets/admin/js/editor.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/admin/js/lfm.js')); ?>"></script>



    <script>

        let getCityRoute = "<?php echo e(route('packages.getCities')); ?>";

        localStorage.setItem('articleGallery', null);
        localStorage.setItem('oldArticleStorage', null);

        $('.add_package_button').click(async function (e) {
            e.preventDefault();

            let form = $('.add_package_form'),
                data = new FormData(form[0]),
                url = form.attr('action'),
                method = form.attr('method');

            $('.discount_dates_input').each(function () {
                if ($(this).prop('checked') === false){
                    data.append('discount_dates[]', 0);
                    data.append('discount_percentage[]', 'empty');
                } else {
                    data.append('discount_dates[]', 1);
                    let inputSibling = $(this).siblings('.discount_percentage');
                    data.append('discount_percentage[]', inputSibling.val());

                }});


            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method
            });

            if (response.url){
                window.location.href = response.url;
            }

            if (response.errors){
                toasterError(response.errors);
            }


        });

        $(document).on('click', '.active_package' , async function (e) {
            e.preventDefault();
            let url = $(this).data('href'),
                method = 'get';

            const response=await ajax({
                url,
                dataType: 'json',
                method,
            });
            if (response.message) {
                $(this).children('i').toggleClass('fa-check text-success fa-times text-danger')

            }
        });

        $('select[name="departure_city"]').change(async function (e) {
            e.preventDefault();

            let arrivalCity = $('select[name="arrival_city"]');
            arrivalCity.html(`<option value=""><?php echo e(__('packages.arrival_city')); ?></option>`);

            if($(this).val() === ''){
              return  false
            }
            let data = {city_id: $(this).val()},
                url = getCityRoute,
                method = 'get';
            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method
            });

            if (response.cities.length){
                for (let i = 0; i < response.cities.length; i++){
                    arrivalCity.append(`<option value="`+response.cities[i].id+`">`+response.cities[i].name+`</option>`)
                }
            }
            if (response.errors){
                toasterError(response.errors);
            }


        });

        $('.add_point_link').click(function (e) {
            e.preventDefault();

            $('.point_container').append(`<div class="d-flex justify-content-between align-items-center mb-4 deleted_point">
                        <a href="#" class="delete_point_link ml-2"> <i class="fas fa-times fa-2x text-danger"></i> </a>
                        <input type="text" name="point_address[]" class="form-control" placeholder="<?php echo e(__('packages.point_address') . __('packages.choose_address_via_map')); ?>" value=''>
                        <button style="font-size: 12px" type="button" class="butn small modal-btn mr-2 point_map_button" data-toggle="modal" data-target="#exampleModalCenter">
                            <span><?php echo e(__('packages.point_location')); ?></span>
                        </button>
                        <input type="hidden" name="lat[]" value=''>
                        <input type="hidden" name="lng[]" value=''>
                    </div>`);

        });

        $(document).on('click', '.delete_point_link', function (e) {
            e.preventDefault();

            $(this).parents('.deleted_point').remove();

        });

        $(document).on('click', '.point_map_button', function () {
           $(this).siblings('input[type="text"]').addClass('active_point_address');
           $(this).siblings('input[name="lat[]"]').addClass('active_lat');
           $(this).siblings('input[name="lng[]"]').addClass('active_lng');
        });

        // let package_type = $('select[name="package_type"]');

        $('select[name="package_type"]').change(function () {
            if ($(this).val() === 'u'){
                $('.show_both, .show_uta').addClass('d-none');
                $('select[name="departure_city"]').val('');
                $('select[name="arrival_city"]').html(`<option value=""><?php echo e(__('packages.arrival_city')); ?></option>`);
                $('input[name="point_address[]"]').val('');
                $('select[name="house_type"]').val('');
            }
            if ($(this).val() === 'ut'){
                $('.show_both').removeClass('d-none');
                $('.show_uta').addClass('d-none');
                $('select[name="house_type"]').val('');
            }
            if ($(this).val() === 'uta'){
                $('.show_both, .show_uta').removeClass('d-none');
            }
        })

    </script>

    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA5HuBEjkPPxQH4c7Nhfx2-u5XXCtSIzUk&callback=initMap&libraries=&v=weekly" defer></script>


    <script>
        // The following example creates a marker in Stockholm, Sweden using a DROP
        // animation. Clicking on the marker will toggle the animation between a BOUNCE
        // animation and no animation.

        let latitude = null,
            longitude = null;
        if (navigator.geolocation) {
            navigator.geolocation.watchPosition(function (position) {
                // let lat = $('input.latitude'),
                //     lng = $('input.longitude');
                // latitude = lat.val(parseFloat(position.coords.latitude));
                // longitude = lng.val(parseFloat(position.coords.longitude));
                latitude = parseFloat(position.coords.latitude);
                longitude = parseFloat(position.coords.longitude);
                localStorage.setItem('lat', latitude);
                localStorage.setItem('lng', longitude);
            });
        } else {
            alert('Geolocation is not supported by this browser')
        }

        var marker;
        var save_location = $('.save_location');
        function initMap() {
            var map = new google.maps.Map(document.getElementById("map"), {
                zoom: 7,
                center: { lat: parseFloat(latitude) , lng: parseFloat(longitude) }
            });

            marker = new google.maps.Marker({
                map: map,
                draggable: true,
                animation: google.maps.Animation.DROP,
                position: { lat: parseFloat(latitude) , lng: parseFloat(longitude) }
            });

            marker.addListener("dragend", function (map) {
                let lat = map.latLng.lat(), lng = map.latLng.lng();
                localStorage.setItem('lat', lat);
                localStorage.setItem('lng', lng);
                $('#latitude').val(lat);
                $('#longitude').val(lng);
                let activeLat = $('.active_lat'),
                    activeLng = $('.active_lng');

                activeLat.val(lat);
                activeLng.val(lng);

                activeLat.removeClass('active_lat');
                activeLng.removeClass('active_lng');
                var geocoder = new google.maps.Geocoder();
                var infowindow = new google.maps.InfoWindow();

                google.maps.event.addListener(marker, 'dragend', function() {
                    infowindow.close();
                });

                var latlng = { lat: parseFloat(lat), lng: parseFloat(lng) };
                geocoder.geocode({ location: latlng }, function(results, status) {
                    if (status === "OK") {
                        if (results[0]) {
                            infowindow.setContent(results[0].formatted_address);
                            infowindow.open(map, marker);
                            let activePointAddress = $('.active_point_address');
                            activePointAddress.val(results[0].formatted_address);
                            activePointAddress.removeClass('active_point_address');
                            // document.querySelector('.active_point_address').value = results[0].formatted_address
                        } else {
                            window.alert("No results found");
                        }
                    } else {
                        window.alert("Geocoder failed due to: " + status);
                    }
                });
                if (marker.getAnimation() !== null) {
                    marker.setAnimation(null);
                } else {
                    marker.setAnimation(google.maps.Animation.BOUNCE);
                }
            });
        }

        save_location.click(function (map) {
            let lat = localStorage.getItem('lat'),
                lng = localStorage.getItem('lng');
            localStorage.setItem('lat', lat);
            localStorage.setItem('lng', lng);
            let activeLat = $('.active_lat'),
                activeLng = $('.active_lng');

            activeLat.val(lat);
            activeLng.val(lng);

            activeLat.removeClass('active_lat');
            activeLng.removeClass('active_lng');

            var geocoder = new google.maps.Geocoder();
            var infowindow = new google.maps.InfoWindow();

            var latlng = { lat: parseFloat(lat), lng: parseFloat(lng) };
            geocoder.geocode({ location: latlng }, function(results, status) {
                if (status === "OK") {
                    if (results[0]) {
                        infowindow.setContent(results[0].formatted_address);
                        infowindow.open(map, marker);
                        let activePointAddress = $('.active_point_address');
                        activePointAddress.val(results[0].formatted_address);
                        activePointAddress.removeClass('active_point_address');
                        // document.getElementById('location').value = results[0].formatted_address
                    } else {
                        window.alert("No results found");
                    }
                } else {
                    window.alert("Geocoder failed due to: " + status);
                }
            });
            if (marker.getAnimation() !== null) {
                marker.setAnimation(null);
            } else {
                marker.setAnimation(google.maps.Animation.BOUNCE);
            }

            $('.modal').modal('hide')
        });
    </script>

<?php $__env->stopSection(); ?>




<?php echo $__env->make('admin.layouts.container', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\wamp64\www\nosk\resources\views/admin/packages/form.blade.php ENDPATH**/ ?>