<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<link rel="stylesheet" href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/css/leaflet.css'); ?>"/>
<script src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/leaflet.js'); ?>"></script>
<style>
    #sortable {
        list-style-type: none;
        margin: 0;
        padding: 0;
        width: 90%;
    }

    #sortable li {
        margin: 3px 3px 3px 0;
        padding: 1px;
        float: left;
        border: 0;
        background: none;
    }

    #sortable li img {
        width: 180px;
        height: 140px;
    }
</style>
<div id="wrapper">
    <div class="content">
        <div class="row">
            <?php
            if (isset($property_data)) {
                $requestUrl = PROPERTYBASE_MODULE_NAME . '/create/' . $property_data->id;
            } else {
                $requestUrl = PROPERTYBASE_MODULE_NAME . '/create';
            }

            echo form_open_multipart(admin_url($requestUrl), ['id' => 'propertyForm']);
            ?>
            <div class="col-md-6">
                <h4 class="tw-mt-0 tw-font-semibold tw-text-lg tw-text-neutral-700">
                    <?php echo _l('propertybase_property_information'); ?>
                </h4>
                <div class="panel_s">
                    <div class="panel-body">
                        <div class="col-md-12">
                            <?php if (isset($property_data) && !empty($property_main_image) != '') { ?>
                                <div class="row">
                                    <div class="col-md-9">
                                        <a target="_blank"
                                           href="<?php echo substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/main_image/' . $property_data->id . '/' . $property_main_image[0]['file_name']), 0, -1); ?>"
                                           class="display-block mbot5">
                                            <i class=""></i>
                                            <img
                                                 class="mtop5 img img-responsive text-center propertybase-create-image-size"
                                                 src="<?php echo substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/main_image/' . $property_data->id . '/' . $property_main_image[0]['file_name']), 0, -1); ?>">
                                        </a>
                                    </div>
                                </div>
                                <div class="clearfix"></div>
                            <?php } ?>
                            <div class="form-group">
                                <label for="asset_image"
                                       class="control-label"><?php echo _l('propertybase_property_main_image'); ?></label>
                                <input type="file" name="file" class="form-control" value=""
                                       data-toggle="tooltip">
                            </div>
                        </div>

                        <?php hooks()->do_action('propertybase_property_create_update_before_main_information', $property_data ?? []); ?>

                        <div class="col-md-12">
                            <?php echo render_input('name', 'propertybase_property_name', $property_data->name ?? ''); ?>
                        </div>

                        <div class="col-md-6">
                            <?php echo render_select('selected_agent', $members, ['staffid', ['firstname', 'lastname']], 'propertybase_agent', $property_data->selected_agent ?? '', [], [], '', '', false); ?>
                        </div>

                        <div class="col-md-6">
                            <?php echo render_select('category', $property_categories, ['id', 'name'], 'propertybase_property_category', $property_data->category ?? '', [], [], '', '', false); ?>
                        </div>

                        <div class="col-md-12">
                            <?php echo render_textarea('short_description', 'propertybase_property_short_description', $property_data->short_description ?? '', ['rows' => 10], [], '', 'tinymce'); ?>
                        </div>

                        <div class="col-md-12">
                            <?php echo render_textarea('long_description', 'propertybase_property_long_description', $property_data->long_description ?? '', ['rows' => 10], [], '', 'tinymce'); ?>
                        </div>

                        <?php
                        if (isset($property_data, $property_list_images)) {
                            ?>
                            <div class="col-md-12 mbot30">
                                <h4><?php echo _l('propertybase_property_images'); ?></h4>

                                <hr class="hr-panel-separator"/>
                                <div class="dropzone-previews"></div>

                                <div id="dropzoneDragArea" class="dz-default dz-message">
                                    <span><?php echo _l('propertybase_attach_file_placeholder'); ?></span>
                                </div>
                                <hr>
                                <h4 class="tw-mt-0 tw-font-semibold tw-text-lg tw-text-neutral-700">
                                    <?php echo _l('propertybase_property_rearrange_images'); ?> <br></h4>
                                <p><?php echo _l('propertybase_property_p_text'); ?></p>
                                <button type="button" id="updateOrder"
                                        class="btn btn-primary"><?php echo _l('propertybase_property_update_order'); ?></button>
                                <ul id="sortable">
                                    <?php
                                    foreach ($property_list_images as $image) {
                                        ?>
                                        <li class="ui-state-default" data-id="<?php echo $image['id']; ?>">
                                            <img src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'uploads/property_images/attachments/' . $property_data->id . '/' . $image['image_url']) ?>"
                                                 title="<?php echo $image['image_url'] ?>">
                                            <br>
                                            <button onclick="delete_image('<?php echo $image['property_id'] ?>','<?php echo $image['id'] ?>','<?php echo $image['image_url'] ?>')"
                                                    class="btn btn-danger _delete">X
                                            </button>
                                        </li>
                                        <?php
                                    }
                                    ?>
                                </ul>
                            </div>
                            <?php
                        }
                        ?>
                        <hr class="hr-panel-separator"/>
                        <?php hooks()->do_action('propertybase_property_create_update_before_first_tab', $property_data ?? []); ?>

                        <div class="col-md-12">
                            <div class="panel-group" role="tablist" aria-multiselectable="false">
                                <div class="panel panel-default">
                                    <div class="panel-heading" role="tab" id="propertylocationsid">
                                        <h4 class="panel-title">
                                            <a role="button" data-toggle="collapse" href="#property_location"
                                               aria-expanded="true">
                                                <?php echo _l('propertybase_property_location_information'); ?> <span
                                                        class="pull-right"><i class="fa fa-sort-down"></i></span>
                                            </a>
                                        </h4>
                                    </div>
                                    <div id="property_location" class="panel-collapse collapse in" role="tabpanel"
                                         aria-labelledby="propertylocationsid" aria-expanded="true">
                                        <div class="panel-body">

                                            <?php hooks()->do_action('propertybase_property_create_update_before_property_location_information', $property_data ?? []); ?>

                                            <div class="col-md-6">
                                                <?php echo render_input('address', 'propertybase_property_address', $property_data->address ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('city', 'propertybase_property_city', $property_data->city ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('zip_code', 'propertybase_property_zip_code', $property_data->zip_code ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_select('country', $property_countries, ['country_id', ['short_name'], 'iso2'], 'propertybase_property_country', $property_data->country ?? ''); ?>
                                            </div>

                                            <div class="col-md-12">
                                                <div id="map" class="propertybase-single-map-size"></div>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('lat', 'propertybase_gps_coordinate_lat', $property_data->lat ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('lng', 'propertybase_gps_coordinate_lng', $property_data->lng ?? ''); ?>
                                            </div>

                                            <?php hooks()->do_action('propertybase_property_create_update_after_property_location_information', $property_data ?? []); ?>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-12">
                            <div class="panel-group" role="tablist" aria-multiselectable="false">
                                <div class="panel panel-default">
                                    <div class="panel-heading" role="tab" id="propertyspecificationsid">
                                        <h4 class="panel-title">
                                            <a role="button" data-toggle="collapse" href="#property_specifications"
                                               aria-expanded="true">
                                                <?php echo _l('propertybase_property_specifications_information'); ?>
                                                <span
                                                        class="pull-right"><i class="fa fa-sort-down"></i></span>
                                            </a>
                                        </h4>
                                    </div>
                                    <div id="property_specifications"
                                         class="panel-collapse collapse <?php echo isset($property_data) ? 'in' : ''; ?>"
                                         role="tabpanel"
                                         aria-labelledby="propertyspecificationsid"
                                         aria-expanded="<?php echo isset($property_data) ? 'true' : ''; ?>" style="">
                                        <div class="panel-body">

                                            <?php hooks()->do_action('propertybase_property_create_update_before_property_specification_information', $property_data ?? []); ?>

                                            <div class="col-md-12">
                                                <?php echo render_select('property_purpose', propertybase_property_purposes(null, true), ['id', 'purpose'], 'propertybase_property_purpose', $property_data->property_purpose ?? '', [], [], '', '', false); ?>
                                            </div>

                                            <div class="col-md-12">
                                                <?php echo render_input('size', 'propertybase_property_size', $property_data->size ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('bathrooms', 'propertybase_property_bathrooms', $property_data->bathrooms ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('bedrooms', 'propertybase_property_bedrooms', $property_data->bedrooms ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('rooms', 'propertybase_property_rooms', $property_data->rooms ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('floor', 'propertybase_property_floor', $property_data->floor ?? ''); ?>
                                            </div>

                                            <div class="col-md-12">
                                                <?php echo render_select('ownership', $property_ownership_types, ['id', 'name'], 'propertybase_property_ownership', $property_data->ownership ?? '', [], [], '', '', false); ?>
                                            </div>

                                            <?php hooks()->do_action('propertybase_property_create_update_after_property_specification_information', $property_data ?? []); ?>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-12">
                            <div class="panel-group" role="tablist" aria-multiselectable="false">
                                <div class="panel panel-default">
                                    <div class="panel-heading" role="tab" id="propertymediaseoid">
                                        <h4 class="panel-title">
                                            <a role="button" data-toggle="collapse" href="#property_media_seo"
                                               aria-expanded="true">
                                                <?php echo _l('propertybase_property_seo'); ?> <span
                                                        class="pull-right"><i class="fa fa-sort-down"></i></span>
                                            </a>
                                        </h4>
                                    </div>
                                    <div id="property_media_seo"
                                         class="panel-collapse collapse <?php echo isset($property_data) ? 'in' : ''; ?>"
                                         role="tabpanel"
                                         aria-labelledby="propertymediaseoid"
                                         aria-expanded="<?php echo isset($property_data) ? 'true' : ''; ?>" style="">
                                        <div class="panel-body">

                                            <?php hooks()->do_action('propertybase_property_create_update_before_property_media_and_seo_information', $property_data ?? []); ?>

                                            <div class="col-md-12">
                                                <?php echo render_input('seo_keywords', 'propertybase_property_seo_keywords', $property_data->seo_keywords ?? ''); ?>
                                            </div>

                                            <div class="col-md-12">
                                                <?php if (isset($property_data) && !empty($property_floor_image) != '') { ?>
                                                    <div class="row">
                                                        <div class="col-md-9">
                                                            <a target="_blank"
                                                               href="<?php echo substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/floor_image/' . $property_data->id . '/' . $property_floor_image[0]['file_name']), 0, -1); ?>"
                                                               class="display-block mbot5">
                                                                <i class=""></i>
                                                                <?php
                                                                $path = PROPERTYBASE_PROPERTY_FLOOR_IMAGE_PATH . $property_data->id . '/' . $property_floor_image[0]['file_name'];
                                                                ?>
                                                                <img
                                                                     class="mtop5 img img-responsive text-center propertybase-floor-image-size"
                                                                     src="<?php echo site_url('download/preview_image?path=' . protected_file_url_by_path($path) . '&type='); ?>">
                                                            </a>
                                                        </div>
                                                    </div>
                                                    <div class="clearfix"></div>
                                                <?php } ?>
                                                <div class="form-group">
                                                    <label for="asset_image"
                                                           class="control-label"><?php echo _l('propertybase_property_floor_plan_image'); ?></label>
                                                    <input type="file" name="floor" class="form-control" value=""
                                                           data-toggle="tooltip">
                                                </div>
                                            </div>

                                            <div class="col-md-12">
                                                <?php echo render_input('embeded_video', 'propertybase_property_embeded_video', isset($property_data->embeded_video) ? html_entity_decode($property_data->embeded_video) : ''); ?>
                                            </div>

                                            <div class="col-md-12">
                                                <?php echo isset($property_data->embeded_video) ? html_entity_decode($property_data->embeded_video) : ''; ?>
                                            </div>

                                            <?php hooks()->do_action('propertybase_property_create_update_after_property_media_and_seo_information', $property_data ?? []); ?>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-12">
                            <div class="panel-group" role="tablist" aria-multiselectable="false">
                                <div class="panel panel-default">
                                    <div class="panel-heading" role="tab" id="propertypricingid">
                                        <h4 class="panel-title">
                                            <a role="button" data-toggle="collapse" href="#property_pricing"
                                               aria-expanded="true">
                                                <?php echo _l('propertybase_property_pricing_information'); ?> <span
                                                        class="pull-right"><i class="fa fa-sort-down"></i></span>
                                            </a>
                                        </h4>
                                    </div>
                                    <div id="property_pricing"
                                         class="panel-collapse collapse <?php echo isset($property_data) ? 'in' : ''; ?>"
                                         role="tabpanel"
                                         aria-labelledby="propertypricingid"
                                         aria-expanded="<?php echo isset($property_data) ? 'true' : ''; ?>" style="">
                                        <div class="panel-body">

                                            <?php hooks()->do_action('propertybase_property_create_update_before_property_pricing_information', $property_data ?? []); ?>

                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label for="sale_price"><?php echo _l('propertybase_property_sale_price'); ?></label>
                                                    <div class="input-group">
                                                        <input type="number" class="form-control" name="sale_price"
                                                               value="<?php echo $property_data->sale_price ?? ''; ?>">
                                                        <div class="input-group-addon">
                                                            <?php echo get_base_currency()->symbol; ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="rent_price_incl"><?php echo _l('propertybase_property_rent_price_incl'); ?></label>
                                                    <div class="input-group">
                                                        <input type="number" class="form-control" name="rent_price_incl"
                                                               value="<?php echo $property_data->rent_price_incl ?? ''; ?>">
                                                        <div class="input-group-addon">
                                                            <?php echo get_base_currency()->symbol; ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="rent_price_excl"><?php echo _l('propertybase_property_rent_price_excl'); ?></label>
                                                    <div class="input-group">
                                                        <input type="number" class="form-control" name="rent_price_excl"
                                                               value="<?php echo $property_data->rent_price_excl ?? ''; ?>">
                                                        <div class="input-group-addon">
                                                            <?php echo get_base_currency()->symbol; ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <?php hooks()->do_action('propertybase_property_create_update_after_property_pricing_information', $property_data ?? []); ?>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php foreach ($property_amenities_types as $amenity_type): ?>
                            <?php if ($amenity_type['is_enabled'] == 0): // Only render enabled amenity types ?>
                                <div class="col-md-12">
                                    <div class="panel-group" role="tablist" aria-multiselectable="false">
                                        <div class="panel panel-default">
                                            <div class="panel-heading" role="tab"
                                                 id="amenityType-<?php echo $amenity_type['id']; ?>">
                                                <h4 class="panel-title">
                                                    <a role="button" data-toggle="collapse"
                                                       href="#amenityTypeContent-<?php echo $amenity_type['id']; ?>"
                                                       aria-expanded="true">
                                                        <?php echo htmlspecialchars($amenity_type['name']); ?> <span
                                                                class="pull-right"><i
                                                                    class="fa fa-sort-down"></i></span>
                                                    </a>
                                                </h4>
                                            </div>
                                            <div id="amenityTypeContent-<?php echo $amenity_type['id']; ?>"
                                                 class="panel-collapse collapse <?php echo isset($property_data) ? 'in' : ''; ?>"
                                                 role="tabpanel"
                                                 aria-labelledby="amenityType-<?php echo $amenity_type['id']; ?>">
                                                <div class="panel-body">
                                                    <div class="row">
                                                        <?php foreach ($property_amenities as $amenity): ?>
                                                            <?php if ($amenity['is_enabled'] == 0 && $amenity['category'] == $amenity_type['id']): ?>
                                                                <div class="col-md-3">
                                                                    <div class="checkbox">
                                                                        <input type="checkbox"
                                                                               id="amenity-<?php echo $amenity['id']; ?>"
                                                                               name="amenities[<?php echo $amenity['id']; ?>]"
                                                                               value="<?php echo $amenity['id']; ?>"
                                                                            <?php echo isset($property_data) && in_array($amenity['id'], $property_data->amenities ?? []) ? 'checked' : ''; ?>>
                                                                        <label for="amenity-<?php echo $amenity['id']; ?>">
                                                                            <i class="<?php echo $amenity['icon']; ?>"></i>
                                                                            <?php echo htmlspecialchars($amenity['name']); ?>
                                                                        </label>
                                                                    </div>
                                                                </div>
                                                            <?php endif; ?>
                                                        <?php endforeach; ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endif; ?>
                        <?php endforeach; ?>


                        <div class="col-md-12">
                            <div class="panel-group" role="tablist" aria-multiselectable="false">
                                <div class="panel panel-default">
                                    <div class="panel-heading" role="tab" id="propertysatussettingsid">
                                        <h4 class="panel-title">
                                            <a role="button" data-toggle="collapse" href="#property_status_settings"
                                               aria-expanded="true">
                                                <?php echo _l('propertybase_property_status_settings_information'); ?>
                                                <span
                                                        class="pull-right"><i class="fa fa-sort-down"></i></span>
                                            </a>
                                        </h4>
                                    </div>
                                    <div id="property_status_settings"
                                         class="panel-collapse collapse <?php echo isset($property_data) ? 'in' : ''; ?>"
                                         role="tabpanel"
                                         aria-labelledby="propertysatussettingsid"
                                         aria-expanded="<?php echo isset($property_data) ? 'true' : ''; ?>" style="">
                                        <div class="panel-body">

                                            <?php hooks()->do_action('propertybase_property_create_update_before_property_status_and_settings_information', $property_data ?? []); ?>

                                            <div class="col-md-4">
                                                <?php echo render_select('is_featured', propertybase_yes_no_options(), ['id', 'value'], 'propertybase_property_is_featured', $property_data->is_featured ?? '', [], [], '', '', false); ?>
                                            </div>

                                            <div class="col-md-4">
                                                <?php echo render_select('is_visible_for_public', propertybase_yes_no_options(), ['id', 'value'], 'propertybase_property_is_visible_for_public', $property_data->is_visible_for_public ?? '', [], [], '', '', false); ?>
                                            </div>

                                            <div class="col-md-4">
                                                <?php echo render_select('is_enabled', propertybase_yes_no_options(), ['id', 'value'], 'propertybase_property_is_activated', $property_data->is_enabled ?? '', [], [], '', '', false); ?>
                                            </div>

                                            <div class="col-md-12">
                                                <?php echo render_select('energy_effiency', $property_energy_efficiency_types, ['id', 'name'], 'propertybase_property_energy_effiency', $property_data->energy_effiency ?? '', [], [], '', '', false); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('energy_efficient', 'propertybase_property_energy_efficient', $property_data->energy_efficient ?? ''); ?>
                                            </div>

                                            <div class="col-md-6">
                                                <?php echo render_input('gas_emission', 'propertybase_property_gas_emission', $property_data->gas_emission ?? ''); ?>
                                            </div>

                                            <?php hooks()->do_action('propertybase_property_create_update_after_property_status_and_settings_information', $property_data ?? []); ?>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php hooks()->do_action('propertybase_property_create_update_after_last_tab', $property_data ?? []); ?>
                    </div>
                </div>
            </div>

            <?php hooks()->do_action('propertybase_property_create_update_before_right_side', $property_data ?? []); ?>

            <div class="col-md-6">
                <h4 class="tw-mt-0 tw-font-semibold tw-text-lg tw-text-neutral-700">
                    <?php echo _l('propertybase_property_custom_fields') ?>
                </h4>
                <div class="panel_s">
                    <div class="panel-body">
                        <?php
                        $customFields = render_custom_fields('propertybase_pr', $property_data->id ?? 0);
                        if (empty($customFields)) {
                            echo _l('propertybase_asset_no_custom_fields_available');
                        } else {
                            echo $customFields;
                        }
                        ?>
                    </div>
                </div>
            </div>

            <?php hooks()->do_action('propertybase_property_create_update_after_right_side', $property_data ?? []); ?>

            <div class="btn-bottom-toolbar text-right">
                <button type="submit"
                        class="btn btn-primary"><?php echo !isset($property_data) ? _l('propertybase_create') : _l('save'); ?></button>
            </div>
            <?php echo form_close(); ?>
        </div>
    </div>
</div>
<?php init_tail(); ?>
<script>
    (function ($) {
        "use strict";

        var map;
        Dropzone.options.quickshareForm = false;
        var expenseDropzone;

        $("#sortable").sortable();

        $("#propertyForm").appFormValidator({
            rules: {
                name: "required",
                selected_agent: "required",
                category: "required",
            },
        });

        if ($('#dropzoneDragArea').length > 0) {
            expenseDropzone = new Dropzone("#propertyForm", appCreateDropzoneOptions({
                autoProcessQueue: false,
                clickable: '#dropzoneDragArea',
                previewsContainer: '.dropzone-previews',
                maxFiles: 10,
                addRemoveLinks: true,
                success: function (file, response) {
                    response = JSON.parse(response);
                    if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
                        window.location.assign(response.url);
                    }
                },
            }));
        }

        <?php if (!empty($property_data->id)) { ?>
        $('#propertyForm').on('submit', function () {
            if (typeof expenseDropzone !== 'undefined' && expenseDropzone.getQueuedFiles().length > 0) {
                expenseDropzone.options.url = admin_url + 'propertybase/queue_uploaded_file/<?php echo $property_data->id; ?>';
                expenseDropzone.processQueue();
            }
        });
        <?php } ?>

        <?php if (!empty($property_data->lat) && !empty($property_data->lng)) { ?>
        initMap('<?php echo $property_data->lat ?>', '<?php echo $property_data->lng; ?>');
        <?php } else { ?>
        initMap();
        <?php } ?>

        $(document).on('click', '#updateOrder', function () {
            var imageids_arr = [];

            $('#sortable li').each(function () {
                var id = $(this).data('id');
                imageids_arr.push(id);
            });

            $.post(admin_url + "propertybase/update_images_order", {imageids: imageids_arr}).done(function (response) {
                response = JSON.parse(response);
                if (response.error === 0) {
                    alert_float('success', response.message);
                } else {
                    alert_float('danger', response.message);
                }
            });
        });

    })(jQuery);

    function updateLatLngInputs(lat, lng) {
        document.getElementById('lat').value = lat;
        document.getElementById('lng').value = lng;
    }

    function initMap(lat = '51.505', lng = '-0.09') {
        var defaultLocation = [lat, lng];

        map = L.map('map', {
            center: defaultLocation,
            zoom: 13
        });

        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);

        var marker = L.marker(defaultLocation, {
            draggable: true
        }).addTo(map);

        marker.on('dragend', function (e) {
            var latLng = marker.getLatLng();
            updateLatLngInputs(latLng.lat, latLng.lng);
        });

        map.on('click', function (e) {
            var latLng = e.latlng;
            marker.setLatLng(latLng);
            updateLatLngInputs(latLng.lat, latLng.lng);
        });
    }

    function delete_image(property_id, image_id, image_path) {
        $.post(admin_url + "propertybase/delete_image", {
            property_id: property_id,
            image_id: image_id,
            image_path: image_path
        }).done(function () {
            location.reload();
        });
    }
</script>