<?php

if (!defined('WPINC')) {
    die();
}

use EstatebudConnect\Utilities\Helper;

$settings_data = $settings_data ?? [];
$search_id = $search_id ?? '';
$shortcode_id = $shortcode_id ?? '';
$map = $map ?? 'false';
$map_position = $map_position ?? 'top';
$map_default_state = $map_default_state ?? 'off';
$is_favorites = (bool) ($is_favorites ?? false);

$map_provider = $settings_data['map_provider'] ?? '';
$has_map = !empty($map_provider) && $map !== 'false';
$is_map_active = $has_map && $map_default_state === 'on';
?>
<?php if (!empty($search_id) || $is_favorites === true): ?>
    <div class="estatebud-listings">
        <?php
        $layout_vars = [
            'has_map' => $has_map,
            'is_map_active' => $is_map_active,
            'shortcode_id' => $shortcode_id,
            'map_position' => $map_position,
            'settings_data' => $settings_data,
        ];

        if ($map_position === 'left' || $map_position === 'right') {
            Helper::render_markup_from_views('Public/Listings/layouts/map-side.php', $layout_vars);
        } else {
            Helper::render_markup_from_views('Public/Listings/layouts/map-top.php', $layout_vars);
        }
        ?>
    </div>
<?php endif; ?>