<?php

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

use EstatebudConnect\Utilities\Helper;

$settings_data = $settings_data ?? [];
$search_id = $search_id ?? '';
$page_number = (int) ($page_number ?? 1);
$map_position = $map_position ?? 'top';
$map_default_state = $map_default_state ?? 'off';
$is_favorites = (bool) ($is_favorites ?? false);
?>
<?php if (!empty($search_id) || $is_favorites === true): ?>
    <div class="estatebud-listings">
        <?php
        $listings_content_class = 'estatebud-listings-content';

        if ($map_default_state === 'on' && ($map_position === 'left' || $map_position === 'right')) {
            $listings_content_class .= ' estatebud-listings-content-map-' . esc_attr($map_position);
        }
        ?>
        <div class="<?php echo esc_attr($listings_content_class); ?>">
            <?php
            $map_provider = $settings_data['map_provider'] ?? '';

            if (!empty($map_provider) && $map_default_state === 'on' && ($map_position === 'left' || $map_position === 'right')) {
                $map_wrapper_style =
                    'width: 40% !important; flex-shrink: 0 !important; flex-grow: 0 !important; display: flex !important; visibility: visible !important; background: var(--estatebud-neutral-50); position: relative; overflow: hidden; z-index: 10; height: 800px !important;';
                echo '<div class="estatebud-map-wrapper estatebud-map-wrapper-is-active" style="' .
                    esc_attr($map_wrapper_style) .
                    '"></div>';
            } ?>
            <?php Helper::render_markup_from_views('Public/Listings/components/loading.php', [
                'page_number' => $page_number,
                'map_position' => $map_position,
                'map_default_state' => $map_default_state,
                'settings_data' => $settings_data,
            ]); ?>
        </div>
    </div>
<?php endif; ?>