<?php $__env->startSection('css'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('assets/admin/css/lib/toastr.css')); ?>">

    <style>
        .highlight{
            background: #FC0 !important;
        }
    </style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="side-title">
        <h3><?php echo e($head ?? ''); ?></h3>
    </div>

    <div class="border-item">
        <form class="form-row add_hall_from" method="post" action="<?php echo e($action); ?>" enctype="multipart/form-data">
            <?php if($hall ?? ''  && $hall->id): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>
            <?php echo csrf_field(); ?>
            <div class="form-group col-lg-4">
                <label><?php echo e(meta('user_id', $local) ?? __('halls.user_id')); ?> </label>
                <select name="user_id" class="form-control">
                    <option value=""><?php echo e(meta('user_id', $local) ?? __('halls.user_id')); ?></option>
                    <?php if(count($providers)): ?>
                        <?php $__currentLoopData = $providers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $provider): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option <?php echo e(($hall->user_id ?? null) == $provider->id ? 'selected': ''); ?> value="<?php echo e($provider->id); ?>"><?php echo e($provider->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </select>
            </div>
            <div class="form-group col-lg-4">
                <label><?php echo e(meta('category_id', $local) ?? __('halls.category_id')); ?> </label>
                <select name="category_id" class="form-control">
                    <option value=""><?php echo e(meta('category_id', $local) ?? __('halls.category_id')); ?></option>
                    <?php if(count($categories)): ?>
                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option <?php echo e(($hall->category_id ?? null) == $category->id ? 'selected': ''); ?> value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </select>
            </div>
            <div class="form-group col-lg-2">
                <label><?php echo e(meta('is_offer', $local) ?? __('halls.is_offer')); ?> </label>
                <select name="is_offer" class="form-control">
                    <option value=""><?php echo e(meta('is_offer', $local) ?? __('halls.is_offer')); ?></option>
                    <option <?php echo e(($hall->is_offer ?? null) == 1 ? 'selected': ''); ?> value="1"><?php echo e(__('halls.yes')); ?></option>
                    <option <?php echo e(($hall->is_offer ?? null) == 0 ? 'selected': ''); ?> value="0"><?php echo e(__('halls.no')); ?></option>
                </select>
            </div>
            <div class="form-group col-lg-2">
                <label><?php echo e(meta('status', $local) ?? __('halls.status')); ?> </label>
                <select name="hall_status" class="form-control">
                    <option value=""><?php echo e(meta('status', $local) ?? __('halls.status')); ?></option>
                    <option <?php echo e(($hall->hall_status ?? null) == 1 ? 'selected': ''); ?> value="1"><?php echo e(__('halls.active')); ?></option>
                    <option <?php echo e(($hall->hall_status?? null) == 0 ? 'selected': ''); ?> value="0"><?php echo e(__('halls.non_active')); ?></option>
                </select>
            </div>
            <div class="form-group col-lg-4">
                <label><?php echo e(meta('region_id', $local) ?? __('halls.region_id')); ?> </label>
                <select name="region_id" class="form-control">
                    <option value=""><?php echo e(meta('region_id', $local) ?? __('halls.region_id')); ?></option>
                    <?php if(count($regions)): ?>
                        <?php $__currentLoopData = $regions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $region): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option <?php echo e(($hall->region_id ?? null) == $region->id ? 'selected': ''); ?> value="<?php echo e($region->id); ?>"><?php echo e($region->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </select>
            </div>
            <div class="form-group col-lg-4">
                <label><?php echo e(meta('city_id', $local) ?? __('halls.city_id')); ?> </label>
                <select name="city_id" class="form-control">
                    <option value=""><?php echo e(meta('city_id', $local) ?? __('halls.city_id')); ?></option>
                    <?php if(count($cities)): ?>
                        <?php $__currentLoopData = $cities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $city): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option <?php echo e(($hall->city_id ?? 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-4">
                <label><?php echo e(meta('sector_id', $local) ?? __('halls.sector_id')); ?> </label>
                <select name="sector_id" class="form-control">
                    <option value=""><?php echo e(meta('sector_id', $local) ?? __('halls.sector_id')); ?></option>
                    <?php if(count($sectors)): ?>
                        <?php $__currentLoopData = $sectors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sector): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option <?php echo e(($hall->sector_id ?? null) == $sector->id ? 'selected': ''); ?> value="<?php echo e($sector->id); ?>"><?php echo e($sector->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </select>
            </div>
            <div class="form-group col-lg-12">
                <label><?php echo e(meta('street', $local) ?? __('halls.street')); ?> </label>
                <input type="text" class="form-control" name="street" placeholder="<?php echo e(meta('street', $local) ?? __('halls.street')); ?>" value='<?php echo e($hall->street ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(meta('reservation_way', $local) ?? __('halls.reservation_way')); ?> </label>
                <select name="reservation_way" class="form-control">
                    <option value=""><?php echo e(meta('reservation_way', $local) ?? __('halls.reservation_way')); ?></option>
                    <option <?php echo e(($hall->reservation_way ?? null) == 'direct' ? 'selected' : ''); ?> value="direct"><?php echo e(__('halls.direct')); ?></option>
                    <option <?php echo e(($hall->reservation_way ?? null) == 'accept_request' ? 'selected' : ''); ?> value="accept_request"><?php echo e(__('halls.accept_request')); ?></option>
                </select>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(meta('reservation_type', $local) ?? __('halls.reservation_type')); ?> </label>
                <select name="reservation_type" class="form-control">
                    
                    <option <?php echo e(($hall->reservation_type ?? null) == 'person_count' ? 'selected' : ''); ?> value="person_count"><?php echo e(__('halls.person_count')); ?></option>
                    <option <?php echo e(($hall->reservation_type ?? null) == 'days_count' ? 'selected' : ''); ?> value="days_count"><?php echo e(__('halls.days_count')); ?></option>
                </select>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(meta('capacity', $local) ?? __('halls.capacity')); ?> </label>
                <input type="number" min="1" class="form-control" name="capacity" placeholder="<?php echo e(meta('capacity', $local) ?? __('halls.capacity')); ?>" value='<?php echo e($hall->capacity ?? ""); ?>'/>
            </div>

            <div class="form-group col-lg-6 booking_amount_per_person">
                <label><?php echo e(meta('booking_amount_per_person', $local) ?? __('halls.booking_amount_per_person')); ?> </label>
                <input type="number" min="1" class="form-control" name="booking_amount_per_person" placeholder="<?php echo e(meta('booking_amount_per_person', $local) ?? __('halls.booking_amount_per_person')); ?>" value='<?php echo e($hall->booking_amount_per_person ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-6 d-none booking_amount_per_day">
                <label><?php echo e(meta('booking_amount_per_day', $local) ?? __('halls.booking_amount_per_day')); ?> </label>
                <input type="number" min="1" class="form-control" name="booking_amount_per_day" placeholder="<?php echo e(meta('booking_amount_per_day', $local) ?? __('halls.booking_amount_per_day')); ?>" value='<?php echo e($hall->booking_amount_per_day ?? ""); ?>'/>
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(meta('min_capacity', $local) ?? __('halls.min_capacity')); ?> </label>
                <input type="number" min="1" class="form-control" name="min_capacity" placeholder="<?php echo e(meta('min_capacity', $local) ?? __('halls.min_capacity')); ?>" value='<?php echo e($hall->min_capacity ?? ""); ?>'/>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(meta('total_capacity', $local) ?? __('halls.total_capacity')); ?> </label>
                <input type="number" min="1" class="form-control" name="total_capacity" placeholder="<?php echo e(meta('total_capacity', $local) ?? __('halls.total_capacity')); ?>" value='<?php echo e($hall->total_capacity ?? ""); ?>'/>
            </div>

            
            <div class="card col-lg-12 p-3 mb-3">
                <label><?php echo e(meta('available_dates', $local) ??  __('halls.available_dates')); ?> </label>
                <div class="available_dates_container">
                    <?php if(($hall ?? null) && is_array($hall->available_dates) && count($hall->available_dates)): ?>
                        <?php $__currentLoopData = $hall->available_dates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $availableDate): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="deleted_available_dates_container row flex-row-reverse justify-content-between align-items-center align-content-center">
                                <div class="form-group col-md-5">
                                    <div class="custom-control custom-checkbox">
                                        <div class="discount_dates_container d-flex justify-content-start align-content-center align-items-center">
                                            <input type="checkbox" <?php echo e($availableDate['discount'] ? 'checked' : ''); ?>  value="1" class="custom-control-input discount_dates_input" id="discount_dates_<?php echo e($loop->iteration); ?>">
                                            <label class="custom-control-label col-md-4" for="discount_dates_<?php echo e($loop->iteration); ?>"> <?php echo e(__('halls.discount_dates')); ?></label>
                                            <?php if($availableDate['discount_percentage'] && $availableDate['discount']): ?>
                                                <input type="number" min="1" pattern="/[1-9]/" class="discount_percentage col-md-8 form-control" placeholder="<?php echo e(__('halls.discount_percentage')); ?>" value="<?php echo e($availableDate['discount_percentage']); ?>">
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group col-md-3">
                                    <input type="text" placeholder="<?php echo e(__('halls.available_dates_to')); ?>" name="available_dates_to[]" value="<?php echo e(date('m/d/Y', strtotime($availableDate['to']))); ?>" class="available_dates available_dates_to form-control">
                                </div>
                                <div class="form-group col-md-3">
                                    <input type="text" placeholder="<?php echo e(__('halls.available_dates_from')); ?>" name="available_dates_from[]" value="<?php echo e(date('m/d/Y', strtotime($availableDate['from']))); ?>" class="available_dates available_dates_from form-control">
                                </div>
                                <?php if($loop->iteration != 1): ?>
                                    <div class="form-group col-md-1">
                                        <a class="btn btn-danger delete_available_dates_link" href="#"><i class="fa fa-times"></i></a>
                                    </div>
                                <?php else: ?>
                                    <div class="form-group col-md-1"></div>
                                <?php endif; ?>

                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php else: ?>
                        <div class="row flex-row-reverse justify-content-between align-items-center align-content-center">
                            <div class="form-group col-md-5">
                                <div class="custom-control custom-checkbox">
                                    <div class="discount_dates_container d-flex justify-content-start align-content-center align-items-center">
                                        <input type="checkbox" value="1" class="custom-control-input discount_dates_input" id="discount_dates_1">
                                        <label class="custom-control-label col-md-4" for="discount_dates_1"> <?php echo e(__('halls.discount_dates')); ?></label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-md-3">
                                <input type="text" placeholder="<?php echo e(__('halls.available_dates_to')); ?>" name="available_dates_to[]" value="" class="available_dates available_dates_to form-control">
                            </div>
                            <div class="form-group col-md-3">
                                <input type="text" placeholder="<?php echo e(__('halls.available_dates_from')); ?>" name="available_dates_from[]" value="" class="available_dates available_dates_from form-control">
                            </div>
                            <div class="form-group col-md-1"></div>
                        </div>
                    <?php endif; ?>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <a href="#" class="btn btn-primary btn-sm btn-block add_available_dates_link"><i class="fa fa-plus"></i></a>
                    </div>
                </div>
            </div>
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            


            <div class="card p-3 mb-3 col-lg-12">
                <label><?php echo e(meta('occasions', $local) ??  __('halls.occasions')); ?> </label>
                <div class="row card-body">
                    <?php if(count($occasions)): ?>
                        <?php $__currentLoopData = $occasions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $occasion): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="col-md-4">
                                <div class="custom-control custom-checkbox">
                                    <input type="checkbox" <?php echo e(in_array($occasion->id, $hall['occasions'] ?? []) ? 'checked' : ''); ?> value="<?php echo e($occasion->id); ?>" class="custom-control-input" id="occasions_<?php echo e($occasion->id); ?>" name="occasions[]">
                                    <label class="custom-control-label" for="occasions_<?php echo e($occasion->id); ?>"> <?php echo e($occasion->name); ?></label>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </div>
            </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) ?? __('halls.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) ?? __('halls.name')); ?>" value='<?php echo e($hall[$language->local]->name ?? ""); ?>'/>
                </div>

                <div class="form-group col-lg-12">
                    <label><?php echo e(meta('description', $language->local) ?? __('halls.description')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                    <textarea name="description_<?php echo e($language->local); ?>" class="form-control " placeholder="<?php echo e(meta('description', $language->local) ?? __('halls.description')); ?>"><?php echo $hall[$language->local]->description ?? ""; ?></textarea>
                </div>

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

            <div class="service_container col-md-12">
                <?php if(($hall ?? null) && is_array($hall->added_services) && count($hall->added_services)): ?>
                    <?php $__currentLoopData = $hall->added_services; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $service): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="form-group col-lg-12 card deleted_service service_card">
                            <label><?php echo e(__('halls.added_services')); ?></label>
                            <div class="row">
                                <?php if($loop->iteration != 1): ?>
                                    <div class="form-group col-md-12 d-flex justify-content-end">
                                        <a href="#" class="btn btn-danger delete_service mr-3"><i class="fa fa-times"></i></a>
                                    </div>
                                <?php endif; ?>
                                <div class="form-group col-md-6">
                                    <input type="text" name="added_services_name[]" placeholder="<?php echo e(__('halls.added_services_name')); ?>" class="form-control" value="<?php echo e($service->name); ?>"/>
                                </div>
                                <div class="form-group col-md-6">
                                    <input type="number" min="1" name="added_services_price[]"  placeholder="<?php echo e(__('halls.added_services_price')); ?>" class="form-control" value="<?php echo e($service->price); ?>"/>
                                </div>
                                <div class="from-group col-md-12">
                                    <textarea name="added_services_description[]"  placeholder="<?php echo e(__('halls.added_services_description')); ?>" class="form-control" cols="30" rows="5"><?php echo e($service->description); ?></textarea>
                                </div>
                                <div class="form-group col-lg-12">
                                    <label><?php echo e(__('halls.added_services_image')); ?> </label>
                                    <input id="image_thumbnail_<?php echo e($loop->iteration); ?>" class="image_thumbnail_<?php echo e($loop->iteration); ?>" type="hidden" name="added_services_image[]" value="<?php echo e(old("added_services_image", $service->image ?? "")); ?>"/>

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

                                    <div class="clearfix"></div>
                                    <span class="input-group-btn pick_button_<?php echo e($loop->iteration); ?> <?php echo e(old('added_services_image', $service->image) ? 'hide' : ''); ?> ">
                                        <a id="lfm" data-input=".image_thumbnail_<?php echo e($loop->iteration); ?>" data-preview=".image_holder_<?php echo e($loop->iteration); ?>" data-show=".main_photo_<?php echo e($loop->iteration); ?>" data-hide=".pick_button_<?php echo e($loop->iteration); ?>" class="lfm btn btn-primary text-light">
                                            <i class="fas fa-camera-retro"></i> Choose
                                        </a>
                                    </span>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <div class="form-group col-lg-12 card service_card">
                        <label><?php echo e(__('halls.added_services')); ?></label>
                        <div class="row">
                            <div class="form-group col-md-6">
                                <input type="text" name="added_services_name[]" placeholder="<?php echo e(__('halls.added_services_name')); ?>" class="form-control" value=""/>
                            </div>
                            <div class="form-group col-md-6">
                                <input type="number" min="1" name="added_services_price[]"  placeholder="<?php echo e(__('halls.added_services_price')); ?>" class="form-control" value=""/>
                            </div>
                            <div class="from-group col-md-12">
                                <textarea name="added_services_description[]"  placeholder="<?php echo e(__('halls.added_services_description')); ?>" class="form-control" cols="30" rows="5"></textarea>
                            </div>
                            <div class="form-group col-lg-12">
                                <label><?php echo e(__('halls.added_services_image')); ?> </label>
                                <input id="image_thumbnail_1" class="image_thumbnail_1" type="hidden" name="added_services_image[]" value=""/>

                                <div class="photos main_photo_1 hide">
                                    <div class="col-lg-4">
                                        <div class="items">
                                            <div class="img">
                                                <a href="#" id="lfm" data-input=".image_thumbnail_1" data-preview=".image_holder_1" class="lfm" data-hide=".pick_button_1">
                                                    <img src=""  id="image_holder_1" class="image_holder_1"/>
                                                </a>
                                            </div>
                                            <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail_1" data-hide=".main_photo_1" data-show=".pick_button_1"><i class="fas fa-times"></i></a>
                                        </div>
                                    </div>
                                </div>

                                <div class="clearfix"></div>
                                <span class="input-group-btn pick_button_1">
                                <a id="lfm" data-input=".image_thumbnail_1" data-preview=".image_holder_1" data-show=".main_photo_1" data-hide=".pick_button_1" class="lfm btn btn-primary text-light">
                                    <i class="fas fa-camera-retro"></i> Choose
                                </a>
                             </span>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            </div>

            <div class="form-group col-lg-12">
                <a href="#" class="btn btn-primary btn-block add_service"><i class="fa fa-plus"></i> <?php echo e(__('halls.added_services')); ?></a>
            </div>

            <div class="border-item photos col-md-12 other_image_container">
                <div class="row">
                    <?php if($hall ?? false): ?>
                        <?php $__currentLoopData = $hall['images']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $photo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="col-md-4">
                                <div class="items">
                                    <div class="img">
                                        <a href="<?php echo e(asset($photo ?? '')); ?>" data-fancybox="gallery"><img src="<?php echo e(asset($photo ?? '')); ?>" alt=""></a>
                                    </div>
                                    <input type="hidden" name="images[]" value="<?php echo e($photo ?? ""); ?>">
                                    <a href="#" class="close"><i class="fas fa-times"></i></a>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php 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>

            <div class="text-center mt-5 col-12">
                <button class="butn add_hall_button"><span><?php echo e(__('dashboard.save')); ?></span></button>
            </div>
        </form>
    </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>
        var route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>";
        var url = "<?php echo e(url('/')); ?>/",
            currentLanguage = "<?php echo e($local); ?>",
            inputName = '';
    </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 src="<?php echo e(asset('assets/admin/js/articles.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/admin/js/lib/toastr.min.js')); ?>"></script>



    <script>

        let getCityAndSectorRoute = "<?php echo e(route('halls.getCityAndSector')); ?>",
            availableDatesFrom = [],
            availableDatesTo = [],
            availableDates = [];

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

        // $(document).ready(function(){
        $('.available_dates_from').each(function () {
            availableDatesFrom.push($(this).val());
        });
        $('.available_dates_to').each(function () {
            availableDatesTo.push($(this).val());
        });

        for (let i = 0; i < availableDatesFrom.length; i++) {
            let start = availableDatesFrom[i],
                end = new Date(availableDatesTo[i]),
                currentDate = new Date(start);
            while (currentDate <= end) {
                availableDates.push(new Date(currentDate));
                currentDate.setDate(currentDate.getDate() + 1);
            }
        }

        // });

        $('.add_service').click(function (e) {
            e.preventDefault();
            let counter = $('.service_container').children('.service_card').length+1;
            let serviceDiv = `
                <div class="form-group col-lg-12 card deleted_service service_card">
                        <label><?php echo e(__('halls.added_services')); ?></label>
                       <div class="row">
                       <div class="form-group col-md-12 d-flex justify-content-end">
                       <a href="#" class="btn btn-danger delete_service mr-3"><i class="fa fa-times"></i></a>
                       </div>
                         <div class="form-group col-md-6">
                            <input type="text" name="added_services_name[]" placeholder="<?php echo e(__('halls.added_services_name')); ?>" class="form-control" value=""/>
                        </div>
                        <div class="form-group col-md-6">
                            <input type="number" min="1" name="added_services_price[]"  placeholder="<?php echo e(__('halls.added_services_price')); ?>" class="form-control" value=""/>
                        </div>
                        <div class="from-group col-md-12">
                            <textarea name="added_services_description[]"  placeholder="<?php echo e(__('halls.added_services_description')); ?>" class="form-control" cols="30" rows="5"></textarea>
                        </div>
                         <div class="form-group col-lg-12">
                                <label><?php echo e(__('halls.added_services_image')); ?> </label>
                                <input id="image_thumbnail_`+counter+`" class="image_thumbnail_`+counter+`" type="hidden" name="added_services_image[]" value=""/>

                                <div class="photos main_photo_`+counter+` hide">
                                    <div class="col-lg-4">
                                        <div class="items">
                                            <div class="img">
                                                <a href="#" id="lfm" data-input=".image_thumbnail_`+counter+`" data-preview=".image_holder_`+counter+`" class="lfm" data-hide=".pick_button_`+counter+`">
                                                    <img src="" id="image_holder_`+counter+`" class="image_holder_`+counter+`"/>
                                                </a>
                                            </div>
                                            <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail_`+counter+`" data-hide=".main_photo_`+counter+`" data-show=".pick_button_`+counter+`"><i class="fas fa-times"></i></a>
                                        </div>
                                    </div>
                                </div>

                                <div class="clearfix"></div>
                                <span class="input-group-btn pick_button_`+counter+`">
                                <a id="lfm" data-input=".image_thumbnail_`+counter+`" data-preview=".image_holder_`+counter+`" data-show=".main_photo_`+counter+`" data-hide=".pick_button_`+counter+`" class="lfm btn btn-primary text-light">
                                    <i class="fas fa-camera-retro"></i> Choose
                                </a>
                             </span>
                            </div>
                       </div>
                    </div>`;

            $('.service_container').append(serviceDiv);

        });

        $(document).on('click', '.delete_service', function (e) {
            e.preventDefault();
            $(this).parents('.deleted_service').remove();
        });

        $('body').on('DOMNodeInserted', '.service_container', function(e) {
            if ($(e.target).find('.lfm')) {
                $('.lfm').filemanager('image', {prefix: route_prefix});
            }
        });

        $('body').on('DOMNodeInserted', '.available_dates_container', function(e) {
            if ($(e.target).find('.available_dates')) {
                fireDatePicker('.available_dates');
            }
        });

        function fireDatePicker(selector) {
            let reservedDaysInput = $(selector);
            let disabledDays = ['08/05/2021', '08/11/2021', '08/17/2021']; // '8/20/2021'

            reservedDaysInput.change(function () {
                for (let i = 0; i < availableDates.length; i++) {
                    if (availableDates[i].toString() === new Date($(this).val()).toString()) {
                        $(this).val('');
                    }
                    // if($.inArray($(this).val(), availableDates) !== -1) {
                    //     $(this).val('');
                    // }
                }
            });

            reservedDaysInput.datepicker({
                beforeShowDay: reservedDays
            });

            function disableAllTheseDays(date) {

                // for (let i = 0; i < availableDatesFrom.length; i++) {
                //     if (new Date(availableDatesFrom[i]) > date || new Date(availableDatesTo[i]) < date) {
                //         return [true];
                //     }
                // }
                for (let i = 0; i < availableDates.length; i++) {
                    if (availableDates[i].toString() === date.toString()) {
                        return [false];
                    }
                }
                return [true];

                // let m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
                // for (let i = 0; i < disabledDays.length; i++) {
                //     if($.inArray((m+1) + '/' + d + '/' + y,disabledDays) !== -1) {
                //         return [false];
                //     }
                // }
                //
                // return [true];
            }
            function highlightDays(date) {
                for (let i = 0; i < availableDates.length; i++) {
                    if (availableDates[i].toString() === date.toString()) {
                        return [true, 'highlight'];
                    }
                }
                return [true, ''];
                // for (let i = 0; i < disabledDays.length; i++) {
                //     if (new Date(disabledDays[i]).toString() === date.toString()) {
                //         return [true, 'highlight'];
                //     }
                // }
                // return [true, ''];

            }

            function reservedDays(date) {
                let clazz = '';
                let highLight = highlightDays(date);
                if (highLight[1] !== ''){
                    clazz = highLight[1];
                }

                let disableDays = disableAllTheseDays(date);
                let noWeekEnd = $.datepicker.noWeekends(date);
                return [(!disableDays[0] || !noWeekEnd[0]) ? false : true, clazz];
            }
        }

        fireDatePicker('.available_dates');

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

            let form = $('.add_hall_from'),
                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_hall' , 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="region_id"], select[name="city_id"]').change(async function (e) {
            e.preventDefault();

            let data = {},
                url = getCityAndSectorRoute,
                method = 'get';

            if($(this).attr('name') === 'region_id'){
                $('select[name="city_id"]').html(`<option value=""><?php echo e(__('halls.city_id')); ?></option>`);
                $('select[name="sector_id"]').html(`<option value=""><?php echo e(__('halls.sector_id')); ?></option>`);

                data.region_id = $(this).val();
            }
            if($(this).attr('name') === 'city_id'){
                $('select[name="sector_id"]').html(`<option value=""><?php echo e(__('halls.sector_id')); ?></option>`);
                data.city_id = $(this).val();
            }

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

            if (response.status === 'city'){
                if (response.data.length){
                    for (let i = 0; i < response.data.length; i++){
                        $('select[name="city_id"]').append(`<option value="`+response.data[i].id+`">`+response.data[i].name+`</option>`)
                    }
                }
            }
            if (response.status === 'sector'){
                if (response.data.length){
                    for (let i = 0; i < response.data.length; i++){
                        $('select[name="sector_id"]').append(`<option value="`+response.data[i].id+`">`+response.data[i].name+`</option>`)
                    }
                }
            }

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


        });


        // Available dates block
        let counter = $('.available_dates_container').children('.deleted_available_dates_container').length+2;
        $('.add_available_dates_link').click(function (e) {
            e.preventDefault();
            $('.available_dates_container').append(`<div class="deleted_available_dates_container row flex-row-reverse justify-content-between align-items-center align-content-center">
                            <div class="form-group col-md-5">
                                <div class="custom-control custom-checkbox">
                                    <div class="discount_dates_container d-flex justify-content-start align-content-center align-items-center">
                                        <input type="checkbox" value="1" class="custom-control-input discount_dates_input" id="discount_dates_`+counter+`">
                                        <label class="custom-control-label col-md-4" for="discount_dates_`+counter+`"> <?php echo e(__('halls.discount_dates')); ?></label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-md-3">
                                <input type="text" placeholder="<?php echo e(__('halls.available_dates_to')); ?>" name="available_dates_to[]" value="" class="available_dates available_dates_to form-control">
                            </div>
                            <div class="form-group col-md-3">
                                <input type="text" placeholder="<?php echo e(__('halls.available_dates_from')); ?>" name="available_dates_from[]" value="" class="available_dates available_dates_from form-control">
                            </div>
                            <div class="form-group col-md-1">
                                <a class="btn btn-danger delete_available_dates_link" href="#"><i class="fa fa-times"></i></a>
                            </div>
                        </div>`);

            counter = counter+1;
        });
        $(document).on('click', '.delete_available_dates_link', function(e){
            e.preventDefault();
            $(this).parents('.deleted_available_dates_container').remove();
            counter = counter+1;
        });

        $(document).on('click', '.discount_dates_input', function () {
            if ($(this).prop('checked') === true){
                $(this).siblings('input[name="discount_percentage[]"]').remove();
                $(this).parents('.discount_dates_container').append(`<input type="number" min="1" pattern="/[1-9]/" class="discount_percentage col-md-8 form-control" placeholder="<?php echo e(__('halls.discount_percentage')); ?>" value="">`)
            } else {
                $(this).siblings('.discount_percentage').remove();
            }
        });


        let reservation_type = $('select[name="reservation_type"] option:selected').val();
        if(reservation_type === 'person_count'){
            $('.booking_amount_per_person').removeClass('d-none');
            $('.booking_amount_per_day').addClass('d-none');
            $('.booking_amount_per_day input').val('');
        }
        if(reservation_type === 'days_count'){
            $('.booking_amount_per_day').removeClass('d-none');
            $('.booking_amount_per_person').addClass('d-none');
            $('.booking_amount_per_person input').val('');
        }


        $('select[name="reservation_type"]').change(function () {
            if($(this).val() === 'person_count'){
                $('.booking_amount_per_person').removeClass('d-none');
                $('.booking_amount_per_day').addClass('d-none');
                $('.booking_amount_per_day input').val('');
            }
            if($(this).val() === 'days_count'){
                $('.booking_amount_per_day').removeClass('d-none');
                $('.booking_amount_per_person').addClass('d-none');
                $('.booking_amount_per_person input').val('');
            }
        });

        // Discount date block
        
        

        
        
        
        
        
        
        
        
        

    </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\meet\resources\views/admin/halls/form.blade.php ENDPATH**/ ?>