<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo $title; ?></title>
    <meta name="description" content="<?php echo $property_data->short_description; ?>">
    <meta name="keywords" content="<?php echo get_option('propertybase_landingpage_seo_keywords'); ?>">

    <!-- Favicon -->
    <?php
    $favIcon = get_option('favicon');
    $favIconPath = '';
    if ($favIcon != '') {
        $favIconPath = 'uploads/company/' . $favIcon;
    }
    ?>
    <link rel="shortcut icon" href="<?php echo base_url($favIconPath); ?>" type="image/x-icon">


    <?php
    if (get_option('propertybase_add_no_follow_tag_for_landingpage')) {
        ?>
        <meta name="robots" content="noindex, nofollow">
        <?php
    }
    ?>

    <!-- Font awesome -->
    <link href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/font-awesome.css') ?>"
          rel="stylesheet">
    <!-- Bootstrap -->
    <link href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/bootstrap.css') ?>"
          rel="stylesheet">
    <!-- slick slider -->
    <link rel="stylesheet" type="text/css"
          href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/slick.css') ?>">
    <!-- price picker slider -->
    <link rel="stylesheet" type="text/css"
          href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/nouislider.css') ?>">
    <!-- Fancybox slider -->
    <link rel="stylesheet"
          href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/jquery.fancybox.css') ?>"
          type="text/css" media="screen"/>
    <!-- Theme color -->
    <link id="switcher"
          href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/theme-color/default-theme.css') ?>"
          rel="stylesheet">

    <!-- Main style sheet -->
    <link href="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/css/style.css') ?>"
          rel="stylesheet">

    <script src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'assets/js/chart.js'); ?>"></script>
    <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>


    <meta property="og:title" content="<?php echo $title; ?>">
    <?php
    if (!empty($property_main_image)) {
        ?>
        <meta property="og:image"
              content="<?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); ?>">
        <?php
    }
    ?>
</head>
<body class="aa-price-range">
<!-- Pre Loader -->
<div id="aa-preloader-area">
    <div class="pulse"></div>
</div>
<!-- SCROLL TOP BUTTON -->
<a class="scrollToTop" href="#"><i class="fa fa-angle-double-up"></i></a>
<!-- END SCROLL TOP BUTTON -->


