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

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

            <?php $__currentLoopData = $languages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $language): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                <div class="form-group col-lg-6">
                    <label><?php echo e(meta('title', $language->local) ?? __('units.title')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                    <input type="text" class="form-control <?php echo e($errors->has('title_'.$language->local) ? 'is-invalid' : ''); ?>" name="title_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('title', $language->local) ?? __('units.title')); ?>" value='<?php echo e(old("title_{$language->local}", $unit[$language->local]->title ?? "")); ?>'/>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?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('description', $language->local) ?? __('units.description')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                    <textarea  class="form-control <?php echo e($errors->has('description_'.$language->local) ? 'is-invalid' : ''); ?>" name="description_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('description', $language->local) ?? __('units.description')); ?>"><?php echo e(old("description_{$language->local}", $unit[$language->local]->description ?? "")); ?></textarea>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.user_id')); ?> </label>
                <select name="user_code" id="user_code" class="form-control <?php echo e($errors->has('user_code') ? 'is-invalid' : ''); ?>">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($row->code); ?>" <?php echo e(old('user_code', $unit->user->code ?? '') == $row->code ? 'selected' : ''); ?>><?php echo e($row->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.type_id')); ?> </label>
                <select name="type_id" id="type_id" class="form-control <?php echo e($errors->has('type_id') ? 'is-invalid' : ''); ?>">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                    <?php $__currentLoopData = $types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($row->id); ?>" <?php echo e(old('type_id', $unit->type_id ?? '') == $row->id ? 'selected' : ''); ?>><?php echo e($row->title); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.city_id')); ?> </label>
                <select name="city_id" id="city_id" class="form-control <?php echo e($errors->has('city_id') ? 'is-invalid' : ''); ?>">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                    <?php $__currentLoopData = $cities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($row->id); ?>" <?php echo e(old('city_id', $unit->area->city_id ?? '') == $row->id ? 'selected' : ''); ?>><?php echo e($row->title); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.area_id')); ?> </label>
                <select name="area_id" id="area_id" class="form-control <?php echo e($errors->has('area_id') ? 'is-invalid' : ''); ?>">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                </select>
            </div>
            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.floor')); ?> </label>
                <select name="floor" id="floor" class="form-control <?php echo e($errors->has('floor') ? 'is-invalid' : ''); ?>">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                    <?php for($i = 1; $i <= 20; $i++): ?>
                        <option value="<?php echo e($i); ?>" <?php echo e(old('floor', $unit->floor ?? '') == $i ? 'selected' : ''); ?>> الدور  <?php echo e($i); ?></option>
                    <?php endfor; ?>
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.price')); ?> </label>
                <input type="number" step="0.1" name="price" value="<?php echo e(old('price', $unit->price ?? '')); ?>" class="form-control <?php echo e($errors->has('price') ? 'is-invalid' : ''); ?>" placeholder="<?php echo e(__('units.price')); ?>">
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.status')); ?> </label>
                <select name="status" id="status" class="form-control">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                    <?php $__currentLoopData = config('globals.unit_statuses'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($status); ?>" <?php echo e(($unit->status ?? '') == $status ? 'selected' : ''); ?>><?php echo e(__('units.statuses.'.$status)); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.sold_status')); ?> </label>
                <select name="sold_status" id="sold_status" class="form-control">
                    <option value=""><?php echo e(__('dashboard.select')); ?></option>
                    <?php $__currentLoopData = config('globals.sold_statuses'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sold_status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($sold_status); ?>" <?php echo e(($unit->sold_status ?? '') == $sold_status ? 'selected' : ''); ?>><?php echo e(__('units.sold_statuses.'.$sold_status)); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.baths')); ?> </label>
                <input type="number" name="baths" value="<?php echo e(old('baths', $unit->baths ?? '')); ?>" class="form-control <?php echo e($errors->has('baths') ? 'is-invalid' : ''); ?>" placeholder="<?php echo e(__('units.baths')); ?>">
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.space')); ?> </label>
                <input type="number" step="0.1" name="space" value="<?php echo e(old('space', $unit->space ?? '')); ?>" class="form-control <?php echo e($errors->has('space') ? 'is-invalid' : ''); ?>" placeholder="<?php echo e(__('units.space')); ?>">
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.net_space')); ?> </label>
                <input type="number" step="0.1" name="net_space" value="<?php echo e(old('net_space', $unit->net_space ?? '')); ?>" class="form-control <?php echo e($errors->has('net_space') ? 'is-invalid' : ''); ?>" placeholder="<?php echo e(__('units.net_space')); ?>">
            </div>

            <div class="form-group col-lg-6">
                <label><?php echo e(__('units.image')); ?> </label>
                <input id="old_image" class="old_image" type="hidden" name="old_image" value="<?php echo e($unit->image ?? ""); ?>"/>
                <input type="file" class="form-control <?php echo e($errors->has('image') ? 'is-invalid' : ''); ?>" name="image" placeholder="<?php echo e(__('units.image')); ?>" value='<?php echo e(old('image', '')); ?>' accept="image/*"/>
                <?php if(($unit->image ?? null) && ($unit->image_url ?? null)): ?>
                    <a href="<?php echo e($unit->image_url); ?>" class="btn btn-primary" target="_new"><i class="fas fa-download"></i></a>
                <?php endif; ?>
            </div>
            
            <div class="border-item photos col-md-12 other_image_container">
                <div class="row" id="imageContainer">
                    <?php $__currentLoopData = $unit['photos'] ?? []; $__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($photo->image_url); ?>" data-fancybox="gallery"><img src="<?php echo e($photo->image_url); ?>" alt=""></a>
                                </div>
                                <input type="hidden" name="old_images[]" value="<?php echo e($photo->image ?? ""); ?>">
                                <a href="#" onclick="DeleteImg(this)" class="close"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <div class="text-center">
                    <div class="clearfix"></div>
                    <span id="add">
                        <a class="add" id="addImage"> <?php echo e(__('units.add_photos')); ?> </a>
                    </span>
                </div>
            </div>

            <div class="text-center mt-5 col-12">
                <button class="butn"><span><?php echo e(__('dashboard.save')); ?></span></button>
            </div>
        </form>
        
        <input type="file" id="fileTemplate" name="images[]" accept="image/*" style="display: none;" />
    </div>

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

<?php $__env->startSection('inner_js'); ?>
<script>
    const area_route = '<?php echo e(route("dashboard.areas")); ?>';
    const area_id = '<?php echo e(old("area_id", $unit->area_id ?? '')); ?>';
</script>
<script src="<?php echo e(asset('assets/admin/js/custom/admin/units.js')); ?>"></script>
<script src="<?php echo e(asset('assets/admin/js/custom/admin/images_grid.js')); ?>"></script>
<?php $__env->stopSection(); ?>




<?php echo $__env->make('admin.layouts.container', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/mostafagalal/Desktop/Sites/AhmedGoda/resources/views/admin/units/form.blade.php ENDPATH**/ ?>