<?php $__env->startSection('title'); ?>
    <?php echo e(__('Edit Space')); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="main-content">
        <div class="page-title">
            <div class="container-fluid">
                <div class="row justify-content-center">
                    <div class="col-xl-8">
                        <div class="title-content">
                            <h2 class="title"><?php echo e(__('Edit Space')); ?></h2>
                            <a href="<?php echo e(url()->previous()); ?>" class="title-btn"><i
                                    data-lucide="corner-down-left"></i><?php echo e(__('Back')); ?></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="container-fluid">
            <div class="row justify-content-center">
                <div class="col-xl-8">
                    <form action="<?php echo e(route('admin.space.update', $space->id)); ?>" method="post"
                        enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>
                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Basic Info')); ?></h3>
                            </div>
                            <div class="site-card-body">
                                <div class="row">
                                    <div class="col-xl-6">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Title:')); ?>

                                                <span class="text-danger">*</span>
                                            </label>
                                            <input type="text" name="title" class="box-input"
                                                value="<?php echo e($space->title); ?>" placeholder="Title Here" required>
                                        </div>
                                    </div>
                                    <?php if(multiLocationEnabled()): ?>
                                        <div class="col-xl-6">
                                            <div class="site-input-groups">
                                                <label class="box-input-label" for="">
                                                    <?php echo e(__('Location:')); ?>

                                                    <span class="text-danger">*</span>
                                                </label>
                                                <div class="input-group joint-input">
                                                    <select name="location_id" id="location" class="form-select" required>
                                                        <option>Select Location</option>
                                                        <?php $__currentLoopData = $locations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $location): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($location->id); ?>"
                                                                <?php if($location->id == $space->location_id): ?> selected <?php endif; ?>>
                                                                <?php echo e($location->name); ?></option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                    <div class="col-xl-6 schema-name">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Space Type:')); ?>

                                                <span class="text-danger">*</span>
                                            </label>
                                            <select name="type_id" id="type_id" class="form-select" required>
                                                <option>Select Space Type</option>
                                                <?php $__currentLoopData = $space_types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($type->id); ?>"
                                                        <?php if($type->id == $space->type_id): ?> selected <?php endif; ?>>
                                                        <?php echo e($type->name); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-xl-6">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Sub Title:')); ?>

                                                <span class="text-danger">*</span>
                                            </label>
                                            <div class="input-group joint-input">
                                                <input type="text" name="sub_title" class="box-input"
                                                    value="<?php echo e($space->sub_title); ?>" placeholder="Sub-title Here" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xl-6">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Stock:')); ?>

                                                <span class="text-danger">*</span>
                                            </label>
                                            <div class="input-group joint-input">
                                                <input type="text" name="stock" class="box-input"
                                                    value="<?php echo e($space->stock); ?>" placeholder="Stock here" required>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Pricing')); ?></h3>
                            </div>
                            <div class="site-card-body">
                                <div class="row">
                                    <div class="col-xl-6" id="price">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Price:')); ?>

                                                <span class="text-danger">*</span>
                                            </label>
                                            <div class="input-group joint-input">
                                                <input type="text" class="form-control" name="price"
                                                    value="<?php echo e($space->price); ?>" required/>
                                                <span class="input-group-text"><?php echo e($currency); ?></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xl-6">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Price Type:')); ?>

                                            </label>
                                            <select name="price_type" class="form-select" id="">
                                                <option value="hourly" data-text="Hours" <?php if($space->price_type == 'hourly'): echo 'selected'; endif; ?>>
                                                    <?php echo e(__('Per Hour')); ?>

                                                </option>
                                                <option value="daily" data-text="Days" <?php if($space->price_type == 'daily'): echo 'selected'; endif; ?>>
                                                    <?php echo e(__('Per Day')); ?>

                                                </option>
                                                <option value="weekly" data-text="Weeks" <?php if($space->price_type == 'weekly'): echo 'selected'; endif; ?>>
                                                    <?php echo e(__('Per Week')); ?>

                                                </option>
                                                <option value="monthly" data-text="Months" <?php if($space->price_type == 'monthly'): echo 'selected'; endif; ?>>
                                                    <?php echo e(__('Per Month')); ?>

                                                </option>
                                                <option value="yearly" data-text="Years" <?php if($space->price_type == 'yearly'): echo 'selected'; endif; ?>>
                                                    <?php echo e(__('Per Year')); ?>

                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-xl-6">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Duration Type:')); ?>

                                            </label>
                                            <div class="switch-field same-type">
                                                <input type="radio" id="durationTypeActive" name="duration_type"
                                                    value="fixed" <?php if($space->duration_type === 'fixed'): echo 'checked'; endif; ?> />
                                                <label for="durationTypeActive"><?php echo e(__('Fixed Time')); ?></label>
                                                <input type="radio" id="durationTypeFlexible" name="duration_type"
                                                    value="flexible" <?php if($space->duration_type === 'flexible'): echo 'checked'; endif; ?> />
                                                <label for="durationTypeFlexible"><?php echo e(__('Flexible Time')); ?></label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xl-6" id="duration-area">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Enter Number Of Duration:')); ?>

                                                <span class="text-danger">*</span>
                                            </label>
                                            <div class="input-group joint-input">
                                                <input type="text" class="form-control" name="fixed_duration"
                                                    value="<?php echo e($space->fixed_duration); ?>" required/>
                                                <span class="input-group-text" id="duration-label"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Images')); ?></h3>
                            </div>
                            <div class="site-card-body">
                                <div class="row">
                                    <div class="site-input-groups row">
                                        <div class="col-xl-3 col-lg-3 col-md-3 col-sm-12 col-label">
                                            <?php echo e(__('Banner Image')); ?> <span class="text-danger">*</span><i icon-name="info" data-bs-toggle="tooltip"
                                                title="" data-bs-original-title="Space Banner image"></i>
                                        </div>
                                        <div class="col-xl-9 col-lg-9 col-md-9 col-sm-12">
                                            <div class="wrap-custom-file">
                                                <input type="file" name="banner_image" id="banner_image"
                                                    accept=".gif, .jpg, .png" />
                                                <label for="banner_image" class="file-ok"
                                                    style="background-image: url(<?php echo e(asset($space->banner_image)); ?>)">
                                                    <span><?php echo e(__('Upload Banner Image')); ?></span>
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="site-input-groups row" id="galleries-section">
                                        <div class="col-xl-3 col-lg-3 col-md-3 col-sm-12 col-label">
                                            <?php echo e(__('Galleries')); ?> <span class="text-danger">*</span>
                                            <i icon-name="info" data-bs-toggle="tooltip" title=""
                                                data-bs-original-title="Space Galleries"></i>
                                        </div>
                                        <input type="hidden" name="old_galleries"
                                            value="<?php echo e(json_encode(array_values($space->galleries))); ?>" />
                                        <?php
                                            $galleries = $space->galleries;
                                        ?>
                                        <div class="col-xl-9 col-lg-9 col-md-9 col-sm-12">
                                            <div class="row gallery-group">
                                                <?php $__currentLoopData = $galleries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $gallery): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <div class="col-xl-6 gallery-item">
                                                        <div class="wrap-custom-file">
                                                            <input type="file" name="galleries[]" id="galleries1"
                                                                accept=".gif, .jpg, .png" />
                                                            <label for="banner_image" class="file-ok"
                                                                style="background-image: url(<?php echo e(asset($gallery)); ?>)">
                                                                <img class="upload-icon"
                                                                    src="<?php echo e(asset('global/materials/upload.svg')); ?>"
                                                                    alt="" />

                                                                <span><?php echo e(__('Upload Galleries')); ?></span>
                                                            </label>
                                                            <div class="close" id="remove-btn"
                                                                data-index="<?php echo e($loop->index); ?>">
                                                                <i data-lucide="x"></i>
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row mt-3">
                                    <div class="col-12">
                                        <button type="button" class="site-btn-sm primary-btn"
                                            id="add-more-galleries"><?php echo e(__('Add More')); ?></button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Highlight Services')); ?></h3>
                            </div>
                            <?php
                                $services = json_decode($space->services, true);
                            ?>
                            <div class="site-card-body">
                                <div class="row">
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('First Icon')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?></a>
                                            </label>
                                            <input type="text" name="first_icon" class="box-input" required
                                                value="<?php echo e($services['first_icon']); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('First Title')); ?> <span class="text-danger">*</span></label>
                                            <input type="text" name="first_title" class="box-input" required
                                                value="<?php echo e($services['first_title']); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Second Icon')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?></a>
                                            </label>
                                            <input type="text" name="second_icon" class="box-input" required
                                                value="<?php echo e($services['second_icon']); ?>">
                                        </div>
                                    </div>

                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for=""
                                                class="box-input-label"><?php echo e(__('Second Title')); ?> <span class="text-danger">*</span></label>
                                            <input type="text" name="second_title" class="box-input" required
                                                value="<?php echo e($services['second_title']); ?>">
                                        </div>
                                    </div>

                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Third Icon')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?></a>
                                            </label>
                                            <input type="text" name="third_icon" class="box-input" required
                                                value="<?php echo e($services['third_icon']); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Third Title')); ?> <span class="text-danger">*</span></label>
                                            <input type="text" name="third_title" class="box-input" required
                                                value="<?php echo e($services['third_icon']); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Fourth Icon')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?></a>
                                            </label>
                                            <input type="text" name="fourth_icon" class="box-input" required
                                                value="<?php echo e($services['fourth_icon']); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for=""
                                                class="box-input-label"><?php echo e(__('Fourth Title')); ?> <span class="text-danger">*</span></label>
                                            <input type="text" name="fourth_title" class="box-input" required
                                                value="<?php echo e($services['fourth_icon']); ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Info')); ?></h3>
                            </div>
                            <div class="site-card-body">
                                <div class="row">
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Capacity Icon ')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?> </a>
                                            </label>
                                            <input type="text" name="capacity_icon" class="box-input"
                                                value="<?php echo e($space->capacity_icon); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Capacity')); ?> <span class="text-danger">*</span></label>
                                            <div class="site-input-groups">
                                                <div class="site-input-groups">
                                                    <input type="text" name="capacity" class="box-input" required
                                                        value="<?php echo e($space->capacity); ?>">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Benefit Icon')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?> </a>
                                            </label>
                                            <input type="text" name="benefit_icon" class="box-input"
                                                value="<?php echo e($space->benefit_icon); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Benefit')); ?> <span class="text-danger">*</span></label>
                                            <div class="site-input-groups">
                                                <div class="site-input-groups">
                                                    <input type="text" name="benefit" class="box-input" required
                                                        value="<?php echo e($space->benefit); ?>">

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Area Icon')); ?> <span class="text-danger">*</span>
                                                <a class="link" href="https://fontawesome.com/icons"
                                                    target="_blank"><?php echo e(__('Font Awesome')); ?> </a>
                                            </label>
                                            <input type="text" name="area_icon" class="box-input"
                                                value="<?php echo e($space->area_icon); ?>">
                                        </div>
                                    </div>
                                    <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Area')); ?> <span class="text-danger">*</span></label>
                                            <div class="site-input-groups">
                                                <div class="site-input-groups">
                                                    <input type="text" name="area" class="box-input" required
                                                        value="<?php echo e($space->area); ?>">
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xl-12 col-lg-6 col-md-6 col-sm-12 col-12">
                                        <div class="site-input-groups">
                                            <label for="" class="box-input-label"><?php echo e(__('Description')); ?> <span class="text-danger">*</span></label>
                                            <div class="site-input-groups">
                                                <div class="site-input-groups">
                                                    <textarea name="description" class="form-textarea summernote" placeholder="Content" required><?php echo e($space->description); ?></textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Facilities')); ?></h3>
                                <a href="javascript:void(0)" id="generate" class="site-btn-xs primary-btn mb-3">
                                    <i data-lucide="plus-circle"></i>

                                    <?php echo e(__('Add')); ?>

                                </a>
                            </div>
                            <div class="row justify-content-center my-4">
                                <div class="col-xxl-10">
                                    <div class="addOptions">
                                        <?php $__currentLoopData = $space->facilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $facility): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="mb-4" id="area<?php echo e($key); ?>">
                                                <div class="option-remove-row row align-items-center">
                                                    <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6 col-12">
                                                        <div class="wrap-custom-file">
                                                            <input type="file"
                                                                name="facilities[<?php echo e($key); ?>][icon]"
                                                                id="facility_image<?php echo e($loop->iteration); ?>"
                                                                accept=".gif, .jpg, .png" class="facility-upload" />
                                                            <label for="facility_image<?php echo e($loop->iteration); ?>"
                                                                class="file-ok"
                                                                style="background-image: url(<?php echo e(asset($facility['icon'])); ?>)">
                                                                <img class="upload-icon"
                                                                    src="<?php echo e(asset('global/materials/upload.svg')); ?>"
                                                                    alt="Facility Icon" />
                                                                <span><?php echo e(__('Upload Facility Icon')); ?></span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6 col-12">
                                                        <div class="site-input-groups mb-0">
                                                            <input name="facilities[<?php echo e($key); ?>][title]"
                                                                class="box-input" type="text"
                                                                value="<?php echo e($facility['title']); ?>" required
                                                                placeholder="Title" />
                                                        </div>
                                                    </div>

                                                    <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6 col-12">
                                                        <div class="site-input-groups mb-0">
                                                            <input name="facilities[<?php echo e($key); ?>][price]"
                                                                class="box-input" type="text"
                                                                value="<?php echo e($facility['price']); ?>" required
                                                                placeholder="Price" />
                                                        </div>
                                                    </div>

                                                    <div class="col-xl-1 col-lg-6 col-md-6 col-sm-6 col-12">
                                                        <button class="delete-option-row delete_desc" type="button">
                                                            <i class="fas fa-times"></i>
                                                        </button>
                                                    </div>

                                                    <div class="option-fields<?php echo e($key); ?> row"></div>
                                                </div>
                                                <hr class="mb-4">
                                            </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                </div>

                            </div>
                        </div>


                        <div class="site-card">
                            <div class="site-card-header">
                                <h3 class="title"><?php echo e(__('Status')); ?></h3>
                            </div>
                            <div class="site-card-body">
                                <div class="row">
                                    <div class="col-xl-6">
                                        <div class="site-input-groups">
                                            <label class="box-input-label" for="">
                                                <?php echo e(__('Status:')); ?>

                                            </label>
                                            <div class="switch-field">
                                                <input type="radio" id="active" name="status" value="1"
                                                    <?php if($space->status): echo 'checked'; endif; ?> />
                                                <label for="active"><?php echo e(__('Active')); ?></label>
                                                <input type="radio" id="deactivate" name="status" value="0"
                                                    <?php if(!$space->status): echo 'checked'; endif; ?> />
                                                <label for="deactivate"><?php echo e(__('Deactive')); ?></label>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xl-12">
                            <button type="submit" class="site-btn-sm primary-btn w-100">
                                <?php echo e(__('Update Space')); ?>

                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script>
        document.getElementById('add-more-galleries').addEventListener('click', function() {
            const galleriesSection = document.querySelector('#galleries-section .gallery-group');
            const galleryCount = galleriesSection.querySelectorAll('.gallery-item').length;

            const newGalleryInput = `
                <div class="col-xl-6 gallery-item">
                            <div class="wrap-custom-file">
                            <input type="file" name="galleries[]" id="galleries${galleryCount + 1}" accept=".gif, .jpg, .png" required />
                            <label for="galleries${galleryCount + 1}">
                                <img class="upload-icon" src="<?php echo e(asset('global/materials/upload.svg')); ?>" alt="" />
                                <span><?php echo e(__('Upload Galleries')); ?></span>
                            </label>
                            <div class="close" id="remove-btn">
                                <i data-lucide="x"></i>
                            </div>
                        </div>
                </div>`;

            galleriesSection.insertAdjacentHTML('beforeend', newGalleryInput);
            imagePreview();
            lucide.createIcons();
        });

        $(document).on('click', '#remove-btn', function() {

            const index = $(this).attr('data-index');

            const oldGalleriesInput = document.querySelector('input[name="old_galleries"]');
            const oldGalleries = JSON.parse(oldGalleriesInput.value);

            // Remove the item from the old galleries array
            const updatedGalleries = oldGalleries.filter((_, i) => i != index);

            // Update the hidden input with the updated array
            oldGalleriesInput.value = JSON.stringify(updatedGalleries);


            $(this).closest('.gallery-item').remove();
        });

        $(document).ready(function() {
            (function($) {
                let i = <?php echo e(count($space->facilities)); ?>;
                "use strict";

                $('select[name=price_type]').on('change', function() {
                    setDurationLabel();
                });

                setDurationLabel();

                function setDurationLabel() {
                    const dataText = $('select[name=price_type]').find('option:selected').data('text');
                    if (dataText) {
                        $('#duration-label').text(dataText);
                    } else {
                        $('#duration-label').text('');
                    }
                }

                $('input[name=duration_type]').on('change', function() {
                    durationToggle();
                });

                durationToggle();

                function durationToggle() {
                    const durationType = $('input[name=duration_type]:checked').val();

                    if (durationType === 'fixed') {
                        $('#duration-area').removeClass('d-none');
                    } else {
                        $('#duration-area').addClass('d-none');
                    }
                }

                $("#generate").on("click", function() {
                    i++;
                    const form = `
            <div class="mb-4" id="area${i}">
                <div class="option-remove-row row align-items-center">
                    <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6 col-12">
                        <div class="wrap-custom-file">
                            <input
                                type="file"
                                name="facilities[${i}][icon]"
                                id="facility_image${i}"
                                accept=".gif, .jpg, .png"
                                class="facility-upload"
                                required
                            />
                            <label for="facility_image${i}">
                                <img class="upload-icon" src="<?php echo e(asset('global/materials/upload.svg')); ?>" alt="" />
                                <span><?php echo e(__('Upload Facility Icon')); ?></span>
                            </label>
                        </div>
                    </div>
                    <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6 col-12">
                        <div class="site-input-groups mb-0">
                            <input
                                name="facilities[${i}][title]"
                                class="box-input"
                                type="text"
                                value=""
                                required
                                placeholder="Title"
                            />
                        </div>
                    </div>
                    <div class="col-xl-3 col-lg-6 col-md-6 col-sm-6 col-12">
                        <div class="site-input-groups mb-0">
                            <input
                                name="facilities[${i}][price]"
                                class="box-input"
                                type="text"
                                value=""
                                required
                                placeholder="Price"
                            />
                        </div>
                    </div>
                    <div class="col-xl-1 col-lg-6 col-md-6 col-sm-6 col-12">
                        <button class="delete-option-row delete_desc" type="button">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                    <div class="option-fields${i} row"></div>
                </div>
                <hr class="mb-4">
            </div>`;
                    $(".addOptions").append(form);
                });

                // Delete dynamically added facility form
                $(document).on("click", ".delete_desc", function() {
                    $(this).closest(".option-remove-row").parent().remove();
                    i--;
                });

                $(document).on("change", ".facility-upload", function(e) {
                    const file = e.target.files[0];
                    if (file) {
                        const reader = new FileReader();
                        reader.onload = function(event) {
                            // Update the sibling label's upload icon specific to this input
                            $(e.target)
                                .closest(".wrap-custom-file") // Find the closest wrapping div
                                .find(".upload-icon") // Target the icon inside this wrap
                                .attr("src", event.target.result); // Set the preview image
                        };
                        reader.readAsDataURL(file);
                    }
                });

            })(jQuery);
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('backend.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /www/wwwroot/mxawfis.atharvatek.com/resources/views/backend/space/edit.blade.php ENDPATH**/ ?>