<!-- Start Properties  -->
<section id="aa-properties">
    <div class="container">
        <div class="row">
            <div class="col-md-8">
                <div class="aa-properties-content">
                    <!-- Start properties content body -->
                    <div class="aa-properties-details">
                        <div class="aa-properties-details-img">
                            <?php
                            if (!empty($property_main_image)) {
                                $path = substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/main_image/' . $property_data->id . '/' . $property_main_image[0]['file_name']), 0, -1);
                                ?>
                                <img src="<?php echo $path; ?>"
                                     alt="<?php echo $property_data->name; ?>">
                                <?php
                            }

                            if (!empty($property_list_images) && count($property_list_images) > 0) {
                                foreach ($property_list_images as $image) {
                                    ?>
                                    <img src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'uploads/property_images/attachments/' . $property_data->id . '/' . $image['image_url']); ?>"
                                         alt="<?php echo $property_data->name; ?>">
                                    <?php
                                }
                            }
                            ?>

                            <?php
                            if (empty($property_main_image) && empty($property_list_images) && count($property_list_images) === 0) {
                                $propertyImage = substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/default_image.jpg'), 0, -1);
                                ?>
                                <img src="<?php echo $propertyImage; ?>" alt="<?php echo $property_data->name; ?>">
                                <?php
                            }
                            ?>
                        </div>
                        <div class="aa-properties-info">
                            <h2><?php echo $title; ?></h2>
                            <span class="aa-price"><?php echo propertybase_get_property_price($property_data->id, true, true) ?></span>
                            <?php echo $property_data->long_description; ?>
                            <h4>Property Details</h4>
                            <ul>
                                <?php if (!empty($property_data->address)) : ?>
                                    <li>Address: <?php echo $property_data->address; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->city)) : ?>
                                    <li>City: <?php echo $property_data->city; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->zip)) : ?>
                                    <li>Zip code: <?php echo $property_data->zip; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->country)) : ?>
                                    <li>Country: <?php echo get_country_name($property_data->country); ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->size)) : ?>
                                    <li>Size: <?php echo $property_data->size; ?> m²</li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->bathrooms)) : ?>
                                    <li>Bathrooms: <?php echo $property_data->bathrooms; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->bedrooms)) : ?>
                                    <li>Bedrooms: <?php echo $property_data->bedrooms; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->rooms)) : ?>
                                    <li>Rooms: <?php echo $property_data->rooms; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->floor)) : ?>
                                    <li>Floor: <?php echo $property_data->floor; ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->property_purpose)) : ?>
                                    <li>
                                        Purpose: <?php echo _l(propertybase_property_purposes($property_data->property_purpose)); ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->category)) : ?>
                                    <li>
                                        Type: <?php echo propertybase_get_property_category_name($property_data->category); ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->ownership)) : ?>
                                    <li>
                                        Ownership: <?php echo propertybase_get_property_ownership_name($property_data->ownership); ?></li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->gas_emission)) : ?>
                                    <li>Gas emissions: <?php echo $property_data->gas_emission; ?> kg CO2 / m², year
                                    </li>
                                <?php endif; ?>

                                <?php if (!empty($property_data->energy_efficient)) : ?>
                                    <li>Energy efficient: <?php echo $property_data->energy_efficient; ?> kWh EP / m²,
                                        year
                                    </li>
                                <?php endif; ?>
                            </ul>

                            <?php if (!empty($property_data->amenities_with_types)) { ?>
                                <?php foreach ($property_data->amenities_with_types as $type => $amenities): ?>
                                    <h4><?php echo ucfirst($type); ?></h4>
                                    <ul>
                                        <?php foreach ($amenities as $amenity): ?>
                                            <li><?php echo htmlspecialchars($amenity); ?></li>
                                        <?php endforeach; ?>
                                    </ul>
                                <?php endforeach; ?>
                            <?php } ?>

                            <?php
                            if (isset($property_floor_image) && !empty($property_floor_image)) {
                                $propertyFloorImage = $property_floor_image[0]['file_name'] ?? '';
                                ?>
                                <h4 class="floorPlanTitle">Property Floor Plan</h4>
                                <img width="100%" height="480" class="floorPlanImage"
                                     alt="<?php echo $title ?? 'n/a' ?>"
                                     src="<?php echo substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/floor_image/' . $property_data->id . '/' . $propertyFloorImage), 0, -1); ?>">
                                <?php
                            }
                            ?>

                            <?php
                            if (isset($property_data->embeded_video) && !empty($property_data->embeded_video)) {
                                ?>
                                <h4>Property Video</h4>
                                <?php echo html_entity_decode($property_data->embeded_video); ?>
                                <?php
                            }
                            ?>
                            <?php
                            if (!empty($property_data->lat) && !empty($property_data->lng)) {
                                ?>
                                <h4>Property Map</h4>
                                <div id="map" style="height: 360px;"></div>
                                <?php
                            }
                            ?>
                        </div>

                        <!-- Properties social share -->
                        <div class="aa-properties-social">
                            <ul>
                                <li>Share</li>

                                <?php
                                // Get property details for sharing
                                $property_url = urlencode(site_url(PROPERTYBASE_MODULE_NAME . '/Landingpage/property/' . $property_data->id));
                                $property_title = urlencode($property_data->name);
                                $property_image = isset($property_main_image[0]['file_name'])
                                    ? urlencode(site_url('download/preview_image?path=' . protected_file_url_by_path($path) . '&type='))
                                    : '';

                                // Social media share URLs
                                $facebook_share_url = "https://www.facebook.com/sharer/sharer.php?u={$property_url}";
                                $twitter_share_url = "https://twitter.com/intent/tweet?text={$property_title}&url={$property_url}";
                                $pinterest_share_url = "https://pinterest.com/pin/create/button/?url={$property_url}&media={$property_image}&description={$property_title}";
                                ?>

                                <li><a href="<?php echo $facebook_share_url; ?>" target="_blank"><i
                                                class="fa fa-facebook"></i></a></li>
                                <li><a href="<?php echo $twitter_share_url; ?>" target="_blank"><i
                                                class="fa fa-twitter"></i></a></li>
                                <li><a href="<?php echo $pinterest_share_url; ?>" target="_blank"><i
                                                class="fa fa-pinterest"></i></a></li>
                            </ul>
                        </div>


                    </div>
                </div>
            </div>
            <!-- Start properties sidebar -->

            <div class="col-md-4">
                <a href="<?php echo site_url(PROPERTYBASE_MODULE_NAME . '/Landingpage'); ?>">GO BACK TO OTHER
                    PROPERTIES</a>
                <br>
                <aside class="aa-properties-sidebar">
                    <!-- Start Single properties sidebar -->
                    <div class="aa-properties-single-sidebar">
                        <?php echo propertybase_render_lead_form($property_data); ?>
                    </div>
                    <!-- Start Single properties sidebar -->
                    <div class="aa-properties-single-sidebar">
                        <h3>Latest Properties</h3>
                        <?php
                        $latest_properties = propertybase_get_latest_properties();

                        if (!empty($latest_properties)) {
                            foreach ($latest_properties as $property) {
                                $propertyMainImage = $property['main_image'][0]['file_name'] ?? 'default.jpg';
                                $propertyUrl = propertybase_get_property_single_page_url($property['id']);
                                $propertyName = $property['name'] ?? 'No Title';
                                $propertyShortDesc = $property['short_description'] ?? 'No description available';
                                $propertyPrice = propertybase_get_property_price($property['id'], true, true);
                                $propertyMainImage = $property['main_image'][0]['file_name'] ?? '';
                                ?>
                                <div class="media">
                                    <div class="media-left">
                                        <a href="<?php echo $propertyUrl; ?>">
                                            <img class="media-object"
                                                 src="<?php echo substr(module_dir_url(PROPERTYBASE_MODULE_NAME . '/uploads/property_images/main_image/' . $property['id'] . '/' . $propertyMainImage), 0, -1); ?>">
                                        </a>
                                    </div>
                                    <div class="media-body">
                                        <h4 class="media-heading"><a
                                                    href="<?php echo $propertyUrl; ?>"><?php echo $propertyName; ?></a>
                                        </h4>
                                        <p><?php echo $propertyShortDesc; ?></p>
                                        <span><?php echo $propertyPrice; ?></span>
                                    </div>
                                </div>
                                <?php
                            }
                        } else {
                            echo '<p>No latest properties available.</p>';
                        }
                        ?>
                    </div>
                </aside>
            </div>
        </div>
    </div>
</section>
<!-- / Properties  -->

<!-- Footer -->
<footer id="aa-footer">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="aa-footer-area">
                    <div class="row">
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            <div class="aa-footer-left">
                                <p>@<?php echo date("Y"); ?></p>
                            </div>
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            <div class="aa-footer-middle">
                                <a href="#"><i class="fa fa-facebook"></i></a>
                                <a href="#"><i class="fa fa-twitter"></i></a>
                                <a href="#"><i class="fa fa-google-plus"></i></a>
                                <a href="#"><i class="fa fa-youtube"></i></a>
                            </div>
                        </div>
                        <div class="col-md-6 col-sm-12 col-xs-12">
                            <div class="aa-footer-right">
                                <a href="<?php echo site_url(PROPERTYBASE_MODULE_NAME . '/Landingpage') ?>">Home</a>
                                <a href="#">FAQ</a>
                                <a href="#">Privacy & Term</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</footer>
<!-- / Footer -->

<!-- jQuery library -->
<script src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/jquery.min.js') ?>"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/bootstrap.js') ?>"></script>
<!-- slick slider -->
<script type="text/javascript"
        src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/slick.js') ?>"></script>
<!-- Price picker slider -->
<script type="text/javascript"
        src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/nouislider.js') ?>"></script>
<!-- mixit slider -->
<script type="text/javascript"
        src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/jquery.mixitup.js') ?>"></script>
<!-- Add fancyBox -->
<script type="text/javascript"
        src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/jquery.fancybox.pack.js') ?>"></script>
<!-- Custom js -->
<script src="<?php echo module_dir_url(PROPERTYBASE_MODULE_NAME, 'views/landing_page/template/default/js/custom.js') ?>"></script>


<script>
    (function ($) {
        "use strict";
        $(document).ready(function () {
            <?php
            if (!empty($property_data->lat) && !empty($property_data->lng)) {
            ?>
            initMap('<?php echo $property_data->lat ?>', '<?php echo $property_data->lng; ?>')
            <?php
            }
            ?>

        })
    })(jQuery);

    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);
        });
    }
</script>

<?php echo get_option('propertybase_google_analytics_code'); ?>
</body>
</html>